Commit Graph

2829 Commits

Author SHA1 Message Date
Travis Geiselbrecht
9c67917dd7 [fpu] Implement two versions of all of the printf routines: with and without fpu support
The default printf and family will now not implement FPU support, a
second copy of the routines will be generated with the _float suffix.

ie, printf() has no %f support, but printf_float() does.

This is to avoid the default printf from emitting any floating point
instructions when used within core kernel code which has been an off and
on problem for years, especially on architectures that are eager to use
fpu/vector instructions for regular non-fpu code.

If FPU is not implemented on the arch, the *_float routines will alias
to the integer only one.

Perhaps a much more proper solution is to invert this and require every
caller of printf that cannot tolerate fpu codegen (which in mainline is
most of it) use a _nofloat implementation, but this would touch
pratically all printfs in mainline.

This solution acknowledges that for the most part most of the code in
mainline is in-kernel support code, and doesn't need floating point,
except for perhaps some app/* code, which already can opt in.

This solution also can potentially bloat the size of the binary by
having two complete implementations, though I think in practice the
architectures where the extra few KB of code will matter generally dont
have FPU support, or aren't using it. In the latter case the
link-time-gc should remove unused _float routines.
2025-10-08 23:51:06 -07:00
Travis Geiselbrecht
5016118509 [fpu] have the arch layers set WITH_NO_FPU based on the cpu
This will generally turn off more FPU codegen, even if its using
software fallback unless the project/target/platform selects a cpu that
has FPU support. This also turns off a few blocks of test code and the
upcoming floating point printf if it's not present on the arch.

This may break projects that were compiling for say cortex-m0 but
expected FPU code to be present. If so it should be pretty easy to
override it, but not going to add that yet unless it's necessary.
2025-10-08 23:50:53 -07:00
Travis Geiselbrecht
85e35e1426 [make] add LIBGCC to the global config
This forces the system to rebuild if the compiler's path changed, which
probably means it is a version switch.
2025-10-08 03:44:51 +00:00
Travis Geiselbrecht
6f89579856 [dev][pl011] track if the uart has been initialized
Dont deref a bad pointer if the uart is uninitialized. This helps if a
system tries to print too early in the boot process.
2025-10-05 15:47:00 -07:00
Travis Geiselbrecht
664bb17afa [ubsan] fix some bugs and warnings discovered by ubsan
- X86 cpuid feature list dump was using the wrong array and walking off
  the end of one.
- GICv2 code had a left shift by up to 31 of an integer. Needs to be
  unsigned.
- PLIC same as GIC code.
- fdtwalker code should be using a bytewise accessor based helper
  function for reading large integers out of an unaliged FDT.
- PCI BIOS32 search code could do a 32bit unaligned read of a string,
  switch to using memcmp.
2025-10-05 15:35:31 -07:00
Travis Geiselbrecht
23cbdcc971 [ubsan] switch external array declarations to a proper array
This fixes a ubsan warning where it thinks you are walking off the end
of a symbol. No functional change.
2025-10-05 15:27:43 -07:00
Travis Geiselbrecht
5a75003102 [ci][gcc] have gcc runs build with -Werror set
Be a bit more strict about what is accepted into mainline by building
with -Werror set for gcc builds.

Clang builds will get the same treatment soon.

Also turn off some ubsan compiles for some of the older arches where
there's very little value (and it probably doesn't work anyway).
2025-10-05 14:43:25 -07:00
Travis Geiselbrecht
ac6468c916 [ubsan] fix some warnings on 32bit arches
Mostly from the use of ssize_t which does not play well with printf and
32bit arches on LK for underlying type reasons that haven't really ever
been sorted out properly.
2025-10-05 14:43:13 -07:00
Travis Geiselbrecht
355b62b13a [pci] fix a warning that only shows up on gcc 7.5.0 2025-10-05 14:22:41 -07:00
Travis Geiselbrecht
c9d2f80e43 [dev][interrupt][gicv2] test that this is a GICv2
Add some boot time informational message and read the maximum number of
interrupts supported by this hardware.
2025-10-05 13:57:21 -07:00
Travis Geiselbrecht
34310ae0ca [make] remove line numbers from the non-debug .lst file
Turns out it's just a little too noisy for me for normal bringup. That's
what .debug.lst is for.
2025-10-05 13:57:13 -07:00
Travis Geiselbrecht
e0b5008641 [riscv][toolchain] fix clang test of -misa switch which is not present
The test inside riscv/rules.mk was assuming gcc and that the CC variable
isn't passed in from the user. This is not a very clean solution and
acts like a bandaid over the problem. Added some todos for a potential
solution.
2025-10-05 13:57:04 -07:00
Travis Geiselbrecht
48d331f144 [clang] fix a few warnings
Mostly dealing with comparing a pointer variable that is declared
nonnull, which I find to be a dubious warning but is pretty safe in this
case since the compiler will be more aggressive about the nullness of
the arguments.
2025-10-05 13:56:55 -07:00
Travis Geiselbrecht
64e1ccfe78 [scripts] add do-qemu-boot-tests.py
This will boot a list of qemu emulated devices with the option to run
all of the unittests at boot.

Will be automatically enabled on the build servers soon which will fail
any pending CLs if it breaks.
2025-10-02 00:01:41 -07:00
Travis Geiselbrecht
976cd70f4f [unittests] add RUN_UNITTESTS_AT_BOOT build option
This will cause the system to automatically run all of the unit tests
after a short pause on boot. Will be used by an automatic test script.

At the moment there aren't a lot of unit tests in the list, but this
should greatly increase the utility of them since they'll be
automatically run.
2025-10-01 23:54:54 -07:00
Travis Geiselbrecht
be07027fe1 [project][pc] add minip and all of the fses to all of the PC projects
Leave minip out of legacy PC right now since the registration scheme is
a bit broken and assumes e1000 is present.
2025-10-01 23:41:11 -07:00
Travis Geiselbrecht
5720b2a32f [fs][fat][tests] be a bit more forgiving if the test device isn't present
Have the unit tests for the FAT driver fail a bit more gracefully if the
test device is not present, to make it somewhat easier to live with this
driver present with systems a way to mount a test volume.
2025-10-01 23:35:48 -07:00
Travis Geiselbrecht
e3ffad684f [scripts] make sure all the do-qemu* scripts exec qemu as the last line
This helps a wrapper script test for proper exit.
2025-10-01 23:33:25 -07:00
Travis Geiselbrecht
ad6ef65a5a [arch][ops.h] force all of the fast routines to be inline
Also make sure each arch_ops.h always includes arch/ops.h at the top, to
make sure the declaration always appears in front of the definition.
2025-10-01 20:56:07 -07:00
Travis Geiselbrecht
04b88750b3 [debug] remove lib/debug and move to the top/ module
Most of the functions for this was declared in a top level lk/ include
space, so go ahead and move it there.

A few exceptions:
- Moved spin() over to platform/time.h and platform/time.c since the
function more logically belongs to platform/time.h.  Any users of
spin() will need to update their headers to include platform/time.h
instead.

- Renamed spin_cycles() to arm_cm_spin_cycles() and moved over into
arm/cm.h since it is currently defined in arch/arm-m and only used for
targets that implicitly are for arm-m.
2025-10-01 20:56:06 -07:00
Travis Geiselbrecht
163e296e70 [docs] tweak a few errors in the blocking primitives doc 2025-10-01 20:56:06 -07:00
Travis Geiselbrecht
022b050925 [vscode] add a few more recommended extensions to the list 2025-10-01 20:56:06 -07:00
Travis Geiselbrecht
e739abc490 [kernel] tweak a few thread apis to to take a const pointer
A bit of reformatting on some ARM code while was touching it.
2025-10-01 20:56:06 -07:00
Travis Geiselbrecht
f5999d5a40 Merge branch 'port_race_test' of github.com:redpig/lk
edit: add a few quickie warning fixes
2025-09-29 23:15:57 -07:00
Mahavir Jain
68c6ae154c [wait-queue] fix wake all to remove threads from tail
While waking up all threads from wait-queue, order should
start from tail to maintain correct scheduling sequence.

Signed-off-by: Mahavir Jain <mahavirpj@gmail.com>
2025-09-29 23:03:59 -07:00
luka177
014de968e1 [target-stm32f429i-disco]: Initial lcd support 2025-09-29 22:44:53 -07:00
Lei Wen
145e9a0d27 [arch] fix link script not include global array init
Using wild match init_array* to include global array init ctor

Before:

 10 .ctors             00000040 ffff0000001e6b80 00000000401e6b80 DATA
 11 .dtors             00000000 ffff0000001e6bc0 00000000401e6bc0 DATA
 12 .got               00000060 ffff0000001e6bc0 00000000401e6bc0 DATA
 13 .init_array.1      00000470 ffff0000001e6c20 00000000401e6c20
 14 .fini_array.1      00000470 ffff0000001e7090 00000000401e7090
 15 .dummy_post_data   00000000 ffff0000001e7500 00000000401e7500 DATA
 16 .bss               00009460 ffff0000001e8000 00000000401e8000 BSS

After:

 10 .ctors             000004b0 ffff0000001e6b80 00000000401e6b80 DATA
 11 .dtors             00000470 ffff0000001e7030 00000000401e7030
 12 .got               00000060 ffff0000001e74a0 00000000401e74a0 DATA
 13 .dummy_post_data   00000000 ffff0000001e7500 00000000401e7500 DATA
 14 .bss               00009460 ffff0000001e8000 00000000401e8000 BSS

Signed-off-by: Lei Wen <leiwen@asrmicro.com>
2025-09-29 22:40:41 -07:00
Travis Geiselbrecht
63e4bdcd92 [build] add line numbers to the disassembly .lst files 2025-09-29 22:28:00 -07:00
Travis Geiselbrecht
1f54072295 [platform][pc] when building with SMP, don't even attempt to bring up the local apic
Not exactly what we want but avoids the lapic code needing the per cpu
structures which aren't set up without SMP support.

Consider leaving the percpu structure in, just only support for cpu 0.

This fixes trying to boot the X86_LEGACY build on a machine with a local
apic.
2025-09-29 22:20:30 -07:00
Travis Geiselbrecht
936ee8ac81 [arch][x86] start of an ioapic driver
Doesn't do much but provided the detection path for it and ability to
hold initialized state. The higher level platform code is going to need
to use it directly so will mostly just provide an api for access to it.

Moved ACPI sniffing back to just after the VM is initialized instead of
all the way into platform_init(). This should try to ensure that all
drivers that come up afterwards will have ioapics discovered in case
future development tries to enable and use them, kicking the machine out
of virtual-wire-mode.
2025-09-24 01:18:52 -07:00
Travis Geiselbrecht
72112c0676 [pci] little bit of code cleanup in the pci bus driver
Mostly just suggestions by clang-tidy. No functional change.
2025-09-23 23:16:55 -07:00
Travis Geiselbrecht
5a17519e54 [arch][riscv] fix rounding issue with PAGE_SIZE on riscv64
Inadvertently added this bug where PAGE_SIZE type is 32bit which causes
truncating when using it to round a kernel address.
2025-09-23 23:05:15 -07:00
Travis Geiselbrecht
b7d69d8804 [arch][x86] handle the local apic of the boot cpu not being 0
I have a bulldozer machine here that curiously starts the APIC IDs for
the cpus at 16 and counts up.

This is a problem since the current code assumes that the boot cpu is 0,
and would try to start itself (apic id 16) later because it thought it
was the first secondary. Fix this by re-reading the APIC id on the boot
cpu and patching the percpu structure a bit into boot. Kinda a hack but
avoids having to detect the APIC, find the type of ID to read, etc.

Also means that practically speaking the system is using the full 32bit
APIC IDs if that feature is present, since now the local apic id is
entirely read from the local apic as it should be (if present).

Fixes #475
2025-09-22 20:57:30 -07:00
Travis Geiselbrecht
bdf2203fdc [arch][x86][lapic] a little bit of restructuring of some recent lapic code
Functionally equivalent, but refactor two copies of local apic
initialization code into a shared routine.
2025-09-21 21:53:35 -07:00
little fairy
d0eb5c464e [arch][x86] Read full 32bit apic id from x2apic msr if available (#465) 2025-09-21 21:04:00 -07:00
Kelvin Zhang
a1be045514 [lib][uefi] Migrate to boot memory protocol
Image loading protocol is deprecated, migrate
2025-09-18 22:13:33 -07:00
Kelvin Zhang
848fbfefe7 [lib][uefi] Mark bio functions as WEAK
OEMs may want to override certain bio functions, hence mark
`open_block_device` and `open_async_block_device`  as WEAK. This allows
OEMs to customize any of the bio functions
2025-09-18 22:13:33 -07:00
Kelvin Zhang
72c92b5d81 [lib][uefi] Update protocol headers from upstream
Copied from https://cs.android.com/android/kernel/superproject/+/common-android-mainline:bootable/libbootloader/gbl/libefi_types/defs/protocols/
2025-09-17 10:27:49 -07:00
Travis Geiselbrecht
5c1bc61e11 [scripts][do-qemuarm] general cleanup of script style and fix potential bugs
Mostly suggestions from shellcheck
2025-09-16 13:36:20 -07:00
Travis Geiselbrecht
457355fa3c [scripts][do-qemuarm] accept 4k/16k/64k as page size aliases 2025-09-16 13:15:15 -07:00
Yi-Yo Chiang
fb9c37cbd6 [lib][uefi] Implement EFI_ERASE_BLOCK protocol 2025-09-05 13:49:28 -07:00
Yi-Yo Chiang
91a76a9a03 [lib][uefi] Fix -Wc++20-compat compiler warning 2025-09-04 23:27:02 -07:00
Yi-Yo Chiang
b1e26e90cd [lib][uefi] Update UEFI protocol definitions
GBL HEAD: 878653395d
2025-09-04 09:59:22 -07:00
Travis Geiselbrecht
2377c3d440 [make] fix three misuses of TOBOOL
Forgot to expand the variable in the call to the TOBOOL function which
would cause the result to always be true. In this case always resulted
in the test code for these three modules to be included.
2025-09-03 15:14:18 -07:00
Travis Geiselbrecht
9325c18b27 [docs] update the getting started doc to be a bit more clear
Issue: 437
2025-08-31 22:20:05 -07:00
Travis Geiselbrecht
c48cfcb5d0 [arch][arm64] add support for 64k pages
Already worked, just needed to set up the address space size and create
a new project.
2025-08-31 21:48:09 -07:00
Travis Geiselbrecht
fff0f2a740 [arch][arm64] add support for 16k pages 2025-08-31 21:47:32 -07:00
Travis Geiselbrecht
cc9c3a053c [arch][mmu] clean up page size definitions in each arch's defines.h
No real functional change except how the smaller ARCH_DEFAULT_PAGE_SIZE
is now computed and set in defines.h instead of rules.mk for arch/arm to
be consistent with the other arch that has a large/small build (riscv).
2025-08-31 19:16:58 -07:00
Travis Geiselbrecht
0a8a4354a9 [clang-format] first stab at a .clang-format file that matches the existing style
Not enabled by default, but if you want to use this one for now while
things are stabilized feel free. Going to move off astyle since this
seems to be superior now (wasn't always).

Also switched scripts/codestyle to use clang-format
2025-08-31 13:13:21 -07:00
Travis Geiselbrecht
c3a754cf03 [github][ci] bump gcc to 15.2.0 2025-08-31 12:44:36 -07:00