Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BITS 16
- ORG 7C00h
- start:
- cli
- mov [drive], dl
- mov ah, 01h
- mov ch, 3Fh
- int 10h
- mov ah, 13h
- mov al, 01h
- mov bh, 00h
- mov bl, 0Fh
- mov cx, 0Ah
- mov dh, 00h
- mov dl, 00h
- mov bp, loading
- int 10h
- mov dl, [drive]
- mov ah, 02h
- mov al, 2
- mov ch, 0
- mov dh, 0
- mov cl, 2
- mov bx, loadLocation
- int 13h
- xor ax, ax
- push ax
- popf
- mov ds, ax
- lgdt [gdt_desc]
- mov eax, cr0
- or eax, 1
- mov cr0, eax
- jmp 08h:protectedModeBegin
- loading:
- db "Loading...", 0
- drive: db 0
- BITS 32
- protectedModeBegin:
- mov ax, 10h
- mov ds, ax
- mov ss, ax
- mov esp, 90000h
- jmp loadLocation
- gdt:
- gdt_null:
- dq 0
- gdt_code:
- dw 0FFFFh
- dw 0
- db 0
- db 10011010b
- db 11001111b
- db 0
- gdt_data:
- dw 0FFFFh
- dw 0
- db 0
- db 10010010b
- db 11001111b
- db 0
- gdt_end:
- gdt_desc:
- dw gdt_end-gdt
- dd gdt
- idtbegin:
- zerodivide:
- dw 0000h
- dw 0008h
- db 00h
- db 8Eh
- dw 0000h
- idtend:
- idt:
- dw idtend-idtbegin
- dq idtbegin
- times 510-($-$$) db 0
- dw 0AA55h
- loadLocation:
- mov eax, zeroDivide_exception
- and eax, 0000FFFFh
- mov [zerodivide], ax
- mov eax, zeroDivide_exception
- and eax, 0FFFF0000h
- mov [zerodivide+6], ax
- lidt [idt]
- mov bl, 00h
- div bl ;Cause a divide-by-zero exception ;)
- call clearTextScreen
- mov si, whoopsie
- mov ax, 01h
- mov bx, 01h
- call placeText
- mov si, oops
- mov ax, 02h
- mov bx, 02h
- call placeText
- mov si, gurumeditation
- mov ax, 03h
- mov bx, 03h
- call placeText
- mov si, abortretryfail
- mov ax, 04h
- mov bx, 04h
- call placeText
- mov si, notatypewriter
- mov ax, 05h
- mov bx, 05h
- call placeText
- mov si, nocarrier
- mov ax, 06h
- mov bx, 06h
- call placeText
- mov si, pcloadletter
- mov ax, 07h
- mov bx, 07h
- call placeText
- mov si, lp0onfire
- mov ax, 08h
- mov bx, 08h
- call placeText
- .loop:
- jmp .loop
- lp0onfire:
- db "lp0 on fire", 0
- pcloadletter:
- db "PC LOAD LETTER", 0
- notatypewriter:
- db "Not a typewriter", 0
- abortretryfail:
- db "Abort, Retry, Fail?", 0
- gurumeditation:
- db "Guru Meditation #00000004.0000AAC0", 0
- nocarrier:
- db "NO CARRIER", 0
- oops:
- db "thing(0): Oops", 0
- whoopsie:
- db "whoopsie", 0
- tempx: dw 0
- tempy: dw 0
- tempattrib: db 0
- tempval: dq 0
- ;esi - Pointer to text
- ;ax - X Pos.
- ;bx - Y Pos.
- ;cx - Attrib.
- placeText:
- mov [tempattrib], cx
- mov [tempx], ax
- mov ax, bx
- mov bx, 160
- mul bx
- mov [tempy], ax
- mov ax, [tempx]
- mov bx, 2
- mul bx
- mov bx, ax
- mov ax, [tempy]
- add eax, ebx
- mov ecx, 0B8000h
- add ecx, eax
- .placeTextLoop:
- lodsb
- cmp al, 00h
- je .donePlacingText
- mov [ecx], BYTE al
- add ecx, 1h
- mov dx, [tempattrib]
- mov [ecx], dx
- add ecx, 1h
- jmp .placeTextLoop
- .donePlacingText:
- ret
- clearTextScreen:
- mov ecx, 0B8000h
- mov ax, (80*25)*2
- .loop:
- mov [ecx], BYTE 00h
- add ecx, 01h
- sub ax, 01h
- cmp ax, 00h
- je .doneClearingTextScreen
- jmp .loop
- .doneClearingTextScreen:
- ret
- divideByZero:
- db "DIVIDE-BY-ZERO EXCEPTION", 0
- pcTxt:
- db "PC: ", 0
- espTxt:
- db "ESP: ", 0
- eaxTxt:
- db "EAX: ", 0
- ebxTxt:
- db "EBX: ", 0
- ecxTxt:
- db "ECX: ", 0
- edxTxt:
- db "EDX: ", 0
- hexTable:
- db "0", 0
- db "1", 0
- db "2", 0
- db "3", 0
- db "4", 0
- db "5", 0
- db "6", 0
- db "7", 0
- db "8", 0
- db "9", 0
- db "A", 0
- db "B", 0
- db "C", 0
- db "D", 0
- db "E", 0
- db "F", 0
- hexEnd:
- db "H", 0
- temppc: dq 0
- tempesp: dq 0
- tempeax: dq 0
- tempebx: dq 0
- tempecx: dq 0
- tempedx: dq 0
- copyRegsToMem:
- mov [tempeax], eax
- mov [tempebx], ebx
- mov [tempecx], ecx
- mov [tempedx], edx
- pop ebx ;Pop the return address from calling this subroutine into EBX
- pop eax
- mov [temppc], eax
- push ebx ;Push the return address back onto the stack
- mov [tempesp], esp
- ret
- zeroDivide_exception:
- call copyRegsToMem
- call clearTextScreen
- mov si, divideByZero
- mov ax, 00h
- mov bx, 00h
- mov cx, 0Ch
- call placeText
- call showRegisters
- jmp hang
- showRegisters:
- mov si, pcTxt
- mov ax, 00h
- mov bx, 01h
- mov cx, 0Ch
- call placeText
- mov si, espTxt
- mov ax, 00h
- mov bx, 02h
- mov cx, 0Ch
- call placeText
- mov si, eaxTxt
- mov ax, 00h
- mov bx, 03h
- mov cx, 0Ch
- call placeText
- mov si, ebxTxt
- mov ax, 00h
- mov bx, 04h
- mov cx, 0Ch
- call placeText
- mov si, ecxTxt
- mov ax, 00h
- mov bx, 05h
- mov cx, 0Ch
- call placeText
- mov si, edxTxt
- mov ax, 00h
- mov bx, 06h
- mov cx, 0Ch
- call placeText
- mov ax, 05h
- mov bx, 01h
- mov ecx, [temppc]
- call print32Bit
- mov ax, 05h
- mov bx, 02h
- mov ecx, [tempesp]
- call print32Bit
- mov ax, 05h
- mov bx, 03h
- mov ecx, [tempeax]
- call print32Bit
- mov ax, 05h
- mov bx, 04h
- mov ecx, [tempebx]
- call print32Bit
- mov ax, 05h
- mov bx, 05h
- mov ecx, [tempecx]
- call print32Bit
- mov ax, 05h
- mov bx, 06h
- mov ecx, [tempedx]
- call print32Bit
- ret
- ;ax - X Pos.
- ;bx - Y Pos.
- ;ecx - Value to print
- print32Bit:
- mov cx, 0Fh
- mov si, hexTable
- call placeText
- ret
- hang:
- jmp hang
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement