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>
Memory is on-demand allocated, meaning it's entirely possible to
allocate and free memory without ever touching physical pages.
Previously, when we attempted to free memory, it would skip over pages
that were never backed by real memory.
With this patch, we continue to free the virtual page even if there is
no associated physical page.
Signed-off-by: Sean Cross <sean@xobs.io>
Memory is on-demand allocated, meaning it's entirely possible to
allocate and free memory without ever touching physical pages.
Previously, when we attempted to free memory, it would skip over pages
that were never backed by real memory.
With this patch, we continue to free the virtual page even if there is
no associated physical page.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
If a process fails for some reason (e.g. by performing a fault) and
there is no exception handler, either terminate the process or (if
gdbserver is enabled) have it suspend the process.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
This fixes the exception handler so that it can support user-defined
exceptions. Additionally, kernel mode errors are called out now.
Signed-off-by: Sean Cross <sean@xobs.io>
When the program counter is NULL, we can still get exceptions. This
happens when we jump to an invalid address, for example.
Signed-off-by: Sean Cross <sean@xobs.io>
This compresses the entirety of the memory range finder into a single
statement. As a result, duplicate code is removed and we can elide more
range checks.
Signed-off-by: Sean Cross <sean@xobs.io>
By vendoring this package, we can avoid causing a rebuild unnecessarily.
This will be removed when Rust 1.55 is released and we can bring the
`kernel` package back into the main workspace.
Signed-off-by: Sean Cross <sean@xobs.io>
This fixes the MemoryRange refactor where `.addr` and `.size` are now
private fields.
Previously it had only been tested on baremetal mode.
Signed-off-by: Sean Cross <sean@xobs.io>
Mark the private fields in a `MemoryRange` struct as being private. This
allows us to perform operations on the memory range armed with the
knowledge that the entire range is valid and unaliased.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
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>
This allows us to support different printers in the kernel. For example,
this can be used to swap out the println!() function to print to GDB
when a debugger is attached.
Signed-off-by: Sean Cross <sean@xobs.io>
Ensure pages of memory can be written to when we write to them. This
lets us patch program code to, for example, insert breakpoints.
Signed-off-by: Sean Cross <sean@xobs.io>
When running in CI, cause processes to panic rather than waiting for a
debugger to attach. This will ensure test failures are caught sooner
rather than later.
Signed-off-by: Sean Cross <sean@xobs.io>
Switch to the message client when returning memory in Hosted mode. This
properly marks a process as ready-to-run, which was otherwise not
correctly done.
Signed-off-by: Sean Cross <sean@xobs.io>
This changes the `p` command to only print processes, and renames the
existing behavior to `P` which prints processes and threads.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
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>
THe MMU flushing logic got disabled due to an experiment. Re-enable it
to ensure pages are consistent when shifting them across boundaries.
Signed-off-by: Sean Cross <sean@xobs.io>
This avoids using uninitialized arrays to manage the pagetables, and
instead uses raw pointers. This should avoid using potentially
uninitialized data.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
These calls can be used to print out thread information for debugging.
This augments the existing `print_thread()` call, which has been renamed
to `print_current_thread()`.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
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>
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>
This rewrites the entire project so that most runnable projects now use
`xous-ipc` instead of `xous::String` where possible.
This also removes `rkyv` from the list of dependencies in `xous-rs`.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
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>
This will enable us to have more information about the result that is
returned when mutable memory is modified by a server.
Signed-off-by: Sean Cross <sean@xobs.io>
The `can_resume` variable doesn't change, and can be made a constant.
This slightly improves reasoning about what the function is doing.
Signed-off-by: Sean Cross <sean@xobs.io>
This reworks the server queue to add a "generation counter". This
counter ensures messages are removed from the queue in the order they
were added, even if they are jumbled up within the queue itself.
Signed-off-by: Sean Cross <sean@xobs.io>