Commit Graph

587 Commits

Author SHA1 Message Date
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
Cody Wong
05b39a87cf [fs][v9fs] Add directory operations for v9fs
- Add the directory operations, e.g., open directory, make directory,
   read directory, and close directory.

Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-25 00:17:02 -07:00
Cody Wong
b29df9194b [fs][v9fs] Add VirtIO 9p filesystem structure
Add the fundamental filesystem structure to attach a VirtualIO 9p
device. With the implementation of VirtIO 9p devices (lk/dev/virtio/9p),
we can use those APIs to connect to a shared folder as a LK filesystem.

Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-25 00:17:02 -07:00
Cody Wong
947cf27830 [fs][shell] Correct the path name for better understanding
Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-25 00:17:02 -07:00
Travis Geiselbrecht
4401560dd9 [libc][printf] pull in fix from fuchsia that handles 0x prefixes properly
With this change printf passes the fuchsia unit tests, except the lack
of field with and precision support. Disabled those parts of the test
for now.

Original change at
https://fuchsia.googlesource.com/fuchsia/+/db61af0d1fc27c4c807f5da7d0553a4bb422882b

The old code used to pad the output with zeros before the 0x,
so you would end up with a 0000000x10. This is not the intended
behavior.

Original author: pedro.falcato@gmail.com
2024-04-24 00:43:42 -07:00
Travis Geiselbrecht
45155fdbf9 [libc][tests] pull over printf unit tests from fuchsia
The fuchsia printf unit tests are a derivative of the current LK ones in
app/tests, but have been somewhat expanded. Pull in the new copy and add
it to the new libc test module.
2024-04-24 00:01:50 -07:00
Travis Geiselbrecht
253bb8225c [libc] have fputs return the number of bytes written
Not strictly according to spec but it matches the way the unit test was
written.
2024-04-23 23:50:25 -07:00
Travis Geiselbrecht
9e9e7d3fe4 [lib][fs] move the existing test code into its own sub module lib/fs/test
No real functional change, just following the pattern of moving unittest
code into a sub module that is picked up by the build system when
WITH_TESTS is set.
2024-04-23 23:49:19 -07:00
Travis Geiselbrecht
9a4fae0714 [warnings] remove some extraneous __PACKED attributes
Also remove a few extra data structures that were marked packed but not
otherwise used anywhere.
2024-04-19 00:07:49 -07:00
Travis Geiselbrecht
6ed6f36fa0 [warnings] remove some redundant declarations
Discovered with -Wredundant-decls
2024-04-19 00:07:49 -07:00
Travis Geiselbrecht
f92aae9dcf [lib][libc] rework a bit of the stdio code to handle errors more closely to spec
Some of the recent refactoring may cause some of the inner error codes
to be eaten or misinterpreted. Restructure fread/fwrite to handle these
a bit more gracefully.

There's some careful use with ssize_t vs size_t here to try to deal with
negatves values properly.
2024-04-18 23:29:17 -07:00
Chieh-Min Wang
b651168fa1 [lib][stdio] wrap file io APIs with stdio APIs
Implement stdio file io APIs with LK lib/fs APIs

Signed-off-by: Chieh-Min Wang <cmwang@google.com>
2024-04-17 23:59:49 -07:00
Travis Geiselbrecht
4a97f932fd [lib][fdtwalk] restructure the fdtwalker helper routines
Instead of one large routine that takes a list of optional callbacks,
build some helper routines that do the work that a few platforms have
implemented on their own to share some code between them.

Future enhancements: move some of the helpers out of this library into
the library that implements the thing it's helping with (ie, PCI
bringup, bootstrapping arch specific cores). For now just leave them in
helper.cc which is conditionally compiled.
2024-04-16 23:11:59 -07:00
Travis Geiselbrecht
05540c992a [lib][fdtwalk] trivially convert to C++ 2024-04-16 23:01:31 -07:00
Mingjie Shen
ed2a3a754d [lib][heap] Fix array index out-of-range
argv[] should have at least 3 elements because argv[2] is accessed in line 345.
2024-03-01 15:22:36 -08:00
Travis Geiselbrecht
8176ae67c8 [libc][cdefs] add a few additional features in cdefs
This seems to only be needed for older gccs (found with 7.5.0).
2024-02-27 00:46:56 -08:00
Travis Geiselbrecht
25ff64d4fd [libc] move sys/cdefs.h out of libm and into the main include path
More code is using it, so try to build a more standardized version of
it. For now, since most of the defines that are needed are similar to
lk/compiler.h, mostly reimplement in terms of those.
2024-02-27 00:12:15 -08:00
Travis Geiselbrecht
74192acef5 [debugcommands][crash] add a variant for cortex-m
Touching around address 0 doesn't cause a cortex-m device to crash, but
branching to an aligned address absolutely will.
2024-02-26 00:58:04 -08:00
Travis Geiselbrecht
23cff5b493 [lib][debug] remove unused function 2024-02-11 00:39:53 -08:00
Travis Geiselbrecht
d9b7d070c9 [top] add header declaration for lk_boot_args
Update users of the boot args array to use the header.
2024-02-11 00:38:09 -08:00
Matt Schulte
6b16ef0da2 [console] Fix complition error when CONSOLE_OUTPUT_TO_PLATFORM_PUTC=0
Need to move `size_t i` into the correct location. Also, set the
CONSOLE_OUTPUT_TO_PLATFORM_PUTC define in the module makefile.

