How Computers Boot Up

本文详细介绍了计算机从按下电源按钮到操作系统加载完成的整个启动过程。包括主板初始化、BIOS自检、主引导记录读取、操作系统加载器工作原理及内核初始化等关键步骤。

http://duartes.org/gustavo/blog/post/how-computers-boot-up

The previous post described motherboards and the memory map in Intel computers to set the scene for the initial phases of boot. Booting is an involved, hacky, multi-stage affair – fun stuff. Here’s an outline of the process:

Boot Sequence Outline
An outline of the boot sequence

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. 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.

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. 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.

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.

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:

Memory Regions During Boot 
Important memory regions during boot

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.

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.

The BIOS now reads the first 512-byte sector (sector zero) of the hard disk. This is called the Master Boot Record and it normally contains two vital components: a tiny OS-specific bootstrapping program at the start of the MBR followed by a partition table for the disk. The BIOS however does not care about any of this: it simply loads the contents of the MBR into memory location 0x7c00 and jumps to that location to start executing whatever code is in the MBR.

Master Boot Record 
Master Boot Record

The specific code in the MBR could be a Windows MBR loader, code from Linux loaders such as LILO or GRUB, or even a virus. In contrast the partition table is standardized: it is a 64-byte area with four 16-byte entries describing how the disk has been divided up (so you can run multiple operating systems or have separate volumes in the same disk). Traditionally Microsoft MBR code takes a look at the partition table, finds the (only) partition marked as active, loads the boot sector for that partition, and runs that code. The boot sector is the first sector of a partition, as opposed to the first sector for the whole disk. If something is wrong with the partition table you would get messages like “Invalid Partition Table” or “Missing Operating System.” This message does not come from the BIOS but rather from the MBR code loaded from disk. Thus the specific message depends on the MBR flavor.

Boot loading has gotten more sophisticated and flexible over time. The Linux boot loaders Lilo and GRUB can handle a wide variety of operating systems, file systems, and boot configurations. Their MBR code does not necessarily follow the “boot the active partition” approach described above. But functionally the process goes like this:

  1. The MBR itself contains the first stage of the boot loader. GRUB calls this stage 1.
  2. Due to its tiny size, the code in the MBR does just enough to load another sector from disk that contains additional boostrap code. This sector might be the boot sector for a partition, but could also be a sector that was hard-coded into the MBR code when the MBR was installed.
  3. The MBR code plus code loaded in step 2 then read a file containing the second stage of the boot loader. In GRUB this is GRUB Stage 2, and in Windows Server this is c:\NTLDR. If step 2 fails in Windows you’d get a message like “NTLDR is missing”. The stage 2 code then reads a boot configuration file (e.g., grub.conf in GRUB, boot.ini in Windows). It then presents boot choices to the user or simply goes ahead in a single-boot system.
  4. At this point the boot loader code needs to fire up a kernel. It must know enough about file systems to read the kernel from the boot partition. In Linux this means reading a file like “vmlinuz-2.6.22-14-server” containing the kernel, loading the file into memory and jumping to the kernel bootstrap code. In Windows Server 2003 some of the kernel start-up code is separate from the kernel image itself and is actually embedded into NTLDR. After performing several initializations, NTDLR loads the kernel image from file c:\Windows\System32\ntoskrnl.exe and, just as GRUB does, jumps to the kernel entry point.

There’s a complication worth mentioning (aka, I told you this thing is hacky). The image for a current Linux kernel, even compressed, does not fit into the 640K of RAM available in real mode. My vanilla Ubuntu kernel is 1.7 MB compressed. Yet the boot loader must run in real mode in order to call the BIOS routines for reading from the disk, since the kernel is clearly not available at that point. The solution is the venerable unreal mode. This is not a true processor mode (I wish the engineers at Intel were allowed to have fun like that), but rather a technique where a program switches back and forth between real mode and protected mode in order to access memory above 1MB while still using the BIOS. If you read GRUB source code, you’ll see these transitions all over the place (look under stage2/ for calls to real_to_prot and prot_to_real). At the end of this sticky process the loader has stuffed the kernel in memory, by hook or by crook, but it leaves the processor in real mode when it’s done.

