LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Code for an os memory manager to execute apps (https://www.linuxquestions.org/questions/programming-9/code-for-an-os-memory-manager-to-execute-apps-354361/)

NCC-1701&NCC-1701-D 08-17-2005 07:02 PM

Code for an os memory manager to execute apps
 
Hi all,

what code could let a memory manager to execute a binary file. I know how to allocate memory, but I don't know how to make the cpu execute the file...

Code:

//I've already allocated memory enough for the process,now I want to tell
//  the cpu to execute my binary.
int run(*pid){
int returncode=1//if 0,then exit
while (TRUE){
/*Because I don't know what to do, i tried this (it's ridicoulous, I know ...*/
int n=0;
n++
n=0;
}

Please help me... I really need some suggestions of code for executing the binaries.
Also,i know that I have to use int 12 in assembly to get my memory size in kb. How can I put this assembly code into my C++ code. Finally, how could I count the size (in MB) of the running processes and those who are going to be forked
[CODE]
bool fork(/*...*/)//using this function I initiate new procs.

If you could answer me these questions, you would REALLY REALLY REALLY HELP ME.
:newbie:

Thank you A LOT!

btmiller 08-17-2005 10:06 PM

Generally, you load the process into the memory you have allocated from disk based on the particular parameters of the type of binary (exe, COFF, a.out, etc.), and then set the prpcessor registers for the process to point to the entrance of the text segment, and finally invoke your scheduler to run the process. The implementation details for how exactly you do that depend on how you've implemented your OS.

As for your int 12, you can use gcc's inline assembly or have the assembly routine in a separate source file that is linked with your C++ code using the correct calling conventions. Inline assembly may be the easiest -- Google for it and you should hit some gold. In general, C++ does some weird things and requires a lot of library support, so most OS development experts recommend sticking with striahgt C for an OS kernel, at least until you have more experience. Hopefully, though, it will work for you in this case.


All times are GMT -5. The time now is 01:33 AM.