如何使用Assembly(NASM)从CD-ROM加载内核到内存

时间:2009-05-13 04:22:48

标签: assembly operating-system kernel nasm bootstrapping

我正在为自己编写一个引导程序和内核,引导程序和内核都将在CD-R上刻录,并将作为CD-live运行。它不是Linux CD-Live或其他东西,完全是我自己的bootloader和内核。我不想使用其他booloader(即GRUB)所以请不要建议我使用它们。

这是我的问题: 在我的引导加载程序ASM代码中,我想将内核和内核条目加载到RAM 从CD-ROM (而不是从硬盘或软盘),并假设我们知道内核到底在哪里在CD-ROM(扇区号)上。 据我所知,我必须使用int 0x13,AH = 02h,它将从Drive读取扇区到RAM。 为了使用这个中断服务,我必须设置几个寄存器,我将在下面列出: 参数: AH 02h AL部门读取计数 CX Track + Sector /见评论 DH主管 DL驱动器 ES:BX缓冲区地址指针

我的问题是关于DL和DH。为了指向要读取的第一个硬盘,我们可以将其设置为80h,或者对于软盘我们可以将其设置为00h。但我想从CD-ROM中读取,我不知道我必须使用什么值来用于DH和DL。

为了从CD-ROM读取扇区连接到RAM ,它是一个正确的中断(int 0x13)?如果是的话,我应该为DH和DL提供什么价值。

此致 Pooria。

1 个答案:

答案 0 :(得分:9)

要让BIOS从CD加载引导扇区,您需要使用"El Torito"标准使CD可引导。

使用后,您有两种选择 一个。仿真 - BIOS模拟软盘驱动器或硬盘驱动器,您可以通过设备00或设备80的INT13调用来读取内核。
湾设备不会模拟,您可以使用INT13 ExtendedRead功能直接从CD读取。

要了解如何完成此操作,请查看Linux“ISOLINUX”加载程序 - ISOLINUX.ASM

为您的问题提供更具体的起点,El Torito规范,第5.3节:

Once the system jumps to segment:0, the program can retrieve its boot
information by issuing INT 13, Function 4B, AL=01.  After the boot process
has been initiated the INT 13 Extensions (functions 41-48) will access the
CD using 800 byte sectors and the LBA address provided to INT 13 is an
absolute sector number. This gives any program running in no emulation mode
the ability to locate the boot catalog, and any other information on the
CD, without providing a device driver.