File: spim.h

package info (click to toggle)
spim 6.1-3
  • links: PTS
  • area: non-free
  • in suites: hamm, slink
  • size: 1,944 kB
  • ctags: 2,839
  • sloc: asm: 10,339; ansic: 9,404; yacc: 1,867; makefile: 713; lex: 583; sh: 95
file content (280 lines) | stat: -rw-r--r-- 6,124 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/* SPIM S20 MIPS simulator.
   Definitions for the SPIM S20.

   Copyright (C) 1990-1997 by James Larus (larus@cs.wisc.edu).
   ALL RIGHTS RESERVED.
   Changes for DOS and Windows versions by David A. Carley (dac@cs.wisc.edu)

   SPIM is distributed under the following conditions:

     You may make copies of SPIM for your own use and modify those copies.

     All copies of SPIM must retain my name and copyright notice.

     You may not sell SPIM or distributed SPIM in conjunction with a
     commerical product or service without the expressed written consent of
     James Larus.

   THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   PURPOSE. */


/* $Header: /u/l/a/larus/Software/SPIM/RCS/spim.h,v 3.29 1997/07/09 22:08:29 larus Exp $
*/

#ifndef NULL
#define NULL 0
#endif


/* Type declarations for portability.  They work for DEC's Alpha (64 bits)
   and 32 bit machines */

typedef int int32;
typedef unsigned int  uint32;
typedef union {int i; void* p;} intptr_union;


#define streq(s1, s2) !strcmp(s1, s2)


/* Round V to next greatest B boundary */

#define ROUND(V, B) (((int) V + (B-1)) & ~(B-1))


/* Sign-extend an int16 to an int32 */

#define SIGN_EX(X) ((X) & 0x8000 ? (X) | 0xffff0000 : (X))


#ifdef MIN			/* Some systems define these in system includes */
#undef MIN
#endif
#ifdef MAX
#undef MAX
#endif

#define MIN(A, B) ((A) < (B) ? (A) : (B))

#define MAX(A, B) ((A) > (B) ? (A) : (B))


#define K 1024


/* Useful and pervasive declarations: */

#ifdef NO_MEM_FUNCTIONS
#define memcpy(T, F, S) bcopy((void*)F, (void*)T, S)
#define memclr(B, S) bzero(B, S)
#define memcmp(S1, S2, N) bcmp(S1, S2, N)
#else
#include <memory.h>
#define memclr(B, S) memset((void*)B, 0, S)
#endif

#ifdef __STDC__
#include <stdlib.h>
#include <string.h>
#define QSORT_FUNC int(*)(const void *, const void *)
#else
double atof ();
int atoi ();
int free ();
char *malloc ();
int strcmp ();
char *strcpy ();
char *strncpy ();
#define QSORT_FUNC int(*)()
#endif



/* Type of a memory address.  Must be a 32-bit quantity to match MIPS.  */

typedef uint32 mem_addr;


#define BYTES_PER_WORD 4	/* On the MIPS processor */


/* Sizes of memory segments. */

/* Initial size of text segment. */

#ifndef TEXT_SIZE
#define TEXT_SIZE	256*K	/* 1/4 MB */
#endif

/* Initial size of k_text segment. */

#ifndef K_TEXT_SIZE
#define K_TEXT_SIZE	64*K	/* 64 KB */
#endif

/* The data segment must be larger than 64K since we immediate grab
   64K for the small data segment pointed to by $gp. The data segment is
   expanded by an sbrk system call. */

/* Initial size of data segment. */

#ifndef DATA_SIZE
#define DATA_SIZE	256*K	/* 1/4 MB */
#endif

/* Maximum size of data segment. */

#ifndef DATA_LIMIT
#define DATA_LIMIT	1000*K	/* 1 MB */
#endif

/* Initial size of k_data segment. */

#ifndef K_DATA_SIZE
#define K_DATA_SIZE	64*K	/* 64 KB */
#endif

/* Maximum size of k_data segment. */

#ifndef K_DATA_LIMIT
#define K_DATA_LIMIT	1000*K	/* 1 MB */
#endif

/* The stack grows down automatically. */

/* Initial size of stack segment. */

#ifndef STACK_SIZE
#define STACK_SIZE	64*K	/* 64 KB */
#endif

/* Maximum size of stack segment. */

#ifndef STACK_LIMIT
#define STACK_LIMIT	256*K	/* 1 MB */
#endif


/* Name of the function to invoke at start up */

#define DEFAULT_RUN_LOCATION "__start"


/* Default number of instructions to execute. */

#define DEFAULT_RUN_STEPS 2147483647


/* Address to branch to when exception occurs */

#define EXCEPTION_ADDR 0x80000080


/* Maximum size of object stored in the small data segment pointed to by
   $gp */

#define SMALL_DATA_SEG_MAX_SIZE 8

#ifndef DIRECT_MAPPED
#define DIRECT_MAPPED 0
#define TWO_WAY_SET 1
#endif


/* Interval (in instructions) at which memory-mapped IO registers are
   checked and updated.*/

#define IO_INTERVAL 100


/* Number of instructions that a character remains in receiver buffer
   if another character is available. (Should be multiple of IO_INTERVAL.) */

#define RECV_LATENCY (10*IO_INTERVAL)


/* Number of instructions that it takes to write a character. (Should
   be multiple of IO_INTERVAL.)*/

#define TRANS_LATENCY (IO_INTERVAL)



/* Triple containing a string and two integers.	 Used in tables
   mapping from a name to values. */

typedef struct strint
{
  char *name;
  int value1;
  int value2;
} inst_info;




/* A port is either a Unix file descriptor (an int) or a FILE* pointer. */

#include <stdio.h>

typedef union {int i; FILE* f;} port;

/* Exported functions (from spim.c or xspim.c): */
#ifdef __STDC__

int console_input_available (void);
void control_c_seen (int);
void error (char *fmt, ...);
void fatal_error (char *fmt, ...);
char get_console_char (void);
void put_console_char (char c);
void read_input (char *str, int n);
int* run_error (char *fmt, ...);
void write_output (port, char *fmt, ...);
#else
int console_input_available ();
void control_c_seen ();
void error ();
void fatal_error ();
char get_console_char ();
void put_console_char ();
void read_input ();
int* run_error ();
void write_output ();
#endif


/* Exported variables: */

extern int bare_machine;	/* Non-zero => simulate bare machine */
extern int accept_pseudo_insts;	/* Non-Zero => parse pseudo instructions  */
extern int quiet;		/* Non-zero => no warning messages */
extern int source_file;		/* Non-zero => program is source, not binary */
extern char *trap_file;		/* Path of file containing trap handler */
extern int force_break;		/* Non-zero => stop interpreter loop  */

/* Actual type of structure pointed to depends on X/terminal interface */
extern port message_out, console_out, console_in;

extern int mapped_io;		/* Non-zero => activate memory-mapped IO */

extern mem_addr program_starting_address;

extern int initial_text_size;

extern int initial_data_size;

extern mem_addr initial_data_limit;

extern int initial_stack_size;

extern mem_addr initial_stack_limit;

extern int initial_k_text_size;

extern int initial_k_data_size;

extern mem_addr initial_k_data_limit;