avcall-m68k.c
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:5k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. #ifndef _avcall_m68k_c /*-*- C -*-*/
  2. #define _avcall_m68k_c
  3. /**
  4.   Copyright 1993 Bill Triggs, <Bill.Triggs@inrialpes.fr>
  5.   Copyright 1995-1999 Bruno Haible, <haible@clisp.cons.org>
  6.   This is free software distributed under the GNU General Public
  7.   Licence described in the file COPYING. Contact the author if
  8.   you don't have this or can't live with it. There is ABSOLUTELY
  9.   NO WARRANTY, explicit or implied, on this software.
  10. **/
  11. /*----------------------------------------------------------------------
  12.   !!! THIS ROUTINE MUST BE COMPILED gcc -O !!!
  13.   Foreign function interface for a m68k Sun3 with gcc/sun-cc.
  14.   This calls a C function with an argument list built up using macros
  15.   defined in av_call.h.
  16.   M68k Argument Passing Conventions:
  17.   All arguments are passed on the stack with word alignment. Doubles take
  18.   two words. Structure args are passed as true structures embedded in the
  19.   argument stack. To return a structure, the called function copies the
  20.   return value to the address supplied in register "a1". Gcc without
  21.   -fpcc-struct-return returns <= 4 byte structures as integers.
  22.   Compile this routine with gcc -O (or -O2 or -g -O) to get the right
  23.   register variables, or use the assembler version.
  24.   ----------------------------------------------------------------------*/
  25. #include "avcall.h.in"
  26. #define RETURN(TYPE,VAL) (*(TYPE*)l->raddr = (TYPE)(VAL))
  27. int
  28. __builtin_avcall(av_alist* l)
  29. {
  30.   register __avword* sp __asm__("sp");  /* C names for registers */
  31.   register __avword* sret __asm__("a1"); /* structure return pointer */
  32. /*register __avword iret __asm__("d0"); */
  33.   register __avword iret2 __asm__("d1");
  34.   register float fret __asm__("d0"); /* d0 */
  35.   register double dret __asm__("d0"); /* d0,d1 */
  36.   register float fp_fret __asm__("fp0");
  37.   register double fp_dret __asm__("fp0");
  38.   __avword* argframe = (sp -= __AV_ALIST_WORDS); /* make room for argument list */
  39.   int arglen = l->aptr - l->args;
  40.   __avword i;
  41.   __avword i2;
  42.   for (i = 0; i < arglen; i++) /* push function args onto stack */
  43.     argframe[i] = l->args[i];
  44.   if (l->rtype == __AVstruct) /* push struct return address */
  45.     __asm__("move%.l %0,%/a1" : : "g" (l->raddr));
  46.   i = (*l->func)(); /* call function */
  47.   i2 = iret2;
  48.   /* save return value */
  49.   if (l->rtype == __AVvoid) {
  50.   } else
  51.   if (l->rtype == __AVword) {
  52.     RETURN(__avword, i);
  53.   } else
  54.   if (l->rtype == __AVchar) {
  55.     RETURN(char, i);
  56.   } else
  57.   if (l->rtype == __AVschar) {
  58.     RETURN(signed char, i);
  59.   } else
  60.   if (l->rtype == __AVuchar) {
  61.     RETURN(unsigned char, i);
  62.   } else
  63.   if (l->rtype == __AVshort) {
  64.     RETURN(short, i);
  65.   } else
  66.   if (l->rtype == __AVushort) {
  67.     RETURN(unsigned short, i);
  68.   } else
  69.   if (l->rtype == __AVint) {
  70.     RETURN(int, i);
  71.   } else
  72.   if (l->rtype == __AVuint) {
  73.     RETURN(unsigned int, i);
  74.   } else
  75.   if (l->rtype == __AVlong) {
  76.     RETURN(long, i);
  77.   } else
  78.   if (l->rtype == __AVulong) {
  79.     RETURN(unsigned long, i);
  80.   } else
  81.   if (l->rtype == __AVlonglong || l->rtype == __AVulonglong) {
  82.     ((__avword*)l->raddr)[0] = i;
  83.     ((__avword*)l->raddr)[1] = i2;
  84.   } else
  85.   if (l->rtype == __AVfloat) {
  86.     if (l->flags & __AV_FREG_FLOAT_RETURN) {
  87.       RETURN(float, fp_fret);
  88.     } else {
  89.       if (l->flags & __AV_SUNCC_FLOAT_RETURN) {
  90.         RETURN(float, (float)dret);
  91.       } else {
  92.         RETURN(float, fret);
  93.       }
  94.     }
  95.   } else
  96.   if (l->rtype == __AVdouble) {
  97.     if (l->flags & __AV_FREG_FLOAT_RETURN) {
  98.       RETURN(double, fp_dret);
  99.     } else {
  100.       RETURN(double, dret);
  101.     }
  102.   } else
  103.   if (l->rtype == __AVvoidp) {
  104.     RETURN(void*, i);
  105.   } else
  106.   if (l->rtype == __AVstruct) {
  107.     /* NB: On m68k, all structure sizes are divisible by 2. */
  108.     if (l->flags & __AV_REGISTER_STRUCT_RETURN) {
  109.       if (l->rsize == sizeof(char)) { /* can't occur */
  110.         RETURN(char, i);
  111.         goto done;
  112.       } else
  113.       if (l->rsize == sizeof(short)) {
  114.         RETURN(short, i);
  115.         goto done;
  116.       } else
  117.       if (l->rsize == sizeof(int)) {
  118.         RETURN(int, i);
  119.         goto done;
  120.       } else
  121.       if (l->rsize == 2*sizeof(__avword)) {
  122.         ((__avword*)l->raddr)[0] = i;
  123.         ((__avword*)l->raddr)[1] = i2;
  124.         goto done;
  125.       }
  126.     }
  127.     if (l->flags & __AV_PCC_STRUCT_RETURN) {
  128.       /* pcc struct return convention: need a  *(TYPE*)l->raddr = *(TYPE*)i;  */
  129.       if (l->rsize == sizeof(char)) { /* can't occur */
  130.         RETURN(char, *(char*)i);
  131.       } else
  132.       if (l->rsize == sizeof(short)) {
  133.         RETURN(short, *(short*)i);
  134.       } else
  135.       if (l->rsize == sizeof(int)) {
  136.         RETURN(int, *(int*)i);
  137.       } else
  138.       if (l->rsize == sizeof(double)) {
  139.         ((int*)l->raddr)[0] = ((int*)i)[0];
  140.         ((int*)l->raddr)[1] = ((int*)i)[1];
  141.       } else {
  142.         int n = (l->rsize + sizeof(__avword)-1)/sizeof(__avword);
  143.         while (--n >= 0)
  144.           ((__avword*)l->raddr)[n] = ((__avword*)i)[n];
  145.       }
  146.     } else {
  147.       /* normal struct return convention */
  148.     }
  149.     done: ;
  150.   }
  151.   sp += __AV_ALIST_WORDS;
  152.   return 0;
  153. }
  154. #endif /*_avcall_m68k_c */