Hi,
junkoi wrote:Because we have only *1MB* memory that is reachable in real-mode, how can we have big size of BIOS, like 16MB as you said? In that case, where in the memory we keep the BIOS??
The simple answer is that the BIOS doesn't start in real mode.
The more complicated answer is that real mode itself is a hallucination (something that the CPU pretends exists, that doesn't actually exist at the lowest levels of the CPU)...
To understand this, you need to understand that internally the CPU operates on descriptor caches that describe the attributes of a segment (rather than what we see as segments). These descriptor caches are hidden from (most) software, and include a segment base address, segment limit, segment type, segment attributes, etc (for each segment register).
Normally when we load a value into a segment register the CPU sets the corresponding descriptor cache to appropriate values. However, when the CPU first starts the descriptor caches are set to "default" values, and the CPU designers can set the (segment base address, segment limit, segment type, segment attributes, etc) values in the descriptor cache to whatever they like.
More specifically, when a CPU first starts, the CPU designers set "CS base" to 0xFFFF0000, which is impossible for us to do (but possible for them). EIP/IP is still set to 0xFFF0, so the first instruction executed by a CPU is at 0xFFFFFFF0 (or "0xFFFF000:0xFFF0" in real mode style addressing).
As long as the BIOS ROM (just below 4 GB) doesn't try to reload CS then "CS base" stays the same. Most BIOSs probably do a near JMP to some code that switches to protected mode (and then switch back to real mode just before attempting to boot an OS's boot loader).
This is partly because there's lots of code for initializing and testing hardware (e.g. RAM controllers, northbridge, southbridge, etc), for building ACPI and MPS tables, for doing the "press F1 to enter setup" configuration, for setting up IRQ routing, for autodetecting hard disk sizes, etc. None of this code needs to be below 1 MB, so they leave it all below 4 GB and only copy what's needed (the "run-time" part) below 1 MB.
Note 1: If you're familiar with "
unreal mode" you'll realise it works by playing tricks with the values in the CPU's descriptor caches.
Note 2: You are right for 80286 and older CPUs (they did start at 0x000FFFF0 and did use a BIOS below 1 MB). AFAIK for the 80386 (and/or 80486?) there was a CPU pin which determined where the CPU's first instruction is (so the motherboard manufacturer could do it the old way or the new way, depending on how they wired this CPU pin). Modern CPUs start at 0xFFFFFFF0.
Cheers,
Brendan