Changed Fault * to Fault, which is a typedef to FaultBase *, which is the old Fault...
[gem5.git] / arch / alpha / isa / main.isa
1 // -*- mode:c++ -*-
2
3 // Copyright (c) 2003-2005 The Regents of The University of Michigan
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met: redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer;
10 // redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution;
13 // neither the name of the copyright holders nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 output header {{
30 #include <sstream>
31 #include <iostream>
32 #include <iomanip>
33
34 #include "config/ss_compatible_fp.hh"
35 #include "cpu/static_inst.hh"
36 #include "arch/alpha/faults.hh"
37 #include "mem/mem_req.hh" // some constructors use MemReq flags
38 }};
39
40 output decoder {{
41 #include "base/cprintf.hh"
42 #include "base/fenv.hh"
43 #include "base/loader/symtab.hh"
44 #include "config/ss_compatible_fp.hh"
45 #include "cpu/exec_context.hh" // for Jump::branchTarget()
46
47 #include <math.h>
48
49 using namespace AlphaISA;
50 }};
51
52 output exec {{
53 #include <math.h>
54
55 #if FULL_SYSTEM
56 #include "sim/pseudo_inst.hh"
57 #endif
58 #include "base/fenv.hh"
59 #include "config/ss_compatible_fp.hh"
60 #include "cpu/base.hh"
61 #include "cpu/exetrace.hh"
62 #include "sim/sim_exit.hh"
63
64 using namespace AlphaISA;
65 }};
66
67 ////////////////////////////////////////////////////////////////////
68 //
69 // Namespace statement. Everything below this line will be in the
70 // AlphaISAInst namespace.
71 //
72
73
74 namespace AlphaISA;
75
76 ////////////////////////////////////////////////////////////////////
77 //
78 // Bitfield definitions.
79 //
80
81 // Universal (format-independent) fields
82 def bitfield OPCODE <31:26>;
83 def bitfield RA <25:21>;
84 def bitfield RB <20:16>;
85
86 // Memory format
87 def signed bitfield MEMDISP <15: 0>; // displacement
88 def bitfield MEMFUNC <15: 0>; // function code (same field, unsigned)
89
90 // Memory-format jumps
91 def bitfield JMPFUNC <15:14>; // function code (disp<15:14>)
92 def bitfield JMPHINT <13: 0>; // tgt Icache idx hint (disp<13:0>)
93
94 // Branch format
95 def signed bitfield BRDISP <20: 0>; // displacement
96
97 // Integer operate format(s>;
98 def bitfield INTIMM <20:13>; // integer immediate (literal)
99 def bitfield IMM <12:12>; // immediate flag
100 def bitfield INTFUNC <11: 5>; // function code
101 def bitfield RC < 4: 0>; // dest reg
102
103 // Floating-point operate format
104 def bitfield FA <25:21>;
105 def bitfield FB <20:16>;
106 def bitfield FP_FULLFUNC <15: 5>; // complete function code
107 def bitfield FP_TRAPMODE <15:13>; // trapping mode
108 def bitfield FP_ROUNDMODE <12:11>; // rounding mode
109 def bitfield FP_TYPEFUNC <10: 5>; // type+func: handiest for decoding
110 def bitfield FP_SRCTYPE <10: 9>; // source reg type
111 def bitfield FP_SHORTFUNC < 8: 5>; // short function code
112 def bitfield FP_SHORTFUNC_TOP2 <8:7>; // top 2 bits of short func code
113 def bitfield FC < 4: 0>; // dest reg
114
115 // PALcode format
116 def bitfield PALFUNC <25: 0>; // function code
117
118 // EV5 PAL instructions:
119 // HW_LD/HW_ST
120 def bitfield HW_LDST_PHYS <15>; // address is physical
121 def bitfield HW_LDST_ALT <14>; // use ALT_MODE IPR
122 def bitfield HW_LDST_WRTCK <13>; // HW_LD only: fault if no write acc
123 def bitfield HW_LDST_QUAD <12>; // size: 0=32b, 1=64b
124 def bitfield HW_LDST_VPTE <11>; // HW_LD only: is PTE fetch
125 def bitfield HW_LDST_LOCK <10>; // HW_LD only: is load locked
126 def bitfield HW_LDST_COND <10>; // HW_ST only: is store conditional
127 def signed bitfield HW_LDST_DISP <9:0>; // signed displacement
128
129 // HW_REI
130 def bitfield HW_REI_TYP <15:14>; // type: stalling vs. non-stallingk
131 def bitfield HW_REI_MBZ <13: 0>; // must be zero
132
133 // HW_MTPR/MW_MFPR
134 def bitfield HW_IPR_IDX <15:0>; // IPR index
135
136 // M5 instructions
137 def bitfield M5FUNC <7:0>;
138
139 def operand_types {{
140 'sb' : ('signed int', 8),
141 'ub' : ('unsigned int', 8),
142 'sw' : ('signed int', 16),
143 'uw' : ('unsigned int', 16),
144 'sl' : ('signed int', 32),
145 'ul' : ('unsigned int', 32),
146 'sq' : ('signed int', 64),
147 'uq' : ('unsigned int', 64),
148 'sf' : ('float', 32),
149 'df' : ('float', 64)
150 }};
151
152 def operands {{
153 # Int regs default to unsigned, but code should not count on this.
154 # For clarity, descriptions that depend on unsigned behavior should
155 # explicitly specify '.uq'.
156 'Ra': ('IntReg', 'uq', 'RA', 'IsInteger', 1),
157 'Rb': ('IntReg', 'uq', 'RB', 'IsInteger', 2),
158 'Rc': ('IntReg', 'uq', 'RC', 'IsInteger', 3),
159 'Fa': ('FloatReg', 'df', 'FA', 'IsFloating', 1),
160 'Fb': ('FloatReg', 'df', 'FB', 'IsFloating', 2),
161 'Fc': ('FloatReg', 'df', 'FC', 'IsFloating', 3),
162 'Mem': ('Mem', 'uq', None, ('IsMemRef', 'IsLoad', 'IsStore'), 4),
163 'NPC': ('NPC', 'uq', None, ( None, None, 'IsControl' ), 4),
164 'Runiq': ('ControlReg', 'uq', 'Uniq', None, 1),
165 'FPCR': (' ControlReg', 'uq', 'Fpcr', None, 1),
166 # The next two are hacks for non-full-system call-pal emulation
167 'R0': ('IntReg', 'uq', '0', None, 1),
168 'R16': ('IntReg', 'uq', '16', None, 1),
169 'R17': ('IntReg', 'uq', '17', None, 1),
170 'R18': ('IntReg', 'uq', '18', None, 1)
171 }};
172
173 ////////////////////////////////////////////////////////////////////
174 //
175 // Basic instruction classes/templates/formats etc.
176 //
177
178 output header {{
179 // uncomment the following to get SimpleScalar-compatible disassembly
180 // (useful for diffing output traces).
181 // #define SS_COMPATIBLE_DISASSEMBLY
182
183 /**
184 * Base class for all Alpha static instructions.
185 */
186 class AlphaStaticInst : public StaticInst
187 {
188 protected:
189
190 /// Make AlphaISA register dependence tags directly visible in
191 /// this class and derived classes. Maybe these should really
192 /// live here and not in the AlphaISA namespace.
193 enum DependenceTags {
194 FP_Base_DepTag = AlphaISA::FP_Base_DepTag,
195 Fpcr_DepTag = AlphaISA::Fpcr_DepTag,
196 Uniq_DepTag = AlphaISA::Uniq_DepTag,
197 IPR_Base_DepTag = AlphaISA::IPR_Base_DepTag
198 };
199
200 /// Constructor.
201 AlphaStaticInst(const char *mnem, MachInst _machInst,
202 OpClass __opClass)
203 : StaticInst(mnem, _machInst, __opClass)
204 {
205 }
206
207 /// Print a register name for disassembly given the unique
208 /// dependence tag number (FP or int).
209 void printReg(std::ostream &os, int reg) const;
210
211 std::string
212 generateDisassembly(Addr pc, const SymbolTable *symtab) const;
213 };
214 }};
215
216 output decoder {{
217 void
218 AlphaStaticInst::printReg(std::ostream &os, int reg) const
219 {
220 if (reg < FP_Base_DepTag) {
221 ccprintf(os, "r%d", reg);
222 }
223 else {
224 ccprintf(os, "f%d", reg - FP_Base_DepTag);
225 }
226 }
227
228 std::string
229 AlphaStaticInst::generateDisassembly(Addr pc,
230 const SymbolTable *symtab) const
231 {
232 std::stringstream ss;
233
234 ccprintf(ss, "%-10s ", mnemonic);
235
236 // just print the first two source regs... if there's
237 // a third one, it's a read-modify-write dest (Rc),
238 // e.g. for CMOVxx
239 if (_numSrcRegs > 0) {
240 printReg(ss, _srcRegIdx[0]);
241 }
242 if (_numSrcRegs > 1) {
243 ss << ",";
244 printReg(ss, _srcRegIdx[1]);
245 }
246
247 // just print the first dest... if there's a second one,
248 // it's generally implicit
249 if (_numDestRegs > 0) {
250 if (_numSrcRegs > 0)
251 ss << ",";
252 printReg(ss, _destRegIdx[0]);
253 }
254
255 return ss.str();
256 }
257 }};
258
259 // Declarations for execute() methods.
260 def template BasicExecDeclare {{
261 Fault execute(%(CPU_exec_context)s *, Trace::InstRecord *) const;
262 }};
263
264 // Basic instruction class declaration template.
265 def template BasicDeclare {{
266 /**
267 * Static instruction class for "%(mnemonic)s".
268 */
269 class %(class_name)s : public %(base_class)s
270 {
271 public:
272 /// Constructor.
273 %(class_name)s(MachInst machInst);
274
275 %(BasicExecDeclare)s
276 };
277 }};
278
279 // Basic instruction class constructor template.
280 def template BasicConstructor {{
281 inline %(class_name)s::%(class_name)s(MachInst machInst)
282 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s)
283 {
284 %(constructor)s;
285 }
286 }};
287
288 // Basic instruction class execute method template.
289 def template BasicExecute {{
290 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc,
291 Trace::InstRecord *traceData) const
292 {
293 Fault fault = NoFault;
294
295 %(fp_enable_check)s;
296 %(op_decl)s;
297 %(op_rd)s;
298 %(code)s;
299
300 if (fault == NoFault) {
301 %(op_wb)s;
302 }
303
304 return fault;
305 }
306 }};
307
308 // Basic decode template.
309 def template BasicDecode {{
310 return new %(class_name)s(machInst);
311 }};
312
313 // Basic decode template, passing mnemonic in as string arg to constructor.
314 def template BasicDecodeWithMnemonic {{
315 return new %(class_name)s("%(mnemonic)s", machInst);
316 }};
317
318 // The most basic instruction format... used only for a few misc. insts
319 def format BasicOperate(code, *flags) {{
320 iop = InstObjParams(name, Name, 'AlphaStaticInst', CodeBlock(code), flags)
321 header_output = BasicDeclare.subst(iop)
322 decoder_output = BasicConstructor.subst(iop)
323 decode_block = BasicDecode.subst(iop)
324 exec_output = BasicExecute.subst(iop)
325 }};
326
327
328
329 ////////////////////////////////////////////////////////////////////
330 //
331 // Nop
332 //
333
334 output header {{
335 /**
336 * Static instruction class for no-ops. This is a leaf class.
337 */
338 class Nop : public AlphaStaticInst
339 {
340 /// Disassembly of original instruction.
341 const std::string originalDisassembly;
342
343 public:
344 /// Constructor
345 Nop(const std::string _originalDisassembly, MachInst _machInst)
346 : AlphaStaticInst("nop", _machInst, No_OpClass),
347 originalDisassembly(_originalDisassembly)
348 {
349 flags[IsNop] = true;
350 }
351
352 ~Nop() { }
353
354 std::string
355 generateDisassembly(Addr pc, const SymbolTable *symtab) const;
356
357 %(BasicExecDeclare)s
358 };
359
360 /// Helper function for decoding nops. Substitute Nop object
361 /// for original inst passed in as arg (and delete latter).
362 static inline
363 AlphaStaticInst *
364 makeNop(AlphaStaticInst *inst)
365 {
366 AlphaStaticInst *nop = new Nop(inst->disassemble(0), inst->machInst);
367 delete inst;
368 return nop;
369 }
370 }};
371
372 output decoder {{
373 std::string Nop::generateDisassembly(Addr pc,
374 const SymbolTable *symtab) const
375 {
376 #ifdef SS_COMPATIBLE_DISASSEMBLY
377 return originalDisassembly;
378 #else
379 return csprintf("%-10s (%s)", "nop", originalDisassembly);
380 #endif
381 }
382 }};
383
384 output exec {{
385 Fault
386 Nop::execute(%(CPU_exec_context)s *, Trace::InstRecord *) const
387 {
388 return NoFault;
389 }
390 }};
391
392 // integer & FP operate instructions use Rc as dest, so check for
393 // Rc == 31 to detect nops
394 def template OperateNopCheckDecode {{
395 {
396 AlphaStaticInst *i = new %(class_name)s(machInst);
397 if (RC == 31) {
398 i = makeNop(i);
399 }
400 return i;
401 }
402 }};
403
404 // Like BasicOperate format, but generates NOP if RC/FC == 31
405 def format BasicOperateWithNopCheck(code, *opt_args) {{
406 iop = InstObjParams(name, Name, 'AlphaStaticInst', CodeBlock(code),
407 opt_args)
408 header_output = BasicDeclare.subst(iop)
409 decoder_output = BasicConstructor.subst(iop)
410 decode_block = OperateNopCheckDecode.subst(iop)
411 exec_output = BasicExecute.subst(iop)
412 }};
413
414 // Integer instruction templates, formats, etc.
415 ##include "m5/arch/alpha/isa/int.isa"
416
417 // Floating-point instruction templates, formats, etc.
418 ##include "m5/arch/alpha/isa/fp.isa"
419
420 // Memory instruction templates, formats, etc.
421 ##include "m5/arch/alpha/isa/mem.isa"
422
423 // Branch/jump instruction templates, formats, etc.
424 ##include "m5/arch/alpha/isa/branch.isa"
425
426 // PAL instruction templates, formats, etc.
427 ##include "m5/arch/alpha/isa/pal.isa"
428
429 // Unimplemented instruction templates, formats, etc.
430 ##include "m5/arch/alpha/isa/unimp.isa"
431
432 // Unknown instruction templates, formats, etc.
433 ##include "m5/arch/alpha/isa/unknown.isa"
434
435 // Execution utility functions
436 ##include "m5/arch/alpha/isa/util.isa"
437
438 // The actual decoder
439 ##include "m5/arch/alpha/isa/decoder.isa"