summaryrefslogtreecommitdiffhomepage
path: root/Kernel/HALKit/AMD64/HalInterruptAPI.asm
blob: e40633884eada52e6ef591d658199df22db1e7ad (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
;; /*
;; *    ---------------------------------------------------
;; *
;; * 	Copyright SoftwareLabs, all rights reserved.
;; *
;; *    File: HalInterruptAPI.asm
;; *    Purpose: Interrupt routing, redirect raw interrupts into their handlers.
;; *
;; *    ---------------------------------------------------
;; */

[bits 64]

%define kInterruptId 0x21

%macro IntExp 1
global __HCR_INT_%1 
__HCR_INT_%1:
    cld

    iretq
%endmacro

%macro IntNormal 1
global __HCR_INT_%1 
__HCR_INT_%1:
    cld

    iretq
%endmacro

; This file handles the core interrupt table
; Last edited 31/01/24

global _ke_power_on_self_test
global ke_handle_irq
global kInterruptVectorTable

extern _hal_handle_mouse
extern idt_handle_gpf
extern idt_handle_pf
extern ke_io_write
extern idt_handle_ud

section .text

IntNormal 0
IntNormal 1

IntNormal 2

IntNormal 3
IntNormal 4
IntNormal 5

;; Invalid opcode interrupt
__HCR_INT_6:
    cli

    push rax

    mov rcx, rsp
    call idt_handle_ud

    pop rax

    sti
    iretq

IntNormal 7
IntExp   8
IntNormal 9
IntExp   10
IntExp   11

IntExp 12

__HCR_INT_13:
    cli

    push rax

    mov rcx, rsp
    call idt_handle_gpf

    pop rax

    sti
    iretq

__HCR_INT_14:
    cli

    push rax

    mov rcx, rsp
    call idt_handle_pf

    pop rax

    sti
    iretq
    
IntNormal 15
IntNormal 16
IntExp 17
IntNormal 18
IntNormal 19
IntNormal 20
IntNormal 21
IntNormal 22
IntNormal 23
IntNormal 24
IntNormal 25
IntNormal 26
IntNormal 27
IntNormal 28
IntNormal 29
IntExp   30

IntNormal 31

IntNormal 32

IntNormal 33

IntNormal 34
IntNormal 35
IntNormal 36
IntNormal 37
IntNormal 38
IntNormal 39
IntNormal 40
IntNormal 41
IntNormal 42
IntNormal 43

__HCR_INT_44:
    cli

    ;; TODO: CoreEvents dispatch routine.

    push rax
    call _hal_handle_mouse
    pop rax

    sti
    iretq

IntNormal 45
IntNormal 46
IntNormal 47
IntNormal 48
IntNormal 49

__HCR_INT_50:
    cli

    ;; todo handle system calls.

    sti
    iretq

IntNormal 51
IntNormal 52
IntNormal 53
IntNormal 54
IntNormal 55
IntNormal 56
IntNormal 57
IntNormal 58
IntNormal 59
IntNormal 60

%assign i 61
%rep 195
    IntNormal i
%assign i i+1
%endrep

;; this one is doing a POST for us.
;; testing interrupts.
_ke_power_on_self_test:
    int 0x32
    int 0x32
    int 0x32
    int 0x32

    ret

[global hal_load_gdt]

hal_load_gdt:
    lgdt [rcx]
    push 0x08
    lea rax, [rel rt_reload_segments]
    push rax
    retfq
rt_reload_segments:
    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax
    ret

global hal_load_idt

hal_load_idt:
    lidt [rcx]
    sti
    ret

section .data

kInterruptVectorTable:
    %assign i 0
    %rep 256
        dq __HCR_INT_%+i
    %assign i i+1
    %endrep