GRUB(二) 扇区1的引导代码注释(start.S)

本文深入解析GRUB引导加载器的start.S文件,详细注释了扇区1中的关键代码,帮助读者理解GRUB如何启动操作系统。
摘要由CSDN通过智能技术生成
/*
 *  GRUB  --  GRand Unified Bootloader
 *  Copyright (C) 1999,2000,2001   Free Software Foundation, Inc.
 *
 *  This program 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 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#define ASM_FILE
#include <shared.h>

#ifndef STAGE1_5
#include <stage2_size.h>
#endif
	
/*
 *  defines for the code go here
 */

	/* 获取绝对地址,如果采用1.5阶段的方案,则开始地址(物理地址)从0x2000开始,
    否则从0x8000开始。*/
#ifdef STAGE1_5
# define ABS(x) (x-_start+0x2000)
#else
# define ABS(x) (x-_start+0x8000)
#endif /* STAGE1_5 */
	
	/* 打印消息 */
#define MSG(x)	movw $ABS(x), %si; call message

	.file	"start.S"

	.text

	/* 让GAS生成16位的指令以便在实模式下工作 */
	.code16

	.globl	start, _start
start:
_start:	
	/*
	 * 在上一个阶段中,这里的代码已经被加载到0x8000并且也跳转到了CS:IP 0:0x8000这个
	 * 地址,见stage1.S中copybuffer部分。
	 */

	/* 
	 * 这里继续使用stage1的栈,并假设一些寄存器已经设置好了正确的值。
	 * 详见 stage1.S的说明。
	 */
	
	/* 首先保存驱动器引用,在硬盘启动时dl值通常是0x80/0x81等,
	 * 分别表示第一硬盘第二硬盘等等*/
	pushw	%dx

	/* 打印信息:"Loading stage2"/"Loading stage1.5" */
	pushw	%si
	MSG(notification_string)
	popw	%si
	
    /* 读取后续引导扇区的参数,放在这个扇区的最后8个字节,
    这里让di指向这个结构的起始位置 。结构及默认值如下,
    注意括号内是stage2的默认值,grub的install命令会设置合适的值。
    blocklist{
        long
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值