From 330a454af3e7ee064931a4e3d9443ffe8e618aec Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Thu, 10 Jul 2014 14:43:52 -0700 Subject: [PATCH] Improving AMD64 header --- sys/amd64/amd64.h | 37 +++++++++++++++++++++---------------- sys/amd64/machine.c | 5 +++++ sys/amd64/trap.h | 42 +++++++++++++++++++++++------------------- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/sys/amd64/amd64.h b/sys/amd64/amd64.h index b018520..2552d5e 100644 --- a/sys/amd64/amd64.h +++ b/sys/amd64/amd64.h @@ -150,22 +150,21 @@ typedef struct PACKED TaskStateSegment64 { #define RFLAGS_CF 0x00000001 /* Carry Flag */ #define RFLAGS_PF 0x00000004 /* Parity Flag */ -#define RFLAGS_AF -#define RFLAGS_ZF -#define RFLAGS_SF -#define RFLAGS_TF -#define RFLAGS_IF -#define RFLAGS_DF -#define RFLAGS_OF -// IOPL -#define RFLAGS_NT - -#define RFLAGS_RF 0x00010000 -#define RFLAGS_VM 0x00020000 -#define RFLAGS_AC 0x00040000 -#define RFLAGS_VIF 0x00080000 -#define RFLAGS_VIP -#define RFLAGS_ID +#define RFLAGS_AF 0x00000010 /* Adjust Flag */ +#define RFLAGS_ZF 0x00000040 /* Zero Flag */ +#define RFLAGS_SF 0x00000080 /* Sign Flag */ +#define RFLAGS_TF 0x00000100 /* Trap Flag */ +#define RFLAGS_IF 0x00000200 /* Interrupt Enable Flag */ +#define RFLAGS_DF 0x00000400 /* Direction Flag */ +#define RFLAGS_OF 0x00000800 /* Overflow Flag */ +// IOPL (bits 12-13) +#define RFLAGS_NT 0x00004000 /* Nested Task Flag */ +#define RFLAGS_RF 0x00010000 /* Resume Flag */ +#define RFLAGS_VM 0x00020000 /* Virtual 8086 Mode */ +#define RFLAGS_AC 0x00040000 /* Alignment Check */ +#define RFLAGS_VIF 0x00080000 /* Virtual Interrupt Flag */ +#define RFLAGS_VIP 0x00100000 /* Virtual Interrupt Pending */ +#define RFLAGS_ID 0x00200000 /* CPUID Supported */ /* * Debug Registers @@ -186,6 +185,12 @@ typedef struct PACKED TaskStateSegment64 { #define EFER_FFXSR 0x4000 /* Fast FXSAVE/FXRSTOR (AMD) */ #define EFER_TCE 0x8000 /* Translation Cache Extension (AMD) */ +// SYSCALL/SYSRET +#define MSR_STAR 0xC0000081 +#define MSR_LSTAR 0xC0000082 +#define MSR_CSTAR 0xC0000083 +#define MSR_SFMASK 0xC0000084 + #include "amd64op.h" #endif /* __AMD64_H__ */ diff --git a/sys/amd64/machine.c b/sys/amd64/machine.c index 4948c2c..9c97d7d 100644 --- a/sys/amd64/machine.c +++ b/sys/amd64/machine.c @@ -76,6 +76,11 @@ void Machine_SyscallInit() { kprintf("Initializing Syscall... "); + wrmsr(MSR_STAR, SEL_KCS << 32 | SEL_UCS << 48); + wrmsr(MSR_LSTAR, 0); + wrmsr(MSR_CSTAR, 0); + wrmsr(MSR_SFMASK, 0); + kprintf("Done!\n"); } diff --git a/sys/amd64/trap.h b/sys/amd64/trap.h index 282f3e9..ad4c2a4 100644 --- a/sys/amd64/trap.h +++ b/sys/amd64/trap.h @@ -2,25 +2,25 @@ #ifndef __TRAP_H__ #define __TRAP_H__ -#define T_DE 0 -#define T_DB 1 -#define T_NMI 2 -#define T_BP 3 -#define T_OF 4 -#define T_BR 5 -#define T_UD 6 -#define T_NM 7 -#define T_DF 8 -#define T_TS 10 -#define T_NP 11 -#define T_SS 12 -#define T_GP 13 -#define T_PF 14 -#define T_MF 16 -#define T_AC 17 -#define T_MC 18 -#define T_XF 19 -#define T_VE 20 +#define T_DE 0 /* Divide Error Exception */ +#define T_DB 1 /* Debug Exception */ +#define T_NMI 2 /* NMI Interrupt */ +#define T_BP 3 /* Breakpoint Exception */ +#define T_OF 4 /* Overflow Exception */ +#define T_BR 5 /* BOUND Range Exceeded Exception */ +#define T_UD 6 /* Invalid Opcode Exception */ +#define T_NM 7 /* Device Not Available Exception */ +#define T_DF 8 /* Double Fault Exception */ +#define T_TS 10 /* Invalid TSS Exception */ +#define T_NP 11 /* Segment Not Present */ +#define T_SS 12 /* Stack Fault Exception */ +#define T_GP 13 /* General Protection Exception */ +#define T_PF 14 /* Page-Fault Exception */ +#define T_MF 16 /* x87 FPU Floating-Point Error */ +#define T_AC 17 /* Alignment Check Exception */ +#define T_MC 18 /* Machine-Check Exception */ +#define T_XF 19 /* SIMB Floating-Point Exception */ +#define T_VE 20 /* Virtualization Exception */ #define T_CPU_LAST T_VE @@ -32,10 +32,14 @@ #define T_IRQ_KBD (T_IRQ_BASE + 1) #define T_IRQ_COM1 (T_IRQ_BASE + 4) #define T_IRQ_MOUSE (T_IRQ_BASE + 12) + +// LAPIC Special Vectors #define T_IRQ_SPURIOUS (T_IRQ_BASE + 24) #define T_IRQ_ERROR (T_IRQ_BASE + 25) #define T_IRQ_THERMAL (T_IRQ_BASE + 26) +#define T_SYSCALL 60 + #define T_MAX 64 typedef struct TrapFrame