打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
精读 | 计算机是如何启动的(上)


计算机通电后,会启动CPU,并加载BIOS。在CPU开始执行BIOS程序之前,它的第一条指令位于存储器的什么位置呢?在启动流程中会遇到哪些问题,启动具体的步骤又是什么呢?我们一起精读这篇译文吧。

01

我们都知道计算机启动是从加电的那一刻开始的,如果CPU不工作,那会发生什么情况呢?


Booting is an involved, hacky, multi-stage affair - fun stuff. Here's an outline of the process: Things start rolling when you press the power button on the computer (no! do tell!). Once the motherboard is powered up it initializes its own firmware - the chipset and other tidbits - and tries to get the CPU running. If things fail at this point (e.g., the CPU is busted or missing) then you will likely have a system that looks completely dead except for rotating fans.

boot 启动

involved 复杂的

hacky 由hack变化过来,可以引申理解为“极客的”。

affair 事情、事务

start rolling 开始滚动,就是开始的意思

power button 电源

power up 启动、通电

initialize 初始化

firmware 固件

chipset 芯片

tidbit 原意指佳肴、花絮;这里指小元件

at this point 在这个时候

bust 破裂

will likely 很可能会

rotate 旋转


计算机启动是一个复杂的、多阶段的事务——并且很有趣。下面是对启动的大致描述:启动始于你按下电源的那一刻。一旦主板被通电,它就会开始初始化自己的固件——芯片和其他元件——然后尝试让CPU运作起来。如果这个阶段失败了(比如CPU坏了或者不见了),除了机箱内还在旋转的风扇外,很可能只剩下看起来一片死寂的系统。


02

如果启动时听到了主板“哔哔”的报警声,应该怎么去排除错误呢?


A few motherboards manage to emit beeps for an absent or faulty CPU, but the zombie-with-fans state is the most common scenario based on my experience. Sometimes USB or other devices can cause this to happen: unplugging all non-essential devices is a possible cure for a system that was working and suddenly appears dead like this. You can then single out the culprit device by elimination.

manage to 设法、勉强做某事

emit 发出

beep 哔哔声

scenario 情节,情况

cause sth to sth 导致

unplug 拔去插头

non-essential 不重要的

cure 疗法、解决方法

appear 看起来

single out 挑出

culprit 犯人、罪犯

elimination 消除


当CPU坏了或者不见了时,有一些主板勉强会发出“哔哔”的警报声,但是根据我的经验,大多数情况下就是这种“僵尸和风扇”的状态。有时候USB和其他设备也能造成这种情况:如果你遇到一个一直在好好工作,然后突然就出现这种情况的系统,拔掉所有非必须的设备可能是一个解决方案,然后你就可以挨个找出有问题的设备了。

03

一个CPU通常指一个处理器。同一台计算机中,可能有多个单核处理器,也可能有单个多核处理器,甚至多个多核处理器。有多个处理器称为multi-processor,有多个核心则称为multi-core。


If all is well the CPU starts running. In a multi-processor or multi-core system one CPU is dynamically chosen to be the bootstrap processor (BSP) that runs all of the BIOS and kernel initialization code. The remaining processors, called application processors (AP) at this point, remain halted until later on when they are explicitly activated by the kernel.

dynamically 动态地

bootstrap processor 启动处理器(BSP)

remaining 余下的,剩余的

application processor 应用处理器(AP)

halted 停止

later on 后来,以后

explicitly 明确地

activated 激活

kernel 内核


如果一切顺利的话,CPU就开始工作了。在一个多处理器或者多核的系统中,只有一个处理器会被动态地选择为启动处理器。启动处理器会负责执行BIOS和内核初始化的代码。余下的处理器和核心,这时候称为应用处理器,会保持停止状态直到后来它们明确地被内核激活时。

04

处理器的工作模式大致可以分为实模式(real mode)和保护模式(protected mode)。在实模式中,程序可以对内存的任意区域进行读写;而且在保护模式下,内存地址被虚拟化了,某些真实的物理地址无法被访问到,因此起到了保护相关程序和数据的作用。


