home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 7.ddi / EXAMPLES / LOADER / LOAD2.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-10-19  |  2.6 KB  |  96 lines

  1. ;************************************************************************/
  2. ;*    Copyright (C) 1986-1990 Phar Lap Software, Inc.            */
  3. ;*    Unpublished - rights reserved under the Copyright Laws of the    */
  4. ;*    United States.  Use, duplication, or disclosure by the         */
  5. ;*    Government is subject to restrictions as set forth in         */
  6. ;*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  7. ;*    Computer Software clause at 252.227-7013.            */
  8. ;*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  9. ;************************************************************************/
  10.  
  11.     include dosx.ah
  12.  
  13.            assume cs:code
  14. code    segment dword 'CODE'
  15. comment ~*********************************************************************
  16.  
  17. call_child(ldblkp)
  18. LDEXP_BLK *ldblkp;
  19.  
  20. Description:
  21.     Does a FAR call to the child program, returns when it returns.
  22.     All regs except EAX are preserved;  EAX contains the value returned
  23.     by the child.
  24.  
  25.     NOTE this routine saves context on the child's stack.  If the child
  26.     program does not return with the same stack you will have to
  27.     modify this code!
  28.  
  29. Calling arguments:
  30.     ldblkp        ptr to param block ret'd by load EXP file system call
  31.  
  32. Returned values:
  33.     Value returned by child program
  34. ~*****************************************************************************
  35.     public    call_child
  36. call_child proc    near
  37. ;
  38. ; Stack frame
  39. ;
  40. #LDBLKP    equ    (dword ptr 8[ebp])
  41.  
  42.     push    ebp            ; Set up stack frame
  43.     mov    ebp,esp                ;
  44.     push    ebx            ; save regs
  45.     push    ecx                ;
  46.     push    edx                ;
  47.     push    esi                ;
  48.     push    edi                ;
  49.     push    ds                ;
  50.     push    es                ;
  51.     push    fs                ;
  52.     push    gs                ;
  53.  
  54.     mov    ebx,#LDBLKP        ; get ptr to regs struct
  55.     mov    cx,ss            ; save current stack
  56.     mov    edx,esp                ;
  57.     lss    esp,pword ptr [ebx].LX_ESP ; set up child's stack
  58.     push    ecx            ; save our old stack on child's stack
  59.     push    edx                ;
  60.     push    cs            ; FAR return point below
  61.     lea    eax,#ret            ;
  62.     push    eax                ;
  63.     pushfd                ; set up entry point in child
  64.     movzx    eax,[ebx].LX_CS            ;
  65.     push    eax                ;
  66.     push    [ebx].LX_EIP            ;
  67.     mov    es,[ebx].LX_ES        ; init rest of child's regs
  68.     mov    fs,[ebx].LX_FS            ;
  69.     mov    gs,[ebx].LX_GS            ;
  70.     mov    ds,[ebx].LX_DS            ;
  71.     xor    eax,eax                ;
  72.     xor    ebx,ebx                ;
  73.     xor    ecx,ecx                ;
  74.     xor    edx,edx                ;
  75.     xor    esi,esi                ;
  76.     xor    edi,edi                ;
  77.     xor    ebp,ebp                ;
  78.     iretd                ; transfer control to child
  79. #ret:
  80.     lss    esp,pword ptr [esp]    ; restore our original stack
  81.  
  82.     pop    gs            ; restore regs & return to caller
  83.     pop    fs                ;
  84.     pop    es                ;
  85.     pop    ds                ;
  86.     pop    edi                ;
  87.     pop    esi                ;
  88.     pop    edx                ;
  89.     pop    ecx                ;
  90.     pop    ebx                ;
  91.     pop    ebp                ;
  92.     ret                    ;
  93. call_child endp
  94. code    ends
  95. end
  96.