run.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <mach.h>
  13. #define Extern extern
  14. #include "power.h"
  15. void lfs(ulong);
  16. void lfd(ulong);
  17. void stfs(ulong);
  18. void stfd(ulong);
  19. /* indexed versions are in 31 */
  20. void addic(ulong);
  21. void addiccc(ulong);
  22. void addi(ulong);
  23. void addis(ulong);
  24. void andicc(ulong);
  25. void andiscc(ulong);
  26. void bcx(ulong);
  27. void bx(ulong);
  28. void cmpi(ulong);
  29. void cmpli(ulong);
  30. void lbz(ulong);
  31. void lha(ulong);
  32. void lhz(ulong);
  33. void lmw(ulong);
  34. void lwz(ulong);
  35. void mulli(ulong);
  36. void ori(ulong);
  37. void oris(ulong);
  38. void rlwimi(ulong);
  39. void rlwinm(ulong);
  40. void rlwnm(ulong);
  41. void sc(ulong);
  42. void stb(ulong);
  43. void sth(ulong);
  44. void stmw(ulong);
  45. void stw(ulong);
  46. void subfic(ulong);
  47. void twi(ulong);
  48. void xori(ulong);
  49. void xoris(ulong);
  50. Inst op0[] = {
  51. [3] {twi, "twi", Ibranch},
  52. [7] {mulli, "mulli", Iarith},
  53. [8] {subfic, "subfic", Iarith},
  54. [10] {cmpli, "cmpli", Iarith},
  55. [11] {cmpi, "cmpi", Iarith},
  56. [12] {addic, "addic", Iarith},
  57. [13] {addiccc, "addic.", Iarith},
  58. [14] {addi, "addi", Iarith},
  59. [15] {addis, "addis", Iarith},
  60. [16] {bcx, "bc⋯", Ibranch},
  61. [17] {sc, "sc", Isyscall},
  62. [18] {bx, "b⋯", Ibranch},
  63. /* group 19; branch unit */
  64. [20] {rlwimi, "rlwimi", Ilog},
  65. [21] {rlwinm, "rlwinm", Ilog},
  66. [23] {rlwnm, "rlwnm", Ilog},
  67. [24] {ori, "ori", Ilog},
  68. [25] {oris, "oris", Ilog},
  69. [26] {xori, "xori", Ilog},
  70. [27] {xoris, "xoris", Ilog},
  71. [28] {andicc, "andi.", Ilog},
  72. [29] {andiscc, "andis.", Ilog},
  73. /* group 31; integer & misc. */
  74. [32] {lwz, "lwz", Iload},
  75. [33] {lwz, "lwzu", Iload},
  76. [34] {lbz, "lbz", Iload},
  77. [35] {lbz, "lbzu", Iload},
  78. [36] {stw, "stw", Istore},
  79. [37] {stw, "stwu", Istore},
  80. [38] {stb, "stb", Istore},
  81. [39] {stb, "stbu", Istore},
  82. [40] {lhz, "lhz", Iload},
  83. [41] {lhz, "lhzu", Iload},
  84. [42] {lha, "lha", Iload},
  85. [43] {lha, "lhau", Iload},
  86. [44] {sth, "sth", Istore},
  87. [45] {sth, "sthu", Istore},
  88. [46] {lmw, "lmw", Iload},
  89. [47] {stmw, "stmw", Istore},
  90. [48] {lfs, "lfs", Iload},
  91. [49] {lfs, "lfsu", Iload},
  92. [50] {lfd, "lfd", Iload},
  93. [51] {lfd, "lfdu", Iload},
  94. [52] {stfs, "stfs", Istore},
  95. [53] {stfs, "stfsu", Istore},
  96. [54] {stfd, "stfd", Istore},
  97. [55] {stfd, "stfdu", Istore},
  98. /* group 59; single precision floating point */
  99. /* group 63; double precision floating point; fpscr */
  100. {0, 0, 0},
  101. };
  102. Inset ops0 = {op0, nelem(op0)-1};
  103. static char oemflag[] = {
  104. [104] 1,
  105. [10] 1,
  106. [136] 1,
  107. [138] 1,
  108. [200] 1,
  109. [202] 1,
  110. [232] 1,
  111. [234] 1,
  112. [235] 1,
  113. [266] 1,
  114. [40] 1,
  115. [459] 1,
  116. [491] 1,
  117. [8] 1,
  118. };
  119. void
  120. run(void)
  121. {
  122. int xo, f;
  123. do {
  124. reg.ir = ifetch(reg.pc);
  125. ci = 0;
  126. switch(reg.ir>>26) {
  127. default:
  128. xo = reg.ir>>26;
  129. if(xo >= nelem(op0))
  130. break;
  131. ci = &op0[xo];
  132. break;
  133. case 19:
  134. xo = getxo(reg.ir);
  135. if(xo >= ops19.nel)
  136. break;
  137. ci = &ops19.tab[xo];
  138. break;
  139. case 31:
  140. xo = getxo(reg.ir);
  141. f = xo & ~getxo(OE);
  142. if(reg.ir&OE && f < sizeof(oemflag) && oemflag[f])
  143. xo = f;
  144. if(xo >= ops31.nel)
  145. break;
  146. ci = &ops31.tab[xo];
  147. break;
  148. case 59:
  149. xo = getxo(reg.ir) & 0x1F;
  150. if(xo >= ops59.nel)
  151. break;
  152. ci = &ops59.tab[xo];
  153. break;
  154. case 63:
  155. xo = getxo(reg.ir) & 0x1F;
  156. if(xo < ops63a.nel) {
  157. ci = &ops63a.tab[xo];
  158. if(ci->func || ci->name)
  159. break;
  160. ci = 0;
  161. }
  162. xo = getxo(reg.ir);
  163. if(xo >= ops63b.nel)
  164. break;
  165. ci = &ops63b.tab[xo];
  166. break;
  167. }
  168. if(ci && ci->func){
  169. ci->count++;
  170. (*ci->func)(reg.ir);
  171. } else {
  172. if(ci && ci->name && trace)
  173. itrace("%s\t[not yet done]", ci->name);
  174. else
  175. undef(reg.ir);
  176. }
  177. reg.pc += 4;
  178. if(bplist)
  179. brkchk(reg.pc, Instruction);
  180. }while(--count);
  181. }
  182. void
  183. ilock(int)
  184. {
  185. }
  186. void
  187. undef(uint32_t ir)
  188. {
  189. /* Bprint(bioout, "op=%d op2=%d op3=%d\n", ir>>30, (ir>>21)&0x7, (ir>>19)&0x3f); */
  190. Bprint(bioout, "illegal_instruction IR #%.8lux (op=%ld/%ld, pc=#%.8lux)\n", ir, getop(ir), getxo(ir), reg.pc);
  191. if(ci && ci->name && ci->func==0)
  192. Bprint(bioout, "(%s not yet implemented)\n", ci->name);
  193. longjmp(errjmp, 0);
  194. }
  195. void
  196. unimp(uint32_t ir)
  197. {
  198. /* Bprint(bioout, "op=%d op2=%d op3=%d\n", ir>>30, (ir>>21)&0x7, (ir>>19)&0x3f); */
  199. Bprint(bioout, "illegal_instruction IR #%.8lux (op=%ld/%ld, pc=#%.8lux) %s not in MPC601\n", ir, getop(ir), getxo(ir), reg.pc, ci->name?ci->name: "-");
  200. longjmp(errjmp, 0);
  201. }