mach.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. * See the copyright notice in the ACK home directory, in the file "Copyright".
  4. *
  5. */
  6. #ifndef NORCSID
  7. static char rcs_m[]= "$Id$" ;
  8. static char rcs_mh[]= ID_MH ;
  9. #endif
  10. /*
  11. * machine dependent back end routines for the Intel 8086
  12. */
  13. con_part(sz,w) register sz; word w; {
  14. while (part_size % sz)
  15. part_size++;
  16. if (part_size == TEM_WSIZE)
  17. part_flush();
  18. if (sz == 1) {
  19. w &= 0xFF;
  20. if (part_size)
  21. w <<= 8;
  22. part_word |= w;
  23. } else {
  24. assert(sz == 2);
  25. part_word = w;
  26. }
  27. part_size += sz;
  28. }
  29. con_mult(sz) word sz; {
  30. long l;
  31. if (sz != 4)
  32. fatal("bad icon/ucon size");
  33. l = atol(str);
  34. fprintf(codefile,"\t.data2 %d,%d\n",
  35. (int)l&0xFFFF,(int)(l>>16)&0xFFFF);
  36. }
  37. #define CODE_GENERATOR
  38. #define IEEEFLOAT
  39. #define FL_MSL_AT_LOW_ADDRESS 0
  40. #define FL_MSW_AT_LOW_ADDRESS 0
  41. #define FL_MSB_AT_LOW_ADDRESS 0
  42. #include <con_float>
  43. /*
  44. string holstr(n) word n; {
  45. sprintf(str,hol_off,n,holno);
  46. return(mystrcpy(str));
  47. }
  48. */
  49. #ifdef REGVARS
  50. full lbytes;
  51. #endif
  52. prolog(nlocals) full nlocals; {
  53. fputs("\tpush\tbp\n\tmov\tbp,sp\n", codefile);
  54. #ifdef REGVARS
  55. lbytes = nlocals;
  56. #else
  57. switch (nlocals) {
  58. case 4: fputs("\tpush\tax\n", codefile);
  59. case 2: fputs("\tpush\tax\n", codefile);
  60. case 0: break;
  61. default:
  62. fprintf(codefile, "\tsub\tsp,%d\n",nlocals); break;
  63. }
  64. #endif
  65. }
  66. #ifdef REGVARS
  67. long si_off;
  68. long di_off;
  69. int firstreg;
  70. regscore(off, size, typ, score, totyp)
  71. long off;
  72. {
  73. if (size != 2) return -1;
  74. score -= 1;
  75. score += score;
  76. if (typ == reg_pointer || typ == reg_loop) score += (score >> 2);
  77. score -= 2; /* cost of saving */
  78. if (off >= 0) score -= 3;
  79. return score;
  80. }
  81. i_regsave()
  82. {
  83. si_off = -1;
  84. di_off = -1;
  85. firstreg = 0;
  86. }
  87. f_regsave()
  88. {
  89. if (si_off != di_off) {
  90. if (di_off == -lbytes) lbytes -= 2;
  91. if (si_off == -lbytes) lbytes -= 2;
  92. if (di_off == -lbytes) lbytes -= 2;
  93. }
  94. switch (lbytes) {
  95. case 4: fputs("\tpush\tax\n", codefile);
  96. case 2: fputs("\tpush\tax\n", codefile);
  97. case 0: break;
  98. default:
  99. fprintf(codefile, "\tsub\tsp,%d\n",lbytes); break;
  100. }
  101. if (firstreg == 1) {
  102. fputs("push di\n", codefile);
  103. if (si_off != -1) fputs("push si\n", codefile);
  104. }
  105. else if (firstreg == -1) {
  106. fputs("push si\n", codefile);
  107. if (di_off != -1) fputs("push di\n", codefile);
  108. }
  109. if (di_off >= 0)
  110. fprintf(codefile, "mov di,%ld(bp)\n", di_off);
  111. if (si_off >= 0)
  112. fprintf(codefile, "mov si,%ld(bp)\n", si_off);
  113. }
  114. regsave(regstr, off, size)
  115. char *regstr;
  116. long off;
  117. {
  118. if (strcmp(regstr, "si") == 0) {
  119. if (! firstreg) firstreg = -1;
  120. si_off = off;
  121. }
  122. else {
  123. if (! firstreg) firstreg = 1;
  124. di_off = off;
  125. }
  126. }
  127. regreturn()
  128. {
  129. if (firstreg == 1) {
  130. if (si_off != -1) fputs("jmp .sdret\n", codefile);
  131. else fputs("jmp .dret\n", codefile);
  132. }
  133. else if (firstreg == -1) {
  134. if (di_off != -1) fputs("jmp .dsret\n", codefile);
  135. else fputs("jmp .sret\n", codefile);
  136. }
  137. else fputs("jmp .cret\n", codefile);
  138. }
  139. #endif /* REGVARS */
  140. mes(type) word type ; {
  141. int argt ;
  142. switch ( (int)type ) {
  143. case ms_ext :
  144. for (;;) {
  145. switch ( argt=getarg(
  146. ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
  147. case sp_cend :
  148. return ;
  149. default:
  150. strarg(argt) ;
  151. fprintf(codefile, ".define %s\n",argstr) ;
  152. break ;
  153. }
  154. }
  155. default :
  156. while ( getarg(any_ptyp) != sp_cend ) ;
  157. break ;
  158. }
  159. }
  160. char *segname[] = {
  161. ".sect .text", /* SEGTXT */
  162. ".sect .data", /* SEGCON */
  163. ".sect .rom", /* SEGROM */
  164. ".sect .bss" /* SEGBSS */
  165. };