We’re now at the jump from “Boot Loader” to “Early Kernel Initialization” as shown in the first diagram. That’s when things heat up as the kernel starts to unfold and set things in motion. The next post will be a guided tour through the Linux Kernel initialization with links to sources at the Linux Cross Reference. I can’t do the same for Windows ;) but I’ll point out the highlights.

内容概要:本文主要介绍了一项基于Pytorch框架搭建神经网络的研究【DQN实现避障控制】使用Pytorch框架搭建神经网络,基于DQN算法、优先级采样的DQN算法、DQN + 人工势场实现避障控制研究(Matlab、Python实现)工作,重点实现了DQN算法、优先级采样的DQN算法以及结合人工势场法的DQN算法在避障控制中的应用。研究通过Matlab和Python平台进行仿真与实验,旨在提升智能体在复杂环境中的自主避障能力。文中详细阐述了三种算法的设计思路、网络结构搭建、训练流程及优化策略,并通过对比实验验证了各方法的有效性与性能差异,尤其突出了DQN结合人工势场法在引导智能体快速学习安全路径方面的优势。此外,文档还列举了大量相关的科研方向与技术应用案例,涵盖无人机控制、路径规划、强化学习、电力系统优化等多个领域,展示了广泛的科研服务能力和技术积累。; 适合人群:具备一定Python和深度学习基础,熟悉强化学习基本概念的研究生、科研人员及工程技术人员;对智能控制、机器人避障、无人机路径规划等领域感兴趣的开发者。; 使用场景及目标:① 学习DQN及其改进算法(如优先经验回放)在实际控制系统中的实现方式;② 掌握如何将传统人工势场法与深度强化学习相结合以提升避障性能;③ 借鉴Matlab与Python混合仿真方法,开展智能控制算法的实验验证与对比分析;④ 拓展至无人机、无人车等智能体的自主导航系统设计。; 阅读建议:建议读者结合提供的代码资源,逐步复现实验过程,重点关注神经网络结构设计、奖励函数设定及算法收敛性分析。同时可参考文中列出的其他研究方向,拓展应用场景,提升科研创新能力。
内容【2025最新高维多目标优化】无人机三维路径规划的导航变量的多目标粒子群优化算法NMOPSO研究(Matlab代码实现)概要:本文围绕“2025最新高维多目标优化”主题,重点研究基于城市场景下无人机三维路径规划的导航变量多目标粒子群优化算法NMOPSO,并提供了完整的Matlab代码实现。该研究旨在解决复杂威胁环境下无人机路径规划中的多目标优化问题,兼顾路径安全性、能耗、距离与时效等多个目标,通过改进的粒子群算法实现高效搜索与优化。文中详细阐述了算法设计思路、数学建模过程、适应度函数构建及约束处理机制,并结合三维城市环境进行仿真实验验证其有效性。此外,文档还列举了大量相关科研方向与技术资源,涵盖智能优化算法、路径规划、无人机控制、机器学习、电力系统等多个领域,展示了广泛的科研应用场景和技术支持体系。; 适合人群:具备一定Matlab编程基础,从事无人机路径规划、智能优化算法或自动化控制等领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①研究高维多目标优化算法在无人机三维路径规划中的应用;②掌握多目标粒子群优化算法(MOPSO/NMOPSO)的设计与实现方法;③复现并改进复杂环境下的无人机协同路径规划模型;④拓展至其他智能优化与控制问题的研究与仿真。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注算法核心模块的实现细节,如种群初始化、非支配排序、拥挤度计算与动态环境建模。同时可参考文中列出的其他研究案例,拓展技术视野,推动算法在实际科研项目中的迁移与应用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值