1// Copyright (c) 2006-2007 The Regents of The University of Michigan 2// All rights reserved. 3// 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. 14// 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. 26// 27// Authors: Ali Saidi 28// Gabe Black 29// Steve Reinhardt 30 31def template ROrImmDecode {{ 32 { 33 return (I ? (SparcStaticInst *)(new %(class_name)sImm(machInst)) 34 : (SparcStaticInst *)(new %(class_name)s(machInst))); 35 } 36}}; 37 38output header {{ 39 union DoubleSingle 40 { 41 double d; 42 uint64_t ui; 43 uint32_t s[2]; 44 DoubleSingle(double _d) : d(_d) 45 {} 46 DoubleSingle(uint64_t _ui) : ui(_ui) 47 {} 48 DoubleSingle(uint32_t _s0, uint32_t _s1) 49 { 50 s[0] = _s0; 51 s[1] = _s1; 52 } 53 }; 54}}; 55 56let {{ 57 def filterDoubles(code): 58 assignRE = re.compile(r'\s*=(?!=)', re.MULTILINE) 59 for opName in ("Frd", "Frs1", "Frs2", "Frd_N"): 60 next_pos = 0 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 65 ''' % opName) 66 operandsRE = re.compile(operandsREString, re.MULTILINE|re.VERBOSE) 67 is_src = False 68 is_dest = False 69 extension = None 70 foundOne = False 71 while 1: 72 match = operandsRE.search(code, next_pos) 73 if not match: 74 break 75 foundOne = True 76 op = match.groups() 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." 83 extension = op_ext 84 next_pos = match.end() 85 if foundOne: 86 # Get rid of any unwanted extension 87 code = operandsRE.sub(op_base, code) 88 is_int = False 89 member = "d" 90 if extension in ("sb", "ub", "shw", "uhw", "sw", "uw", "sdw", "udw"): 91 is_int = True 92 member = "ui" 93 if is_src: 94 code = ("%s = DoubleSingle(%s_high, %s_low).%s;" % \ 95 (opName, opName, opName, member)) + code 96 if is_dest: 97 code += ''' 98 %s_low = DoubleSingle(%s).s[1]; 99 %s_high = DoubleSingle(%s).s[0];''' % \ 100 (opName, opName, opName, opName) 101 if is_int: 102 code = ("uint64_t %s;" % opName) + code 103 else: 104 code = ("double %s;" % opName) + code 105 return code 106}}; 107 108let {{ 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") 118 orig_code = code 119 code = matcher.sub('Rs' + rString, orig_code) 120 imm_code = matcher.sub('imm', orig_code) 121 return (True, code, imm_code, rString, iString) 122}}; 123 124output exec {{ 125 /// Check "FP enabled" machine status bit. Called when executing any FP 126 /// instruction. 127 /// @retval Full-system mode: NoFault if FP is enabled, FpDisabled 128 /// if not. Non-full-system mode: always returns NoFault. 129 static inline Fault 130 checkFpEnableFault(ExecContext *xc) 131 { 132 if (FullSystem) { 133 PSTATE pstate = xc->readMiscReg(MISCREG_PSTATE); 134 if (pstate.pef && xc->readMiscReg(MISCREG_FPRS) & 0x4) { 135 return NoFault; 136 } else { 137 return std::make_shared<FpDisabled>(); 138 } 139 } else { 140 return NoFault; 141 } 142 } 143 144 static inline Fault 145 checkVecEnableFault(ExecContext *xc) 146 { 147 return std::make_shared<VecDisabled>(); 148 } 149}}; 150 151 152