multi tasking: run executables

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

multi tasking: run executables

Post by i586coder »

Have a nice day guy's:

today i have very interested question,most of us will faced :idea:

HOW to run 2,3,...,n executables @ the same time
the code bellow is a part of my UNEXT/os kernel

Code: Select all

int EXE_returnedValue;//var. to save returned offset

byte exec(char* fileName,void* _segment,char* parameter){
     byte fileRetValue;
     fileRetValue=_fopen(fileName,r); //open file
     switch(fileRetValue){
      case 0: return DIR_NOT_FOUND;
      case 1: return FILE_NOT_FOUND;
     }
      _fcopy2segment(_segment); //copy content of file to buffer
     _fclose(); //close file

     _saveTCRegs(); //save turbo C registres and flags (AX,..)

     EXE_returnedValue=(int)return_point;//get returned offset

     _decompressMZ();//get CS,DS,SS from EXE
     _setupMZ(); //setup new Regs,Flags for EXE
     asm{ push MZ_segment //point to jump
          push MZ_offset  //CS:IP
          retf            //jump to our EXE 
     }

asm return_point label byte //when EXE finish will go here throu interrupt
 return EXE_DONE;
}

void interrupt killEXE(){//this method must call from EXE to KILL process
    _loadTCRegs();//return to previous TC registers
    memset(_segment,NULL,_fSize());//clear buffer
     asm{mov ax,cs
         push ax
         push EXE_returnedValue
         retf
     }
}

main(){
  THREAD _thread;     _thread.add(exec("system/Fileviw.exe",0x20000000L,"doc/test.txt"));
_thread.add(exec("system/bscript.exe",0x30000000L,"script/intro.bs"));
_thread.schedule();
}
the problem is:
when i tried this code in my multi thread, each EXE will start from begining #-o

need your opinions :!: :!: :!:
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
Kieran
Member
Member
Posts: 54
Joined: Mon Apr 11, 2005 11:00 pm

Re: multi tasking: run executables

Post by Kieran »

Well, do you mean that each time your sceduler switches to the process containing the loaded program the program starts again from the beginning?

If so, check that you are saving EIP correctly.
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: multi tasking: run executables

Post by i586coder »

ok,
the function:
_saveTCRegs();
save all registers even DS,CS,IP(code offset),...

i think
exec(char*,void*,char*);
need some fix,

anyway, if you have another method to run .EXE better than my method,please let my know [-o<


ThankX
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: multi tasking: run executables

Post by ru2aqare »

AhmadTayseerDajani wrote:ok,
the function:
_saveTCRegs();
save all registers even DS,CS,IP(code offset),...

i think
exec(char*,void*,char*);
need some fix,

anyway, if you have another method to run .EXE better than my method,please let my know [-o<


ThankX
Saves the registers where? If it uses globals, it probably has reentrancy issues. And execution of image files (be it EXE or another format) is supposed to start at the entry point designated by its header, isn't it? Sorry, but I don't understand what the problem is, really.
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: multi tasking: run executables

Post by i586coder »

Saves the registers where? If it uses globals, it probably has reentrancy issues. And execution of image files (be it EXE or another format) is supposed to start at the entry point designated by its header, isn't it? Sorry, but I don't understand what the problem is, really.
yes, regitsters saved in globals

Code: Select all

 void saveTCRegs(){
  _ax=_AX;
  :
  : 
  _cflags=_FLAGS;
 }
execution image is 16 bit MZ executable :shock:
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: multi tasking: run executables

Post by ru2aqare »

AhmadTayseerDajani wrote:yes, regitsters saved in globals

Code: Select all

 void saveTCRegs(){
  _ax=_AX;
  :
  : 
  _cflags=_FLAGS;
 }
There is two problem with storing the processor context in global variables. First, if two threads concurrently try to save the context, either thead A overwrites thread B's context, or they write at the exact same time, resulting in a context X that is neither A nor B. I assume you use threads from this code:

Code: Select all

  THREAD _thread;     _thread.add(exec("system/Fileviw.exe",0x20000000L,"doc/test.txt"));
_thread.add(exec("system/bscript.exe",0x30000000L,"script/intro.bs"));
_thread.schedule();
Second, if you load an executable A that in turn loads another executable B, then the context that was saved before A was executed is overwritten by the context saved before B is executed.
AhmadTayseerDajani wrote:execution image is 16 bit MZ executable :shock:
Yeah, I got that from the Turbo C part.
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: multi tasking: run executables

Post by i586coder »

ru2aqare wrote: There is two problem with storing the processor context in global variables. First, if two threads concurrently try to save the context, either thead A overwrites thread B's context, or they write at the exact same time, resulting in a context X that is neither A nor B.

Second, if you load an executable A that in turn loads another executable B, then the context that was saved before A was executed is overwritten by the context saved before B is executed.
Oh my guess, i forgot that,...,thank you ru2aqare for your help,& I am gona fix up my code by adding struct to save each EXE registers individually

ThAnKX AgAiN =D>
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
Post Reply