less debug
[AROS.git] / arch / x86_64-all / exec / execstubs.s
blob4644e4da363c2e3d187739efd7b526b8f60f319f
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Stubs to call C functions while preserving all registers, x86-64 version
6 Lang: english
7 */
8 #include "aros/x86_64/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
24 * r12 doesn't have to be preserved, however i need to keep stack
25 * alignment. So, i push r12.
26 * x86-64 ABI always suggests 16-byte-aligned stack. 64-bit Windows
27 * crashes in RaiseException() (used to implement kernel syscalls)
28 * if this requirement is not met.
30 #define PUSH \
31 pushq %rax ; \
32 pushq %rcx ; \
33 pushq %rdx ; \
34 pushq %rsi ; \
35 pushq %rdi ; \
36 pushq %r8 ; \
37 pushq %r9 ; \
38 pushq %r10 ; \
39 pushq %r11 ; \
40 pushq %r12
42 #define POP \
43 popq %r12 ; \
44 popq %r11 ; \
45 popq %r10 ; \
46 popq %r9 ; \
47 popq %r8 ; \
48 popq %rdi ; \
49 popq %rsi ; \
50 popq %rdx ; \
51 popq %rcx ; \
52 popq %rax
54 #define STUB_ARG0(name) \
55 push %rbp ; \
56 mov %rsp,%rbp ; \
57 PUSH ; \
58 call name ; \
59 POP ; \
60 leave ; \
61 ret
63 #define STUB_ARG1(name) \
64 push %rbp ; \
65 mov %rsp,%rbp ; \
66 PUSH ; \
67 call name ; \
68 POP ; \
69 leave ; \
70 ret
72 #define STUB_ARG2(name) \
73 push %rbp ; \
74 mov %rsp,%rbp ; \
75 PUSH ; \
76 call name ; \
77 POP ; \
78 leave ; \
79 ret
81 /* To save typing work */
82 #define STUB0(cname,name) \
83 .globl cname ; \
84 _FUNCTION(cname) ; \
85 cname: ; \
86 STUB_ARG0(name)
88 #define STUB1(cname,name) \
89 .globl cname ; \
90 _FUNCTION(cname) ; \
91 cname: ; \
92 STUB_ARG1(name)
95 #define STUB2(cname,name) \
96 .globl cname ; \
97 _FUNCTION(cname) ; \
98 cname: ; \
99 STUB_ARG2(name)
101 .text
102 _ALIGNMENT
104 /* Call functions and preserve registers */
105 #ifdef UseExecstubs
106 STUB1(AROS_SLIB_ENTRY(Disable,Exec,20),AROS_CSYMNAME(_Exec_20_Disable))
107 STUB1(AROS_SLIB_ENTRY(Enable,Exec,21),AROS_CSYMNAME(_Exec_21_Enable))
108 STUB1(AROS_SLIB_ENTRY(Forbid,Exec,22),AROS_CSYMNAME(_Exec_22_Forbid))
109 STUB1(AROS_SLIB_ENTRY(Permit,Exec,23),AROS_CSYMNAME(_Exec_23_Permit))
111 STUB2(AROS_SLIB_ENTRY(ObtainSemaphore,Exec,94),AROS_CSYMNAME(_Exec_94_ObtainSemaphore))
112 STUB2(AROS_SLIB_ENTRY(ReleaseSemaphore,Exec,95),AROS_CSYMNAME(_Exec_95_ReleaseSemaphore))
113 STUB2(AROS_SLIB_ENTRY(ObtainSemaphoreShared,Exec,113),AROS_CSYMNAME(_Exec_113_ObtainSemaphoreShared))
114 #endif