Indentation fix, cleanup.
[AROS.git] / arch / .unmaintained / m68k-emul / runprocess.s
blobb684b7a7c4f0ee7058d8cc143b89442f7a875819
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Run a process ( invoked by dos/Runcommand() )
6 Lang: english
8 LONG RunProcess ( struct Process * proc,
9 struct StackSwapStruct * sss,
10 STRPTR argptr,
11 ULONG argsize,
12 LONG_FUNC entry,
13 struct DosLibrary * DOSBase )
16 #include "machine.i"
19 This is how the stack looks when this function is called:
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)
30 /* .set FirstArg, 4+(2*4) / * Return-address + 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 */
37 #if !UseRegisterArgs
38 #define FirstArg 4+(2*4) /* Return-Address + 2 Registers */
39 #else
40 #define FirstArg 4+(4*4) /* Return-Address + 4 Registers */
41 #endif
42 #define proc FirstArg+0
43 #define sss FirstArg+4
44 #define argptr FirstArg+8
45 #define argsize FirstArg+12
46 #define entry FirstArg+16
47 #define DOSBase FirstArg+20
49 .text
50 .balign 16
51 .globl AROS_SLIB_ENTRY(RunProcess,Dos)
52 .type AROS_SLIB_ENTRY(RunProcess,Dos),@function
53 AROS_SLIB_ENTRY(RunProcess,Dos):
54 #if !UseRegisterArgs
55 movem.l %a5-%a6,-(%sp) /* Save some registers */
56 #else
57 movem.l %d2/%a2/%a5-%a6,-(%sp) /* Save some registers */
58 #endif
60 move.l sss(%sp),%a0 /* Fetch the arguments off the stack */
61 move.l entry(%sp),%a5 /* " " " " " " */
63 /* Move upper bounds of the new stack into a1 */
64 move.l stk_Upper(%a0),%a1
66 #if !UseRegisterArgs
68 Push arguments for entry onto the stack of the new process.
69 This new stack looks like this when the new process is called:
71 sss
72 SysBase
73 argsize
74 argptr
76 move.l argptr(%sp),-16(%a1)
77 move.l argsize(%sp),-12(%a1)
79 move.l %a0,-4(%a1) /* Push sss onto the new stack */
80 #else
82 We need to save both argptr and argsize from the stack.
84 move.l argptr(%sp),%a2
85 move.l argsize(%sp),%d2
87 move.l %a0,-(%a1) /* Push sss onto the new stack */
88 #endif
89 move.l DOSBase(%sp),%a6 /* Get SysBase */
90 move.l dl_SysBase(%a6),%a6 /* " " */
91 #if !UseRegisterArgs
92 move.l %a6,-8(%a1) /* Push SysBase onto the new stack */
93 add.l #-16,%a1
94 #else
95 move.l %a6,-(%a1) /* Push SysBase onto the new stack */
96 #endif
97 move.l %a1,stk_Pointer(%a0) /* Store Switch Point in sss */
99 #if !UseRegisterArgs
100 /* Push SysBase and sss on our stack */
101 move.l %a6,-(%sp)
102 move.l %a0,-(%sp)
103 #endif
105 jsr StackSwap(%a6) /* Switch stacks (a0=sss) */
107 #if !UseRegisterArgs
108 /* Clean new stack from call to StackSwap */
109 addq.w #8,%sp
110 #else
112 The entry function expects to be called with:
113 argptr -> a0
114 arglen -> d0
115 execbase -> a6
117 move.l %a2,%a0 /* argptr in a0 */
118 move.l %d2,%d0 /* arglen in d0 */
119 #endif
121 jsr (%a5) /* Call the specified routine */
123 #if !UseRegisterArgs
124 /* Clean (new) stack partially, leaving SysBase behind */
125 addq.w #8,%sp
126 #endif
127 move.l %d0,%a5 /* Save return value */
129 /* Swap the upper two values on the new stack */
130 move.l (%sp)+,%a6 /* Pop SysBase */
131 move.l (%sp)+,%a0 /* Pop sss */
132 #if !UseRegisterArgs
133 move.l %a6,-(%sp)
134 move.l %a0,-(%sp)
135 #endif
137 jsr StackSwap(%a6) /* Switch stacks back */
139 #if !UseRegisterArgs
140 /* Clean old stack */
141 addq.w #8,%sp
142 #endif
143 move.l %a5,%d0 /* Put result in d0 where our caller expects it */
145 #if !UseRegisterArgs
146 movem.l (%sp)+,%a5-%a6 /* Restore registers */
147 #else
148 movem.l (%sp)+,%d2/%a2/%a5-%a6 /* Restore registers */
149 #endif