目前,我一直在关注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