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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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