Main boot sector file:
Code: Select all
bits 16
org 0x7c00
jmp main
times 0x0b-($-$$) db 0
%include "fat_boot_sector.asm"
%include "real_mode_floppy.asm"
%include "real_mode_print.asm"
%include "real_mode_fat_12.asm"
bsAdditional DB "Quartz Bootsector", 0x0A, 0x0D, 0
bsErrorMsg DD 0
bsErrorMsgB DB "Boot file `/qloader` can not be found.", 0x0A, 0x0D, 0
dFile db "QLOADER "
main: ;Start
xchg bx, bx
cli
xor ax, ax
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov sp, 0x7C00
sti
mov si, bsAdditional
call print
mov WORD [bufloc], 0x0150
push 1
push 32
call ReadSectors
mov ax, dFile
mov WORD [FileName], ax
mov WORD [bsErrorMsg], bsErrorMsgB
call FindFile ; >>> Here it gets stuck
xor ax, ax
mov bx, ax
mov cx, ax
mov dx, ax
jmp 0:0x8000
times 510-($-$$) db 0
dw 0xAA55
Code: Select all
%ifndef FAT_12
%define FAT_12
FileDirSeg dw 0
FileDir dw 0x3900
DirEntryN dw 224
FileBuf dw 0x0800
FileName dw 0
FindFile:
xor dx, dx
mov si, WORD [FileDir] ;ds:si = 0:FileDir
mov di, WORD [FileName];es:di = 0:(string location)
mov ax, WORD [FileDirSeg]
mov ds, ax
findloop:
mov cx, 11
push si
push di
mov al, BYTE [si]
test al, al
jz nfound
repz cmpsb
jz found
pop di
pop si
inc dx
add si, 0x20
cmp dx, [DirEntryN];TODO
jnz findloop
;Not found
nfound:
xor ax, ax
mov ds, ax
mov si, [bsErrorMsg]
call print
cli
hlt
found:
pop di
pop si
push ds
xor ax, ax
mov ds, ax
mov WORD [bufloc], ax
;Entry is in DS:SI
add si, 26 ;First sector
pop ds
mov ax, WORD [si] ;AX contains the sector
xor cx, cx
mov ds, cx
LoadToMem:
mov bx, ax
add bx, 31
push ax
push bx
push 1
call ReadSectors ; >>> Here it gets stuck
pop ax
add WORD [bufloc], 0x20
;Now find the next sector.
xor dx, dx
mov cx, 2
div cx
test dx, dx
jz even_entry
;odd entry
mov dx, 3
mul dx
mov bx, ax
mov ax, word [bx+0x1501]
shr ax, 4
cmp ax, 0xFF0
jl LoadToMem
jmp DoneLoad
even_entry:
mov dx, 3
mul dx
mov bx, ax
mov ax, word [bx+0x1500]
and ax, 0x0FFF
cmp ax, 0xFF0
jl LoadToMem
DoneLoad:
ret
%endif
Code: Select all
%ifndef _floppy
%include "fat_boot_sector.asm"
%define _floppy
sector db 0
head db 0
track db 0
count db 0
bufloc dw 0x0050
stacktemp dw 0
;PROCEDURE
;Reads sectors. (Real Mode)
;Two entries for stack:
;1st - Sector count
;2st - First sector given in LBA
ReadSectors:
pop ax
mov WORD [stacktemp], ax
pop ax
mov BYTE [count], al
pop ax
xor dx, dx
div WORD [bpbSectorsPerTrack]
inc dl
mov BYTE [sector], dl
xor dx, dx
div WORD [bpbHeadsPerCylinder]
mov BYTE [head], dl
mov BYTE [track], al ;LBA to CHS
read_try:
xor ah, ah
xor dl, dl
int 0x13 ;Reset
jc read_try
xor dl, dl
mov bx, WORD [bufloc] ;Loading at bufloc:0
push es
mov es, bx
xor bx, bx
xor dx, dx
mov ah, 0x02
mov al, BYTE [count]
mov ch, BYTE [track]
mov cl, BYTE [sector]
mov dh, BYTE [head]
int 0x13 ; >>> Here it gets stuck
jc read_try
pop es
push word [stacktemp]
ret
%endif
I have been debugging this and could not find what is wrong, maybe because it's 3:40AM and I'm deconcentrated.
Can somebody more experienced find the problem please?
While writing this post, I noticed I put DD instead of DW in the bsErrorMsg, but I doubt that is the problem.
The bootloader finds the file in the root directory and its first sector correctly, by the way.