Commit graph

209 commits

Author SHA1 Message Date
bunnie
002e098538 Fix issue #90
Turns out we didn't end up needing this capability, so, commenting it
out because it is a shy too powerful and is like packing a live
mortar shell in a storage unit: eventually, someone is going to
get hurt, even though it seems mostly harmless at the moment.

Code just commented out in case we need this feature in the future,
but, the main reason it was asked for (the PDDB) was accomplished
without it.
2022-02-02 00:37:57 +08:00
Sean Cross
24dd538a5c kernel: fix process exception handling state
Correctly handle transitions to and from exception handling.

Previously, the thread ID was incorrectly set such that the exception
handler became a valid thread. This has been adjusted so that the
exception handler is no longer considered a thread, and all other
threads will cease scheduling during this process.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-09-28 09:20:12 +08:00
Sean Cross
b43366e6ec kernel: services: fix suspend for running processes
If a process is currently running, it needs to be placed into the
`Debug` state rather than the `Ready` state.

Additionally, the process that's being switched to must enter the
`Running` state.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-25 16:03:06 +08:00
Sean Cross
19653e9c53 kernel: compatibility with riscv32imac-unknown-xous-elf
Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-18 18:14:24 +08:00
Sean Cross
e44eec2334 kernel: fix remaining warnings on hosted mode
This removes all remaining warnings from hosted mode. Tests pass, and
the system continues to run normally.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-16 15:07:25 +08:00
Sean Cross
5eaa3a41b1 kernel: services: fix warnings on hosted mode
Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-16 15:01:07 +08:00
Sean Cross
1b315de830 kernel: make init proces stack grown downwards
Previously, we were creating a stack beginning at the initial page,
and then growing it upwards. The correct behavior is to begin it at
the top and grow it downwards.

In order to do this, subtract the size of the stack from the initial
pointer.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-15 19:26:11 +08:00
Sean Cross
fa2a841f8a kernel: fix hosted mode exception support
Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-06 17:51:24 +08:00
Sean Cross
6985fda7ba kernel: get exceptions fully working
This finishes work with exceptions such that they now actually work.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-06 17:47:44 +08:00
Sean Cross
9dc4fcbf55 kernel: services: fix all clippy warnings
Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-06 10:16:29 +08:00
Sean Cross
d4675ef9cf kernel: services: allow unsetting exception handler
Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-06 10:05:29 +08:00
Sean Cross
059fc18850 services: add exception handler routines
Add a function to set and one to clear the current exception handler.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-06 10:02:32 +08:00
Sean Cross
759ddfedd6 kernel: add initial cut of exception handling
Though it is not yet wired up, the exception handler groundwork is laid
here.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-05 16:18:10 +08:00
Sean Cross
f5cf94524a kernel: add framework for exceptions
Add the ability to invoke exception handlers. This is not yet properly
wired up, but the framework is there.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-08-02 11:04:47 +08:00
Sean Cross
df30fd580d kernel: add Exception(usize) as process state
When a process encounters an exception of some sort, it will enter this
state if a handler is available.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-07-26 15:32:03 +08:00
Sean Cross
1fb7d4ebd5 kernel: use unsafe {} on Hosted mode
Since `MemoryRange::new()` is now unsafe, add an `unsafe {}` note when
calling this function on Hosted mode.

