1 // Copyright (c) 2006-2007 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.
31 def template ROrImmDecode {{
33 return (I ? (SparcStaticInst *)(new %(class_name)sImm(machInst))
34 : (SparcStaticInst *)(new %(class_name)s(machInst)));
44 DoubleSingle(double _d) : d(_d)
46 DoubleSingle(uint64_t _ui) : ui(_ui)
48 DoubleSingle(uint32_t _s0, uint32_t _s1)
57 def filterDoubles(code):
58 assignRE = re.compile(r'\s*=(?!=)', re.MULTILINE)
59 for opName in ("Frd", "Frs1", "Frs2", "Frd_N"):
61 operandsREString = (r'''
62 (?<!\w) # neg. lookbehind assertion: prevent partial matches
63 ((%s)(?:_([^\W_]+))?) # match: operand with optional '.' then suffix
64 (?!\w) # neg. lookahead assertion: prevent partial matches
66 operandsRE = re.compile(operandsREString, re.MULTILINE|re.VERBOSE)
72 match = operandsRE.search(code, next_pos)
77 (op_full, op_base, op_ext) = op
78 is_dest_local = (assignRE.match(code, match.end()) != None)
79 is_dest = is_dest or is_dest_local
80 is_src = is_src or not is_dest_local
81 if extension and extension != op_ext:
82 raise Exception, "Inconsistent extensions in double filter."
84 next_pos = match.end()
86 # Get rid of any unwanted extension
87 code = operandsRE.sub(op_base, code)
90 if extension in ("sb", "ub", "shw", "uhw", "sw", "uw", "sdw", "udw"):
94 code = ("%s = DoubleSingle(%s_high, %s_low).%s;" % \
95 (opName, opName, opName, member)) + code
98 %s_low = DoubleSingle(%s).s[1];
99 %s_high = DoubleSingle(%s).s[0];''' % \
100 (opName, opName, opName, opName)
102 code = ("uint64_t %s;" % opName) + code
104 code = ("double %s;" % opName) + code
109 def splitOutImm(code):
110 matcher = re.compile(r'Rs(?P<rNum>\d)_or_imm(?P<iNum>\d+)(?P<typeQual>_[^\W_]+)?')
111 rOrImmMatch = matcher.search(code)
112 if (rOrImmMatch == None):
113 return (False, code, '', '', '')
114 rString = rOrImmMatch.group("rNum")
115 if (rOrImmMatch.group("typeQual") != None):
116 rString += rOrImmMatch.group("typeQual")
117 iString = rOrImmMatch.group("iNum")
119 code = matcher.sub('Rs' + rString, orig_code)
120 imm_code = matcher.sub('imm', orig_code)
121 return (True, code, imm_code, rString, iString)
125 /// Check "FP enabled" machine status bit. Called when executing any FP
127 /// @retval Full-system mode: NoFault if FP is enabled, FpDisabled
128 /// if not. Non-full-system mode: always returns NoFault.
130 checkFpEnableFault(ExecContext *xc)
133 PSTATE pstate = xc->readMiscReg(MISCREG_PSTATE);
134 if (pstate.pef && xc->readMiscReg(MISCREG_FPRS) & 0x4) {
137 return std::make_shared<FpDisabled>();
145 checkVecEnableFault(ExecContext *xc)
147 return std::make_shared<VecDisabled>();