Memory Management for Dummies??

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
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Memory Management for Dummies??

Post 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?
Getting back in the game.
Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post by Craze Frog »

Allocation of frames (physical memory) or a malloc implementation (arbitarily-sized continous memory areas)?
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post 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.
Getting back in the game.
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post 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.
Getting back in the game.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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!
LordMage
Member
Member
Posts: 115
Joined: Sat Sep 22, 2007 7:26 am
Contact:

Post 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?
Getting back in the game.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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