riscv64 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // riscv64 support
  2. defn acidinit() // Called after all the init modules are loaded
  3. {
  4. bplist = {};
  5. bpfmt = 'Y';
  6. srcpath = {
  7. "./",
  8. "/sys/src/libc/port/",
  9. "/sys/src/libc/9sys/",
  10. "/sys/src/libc/riscv64/"
  11. };
  12. srcfiles = {}; // list of loaded files
  13. srctext = {}; // the text of the files
  14. }
  15. defn stk() // trace
  16. {
  17. _stk(*PC, *SP, linkreg(0), 0);
  18. }
  19. defn lstk() // trace with locals
  20. {
  21. _stk(*PC, *SP, linkreg(0), 1);
  22. }
  23. defn gpr() // print general purpose registers
  24. {
  25. print("R1\t", *R1, " R2\t", *R2, " R3\t", *R3, "\n");
  26. print("R4\t", *R4, " R5\t", *R5, " R6\t", *R6, "\n");
  27. print("R7\t", *R7, " R8\t", *R8, " R9\t", *R9, "\n");
  28. print("R10\t", *R10, " R11\t", *R11, " R12\t", *R12, "\n");
  29. print("R13\t", *R13, " R14\t", *R14, " R15\t", *R15, "\n");
  30. print("R16\t", *R16, " R17\t", *R17, " R18\t", *R18, "\n");
  31. print("R19\t", *R19, " R20\t", *R20, " R21\t", *R21, "\n");
  32. print("R22\t", *R22, " R23\t", *R23, " R24\t", *R24, "\n");
  33. print("R25\t", *R25, " R26\t", *R26, " R27\t", *R27, "\n");
  34. print("R28\t", *R28, " R29\t", *SP, " R30\t", *R30, "\n");
  35. print("R31\t", *R31, "\n");
  36. }
  37. defn Fpr()
  38. {
  39. print("F0\t", *fmt(F0, 'G'), "\tF1\t", *fmt(F1, 'G'), "\n");
  40. print("F2\t", *fmt(F2, 'G'), "\tF3\t", *fmt(F3, 'G'), "\n");
  41. print("F4\t", *fmt(F4, 'G'), "\tF5\t", *fmt(F5, 'G'), "\n");
  42. print("F6\t", *fmt(F6, 'G'), "\tF7\t", *fmt(F7, 'G'), "\n");
  43. print("F8\t", *fmt(F8, 'G'), "\tF9\t", *fmt(F9, 'G'), "\n");
  44. print("F10\t", *fmt(F10, 'G'), "\tF11\t", *fmt(F11, 'G'), "\n");
  45. print("F12\t", *fmt(F12, 'G'), "\tF13\t", *fmt(F13, 'G'), "\n");
  46. print("F14\t", *fmt(F14, 'G'), "\tF15\t", *fmt(F15, 'G'), "\n");
  47. print("F16\t", *fmt(F16, 'G'), "\tF17\t", *fmt(F17, 'G'), "\n");
  48. print("F18\t", *fmt(F18, 'G'), "\tF19\t", *fmt(F19, 'G'), "\n");
  49. print("F20\t", *fmt(F20, 'G'), "\tF21\t", *fmt(F21, 'G'), "\n");
  50. print("F22\t", *fmt(F22, 'G'), "\tF23\t", *fmt(F23, 'G'), "\n");
  51. print("F24\t", *fmt(F24, 'G'), "\tF25\t", *fmt(F25, 'G'), "\n");
  52. print("F26\t", *fmt(F26, 'G'), "\tF27\t", *fmt(F27, 'G'), "\n");
  53. print("F28\t", *fmt(F28, 'G'), "\tF29\t", *fmt(F29, 'G'), "\n");
  54. print("F30\t", *fmt(F30, 'G'), "\tF31\t", *fmt(F31, 'G'), "\n");
  55. }
  56. defn fpr()
  57. {
  58. print("F0\t", *fmt(F0, 'g'), "\tF1\t", *fmt(F1, 'g'), "\n");
  59. print("F2\t", *fmt(F2, 'g'), "\tF3\t", *fmt(F3, 'g'), "\n");
  60. print("F4\t", *fmt(F4, 'g'), "\tF5\t", *fmt(F5, 'g'), "\n");
  61. print("F6\t", *fmt(F6, 'g'), "\tF7\t", *fmt(F7, 'g'), "\n");
  62. print("F8\t", *fmt(F8, 'g'), "\tF9\t", *fmt(F9, 'g'), "\n");
  63. print("F10\t", *fmt(F10, 'g'), "\tF11\t", *fmt(F11, 'g'), "\n");
  64. print("F12\t", *fmt(F12, 'g'), "\tF13\t", *fmt(F13, 'g'), "\n");
  65. print("F14\t", *fmt(F14, 'g'), "\tF15\t", *fmt(F15, 'g'), "\n");
  66. print("F16\t", *fmt(F16, 'g'), "\tF17\t", *fmt(F17, 'g'), "\n");
  67. print("F18\t", *fmt(F18, 'g'), "\tF19\t", *fmt(F19, 'g'), "\n");
  68. print("F20\t", *fmt(F20, 'g'), "\tF21\t", *fmt(F21, 'g'), "\n");
  69. print("F22\t", *fmt(F22, 'g'), "\tF23\t", *fmt(F23, 'g'), "\n");
  70. print("F24\t", *fmt(F24, 'g'), "\tF25\t", *fmt(F25, 'g'), "\n");
  71. print("F26\t", *fmt(F26, 'g'), "\tF27\t", *fmt(F27, 'g'), "\n");
  72. print("F28\t", *fmt(F28, 'g'), "\tF29\t", *fmt(F29, 'g'), "\n");
  73. print("F30\t", *fmt(F30, 'g'), "\tF31\t", *fmt(F31, 'g'), "\n");
  74. }
  75. defn spr() // print special processor registers
  76. {
  77. local pc, link, cause;
  78. pc = *PC;
  79. print("PC\t", pc, " ", fmt(pc, 'a'), " ");
  80. pfl(pc);
  81. link = *R1;
  82. print("SP\t", *SP, "\tLINK\t", link, " ", fmt(link, 'a'), " ");
  83. pfl(link);
  84. cause = *CAUSE;
  85. print("STATUS\t", *STATUS, "\tCAUSE\t", cause, " ", reason(cause), "\n");
  86. }
  87. defn regs() // print all registers
  88. {
  89. spr();
  90. gpr();
  91. Fpr();
  92. }
  93. defn pstop(pid)
  94. {
  95. local l, pc;
  96. pc = *PC;
  97. print(pid,": ", reason(*CAUSE), "\t");
  98. print(fmt(pc, 'a'), "\t", fmt(pc, 'i'), "\n");
  99. if notes then {
  100. if notes[0] != "sys: breakpoint" then {
  101. print("Notes pending:\n");
  102. l = notes;
  103. while l do {
  104. print("\t", head l, "\n");
  105. l = tail l;
  106. }
  107. }
  108. }
  109. }
  110. sizeofUreg = 296;
  111. aggr Ureg
  112. {
  113. {
  114. 'W' 0 pc;
  115. 'a' 0 regs;
  116. };
  117. 'W' 8 r1;
  118. {
  119. 'W' 16 r2;
  120. 'W' 16 sp;
  121. 'W' 16 usp;
  122. };
  123. 'W' 24 r3;
  124. 'W' 32 r4;
  125. 'W' 40 r5;
  126. 'W' 48 r6;
  127. 'W' 56 r7;
  128. {
  129. 'W' 64 r8;
  130. 'W' 64 arg;
  131. 'W' 64 ret;
  132. };
  133. 'W' 72 r9;
  134. 'W' 80 r10;
  135. 'W' 88 r11;
  136. 'W' 96 r12;
  137. 'W' 104 r13;
  138. 'W' 112 r14;
  139. 'W' 120 r15;
  140. 'W' 128 r16;
  141. 'W' 136 r17;
  142. 'W' 144 r18;
  143. 'W' 152 r19;
  144. 'W' 160 r20;
  145. 'W' 168 r21;
  146. 'W' 176 r22;
  147. 'W' 184 r23;
  148. 'W' 192 r24;
  149. 'W' 200 r25;
  150. 'W' 208 r26;
  151. 'W' 216 r27;
  152. 'W' 224 r28;
  153. 'W' 232 r29;
  154. 'W' 240 r30;
  155. 'W' 248 r31;
  156. 'W' 256 status;
  157. 'W' 264 ie;
  158. {
  159. 'W' 272 cause;
  160. 'W' 272 type;
  161. };
  162. 'W' 280 tval;
  163. 'W' 288 curmode;
  164. };
  165. defn
  166. Ureg(addr) {
  167. complex Ureg addr;
  168. print("_32_ {\n");
  169. _32_(addr+0);
  170. print("}\n");
  171. print(" r1 ", addr.r1, "\n");
  172. print("_33_ {\n");
  173. _33_(addr+16);
  174. print("}\n");
  175. print(" r3 ", addr.r3, "\n");
  176. print(" r4 ", addr.r4, "\n");
  177. print(" r5 ", addr.r5, "\n");
  178. print(" r6 ", addr.r6, "\n");
  179. print(" r7 ", addr.r7, "\n");
  180. print("_34_ {\n");
  181. _34_(addr+64);
  182. print("}\n");
  183. print(" r9 ", addr.r9, "\n");
  184. print(" r10 ", addr.r10, "\n");
  185. print(" r11 ", addr.r11, "\n");
  186. print(" r12 ", addr.r12, "\n");
  187. print(" r13 ", addr.r13, "\n");
  188. print(" r14 ", addr.r14, "\n");
  189. print(" r15 ", addr.r15, "\n");
  190. print(" r16 ", addr.r16, "\n");
  191. print(" r17 ", addr.r17, "\n");
  192. print(" r18 ", addr.r18, "\n");
  193. print(" r19 ", addr.r19, "\n");
  194. print(" r20 ", addr.r20, "\n");
  195. print(" r21 ", addr.r21, "\n");
  196. print(" r22 ", addr.r22, "\n");
  197. print(" r23 ", addr.r23, "\n");
  198. print(" r24 ", addr.r24, "\n");
  199. print(" r25 ", addr.r25, "\n");
  200. print(" r26 ", addr.r26, "\n");
  201. print(" r27 ", addr.r27, "\n");
  202. print(" r28 ", addr.r28, "\n");
  203. print(" r29 ", addr.r29, "\n");
  204. print(" r30 ", addr.r30, "\n");
  205. print(" r31 ", addr.r31, "\n");
  206. print(" status ", addr.status, "\n");
  207. print(" ie ", addr.ie, "\n");
  208. print("_35_ {\n");
  209. _35_(addr+272);
  210. print("}\n");
  211. print(" tval ", addr.tval, "\n");
  212. print(" curmode ", addr.curmode, "\n");
  213. };
  214. defn linkreg(addr)
  215. {
  216. complex Ureg addr;
  217. return addr.r1\Y;
  218. }
  219. print("/sys/lib/acid/riscv64");