power.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. * power sim.h
  11. *
  12. * The integer instruction side of this emulator is portable if sizeof(long) >= 4
  13. * Floating point emulation assumes:
  14. * sizeof(ulong) == sizeof(float)
  15. * sizeof(ulong)*2 == sizeof(double) <= sizeof(vlong)
  16. * unions of double & vlong have no padding
  17. * vlongs provide at least 64 bits precision
  18. */
  19. #include "/power/include/ureg.h"
  20. #define USERADDR 0xC0000000
  21. #define UREGADDR (USERADDR+BY2PG-4-0xA0)
  22. #define USER_REG(x) (UREGADDR+(ulong)(x))
  23. #define REGOFF(x) (USER_REG(&((struct Ureg *) 0)->x))
  24. typedef struct Registers Registers;
  25. typedef struct Segment Segment;
  26. typedef struct Memory Memory;
  27. typedef struct Inset Inset;
  28. typedef struct Inst Inst;
  29. typedef struct Icache Icache;
  30. typedef struct Breakpoint Breakpoint;
  31. enum
  32. {
  33. Instruction = 1,
  34. Read = 2,
  35. Write = 4,
  36. Access = 2|4,
  37. Equal = 4|8,
  38. };
  39. struct Breakpoint
  40. {
  41. int type; /* Instruction/Read/Access/Write/Equal */
  42. uint32_t addr; /* Place at address */
  43. int count; /* To execute count times or value */
  44. int done; /* How many times passed through */
  45. Breakpoint *next; /* Link to next one */
  46. };
  47. enum
  48. {
  49. Iload,
  50. Istore,
  51. Iarith,
  52. Ilog,
  53. Ibranch,
  54. Ireg,
  55. Isyscall,
  56. Ifloat,
  57. Inop,
  58. Icontrol,
  59. };
  60. struct Icache
  61. {
  62. int on; /* Turned on */
  63. int linesize; /* Line size in bytes */
  64. int stall; /* Cache stalls */
  65. int *lines; /* Tag array */
  66. int* (*hash)(uint32_t); /* Hash function */
  67. char *hashtext; /* What the function looks like */
  68. };
  69. struct Inset
  70. {
  71. Inst *tab; /* indexed by extended opcode */
  72. int nel;
  73. };
  74. struct Inst
  75. {
  76. void (*func)(uint32_t);
  77. char *name;
  78. int type;
  79. int count;
  80. int taken;
  81. };
  82. struct Registers
  83. {
  84. uint32_t pc;
  85. uint32_t ir;
  86. Inst *ip;
  87. long r[32];
  88. uint32_t ctr;
  89. uint32_t cr;
  90. uint32_t xer;
  91. uint32_t lr;
  92. uint32_t fpscr;
  93. uint32_t dec;
  94. uint32_t tbl;
  95. uint32_t tbu;
  96. double fd[32];
  97. };
  98. enum
  99. {
  100. MemRead,
  101. MemReadstring,
  102. MemWrite,
  103. };
  104. enum
  105. {
  106. Stack,
  107. Text,
  108. Data,
  109. Bss,
  110. Nseg,
  111. };
  112. struct Segment
  113. {
  114. short type;
  115. uint32_t base;
  116. uint32_t end;
  117. uint32_t fileoff;
  118. uint32_t fileend;
  119. int rss;
  120. int refs;
  121. uchar **table;
  122. };
  123. struct Memory
  124. {
  125. Segment seg[Nseg];
  126. };
  127. void fatal(int, char*, ...);
  128. void fpreginit(void);
  129. void run(void);
  130. void undef(uint32_t);
  131. void unimp(uint32_t);
  132. void dumpreg(void);
  133. void dumpfreg(void);
  134. void dumpdreg(void);
  135. void* emalloc(uint32_t);
  136. void* erealloc(void*, uint32_t, uint32_t);
  137. void* vaddr(uint32_t);
  138. void itrace(char *, ...);
  139. void segsum(void);
  140. void sc(uint32_t);
  141. char* memio(char*, uint32_t, int, int);
  142. uint32_t getmem_w(uint32_t);
  143. uint32_t ifetch(uint32_t);
  144. ushort getmem_h(uint32_t);
  145. void putmem_w(uint32_t, uint32_t);
  146. uchar getmem_b(uint32_t);
  147. void putmem_b(uint32_t, uchar);
  148. uvlong getmem_v(uint32_t);
  149. uint32_t getmem_4(uint32_t);
  150. uint32_t getmem_2(uint32_t);
  151. void putmem_v(uint32_t, uvlong);
  152. void putmem_h(uint32_t, short);
  153. void isum(void);
  154. void initicache(void);
  155. void updateicache(uint32_t addr);
  156. long lnrand(long);
  157. void randseed(long, long);
  158. void cmd(void);
  159. void brkchk(uint32_t, int);
  160. void delbpt(char*);
  161. void breakpoint(char*, char*);
  162. char* nextc(char*);
  163. uint32_t expr(char*);
  164. void initstk(int, char**);
  165. void initmap(void);
  166. void inithdr(int);
  167. void reset(void);
  168. void dobplist(void);
  169. void procinit(int);
  170. void printsource(long);
  171. void printparams(Symbol *, uint32_t);
  172. void printlocals(Symbol *, uint32_t);
  173. void stktrace(int);
  174. void iprofile(void);
  175. /* Globals */
  176. Extern Registers reg;
  177. Extern Memory memory;
  178. Extern int text;
  179. Extern int trace;
  180. Extern int sysdbg;
  181. Extern int calltree;
  182. Extern Icache icache;
  183. Extern int count;
  184. Extern jmp_buf errjmp;
  185. Extern Breakpoint *bplist;
  186. Extern int atbpt;
  187. Extern int membpt;
  188. Extern int cmdcount;
  189. Extern int nopcount;
  190. Extern ulong dot;
  191. extern char *file;
  192. Extern Biobuf *bioout;
  193. Extern Biobuf *bin;
  194. Extern Inst *ci;
  195. Extern ulong *iprof;
  196. Extern ulong iprofsize;
  197. Extern ulong loadlock;
  198. extern int datasize;
  199. extern int printcol;
  200. Extern Map *symmap;
  201. extern uint32_t bits[];
  202. extern Inset ops0, ops19, ops31, ops59, ops63a, ops63b;
  203. /* Plan9 Kernel constants */
  204. #define BY2PG 4096
  205. #define BY2WD 4
  206. #define UTZERO 0x1000
  207. #define TSTKSIZ 32
  208. #define TSTACKTOP 0x20000000
  209. #define STACKTOP (TSTACKTOP-TSTKSIZ*BY2PG)
  210. #define STACKSIZE (4*1024*1024)
  211. #define PROFGRAN 4
  212. #define NOP 0x80300000
  213. #define SIGNBIT 0x80000000
  214. enum {
  215. CRLT = 1<<31,
  216. CRGT = 1<<30,
  217. CREQ = 1<<29,
  218. CRSO = 1<<28,
  219. CRFU = CRSO,
  220. CRFX = 1<<27,
  221. CRFEX = 1<<26,
  222. CRVX = 1<<25,
  223. CROX = 1<<24,
  224. };
  225. #define getCR(x,w) (((w)>>(28-(x*4)))&0xF)
  226. #define mkCR(x,v) (((v)&0xF)<<(28-(x*4)))
  227. #define simm(xx, ii) xx = (short)(ii&0xFFFF);
  228. #define uimm(xx, ii) xx = ii&0xFFFF;
  229. #define imms(xx, ii) xx = ii<<16;
  230. #define getairr(i) rd = (i>>21)&0x1f; ra = (i>>16)&0x1f; simm(imm,i)
  231. #define getarrr(i) rd = (i>>21)&0x1f; ra = (i>>16)&0x1f; rb = (i>>11)&0x1f;
  232. #define getbobi(i) bo = (i>>21)&0x1f; bi = (i>>16)&0x1f; xx = (i>>11)&0x1f;
  233. #define getlirr(i) rs = (i>>21)&0x1f; ra = (i>>16)&0x1f; uimm(imm,i)
  234. #define getlrrr(i) rs = (i>>21)&0x1f; ra = (i>>16)&0x1f; rb = (i>>11)&0x1f;
  235. #define OP(o,xo) ((o<<26)|(xo<<1)) /* build an operation */
  236. #define xop(a,b) ((b<<6)|a) /* compact form for use in a decoding switch on op/xo */
  237. #define getop(i) ((i>>26)&0x3F)
  238. #define getxo(i) ((i>>1)&0x3FF)
  239. #define FPS_FX (1<<31) /* exception summary (sticky) */
  240. #define FPS_EX (1<<30) /* enabled exception summary */
  241. #define FPS_VX (1<<29) /* invalid operation exception summary */
  242. #define FPS_OX (1<<28) /* overflow exception OX (sticky) */
  243. #define FPS_UX (1<<27) /* underflow exception UX (sticky) */
  244. #define FPS_ZX (1<<26) /* zero divide exception ZX (sticky) */
  245. #define FPS_XX (1<<25) /* inexact exception XX (sticky) */
  246. #define FPS_VXSNAN (1<<24) /* invalid operation exception for SNaN (sticky) */
  247. #define FPS_VXISI (1<<23) /* invalid operation exception for ∞-∞ (sticky) */
  248. #define FPS_VXIDI (1<<22) /* invalid operation exception for ∞/∞ (sticky) */
  249. #define FPS_VXZDZ (1<<21) /* invalid operation exception for 0/0 (sticky) */
  250. #define FPS_VXIMZ (1<<20) /* invalid operation exception for ∞*0 (sticky) */
  251. #define FPS_VXVC (1<<19) /* invalid operation exception for invalid compare (sticky) */
  252. #define FPS_FR (1<<18) /* fraction rounded */
  253. #define FPS_FI (1<<17) /* fraction inexact */
  254. #define FPS_FPRF (1<<16) /* floating point result class */
  255. #define FPS_FPCC (0xF<<12) /* <, >, =, unordered */
  256. #define FPS_VXCVI (1<<8) /* enable exception for invalid integer convert (sticky) */
  257. #define FPS_VE (1<<7) /* invalid operation exception enable */
  258. #define FPS_OE (1<<6) /* enable overflow exceptions */
  259. #define FPS_UE (1<<5) /* enable underflow */
  260. #define FPS_ZE (1<<4) /* enable zero divide */
  261. #define FPS_XE (1<<3) /* enable inexact exceptions */
  262. #define FPS_RN (3<<0) /* rounding mode */
  263. #define XER_SO (1<<31)
  264. #define XER_OV (1<<30)
  265. #define XER_CA (1<<29)
  266. #define Rc 1
  267. #define OE 0x400