2 /* --------------------------------------------------------------------------
3 * Assembly code to call C and Haskell functions
5 * Copyright (c) 1994-1999.
7 * $RCSfile: universal_call_c.S,v $
9 * $Date: 1999/11/17 13:19:36 $
10 * ------------------------------------------------------------------------*/
16 .file "universal_call_c.S"
19 Implement this. See comment in rts/ForeignCall.c for details.
21 void universal_call_c_ARCHNAME
27 You can get a crude approximation to the assembly you need by
28 compiling the following:
30 extern void pingi64 ( unsigned long long int );
31 extern void pingi32 ( unsigned int );
32 extern void pingf32 ( float f );
33 extern void pingf64 ( double d );
35 void universal_call_c_ARCHNAME ( int n_args,
41 for (i = 1; i <= n_args; i++) {
42 if (argstr[i] == 'i') {
43 unsigned int u1 = ((unsigned int*)args)[2*i];
46 if (argstr[i] == 'I') {
47 unsigned long long int uu1 = ((unsigned long long int*)args)[i];
50 if (argstr[i] == 'f') {
51 float u1 = ((float*)args)[2*i];
54 if (argstr[i] == 'F') {
55 double u1 = ((double*)args)[i];
60 if (argstr[0] == 'f' || argstr[0] == 'F') {
68 #if LEADING_UNDERSCORE
69 #define ADD_UNDERSCORE(sss) _##sss
71 #define ADD_UNDERSCORE(sss) sss
77 * Tricky! Calls the specified function using ccall convention,
78 * *and* assumes that I myself was called using ccall.
81 .globl ADD_UNDERSCORE(universal_call_c_x86_ccall)
82 ADD_UNDERSCORE(universal_call_c_x86_ccall:)
95 cmpb $105,(%ebx,%edi) # 'i'
100 cmpb $73,(%ebx,%edi) # 'I'
106 cmpb $102,(%ebx,%edi) # 'f'
108 movl (%esi,%ebx,8),%eax
112 cmpb $70,(%ebx,%edi) # 'F'
114 movl 4(%esi,%ebx,8),%eax
115 movl (%esi,%ebx,8),%edx
126 cmpb $102,(%edi) # 'f'
128 cmpb $70,(%edi) # 'F'
150 # Almost identical to the above piece of code
151 # see comments near end for differences
153 # Even more tricky! Calls the specified function using
154 # stdcall convention, *but* assumes that I myself was called
157 .globl ADD_UNDERSCORE(universal_call_c_x86_stdcall)
158 ADD_UNDERSCORE(universal_call_c_x86_stdcall:)
171 cmpb $105,(%ebx,%edi) # 'i'
176 cmpb $73,(%ebx,%edi) # 'I'
182 cmpb $102,(%ebx,%edi) # 'f'
184 movl (%esi,%ebx,8),%eax
188 cmpb $70,(%ebx,%edi) # 'F'
190 movl 4(%esi,%ebx,8),%eax
191 movl (%esi,%ebx,8),%edx
202 cmpb $102,(%edi) # 'f'
204 cmpb $70,(%edi) # 'F'
217 /* don_t clear the args -- the callee does it */
218 /* leal -12(%ebp),%esp */
223 /* ret $16 # but we have to clear our own! (no! we were ccall_d) */
226 #endif /* i386_TARGET_ARCH */
228 #endif /* INTERPRETER */