MushOS  0.1
A UNIX-like OS prototype, written from scratch
Loading...
Searching...
No Matches
interruptions.asm
1[bits 32]
2global idt_flush
3extern isr_handler
4extern irq_handler
5
6idt_flush:
7 push ebp
8 mov ebp, esp
9
10 mov eax, [ebp+8] ; Get the pointer to the IDT, passed as a parameter.
11 lidt [eax] ; Load the IDT pointer.
12 sti
13
14 mov esp, ebp
15 pop ebp
16 ret
17
18
19
20%macro ISR_NO_ERROR_CODE 1 ; define a macro, taking one parameter
21 global isr%1 ; %1 accesses the first parameter.
22 isr%1:
23 push byte 0
24 push byte %1
25 jmp isr_common
26%endmacro
27
28%macro ISR_ERROR_CODE 1
29 global isr%1
30 isr%1:
31 push byte %1
32 jmp isr_common
33%endmacro
34
35%macro IRQ 2
36 global irq%1
37 irq%1:
38 push byte 0
39 push byte %2
40 jmp irq_common
41%endmacro
42
43ISR_NO_ERROR_CODE 0
44ISR_NO_ERROR_CODE 1
45ISR_NO_ERROR_CODE 2
46ISR_NO_ERROR_CODE 3
47ISR_NO_ERROR_CODE 4
48ISR_NO_ERROR_CODE 5
49ISR_NO_ERROR_CODE 6
50ISR_NO_ERROR_CODE 7
51ISR_ERROR_CODE 8
52ISR_NO_ERROR_CODE 9
53ISR_ERROR_CODE 10
54ISR_ERROR_CODE 11
55ISR_ERROR_CODE 12
56ISR_ERROR_CODE 13
57ISR_ERROR_CODE 14
58ISR_NO_ERROR_CODE 15
59ISR_NO_ERROR_CODE 16
60ISR_ERROR_CODE 17
61ISR_NO_ERROR_CODE 18
62ISR_NO_ERROR_CODE 19
63ISR_NO_ERROR_CODE 20
64ISR_ERROR_CODE 21
65ISR_NO_ERROR_CODE 22
66ISR_NO_ERROR_CODE 23
67ISR_NO_ERROR_CODE 24
68ISR_NO_ERROR_CODE 25
69ISR_NO_ERROR_CODE 26
70ISR_NO_ERROR_CODE 27
71ISR_NO_ERROR_CODE 28
72ISR_NO_ERROR_CODE 29
73ISR_NO_ERROR_CODE 30
74ISR_NO_ERROR_CODE 31
75
76ISR_NO_ERROR_CODE 32
77
78IRQ 0, 32
79IRQ 1, 33
80IRQ 2, 34
81IRQ 3, 35
82IRQ 4, 36
83IRQ 5, 37
84IRQ 6, 38
85IRQ 7, 39
86IRQ 8, 40
87IRQ 9, 41
88IRQ 10, 42
89IRQ 11, 43
90IRQ 12, 44
91IRQ 13, 45
92IRQ 14, 46
93IRQ 15, 47
94
95
96
97ISR_NO_ERROR_CODE 48
98ISR_NO_ERROR_CODE 49
99ISR_NO_ERROR_CODE 50
100ISR_NO_ERROR_CODE 51
101ISR_NO_ERROR_CODE 52
102
103
104
105; This is our common ISR stub. It saves the processor state, sets
106; up for kernel mode segments, calls the C-level fault handler,
107; and finally restores the stack frame.
108isr_common:
109 pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
110
111 mov ax, ds ; Lower 16-bits of eax = ds.
112 push eax ; save the data segment descriptor
113
114 mov ax, 0x10 ; load the kernel data segment descriptor
115 mov ds, ax
116 mov es, ax
117 mov fs, ax
118 mov gs, ax
119
120 push esp
121
122 call isr_handler
123
124 pop eax
125
126 pop eax ; reload the original data segment descriptor
127 mov ds, ax
128 mov es, ax
129 mov fs, ax
130 mov gs, ax
131
132 popa ; Pops edi,esi,ebp...
133 add esp, 8 ; Cleans up the pushed error code and pushed ISR number
134 iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP
135
136
137
138; This is our common IRQ stub. It saves the processor state, sets
139; up for kernel mode segments, calls the C-level fault handler,
140; and finally restores the stack frame.
141irq_common:
142 pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax
143
144 mov ax, ds ; Lower 16-bits of eax = ds.
145 push eax ; save the data segment descriptor
146
147 mov ax, 0x10 ; load the kernel data segment descriptor
148 mov ds, ax
149 mov es, ax
150 mov fs, ax
151 mov gs, ax
152
153 push esp
154
155 call irq_handler
156
157 pop ebx
158
159 pop ebx ; reload the original data segment descriptor
160 mov ds, bx
161 mov es, bx
162 mov fs, bx
163 mov gs, bx
164
165 popa ; Pops edi,esi,ebp...
166 add esp, 8 ; Cleans up the pushed error code and pushed ISR number
167 iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP