Yanyg - SAN Software Engineer

深入理解 GNU GRUB - 02 boot.S 2.4 boot.S详细注释

本文最初发布于CSDN:https://blog.csdn.net/cppgp/article/details/6361020

boot.S位于grub-1.98/boot/i386/pc/目录,采用AT&T汇编语法编写。

/* -*-Asm-*- */
/*
 *  GRUB  --  GRand Unified Bootloader
 *  Copyright (C) 1999,2000,2001,2002,2005,2006,2007,2008,2009  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
 *    [email protected],
 *    [email protected]
 *
 * GRUB version:
 *    gnu grub-1.98
 */
/*
 * boot.S
 *
 * boot.S生成boot.img, 共512字节
 *
 * 安装程序根据实际情况, 改写kernel_sector所在LBA地址,
 * kernel_sector占用8字节, 首先是低4字节,然后是高4字节,
 * 它指明diskboot.img所在绝对扇区位置.
 *
 * 安装在硬盘上时,DPT部分(0x1BE~0x1FD)保留不变,
 *
 * 安装在软盘上时, DPT部分(0x1BE~0x1FD)是软盘复位和
 * 扇区探测代码. 扇区末尾两字节
 *
 * 扇区最后两字节 写入0xAA55 (小端表示, 0x1FE位置为0x55,
 * 0x1FF位置为0xAA).
 *
 * boot.img开机时加载到0x7C00~0x7DFF, 并以CS:IP=0x0000:0x7C00
 * 跳转执行, 它将加载diskboot.img到内存0x8000位置,并以
 * CS:IP=0x0000:0x8000跳转执行.
 *
 * boot.img保存磁盘参数和模式到BPB(BIOS parameter block)块.
 * diskboot.img和kernel.img都用到这些参数.
 *
 * boot.img设置堆栈和一些寄存器, diskboot.img和kernel.img都
 * 使用到这些设置. 包括:
 *  SP=0x2000 --> stack
 *  DL=boot-disk-driver
 *  SI=DAP --> disk address packet, -1(%si) is mode of disk read
 *  DS=SS=0 --> data segment and stack segment
 */
/*
  *
  * 关于宏LOCAL
  *
  * 所在文件:   grub-1.98/include/grub/symbol.h
  *
  * 描述
  *  #define LOCAL(sym) L_ ## sym
  *      ##在C语言中其粘贴作用
  *      LOCAL(sym)在sym符号前附加L_
  *      它以一种更易读的方式暗示这是一个局部(本地)符号
  *      例如, LOCAL(after_BPB)等价于L_after_BPB
  *
  */

#include <grub/symbol.h>
#include <grub/boot.h>