Yet Another Fat12 Problem YaFP 12 :-)
Posted: Wed Mar 17, 2004 6:47 am
Hey, first i will thank those people which check my code and help me to find the problem.
Now I have a problem with Fat12:
I search for a kernel on a Floppy (with my bootloader), when the kernel isn't found the kernel outs an error message.
Here are the functions I use (the read_sector is my own, the FindName is from someone in this Forum):
How you can see the FindName function returns the number of the Start Sector of the searched file in si.
If I try to read the sector returned in si:
mov cx, [si] ; cx = sector number
i got an empty buffer (where the sector is load in). Should I do other things before with the sector number ??? Additional I find out that if I read a the sector 33 (where the file begins, i checked this with an Image I make from the current disk) first a few zeros are loaded not directly the begin of the kernel.
Now I have a problem with Fat12:
I search for a kernel on a Floppy (with my bootloader), when the kernel isn't found the kernel outs an error message.
Here are the functions I use (the read_sector is my own, the FindName is from someone in this Forum):
Code: Select all
;----------------------------------------------;
;------------- read_sector --------------------;
;----------------------------------------------;
;------ es = buffer address -------------------;
;------ bx = buffer offset -------------------;
;------ cx = sector to read -------------------;
;------ dl = drive -------------------;
;----------------------------------------------;
;------ for 1.44MB Floppys 80 Sectors ---------;
;----------------------------------------------;
read_sector:
pusha
push bx ; save buffer offset
; compute the sector number: sector_number%sectors_per_track + 1
mov ax, cx ; ax = sector number
mov bl, 18 ; bl = number of sectors per track
div bl ; al = ax / bl
mov cl, ah ; cl = real sector number (cl is used by int 13)
add cl, 1
; compute the head number: (sector_number/sector_per_track) just in ax mod number_of_heads
; and the track number: (sector_number/sector_per_track) / number_of_heads
xor ah, ah ; del the rest of the div before
mov bl, 2 ; bl = number of heads
div bl ; ah = rest of ( ax / bx ), al = ax / bx
mov ch, al ; ch = number of track
mov dh, ah ; dh = the head number (dh is used by int 13)
pop bx ; restore the buffer offset
mov ax, cx ; save cx in ax
mov cx, 5 ; try to read the sector 5 times ;!!! overwrite the num of track and num of sec
read_sector_next_try:
pusha
mov cx, ax ; restore cx
mov ah, 0x02 ; function number 2 (read from disk)
mov al, 0x01 ; number of sectors to read
int 0x13
jnc load_ok ; if all is ok return
popa
loop read_sector_next_try; else try once again if there is an error
jmp error ; if cx = 0 and the read operation always failed, halt
load_ok:
popa
popa
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Looks for a file with particular name ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Input: DS:SI -> file name (11 chars) ;;
;; ES:DI -> root directory array ;;
;; DX = number of root entries ;;
;; Output: SI = cluster number ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FindName:
cld
mov cx, 11
FindNameCycle:
cmp byte [es:di], ch
je FindNameFailed ; end of root directory
pusha
repe cmpsb
popa
je FindNameFound
add di, 32
dec dx
jnz FindNameCycle ; next root entry
FindNameFailed:
mov ax, 0
ret
FindNameFound:
; mov si, [es:di+1Ah] ; si = cluster no.
mov ax, di
add ax, 0x1A
mov si, ax
mov ax, 1
retIf I try to read the sector returned in si:
mov cx, [si] ; cx = sector number
i got an empty buffer (where the sector is load in). Should I do other things before with the sector number ??? Additional I find out that if I read a the sector 33 (where the file begins, i checked this with an Image I make from the current disk) first a few zeros are loaded not directly the begin of the kernel.