它已经一段时间,因为我没有任何ASM,并决定再次尝试写一个小的引导程序,用QEMU测试。我的问题是与interupt 13,由于某种原因,进位标志被设定,所以读取失败。目前,我的磁盘映像如下:

512字节的BootLoader < - 该(据我所知)是块0中LBA

主要功能 < - 这将是块1

基本上,与512字节的BIOS加载到内存中,我想从相同的驱动器装载下一个512个字节。我想不通但是什么错误。希望我已经给了足够的信息。

下面是代码,问题是与第二0×13中断,只是跳到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 $
有帮助吗?

解决方案

问题结束了简单,代码是正确的。但由于最终的图像为525个字节,而不是512个字节的倍数,读破了。只是要我垫出的图像以0使图像尺寸1024B所以读可以得到所有512个字节。

(显然可能是一个更好的主意,不是有一个微小的未格式化的磁盘是这样,但对于学习的目的,这是所有我真正需要的)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top