This fixes the build.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-06-24 17:07:41 +08:00
Sean Cross
977a175bb5 xous: mark MemoryRange::new() as unsafe
This function allows for creating arbitrary memory ranges. Mark this
function as `unsafe` in order to warn users that this can be used to
create invalid memory regions.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-06-24 17:02:02 +08:00
Sean Cross
86dd38f7fa kernel: fix hosted build
Signed-off-by: Sean Cross <sean@xobs.io>
2021-06-21 14:24:16 +08:00
Sean Cross
9ced90190e kernel: fix process suspension
This enables processes to be "suspended" by going into a Debug state.
Messages will back up and processes will continue to be scheduled around
the suspended process, while the system will continue to operate.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-06-18 12:55:21 +08:00
Sean Cross
13204d1714 Merge branch 'master' into debugger
Signed-off-by: Sean Cross <sean@xobs.io>
2021-06-18 10:56:30 +08:00
Sean Cross
180c99aa8d kernel: services: free servers on process termination
When a process is terminated, we disconnect it from all other processes.
We also need to free the slot in the server table.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-06-16 17:55:23 +08:00
Sean Cross
fb839f3217 wip
Signed-off-by: Sean Cross <sean@xobs.io>
2021-06-16 16:53:40 +08:00
Sean Cross
bbda4365ae wip commit
Signed-off-by: Sean Cross <sean@xobs.io>
2021-06-01 17:57:01 +08:00
Sean Cross
be6e0a9895 kernel: fix thread termination and waiting
Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-21 17:23:13 +08:00
Sean Cross
714aff830c kernel: implement JoinThread(tid)
Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-21 16:32:38 +08:00
Sean Cross
7c2d3a2247 kernel: implement thread exit support
Threads now have the ability to exit. Previously this resulted in a
kernel panic.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-21 13:04:14 +08:00
Sean Cross
e616a4bf4f kernel: fix hosted build/warnings
Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-20 11:52:03 +08:00
Sean Cross
09b8242bb2 kernel: get process termination "working" on risc-v
This successfully allows a process to call `terminate_process(val)`.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-20 11:42:31 +08:00
Sean Cross
30b82b25b1 kernel: run cargo fmt
Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-19 14:12:01 +08:00
Sean Cross
040759af25 kernel: services: add process_name(pid)
Add a function to determine the name of a process.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-10 14:37:33 +08:00
Sean Cross
5b92dd9874 kernel: services: use exception stack for kernel interrupts
When the kernel is processing an interrupt, use the exception stack.
This ensures that the kernel interrupt handler can switch processes
without having its stack go away.

This is used for debug information.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-10 14:37:33 +08:00
bunnie
08a86749fe fix hosted mode bugs 2021-05-09 01:13:16 +08:00
bunnie
f975884f1e increase server limit to 128 2021-05-06 00:41:27 +08:00
Sean Cross
23e759ffd8 kernel: fix multi-page lending
Due to several errors, multi-page lending did not work properly.

To begin with, if a page was not allocated then it would not be able to
be sent. That is, if you allocated 8192 bytes but only ever accessed the
first 4096 bytes, then an error would be encountered when lending the
unaccessed upper page.

Furthermore, due to a striding error in accessing pointers, half-pages
were treated as full pages.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-05-05 10:58:12 +08:00
Sean Cross
21a8ddd458 kernel: services: don't remap memory on intra-process lends
This brings intra-process lending in-line with intra-process sending,
where memory is not remapped the pointer is simply reused.

We may change this at a later point in order to further enforce the
concept of lent-memory-is-inaccessible, so do not rely in this behavior.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-04-06 09:08:03 +08:00
Sean Cross
4830f3eb2c kernel: server: implement DestroyServer(sid)
This implements a syscall to shut down a server. Servers may not be shut
down if they have outstanding messages that they have seen but not
responded to.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-04-05 18:18:48 +08:00
Sean Cross
85f0adbb2d kernel: implement Disconnect() syscall
Signed-off-by: Sean Cross <sean@xobs.io>
2021-04-02 18:37:09 +08:00
Sean Cross
af5598d2dc kernel: move memory owner when a Move occurs
When moving memory between processes, update the owner of that page to
match the new PID. Otherwise, memory can never be released.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-26 17:14:26 +08:00
Sean Cross
078f6ba625 kernel: services: be more proactive about updating current_thread
The `current_thread` variable is used to determine which thread to
switch back to after a context switch occurs. Keep track of the thread
more closely.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-25 16:15:19 +08:00
Sean Cross
2b97ea25ab xous: add create_thread_n functions
These are used to create threads with between 0 and 4 arguments.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-25 10:42:49 +08:00
Sean Cross
455bd4ccfb kernel: services: add more debug print crumbs
These could be useful in finding out what's gone wrong.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-24 22:12:29 +08:00
Sean Cross
090354c882 kernel: services: remove syscall_stack
This field is unused, so remove it.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-24 20:21:30 +08:00
Sean Cross
0d77f704a9 kernel: services: run cargo fmt on this file
Minor text reformatting.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-23 19:51:33 +08:00
Sean Cross
00e7f07187 kernel: services: remember new thread if specified
If we switch to a thread and specify a thread ID, remember that as the
current thread ID.

This prevents thread starvation by repeatedly going back to the same
thread ID.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-23 19:50:12 +08:00
bunnie
e62256b3df clean up hosted mode warnings 2021-03-03 22:50:46 +08:00
Sean Cross
f5a678e36f kernel: services: remove extra debugging prints
Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-03 21:20:03 +08:00
Sean Cross
db8e814cb7 kernel: services: fix sending messages within a process
This fixes the case where there is only one process active and it tries
to send messages to itself, or it yields to itself.

