Page 1 of 1

Memory Management for Dummies??

Posted: Tue Nov 06, 2007 8:16 am
by LordMage
Okay I have started to read the memory management information on OSdever, and on the wiki here, but I really just need to see a well documented implementation of it in action. I don't need something optimized just something that will show me how it works. I will do optimization and possibly even completely design my own system but first I need to see an example of how everything works. Does anybody know of a good example that I could look at?

Posted: Tue Nov 06, 2007 8:33 am
by Craze Frog
Allocation of frames (physical memory) or a malloc implementation (arbitarily-sized continous memory areas)?

Posted: Tue Nov 06, 2007 8:44 am
by LordMage
Well, I don't have any memory management at this point, my kerenl boots loads GDT IDT isrs and irqs 1 and 2. It prints some stuff on the screen and accepts input with a couple semi-console like features. I would assume that I have to manage the physical memory first. I am not really sure though. I learn better through doing then I do from reading.

edit: I would request a high-level language example. I don't think I know ASM well enough to extract what I need from it. but I can figure out any highlevel language even if I don't know it yet.

Posted: Wed Nov 07, 2007 5:27 am
by JamesM

Posted: Sat Nov 10, 2007 2:46 pm
by LordMage
I was looking at your paging tutorial, you don't define several variables.

kernel_directory
current_directory
placement_address
tables_idx

why are they not defined. you also don't say what files the functions and everything are being placed in. I can't download your source code since I am at work but I would really like to get this running so I can see it working and then I will be able to personalize it and learn from it.

Posted: Sat Nov 10, 2007 5:01 pm
by JamesM
Hi!

Kernel_directory and current_directory are just globals of type pagedirectory_t. They're defined at the top of the paging.c file. I didn't paste all the globals/#includes etc in - thought people could work it out themselves! I might add them now though...

placement_address is similar: in my code it is defined as

Code: Select all

u32int placement_address = &end;
Where end is a constant defined in the linker script. I must have forgotten to add that in - sorry!

tables_idx does not exist: I can't find a reference to that anywhere on the page. The nearest I found was table_idx:

Code: Select all

page_t *get_page(u32int address, int make, page_directory_t *dir)
{
   // Turn the address into an index.
   address /= 0x1000;
   // Find the page table containing this address.
   u32int table_idx = address / 1024;
   if (dir->tables[table_idx]) // If this table is already assigned
   {
       return &dir->tables[table_idx]->pages[address%1024];
   }
   else if(make)
   {
       u32int tmp;
       dir->tables[table_idx] = (page_table_t*)kmalloc_ap(sizeof(page_table_t), &tmp);
       dir->tablesPhysical[table_idx] = tmp | 0x7; // PRESENT, RW, US.
       return &dir->tables[table_idx]->pages[address%1024];
   }
   else
   {
       return 0;
   }
}
As you can see table_idx there is defined as a local.

Cheers for looking at it, seems there are some omissions on my part! If you'd been able to get the code hopefully it would have all been explained!

Posted: Sat Nov 10, 2007 7:28 pm
by LordMage
Okay. I asked this in the general programming forum but I don't know how long it will be until someone answers the question so I will also ask it here. I am getting an unresolved external error for my memset function but it isn't external and is not declared so anywhere. any ideas?

Posted: Sun Nov 11, 2007 3:50 am
by JamesM
have you compiled and linked against the file in which it is declared?

do an 'nm' of the object file it is declared in and look to see how it is defined. a 'T' means all is good, a 't' means it has static linkage: remove the 'static' keyword before the memset declaration.