1 // Copyright (c) 2006 The Regents of The University of Michigan
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met: redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer;
8 // redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution;
11 // neither the name of the copyright holders nor the names of its
12 // contributors may be used to endorse or promote products derived from
13 // this software without specific prior written permission.
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 ////////////////////////////////////////////////////////////////////
32 // Block Memory instructions
37 class BlockMem : public SparcMacroInst
42 // We make the assumption that all block memory operations
43 // Will take 8 instructions to execute
44 BlockMem(const char *mnem, ExtMachInst _machInst) :
45 SparcMacroInst(mnem, _machInst, No_OpClass, 8)
49 class BlockMemImm : public BlockMem
54 BlockMemImm(const char *mnem, ExtMachInst _machInst) :
55 BlockMem(mnem, _machInst)
59 class BlockMemMicro : public SparcMicroInst
64 BlockMemMicro(const char *mnem, ExtMachInst _machInst,
65 OpClass __opClass, int8_t _offset) :
66 SparcMicroInst(mnem, _machInst, __opClass),
70 std::string generateDisassembly(Addr pc,
71 const SymbolTable *symtab) const;
76 class BlockMemImmMicro : public BlockMemMicro
81 BlockMemImmMicro(const char *mnem, ExtMachInst _machInst,
82 OpClass __opClass, int8_t _offset) :
83 BlockMemMicro(mnem, _machInst, __opClass, _offset),
87 std::string generateDisassembly(Addr pc,
88 const SymbolTable *symtab) const;
95 std::string BlockMemMicro::generateDisassembly(Addr pc,
96 const SymbolTable *symtab) const
98 std::stringstream response;
99 bool load = flags[IsLoad];
100 bool save = flags[IsStore];
102 printMnemonic(response, mnemonic);
105 printReg(response, _srcRegIdx[0]);
106 ccprintf(response, ", ");
108 ccprintf(response, "[ ");
109 printReg(response, _srcRegIdx[!save ? 0 : 1]);
110 ccprintf(response, " + ");
111 printReg(response, _srcRegIdx[!save ? 1 : 2]);
112 ccprintf(response, " ]");
115 ccprintf(response, ", ");
116 printReg(response, _destRegIdx[0]);
119 return response.str();
122 std::string BlockMemImmMicro::generateDisassembly(Addr pc,
123 const SymbolTable *symtab) const
125 std::stringstream response;
126 bool load = flags[IsLoad];
127 bool save = flags[IsStore];
129 printMnemonic(response, mnemonic);
132 printReg(response, _srcRegIdx[1]);
133 ccprintf(response, ", ");
135 ccprintf(response, "[ ");
136 printReg(response, _srcRegIdx[0]);
138 ccprintf(response, " + 0x%x ]", imm);
140 ccprintf(response, " + -0x%x ]", -imm);
143 ccprintf(response, ", ");
144 printReg(response, _destRegIdx[0]);
147 return response.str();
152 def template BlockMemDeclare {{
154 * Static instruction class for a block memory operation
156 class %(class_name)s : public %(base_class)s
160 %(class_name)s(ExtMachInst machInst);
163 class %(class_name)s_0 : public %(base_class)sMicro
167 %(class_name)s_0(ExtMachInst machInst);
169 %(InitiateAccDeclare)s
170 %(CompleteAccDeclare)s
173 class %(class_name)s_1 : public %(base_class)sMicro
177 %(class_name)s_1(ExtMachInst machInst);
179 %(InitiateAccDeclare)s
180 %(CompleteAccDeclare)s
183 class %(class_name)s_2 : public %(base_class)sMicro
187 %(class_name)s_2(ExtMachInst machInst);
189 %(InitiateAccDeclare)s
190 %(CompleteAccDeclare)s
193 class %(class_name)s_3 : public %(base_class)sMicro
197 %(class_name)s_3(ExtMachInst machInst);
199 %(InitiateAccDeclare)s
200 %(CompleteAccDeclare)s
203 class %(class_name)s_4 : public %(base_class)sMicro
207 %(class_name)s_4(ExtMachInst machInst);
209 %(InitiateAccDeclare)s
210 %(CompleteAccDeclare)s
213 class %(class_name)s_5 : public %(base_class)sMicro
217 %(class_name)s_5(ExtMachInst machInst);
219 %(InitiateAccDeclare)s
220 %(CompleteAccDeclare)s
223 class %(class_name)s_6 : public %(base_class)sMicro
227 %(class_name)s_6(ExtMachInst machInst);
229 %(InitiateAccDeclare)s
230 %(CompleteAccDeclare)s
233 class %(class_name)s_7 : public %(base_class)sMicro
237 %(class_name)s_7(ExtMachInst machInst);
239 %(InitiateAccDeclare)s
240 %(CompleteAccDeclare)s
245 // Basic instruction class constructor template.
246 def template BlockMemConstructor {{
247 inline %(class_name)s::%(class_name)s(ExtMachInst machInst)
248 : %(base_class)s("%(mnemonic)s", machInst)
251 microOps[0] = new %(class_name)s_0(machInst);
252 microOps[1] = new %(class_name)s_1(machInst);
253 microOps[2] = new %(class_name)s_2(machInst);
254 microOps[3] = new %(class_name)s_3(machInst);
255 microOps[4] = new %(class_name)s_4(machInst);
256 microOps[5] = new %(class_name)s_5(machInst);
257 microOps[6] = new %(class_name)s_6(machInst);
258 microOps[7] = new %(class_name)s_7(machInst);
262 def template BlockMemMicroConstructor {{
263 inline %(class_name)s::
264 %(class_name)s_%(micro_pc)s::
265 %(class_name)s_%(micro_pc)s(ExtMachInst machInst) :
266 %(base_class)sMicro("%(mnemonic)s[%(micro_pc)s]",
267 machInst, %(op_class)s, %(micro_pc)s * 8)
276 def doBlockMemFormat(code, faultCode, execute, name, Name, asi, opt_flags):
277 # XXX Need to take care of pstate.hpriv as well. The lower ASIs
278 # are split into ones that are available in priv and hpriv, and
279 # those that are only available in hpriv
280 addrCalcReg = 'EA = Rs1 + Rs2 + offset;'
281 addrCalcImm = 'EA = Rs1 + imm + offset;'
282 iop = InstObjParams(name, Name, 'BlockMem', code, opt_flags)
283 iop_imm = InstObjParams(name, Name + 'Imm', 'BlockMemImm', code, opt_flags)
284 header_output = BlockMemDeclare.subst(iop) + BlockMemDeclare.subst(iop_imm)
285 decoder_output = BlockMemConstructor.subst(iop) + BlockMemConstructor.subst(iop_imm)
286 decode_block = ROrImmDecode.subst(iop)
287 matcher = re.compile(r'Frd_N')
289 for microPc in range(8):
292 flag_code = "flags[IsLastMicroOp] = true;"
294 flag_code = "flags[IsDelayedCommit] = true;"
295 pcedCode = matcher.sub("Frd_%d" % microPc, code)
296 iop = InstObjParams(name, Name, 'BlockMem', pcedCode,
297 opt_flags, {"ea_code": addrCalcReg,
298 "fault_check": faultCode, "micro_pc": microPc,
299 "set_flags": flag_code})
300 iop_imm = InstObjParams(name, Name + 'Imm', 'BlockMemImm', pcedCode,
301 opt_flags, {"ea_code": addrCalcImm,
302 "fault_check": faultCode, "micro_pc": microPc,
303 "set_flags": flag_code})
304 decoder_output += BlockMemMicroConstructor.subst(iop)
305 decoder_output += BlockMemMicroConstructor.subst(iop_imm)
306 exec_output += doDualSplitExecute(
307 pcedCode, addrCalcReg, addrCalcImm, execute, faultCode,
308 makeMicroName(name, microPc),
309 makeMicroName(name + "Imm", microPc),
310 makeMicroName(Name, microPc),
311 makeMicroName(Name + "Imm", microPc),
314 return (header_output, decoder_output, exec_output, decode_block)
317 def format BlockLoad(code, asi, *opt_flags) {{
318 # We need to make sure to check the highest priority fault last.
319 # That way, if other faults have been detected, they'll be overwritten
320 # rather than the other way around.
321 faultCode = AlternateASIPrivFaultCheck + BlockAlignmentFaultCheck
325 decode_block) = doBlockMemFormat(code, faultCode,
326 LoadExecute, name, Name, asi, opt_flags)
329 def format BlockStore(code, asi, *opt_flags) {{
330 # We need to make sure to check the highest priority fault last.
331 # That way, if other faults have been detected, they'll be overwritten
332 # rather than the other way around.
333 faultCode = AlternateASIPrivFaultCheck + BlockAlignmentFaultCheck
337 decode_block) = doBlockMemFormat(code, faultCode,
338 StoreExecute, name, Name, asi, opt_flags)