home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / config / i386 / runprocess.s < prev    next >
Encoding:
Text File  |  1997-01-30  |  2.7 KB  |  136 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: runprocess.s,v 1.12 1997/01/30 09:56:03 digulla Exp $
  4.  
  5.     Desc: DOS utility function RunProcess
  6.     Lang: english
  7.  
  8.  LONG RunProcess ( struct Process         * proc,
  9.            struct StackSwapStruct * sss,
  10.            STRPTR            argptr,
  11.            ULONG            argsize,
  12.            LONG_FUNC            entry,
  13.            struct DosLibrary      * DOSBase )
  14. */
  15.  
  16.     #include "machine.i"
  17.  
  18. /*
  19.     This is how the stack looks when this function is called:
  20.  
  21.     20    DOSBase(4)
  22.     16    entry(4)
  23.     12    argsize(4)
  24.      8    argptr(4)
  25.      4    sss(4)
  26.      0    proc(4)
  27.     Return Address(4)
  28.  
  29.  
  30. /*      .set FirstArg, 4+(4*4)   / * Return-Adress + 4 Registers * /
  31.     .set proc,     FirstArg
  32.     .set sss,      proc+4
  33.     .set argptr,   sss+4
  34.     .set argsize,  argptr+4
  35.     .set entry,    argsize+4 */
  36.  
  37. #define FirstArg    4+(4*4)     /* Return-Adress + 4 Registers */
  38. #define proc        FirstArg+0
  39. #define sss        FirstArg+4
  40. #define argptr        FirstArg+8
  41. #define argsize     FirstArg+12
  42. #define entry        FirstArg+16
  43. #define DOSBase     FirstArg+20
  44.  
  45.     .text
  46.     .balign 16
  47.     .globl    AROS_SLIB_ENTRY(RunProcess,Dos)
  48.     .type    AROS_SLIB_ENTRY(RunProcess,Dos),@function
  49.  
  50. AROS_SLIB_ENTRY(RunProcess,Dos):
  51.     /* Save some registers. This changes the offset of the arguments by 4*4 */
  52.     pushl %edi
  53.     pushl %esi
  54.     pushl %ebx
  55.     pushl %ebp
  56.  
  57.     /* Fetch the arguments off the stack */
  58.     movl sss(%esp),%ebx
  59.     movl entry(%esp),%edi
  60.  
  61.     /* Move upper bounds of the new stack into eax */
  62.     movl stk_Upper(%ebx),%eax
  63.  
  64.     /*
  65.         Push arguments for entry onto the stack of the new process.
  66.         This new stack looks like this when the new process is called:
  67.  
  68.         sss
  69.         SysBase
  70.         argsize
  71.         argptr
  72.     */
  73.     movl argptr(%esp),%edx
  74.     movl %edx,-16(%eax)
  75.     movl argsize(%esp),%edx
  76.     movl %edx,-12(%eax)
  77.  
  78.     /* Push sss onto the new stack */
  79.     movl %ebx,-4(%eax)
  80.  
  81.     /* Get SysBase */
  82.     movl DOSBase(%esp),%edx
  83.     movl dl_SysBase(%edx),%edx
  84.  
  85.     /* Push SysBase on the new stack */
  86.     movl %edx,-8(%eax)
  87.  
  88.     /* Store switch point in sss */
  89.     addl $-16,%eax
  90.     movl %eax,stk_Pointer(%ebx)
  91.  
  92.     /* Push SysBase and sss on our stack */
  93.     pushl %edx /* SysBase */
  94.     pushl %ebx /* sss */
  95.  
  96.     /* Switch stacks */
  97.     leal StackSwap(%edx),%edx
  98.     call *%edx
  99.  
  100.     /* Clean new stack from call to StackSwap */
  101.     addl $8,%esp
  102.  
  103.     /* Call the specified routine */
  104.     call *%edi
  105.  
  106.     /* Clean (new) stack partially, leaving SysBase behind */
  107.     addl $8,%esp
  108.  
  109.     /* Store the result of the routine in esi */
  110.     movl %eax,%esi
  111.  
  112.     /* Swap the upper two values on the new stack */
  113.     popl %edx /* SysBase */
  114.     popl %ebx /* sss */
  115.     pushl %edx /* SysBase */
  116.     pushl %ebx /* sss */
  117.  
  118.     /* Switch stacks back */
  119.     leal StackSwap(%edx),%edx
  120.     call *%edx
  121.  
  122.     /* Clean old stack */
  123.     addl $8,%esp
  124.  
  125.     /* Put the result in eax where our caller expects it */
  126.     movl %esi,%eax
  127.  
  128.     /* Restore registers */
  129.     popl %ebp
  130.     popl %ebx
  131.     popl %esi
  132.     popl %edi
  133.  
  134.     /* Done */
  135.     ret
  136.