現在、私は OS Dev の BrokenThorn シリーズをフォローしていて、ちょっとした問題に遭遇しました。現在、チュートリアルの旅の一環として、第 2 段階のブートローダーでロードする部分をコーディングしていますが、残念ながらコードがクラッシュします。面倒だと思うコードの部分は次のとおりです。
コード:
;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 を実行しています。
アップデート
すべての有益なコメントの後、コードを更新しました。
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
残念ながら、OS はまだファイルを見つけることができません。
更新 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
ありがとう!