2841 Commits

Author SHA1 Message Date
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
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