我已经写了一些简单的引导程序,可以在QEMU中很好地工作,所以我决定在真实的机器上尝试一下。我将图像文件复制到闪存驱动器,并尝试从中加载。但是由于某种原因,我一直只得到黑屏,而光标位于左上角附近,这使我认为在屏幕上显示字符串可能有些问题。为了检查这个想法,我编写了一个简单的引导程序,显示消息“ Loading Image”,并检查是否支持IO扩展(int 13h ah = 42)。如果受支持,则显示消息“ Extensions are here”。因此,在qemu中它可以正常工作,并且我得到了预期的这两个消息。但是在我的计算机上,而不是两行,我得到的是这样的一行:“ LoaExtensions在这里”。要打印消息,我使用int 10h ah = 0Eh 我尝试使用int 10h的ah = 0功能设置不同的视频模式,但是我总是得到相同的结果。 您能帮我了解可能出什么问题吗? 这是代码:
bits 16 ; we are in 16 bit real mode
org 0 ; we will set regisers later
start: jmp Main ; jump to start of bootloader
msgLoading db "Loading Image ", 0x0D, 0x0A, 0x00
msgSectorReadingError db "ERROR: Can't read sectors from disk",0x0D,0x0A, 0x00
msgExtNotSupported db "ERROR: BIOS doesn't support LBA",0x0D,0x0A, 0x00
msgErrWhileLoadingImage db "ERROR: Couldn't read seconday image",0x0D,0x0A, 0x00
msgExtSupported db "Extensions are here",0x0D,0x0A, 0x00
imgName db "STAGE2 SYS"
;************************************************;
;************************************************;
; Prints a string
; DS=>SI: 0 terminated string
;************************************************;
Print:
lodsb ; load next byte from string from SI to AL
or al, al ; Does AL=0?
jz PrintDone ; Yep, null terminator found-bail out
mov ah, 0xE ; Nope-Print the character
int 0x10
jmp Print ; Repeat until null terminator found
PrintDone:
ret ; we are done, so return
;************************************************;
; Set Video mode
;
;************************************************;
SetVideoMode:
mov ax,0x0002
int 0x10
ret
;***********************************************;
; Checks whether BIOS supports extensions
;************************************************;
CheckExtenstions:
xor ax,ax
mov ah,0x41
xor dx,dx
mov dl,BYTE[driveNumber]
mov bx,0x55AA
int 0x13
cmp bx,0xAA55
jnz .error
test cl,0x1
jz .error
jmp .exit
.error:
mov si,msgExtNotSupported
call Print
cli
hlt
.exit:
mov si,msgExtSupported
call Print
cli
hlt
ret
Main:
;----------------------------------------------------
; code located at 0000:7C00, adjust segment registers
;----------------------------------------------------
cli ; disable interrupts
mov ax, 0x07C0 ; setup registers to point to our segment
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
;----------------------------------------------------
; create stack
;----------------------------------------------------
mov ax, 0x0000 ; set the stack
mov ss, ax
mov sp, 0xFFFE
mov BYTE[driveNumber],dl
sti ; restore interrupts
call SetVideoMode
mov si, msgLoading ; Show Loading Message
call Print
call CheckExtenstions
cli
hlt
TIMES 510-($-$$) DB 0
DW 0xAA55