I'm trying to write my own fat bootsector. For now i want it to load the root dir to a memory segment and check for a file called test.txt if it's there it shall display a "File Found!!!!" Message and hang and if it doesn't a "File not foun" and hang. But instead it only displays a blinking cursor so i don't know if has done it's job or not :'(. Here is my code
Code: Select all
[BITS 16]
[ORG 0]
jmp short start
nop
OEM_ID db 'MANYLOLS'
BytesPerSector dw 0x0200
SectorsPerCluster db 0x01
ReservedSectors dw 0x0001
TotalFats db 0x02
MaxRootEntries dw 0x0E0
TotalSectors dw 0x0B40
MediaDescriptor db 0xF0
SectorsPerFat dw 0x0009
SectorsPerTrack dw 0x0012
NumHeads dw 0x0002
HiddenSectors dd 0x00000000
TotalSectorsLarge dd 0x00000000
DriveNumber db 0x00
Flags db 0x00
Signature db 0x29
VolumeID dd 0xFFFFFFFF
VolumeLabel db "Testdisk "
SystemID db 'FAT12 '
start:
mov ax,0x7C0
mov ds,ax
mov es,ax
mov ax,0x0000
mov ss,ax
mov sp,0xFFFF
; load file kernel.bin to 1000:0000
success db 'FileFound!!!!',0
filenotfound db 'FilenotFound',0
rootdirsec db 0
firstrootsec db 0
ABSsector db 0
ABStrack db 0
ABShead db 0
filename db 'TEST TXT'
main:
xor ax,ax
xor dx,dx
mov dl,[DriveNumber]
int 13h
call findroot
call getroot
push es
call searchroot
findroot: ;Let's Find the root directory ;)
xor ax,ax
mov ax,[MaxRootEntries] ; Rootdirsectors=((Maxrootent*32)+(BytesPerSec-1))/BPS
mov bx,32
mul bx
xor bx,bx
mov bx,[BytesPerSector]
dec bx
add ax,bx
div BYTE [BytesPerSector]
mov di,rootdirsec
mov [es:di],ax
firstdatasec: ; find first data sector
xor ax,ax
mov ax,[ReservedSectors]
mov bx,[TotalFats]
add ax,bx
mov bx,12
mul bx
add ax,[rootdirsec]
mov di,firstrootsec
mov [es:di],ax
getroot:
xor cx,cx
xor bx,bx
mov cx,[rootdirsec] ; COUNT IN CX
mov bx,[firstrootsec] ; LBA IN BX
loopsec:
cmp cx,0
je finished
call LBACHS
call readsector
inc bx
dec cx
jmp loopsec
finished:
ret
LBACHS:
xor dx,dx
xor ax,ax
mov ax,bx
div BYTE [SectorsPerTrack] ;Sector
inc dx
mov di,ABSsector
mov [es:di],dx
xor ax,ax
xor dx,dx
mov ax,bx
div BYTE [SectorsPerTrack]
div BYTE [NumHeads]
mov di,ABStrack
mov [es:di],dx
mov di,ABShead
mov [es:di],ax
ret
readsector:
push es
push bx
push cx
xor ax,ax
xor bx,bx
xor dx,dx
xor cx,cx
mov ah,0x2
mov al,0x1
mov ch,[ABStrack]
mov cl,[ABSsector]
mov dh,[ABShead]
mov dl,[DriveNumber]
mov ax,9A00h
mov es,ax
int 13h
pop cx
pop bx
pop es
ret
searchroot:
mov ax,9A00h
mov es,ax
mov cx,11
xor di,di
push di
mov si,filename
repe cmpsb
pop di
je filefound ; ;D
add di,32
mov ax,di
mov dl,32
div dl
cmp ax,[MaxRootEntries]
jle searchroot
jmp failure ; :(
filefound:
mov ax,0x7C0
mov es,ax
mov si,success
call print
jmp hang
failure:
mov si,filenotfound
call print
jmp hang
print:
lodsb
cmp al,0
je printend
mov ah,0Eh
mov bh,0h
mov bl, 0Fh
int 10h
jmp print
printend:
ret
hang:
jmp hang
times 510-($-$$) db 0
dw 0AA55h