Commit Graph

672 Commits

Author SHA1 Message Date
Kelvin Zhang
b8a584b69a [lib][uefi] Move certain UEFI headers to public include dir
This allows other components to reference basic UEFI types. Now
different platforms can provide their own override for certain UEFI
protocols.

To keep good include structure, all public headers are put under
include/uefi.
2025-06-03 22:17:22 -07:00
Kelvin Zhang
b10701feaa [lib][uefi] Make load_pe_file extern linkage
This function was previously put in anon namespace, making it
unavailable for other source files to consume. Since we made this
function an API for consumption, move outside anon namespace so
that linkers can find it.
2025-05-28 16:04:10 -07:00
Michael Bishop
d66ad44db3 bio: use shifts to divide 2025-05-06 23:40:25 -07:00
Kelvin Zhang
55e2d6f2aa [lib][uefi] Move platform dependent functions to a separate file 2025-04-29 14:17:10 -07:00
Kelvin Zhang
9b5a187952 Put functions in anon namespace if possible 2025-04-28 17:53:55 -07:00
Kelvin Zhang
5ee4e35921 [lib][uefi] Allow load_pe_file to be called from other apps/libs 2025-04-28 17:48:52 -07:00
Kelvin Zhang
fbc354e7e3 [lib][uefi] Implement ResetSystem protocol 2025-04-28 17:48:52 -07:00
Kelvin Zhang
27696ee6c2 [lib][uefi] Make exit_boot_service weak link
This allows different platforms to provide their own implementation
of exit_boot_service
2025-04-28 17:48:52 -07:00
Travis Geiselbrecht
9d66069183 Merge from x86-smp: implement SMP for both 32 and 64bit x86
A large pile of changes to the PC platform and x86 architecture that
facilitate SMP support. Tested in both 64 and 32bit on qemu and real
hardware all the way back through i486.
2025-04-10 22:17:02 -07:00
Heiko Behrens
dd8210d957 atol handles overflow and accepts leading whitespace and '+' 2025-04-10 21:41:06 -07:00
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
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
Dmitrii Merkurev
5fa9649ad9 [lib][uefi] initialize uefi system table with zeroes 2025-03-17 17:50:31 -07: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
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
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
829fdfa264 libcpp: fix deprecated builtin warning with clang 2025-01-07 22:28:07 -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
1afb5d7a66 WIP x86 smp: start the framework for detecting and starting secondary cores 2024-12-06 23:40:26 -08:00
Kelvin Zhang
649d432b8a Move UEFI header files into private include namespace
This help reduce the risk of name collision. As MODULE_DIR/include is
automatically added to global includes.
2024-11-06 10:12:17 -08:00
Kelvin Zhang
0d8a1ec055 [app][uefi] Make allocate_pool return identity mapped memory 2024-11-06 10:12:17 -08:00
Kelvin Zhang
1249e8a03b [app][uefi] Add configuration table 2024-11-06 10:12:17 -08:00
Kelvin Zhang
7d77e28430 [app][uefi] Enable mspace feature on dlmalloc
This allows us to use an identitiy mapped piece of memory as the heap
for UEFI app. UEFI app's allocation would go from this heap.
2024-11-06 10:12:17 -08:00
Kelvin Zhang
763ff7ce70 [app][uefi] Call kernel at an identity mapped stack 2024-11-06 10:12:17 -08:00
Kelvin Zhang
347db09959 [app][uefi] Place linux kernel at identity mapped virtual memory addresses 2024-11-06 10:12:17 -08:00
Kelvin Zhang
253e3099ec [app][uefi] Add relocation support for UEFI binary 2024-11-06 10:12:17 -08:00
Kelvin Zhang
6a37823f71 [app][uefi] Add runtime service support 2024-11-06 10:12:17 -08:00
Kelvin Zhang
9fc4532ad7 [app][uefi] Imlement get_memory_map UEFI protocol 2024-11-06 10:12:16 -08:00
Kelvin Zhang
5ea19f1b0a [app][uefi] Setup skeleton for UEFI boot service 2024-11-06 10:12:16 -08:00
Kelvin Zhang
6b903f480c [git] Ignore common linux build files, update README 2024-11-06 10:12:15 -08:00
Travis Geiselbrecht
baaa474628 [console][help] dont print command blocks if no commands are available
When in crash mode, a lot of the commands are unavailable, so delay
printing the command block header until the first unmasked command is
printed.
2024-08-09 19:50:27 -07:00
Joshua Seaton
f10d685722 [console] List commands alphabetically by name in normal mode
This change updates the `help` console command to list the available
commands alphabetically, but only when we're not panicking. This makes
`help`'s helping more helpful.
2024-08-09 19:41:54 -07:00
Travis Geiselbrecht
bd423cad4d [lib][fdtwalk] skip scanning pci busses marked 'disabled' 2024-06-19 16:18:28 -07:00
Travis Geiselbrecht
e3a5f9c363 [lib][fdtwalk] fix some unfound bugs in the riscv isa string detection 2024-06-17 00:45:20 -07:00
Travis Geiselbrecht
907d2d5579 [app][uefi] fix warning in uefi code 2024-06-16 22:37:10 -07:00
Kelvin Zhang
07b80bf495 Add section loading and entry point execution to UEFI loader
This loads all sections specified by PE header at the correct memory
location, and executes the entry point function. Only the
OutputString function of text output protocol is implemented,
so the only application we can run is hello world.

