转载注明出处(cppgp: http://blog.csdn.net/cppgp ) diskboot.S位于grub-1.98/boot/i386/pc/目录,采用AT&T汇编语法编写。详细注释如下: /* * GRUB -- GRand Unified Bootloader * Copyright (C) 1999,2000,2001,2002,2006,2007,2009,2010 Free Software Foundation, Inc. * * GRUB is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * GRUB is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GRUB. If not, see <http://www.gnu.org/licenses/>. */ /* * cppgp 注释 * * 转载请注明原作者 * * 日期: 2011-04-22 * * Email * cppgp@qq.com, * yanyg02@163.com * * GRUB version: * gnu grub-1.98 */ /* * diskboot.S * * diskboot.S生成diskboot.img, 共512字节 * * 安装程序根据实际情况, 改写blocklist数据集. 最多支持 * 15个数据集, 每个数据集占用12字节, 0~7字节表示起始 * 扇区, 8~9字节表示该数据集扇区数, 10~11表示目的 * 缓冲区起始段地址. 必须有一个数据集的扇区数字段 * 为0, 程序根据此判断读取结束. * * * 安装在硬盘上时,DPT部分(0x1BE~0x1FD)保留不变, * * 安装在软盘上时, DPT部分(0x1BE~0x1FD)是软盘复位和 * 扇区探测代码. 扇区末尾两字节 * * 扇区最后两字节 写入0xAA55 (小端表示, 0x1FE位置为0x55, * 0x1FF位置为0xAA). * * diskboot.img开机时加载到0x8000~0x81FF, 并以CS:IP=0x0000:0x8000 * 跳转执行, 它将加载kernel.img到内存0x8200开始位置,并以 * CS:IP=0x0000:0x8200跳转执行. kernel.img扇区数可能有多个, * 在生成影像(grub-mkinage)时确定. * * diskboot.img可以使用boot.img设置的堆栈和寄存器值,但是在 * 跳转到0x8200之前,要确保没有更改这些设置, 因为kernel.img * 还会用到这些寄存器. * * diskboot.img当前只用到一个数据集. 在我的机器上, 反解 * 安装以后的diskboot.img, 得到的值如下: * * 起始扇区: 0x0000 0000 0000 0002 * 扇区数 : 0x002e * 段地址 : 0x0820 */ #include <grub/symbol.h> #include <grub/machine/boot.h> /* * defines for the code go here */ #define MSG(x) movw $x, %si; call LOCAL(message) .file "diskboot.S" .text /* Tell GAS to generate 16-bit instructions so that this code works in real mode. */ /* * 告诉汇编器产生16位代码 */ .code16 /* * 如同在boot.S所指明的, * 此处的代码被加载在内存0x8000处 * 并且以CS:IP=0x0000:0x8000跳转执行 */ .globl start, _start start: _start: /* * _start is loaded at 0x2000 and is jumped to with * CS:IP 0:0x2000 in kernel. */ /* * we continue to use the stack for boot.img and assume that * some registers are set to correct values. See boot.S * for more information. */ /* *