我无法从x86汇编中的CD-ROM读取扇区 [英] I can't read a sector from a CD-ROM in x86 assembly
问题描述
我正在尝试从我的OS32操作系统的ISOSYS引导加载程序中加载第二阶段的引导加载程序,但是我似乎做不到.CF似乎总是被设置.这将从CD/DVD引导,我正在使用Debian GNU/Linux 7.6(Wheezy)
I'm trying to load the second stage bootloader from my ISOSYS bootloader for my OS32 operating system, but I can't seem to do it. CF seems to always be set. This is to be booted from a CD/DVD and I'm using Debian GNU/Linux 7.6 (Wheezy)
这是isosys.asm:
Here's isosys.asm:
;===============================================================
;
; ISOSYS v1.0 in isosys.asm
;
; Program for booting OS32 and OS32-based systems from CD/DVDs
; using the ElTorito boot standard.
;
; By Omar, 2014
;
; ===============================================================
; set up bios...
bits 16
org 0x7c00
; beginning of sector 1, byte 0:
; jump over functions block
jmp Start
;
; Print()
; prints a string to standard output
; AL = 0 : terminate
;
Print:
lodsb ; grab a byte from SI and place it in AL
cmp al, 0 ; is AL = 0?
jc PrintDone ; yep, we're done so return
mov ah, 0eh
int 0x10 ; nope, print the character
jmp Print ; loop until no more characters to be printed
PrintDone:
ret ; return to wherever we were!
;
; Start()
; bootloader entry point
;
Start:
mov si, creditmsg
call Print ; print the first message
mov dh, 1 ; read 1 sector
.ReadSector:
cli ; disable interrupts
push dx ; push this stack value
sti ; re-enable interrupts
mov ax, 0x1000 ; read sector into address 0x1000
xor bx, bx ; read sector into offset 0x0
mov ah, 0x02 ; read sector function
mov al, dh ; read 1 sector
mov ch, 0x0 ; must be 0x0 to read sector
mov dh, 0 ; reading head 0
mov cl, 0x02 ; start reading from sector 2 to load the second stage
mov [CDDriveNumber], dl ; store our drive number is variable CDDriveNumber
cli ; disable interrupts
pusha ; save the stack
sti ; enable interrupts
int 0x13 ; INT 13h
jc Error ; handle error because Carry Flag is set
pop dx ; Restore DX
.ExecuteSector:
; now that our sector was loaded into address 0x1000:0x0, let's execute it!
jmp 0x1000:0x0 ; jump to execute the sector
;
; Error()
; handles errors when carry is set
;
Error:
mov si, errmsg
call Print ; print an error message
cli ; disable interrupts to prevent problems
hlt ; halt the system... :(
; data section
creditmsg db "ISOSYS v1.0 by Omar Mohammad, Init...", 0
errmsg db "Cannot load the second stage. (File not found maybe?)", 0
CDDriveNumber db 0
times 2048 - ($-$$) db 0 ; fill in 2048 bytes with zeroes
; end of sector 1! :D Any more code here would take bytes 2048 and 2049 but we don't need that...
这是boot.asm,第二阶段:
This is boot.asm, the second stage:
bits 16
org 0x1000
Main:
xor bx, bx
mov ah, 0eh
mov al, 'A'
int 0x10
cli
hlt
times 2048 - ($-$$) db 0
我使用 nasm -f bin isosys.asm -o ISOSYS
和 nasm -f bin boot.asm -o BOOT
进行了编译然后我做了 mkdir iso
,然后是 cp ISOSYS iso/
,然后是 cp BOOT iso/
,然后生成了ISO: genisoimage -no-emul-boot -boot-load-size 4 -eltorito-boot ISOSYS -o boot.iso iso/
I compiled with nasm -f bin isosys.asm -o ISOSYS
and nasm -f bin boot.asm -o BOOT
Then I did mkdir iso
and then cp ISOSYS iso/
then cp BOOT iso/
and then generated ISO:
genisoimage -no-emul-boot -boot-load-size 4 -eltorito-boot ISOSYS -o boot.iso iso/
我在VirtualBox中运行它,但它只说是无法加载第二阶段(也许找不到文件?),这意味着已设置了进位标志,但我似乎找不到错误.
I run it in VirtualBox but all it says is Cannot load the second stage (file not found maybe?) which means that Carry Flag is set but I can't seem to find the error.
有帮助吗?帮助将不胜感激!:*
Any help anyone? Help would be greatly appreciated! :*
推荐答案
您的堆栈处理已完全关闭.您将 dx
(为什么?)推入 cli
‥ sti
块(WHY?)内,然后将其推入 pusha
,但不要't popa
.
Your stack handling is totally off. You push dx
(why?) inside a cli
‥sti
block (WHY?), then pusha
but don't popa
.
在 mov ax,0x1000
之后,您实际上还缺少一个 mov es,ax
,它实际上将段寄存器设置为要在其上加载代码的位置.
You're also missing a mov es,ax
after the mov ax, 0x1000
to actually set the segment register to where you want your code to be loaded at.
您无法使用CHS功能(AH = 02h)读取ISO,必须将LBA功能(AH = 42h)与参数块一起使用.有一个例子.
You cannot read ISOs with the CHS function (AH=02h), you must use the LBA function (AH=42h) with a parameter block. Have an example.
这篇关于我无法从x86汇编中的CD-ROM读取扇区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!