summaryrefslogtreecommitdiff
path: root/sys/include/arch
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2023-12-17 20:24:15 -0500
committerIan Moffett <ian@osmora.org>2023-12-17 20:24:15 -0500
commit8bfb0c8da5b224ebfd4118aad94a68a4c240e344 (patch)
treeb7e02ddd733215df9a9c0cf8072b1a1bc9d18757 /sys/include/arch
parenta7aac6787783f3f5920aec00245141834b859d69 (diff)
kernel/amd64: trap: Fix stack issues
This fixes a bug relating to a lack of error code (pushed by hardware) misaligning the stack. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/include/arch')
-rw-r--r--sys/include/arch/amd64/frameasm.h46
1 files changed, 31 insertions, 15 deletions
diff --git a/sys/include/arch/amd64/frameasm.h b/sys/include/arch/amd64/frameasm.h
index bf02d00..2d251e7 100644
--- a/sys/include/arch/amd64/frameasm.h
+++ b/sys/include/arch/amd64/frameasm.h
@@ -31,21 +31,13 @@
#define _AMD64_FRAMEASM_H_
/*
- * XXX: Before this macro is invoked,
- * you should determine if an error
- * code will be present already on the
- * stack. If not, push a null qword as
- * padding (e.g push $0).
- *
- * There *must* be a value used
- * as an error code whether that be
- * a real error code or just padding.
- *
- * Failing to do so will result in
- * undefined behaviour.
+ * If the interrupt has an error code, this macro shall
+ * be used to create the trapframe.
*
+ * XXX: A trapframe created with this must be popped with
+ * pop_trapframe_ec
*/
-.macro push_trapframe trapno
+.macro push_trapframe_ec trapno
push %r15
push %r14
push %r13
@@ -64,7 +56,11 @@
push \trapno
.endm
-.macro pop_trapframe
+/*
+ * If the interrupt has an error code, this macro shall
+ * be used to cleanup the trapframe.
+ */
+.macro pop_trapframe_ec
add $8, %rsp /* Trapno */
pop %rax
pop %rcx
@@ -80,7 +76,27 @@
pop %r13
pop %r14
pop %r15
+.endm
+
+/*
+ * If the interrupt has no error code, this macro
+ * shall be used to create the trapframe.
+ *
+ * XXX: A trapframe created with this must be popped
+ * with pop_trapframe
+ */
+.macro push_trapframe trapno
+ push $0
+ push_trapframe_ec \trapno
+.endm
+
+
+/*
+ * If the interrupt has no error code, this macro shall
+ * be used to cleanup the trapframe.
+ */
+.macro pop_trapframe
+ pop_trapframe_ec
add $8, %rsp /* Pop error code */
- iretq
.endm
#endif /* !_AMD64_FRAMEASM_H_ */