-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathirq.asm
99 lines (85 loc) · 2.25 KB
/
irq.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;;
;; (c) 2020 iomonad <clement@trosa.io>
;; This is part of the KFS Project
;; See: https://github.com/iomonad/KFS
;;
bits 32
;; Global Interrupt Table
;; assembly routine
global _idt_commit
_idt_commit:
mov eax, [esp+4] ; Load memory pointer
lidt [eax] ; Store IDT pointer on
ret
;;
;; Interrups implementations
;;
extern interrupt_handler ; High level Handler
;; IRQ Stub:
;; - Save processor state
;; - Setup kernel mode segment
;; - Call Highlevel C Handler
;; - Restore the stackframe
;;
interrupt_stub:
pusha ; Push all general purpose registers
mov ax, ds ; low 16bits eax
push eax ; save data segment descriptor
mov ax, 0x10 ; load the kernel data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call interrupt_handler ; C Implementations
pop eax ; Reload data segment descriptor
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
popa ; Pop all gener purpose registers
add esp, 8 ; Clean parameters
sti
;;
;; See: https://www.felixcloutier.com/x86/iret:iretd
;;
;; See the section titled “Task Linking” in Chapter 7 of
;; the Intel® 64 and IA-32 Architectures Software
;; Developer’s Manual, Volume 3A.
;;
iret ; Interrupt Return
;;
;; Routine Implementation
;;
%macro IRQ_NO_ERR 1
global irq%1
irq%1:
cli ; Clean Interrupt Flag
push byte 0
push byte %1 ; Push ID
jmp interrupt_stub
%endmacro
%macro IRQ_ERR 1
global irq%1
irq%1:
cli ; Clean Interrupt Flag
push byte %1 ; Push ID
jmp interrupt_stub
%endmacro
;; Create Interrupt here
IRQ_NO_ERR 0
IRQ_NO_ERR 1
IRQ_NO_ERR 2
IRQ_NO_ERR 3
IRQ_NO_ERR 4
IRQ_NO_ERR 5
IRQ_NO_ERR 6
IRQ_NO_ERR 7
IRQ_ERR 8
IRQ_NO_ERR 9
IRQ_ERR 10
IRQ_ERR 11
IRQ_ERR 12
IRQ_ERR 13
IRQ_ERR 14
IRQ_NO_ERR 15
IRQ_NO_ERR 16