Commit graph

209 commits

Author SHA1 Message Date
bunnie
4eefbd88bc cleanup warning that crept into the code 2024-03-23 11:59:31 +08:00
bunnie
5234127b7b support multiple irq-like contexts with an enum 2024-03-23 11:59:31 +08:00
bunnie
500a641848 specify the irq return address for irqs 2024-03-23 11:59:31 +08:00
Sean Cross
b4d6884cc4 kernel: use addr_of!() and addr_of_mut!()
DUe to https://github.com/rust-lang/rust/issues/114447 direct access to
static mut variables causes a warning which will be turned into an
error in the 2024 edition.

The workaround is to use `addr_of!()` and `addr_of_mut!()` macros and
then dereference that.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-03-22 15:53:11 +08:00
Sean Cross
bf61ce5071 kernel: remove dead code
This code is commented-out and dead. It gets adjusted with `cargo fmt`,
so just remove it.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-02-06 10:33:33 +08:00
Sean Cross
ed4ec01017 kernel: support riscv32imac-unknown-none-elf
With Rust 1.76.0, we no longer support building with `#![no_std]` or
`panic = "abort"`, both of which are required within the kernel. As a
workaround, go back to building the kernel under
`riscv32imac-unknown-none-elf`.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-02-06 10:28:33 +08:00
bunnie
f9fc3d0d4b ok, format the kernel now that all in-line assembly has been checked 2024-01-14 19:27:14 +08:00
bunnie
710c45969f Revert "format the kernel"
This reverts commit 1f69e6aa39.

this has in-line assembly, let's fix that before we format
2024-01-14 19:24:33 +08:00
bunnie
1f69e6aa39 format the kernel 2024-01-14 19:11:19 +08:00
Sean Cross
60f2a17649 kernel: support receiving process arguments
Support passing process arguments in register 2 as part of arguments to
a process.

This requires updating the `InitialProcess` struct that is received from
the loader, and so requires modeifications to be made in tandem.

Signed-off-by: Sean Cross <sean@xobs.io>
2024-01-07 23:02:58 +08:00
bunnie
8ec08c9c76 fix rust v1.75.0 warnings that are probably benign
a lot of re-import warnings have cropped up. While I appreciate
their studiousness on this, the problem is that removing some
of these exports in the API crate could mean that future users
who want access to some API features that aren't used in this
configuration are now unaccessible.

I think it's not a huge problem at the moment, just spam-cleaning
the warnings because there are too many to deal with carefully
at the moment.
2024-01-04 19:15:28 +08:00
Sean Cross
6b5b4a5d21 kernel: services: don't crash when a process quits
When enumerating processes, the `find_process()` process didn't consult
whether a process was actually free. This resulted in a crash,
particularly when attaching a debugger to a crashed process.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-12-29 18:42:16 +08:00
bunnie
c2c56f9d3f fix typo in kernel feature specifier 2023-12-26 00:20:56 +08:00
Sean Cross
3658940260 kernel: add big-heap flag for running tests
When running Rust tests, a larger heap is needed. Add a kernel flag to
support this by default.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-12-25 23:35:37 +08:00
Sean Cross
5dfad296ae xous: mark MemoryRange::as_slice and friends as unsafe
Mark `MemoryRange::as_slice()` and `MemoryRange::as_slice_mut()` as
unsafe.

This is due to the fact that not all representable types can be cast to
an arbitrary value. For example, if Process A sends random values to
Process B, then Process B casts the memory to a slice of `bool`, then
any values that are not 0 or 1 are undefined.

Because these functions can leak UB into the program, they are marked as
unsafe.

This patch adds `unsafe {}` blocks to all instances where this function
is called. Additionally, all instances have been checked to verify that
they do not cast to any invalid types -- most use `u8` or `u32`.

