Windows/Linux Booting process
- Part 1 -
sinuxs *
There're lot of interesting (for me; i don't know for others) things hapenning under the hoods of a computer, a fraction of second after we press the power button (to start the computer). The decription explained here is a gleam of my experience on my own machine and from other sources; and is taken Intel(including AMD) as an example.
While the PC architecure is open since its inception in the early 80s, the explanation here is assumed to be consistent for my machine but may possibly be inaccurate for other. However, one can take a general perception though.
When you press the power button, the AC current from your wall socket surges into your power supply (or adapter, in case of laptop) and gets converted into various DC supplies which are eventually fed into the Motherboard and its various hardware components. This is where your computer is ready to start off. Your computer at this stage is suffering from 'Amnesia'- Loss of memory.
It doesn't remember anything which was happened before your last shutdown. you can blame(or flame?) it to the non-volatile nature of the RAM sticks! As this is so, it has to start loading the OS to run any user applications.
The next obvious question is - what is the first address the CPU accesses when your computer is started for the first time? Depends on the architecture. For the Intel(x86 from now on) architecture, the designer has been hardcoding the intial address to be : 0xFFFFFFF0 (reset vector), which is just a 16 byte down the 4GB. This address contains a JUMP to the first instruction of BIOS which is located at the last 64K segment of the first 1MB.
Why a JUMP? Is this necessary or is it that the Intel designers are a JUMPER . It's necessary because the x86 computer following a restart starts from 16 bit processor called 'Real mode' which sees only 1MB of memory space. And you may logically asks me how the CPU starts first with the address '0xFFFFFFF0'(see above) in this 1MB restricted mode.
Again, blame on to the Intel designers. They hardwired all the x86 procesors to anyhow starts the computer with this exceptional protected mode address. A protected mode is the full 32 bit processor with the 4GB address space. Coming to the point, we need a JUMP so that the CPU will restrictively operate in real mode and hence points to the last 64K segment of the first 1MB memory. The BIOS loads there so that the CPU will always execute the BIOS code following a restart/power-on of a computer.
Now, after the JUMP, the control (of execution) will go to the first instruction of BIOS and from now on, BIOS will take the control of execution. If you ask me why only the 1MB address space in real mode, I would say this time to blame on Intel(Early PC) and Microsoft(DOS). Actually, it's not their faults. During the early 80's when the PC was introduced, 1MB of memory was just unthinkabl!y and unanimously a huge memory then and had taken off with the decission.
The intention was to divide the 1MB address space into 16 segments of 64k bytes. We called them as the 16 segments of real mode. The Intel/Microsoft strategy was to allocate the first 10 segments (10*64k = 640K) called a 'conventional memory' to user programs and DOS and the remaining 6 segments(6*64k = 384K) to BIOS and BIOS areas. The last segment (16th segment) is the BIOS area where the computer first jumps into following a computer restart.
The last 6 segments of the real mode cannot be accessible even to DOS and other user programs and hence we could say that there is a HOLE in the first 1MB address space from 640K to 1023K (1MB). Somebody has rightly said this as the infamous 384K HOLE of real mode. A memory hole, in general, is a region of physical memory where an OS cannot allocate it to a user application. They can be because of the above ROM BIOS mapping or because of I/O device mapping.
I/O devices like Video RAM are often mapped into the physical RAM for effeciency purpose(through ioremap() in Linux kernel) and these are treated as 'Reserved' and hence treated as a 'HOLE' regions.
Now, let's come to the booting process. We jump into the BIOS code post restart. The BIOS code, as we're refering currently, is the Motherboard BIOS which comes with a chip embedded on it. It consists of POST code and 16bit drivers of all legacy hardware components - Keyboard, Mouse, Disk, various controllers and a setup-program called CMOS/BIOS setup. A computer system also has other BIOS code coming in along with Adapter cards like Video card, SCSI controller etc.
Motherboard BIOS has roughly the following responsibilites:-
= Execute other BIOS code(Video BIOS, SCSI BIOS etc), if present and as and when required.
= Check whether the booting is 'Cold boot' or 'Warm boot'.
= POST (Power-On Self Test) - Detecting, Initializing hardware components.
= IVT(Interrupt Vector Table) Setup - Loading 16 bit BIOS drivers. (part of POST)
= Allows the user to configure the BIOS setting through CMOS/BIOS editor utility.
= Displays the available final hardware settings - CPU, Memory, PCI controllers, SCSI controllers etc.
= Read the bootable disks. Load the first sector of the boot disk and pass on the control to it.
Running other BIOSes (Adapter's):
= The first of the activities done by the Motherboard(main) BIOS is to jump into the video BIOS code. This is when the screen shows the BIOS manufacturer Logo(Phoenix, in my case) and telling you that the video adapter is initializing and off course is workng properly!
The main reason the adapter card(like Video card/controller) has their own BIOS is probably the way to extend the main BIOS code and may be for some other extra features, the manufacturers(of the cards) want to initiate while the card is initialized with. How did the main BIOS finds the locations of other adapter's BIOS? The x86 architecture insists the adapter card manufacturers to map their BIOS from 0xC000(12th segment) to 0xF0000(15th segment).
The 16th segment, as mentioned earlier, is for the BIOS(main) code. The main BIOS starts looking for other adapter's BIOS from 0xC000. The main BIOS starts looking from this address a signature "0xAA55" for every 2K bytes successively till 0xF0000.The signature, if there, identifies that the segment is an adapter's BIOS. The following byte after this signature will give the size of the BIOS in 512 bytes chunks.So,the main BIOS will start looking for this signature for the video BIOS code at 0xC0000. It jumps into it and initializes the video card and all those logo (Energy),BIOS manufacturer details, CPU vendor and speed, Memory size etc. are shown up.
This is the first phase of POST. Once the video BIOS is executed, the control comes back to the main BIOS code. POST (Power-On Self Test): = POST test (a black screen at the computer startup) is done to find and initialize the hardware components(Physical drives, RAM, CD/DVD drives, Expansion slots, Keyboard, Mouse etc) so that an OS can be loaded. It consists of various POST tasks and any one of them fail would bring down the system. The error code of, if any of them is failed, will be written to '0x80h'(this is for Phoenix BIOS - mine. you may see your BIOS manufacturer datasheet to verify the same).
The error handler of the POST routine will decode the error codes and send to the display(if video adapter is working) or into a beep codes. Some of the POST tasks are mentioned below:-
- Initialize CPU registers
- Initialize I/O component
- Initialize the local bus IDE
- Initialize Power Management
- Initialize PCI Bus Mastering devices
- Initialize keyboard controller
- 8254 timer initialization
- 8237 DMA controller initialization
- Reset Programmable Interrupt Controller
- Test DRAM refresh
- Test CPU bus-clock frequency
- Advanced configuration of chipset registers
- Initialize interrupt vectors
- Initialize hard-disk controllers
- Set up Power Management
- Initialize the chipset
- Initialize the CPU
- Initialize PCI and DMA
You may check your BIOS manaufacturer manual for finer detail on the possible POST activitied from the error codes your BIOS is hardcoded.
One of the important functions done during POST is the initialization of IVT (Interrupt Vectore Table). The IVT is an array of 4 bytes pointers to interrupt routines. There is 4bytes for each IVT entry because the first 2bytes will give the segment address and the remaining two bytes will give the offset in the segment.
There are 256 interrupts define for real mode and hence the first 1024bytes (256*4) is occupied by IVT. You cannot press 'F2' or 'DEl' or 'F10' to enter the BIOS configuration without this IVT setup. The pressing of keystroke (will invoke IRQ1) fires the keyboard driver and displays the BIOS/CMOS configuration utility. Hence,
IVT setup is necessarily done before the computer displays something like, "Press 'F10' to enter BIOS/CMOS" etc. When all hardware components are set and proper, the BIOS code will determine the boot-disk sequence from the CMOS RAM. Well, before going further, let's go into a little bit about CMOS/RAM. CMOS/RAM is a chip comprises of RTC (Real Time Clock) and a RAM.This chip is powered by a button-like baterry. The CMOS chip is consuming a very low power(CMOS technology) that a battery can power it upto a maximum of 5-10 years.
With this battery,your computer can remember all the hardware components configurations and most importantly the date and time of the day. There are two parts of CMOS/RAM - user configurable data and static hardware configuration data. The user configurable data is the one we can change by pressing 'DEL' or 'F10' or 'F2' (depends on your BIOS manufacture). Here, you can change the booting sequence, master/secondary slave of IDE controller, change the date/time and some other parameters.
The other part of CMOS/RAM contains the non-changeable data of your hardware components like - the type of hard disk, the type of RAM(SDRAM, DDRAM,RDRAM etc), keyboard/mouse type,video display type(MDA/CGA/VGA etc) to name a few. The BIOS during its POST activity needs to know the type of your hardware to properly called its corresponding driver and probing as to whether it's correct or not. Any inconsistency with the hardware information present in CMOS/data and what's actually found after probing will halt the POST process.
In a sense, what we can conclude with this CMOS/RAM information is that there's a fair chance your computer will not boot properly if there's a problem in your button-battery causing the loss of CMOS/RAM data and ultimately (your) BIOS will not continue its POST activities. Now, coming to booting procedure, the BIOS after POST, will keep on searching a bootable disk from the sequence and load the first one which is found.
How does the BIOS code determines a bootable disk? Good question. A disk having a magic number "0xAA55" at the end of its first sector is a bootable disk. So, every bootbale disk will have this signature at the end of their first sector and this is how a BIOS knows and displays "No bootable disk ..." in the absence of any bootable disk or when a bootable disk drive is corrupted.
(Next: Windows vs Linux booting)
Linux kernel is an addict. Hardware is the driver of its existency. Join the community to make this open-source kernel, the best of its kind, as it is and for will be in the future.
Sign-off,
A Kernel junky.
* sinuxs (A pseudonym and a "kernel junky" ) contributes to e-pao.net regularly. The writer can be contacted at sinuxs(at)yahoo(dot)com
This article was webcasted on November 16th, 2009.
* Comments posted by users in this discussion thread and other parts of this site are opinions of the individuals posting them (whose user ID is displayed alongside) and not the views of e-pao.net. We strongly recommend that users exercise responsibility, sensitivity and caution over language while writing your opinions which will be seen and read by other users. Please read a complete Guideline on using comments on this website.