Commit Graph

2738 Commits

Author SHA1 Message Date
Travis Geiselbrecht
41ae8ad4ee [github][ci] Reduce the number of GCC runs on older compiler
-Don't try to compile any riscv targets on gcc 7.5.0 which is a bit too
old to deal with any of the newer ISA extensions.
-Stop building UBSAN on 7.5.0 builds since that's not particularly
useful.
2024-04-07 23:55:07 -07:00
Travis Geiselbrecht
37c3228443 [clang][riscv] add -menable-experimental-extensions
When building with clang-13 the zba riscv extension triggers a build
failure unless this switch is set. Set it for now, though it appears to
not be necessary for clang 14 and above.

TODO: add a version check for clang for a series of switches set based
on version in engine.mk.
2024-04-07 23:34:37 -07:00
Travis Geiselbrecht
03eb343e52 [arch][riscv] add a way for platforms to set optional riscv ISA extensions
A pretty simple mechanism, a list of extensions added to
RISCV_EXTENSION_LIST make variable is expanded to an underscore
delimited string appended to the end of -march=

Pretty simple but it should work for now.
2024-04-07 23:10:31 -07:00
Travis Geiselbrecht
00b06a8302 [arch][riscv] change secondary cpu bootstrap api
Instead of setting a counter of the number of secondaries to start, have
platform or target code pass in a list of harts to start instead. This
allows for there to be discontinuties in the layout of the cpu harts, or
in the case of some sifive based hardware, hart 0 is otherwise offline.
2024-04-07 22:32:49 -07:00
Travis Geiselbrecht
a070819c46 [clang] fix another warning that clang doesn't like 2024-04-01 23:48:50 -07:00
Travis Geiselbrecht
14f430d5e8 [arch][x86][clang] fix clang error introduced with exception cleanup
Remove extra declaration of assembly label which clang does not like.
2024-04-01 23:19:35 -07:00
Cody Wong
64b462cb37 [arm][v9p] Add v9p host dir sharing support for arm platform
- Add the v9p support for arm platform.
 - Add an option `-f` to set the shared directory on the host machine to
   `do-qemuarm`.
 - For example, to use the v9p dir sharing, run the script as:
    ```
    # under `lk/` run the follow command will share the current
    # directory `lk/` within LK vm as VirtIO 9p device
    scripts/do-qemuarm -f .
    ```

Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-01 23:09:30 -07:00
Cody Wong
db81f606da [tests][v9p] Add an example test for VirtIO 9p device
Add a simple test to validate basic functionalities of the VirtIO 9p
device driver, `dev/virtio/9p`.

For now the test attaches to the first v9p device and try to read the
file `LICENSE` under the shared folder. Therefore, if you set the shared
folder to the git root of `lk`, it will read the `LICENSE` of the
littlekernel and dump it to the console after running `v9p_tests`.

For example:

