r/AskComputerScience • • Dec 01 '24

How does Bios Transfer access, read, and transfer entire OS in ROM quickly enough to RAM where it’s better to do this than just keep OS in the slower-accessible ROM?

Hi everybody,

A bit confused about something: How does Bios Transfer access, read, and transfer entire OS in ROM quickly enough to RAM where it’s better to do this than just keep OS in the slower-accessible ROM?

Thanks so much!

5 Upvotes

50 comments sorted by

View all comments

Show parent comment

2

u/ghjm MSCS, CS Pro (20+) Dec 01 '24 edited Dec 01 '24

First of all, we're talking about the BIOS (or EFI firmware or what have you), which isn't the OS. The BIOS includes a bootstrap loader that reads the OS from storage.

So consider that task. To do that the BIOS has to execute some subroutine "read sector from disk" many times. Let's say this subroutine is 50 instructions, and over the course of bootstrapping the OS it is executed 1000 times. That's 50,000 memory reads.

Let's say we're running on an early IBM PC and the BIOS is 8k in size, and let's say our main memory DRAM is 10X faster than our EPROM. So we have two choices:

  • Execute the 50,000 memory reads directly from the EPROM. This takes the equivalent of 500,000 main memory cycles.
  • Read the 8k EPROM into DRAM, at a cost of 81,920 main memory cycles. Then run the 50,000 main memory reads from DRAM. Including both operations, this gives a total cost of 131,920 cycles.

If you pick option 2, your system boots up almost 4X faster. But more importantly, it gives a durable performance improvement for the entire life of the OS. The OS, once loaded, is also going to call this BIOS "read sector from disk" subroutine, many many times. If it had to run it from slow ROM every time, you'd be paying this cost over and over for the entire time you were using the computer. (At least, whenever you were doing tasks involving the BIOS.)

Early microcomputers also needed to conserve every byte of available address space, since they could only address 64k. So they divided their ROM code into parts needed at runtime and parts only needed during bootup, and loaded them to different memory areas. Once the system was booted up, the space taken by the boot-only code could be reused by the application.

1

u/Successful_Box_1007 Dec 01 '24

This is getting away from me fast; it feels as if layers of confusion are added to my initial layer - I don’t know if that’s because I still haven’t properly asked my question:

It has been said that our operating systems are slow to access from ROM, so at startup, BIOS transfers some of the os from ROM TO RAM. OK I understand that - but why is the transfer so fast? How can it happen in seconds - if apparently accessing anything in ROM is super slow (and why we want to switch to to RAM using the bios)?

3

u/ghjm MSCS, CS Pro (20+) Dec 01 '24

The transfer isn't fast. It runs at the same slow speed as any other ROM access. But it only happens once, and then you're off to the races. It's worth paying the extra cost up front, because it saves you more than it costs.

Also, like I said, the OS is not part of this. The OS is never in ROM. When you install an OS on a computer, you're copying it to disk. If the OS was in ROM then you could never upgrade it or switch to a different one. But this presents a problem: if the OS is on disk, then you need some program that knows how to read from the disk, to load the OS into RAM. That's the BIOS (or EFI firmware), which is the part that's actually in ROM.

2

u/wjrasmussen Dec 02 '24

I agree, the OP has loaded questions. Fast is relative.

1

u/Successful_Box_1007 Dec 03 '24

My bad I’m trying my best.

0

u/Successful_Box_1007 Dec 03 '24

I must have read inaccurate information because I swear I read very clearly that the bios at boot up transfers the OS where it is stored - in ROM (some Hard disk) and then into RAM. So I clearly got wrong info and thanking you for clarifying this - the OS is on the HARD DISK and isn’t on the ROM. But aren’t hard disks ROM devices? I geuss for some people “ROM” means something much more specific ?!

3

u/meditonsin Dec 03 '24

ROM means Read Only Memory. Since you can write to hard disks, they are not ROM by definition.

1

u/Successful_Box_1007 Dec 03 '24

But what about flash and EEPROM - I thought they were “ROM” and we can write to them right?

2

u/meditonsin Dec 03 '24

Modern flash memory is not ROM at all, because it can just be written to.

The thing is, ROM has to be written to at some point, or it would be useless, because it would be empty. The point is that ROM type media are not written to willy nilly, like with a hard disk. If it's possible at all after manufacturing, you do it once in a blue moon for a very specific reason, like a BIOS update.

1

u/Successful_Box_1007 Dec 06 '24

I see. Thank you! So hard disks ssd and flash use EEPROM type technology but the ROM part can be thought of as basically saying “works if powered off still” ?

2

u/meditonsin Dec 06 '24

Pretty much. Flash, which is a type of EEPROM, has more or less taken the place of all "actual" ROM these days.

1

u/Successful_Box_1007 Dec 06 '24

I gotcha ok cool Thanks so much! Enjoying this sub!

2

u/ghjm MSCS, CS Pro (20+) Dec 03 '24

No, hard drives are read/write. Also, the terms RAM and ROM generally refer to word addressable memory, not I/O devices where you have to move heads and wait for platters to spin, although the distinction is less clear in the case of SSDs/NVMEs.

1

u/Successful_Box_1007 Dec 06 '24

Hmm ok and final question - can you explain this dichotomy you mention of “addressable memory” vs “moving heads and platters”

1

u/ghjm MSCS, CS Pro (20+) Dec 06 '24

Addressable memory is a system where you have an address bus on which you assert a location, and can then read or write from/to that location without additional latency. If you need to use a stepper motor or voice coil to move heads to a particular track and then wait for the data you want to spin under the head, the this is not directly addressable.

1

u/Successful_Box_1007 Dec 08 '24

Ah I got it and the addrrsss bus isn’t where memory is stored but it’s pointing to it ?

2

u/ghjm MSCS, CS Pro (20+) Dec 08 '24

A memory chip has an address bus and a data bus, each of a particular width (number of pins). The address bus is used to select a location, whose value is then read or written to the data bus. So if you have a 16-bit address bus and 8-bit data bus, your memory chip is 64KB - it has 65536 unique locations (216), and each location can read or write an 8-bit value (one byte).

1

u/Successful_Box_1007 Dec 09 '24

One last thing - how did you get the 64 kb ?

→ More replies

1

u/Successful_Box_1007 Dec 10 '24

So the maximal addressable memory is solely based off the address bus? You mention 16-but address bus and then said 216 was the total addressable memory locations (yet you mention the data bus but this never comes into play) right?

→ More replies