计划读一读FreeBSD的源代码

/*
 * Copyright (c) 2008 Luigi Rizzo (mostly documentation)
 * Copyright (c) 2002 Bruce M. Simpson
 * Copyright (c) 1998 Robert Nordier
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are freely
 * permitted provided that the above copyright notice and this
 * paragraph and the following disclaimer are duplicated in all
 * such forms.
 *
 * This software is provided "AS IS" and without any express or
 * implied warranties, including, without limitation, the implied
 * warranties of merchantability and fitness for a particular
 * purpose.
 *
 * $FreeBSD: release/10.0.0/sys/boot/i386/boot0/boot0.S 228738 2011-12-20 15:19:29Z jhb $
 */

/* build options: */
#ifdef SIO		/* use serial console on COM1.	*/
#endif

#ifdef PXE		/* enable PXE/INT18 booting with F6 */
#define SAVE_MORE_MEMORY
#endif

#ifdef CHECK_DRIVE	/* make sure we boot from a HD. */
#endif

#ifdef ONLY_F_KEYS	/* Only F1..F6, no digits on console */
#endif

#ifdef VOLUME_SERIAL	/* support Volume serial number */
#define B0_BASE	0x1ae	/* move the internal data area */
#define SAVE_MEMORY
#else
#define B0_BASE	0x1b2
#endif

#ifdef TEST		/* enable some test code */
#define SAVE_MEMORY
#define SAVE_MORE_MEMORY
#endif

/*
 * Note - this code uses many tricks to save space and fit in one sector.
 * This includes using side effects of certain instructions, reusing
 * register values from previous operations, etc.
 * Be extremely careful when changing the code, even for simple things.
 */

/*
 *		BOOT BLOCK STRUCTURE
 *
 * This code implements a Master Boot Record (MBR) for an Intel/PC disk.
 * It is 512 bytes long and it is normally loaded by the BIOS (or another
 * bootloader) at 0:0x7c00. This code depends on %cs:%ip being 0:0x7c00
 *
 * The initial chunk of instructions is used as a signature by external
 * tools (e.g. boot0cfg) which can manipulate the block itself.
 *
 * The area at offset 0x1b2 contains a magic string ('Drive '), also
 * used as a signature to detect the block, and some variables that can
 * be updated by boot0cfg (and optionally written back to the disk).
 * These variables control the operation of the bootloader itself,
 * e.g. which partitions to enable, the timeout, the use of LBA
 * (called 'packet') or CHS mode, whether to force a drive number,
 * and whether to write back the user's selection back to disk.
 *
 * As in every Master Boot Record, the partition table is at 0x1be,
 * made of four 16-byte entries each containing:
 *
 *   OFF SIZE	DESCRIPTION
 *    0	  1	status (0x80: bootable, 0: non bootable)
 *    1	  3	start sector CHS
 *		   8:head, 6:sector, 2:cyl bit 9..8, 8:cyl bit 7..0
 *    4   1	partition type
 *    5   3	end sector CHS
 *    8   4	LBA of first sector
 *   12   4	partition size in sectors
 *
 * and followed by the two bytes 0x55, 0xAA (MBR signature).
 */


/*
 *		BOOT BLOCK OPERATION
 *
 * On entry, the registers contain the following values:
 *
 *	%cs:%ip	0:0x7c00
 *	%dl	drive number (0x80, 0x81, ... )
 *	%si	pointer to the partition table from which we were loaded.
 *		Some boot code (e.g. syslinux) use this info to relocate
 *		themselves, so we want to pass a valid one to the next stage.
 *		NOTE: the use of %si is not a standard.
 *
 * This boot block first relocates itself at a different address (0:0x600),
 * to free the space at 0:0x7c00 for the next stage boot block.
 *
 * It then initializes some memory at 0:0x800 and above (pointed by %bp)
 * to store the original drive number (%dl) passed to us, and to construct a
 * fake partition entry. The latter is used by the disk I/O routine and,
 * in some cases, passed in %si to the next stage boot code.
 *
 * The variables at 0x1b2 are accessed as negative offsets from %bp.
 *
 * After the relocation, the code scans the partition table printing
 * out enabled partition or disks, and waits for user input.
 *
 * When a partition is selected, or a timeout expires, the currently
 * selected partition is used to load the next stage boot code,
 * %dl and %si are set appropriately as when we were called, and
 * control is transferred to the newly loaded code at 0:0x7c00.
 */

/*
 *	CONSTANTS
 *
 * NHRDRV is the address in segment 0 where the BIOS writes the
 *	total number of hard disks in the system.
 * LOAD is the original load address and cannot be changed.
 * ORIGIN is the relocation addr
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值