Move struct cpu to cpu.h
This commit is contained in:
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+2
-7
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user