mach.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #ifndef NORCSID
  2. static char rcsid[] = "$Header$";
  3. #endif
  4. /*
  5. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  6. * See the copyright notice in the ACK home directory, in the file "Copyright".
  7. *
  8. * Author: Hans van Staveren
  9. */
  10. /*
  11. * machine dependent back end routines for the PDP-11
  12. */
  13. /* #define REGPATCH /* save all registers in markblock */
  14. con_part(sz,w) register sz; word w; {
  15. while (part_size % sz)
  16. part_size++;
  17. if (part_size == TEM_WSIZE)
  18. part_flush();
  19. if (sz == 1) {
  20. w &= 0xFF;
  21. if (part_size)
  22. w <<= 8;
  23. part_word |= w;
  24. } else {
  25. assert(sz == 2);
  26. part_word = w;
  27. }
  28. part_size += sz;
  29. }
  30. con_mult(sz) word sz; {
  31. long l, atol();
  32. if (sz != 4)
  33. fatal("bad icon/ucon size");
  34. l = atol(str);
  35. #ifdef ACK_ASS
  36. fprintf(codefile,".data2 0%o, 0%o !%s\n",(int)(l>>16),(int)l, str);
  37. #else
  38. fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l);
  39. #endif
  40. }
  41. #define PDPFLOAT
  42. #define FL_MSL_AT_LOW_ADDRESS 1
  43. #define FL_MSW_AT_LOW_ADDRESS 1
  44. #define FL_MSB_AT_LOW_ADDRESS 0
  45. #define CODE_GENERATOR
  46. #include <con_float>
  47. #ifdef REGVARS
  48. char Rstring[10];
  49. full lbytes;
  50. struct regadm {
  51. char *ra_str;
  52. long ra_off;
  53. } regadm[2];
  54. int n_regvars;
  55. regscore(off,size,typ,score,totyp) long off; {
  56. if (size != 2)
  57. return(-1);
  58. score -= 1; /* allow for save/restore */
  59. if (off>=0)
  60. score -= 2;
  61. if (typ==reg_pointer)
  62. score *= 17;
  63. else if (typ==reg_loop)
  64. score = 10*score+50; /* Guestimate */
  65. else
  66. score *= 10;
  67. return(score); /* estimated # of words of profit */
  68. }
  69. i_regsave() {
  70. Rstring[0] = 0;
  71. n_regvars=0;
  72. }
  73. f_regsave() {
  74. register i;
  75. if (n_regvars==0 || lbytes==0) {
  76. #ifdef REGPATCH
  77. fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
  78. #endif
  79. fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
  80. if (lbytes == 2)
  81. fprintf(codefile,"tst -(sp)\n");
  82. else if (lbytes!=0)
  83. fprintf(codefile,"sub $0%o,sp\n",lbytes);
  84. for (i=0;i<n_regvars;i++)
  85. fprintf(codefile,"mov %s,-(sp)\n",regadm[i].ra_str);
  86. } else {
  87. if (lbytes>6) {
  88. fprintf(codefile,"mov $0%o,r0\n",lbytes);
  89. fprintf(codefile,"jsr r5,PR%s\n",Rstring);
  90. } else {
  91. fprintf(codefile,"jsr r5,PR%d%s\n",lbytes,Rstring);
  92. }
  93. }
  94. for (i=0;i<n_regvars;i++)
  95. if (regadm[i].ra_off>=0)
  96. fprintf(codefile,"mov 0%lo(r5),%s\n",regadm[i].ra_off,
  97. regadm[i].ra_str);
  98. }
  99. regsave(regstr,off,size) char *regstr; long off; {
  100. fprintf(codefile,"%c Local %ld into %s\n",COMMENTCHAR,off,regstr);
  101. /* commented away
  102. #ifndef REGPATCH
  103. fprintf(codefile,"mov %s,-(sp)\n",regstr);
  104. #endif
  105. strcat(Rstring,regstr);
  106. if (off>=0)
  107. fprintf(codefile,"mov 0%lo(r5),%s\n",off,regstr);
  108. end of commented away */
  109. strcat(Rstring,regstr);
  110. regadm[n_regvars].ra_str = regstr;
  111. regadm[n_regvars].ra_off = off;
  112. n_regvars++;
  113. }
  114. regreturn() {
  115. #ifdef REGPATCH
  116. fprintf(codefile,"jmp eret\n");
  117. #else
  118. fprintf(codefile,"jmp RT%s\n",Rstring);
  119. #endif
  120. }
  121. #endif
  122. prolog(nlocals) full nlocals; {
  123. #ifndef REGVARS
  124. #ifdef REGPATCH
  125. fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
  126. #endif
  127. fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
  128. if (nlocals == 0)
  129. return;
  130. if (nlocals == 2)
  131. fprintf(codefile,"tst -(sp)\n");
  132. else
  133. fprintf(codefile,"sub $0%o,sp\n",nlocals);
  134. #else
  135. lbytes = nlocals;
  136. #endif
  137. }
  138. dlbdlb(as,ls) string as,ls; {
  139. if (strlen(as)+strlen(ls)+2<sizeof(labstr)) {
  140. strcat(ls,":");
  141. strcat(ls,as);
  142. } else
  143. fatal("too many consecutive labels");
  144. }
  145. mes(type) word type; {
  146. int argt ;
  147. switch ( (int)type ) {
  148. case ms_ext :
  149. for (;;) {
  150. switch ( argt=getarg(
  151. ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
  152. case sp_cend :
  153. return ;
  154. default:
  155. strarg(argt) ;
  156. #ifdef ACK_ASS
  157. fprintf(codefile,".define %s\n",argstr) ;
  158. #else
  159. fprintf(codefile,".globl %s\n",argstr) ;
  160. #endif
  161. break ;
  162. }
  163. }
  164. default :
  165. while ( getarg(any_ptyp) != sp_cend ) ;
  166. break ;
  167. }
  168. }
  169. char *segname[] = {
  170. #ifdef ACK_ASS
  171. ".sect .text", /* SEGTXT */
  172. ".sect .data", /* SEGCON */
  173. ".sect .rom", /* SEGROM */
  174. ".sect .bss" /* SEGBSS */
  175. #else
  176. ".text", /* SEGTXT */
  177. ".data", /* SEGCON */
  178. ".data", /* SEGROM */
  179. ".bss" /* SEGBSS */
  180. #endif
  181. };