问题描述
我有一个自定义 MBR,我用 NASM 将其编译为二进制文件,我可以在 qemu 和 bochs 中正常启动它。
我正在尝试使用 boot mbr.bin
在 DosBox 中启动此 MBR。只要 MBR 很小并且不调用 int 13h
来从磁盘读取扇区,这就能正常工作。
如果我尝试读取下一个扇区,它会失败,从而导致某种磁盘读取错误。我想这与 dl
的值没有设置为“启动驱动器”有关。我尝试将 dl
手动设置为 0 和 80h,但都不起作用。
有谁知道 dl
的值应该是什么,以便使用 int 13h
命令使 boot
在 DosBox 中工作?或者是否有其他方法可以动态获取该值?
编辑;这是初始代码:
cpu 386
BITS 16
org 7C00h
; Calculate the full size of the code from start of segment $$ to the end label at the bottom (end - $$)
%define SECTORS_TO_LOAD ((end - $$) / 512) + ((end - $$) % 512 > 0) - 1
main:
jmp 0x0000:setcs
; Some error messages
disk_err db "Error reading disk",0
sector_err db "Error reading sector",0
setcs:
; Base setup
cld
xor ax,ax ; Set ES=DS=0 - this can be changed later for rep operations
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x7c00
; Clear the screen
mov ah,0x07 ; Function 0x07: scroll window
mov al,0x00 ; Clear entire window
mov bh,0x07 ; White on black
mov cx,0x00 ; Specifies top left of screen as (0,0)
mov dh,0x18 ; 18h = 24 rows of chars
mov dl,0x4f ; 4fh = 79 cols of chars
int 0x10 ; Video interrupt
; Move cursor to position 0,0
mov ah,0x02 ; Function 0x02: set cursor position
mov dh,0x00 ; Row 0
mov dl,0x00 ; Col 0
mov bh,0x00 ; Page 0
int 0x10 ; Video interrupt
; Load the calculated numbers of sector from the disk
; For this function call,dl should be set to the disk number to read from. The BIOS sets dl to
; the disk number of the MBR and dl was not changed,so we don't have to set it.
;mov dl,0x80
mov ax,SECTORS_TO_LOAD ; Number of sectors to read
mov bx,next_sector ; The memory address to read to
xor ch,ch ; Cylinder 0
mov cl,0x02 ; Start at sector 2 (sector 1 is the first part of the MBR)
xor dh,dh ; Head 0
mov ah,0x02 ; Read mode
int 0x13 ; Read interrupt
jc .disk_error ; Check carry bit for error
cmp al,SECTORS_TO_LOAD ; The interrupt sets 'al' to the number of sectors actually read
jne .sectors_error
; After a succesful load,the layout in memory will be the same as the layout in our ASM files,; so we can jump to a defined label without worrying about offsets and exact addresses.
jmp after_load
.disk_error:
push disk_err ; Print a disk error message
call print
cli ; Halt all interrupts and operations
hlt
.sectors_error:
push sector_err ; Same as above,different message
call print
cli
hlt
; The print function prints a string onto the screen in text mode
print:
push bp ; Basic stack setup
mov bp,sp
pusha ; Push everything - this function doesn't
; return anything
mov si,[bp+4] ; Grab the pointer to the data
mov bh,0 ; Page 0
mov bl,0 ; Foreground color,irrelevant - in text mode
mov ah,0x0E ; Function 0x0E: print character in TTY
.char:
mov al,[si] ; Get current char from pointer position
inc si ; Keep incrementing si until a null char
or al,0
je .return
int 0x10 ; Video interrupt
jmp .char
.return:
popa ; Restore registers
mov sp,bp ; Restore stack
pop bp
ret 2 ; Remove param from stack on return
times 510-($-$$) db 0
; MBR signature
db 55h,0AAh
next_sector:
之后,在 next_sector 下,它有一些 incbins 和一些其他代码,包括标签 after_load
。
我得到的错误是第一个; “读取磁盘时出错”,显示正常。这样看来es,ds等都设置对了。
注意注释掉的 mov dl,0x80
- 这是我尝试让它工作的尝试之一。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)