Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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