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

信息检索与抽取

开发平台:

Unix_Linux

  1. #ifndef _avcall_alpha_c /*-*- C -*-*/
  2. #define _avcall_alpha_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 DEC Alpha with gcc.
  14.   This calls a C function with an argument list built up using macros
  15.   defined in av_call.h.
  16.   Alpha Argument Passing Conventions
  17.   The first 6 arguments are passed in registers $16-$21 for integers,
  18.   in registers $f16-$f21 for floats. From then on, everything is passed
  19.   on the stack.
  20.   Everything on the stack is word-aligned.
  21.   Integers and pointers are returned in $0, floats and doubles in $f0.
  22.   To return a structure, the called function copies the value to space
  23.   pointed to by its first argument, and all other arguments are shifted
  24.   down by one.
  25.   Compile this routine with gcc for the __asm__ extensions and with
  26.   optimisation on (-O or -O2 or -g -O) so that argframe is set to the
  27.   correct offset.
  28.   ----------------------------------------------------------------------*/
  29. #include "avcall.h.in"
  30. #define RETURN(TYPE,VAL) (*(TYPE*)l->raddr = (TYPE)(VAL))
  31. int
  32. __builtin_avcall(av_alist* l)
  33. {
  34.   register __avword* sp __asm__("$30");  /* C names for registers */
  35.   register long arg1 __asm__("$16");
  36.   register long arg2 __asm__("$17");
  37.   register long arg3 __asm__("$18");
  38.   register long arg4 __asm__("$19");
  39.   register long arg5 __asm__("$20");
  40.   register long arg6 __asm__("$21");
  41.   register double fret __asm__("$f0");
  42.   register double farg1 __asm__("$f16");
  43.   register double farg2 __asm__("$f17");
  44.   register double farg3 __asm__("$f18");
  45.   register double farg4 __asm__("$f19");
  46.   register double farg5 __asm__("$f20");
  47.   register double farg6 __asm__("$f21");
  48. /*register __avword iret __asm__("$0"); */
  49.   register __avword iret2 __asm__("$1");
  50.   __avword* argframe = (sp -= __AV_ALIST_WORDS); /* make room for argument list */
  51.   int arglen = ((unsigned long) l->aptr - (unsigned long) l->args) >> 3;
  52.   __avword i, i2;
  53.   for (i = 6; i < arglen; i++) /* push excess function args */
  54.     argframe[i-6] = l->args[i];
  55. /* call function with 1st 6 args */
  56.   /* we pass the args both in the integer registers and the floating point
  57.      registers, so we don't have to store the argument types. */
  58.   __asm__ __volatile__ ("ldq $16,%0" : : "m" (l->args[0])); /* arg1 = l->args[0]; */
  59.   __asm__ __volatile__ ("ldt $f16,%0" : : "m" (l->args[0])); /* farg1 = *(double*) &l->args[0]; */
  60.   __asm__ __volatile__ ("ldq $17,%0" : : "m" (l->args[1])); /* arg2 = l->args[1]; */
  61.   __asm__ __volatile__ ("ldt $f17,%0" : : "m" (l->args[1])); /* farg2 = *(double*) &l->args[1]; */
  62.   __asm__ __volatile__ ("ldq $18,%0" : : "m" (l->args[2])); /* arg3 = l->args[2]; */
  63.   __asm__ __volatile__ ("ldt $f18,%0" : : "m" (l->args[2])); /* farg3 = *(double*) &l->args[2]; */
  64.   __asm__ __volatile__ ("ldq $19,%0" : : "m" (l->args[3])); /* arg4 = l->args[3]; */
  65.   __asm__ __volatile__ ("ldt $f19,%0" : : "m" (l->args[3])); /* farg4 = *(double*) &l->args[3]; */
  66.   __asm__ __volatile__ ("ldq $20,%0" : : "m" (l->args[4])); /* arg5 = l->args[4]; */
  67.   __asm__ __volatile__ ("ldt $f20,%0" : : "m" (l->args[4])); /* farg5 = *(double*) &l->args[4]; */
  68.   __asm__ __volatile__ ("ldq $21,%0" : : "m" (l->args[5])); /* arg6 = l->args[5]; */
  69.   __asm__ __volatile__ ("ldt $f21,%0" : : "m" (l->args[5])); /* farg6 = *(double*) &l->args[5]; */
  70.   i = (*l->func)();
  71.   i2 = iret2;
  72.   sp += __AV_ALIST_WORDS; /* remove argument list from the stack */
  73.   /* this is apparently not needed, but better safe than sorry... */
  74.   __asm__ __volatile__ ("" : : :
  75. /* clobber */ "$16", "$17", "$18", "$19", "$20", "$21",
  76.      "$f16","$f17","$f18","$f19","$f20","$f21");
  77.   /* save return value */
  78.   if (l->rtype == __AVvoid) {
  79.   } else
  80.   if (l->rtype == __AVword) {
  81.     RETURN(__avword, i);
  82.   } else
  83.   if (l->rtype == __AVchar) {
  84.     RETURN(char, i);
  85.   } else
  86.   if (l->rtype == __AVschar) {
  87.     RETURN(signed char, i);
  88.   } else
  89.   if (l->rtype == __AVuchar) {
  90.     RETURN(unsigned char, i);
  91.   } else
  92.   if (l->rtype == __AVshort) {
  93.     RETURN(short, i);
  94.   } else
  95.   if (l->rtype == __AVushort) {
  96.     RETURN(unsigned short, i);
  97.   } else
  98.   if (l->rtype == __AVint) {
  99.     RETURN(int, i);
  100.   } else
  101.   if (l->rtype == __AVuint) {
  102.     RETURN(unsigned int, i);
  103.   } else
  104.   if (l->rtype == __AVlong) {
  105.     RETURN(long, i);
  106.   } else
  107.   if (l->rtype == __AVulong) {
  108.     RETURN(unsigned long, i);
  109.   } else
  110.   if (l->rtype == __AVlonglong) {
  111.     RETURN(long long, i);
  112.   } else
  113.   if (l->rtype == __AVulonglong) {
  114.     RETURN(unsigned long long, i);
  115.   } else
  116.   if (l->rtype == __AVfloat) {
  117.     RETURN(float, fret);
  118.   } else
  119.   if (l->rtype == __AVdouble) {
  120.     RETURN(double, fret);
  121.   } else
  122.   if (l->rtype == __AVvoidp) {
  123.     RETURN(void*, i);
  124.   } else
  125.   if (l->rtype == __AVstruct) {
  126.     if (l->flags & __AV_PCC_STRUCT_RETURN) {
  127.       /* pcc struct return convention: need a  *(TYPE*)l->raddr = *(TYPE*)i;  */
  128.       if (l->rsize == sizeof(char)) {
  129.         RETURN(char, *(char*)i);
  130.       } else
  131.       if (l->rsize == sizeof(short)) {
  132.         RETURN(short, *(short*)i);
  133.       } else
  134.       if (l->rsize == sizeof(int)) {
  135.         RETURN(int, *(int*)i);
  136.       } else
  137.       if (l->rsize == sizeof(long)) {
  138.         RETURN(long, *(long*)i);
  139.       } else {
  140.         int n = (l->rsize + sizeof(__avword)-1)/sizeof(__avword);
  141.         while (--n >= 0)
  142.           ((__avword*)l->raddr)[n] = ((__avword*)i)[n];
  143.       }
  144.     } else {
  145.       /* normal struct return convention */
  146.       if (l->flags & __AV_REGISTER_STRUCT_RETURN) {
  147.         if (l->rsize == sizeof(char)) {
  148.           RETURN(char, i);
  149.         } else
  150.         if (l->rsize == sizeof(short)) {
  151.           RETURN(short, i);
  152.         } else
  153.         if (l->rsize == sizeof(int)) {
  154.           RETURN(int, i);
  155.         } else
  156.         if (l->rsize == sizeof(long)) {
  157.           RETURN(long, i);
  158.         } else
  159.         if (l->rsize == 2*sizeof(__avword)) {
  160.           ((__avword*)l->raddr)[0] = i;
  161.           ((__avword*)l->raddr)[1] = i2;
  162.         }
  163.       }
  164.     }
  165.   }
  166.   return 0;
  167. }
  168. #endif /*_avcall_alpha_c */