From 2d6b898c497836dbf0eb20b262fc41fbdb8f0d01 Mon Sep 17 00:00:00 2001 From: pointer-to-bios Date: Sat, 27 Apr 2024 19:03:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E4=B8=AD=E6=96=AD=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=87=8D=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/kernel/arch/x86_64/interrupt.in | 4 ++++ src/kernel/arch/x86_64/interrupt_x86_64.s | 27 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/kernel/arch/x86_64/interrupt.in b/src/kernel/arch/x86_64/interrupt.in index 9d9e9bf..1382588 100644 --- a/src/kernel/arch/x86_64/interrupt.in +++ b/src/kernel/arch/x86_64/interrupt.in @@ -51,7 +51,10 @@ add rsp, 4 %endmacro +; 此处的cli在进入rust的中断处理函数后才会对应sti +; 因为在保存栈帧前中断不可以被打断 %macro interrupt_entry_enter 0 + cli push rbp lea rbp, [rsp] store_regs @@ -62,6 +65,7 @@ retrieve_section retrieve_regs leave + sti %endmacro ; 用于带有错误码的中断,创建一个没有错误码的上下文拷贝 diff --git a/src/kernel/arch/x86_64/interrupt_x86_64.s b/src/kernel/arch/x86_64/interrupt_x86_64.s index 5ca55b7..5fb0bcc 100644 --- a/src/kernel/arch/x86_64/interrupt_x86_64.s +++ b/src/kernel/arch/x86_64/interrupt_x86_64.s @@ -9,3 +9,30 @@ interrupt_open: interrupt_close: cli ret + + global interrupt_rust_enter + extern TSS +; usize interrupt_rust_enter() +; 返回值用于为寄存器rax占位 +interrupt_rust_enter: + ; *(rsp - 8) = *(TSS + 36) + mov rax, [TSS + 36] + mov qword [rsp - 8], rax + ; *(TSS + 36) = rsp - 8 + mov rax, TSS + lea rax, [rax + 36] + mov [rax], rsp + sub qword [rax], 8 + sti + ret + + global interrupt_rust_leave + extern TSS +; usize interrupt_rust_leave() +; 返回值用于为寄存器rax占位 +interrupt_rust_leave: + cli + ; *(TSS + 36) = *(rsp - 8) + mov rax, [rsp - 8] + mov [TSS + 36], rax + ret