mips.h 5.3 KB

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