Test: th
Bug: 294283461
Change-Id: I786bc8b7db9e1c0a6019b8fe4ba5a8c8ab4f2936
2024-06-14 15:26:15 -07:00
Kelvin Zhang
2e3c153a05 Add UEFI protocol headers
These headers define the API boundary between UEFI loader and
UEFI applications.

Test: th
Bug: 294283461
Change-Id: Idf064563bb033a8bf2b994261bcd77c0ed7aa2d8
2024-06-14 15:26:15 -07:00
Kelvin Zhang
c750ed0fa3 Add basic UEFI loader to lk
Thids adds a uefi_load <block dev name> command, which will
parse the PE header and do some basic validation checks.

Bug: 294283461
Test: uefi_load virtio0
Change-Id: I97393652526bda5be1b995e59647e239c64d31d6
2024-06-14 15:26:15 -07:00
Travis Geiselbrecht
566b25d1ec [arch][riscv] read the riscv feature string out of device tree
Also added initial implementation of a way to query run time features of
the cpu.
2024-06-01 17:21:01 -07:00
Travis Geiselbrecht
ec4da9673b [platform][qemu-riscv32] trim usable memory to 1GB on qemu-riscv32 2024-05-16 20:52:45 -07:00
Travis Geiselbrecht
ed3876dae7 [lib][cmpctmalloc] mark cmpctmalloc as needing float
It's just a test routine that's using floating point, but since nothing
in cmpctmalloc should be used in interrupt context, it should be okay to
mark this code as using float.
2024-05-14 00:47:43 -07:00
Travis Geiselbrecht
2f98fbf772 [pci][fdt] do not attempt to configure PCI with 64bit bars on a 32bit system
Especially in the case where the 32bit system doesn't have an MMU, avoid
using any high addresses for BARs.
2024-05-09 22:18:19 -07:00
Travis Geiselbrecht
6a3db09e55 [compiler] GCC 14.1 supports __has_feature
Enable it if not present, not just if its clang.
2024-05-09 18:54:38 -07:00
Travis Geiselbrecht
ac5cd774a6 [lib][fs][9p] fail mount gracefully if bdev isn't passed 2024-04-25 00:25:30 -07:00
Cody Wong
7ed757b144 [fs][v9fs] Add file operations for v9fs
- Add the file operations APIs for VirtIO 9p devices, such as file
   create/open/close/read/write/stat.
 - After this commit, almost complete file operations for v9p file
   sharing are supported. An intuitive example is that users can use
   filesystem commands, such as `ls`, to examine the shared folder.

   Example:

   ```
   # Build the littlekernel with the current directory (the codebase) as
   the shared v9p folder
   $ scripts/do-qemuarm -f .
   ...
   welcome to lk/MP

   boot args 0x0 0x0 0x0 0x0
   INIT: cpu 0, calling hook 0x8011fa81 (version) at level 0x3ffff,
   flags 0x1
   ...
   # Mount the default VirtIO 9p device `v9p0` as the 9p filesystem onto
   # `/v9p` path
   ] fs mount /v9p 9p v9p0
   # List the `/v9p` folder, and we can see the littlekernel codebase
   ] ls /v9p
   D 4096             arch
   F 590              lk_inc.mk.example
   D 4096             .cache
   D 4096             project
   D 4096             .github
   D 4096             platform
   D 4096             kernel
   D 4096             external
   F 1132             LICENSE
   D 4096             target
   D 4096             dev
   D 4096             .git
   F 120              .gitignore
   F 12579            engine.mk
   F 1388             README.md
   D 4096             make
   D 4096             top
   error -2 opening file '/v9p/..'
   D 4096             build-qemu-virt-arm32-test
   F 763965           compile_commands.json
   D 4096             scripts
   D 4096             lib
   D 4096             app
   D 4096             docs
   D 4096             .
   D 4096             tools
   F 1113             makefile
   ```

Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-25 00:17:02 -07:00