Here's我的引導加載程序代碼和here's一個文檔顯示寄存器的圖片(萬一在我做錯了什麼是重要的),什麼在位置0x10000(我告訴引導加載程序加載內核),內核的源程序集以及Qemu運行時的屏幕輸出的內存中。引導加載程序總是混淆了Int 13h調用的前兩個字節來加載內核
kernelStub.bin在最開始有EB 1B(右跳命令)。 hda.img在第二部門開始時的55 AA之後擁有EB 1B。進位標誌在我的load_mem子程序中清楚表明它相信負載很好。所有的字節在內存中是正確的,除了前兩個總是63 61.
爲什麼load_mem例程總是將扇區2的前兩個字節加載到地址0x10000錯誤,然後讓剩下的權利呢?
的Bootloader代碼:
更新:改變jmp SYSADDR:0000
到jmp 0x1000:0x0000
每馬修·斯萊特里的修正。
;Very minimal boot loader
BITS 16 ;Tell assembler to use 16-bit mode
jmp start ;Jump over defines
SYSADDR dw 0x1000 ;Load system at 0x10000
DRIVENUM db 0x80 ;Variable for drive number
HEADNUM db 0
CYLNUM db 0 ;Low bits of cylinder number
SECTNUM db 2 ;Bits 6 and 7 high bits of cylinder number (0),
;Bits 0-5 starting sector number (2)
NUMKERNELSECTS db 0x01 ;Will Probably Change! Number of sectors
;to read from disk
load_msg db 'Loading OS', 0
msg_2 db 'carry flag not clear', 0
load_worked db 'Load worked', 0
start:
mov ax, 0x07C0 ;Set data segment to where BIOS loaded boot loader
mov ds, ax
mov si, load_msg ;Simple text string to indicate loading
call show_message
call load_mem ;Subroutine to load bytes from disk to location
;pointed to by es
jmp 0x1000:0x0000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Subroutines
;;;Show Message;;;
show_message:
mov ah, 0x0E ;int 0x10 print character to screen function
.repeat:
lodsb ;Get char pointed to by si, puts in al
cmp al, 0 ;see if char is 0 (null)
je .done ;null signifies done
int 0x10 ;If not null, print to screen
jmp .repeat ;Get next char
.done:
ret
;;;Load Memory;;;
load_mem:
xor ah, ah ;ah=0, reset drive
int 0x13 ;Call drive reset
mov ax, [SYSADDR]
mov es, ax ;Destination- es:bx
mov bx, 0
mov dl, [DRIVENUM]
mov dh, [HEADNUM]
mov al, [NUMKERNELSECTS]
mov ch, [CYLNUM]
mov cl, [SECTNUM]
mov ah, 0x02 ;ah=2, read drive
int 0x13 ;Call read interrupt
jnc exit ;If carry flag is clear, exit
exit:
ret
times 510 - ($-$$) db 0;Pad sector with 0
dw 0xAA55 ;Boot signature
請在此填寫您的代碼,以便將來不會改變或丟失。 –