2014-01-11 65 views
2

我對這個引導加載程序非常陌生和困惑。我使用QEMU引導程序。我真的遇到了如何在NASM中加載內核或某些.asm文件的問題。我已經實現了我的內核文件,我想把它加載到我的啓動文件中。在引導程序中加載內核

我只要按照互聯網有什麼用建立一個引導扇區說,我想出了這個:

[BITS 16]  
[ORG 0x7C00] 

mov [bootdrv], dl ;put drive number 
     ;disable interrupt, set stack, enable interrupt       
cli      
mov ax, 0x9000   
mov ss, ax    
mov sp, 0    
sti   

... 
*some code here nothing to do with loading 
... 

.load_kernel:  
    call read_kernel   ; Load stuff from the bootdrive 
    jmp dword KERNEL_SEGMENT:0 

read_kernel: 
    push ds    
    .reset: 
     mov ax, 0    ;reset disk 
     mov dl, [bootdrv]  ;drive to reset 
     int 13h     
     jc .reset    ;try again if fail 
    pop ds 

.read: 
    *this is where I became confused and lost. I read that you should 
    locate your kernel and pass around using the bootdrv(drive number) 
    and return. I can't seem to understand. 

任何答案將是非常有益因爲我是真的失去了。

回答

1

你可以把你的內核放在你想要的任何地方。 最簡單的解決方案是用零填充引導加載程序扇區的其餘部分,並繼續將代碼寫入同一文件。

; your code 
... 

; bootloader has 512 bytes, so... 

; fill up to 510 bytes with zeroes and ... 
times 510-($-$$) db 0 

; place the boot signature on the end 
dw 0xAA55 

裝貨,你可以使用的中斷0x13功能2

.read: 
    push es ; save ES if there's something important in it 

    ; load the "kernel" at KERNEL_SEGMENT:0 
    mov ax, KERNEL_SEGMENT 
    mov es, ax 
    xor bx, bx 

    ; your kernel will have 512 bytes (1 sector) for now 
    mov al, 0x1 

    ; get the saved drive number back to DL 
    mov dl, [bootdrv] 

    mov dh, 0x0 ; head 0 
    mov cl, 0x2 ; start reading from 2nd sector 

    ; read 
    int 0x13 

    pop es ; restore ES 

    ret ; return and continue after call instruction 
+0

不錯,看起來很簡單。我可以一點一點地理解。重置已經實現並且堆棧設置良好。但是,它仍然不加載我的內核文件。什麼似乎是問題?你能教我更多嗎?如果您需要更清晰的信息,我可以將我的啓動扇區編輯爲整個nasm代碼。 – ThisGuy

+0

嘗試使用一些調試環境。 – user35443

相關問題