mips.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * mipsim.h
  3. */
  4. #include "/mips/include/ureg.h"
  5. #define USERADDR 0xC0000000
  6. #define UREGADDR (USERADDR+BY2PG-4-0xA0)
  7. #define USER_REG(x) (UREGADDR+(ulong)(x))
  8. #define REGOFF(x) (USER_REG(&((struct Ureg *) 0)->x))
  9. typedef struct Registers Registers;
  10. typedef struct Segment Segment;
  11. typedef struct Memory Memory;
  12. typedef struct Mul Mul;
  13. typedef struct Mulu Mulu;
  14. typedef struct Inst Inst;
  15. typedef struct Icache Icache;
  16. typedef struct Tlb Tlb;
  17. typedef struct Breakpoint Breakpoint;
  18. enum
  19. {
  20. Instruction = 1,
  21. Read = 2,
  22. Write = 4,
  23. Access = 2|4,
  24. Equal = 4|8,
  25. };
  26. struct Breakpoint
  27. {
  28. int type; /* Instruction/Read/Access/Write/Equal */
  29. ulong addr; /* Place at address */
  30. int count; /* To execute count times or value */
  31. int done; /* How many times passed through */
  32. Breakpoint *next; /* Link to next one */
  33. };
  34. enum
  35. {
  36. Iload,
  37. Istore,
  38. Iarith,
  39. Ibranch,
  40. Ireg,
  41. Isyscall,
  42. Ifloat,
  43. };
  44. enum
  45. {
  46. Nmaxtlb = 64,
  47. };
  48. struct Tlb
  49. {
  50. int on; /* Being updated */
  51. int tlbsize; /* Number of entries */
  52. ulong tlbent[Nmaxtlb]; /* Virtual address tags */
  53. int hit; /* Number of successful tag matches */
  54. int miss; /* Number of failed tag matches */
  55. };
  56. struct Icache
  57. {
  58. int on; /* Turned on */
  59. int linesize; /* Line size in bytes */
  60. int stall; /* Cache stalls */
  61. int *lines; /* Tag array */
  62. int* (*hash)(ulong); /* Hash function */
  63. char *hashtext; /* What the function looks like */
  64. };
  65. struct Inst
  66. {
  67. void (*func)(ulong);
  68. char *name;
  69. int type;
  70. int count;
  71. int taken;
  72. int useddelay;
  73. };
  74. struct Registers
  75. {
  76. ulong pc;
  77. ulong ir;
  78. Inst *ip;
  79. long r[32];
  80. ulong mhi;
  81. ulong mlo;
  82. ulong fpsr;
  83. union {
  84. double fd[16];
  85. float fl[32];
  86. ulong di[32];
  87. };
  88. char ft[32];
  89. };
  90. enum
  91. {
  92. FPd = 0,
  93. FPs,
  94. FPmemory,
  95. };
  96. #define dreg(r) ((r)>>1)
  97. struct Mulu
  98. {
  99. ulong lo;
  100. ulong hi;
  101. };
  102. struct Mul
  103. {
  104. long lo;
  105. long hi;
  106. };
  107. enum
  108. {
  109. MemRead,
  110. MemReadstring,
  111. MemWrite,
  112. };
  113. enum
  114. {
  115. Stack,
  116. Text,
  117. Data,
  118. Bss,
  119. Nseg,
  120. };
  121. struct Segment
  122. {
  123. short type;
  124. ulong base;
  125. ulong end;
  126. ulong fileoff;
  127. ulong fileend;
  128. int rss;
  129. int refs;
  130. uchar **table;
  131. };
  132. struct Memory
  133. {
  134. Segment seg[Nseg];
  135. };
  136. void fatal(int, char*, ...);
  137. void run(void);
  138. void undef(ulong);
  139. void dumpreg(void);
  140. void dumpfreg(void);
  141. void dumpdreg(void);
  142. void* emalloc(ulong);
  143. void* erealloc(void*, ulong, ulong);
  144. void* vaddr(ulong);
  145. int badvaddr(ulong, int);
  146. void itrace(char *, ...);
  147. void segsum(void);
  148. void Ssyscall(ulong);
  149. char* memio(char*, ulong, int, int);
  150. ulong ifetch(ulong);
  151. ulong getmem_w(ulong);
  152. ushort getmem_h(ulong);
  153. void putmem_w(ulong, ulong);
  154. uchar getmem_b(ulong);
  155. void putmem_b(ulong, uchar);
  156. ulong getmem_4(ulong);
  157. ulong getmem_2(ulong);
  158. void putmem_h(ulong, short);
  159. Mul mul(long, long);
  160. Mulu mulu(ulong, ulong);
  161. void isum(void);
  162. void initicache(void);
  163. void updateicache(ulong addr);
  164. void tlbsum(void);
  165. long lnrand(long);
  166. void randseed(long, long);
  167. void cmd(void);
  168. void brkchk(ulong, int);
  169. void delbpt(char*);
  170. void breakpoint(char*, char*);
  171. char* nextc(char*);
  172. ulong expr(char*);
  173. void initmap(void);
  174. void inithdr(int);
  175. void initstk(int, char**);
  176. void reset(void);
  177. void dobplist(void);
  178. int _mipscoinst(Map*, uvlong, char*, int);
  179. void procinit(int);
  180. void printsource(long);
  181. void printparams(Symbol *, ulong);
  182. void printlocals(Symbol *, ulong);
  183. void stktrace(int);
  184. void iprofile(void);
  185. /* Globals */
  186. Extern Registers reg;
  187. Extern Memory memory;
  188. Extern int text;
  189. Extern int trace;
  190. Extern int sysdbg;
  191. Extern int calltree;
  192. Extern Inst itab[];
  193. Extern Inst ispec[];
  194. Extern Icache icache;
  195. Extern Tlb tlb;
  196. Extern int count;
  197. Extern jmp_buf errjmp;
  198. Extern Breakpoint *bplist;
  199. Extern int atbpt;
  200. Extern int membpt;
  201. Extern int cmdcount;
  202. Extern int nopcount;
  203. Extern ulong dot;
  204. extern char *file;
  205. Extern Biobuf *bioout;
  206. Extern Biobuf *bin;
  207. Extern ulong *iprof;
  208. extern int datasize;
  209. Extern Map *symmap;
  210. Extern int rtrace;
  211. /* Plan9 Kernel constants */
  212. #define BY2PG 4096
  213. #define BY2WD 4
  214. #define UTZERO 0x1000
  215. #define STACKTOP 0x80000000
  216. #define STACKSIZE 0x10000
  217. #define PROFGRAN 4
  218. /* Opcode decoders */
  219. #define Getrsrt(s,t,i) s = (i>>21)&0x1f; t = (i>>16)&0x1f;
  220. #define Getrbrt(b,t,i) b = (i>>21)&0x1f; t = (i>>16)&0x1f;
  221. #define Get3(s, t, d, i) s = (i>>21)&0x1f; t = (i>>16)&0x1f; d = (i>>11)&0x1f;
  222. #define Getf3(s, t, d, i) s = (i>>11)&0x1f; t = (i>>16)&0x1f; d = (i>>6)&0x1f;
  223. #define Getf2(s, d, i) s = (i>>11)&0x1f; d = (i>>6)&0x1f;
  224. #define SpecialGetrtrd(t, d, i) t = (i>>16)&0x1f; d = (i>>11)&0x1f;
  225. #define INOPINST "nor"
  226. #define INOP 0x00000027 /* Instruction used as nop */
  227. #define SIGNBIT 0x80000000
  228. #define Iexec(ir) {Inst *i; i = &itab[(ir)>>26]; reg.ip = i; i->count++; (*i->func)(ir); }
  229. #define Statbra() reg.ip->taken++; if(reg.ir != INOP) reg.ip->useddelay++;
  230. #define FP_U 3
  231. #define FP_L 1
  232. #define FP_G 2
  233. #define FP_E 0
  234. #define FP_CBIT (1<<23)