3 // Copyright
\eN) 2007 MIPS Technologies, Inc. All Rights Reserved
5 // This software is part of the M5 simulator.
7 // THIS IS A LEGAL AGREEMENT. BY DOWNLOADING, USING, COPYING, CREATING
8 // DERIVATIVE WORKS, AND/OR DISTRIBUTING THIS SOFTWARE YOU ARE AGREEING
9 // TO THESE TERMS AND CONDITIONS.
11 // Permission is granted to use, copy, create derivative works and
12 // distribute this software and such derivative works for any purpose,
13 // so long as (1) the copyright notice above, this grant of permission,
14 // and the disclaimer below appear in all copies and derivative works
15 // made, (2) the copyright notice above is augmented as appropriate to
16 // reflect the addition of any new copyrightable work in a derivative
17 // work (e.g., Copyright
\eN) <Publication Year> Copyright Owner), and (3)
18 // the name of MIPS Technologies, Inc. (
\e$(B!H
\e(BMIPS
\e$(B!I
\e(B) is not used in any
19 // advertising or publicity pertaining to the use or distribution of
20 // this software without specific, written prior authorization.
22 // THIS SOFTWARE IS PROVIDED
\e$(B!H
\e(BAS IS.
\e$(B!I
\e(B MIPS MAKES NO WARRANTIES AND
23 // DISCLAIMS ALL WARRANTIES, WHETHER EXPRESS, STATUTORY, IMPLIED OR
24 // OTHERWISE, INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
26 // NON-INFRINGEMENT OF THIRD PARTY RIGHTS, REGARDING THIS SOFTWARE.
27 // IN NO EVENT SHALL MIPS BE LIABLE FOR ANY DAMAGES, INCLUDING DIRECT,
28 // INDIRECT, INCIDENTAL, CONSEQUENTIAL, SPECIAL, OR PUNITIVE DAMAGES OF
29 // ANY KIND OR NATURE, ARISING OUT OF OR IN CONNECTION WITH THIS AGREEMENT,
30 // THIS SOFTWARE AND/OR THE USE OF THIS SOFTWARE, WHETHER SUCH LIABILITY
31 // IS ASSERTED ON THE BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE OR
32 // STRICT LIABILITY), OR OTHERWISE, EVEN IF MIPS HAS BEEN WARNED OF THE
33 // POSSIBILITY OF ANY SUCH LOSS OR DAMAGE IN ADVANCE.
35 //Authors: Korey L. Sewell
38 ////////////////////////////////////////////////////////////////////
40 // Coprocessor instructions
43 //Outputs to decoder.hh
46 class CP0Control : public MipsStaticInst
51 CP0Control(const char *mnem, MachInst _machInst, OpClass __opClass) :
52 MipsStaticInst(mnem, _machInst, __opClass)
56 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
58 class CP0TLB : public MipsStaticInst
63 CP0TLB(const char *mnem, MachInst _machInst, OpClass __opClass) :
64 MipsStaticInst(mnem, _machInst, __opClass)
68 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
72 class CP1Control : public MipsStaticInst
77 CP1Control(const char *mnem, MachInst _machInst, OpClass __opClass) :
78 MipsStaticInst(mnem, _machInst, __opClass)
82 std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const;
87 // Basic instruction class execute method template.
88 def template CP0Execute {{
89 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const
91 Fault fault = NoFault;
95 if (isCoprocessorEnabled(xc, 0)) {
98 fault = new CoprocessorUnusableFault(0);
109 def template CP1Execute {{
110 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const
112 Fault fault = NoFault;
116 if (isCoprocessorEnabled(xc, 1)) {
119 fault = new CoprocessorUnusableFault(1);
129 // Basic instruction class execute method template.
130 def template ControlTLBExecute {{
131 Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, Trace::InstRecord *traceData) const
133 Fault fault = NoFault;
138 if (isCoprocessor0Enabled(xc)) {
142 fault = new ReservedInstructionFault();
145 fault = new CoprocessorUnusableFault(0);
147 #else // Syscall Emulation Mode - No TLB Instructions
148 fault = new ReservedInstructionFault();
160 //Outputs to decoder.cc
162 std::string CP0Control::generateDisassembly(Addr pc, const SymbolTable *symtab) const
164 std::stringstream ss;
165 ccprintf(ss, "%-10s r%d, %d, %d", mnemonic, RT, RD, SEL);
168 std::string CP0TLB::generateDisassembly(Addr pc, const SymbolTable *symtab) const
170 std::stringstream ss;
171 ccprintf(ss, "%-10s r%d, %d, %d", mnemonic, RT, RD, SEL);
174 std::string CP1Control::generateDisassembly(Addr pc, const SymbolTable *symtab) const
176 std::stringstream ss;
177 ccprintf(ss, "%-10s r%d, f%d", mnemonic, RT, FS);
184 bool isCoprocessorEnabled(%(CPU_exec_context)s *xc, unsigned cop_num)
189 MiscReg Stat = xc->readMiscReg(MipsISA::Status);
194 MiscReg Dbg = xc->readMiscReg(MipsISA::Debug);
195 if((Stat & 0x10000006) == 0 // EXL, ERL or CU0 set, CP0 accessible
196 && (Dbg & 0x40000000) == 0 // DM bit set, CP0 accessible
197 && (Stat & 0x00000018) != 0) { // KSU = 0, kernel mode is base mode
198 // Unable to use Status_CU0, etc directly, using bitfields & masks
205 if((Stat & 0x20000000) == 0) // CU1 is reset
209 if((Stat & 0x40000000) == 0) // CU2 is reset
213 if((Stat & 0x80000000) == 0) // CU3 is reset
216 default: panic("Invalid Coprocessor Number Specified");
222 bool inline isCoprocessor0Enabled(%(CPU_exec_context)s *xc)
225 MiscReg Stat = xc->readMiscRegNoEffect(MipsISA::Status);
226 MiscReg Dbg = xc->readMiscRegNoEffect(MipsISA::Debug);
227 if((Stat & 0x10000006) == 0 // EXL, ERL or CU0 set, CP0 accessible
228 && (Dbg & 0x40000000) == 0 // DM bit set, CP0 accessible
229 && (Stat & 0x00000018) != 0) { // KSU = 0, kernel mode is base mode
230 // Unable to use Status_CU0, etc directly, using bitfields & masks
234 //printf("Syscall Emulation Mode: CP0 Enable Check defaults to TRUE\n");
238 bool isMMUTLB(%(CPU_exec_context)s *xc)
241 if((xc->readMiscRegNoEffect(MipsISA::Config) & 0x00000380)==0x80)
248 def format CP0Control(code, *flags) {{
249 flags += ('IsNonSpeculative', )
250 iop = InstObjParams(name, Name, 'CP0Control', code, flags)
251 header_output = BasicDeclare.subst(iop)
252 decoder_output = BasicConstructor.subst(iop)
253 decode_block = BasicDecode.subst(iop)
254 exec_output = CP0Execute.subst(iop)
256 def format CP0TLB(code, *flags) {{
257 flags += ('IsNonSpeculative', )
258 iop = InstObjParams(name, Name, 'CP0Control', code, flags)
259 header_output = BasicDeclare.subst(iop)
260 decoder_output = BasicConstructor.subst(iop)
261 decode_block = BasicDecode.subst(iop)
262 exec_output = ControlTLBExecute.subst(iop)
264 def format CP1Control(code, *flags) {{
265 flags += ('IsNonSpeculative', )
266 iop = InstObjParams(name, Name, 'CP1Control', code, flags)
267 header_output = BasicDeclare.subst(iop)
268 decoder_output = BasicConstructor.subst(iop)
269 decode_block = BasicDecode.subst(iop)
270 exec_output = CP1Execute.subst(iop)