Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Okay...And you should not be surprised if it doesn't work when you un-nest it from all that virtualization...
Virtual machines are pretty good, but they're not perfect...
But how do I allocate memory? I mean there are various tutorials on the net on how the process should be done, and the dangers of making one(which is kind of why I'm using a Virtual Machine), but not one line of code. What function/command in C allocates memory? Or do I need to use assembly's mov command?
The only C function that allocates memory is malloc() and it is dependent upon the underlying operating system.
If you are working on an OS kernel you need to write a complete memory manager, that is, the underlying stuff behind malloc()...
Usually memory is allocated by placing frames around blocks of memory... they form a sort of linked list (loose analogy, but close enough for illustration purposes) of allocated blocks, each pointing to the next. You start at the bottom (or top) of memory and allocate 100 bytes, so you put a frame there, the frame contains a pointer to the next block and the size of the current block and you return a pointer to the first byte of the block to the program... to allocate another block you simply add a nother frame...
Then to deallocate a block you fix the pointers and remove the frame...Code:* *allocated block * size of this block pointer to next block =================== * * allocated block * Size of this block pointer to next block ====================
You know where each block begins and ends, so as you add and remove blocks you can "manage" the memory by filling gaps.
Of course it's a little bit more complicated than this --well, more than a little actually-- but that's the jist of it... If you understand linked lists you understand memory management.
Where exactly are you at with regard to this OS development? Is your boatloader done or are you using something like GRUB? When you say, "I made my own printf function", what do you mean by that? I hope you understand that when creating your own OS you leave behind the comfort of the standard libraries when it comes to input/output, memory management, disk access, ect. All these libraries implement there functions by OS specific API calls that conform to the standard; however they are specific to the OS they were made for.
The reason I am saying this is because of your question asking for what "C function to allocate memory". There is no standard C function available to you because you are creating your own OS. You have left the comfort zone of the standard libraries and you are on your own in the woods so to say.
Keep this in mind when you decide to come back here and ask for what C function to make files or access the harddrive. There are none for you. You are going to need to make them yourself.
That being said take a look at these tutorials. This should get you going with your project. I would suggest you start at the top and read your way through.
I've already checked out the link before posting here, but I've already built my kernel structure specifically to avoid the amount of extra assembly he's using. Additionally, with every article he's specified a multiboot header for his own bootloader, while I'm using GRUB. By printf command, I mean a basic function that prints to 0Xb80000(the video display). Both numbers and strings can be printed. Any other suggestions?
Because they assume that if you think you are capable of writing your own kernel you shouldn't need to be hand held by copying finished code.
The OSDev page you yourself linked mentions two different approaches: Bitmaps or headers. The same site also has explanations of what those two words mean.
First of all I didn't 'myself' link this page AndrewHunter did. That being said, I found help here I understand how the code works, but I can't identify the line of code which actually assigns the memory. Any help?
It's all assigning memory... he's doing what I showed you in message 35 of the thread... writing frames into memory.
One problem I had with the script here:i386/boot/cdboot/malloc.c Source is that I have no idea what &end is. It hasn't been declared in this piece of code, so I assume its in boot.h. How do I define end?
end is probably the end of the allocated block of memory; but as you say, it is not defined here (nor is it changed here!) so if you want to know what it is you'll have to find it elsewhere.
Perhaps, but we've all started projects that we never finished because we did not have the resources to do so (whether that is time or expertise or whatever).
That doesn't make the attempt pointless. The OP will gain experience whether s/he succeeds or not. For example, "Learning to quit while you are ahead" appropriately is something you learn thru experience, but beyond that there's lots worthwhile in studying how an OS kernel works, and doing it hands on might be a good idea. I'm jealous
Last edited by MK27; 08-14-2011 at 11:59 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge