`
tianshi_kco
  • 浏览: 22482 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

为什么bios将mbr装载到0x7c00地址,0x7c00怎么来的?

 
阅读更多

Do you know "0x7C00", a magic number, in x86 assembler programming ?
"0x7C00" is the memory address which BIOS loads MBR(Master Boot Record, a first sector in hdd/fdd) into. OS or bootloader developer must assume that their assembler codes are loaded and start from 0x7C00.

But...1st, you may wonder.

"I read all of Intel x86(32bit) programmers manual, but did not found the magic number 0x7C00."

Yes.0x7C00 is NOT related to x86 CPU. It's natural that you couldn't find out it in cpu specifications from intel. Then, you wonder, "Who decided it ?"

2nd, you may wonder:

"0x7C00 is 32KiB - 1024B at decimal number. What's this number means ?"

Anyone decided it. But, why he/she decided such a halfway address?

Hum...There're TWO questions(mysteries) arround the magic number "0x7C00".

  1. Who decided "0x7C00" ?
  2. What "0x7C00 = 32KiB - 1024B" means ?

Okay, let's dive into the secret of BIOS for "IBM PC 5150", ancestor of modern x86(32bit) PCs, with me...!!

"0x7C00" First appeared in IBM PC 5150 ROM BIOS INT 19h handler.

Wandering arround the history of x86 IBM Compatible PC, you know IBM PC 5150 is the ancestor of modern x86(32bit) IBM PC/AT Compatible PCs.
This PC was released at 1981 August, with Intel 8088(16bit) and 16KiB RAM(for minimum memory model). BIOS and Microsoft BASIC was stored in ROM.

When power on, BIOS processes "POST"(Power On Self Test) procedure, and after, call INT 19h.
In INT 19h handler, BIOS checks that PC has any of floppy/hard/fixed diskette or not have.
If PC has any of available diskkete, BIOS loads a first sector(512B) of diskette into 0x7C00.

Now, you understand why you couldn't find out this magic number in x86 documents. This magic number belongs to BIOS specification.

The origin of 0x7C00

Stories surrounding IBM PC DOS, Microsoft, and SCP's 86-DOS are famous stories. See: "A Short History of MS-DOS".

SCP's "86-DOS"(at 1980) is the reference OS for IBM PC DOS 1.0.
86-DOS(early called "QDOS") is CP/M compatible OS for 8086/8088 cpu. At 1979, Digital Research Inc didn't have developed CP/M for 8086/8088 cpu yet.

SCP sold two S-100 bus board, one is 8086 CPU board, two is "CPU Monitor" rom board.
"CPU Monitor" program provided bootloader and debugger. This "CPU Monitor" bootloader loaded MBR into "0x200", NOT "0x7C00". In 1981, IBM PC DOS was the NEXT CP/M like OS for 8086/8088.

So, I told you that "0x7C00 FIRST appeared in IBM PC 5150 ROM BIOS".
Previous one, SCP's CPU Monitor bootloader loads into 0x200, not 0x7C00.

Why that CPU Monitor's bootloader loeded MBR into "0x200" ?

There're THREE reasons about "0x200".

  1. 8086 Interrupts Vector use 0x0 - 0x3FF.
  2. 86-DOS was loaded from 0x400.
  3. 86-DOS didn't use interrupts vectors between 0x200 - 0x3FF.

These reasons mean 0x200 - 0x3FF needed to be reserved and couldn't be in the way of an OS, no matter where 86-DOS or user application wanted to load.

So Tim Paterson (86-DOS developer) chose 0x200 for MBR load address.

Q:Who decided "0x7C00" ? - A: IBM PC 5150 BIOS Developer Team.

"0x7C00" was decided by IBM PC 5150 BIOS developer team (Dr. David Bradley).
As mentioned above, this magic number was born at 1981 and "IBM PC/AT Compat" PC/BIOS vendors did not change this value for BIOS and OS's backward compatibility.

Not Intel(8086/8088 vendor) nor Microsoft(OS vendor) decided it.

Q:What "0x7C00 = 32KiB - 1024B" means ? A: Affected by OS requirements and CPU memory layout.

IBM PC 5150 minimum memory model had only 16KiB RAM. So, you may have a question.

"Could minimum memory model (16KiB) load OS from diskette ? BIOS loads MBR into 32KiB - 1024B address, but physical RAM is not enough..."

No, that case was out of consideration. One of IBM PC 5150 ROM BIOS Developer Team Members, Dr. David Bradley says:

"DOS 1.0 required a minimum of 32KB, so we weren't concerned about attempting a boot in 16KB."

(Note: DOS 1.0 required 16KiB minimum ? or 32KiB ? I couldn't find out which correct. But, at least, in 1981's early BIOS development, they supposed that 32KiB is DOS minimum requirements.)

BIOS developer team decided 0x7C00 because:

  1. They wanted to leave as much room as possible for the OS to load itself within the 32KiB.
  2. 8086/8088 used 0x0 - 0x3FF for interrupts vector, and BIOS data area was after it.
  3. The boot sector was 512 bytes, and stack/data area for boot program needed more 512 bytes.
  4. So, 0x7C00, the last 1024B of 32KiB was chosen.

Once OS loaded and started, boot sector is never used until power reset. So, OS and application can use the last 1024B of 32KiB freely.

After OS loaded, memory layout will be:

+--------------------- 0x0| Interrupts vectors+--------------------- 0x400| BIOS data area+--------------------- 0x5??| OS load area+--------------------- 0x7C00| Boot sector+--------------------- 0x7E00| Boot data/stack+--------------------- 0x7FFF| (not used)+--------------------- (...)

That are the origin and reasons of "0x7C00", the magic number survived for about three decades in PC/AT Compat BIOS INT 19h handler.

References

86-DOS related:

  • "8086 Monitor Instruction Manual"(MON 86 - V1.4)
  • "86-DOS(TM) User's Manual Version 0.3"
  • "86-DOS(TM) Programmer's Manual Version 0.3"
  • "86-DOS(TM) Instruction Manual Version ??"

IBM PC 5150 related:

  • "IBM Personal Computer Hardware Reference Library", "Technical Reference" (IBM Personal Computer Technical Reference manual)
  • "IBM Personal Computer XT Hardware Reference Library", "Technical Reference" (IBM Personal Computer XT Technical Reference manual)

Intel 8086/8088 data sheets:

  • "8086 16-BIT HMOS MICROPROCESSOR"
  • "M80C86/M80C86-2 16-BIT CHMOS MICROPROCESSOR"
  • "8088 8-BIT HMOS MICROPROCESSOR"

CP/M related:

86-DOS related:

And all related Wikipedia pages.

Special Thanks To...

Special Thanks To:

  • Tim Peterson
  • David Bradley
for japanese article, see:
"Assembler/なぜx86ではMBRが"0x7C00"にロードされるのか?(完全版)"
http://www.glamenv-septzen.net/view/614
分享到:
评论

相关推荐

    刚Windows xp读出来的MBR代码详细分析

    - `mov sp, 0x7c00`:将SP(栈指针寄存器)设置为0x7c00,这表示栈的顶部将被初始化到MBR代码区域的末尾。 这些操作用于设置栈环境,以便后续可以正确地使用栈进行数据传递和存储。 #### 2. 设置中断和保护模式 `...

    MBR反编译[借鉴].pdf

    首先,反编译结果显示的汇编指令是从地址`0x7C00`开始的,这是BIOS加载MBR到内存的默认位置。以下是部分关键指令的解释: 1. `xor ax, ax`: 清零AX寄存器,通常用于初始化。 2. `mov ss, ax`: 将AX寄存器的值(0)...

    开发操作系统整理

    5. **为什么BIOS将MBR读入0x7C00地址处(x86平台下).doc**:主引导记录(MBR)包含启动加载器,用于启动操作系统。此文档可能解释BIOS选择0x7C00作为加载点的历史原因和技术考虑。 6. **VGA.doc**:VGA(Video ...

    主引导记录(MBR)的反汇编分析.doc

    在地址7C00处,我们发现了一个jmp 7c0c指令,这个指令将控制权转移到地址7C0C处。 2. 在地址7C0C处,我们发现了一个sti指令,这个指令将中断标志置位。然后,我们发现了一个REPZ MOVSB指令,这个指令将7C1B地址的...

    操作系统实验21

    引导扇区程序被加载到物理地址0x7c00开始执行,这是BIOS加载引导扇区的标准位置。在Bochs中,可以通过`sreg`命令查看CPU的段寄存器状态,`xp`命令用于打印内存区域的内容,而`vb`命令则用于设置断点。 实验步骤中,...

    读bootsct.S、setup.S、head.S心得

    1. bootsect.S将自己从ROM BIOS载入的绝对地址0x7C00处搬到0x9000处,然后利用一个jmpi的指令,跳到新位置的jmpi的下一行(go:)去执行。 2.接着,将其他segment registers包括DS、ES、SS都指向0x9000这个位置,与CS...

    BIOS、MBR、PBR、分区等基础知识.txt

    ### BIOS、MBR、PBR、分区等基础知识详解 #### 一、BIOS(基本输入输出系统) **定义与功能:** BIOS(Basic Input/Output System)是一种存储在计算机主板上的只读内存(ROM)中的程序。它为计算机硬件与操作系统...

    mbr.rar_mbr

    1. **BIOS中断调用**:MBR的执行始于BIOS,它会加载MBR到内存的0x7C00地址。源码中可能会包含诸如`int 13h`这样的中断调用来与BIOS交互,如读取硬盘数据。 2. **检测硬盘分区**:MBR中包含了检查硬盘分区表的代码,...

    grub源代码0.95

    (1) BIOS执行INT 0x19,加载MBR至0x7c00并跳转执行。如果你安装GRUB到MBR,GRUB的安装程序会把Stage1(512B)拷贝到MBR。视stage2的大小,安装程序会在Stage1中嵌入Stage1_5或者Stage2的磁盘位置信息。 (2) Stage1...

    BIOS中断大全(各种BIOS中断调用指令)

    使用功能02H可以将光标定位到指定的文本坐标。BH为显示页码,DH和DL则分别代表行和列的坐标。 4. **读取光标信息** (功能03H) 这个功能用于获取光标的位置和形状信息。CH和CL返回光标的起始和终止行,DH和DL返回...

    MBR引导代码分析

    下面这段代码实现把0000:7c1b处MBR代码复制485个字节到0000:061b处,为什么不从0000:7c00开始复制512个到0000:06cc处,因为前面1b 个字节为复制代码,所以忽略.空出的0000:7c00 开始的空间将读入活动分区的操作系统的...

    中科院操作系统高级教程_思考题_2021最新版参考.pdf

    BIOS将引导扇区加载到内存的0x7C00处,然后跳转执行,因为这是BIOS规定的位置。 2. BIOS仅加载一个扇区是因为它的职责是找到操作系统并将其初步加载到内存,后续的扇区加载由引导加载器(如bootsect)负责。这样的...

    国科大操作系统高级教程-思考题(更新之2023.10.24)

    而这个工作最开始的部分,BIOS需要完成一些检测工作,和设置实模式下的中断向量表和服务程序,并将操作系统的引导扇区加载至0x7C00处,然后将跳转至0x7C00。 思考题2:为什么BIOS只加载了一个扇区,后续扇区却是由...

    ntfs boot代码反汇编注释

    `BC007C mov sp,0x7c00`设定堆栈指针SP为0x7c00,初始化堆栈。`FB sti`开启中断,允许系统处理中断请求。 `B8C007 mov ax,0x7c00`将0x7c00赋值给AX,`8ED8 mov ds,ax`设置数据段DS。这一系列操作是用来设置系统的...

    计算机启动过程(1)-BIOS+MBR部分.pdf

    4. 系统 BIOS 将查找其它设备的 BIOS 程序,找到之后同样要调用这些 BIOS 内部的初始化代码来初始化相关的设备。 5. 查找完所有其它设备的 BIOS 之后,系统 BIOS 将显示出它自己的启动画面,其中包括有系统 BIOS 的...

    BIOS+MBR硬盘,一步一步教你怎么用clover装黑苹果.doc

    BIOS+MBR硬盘,一步一步教你怎么用clover装黑苹果,教程采用的格式是MBR硬盘格式安装的,采用的电脑是笔记本G510,关闭独显采用核显为HD4600,配置如下:

    Windows 7的MBR引导代码分析【汇编】

    引导过程始于BIOS读取MBR并将其加载到内存的0x7C00地址。MBR中的汇编代码首先执行一些基本的硬件初始化,如设置堆栈指针、检查引导扇区的签名以验证其有效性。接着,代码会查找活动分区,即分区表中标识为活动的分区...

    电脑蓝屏,0x电脑报错查询

    - **0x0009**: 文件缓冲区地址无效。 - **0x000A**: 未知错误。 - **0x000B**: 系统无法识别某种格式。 - **0x000C**: 系统无法读取数据。 - **0x000D**: 系统无法执行指定的操作。 - **0x000E**: 文件缓冲区太小,...

    BIOS、MBR、PBR等基础知识

    ### BIOS、MBR、PBR等基础知识 #### 1. BIOS概述 BIOS(Basic Input/Output System)即基本输入输出系统,是一组被固化在计算机主板上的ROM芯片中的程序,它保存着计算机最重要的基本输入输出的程序、系统设置信息...

Global site tag (gtag.js) - Google Analytics