m16e.igen 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. // -*- C -*-
  2. // Simulator definition for the MIPS16e instructions.
  3. // Copyright (C) 2005-2022 Free Software Foundation, Inc.
  4. // Contributed by Nigel Stephens (nigel@mips.com) and
  5. // David Ung (davidu@mips.com) of MIPS Technologies.
  6. //
  7. // This file is part of GDB, the GNU debugger.
  8. //
  9. // This program is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU General Public License as published by
  11. // the Free Software Foundation; either version 3 of the License, or
  12. // (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. 11101,3.RX,100,10001:RR:16::SEB
  22. "seb r<TRX>"
  23. *mips16e:
  24. {
  25. TRACE_ALU_INPUT1 (GPR[TRX]);
  26. GPR[TRX] = EXTEND8 (GPR[TRX]);
  27. TRACE_ALU_RESULT (GPR[TRX]);
  28. }
  29. 11101,3.RX,101,10001:RR:16::SEH
  30. "seh r<TRX>"
  31. *mips16e:
  32. {
  33. TRACE_ALU_INPUT1 (GPR[TRX]);
  34. GPR[TRX] = EXTEND16 (GPR[TRX]);
  35. TRACE_ALU_RESULT (GPR[TRX]);
  36. }
  37. 11101,3.RX,110,10001:RR:16::SEW
  38. "sew r<TRX>"
  39. *mips16e:
  40. {
  41. check_u64 (SD_, instruction_0);
  42. TRACE_ALU_INPUT1 (GPR[TRX]);
  43. GPR[TRX] = EXTEND32 (GPR[TRX]);
  44. TRACE_ALU_RESULT (GPR[TRX]);
  45. }
  46. 11101,3.RX,000,10001:RR:16::ZEB
  47. "zeb r<TRX>"
  48. *mips16e:
  49. {
  50. TRACE_ALU_INPUT1 (GPR[TRX]);
  51. GPR[TRX] = (unsigned_word)(uint8_t)(GPR[TRX]);
  52. TRACE_ALU_RESULT (GPR[TRX]);
  53. }
  54. 11101,3.RX,001,10001:RR:16::ZEH
  55. "zeh r<TRX>"
  56. *mips16e:
  57. {
  58. TRACE_ALU_INPUT1 (GPR[TRX]);
  59. GPR[TRX] = (unsigned_word)(uint16_t)(GPR[TRX]);
  60. TRACE_ALU_RESULT (GPR[TRX]);
  61. }
  62. 11101,3.RX,010,10001:RR:16::ZEW
  63. "zew r<TRX>"
  64. *mips16e:
  65. {
  66. check_u64 (SD_, instruction_0);
  67. TRACE_ALU_INPUT1 (GPR[TRX]);
  68. GPR[TRX] = (unsigned_word)(uint32_t)(GPR[TRX]);
  69. TRACE_ALU_RESULT (GPR[TRX]);
  70. }
  71. 11101,3.RX,100,00000:RR:16::JRC
  72. "jrc r<TRX>"
  73. *mips16e:
  74. {
  75. NIA = GPR[TRX];
  76. }
  77. 11101,000,101,00000:RR:16::JRCRA
  78. "jrc ra"
  79. *mips16e:
  80. {
  81. NIA = RA;
  82. }
  83. 11101,3.RX,110,00000:RR:16::JALRC
  84. "jalrc r<TRX>"
  85. *mips16e:
  86. {
  87. RA = NIA;
  88. NIA = GPR[TRX];
  89. }
  90. // format routines for save/restore
  91. :%s::::RAS:int ras
  92. *mips16e
  93. {
  94. static char buf[10];
  95. buf[0] = '\0';
  96. if (ras & 4)
  97. strcat (buf,"ra,");
  98. if (ras & 2)
  99. strcat (buf,"s0,");
  100. if (ras & 1)
  101. strcat (buf,"s1,");
  102. return (buf);
  103. }
  104. :%s::::XSREGS:int xsregs
  105. *mips16e
  106. {
  107. if (xsregs > 6)
  108. return "s2,s3,s4,s5,s6,s7,s8,";
  109. if (xsregs > 5)
  110. return "s2,s3,s4,s5,s6,s7,";
  111. if (xsregs > 4)
  112. return "s2,s3,s4,s5,s6,";
  113. if (xsregs > 3)
  114. return "s2,s3,s4,s5,";
  115. if (xsregs > 2)
  116. return "s2,s3,s4,";
  117. if (xsregs > 1)
  118. return "s2,s3,";
  119. if (xsregs > 0)
  120. return "s2,";
  121. return "";
  122. }
  123. :%s::::AREGS:int aregs
  124. *mips16e
  125. {
  126. // Fixme: how is the arg/static distinction made by the assembler?
  127. static const char * const aregstr[16] = {
  128. "",
  129. "A3,",
  130. "A2,A3,",
  131. "A1,A2,A3,",
  132. "A0,A1,A2,A3,",
  133. "a0,",
  134. "a0,A3,",
  135. "a0,A2,A3,",
  136. "a0,A1,A2,A3,",
  137. "a0,a1,",
  138. "a0,a1,A3,",
  139. "a0,a1,A2,A3,",
  140. "a0,a1,a2,",
  141. "a0,a1,a2,A3,",
  142. "?,"
  143. };
  144. return aregstr[aregs];
  145. }
  146. :compute:::int:SFRAME:FS:((FS == 0) ? 128 \: (FS << 3))
  147. :compute:::int:BFRAME:FSHI,FSLO:(((FSHI << 4) | FSLO) << 3)
  148. :function:::void:do_save:int xsregs, int aregs, int ras0s1, int framesize
  149. {
  150. unsigned_word temp;
  151. int args, astatic;
  152. temp = GPR[29];
  153. /* writes are in the same order as the hardware description... */
  154. switch (aregs) {
  155. case 0: case 1: case 2: case 3: case 11:
  156. args = 0;
  157. break;
  158. case 4: case 5: case 6: case 7:
  159. args = 1;
  160. break;
  161. case 8: case 9: case 10:
  162. args = 2;
  163. break;
  164. case 12: case 13:
  165. args = 3;
  166. break;
  167. case 14:
  168. args = 4;
  169. break;
  170. default:
  171. sim_engine_abort (SD, CPU, CIA, "save: aregs=%d causes unpredictable results\n", aregs);
  172. }
  173. if (args > 0) {
  174. do_store (SD_, AccessLength_WORD, temp, 0, GPR[4]);
  175. if (args > 1) {
  176. do_store (SD_,AccessLength_WORD, temp, 4 , GPR[5]);
  177. if (args > 2) {
  178. do_store (SD_,AccessLength_WORD, temp, 8 , GPR[6]);
  179. if (args > 3) {
  180. do_store (SD_,AccessLength_WORD, temp, 12, GPR[7]);
  181. }
  182. }
  183. }
  184. }
  185. if (ras0s1 & 4)
  186. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[31]);
  187. switch (xsregs) {
  188. case 7:
  189. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[30]);
  190. case 6:
  191. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[23]);
  192. case 5:
  193. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[22]);
  194. case 4:
  195. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[21]);
  196. case 3:
  197. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[20]);
  198. case 2:
  199. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[19]);
  200. case 1:
  201. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[18]);
  202. }
  203. if (ras0s1 & 1)
  204. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[17]);
  205. if (ras0s1 & 2)
  206. do_store (SD_,AccessLength_WORD, temp -= 4, 0, GPR[16]);
  207. switch (aregs) {
  208. case 0: case 4: case 8: case 12: case 14:
  209. astatic = 0;
  210. break;
  211. case 1: case 5: case 9: case 13:
  212. astatic = 1;
  213. break;
  214. case 2: case 6: case 10:
  215. astatic = 2;
  216. break;
  217. case 3: case 7:
  218. astatic = 3;
  219. break;
  220. case 11:
  221. astatic = 4;
  222. break;
  223. default:
  224. sim_engine_abort (SD, CPU, CIA, "save: aregs=%d causes unpredictable results\n", aregs);
  225. }
  226. if (astatic > 0) {
  227. do_store (SD_, AccessLength_WORD, temp -= 4, 0, GPR[7]);
  228. if (astatic > 1) {
  229. do_store (SD_, AccessLength_WORD, temp -= 4, 0, GPR[6]);
  230. if (astatic > 2) {
  231. do_store (SD_, AccessLength_WORD, temp -= 4, 0, GPR[5]);
  232. if (astatic > 3) {
  233. do_store (SD_, AccessLength_WORD, temp -= 4, 0, GPR[4]);
  234. }
  235. }
  236. }
  237. }
  238. GPR[29] -= framesize;
  239. }
  240. 01100,100,1,3.RAS,4.FS:I8:16::SAVE
  241. "save %s<RAS>,<SFRAME>"
  242. *mips16e
  243. {
  244. do_save (SD_, 0, 0, RAS, SFRAME);
  245. }
  246. 11110,3.XSREGS,4.FSHI,4.AREGS + 01100,100,1,3.RAS,4.FSLO:EXT-I8:16::SAVE
  247. "save %s<RAS>%s<XSREGS>%s<AREGS><BFRAME>"
  248. *mips16e
  249. {
  250. do_save (SD_, XSREGS, AREGS, RAS, BFRAME);
  251. }
  252. :function:::void:do_restore:int xsregs, int aregs, int ras0s1, int framesize
  253. *mips16e
  254. {
  255. unsigned_word temp, temp2;
  256. int astatic;
  257. temp = GPR[29] + framesize;
  258. temp2 = temp;
  259. /* reads are in the same order as the hardware description... */
  260. if (ras0s1 & 4)
  261. GPR[31] = EXTEND32 (do_load(SD_, AccessLength_WORD, temp -= 4, 0));
  262. switch (xsregs) {
  263. case 7:
  264. GPR[30] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  265. case 6:
  266. GPR[23] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  267. case 5:
  268. GPR[22] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  269. case 4:
  270. GPR[21] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  271. case 3:
  272. GPR[20] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  273. case 2:
  274. GPR[19] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  275. case 1:
  276. GPR[18] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  277. }
  278. if (ras0s1 & 1)
  279. GPR[17] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  280. if (ras0s1 & 2)
  281. GPR[16] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  282. switch (aregs) {
  283. case 0: case 4: case 8: case 12: case 14:
  284. astatic = 0;
  285. break;
  286. case 1: case 5: case 9: case 13:
  287. astatic = 1;
  288. break;
  289. case 2: case 6: case 10:
  290. astatic = 2;
  291. break;
  292. case 3: case 7:
  293. astatic = 3;
  294. break;
  295. case 11:
  296. astatic = 4;
  297. break;
  298. default:
  299. sim_engine_abort (SD, CPU, CIA, "save: aregs=%d causes unpredictable results\n", aregs);
  300. }
  301. if (astatic > 0) {
  302. GPR[7] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  303. if (astatic > 1) {
  304. GPR[6] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  305. if (astatic > 2) {
  306. GPR[5] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  307. if (astatic > 3) {
  308. GPR[4] = EXTEND32 (do_load (SD_,AccessLength_WORD, temp -= 4, 0));
  309. }
  310. }
  311. }
  312. }
  313. GPR[29] = temp2;
  314. }
  315. 01100,100,0,3.RAS,4.FS:I8:16::RESTORE
  316. "restore %s<RAS>,<SFRAME>"
  317. *mips16e
  318. {
  319. do_restore (SD_,0,0,RAS,SFRAME);
  320. }
  321. 11110,3.XSREGS,4.FSHI,4.AREGS + 01100,100,0,3.RAS,4.FSLO:EXT-I8:16::RESTORE
  322. "restore %s<RAS>%s<XSREGS>%s<AREGS><BFRAME>"
  323. *mips16e
  324. {
  325. do_restore (SD_,XSREGS,AREGS,RAS,BFRAME);
  326. }