在引导程序中加载内核 [英] Loading kernel in a bootsector

查看:65
本文介绍了在引导程序中加载内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新,并且对此引导程序感到困惑.我使用QEMU引导程序.我真的在实现如何在NASM中加载内核或某些.asm文件时遇到问题.我已经实现了我的内核文件,并且想要将其加载到我的bootsector文件中.

I'm very new and confused with this bootloader. I use QEMU bootloader. I'm really having problems with implementing how to load kernel or some .asm file in NASM. I already implemented my kernel file and I want to load it to my bootsector file.

我只是遵循互联网在建立引导区时所说的话,所以我想到了这一点:

I just follow what the internet has to say with building a bootsector and I came up with this:

[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.

任何答案都将非常有用,因为我真的迷路了.

Any answer would be very helpful cuz I'm really lost.

推荐答案

您可以将内核放置在所需的任何位置. 对您来说,最简单的解决方案是用零填充引导加载程序的其余扇区,然后继续在同一文件中编写代码.

You can place your kernel anywhere you want. The easiest solution for you is to fill the rest of bootloader´s sector by zeroes and continue writing your code in the same file.

; 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.

For loading, you can use function 2 of interrupt 0x13.

.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 

这篇关于在引导程序中加载内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