StupidOS/kernel/idt.s

47 lines
791 B
ArmAsm
Raw Normal View History

2023-05-17 07:51:10 +00:00
; file: idt.s
;
2023-01-15 19:25:25 +00:00
[BITS 32]
section .text
global setup_idt
setup_idt:
2023-01-17 10:35:11 +00:00
%assign i 0
2023-01-17 14:36:21 +00:00
%rep 32
;; TODO: refactor
2023-01-17 10:35:11 +00:00
extern isr %+ i
mov eax, isr %+ i
2023-01-17 14:36:21 +00:00
; offset (low)
mov word [idt_entries + (i * 8)], ax
; segment selector (kernel code)
mov word [idt_entries + (i * 8) + 2], 0x08
2023-01-17 10:35:11 +00:00
2023-01-17 14:36:21 +00:00
; zero (skip)
; attr: 1 (Present) 00 (DPL) 0 1 (D: 32bits) 110
2023-05-22 12:01:20 +00:00
mov byte [idt_entries + (i * 8) + 5], 0x8F
2023-01-17 14:36:21 +00:00
; offset (high)
shr eax, 16
mov word [idt_entries + (i * 8) + 6], ax
2023-01-17 10:35:11 +00:00
%assign i i+1
%endrep
2023-01-17 14:36:21 +00:00
2023-01-15 19:25:25 +00:00
lidt [idt_ptr]
2023-01-17 10:35:11 +00:00
sti
2023-01-15 19:25:25 +00:00
ret
section .data
2023-01-17 14:36:21 +00:00
align 8
2023-01-15 19:25:25 +00:00
idt_ptr:
2023-05-17 07:51:10 +00:00
dw idt_entries.end-idt_entries-1
2023-01-15 19:25:25 +00:00
dd idt_entries
2023-05-17 07:51:10 +00:00
; variable: idt_entries
2023-01-17 14:36:21 +00:00
align 8
2023-01-15 19:25:25 +00:00
idt_entries:
times 256 dd 0x00000000, 0x00000000
2023-01-17 14:36:21 +00:00
;; dw offset (low)
;; dw segment selector
2023-01-17 10:35:11 +00:00
;; db zero
2023-01-17 14:36:21 +00:00
;; db attr | P | DPL | 0 D 1 1 0 |
;; dw offset (high)
2023-01-15 19:25:25 +00:00
.end: