BarryServer : Git

All the code for all my projects
// BarryServer : Git / Orion / commit / d41a53cbc7d055b1c00cf0a339dbed6925f4f02c / proc / stub.S

// Related

Orion

Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)
diff --git a/proc/stub.S b/proc/stub.S
new file mode 100644
index 0000000..a16d014
--- /dev/null
+++ b/proc/stub.S
@@ -0,0 +1,149 @@
+; This file contains the stubs for the interrupt handlers, which can push more
+; useful information on the the stack, before calling a generic handler.  Since
+; each exception/interrupt must have it's own handler, macros are used to create
+; a handler for each of them.
+
+[bits 32]
+
+[extern irq_handler]
+[extern exc_handler]
+
+; Exception without error code
+%macro EXC_NOERRCODE 1
+[global exc%1]
+exc%1:
+	cli
+	push byte 0
+	push %1
+	jmp exc_stub
+%endmacro
+
+; Exception with error code
+%macro EXC_ERRCODE 1
+[global exc%1]
+exc%1:
+	cli
+	push %1
+	jmp exc_stub
+%endmacro
+
+; Interrupt
+%macro IRQ 2
+[global irq%1]
+irq%1:
+	cli
+	push byte 0
+	push byte %2
+	jmp irq_stub
+%endmacro
+
+EXC_NOERRCODE 0
+EXC_NOERRCODE 1
+EXC_NOERRCODE 2
+EXC_NOERRCODE 3
+EXC_NOERRCODE 4
+EXC_NOERRCODE 5
+EXC_NOERRCODE 6
+EXC_NOERRCODE 7
+EXC_ERRCODE   8
+EXC_NOERRCODE 9
+EXC_ERRCODE   10
+EXC_ERRCODE   11
+EXC_ERRCODE   12
+EXC_ERRCODE   13
+EXC_ERRCODE   14
+EXC_NOERRCODE 15
+EXC_NOERRCODE 16
+EXC_ERRCODE   17
+EXC_NOERRCODE 18
+EXC_NOERRCODE 19
+EXC_NOERRCODE 20
+EXC_NOERRCODE 30
+EXC_NOERRCODE 128 ; syscall
+
+IRQ  0, 32
+IRQ  1, 33
+IRQ  2, 34
+IRQ  3, 35
+IRQ  4, 36
+IRQ  5, 37
+IRQ  6, 38
+IRQ  7, 39
+IRQ  8, 40
+IRQ  9, 41
+IRQ 10, 42
+IRQ 11, 43
+IRQ 12, 44
+IRQ 13, 45
+IRQ 14, 46
+IRQ 15, 47
+
+; Handle an exception
+exc_stub:
+	pusha
+	mov ax, gs
+	push eax
+	mov ax, fs
+	push eax
+	mov ax, ds
+	push eax
+
+	mov ax, 0x10
+	mov ds, ax
+	mov es, ax
+	mov fs, ax
+	mov gs, ax
+
+	call exc_handler
+
+	pop ebx
+	mov ds, bx
+	mov es, bx
+	pop ebx
+	mov fs, bx
+	pop ebx
+	mov gs, bx
+
+	mov ecx, 0xC0000101
+	xor edx, edx
+	wrmsr
+
+	popa
+	add esp, 8
+	sti
+	iret
+
+; Handle an interrupt
+irq_stub:
+	pusha
+	mov ax, gs
+	push eax
+	mov ax, fs
+	push eax
+	mov ax, ds
+	push eax
+
+	mov ax, 0x10
+	mov ds, ax
+	mov es, ax
+	mov fs, ax
+	mov gs, ax
+
+	call irq_handler
+
+	pop ebx
+	mov ds, bx
+	mov es, bx
+	pop ebx
+	mov fs, bx
+	pop ebx
+	mov gs, bx
+
+	mov ecx, 0xC0000101
+	xor edx, edx
+	wrmsr
+
+	popa
+	add esp, 8
+	sti
+	iret