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

« back to all changes in this revision

Viewing changes to callback/vacall_r/vacall-m88k.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 m88k 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__("r11");
 
22
#endif
 
23
register __vaword* sret __asm__("r12");
 
24
register int    iret    __asm__("r2");
 
25
register int    iret2   __asm__("r3");
 
26
register float  fret    __asm__("r2");
 
27
register double dret    __asm__("r2");
 
28
 
 
29
void /* the return type is variable, not void! */
 
30
__vacall (__vaword word1, __vaword word2, __vaword word3, __vaword word4,
 
31
          __vaword word5, __vaword word6, __vaword word7, __vaword word8,
 
32
          __vaword firstword)
 
33
{
 
34
  __va_alist list;
 
35
  /* gcc-2.6.3 source says: When a parameter is passed in a register,
 
36
   * stack space is still allocated for it.
 
37
   */
 
38
  /* Move the arguments passed in registers to their stack locations. */
 
39
  /*
 
40
   * Is this correct?? I think struct arguments among the first 8 words
 
41
   * are passed on the stack, not in registers, and we shouldn't overwrite
 
42
   * them.
 
43
   */
 
44
  (&firstword)[-8] = word1;
 
45
  (&firstword)[-7] = word2;
 
46
  (&firstword)[-6] = word3;
 
47
  (&firstword)[-5] = word4;
 
48
  (&firstword)[-4] = word5;
 
49
  (&firstword)[-3] = word6;
 
50
  (&firstword)[-2] = word7;
 
51
  (&firstword)[-1] = word8;
 
52
  /* Prepare the va_alist. */
 
53
  list.flags = 0;
 
54
  list.aptr = (long)&firstword;
 
55
  list.raddr = (void*)0;
 
56
  list.rtype = __VAvoid;
 
57
  list.structraddr = sret;
 
58
  /* Call vacall_function. The macros do all the rest. */
 
59
#ifndef REENTRANT
 
60
  (*vacall_function) (&list);
 
61
#else /* REENTRANT */
 
62
  (*env->vacall_function) (env->arg,&list);
 
63
#endif
 
64
  /* Put return value into proper register. */
 
65
  if (list.rtype == __VAvoid) {
 
66
  } else
 
67
  if (list.rtype == __VAchar) {
 
68
    iret = list.tmp._char;
 
69
  } else
 
70
  if (list.rtype == __VAschar) {
 
71
    iret = list.tmp._schar;
 
72
  } else
 
73
  if (list.rtype == __VAuchar) {
 
74
    iret = list.tmp._uchar;
 
75
  } else
 
76
  if (list.rtype == __VAshort) {
 
77
    iret = list.tmp._short;
 
78
  } else
 
79
  if (list.rtype == __VAushort) {
 
80
    iret = list.tmp._ushort;
 
81
  } else
 
82
  if (list.rtype == __VAint) {
 
83
    iret = list.tmp._int;
 
84
  } else
 
85
  if (list.rtype == __VAuint) {
 
86
    iret = list.tmp._uint;
 
87
  } else
 
88
  if (list.rtype == __VAlong) {
 
89
    iret = list.tmp._long;
 
90
  } else
 
91
  if (list.rtype == __VAulong) {
 
92
    iret = list.tmp._ulong;
 
93
  } else
 
94
  if (list.rtype == __VAlonglong || list.rtype == __VAulonglong) {
 
95
    iret  = ((__vaword *) &list.tmp._longlong)[0];
 
96
    iret2 = ((__vaword *) &list.tmp._longlong)[1];
 
97
  } else
 
98
  if (list.rtype == __VAfloat) {
 
99
    fret = list.tmp._float;
 
100
  } else
 
101
  if (list.rtype == __VAdouble) {
 
102
    dret = list.tmp._double;
 
103
  } else
 
104
  if (list.rtype == __VAvoidp) {
 
105
    iret = (long)list.tmp._ptr;
 
106
  } else
 
107
  if (list.rtype == __VAstruct) {
 
108
    if (list.flags & __VA_PCC_STRUCT_RETURN) {
 
109
      /* pcc struct return convention */
 
110
      iret = (long) list.raddr;
 
111
    } else {
 
112
      /* normal struct return convention */
 
113
      if (list.flags & __VA_SMALL_STRUCT_RETURN) {
 
114
        if (list.rsize == sizeof(char)) {
 
115
          iret = *(unsigned char *) list.raddr;
 
116
        } else
 
117
        if (list.rsize == sizeof(short)) {
 
118
          iret = *(unsigned short *) list.raddr;
 
119
        } else
 
120
        if (list.rsize == sizeof(int)) {
 
121
          iret = *(unsigned int *) list.raddr;
 
122
        }
 
123
      }
 
124
    }
 
125
  }
 
126
}