10

When the computer starts up, the code in BIOS is executed first. However, how is the code in BIOS loaded into the RAM for execution ?

I have referred to this question - Is BIOS read from the BIOS chip or copied into RAM on startup?. However, it has confused me more. If the BIOS is loaded from ROM and the ROM is a separate chip, what is the point of talking about segment addresses in RAM ? Also, where is the BIOS code loaded - is it in the last 1 MiB of real mode address space, or some other location ?

If someone could list the steps from computer start-up upto the execution of first BIOS instruction including the memory addresses used, it would be very helpful

2 Answers 2

7

As I wrote in my answer to that question the received folk wisdom on the subject — as unfortunately exemplified by other answers there (and elsehere in SuperUser) — is stuck in the world as it was around 1991, despite the wealth of technical references available explaining how it is now otherwise.

You wouldn't have been this confused if you had read my answer, because you wouldn't be asking about "BIOS loaded from ROM" in the first place.

Your "BIOS chip" is not ROM; there is no machine code between processor startup and the first instruction in firmware; and the "M" in both "RAM" and "ROM" means "memory".

As I wrote before, in modern PCs, the machine firmware is held in non-volatile RAM. It's not ROM as it used to be. See the previous answer for details of the NVRAM chip connected to the LPC bus. (For example: On a machine sitting disassembled beside me as I type this, the NVRAM holding the firmware is a Pm49FL004T, an LPC Flash RAM chip.)

32-bit CPUs don't start up in real mode, and don't start with an address that is below the 1MiB line. That's decades out of date rubbish from the times of 16-bit x86 processors. They start in what is colloquially known as unreal mode, and again in my prior answer I gave the details of what has actually been the case since the advent of the 80386. They load their first instruction from an address that is in fact right at the top of the 32-bit address space, FFFFFFF0.

In my prior answer I told you in detail where the machine firmware is principally mapped into physical address space on 32-bit and 64-bit x86 machines. Remember: Both RAM and ROM are memory. Physical addresses are memory addresses, on the system bus. They can address either RAM or ROM. (They can even address other things as well, but that's just complicating this discussion.) The physical address FFFFFFF0 is 16 bytes below the top of the 512KiB range where the top 512KiB of the firmware, in non-volatile RAM, is always mapped on the system bus by the "chipset".

There's no "loading" from some mythical ROM chip that goes on at processor initialization or reset. The chip holding the firmware is non-volatile RAM. It retains its contents, written when it is "flashed", across power cycles. And the CPU just reads the firmware instructions and data from it, over the system bus and over an LPC bus (and possibly an LPC/FWH bridge) connected to the system bus via the chipset, using a physical memory address.

Further reading

10
  • Thank you, this seems much more clear to me. However, when you say non-volatile RAM and data being read from it, does it mean that the BIOS is coupled with the RAM in some way ? Does each RAM chip come with a BIOS ? I know this may seem stupid, but I'm a beginner in this topic.
    – Cygnus
    Commented Jan 1, 2014 at 16:41
  • When he says non-volatile random access memory (NVRAM) he is referring to a different technology than the RAM used as main system memory (Typically Dynamic Random Access Memory, DRAM). It's a separate chip from main RAM that contains the firmware even when powered off, thus the "non-volatile" part.
    – Dougvj
    Commented Jan 1, 2014 at 16:46
  • @Dougvj : In that case, why do we have a separate address of FFFFFFF0 for it ? Wouldn't the NVRAM size be just the size of the firmware ?
    – Cygnus
    Commented Jan 1, 2014 at 16:54
  • I think that your questions are better handled as actual questions, not comments on this answer. Look at some of the "Related" questions on the right, then figure out a question to ask that will further your understanding. (There's certainly room on SuperUser for some questions+answers on the very basics, it seems from a brief shufti.)
    – JdeBP
    Commented Jan 1, 2014 at 16:59
  • @JdeBP : I have added a new question- superuser.com/questions/695769/…
    – Cygnus
    Commented Jan 1, 2014 at 18:21
1

When the computer starts up, the code in BIOS is executed first. However, how is the code in BIOS loaded into the RAM for execution ?

It doesn't need to be loaded, it's just there.

Keeping it simple: A CPU has a big address space.

  • 32 bit CPUs have 232 addresses (0 through 4294967295 ,or 0x00000000 through 0xFFFFFFFF)

  • 64 bit CPUs have 264 (0 through 18446744073709551999 or 0x0000000000000000 through 0xFFFFFFFFFFFFFFFF), when in 64-bit mode.

External hardware determines what appears where. Obviously RAM will be assigned some addresses, but it's also possible to map external devices to addresses - particularly common for graphics adapters.

I believe the chipset, specifically the Platform Controller Hub, will make the firmware chip appear where the CPU is looking when it powers on. The CPU will be able to run the firmware without having to load it - this is called "Execute In Place" or XIP.

Intel x86 CPUs look at 0x00000000FFFFFFF0 at power on. This is likely because of Intel's decision to put processor exception vectors at 0x0 in the 70's or early 80's when the first x86 CPU, the 8086 was developed - and you couldn't tell the 8086 to relocate those elsewhere.

It's called a ROM because historically it was a real socketed mask ROM chip long ago, but since at least the mid-90's it's almost always a NOR or NAND flash chip that can be erased and reprogrammed.

NVRAM can mean anything from battery-backed RAM to flash, so it's an imprecise term, but I've never heard a chip containing firmware called the "BIOS NVRAM".

Firmware flash chips are slow compared to DRAM, and some of the code in the firmware will be running often (e.g. System Management Mode code - code that manages the fans and power). So firmwares will copy themselves to RAM early in boot (called shadowing), and use additional chipset features to protect that region of memory.

If someone could list the steps from computer start-up upto the execution of first BIOS instruction including the memory addresses used, it would be very helpful

It used to be - power on, CPU spends some cycles initializing, then starts executing code at 0xFFFF0000 - and in 1981 when the first PC was developed, the CPU and everything it interacted with was on a common bus - literally wired together - so the ROM was simply on that bus and wired in to the right address lines on the CPU. In the early 90's, PCI was developed, and RAM started to become faster, so everything got separated from the CPU behind controllers and the chipset. Things have gotten even more complex with the Intel Management Engine and AMD's equivalent - the Platform Security Processor - now these processors with their own embedded firmware (and complete access to the rest of the system) bootup, verify various things and "turn on" the CPU when they are ready.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .