summaryrefslogtreecommitdiff
path: root/kc/core/cpu/exceptions.S
diff options
context:
space:
mode:
authorAda Christine <adachristine18@gmail.com>2022-02-13 18:47:58 +0000
committerAda Christine <adachristine18@gmail.com>2022-02-13 18:47:58 +0000
commite8a76b2f6b53d99640ceb2850bf4e45118b923f1 (patch)
tree9e7ab33233883a2db2aa60393b66e6d526edbaf1 /kc/core/cpu/exceptions.S
parent78788acf026b21b516fd981d321b0809c07de921 (diff)
rudimentary irq and timer support
Diffstat (limited to 'kc/core/cpu/exceptions.S')
-rw-r--r--kc/core/cpu/exceptions.S50
1 files changed, 9 insertions, 41 deletions
diff --git a/kc/core/cpu/exceptions.S b/kc/core/cpu/exceptions.S
index 8a19c8c..087cf12 100644
--- a/kc/core/cpu/exceptions.S
+++ b/kc/core/cpu/exceptions.S
@@ -1,67 +1,35 @@
#include "exceptions.h"
+#include "interrupt.h"
.macro EXCEPTION_BEGIN vec:req, code=0
// just in case something tried to be clever before
cld
// push param registers
- push %rdi
+ ISR_STORE_PARAM_REGS
// store certain parameters
movb $\vec,%dil
- push %rsi
.if \code
- movq 16(%rsp), %rsi
+ movq ISR_PARAM_REGS_SIZE(%rsp), %rsi
.else
xor %rsi, %rsi
.endif
- push %rdx
- push %rcx
- push %r8
- push %r9
// caller-saved registers
- push %rax
- push %r10
- push %r11
+ ISR_STORE_CALLER_REGS
// callee-saved registers
- push %rbx
- push %rbp
- push %r12
- push %r13
- push %r14
- push %r15
+ ISR_STORE_CALLEE_REGS
.endm
.macro EXCEPTION_END vec:req, code=0
// restore all the registers
- pop %r15
- pop %r14
- pop %r13
- pop %r12
- pop %rbp
- pop %rbx
- pop %r11
- pop %r10
- pop %rax
- pop %r9
- pop %r8
- pop %rcx
- pop %rdx
- pop %rsi
- pop %rdi
+ ISR_RESTORE_CALLEE_REGS
+ ISR_RESTORE_CALLER_REGS
+ ISR_RESTORE_PARAM_REGS
.if \code
add $8, %rsp
.endif
iretq
.endm
-.macro EXCEPTION_CALL func
- // align the stack for the call to the handler function
- mov %rsp, %rbp
- and $-16, %rsp
- call \func
- // restore stack pointer, possibly unaligned
- mov %rbp, %rsp
-.endm
-
.macro EXCEPTION_DEFINE name:req, vec:req
\name\()_isr:
.if \vec > 9 && \vec < 15 || \vec == 17 || \vec == 21 || \vec > 28 && \vec < 31
@@ -69,7 +37,7 @@
.else
EXCEPTION_BEGIN \vec
.endif
- EXCEPTION_CALL \name\()_handler
+ ISR_CALL \name\()_handler
.if \vec > 9 && \vec < 15 || \vec == 17 || \vec == 21 || \vec > 28 && \vec < 31
EXCEPTION_END \vec, 1
.else