Commit Graph

2806 Commits

Author SHA1 Message Date
Travis Geiselbrecht
e63c132f9c [dev][interrupt][plic] kick the max irqs to 256
Will need to figure out a cleaner way of doing this, but for now just
keep increasing the size.
2024-06-17 00:45:20 -07:00
Travis Geiselbrecht
69b8bccd76 [riscv] switch stimecmp/stimecmph registers to using the raw integer format
Though using the named nmemonics is a generally better idea it has the
unforunate property of not working on older compilers. In this case,
these new registers are for the Sstic extension, which is new enough
that even reasonably recent compilers as GCC 12.1 doesn't understand it.

Fixes issue #410
2024-06-16 22:37:10 -07:00
Travis Geiselbrecht
371a03357a [vscode] some recommended extensions 2024-06-16 22:37:10 -07:00
Travis Geiselbrecht
907d2d5579 [app][uefi] fix warning in uefi code 2024-06-16 22:37:10 -07:00
Travis Geiselbrecht
74864a56c0 [scripts][buildall] catch ctrl-c and abort the script 2024-06-14 15:35:58 -07:00
Travis Geiselbrecht
50b6f8c85c [include][compiler.h] fix a warning with gcc 2024-06-14 15:32:38 -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
Kelvin Zhang
4e9edd234f Fix missing apps section issue on clang
Clang linker would remove apps section even though variable
insied it are marked as "used". Per clang doc, we need to add
"retain" attribute to prevent section gc.

Bug: 294283461
Test: th
Change-Id: I5fc0aee885a419f314de811a2cf92b77af230c0c
2024-06-14 15:26:15 -07:00
Travis Geiselbrecht
c572b70083 [README] add links to point to arm64 toolchains 2024-06-14 14:34:44 -07:00
Travis Geiselbrecht
ea425e5473 [dev][gicv2] switch all of the register accessors to mmio_*
This fixes a bug when trying to start on qemu + kvm on an arm host.

A few minor fixes as suggested by clang tidy.
2024-06-04 20:28:03 -07:00
Travis Geiselbrecht
14bd7728a6 [arch][riscv][feature] add a few more feature bits
These may be useful in the future.
2024-06-02 15:31:30 -07:00
Travis Geiselbrecht
c4effaeef0 [arch][riscv] add SSTC extension support
Pretty simple extension, just directly set the supervisor timer compare
register (new) instead of calling through to SBI to set it for you.
2024-06-02 15:29:53 -07:00
Travis Geiselbrecht
b9c3603c59 [arch][riscv] fix typo matching against the zifencei feature 2024-06-02 14:51:53 -07:00
Travis Geiselbrecht
59f97195d4 [vscode] add a new (mostly empty) code workspace and a clang tidy file
The clang tidy file is mostly a copy of the fuchsia one, with a few
tweaks here and there.
2024-06-01 17:45:48 -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
479f7fb9b7 Revert "[arch][arm64][mmio] add 'Z' to the mmio write accessor inline asm"
Sadly this doesn't really work in all situations and only happens to
work with gcc + binutils for 32bit accesses, presumably because gnu as
replaces a literal 0 with wzr.

Clang doesn't understand it at all.

This reverts commit 6c14941dec.
2024-06-01 14:59:53 -07:00
Travis Geiselbrecht
0e25214ed8 [README] update link to gcc 14.1 2024-05-28 22:07:04 -07:00
Travis Geiselbrecht
f99cc0f584 [project][fs] add partition sniffing code to the default fs virtual project 2024-05-25 16:22:12 -07:00
Travis Geiselbrecht
6c14941dec [arch][arm64][mmio] add 'Z' to the mmio write accessor inline asm
This allows the compiler to use the xzr register if writing a zero
value, instead of uselessly moving 0 into a register first.
2024-05-24 22:33:32 -07:00
Travis Geiselbrecht
7791ec047c [gitignore] ignore .cache directory
Seems to be where some clangd stuff is tossed.
2024-05-23 20:47:00 -07:00
Mike McTernan
e870c0b097 trusty: arm32: fix potential double fault when printing diagnostics
When dumping_mode_regs() on a fault, avoid printing the stack beyond the
current page.  This prevents exceeding the stack base and hitting a
guard page in the case the stack use is < 128 bytes.

Bug: 336957655
Test: crash test, observe double fault fixed
Change-Id: If49b5fe5e1651557d19bf18c4026224cfb038101
2024-05-23 20:47:00 -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
035739433e [arch][arm] avoid using -mgeneral-regs-only for arm32
For older compilers (gcc 7.5.0 in particular) avoid using
-mgeneral-regs-only to override the floating point switches, since it
doesn't seem to understand that switch.

