Memory Handling
Posted: Sat Mar 10, 2007 1:07 pm
I'm working on a small OS mostly just to learn how some things work at the lowest levels of a computer, and need some tips on memory handling.
My small OS (currently just a kernel booted by GRUB & a file loaded as a module), doesn't work like most others in that applications (and drivers) aren't native code but are written in a custom byte code which is interpreted (plan is to eventually JIT it, but for now interpreting will do). This byte code gives no access to pointers, so I don't think I need to use paging or segmentation (correct me if I'm wrong) as there's no way for apps to access random memory locations anyway. So, when there's no need to worry about paging or segmentation, whats the best way to handle memory?
Below is my current memory code:
Very simple, no freeing yet, and it doesn't detect when its out of memory. I know I can handle this as a linked list that tracks allocated memory, but how do I know what parts of memory it is OK to use? The kernel has to be in there somewhere, how do I know where GRUB loaded it to avoid overwriting something vital? Also, there's video memory at 0xB8000, is this always a given size so I avoid using that memory? Are there other areas of memory like the video memory that I shouldn't use?
Sorry if I don't understand this at all and sound completely stupid, I just don't really understand how to handle the memory.
My small OS (currently just a kernel booted by GRUB & a file loaded as a module), doesn't work like most others in that applications (and drivers) aren't native code but are written in a custom byte code which is interpreted (plan is to eventually JIT it, but for now interpreting will do). This byte code gives no access to pointers, so I don't think I need to use paging or segmentation (correct me if I'm wrong) as there's no way for apps to access random memory locations anyway. So, when there's no need to worry about paging or segmentation, whats the best way to handle memory?
Below is my current memory code:
Code: Select all
pointer memBase = 0x000001;
ulong memAllocated = 0;
pointer memAlloc(ulong size)
{
pointer mem = memBase + memAllocated;
memAllocated += size;
return mem;
}
void memFree(pointer mem)
{
}
pointer memReAlloc(pointer mem, ulong size)
{
memFree(mem);
return memAlloc(size);
}
Sorry if I don't understand this at all and sound completely stupid, I just don't really understand how to handle the memory.