start work on panic handler

main
pantonshire 1 year ago
parent 030edfc301
commit 89e2cef4fa

@ -216,9 +216,9 @@ main:
mov ax, msg_boot1_loaded mov ax, msg_boot1_loaded
call vga_println call vga_println
mov ecx, 0xa1b2c3d4 mov eax, 0xa1b2c3d4
call vga_dump_reg mov ebx, 0x12345678
hlt call panic_fancy
call test_a20 call test_a20
test ax, ax test ax, ax
@ -252,14 +252,50 @@ panic_default:
; Print a panic message then terminate. ; Print a panic message then terminate.
; Arguments: ; Arguments:
; - [sp - 2]: pointer to panic message ; - [sp - 2]: panic message segment
; - [sp]: panic message length ; - [sp]: panic message offset
; Does not return ; Does not return
panic_fancy: panic_fancy:
push bp push bp
mov bp, sp mov bp, sp
sub sp, 16 ; Buffer: bp - 16
push eax ; bp - 20
push ebx ; bp - 24
push ecx ; bp - 28
push edx ; bp - 32
push esi ; bp - 36
push edi ; bp - 40
mov word [GLOBALS + VGA_COL], 0x4f00 mov word [GLOBALS + VGA_COL], 0x4f00
call vga_clear
mov ax, ss
mov es, ax
lea ax, [bp - 16]
push ax
mov ecx, [bp - 20]
call dump_reg
pop cx
xor ax, ax
mov dx, 8
call vga_print_raw
lea ax, [bp - 16]
push ax
mov ecx, [bp - 24]
call dump_reg
pop cx
mov ax, VGA_WIDTH
mov dx, 8
call vga_print_raw
.halt:
hlt hlt
; Handle non-maskable interrupts
jmp .halt
; Clear the VGA text buffer. ; Clear the VGA text buffer.
@ -334,40 +370,42 @@ vga_scroll:
fnret fnret
; Write one line to the VGA text buffer. The string should be null-terminated; we embrace the evil ; Write a null-terminated string to the given position in the VGA text buffer.
; of null-termination so this function only takes one argument, so it's slightly less of a faff to
; call in most cases.
; Arguments: ; Arguments:
; - es: output string segment ; - es: output string segment
; - ax: output string offset ; - ax: vga buffer index
; Return: none ; - cx: output string offset
; Clobber: ax ; - dx: maximum length of string to print
vga_println: ; Return:
; - ax: vga buffer index after last character written
; Clobber: none
vga_print_raw:
fnstart fnstart
push fs
push si push si
push di push di
push cx
push dx push dx
push fs
cmp word [GLOBALS + TEXTBUF_LINE], VGA_HEIGHT
jb .scroll_done
call vga_scroll
.scroll_done:
mov si, ax
xor dx, dx
mov ax, [GLOBALS + TEXTBUF_LINE]
mov di, VGA_WIDTH * 2
mul di
mov di, ax
mov si, cx
xchg ax, cx
; Find the distance between the starting index and the end of the buffer.
mov ax, (VGA_WIDTH * VGA_HEIGHT)
sub ax, cx
; If the starting index is past the end of the buffer, return early.
jc .done
; Clamp the maximum length to the distance between the starting index and the end of the buffer.
cmp ax, dx
cmovb dx, ax
mov di, cx
shl di, 1
mov ax, 0xb800 mov ax, 0xb800
mov fs, ax mov fs, ax
mov ah, [GLOBALS + VGA_COL + 1] mov ah, [GLOBALS + VGA_COL + 1]
mov dx, VGA_WIDTH
.loop: .loop:
test dx, dx test dx, dx
jz .done jz .done
@ -378,38 +416,58 @@ vga_println:
mov fs:[di], ax mov fs:[di], ax
add di, 2 add di, 2
inc si inc si
dec cx inc cx
jmp .loop jmp .loop
.done: .done:
inc word [GLOBALS + TEXTBUF_LINE] xchg ax, cx
pop fs
pop dx pop dx
pop cx
pop di pop di
pop si pop si
pop fs
fnret fnret
vga_dump_reg: ; Write one line to the VGA text buffer. The string should be null-terminated; we embrace the evil
; of null-termination so this function only takes one argument, so it's slightly less of a faff to
; call in most cases.
; Arguments:
; - es: output string segment
; - ax: output string offset
; Return: none
; Clobber: none
vga_println:
fnstart fnstart
sub sp, VGA_WIDTH push ax
push es
push bx push bx
push cx
push dx
cmp word [GLOBALS + TEXTBUF_LINE], VGA_HEIGHT
jb .scroll_done
call vga_scroll
.scroll_done:
mov ax, ss
mov es, ax
lea ax, [bp - VGA_WIDTH]
call dump_reg
mov bx, ax mov bx, ax
mov byte es:[bx], 0
xor dx, dx
mov ax, [GLOBALS + TEXTBUF_LINE]
mov cx, VGA_WIDTH
mul cx
lea ax, [bp - VGA_WIDTH] mov dx, VGA_WIDTH
call vga_println mov cx, bx
call vga_print_raw
inc word [GLOBALS + TEXTBUF_LINE]
pop bx pop dx
pop es pop cx
add sp, VGA_WIDTH pop bx
pop ax
fnret fnret

Loading…
Cancel
Save