Hacker News new | ask | show | jobs
by justin_ 267 days ago
The program in the boot sector is run similar to other software: the code is loaded into memory, and then the processor is jumped to the first instruction. This loading and jumping is done by the firmware, which is included in your hardware, separate from your disks.

Let's back up to the start. When you switch on a computer, the power rails on a bunch of the chips come up. As this happens, the chips enter a "reset" state with initial data that is baked into the circuitry. This is the power-on reset (PoR) circuitry. When the power is up and stable, the "reset" is over and the processor starts executing. The initial value of program counter / instruction pointer is called the reset vector, and this is where software execution begins. On an x86 PC, this is something like 0xFFFFFFF0. The memory controller on the system is configured for reads from this address to go NOT to the main RAM, but to a flash memory chip on the board that holds the firmware software. From there the firmware will find your bootable disks, load the bootloader, and pass control to it.

In practice, systems vary wildly.

1 comments

Honestly, I loved the simple way you explained the general idea, for what I assume is a process full of details and gotchas.

Is there any resource you could point me to where I can learn?

I’m mostly used to working at a higher abstraction level and taking as “magic” everything below that.

I’d like to bridge the gap with lower level stuff now, it’s about time.

https://openlibrary.org/books/OL28332948M/Hands-on_Booting may not be the very best resource, but it covers the process for multiple operating systems.

For individual hardware stacks, there are processor and system documentation that explain exactly the memory addresses, the state of registers, the location on a drive where the firmware tries to find your bootloader, and all that.

Ben Eater's "computer from scratch" series is phenomenal for going from that "building on black box APIs" level to "this is what's physically happening in the real world inside that black box"

https://eater.net/