2841 Commits

Author SHA1 Message Date
vivek.j
322ff67050 [lib][miniheap] fix: modify the assert condition in miniheap
For LK_DEBUGLEVEL > 1
> alloc_struct_begin_size: 24
> free_heap_chunk_size: 24

size: max(alloc_struct_begin_size, free_heap_chunk_size)

But when freeing the chunk, allocated size is expected to be
greater than size of free_heap_chunk struct.
It contradicts its own code.
So add >= instead of > to maintain the integrity between
allocation and freeing of memory chunk.

Signed-off-by: vivek.j <vivek.j@samsung.com>
2025-04-05 00:25:54 -07:00
Travis Geiselbrecht
8fdadd9b33 [arch][x86] implement basic spinlocks
-This fixes the instability, seems stable on x86-64.
2025-04-01 20:10:18 -07:00
Travis Geiselbrecht
5a520eca3e [arch][x86] start getting inter-processor-interrupts working
-Move the local apic driver to arch/x86
-Add routines to send IPIs between cpus

Something is unstable at the moment and the system crashes after a while
with random corruptions when using SMP.
2025-04-01 00:40:50 -07:00
Travis Geiselbrecht
21ce533327 [platform][pc] make sure lapic is initialized per cpu
Actually boots secondaries to the point where it actually panics because
of missing IPI support.
2025-03-31 01:05:13 -07:00
Travis Geiselbrecht
d05bed3a25 [platform][pc] add local apic timer support
Supports deadline TSC and regular timer support.
Calibrated from the PIT if regular timer support is used.
2025-03-31 00:01:45 -07:00
Travis Geiselbrecht
2987f73d08 [platform][pc] add support for TSC based clock
-Detect if under KVM hypervisor and read tick rate or
-calibrate tick against PIT
2025-03-30 21:59:39 -07:00
Travis Geiselbrecht
09412c194f [platform][pc] refactor existing PIT code into separate file
Extend the PIT driver to allow for one shot timers even though it
monotonically runs a 1kHz tick. This allows it to keep time and provide
one shot events, though only at 1ms resolution.
2025-03-30 14:54:01 -07:00
Arve Hjønnevåg
4ff60704a5 kernel: mutex: Don't allow mutex_acquire with interrupts disabled
Calling mutex_acquire with interrupts disabled is usually unsafe. Add a
debug assert to catch this. Only check this after threading is enabled
on the primary CPU though, as the thread that runs the initial init
hooks run with interrupts disabled and in this case no other thread can
own the mutex anyway. Also allow 0 timeout since
vmm_get_address_description uses this to allow exception handlers to
dump additional information when the vmm_lock is available.

Bug: 304850822
Change-Id: I22c91c48b7853c0b8e0eb8da61cdfc9cd1650ae8
2025-03-29 16:18:55 -07:00
Dmitrii Merkurev
5fa9649ad9 [lib][uefi] initialize uefi system table with zeroes 2025-03-17 17:50:31 -07:00
SP-Melokc
a74f9ebbd8 Update thread.c
Changed kmain to lk_main
2025-02-25 01:08:59 -08:00
Kelvin Zhang
3fb0e31374 [app][uefi] Split memory and block io code into separate files 2025-02-25 01:05:22 -08:00
Kelvin Zhang
c7576472f2 [app][uefi] refactor relocation logic to a separate file 2025-02-25 01:05:22 -08:00
Travis Geiselbrecht
3543217461 [lib][uefi] fix a few warnings and a little code tidying
GCC 14 is quite picky about warnings, probably more so than clang.