Instead more properly add the floating point switches for a module or
source file compiled with float. More compatible with all compilers.
2024-05-14 01:28:51 -07:00
Travis Geiselbrecht
1a761abb83 [arch][arm] Add support for float/nofloat compile options
Was already added to arm64, but arch/arm hadn't picked up this feature
yet. Uncovered a few places here or there that wasn't marking code as
float/no-float, but this fixes a problem where newer compilers are
starting to sneak in vector code because they can.

Issue #406
2024-05-14 00:57:19 -07:00
Travis Geiselbrecht
973a0ae466 [platform][qemu-virt-arm32] set the default cpu in one spot
The project file was setting cortex-a15, but the platform was also
setting it, so let the platform default stick.
2024-05-14 00:57:19 -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
2360f0fea1 [target][dartuino] properly mark files as needing float
Some routines inside the sensor bus code in dartuino need floating
point, so put those in MODULE_FLOAT_SRCS.

Also mark app/accellerometer as needing float.
2024-05-14 00:46:28 -07:00
Travis Geiselbrecht
2f336c9ba2 [platform][qemu-virt-arm] update the uart driver to use the new mmio routines
This was the driver that triggered the whole thing, since GCC 14.1 was
starting to use more fancier addressing modes that was causing QEMU to
bomb out when using KVM.
2024-05-14 00:01:49 -07:00
Travis Geiselbrecht
86267ca23c [include][reg.h] define new mmio_read/write accessors
To work properly with some hypervisors on various architectures (ARM,
ARM64, x86), add global routines to allow access to MMIO registers via
architecturally defined accessors.

Add accessors for ARM, ARM64, and x86-32/64. Have the other arches
default to just using whatever the compiler emits.

Will need to generally move things off the legacy REG*() accessors
since they're really not safe going forward with what compilers emit.
2024-05-13 00:39:29 -07:00
Travis Geiselbrecht
356e9adc01 [make] remove an undefine, unsupported on older gnu makes
It wasn't really that important anyway, was just a general nicety in the
riscv rules.mk
2024-05-10 16:15:54 -07:00
Travis Geiselbrecht
3c71b665f6 [platform][arm-qemu] fix issue with uart driver on KVM
The accessing method the compiler is emitting for the *REG32 macros on
arm32 and arm64 is occasionally generating load/stores with writeback.
Though this has worked before, it seems to be rejected with whatever
combination of qemu + linux + hardware on this Raspberry Pi 5.

Convert the register accessors to inline asm that uses basic load/store
instructions, which is really the only correct thing to do now and in
the long run. Add a TODO to move this to reg.h and start to revamp how
registers are accessed across LK, but for now keep it just here to fix
things.
2024-05-10 07:36:29 +00:00
Travis Geiselbrecht
d54735cf5d [scripts][do-qemuarm] add switch to try to use KVM 2024-05-09 23:11:58 -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
5d8dd9c36a [make] add 'make tags'
Tries to generate a curated ctags file for the current project and
configuration.
2024-05-09 20:29:08 -07:00
Travis Geiselbrecht
60bee01621 [arch][x86] stub out the cache routines 2024-05-09 19:54:54 -07:00
Travis Geiselbrecht
339ff8995a [arch][barriers] add default memory barriers for all of the architectures
Most are pretty straightforward, but a few of the more esoteric
architectures just defaults are implemented.
2024-05-09 19:51:32 -07:00
Travis Geiselbrecht
d3cd5be13e [arch][ops] define some global ARCH macros to be a bit more scoped
Instead of ICACHE/DCACHE/UCACHE, add the ARCH_CACHE_FLAG_ prefix to be a
little cleaner and not collide with anything else.

No functional change.
2024-05-09 19:28:56 -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
7cda17edfc [fs][v9fs] Add an example test for VirtIO 9p filesystem
Add a simple test to validate the filesystem APIs that connect the LK
filesystem layer and the virtualIO 9p devices. The test does the same as
`app/tests/v9p_tests.c` to mount the littlekernel codebase folder as the
`/v9p` on the LK filesystem. Then it tries to read the `LICENSE` file
under the codebase and show the first 1024 bytes of the file.

For example:

```
starting internet servers
starting app shell
entering main console loop
] v9fs_tests
0x80017060: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 |/*. * Copyright
0x80017070: 28 63 29 20 32 30 30 38 2d 32 30 31 35 20 54 72 |(c) 2008-2015 Tr
0x80017080: 61 76 69 73 20 47 65 69 73 65 6c 62 72 65 63 68 |avis Geiselbrech
0x80017090: 74 0a 20 2a 0a 20 2a 20 50 65 72 6d 69 73 73 69 |t. *. * Permissi
0x800170a0: 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-25 00:17:02 -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