x86 stuff

This commit is contained in:
2026-10-14 00:02:13 +02:00
parent deec8099cb
commit f9a456b09d
4 changed files with 30 additions and 3 deletions
+1
View File
@@ -240,6 +240,7 @@ static struct idt_entry idt[256] = {};
void idt_init() {
REPEAT_256(INTERRUPT_SETUP)
idt[IDT_BP].attrib |= CPL_USER << 5;
}
void idt_load() {
+6
View File
@@ -37,6 +37,7 @@ struct arch_context {
};
#define ARCH_CTX_NUM rax
#define ARCH_CTX_SP rsp
#define ARCH_CTX_A0 rdi
#define ARCH_CTX_A1 rsi
#define ARCH_CTX_A2 rdx
@@ -45,3 +46,8 @@ struct arch_context {
#define ARCH_CTX_A5 r9
#define ARCH_CTX_RET0 rax
#define ARCH_CTX_RET1 rdx
struct arch_syscall_restart {
uint64_t rax;
uint64_t rdx;
};
+6
View File
@@ -40,6 +40,12 @@ static inline void asm_wrxcr(uint32_t reg, uint64_t val) {
asm volatile("xsetbv" ::"a"(eax), "d"(edx), "c"(reg) : "memory");
}
static inline uint64_t asm_rdxcr(uint32_t reg) {
uint32_t eax, edx;
asm volatile("xgetbv" : "=a"(eax), "=d"(edx) : "c"(reg));
return ((uint64_t)edx << 32) | eax;
}
// Saves the FPU state to a 512-byte region of memory using FXSAVE.
// Pointer must be 16-byte aligned.
static inline void asm_fxsave(void* mem) {
+17 -3
View File
@@ -206,6 +206,20 @@
#define CPL_USER (0x3)
#define CPL_KERNEL (0x0)
#define IDT_PF (0xE)
#define IDT_SPURIOUS (0xFE)
#define IDT_IPI_RESCHED (0xFF)
#define IDT_DE (0x0)
#define IDT_DB (0x1)
#define IDT_BP (0x3)
#define IDT_OF (0x4)
#define IDT_BR (0x5)
#define IDT_UD (0x6)
#define IDT_NM (0x7)
#define IDT_SS (0xC)
#define IDT_GP (0xD)
#define IDT_PF (0xE)
#define IDT_MF (0x10)
#define IDT_AC (0x11)
#define IDT_XM (0x13)
#define IDT_IPI_SHOOTDOWN (0xFC)
#define IDT_TIMER (0xFD)
#define IDT_SPURIOUS (0xFE)
#define IDT_IPI_RESCHED (0xFF)