From 2c4854e23fdba1a35e2faab34377dc34539ecca8 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 11 Oct 2019 14:09:41 +0300 Subject: [PATCH] Move `struct cpu` to cpu.h --- include/sys/amd64/cpu.h | 23 +++++++++++++++++++++++ include/sys/amd64/smp/smp.h | 8 -------- sys/amd64/hw/irq0.S | 21 --------------------- sys/amd64/hw/timer.c | 1 - sys/amd64/smp/smp.c | 9 ++------- 5 files changed, 25 insertions(+), 37 deletions(-) create mode 100644 include/sys/amd64/cpu.h diff --git a/include/sys/amd64/cpu.h b/include/sys/amd64/cpu.h new file mode 100644 index 0000000..092450c --- /dev/null +++ b/include/sys/amd64/cpu.h @@ -0,0 +1,23 @@ +#pragma once + +struct cpu { + struct cpu *self; + uint64_t flags; + + uint64_t processor_id; + uint64_t apic_id; +}; + +#if defined(AMD64_SMP) +extern struct cpu cpus[AMD64_MAX_SMP]; + +static inline struct cpu *get_cpu(void) { + struct cpu *cpu; + asm volatile ("movq %%gs:0, %0":"=r"(cpu)); + return cpu; +} +#else +extern struct cpu cpu; + +#define get_cpu() &cpu +#endif diff --git a/include/sys/amd64/smp/smp.h b/include/sys/amd64/smp/smp.h index af22281..4c9a9e0 100644 --- a/include/sys/amd64/smp/smp.h +++ b/include/sys/amd64/smp/smp.h @@ -1,14 +1,6 @@ #pragma once #include "sys/types.h" -struct cpu { - struct cpu *self; - uint64_t flags; - - uint64_t processor_id; - uint64_t apic_id; -}; - void amd64_smp_add(uint8_t apic_id); void amd64_smp_init(void); void amd64_load_ap_code(void); diff --git a/sys/amd64/hw/irq0.S b/sys/amd64/hw/irq0.S index 48ca7df..841660f 100644 --- a/sys/amd64/hw/irq0.S +++ b/sys/amd64/hw/irq0.S @@ -1,14 +1,9 @@ #include "asm/asm_irq.h" .section .text .global amd64_irq0 -.global amd64_irq0_counting -.extern amd64_timer_counter // TODO: per-cpu amd64_irq0: cli - testq $1, amd64_irq0_counting(%rip) - jnz amd64_irq0_count - // Interrupt entry: // rsp should be one of the following: // The one specified in the TSS.RSP0 @@ -27,19 +22,3 @@ amd64_irq0: irq_pop_ctx iretq - -amd64_irq0_count: - // Instead of running like a normal timer IRQ, - // It'll just increment the counter so a better - incq amd64_timer_counter(%rip) - - irq_eoi_lapic 0 - - movb $0x20, %al - outb %al, $0x20 - - iretq - -.section .data -amd64_irq0_counting: - .quad 0 diff --git a/sys/amd64/hw/timer.c b/sys/amd64/hw/timer.c index a12b8bf..f502efa 100644 --- a/sys/amd64/hw/timer.c +++ b/sys/amd64/hw/timer.c @@ -10,7 +10,6 @@ static spin_t amd64_timer_spin = 0; // TODO: proper GS-based smp_per_cpu(x) macro for per-CPU variable access -uint64_t amd64_timer_counter[AMD64_MAX_SMP] = {0}; extern uint64_t amd64_irq0_counting; void amd64_timer_init(void) { diff --git a/sys/amd64/smp/smp.c b/sys/amd64/smp/smp.c index 0ef8fff..9efbd94 100644 --- a/sys/amd64/smp/smp.c +++ b/sys/amd64/smp/smp.c @@ -4,6 +4,7 @@ #include "sys/amd64/hw/gdt.h" #include "sys/amd64/hw/idt.h" #include "sys/amd64/mm/mm.h" +#include "sys/amd64/cpu.h" #include "sys/string.h" #include "sys/debug.h" @@ -24,13 +25,7 @@ struct ap_param_block { extern char kernel_stacks_top[]; // TODO: use mutual exclusion for this static size_t ncpus = 1; -static struct cpu cpus[AMD64_MAX_SMP] = { 0 }; - -static inline struct cpu *get_cpu(void) { - struct cpu *cpu; - asm volatile ("movq %%gs:0, %0":"=r"(cpu)); - return cpu; -} +struct cpu cpus[AMD64_MAX_SMP] = { 0 }; static inline void wrmsr(uint32_t addr, uint64_t v) { uint32_t low = (v & 0xFFFFFFFF), high = v >> 32;