~ubuntu-branches/ubuntu/jaunty/spim/jaunty

« back to all changes in this revision

Viewing changes to inst.h

  • Committer: Bazaar Package Importer
  • Author(s): Fernando Sanchez
  • Date: 2001-01-24 14:05:34 UTC
  • Revision ID: james.westby@ubuntu.com-20010124140534-3le9wmofforjjcd8
Tags: upstream-6.3
ImportĀ upstreamĀ versionĀ 6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* SPIM S20 MIPS simulator.
 
2
   Description of a SPIM S20 instruction.
 
3
 
 
4
   Copyright (C) 1990-2000 by James Larus (larus@cs.wisc.edu).
 
5
   ALL RIGHTS RESERVED.
 
6
 
 
7
   SPIM is distributed under the following conditions:
 
8
 
 
9
     You may make copies of SPIM for your own use and modify those copies.
 
10
 
 
11
     All copies of SPIM must retain my name and copyright notice.
 
12
 
 
13
     You may not sell SPIM or distributed SPIM in conjunction with a
 
14
     commerical product or service without the expressed written consent of
 
15
     James Larus.
 
16
 
 
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
 
20
   PURPOSE. */
 
21
 
 
22
 
 
23
/* $Header: /Software/SPIM/src/inst.h 7     12/24/00 1:37p Larus $
 
24
*/
 
25
 
 
26
 
 
27
/* Describes an expression that produce a value for an instruction's
 
28
   immediate field.  Immediates have the form: label +/- offset. */
 
29
 
 
30
typedef struct immexpr
 
31
{
 
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 */
 
36
} imm_expr;
 
37
 
 
38
 
 
39
/* Describes an expression that produce an address for an instruction.
 
40
   Address have the form: label +/- offset (register). */
 
41
 
 
42
typedef struct addrexpr
 
43
{
 
44
  unsigned char reg_no;         /* Register number */
 
45
  imm_expr *imm;                /* The immediate part */
 
46
} addr_expr;
 
47
 
 
48
 
 
49
 
 
50
/* Store the instruction fields in an overlapping manner similar to
 
51
   the real encoding. */
 
52
 
 
53
typedef struct inst_s
 
54
{
 
55
  short opcode;
 
56
 
 
57
  union
 
58
    {
 
59
      /* R-type or I-type: */
 
60
      struct
 
61
        {
 
62
          unsigned char rs;
 
63
          unsigned char rt;
 
64
 
 
65
          union
 
66
            {
 
67
              short imm;
 
68
 
 
69
              struct
 
70
                {
 
71
                  unsigned char rd;
 
72
                  unsigned char shamt;
 
73
                } r;
 
74
            } r_i;
 
75
        } r_i;
 
76
 
 
77
      /* J-type: */
 
78
      mem_addr target;
 
79
    } r_t;
 
80
 
 
81
  uint32 encoding;
 
82
  imm_expr *expr;
 
83
  char *source_line;
 
84
} instruction;
 
85
 
 
86
 
 
87
#define OPCODE(INST)    (INST)->opcode
 
88
#define SET_OPCODE(INST, VAL)   (INST)->opcode = (short)(VAL)
 
89
 
 
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)
 
96
 
 
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)
 
101
 
 
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)
 
106
 
 
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)
 
109
 
 
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))
 
115
 
 
116
#define COND(INST)                      IMM(INST)
 
117
#define SET_COND(INST, VAL)     SET_IMM(INST, VAL)
 
118
 
 
119
#define TARGET(INST)            (INST)->r_t.target
 
120
#define SET_TARGET(INST, VAL)   (INST)->r_t.target = (mem_addr)(VAL)
 
121
 
 
122
#define ENCODING(INST)          (INST)->encoding
 
123
#define SET_ENCODING(INST, VAL) (INST)->encoding = (uint32)(VAL)
 
124
 
 
125
#define EXPR(INST)                      (INST)->expr
 
126
#define SET_EXPR(INST, VAL)     (INST)->expr = (imm_expr*)(VAL)
 
127
 
 
128
#define SOURCE(INST)            (INST)->source_line
 
129
#define SET_SOURCE(INST, VAL)   (INST)->source_line = (char *)(VAL)
 
130
 
 
131
 
 
132
#define COND_UN         0x1
 
133
#define COND_EQ         0x2
 
134
#define COND_LT         0x4
 
135
#define COND_IN         0x8
 
136
 
 
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)
 
140
 
 
141
#define UIMM_MIN  0
 
142
#define UIMM_MAX  ((1<<16)-1)
 
143
 
 
144
 
 
145
 
 
146
/* Raise an exception! */
 
147
 
 
148
#define RAISE_EXCEPTION(CAUSE, MISC)                                    \
 
149
        {                                                               \
 
150
          if (((CAUSE)<= LAST_REAL_EXCEPT) || (Status_Reg & 0x1))       \
 
151
            {                                                           \
 
152
              Cause = (CAUSE) << 2;                                     \
 
153
              exception_occurred = 1;                                   \
 
154
              EPC = PC;                                                 \
 
155
              Status_Reg = (Status_Reg & 0xffffffc0) | ((Status_Reg & 0xf) << 2); \
 
156
              MISC;                                                     \
 
157
            }                                                           \
 
158
        }                                                               \
 
159
 
 
160
 
 
161
/* Recognized exceptions (see Ch. 5): */
 
162
 
 
163
#define INT_EXCPT 0
 
164
#define MOD_EXCPT 1
 
165
#define TLBL_EXCPT 2
 
166
#define TLBS_EXCPT 3
 
167
#define ADDRL_EXCPT 4
 
168
#define ADDRS_EXCPT 5
 
169
#define IBUS_EXCPT 6
 
170
#define DBUS_EXCPT 7
 
171
#define SYSCALL_EXCPT 8
 
172
#define BKPT_EXCPT 9
 
173
#define RI_EXCPT 10
 
174
#define CPU_EXCPT 11
 
175
#define OVF_EXCPT 12
 
176
 
 
177
#define CACHEABLE 13
 
178
#define NOT_CACHEABLE 14
 
179
 
 
180
 
 
181
/* Floating point exceptions (Ch. 8): */
 
182
 
 
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
 
188
 
 
189
#define LAST_REAL_EXCEPT FUNF_EXCEPT
 
190
 
 
191
 
 
192
 
 
193
/* Exported functions: */
 
194
 
 
195
#ifdef __STDC__
 
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);
 
230
#else
 
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 ();
 
238
void free_inst ();
 
239
void i_type_inst ();
 
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 ();
 
246
void j_type_inst ();
 
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 ();
 
254
void print_inst ();
 
255
int print_inst_internal ();
 
256
void r_cond_type_inst ();
 
257
void r_sh_type_inst ();
 
258
void r_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 ();
 
264
int zero_imm ();
 
265
#endif