My grub-probed free memory address is off. Why?

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
netrom
Posts: 4
Joined: Thu Jan 21, 2010 10:50 am

My grub-probed free memory address is off. Why?

Post by netrom »

Hello fellow developers.

I've recently started programming my own OS in C/assembler. The Bare Bones article pretty much set me up.

In my current phase I'm trying to get the memory management up and running. So I access the provided multiboot_memory_map structure (from multiboot.h) for those whose 'type' is 1, and thereby not reserved.

My actual problem arises when I try to set up my virtual memory (just using a simple linked list at first). The address provided from the 'addr' field is somewhat off.. In my perception. If I use it as it is then I overwrite my running kernel code at some point. I have interpreted 'addr' as the starting address of the free memory available, which then spans the amount of bytes specified in the 'len' field.

As of now I'm using a hack (multiplying 'addr' by 4, haha I know) but I would like to know why the offset is off?

Thank you very much in advance.
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: My grub-probed free memory address is off. Why?

Post by gravaera »

Hi:

GRUB doesn't map your kernel's executable image as reserved in the memory map. It's just supposed to tell you about which ranges of RAM are usable for the kernel. The kernel itself should handle protecting its physical frames in RAM.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
netrom
Posts: 4
Joined: Thu Jan 21, 2010 10:50 am

Re: My grub-probed free memory address is off. Why?

Post by netrom »

Of course, that makes sense.

What is the best way of deducing the size of the running footprint of the kernel? I mean, before anything has been allocated and so on.
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: My grub-probed free memory address is off. Why?

Post by Creature »

netrom wrote:Of course, that makes sense.

What is the best way of deducing the size of the running footprint of the kernel? I mean, before anything has been allocated and so on.
If you're referring to getting the size of your executable, I suppose what most of us here do is use the linker script to determine the size. You put a linker script entry at the end (and possibly at the start) and subtract them from each other.

For example:

Code: Select all

SECTIONS
{
   . = 0x100000;

   /* ... */

   KernelEnd = .;
}
Then the size of the kernel executable would be KernelEnd - 0x100000.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
netrom
Posts: 4
Joined: Thu Jan 21, 2010 10:50 am

Re: My grub-probed free memory address is off. Why?

Post by netrom »

Creature wrote:[...]You put a linker script entry at the end (and possibly at the start) and subtract them from each other.

Then the size of the kernel executable would be KernelEnd - 0x100000.
That sounds like the way to go, but how to I access 'KernelEnd' then? I mean, how I read the value from C (or assembler)?
User avatar
-m32
Member
Member
Posts: 120
Joined: Thu Feb 21, 2008 5:59 am
Location: Ottawa, Canada

Re: My grub-probed free memory address is off. Why?

Post by -m32 »

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: My grub-probed free memory address is off. Why?

Post by gravaera »

EDIT: No need. Good luck :)
Last edited by gravaera on Thu Jan 21, 2010 5:51 pm, edited 1 time in total.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
netrom
Posts: 4
Joined: Thu Jan 21, 2010 10:50 am

Re: My grub-probed free memory address is off. Why?

Post by netrom »

I'm sorry.. That was kinda embarrassing as I have used the wiki quite a lot. #-o
Thanks again anyways.
Post Reply