mach.c 5.0 KB

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