X86 编写引导加载程序&;内核--”;“固定驱动器未就绪”;通过QEMU启动自定义引导加载程序时
我是以下,基于(也阅读) 它通过创建一个简单的内核来牵手我。我正在写引导程序 我试图访问我的引导扇区之外的内存,这让我很伤心。在尝试BIOS磁盘读取“中断(代码X86 编写引导加载程序&;内核--”;“固定驱动器未就绪”;通过QEMU启动自定义引导加载程序时,x86,operating-system,qemu,bootloader,X86,Operating System,Qemu,Bootloader,我是以下,基于(也阅读) 它通过创建一个简单的内核来牵手我。我正在写引导程序 我试图访问我的引导扇区之外的内存,这让我很伤心。在尝试BIOS磁盘读取“中断(代码int0x13)后,我得到了错误(代码0xAA) ,以及电子书中相应的第28页(非常好的阅读,推荐!) 这是我的引导加载程序boot\u sect\u main.asm: ; ; Simple bootsector that prints a line ; [org 0x7c00] ; Offset for star
int0x13
)后,我得到了错误(代码0xAA
)
,以及电子书中相应的第28页(非常好的阅读,推荐!)
这是我的引导加载程序boot\u sect\u main.asm
:
;
; Simple bootsector that prints a line
;
[org 0x7c00] ; Offset for start of loaded bootsector at mem address 0x7c00
; Offets are treated absolutely -- i.e. from the beginning of memory, but
; our code gives the offset from the start of our loaded code, i.e. the
; Initialization
mov [BOOT_DRIVE], dl ; BIOS stores boot drive in dl. Save for later.
mov bp, 0x8000 ; Set the stack far away from us
mov sp, bp
; Load data
mov bx, 0x9000 ; Load sectors 0x0000:0x9000 (ES:BX)
mov dh, 2
mov dl, [BOOT_DRIVE]
call disk_load
mov dx, [0x9000] ; Print first loaded word (expect to be 0xdada, see EOF)
call print_hex
mov dx, [0x9000 + 512] ; Print first word from 2nd loaded sector
call print_hex
; Main
jmp $
%include "lib_str.asm"
%include "lib_disk.asm"
; Global variables
BOOT_DRIVE: db 0
BOOT_MESSAGE: db "Booting custom OS...", 0
; Bootsector padding & magic number
times 510 - ($-$$) db 0
dw 0xaa55
times 256 dw 0xdada
times 256 dw 0xface
这是我的lib_disk.asm
,我在这里触发磁盘读取中断,0x13
:
; disk_load loads the DH sectors to ES:BX
; from drive DL.
; --paramaters--
; bx: offset. E.g. 0x9000 reads from 0x0000:0x9000.
; dh: number of sectors to read
; dl: boot drive
disk_load:
pusha
push dx ; Store DX so we can recall how many sectors we
; requested to read.
mov ah, 0x02 ; BIOS read sector function
mov al, dh ; Read DH sectors
mov ch, 0 ; Cylinder 0
mov dh, 0 ; Head 0
mov cl, 2 ; Start reading from second sector
; (i.e. after boot sector)
int 0x13 ; BIOS interrupt to read the disk
; [es:bx] <- pointer to buffer with data
jc disk_error ; Jump if error (i.e. carry flag set)
pop dx ; Restore number of sectors we requested
cmp dh, al ; If didn't read the right number of sectors...
jne sector_error ; Error
popa
ret ; Otherwise return
; disk_error prints the disk error message
; and hangs.
disk_error:
mov bx, DISK_ERROR_MESSAGE
call print_str
call print_nl
mov bx, 0
mov bh, ah ; ah = error code
mov ax, bx
call print_hex
jmp $
; sector_error prints the sector error
; message, and then hands
sector_error:
mov ax, SECTOR_ERROR_MESSAGE
call print_str
call print_nl
jmp $
DISK_ERROR_MESSAGE: db "Disk read error!", 0
SECTOR_ERROR_MESSAGE: db "Sector read error!", 0
好像什么都没用!我做错什么了
提前谢谢。您没有向我们展示您的文件
lib_str.asm
。您是如何构建(生成)main.bin的main.bin
。您在什么操作系统上进行开发的?(Windows?Linux?MacOS?其他。通常您会以这种方式运行i386模拟器qemu-system-i386-drive file=main.bin,index=0,media=disk,format=raw
> qemu -fda main.asm
> qemu main.asm -boot c
> qemu -drive file=main.bin,index=0,media=disk,format=raw
> qemu -drive file=main.bin,index=0,media=disk,format=raw -boot c