~ubuntu-branches/debian/squeeze/ffcall/squeeze

« back to all changes in this revision

Viewing changes to ffcall/callback/vacall_r/vacall-arm.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2010-06-26 15:29:30 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100626152930-c09y01gk3szcnykn
Tags: 1.10+cvs20100619-2
Ship to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* vacall function for arm CPU */
2
 
 
3
 
/*
4
 
 * Copyright 1995-2004 Bruno Haible, <bruno@clisp.org>
5
 
 *
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,
9
 
 * on this software.
10
 
 */
11
 
 
12
 
#ifndef REENTRANT
13
 
#include "vacall.h.in"
14
 
#else /* REENTRANT */
15
 
#include "vacall_r.h.in"
16
 
#endif
17
 
 
18
 
#ifdef REENTRANT
19
 
#define __vacall __vacall_r
20
 
register struct { void (*vacall_function) (void*,va_alist); void* arg; }
21
 
         *              env     __asm__("r12");
22
 
#endif
23
 
register __vaword       iret    __asm__("r0");
24
 
register __vaword       iret2   __asm__("r1");
25
 
register float          fret    __asm__("f0");
26
 
register double         dret    __asm__("f0");
27
 
 
28
 
void /* the return type is variable, not void! */
29
 
__vacall (__vaword word1, __vaword word2, __vaword word3, __vaword word4,
30
 
          __vaword firstword)
31
 
{
32
 
  struct { long retaddr, arg1, arg2, arg3, arg4; } args;
33
 
  __va_alist list;
34
 
  /* MAGIC ALERT!
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.
38
 
   */
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. */
46
 
  list.flags = 0;
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. */
51
 
#ifndef REENTRANT
52
 
  (*vacall_function) (&list);
53
 
#else /* REENTRANT */
54
 
  (*env->vacall_function) (env->arg,&list);
55
 
#endif
56
 
  /* Put return value into proper register. */
57
 
  if (list.rtype == __VAvoid) {
58
 
  } else
59
 
  if (list.rtype == __VAchar) {
60
 
    iret = list.tmp._char;
61
 
  } else
62
 
  if (list.rtype == __VAschar) {
63
 
    iret = list.tmp._schar;
64
 
  } else
65
 
  if (list.rtype == __VAuchar) {
66
 
    iret = list.tmp._uchar;
67
 
  } else
68
 
  if (list.rtype == __VAshort) {
69
 
    iret = list.tmp._short;
70
 
  } else
71
 
  if (list.rtype == __VAushort) {
72
 
    iret = list.tmp._ushort;
73
 
  } else
74
 
  if (list.rtype == __VAint) {
75
 
    iret = list.tmp._int;
76
 
  } else
77
 
  if (list.rtype == __VAuint) {
78
 
    iret = list.tmp._uint;
79
 
  } else
80
 
  if (list.rtype == __VAlong) {
81
 
    iret = list.tmp._long;
82
 
  } else
83
 
  if (list.rtype == __VAulong) {
84
 
    iret = list.tmp._ulong;
85
 
  } else
86
 
  if (list.rtype == __VAlonglong || list.rtype == __VAulonglong) {
87
 
    iret  = ((__vaword *) &list.tmp._longlong)[0];
88
 
    iret2 = ((__vaword *) &list.tmp._longlong)[1];
89
 
  } else
90
 
  if (list.rtype == __VAfloat) {
91
 
    fret = list.tmp._float;
92
 
  } else
93
 
  if (list.rtype == __VAdouble) {
94
 
    dret = list.tmp._double;
95
 
  } else
96
 
  if (list.rtype == __VAvoidp) {
97
 
    iret = (long)list.tmp._ptr;
98
 
  } else
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;
104
 
    } else {
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;
109
 
        } else
110
 
        if (list.rsize == sizeof(short)) { /* can't occur */
111
 
          iret = *(unsigned short *) list.raddr;
112
 
        } else
113
 
        if (list.rsize == sizeof(int)) {
114
 
          iret = *(unsigned int *) list.raddr;
115
 
        } else
116
 
        if (list.rsize == 2*sizeof(__vaword)) {
117
 
          iret  = ((__vaword *) list.raddr)[0];
118
 
          iret2 = ((__vaword *) list.raddr)[1];
119
 
        }
120
 
      }
121
 
    }
122
 
  }
123
 
  (&firstword)[-1] = args.retaddr; /* restore the return address */
124
 
}