最近在读Linux的grub的stage1中看到“BIOS执行INT 0x19,加载MBR内容至0x7c00,然后跳转执行”,为什么一定是0x7c00这个地址。

作者刚好在下面推荐了这篇文件,刚好顺手记录一下。// 最下方有中文版,英语不好的同学可以跳到最下面

The mysteries arround "0x7C00" in x86 architecture bios bootloader

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"にロードされるのか?(完全版)" 
https://www.glamenv-septzen.net/view/614

中文版:

https://www.douban.com/note/249471773/

Referer:

https://www.glamenv-septzen.net/en/view/6

【转】Why BIOS loads MBR into 0x7C00 in x86 ?的更多相关文章

  1. 矩阵乘法 and BIOS loads MBR into 0x7C00?

    tianpeng <再谈矩阵与矩阵乘法> 讲的也好 矩阵乘矩阵 这个结果是怎么算出来的? 第一个矩阵第一行的每个数字(2和1),各自乘以第二个矩阵第一列对应位置的数字(1和1),然后将乘积 ...

  2. BIOS将MBR读入0x7C00地址处(x86平台下)

    BIOS将MBR读入0x7C00地址处(x86平台下) https://www.cnblogs.com/jikebiancheng/p/6193953.html http://www.ruanyife ...

  3. BIOS 搭配 MBR/GPT 的开机流程

    鸟哥私房菜书上内容: BIOS 搭配 MBR/GPT 的开机流程 在计算机概论里面我们有谈到那个可爱的BIOS与CMOS两个东西, CMOS是记录各项硬件参数且嵌入在主板上面的储存器,BIOS则是一个 ...

  4. BIOS、MBR、UEFI和GPT关系

    很多用户在新买电脑,或是给已有电脑重装系统时都出现过怎么都无法引导U盘安装的情况.究其原因,还是没能搞清楚BIOS.MBR.UEFI和GPT的复杂关系.所以,今天小编就和大家分享一下它们之间的爱恨情仇 ...

  5. EFI、GPT和BIOS、MBR

    用了数十年的PC机主板架构是BIOS模式.但在2004年,微软和英特尔共同推出一种名为可扩展固件接口(EFI)的主板升级换代方案.EFI,即可扩展固件接口(Extensible Firmware In ...

  6. UEFI +、GPT 、BIOS 、 MBR的关系

    1.传统的主板就是传统 BIOS,可在使用 MBR 分区表的硬盘(俗称 MBR磁盘,就是传统常用的模式)上安装32或64位操作系统.同时也支持使用 GUID 分区表的硬盘(俗称GPT磁盘),但该硬盘上 ...

  7. OpenBSD内核之引导PBR

    OpenBSD引导的第二部PBR,也是活动分区的一个扇区的代码,由第一步的MBR加载到0x7C00处,manpage里详细的讲解了过程和大致实现 biosboot(8) (http://man.ope ...

  8. 操作系统的启动与引导问题 BIOS、UEFI、MBR、GPT

    关于ISO.WIM.GHO三者的正确理解. ISO(Isolation)文件一般以ISO为扩展名,是复制光盘上全部信息而形成的镜像文件. WIM是英文Microsoft Windows Imaging ...

  9. 【干货】BIOS、UEFI、MBR、GPT、GRUB 到底是什么意思?

    公众号关注 「开源Linux」 回复「学习」,有我为您特别筛选的学习资料~ 01 前言 在学习 Linux 系统启动原理之前,我们先了解下与操作系统启动相关的几个概念. 02 与操作系统启动相关的几个 ...

随机推荐

  1. centos 下 gradle 编译打包 apk

    由于Jenkins 装在centos环境下,想实现Android程序的编译,只能通过gradle 命令去打包版本apk,以下记录了如何在centos下使用gradle 打包apk 一.安装 gradl ...

  2. Access-Control-Allow-Origin 响应一个携带身份信息(Credential)的HTTP请求时,必需指定具体的域,不能用通配符

    https://www.cnblogs.com/raind/p/10771778.html Access-Control-Allow-Origin.HTTP响应头,指定服务器端允许进行跨域资源访问的来 ...

  3. Python-numpy包中多维数组转置,transpose.swapaxes的轴编号(axis)的理解

    transpose()中三个轴编号的位置变化理解 transpose(a,b,c)其中a轴编号即为参考编号,垂直于a的平面即为所有平面,该平面上的数据再根据b,c相对于(0,1,2)的位置关系进行改变 ...

  4. 缓存原理,自己写一个缓存类(c#版)

    .net中的MemoryCache是通过内部封装一个静态Dictionary 自己写一个缓存,来看看内部怎么实现的 public class CustomerCache : ICache { priv ...

  5. JAVA基础概念(一)

    一.JAVA标识符 标识符就是用于给 Java 程序中变量.类.方法等命名的符号.如图标黄部分: 使用标识符时,需要遵守几条规则: 1.  标识符可以由字母.数字.下划线(_).美元符($)组成,但不 ...

  6. JS判断是否是ioS或者Android

    每个客户端都带有自身的UA标识,通过JavaScript,可以获取客户端标识,我们可以获取浏览器的userAgent,用正则来判断手机是ios(苹果)还是Android(安卓)客户端. 项目实例:ht ...

  7. 【07月15日】A股滚动市盈率PE最低排名

    ​仅根据最新的市盈率计算公式进行排名,无法对未来的业绩做出预测. 方大集团(SZ000055) - 滚动市盈率PE:2.53 - 滚动市净率PB:1.13 - 滚动年化股息收益率:4.01% - 建筑 ...

  8. mac解决安装提示“xxx软件已损坏,打不开,您应该将它移到废纸篓”的提示

    如果没有“任何来源”选项则运行: macOS Sierra设置说明 若已安装了最新系统 macOS Sierra 则有可能出现某些安装包已损坏.显示未激活.打开崩溃等的提示!!原因是因为新系统屏蔽了任 ...

  9. python接口自动化1-http协议简介

    前言 知道接口测试的小伙伴都应清楚http协议了,如果你还不清楚,那么接口测试做不好,自动化接口就更做不好了.那么做接口测试前先了解下http: HTTP协议(HyperText Transfer P ...

  10. Linux命令随手记

    随手记录常用的Linux命令. tar 解压.   tar   -xzvf tar 压缩:tar   -czvf   .tgz (z是压缩格式,x为解压,v为显示过程,f指定备份文件) tar -zc ...