This closes issue #42.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-03 21:18:58 +08:00
Sean Cross
cc4c0f3c58 kernel: services: implement Debug for ProcessState
This gives us prettier and more useful displays for ProcessState.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-03-03 21:18:01 +08:00
bunnie
0889e83401 Merge remote-tracking branch 'betrusted/hardware' 2021-03-02 21:51:41 +08:00
bunnie
2d59adbe0e fix thread scheduling bug
the code originally would pick the same thread over and over again
this fix starts the thread search at one plus the current thread
wrapping around to one plus the current thread, so we always try
to pick a new thread compared to the current one, instead of
generally picking the same thread most of the time.
2021-03-02 21:46:14 +08:00
bunnie
4b0f50293f another intermediate commit 2021-03-02 21:15:40 +08:00
bunnie
96a19baa8d state before refactor of status to own process 2021-03-02 19:25:41 +08:00
bunnie
cb77dde6d8
Merge pull request #39 from betrusted-io/hardware
Synchronize in the rkyv changes
2021-02-18 02:07:13 +08:00
bunnie
2a46f541f2 add PID identification facility to help with debugging 2021-02-15 19:15:58 +08:00
Sean Cross
715e76bee0 kernel: allow connection IDs to be u32
In an effort to homogonize platforms, we are moving away from `usize` in
favour of `u32`. Allow the `CID` type to be a `u32` in the kernel by
casting it to a `usize` as necessary.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-02-04 10:29:12 +08:00
Lina Ceballos
d18500f4d6 adding license and copyright headers 2021-01-25 14:54:00 +01:00
bunnie
4ef581a266 riddled with race conditions, but...sort of works 2021-01-08 05:20:53 +08:00
Sean Cross
7b50d00eb8 repo: run cargo fmt
This reformats line endings to be consistent, and reinforces the
contents of `.gitattributes`.

Signed-off-by: Sean Cross <sean@xobs.io>
2021-01-03 18:31:51 +08:00
Sean Cross
f49518f7d5 kernel: add connect_for_process()
This allows one process to establish a connection to a server on behalf
of another process.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-12-04 23:25:41 +08:00
Sean Cross
85b6357d26 kernel: implement CreateServer
This implements CreateServer, which creates a server with a random name.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-12-04 20:58:14 +08:00
Sean Cross
25e4d16de3 xous-os: rename CreateServer to CreateServerWithAddress
Servers will, by default, get randomly-assigned SIDs. Certain servers
will want to have well-known SIDs, such as the log server or the
nameserver. These will use a separate call in order to perform this
priveledged operation.

A subsequent patch will add `CreateServer`.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-12-04 20:33:33 +08:00
Sean Cross
e7744b25ec kernel: services: format document
Signed-off-by: Sean Cross <sean@xobs.io>
2020-12-01 11:54:23 +08:00
Sean Cross
8a3f6a2b43 kernel: fix mutableborrow message returning
We weren't properly updating the packet when a mutableborrow was getting
returned.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-11-23 15:19:02 +08:00
Sean Cross
d76832dada kernel: services: return ServerNotFound when server isn't found
This is more intuitive than `OutOfMemory`.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-10-30 20:43:59 +08:00
Sean Cross
fa9a3e0954 kernel: rework hosted network protocol
This fixes issues regarding passing memory between processes.

We now properly catch `ReturnMemory` and give the memory back.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-10-29 19:46:17 +08:00
Sean Cross
84b39c931a kernel: services: switch address space prior to passing messages
Switch address spaces to pass messages to the new process, and switch
backafterwards.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-10-13 22:56:04 +08:00
Sean Cross
d4f0496371 kernel: remove unused debug data
Signed-off-by: Sean Cross <sean@xobs.io>
2020-10-04 19:08:29 +08:00
Sean Cross
fa23cfa88b kernel: services: update some debug comments
Signed-off-by: Sean Cross <sean@xobs.io>
2020-10-04 18:28:29 +08:00
Sean Cross
e5583a7646 kernel: fix message sender parameter
The `sender` was, previously, somewhat mislabeled. It was a combination
of PID and TID, except when it wasn't.

Instead, make this value a combination of ConnectionID and queue index.
This makes it easier to reason about which connection we're responding
to.

Additionally, don't expose teh global Server Index Table to userspace
programs.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-09-23 10:52:22 +08:00
Sean
1b59719a74 kernel: hosted: support per-thread memory messages
Previously, each process could return one chunk of memory. With this
change, processes can now return one chunk of memory per thread. This
enables multiple threads to lend memory to a server.

