Memory Management: Will this work?

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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Memory Management: Will this work?

Post by pcmattman »

I'm about to re-implement my memory manager (ATM it's just using a running integer that has the top of the heap in it).

My kernel is not going to use paging. So it should be simple to implement a memory manager, I think.

I'm thinking of implementing the same style of memory manager as shown in http://www.koders.com/c/fid2F3F21877FD9 ... C4A26.aspx

Is this a good system, or is there a better, more efficient way of doing this?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

OK, I implemented it, keeping the copyright info as well. I'm happy to see it works perfectly, and (unlike my old memory manager) has no bugs!

Previously, the allocated memory ran all over the place, into other variable's memory, and it was a total mess.

Now I can actually do stuff with my kernel :D
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post by XCHG »

I'm glad you have your memory manager working but I thought maybe this will help you if you want to code your own memory manager. I am coding in NASM and thus I have to keep track of every memory location that I use. For now I am using MEGABYTE(0) to MEGABYTE(16) for my kernel and MEGABYTE(16) to MEGABYTE(24) for my physical memory manager's free space and I have defined constant values like this:

Code: Select all

; ——————————————————————————————————————————————————
  MEM_MAP_KERNEL_DOMAINSTART          EQU       MEGABYTE(0)
  MEM_MAP_KERNEL_DOMAINLENGTH         EQU       MEGABYTE(8)
  MEM_MAP_KERNEL_DOMAINEND            EQU       MEM_MAP_KERNEL_DOMAINSTART + MEM_MAP_KERNEL_DOMAINLENGTH - 1
  MEM_MAP_KERNEL_ENTRY                EQU       MEGABYTE(1)
  ; ——————————————————————————————————————————————————
  MEM_MAP_PDES_DOMAINSTART            EQU       MEM_MAP_KERNEL_DOMAINEND + 1
  MEM_MAP_PDES_DOMAINLENGTH           EQU       KILOBYTE(4)
  MEM_MAP_PDES_DOMAINEND              EQU       MEM_MAP_PDES_DOMAINSTART + MEM_MAP_PDES_DOMAINLENGTH - 1
  MEM_MAP_PDES_ENTRY                  EQU       MEM_MAP_PDES_DOMAINSTART
  ; ——————————————————————————————————————————————————
  MEM_MAP_PTES_DOMAINSTART            EQU       MEM_MAP_PDES_DOMAINEND + 1
  MEM_MAP_PTES_DOMAINLENGTH           EQU       MEGABYTE(4)
  MEM_MAP_PTES_DOMAINEND              EQU       MEM_MAP_PTES_DOMAINSTART + MEM_MAP_PTES_DOMAINLENGTH - 1
  MEM_MAP_PTES_ENTRY                  EQU       MEM_MAP_PTES_DOMAINSTART
  ; ——————————————————————————————————————————————————
And I always refer to these instead of using variable memory locations and so if I need to change the location of these values I will just change the way they are declared.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
Post Reply