hanumant wrote:
1)For the size of RAM i have come across the memory map (mmap_*) method, though i dont understand how its supposed to be used . i mean for every mmap structure ,
(if flag ==1)(RAM available)
current_size_RAM += sizeofstructure. ????
The physical memory seen by the processor in your system is not necessarily the same as the DIMMs that are plugged onto you motherboard. There are many memory mapped devices at various places in the physical memory layout which are not RAM. The most obvious of these is the vga color text framebuffer at 0xb8000, but other pieces exist, such as ACPI and PCI configuration spaces. The memory map provided by grub (usually obtained from the bios int 15h e820 as mentioned above) is one of the best ways of identifying which parts of physical memory you can use, and which you can't.
From the multiboot header, you could do something like:
- iterate through each mmap entry defined as available
- start at 1MB or the start of the entry (whichever is least) and iterate up in 4kB pages.
- check each page is not 1) overlapping part of an elf section, 2) overlapping part of a grub module and 3) overlapping part of an unavailable mmap section.
- if page is really free, set it as free in your physical memory allocator.
The reason I suggest not including pages below 1MB is that some bios' report that all the memory below 1MB is free. They assume you to know what to touch and what not to. For simplicity's sake, just ignore it (most modern computers have another GB or several hundred MBs anyway).
One of the problems you have to deal with is that grub can place its multiboot information, and all the tables it references (elf sections, mmap and modules) anywhere in memory, according to the multiboot specification. In reality, in current grub legacy, they are allocated as parts of the grub program itself, below 1MB, but that is not guaranteed to remain the same. For that reason, you have to somehow protect these tables before you start using a certain bit of memory as a physical memory bitmap or something.
Regards,
John