sparc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. * sparc sim.h
  11. *
  12. * The integer instruction side of this emulator is portable if sizeof(long) >= 4
  13. * Floating point emulation however is not. Assumptions made are:
  14. * sizeof(ulong) == sizeof(float)
  15. * sizeof(ulong)*2 == sizeof(double)
  16. * bits of floating point in memory may be reversed lsw/msw
  17. * unions of double & 2*float & 2*long have no padding
  18. */
  19. #include "/sparc/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 Mul Mul;
  28. typedef struct Mulu Mulu;
  29. typedef struct Inst Inst;
  30. typedef struct Icache Icache;
  31. typedef struct Breakpoint Breakpoint;
  32. enum
  33. {
  34. Instruction = 1,
  35. Read = 2,
  36. Write = 4,
  37. Access = 2|4,
  38. Equal = 4|8,
  39. };
  40. struct Breakpoint
  41. {
  42. int type; /* Instruction/Read/Access/Write/Equal */
  43. uint32_t addr; /* Place at address */
  44. int count; /* To execute count times or value */
  45. int done; /* How many times passed through */
  46. Breakpoint *next; /* Link to next one */
  47. };
  48. enum
  49. {
  50. Iload,
  51. Istore,
  52. Iarith,
  53. Ibranch,
  54. Ireg,
  55. Isyscall,
  56. Ifloat,
  57. Inop,
  58. };
  59. struct Icache
  60. {
  61. int on; /* Turned on */
  62. int linesize; /* Line size in bytes */
  63. int stall; /* Cache stalls */
  64. int *lines; /* Tag array */
  65. int* (*hash)(uint32_t); /* Hash function */
  66. char *hashtext; /* What the function looks like */
  67. };
  68. struct Inst
  69. {
  70. void (*func)(uint32_t);
  71. char *name;
  72. int type;
  73. int count;
  74. int taken;
  75. int useddelay;
  76. };
  77. struct Registers
  78. {
  79. uint32_t pc;
  80. uint32_t ir;
  81. Inst *ip;
  82. long r[32];
  83. uint32_t Y;
  84. uint32_t psr;
  85. uint32_t fpsr;
  86. union {
  87. double fd[16];
  88. float fl[32];
  89. uint32_t di[32];
  90. };
  91. };
  92. struct Mulu{
  93. uint32_t lo;
  94. uint32_t hi;
  95. };
  96. struct Mul{
  97. long lo;
  98. long hi;
  99. };
  100. enum
  101. {
  102. MemRead,
  103. MemReadstring,
  104. MemWrite,
  105. };
  106. enum
  107. {
  108. Stack,
  109. Text,
  110. Data,
  111. Bss,
  112. Nseg,
  113. };
  114. struct Segment
  115. {
  116. short type;
  117. uint32_t base;
  118. uint32_t end;
  119. uint32_t fileoff;
  120. uint32_t fileend;
  121. int rss;
  122. int refs;
  123. uchar **table;
  124. };
  125. struct Memory
  126. {
  127. Segment seg[Nseg];
  128. };
  129. void fatal(int, char*, ...);
  130. void run(void);
  131. void undef(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 ta(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. uint32_t getmem_4(uint32_t);
  149. uint32_t getmem_2(uint32_t);
  150. void putmem_h(uint32_t, short);
  151. Mul mul(long, long);
  152. Mulu mulu(uint32_t, uint32_t);
  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 delay(uint32_t);
  175. void iprofile(void);
  176. /* Globals */
  177. Extern Registers reg;
  178. Extern Memory memory;
  179. Extern int text;
  180. Extern int trace;
  181. Extern int sysdbg;
  182. Extern int calltree;
  183. Extern Icache icache;
  184. Extern int count;
  185. Extern jmp_buf errjmp;
  186. Extern Breakpoint *bplist;
  187. Extern int atbpt;
  188. Extern int membpt;
  189. Extern int cmdcount;
  190. Extern int nopcount;
  191. Extern ulong dot;
  192. extern char *file;
  193. Extern Biobuf *bioout;
  194. Extern Biobuf *bin;
  195. Extern Inst *ci;
  196. Extern ulong *iprof;
  197. Extern ulong loadlock;
  198. Extern ulong anulled;
  199. extern int datasize;
  200. extern int printcol;
  201. Extern Map *symmap;
  202. /* Plan9 Kernel constants */
  203. #define BY2PG 4096
  204. #define BY2WD 4
  205. #define UTZERO 0x1000
  206. #define TSTKSIZ 32
  207. #define TSTACKTOP 0x10000000
  208. #define STACKTOP (TSTACKTOP-TSTKSIZ*BY2PG)
  209. #define STACKSIZE (4*1024*1024)
  210. #define ANUL (1<<29)
  211. #define PROFGRAN 4
  212. #define NOP 0x80300000
  213. #define SIGNBIT 0x80000000
  214. #define IMMBIT (1<<13)
  215. #define getrop23(i) rd = (i>>25)&0x1f; rs1 = (i>>14)&0x1f; rs2 = i&0x1f;
  216. #define ximm(xx, ii) xx = ii&0x1FFF; if(xx&0x1000) xx |= ~0x1FFF
  217. #define PSR_n (1<<23)
  218. #define PSR_z (1<<22)
  219. #define PSR_v (1<<21)
  220. #define PSR_c (1<<20)
  221. #define FP_U 3
  222. #define FP_L 1
  223. #define FP_G 2
  224. #define FP_E 0