12

For the BIOS, Wikipedia states:

The address of the BIOS's memory is located such that it will be executed when the computer is first started up. A jump instruction then directs the processor to start executing code in the BIOS.

I know that BIOS lives in non-volatile memory. But it would have to be loaded into the RAM for it to be executed. So who loads the BIOS into RAM ?

I have also read that a memory map is loaded at start-up. Does the BIOS load this memory map ? Where is is stored ?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Cygnus
  • 3,222
  • 9
  • 35
  • 65
  • 5
    You can very much run a BIOS from ROM. – nos Dec 31 '13 at 17:35
  • 1
    This question is off topic here. Use superuser.com in the future, this question is [already covered](http://superuser.com/questions/336021/is-bios-read-from-the-bios-chip-or-copied-into-ram-on-startup). – Hans Passant Dec 31 '13 at 19:29
  • The memory map is hard coded into the hardware AFAIK. There isn't a 'memory map' to load. – tangrs Jan 01 '14 at 03:07
  • 1
    I think this other topic answers your question. http://stackoverflow.com/questions/5300527/do-normal-x86-or-amd-pcs-run-startup-bios-code-directly-from-rom-or-do-they-cop/5347759#5347759 – myron-semack Jan 06 '14 at 14:58
  • 3
    @tangrs the memory map is definitely not always hard-coded - if it was, how would it support changing the amount of RAM? – Drew McGowen Jan 08 '14 at 09:53

1 Answers1

18

At initial power on, the BIOS is executed directly from ROM. The ROM chip is mapped to a fixed location in the processor's memory space (this is typically a feature of the chipset). When the x86 processor comes out of reset, it immediately begins executing from 0xFFFFFFF0.

However, executing directly from ROM is quite slow, so usually one of the first things the BIOS does is to copy and decompress the BIOS code into RAM, and it executes from there. Of course, the memory controller must be initialized first! The BIOS takes care of that beforehand.

The memory map layout will vary from system to system. At power-on, the BIOS will query the attached PCI/PCIe devices, determine what resources are needed, and place them in the memory map at the optimal location. If everything is working properly, memory-mapped devices should not overlap with RAM. (Note that on a 64-bit system with >3GB of RAM, things get complicated because you need a "hole" in the middle of RAM for your 32-bit PCI/PCIe devices. Some early x64 BIOSes and chipsets had issues with this.)

myron-semack
  • 6,259
  • 1
  • 26
  • 38
  • `The ROM chip is mapped to a fixed location in the processor's memory space.` Does this mean that the memory controller (which AFAIK is on the CPU for both Intel & AMD) has pins out to the CMOS containing the BIOS and has hardcoded that redirect for that memory range to go to those pins? – Sled Aug 20 '20 at 15:58
  • 2
    @Sled: No, physical address space includes DRAM but also PCIe and other device memory. Physical addresses that don't refer to DRAM are routed to the "system agent" on the ring bus, instead of one of the memory controllers. The system agent has off-chip connections to the chipset (and some other dedicated PCIe lanes that are usually wired up to a PCIe x16 slot for a graphics card.) [X86 Address Space Controller?](https://superuser.com/a/1226198) – Peter Cordes Oct 28 '21 at 03:40
  • @PeterCordes What do you mean by the processor's memory space? Are you talking about RAM? If so, how is the ROM chip mapped to a fixed location in RAM? What does "mapped" mean here? My understanding is that RAM is volatile, and hence doesn't contain any data when the computer is turned on. – Mehdi Charife Nov 09 '22 at 09:10
  • @MehdiCharife: I said "*address space*" not *memory space* for a reason. ROM and RAM both have physical addresses; they're at different places in physical address-space, and PCIe device memory exists at other places, too. Other people are using "mapped" to mean "located". The motherboard designer may physically have wired up some ROM in a certain way that makes it respond to certain physical addresses. (Or actually it will be behind probably a super-IO motherboard chip which decodes the physical addresses.) – Peter Cordes Nov 09 '22 at 09:15
  • @PeterCordes *" The ROM chip is mapped to a fixed location in the processor's memory space"* You said memory space, not address space. – Mehdi Charife Nov 09 '22 at 09:19
  • @PeterCordes *"PCIe device memory exists at other places, too. Other people are using "mapped" to mean "located". The motherboard designer may physically have wired up some ROM in a certain way that makes it respond to certain physical addresses."* But how does the CPU know that physical address (where the BIOS is located) when the computer is turned on? – Mehdi Charife Nov 09 '22 at 09:21
  • 1
    @MehdiCharife: [How does a modern x86 CPU access the BIOS ROM](https://superuser.com/q/1390523) has a sort of answer. In terms of [X86 Address Space Controller?](https://superuser.com/a/1226198), think of ROM as just another device the CPU can access via a range of physical addresses. The motherboard designers set things up so the ROM responds to those addresses. – Peter Cordes Nov 09 '22 at 09:21
  • 1
    @MehdiCharife: The CPU doesn't find out from the motherboard where the ROM is, it's hard-wired to fetch code from physical address 0xFFFFFFF0 at bootup. It's up to the motherboard designer to build a system that has useful machine code at that physical address, normally by wiring up a flash ROM. – Peter Cordes Nov 09 '22 at 09:24
  • 1
    @MehdiCharife: Re: who said what: maybe you're looking at someone else's comments or answer. Before you replied, the only text of mine on this page was the 2nd comment. If I search-within-page in my web browser, the phrase "memory space" appears in the answer and the comment above mine, but not in my comment. I can't help it if other people use weird and confusing terminology, but I intentionally didn't repeat it. (OTOH I didn't think it was bad enough to explicitly call out and correct.) – Peter Cordes Nov 09 '22 at 09:26
  • @PeterCordes *"it's hard-wired to fetch code from physical address 0xFFFFFFF0 at bootup."* How is it hardwired to do so? Does it store that address at some internal memory component that it has internally, or is the instruction register electrically designed to have 0xFFFFFFF0 as its default value? – Mehdi Charife Nov 09 '22 at 09:27
  • 1
    @MehdiCharife: One or the other of those, yes; either microcode sets the initial CS:EIP, or they're just built to default to that value at power-up. Depends on the CPU design, both sound valid. Also related re: motherboards having ROM at that address, [Software initialization code at 0xFFFFFFF0H](https://stackoverflow.com/q/9210296) / [Is address 0xFFFFFFF0 hardwired for system BIOS ROM?](https://stackoverflow.com/q/23075586) **Or better, [How is the BIOS ROM mapped into address space on PC?](https://stackoverflow.com/q/7804724)** – Peter Cordes Nov 09 '22 at 09:31