Additionally, the long-deprecated `MemoryRange::from_parts()` call was
removed, since that causes UB without being marked as unsafe.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-09-12 10:07:38 +08:00
Sean Cross
e7cb72c478 kernel: services: remove unneeded muts
With Rust 1.71.0, mut detection has changed slightly, and it is more
aggressive about warning when things do not need to be mutable.

Remove these from the `services` file.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-07-16 15:28:21 +08:00
bunnie
cbbeaa27ad prevent overwriting current process ID in case of double-interrupt
this is part of #361, per @xobs
2023-04-12 23:14:09 +08:00
Sean Cross
ec97b3cdcf kernel: throw error when debugging invalid process
When debugging an invalid process (e.g. not yet run, terminated, etc.)
return an error rather than silently continuing.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-04-06 10:48:45 +08:00
Sean Cross
a34733e5e9 kernel: basic version of gdb serevr
This adds a basic gdb server. Currently, it is possible to list
processes and inspect memory and threads. It is not yet possible to
actually interact with code (e.g. no breakpoints and no single
stepping).

Signed-off-by: Sean Cross <sean@xobs.io>
2023-04-06 10:48:45 +08:00
Sean Cross
13029a76a2 kernel: initial gdb-stub reimplementation
Add an initial reimplementation of the gdb-stub using the gdbstub
backing crate.

This supports process enumeration and basic thread investigation.
Processes will pause when the debugger is inspecting them. Memory and
registers can be investigated. Threads can be listed and selected.

It does not yet support breakpoints.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-04-06 10:45:42 +08:00
eupn
723a730231
kernel: fix warnings 2023-03-14 19:01:11 +04:00
eupn
e2d34d364c
kernel: always print when process is terminated 2023-03-14 18:48:45 +04:00
eupn
7f5656445a
kernel: change some println!s to klog!s
Even when the print-debug feature isn't turned on, println! macro is still able to output some critical non-debug info to the console such as panics, process crashes and violations, etc. Debugging messages are printed with klog! macro that's disabled when debug-print feature is not set.
2023-03-14 18:47:57 +04:00
eupn
0953812dfc
kernel: hide hw specific details in process init 2023-03-14 18:35:12 +04:00
bunnie
73aa6c3b14 cleanup hosted mode warning 2023-02-15 20:35:32 +08:00
bunnie
08ae66a264 fix: #320
this commit adds the facilities to extract eh_frame[_header]
sections and pass it to each process.

A bump is required to `std` to extract the passed parameters.
2023-02-15 19:55:08 +08:00
bunnie
4a2234f539 XIP works with some processes, but not others
it works with e.g. shellchat, but not vault.

still scratching my head on what's gone wrong -- it's
crashing in the pre-boot, which means something is not
mapped right for some case that wasn't caught in the
earlier testing.
2023-02-11 01:42:04 +08:00
Sean Cross
043365ac82 kernel: re-add set_last_thread
git somehow dropped this function during the merge, which would have
made things very sad.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-02-01 20:45:43 +08:00
bunnie
680ddd1c58
Revert "Give servers their full quantum" 2023-02-01 14:08:16 +08:00
Sean Cross
63e6deae53 kernel: save current thread at context switch
Note the current thread in the original process when its quantum
expires. This will allow us to clean up after ourselves when a context
switch occurs, and will help to prevent thread starvation.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-02-01 10:46:25 +08:00
Sean Cross
1303e6416d kernel: fixup current_thread==0 on resume
For some reason, the current thread becomes 0 during suspend or resume.
This causes an error during boot.

Patch this up while we figure out what's causing it.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-01-31 16:01:35 +08:00
Sean Cross
fc8d78c2ec kernel: fix hosted mode
The process scheduler changed in subtle ways taht completely broke
hosted mode.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-01-31 11:24:09 +08:00
Sean Cross
8875d9b4b4 kernel: services: fix corner cases on thread selection
There were a few corner cases when it came to thread selection. Namely,
the same thread had a higher chance of repeatedly being executed.

