Today, I'm here because while trying to handle the multiboot information structure, I encountered a new puzzling behavior. This time, I was trying to get a memory map.
According to the multiboot doc...
Okay, so after a long puzzled look, I made some code reading the memory map in order to make sure everything is okay.If bit 6 in the `flags' word is set, then the `mmap_*' fields are
valid, and indicate the address and length of a buffer containing a
memory map of the machine provided by the BIOS. `mmap_addr' is the
address, and `mmap_length' is the total size of the buffer. The buffer
consists of one or more of the following size/structure pairs (`size'
is really used for skipping to the next pair):
+-------------------+
-4 | size |
+-------------------+
0 | base_addr_low |
4 | base_addr_high |
8 | length_low |
12 | length_high |
16 | type |
+-------------------+
where `size' is the size of the associated structure in bytes, which
can be greater than the minimum of 20 bytes. `base_addr_low' is the
lower 32 bits of the starting address, and `base_addr_high' is the
upper 32 bits, for a total of a 64-bit starting address. `length_low'
is the lower 32 bits of the size of the memory region in bytes, and
`length_high' is the upper 32 bits, for a total of a 64-bit length.
`type' is the variety of address range represented, where a value of 1
indicates available RAM, and all other values currently indicated a
reserved area.
The map provided is guaranteed to list all standard RAM that should
be available for normal use.
Code: Select all
void print_mmap(multiboot_info_t* mbd) {
unsigned int remaining_mmap;
memory_map_t* current_mmap;
unsigned long hack_current_mmap;
int i;
if((mbd->flags & 64) == 64) {
remaining_mmap = mbd->mmap_length;
current_mmap = mbd->mmap_addr;
i = 0;
dbg_print_str("Map of the memory :\n");
while(remaining_mmap > 0) {
//Display contents
dbg_print_str("* Memory item ");
dbg_print_int(i);
dbg_print_str(" from ");
dbg_print_uint(current_mmap->base_addr_high);
dbg_print_chr('/');
dbg_print_uint(current_mmap->base_addr_low);
dbg_print_str(" of size ");
dbg_print_uint(current_mmap->length_high);
dbg_print_chr('/');
dbg_print_uint(current_mmap->length_low);
if(current_mmap->type == 1) dbg_print_str(" is available\n");
else dbg_print_str(" is reserved\n");
//Move to next mmap item
hack_current_mmap = (unsigned long) current_mmap;
hack_current_mmap += current_mmap->size+4;
remaining_mmap -= current_mmap->size+4;
current_mmap = (memory_map_t*) hack_current_mmap;
++i;
}
} else dbg_print_str("No memory map found\n");
}
Item 2->Item 3->Item 4 transitions look fine, but Item 4->Item 5 transition look strange, too.
That's strange, and according to the Multiboot doc,
Shouldn't RAM take the form of a contiguous address space ? Is my code wrong ?The map provided is guaranteed to list all standard RAM that should
be available for normal use.
(My OS will surely rule the world someday, but in meantime it's very hard to go back to the "noob programmer" state )