2013-05-03 80 views
0

我編寫了以下引導加載程序,但存在問題。Linux中的引導加載程序

;=================================================================== 
;Following is an incomplete code of a boot-loader with blanks(.....) 
;Replace each blank with appropriate word, words or character 
;=================================================================== 

[ORG 0x7C00] 

;============================================================== 
;MSG2, MSG3 and MSG4 should describe the right order of typical 
;boot-loading functionality (i.e. What basially a boot-loader does?) 

MSG1 dd '1. Boot Loader starts ', 0 
MSG2 dq '2. Initialize Hardware', 0 
MSG3 dq '3. Pass an abstraction of Initialize Hardware', 0 
MSG4 dq '4. Execute Kernel', 0 
MSG5 dq '5. Boot Loader exits ', 0 
;============================================================== 

;============================================================== 
;Printing the messages (MSG1, MSG2, .....) 

MOV SI, MSG1 
CALL PrintString ;Call print string procedure 
MOV SI, MSG1 
CALL PrintString ;Call print string procedure 
MOV SI, MSG2 
CALL PrintString ;Call print string procedure 
MOV SI , MSG3 
CALL PrintString ;Call print string procedure 
MOV SI , MSG4 
CALL PrintString ;Call print string procedure 
MOV SI, MSG5 
CALL PrintString ;Call print string procedure 

JMP $ ;infinite loop here 
;=============================================================== 

;=============================================================== 
PrintCharacter: ;Procedure to print character on screen 

MOV AH, 0x0E 
MOV BH, 0x00 
MOV BL, 0x07 

INT 0x10 
RET 
;=============================================================== 

;=============================================================== 
PrintString: ;Procedure to print string on screen 

MOV AL , [SI] 
CALL PrintCharacter 
NextChar: 
INC SI 
MOV AL , [SI] 
CMP AL , 0 
JZ exit_function 
CALL PrintCharacter 
JMP NextChar 
exit_function: 
RET 
;=============================================================== 

;=============================================================== 

times (495) - ($ - $$) db 0 
db 0 
dw 0xAA52 
dd 0xAA53 
dq 0xAA54 
dw 0xAA55 ;End of Boot-loader 

;=== 

它不輸出第一條消息。我該如何糾正它?。謝謝。

回答

2

對於定義字符串,您應該使用db(或可能是dw)而不是dd/dq

哦,你應該跳到之前之前的字符串數據,否則CPU會認爲字符串是應該執行的代碼。

2

比這(省略的評論)還沒有讀任何進一步:

[ORG 0x7C00] 

MSG1 dd '1. Boot Loader starts ', 0 

這意味着你的代碼的前幾個字節是不是代碼可言,而是一個ASCII字符串。你想要的東西是這樣的:

[ORG 0x7C00] 

jmp start 

; comments blah blah blah 
MSG1 db '1. Boot Loader starts ', 0 
; ... etc ... 

start: 

; instructons start here. 

mov si, MSG1 
; ... 
+1

可能還想確保'ds'爲零。它可能是,當BIOS將控制權轉移到我們的引導加載程序,但它不能保證! – 2013-05-03 09:21:11