r/AskComputerScience • u/AnyCourse6366 • Jan 22 '26
What loads into RAM first when a computer starts?
1 hour ago,the teacher of my class asked "What loads into RAM first when a computer starts?" a guy answered that was the operating system and my teacher said it was correct.But i thought it would be uefi loaded in ram first. So I asked my teacher and she said that was not true because the uefi was a firmware in the computer.But it still didn't convinced me.I would appreciate it if you could answer my questions about what is loaded in ram first when the computer starts 😁😁😘
63
Upvotes
39
u/wrosecrans Jan 22 '26
You sort of need to be talking about a very specific kind of computer to get a very specific answer. Not all computers have UEFI, etc.
For a modern UEFI based PC, there will be some very low level firmware doing initialization that will presumably use at least some RAM before UEFI even enters the picture. For example, the code that initially probes how much RAM is installed has to write that fact to a known address in RAM, which is a fun little bit of bootstrapping paradox. Then yeah, the UEFI code is probably not stored in a way that it is executed in place, so it is probably loaded into RAM and executed there by the lower level firmware. At very least, even if UEFI is running directly from a ROM without having been loaded into RAM, it writes some sort of data in RAM to keep track of what it is doing when it loads the OS bootloader.
And yeah, we haven't actually gotten to the OS yet because ntldr or Grub or whatever gets loaded by UEFI isn't actually "the OS" even if it is shipped as a component of the OS.
Also, we skipped over stuff that might get loaded like Option ROM data... https://en.wikipedia.org/wiki/Option_ROM#UEFI_Option_ROMs
Anyhow booting is complicated. Check out https://wiki.osdev.org/System_Initialization_(x86) for some more notes.
Anyhow, it sounds like you are in a very basic introduction to computers kind of class and the teacher is telling "lies for children" to simplify things down to some simple abstract concepts. Tell the teacher what they want on the test. Use the class as a jumping off point for deeper understanding.
One slightly bonkers answer to the question of "what is loaded first into RAM" is the contents of the SPD EEPROM. It's a non-DRAM device which sits on the DIMM and stores information about the memory module. Now sure, it's insane to call an EEPROM RAM. But people also refer to a whole DIMM as RAM all the time. "I am going to install some RAM in my computer" doesn't mean buying a DIMM and desoldering the actual DRAM devices to use by themselves. And in many contexts it would be nonsensical to say that data on the DIMM that was sold as a piece of RAM isn't on the thing that was sold and purchased and referred to as "RAM." The information in the SPD chip is "loaded into RAM" months before the computer is assembled, let alone turned on. I only give this cheeky answer by way of making the point that when you go down a rabbit hole of "Um, Actually..." you need to define your terms and context quite carefully to make sure that the answers to your question are useful to whatever you are doing.
16
u/ghjm MSCS, CS Pro (20+) Jan 22 '26
To add to /u/wrosecrans's good answer, for early computers, the answer was often nothing. When you powered on the computer, nothing immediately happened at all, and you had to use toggle switches on the front panel to manually copy a bootloader program into memory and then jump to it. The bootloader program would load some larger program, usually an operating system and usually from tape, and then jump to that. Eventually people got tired of toggling in the same bootloader every time they wanted to start the computer, so computers started shipping with the bootloader hardcoded into ROM. The PDP-8 was the last major computer to have toggle switches on the front panel.
4
u/not_from_this_world Jan 22 '26
UEFI has a core that stays on an EPROM and usually performs some very basic hardware checks. That core UEFI loads UEFI extensions from the main storage into RAM. If you have Linux you can see them at /boot/efi, on Windows they are in the Boot partition. Those extensions perform more complex tasks like being a networking driver, an USB driver or even a basic GPU driver. Also one of the extensions is the bootloader that loads the OS into memory. Mostly of the UEFI stuff are in the extensions, so you're mostly right.
2
u/Worth-Wonder-7386 Jan 22 '26
It depends on the architecture. But the first thing to load into memory is the part that does the booting to the UEFI.
This video explains a bit on it: https://www.youtube.com/watch?v=Pu7LvnxV6N0
So there is some basic program stored in your computer that just tell it to go look for the UEFI and such so that it can boot.
7
u/rustacean909 Jan 22 '26
I've written some code for the Coreboot project, so I mainly know how it works for x86-64. As others already wrote, the details depend on the platform.
For modern UEFI firmware the ROM is usually too small to contain the whole firmware uncompressed (and accessing RAM is way faster tham ROM), so the later stages of the firmware are the first thing loaded into RAM.
Here's an abridged version of what usually happens until the OS starts on x86-64:
1
u/jean_dudey Jan 22 '26
The answer is also “it depends”, some platforms have a ROM that can load a payload directly to RAM, some only load a firmware that initialises RAM first then loads the next payload.
But for 90% of the cases there will be multiple stages of firmware that initialise the hardware at each step, like coreboot for example where some stages use cache as RAM, then some stages run in the RAM after it’s been initialised, then the next payload like EDK2, Grub or any you specify.
1
u/cormack_gv Jan 22 '26
Well, OS is correct, but OS loads in stages, which is why it is called "bootstrap" or "boot" for short.
Generally, the first stage is in ROM not RAM. In the old days, the first stage might've been on punched cards or paper tape, or magnetic tape.
On IBM mainfraimes (and many cash registers) the first stage is called IPL for "initial program load." I haven't been hands on with a mainframe in decades, but the '360 had a rotary dial that you could point at tape, card reader, etc. And a blue button labeled IPL.
Before then you might've had to put the initial stage in using switches.
2
u/AYamHah Jan 22 '26
Glad you are pushing back on this. The teacher is way oversimplifying things, typical for school, but since they asked the question, they should expect an intelligent student to question and be prepared with a lot of "Well, in modern computers..." and "It depends..." style answers.
If they were just like "No, you're wrong" then find a new CS teacher or talk to the dean about how this person ever got their position.
1
u/Marutks Jan 22 '26
Bootloader loads into RAM before OS. And UEFI / BIOS before that.
1
u/Silly_Guidance_8871 Jan 22 '26
Speaking from an x86 perspective: UEFI often runs directly from ROM (mapped to physical memory address, but not actually copied to RAM), which loads the bootloader from disk into RAM, which then decides which operating system to load. Programmers, even systems programmers, rarely have to consider the first two, as they're basically just there to bootstrap the OS, which will stay loaded into RAM for as long as the machine is up.
It's a question of perspective.
1
u/ebmarhar Jan 22 '26
Older computers were a lot simpler than modern computers in this regard. From memory, here's how CP/M worked:
A system ROM is hardware-mapped to address 0. It has just enough code to
- initialize the floppy disk
- read the 128 bytes of track 0, sector 1 to address 0x80
- jump to 0x80
This was called something like. the "level 0 bootloader". That bootloader would then read the rest of the operating system and then jump to the command line processor.
1
u/motific Jan 23 '26
Answer: Whatever the ROM tells it to
1
u/bkubicek Jan 26 '26
Is it not random garbage that is loaded to test basic memory functionality during memory training? At least for AMD?
-2
u/Awkward-Chair2047 Jan 22 '26
Check out POST or Power On Self Test and the pre-boot loader on google or chatgpt. Also look into BIOS Routines and the IVT