Creating a Physical Memory Manager

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

Creating a Physical Memory Manager

Post 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?
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Creating a Physical Memory Manager

Post 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
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
TylerH
Member
Member
Posts: 285
Joined: Tue Apr 13, 2010 8:00 pm
Contact:

Re: Creating a Physical Memory Manager

Post 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]
HitmanYesman
Member
Member
Posts: 47
Joined: Fri Apr 23, 2010 8:27 am

Re: Creating a Physical Memory Manager

Post 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.
Post Reply