```
starting internet servers
starting app shell
entering main console loop
] v9p_tests
0x80013c08: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 |/*. * Copyright
0x80013c18: 28 63 29 20 32 30 30 38 2d 32 30 31 35 20 54 72 |(c) 2008-2015 Tr
0x80013c28: 61 76 69 73 20 47 65 69 73 65 6c 62 72 65 63 68 |avis Geiselbrech
0x80013c38: 74 0a 20 2a 0a 20 2a 20 50 65 72 6d 69 73 73 69 |t. *. * Permissi
0x80013c48: 6f 6e 20 69 73 20 68 65 72 65 62 79 20 67 72 61 |on is hereby gra
...
```

Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-01 23:09:30 -07:00
Cody Wong
2b02c8a046 [virtio][v9p] Add the VirtIO 9p device driver
This commit adds the VirtIO 9p device driver based on the VirtIO driver
stack in LK, `dev/virtio`. The driver supports a subset of 9P2000.L
protocol (https://github.com/chaos/diod/blob/master/protocol.md), which
is able to perform basic file operations (fread, fwrite, dirread, etc.).
The primary interface for sending and receiving the 9p messages is
`virtio_9p_rpc`, which is handy and scalable.

The driver is limited to communicate to the host with only one
outstanding 9p message per device due to the simplified driver design.
Basically that is enough for embedded environments when there is no
massive file IO.

Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-01 23:09:30 -07:00
Travis Geiselbrecht
3288b15a39 [dev][virtio-net] sync feature bits with virtio v1.3
Add new feature bits for the net device
Since the new feature bits are >= 32, add support for reading higher
than 32bit feature words from the virtio mmio interface.
2024-03-20 00:26:58 -07:00
Travis Geiselbrecht
c3cf81a8d8 [dev][virtio-block] update defs to virtio v1.3
No real functional change, just update the list of features to v1.3 of
the spec.
2024-03-19 23:40:57 -07:00
Travis Geiselbrecht
ab0e1fd3a1 [arch][x86][exceptions] clean up the exception handlers
For both 32 and 64bit x86, have each of the exception stubs which push a
few words and branch to the common isr routine be simply 16 byte aligned
to make it easy to calculate the offset from the main isr table. This
cleans up some complexity that was actually broken for interrupts >= 0x80.

Also:
-Switch alignment directives to .balign
-Expand the x86-32 exception table to a full 256
-Remove an extraneous define
-Make sure the IDT is 8 or 16 byte aligned
-Use END_DATA and END_FUNCTION in the exception and gdt asm files
2024-03-10 21:50:01 -07:00
Travis Geiselbrecht
6d7d31d9b4 [readme] A few new updates 2024-03-09 17:58:08 -08:00
Travis Geiselbrecht
ed309d2d7f [platform][pc] use legacy memory descriptor if multiboot doesn't pass new style
Use the legacy version of the memory sizing info that just hands the
kernel 2 implicit ranges: 0 ... X and 1MB ... Y.

Not ideal, but when booting on very old machines without BIOS e820 call
implemented it's all you got.
2024-03-07 23:35:58 -08: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
679fbb6e96 [github][actions] update checkout and cache to v4 2024-02-27 00:53:37 -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
406f28a3ea [platform][rp2040] Update the pico platform after updating the SDK
The build was momentarily broken until this was added to fix it.

Also generally remove a few extraneous defines in the platform code.
2024-02-27 00:35:23 -08:00
Travis Geiselbrecht
c892c958f4 [external] update raspberry pi pico SDK
Bump to version 1.5.1 from
https://github.com/raspberrypi/pico-sdk
6a7db34ff63345a7badec79ebea3aaef1712f374

All code verbatim with the exception of the removal of CmakeList.txt
files and a tweak to platform.h.
2024-02-27 00:12:23 -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
770d475224 [arch][arm-m] add additional comments and asserts to exception/context switch code 2024-02-26 00:58:04 -08:00
Travis Geiselbrecht
be19e2a960 [arch][arm-m] add clrex to context switch 2024-02-26 00:58:04 -08:00
Frank Dischner
5e69cd930d [arch][arm-m] simplify context switch
The context switch is now always performed inside the PendSV handler,
which greatly simplifies the code by reducing all switches to a single
path. This should also eliminate any race conditions during the switch.

Because we always enter PendSV for a switch, there is a slight
performance penalty in the case of switching from a non-preempted thread
to another non-preempted thread (~40 cycles longer on an M4, compared to
the previous implementation)
2024-02-26 00:58:04 -08:00
Travis Geiselbrecht
b8cff0e203 [arch][arm-m] remove the was_preempted field from the debugger structure
It will be removed in a upcoming CL, so remove it now so the future CL
cleanly applies.

Bump the major number of the structure in case there's a tool somewhere
that uses it.
2024-02-26 00:58:04 -08:00
Travis Geiselbrecht
71a413dab4 [arch][arm-m] move the debugger structure out of kernel/thread
The arm-m specific debugger structure really should live in arm-m code,
so move it there to clean things up a bit.
2024-02-26 00:58:04 -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
5249549e12 [platform][rosco_m68k] update the duart driver
-Reinitialize the uart bit modes
-Ignore framing/break errors on receive. Unclear why they seem to always
be set in the fifo, but seems to be safe to ignore for now
-Make sure platform_pgetc returns the right error code
-Initialize the output ports to all gpios
2024-02-11 01:28:49 -08:00
Travis Geiselbrecht
23cff5b493 [lib][debug] remove unused function 2024-02-11 00:39:53 -08:00
Travis Geiselbrecht
7e11c3bf78 [arch][m68k] save up to 4 arguments passed to LK
Pass the first 4 words on the stack that may have been passed from
firmware or bootloader to LK on to lk_main.
2024-02-11 00:38:52 -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
Travis Geiselbrecht
f7121c7b7e [arch][riscv] general riscv spinlock cleanup
-Hard set the spinlock type to uint32_t to be clearer
-Switch the free/held value to a simple 0 or 1

Previously, was writing the current cpu number into the spinlock, which
was only useful for debugging purposes. However, since the atomic
operation was an amoswap instead of a proper CAS, it would end up
overwriting the old cpu number with the new cpu number when it tried to
take it. It would still work as a spinlock, since the value was !0, but
it was falsely tracking which cpu actually held it.

To keep it simple, just switch to 0/1 and stick with the amoswap
instruction, which is much more efficient than a LR/SC pair to implement
CAS on riscv.

Internally still use an unsigned long for the old value, since the
amoswap instruction overwrites the entire Rd register, and thus keeps
the codegen efficient since it wont try to sign extend it for any
comparisons afterwards.

Thanks @loqoman (darwin.s.clark@gmail.com) for catching this one.
2023-12-28 17:02:07 -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
crady
712d7f58dc [documentation] LK Memory Management Overview 2023-12-04 01:00:24 -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
Matt Schulte
6414dd13b0 [make] Remove duplicate compile rules for modes
Currently, the compilation rules are mostly duplicated for normal vs
float vs ARM source files. This fix deduplicates the compilation logic
for these different "mode" of source files by using make's
Target-specific variable functionality.

https://www.gnu.org/software/make/manual/make.html#Target_002dspecific

This change was tested by using
[`bear`](https://github.com/rizsotto/Bear) to generate a
compile_commands.json file. The file was generated both before and after
the change and the json diff'd to ensure the generated compile commands
were not changed.

Change-Id: Id472045cc2e65bf542dfbf0ff52089be224c9d13
2023-12-04 00:56:39 -08:00
Matt Schulte
b0b2665cea [make] Add ability to deny modules from being used
Certain projects may want to prevent the usage of certain modules from
being used. Here are two examples of when this may occur:

1. The Project has it's own fdt library and does not want developer's
   using the version of libfdt included with LK

2. The project does not want developers using mincrypt.

`DENY_MODULES` is a list which developers can set in their own project
makefiles which is checked on each module inclusion. If that module is
on the deny list, it causes a build failure.
2023-12-04 00:53:01 -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
ec261bcf45 [github][ci] switch to gcc 13.2.0 for the default build compiler 2023-10-15 14:45:49 -07:00
Travis Geiselbrecht
58fd2c36d5 [platform][jh7110] Tweak logic to find the FDT from the uimage 2023-10-15 14:41:30 -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
Michael Shavit
284f83af11 [arch][arm64] Fix mmu_unmap issue when FEAT_TTL is implemented
Precisely set bits [55:22] of the vaddress in bits [43:0] for the vae1is
and vaee1is TLBI commands.

On platforms where FEAT_TLL is implemented, bits [47:44] of the command
accept a TTL parameter which can optionally be set to hint the
translation table level containing the address being invalidated.
Implementations aren't architecturally required to perform the
invalidation if the hint is incorrect however. Invalidations may
therefore fail with the current implementation if the vaddress has bits
set in [58:55].

This is notably an issue on ARM fastmodels which doesn't perform the
invalidation when the TTL parameter is incorrect.
2023-09-25 16:03:45 -07:00
Travis Geiselbrecht
30dc320054 [github] Merge pull request #380 from arichardson/add-clang-ci
Allow building RISCV64 and x86_64 with clang and add a Clang CI job
2023-06-21 15:42:35 -07:00
Matt Schulte
9325ca7f3b Fix typo in endif comment 2023-06-21 15:36:22 -07:00
Alex Richardson
3b215c398e [ci] Add 64-bit RISC-V to Clang CI 2023-06-08 07:08:49 -07:00
Alex Richardson
bf6ab93088 [riscv] Workaround for undef-weak symbol relocations with clang+lld
When building with clang -mcmodel=medany and linking with ld.lld, we get
out-of-range relocation errors for undefined __start_<section> symbols
since 0 cannot be represented as a PC-relative offset). This is not a
problem with ld.bfd since ld.bfd rewrites the instructions to avoid the
out-of-range PC-relative relocation. For now, the simplest workaround is
to build with -fpie -mcmodel=medany (thus indirecting these symbols via
the GOT). This will be done automatically once clang includes
https://reviews.llvm.org/D107280.

Without this change I get the following linker errors:
ld.lld: error: dev/driver.c:21:(.text+0x1E): relocation R_RISCV_PCREL_HI20 out of range: -524295 is not in [-524288, 524287]; references __start_devices

See https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/126 and
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/201.
2023-06-08 07:08:49 -07:00
Alex Richardson
69111c40f5 [make] Add a COMPILER_TYPE variable
This can be used to change compiler flags for GCC vs Clang.
2023-06-08 07:08:49 -07:00
Alex Richardson
135479c70e [riscv] Disable linker relaxations when linking with ld.lld
We have to compile RISC-V code with -mno-relax when linking with ld.lld
since ld.lld does not yet support RISC-V linker relaxations. Without this
change, linking with ld.lld results in many errors such as:
`relocation R_RISCV_ALIGN requires unimplemented linker relaxation`.

This support was implemented as part of LLVM 15, but to support older
versions of ld.lld we add the flag unconditionally for now.
2023-06-08 07:08:49 -07:00
Alex Richardson
8c20e005ca [make] Set LINKER_TYPE to lld when building with ld.lld
This will be needed in a follow-up commit to disable linker relaxations
for RISC-V since ld.ldd does not support them yet.
2023-06-08 07:08:49 -07:00
Alex Richardson
496e2f4b8c [riscv][clang] Use a CSR name instead of a numeric expression
Clang's assembler rejects expressions containing e.g. (1u << N) in the
assembler. Instead using numeric expressions for per-privilege level
CSRs, we can prepend `m` or `s`. This also lets the compiler assign the
CSR encoding instead of having to hardcode it in the source code.
2023-06-08 07:08:49 -07:00