Showing posts with label BIOS. Show all posts
Showing posts with label BIOS. Show all posts

Sunday, September 11, 2011

Booting

Today let's discuss about booting and what actually happens when a system boots.

During the early days of computers, the boot program is made read only and is put in hardware chips. This boot program is called a bootstrap in computer terminology. The bootstrap initiates all the CPU registers, device controllers and finally loads the operating system into memory. The advantage of this scheme is that, since the bootstrap is read only, no virus can effect it. But the disadvantages outweigh this. First, if we want to add any external hardware,  it's device driver needs to be loaded when the system starts. But, since the bootstrap is read only, we need to change the hardware chips. Also, the operating system must be in a fixed location as specified in the boot strap, if we install the operating system in a different area, then also there is a need to change the chip.


So our computer scientists thought over this and came up with a simple solution. Instead of making ROM's with complete bootstrap program in them, they started making ROM's with tiny bootstrap program's called bootstrap loader. And the main bootstrap program is stored in the disk. Since changing the bootstrap program simply requires a write to the disk, our problem is solved. The bootstrap program on the disk is generally stored in first sector of the hard disk called boot sector.

But... a new problem arrived -- Boot sector virus

Enough of computer terminology, now I will explain in simple terms. BIOS is generally present in non-volatile ROM chips as you know, and this generally initiates the main memory, CPU registers, device controllers and starts the tiny bootstrap loader that is present in it. The BIOS is built at the time of manufacture of a PC and when you start the PC, it is the first software that normally executes, even before the main memory or disk gets initialised. It looks as below


The full bootstrap program as I told earlier, is stored in first sector of harddisk called boot sector. After initialisation of all aspects, the BIOS loads this program to main memory and hands the baton to it for execution. This boot sector in windows computers is called Master Boot Record or simply MBR. MBR contains the full boot code, along with a partition table. This partition table contains the information of partitions along with information whether an Operating system is present in each one or not. If only one OS is present, it is shown or by default it's loaded since there is no need for user to make choice. If more than one OS is present, the user is presented with options to load what ever operating system he wants to be loaded.


Last, about boot sector virus. To prevent boot sector virus, there is an option in BIOS, which makes the bootstrap program on the disk read-only. When ever you think you are not going to install any more OS, check it on and when you want to change your OS, check it off. Happy now...virus problem also solved

Friday, June 10, 2011

Macro Processor

Macro Processor is a program that lets you define the code that is reused many times giving it a specific Macro name and reuse the code by just writing the Macro name only.

Generally it doesn't come as a separate program but as a bundle to either assembler or compiler

Note : Please don't confuse Macro Processor with Micro Processor, remember Micro Processor is a hardware device and it's a completely different area of study

There are three main steps of using a macro

1.Define the macro name
2.Give it's definetion
3.Use the macro name from with in the program anywhere to use it's definetion (this step is called macro call)

And the most important thing is that, macro processing is done before the compilation replacing the code in place of macro calls and deleting macro definetions.If you are on an open source OS, this can easily be tested.For others, this is how it happens.This is my helloworld programme


#include<stdio.h>
#define hell printf("\nHello world\n");printf("I am a good boy\n\n");


int main()
{
hell;
}

Now there is are a lot of options in gcc compiler and if you use gcc helloworld.c -E , it gives you the code that is processed before it is passed to the compiler.It includes a lot of things along with the code.But since our main discussion is about Macro processing, let's see how the macro processed code looks like

# 916 "/usr/include/stdio.h" 3 4

# 2 "helloworld.c" 2


int main()
{
printf("\nHello world\n");printf("I am a good boy\n\n");;
}




You can clearly see that macro processing is already done replacing hell with the corresponding macro definition.This is passed onto the compiler which does the remaining job. This is the compiled output


Hello world
I am a good boy



Note : There are a lot of interesting things gcc command does apart from compiling type gcc --help for more info
Gcc logo

There are a lot more uses for macro and don't confuse functions with macros even though both are used for same purpose and if any one asks you the difference tell them, the things I showed you above, function gets compiled but a macro gets macro processed

One important use of these macros is for booting.During the boot time, the system uses a lot of macros to get itself started since they need not be compiled to use, but just macro processing is enough which is a small task

So, for today, alvida guys, thanks for baring with me, and if you have suggestions pass the comments as you like and hit the +1, button below this post, if you want you can post this one to your friend, since I have enabled posting, see the social buttons for all the things you need.