Fix user CPU context saving
All checks were successful
Build documentation / build-and-deploy (push) Successful in 31s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 31s
This commit is contained in:
@@ -47,8 +47,8 @@ void app_main (void) {
|
||||
|
||||
spawn (&app_thread1);
|
||||
|
||||
/* for (volatile int i = 0; i < 1000*1000; i++) */
|
||||
/* ; */
|
||||
/* for (volatile int i = 0; i < 1000*1000; i++) */
|
||||
/* ; */
|
||||
for (;;) {
|
||||
lock_mutex (MUTEX, RV_PRIVATE);
|
||||
|
||||
|
||||
@@ -165,13 +165,19 @@ static void amd64_intr_exception (struct saved_regs* regs) {
|
||||
|
||||
/* Handle incoming interrupt, dispatch IRQ handlers. */
|
||||
void amd64_intr_handler (void* stack_ptr) {
|
||||
spin_lock_ctx_t ctxcpu;
|
||||
spin_lock_ctx_t ctxcpu, ctxpr;
|
||||
|
||||
amd64_load_kernel_cr3 ();
|
||||
|
||||
struct saved_regs* regs = stack_ptr;
|
||||
|
||||
spin_lock (&thiscpu->lock, &ctxcpu);
|
||||
memcpy (&thiscpu->regs, regs, sizeof (struct saved_regs));
|
||||
struct proc* proc_current = thiscpu->proc_current;
|
||||
spin_lock (&proc_current->lock, &ctxpr);
|
||||
|
||||
memcpy (&proc_current->pdata.regs, regs, sizeof (struct saved_regs));
|
||||
|
||||
spin_unlock (&proc_current->lock, &ctxpr);
|
||||
spin_unlock (&thiscpu->lock, &ctxcpu);
|
||||
|
||||
if (regs->trap <= 31) {
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include <amd64/sched.h>
|
||||
#include <libk/std.h>
|
||||
#include <proc/proc.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/mm.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sync/spin_lock.h>
|
||||
|
||||
void do_sched (struct proc* proc, spin_lock_t* cpu_lock, spin_lock_ctx_t* ctxcpu) {
|
||||
spin_lock_ctx_t ctxpr;
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include <proc/proc.h>
|
||||
#include <sync/spin_lock.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/sched.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/sched.h>
|
||||
|
||||
/// Cpu ID counter
|
||||
static atomic_uint cpu_counter = 0;
|
||||
|
||||
@@ -21,7 +21,6 @@ struct cpu {
|
||||
volatile uint8_t irq_stack[KSTACK_SIZE] ALIGNED (16);
|
||||
volatile struct gdt_extended gdt ALIGNED (16);
|
||||
volatile struct tss tss;
|
||||
struct saved_regs regs;
|
||||
|
||||
uintptr_t lapic_mmio_base;
|
||||
uint64_t lapic_ticks;
|
||||
|
||||
@@ -14,27 +14,27 @@
|
||||
extern void amd64_syscall_entry (void);
|
||||
|
||||
int amd64_syscall_dispatch (void* stack_ptr) {
|
||||
spin_lock_ctx_t ctxcpu;
|
||||
|
||||
spin_lock (&thiscpu->lock, &ctxcpu);
|
||||
spin_lock_ctx_t ctxcpu, ctxpr;
|
||||
|
||||
amd64_load_kernel_cr3 ();
|
||||
struct saved_regs* regs = stack_ptr;
|
||||
|
||||
memcpy (&thiscpu->regs, regs, sizeof (struct saved_regs));
|
||||
spin_lock (&thiscpu->lock, &ctxcpu);
|
||||
struct proc* caller = thiscpu->proc_current;
|
||||
spin_lock (&caller->lock, &ctxpr);
|
||||
|
||||
memcpy (&caller->pdata.regs, regs, sizeof (struct saved_regs));
|
||||
|
||||
spin_unlock (&caller->lock, &ctxpr);
|
||||
spin_unlock (&thiscpu->lock, &ctxcpu);
|
||||
|
||||
int syscall_num = regs->rax;
|
||||
syscall_handler_func_t func = syscall_find_handler (syscall_num);
|
||||
|
||||
if (func == NULL) {
|
||||
spin_unlock (&thiscpu->lock, &ctxcpu);
|
||||
return -ST_SYSCALL_NOT_FOUND;
|
||||
}
|
||||
|
||||
struct proc* caller = thiscpu->proc_current;
|
||||
|
||||
spin_unlock (&thiscpu->lock, &ctxcpu);
|
||||
|
||||
int result = func (caller, regs, regs->rdi, regs->rsi, regs->rdx, regs->r10, regs->r8, regs->r9);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ bool proc_create_resource_mutex (struct proc_mutex* mutex) {
|
||||
void proc_cleanup_resource_mutex (struct proc* proc, struct proc_resource* resource) {
|
||||
struct proc_mutex* mutex = &resource->u.mutex;
|
||||
|
||||
proc_mutex_unlock (proc, mutex);
|
||||
/* proc_mutex_unlock (proc, mutex); */
|
||||
}
|
||||
|
||||
static void proc_mutex_suspend (struct proc* proc, struct proc_suspension_q* sq,
|
||||
|
||||
@@ -294,7 +294,7 @@ static void proc_reap (void) {
|
||||
}
|
||||
|
||||
void proc_sched (void) {
|
||||
spin_lock_ctx_t ctxcpu, ctxpr;
|
||||
spin_lock_ctx_t ctxcpu;
|
||||
|
||||
int s_cycles = atomic_fetch_add (&sched_cycles, 1);
|
||||
|
||||
@@ -306,15 +306,8 @@ void proc_sched (void) {
|
||||
|
||||
spin_lock (&cpu->lock, &ctxcpu);
|
||||
|
||||
struct proc* prev = cpu->proc_current;
|
||||
next = proc_find_sched (cpu);
|
||||
|
||||
if (prev != NULL) {
|
||||
spin_lock (&prev->lock, &ctxpr);
|
||||
memcpy (&prev->pdata.regs, &cpu->regs, sizeof (struct saved_regs));
|
||||
spin_unlock (&prev->lock, &ctxpr);
|
||||
}
|
||||
|
||||
if (next) {
|
||||
cpu->proc_current = next;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user