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>
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>
Instead of queueing the client thread number inside the server, queue
the server's thread number inside the server.
This prevents many spooky messages that were occurring when server
queues got full.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
Previously, we would only look at the top item on the server queue. If
it was not a known message, we would return an error.
This patch changes this behavior to look through the entire queue for
something we can take, and then clean it up as we go along.
This allow for having outstanding requests in the queue an forms the
backbone of the sleep server.
Signed-off-by: Sean Cross <sean@xobs.io>
When claiming an IRQ, we used to disable interrupts.
This is unnecessary, as interrupts are already disabled when running in
kernel mode.
Signed-off-by: Sean Cross <sean@xobs.io>
Keep interrupts nominally disabled in supervisor mode, and only enable
them for a brief period after WFI hits.
If an interrupt occurs, then WFI becomes a NOP. The `idle()` function is
only called when no more processes are running, which happens when all
processes are waiting for an interrupt.
Therefore, enable interrupts for a brief period when WFI returns in
order to drain all pending interrupts and return to the caller to handle
any change in the process table.
Signed-off-by: Sean Cross <sean@xobs.io>
When the kernel is running its main loop, interrupts are disabled as it
is running in supervisor mode.
As a result, we can ignore any interrupt enabling/disabling that may
need to occur.
Signed-off-by: Sean Cross <sean@xobs.io>
This feature works around a bug in Renode where unwrapped lines cause it
to crash. This forces columns to be wrapped at 80 characters.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
This allows us to use println early on even before it's initialized,
which will allow us to ignore prints to an uninitialized port.
Signed-off-by: Sean Cross <sean@xobs.io>
Memory that was marked as reserved-but-not-in-use could get reallocated.
Practically speaking, this caused threads to share stack, which makes
things spooky.
Signed-off-by: Sean Cross <sean@xobs.io>
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.
When a page is shared, only report an address as being available when
we receive a `BadAddress` error when doing the translation. Otherwise,
assume it is in use.
Signed-off-by: Sean Cross <sean@xobs.io>
When memory has been shared, it is no longer valid. However, it is still
"in use".
Return a `ShareViolation` error in this case so we can check for it
elsewhere.
Signed-off-by: Sean Cross <sean@xobs.io>
Initially, we wanted to be able to immutably lend data in a one-to-many
fashion. However, this has proven challenging, and doesn't have any
immediately obvious useful benefits.
For now, only allow one-to-one immutable lends.
Signed-off-by: Sean Cross <sean@xobs.io>
Instead of hardcoding bit values, use the symbolic names. This will
ensure we don't make mistakes by using magic numbers.
Signed-off-by: Sean Cross <sean@xobs.io>
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>
When allocating a page, it is only assigned a physical address once it
is actually needed. This on-demand paging works well, however we were
assuming that the first address of a page was accessed first.
This fixes an issue where a Message is allocated but the first byte
isn't accessed first.
Signed-off-by: Sean Cross <sean@xobs.io>
This tracks a variable that has been renamed, and was preventing the
kernel from compiling when debug printing is enabled.
This fixes#19.
Signed-off-by: Sean Cross <sean@xobs.io>
When compiling under non-test scenarios, the `rand` create conflicts
with the new `rand` module.
Disambiguate this field.
Signed-off-by: Sean Cross <sean@xobs.io>
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>