Page 1 of 1

Creating a Physical Memory Manager

Posted: Sun May 09, 2010 11:56 am
by HitmanYesman
I'm trying to set up a real 'simple' PMM using the memory map from GRUB. This is what I have so far:

Code: Select all

if ((*((uint32 *)mbd + 0) >> 5) & 1) 
{
	if (*((uint32 *)mbd + 44) != 0)
	{
		mem_length = (*(uint32 *)mbd + 44);
		puts(mem_length);
	}
}
I'm trying to print out the length of memory, but either nothing prints out or sometimes I get can get some weird ASCII characters. Bochs doesn't seem to have any errors. Am I doing something wrong?

Re: Creating a Physical Memory Manager

Posted: Sun May 09, 2010 12:19 pm
by gravaera
Hi,

Why use absolute offsets? The compiler can do that for you if you give it the appropriate size offsets in a structure definition. Try looking up the Multiboot Header include file in the Multiboot Specification. Use it to strongly type your offsets and let the compiler do the work for you.

Also, remember that if you're using paging, a paged kernel (on x86) must ensure it accesses all memory addresses through virtual addresses. You should map some page to the regions in low memory where GRUB places the multiboot structures. Or if you identity map the 1st MB of RAM, it would be as easy as calculating offsets.

--All the best,
gravaera

Re: Creating a Physical Memory Manager

Posted: Sun May 09, 2010 12:24 pm
by TylerH
Have you implemented "puts" and, if you have, does it require ASCII values or does it convert int to string automatically?

Have an example of those "weird ASCII characters"?

[edit]
What does printing the amount of memory have to do with managing it? :P
[/edit]

Re: Creating a Physical Memory Manager

Posted: Sun May 09, 2010 1:35 pm
by HitmanYesman
Thanks Gravaera.

I figured it out:

Code: Select all

struct mb_info *mb_info;
mb_info = (mb_info *) mbd;

uint32 mem_length = mb_info->mmap_length;
puts(mem_length);
Oh and puts changes int to string.