Commit Graph

2577 Commits

Author SHA1 Message Date
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
Travis Geiselbrecht
78fa76a658 [build] add a vim tag to some build generated files
Set the tab stop to 8 and turn off listing characters to look proper on
some editors that have that set to something else.
2024-04-23 23:27:37 -07:00
Travis Geiselbrecht
284bf108bc [arch][riscv] add new extensions for SBI 2.0
No actual features enabled, just detection.
2024-04-23 23:27:02 -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
d39f2db58d [platform][device-tree] fix up 3 platforms to use the new fdtwalk routines
Three platforms had basically duplicated logic that just was pulled into
the fdtwalk library. Fix these up to call into those routines instead.

-qemu-virt-arm
-qemu-virt-riscv
-jh7110 (visionfive 2 soc)
2024-04-16 23:15:00 -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
Travis Geiselbrecht
0255d80bd0 [external][libfdt] rename a top level function that collides with the name of a structure
Fixes an issue when the header is compiled with C++.
2024-04-16 23:01:31 -07:00
Travis Geiselbrecht
414c1e2665 [external][libfdt] update libfdt to newest version
Update libfdt from https://github.com/dgibson/dtc at revision
855c934e26aeadb5bab878d1b148090af2480c90

Source is verbatim except moving headers into an include directory added
to the path.

Using 2-clause BSD option.
2024-04-16 23:01:26 -07:00
Travis Geiselbrecht
f7b694e855 Revert "[clang][riscv] add -menable-experimental-extensions"
This reverts commit 37c3228443.

Decided it's probably not worth maintaining this and simply removed this
particular build combination (clang 13 + riscv) from the build matrix.
2024-04-08 00:08:01 -07:00
Travis Geiselbrecht
1ae8bf68fc [github][ci] build debug and release builds with clang 2024-04-08 00:07:17 -07:00
Travis Geiselbrecht
3e6fd78a38 [github][ci] limit riscv builds to clang 14+
Clang 13 is missing some support for some new ISA extensions that may
not be worth maintaining build system workarounds for.
2024-04-08 00:07:17 -07:00
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