Satisfy request for port connection
[AROS.git] / arch / m68k-all / dos / callentry.S
blob8d4c753fe8a88092f845600e3a5fdf7169bec706
1 /*
2     Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3     $Id$
5     Desc: Call the entry point of a BCPL style routine
6     Lang: english
7 */
9 /*****************************************************************************
11     NAME
13         AROS_UFH7(ULONG, AOS_CallEntry,
15     SYNOPSIS
16         AROS_UFHA(STRPTR, argptr, A0),
17         AROS_UFHA(ULONG,  argsize, D0),
18         AROS_UFHA(LONG_FUNC, entry, A4),
19         AROS_UFHA(BPTR, startpkt, D1),
20         AROS_UFHA(APTR, globvec, A2),
21         AROS_UFHA(APTR, splower, A1),
22         AROS_UFHA(APTR, returnaddr, A3)
24     LOCATION
25         dos.library
27     FUNCTION
28         Call a DOS process
30     INPUTS
31         argptr  - Argument pointer (advisory)
32                   Non-NULL for CLI, NULL for Workbench
33         argsize - Length of arguments (for CLI only)
34         entry   - Routine to call
35         startpkt - BPTR to startup packet (for CLI only)
36         globvec - DOS global vector (for CLI only)
37         splower - Bottom of the stack
39     RESULT
40         Return value from calling entry()
42     NOTES
43         Internal use only
45     EXAMPLE
47     BUGS
49     SEE ALSO
51     INTERNALS
53 ******************************************************************************/
55         #include "aros/m68k/asm.h"
57         .text
58         .balign 4
59         .globl  AOS_CallEntry
60 AOS_CallEntry:
62         /* - Call with:
63          * D0 - Argsize
64          * D1..D4 - arguments
65          * A0 - Argptr (NULL for WB, non-NULL for CLI)
66          * A1 - SPLower
67          * A2 - GlobVec
68          * A3 - ReturnAddr
69          * A4 - Entry
70          * - Sets:
71          * D5..D7 - 0
72          * A5 - 0/BCPL_jsr
73          * A6 - 0/BCPL_rts
74          * A7 - C Stack
75          */
77         movem.l %d2-%d7/%a2-%a6,%sp@-
78         movq.l  #0,%d5
79         movq.l  #0,%d6
81         /* Make sure me->pr_ReturnAddr is correct */
82         move.l  %a1,%d7
83         neg.l   %d7                     /* D7 = - tc_SPLower */
84         lea.l   %sp@(%d7),%a5           /* A5 = %sp - tc_SPLower */
85         move.l  %a5,%sp@-               /* sp+ 4 = stksize */
86         move.l  %sp,%a3@                /* Save address of return address */
88         /* If %a0 is set, it's a CLI app */
89         move.l  %a0,%d7
90         tst.l   %d7
91         beq     wb_setup
93 /* CLI setup
94  */
95 cli_setup:
96         lea.l   BCPL_jsr,%a5
97         lea.l   BCPL_rts,%a6
98         jsr     (%a4)
99         bra     cleanup
101 /* WB setup */
102 wb_setup:
103         pea.l   0f
104         move.l  %a4,%sp@-       /* Put the address to call on the stack */
105         clr.l   %d7
106         move.l  %d7,%a0         /* Clear registers */
107         move.l  %d7,%a1         /* Clear registers */
108         move.l  %d7,%a2
109         move.l  %d7,%a3
110         move.l  %d7,%a4
111         move.l  %d7,%a5
112         move.l  SysBase,%a6
113         rts                     /* Pop and 'return' to the entry point */
116 cleanup:
117         addq.l  #4,%sp          /* Drop the stacksize off the stack */
118         movem.l %sp@+,%d2-%d7/%a2-%a6
119         rts
120         
121         /* Helper function used by BCPL_RunHandler
122          */
123         .global BCPL_thunk
124 BCPL_thunk:
125         movem.l %d2-%d7/%a2-%a6,%sp@-
126         /* Make sure me->pr_ReturnAddr is correct */
127         move.l  %a1,%d7
128         neg.l   %d7                     /* D7 = - tc_SPLower */
129         lea.l   %sp@(%d7),%a5           /* A5 = %sp - tc_SPLower */
130         move.l  %a5,%sp@-               /* sp+ 4 = stksize */
131         move.l  %sp,%a3@                /* Save address of return address */
133         sub.l   %a0,%a0
134         lea.l   BCPL_jsr,%a5
135         lea.l   BCPL_rts,%a6
136         /* Skip past the 3 words we need for the BCPL_jsr */
137         moveq.l #(3*4),%d0
138         pea.l   0f                      /* sp   = return address */
139         jsr     %a5@                    /* The BCPL_jsr will pop the stack ! */
140         addq.l  #4,%sp                  /* Drop the return location */
141 0:                                      /* BCPL Exit arrives here */
142         addq.l  #4,%sp                  /* Drop the stacksize off */
143         movem.l %sp@+,%d2-%d7/%a2-%a6
144         move.l  %d1,%d0                 /* Duplicate D1 */
145         rts