Start working on rom-based kernel

This commit is contained in:
Nero 2020-05-29 00:32:30 +02:00
parent 04a7087d79
commit 65564b78af
3 changed files with 141 additions and 0 deletions

70
kernel/intr.asm Normal file
View file

@ -0,0 +1,70 @@
; Get pointer to interrupt vector
; IN al number
; OUT 0:bx ptr to vector
intr_ptr:
xor bh, bh
mov bl, al
add bx, bx
add bx, bx
ret
; Set interrupt vector
; IN al number
; ds:dx ptr
intr_set:
push bx
call intr_ptr
ss mov [bx], dx
ss mov [bx+2], ds
pop bx
ret
; Get interrupt vector
; IN al number
; OUT es:bx ptr
intr_get:
call intr_ptr
ss mov es, [bx+2]
ss mov bx, [bx]
ret
; Save BIOS vectors
; Trashes ax, cx, bx, ds
intr_backup:
mov cx, 0x20
xor bx, bx
mov ds, bx
.loop: ; load segment
mov ax, [bx+2]
; skip transfer if not pointing to BIOS
cmp ax, 0xA000
jc .skip
; store segment
mov [bx+ivt2+2], ax
; copy offset
mov ax, [bx]
mov [bx+ivt2], ax
; iterate to next vector
.skip: add bx, 4
loop .loop
ret
; Restore BIOS vectors
intr_restore:
mov cx, 0x20
xor bx, bx
mov ds, bx
.loop: ; load segment
mov ax, [bx+ivt2+2]
; skip if not a vector to BIOS
cmp ax, 0xA000
jc .skip
; store segment
mov [bx+2], ax
; copy offset
mov ax, [bx+ivt2]
mov [bx], ax
; iterate to next vector
.skip: add bx, 4
loop .loop
ret