Change-Id: I732ebbcc43219806d5dfd3b9bdd28bf1811248dc
2023-12-16 15:52:24 -08:00
gvk51
6a33334c1e [lib][debugcommands] option to input physical address for debug commands
dw/mw and the sister commands take virtual address as input for display
or modify. Option "-p" to the command signifies the address input is
physical, and the address translation is handled by the command.

Newly added option is available with WITH_KERNEL_VM, usage as follows

] dw 0xffffffff05100000 4
0xffffffff05100000: 0000dead
] dw 0x5100000 4 -p
0xffffffff05100000: 0000dead

Signed-off-by: VAMSHI GAJJELA <vamshigajjela@google.com>
2023-12-04 01:07:26 -08:00
Matt Schulte
1ce428d305 [console] Flag to disable default console output
Introduces a flag which allows a project to disable the default output
to platform_dputc. This is useful is the project wants to maintain
`platform_dputc` for panic conditions but otherwise use a registered
callback for console io.

Change-Id: I1362529a6bb40d191ac3f7c6069985c371d9284c
2023-12-04 00:57:16 -08:00
Cody Wong
94a15119b2 [libc][string] fix strncpy potential buffer overflow
The wrong placement of the increment for index `i` causes an unexpected
behavior, which the `strncpy` writes an extra '\0'.

For example:
The `src` string is "abc". The buffer size of `dest` is 5.

When we call `strncpy(dest, src, 5)`, the first `for` loop copies the
characters, 'a', 'b', and 'c', to the `dest[0:2]`. In the 4th iteration,
however, the `for` loop breaks due to the termination of `src` whereas
the value of `i` stays 3. At the moment, it has copied 4 bytes,
including the '\0' of `src`.

In the second `for` loop, we have `i = 3` and `count = 5`, so the loop
copies two more '\0' to the `dest`. As a result, the `strncpy` copies 6
bytes to the `dest` buffer, leading to buffer overflow.

Fix the issue by increasing the index `i` before every copy.

Signed-off-by: Cody Wong <codycswong@google.com>
2023-11-04 13:16:24 -07:00
Travis Geiselbrecht
6b7d0ab627 [lib][fdtwalk] add code to skip a cpu if disabled
Some RISC-V cpus come up disabled, skip enumerating them.
2023-10-15 14:41:30 -07:00
Alex Richardson
e40ac2a883 [clang] Avoid a nested function in heap_wrapper.c
This GCC extension is not supported by clang and in this case is not
necessary. Move the function to the top level to avoid the syntax error.
2023-06-01 17:50:50 -07:00
Aaron Odell
8fc673fe4a [lib][debugcommands] Add panic command
Add a simple command to generate a test panic.
2023-04-23 17:34:57 -07:00
Aaron Odell
9ba1f165cd [libc][string] Add strcasecmp support
Add strcasecmp() for case insensitive string compares. There is no ISO
standard function for this purpose but strcasecmp() is POSIX standard.
2023-04-23 17:34:54 -07:00
Aaron Odell
9ac5708eb5 [lib][debugcommands] Add commands to display current time
Add debug commands "time" and "timeh" to display current_time() and
current_time_hires() respectively.
2023-04-23 17:34:51 -07:00
Aaron Odell
af844a2ff6 [lib][console] Add an unsigned long long to console_cmd_args
Add and populate an unsigned long long element in the console_cmd_args
struct. This enables handling of 64 bit values on 32 bit targets.
2023-04-23 17:34:49 -07:00
Alex Richardson
7c7612225a [libc] Fix -Wincompatible-library-redeclaration for strerror
Return a char * instead of a const char * to silence this Clang warning.
2023-04-23 17:23:31 -07:00
Pedro Falcato
ca633e2cb2 [ubsan] Improve printing of value in shift_out_of_bounds
Print it according to the type information we're given.
2023-02-18 23:13:23 -08:00
Pedro Falcato
36fd884faa [ubsan] Fix minor copy-paste bugs
Two handlers accidentally had the wrong prototype, called the wrong
thing and/or had the wrong name.

Should only affect divrem_overflow_abort, negate_overflow_abort.
2023-02-18 23:13:23 -08:00
Pedro Falcato
8ebbcea5ed [ubsan] Add UBSAN implementation
Add an UBSAN implementation and a new UBSAN switch to the make build.
The implementation is taken from Onyx and handles most of the cases
that should be needed for a kernel build. Floating point and fancy
C++ CFI features are not supported yet.

To build with UBSAN, pass UBSAN=1 to make such as:
PROJECT=pc-x86-64-test make -jN UBSAN=1
2023-02-18 16:47:16 -08:00
Pedro Falcato
bf2e94c2f8 [minip] Fix undefined behavior in mac_addr_copy
There was a possibly unaligned store in mac_addr_copy.
Replace it with a memcpy call that should generate equivalent,
well defined code.
2023-02-18 16:47:16 -08:00
Travis Geiselbrecht
91d0a5f7d1 [lib][fdtwalk] add routine to find and parse /reserved-memory node
Add logic to the riscv virt platform to properly mark off memory
claimed by OpenSBI.
2022-12-17 17:12:35 -08:00