如何从第二阶段引导加载程序将更多代码加载到内存中? [英] How i can load more code to memory from a second-stage bootloader?

查看:56
本文介绍了如何从第二阶段引导加载程序将更多代码加载到内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用该代码加载我的第二个扇区(引导加载程序扩展):

i load my second sector( a bootloader expansion ), with that code:

mov ah, 00;                     // reset disk
int 13h;                        // disk interrupt

mov ax, 0x0000;                 // register ax [0000]:1000
mov bx, 0x1000;                 // register bx  0000:[1000]

mov ah, 0x2;                    // read sector instruction
mov al, 0x2;                    // sectors to read
mov ch, 0x0;                    // cylinder
mov cl, 0x6;                    // local to write
mov dh, 0x0;                    // head

int 0x13;                       // call the disk interupter

jmp 0x0000:0x1000;              // Jump to kernel

但是我想在内存中加载另一个内核(保护模式内核),我该如何使用此代码加载它或者我必须使用其他方式?

but i want to load another kernel at memory( the protected mode kernel ), how i can use this code to load it or i got to use other way?

bootloader = 1 个扇区 512 字节

bootloader = 1 sector 512 bytes

内核 x16 = 2 个扇区 1024 字节

kernel x16 = 2 sector 1024 bytes

内核 x32 = 2 个扇区 1024 字节(我知道我可以加载更多,更改 AL)

kernel x32 = 2 sector 1024 bytes ( i know that i can load more, changing AL )

推荐答案

您不想在 16 位内核运行时在 16 位内核上加载 32 位内核,因此您需要为数据使用不同的内存地址要加载.(在磁盘读取调用和远 jmp 中).

You don't want to load the 32-bit kernel over your 16-bit kernel while it's running so you need to use a different memory address for the data to be loaded. (In the disk-read call and the far jmp).

但是,很明显,当您仍处于 16 位实模式时,相同的 BIOS 调用以相同的方式工作.@MichaelPetch 评论了 我必须不断改变扇区,或者我可以加载多个,您可以安全地加载多个扇区,但为了便于携带有问题的 BIOS,您应该避免加载太多以至于跨越柱面边界.如果是这种情况,请使用多个调用.

But yes, obviously the same BIOS call works the same way while you're still in 16-bit real mode. @MichaelPetch commented on Do I have to keep changing sectors or can I load multiple that you can safely load multiple sectors but for portability to buggy BIOSes you should avoid loading so many that you cross a cylinder boundary. If that's the case use multiple calls.

制作一个带有 16 位入口点的组合内核并使用一个 4 扇区加载从引导加载程序加载整个内容会更简单.

It would be simpler to just make a combined kernel with a 16-bit entry point and load the whole thing from your bootloader with one 4-sector load.

您可以在一个 NASM 源文件中使用 BITS 16BITS 32 来组装 16 位与 32 位模式.您甚至可以将 far-jmp 标签用于 32 位代码,而不是用于加载代码的硬编码地址.

You can use BITS 16 and BITS 32 within one NASM source file to assemble for 16-bit vs. 32-bit mode. You can even use a label for the far-jmp to 32-bit code instead of to a hard-coded address where you load the code.

另见:

  • Boot loader doesn't jump to kernel code
  • How to make the kernel for my bootloader?
  • How to load second stage boot loader from first stage? (a two-stage bootloader setup is something like what you're asking about.)

这篇关于如何从第二阶段引导加载程序将更多代码加载到内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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