Signed-off-by: Sean <xobs@ci.betrusted.io>
2020-09-03 13:20:16 +08:00
Sean Cross
fbda077aff kernel: remove excess println() statements
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-30 10:46:48 +08:00
Sean Cross
96c5739cdd kernel: fix remaining warnings
This fixes all remaining warnings in the kernel. For now.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-30 01:17:35 +08:00
Sean Cross
bc92f4b042 kernel: services: fix build on riscv
Somehow the build broke. Oops.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-30 00:36:39 +08:00
Sean Cross
25824df335 kernel: services: print fewer diagnostic messages
These were printed a lot, which is not a thing we want right now.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-30 00:36:11 +08:00
Sean Cross
8f70c0640c kernel: fix server indexing
Server IDs were being improperly indexed, resulting in a
probably-invalid server index being returned.

Adjust these so that correct server indices are returned.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-29 22:10:24 +08:00
Sean Cross
bb17038bfe kernel: rename "xous" to "xous-kernel" in import
Cargo appears to cache packages in the workspace when multiple packages
use the same crate. Unfortunately, Xous uses different features
depending on whether it's running in the kernel or in userspace.

Pull the kernel version of "xous" in under a different namespace in
order to force it to use a different build.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-17 18:37:40 +08:00
Sean Cross
cb959eb1cf kernel: fix interrupts
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-10 22:43:38 +08:00
Sean Cross
31f63c3f5f kernel: threads work now
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-10 22:05:06 +08:00
Sean Cross
1d23bc5aae kernel: first multiple threads working
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-10 21:17:48 +08:00
Sean Cross
a467d6fcc7 kernel: baremetal: 2nd process starts to run and crashes
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-10 16:06:38 +08:00
Sean Cross
75449f1deb kernel: get PID1 running, now working on PID2
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-10 00:35:37 +08:00
Sean Cross
10ecacd136 kernel: native: create process for initial processes
These all need to bootstrap themselves.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 23:08:54 +08:00
Sean Cross
bef0168c20 kernel: more warning fixes
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 22:14:14 +08:00
Sean Cross
ba30b4919d kernel: remove more warnings
Still haven't run it on real hardware, but this removes more warnings
from the system.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 21:52:28 +08:00
Sean Cross
0006d4d99c kernel: get building
This is where the story really starts...

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 21:33:21 +08:00
Sean Cross
8ccecb6d99 kernel: down to 12 errors again
Slowly chipping away at it.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 20:59:31 +08:00
Sean Cross
299b9fc298 kernel: start working on lifetime errors
Only about 24 errors, so it's better than it could have been.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 19:45:02 +08:00
Sean Cross
8925964754 kernel: on to lifetime issues now!
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 19:38:15 +08:00
Sean Cross
30fef020f2 baremetal: just one more build error for this phase
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 19:27:43 +08:00
Sean Cross
e7a4927943 kernel: down to 7 compile errors
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 19:21:54 +08:00
Sean Cross
9bba5cbe4d server: pass memory buffer to server init
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 19:02:05 +08:00
Sean Cross
e48e1820f6 kernel: down to 12 errors
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 18:27:18 +08:00
Sean Cross
814be7cd84 kernel: down to 29 errors on bare metal
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 16:48:58 +08:00
Sean Cross
ebf568dadd baremetal: slowly whittling down the number of errors
Signed-off-by: Sean Cross <sean@xobs.io>
2020-08-09 16:14:34 +08:00
Sean Cross
ef0ef924c8 fix more clippy warnings
Signed-off-by: Sean Cross <sean@xobs.io>
2020-07-29 22:48:48 +08:00
Sean Cross
039975323e tests: add tests package
This package serves only to build tests for the kernel, because the
kernel wants to use a different mechanism for spawning processes.

Cargo doesn't support having `#[cfg(test)]` attributes on modules in
order to allow conditional compilation depending on whether we're
running a test or not. To work around this, `main.rs` is included in
another dummy crate.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-07-29 21:18:30 +08:00
Sean Cross
cece761ff1 xous: SID: convert to using newtype
Rather than simply casting a tuple as a type, create a new struct SID.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-07-29 20:03:21 +08:00
Sean Cross
e7e8a2b748 kernel: get initial hosted non-test processes working
This now has the ability to fork off processes.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-07-29 17:52:01 +08:00
Sean Cross
9af0fec049 kernel: convert multi-thread test (it's broken right now)
Signed-off-by: Sean Cross <sean@xobs.io>
2020-07-28 13:54:11 +08:00
Sean Cross
19222c34a9 kernel: get shutdown and multi-clients working
THis now has proper authentication for tests.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-07-28 13:28:14 +08:00