My os works in qemu but not on real hardware
Posted: Tue Jun 25, 2013 7:26 am
I am running the operating system from a USB stick the code works fine in qemu but on real hardware their is problems. Here is my code
As you can see I have set up some tests e.g space bar reads current byte in memory then increments and I can say with certainty their is no data at 0x7e00. I thought maybe it was a segment issue so I tried a further tests e.g reading from 0x7e0, 0x7e00. I have the american megatrends bios. Can anybody see anything in this code that could cause it to run incorrectly I was thinking maybe its something to do with the way its emulating my USB stick but I'm not sure
Code: Select all
org 0 ; we start everything at zero
jmp short start
nop
MANU_DESC db 'mkdosfs '
BLOCK_SIZE dw 512
BLOCKS_PER_ALLOCATION_UNIT db 128
RESERVED_BLOCKS dw 1
TOTAL_FATS db 1
TOTAL_ROOT_ENTRIES dw 512
TOTAL_BLOCKS dw 0xffff
MEDIA_DESCRIPTOR db 0xf8
BLOCKS_PER_FAT dw 0x01
BLOCKS_PER_TRACK dw 18
TOTAL_HEADS dw 0x02
HIDDEN_BLOCKS dd 0x00
TOTAL_BLOCKS_2 dd 0x00
DRIVE_NUMBER dw 0x00
EXTENDED_BOOT_SIGNATURE db 0x29
VOLUME_SERIAL_NUMBER dd 0x9d86f18c
VOLUME_LABEL db 'SEAGULL '
FILE_SYSTEM_IDENTIFIER db 'FAT16 '
; Calculated in memory
ROOT_DIRECTORY dd 0x00
DAPACK:
db 0x10
db 0
.len: dw 1
.loc: dd 0x7e00
.sec: dd 2
dd 0
start:
cli
mov ax, 0x7c0
mov ds, ax
mov es, ax
mov sp, 0x1000
mov bp, 0
mov ss, bp
sti
mov byte [DRIVE], dl
; Root Directory Logical Sector = (TOTAL_FATS * BLOCKS_PER_FAT) + (RESERVED_BLOCKS)
mov ax, [TOTAL_FATS]
mul word [BLOCKS_PER_FAT]
mov word [ROOT_DIRECTORY+2], dx
push dx
add ax, [RESERVED_BLOCKS]
mov word [ROOT_DIRECTORY], ax
; Load root directory
mov word [DAPACK.sec], ax
pop dx
mov word [DAPACK.sec+2], dx
mov si, DAPACK ; address of "disk address packet"
mov ah, 0x42 ; AL is unused
mov dl, [DRIVE] ; drive number 0 (OR the drive # with 0x80)
int 0x13
jc err
mov si, 512
call print
mov ah, 0eh
mov al, 65
int 10h
mov si, 0x7e00
call print
mov ah, 0eh
mov al, 65
int 10h
mov si, 0x7e0
call print
mov ah, 0eh
mov al, 65
int 10h
mov si, 0
keyboard:
mov ah, 00
int 16h
lodsb
mov ah, 0eh
int 10h
jmp keyboard
err:
mov si, ERROR
call print
jmp $
print:
pusha
mov ah, 0eh
.repeat:
lodsb
cmp al, 0
je .done
int 10h
jmp .repeat
.done:
popa
ret
print_until:
mov ah, 0eh
.repeat:
lodsb
cmp bx, 0
je .done
int 10h
dec bx
jmp .repeat
.done:
popa
ret
ERROR db "Failed to load sector", 10, 13, 0
DRIVE db 0
times 510-($-$$) db 0 ; fill in the remaining space with zero
dw 0xaa55 ; legacy boot signature