Extendido de interrupción 13, Lectura de un disco sin formato
-
22-09-2019 - |
Pregunta
Ha sido un tiempo desde que hice ninguna ASM, y decidí una vez más tratar de escribir un pequeño gestor de arranque, prueba con QEMU. Mi problema es con interupt 13, por alguna razón la bandera de acarreo se está estableciendo, por lo que la lectura está fallando. Actualmente, mi imagen de disco se ve así:
512 Byte BootLoader <- Este (por lo que yo sepa) es el bloque 0 en LBA
Función principal <- Este sería el bloque 1
Básicamente, con los 512 bytes que el BIOS carga en la memoria, quiero cargar los próximos 512 bytes desde la misma unidad. No puedo imaginar lo que va mal sin embargo. La esperanza me he dado suficiente información.
Este es el código, el problema está en la segunda interrupción 0x13, justo antes del salto a 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 $
Solución
Problema terminó siendo sencilla, el código correcto. Pero debido a que la imagen final fue de 525 bytes, en lugar de un múltiplo de 512 bytes, la lectura se rompió. Sólo tenía para rellenar mi imagen con 0s para hacer que el tamaño de la imagen 1024B por lo que la lectura podría conseguir los 512 bytes.
(Obviamente probablemente una mejor idea de no tener un pequeño disco sin formato como este, pero a efectos de aprendizaje esto es todo lo que realmente necesitaba)