LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-17-2005, 08:02 PM   #1
NCC-1701&NCC-1701-D
Member
 
Registered: May 2005
Distribution: Debian Woody,Knoppix
Posts: 88

Rep: Reputation: 16
Question 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.


Thank you A LOT!
 
Old 08-17-2005, 11:06 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,143

Rep: Reputation: 322Reputation: 322Reputation: 322Reputation: 322
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C program code to execute linux-command supermichou_fr Linux - Software 4 08-01-2012 09:25 AM
execute command from c code alaios Programming 3 06-06-2005 06:26 AM
how to execute shell script with c code? khucinx Programming 3 05-04-2004 03:54 PM
Getting PHP code to execute in phpBB templates Travis86 Linux - Software 3 12-22-2003 08:53 PM
How do I have X-apps automatically execute on startup of the X-server? jtX Slackware 13 08-07-2003 07:23 PM


All times are GMT -5. The time now is 02:40 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration