2022-09-14 21:54:59 -05:00
|
|
|
extern unhandled_handler
|
|
|
|
unhandled_handler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | 'E' | 'R' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'R' | 'O' << 16
|
|
|
|
mov dword [0xb8008], 0x0f000f00 | 'R' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
|
2023-01-31 21:26:43 -06:00
|
|
|
global pageFaultHandler
|
|
|
|
pageFaultHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
pop eax ; error code
|
|
|
|
mov ebx, 0x0f000f00 | '0' | '!' << 16
|
|
|
|
and eax, 0x7 ; U/S,R/W,P
|
|
|
|
add ebx, eax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | 'P' | 'G' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'F' | 'L' << 16
|
|
|
|
mov dword [0xb8008], 0x0f000f00 | 'T' | ':' << 16
|
|
|
|
mov dword [0xb800C], ebx
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
|
2022-09-14 21:54:59 -05:00
|
|
|
extern gpf_handler_v86
|
|
|
|
global gpfHandler
|
|
|
|
gpfHandler:
|
2022-09-16 17:07:27 -05:00
|
|
|
push eax
|
2022-09-14 21:54:59 -05:00
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
2022-09-16 17:07:27 -05:00
|
|
|
mov eax, dword [esp+16] ; EFLAGS
|
|
|
|
and eax, 1 << 17 ; VM flag
|
|
|
|
test eax, eax
|
|
|
|
pop eax
|
|
|
|
jnz gpf_handler_v86
|
2022-09-18 00:30:24 -05:00
|
|
|
jmp gpf_handler_32
|
|
|
|
gpf_unhandled:
|
2022-09-17 16:31:41 -05:00
|
|
|
mov dword [0xb8000], 0x0f000f00 | 'G' | 'P' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'F' | '!' << 16
|
2022-09-14 21:54:59 -05:00
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
|
2022-09-18 00:30:24 -05:00
|
|
|
gpf_handler_32:
|
|
|
|
push eax
|
|
|
|
mov eax, dword [esp+8] ; EIP
|
|
|
|
movzx eax, word [eax]
|
|
|
|
cmp eax, 0x30CD ; int 0x30
|
|
|
|
jne gpf_unhandled
|
|
|
|
pop eax ; return value
|
2022-09-19 16:06:01 -05:00
|
|
|
jmp return_prev_task
|
|
|
|
|
|
|
|
extern return_prev_task
|
2022-09-18 00:30:24 -05:00
|
|
|
|
2022-09-14 21:54:59 -05:00
|
|
|
scancodesToAscii: db 0, 0 ; 0x00 - 0x01
|
|
|
|
db "1234567890" ; 0x02 - 0x0B
|
|
|
|
db "-=" ; 0x0C - 0x0D
|
|
|
|
db 0, 0 ; 0x0E - 0x0F
|
|
|
|
db "qwertyuiop[]" ; 0x10 - 0x1B
|
|
|
|
db 0, 0 ; 0x1C - 0x1D
|
|
|
|
db "asdfghjkl;'`" ; 0x1E - 0x29
|
|
|
|
db 0 ; 0x2A
|
|
|
|
db "\zxcvbnm,./" ; 0x2B - 0x35
|
|
|
|
db 0 ; 0x36
|
|
|
|
db '*' ; 0x37
|
|
|
|
db 0 ; 0x38
|
|
|
|
db ' ' ; 0x39
|
|
|
|
db 'C'
|
|
|
|
scancodesToAsciiEnd:
|
|
|
|
cursorCurrent: dd 0xb8000 + (80*6*2)
|
|
|
|
global keyboardHandler
|
|
|
|
keyboardHandler:
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ds
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
xor eax, eax
|
|
|
|
in al, 0x60
|
|
|
|
cmp eax, 0x3A
|
|
|
|
jg .done
|
|
|
|
mov al, [scancodesToAscii+eax]
|
|
|
|
test al, al
|
|
|
|
jz .done
|
|
|
|
mov ebx, [cursorCurrent]
|
|
|
|
mov byte [ebx], al
|
|
|
|
add dword [cursorCurrent], 2
|
|
|
|
mov byte [KBDWAIT], 1
|
|
|
|
.done:
|
|
|
|
mov al, 0x20
|
|
|
|
out 0x20, al
|
|
|
|
pop ds
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
iret
|
|
|
|
|
|
|
|
KBDWAIT: db 0
|
|
|
|
global kbd_wait
|
|
|
|
kbd_wait:
|
|
|
|
mov byte [KBDWAIT], 0
|
|
|
|
.loop:
|
|
|
|
hlt
|
2022-09-16 17:07:27 -05:00
|
|
|
movzx eax, byte [KBDWAIT]
|
2022-09-14 21:54:59 -05:00
|
|
|
test eax, eax
|
|
|
|
jz .loop
|
|
|
|
ret
|
|
|
|
|
|
|
|
global timerHandler
|
|
|
|
timerHandler:
|
|
|
|
push eax
|
|
|
|
push ds
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
inc byte [(0xb8000 + (80*8*2))]
|
|
|
|
mov al, 0x20
|
|
|
|
out 0x20, al
|
|
|
|
pop ds
|
|
|
|
pop eax
|
|
|
|
iret
|
|
|
|
|
|
|
|
global picInit
|
|
|
|
picInit:
|
|
|
|
mov al, 0x11 ; initialization sequence
|
|
|
|
out 0x20, al ; send to 8259A-1
|
|
|
|
jmp $+2
|
|
|
|
jmp $+2
|
|
|
|
out 0xA0, al ; and to 8259A-2
|
|
|
|
jmp $+2
|
|
|
|
jmp $+2
|
|
|
|
mov al, 0x20 ; start of hardware ints (0x20)
|
|
|
|
out 0x21, al
|
|
|
|
jmp $+2
|
|
|
|
jmp $+2
|
|
|
|
mov al, 0x28 ; start of hardware ints 2 (0x28)
|
|
|
|
out 0xA1, al
|
|
|
|
jmp $+2
|
|
|
|
jmp $+2
|
|
|
|
mov al, 0x04 ; 8259-1 is master
|
|
|
|
out 0x21, al
|
|
|
|
jmp $+2
|
|
|
|
jmp $+2
|
|
|
|
mov al, 0x02 ; 8259-2 is slave
|
|
|
|
out 0xA1, al
|
|
|
|
jmp $+2
|
|
|
|
jmp $+2
|
|
|
|
mov al, 0x01 ; 8086 mode for both
|
|
|
|
out 0x21, al
|
|
|
|
jmp $+2
|
|
|
|
jmp $+2
|
|
|
|
out 0xA1, al
|
|
|
|
jmp $+2
|
|
|
|
jmp $+2
|
|
|
|
mov al, 0xFF ; all interrupts off for now
|
|
|
|
out 0x21, al
|
|
|
|
jmp $+2
|
|
|
|
jmp $+2
|
|
|
|
out 0xA1, al
|
|
|
|
ret
|
2023-02-01 14:18:27 -06:00
|
|
|
|
|
|
|
global divisionErrorHandler
|
|
|
|
divisionErrorHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'D' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'E' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global boundRangeHandler
|
|
|
|
boundRangeHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'B' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'R' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global invalidOpcodeHandler
|
|
|
|
invalidOpcodeHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'U' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'D' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global deviceNotAvailableHandler
|
|
|
|
deviceNotAvailableHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'N' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'D' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global doubleFaultHandler
|
|
|
|
doubleFaultHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'D' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'F' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global invalidTSSHandler
|
|
|
|
invalidTSSHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'T' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'S' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global segmentNotPresentHandler
|
|
|
|
segmentNotPresentHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'N' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'P' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global stackSegmentHandler
|
|
|
|
stackSegmentHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'S' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'S' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global x87FloatingHandler
|
|
|
|
x87FloatingHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'M' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'F' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global alignmentCheckHandler
|
|
|
|
alignmentCheckHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'A' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'C' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|
|
|
|
global controlProtectionHandler
|
|
|
|
controlProtectionHandler:
|
|
|
|
mov ax, 0x10
|
|
|
|
mov ds, ax
|
|
|
|
mov dword [0xb8000], 0x0f000f00 | '#' | 'C' << 16
|
|
|
|
mov dword [0xb8004], 0x0f000f00 | 'P' | '!' << 16
|
|
|
|
.hlt:
|
|
|
|
hlt
|
|
|
|
jmp .hlt
|