home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / sozobon / scsrc20 / ld / cross.c < prev    next >
C/C++ Source or Header  |  1991-02-22  |  2KB  |  148 lines

  1.  
  2. /*
  3.  * Copyright (c) 1991 by Sozobon, Limited.  Author: Johann Ruegg
  4.  *
  5.  * Permission is granted to anyone to use this software for any purpose
  6.  * on any computer system, and to redistribute it freely, with the
  7.  * following restrictions:
  8.  * 1) No charge may be made other than reasonable charges for reproduction.
  9.  * 2) Modified versions must be clearly marked as such.
  10.  * 3) The authors are not responsible for any harmful consequences
  11.  *    of using this software, even if they result from defects in it.
  12.  */
  13.  
  14. #include "syms.h"
  15.  
  16. /*
  17.  * fix alignment and byte order problems in cross environment
  18.  */
  19.  
  20. long
  21. crossl(cp)
  22. char *cp;
  23. {
  24.     union {
  25.         long l;
  26.         char c[4];
  27.     } u;
  28.  
  29. #ifdef LITTLE_ENDIAN
  30.     u.c[0] = cp[3];
  31.     u.c[1] = cp[2];
  32.     u.c[2] = cp[1];
  33.     u.c[3] = cp[0];
  34. #else
  35.     u.c[0] = cp[0];
  36.     u.c[1] = cp[1];
  37.     u.c[2] = cp[2];
  38.     u.c[3] = cp[3];
  39. #endif
  40.     return u.l;
  41. }
  42.  
  43. pcrossl(l, cp)
  44. long l;
  45. char *cp;
  46. {
  47.     union {
  48.         long l;
  49.         char c[4];
  50.     } u;
  51.  
  52.     u.l = l;
  53. #ifdef LITTLE_ENDIAN
  54.     cp[0] = u.c[3];
  55.     cp[1] = u.c[2];
  56.     cp[2] = u.c[1];
  57.     cp[3] = u.c[0];
  58. #else
  59.     cp[0] = u.c[0];
  60.     cp[1] = u.c[1];
  61.     cp[2] = u.c[2];
  62.     cp[3] = u.c[3];
  63. #endif
  64. }
  65.  
  66. swapw(cp, n)
  67. char *cp;
  68. {
  69. #ifdef LITTLE_ENDIAN
  70.     char t;
  71.  
  72.     while (n--) {
  73.         t = cp[1];
  74.         cp[1] = cp[0];
  75.         cp[0] = t;
  76.         cp += 2;
  77.     }
  78. #endif
  79. }
  80.  
  81. swapl(cp, n)
  82. char *cp;
  83. {
  84. #ifdef LITTLE_ENDIAN
  85.     char t;
  86.  
  87.     while (n--) {
  88.         t = cp[3];
  89.         cp[3] = cp[0];
  90.         cp[0] = t;
  91.  
  92.         t = cp[2];
  93.         cp[2] = cp[1];
  94.         cp[1] = t;
  95.         cp += 4;
  96.     }
  97. #endif
  98. }
  99.  
  100. symhacki(sp, n)
  101. char *sp;
  102. {
  103.     struct fsym *fp;
  104.     struct sym *tp;
  105.  
  106.     fp = (struct fsym *)sp + (n-1);
  107.     tp = (struct sym *)sp + (n-1);
  108.  
  109.     while (n--) {
  110.         tp->value = crossl(fp->value);
  111.         if (n == 0)
  112.             return;
  113.         tp->mark = fp->mark;
  114.         tp->flags = fp->flags;
  115.         rbcopy(fp->name, tp->name, 8);
  116.  
  117.         fp--;
  118.         tp--;
  119.     }
  120. }
  121.  
  122. fixsym(sp)
  123. struct sym *sp;
  124. {
  125.     struct fsym *fp;
  126.  
  127.     fp = (struct fsym *)sp;
  128.     fp->flags = sp->flags;
  129.     fp->mark = 0;
  130.     pcrossl(sp->value, fp->value);
  131. }
  132.  
  133. rbcopy(fr, to, n)
  134. char *fr, *to;
  135. {
  136.     fr += (n-1);
  137.     to += (n-1);
  138.     while (n--)
  139.         *to-- = *fr--;
  140. }
  141.  
  142. bcopy(fr,to, n)
  143. char *fr, *to;
  144. {
  145.     while (n--)
  146.         *to++ = *fr++;
  147. }
  148.