Merging NList MCC 0.119 into the main branch.
[AROS.git] / arch / ppc-all / exec / execstubs.s
blobe10d2624190cba335c1cbbdeefe9b9eaa5fe10fd
1 /*
2 Copyright ? 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Stubs to call C functions while preserving all registers
6 Lang: english
7 */
8 #include "aros/ppc/asm.h"
11 Macros:
12 PUSH - Save all registers on the stack
13 POP - Restore all registers from the stack
15 STUB_ARG0(name) - Call a function preserving all registers
16 which gets no arguments
17 STUB_ARG1(name) - Call a function preserving all registers
18 which gets a single argument
19 STUB_ARG2(name) - Call a function preserving all registers
20 which gets two arguments
23 #define NUM_REGS (32 + 2)
24 #define OFFSET ((NUM_REGS) * 4)
25 #define FIRST_ARG (((NUM_REGS + 0) * 4) + OFFSET)
26 #define SECOND_ARG (((NUM_REGS + 1) * 4) + OFFSET)
28 /* 4(1) is used by the called function
29 to store lr much the same way we do
31 #define PUSH \
32 stwu 1,-OFFSET(1) ;\
33 stw 0,8(1) ;\
34 stmw 2,12(1) ;\
35 mflr 0 ;\
36 stw 0,OFFSET-4(1);
38 #define POP \
39 lwz 0,OFFSET-4(1); \
40 mtlr 0 ; \
41 lmw 2,12(1) ; \
42 lwz 0,8(1) ; \
43 lwz 1,0(1);
45 #define STUB_ARG0(name)\
46 PUSH ; \
47 lis 9,name@ha ; \
48 la 0,name@l(9); \
49 mtlr 0 ; \
50 blrl ; \
51 POP ; \
52 blrl
54 #define STUB_ARG1(name) \
55 PUSH ; \
56 lwz 0,FIRST_ARG(1); \
57 stw 0,-4(1) ; \
58 lis 9,name@ha ; \
59 la 0,name@l(9) ; \
60 mtlr 0 ; \
61 blrl ; \
62 POP ; \
63 blrl
65 #define STUB_ARG2(name) \
66 PUSH ; \
67 lwz 0,SECOND_ARG(1); \
68 stw 0,-4(1) ; \
69 lwz 0,FIRST_ARG(1) ; \
70 stw 0,-8(1) ; \
71 lis 9,name@ha ; \
72 la 0,name@l(9) ; \
73 mtlr 0 ; \
74 blrl ; \
75 POP ; \
76 blrl
78 /* To save typing work */
79 #define STUB0(cname,name)\
80 .globl cname ; \
81 _FUNCTION(cname) ; \
82 cname: ; \
83 STUB_ARG0(name)
85 #define STUB1(cname,name)\
86 .globl cname ; \
87 _FUNCTION(cname) ; \
88 cname: ; \
89 STUB_ARG1(name)
91 #define STUB2(cname,name)\
92 .globl cname ; \
93 _FUNCTION(cname) ; \
94 cname: ; \
95 STUB_ARG2(name)
97 .text
98 _ALIGNMENT
100 /* Call functions and preserve registers */
101 #ifdef UseExecstubs
102 STUB1(AROS_SLIB_ENTRY(Disable,Exec,20),AROS_CSYMNAME(_Exec_Disable))
103 STUB1(AROS_SLIB_ENTRY(Enable,Exec,21),AROS_CSYMNAME(_Exec_Enable))
104 STUB1(AROS_SLIB_ENTRY(Forbid,Exec,22),AROS_CSYMNAME(_Exec_Forbid))
105 STUB1(AROS_SLIB_ENTRY(Permit,Exec,23),AROS_CSYMNAME(_Exec_Permit))
107 STUB2(AROS_SLIB_ENTRY(ObtainSemaphore,Exec,94),AROS_CSYMNAME(_Exec_ObtainSemaphore))
108 STUB2(AROS_SLIB_ENTRY(ReleaseSemaphore,Exec,95),AROS_CSYMNAME(_Exec_ReleaseSemaphore))
109 STUB2(AROS_SLIB_ENTRY(ObtainSemaphoreShared,Exec,113),AROS_CSYMNAME(_Exec_ObtainSemaphoreShared))
110 #endif