Samar and his thoughts

Saturday, August 2, 2008

Find hard to understand the BIOS call sequnce during Booting a PC

Hum .. Today is 3rd August 2008, My last blog was 19th July, was trying to build custom kernel without success. Then i thought of making some documentation on Linux system call sequence. I started and confused in understanding the protocol initialization during startup time. Hence i jumped from system call sequence to system booting up process and decided to create documentation on PC boot up sequence.

This time i am strongly determined of doing the documentation. I downloaded the Linux kernel code 2.4.19 and started looking into it.Soon i learned that "I am very confuse guy who didn't understand anything except computer/linux assembly and machine code." -- Got depressed very much(Probably no one will dream me as BF ;-))

Meantime 7 bomb blast rocked the city of Bangalore, and i got depressed again feeling the insecurity.Then i don't know , all of a sudden again i got interested in browsing Linux kernel code.

-- Ha, haha this time success smiles on my face.I was able to understand the majority of the bootsect.S code, but still there was something missing.After some time i realized that it was the concept of memory management. I started looking into the memory layout during the PC bots up and finally came up with the following concept.

As the system boots up the real mode addressing works, thus specifying all address in seg:off format. The seg:off format can be converted into linear address by the rule (seg*16+off) == Linuear address.

Memory Layout overview:
------------------------------------------
1) Conventional Memory:
2) Upper Memory Area(UMA)
3) High Memory Area (HMA)
4) Extented Memory Area (EMA)

1) Convetional Memory:
-----------------------------------
The first 640KB of system memory is known as "convetional memory".In the historic age DOS and some it's driver code used to run in this memory region, thus the naming convention.
Linear address range : 0x00000 to 0x9FFFF
Segmented address : 0x0000:0 to 0x90000:FFFF

For more infos: Please read
http://www.pcguide.com/ref/ram/logicConventional-c.html

... Feeling sleeping today, leaving right now, tomorrow we will discuss rest of the memory layout. :-)

After 12 hrs of rest in the evening of a friendship day, i woke up to complete the blog ;-).

Ok last, we have discussed about the convetional memory layout. Lets talk about the "Upper Memory Area" or (UMA)

2) Upper Memory Area:
-------------------------------------
The next 384 KB starting from the address 0xa000:0 to 0xFFFF:000F(or 0xA0000 to 0xFFFFF in linear address format) are supposed to be UMA. These memory range has been used for VIDEO RAM/ SYSTEM BIOS AREA/ Other Expansion CARD BIOS area. Remember when the machine is switched on the IP is set to the address as
CS:IP = 0xF000:FFF0
(Don't get confused 0xF000:FFF0 and 0xFFFF:000F --> Limit of UMA)
Means when the machine switched on the first instruction it tried to read from UMA.
More over we need to keep in mind that in UMA area some ROM addresses were being mapped in to the RAM and thus those addresses are READ ONLY.
We will talk about later while discussing the overall memory layout.

With the end of UMA the first megabyte of the memory layout ends here.

3) High Memory Area (HMA)
--------------------------------------------
The first 64KB(less than 16 bytes) of the second megabyte of the sytem memory. Technically this 64KB of memory is part of "Extended Memory Area"(EMA), though the difference it this part of memory range can be addressed when the processor is in real mode which makes it different from the rest of the extended momory.

Wait a minute....

Lets think about "How this memory range can be addressed by real mode??"

yes.. Any one ?? Besically i am a dummy guy.. never understand anything in a single shot...

Proof of Thinking 1 :
----------------------------------
We have 16 bits for SEGMENT addressing and another 16 bits for OFFSET addressing while the processor is in REAL MODE. Hence all possible combination are 2^16 x 2^16 = 2^32
As we know 2^20 == 1MB (First megabyte of the physical RAM ) the rest of the address i.e. 2^12 should be available as "High Memory Area"(HMA).
... Wait wait...
2^12 is 4KB but we were talking ablout 64KB as HMA?
?????????????????? What happend wrong ?????????????????????

Proof of Thinking 2 :
----------------------------------
Lets think in different manner. We know that Upper memory area ends at the address 0xFFFF:000F(Upto this address we already covered 1MB of the physical RAM). Now consider the address range 0xFFFF:000F to 0xFFFF:FFFF.
All possible combination is (2^16 -16) as we have started from 000F.
2^16 == 64KB. Finally got it.

4) Extented Memory Area (EMA):
---------------------------------------------------
This is the memory region above the High Memory Area until the end of the system memory.To use this memory region OS needs to be boots up in protected mode as no real mode addressing can access the memory region.
Extended memory is found from address 10FFF0h to the last address of system memory. (Technically, the high memory area is part of extended memory, it all depends on how you are looking at things).

We will talk about the memory layout in the pictorial manner in the next blog.
Good bye for now.

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home