1
/* vacall function for arm CPU */
4
* Copyright 1995-2004 Bruno Haible, <bruno@clisp.org>
6
* This is free software distributed under the GNU General Public Licence
7
* described in the file COPYING. Contact the author if you don't have this
8
* or can't live with it. There is ABSOLUTELY NO WARRANTY, explicit or implied,
13
#include "vacall.h.in"
15
#include "vacall_r.h.in"
19
#define __vacall __vacall_r
20
register struct { void (*vacall_function) (void*,va_alist); void* arg; }
23
register __vaword iret __asm__("r0");
24
register __vaword iret2 __asm__("r1");
25
register float fret __asm__("f0");
26
register double dret __asm__("f0");
28
void /* the return type is variable, not void! */
29
__vacall (__vaword word1, __vaword word2, __vaword word3, __vaword word4,
32
struct { long retaddr, arg1, arg2, arg3, arg4; } args;
35
* This is the last struct on the stack, so that
36
* &args + 1 == &return_address == &firstword - 1.
37
* Look at the assembly code to convince yourself.
39
/* Move the arguments passed in registers to their stack locations. */
40
args.retaddr = (&firstword)[-1]; /* save the return address */
41
(&firstword)[-4] = word1;
42
(&firstword)[-3] = word2;
43
(&firstword)[-2] = word3;
44
(&firstword)[-1] = word4;
45
/* Prepare the va_alist. */
47
list.aptr = (long)(&firstword - 4);
48
list.raddr = (void*)0;
49
list.rtype = __VAvoid;
50
/* Call vacall_function. The macros do all the rest. */
52
(*vacall_function) (&list);
54
(*env->vacall_function) (env->arg,&list);
56
/* Put return value into proper register. */
57
if (list.rtype == __VAvoid) {
59
if (list.rtype == __VAchar) {
60
iret = list.tmp._char;
62
if (list.rtype == __VAschar) {
63
iret = list.tmp._schar;
65
if (list.rtype == __VAuchar) {
66
iret = list.tmp._uchar;
68
if (list.rtype == __VAshort) {
69
iret = list.tmp._short;
71
if (list.rtype == __VAushort) {
72
iret = list.tmp._ushort;
74
if (list.rtype == __VAint) {
77
if (list.rtype == __VAuint) {
78
iret = list.tmp._uint;
80
if (list.rtype == __VAlong) {
81
iret = list.tmp._long;
83
if (list.rtype == __VAulong) {
84
iret = list.tmp._ulong;
86
if (list.rtype == __VAlonglong || list.rtype == __VAulonglong) {
87
iret = ((__vaword *) &list.tmp._longlong)[0];
88
iret2 = ((__vaword *) &list.tmp._longlong)[1];
90
if (list.rtype == __VAfloat) {
91
fret = list.tmp._float;
93
if (list.rtype == __VAdouble) {
94
dret = list.tmp._double;
96
if (list.rtype == __VAvoidp) {
97
iret = (long)list.tmp._ptr;
99
if (list.rtype == __VAstruct) {
100
/* NB: On arm, all structure sizes are divisible by 4. */
101
if (list.flags & __VA_PCC_STRUCT_RETURN) {
102
/* pcc struct return convention */
103
iret = (long) list.raddr;
105
/* normal struct return convention */
106
if (list.flags & __VA_REGISTER_STRUCT_RETURN) {
107
if (list.rsize == sizeof(char)) { /* can't occur */
108
iret = *(unsigned char *) list.raddr;
110
if (list.rsize == sizeof(short)) { /* can't occur */
111
iret = *(unsigned short *) list.raddr;
113
if (list.rsize == sizeof(int)) {
114
iret = *(unsigned int *) list.raddr;
116
if (list.rsize == 2*sizeof(__vaword)) {
117
iret = ((__vaword *) list.raddr)[0];
118
iret2 = ((__vaword *) list.raddr)[1];
123
(&firstword)[-1] = args.retaddr; /* restore the return address */