1
/* SPIM S20 MIPS simulator.
2
Description of a SPIM S20 instruction.
4
Copyright (C) 1990-2000 by James Larus (larus@cs.wisc.edu).
7
SPIM is distributed under the following conditions:
9
You may make copies of SPIM for your own use and modify those copies.
11
All copies of SPIM must retain my name and copyright notice.
13
You may not sell SPIM or distributed SPIM in conjunction with a
14
commerical product or service without the expressed written consent of
17
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
/* $Header: /Software/SPIM/src/inst.h 7 12/24/00 1:37p Larus $
27
/* Describes an expression that produce a value for an instruction's
28
immediate field. Immediates have the form: label +/- offset. */
30
typedef struct immexpr
32
int offset; /* Offset from symbol */
33
struct lab *symbol; /* Symbolic label */
34
short bits; /* > 0 => 31..16, < 0 => 15..0 */
35
short pc_relative; /* Non-zero => offset from label in code */
39
/* Describes an expression that produce an address for an instruction.
40
Address have the form: label +/- offset (register). */
42
typedef struct addrexpr
44
unsigned char reg_no; /* Register number */
45
imm_expr *imm; /* The immediate part */
50
/* Store the instruction fields in an overlapping manner similar to
59
/* R-type or I-type: */
87
#define OPCODE(INST) (INST)->opcode
88
#define SET_OPCODE(INST, VAL) (INST)->opcode = (short)(VAL)
90
#define RS(INST) (INST)->r_t.r_i.rs
91
#define SET_RS(INST, VAL) (INST)->r_t.r_i.rs = (unsigned char)(VAL)
92
#define FS(INST) RS(INST)
93
#define SET_FS(INST, VAL) SET_RS(INST, VAL)
94
#define BASE(INST) RS(INST)
95
#define SET_BASE(INST, VAL) SET_RS(INST, VAL)
97
#define RT(INST) (INST)->r_t.r_i.rt
98
#define SET_RT(INST, VAL) (INST)->r_t.r_i.rt = (unsigned char)(VAL)
99
#define FT(INST) RT(INST)
100
#define SET_FT(INST, VAL) SET_RT(INST, VAL)
102
#define RD(INST) (INST)->r_t.r_i.r_i.r.rd
103
#define SET_RD(INST, VAL) (INST)->r_t.r_i.r_i.r.rd = (unsigned char)(VAL)
104
#define FD(INST) RD(INST)
105
#define SET_FD(INST, VAL) SET_RD(INST, VAL)
107
#define SHAMT(INST) (INST)->r_t.r_i.r_i.r.shamt
108
#define SET_SHAMT(INST, VAL)(INST)->r_t.r_i.r_i.r.shamt = (unsigned char)(VAL)
110
#define IMM(INST) (INST)->r_t.r_i.r_i.imm
111
#define SET_IMM(INST, VAL) (INST)->r_t.r_i.r_i.imm = (short)(VAL)
112
#define IOFFSET(INST) IMM(INST)
113
#define SET_IOFFSET(INST, VAL) SET_IMM(INST, VAL)
114
#define IDISP(INST) (SIGN_EX (IOFFSET (INST) << 2))
116
#define COND(INST) IMM(INST)
117
#define SET_COND(INST, VAL) SET_IMM(INST, VAL)
119
#define TARGET(INST) (INST)->r_t.target
120
#define SET_TARGET(INST, VAL) (INST)->r_t.target = (mem_addr)(VAL)
122
#define ENCODING(INST) (INST)->encoding
123
#define SET_ENCODING(INST, VAL) (INST)->encoding = (uint32)(VAL)
125
#define EXPR(INST) (INST)->expr
126
#define SET_EXPR(INST, VAL) (INST)->expr = (imm_expr*)(VAL)
128
#define SOURCE(INST) (INST)->source_line
129
#define SET_SOURCE(INST, VAL) (INST)->source_line = (char *)(VAL)
137
/* Minimum and maximum values that fit in instruction's imm field */
138
#define IMM_MIN -(1<<15)
139
#define IMM_MAX ((1<<15)-1)
142
#define UIMM_MAX ((1<<16)-1)
146
/* Raise an exception! */
148
#define RAISE_EXCEPTION(CAUSE, MISC) \
150
if (((CAUSE)<= LAST_REAL_EXCEPT) || (Status_Reg & 0x1)) \
152
Cause = (CAUSE) << 2; \
153
exception_occurred = 1; \
155
Status_Reg = (Status_Reg & 0xffffffc0) | ((Status_Reg & 0xf) << 2); \
161
/* Recognized exceptions (see Ch. 5): */
167
#define ADDRL_EXCPT 4
168
#define ADDRS_EXCPT 5
171
#define SYSCALL_EXCPT 8
178
#define NOT_CACHEABLE 14
181
/* Floating point exceptions (Ch. 8): */
183
#define INEXACT_EXCEPT 13
184
#define INVALID_EXCEPT 14
185
#define DIV0_EXCEPT 15
186
#define FOVF_EXCEPT 16
187
#define FUNF_EXCEPT 17
189
#define LAST_REAL_EXCEPT FUNF_EXCEPT
193
/* Exported functions: */
196
imm_expr *addr_expr_imm (addr_expr *expr);
197
int addr_expr_reg (addr_expr *expr);
198
imm_expr *const_imm_expr (int32 value);
199
imm_expr *copy_imm_expr (imm_expr *old_expr);
200
instruction *copy_inst (instruction *inst);
201
mem_addr current_text_pc (void);
202
int32 eval_imm_expr (imm_expr *expr);
203
void free_inst (instruction *inst);
204
void i_type_inst (int opcode, int rt, int rs, imm_expr *expr);
205
void i_type_inst_free (int opcode, int rt, int rs, imm_expr *expr);
206
void increment_text_pc (int delta);
207
imm_expr *incr_expr_offset (imm_expr *expr, int32 value);
208
instruction *inst_decode (uint32 value);
209
int32 inst_encode (instruction *inst);
210
int inst_is_breakpoint (mem_addr addr);
211
void j_type_inst (int opcode, imm_expr *target);
212
void k_text_begins_at_point (mem_addr addr);
213
imm_expr *lower_bits_of_expr (imm_expr *old_expr);
214
addr_expr *make_addr_expr (int offs, char *sym, int reg_no);
215
imm_expr *make_imm_expr (int offs, char *sym, int pc_rel);
216
int opcode_is_branch (int opcode);
217
int opcode_is_jump (int opcode);
218
int opcode_is_load_store (int opcode);
219
void print_inst (mem_addr addr);
220
int print_inst_internal (char *buf, int len, instruction *inst, mem_addr addr);
221
void r_cond_type_inst (int opcode, int rs, int rt);
222
void r_sh_type_inst (int opcode, int rd, int rt, int shamt);
223
void r_type_inst (int opcode, int rd, int rs, int rt);
224
instruction *set_breakpoint (mem_addr addr);
225
void store_instruction (instruction *inst);
226
void text_begins_at_point (mem_addr addr);
227
imm_expr *upper_bits_of_expr (imm_expr *old_expr);
228
void user_kernel_text_segment (int to_kernel);
229
int zero_imm (imm_expr *expr);
231
imm_expr *addr_expr_imm ();
232
int addr_expr_reg ();
233
imm_expr *const_imm_expr ();
234
imm_expr *copy_imm_expr ();
235
instruction *copy_inst ();
236
mem_addr current_text_pc ();
237
int32 eval_imm_expr ();
240
void i_type_inst_free ();
241
void increment_text_pc ();
242
imm_expr *incr_expr_offset ();
243
instruction *inst_decode ();
244
int32 inst_encode ();
245
int inst_is_breakpoint ();
247
void k_text_begins_at_point ();
248
imm_expr *lower_bits_of_expr ();
249
addr_expr *make_addr_expr ();
250
imm_expr *make_imm_expr ();
251
int opcode_is_branch ();
252
int opcode_is_jump ();
253
int opcode_is_load_store ();
255
int print_inst_internal ();
256
void r_cond_type_inst ();
257
void r_sh_type_inst ();
259
instruction *set_breakpoint ();
260
void store_instruction ();
261
void text_begins_at_point ();
262
imm_expr *upper_bits_of_expr ();
263
void user_kernel_text_segment ();