Remove spinlock contexts
All checks were successful
Build documentation / build-and-deploy (push) Successful in 28s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 28s
This commit is contained in:
@@ -57,23 +57,19 @@ static spin_lock_t lapic_calibration_lock = SPIN_LOCK_INIT;
|
||||
|
||||
/* Read IOAPIC */
|
||||
static uint32_t amd64_ioapic_read (struct ioapic* ioapic, uint32_t reg) {
|
||||
spin_lock_ctx_t ctxioar;
|
||||
|
||||
spin_lock (&ioapic->lock, &ctxioar);
|
||||
spin_lock (&ioapic->lock);
|
||||
*(volatile uint32_t*)ioapic->mmio_base = reg;
|
||||
uint32_t ret = *(volatile uint32_t*)(ioapic->mmio_base + 0x10);
|
||||
spin_unlock (&ioapic->lock, &ctxioar);
|
||||
spin_unlock (&ioapic->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Write IOAPIC */
|
||||
static void amd64_ioapic_write (struct ioapic* ioapic, uint32_t reg, uint32_t value) {
|
||||
spin_lock_ctx_t ctxioaw;
|
||||
|
||||
spin_lock (&ioapic->lock, &ctxioaw);
|
||||
spin_lock (&ioapic->lock);
|
||||
*(volatile uint32_t*)ioapic->mmio_base = reg;
|
||||
*(volatile uint32_t*)(ioapic->mmio_base + 0x10) = value;
|
||||
spin_unlock (&ioapic->lock, &ctxioaw);
|
||||
spin_unlock (&ioapic->lock);
|
||||
}
|
||||
|
||||
/* Find an IOAPIC corresposting to provided IRQ */
|
||||
@@ -203,9 +199,7 @@ void amd64_lapic_eoi (void) { amd64_lapic_write (LAPIC_EOI, 0); }
|
||||
* us - Period length in microseconds
|
||||
*/
|
||||
static uint32_t amd64_lapic_calibrate (uint32_t us) {
|
||||
spin_lock_ctx_t ctxlacb;
|
||||
|
||||
spin_lock (&lapic_calibration_lock, &ctxlacb);
|
||||
spin_lock (&lapic_calibration_lock);
|
||||
|
||||
amd64_lapic_write (LAPIC_DCR, DIVIDER_VALUE);
|
||||
|
||||
@@ -218,7 +212,7 @@ static uint32_t amd64_lapic_calibrate (uint32_t us) {
|
||||
uint32_t ticks = 0xFFFFFFFF - amd64_lapic_read (LAPIC_TIMCCT);
|
||||
DEBUG ("timer ticks = %u\n", ticks);
|
||||
|
||||
spin_unlock (&lapic_calibration_lock, &ctxlacb);
|
||||
spin_unlock (&lapic_calibration_lock);
|
||||
|
||||
return ticks;
|
||||
}
|
||||
|
||||
@@ -35,8 +35,6 @@ static void amd64_debug_serial_write (char x) {
|
||||
* Formatted printing to serial. serial_lock ensures that all prints are atomic.
|
||||
*/
|
||||
void debugprintf (const char* fmt, ...) {
|
||||
spin_lock_ctx_t ctxdbgp;
|
||||
|
||||
if (!debug_init)
|
||||
return;
|
||||
|
||||
@@ -52,14 +50,14 @@ void debugprintf (const char* fmt, ...) {
|
||||
|
||||
const char* p = buffer;
|
||||
|
||||
spin_lock (&serial_lock, &ctxdbgp);
|
||||
spin_lock (&serial_lock);
|
||||
|
||||
while (*p) {
|
||||
amd64_debug_serial_write (*p);
|
||||
p++;
|
||||
}
|
||||
|
||||
spin_unlock (&serial_lock, &ctxdbgp);
|
||||
spin_unlock (&serial_lock);
|
||||
}
|
||||
|
||||
/* Initialize serial */
|
||||
|
||||
@@ -60,9 +60,7 @@ static void amd64_hpet_write32 (uint32_t reg, uint32_t value) {
|
||||
|
||||
static uint64_t amd64_hpet_read_counter (void) {
|
||||
uint64_t value;
|
||||
spin_lock_ctx_t ctxhrc;
|
||||
|
||||
spin_lock (&hpet_lock, &ctxhrc);
|
||||
spin_lock (&hpet_lock);
|
||||
|
||||
if (!hpet_32bits)
|
||||
value = amd64_hpet_read64 (HPET_MCVR);
|
||||
@@ -77,15 +75,13 @@ static uint64_t amd64_hpet_read_counter (void) {
|
||||
value = ((uint64_t)hi1 << 32) | lo;
|
||||
}
|
||||
|
||||
spin_unlock (&hpet_lock, &ctxhrc);
|
||||
spin_unlock (&hpet_lock);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static void amd64_hpet_write_counter (uint64_t value) {
|
||||
spin_lock_ctx_t ctxhwc;
|
||||
|
||||
spin_lock (&hpet_lock, &ctxhwc);
|
||||
spin_lock (&hpet_lock);
|
||||
|
||||
if (!hpet_32bits)
|
||||
amd64_hpet_write64 (HPET_MCVR, value);
|
||||
@@ -94,7 +90,7 @@ static void amd64_hpet_write_counter (uint64_t value) {
|
||||
amd64_hpet_write32 (HPET_MCVR + 4, (uint32_t)(value >> 32));
|
||||
}
|
||||
|
||||
spin_unlock (&hpet_lock, &ctxhwc);
|
||||
spin_unlock (&hpet_lock);
|
||||
}
|
||||
|
||||
/* Sleep for a given amount of microseconds. This time can last longer due to \ref hpet_lock being
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <libk/string.h>
|
||||
#include <m/syscall_defs.h>
|
||||
#include <sys/debug.h>
|
||||
#include <sys/irq.h>
|
||||
#include <sys/smp.h>
|
||||
#include <sys/spin.h>
|
||||
#include <syscall/syscall.h>
|
||||
@@ -167,20 +166,18 @@ 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, ctxpr;
|
||||
|
||||
amd64_load_kernel_cr3 ();
|
||||
|
||||
struct saved_regs* regs = stack_ptr;
|
||||
|
||||
spin_lock (&thiscpu->lock, &ctxcpu);
|
||||
spin_lock (&thiscpu->lock);
|
||||
struct proc* proc_current = thiscpu->proc_current;
|
||||
spin_lock (&proc_current->lock, &ctxpr);
|
||||
spin_lock (&proc_current->lock);
|
||||
|
||||
memcpy (&proc_current->pdata.regs, regs, sizeof (struct saved_regs));
|
||||
|
||||
spin_unlock (&proc_current->lock, &ctxpr);
|
||||
spin_unlock (&thiscpu->lock, &ctxcpu);
|
||||
spin_unlock (&proc_current->lock);
|
||||
spin_unlock (&thiscpu->lock);
|
||||
|
||||
if (regs->trap <= 31) {
|
||||
amd64_intr_exception (regs);
|
||||
@@ -200,24 +197,3 @@ void amd64_intr_init (void) {
|
||||
amd64_init_pic ();
|
||||
amd64_idt_init ();
|
||||
}
|
||||
|
||||
/* Aux. */
|
||||
|
||||
/* Save RFLAGS of the current CPU */
|
||||
static uint64_t amd64_irq_save_flags (void) {
|
||||
uint64_t rflags;
|
||||
__asm__ volatile ("pushfq; cli; popq %0" : "=r"(rflags)::"memory", "cc");
|
||||
return rflags;
|
||||
}
|
||||
|
||||
/* Restore interrupts (IF bit) from RFLAGS */
|
||||
static void amd64_irq_restore_flags (uint64_t rflags) {
|
||||
if (rflags & (1ULL << 9))
|
||||
__asm__ volatile ("sti");
|
||||
}
|
||||
|
||||
/* Save current interrupt state */
|
||||
void irq_save (spin_lock_ctx_t* ctx) { *ctx = amd64_irq_save_flags (); }
|
||||
|
||||
/* Restore interrupt state */
|
||||
void irq_restore (spin_lock_ctx_t* ctx) { amd64_irq_restore_flags (*ctx); }
|
||||
|
||||
@@ -25,9 +25,9 @@ struct pg_index {
|
||||
static struct pd kernel_pd;
|
||||
static spin_lock_t kernel_pd_lock;
|
||||
|
||||
void mm_kernel_lock (spin_lock_ctx_t* ctx) { spin_lock (&kernel_pd_lock, ctx); }
|
||||
void mm_kernel_lock (void) { spin_lock (&kernel_pd_lock); }
|
||||
|
||||
void mm_kernel_unlock (spin_lock_ctx_t* ctx) { spin_lock (&kernel_pd_lock, ctx); }
|
||||
void mm_kernel_unlock (void) { spin_lock (&kernel_pd_lock); }
|
||||
|
||||
/* Get current value of CR3 register */
|
||||
static uintptr_t amd64_current_cr3 (void) {
|
||||
|
||||
@@ -61,7 +61,6 @@ struct proc* proc_from_elf (uint8_t* elf_contents) {
|
||||
struct proc* proc_clone (struct proc* proto, uintptr_t vstack_top, uintptr_t entry,
|
||||
uintptr_t argument_ptr) {
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
spin_lock_ctx_t ctxprt;
|
||||
|
||||
struct proc* proc = malloc (sizeof (*proc));
|
||||
if (proc == NULL)
|
||||
@@ -73,12 +72,12 @@ struct proc* proc_clone (struct proc* proto, uintptr_t vstack_top, uintptr_t ent
|
||||
atomic_store (&proc->state, PROC_READY);
|
||||
proc->pid = atomic_fetch_add (&pids, 1);
|
||||
|
||||
spin_lock (&proto->lock, &ctxprt);
|
||||
spin_lock (&proto->lock);
|
||||
|
||||
proc->procgroup = proto->procgroup;
|
||||
procgroup_attach (proc->procgroup, proc);
|
||||
|
||||
spin_unlock (&proto->lock, &ctxprt);
|
||||
spin_unlock (&proto->lock);
|
||||
|
||||
uintptr_t kstack_paddr = pmm_alloc (KSTACK_SIZE / PAGE_SIZE);
|
||||
proc->pdata.kernel_stack = kstack_paddr + (uintptr_t)hhdm->offset + KSTACK_SIZE;
|
||||
|
||||
@@ -7,17 +7,15 @@
|
||||
#include <sys/mm.h>
|
||||
#include <sys/smp.h>
|
||||
|
||||
void do_sched (struct proc* proc, spin_lock_t* cpu_lock, spin_lock_ctx_t* ctxcpu) {
|
||||
spin_lock_ctx_t ctxpr;
|
||||
|
||||
spin_lock (&proc->lock, &ctxpr);
|
||||
void do_sched (struct proc* proc, spin_lock_t* cpu_lock) {
|
||||
spin_lock (&proc->lock);
|
||||
|
||||
thiscpu->tss.rsp0 = proc->pdata.kernel_stack;
|
||||
thiscpu->syscall_kernel_stack = proc->pdata.kernel_stack;
|
||||
amd64_wrmsr (MSR_FS_BASE, proc->pdata.fs_base);
|
||||
|
||||
spin_unlock (&proc->lock, &ctxpr);
|
||||
spin_unlock (cpu_lock, ctxcpu);
|
||||
spin_unlock (&proc->lock);
|
||||
spin_unlock (cpu_lock);
|
||||
|
||||
amd64_do_sched ((void*)&proc->pdata.regs, (void*)proc->procgroup->pd.cr3_paddr);
|
||||
}
|
||||
|
||||
@@ -91,9 +91,8 @@ static void amd64_smp_bootstrap (struct limine_mp_info* mp_info) {
|
||||
struct cpu* spin_cpu = thiscpu;
|
||||
proc_register (spin_proc, &spin_cpu);
|
||||
|
||||
spin_lock_ctx_t ctxcpu;
|
||||
spin_lock (&spin_proc->cpu->lock, &ctxcpu);
|
||||
do_sched (spin_proc, &spin_proc->cpu->lock, &ctxcpu);
|
||||
spin_lock (&spin_proc->cpu->lock);
|
||||
do_sched (spin_proc, &spin_proc->cpu->lock);
|
||||
}
|
||||
|
||||
/// Initialize SMP subsystem for AMD64. Start AP CPUs
|
||||
|
||||
@@ -14,20 +14,18 @@
|
||||
extern void amd64_syscall_entry (void);
|
||||
|
||||
uintptr_t amd64_syscall_dispatch (void* stack_ptr) {
|
||||
spin_lock_ctx_t ctxcpu, ctxpr;
|
||||
|
||||
amd64_load_kernel_cr3 ();
|
||||
struct saved_regs* regs = stack_ptr;
|
||||
|
||||
spin_lock (&thiscpu->lock, &ctxcpu);
|
||||
spin_lock (&thiscpu->lock);
|
||||
struct proc* caller = thiscpu->proc_current;
|
||||
int caller_pid = caller->pid;
|
||||
spin_lock (&caller->lock, &ctxpr);
|
||||
spin_lock (&caller->lock);
|
||||
|
||||
memcpy (&caller->pdata.regs, regs, sizeof (struct saved_regs));
|
||||
|
||||
spin_unlock (&caller->lock, &ctxpr);
|
||||
spin_unlock (&thiscpu->lock, &ctxcpu);
|
||||
spin_unlock (&caller->lock);
|
||||
spin_unlock (&thiscpu->lock);
|
||||
|
||||
int syscall_num = regs->rax;
|
||||
syscall_handler_func_t func = syscall_find_handler (syscall_num);
|
||||
@@ -45,9 +43,9 @@ uintptr_t amd64_syscall_dispatch (void* stack_ptr) {
|
||||
caller = proc_find_pid (caller_pid);
|
||||
|
||||
if (caller != NULL) {
|
||||
spin_lock (&caller->lock, &ctxpr);
|
||||
spin_lock (&caller->lock);
|
||||
caller->pdata.regs.rax = r;
|
||||
spin_unlock (&caller->lock, &ctxpr);
|
||||
spin_unlock (&caller->lock);
|
||||
}
|
||||
|
||||
if (reschedule)
|
||||
|
||||
Reference in New Issue
Block a user