1 /* 2 * sparc sim.h 3 * 4 * The integer instruction side of this emulator is portable if sizeof(long) >= 4 5 * Floating point emulation however is not. Assumptions made are: 6 * sizeof(ulong) == sizeof(float) 7 * sizeof(ulong)*2 == sizeof(double) 8 * bits of floating point in memory may be reversed lsw/msw 9 * unions of double & 2*float & 2*long have no padding 10 */ 11 #include "/sparc/include/ureg.h" 12 #define USERADDR 0xC0000000 13 #define UREGADDR (USERADDR+BY2PG-4-0xA0) 14 #define USER_REG(x) (UREGADDR+(ulong)(x)) 15 #define REGOFF(x) (USER_REG(&((struct Ureg *) 0)->x)) 16 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 Breakpoint Breakpoint; 25 26 enum 27 { 28 Instruction = 1, 29 Read = 2, 30 Write = 4, 31 Access = 2|4, 32 Equal = 4|8, 33 }; 34 35 struct Breakpoint 36 { 37 int type; /* Instruction/Read/Access/Write/Equal */ 38 ulong addr; /* Place at address */ 39 int count; /* To execute count times or value */ 40 int done; /* How many times passed through */ 41 Breakpoint *next; /* Link to next one */ 42 }; 43 44 enum 45 { 46 Iload, 47 Istore, 48 Iarith, 49 Ibranch, 50 Ireg, 51 Isyscall, 52 Ifloat, 53 Inop, 54 }; 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 66 struct Inst 67 { 68 void (*func)(ulong); 69 char *name; 70 int type; 71 int count; 72 int taken; 73 int useddelay; 74 }; 75 76 struct Registers 77 { 78 ulong pc; 79 ulong ir; 80 Inst *ip; 81 long r[32]; 82 ulong Y; 83 ulong psr; 84 ulong fpsr; 85 86 union { 87 double fd[16]; 88 float fl[32]; 89 ulong di[32]; 90 }; 91 }; 92 93 struct Mulu{ 94 ulong lo; 95 ulong hi; 96 }; 97 98 struct Mul{ 99 long lo; 100 long hi; 101 }; 102 103 enum 104 { 105 MemRead, 106 MemReadstring, 107 MemWrite, 108 }; 109 110 enum 111 { 112 Stack, 113 Text, 114 Data, 115 Bss, 116 Nseg, 117 }; 118 119 struct Segment 120 { 121 short type; 122 ulong base; 123 ulong end; 124 ulong fileoff; 125 ulong fileend; 126 int rss; 127 int refs; 128 uchar **table; 129 }; 130 131 struct Memory 132 { 133 Segment seg[Nseg]; 134 }; 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 void itrace(char *, ...); 146 void segsum(void); 147 void ta(ulong); 148 char* memio(char*, ulong, int, int); 149 ulong getmem_w(ulong); 150 ulong ifetch(ulong); 151 ushort getmem_h(ulong); 152 void putmem_w(ulong, ulong); 153 uchar getmem_b(ulong); 154 void putmem_b(ulong, uchar); 155 ulong getmem_4(ulong); 156 ulong getmem_2(ulong); 157 void putmem_h(ulong, short); 158 Mul mul(long, long); 159 Mulu mulu(ulong, ulong); 160 void isum(void); 161 void initicache(void); 162 void updateicache(ulong addr); 163 long lnrand(long); 164 void randseed(long, long); 165 void cmd(void); 166 void brkchk(ulong, int); 167 void delbpt(char*); 168 void breakpoint(char*, char*); 169 char* nextc(char*); 170 ulong expr(char*); 171 void initstk(int, char**); 172 void initmap(void); 173 void inithdr(int); 174 void reset(void); 175 void dobplist(void); 176 void procinit(int); 177 void printsource(long); 178 void printparams(Symbol *, ulong); 179 void printlocals(Symbol *, ulong); 180 void stktrace(int); 181 void delay(ulong); 182 void iprofile(void); 183 184 /* Globals */ 185 Extern Registers reg; 186 Extern Memory memory; 187 Extern int text; 188 Extern int trace; 189 Extern int sysdbg; 190 Extern int calltree; 191 Extern Icache icache; 192 Extern int count; 193 Extern jmp_buf errjmp; 194 Extern Breakpoint *bplist; 195 Extern int atbpt; 196 Extern int membpt; 197 Extern int cmdcount; 198 Extern int nopcount; 199 Extern ulong dot; 200 extern char *file; 201 Extern Biobuf *bioout; 202 Extern Biobuf *bin; 203 Extern Inst *ci; 204 Extern ulong *iprof; 205 Extern ulong loadlock; 206 Extern ulong anulled; 207 extern int datasize; 208 extern int printcol; 209 Extern Map *symmap; 210 211 /* Plan9 Kernel constants */ 212 #define BY2PG 4096 213 #define BY2WD 4 214 #define UTZERO 0x1000 215 #define TSTKSIZ 32 216 #define TSTACKTOP 0x10000000 217 #define STACKTOP (TSTACKTOP-TSTKSIZ*BY2PG) 218 #define STACKSIZE (4*1024*1024) 219 220 #define ANUL (1<<29) 221 #define PROFGRAN 4 222 #define NOP 0x80300000 223 #define SIGNBIT 0x80000000 224 #define IMMBIT (1<<13) 225 #define getrop23(i) rd = (i>>25)&0x1f; rs1 = (i>>14)&0x1f; rs2 = i&0x1f; 226 #define ximm(xx, ii) xx = ii&0x1FFF; if(xx&0x1000) xx |= ~0x1FFF 227 228 #define PSR_n (1<<23) 229 #define PSR_z (1<<22) 230 #define PSR_v (1<<21) 231 #define PSR_c (1<<20) 232 233 #define FP_U 3 234 #define FP_L 1 235 #define FP_G 2 236 #define FP_E 0 237