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