2007-03-01 Paul Brook <paul@codesourcery.com>
[official-gcc.git] / libffi / src / m68k / sysv.S
blobd019a377e5b6ea248e21520852867af5c7b314eb
1 /* -----------------------------------------------------------------------
2    sysv.S
3    
4    m68k Foreign Function Interface 
5    ----------------------------------------------------------------------- */
7 #define LIBFFI_ASM      
8 #include <fficonfig.h>
9 #include <ffi.h>
11         .text
13         .globl  ffi_call_SYSV
14         .type   ffi_call_SYSV,@function
16 ffi_call_SYSV:
17         link    %fp,#0
18         move.l  %d2,-(%sp)
20         | Make room for all of the new args.
21         sub.l   16(%fp),%sp
23         | Call ffi_prep_args
24         move.l  12(%fp),-(%sp)
25         pea     4(%sp)
26         move.l  8(%fp),%a0
27         jsr     (%a0)
28         addq.l  #8,%sp  
30         | Pass pointer to struct value, if any
31         move.l  %a0,%a1
33         | Call the function
34         move.l  32(%fp),%a0
35         jsr     (%a0)
37         | Remove the space we pushed for the args
38         add.l   16(%fp),%sp
40         | Load the pointer to storage for the return value
41         move.l  28(%fp),%a1
43         | Load the return type code 
44         move.l  20(%fp),%d2
46         | If the return value pointer is NULL, assume no return value.
47         tst.l   %a1
48         jbeq    noretval
50         btst    #0,%d2
51         jbeq    retlongint
52         move.l  %d0,(%a1)
53         jbra    epilogue
55 retlongint:
56         btst    #1,%d2
57         jbeq    retfloat
58         move.l  %d0,(%a1)
59         move.l  %d1,4(%a1)
60         jbra    epilogue
62 retfloat:
63         btst    #2,%d2
64         jbeq    retdouble
65         fmove.s %fp0,(%a1)
66         jbra    epilogue
68 retdouble:
69         btst    #3,%d2
70         jbeq    retlongdouble
71         fmove.d %fp0,(%a1)
72         jbra    epilogue
74 retlongdouble:
75         btst    #4,%d2
76         jbeq    retpointer
77         fmove.x %fp0,(%a1)
78         jbra    epilogue
80 retpointer:
81         btst    #5,%d2
82         jbeq    retstruct
83         move.l  %a0,(%a1)
84         jbra    epilogue
86 retstruct:
87         btst    #6,%d2
88         jbeq    noretval
89         move.l  24(%fp),%d2
90         bfins   %d0,(%a1){#0,%d2}
92 noretval:
93 epilogue:
94         move.l  (%sp)+,%d2
95         unlk    %a6
96         rts
97         .size   ffi_call_SYSV,.-ffi_call_SYSV