目前,我一直在關注OS Dev上的BrokenThorn系列,並且遇到了一些問題。現在,作爲本教程的一部分,我正在編寫加載到第二階段引導加載程序的部分,但不幸的是,代碼崩潰。這是我認爲的代碼部分麻煩:如何在組件中搜索FAT12系統中的文件
代碼:
;browse root directory for binary image
mov ax, WORD [bpbRootEntries]; load loop counter, bpbRootEntries is the number of entries in the FAT table
mov di, 0x0000 ; because rep cmpsb compares the string in es:di to ds:si, and es holds 0x7e00 (the location of the FAT Table), I decided to set di to 0x0000
mov cx, 0x000B; eleven character name
lea si, [ImageName] ;set si to the memory location of ImageName so ds:si points to ImageName
.LOOP:
rep cmpsb
jz LOAD_FAT
add di, 32 ; queue next directory entry
dec ax
cmp ax, 0x0
jne .LOOP
jmp FAILURE
的這部分程序會在FAT表文件。但是,它無法找到它,所以崩潰。 在此代碼中,ImageName是一個變量,其值爲「KRNLDR SYS」。在我的軟盤驅動器中,我的軟盤驅動器中有一個名爲「KRNLDR SYS」的文件(帶有空格,而不是「KRNLDR.SYS」)。如果有人能提供任何建議,這將是一個很大的幫助。
注:目前我捉迷藏了64位的Windows 7 PC
UPDATE
所有有用的意見後,我已經更新了代碼:
mov ax, WORD [bpbRootEntries] ; load loop counter
mov di, 0x0000 ; locate first root entry
mov cx, 0x000B ; eleven character name
lea si, [ImageName] ; image name to find
.LOOP:
push di
push si
repe cmpsb
pop di
pop si
jz LOAD_FAT
add di, 32 ; queue next directory entry
dec ax
or ax, ax
jne .LOOP
jmp FAILURE
不幸的是,操作系統仍然無法找到該文件。
更新2
這裏是我用來加載根目錄表的代碼:
LOAD_ROOT:
; compute size of root directory and store in "cx"
xor si, si
mov ax, 0x0020 ; 32 byte directory entry
mul WORD [bpbRootEntries] ; total size of directory
div WORD [bpbBytesPerSector] ; sectors used by directory
xchg ax, cx
; compute location of root directory and store in "ax"
mov al, BYTE [bpbNumberOfFATs] ; number of FATs
mul WORD [bpbSectorsPerFAT] ; sectors used by FATs
add ax, WORD [bpbReservedSectors] ; adjust for bootsector
mov WORD [datasector], ax ; base of root directory
add WORD [datasector], cx
; read root directory into memory (7C00:0200)
mov dx, 0x7e00
mov es, dx
mov bx, 0x0 ; copy root dir above bootcode
call ReadSectors
謝謝!
你確信你的軟盤文件系統實際上是FAT12,並且該文件確實是名爲「KRNLDR SYS」? – duskwuff 2013-04-06 02:13:36
因此,我在Windows中命名文件KRNLDR.SYS。在引導程序中,我正在搜索KRNLDR SYS(有2個空格)。但是,代碼仍然無法找到該文件。我正在使用VFD創建虛擬軟盤驅動器並對其進行格式化。我正在使用RawWrite將引導加載程序調整到扇區0,並在Windows中使用複製命令將KRNLDR加載到軟盤。這個設置有問題嗎? 在此先感謝您的幫助! – user1231745 2013-04-06 02:18:05