fix: interrupt handler

This commit is contained in:
d0p1 🏳️‍⚧️ 2023-01-17 15:36:21 +01:00
parent 33d96c6d68
commit 067f09d6ca
7 changed files with 58 additions and 38 deletions

View file

@ -7,7 +7,7 @@ setup_gdt:
lgdt [gdt_ptr]
jmp 0x08:.flush_cs
.flush_cs:
mov ax, 0x10
mov ax, 0x10 ; data segment
mov ds, ax
mov es, ax
mov fs, ax
@ -23,20 +23,16 @@ gdt_ptr:
gdt_entries:
;; null descriptor
dw 0x0 ; limit
dw 0x0 ; base (low)
db 0x0 ; base (mid)
db 0x0 ; access
db 0x0 ; granularity
db 0x0 ; base (high)
dd 0x0
dd 0x0
;; kernel mode code segment
dw 0xFFFF
dw 0x00
db 0x00
db 0x9A
db 0xCF
db 0x00
dw 0xFFFF ; Limit
dw 0x00 ; Base (low)
db 0x00 ; Base (mid)
db 0x9A ; Access: 1 (P) 0 (DPL), 1 (S), 1010 (Type)
db 0xCF ; Granularity: 1 (G), 1 (D/B), 0 (AVL), Limit
db 0x00 ; Base (high)
;; kernel mode data segment
dw 0xFFFF

View file

@ -40,13 +40,14 @@ entry:
extern setup_idt
call setup_idt
int3
;extern setup_paging
;call setup_paging
int3
LOG file
cli
hang:
hlt
jmp hang

View file

@ -3,32 +3,40 @@ section .text
global setup_idt
setup_idt:
%assign i 0
%rep 32
extern isr %+ i
mov eax, isr %+ i
mov [idt_entries + i * 4], ax
shr eax, 16
mov word [idt_entries + i * 4 + 2], 0x8
mov byte [idt_entries + i * 4 + 5], 0x8E
mov [idt_entries + i * 4 + 6], ax
; offset (low)
mov word [idt_entries + (i * 8)], ax
; segment selector (kernel code)
mov word [idt_entries + (i * 8) + 2], 0x08
; zero (skip)
; attr: 1 (Present) 00 (DPL) 0 1 (D: 32bits) 110
mov byte [idt_entries + (i * 8) + 5], 0x8E
; offset (high)
shr eax, 16
mov word [idt_entries + (i * 8) + 6], ax
%assign i i+1
%rep 32
%endrep
lidt [idt_ptr]
sti
ret
section .data
align 8
idt_ptr:
dw 256 * 8
dw 255 * 8
dd idt_entries
align 8
idt_entries:
times 256 dd 0x00000000, 0x00000000
;; dw isr_low
;; dw kernel cs
;; dw offset (low)
;; dw segment selector
;; db zero
;; db attr
;; dw isr_high
;; db attr | P | DPL | 0 D 1 1 0 |
;; dw offset (high)
.end:

View file

@ -15,7 +15,6 @@ isr%1:
global isr%1
isr%1:
cli
push byte 1
push byte %1
jmp isr_handler
%endmacro
@ -69,6 +68,9 @@ isr_handler:
LOG msg_interrupt
extern pic_eoi
call pic_eoi
pop eax
mov ds, ax
mov es, ax

View file

@ -4,7 +4,7 @@ section .data
align 4096
page_directory:
times 1024 dd 0x00000002
times 1024 dd 0x00000000
section .text

View file

@ -1,24 +1,37 @@
[BITS 32]
PIC1_CMD equ 0x20
PIC1_DATA equ 0x21
PIC2_CMD equ 0xA0
PIC2_DATA equ 0xA1
section .text
global setup_pic
setup_pic:
mov al, 0x11
out 0x20, al
out 0xA0, al
out PIC1_CMD, al
out PIC2_CMD, al
mov al, 0x20
out 0x21, al
out PIC1_DATA, al
mov al, 0x28
out 0xA1, al
out PIC2_DATA, al
mov al, 4
out 0x21, al
out PIC1_DATA, al
mov al, 2
out 0xA1, al
out PIC2_DATA, al
; mask all
mov al, 0xFF
out 0x21, al
out 0xA1, al
out PIC1_DATA, al
out PIC2_DATA, al
ret
global pic_eoi
pic_eoi:
mov al, 0x20
out PIC2_CMD, al
out PIC1_CMD, al
ret

View file

@ -18,7 +18,7 @@ EOF
gen_iso_file() {
mkdir -p "$2/boot/grub"
echo "$grub_config" > "$2/boot/grub/grub.cfg"
sha256sum "$2"/vmstupid > "$2/boot/hashfile"
sha256sum vmstupid > "$2/boot/hashfile"
grub-mkrescue -o $1 $2
}