找到根目录的BootLoader的开始 [英] Finding the start of the Root Directory BootLoader
问题描述
我创建从CD的靴子的BootLoader,我有麻烦发现如何找到根目录开始对磁盘这里是我的引导code:
位16ORG为0x00开始:JMP主
;颜色文本
%DEFINE TEAL×03
%DEFINE RED 0×04
%DEFINE紫色0×05
COL:0分贝
ROW:0分贝;宏打印
%宏打印2
PUSHA
异斧,斧
XOR DX,DX
MOV DH,BYTE [ROW];把行到DH寄存器
MOV DL,BYTE [COL]
异或BX,BX
MOV BL,2%
MOV SI,1%
调用cPrint
MOV BYTE [COL],DL
;保存行,我们需要打印下一次
波帕
%endmacroPrint_ln:PUSHA
MOV DH,BYTE [ROW]
MOV啊,0X02;设置光标POS
MOV BH,0×00; 00页
INC DH;排00
MOV DL,0×00;山坳。 00
INT为0x10
MOV BYTE [ROW],DH
MOV BYTE [COL] 0
波帕
RETcPrint:;常规:在SI输出字符串到屏幕
。最佳:
; PARAMATERS输入
MOV啊,09H;必须是9打印彩色
MOV CX,0×01; x位置
LODSB;从字符串获取字符
测试人,人
JE .done;如果char是零,字符串的结尾
诠释为0x10;否则,打印 MOV啊,0X02;设置光标位置
MOV BH,0×00;页
INC。DL;列
INT为0x10;改变光标位置以使下一个字符可以在新的位置被写入
JMP .TOP .done:
RET;清除屏幕并将光标位置左上角
明确:
MOV啊,为0x0F;获取当前视频模式
MOV等,为0x00;复位寄存器
诠释为0x10;获取视频模式
MOV啊,为0x00;设置视频模式
诠释为0x10;复位屏幕
MOV啊,0X02;设置光标POS
MOV BH,0×00; 00页
MOV DH,0×00;排00
MOV DL,0×00;山坳。 00
诠释为0x10;设置POS
RET或[DS:ESI]与字节:; CMPSB字节在[SI DS]比较[ES:DI]
;或[ES:EDI]
;并设置相应的标志。然后,它递增或递减(视
;上方向标志:增量
;如果该标志是明确的,如果递减它设置)SI和DI(或ESI和EDI)。
Read_Sectors:
; / *读取扇区到内存中。 * / .ForLoop:
MOV啊,042h
异人,人
MOV SI,DiskAddressPacket
MOV DL,[CDDriveNumber]
INT 013h
JNC .Success; / *读取错误? * / 打印Read_Sector_Error_MSG,RED CLI
HLT。成功:
打印Progress_MSG,紫
INC字[DiskAddressPacket.SectorsToRead] 环.ForLoopRET
主要: CLI
MOV AX,0x07c0;调整段寄存器
MOV DS,AX
MOV GS,斧
MOV FS,斧
Create_Stack:
异斧,斧
MOV ES,AX
MOV SS,AX
MOV SP,0x0FFFE
STI
MOV ES,为0x200 MOV [CDDriveNumber],DL
通话清晰
打印W_MSG,TEAL;以彩色打印加载消息
调用Print_ln LOAD_ROOT:
;首先计算的根目录开始
MOV字[DiskAddressPacket.Offset],0x01000
MOV CX,为0x01
电话Read_Sectors 调用Print_ln
打印READ_SUCCESS蒂尔
调用Print_ln
CLI
HLTSECTOR_SIZE:DW 512
CDDriveNumber:DB 80H
CD_bytes_per_sect:DW 0
CD_root_dir_size:DD 0
CD_root_dir_sectors:DW 0
CD_root_dir_start:DD 0
CD_file_size:DD 0
CD_file_sectors:DW 0
CD_file_start:DD 0
CD_desc_sector:DD 0
CD_Signature:DB\\ 2CD001
CD_FILE_VER:DB为0x01;磁盘地址数据包
DiskAddressPacket:DB 16,0
.SectorsToRead:DW 1;扇区数读(读OS的大小)
.Offset:DW 0;偏移:0000
.SEGMENT:DW 0200H;段0200
.END:DQ 16;部门16或10小时的CD-ROM上返回:DB 0W_MSG:DB装载Z-引导,0
阶段2:DBSTAGE2 BIN
Read_Sector_Error_MSG:DB的错误,无法读取扇区,0
READ_SUCCESS:DB扇区读取正确,0
Progress_MSG:分贝,0。
FILE_NOT_FOUND:DB错误,找不到文件,0
实测:DB发现,0
次2046 - ($ - $$)分贝0; PADD出该文件的其余部分为0
DW 0xAA55将
我看到一些code,它做了这样的事情找到卷描述我有一种感觉你需要找到根目录,但我不能把我的手指上这里是code,它这是否:
get_next_desc:
/ *读取在存储器中的扇区0000:1000。 * /
MOV [desc_sector],EAX
MOV BX,01000h
MOV CX,1
电话read_sectors / *检查签名\\ 2CD001的描述符的开始。 * /
MOV SI,cd_signature
MOV DI,01000h
MOV CX,6
CMPSB
JE found_desc ; / *检查如果我们卷的所有描述都看了。 * /
CMP字节[ES:为0x1000],0FFh的
JNE next_desc ; / *我们期待在磁盘的所有会议,并没有发现操作系统映像。
;我们在屏幕上显示一个错误信息,然后提示用户
; preSS一键重新启动计算机。 * /
MOV SI,msg_file_not_found
电话print_string
JMP重启next_desc:
下面是我用来组装我的code:
NASM ZerothStage.asm -o ZerothStage.binmkisofs的-b ZerothStage.bin -no-EMUL引导-o BootLoader.iso ./
没关系我得到它显然我需要从DAP加载段偏移地址到ES:DI并查找卷描述符有
以下是我用来解决它,如果有人有兴趣。
code:
MOV ES,字[DiskAddressPacket.Segment]
MOV DI,字[DiskAddressPacket.Offset] 异或BX,BX
。最佳
MOV人,BYTE [ES:DI + BX]
CMP人,''
JE .Done
MOV啊,0xE
INT量0x010
INC BX
JMP .TOP .Done:
我读了第四界,而不是16部门显然这是你必须阅读在图像的最后一个扇区
我是新来这个所以若有人翻过这可以解释这一点更好,这将是伟大的,因为我仍然在试图让这些引导概念的掌握
I am creating a BootLoader that boots from a CD and I am having trouble discovering how to find the start of the root Directory on the Disk here is my boot code:
BITS 16
ORG 0x00
Start: jmp main
;Colors for text
%DEFINE TEAL 0x03
%DEFINE RED 0x04
%DEFINE PURPLE 0x05
COL: db 0
ROW: db 0
;macro for print
%macro Print 2
pusha
xor ax, ax
xor dx, dx
mov dh, BYTE[ROW];puts the row into the dh register
mov dl, BYTE[COL]
xor bx, bx
mov bl, %2
mov si, %1
call cPrint
mov BYTE[COL], dl
;saves the rows for the next time we need to print
popa
%endmacro
Print_ln:
pusha
mov dh, BYTE[ROW]
mov ah, 0x02 ;set cursor pos
mov bh, 0x00 ;page 00
inc dh ;row 00
mov dl, 0x00 ;col. 00
int 0x10
mov BYTE[ROW], dh
mov BYTE[COL], 0
popa
ret
cPrint: ; Routine: output string in SI to screen
.top:
;Paramaters for Input
mov ah, 09h ; Must be 9 to print color
mov cx, 0x01 ;x position
lodsb ; Get character from string
test al, al
je .done ; If char is zero, end of string
int 0x10 ; Otherwise, print it
mov ah, 0x02 ;set cursor position
mov bh, 0x00 ;page
inc dl ;column
int 0x10 ;changes the cursor position so the next char can be written at the new location
jmp .top
.done:
ret
;clears the screen and sets the cursor position to the top left
clear:
mov ah, 0x0F ;get current video mode
mov al, 0x00 ;reset register
int 0x10 ;get video mode
mov ah, 0x00 ;set video mode
int 0x10 ;reset screen
mov ah, 0x02 ;set cursor pos
mov bh, 0x00 ;page 00
mov dh, 0x00 ;row 00
mov dl, 0x00 ;col. 00
int 0x10 ;set pos
ret
;CMPSB compares the byte at [DS:SI] or [DS:ESI] with the byte at [ES:DI]
;or [ES:EDI],
;and sets the flags accordingly. It then increments or decrements (depending
;on the direction flag: increments
; if the flag is clear, decrements if it is set) SI and DI (or ESI and EDI).
Read_Sectors:
;/* Read the sector into memory. */
.ForLoop:
mov ah,042h
xor al,al
mov si, DiskAddressPacket
mov dl, [CDDriveNumber]
int 013h
jnc .Success ; /* read error? */
Print Read_Sector_Error_MSG, RED
cli
hlt
.Success:
Print Progress_MSG , PURPLE
inc WORD[DiskAddressPacket.SectorsToRead]
loop .ForLoop
ret
main:
cli
mov ax, 0x07c0 ;adjust the segment registers
mov ds, ax
mov gs, ax
mov fs, ax
Create_Stack:
xor ax, ax
mov es, ax
mov ss, ax
mov sp ,0x0FFFE
sti
mov es, 0x200
mov [CDDriveNumber],dl
call clear
Print W_MSG, TEAL;prints the loading message in colour
call Print_ln
LOAD_ROOT:
;first calculate the start of the Root directory
mov WORD[DiskAddressPacket.Offset], 0x01000
mov cx, 0x01
call Read_Sectors
call Print_ln
Print READ_SUCCESS, TEAL
call Print_ln
cli
hlt
Sector_Size: dw 512
CDDriveNumber: db 80h
CD_bytes_per_sect: dw 0
CD_root_dir_size: dd 0
CD_root_dir_sectors: dw 0
CD_root_dir_start: dd 0
CD_file_size: dd 0
CD_file_sectors: dw 0
CD_file_start: dd 0
CD_desc_sector: dd 0
CD_Signature: db "\2CD001"
CD_FILE_VER: db 0x01
;Disk Address Packet
DiskAddressPacket: db 16,0
.SectorsToRead: dw 1 ; Number of sectors to read (read size of OS)
.Offset: dw 0 ; Offset :0000
.Segment: dw 0200h ; Segment 0200
.End: dq 16 ; Sector 16 or 10h on CD-ROM
RETURN: DB 0
W_MSG: db "Loading Z-Boot", 0
Stage2: db "STAGE2 BIN"
Read_Sector_Error_MSG: db "Error, failed to read sector",0
READ_SUCCESS: db "Sectors read in correctly",0
Progress_MSG: db ".",0
FILE_NOT_FOUND: db "Error, file not found",0
FOUND: db "Found", 0
times 2046 - ($ - $$) db 0; padd out the rest of the file to 0
DW 0xAA55
I saw some code that did something like this to find the Volume descriptor I have a feeling you need that to find the root directory but I can't put my finger on it here is the code that does that:
get_next_desc:
;/* Read the sector in memory at 0000:1000. */
mov [desc_sector],eax
mov bx,01000h
mov cx,1
call read_sectors
;/* Check for the signature "\2CD001" at the beginning of the descriptor. */
mov si, cd_signature
mov di,01000h
mov cx,6
cmpsb
je found_desc
;/* Check if we have looked in all the descriptors of volume. */
cmp byte [es:0x1000],0FFh
jne next_desc
;/* We looked in all sessions of the disk, and the OS image wasn't found.
; We display an error message on the screen and then prompts the user to
; press a key to restart the computer. */
mov si, msg_file_not_found
call print_string
jmp reboot
next_desc:
Here is what I use to assemble my code:
nasm ZerothStage.asm -o ZerothStage.bin
mkisofs -b ZerothStage.bin -no-emul-boot -o BootLoader.iso ./
Nevermind I got it apparently I needed to load the segment offset address from the DAP into ES:DI and look for the Volume descriptor there here is what i used to solve it if anyone is interested.
Code:
mov es, WORD[DiskAddressPacket.Segment]
mov di, WORD[DiskAddressPacket.Offset]
xor bx, bx
.top
mov al, BYTE[ES:DI+BX]
cmp al, ' '
je .Done
mov ah, 0xE
int 0x010
inc bx
jmp .top
.Done:
I read the fourth sector instead of the 16th sector apparently it is the last sector of the image that you must read in I am new to this so If anyone comes accross this could explain this a little better that would be great as I am still trying to get a grasp on these boot concepts
这篇关于找到根目录的BootLoader的开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!