-Fix a bunch of printf warnings. Pointers should be printed with %p.
-Move some stuff into an anonymous namespace.
-Worked around GCC really not liking reinterpret_casting from one
function pointer type to another. Fiddled with it a bit and eventually
settled on casting the function pointer to const void * and passing it
through.
2025-01-20 01:46:21 -08:00
Travis Geiselbrecht
7fff3510a3 [scripts][buildall] hard set WERROR=0 if -e not passed
This allows it to override the WERROR setting if, say, someone put
WERROR?=1 in their local.mk. (It's a good idea)

Note: I can't really leave WERROR enabled in the default build because
of all of the variants of compilers folks use in the wild, but I do
highly suggest folks use it locally.
2025-01-11 17:24:51 -08:00
Travis Geiselbrecht
6747010a5c [arch][arm64] restructure some start.S to allow KERNEL_VM and WITH_SMP
Currently only supports both set at the same time, but rearrange their
order such that theoretically both are pretty independent.

Somewhat untested in that there's no configuration for !KERNEL_VM and
WITH_SMP, but at least allows that config to be tested.
2025-01-11 17:12:16 -08:00
Travis Geiselbrecht
538f32e09d [arch][arm64] make sure SPSel is set to SP_ELx at boot
Just a safety check, has not been a problem in general, but pulled from
a similar trusty change.
2025-01-11 17:11:27 -08:00
Travis Geiselbrecht
0ac7a2d7cb [kernel][mp] use proper types when computing idle and active cpus
Also return a proper bool instead of an int. No functional change.
2025-01-11 16:59:42 -08:00
Travis Geiselbrecht
6d9a0b5c35 [libc][printf] Handle case where snprintf underflows for len = 0
The code would write a null pointer always, even if len = 0, or if the
buffer pointer is null.

Test for this condition and add a unit test.

fixes #407
2025-01-09 23:32:56 -08:00
Alexander Richardson
e7b71623c4 Document how to use clang in README
Fixes: https://github.com/littlekernel/lk/issues/426
2025-01-09 19:52:18 -08:00
Travis Geiselbrecht
f9a5a16db5 Merge pull request #429 from zhangxp1998/gbl
Add block IO protocol to UEFI loader
2025-01-09 19:49:49 -08:00
Kelvin Zhang
5c066ae52c [app][uefi] Implement GLB fdt fixiup protocol 2025-01-08 09:54:00 -08:00
Kelvin Zhang
0c1cb6bf03 [app][uefi] Add block device protocol 2025-01-08 09:54:00 -08:00
Kelvin Zhang
1103fd5575 [app][uefi] Pass DTB to linux kernel 2025-01-08 09:53:59 -08:00
Alex Richardson
0fd355ea4b dlmalloc: fix -Wstrict-prototypes warning 2025-01-07 22:28:07 -08:00
Alex Richardson
d22534704d pci: remove write-only variable
This is not used anywhere so just drop it.
2025-01-07 22:28:07 -08:00
Alex Richardson
d673d211eb riscv: add missing stdint.h include
While this is currently pulled in transitively, uint32_t is defined there
and we should explicitly include the appropriate header.
2025-01-07 22:28:07 -08:00
Alex Richardson
22ae6b6cea riscv: ensure arguments to __ASM_STR() are expanded first
Right now this does not cause any issues, but I had a local change where
missing expansion resulted in compilation errors when reading CSRs.
2025-01-07 22:28:07 -08:00
Alex Richardson
829fdfa264 libcpp: fix deprecated builtin warning with clang 2025-01-07 22:28:07 -08:00
Alex Richardson
9241c78667 riscv: Add missing parens around macro argument
This triggered a out of range count overflow warning when
building for RV32 (calling the macro with `ticks >> 32`)
since the truncation happened before the shift.
2025-01-07 22:28:07 -08:00
Travis Geiselbrecht
164f9fa47e WIP working with lapic to trigger a timer 2025-01-03 20:54:30 -08:00
Noah Woo
bea3787d6e [kernel][port] add a missing THREAD_UNLOCK call in port_group_remove()
port_group_remove() used to return without unlocking a thread if no
matching read port is found, which is not correct. This patch adds a
call to THREAD_UNLOCK before it returns ERR_BAD_HANDLE.
2025-01-03 20:52:08 -08:00
Travis Geiselbrecht
d1a332891c [arch][x86] add x2apic mode to the local apic driver
Fill in some more x86 feature bits while at it.
2024-12-17 23:57:56 -08:00
Travis Geiselbrecht
6b89609887 WIP x86-64 SMP: get the 64bit secondaries fully started
Rearrange some of the cpu initialization code to be runnable on each cpu
as they come up. Complete the 64bit bootstrap mechanism and call into C
code.

Makes it as far as trying to reschedule via an IPI. Need to implement
local apic based IPI mechanism.
2024-12-13 00:21:16 -08:00
Travis Geiselbrecht
3ea007a237 [arch][x86] split the single GDT.S into two separate ones per subarch
It's getting too hard to maintain a single layout that works with both,
so go ahead and split it. Also redo the layout so it should be usable
with user space and syscall and sysenter instructions from either mode.
2024-12-12 22:23:50 -08:00
Travis Geiselbrecht
6538baea70 WIP x86-smp
add uspace mmu support for x86-64
trampoline x86-64 cpus to long mode and into the kernel aspace
2024-12-11 00:19:57 -08:00
Travis Geiselbrecht
1ca821ec54 WIP x86-smp squelch some warnings in no smp mode 2024-12-06 23:44:19 -08:00
Travis Geiselbrecht
1afb5d7a66 WIP x86 smp: start the framework for detecting and starting secondary cores 2024-12-06 23:40:26 -08:00
Travis Geiselbrecht
181796e843 WIP x86 get x86-32 working with a per-cpu gs: segment register for the kernel 2024-12-06 22:30:48 -08:00
Travis Geiselbrecht
902e2fcb8a WIP set up per cpu structures for x86-64
only on the boot cpu for now
2024-12-06 21:11:51 -08:00
Travis Geiselbrecht
fd79fccdde WIP x86 SMP 2024-12-06 00:03:48 -08:00
Travis Geiselbrecht
6f32a0f377 [arch][riscv] use newly discovered pseudo-instructions for load/stores
I hadn't noticed this before, but you can directly reference a global
variable in a load/store in assembly, which combines a lla + ld/sd into
a 2 instruction pair instead of 3 due to the 12 bit offset provided in
the load/store.
2024-11-27 21:53:29 -08:00
Travis Geiselbrecht
77eb84d152 [arch][x86] a few little tweaks while looking at some older code 2024-11-27 21:34:05 -08:00
Travis Geiselbrecht
adde2d64ba [clang-tidy] turn off the no-recursion complaint
I get the sentiment but I think it's just a bridge too far.
2024-11-27 21:33:31 -08:00
Travis Geiselbrecht
2ca679aeca [arch][riscv][asm] use the call pseudoinstruction instead of jal
This fixes a problem if the text segment gets larger than ~1MB where the
raw jal instruction cannot reach. Using 'call' or 'tail' allows the
assembler to emit a 2 instruction sequence that the linker later
relaxes if it can.
2024-11-14 19:33:46 -08:00
Travis Geiselbrecht
52fa818e21 [arch][arm64] remove an unnecessary call to arm64_el3_to_el1
The existing arm64_elx_to_el1 already handles dropping the primary and
any secondary cpu down to el1 by the time this code path is reached.
2024-11-10 03:39:34 +00:00
Travis Geiselbrecht
6e39e5674c [arch][arm64] Make sure mpidr_el1 and mipr_el1 is configured
When dropping from EL2 (or EL3), load vmpidr_el2 and vpidr_el2 with the
correct values to make sure EL1 sees the 'real' mpidr_el1 and midr_el1.

Though in most cases they're already configured by whatever firmware ran
before, there's no actual guarantee that it is, and it may be full of
random garbage.
2024-11-10 03:31:23 +00:00
Travis Geiselbrecht
98a5703451 [github][ci][clang] add clang 16, 17, 18 to the list 2024-11-07 08:44:27 +00:00
Travis Geiselbrecht
d1579678ab [github][ci] use apt-get to fetch clang to remove a warning 2024-11-07 08:44:27 +00:00
Travis Geiselbrecht
4102844048 [arm64][fpu] add fp arch extension around inline fpu asm
This quiets warnings on clang 18 about the missing fp arch extension
feature when using fp instructions.
2024-11-07 08:44:27 +00:00
Travis Geiselbrecht
afa56793d8 Merge pull request #423 from zhangxp1998/dev
Implement bulk of UEFI protocol needed by linux kernel
2024-11-07 00:10:35 -08:00