Clean up these corner cases, and as a result get libstd tests to pass.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-01-30 22:15:01 +08:00
Sean Cross
2cb44cdfc2 kernel: services: optimize find_next_thread()
Use a multiply-based algorithm to count the number of leading zeroes.
This results in a function that's just 20 instructions long.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-01-30 22:15:01 +08:00
Sean Cross
a75bc4f54c kernel: minor formatting cleanups
These files have had rustfmt run on them.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-01-30 22:15:00 +08:00
Sean Cross
516876a30f kernel: use common function for finding next thread
THe act of finding a runnable thread is so common, yet the kernel
contains three ways of doing this.

Use a unified function to select the next available thread.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-01-30 22:15:00 +08:00
Sean Cross
69b5e924f3 kernel: properly set current_thread on init
Previously the `current_thread` was set to 0, which is invalid. Set the
`current_thread` so that it defaults to the initial thread ID.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-01-30 22:15:00 +08:00
bunnie
7be4a88a9b fix scheduler bug (credit: @xobs)
@xobs found a scheduler bug that would trigger a runnable process
search every time a scalar message returned. This fixes the problem,
causing the quantum to go back to the caller as intended.

Improves performance on the syscall by about 40%.
2023-01-17 02:11:48 +08:00
bunnie
6332bf1c90
Merge branch 'main' into driver-refactor 2022-11-03 01:53:23 +08:00
Jean-Pierre De Jesus DIAZ
d8807e6cea
kernel: Move rand driver to platform module.
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2022-11-02 14:36:41 +01:00
Sean Cross
c17a6d3786 kernel: make SYSTEM_SERVICES unmangled
This symbol will be viewed by external tools.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-10-28 17:38:25 +08:00
bunnie
755556611c prep kernel for packaging
- strip out gdb-stub. Per xobs, the feature never worked, and it
depends upon a branch of a git repo which is not allowed by crates.io
Since the feature hasn't been developed, and crates.io will not
allow even an optional feature that points to a git repo, the feature
was stripped out.

- rename "kernel" to "xous-kernel", so that we can live in a crates.io
package namespace that is specific to Xous.

still have to figure out the riscv package issue.
2022-09-27 17:02:20 +08:00
Sean Cross
581603b205 kernel: services: fix compile error when debugging enabled
Signed-off-by: Sean Cross <sean@xobs.io>
2022-06-26 16:45:41 +08:00
Sean Cross
75e855cc4d hosted: fix hosted mode after CreateProcess addition
Hosted mode spawns processes very differently, and this difference was
not reflected after changes were made to native mode.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-05-30 13:41:05 +08:00
Sean Cross
a241d89b5b kernel: ignore "ppid unused" warning for now
Signed-off-by: Sean Cross <sean@xobs.io>
2022-05-29 19:41:13 +08:00
Sean Cross
a2e57195ba kernel: implement CreateProcess for riscv
Implement a functioning CreateProcess syscall on riscv. This call
creates a server in the child process, and connects the server to the
parent. The parent can communicate with the child process using this
server.

The Server ID is passed as four `u32` values to the entrypoint function.
This can be reassembled into something that can then be passed to the
`ReceiveMessage` syscall.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-05-29 18:47:37 +08:00
Sean Cross
2e69ae8a12 spawn: compiles, but does not work yet
Signed-off-by: Sean Cross <sean@xobs.io>
2022-05-28 05:10:48 +08:00
Sean Cross
d8eb7be352 process: finish implementing ProcessStartup as return
We now us `ProcessStartup` as the return type. This builds in tset
mode, hosted mode, and RISC-V mode.

Process Startup is still not implemented for RISC-V mode.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-04-28 22:43:42 -04:00
Sean Cross
ab512c8996 kernel: services: fix recursion warning in Process
The `Process::defualt()` implementation started getting a recursion
warning in 1.60.0.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-04-05 13:32:48 +08:00
Sean Cross
ce4e40b28a kernel: add s command to print servers
This will print all allocated servers on the system.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-04-05 10:36:00 +08:00