From c34021e4d6279fb7d065eb04ce978bac6caee479 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 8 Feb 2025 20:13:30 -0300 Subject: [PATCH] context: irq --- kernel-src/arch/x86-64/context.asm | 2 ++ kernel-src/arch/x86-64/isr.asm | 3 +++ kernel-src/arch/x86-64/syscall.asm | 2 ++ kernel-src/include/x86-64/arch/context.h | 2 ++ 4 files changed, 9 insertions(+) diff --git a/kernel-src/arch/x86-64/context.asm b/kernel-src/arch/x86-64/context.asm index 671126f3..4835c9f2 100644 --- a/kernel-src/arch/x86-64/context.asm +++ b/kernel-src/arch/x86-64/context.asm @@ -27,6 +27,7 @@ arch_context_switch: pop r15 pop rdi pop rsi + add rsp,8 ; remove irq pop rbp add rsp,8 ; remove error code @@ -60,6 +61,7 @@ arch_context_saveandcall: push r11 ; return address sub rsp, 8 ; error code push rbp + sub rsp, 8 ; irq push rsi push rdi push r15 diff --git a/kernel-src/arch/x86-64/isr.asm b/kernel-src/arch/x86-64/isr.asm index f5d5b775..7dce6d33 100644 --- a/kernel-src/arch/x86-64/isr.asm +++ b/kernel-src/arch/x86-64/isr.asm @@ -10,6 +10,7 @@ isr_%+ i: push rbp ; this push is here to free a register mov rbp, i + jmp isr_common %assign i i + 1 %endrep @@ -21,6 +22,7 @@ isr_common: swapgs .notneeded1: ; push context + push rbp ; push irq num push rsi push rdi push r15 @@ -80,6 +82,7 @@ isr_common: pop r15 pop rdi pop rsi + add rsp,8 ; remove irq pop rbp add rsp,8 ; remove error code diff --git a/kernel-src/arch/x86-64/syscall.asm b/kernel-src/arch/x86-64/syscall.asm index e97ec479..5b683dfd 100644 --- a/kernel-src/arch/x86-64/syscall.asm +++ b/kernel-src/arch/x86-64/syscall.asm @@ -221,6 +221,7 @@ arch_syscall_entry: push qword rcx ; save return RIP push qword 0 ; error push rbp + push qword 0 ; irq push rsi push rdi push r15 @@ -315,6 +316,7 @@ arch_syscall_entry: pop r15 pop rdi pop rsi + add rsp, 8 ; remove irq pop rbp add rsp, 8 ; remove error code pop rcx diff --git a/kernel-src/include/x86-64/arch/context.h b/kernel-src/include/x86-64/arch/context.h index 79746168..fda9ca5c 100644 --- a/kernel-src/include/x86-64/arch/context.h +++ b/kernel-src/include/x86-64/arch/context.h @@ -28,6 +28,7 @@ typedef struct { uint64_t r15; uint64_t rdi; uint64_t rsi; + uint64_t irq; uint64_t rbp; uint64_t error; uint64_t rip; @@ -67,6 +68,7 @@ typedef struct { #define CTX_IP(x) (x)->rip #define CTX_RET(x) (x)->rax #define CTX_ERRNO(x) (x)->rdx +#define CTX_TRAP_ADDR(x) (x)->cr2 #define CTX_ARG0(x) (x)->rdi #define CTX_ARG1(x) (x)->rsi #define CTX_ARG2(x) (x)->rdx