引导加载程序代码如何计算软盘的第一个簇?

时间:2020-11-06 14:15:59

标签: assembly x86-16 bootloader fat

我下面给出了一个引导加载程序代码,除了它如何根据下面给出的计算簇数外,我已经理解了所有内容:

mov ax, word [es:di+0Fh] <------; Offset 11 + 15 = 26, 
                            ;contains 1st cluster 

大部分代码部分如下: bpb区域如下所示:

OEMLabel        db "FTLBOOT "   ; Disk label
BytesPerSector      dw 512      ; Bytes per sector
SectorsPerCluster   db 1        ; Sectors per cluster
ReservedForBoot     dw 1        ; Reserved sectors for 
                                ;boot record
NumberOfFats        db 2        ; Number of copies of 
                                ;the FAT
RootDirEntries      dw 224      ; Number of entries in 
                                ;root dir
                ; (224 * 32 = 7168 = 14 sectors to read)
LogicalSectors      dw 2880     ; Number of logical 
                                ;sectors
MediumByte      db 0F0h     ; Medium descriptor byte
SectorsPerFat       dw 9        ; Sectors per FAT
SectorsPerTrack     dw 18       ; Sectors per track 
(36/cylinder)
Sides           dw 2        ; Number of sides/heads
HiddenSectors       dd 0        ; Number of hidden 
                                ;sectors
LargeSectors        dd 0        ; Number of LBA sectors
DriveNo         dw 0        ; Drive No: 0
Signature       db 41       ; Drive signature: 41 for 
                            ;floppy
VolumeID        dd __POSIX_TIME__   ; Volume ID
VolumeLabel     db "TACHYONOS  "; Volume Label: any 11 
                                ;chars
FileSystem      db "FAT12   "   ; File system type: 
                                ;don't change!

多余部分如下: 请看箭头所指的行(<-----):

next_root_entry:
xchg cx, dx         ; We use CX in the inner loop...

mov si, kern_filename       ; Start searching for kernel 
                            ;filename
mov cx, 11
rep cmpsb
je found_file_to_load       ; Pointer DI will be at 
                            ;offset 11

add ax, 32          ; Bump searched entries by 1 (32 
                    ;bytes per entry)

mov di, buffer          ; Point to next entry
add di, ax

xchg dx, cx         ; Get the original CX back
loop next_root_entry

mov si, file_not_found      ; If kernel is not found, 
                            ;bail out
call print_string
jmp reboot


found_file_to_load:         ; Fetch cluster and load 
                                ;FAT into RAM
mov ax, word [es:di+0Fh] <------; Offset 11 + 15 = 26, 
                            ;contains 1st cluster
mov word [cluster], ax

从第二行开始,代码正在计算第一簇,我无法理解代码部分“ [es:di + 0Fh]”。

0 个答案:

没有答案