finish implementation of running multiple processes concurrently (unsafely)
This commit is contained in:
12
kernel.c
12
kernel.c
@@ -43,7 +43,9 @@ __attribute__((naked))
|
||||
__attribute__((aligned(4)))
|
||||
void kernel_entry(void) {
|
||||
__asm__ __volatile__(
|
||||
"csrw sscratch, sp\n"
|
||||
// Retrieve the kernel stack of the running process from sscratch
|
||||
"csrrw sp, sscratch, sp\n"
|
||||
|
||||
"addi sp, sp, -4 * 31\n"
|
||||
"sw ra, 4 * 0(sp)\n"
|
||||
"sw gp, 4 * 1(sp)\n"
|
||||
@@ -76,9 +78,11 @@ void kernel_entry(void) {
|
||||
"sw s10, 4 * 28(sp)\n"
|
||||
"sw s11, 4 * 29(sp)\n"
|
||||
|
||||
// Retrieve and save the sp at the time of exception
|
||||
"csrr a0, sscratch\n"
|
||||
"sw a0, 4 * 30(sp)\n"
|
||||
|
||||
// Reset the kernel stack
|
||||
"mv a0, sp\n"
|
||||
"call handle_trap\n"
|
||||
|
||||
@@ -230,6 +234,12 @@ void yield(void) {
|
||||
if (next == current_proc)
|
||||
return;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"csrw sscratch, %[sscratch]\n"
|
||||
:
|
||||
: [sscratch] "r" ((uint32_t) &next->stack[sizeof(next->stack)])
|
||||
);
|
||||
|
||||
// Context switch
|
||||
struct process *prev = current_proc;
|
||||
current_proc = next;
|
||||
|
Reference in New Issue
Block a user