mach4.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #define RCSID4 "$Id$"
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. *
  6. */
  7. /*
  8. * Mostek 6500 parsing tables.
  9. */
  10. /* From the READ_ME file - translation by Albert Koelmans:
  11. * ________________
  12. *
  13. * De .h en .l extensions van expressies zijn hard nodig.
  14. * Ze zorgen er echter ook voor dat er geen relocatable code geproduceerd
  15. * kan worden. Beschouw het volgende voorbeeld:
  16. *
  17. * The .h and .l extensions of expressions are vital. However, they prevent
  18. * relocatable code from being generated. Consider the following example:
  19. *
  20. * (file 1)
  21. * .sect .text ! 1
  22. * lda #[endbss].l ! 2
  23. * ldx #[endbss].h ! 3
  24. *
  25. * (file 2)
  26. * .sect .bss ! 4
  27. * endbss: ! 5
  28. *
  29. * Wat voor relocation struct moet er nu voor de instructie in regel 3
  30. * worden geproduceerd?
  31. *
  32. * What kind of relocation structure needs to be generated for the instruction
  33. * in line 3?
  34. */
  35. expr
  36. : expr EXTENSION
  37. { $$.val = ($1.val >> $2) & 0xFF;
  38. #ifdef RELOCATION
  39. $$.typ = combine($1.typ, S_ABS, '&');
  40. /* This will generate an 'invalid operator' */
  41. /* error if $1.typ is not absolute after pass 1. */
  42. #else
  43. $$.typ = $1.typ; /* Even if $1.typ is relocatable, it should be */
  44. /* absolute by the final pass. */
  45. #endif /* RELOCATION */
  46. }
  47. ;
  48. operation
  49. : NOPOP
  50. { emit1($1); }
  51. | BITOP expr
  52. { code($2,$1,$1+8); }
  53. | JMPOP expr
  54. { emit1($1);
  55. #ifdef RELOCATION
  56. newrelo($2.typ, RELO2);
  57. #endif
  58. emit2($2.val);
  59. }
  60. | JMPOP '(' expr ')'
  61. { emit1($1+0x20);
  62. #ifdef RELOCATION
  63. newrelo($3.typ, RELO2);
  64. #endif
  65. emit2($3.val);
  66. }
  67. | JSROP expr
  68. { emit1($1);
  69. #ifdef RELOCATION
  70. newrelo($2.typ, RELO2);
  71. #endif
  72. emit2($2.val);
  73. }
  74. | LDXOP '#' expr
  75. { emit1(0xA2);
  76. #ifdef RELOCATION
  77. newrelo($3.typ, RELO1);
  78. #endif
  79. emit1($3.val);
  80. }
  81. | LDXOP expr
  82. { code($2,0xA6,0xAE); }
  83. | LDXOP expr ',' Y
  84. { code($2,0xB6,0xBE); }
  85. | LDYOP '#' expr
  86. { emit1(0xA0);
  87. #ifdef RELOCATION
  88. newrelo($3.typ, RELO1);
  89. #endif
  90. emit1($3.val);
  91. }
  92. | LDYOP expr
  93. { code($2,0xA4,0xAC); }
  94. | LDYOP expr ',' X
  95. { code($2,0xB4,0xBC); }
  96. | STXOP expr
  97. { code($2,$1+0x06,$1+0x0E); }
  98. | STXOP expr ',' Y
  99. { emit1($1+0x16);
  100. #ifdef RELOCATION
  101. newrelo($2.typ, RELO1);
  102. #endif
  103. emit1(lowb($2.val));
  104. }
  105. | STYOP expr
  106. { code($2,$1+0x04,$1+0x0C); }
  107. | STYOP expr ',' X
  108. { emit1($1+0x14);
  109. #ifdef RELOCATION
  110. newrelo($2.typ, RELO1);
  111. #endif
  112. emit1(lowb($2.val));
  113. }
  114. | addop '#' expr
  115. { if ($1==0x80) serror("no store immediate");
  116. emit1($1+0x09);
  117. #ifdef RELOCATION
  118. newrelo($3.typ, RELO1);
  119. #endif
  120. emit1($3.val);
  121. }
  122. | addop expr
  123. { code($2,$1+0x05,$1+0x0D); }
  124. | addop expr ',' X
  125. { code($2,$1+0x15,$1+0x1D); }
  126. | addop expr ',' Y
  127. { emit1($1+0x19);
  128. #ifdef RELOCATION
  129. newrelo($2.typ, RELO2);
  130. #endif
  131. emit2($2.val);
  132. }
  133. | addop '(' expr ',' X ')'
  134. { emit1($1+0x01);
  135. #ifdef RELOCATION
  136. newrelo($3.typ, RELO1);
  137. #endif
  138. emit1(lowb($3.val));
  139. }
  140. | addop '(' expr ')' ',' Y
  141. { emit1($1+0x11);
  142. #ifdef RELOCATION
  143. newrelo($3.typ, RELO1);
  144. #endif
  145. emit1(lowb($3.val));
  146. }
  147. | ROLOP /* Default is A. */
  148. { emit1($1+0x0A); }
  149. | ROLOP A
  150. { emit1($1+0x0A); }
  151. | ROLOP expr
  152. { code($2,$1+0x06,$1+0x0E); }
  153. | ROLOP expr ',' X
  154. { code($2,$1+0x16,$1+0x1E); }
  155. | BRAOP expr
  156. { branch($1,$2); }
  157. | CPXOP '#' expr
  158. { emit1($1+0x00);
  159. #ifdef RELOCATION
  160. newrelo($3.typ, RELO1);
  161. #endif
  162. emit1($3.val);
  163. }
  164. | CPXOP expr
  165. { code($2,$1+0x04,$1+0x0C); }
  166. | INCOP expr
  167. { code($2,$1+0x06,$1+0x0E); }
  168. | INCOP expr ',' X
  169. { code($2,$1+0x16,$1+0x1E); }
  170. ;
  171. addop
  172. : ADDOP
  173. | PSEU
  174. { emit1($1>>8); $$ = $1 & 0xFF; }
  175. ;