[SOLVED] Memory Map from GRUB is complete, Right?
Posted: Sun Jan 17, 2016 6:35 am
Here is another stupid post and please bear it as you did my last posts :p sorry again for disturbing.
But this time,
I want to ask wether the Memory Map GRUB gives us is complete or not? Don't Jump to conclusion, please read the query completely :3
I have successfully got the memory map from grub which I used to make memory blocks (each of 4096 bytes size) which I then use in my virtual memory allocation system. Now what I do is I just tested wether the memory which GRUB Memory map said its available (type 1) is actually working or not. I just Identity mapped the whole memory (and didn't did anything else before it), enabled paging and then tested the virtual mem system. I Tested the system by simply writing and reading from the memory which a block contained. I could successfully Read ALL available memory in QEMU (with 1 GB mem ) without any trouble. But when I try the SAME thing with VMWare (with 3.5GB mem, 3.3 GB available from first 1 MB to 3.3rd GB straight as GRUB says), I get Page Fault at 1.1GB (sorry for not using hex, its 3219062784) and the system crashes. The Page Fault Handler I used displayed the address and reason for page fault. It said that the page fault was due to READ ONLY page but it didn't displayed the physical memory address of the fault. But because I was displaying every memory address which I checked, I got to know the memory location was 11016561968 (bytes) though the last mem location which should be accessible is 3219062784. I concluded the error was because the frame the page refered to at 11016561968 was not available (the memory wasn't there). If it is so OR if itsnt so, then too, why the Memory Map GRUB provides in VMWARE is not complete while everything is FINE in qemu??
Or if I am missing something, please do tell me
Reply politely, because I know I am an IDIOT :3 :p Thanks for helping
EDIT: VIRTUAL BOX SHOWING SAME PROBLEM
Memory Map from Virtual Box:
start: 0 size: 652288 type 1
start: 652288 size: 3072 type 2
start: 817392 size: 8192 type 2
start: 901120 size: 147456 type 2
start: 1048576 size: 3219062784 type 1
start: 3220111360 size: 61440 type 3
rest if needed, ask me.
Memory Map from GRUB IN VIRTUALBOX:
start: 0 size: 652288 type 1
start: 652288 size: 3072 type 2
start: 817392 size: 8192 type 2
start: 901120 size: 147456 type 2
start: 1048576 size: 3333357568 type 1
start: 3334406144 size: 65535 type 3
rest if needed, ask me.
Memory Map from GRUB IN QEMU:
start: 0 size: 652288 type 1
start: 652288 size: 3072 type 2
start: 817392 size: 8192 type 2
start: 901120 size: 147456 type 2
start: 1048576 size: 107255808 type 1
start: 1073606656 size: 135168 type 2
rest if needed, ask me.
Paging Code:
// The size of physical memory.
u32int mem_end_page=(0xFFFFFFFF-(4096*1024));
nframes = mem_end_page / 0x1000;
frames = (u32int*)kmalloc(INDEX_FROM_BIT(nframes));
memset(frames, 0, INDEX_FROM_BIT(nframes));
u32int phys;
kernel_directory = (page_directory_t*)kmalloc_a(sizeof(page_directory_t));
memset(kernel_directory, 0, sizeof(page_directory_t));
kernel_directory->physicalAddr = (u32int)kernel_directory->tablesPhysical;
for(uint32_t i=0;i<(1024*maxmem);i+=4096) //page virtually every available free memory. maxmem is Memory size in KB from GRUB
alloc_frame(get_page(i,1,kernel_directory),1,1);
int i = 0;
switch_page_directory(kernel_directory);
current_directory = clone_directory(kernel_directory);
switch_page_directory(current_directory);
But this time,
I want to ask wether the Memory Map GRUB gives us is complete or not? Don't Jump to conclusion, please read the query completely :3
I have successfully got the memory map from grub which I used to make memory blocks (each of 4096 bytes size) which I then use in my virtual memory allocation system. Now what I do is I just tested wether the memory which GRUB Memory map said its available (type 1) is actually working or not. I just Identity mapped the whole memory (and didn't did anything else before it), enabled paging and then tested the virtual mem system. I Tested the system by simply writing and reading from the memory which a block contained. I could successfully Read ALL available memory in QEMU (with 1 GB mem ) without any trouble. But when I try the SAME thing with VMWare (with 3.5GB mem, 3.3 GB available from first 1 MB to 3.3rd GB straight as GRUB says), I get Page Fault at 1.1GB (sorry for not using hex, its 3219062784) and the system crashes. The Page Fault Handler I used displayed the address and reason for page fault. It said that the page fault was due to READ ONLY page but it didn't displayed the physical memory address of the fault. But because I was displaying every memory address which I checked, I got to know the memory location was 11016561968 (bytes) though the last mem location which should be accessible is 3219062784. I concluded the error was because the frame the page refered to at 11016561968 was not available (the memory wasn't there). If it is so OR if itsnt so, then too, why the Memory Map GRUB provides in VMWARE is not complete while everything is FINE in qemu??
Or if I am missing something, please do tell me
Reply politely, because I know I am an IDIOT :3 :p Thanks for helping
EDIT: VIRTUAL BOX SHOWING SAME PROBLEM
Memory Map from Virtual Box:
start: 0 size: 652288 type 1
start: 652288 size: 3072 type 2
start: 817392 size: 8192 type 2
start: 901120 size: 147456 type 2
start: 1048576 size: 3219062784 type 1
start: 3220111360 size: 61440 type 3
rest if needed, ask me.
Memory Map from GRUB IN VIRTUALBOX:
start: 0 size: 652288 type 1
start: 652288 size: 3072 type 2
start: 817392 size: 8192 type 2
start: 901120 size: 147456 type 2
start: 1048576 size: 3333357568 type 1
start: 3334406144 size: 65535 type 3
rest if needed, ask me.
Memory Map from GRUB IN QEMU:
start: 0 size: 652288 type 1
start: 652288 size: 3072 type 2
start: 817392 size: 8192 type 2
start: 901120 size: 147456 type 2
start: 1048576 size: 107255808 type 1
start: 1073606656 size: 135168 type 2
rest if needed, ask me.
Paging Code:
// The size of physical memory.
u32int mem_end_page=(0xFFFFFFFF-(4096*1024));
nframes = mem_end_page / 0x1000;
frames = (u32int*)kmalloc(INDEX_FROM_BIT(nframes));
memset(frames, 0, INDEX_FROM_BIT(nframes));
u32int phys;
kernel_directory = (page_directory_t*)kmalloc_a(sizeof(page_directory_t));
memset(kernel_directory, 0, sizeof(page_directory_t));
kernel_directory->physicalAddr = (u32int)kernel_directory->tablesPhysical;
for(uint32_t i=0;i<(1024*maxmem);i+=4096) //page virtually every available free memory. maxmem is Memory size in KB from GRUB
alloc_frame(get_page(i,1,kernel_directory),1,1);
int i = 0;
switch_page_directory(kernel_directory);
current_directory = clone_directory(kernel_directory);
switch_page_directory(current_directory);