diff --git a/arch/x86_64/apic.c b/arch/x86_64/apic.c index e65478a..2540c4b 100644 --- a/arch/x86_64/apic.c +++ b/arch/x86_64/apic.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -129,7 +130,7 @@ void lapic_send_ipi( if (lapic->xapic_regs) { while (mmio_field_get(APIC_ICR_DELIVERY_STATUS, lapic_read_icr(lapic)) == APIC_DELIVERY_STATUS_PENDING) - asm volatile("pause"); + arch_cpu_pause(); } } diff --git a/arch/x86_64/include/bits/cpu.h b/arch/x86_64/include/bits/cpu.h new file mode 100644 index 0000000..456ca3b --- /dev/null +++ b/arch/x86_64/include/bits/cpu.h @@ -0,0 +1,5 @@ +#pragma once + +static inline void arch_cpu_pause() { + asm volatile("pause"); +} diff --git a/arch/x86_64/serial.c b/arch/x86_64/serial.c index b4c6ca3..b5adc94 100644 --- a/arch/x86_64/serial.c +++ b/arch/x86_64/serial.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -13,7 +14,7 @@ static bool is_ready() { static void serial_write(struct console* con, const char* buf, size_t count) { for (size_t i = 0; i < count; i++) { while (!is_ready()) - asm volatile("pause"); + arch_cpu_pause(); asm_outb(COM1_BASE, buf[i]); } diff --git a/core/clock.c b/core/clock.c index 5f2c36e..125b025 100644 --- a/core/clock.c +++ b/core/clock.c @@ -4,6 +4,7 @@ #include #include #include +#include #include static struct clock* active_clock = nullptr; @@ -62,6 +63,6 @@ void clock_spin_ns(uint64_t ns) { uint64_t target = clock_get_elapsed_ns() + ns; while (clock_get_elapsed_ns() < target) { - // TODO: Maybe pause? + arch_cpu_pause(); } } diff --git a/core/mem/pmap.c b/core/mem/pmap.c index 88e9397..8bf1524 100644 --- a/core/mem/pmap.c +++ b/core/mem/pmap.c @@ -6,6 +6,7 @@ #include #include #include +#include #include // TODO: For now, we assume that we can do generic PTE lookups on every arch that has a MMU. @@ -231,7 +232,7 @@ void pmap_shootdown(struct pmap* pt) { const size_t req = atomic_load(percpu_ref_on(cpu, shootdown_req), ATOMIC_RELAXED); while ((ptrdiff_t)(req - atomic_load(percpu_ref_on(cpu, shootdown_ack), ATOMIC_ACQUIRE)) > 0) { pmap_shootdown_handle(); - asm volatile("pause"); + arch_cpu_pause(); } } irq_unlock(); diff --git a/core/module.c b/core/module.c index 1c36ee8..d49420e 100644 --- a/core/module.c +++ b/core/module.c @@ -68,7 +68,7 @@ static struct module* find_locked(const char* name) { return nullptr; } -void module_init(struct boot_info*) { +void module_init() { spin_init(&module_lock); tailq_init(&module_list); @@ -77,8 +77,6 @@ void module_init(struct boot_info*) { assert(mod_status == 0, "Built-in entry point returned %i", mod_status); } } -INIT_TASK(module_stage, "core.module", module_init); -INIT_DEPENDS(module_stage, sched_stage, ksyms_stage); static errno_t resolve_symbol(struct module* mod, uint32_t index, uintptr_t* out) { if (index >= mod->num_syms) diff --git a/core/spin.c b/core/spin.c index 5e4ec63..8cfac39 100644 --- a/core/spin.c +++ b/core/spin.c @@ -1,6 +1,7 @@ #include #include #include +#include void spin_init(struct spinlock* spin) { spin->next = 0; @@ -12,7 +13,7 @@ void spin_lock(struct spinlock* spin) { uint32_t my = atomic_fetch_add(&spin->next, 1, ATOMIC_RELAXED); while (atomic_load(&spin->owner, ATOMIC_ACQUIRE) != my) { - asm volatile("pause"); + arch_cpu_pause(); } } diff --git a/include/arch/cpu.h b/include/arch/cpu.h new file mode 100644 index 0000000..705fba2 --- /dev/null +++ b/include/arch/cpu.h @@ -0,0 +1,3 @@ +#pragma once + +#include