Intel CPUs have been evolving over the years but they're fully backwards compatible, so modern CPUs can behave like the original 1978 Intel 8086, which is exactly what they do after power up. In this primitive power up state the processor is in real mode with memory paging disabled. This is like ancient MS-DOS where only 1 MB of memory can be addressed and any code can write to any place in memory - there's no notion of protection or privilege.

evolve 演变; 进化

backwards 向后

compatible 兼容的

primitive 早期的

memory paging 内存分页

disabled 不可用的,禁用的

address 寻址

notion 概念


Intel的处理器这些年来一直在演变和进步,但它们是完全向后兼容的,所以今天的CPU可以像1978年原始的Intel 8086那样去工作,特别是通电启动的过程。在这个计算机启动的早期阶段中,处理器处于“实模式”,内存的分页机制也被禁用了。这就像早期的MS-DOS系统一样,只有1MB的内存能够被寻址,而且任何代码都可以往内存的任何位置去写入数据——根本就没有保护和权限的概念。

05

在冯诺依曼的计算机体系中,CPU负责执行指令,EIP负责告诉CPU当前应该执行哪条指令,而指令和数据被存放在存储器。但第一条指令在哪里呢?Intel有自己的规定。计算机刚启动时,它会给EIP一个偏移量,实际被执行的第一条指令位于0xFFFFFFF0,也就是存储地址中接近4G的位置上。这里的4G是怎么来的呢?我们知道0x开始的数字是16进制,F就是16,16的8次方就是4294967296 byte,换算一下,就是4294967296 / 1024 / 1024 / 1024 = 4G。由于末位不是F而是0,因此这里是距离4G的最高位16个字节的位置。


Most registers in the CPU have well-defined values after power up, including the instruction pointer (EIP) which holds the memory address for the instruction being executed by the CPU. Intel CPUs use a hack whereby even though only 1MB of memory can be addressed at power up, a hidden base address (an offset, essentially) is applied to EIP so that the first instruction executed is at address 0xFFFFFFF0 (16 bytes short of the end of 4 gigs of memory and well above one megabyte). This magical address is called the reset vector and is standard for modern Intel CPUs.

register 寄存器

well-defined 预定好的

instruction pointer 指令指针(EIP)

whereby 借此,靠这个

offset 偏移量

essentially 本质上

is applied to 应用于

reset vector 复位向量


大多数CPU中的寄存器在通电后都被写入了预定好的数值,包括指令指针。指令指针保存了正在被CPU执行的指令的内存地址。Intel的CPU使用了一个小技巧,即使在通电后只有1MB的内存可以被寻址,一个隐藏的基地址(其实是一个偏移量)被加到了指令指针上,因此第一个被执行的指令的内存地址其实是0xFFFFFFF0(这是4G内存的最高位减去16个字节后的地址,比1M要大得多)。这个魔法般的地址被称为“复位向量”,它已经成为了今天Intel CPU的标准。

06

启动到当前步骤时,CPU向主板请求位于“复位向量”上的指令。主板为了确保BIOS程序能够被执行,“复位向量”上的指令其实是一个“跳转”到BIOS程序的指令。由于此时RAM模块中是一些随机数据,CPU加载的程序和数据,是放在主板闪存上的。


The motherboard ensures that the instruction at the reset vector is a jump to the memory location mapped to the BIOS entry point. This jump implicitly clears the hidden base address present at power up. All of these memory locations have the right contents needed by the CPU thanks to the memory map kept by the chipset. They are all mapped to flash memory containing the BIOS since at this point the RAM modules have random crap in them. An example of the relevant memory regions is shown below:

mapped to 映射到

implicitly 无保留地

thanks to 由于

flash memory 闪存

contain 包含

module 模块

random crap 随机数据,没有意义的数据


主板会保证,位于“复位向量”位置上的指令,其实是一个指向BIOS入口程序的“跳转”指令。这次跳转消除了CPU早先加上的隐藏基地址。跳转后的存储地址上有CPU需要执行的内容——这是由于主板上的芯片已经维护好了存储映射关系。这些地址会被映射到存放BIOS程序的主板闪存上,因为这个时候RAM模块还无法正常工作。请看下面相关内存区域的示意图:


07

