0

現在、私は 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

ありがとう!

4

3 に答える 3

0

REPon theは関係なく回数CMPSBを繰り返し、最後に行われた比較の結果に設定されます。CMPSB CXZF

  • REPEここが必要です

を使用しても、 と のREPE両方REPE CMPSBを変更DISIて、それぞれが比較された最後のバイトの後のバイトを指すようにします (UP に設定されていると仮定しましょDF) 。DI

  • の前にとのPUSH両方DIを行う必要があり、直後に戻る必要があります (これは には影響しません) 。SIREPE CMPSBPOPFLAGS

そうすれば、どちらDISI変更されていないように見え、32 の追加は有効です。

巧妙に、と同じOR AX,AXに設定されますが、より小さく、より高速な命令です。ZFCMP AX,0x0

于 2013-04-06T03:43:17.930 に答える