mach.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #ifndef NORCSID
  2. static char rcsid[] = "$Header$";
  3. #endif
  4. /*
  5. * (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  6. *
  7. * This product is part of the Amsterdam Compiler Kit.
  8. *
  9. * Permission to use, sell, duplicate or disclose this software must be
  10. * obtained in writing. Requests for such permissions may be sent to
  11. *
  12. * Dr. Andrew S. Tanenbaum
  13. * Wiskundig Seminarium
  14. * Vrije Universiteit
  15. * Postbox 7161
  16. * 1007 MC Amsterdam
  17. * The Netherlands
  18. *
  19. * Author: Hans van Staveren
  20. */
  21. /*
  22. * machine dependent back end routines for the PDP-11
  23. */
  24. /* #define REGPATCH /* save all registers in markblock */
  25. con_part(sz,w) register sz; word w; {
  26. while (part_size % sz)
  27. part_size++;
  28. if (part_size == TEM_WSIZE)
  29. part_flush();
  30. if (sz == 1) {
  31. w &= 0xFF;
  32. if (part_size)
  33. w <<= 8;
  34. part_word |= w;
  35. } else {
  36. assert(sz == 2);
  37. part_word = w;
  38. }
  39. part_size += sz;
  40. }
  41. con_mult(sz) word sz; {
  42. long l;
  43. if (sz != 4)
  44. fatal("bad icon/ucon size");
  45. #ifdef ACK_ASS
  46. fprintf(codefile,".long %s\n",str);
  47. #else
  48. l = atol(str);
  49. fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l);
  50. #endif
  51. }
  52. /*
  53. * The next function is difficult to do when not running on a PDP 11 or VAX
  54. * The strategy followed is to assume the code generator is running on a PDP 11
  55. * unless the ACK_ASS define is on.
  56. * In the last case floating point constants are simply not handled
  57. */
  58. con_float() {
  59. #ifdef ACK_ASS
  60. static int been_here;
  61. if (argval != 4 && argval != 8)
  62. fatal("bad fcon size");
  63. fprintf(codefile,".long\t");
  64. if (argval == 8)
  65. fprintf(codefile,"F_DUM,");
  66. fprintf(codefile,"F_DUM\n");
  67. if ( !been_here++)
  68. fprintf(stderr,"Warning : dummy float-constant(s)\n");
  69. #else
  70. double f;
  71. register short *p,i;
  72. if (argval != 4 && argval != 8)
  73. fatal("bad fcon size");
  74. f = atof(str);
  75. p = (short *) &f;
  76. i = *p++;
  77. if (argval == 8) {
  78. fprintf(codefile,"\t%o;%o;",i,*p++);
  79. i = *p++;
  80. }
  81. fprintf(codefile,"\t%o;%o\n",i,*p++);
  82. #endif
  83. }
  84. #ifdef REGVARS
  85. char Rstring[10];
  86. full lbytes;
  87. struct regadm {
  88. char *ra_str;
  89. long ra_off;
  90. } regadm[2];
  91. int n_regvars;
  92. regscore(off,size,typ,score,totyp) long off; {
  93. if (size != 2)
  94. return(-1);
  95. score -= 1; /* allow for save/restore */
  96. if (off>=0)
  97. score -= 2;
  98. if (typ==reg_pointer)
  99. score *= 17;
  100. else if (typ==reg_loop)
  101. score = 10*score+50; /* Guestimate */
  102. else
  103. score *= 10;
  104. return(score); /* estimated # of words of profit */
  105. }
  106. i_regsave() {
  107. Rstring[0] = 0;
  108. n_regvars=0;
  109. }
  110. f_regsave() {
  111. register i;
  112. if (n_regvars==0 || lbytes==0) {
  113. #ifdef REGPATCH
  114. fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
  115. #endif
  116. fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
  117. if (lbytes == 2)
  118. fprintf(codefile,"tst -(sp)\n");
  119. else if (lbytes!=0)
  120. fprintf(codefile,"sub $0%o,sp\n",lbytes);
  121. for (i=0;i<n_regvars;i++)
  122. fprintf(codefile,"mov %s,-(sp)\n",regadm[i].ra_str);
  123. } else {
  124. if (lbytes>6) {
  125. fprintf(codefile,"mov $0%o,r0\n",lbytes);
  126. fprintf(codefile,"jsr r5,PR%s\n",Rstring);
  127. } else {
  128. fprintf(codefile,"jsr r5,PR%d%s\n",lbytes,Rstring);
  129. }
  130. }
  131. for (i=0;i<n_regvars;i++)
  132. if (regadm[i].ra_off>=0)
  133. fprintf(codefile,"mov 0%lo(r5),%s\n",regadm[i].ra_off,
  134. regadm[i].ra_str);
  135. }
  136. regsave(regstr,off,size) char *regstr; long off; {
  137. fprintf(codefile,"%c Local %ld into %s\n",COMMENTCHAR,off,regstr);
  138. /* commented away
  139. #ifndef REGPATCH
  140. fprintf(codefile,"mov %s,-(sp)\n",regstr);
  141. #endif
  142. strcat(Rstring,regstr);
  143. if (off>=0)
  144. fprintf(codefile,"mov 0%lo(r5),%s\n",off,regstr);
  145. end of commented away */
  146. strcat(Rstring,regstr);
  147. regadm[n_regvars].ra_str = regstr;
  148. regadm[n_regvars].ra_off = off;
  149. n_regvars++;
  150. }
  151. regreturn() {
  152. #ifdef REGPATCH
  153. fprintf(codefile,"jmp eret\n");
  154. #else
  155. fprintf(codefile,"jmp RT%s\n",Rstring);
  156. #endif
  157. }
  158. #endif
  159. prolog(nlocals) full nlocals; {
  160. #ifndef REGVARS
  161. #ifdef REGPATCH
  162. fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
  163. #endif
  164. fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
  165. if (nlocals == 0)
  166. return;
  167. if (nlocals == 2)
  168. fprintf(codefile,"tst -(sp)\n");
  169. else
  170. fprintf(codefile,"sub $0%o,sp\n",nlocals);
  171. #else
  172. lbytes = nlocals;
  173. #endif
  174. }
  175. dlbdlb(as,ls) string as,ls; {
  176. if (strlen(as)+strlen(ls)+2<sizeof(labstr)) {
  177. strcat(ls,":");
  178. strcat(ls,as);
  179. } else
  180. fatal("too many consecutive labels");
  181. }
  182. mes(type) word type; {
  183. int argt ;
  184. switch ( (int)type ) {
  185. case ms_ext :
  186. for (;;) {
  187. switch ( argt=getarg(
  188. ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
  189. case sp_cend :
  190. return ;
  191. default:
  192. strarg(argt) ;
  193. #ifdef ACK_ASS
  194. fprintf(codefile,".define %s\n",argstr) ;
  195. #else
  196. fprintf(codefile,".globl %s\n",argstr) ;
  197. #endif
  198. break ;
  199. }
  200. }
  201. default :
  202. while ( getarg(any_ptyp) != sp_cend ) ;
  203. break ;
  204. }
  205. }
  206. char *segname[] = {
  207. ".text", /* SEGTXT */
  208. ".data", /* SEGCON */
  209. ".data", /* SEGROM */
  210. ".bss" /* SEGBSS */
  211. };