From 52760e9c5e677b76c81e921bbab95da26478f425 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 2 Jul 2024 21:15:01 -0400 Subject: kernel/amd64: Add INTRENTRY() and TRAPENTRY() Add macros that perform certain operations before invoking the actual handler. This will be useful in the future for more complicated operations that need to be done before the handler is ran. Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/lapic_intr.S | 8 ++-- sys/arch/amd64/amd64/trap.S | 99 +++++---------------------------------- sys/include/arch/amd64/frameasm.h | 24 ++++++++++ 3 files changed, 39 insertions(+), 92 deletions(-) diff --git a/sys/arch/amd64/amd64/lapic_intr.S b/sys/arch/amd64/amd64/lapic_intr.S index e0d16de..f19480c 100644 --- a/sys/arch/amd64/amd64/lapic_intr.S +++ b/sys/arch/amd64/amd64/lapic_intr.S @@ -31,10 +31,8 @@ .text .globl lapic_tmr_isr -lapic_tmr_isr: - push_trapframe $0 - mov %rsp, %rdi +INTRENTRY(lapic_tmr_isr, handle_lapic_tmr) +handle_lapic_tmr: call sched_switch call lapic_eoi - pop_trapframe - iretq + retq diff --git a/sys/arch/amd64/amd64/trap.S b/sys/arch/amd64/amd64/trap.S index fb3ca77..ce70138 100644 --- a/sys/arch/amd64/amd64/trap.S +++ b/sys/arch/amd64/amd64/trap.S @@ -30,114 +30,39 @@ #include #include -.macro handle_trap - mov %rsp, %rdi - call trap_handler -.endm - .text .globl breakpoint_handler -breakpoint_handler: - push_trapframe_ec $TRAP_BREAKPOINT - - handle_trap - - cli - hlt +TRAPENTRY(breakpoint_handler, $TRAP_BREAKPOINT) .globl arith_err -arith_err: - push_trapframe_ec $TRAP_ARITH_ERR - - handle_trap - - cli - hlt +TRAPENTRY(arith_err, $TRAP_ARITH_ERR) .globl overflow -overflow: - push_trapframe_ec $TRAP_OVERFLOW - - handle_trap - - cli - hlt +TRAPENTRY(overflow, $TRAP_OVERFLOW) .globl bound_range -bound_range: - push_trapframe_ec $TRAP_BOUND_RANGE - - handle_trap - - cli - hlt +TRAPENTRY(bound_range, $TRAP_BOUND_RANGE) .globl invl_op -invl_op: - push_trapframe_ec $TRAP_INVLOP - - handle_trap - - cli - hlt +TRAPENTRY(invl_op, $TRAP_INVLOP) .globl double_fault -double_fault: - push_trapframe_ec $TRAP_DOUBLE_FAULT - - handle_trap - - cli - hlt +TRAPENTRY(double_fault, $TRAP_DOUBLE_FAULT) .globl invl_tss -invl_tss: - push_trapframe_ec $TRAP_INVLTSS - - handle_trap - - cli - hlt +TRAPENTRY(invl_tss, $TRAP_INVLTSS) .globl segnp -segnp: - push_trapframe_ec $TRAP_SEGNP - - handle_trap - - cli - hlt +TRAPENTRY(segnp, $TRAP_SEGNP) .globl general_prot -general_prot: - push_trapframe_ec $TRAP_PROTFLT - - handle_trap - - cli - hlt +TRAPENTRY(general_prot, $TRAP_PROTFLT) .globl page_fault -page_fault: - push_trapframe_ec $TRAP_PAGEFLT - - handle_trap - cli - hlt +TRAPENTRY(page_fault, $TRAP_PAGEFLT) .globl nmi -nmi: - push_trapframe_ec $TRAP_NMI - - handle_trap - - cli - hlt +TRAPENTRY(nmi, $TRAP_NMI) .globl ss_fault -ss_fault: - push_trapframe_ec $TRAP_SS - - handle_trap - cli - hlt +TRAPENTRY(ss_fault, $TRAP_SS) diff --git a/sys/include/arch/amd64/frameasm.h b/sys/include/arch/amd64/frameasm.h index b6d4f39..b8791ba 100644 --- a/sys/include/arch/amd64/frameasm.h +++ b/sys/include/arch/amd64/frameasm.h @@ -100,4 +100,28 @@ pop_trapframe_ec add $8, %rsp /* Pop error code */ .endm + +/* + * Generic interrupt entry. + */ +#define INTRENTRY(ENTLABEL, HANDLER) \ + ENTLABEL: \ + push_trapframe $0 ; \ + mov %rsp, %rdi ; \ + call HANDLER ; \ + pop_trapframe ; \ + iretq + +/* + * Trap entry where an error code is on + * the stack. + */ +#define TRAPENTRY(ENTLABEL, TRAPNO) \ + ENTLABEL: \ + push_trapframe_ec TRAPNO ; \ + mov %rsp, %rdi ; \ + call trap_handler ; \ + pop_trapframe_ec ; \ + iretq + #endif /* !_MACHINE_FRAMEASM_H_ */ -- cgit v1.2.3