My OS
I always wanted to make an OS, ever since i first read a mini article on the topic back at HTS 3 years ago.
I finally started 3 days ago. Its remarkably easy once you get started, you just gotta be extremely patient, play around with ALOT of very low level c, and read alot of documentation for VGA drivers and other such boring things.
I was thinking of posting bits of the source, or the iso's or whatever once theres something worth showing, but for now i'd just like to ask a fairly quick question (and i felt like showing off slightly, cos im fucking proud of myself lol).
Does anybody have any clue how i could implement my own version of malloc() without using any system calls except:
strcat
strcpy
strcmp
strlen
memset
memcpy
memsetw
inportb
outportb
These are the ones i've got to work so far. Aswell as the worlds crappiest print function, and a pimped, colour, ascii art logo. Theres also CPU and floppy detection cos i worked out how to do that using the importb() asm ported function.
You're going to have to manage start managing your own heap for allocation calls :)
The simplest form would be:
// 100k heap
char myHeap[100 * 1024];
char *nextBlock = &myHeap[0];
void* malloc( size_t size )
{
void *ptr;
// Check to see if there's anything left
if( (nextBlock + size) > (myHeap + (100 * 1024)) )
{
return NULL;
}
ptr = (void *)nextBlock;
nextBlock += size;
return ptr;
}
Going further than that you can use a linked list to keep track of how much memory is being used and the blocks next to it (but as the first, say, 64 bytes of each allocation) and work your own algorithm up to handle freeing & re-allocating memory etc.
I think the Thinking in C++ 2nd edition book covers mini object allocators which was an interesting read :)