mach.c 3.3 KB

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