Domanda

E 'stato un po' che ho fatto qualsiasi ASM, e ho deciso di provare ancora una volta e scrivere un piccolo bootloader, il test con QEMU. Il mio problema è con interrupt 13, per qualche motivo è stato impostato il flag di carry, in modo che la lettura sta fallendo. Attualmente, la mia immagine del disco appare come:

512 Byte BootLoader <- Questo (per quanto io sappia) è blocco 0 a LBA

Funzione principale <- Questo sarebbe blocco 1

In sostanza, con i 512 byte Il BIOS carica in memoria, voglio caricare i prossimi 512 byte dalla stessa unità. Non riesco a capire che cosa sta andando male comunque. Spero di aver dato abbastanza informazioni.

Ecco il codice, il problema è con il secondo interrupt 0x13, poco prima che il salto per 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 $
È stato utile?

Soluzione

Problema finito per essere semplice, il codice è stato giusto. Ma perché l'immagine finale è stato 525 byte, invece di un multiplo di 512 byte, la lettura si è rotto. Appena avuto per riempire la mia immagine con 0s per rendere l'1024b dimensioni dell'immagine in modo che la lettura potrebbe ottenere tutti i 512 byte.

(Ovviamente probabilmente un'idea molto meglio non ha un piccolo disco non formattato in questo modo, ma per scopi di apprendimento questo è tutto quello che ho davvero bisogno)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top