BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / d46e09a34ca8cd546f3a4312976cf3b6a5a55ccf / kernel / isr.S

// Related

Nucleus

Barry Improved context switching and interrupt handling d46e09a (3 years, 2 months ago)
diff --git a/kernel/isr.S b/kernel/isr.S
new file mode 100644
index 0000000..c807e7b
--- /dev/null
+++ b/kernel/isr.S
@@ -0,0 +1,94 @@
+/*
+ * This file contains the interrupt service routine stubs.  For the most part
+ * they just call into the generic handlers after setting up the stack for them.
+ */
+
+.extern isr_handler
+
+/* Exception with an error */
+.macro exc_err num
+.globl exc\num
+exc\num:
+	cli
+	push $\num
+	jmp isr_stub
+.endm
+/* Exception without an error */
+.macro exc_noerr num
+.globl exc\num
+exc\num:
+	cli
+	push $0
+	push $\num
+	jmp isr_stub
+.endm
+
+/* Exceptions */
+EXC_NOERR 0
+EXC_NOERR 1
+EXC_NOERR 2
+EXC_NOERR 3
+EXC_NOERR 4
+EXC_NOERR 5
+EXC_NOERR 6
+EXC_NOERR 7
+EXC_ERR   8
+EXC_NOERR 9
+EXC_ERR   10
+EXC_ERR   11
+EXC_ERR   12
+EXC_ERR   13
+EXC_ERR   14
+EXC_NOERR 15
+EXC_NOERR 16
+EXC_ERR   17
+EXC_NOERR 18
+EXC_NOERR 19
+EXC_NOERR 20
+EXC_NOERR 30
+/* Interrupts */
+EXC_NOERR 32
+EXC_NOERR 33
+EXC_NOERR 34
+EXC_NOERR 35
+EXC_NOERR 36
+EXC_NOERR 37
+EXC_NOERR 38
+EXC_NOERR 39
+EXC_NOERR 40
+EXC_NOERR 41
+EXC_NOERR 42
+EXC_NOERR 43
+EXC_NOERR 44
+EXC_NOERR 45
+EXC_NOERR 46
+EXC_NOERR 47
+/* System Call */
+EXC_NOERR 128
+
+/* Generic ISR stub */
+isr_stub:
+	pusha
+	mov %ds, %ax
+	pushl %eax
+
+	/* Switch to kernel segments */
+	mov $0x10, %ax
+	mov %ax, %ds
+	mov %ax, %es
+	mov %ax, %fs
+	mov %ax, %gs
+
+	call isr_handler
+
+	/* Restore original segments */
+	popl %ebx
+	mov %bx, %ds
+	mov %bx, %es
+	mov %bx, %fs
+	mov %bx, %gs
+
+	popa
+	addl $8, %esp
+	sti
+	iret