随后BIOS程序就开始被执行了。在这个阶段,计算机会对硬件进行一系列的检查和初始化。这些检查可能成功,也可能会失败。


The CPU then starts executing BIOS code, which initializes some of the hardware in the machine. Afterwards the BIOS kicks off the Power-on Self Test (POST) which tests various components in the computer. Lack of a working video card fails the POST and causes the BIOS to halt and emit beeps to let you know what's wrong, since messages on the screen aren't an option. A working video card takes us to a stage where the computer looks alive: manufacturer logos are printed, memory starts to be tested, angels blare their horns. Other POST failures, like a missing keyboard, lead to halts with an error message on the screen. The POST involves a mixture of testing and initialization, including sorting out all the resources - interrupts, memory ranges, I/O ports - for PCI devices. Modern BIOSes that follow the Advanced Configuration and Power Interface build a number of data tables that describe the devices in the computer; these tables are later used by the kernel.

kick off 开始

power-on Self Test 加电自检(POST)

component 部件

lack of 缺乏

option 选择

stage 阶段

manufacturer 制造商,生产商

blare 使发出刺耳的响声

sort out 整理

interrupt 中断

Advanced Configuration and Power Interface 高级配置和电源接口


然后CPU就开始执行BIOS的代码了,这个阶段会初始化计算机中的部分硬件。随后,BIOS会启动“加电自检”程序,这个程序会测试计算机中的多个部件。如果显卡不工作,POST检查会报错,BIOS也会终止,同时会发出“哔哔”的声音让我们知道什么出错了,因为这个时候还没法在显示器上打印错误消息。如果显卡工作的话,我们就进入到“计算机看上去活起来了”的新阶段了:生产商的Logo会被显示出来,存储设备开始被测试,天使吹响了他们的号角。其他的POST检查错误,比如找不到键盘,会导致程序终止,相应的错误信息也会被显示在屏幕上。POST检查涉及到了测试和初始化,包括为随后的阶段整理好各类资源:中断、内存区域、为PCI预留的I/O端口。遵循“高级配置和电源接口”协议的现代BIOS会创建一系列的数据表来描述计算机中的硬件,这些数据表随后会被内核使用。

08

POST自检完成后,BIOS就准备启动操作系统了。BIOS首先需要找到操作系统存放的位置,这个位置可能在硬盘上,也可能在其他存储设备上。


After the POST the BIOS wants to boot up an operating system, which must be found somewhere: hard drives, CD-ROM drives, floppy disks, etc. The actual order in which the BIOS seeks a boot device is user configurable. If there is no suitable boot device the BIOS halts with a complaint like 'Non-System Disk or Disk Error.' A dead hard drive might present with this symptom. Hopefully this doesn't happen and the BIOS finds a working disk allowing the boot to proceed.

boot up 启动

floppy disks 软驱

configurable 可配置的

suitable 合适的

complaint 错误信息

present 呈现,显示

symptom 症状

proceed 进行


POST检查后,BIOS就准备启动操作系统了。操作系统一定会被存放在某个位置:硬盘、光驱或者软驱等等。BIOS查找启动设备的顺序是可以被用户配置的。如果BIOS没有找到合适的启动设备,那么BIOS就会停止工作,并且显示出“没有系统盘,或者硬盘错误”这类的错误信息。故障硬盘可能也会导致相同的症状。这样的事情还是不要发生为好,希望BIOS可以找到一个工作的硬盘以使得启动流程能够继续下去。


原文地址:

https://manybutfinite.com/post/how-computers-boot-up/



读完这篇文章后感觉有些意犹未尽?

那就来挑战【吐司逐句精读】环节吧!


吐司逐句精读

逐句拆解文档

重点单词标记

附带精品译文

帮助你加深对文章的记忆和理解!

扫描下方二维码

立即免费学习

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
CPU加电后第一条指令
计算机启动后,8086处理器执行的第一条指令是什么?| BIOS简介
一个程序在计算机中到底是如何运行的?
intel IA-32架构简介
IA
换种方法学操作系统轻松入门Linux内核(与图灵机不同冯诺依曼机是一个实际的体系结构)CPU就是从EIP指向的那个地址取过来一条指令执行
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服