Reference cpu specific information via gs segment
This commit is contained in:
parent
01ff25eefb
commit
cce444f546
@ -1,15 +1,20 @@
|
|||||||
#include <cpu.h>
|
#include <cpu.h>
|
||||||
#include <interrupts.h>
|
#include <interrupts.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
void gdt_init(struct cpu *cpu);
|
void gdt_init(struct cpu *cpu);
|
||||||
|
|
||||||
struct cpu *cpu;
|
struct cpu __seg_gs *cpu = 0;
|
||||||
|
|
||||||
void cpu_init()
|
void cpu_init()
|
||||||
{
|
{
|
||||||
cpu = P2V(pmm_calloc());
|
struct cpu *c = P2V(pmm_calloc());
|
||||||
|
c->cpu = c;
|
||||||
|
write_msr(0xc0000102, (uint64_t)c);
|
||||||
|
asm("swapgs");
|
||||||
|
|
||||||
interrupt_init();
|
interrupt_init();
|
||||||
gdt_init(cpu);
|
gdt_init(cpu->cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +77,6 @@ void gdt_init(struct cpu *c)
|
|||||||
|
|
||||||
void interrupt_stack(void *rsp0)
|
void interrupt_stack(void *rsp0)
|
||||||
{
|
{
|
||||||
struct tss *tss = (void *)cpu->tss;
|
struct tss __seg_gs *tss = (void __seg_gs *)(cpu->tss);
|
||||||
tss->rsp0 = (uint64_t)rsp0;
|
tss->rsp0 = (uint64_t)rsp0;
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,26 @@ isr_common:
|
|||||||
push rcx
|
push rcx
|
||||||
push rbx
|
push rbx
|
||||||
push rax
|
push rax
|
||||||
|
|
||||||
|
mov rax, [rsp + 152]
|
||||||
|
and rax, (3<<12)
|
||||||
|
jz .kernel_interrupt
|
||||||
|
swapgs
|
||||||
|
|
||||||
|
.kernel_interrupt:
|
||||||
mov rdi, rsp
|
mov rdi, rsp
|
||||||
call int_handler
|
call int_handler
|
||||||
|
|
||||||
mov rdi, rax
|
mov rdi, rax
|
||||||
isr_return:
|
isr_return:
|
||||||
mov rsp, rdi
|
mov rsp, rdi
|
||||||
|
|
||||||
|
mov rax, [rsp + 152]
|
||||||
|
and rax, (3<<12)
|
||||||
|
jz .kernel_return
|
||||||
|
swapgs
|
||||||
|
|
||||||
|
.kernel_return:
|
||||||
pop rax
|
pop rax
|
||||||
pop rbx
|
pop rbx
|
||||||
pop rcx
|
pop rcx
|
||||||
|
@ -41,3 +41,20 @@ write_cr3:
|
|||||||
read_cr4:
|
read_cr4:
|
||||||
mov rax, cr4
|
mov rax, cr4
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
.global read_msr
|
||||||
|
read_msr:
|
||||||
|
mov rcx, rdi
|
||||||
|
rdmsr
|
||||||
|
shl rdx, 32
|
||||||
|
add rax, rdx
|
||||||
|
ret
|
||||||
|
|
||||||
|
.global write_msr
|
||||||
|
write_msr:
|
||||||
|
mov rcx, rdi
|
||||||
|
mov rax, rsi
|
||||||
|
mov rdx, rsi
|
||||||
|
shr rdx, 32
|
||||||
|
wrmsr
|
||||||
|
ret
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
|
|
||||||
struct cpu
|
struct cpu
|
||||||
{
|
{
|
||||||
|
void *cpu;
|
||||||
uint64_t gdt[6];
|
uint64_t gdt[6];
|
||||||
uint8_t tss[104];
|
uint8_t tss[104];
|
||||||
struct process *proc;
|
struct process *proc;
|
||||||
struct process *scheduler;
|
struct process *scheduler;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct cpu *cpu;
|
extern struct cpu __seg_gs *cpu;
|
||||||
|
|
||||||
void cpu_init();
|
void cpu_init();
|
||||||
|
|
||||||
@ -24,3 +25,6 @@ uint64_t read_cr2();
|
|||||||
uint64_t read_cr3();
|
uint64_t read_cr3();
|
||||||
void write_cr3(uint64_t);
|
void write_cr3(uint64_t);
|
||||||
uint64_t read_cr4();
|
uint64_t read_cr4();
|
||||||
|
|
||||||
|
void write_msr(uint64_t reg, uint64_t value);
|
||||||
|
uint64_t read_msr(uint64_t reg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user