I've been staring at it for days and I finally decided it was time to ask for help, so here it is.
I debugged my bootsector w/ bochs and right after I make the jump to protected mode it lists this as the next command
Code: Select all
jmp far f000:e05b
Code: Select all
An unrecoverable processor error has been encountered.
Code: Select all
[ORG 0x0]
[BITS 16]
start:
jmp main
Failure:
xor ax, ax
int 0x16 ; wait for keypress
int 0x19 ; warm reboot
db 'MH' ; padding
;----------------------------------------------------------------------------------------------------
; OEM Parameter Block
;----------------------------------------------------------------------------------------------------
bytesPerSector dw 512
sectorsPerCluster db 1
reservedSectors dw 1
numberOfFATs db 2
rootEntries dw 224
totalSectors dw 2880
media db 0xF0
sectorsPerFAT dw 9
sectorsPerTrack dw 18
headsPerCylinder dw 2
hiddenSectors dd 0
totalSectorsBig dd 0
driveNumber db 0
unused db 0
extBootSignature db 0x29
serialNumber dd 0xa0a1a2a3
volumeLabel db "Phenom OS"
fileSystem db "FAT12 "
main:
;----------------------------------------------------------------------------------------------------
; Adjust segment registers
;----------------------------------------------------------------------------------------------------
cli
mov ax, 0x07C0 ; (7C00:0000)
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
;----------------------------------------------------------------------------------------------------
; Create stack
;----------------------------------------------------------------------------------------------------
mov ax, 0x0000 ; bottom of stack
mov ss, ax
mov sp, 0xFFFF ; top of stack
sti
;----------------------------------------------------------------------------------------------------
; Load root directory table and FAT
;----------------------------------------------------------------------------------------------------
xor ax, ax
mov al, byte [numberOfFATs] ; number of FATs
mul word [sectorsPerFAT] ; total sectors used
mov cx, ax
mov ax, 0x0020 ; 32 byte directories
mul word [rootEntries] ; number of bytes
div word [bytesPerSector] ; number of sectors
add cx, ax
mov ax, word [reservedSectors] ; adjust for bootsector
mov word [datasector], ax
add word [datasector], cx
mov bx, 0x0200 ; (7C00:0200)
call ReadSectors
;----------------------------------------------------------------------------------------------------
; Find stage 2
;----------------------------------------------------------------------------------------------------
mov cx, word [rootEntries] ; loop counter
mov di, 0x2600 ; first entry
.loop:
push cx
mov cx, 0x000B ; 8.3 names
mov si, fileName ; file to find
push di
rep cmpsb
pop di
je Load_File
pop cx
add di, 0x0020 ; next directory
loop .loop
jmp Failure
;----------------------------------------------------------------------------------------------------
; Load Kernel
;----------------------------------------------------------------------------------------------------
Load_File:
mov dx, word [di + 0x001A]
mov word [cluster], dx ; file's first cluster
mov ax, 0x0050
mov es, ax
mov bx, 0x0000 ; (0050:0000)
push bx
mov ax, word [cluster] ; cluster to read
pop bx ; buffer to read into
sub ax, 0x0002 ; zero base cluster
xor cx, cx
mov cl, byte [sectorsPerCluster]
mul cx
add ax, word [datasector] ; offset after root directory table
xor cx, cx
mov cl, byte [sectorsPerCluster] ; sectors to read
call ReadSectors
push bx
mov ax, word [cluster] ; current cluster
mov cx, ax
mov dx, ax
shr dx, 0x0001 ; divide by 2
add cx, dx ; sum for (3/2)
mov bx, 0x0200 ; location of FAT
add bx, cx ; index into FAT
mov dx, word [bx] ; read 2 bytes
test ax, 0x0001
jnz .odd
.even:
and dx, 0000111111111111b ; take 12 low bits
jmp .done
.odd:
shr dx, 0x0004 ; take 12 high bits
.done:
;----------------------------------------------------------------------------------------------------
; Load GDT
;----------------------------------------------------------------------------------------------------
cli
lgdt [toc]
;----------------------------------------------------------------------------------------------------
; Enable A20 line
;----------------------------------------------------------------------------------------------------
call Wait_Input
mov al, 0xAD
out 0x64, al ; disable keyboard
call Wait_Input
mov al, 0xD0
out 0x64, al ; read output port command
call Wait_Output
in al, 0x60
push eax ; store output data
call Wait_Input
mov al, 0xD1
out 0x64, al ; write ouput port command
call Wait_Input
pop eax
or al, 2 ; enable A20
out 0x60, al
call Wait_Input
mov al, 0xAE ; enable keyboard
out 0x64, al
;----------------------------------------------------------------------------------------------------
; Enter Protected Mode
;----------------------------------------------------------------------------------------------------
cli
mov eax, cr0
or eax, 0x01
mov cr0, eax
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Problem
jmp 0x8:Protected
[BITS 32]
;----------------------------------------------------------------------------------------------------
; Set Registers
;----------------------------------------------------------------------------------------------------
Protected:
mov ax, 0x10
mov ds, ax
mov ss, ax
mov es, ax
mov esp, 0x90000 ; stack begins at 0x90000
jmp 0x8:0x500
[BITS 16]
cli
hlt
;----------------------------------------------------------------------------------------------------
; Print a string
;
; si <= Address of string
;----------------------------------------------------------------------------------------------------
;Print:
; mov ah, 0x0E
;.loop:
; lodsb
; or al, al
; jz .finish
; int 0x10
; jmp .loop
;.finish:
; ret
;----------------------------------------------------------------------------------------------------
; GDT (Global Descriptor Table)
;----------------------------------------------------------------------------------------------------
gdt_null:
dq 0 ; null descriptor
gdt_code: ; code descriptor
dw 0xFFFF ; limit low
dw 0 ; base low
db 0 ; base middle
db 10011010b ; access
db 11001111b ; granularity
db 0 ; base high
gdt_data: ; data descriptor
dw 0xFFFF ; limit low
dw 0 ; base low
db 0 ; base middle
db 10010010b ; access
db 11001111b ; granularity
db 0 ; base high
end_of_gdt:
toc:
dw end_of_gdt - gdt_null - 1 ; limit
dd gdt_null ; base of GDT
;----------------------------------------------------------------------------------------------------
; Wait for keyboard input buffer
;----------------------------------------------------------------------------------------------------
Wait_Input:
in al, 0x64
test al, 2
jnz Wait_Input
ret
;----------------------------------------------------------------------------------------------------
; Wait for keyboard output buffer
;----------------------------------------------------------------------------------------------------
Wait_Output:
in al, 0x64
test al, 1
jz Wait_Output
ret
;----------------------------------------------------------------------------------------------------
; Read sectors from floppy drive
;
; cx => # of sectors
; ax => starting sector
; es:bx => buffer to read to
;----------------------------------------------------------------------------------------------------
ReadSectors:
.main:
mov di, 0x0005 ; five tries for error
.loop:
push ax
push bx
push cx
xor dx, dx ; prepare dx:ax
div word [sectorsPerTrack]
inc dl
mov cl, dl
xor dx, dx
div word [headsPerCylinder] ; calculate
mov dh, dl
mov ch, al
mov ah, 0x02 ; read sector
mov al, 0x01 ; read one sector
mov dl, byte [driveNumber] ; drive
int 0x13 ; BIOS low level disk operations
jnc .success ; test for read error
xor ax, ax ; BIOS reset disk
int 0x13 ; BIOS low level disk operations
dec di ; decrement error counter
pop cx
pop bx
pop ax
jnz .loop
int 0x18
.success:
pop cx
pop bx
pop ax
add bx, word [bytesPerSector] ; next
inc ax
loop .main ; read next sector
ret
fileName db "KERNEL SYS"
datasector dw 0x0000
cluster dw 0x0000
times 510 - ($-$$) db 0 ; fill with zeros
dw 0xAA55