1 /* --------------------------------------------------------------------------
2 * Assembly code to call C and Haskell functions
4 * Copyright (c) 1994-2001.
6 * $Id: universal_call_c.S,v 1.10 2001/02/09 17:15:20 simonmar Exp $
7 * ------------------------------------------------------------------------*/
9 #if 0 /* later: GHCI */
13 .file "universal_call_c.S"
16 Implement this. See comment in rts/ForeignCall.c for details.
18 void universal_call_c_ARCHNAME
24 You can get a crude approximation to the assembly you need by
25 compiling the following:
27 extern void pingi64 ( unsigned long long int );
28 extern void pingi32 ( unsigned int );
29 extern void pingf32 ( float f );
30 extern void pingf64 ( double d );
32 void universal_call_c_ARCHNAME ( int n_args,
38 for (i = 1; i <= n_args; i++) {
39 if (argstr[i] == 'i') {
40 unsigned int u1 = ((unsigned int*)args)[2*i];
43 if (argstr[i] == 'I') {
44 unsigned long long int uu1 = ((unsigned long long int*)args)[i];
47 if (argstr[i] == 'f') {
48 float u1 = ((float*)args)[2*i];
51 if (argstr[i] == 'F') {
52 double u1 = ((double*)args)[i];
57 if (argstr[0] == 'f' || argstr[0] == 'F') {
65 #if LEADING_UNDERSCORE
66 #define ADD_UNDERSCORE(sss) _##sss
68 #define ADD_UNDERSCORE(sss) sss
74 * Tricky! Calls the specified function using ccall convention,
75 * *and* assumes that I myself was called using ccall.
78 .globl ADD_UNDERSCORE(universal_call_c_x86_ccall)
79 ADD_UNDERSCORE(universal_call_c_x86_ccall:)
92 cmpb $105,(%ebx,%edi) # 'i'
97 cmpb $73,(%ebx,%edi) # 'I'
103 cmpb $102,(%ebx,%edi) # 'f'
105 movl (%esi,%ebx,8),%eax
109 cmpb $70,(%ebx,%edi) # 'F'
111 movl 4(%esi,%ebx,8),%eax
112 movl (%esi,%ebx,8),%edx
123 cmpb $102,(%edi) # 'f'
125 cmpb $70,(%edi) # 'F'
147 # Almost identical to the above piece of code
148 # see comments near end for differences
150 # Even more tricky! Calls the specified function using
151 # stdcall convention, *but* assumes that I myself was called
154 .globl ADD_UNDERSCORE(universal_call_c_x86_stdcall)
155 ADD_UNDERSCORE(universal_call_c_x86_stdcall:)
168 cmpb $105,(%ebx,%edi) # 'i'
173 cmpb $73,(%ebx,%edi) # 'I'
179 cmpb $102,(%ebx,%edi) # 'f'
181 movl (%esi,%ebx,8),%eax
185 cmpb $70,(%ebx,%edi) # 'F'
187 movl 4(%esi,%ebx,8),%eax
188 movl (%esi,%ebx,8),%edx
199 cmpb $102,(%edi) # 'f'
201 cmpb $70,(%edi) # 'F'
214 /* don_t clear the args -- the callee does it */
215 /* leal -12(%ebp),%esp */
220 /* ret $16 # but we have to clear our own! (no! we were ccall_d) */
223 #endif /* i386_TARGET_ARCH */