扩展中断13,读取未格式化的磁盘
我已经有一段时间没有做过任何 ASM 了,并决定再次尝试编写一个小型引导加载程序,并使用 qemu 进行测试。我的问题是中断 13,由于某种原因设置了进位标志,因此读取失败。目前,我的磁盘映像如下所示:
512 Byte BootLoader <- 这(据我所知)是 LBA 中的块 0
主要功能 <- 这将be block 1
基本上,BIOS 将 512 字节加载到内存中,我想从同一驱动器加载接下来的 512 字节。但我不知道出了什么问题。希望我已经提供了足够的信息。
这是代码,问题出在第二个 0x13 中断,就在跳转到 0x7E00 之前:
[bits 16]
[org 0x7C00]
; Prepare Stack Segment
;-----------------------------------------------------------------
mov sp, 0x7A00 ; Move Stack into SP
mov bp, sp ; Store current Stack Base
; Print Character to Make Sure Bootloader Has Reached this Point
;-----------------------------------------------------------------
mov ah, 0x0E ; Print Character to Screen
mov bh, 0x00 ; No Page Numbering
mov bl, 0x07 ; White Text, Black Background
mov al, 65 ; Print Letter A
int 0x10
; Check if INT0x13 Extentions are Supported
;-----------------------------------------------------------------
mov ah, 0x41 ; Set Function 0x41
mov word bx, 0x55AA
push dx ; Save old Drive Identifier
mov dl, 0x80 ; Load 'Active' ID Into dl
int 0x13 ; Call Interupt
jc short unsupported ; If Extentions aren't Supported, Jump
xor ax, ax
add ax, 1 ; Clear Carry Bit
mov si, DAPS ; Load DAPS Struct to DS:SI
mov ah, 0x42 ; Read Functions (AL Ignored)
mov dl, 0x80 ; Active Boot Drive (Commented Out Due to Line 24)
int 0x13
jc short unsupported ; If something goes wrong...
jmp 0x7E00 ; Jump to main
; Errors
;-----------------------------------------------------------------
unsupported:
mov ah, 0x0E ; Print Letter F, Gives Indication of Failure
mov bh, 0x00
mov bl, 0x07
mov al, 70
int 0x10
success:
pop dx ; Pop Original Drive Identifier
jmp $
; Fill Out Rest of Bootloader
;-----------------------------------------------------------------
times 494-($-$$) db 0
; Memory Data Structures and Other Variables
;-----------------------------------------------------------------
; Disk Address Packet Structure (Used For Loading Rest of OS)
DAPS: db 0x10 ; Size of Structure (16 bytes)
db 0 ; Always 0
db 1 ; Number of Sectors to Read (1x512)
db 0 ; Always 0
dw 0x7E00 ; Target Location for Reading To
dw 0 ; Page Table (0, Disabled)
dd 1 ; Read from Second Block
dd 0 ; Large LBAs, ignore
db 0x55, 0xAA ; Add Boot Record Signature
main:
mov ah, 0x0E ; Print Character to Screen
mov bh, 0x00 ; No Page Numbering
mov bl, 0x07 ; White Text, Black Background
mov al, 66 ; Print Letter B
int 0x10
jmp $
It's been a while since I did any ASM, and decided to once again try and write a small bootloader, testing with qemu. My issue is with interupt 13, for some reason the carry flag is being set, so the read is failing. Currently, my disk image looks like:
512 Byte BootLoader <- This (as far as I'm aware) Is block 0 in LBA
Main Function <- This would be block 1
Basically, with the 512 bytes the bios loads into memory, I want to load the next 512 bytes from the same drive. I can't figure out what's going wrong however. Hope I've given enough information.
Here's the code, the problem is with the second 0x13 interrupt, just before the jump to 0x7E00:
[bits 16]
[org 0x7C00]
; Prepare Stack Segment
;-----------------------------------------------------------------
mov sp, 0x7A00 ; Move Stack into SP
mov bp, sp ; Store current Stack Base
; Print Character to Make Sure Bootloader Has Reached this Point
;-----------------------------------------------------------------
mov ah, 0x0E ; Print Character to Screen
mov bh, 0x00 ; No Page Numbering
mov bl, 0x07 ; White Text, Black Background
mov al, 65 ; Print Letter A
int 0x10
; Check if INT0x13 Extentions are Supported
;-----------------------------------------------------------------
mov ah, 0x41 ; Set Function 0x41
mov word bx, 0x55AA
push dx ; Save old Drive Identifier
mov dl, 0x80 ; Load 'Active' ID Into dl
int 0x13 ; Call Interupt
jc short unsupported ; If Extentions aren't Supported, Jump
xor ax, ax
add ax, 1 ; Clear Carry Bit
mov si, DAPS ; Load DAPS Struct to DS:SI
mov ah, 0x42 ; Read Functions (AL Ignored)
mov dl, 0x80 ; Active Boot Drive (Commented Out Due to Line 24)
int 0x13
jc short unsupported ; If something goes wrong...
jmp 0x7E00 ; Jump to main
; Errors
;-----------------------------------------------------------------
unsupported:
mov ah, 0x0E ; Print Letter F, Gives Indication of Failure
mov bh, 0x00
mov bl, 0x07
mov al, 70
int 0x10
success:
pop dx ; Pop Original Drive Identifier
jmp $
; Fill Out Rest of Bootloader
;-----------------------------------------------------------------
times 494-($-$) db 0
; Memory Data Structures and Other Variables
;-----------------------------------------------------------------
; Disk Address Packet Structure (Used For Loading Rest of OS)
DAPS: db 0x10 ; Size of Structure (16 bytes)
db 0 ; Always 0
db 1 ; Number of Sectors to Read (1x512)
db 0 ; Always 0
dw 0x7E00 ; Target Location for Reading To
dw 0 ; Page Table (0, Disabled)
dd 1 ; Read from Second Block
dd 0 ; Large LBAs, ignore
db 0x55, 0xAA ; Add Boot Record Signature
main:
mov ah, 0x0E ; Print Character to Screen
mov bh, 0x00 ; No Page Numbering
mov bl, 0x07 ; White Text, Black Background
mov al, 66 ; Print Letter B
int 0x10
jmp $
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题很简单,代码是正确的。但由于最终图像为 525 字节,而不是 512 字节的倍数,因此读取失败。只需用 0 填充图像即可使图像大小为 1024B,这样读取就可以获得全部 512 字节。
(显然,没有像这样的小型未格式化磁盘可能是一个更好的主意,但出于学习目的,这就是我真正需要的)
Problem ended up being simple, the code was right. But because the final image was 525 bytes, instead of a multiple of 512 bytes, the read broke. Just had to pad my image out with 0s to make the image size 1024B so the read could get all 512 bytes.
(Obviously probably a much better idea to not have a tiny unformatted disk like this, but for learning purposes this is all I really needed)