mach4.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* $Header$ */
  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. /* @(#)mach4.c 1.11 */
  7. /*
  8. * Motorola 68000/68010 syntax rules
  9. */
  10. operation
  11. : bcdx DREG ',' DREG
  12. { emit2($1 | $2 | $4<<9);}
  13. | bcdx '-' '(' AREG ')' ',' '-' '(' AREG ')'
  14. { emit2($1 | $4 | $9<<9 | 010);}
  15. | ADD sizedef ea_ea
  16. { add($1, $2);}
  17. | AND sizenon ea_ea
  18. { and($1, $2);}
  19. | SHIFT sizedef ea_ea
  20. { shift_op($1, $2);}
  21. | BR expr
  22. { branch($1, $2);}
  23. | DBR DREG ',' expr
  24. { $4.val -= (DOTVAL+2);
  25. fit(fitw($4.val));
  26. emit2($1 | $2);
  27. #ifdef RELOCATION
  28. newrelo($4.typ, RELPC|RELO2|RELBR|RELWR);
  29. #endif
  30. emit2(loww($4.val));
  31. }
  32. | BITOP ea_ea
  33. { bitop($1);}
  34. | OP_EA_D ea ',' DREG
  35. { emit2($1 | mrg_2 | $4<<9);
  36. ea_2(SIZE_W, DTA);
  37. }
  38. | LEA ea ',' AREG
  39. { emit2(040700 | mrg_2 | $4<<9);
  40. ea_2(SIZE_L, CTR);
  41. }
  42. | op_ea ea
  43. { emit2(($1&0177700) | mrg_2);
  44. ea_2($1&0300, $1&017);
  45. }
  46. | OP_NOOP
  47. { emit2($1);}
  48. | CMP sizedef ea_ea
  49. { cmp($2);}
  50. | MOVE sizenon ea_ea
  51. { move($2);}
  52. | MOVEP sizedef ea_ea
  53. { movep($2);}
  54. | MOVEM sizedef regs ',' notimmreg
  55. { movem(0, $2, $3);}
  56. | MOVEM sizedef notimmreg ',' regs
  57. { movem(1, $2, $5);}
  58. | MOVES sizedef ea_ea
  59. { test68010();
  60. if (mrg_1 <= 017) {
  61. emit2(007000 | $2 | mrg_2);
  62. emit2(mrg_1 << 12 | 04000);
  63. ea_2($2,ALT|MEM);
  64. } else if (mrg_2 <= 017) {
  65. emit2(007000 | $2 | mrg_1);
  66. emit2(mrg_2 << 12);
  67. ea_1($2,ALT|MEM);
  68. } else
  69. badoperand();
  70. }
  71. | MOVEC creg ',' reg
  72. { test68010();
  73. emit2(047172); emit2($2 | $4<<12);
  74. }
  75. | MOVEC reg ',' creg
  76. { test68010();
  77. emit2(047173); emit2($4 | $2<<12);
  78. }
  79. | EXG reg ',' reg
  80. { if (($2 & 010) == 0)
  81. emit2(
  82. (0140500|$4|$2<<9)
  83. +
  84. (($4&010)<<3)
  85. );
  86. else
  87. emit2(
  88. (0140600|$2|($4&07)<<9)
  89. -
  90. (($4&010)<<3)
  91. );
  92. }
  93. | OP_EXT sizedef DREG
  94. { checksize($2, 2|4); emit2(044000 | $2+0100 | $3);}
  95. | SWAP DREG
  96. { emit2(044100 | $2);}
  97. | STOP imm
  98. { emit2($1); ea_2(SIZE_W, 0);}
  99. | LINK AREG ',' imm
  100. { emit2(047120 | $2); ea_2(SIZE_W, 0);}
  101. | UNLK AREG
  102. { emit2(047130 | $2);}
  103. | TRAP '#' absexp
  104. { fit(fit4($3)); emit2(047100|low4($3));}
  105. | RTD imm
  106. { test68010();
  107. emit2(047164);
  108. ea_2(SIZE_W, 0);
  109. }
  110. | MODEL
  111. { model = $1;}
  112. ;
  113. bcdx : ABCD
  114. | ADDX sizedef
  115. { $$ = $1 | $2;}
  116. ;
  117. creg : CREG
  118. | SPEC { if ($1 != 075) badoperand(); $$ = 04000;}
  119. ;
  120. op_ea : OP_EA
  121. | SZ_EA sizedef
  122. { $$ = $1 | $2;}
  123. ;
  124. regs : rrange
  125. | regs '/' rrange
  126. { $$ = $1 | $3;}
  127. ;
  128. rrange : reg
  129. { $$ = 1<<$1;}
  130. | reg '-' reg
  131. { if ($1 > $3)
  132. badoperand();
  133. for ($$ = 0; $1 <= $3; $1++)
  134. $$ |= (1<<$1);
  135. }
  136. ;
  137. ea : DREG
  138. { mrg_2 = $1;}
  139. | AREG
  140. { mrg_2 = 010 | $1;}
  141. | SPEC
  142. { mrg_2 = $1;}
  143. | notimmreg
  144. | imm
  145. ;
  146. notimmreg
  147. : '(' AREG ')'
  148. { mrg_2 = 020 | $2;}
  149. | '(' AREG ')' '+'
  150. { mrg_2 = 030 | $2;}
  151. | '-' '(' AREG ')'
  152. { mrg_2 = 040 | $3;}
  153. | expr sizenon
  154. { exp_2 = $1; ea707172($2);
  155. RELOMOVE(rel_2, relonami);
  156. }
  157. | expr '(' reg sizenon ')'
  158. { exp_2 = $1; ea5x73($3, $4);
  159. RELOMOVE(rel_2, relonami);
  160. }
  161. | expr '(' AREG ',' reg sizedef ')'
  162. { exp_2 = $1; ea6x($3, $5, $6);
  163. RELOMOVE(rel_2, relonami);
  164. }
  165. | expr '(' PC ')'
  166. { exp_2 = $1; ea72();
  167. RELOMOVE(rel_2, relonami);
  168. }
  169. | expr '(' PC ',' reg sizedef ')'
  170. { exp_2 = $1; ea73($5, $6);
  171. RELOMOVE(rel_2, relonami);
  172. }
  173. ;
  174. imm : '#' expr
  175. { mrg_2 = 074; exp_2 = $2;
  176. RELOMOVE(rel_2, relonami);
  177. }
  178. ;
  179. reg : DREG
  180. | AREG
  181. { $$ = $1 | 010;}
  182. ;
  183. sizedef : /* empty */
  184. { $$ = SIZE_DEF;}
  185. | SIZE
  186. ;
  187. sizenon : /* empty */
  188. { $$ = SIZE_NON;}
  189. | SIZE
  190. ;
  191. ea_ea : ea ','
  192. { mrg_1 = mrg_2; exp_1 = exp_2;
  193. RELOMOVE(rel_1, rel_2);
  194. }
  195. ea
  196. ;