使用int 13h在真实机器上使用引导加载程序从驱动器读取



嘿,我正在尝试加载一个字符串,该字符串放置在引导加载程序的末尾或0x7e00。我正在尝试使用 int 13h 将字符串加载到内存中,然后将其打印到屏幕上。我检查错误,但没有发生错误。但是,没有任何东西打印到屏幕上,它只是挂在空白屏幕上。

这是我的引导加载程序代码:

[org 0x7c00]
[bits 16]
mov byte [driveno], dl    ;save dl
;set up stack
xor ax, ax
cli
mov ss, ax
mov sp, 0x9000
sti
;set up segment regs
jmp 0x0000:start
start:
xor ax, ax
mov ds, ax
mov es, ax
;reset drive
xor ax, ax
int 0x13
;read 2nd sector
mov al, 0x01
mov bx, 0
mov es, bx
mov bx, 0x7e00
mov cx, 0x0002
xor dh, dh
mov dl, byte [driveno]
mov ah, 0x02
int 0x13
jc read_error   ;Apparently no error!!!
mov ah, 0x01   ;Check status of last operation
int 0x13
mov dx, ax     ;Print the value stored in ax
call printhex   ;This outputs 0x0001 or al=01 so I get an invalid function error?
mov si, 0x7e00   ;print my "loaded" message
call print
mov si, teststr  ;test if my print function works, it does.
call print
cli
hlt
jmp $
read_error:
mov si, error
call print
ret
print:
loop:
lodsb
or al, al
jz done
mov ah, 0x0e
mov bx, 0x0003 ;page 0 and default color
int 0x10
jmp loop
done:
ret
printhex:   ;This method allows me to see what is inside of registers such    as ax.
push bx
push si
mov si, hex_template
mov bx, dx
shr bx, 12
mov bx, [bx+hexabet]
mov [hex_template+2], bl
mov bx, dx
shr bx, 8
and bx, 0x000f
mov bx, [bx+hexabet]
mov [hex_template+3], bl
mov bx, dx
shr bx, 4
and bx, 0x000f
mov bx, [bx+hexabet]
mov [hex_template+4], bl
mov bx, dx
and bx, 0x000f
mov bx, [bx+hexabet]
mov [hex_template+5], bl
call print
pop si
pop bx
ret

error db 'Error',0
teststr db 'Printing works',0
hex_template db '0x????',0  ;For my hex print method
hexabet db '0123456789abcdef' ;Also for my hex print method
driveno db 0      ;Storing dl
times 510-($-$$) db 0
dw 0xaa55
db 'ABCD',0   ;this needs to be loaded
times 1024-($-$$) db 0   ;fill my file so it is 2 whole sectors

我编译

nasm -f bin boot.asm -o boot.bin

我用

dd if=boot.bin of=\.e: bs=512 count=2

有谁知道为什么当我启动到USB时我的消息不显示?谢谢!

你应该像这样重新排列你的代码。

    [org 0x7c00]
    [bits 16]
    jmp 0x00:0x7c00
start:  
    ;set up stack and segment registers
    xor ax, ax
    cli
    mov ds,ax
    mov es,ax
    mov ss, ax
    mov sp, 0x9000
    sti
    ;Save driveno
    mov byte[driveno],dl
    ;reset drive
    xor ax, ax
    int 0x13
    ;read 2nd sector
    mov al, 0x01
    mov bx, 0
    mov es, bx
    mov bx, 0x7e00
    mov cx, 0x0002
    xor dh, dh
    mov dl, byte [driveno]
    mov ah, 0x02
    int 0x13
    jc read_error   ;Apparently no error!!!
    mov ah, 0x01   ;Check status of last operation
    int 0x13
    mov dx, ax     ;Print the value stored in ax
    call printhex   ;This outputs 0x0001 or al=01 so I get an invalid function error?
    mov si, 0x7e00   ;print my "loaded" message
    call print
    mov si, teststr  ;test if my print function works, it does.
    call print
    cli
    hlt
    jmp $
    read_error:
    mov si, error
    call print
    ret
    print:
    loop:
    lodsb
    or al, al
    jz done
    mov ah, 0x0e
    mov bx, 0x0003 ;page 0 and default color
    int 0x10
    jmp loop
    done:
    ret
    printhex:   ;This method allows me to see what is inside of registers such    as ax.
    push bx
    push si
    mov si, hex_template
    mov bx, dx
    shr bx, 12
    mov bx, [bx+hexabet]
    mov [hex_template+2], bl
    mov bx, dx
    shr bx, 8
    and bx, 0x000f
    mov bx, [bx+hexabet]
    mov [hex_template+3], bl
    mov bx, dx
    shr bx, 4
    and bx, 0x000f
    mov bx, [bx+hexabet]
    mov [hex_template+4], bl
    mov bx, dx
    and bx, 0x000f
    mov bx, [bx+hexabet]
    mov [hex_template+5], bl
    call print
    pop si
    pop bx
    ret

    error db 'Error',0
    teststr db 'Printing works',0
    hex_template db '0x????',0  ;For my hex print method
    hexabet db '0123456789abcdef' ;Also for my hex print method
    driveno db 0      ;Storing dl
    times 510-($-$$) db 0
    dw 0xaa55
    db 'ABCD',0   ;this needs to be loaded
    times 1024-($-$$) db 0   ;fill my file so it is 2 whole sectors

它应该已经解决了你的问题。

最新更新