Lets watch the following video before we go ahead with memory management. The video clip is from a famous TV series "NEWSROOM".
If you saw that video then the person sitting in the center quotes "first step in solving any problem is in recognizing that there is one". This part of the tutorial is inspired by that quote.
"first step in managing memory is in recognizing that there is one"
To accomplish this grub comes to our rescue. So how exactly the grub loader help us in this.
Once the operating system is loaded by the grub and its execution starts, the EBX register contains the physical address of a Multiboot information data structure. Through this information the boot loader communicates important information to the operating system. The Multiboot information is placed anywhere in memory by the boot loader (with the exception of the memory reserved for the kernel and boot modules, of course). The operating system uses this information to detect the memory.
Steps that should be followed :-
1) Create a file with name multiboot.h.
2) Copy the code on this page and paste it in multiboot.h.
3) Save it in the same folder where your kernel.c lies.
4) Edit the kernel.c
//add this #include "multiboot.h" //change the kernel_main function void kernel_main(multiboot_info_t* mbd,unsigned int magic) { //Now we have the memory information with us.
//Use your printf function to print the data here.
}
5) To understand each part of multiboot.h you should go through this. Basically the "multiboot.h" has the structure of how the memory map is stored in memory. You get a pointer to that memory section through "mbd" variable. If you understand pointers in C then it won't be difficult to get the memory map.
6) Print each value. Then you will find that the values are consistent with the memory you allocated for this virtual machine (Note: you have to patiently check the values as they involve a lot of calculations). You should also go through this to understand what part of memory is usable.
No comments:
Post a Comment