我正在根据this tutorial
追踪this ebook.通过创建一个简单的内核握住了我的手。我正在写引导程序。
我正在尝试在我的引导程序之外访问内存,这让我感到悲伤。尝试读取BIOS磁盘读取中断(代码0xAA
)后,出现错误"fixed disk drive not ready"(代码int 0x13
)。
This is the tutorial section I'm up to,以及电子书中相应的第28页(推荐阅读!)
这是我的引导程序boot_sect_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
我尝试使用以下各项运行qemu
:
> 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
似乎没有任何效果!我在这里做什么错了?
谢谢。