regop.isa revision 6461
15409Sgblack@eecs.umich.edu// Copyright (c) 2007-2008 The Hewlett-Packard Development Company 24519Sgblack@eecs.umich.edu// All rights reserved. 34519Sgblack@eecs.umich.edu// 44519Sgblack@eecs.umich.edu// Redistribution and use of this software in source and binary forms, 54519Sgblack@eecs.umich.edu// with or without modification, are permitted provided that the 64519Sgblack@eecs.umich.edu// following conditions are met: 74519Sgblack@eecs.umich.edu// 84519Sgblack@eecs.umich.edu// The software must be used only for Non-Commercial Use which means any 94519Sgblack@eecs.umich.edu// use which is NOT directed to receiving any direct monetary 104519Sgblack@eecs.umich.edu// compensation for, or commercial advantage from such use. Illustrative 114519Sgblack@eecs.umich.edu// examples of non-commercial use are academic research, personal study, 124519Sgblack@eecs.umich.edu// teaching, education and corporate research & development. 134519Sgblack@eecs.umich.edu// Illustrative examples of commercial use are distributing products for 144519Sgblack@eecs.umich.edu// commercial advantage and providing services using the software for 154519Sgblack@eecs.umich.edu// commercial advantage. 164519Sgblack@eecs.umich.edu// 174519Sgblack@eecs.umich.edu// If you wish to use this software or functionality therein that may be 184519Sgblack@eecs.umich.edu// covered by patents for commercial use, please contact: 194519Sgblack@eecs.umich.edu// Director of Intellectual Property Licensing 204519Sgblack@eecs.umich.edu// Office of Strategy and Technology 214519Sgblack@eecs.umich.edu// Hewlett-Packard Company 224519Sgblack@eecs.umich.edu// 1501 Page Mill Road 234519Sgblack@eecs.umich.edu// Palo Alto, California 94304 244519Sgblack@eecs.umich.edu// 254519Sgblack@eecs.umich.edu// Redistributions of source code must retain the above copyright notice, 264519Sgblack@eecs.umich.edu// this list of conditions and the following disclaimer. Redistributions 274519Sgblack@eecs.umich.edu// in binary form must reproduce the above copyright notice, this list of 284519Sgblack@eecs.umich.edu// conditions and the following disclaimer in the documentation and/or 294519Sgblack@eecs.umich.edu// other materials provided with the distribution. Neither the name of 304519Sgblack@eecs.umich.edu// the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 314519Sgblack@eecs.umich.edu// contributors may be used to endorse or promote products derived from 324519Sgblack@eecs.umich.edu// this software without specific prior written permission. No right of 334519Sgblack@eecs.umich.edu// sublicense is granted herewith. Derivatives of the software and 344519Sgblack@eecs.umich.edu// output created using the software may be prepared, but only for 354519Sgblack@eecs.umich.edu// Non-Commercial Uses. Derivatives of the software may be shared with 364519Sgblack@eecs.umich.edu// others provided: (i) the others agree to abide by the list of 374519Sgblack@eecs.umich.edu// conditions herein which includes the Non-Commercial Use restrictions; 384519Sgblack@eecs.umich.edu// and (ii) such Derivatives of the software include the above copyright 394519Sgblack@eecs.umich.edu// notice to acknowledge the contribution from this software where 404519Sgblack@eecs.umich.edu// applicable, this list of conditions and the disclaimer below. 414519Sgblack@eecs.umich.edu// 424519Sgblack@eecs.umich.edu// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 434519Sgblack@eecs.umich.edu// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 444519Sgblack@eecs.umich.edu// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 454519Sgblack@eecs.umich.edu// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 464519Sgblack@eecs.umich.edu// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 474519Sgblack@eecs.umich.edu// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 484519Sgblack@eecs.umich.edu// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 494519Sgblack@eecs.umich.edu// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 504519Sgblack@eecs.umich.edu// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 514519Sgblack@eecs.umich.edu// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 524519Sgblack@eecs.umich.edu// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 534519Sgblack@eecs.umich.edu// 544519Sgblack@eecs.umich.edu// Authors: Gabe Black 554519Sgblack@eecs.umich.edu 564519Sgblack@eecs.umich.edu////////////////////////////////////////////////////////////////////////// 574519Sgblack@eecs.umich.edu// 584519Sgblack@eecs.umich.edu// RegOp Microop templates 594519Sgblack@eecs.umich.edu// 604519Sgblack@eecs.umich.edu////////////////////////////////////////////////////////////////////////// 614519Sgblack@eecs.umich.edu 624519Sgblack@eecs.umich.edudef template MicroRegOpExecute {{ 634519Sgblack@eecs.umich.edu Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 644519Sgblack@eecs.umich.edu Trace::InstRecord *traceData) const 654519Sgblack@eecs.umich.edu { 664519Sgblack@eecs.umich.edu Fault fault = NoFault; 674519Sgblack@eecs.umich.edu 684809Sgblack@eecs.umich.edu DPRINTF(X86, "The data size is %d\n", dataSize); 694519Sgblack@eecs.umich.edu %(op_decl)s; 704519Sgblack@eecs.umich.edu %(op_rd)s; 714688Sgblack@eecs.umich.edu 724688Sgblack@eecs.umich.edu if(%(cond_check)s) 734688Sgblack@eecs.umich.edu { 744688Sgblack@eecs.umich.edu %(code)s; 754688Sgblack@eecs.umich.edu %(flag_code)s; 764688Sgblack@eecs.umich.edu } 774708Sgblack@eecs.umich.edu else 784708Sgblack@eecs.umich.edu { 794708Sgblack@eecs.umich.edu %(else_code)s; 804708Sgblack@eecs.umich.edu } 814519Sgblack@eecs.umich.edu 824519Sgblack@eecs.umich.edu //Write the resulting state to the execution context 834519Sgblack@eecs.umich.edu if(fault == NoFault) 844519Sgblack@eecs.umich.edu { 854519Sgblack@eecs.umich.edu %(op_wb)s; 864519Sgblack@eecs.umich.edu } 874519Sgblack@eecs.umich.edu return fault; 884519Sgblack@eecs.umich.edu } 894519Sgblack@eecs.umich.edu}}; 904519Sgblack@eecs.umich.edu 914519Sgblack@eecs.umich.edudef template MicroRegOpImmExecute {{ 924951Sgblack@eecs.umich.edu Fault %(class_name)s::execute(%(CPU_exec_context)s *xc, 934519Sgblack@eecs.umich.edu Trace::InstRecord *traceData) const 944519Sgblack@eecs.umich.edu { 954519Sgblack@eecs.umich.edu Fault fault = NoFault; 964519Sgblack@eecs.umich.edu 974519Sgblack@eecs.umich.edu %(op_decl)s; 984519Sgblack@eecs.umich.edu %(op_rd)s; 994688Sgblack@eecs.umich.edu 1004688Sgblack@eecs.umich.edu if(%(cond_check)s) 1014688Sgblack@eecs.umich.edu { 1024688Sgblack@eecs.umich.edu %(code)s; 1034688Sgblack@eecs.umich.edu %(flag_code)s; 1044688Sgblack@eecs.umich.edu } 1054708Sgblack@eecs.umich.edu else 1064708Sgblack@eecs.umich.edu { 1074708Sgblack@eecs.umich.edu %(else_code)s; 1084708Sgblack@eecs.umich.edu } 1094519Sgblack@eecs.umich.edu 1104519Sgblack@eecs.umich.edu //Write the resulting state to the execution context 1114519Sgblack@eecs.umich.edu if(fault == NoFault) 1124519Sgblack@eecs.umich.edu { 1134519Sgblack@eecs.umich.edu %(op_wb)s; 1144519Sgblack@eecs.umich.edu } 1154519Sgblack@eecs.umich.edu return fault; 1164519Sgblack@eecs.umich.edu } 1174519Sgblack@eecs.umich.edu}}; 1184519Sgblack@eecs.umich.edu 1194519Sgblack@eecs.umich.edudef template MicroRegOpDeclare {{ 1204519Sgblack@eecs.umich.edu class %(class_name)s : public %(base_class)s 1214519Sgblack@eecs.umich.edu { 1224519Sgblack@eecs.umich.edu protected: 1234519Sgblack@eecs.umich.edu void buildMe(); 1244519Sgblack@eecs.umich.edu 1254519Sgblack@eecs.umich.edu public: 1264519Sgblack@eecs.umich.edu %(class_name)s(ExtMachInst _machInst, 1274519Sgblack@eecs.umich.edu const char * instMnem, 1284519Sgblack@eecs.umich.edu bool isMicro, bool isDelayed, bool isFirst, bool isLast, 1296345Sgblack@eecs.umich.edu InstRegIndex _src1, InstRegIndex _src2, InstRegIndex _dest, 1304712Sgblack@eecs.umich.edu uint8_t _dataSize, uint16_t _ext); 1314519Sgblack@eecs.umich.edu 1324519Sgblack@eecs.umich.edu %(class_name)s(ExtMachInst _machInst, 1334519Sgblack@eecs.umich.edu const char * instMnem, 1346345Sgblack@eecs.umich.edu InstRegIndex _src1, InstRegIndex _src2, InstRegIndex _dest, 1354712Sgblack@eecs.umich.edu uint8_t _dataSize, uint16_t _ext); 1364519Sgblack@eecs.umich.edu 1374519Sgblack@eecs.umich.edu %(BasicExecDeclare)s 1384519Sgblack@eecs.umich.edu }; 1394519Sgblack@eecs.umich.edu}}; 1404519Sgblack@eecs.umich.edu 1414519Sgblack@eecs.umich.edudef template MicroRegOpImmDeclare {{ 1424519Sgblack@eecs.umich.edu 1434951Sgblack@eecs.umich.edu class %(class_name)s : public %(base_class)s 1444519Sgblack@eecs.umich.edu { 1454519Sgblack@eecs.umich.edu protected: 1464519Sgblack@eecs.umich.edu void buildMe(); 1474519Sgblack@eecs.umich.edu 1484519Sgblack@eecs.umich.edu public: 1494951Sgblack@eecs.umich.edu %(class_name)s(ExtMachInst _machInst, 1504519Sgblack@eecs.umich.edu const char * instMnem, 1514519Sgblack@eecs.umich.edu bool isMicro, bool isDelayed, bool isFirst, bool isLast, 1526345Sgblack@eecs.umich.edu InstRegIndex _src1, uint16_t _imm8, InstRegIndex _dest, 1534712Sgblack@eecs.umich.edu uint8_t _dataSize, uint16_t _ext); 1544519Sgblack@eecs.umich.edu 1554951Sgblack@eecs.umich.edu %(class_name)s(ExtMachInst _machInst, 1564519Sgblack@eecs.umich.edu const char * instMnem, 1576345Sgblack@eecs.umich.edu InstRegIndex _src1, uint16_t _imm8, InstRegIndex _dest, 1584712Sgblack@eecs.umich.edu uint8_t _dataSize, uint16_t _ext); 1594519Sgblack@eecs.umich.edu 1604519Sgblack@eecs.umich.edu %(BasicExecDeclare)s 1614519Sgblack@eecs.umich.edu }; 1624519Sgblack@eecs.umich.edu}}; 1634519Sgblack@eecs.umich.edu 1644519Sgblack@eecs.umich.edudef template MicroRegOpConstructor {{ 1654519Sgblack@eecs.umich.edu 1664519Sgblack@eecs.umich.edu inline void %(class_name)s::buildMe() 1674519Sgblack@eecs.umich.edu { 1684519Sgblack@eecs.umich.edu %(constructor)s; 1694519Sgblack@eecs.umich.edu } 1704519Sgblack@eecs.umich.edu 1714519Sgblack@eecs.umich.edu inline %(class_name)s::%(class_name)s( 1724519Sgblack@eecs.umich.edu ExtMachInst machInst, const char * instMnem, 1736345Sgblack@eecs.umich.edu InstRegIndex _src1, InstRegIndex _src2, InstRegIndex _dest, 1744712Sgblack@eecs.umich.edu uint8_t _dataSize, uint16_t _ext) : 1754519Sgblack@eecs.umich.edu %(base_class)s(machInst, "%(mnemonic)s", instMnem, 1764581Sgblack@eecs.umich.edu false, false, false, false, 1774688Sgblack@eecs.umich.edu _src1, _src2, _dest, _dataSize, _ext, 1784581Sgblack@eecs.umich.edu %(op_class)s) 1794519Sgblack@eecs.umich.edu { 1804519Sgblack@eecs.umich.edu buildMe(); 1814519Sgblack@eecs.umich.edu } 1824519Sgblack@eecs.umich.edu 1834519Sgblack@eecs.umich.edu inline %(class_name)s::%(class_name)s( 1844519Sgblack@eecs.umich.edu ExtMachInst machInst, const char * instMnem, 1854519Sgblack@eecs.umich.edu bool isMicro, bool isDelayed, bool isFirst, bool isLast, 1866345Sgblack@eecs.umich.edu InstRegIndex _src1, InstRegIndex _src2, InstRegIndex _dest, 1874712Sgblack@eecs.umich.edu uint8_t _dataSize, uint16_t _ext) : 1884519Sgblack@eecs.umich.edu %(base_class)s(machInst, "%(mnemonic)s", instMnem, 1894581Sgblack@eecs.umich.edu isMicro, isDelayed, isFirst, isLast, 1904688Sgblack@eecs.umich.edu _src1, _src2, _dest, _dataSize, _ext, 1914581Sgblack@eecs.umich.edu %(op_class)s) 1924519Sgblack@eecs.umich.edu { 1934519Sgblack@eecs.umich.edu buildMe(); 1944519Sgblack@eecs.umich.edu } 1954519Sgblack@eecs.umich.edu}}; 1964519Sgblack@eecs.umich.edu 1974519Sgblack@eecs.umich.edudef template MicroRegOpImmConstructor {{ 1984519Sgblack@eecs.umich.edu 1994951Sgblack@eecs.umich.edu inline void %(class_name)s::buildMe() 2004519Sgblack@eecs.umich.edu { 2014519Sgblack@eecs.umich.edu %(constructor)s; 2024519Sgblack@eecs.umich.edu } 2034519Sgblack@eecs.umich.edu 2044951Sgblack@eecs.umich.edu inline %(class_name)s::%(class_name)s( 2054519Sgblack@eecs.umich.edu ExtMachInst machInst, const char * instMnem, 2066345Sgblack@eecs.umich.edu InstRegIndex _src1, uint16_t _imm8, InstRegIndex _dest, 2074712Sgblack@eecs.umich.edu uint8_t _dataSize, uint16_t _ext) : 2084519Sgblack@eecs.umich.edu %(base_class)s(machInst, "%(mnemonic)s", instMnem, 2094581Sgblack@eecs.umich.edu false, false, false, false, 2104688Sgblack@eecs.umich.edu _src1, _imm8, _dest, _dataSize, _ext, 2114581Sgblack@eecs.umich.edu %(op_class)s) 2124519Sgblack@eecs.umich.edu { 2134519Sgblack@eecs.umich.edu buildMe(); 2144519Sgblack@eecs.umich.edu } 2154519Sgblack@eecs.umich.edu 2164951Sgblack@eecs.umich.edu inline %(class_name)s::%(class_name)s( 2174519Sgblack@eecs.umich.edu ExtMachInst machInst, const char * instMnem, 2184519Sgblack@eecs.umich.edu bool isMicro, bool isDelayed, bool isFirst, bool isLast, 2196345Sgblack@eecs.umich.edu InstRegIndex _src1, uint16_t _imm8, InstRegIndex _dest, 2204712Sgblack@eecs.umich.edu uint8_t _dataSize, uint16_t _ext) : 2214519Sgblack@eecs.umich.edu %(base_class)s(machInst, "%(mnemonic)s", instMnem, 2224581Sgblack@eecs.umich.edu isMicro, isDelayed, isFirst, isLast, 2234688Sgblack@eecs.umich.edu _src1, _imm8, _dest, _dataSize, _ext, 2244581Sgblack@eecs.umich.edu %(op_class)s) 2254519Sgblack@eecs.umich.edu { 2264519Sgblack@eecs.umich.edu buildMe(); 2274519Sgblack@eecs.umich.edu } 2284519Sgblack@eecs.umich.edu}}; 2294519Sgblack@eecs.umich.edu 2305075Sgblack@eecs.umich.eduoutput header {{ 2315075Sgblack@eecs.umich.edu void 2325075Sgblack@eecs.umich.edu divide(uint64_t dividend, uint64_t divisor, 2335075Sgblack@eecs.umich.edu uint64_t "ient, uint64_t &remainder); 2345428Sgblack@eecs.umich.edu 2355428Sgblack@eecs.umich.edu enum SegmentSelectorCheck { 2365674Sgblack@eecs.umich.edu SegNoCheck, SegCSCheck, SegCallGateCheck, SegIntGateCheck, 2375899Sgblack@eecs.umich.edu SegSoftIntGateCheck, SegSSCheck, SegIretCheck, SegIntCSCheck, 2385936Sgblack@eecs.umich.edu SegTRCheck, SegTSSCheck, SegInGDTCheck, SegLDTCheck 2395428Sgblack@eecs.umich.edu }; 2405678Sgblack@eecs.umich.edu 2415678Sgblack@eecs.umich.edu enum LongModeDescriptorType { 2425678Sgblack@eecs.umich.edu LDT64 = 2, 2435678Sgblack@eecs.umich.edu AvailableTSS64 = 9, 2445678Sgblack@eecs.umich.edu BusyTSS64 = 0xb, 2455678Sgblack@eecs.umich.edu CallGate64 = 0xc, 2465678Sgblack@eecs.umich.edu IntGate64 = 0xe, 2475678Sgblack@eecs.umich.edu TrapGate64 = 0xf 2485678Sgblack@eecs.umich.edu }; 2495075Sgblack@eecs.umich.edu}}; 2505075Sgblack@eecs.umich.edu 2515075Sgblack@eecs.umich.eduoutput decoder {{ 2525075Sgblack@eecs.umich.edu void 2535075Sgblack@eecs.umich.edu divide(uint64_t dividend, uint64_t divisor, 2545075Sgblack@eecs.umich.edu uint64_t "ient, uint64_t &remainder) 2555075Sgblack@eecs.umich.edu { 2565075Sgblack@eecs.umich.edu //Check for divide by zero. 2575075Sgblack@eecs.umich.edu if (divisor == 0) 2585075Sgblack@eecs.umich.edu panic("Divide by zero!\\n"); 2595075Sgblack@eecs.umich.edu //If the divisor is bigger than the dividend, don't do anything. 2605075Sgblack@eecs.umich.edu if (divisor <= dividend) { 2615075Sgblack@eecs.umich.edu //Shift the divisor so it's msb lines up with the dividend. 2625075Sgblack@eecs.umich.edu int dividendMsb = findMsbSet(dividend); 2635075Sgblack@eecs.umich.edu int divisorMsb = findMsbSet(divisor); 2645075Sgblack@eecs.umich.edu int shift = dividendMsb - divisorMsb; 2655075Sgblack@eecs.umich.edu divisor <<= shift; 2665075Sgblack@eecs.umich.edu //Compute what we'll add to the quotient if the divisor isn't 2675075Sgblack@eecs.umich.edu //now larger than the dividend. 2685075Sgblack@eecs.umich.edu uint64_t quotientBit = 1; 2695075Sgblack@eecs.umich.edu quotientBit <<= shift; 2705075Sgblack@eecs.umich.edu //If we need to step back a bit (no pun intended) because the 2715075Sgblack@eecs.umich.edu //divisor got too to large, do that here. This is the "or two" 2725075Sgblack@eecs.umich.edu //part of one or two bit division. 2735075Sgblack@eecs.umich.edu if (divisor > dividend) { 2745075Sgblack@eecs.umich.edu quotientBit >>= 1; 2755075Sgblack@eecs.umich.edu divisor >>= 1; 2765075Sgblack@eecs.umich.edu } 2775075Sgblack@eecs.umich.edu //Decrement the remainder and increment the quotient. 2785075Sgblack@eecs.umich.edu quotient += quotientBit; 2795075Sgblack@eecs.umich.edu remainder -= divisor; 2805075Sgblack@eecs.umich.edu } 2815075Sgblack@eecs.umich.edu } 2825075Sgblack@eecs.umich.edu}}; 2835075Sgblack@eecs.umich.edu 2844519Sgblack@eecs.umich.edulet {{ 2855040Sgblack@eecs.umich.edu # Make these empty strings so that concatenating onto 2865040Sgblack@eecs.umich.edu # them will always work. 2875040Sgblack@eecs.umich.edu header_output = "" 2885040Sgblack@eecs.umich.edu decoder_output = "" 2895040Sgblack@eecs.umich.edu exec_output = "" 2905040Sgblack@eecs.umich.edu 2915040Sgblack@eecs.umich.edu immTemplates = ( 2925040Sgblack@eecs.umich.edu MicroRegOpImmDeclare, 2935040Sgblack@eecs.umich.edu MicroRegOpImmConstructor, 2945040Sgblack@eecs.umich.edu MicroRegOpImmExecute) 2955040Sgblack@eecs.umich.edu 2965040Sgblack@eecs.umich.edu regTemplates = ( 2975040Sgblack@eecs.umich.edu MicroRegOpDeclare, 2985040Sgblack@eecs.umich.edu MicroRegOpConstructor, 2995040Sgblack@eecs.umich.edu MicroRegOpExecute) 3005040Sgblack@eecs.umich.edu 3015040Sgblack@eecs.umich.edu class RegOpMeta(type): 3025040Sgblack@eecs.umich.edu def buildCppClasses(self, name, Name, suffix, \ 3035040Sgblack@eecs.umich.edu code, flag_code, cond_check, else_code): 3045040Sgblack@eecs.umich.edu 3055040Sgblack@eecs.umich.edu # Globals to stick the output in 3065040Sgblack@eecs.umich.edu global header_output 3075040Sgblack@eecs.umich.edu global decoder_output 3085040Sgblack@eecs.umich.edu global exec_output 3095040Sgblack@eecs.umich.edu 3105040Sgblack@eecs.umich.edu # Stick all the code together so it can be searched at once 3115040Sgblack@eecs.umich.edu allCode = "|".join((code, flag_code, cond_check, else_code)) 3125040Sgblack@eecs.umich.edu 3135040Sgblack@eecs.umich.edu # If op2 is used anywhere, make register and immediate versions 3145040Sgblack@eecs.umich.edu # of this code. 3155062Sgblack@eecs.umich.edu matcher = re.compile("(?<!\\w)(?P<prefix>s?)op2(?P<typeQual>\\.\\w+)?") 3165062Sgblack@eecs.umich.edu match = matcher.search(allCode) 3175062Sgblack@eecs.umich.edu if match: 3185062Sgblack@eecs.umich.edu typeQual = "" 3195062Sgblack@eecs.umich.edu if match.group("typeQual"): 3205062Sgblack@eecs.umich.edu typeQual = match.group("typeQual") 3215062Sgblack@eecs.umich.edu src2_name = "%spsrc2%s" % (match.group("prefix"), typeQual) 3225040Sgblack@eecs.umich.edu self.buildCppClasses(name, Name, suffix, 3235062Sgblack@eecs.umich.edu matcher.sub(src2_name, code), 3245062Sgblack@eecs.umich.edu matcher.sub(src2_name, flag_code), 3255062Sgblack@eecs.umich.edu matcher.sub(src2_name, cond_check), 3265062Sgblack@eecs.umich.edu matcher.sub(src2_name, else_code)) 3275040Sgblack@eecs.umich.edu self.buildCppClasses(name + "i", Name, suffix + "Imm", 3285040Sgblack@eecs.umich.edu matcher.sub("imm8", code), 3295040Sgblack@eecs.umich.edu matcher.sub("imm8", flag_code), 3305040Sgblack@eecs.umich.edu matcher.sub("imm8", cond_check), 3315040Sgblack@eecs.umich.edu matcher.sub("imm8", else_code)) 3325040Sgblack@eecs.umich.edu return 3335040Sgblack@eecs.umich.edu 3345040Sgblack@eecs.umich.edu # If there's something optional to do with flags, generate 3355040Sgblack@eecs.umich.edu # a version without it and fix up this version to use it. 3365239Sgblack@eecs.umich.edu if flag_code != "" or cond_check != "true": 3375040Sgblack@eecs.umich.edu self.buildCppClasses(name, Name, suffix, 3385040Sgblack@eecs.umich.edu code, "", "true", else_code) 3395040Sgblack@eecs.umich.edu suffix = "Flags" + suffix 3405040Sgblack@eecs.umich.edu 3415040Sgblack@eecs.umich.edu # If psrc1 or psrc2 is used, we need to actually insert code to 3425040Sgblack@eecs.umich.edu # compute it. 3435040Sgblack@eecs.umich.edu matcher = re.compile("(?<!\w)psrc1(?!\w)") 3445040Sgblack@eecs.umich.edu if matcher.search(allCode): 3455061Sgblack@eecs.umich.edu code = "uint64_t psrc1 = pick(SrcReg1, 0, dataSize);" + code 3465040Sgblack@eecs.umich.edu matcher = re.compile("(?<!\w)psrc2(?!\w)") 3475040Sgblack@eecs.umich.edu if matcher.search(allCode): 3485061Sgblack@eecs.umich.edu code = "uint64_t psrc2 = pick(SrcReg2, 1, dataSize);" + code 3495061Sgblack@eecs.umich.edu # Also make available versions which do sign extension 3505061Sgblack@eecs.umich.edu matcher = re.compile("(?<!\w)spsrc1(?!\w)") 3515061Sgblack@eecs.umich.edu if matcher.search(allCode): 3525061Sgblack@eecs.umich.edu code = "int64_t spsrc1 = signedPick(SrcReg1, 0, dataSize);" + code 3535061Sgblack@eecs.umich.edu matcher = re.compile("(?<!\w)spsrc2(?!\w)") 3545061Sgblack@eecs.umich.edu if matcher.search(allCode): 3555061Sgblack@eecs.umich.edu code = "int64_t spsrc2 = signedPick(SrcReg2, 1, dataSize);" + code 3565040Sgblack@eecs.umich.edu 3575040Sgblack@eecs.umich.edu base = "X86ISA::RegOp" 3585040Sgblack@eecs.umich.edu 3595040Sgblack@eecs.umich.edu # If imm8 shows up in the code, use the immediate templates, if 3605040Sgblack@eecs.umich.edu # not, hopefully the register ones will be correct. 3615040Sgblack@eecs.umich.edu templates = regTemplates 3625040Sgblack@eecs.umich.edu matcher = re.compile("(?<!\w)imm8(?!\w)") 3635040Sgblack@eecs.umich.edu if matcher.search(allCode): 3645040Sgblack@eecs.umich.edu base += "Imm" 3655040Sgblack@eecs.umich.edu templates = immTemplates 3665040Sgblack@eecs.umich.edu 3675040Sgblack@eecs.umich.edu # Get everything ready for the substitution 3685040Sgblack@eecs.umich.edu iop = InstObjParams(name, Name + suffix, base, 3695040Sgblack@eecs.umich.edu {"code" : code, 3705040Sgblack@eecs.umich.edu "flag_code" : flag_code, 3715040Sgblack@eecs.umich.edu "cond_check" : cond_check, 3725040Sgblack@eecs.umich.edu "else_code" : else_code}) 3735040Sgblack@eecs.umich.edu 3745040Sgblack@eecs.umich.edu # Generate the actual code (finally!) 3755040Sgblack@eecs.umich.edu header_output += templates[0].subst(iop) 3765040Sgblack@eecs.umich.edu decoder_output += templates[1].subst(iop) 3775040Sgblack@eecs.umich.edu exec_output += templates[2].subst(iop) 3785040Sgblack@eecs.umich.edu 3795040Sgblack@eecs.umich.edu 3805040Sgblack@eecs.umich.edu def __new__(mcls, Name, bases, dict): 3814688Sgblack@eecs.umich.edu abstract = False 3825040Sgblack@eecs.umich.edu name = Name.lower() 3834688Sgblack@eecs.umich.edu if "abstract" in dict: 3844688Sgblack@eecs.umich.edu abstract = dict['abstract'] 3854688Sgblack@eecs.umich.edu del dict['abstract'] 3864688Sgblack@eecs.umich.edu 3875040Sgblack@eecs.umich.edu cls = super(RegOpMeta, mcls).__new__(mcls, Name, bases, dict) 3884688Sgblack@eecs.umich.edu if not abstract: 3895040Sgblack@eecs.umich.edu cls.className = Name 3905040Sgblack@eecs.umich.edu cls.base_mnemonic = name 3915040Sgblack@eecs.umich.edu code = cls.code 3925040Sgblack@eecs.umich.edu flag_code = cls.flag_code 3935040Sgblack@eecs.umich.edu cond_check = cls.cond_check 3945040Sgblack@eecs.umich.edu else_code = cls.else_code 3955040Sgblack@eecs.umich.edu 3965040Sgblack@eecs.umich.edu # Set up the C++ classes 3975040Sgblack@eecs.umich.edu mcls.buildCppClasses(cls, name, Name, "", 3985040Sgblack@eecs.umich.edu code, flag_code, cond_check, else_code) 3995040Sgblack@eecs.umich.edu 4005040Sgblack@eecs.umich.edu # Hook into the microassembler dict 4015040Sgblack@eecs.umich.edu global microopClasses 4025040Sgblack@eecs.umich.edu microopClasses[name] = cls 4035040Sgblack@eecs.umich.edu 4045040Sgblack@eecs.umich.edu allCode = "|".join((code, flag_code, cond_check, else_code)) 4055040Sgblack@eecs.umich.edu 4065040Sgblack@eecs.umich.edu # If op2 is used anywhere, make register and immediate versions 4075040Sgblack@eecs.umich.edu # of this code. 4085040Sgblack@eecs.umich.edu matcher = re.compile("op2(?P<typeQual>\\.\\w+)?") 4095040Sgblack@eecs.umich.edu if matcher.search(allCode): 4105040Sgblack@eecs.umich.edu microopClasses[name + 'i'] = cls 4114688Sgblack@eecs.umich.edu return cls 4124688Sgblack@eecs.umich.edu 4135040Sgblack@eecs.umich.edu 4145040Sgblack@eecs.umich.edu class RegOp(X86Microop): 4155040Sgblack@eecs.umich.edu __metaclass__ = RegOpMeta 4165040Sgblack@eecs.umich.edu # This class itself doesn't act as a microop 4174688Sgblack@eecs.umich.edu abstract = True 4184688Sgblack@eecs.umich.edu 4195040Sgblack@eecs.umich.edu # Default template parameter values 4205040Sgblack@eecs.umich.edu flag_code = "" 4215040Sgblack@eecs.umich.edu cond_check = "true" 4225040Sgblack@eecs.umich.edu else_code = ";" 4235040Sgblack@eecs.umich.edu 4245040Sgblack@eecs.umich.edu def __init__(self, dest, src1, op2, flags = None, dataSize = "env.dataSize"): 4254519Sgblack@eecs.umich.edu self.dest = dest 4264519Sgblack@eecs.umich.edu self.src1 = src1 4275040Sgblack@eecs.umich.edu self.op2 = op2 4284688Sgblack@eecs.umich.edu self.flags = flags 4294701Sgblack@eecs.umich.edu self.dataSize = dataSize 4304688Sgblack@eecs.umich.edu if flags is None: 4314688Sgblack@eecs.umich.edu self.ext = 0 4324688Sgblack@eecs.umich.edu else: 4334688Sgblack@eecs.umich.edu if not isinstance(flags, (list, tuple)): 4344688Sgblack@eecs.umich.edu raise Exception, "flags must be a list or tuple of flags" 4354688Sgblack@eecs.umich.edu self.ext = " | ".join(flags) 4364688Sgblack@eecs.umich.edu self.className += "Flags" 4374519Sgblack@eecs.umich.edu 4384519Sgblack@eecs.umich.edu def getAllocator(self, *microFlags): 4395040Sgblack@eecs.umich.edu className = self.className 4405040Sgblack@eecs.umich.edu if self.mnemonic == self.base_mnemonic + 'i': 4415040Sgblack@eecs.umich.edu className += "Imm" 4425788Sgblack@eecs.umich.edu allocator = '''new %(class_name)s(machInst, macrocodeBlock 4435040Sgblack@eecs.umich.edu %(flags)s, %(src1)s, %(op2)s, %(dest)s, 4444688Sgblack@eecs.umich.edu %(dataSize)s, %(ext)s)''' % { 4455040Sgblack@eecs.umich.edu "class_name" : className, 4464519Sgblack@eecs.umich.edu "flags" : self.microFlagsText(microFlags), 4475040Sgblack@eecs.umich.edu "src1" : self.src1, "op2" : self.op2, 4484519Sgblack@eecs.umich.edu "dest" : self.dest, 4494519Sgblack@eecs.umich.edu "dataSize" : self.dataSize, 4504519Sgblack@eecs.umich.edu "ext" : self.ext} 4514539Sgblack@eecs.umich.edu return allocator 4524519Sgblack@eecs.umich.edu 4535040Sgblack@eecs.umich.edu class LogicRegOp(RegOp): 4544688Sgblack@eecs.umich.edu abstract = True 4555040Sgblack@eecs.umich.edu flag_code = ''' 4565040Sgblack@eecs.umich.edu //Don't have genFlags handle the OF or CF bits 4575115Sgblack@eecs.umich.edu uint64_t mask = CFBit | ECFBit | OFBit; 4585040Sgblack@eecs.umich.edu ccFlagBits = genFlags(ccFlagBits, ext & ~mask, DestReg, psrc1, op2); 4595040Sgblack@eecs.umich.edu //If a logic microop wants to set these, it wants to set them to 0. 4605040Sgblack@eecs.umich.edu ccFlagBits &= ~(CFBit & ext); 4615115Sgblack@eecs.umich.edu ccFlagBits &= ~(ECFBit & ext); 4625040Sgblack@eecs.umich.edu ccFlagBits &= ~(OFBit & ext); 4635040Sgblack@eecs.umich.edu ''' 4644519Sgblack@eecs.umich.edu 4655040Sgblack@eecs.umich.edu class FlagRegOp(RegOp): 4665040Sgblack@eecs.umich.edu abstract = True 4675040Sgblack@eecs.umich.edu flag_code = \ 4685040Sgblack@eecs.umich.edu "ccFlagBits = genFlags(ccFlagBits, ext, DestReg, psrc1, op2);" 4694519Sgblack@eecs.umich.edu 4705040Sgblack@eecs.umich.edu class SubRegOp(RegOp): 4715040Sgblack@eecs.umich.edu abstract = True 4725040Sgblack@eecs.umich.edu flag_code = \ 4735040Sgblack@eecs.umich.edu "ccFlagBits = genFlags(ccFlagBits, ext, DestReg, psrc1, ~op2, true);" 4744519Sgblack@eecs.umich.edu 4755040Sgblack@eecs.umich.edu class CondRegOp(RegOp): 4765040Sgblack@eecs.umich.edu abstract = True 4775083Sgblack@eecs.umich.edu cond_check = "checkCondition(ccFlagBits, ext)" 4784519Sgblack@eecs.umich.edu 4795063Sgblack@eecs.umich.edu class RdRegOp(RegOp): 4805063Sgblack@eecs.umich.edu abstract = True 4815063Sgblack@eecs.umich.edu def __init__(self, dest, src1=None, dataSize="env.dataSize"): 4825063Sgblack@eecs.umich.edu if not src1: 4835063Sgblack@eecs.umich.edu src1 = dest 4846345Sgblack@eecs.umich.edu super(RdRegOp, self).__init__(dest, src1, \ 4856345Sgblack@eecs.umich.edu "InstRegIndex(NUM_INTREGS)", None, dataSize) 4865063Sgblack@eecs.umich.edu 4875063Sgblack@eecs.umich.edu class WrRegOp(RegOp): 4885063Sgblack@eecs.umich.edu abstract = True 4895063Sgblack@eecs.umich.edu def __init__(self, src1, src2, flags=None, dataSize="env.dataSize"): 4906345Sgblack@eecs.umich.edu super(WrRegOp, self).__init__("InstRegIndex(NUM_INTREGS)", \ 4916345Sgblack@eecs.umich.edu src1, src2, flags, dataSize) 4925063Sgblack@eecs.umich.edu 4935040Sgblack@eecs.umich.edu class Add(FlagRegOp): 4945040Sgblack@eecs.umich.edu code = 'DestReg = merge(DestReg, psrc1 + op2, dataSize);' 4954595Sgblack@eecs.umich.edu 4965040Sgblack@eecs.umich.edu class Or(LogicRegOp): 4975040Sgblack@eecs.umich.edu code = 'DestReg = merge(DestReg, psrc1 | op2, dataSize);' 4984595Sgblack@eecs.umich.edu 4995040Sgblack@eecs.umich.edu class Adc(FlagRegOp): 5005040Sgblack@eecs.umich.edu code = ''' 5014732Sgblack@eecs.umich.edu CCFlagBits flags = ccFlagBits; 5025138Sgblack@eecs.umich.edu DestReg = merge(DestReg, psrc1 + op2 + flags.cf, dataSize); 5035040Sgblack@eecs.umich.edu ''' 5045040Sgblack@eecs.umich.edu 5055040Sgblack@eecs.umich.edu class Sbb(SubRegOp): 5065040Sgblack@eecs.umich.edu code = ''' 5074732Sgblack@eecs.umich.edu CCFlagBits flags = ccFlagBits; 5085138Sgblack@eecs.umich.edu DestReg = merge(DestReg, psrc1 - op2 - flags.cf, dataSize); 5095040Sgblack@eecs.umich.edu ''' 5105040Sgblack@eecs.umich.edu 5115040Sgblack@eecs.umich.edu class And(LogicRegOp): 5125040Sgblack@eecs.umich.edu code = 'DestReg = merge(DestReg, psrc1 & op2, dataSize)' 5135040Sgblack@eecs.umich.edu 5145040Sgblack@eecs.umich.edu class Sub(SubRegOp): 5155040Sgblack@eecs.umich.edu code = 'DestReg = merge(DestReg, psrc1 - op2, dataSize)' 5165040Sgblack@eecs.umich.edu 5175040Sgblack@eecs.umich.edu class Xor(LogicRegOp): 5185040Sgblack@eecs.umich.edu code = 'DestReg = merge(DestReg, psrc1 ^ op2, dataSize)' 5195040Sgblack@eecs.umich.edu 5205063Sgblack@eecs.umich.edu class Mul1s(WrRegOp): 5215040Sgblack@eecs.umich.edu code = ''' 5225063Sgblack@eecs.umich.edu ProdLow = psrc1 * op2; 5235063Sgblack@eecs.umich.edu int halfSize = (dataSize * 8) / 2; 5246430Sgblack@eecs.umich.edu uint64_t shifter = (1ULL << halfSize); 5256430Sgblack@eecs.umich.edu uint64_t hiResult; 5266430Sgblack@eecs.umich.edu uint64_t psrc1_h = psrc1 / shifter; 5276430Sgblack@eecs.umich.edu uint64_t psrc1_l = psrc1 & mask(halfSize); 5286461Sgblack@eecs.umich.edu uint64_t psrc2_h = (op2 / shifter) & mask(halfSize); 5296430Sgblack@eecs.umich.edu uint64_t psrc2_l = op2 & mask(halfSize); 5306430Sgblack@eecs.umich.edu hiResult = ((psrc1_l * psrc2_h + psrc1_h * psrc2_l + 5316430Sgblack@eecs.umich.edu ((psrc1_l * psrc2_l) / shifter)) /shifter) + 5326430Sgblack@eecs.umich.edu psrc1_h * psrc2_h; 5336430Sgblack@eecs.umich.edu if (spsrc1 < 0) 5346430Sgblack@eecs.umich.edu hiResult -= op2; 5356430Sgblack@eecs.umich.edu int64_t bigSop2 = sop2; 5366430Sgblack@eecs.umich.edu if (bigSop2 < 0) 5376430Sgblack@eecs.umich.edu hiResult -= psrc1; 5386430Sgblack@eecs.umich.edu ProdHi = hiResult; 5395040Sgblack@eecs.umich.edu ''' 5405040Sgblack@eecs.umich.edu 5415063Sgblack@eecs.umich.edu class Mul1u(WrRegOp): 5425040Sgblack@eecs.umich.edu code = ''' 5435063Sgblack@eecs.umich.edu ProdLow = psrc1 * op2; 5444809Sgblack@eecs.umich.edu int halfSize = (dataSize * 8) / 2; 5456430Sgblack@eecs.umich.edu uint64_t shifter = (1ULL << halfSize); 5466430Sgblack@eecs.umich.edu uint64_t psrc1_h = psrc1 / shifter; 5475063Sgblack@eecs.umich.edu uint64_t psrc1_l = psrc1 & mask(halfSize); 5486461Sgblack@eecs.umich.edu uint64_t psrc2_h = (op2 / shifter) & mask(halfSize); 5495063Sgblack@eecs.umich.edu uint64_t psrc2_l = op2 & mask(halfSize); 5505063Sgblack@eecs.umich.edu ProdHi = ((psrc1_l * psrc2_h + psrc1_h * psrc2_l + 5516430Sgblack@eecs.umich.edu ((psrc1_l * psrc2_l) / shifter)) / shifter) + 5525063Sgblack@eecs.umich.edu psrc1_h * psrc2_h; 5535040Sgblack@eecs.umich.edu ''' 5545040Sgblack@eecs.umich.edu 5555063Sgblack@eecs.umich.edu class Mulel(RdRegOp): 5565063Sgblack@eecs.umich.edu code = 'DestReg = merge(SrcReg1, ProdLow, dataSize);' 5575040Sgblack@eecs.umich.edu 5585063Sgblack@eecs.umich.edu class Muleh(RdRegOp): 5595063Sgblack@eecs.umich.edu def __init__(self, dest, src1=None, flags=None, dataSize="env.dataSize"): 5605063Sgblack@eecs.umich.edu if not src1: 5615063Sgblack@eecs.umich.edu src1 = dest 5626345Sgblack@eecs.umich.edu super(RdRegOp, self).__init__(dest, src1, \ 5636345Sgblack@eecs.umich.edu "InstRegIndex(NUM_INTREGS)", flags, dataSize) 5645063Sgblack@eecs.umich.edu code = 'DestReg = merge(SrcReg1, ProdHi, dataSize);' 5655063Sgblack@eecs.umich.edu flag_code = ''' 5665063Sgblack@eecs.umich.edu if (ProdHi) 5675063Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & (CFBit | OFBit | ECFBit)); 5685063Sgblack@eecs.umich.edu else 5695063Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & (CFBit | OFBit | ECFBit)); 5705063Sgblack@eecs.umich.edu ''' 5715062Sgblack@eecs.umich.edu 5725075Sgblack@eecs.umich.edu # One or two bit divide 5735075Sgblack@eecs.umich.edu class Div1(WrRegOp): 5745040Sgblack@eecs.umich.edu code = ''' 5755075Sgblack@eecs.umich.edu //These are temporaries so that modifying them later won't make 5765075Sgblack@eecs.umich.edu //the ISA parser think they're also sources. 5775075Sgblack@eecs.umich.edu uint64_t quotient = 0; 5785075Sgblack@eecs.umich.edu uint64_t remainder = psrc1; 5795075Sgblack@eecs.umich.edu //Similarly, this is a temporary so changing it doesn't make it 5805075Sgblack@eecs.umich.edu //a source. 5815075Sgblack@eecs.umich.edu uint64_t divisor = op2; 5825075Sgblack@eecs.umich.edu //This is a temporary just for consistency and clarity. 5835075Sgblack@eecs.umich.edu uint64_t dividend = remainder; 5845075Sgblack@eecs.umich.edu //Do the division. 5855075Sgblack@eecs.umich.edu divide(dividend, divisor, quotient, remainder); 5865075Sgblack@eecs.umich.edu //Record the final results. 5875075Sgblack@eecs.umich.edu Remainder = remainder; 5885075Sgblack@eecs.umich.edu Quotient = quotient; 5895075Sgblack@eecs.umich.edu Divisor = divisor; 5905040Sgblack@eecs.umich.edu ''' 5914823Sgblack@eecs.umich.edu 5925075Sgblack@eecs.umich.edu # Step divide 5935075Sgblack@eecs.umich.edu class Div2(RegOp): 5945075Sgblack@eecs.umich.edu code = ''' 5955075Sgblack@eecs.umich.edu uint64_t dividend = Remainder; 5965075Sgblack@eecs.umich.edu uint64_t divisor = Divisor; 5975075Sgblack@eecs.umich.edu uint64_t quotient = Quotient; 5985075Sgblack@eecs.umich.edu uint64_t remainder = dividend; 5995075Sgblack@eecs.umich.edu int remaining = op2; 6005075Sgblack@eecs.umich.edu //If we overshot, do nothing. This lets us unrool division loops a 6015075Sgblack@eecs.umich.edu //little. 6025075Sgblack@eecs.umich.edu if (remaining) { 6035075Sgblack@eecs.umich.edu //Shift in bits from the low order portion of the dividend 6045075Sgblack@eecs.umich.edu while(dividend < divisor && remaining) { 6055075Sgblack@eecs.umich.edu dividend = (dividend << 1) | bits(SrcReg1, remaining - 1); 6065075Sgblack@eecs.umich.edu quotient <<= 1; 6075075Sgblack@eecs.umich.edu remaining--; 6085075Sgblack@eecs.umich.edu } 6095075Sgblack@eecs.umich.edu remainder = dividend; 6105075Sgblack@eecs.umich.edu //Do the division. 6115075Sgblack@eecs.umich.edu divide(dividend, divisor, quotient, remainder); 6125075Sgblack@eecs.umich.edu } 6135075Sgblack@eecs.umich.edu //Keep track of how many bits there are still to pull in. 6145075Sgblack@eecs.umich.edu DestReg = merge(DestReg, remaining, dataSize); 6155075Sgblack@eecs.umich.edu //Record the final results 6165075Sgblack@eecs.umich.edu Remainder = remainder; 6175075Sgblack@eecs.umich.edu Quotient = quotient; 6185075Sgblack@eecs.umich.edu ''' 6195075Sgblack@eecs.umich.edu flag_code = ''' 6205075Sgblack@eecs.umich.edu if (DestReg == 0) 6215075Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & EZFBit); 6225075Sgblack@eecs.umich.edu else 6235075Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & EZFBit); 6245075Sgblack@eecs.umich.edu ''' 6254732Sgblack@eecs.umich.edu 6265075Sgblack@eecs.umich.edu class Divq(RdRegOp): 6275075Sgblack@eecs.umich.edu code = 'DestReg = merge(SrcReg1, Quotient, dataSize);' 6285075Sgblack@eecs.umich.edu 6295075Sgblack@eecs.umich.edu class Divr(RdRegOp): 6305075Sgblack@eecs.umich.edu code = 'DestReg = merge(SrcReg1, Remainder, dataSize);' 6315040Sgblack@eecs.umich.edu 6325040Sgblack@eecs.umich.edu class Mov(CondRegOp): 6335040Sgblack@eecs.umich.edu code = 'DestReg = merge(SrcReg1, op2, dataSize)' 6345040Sgblack@eecs.umich.edu else_code = 'DestReg=DestReg;' 6355040Sgblack@eecs.umich.edu 6364732Sgblack@eecs.umich.edu # Shift instructions 6375040Sgblack@eecs.umich.edu 6385076Sgblack@eecs.umich.edu class Sll(RegOp): 6395040Sgblack@eecs.umich.edu code = ''' 6404756Sgblack@eecs.umich.edu uint8_t shiftAmt = (op2 & ((dataSize == 8) ? mask(6) : mask(5))); 6414823Sgblack@eecs.umich.edu DestReg = merge(DestReg, psrc1 << shiftAmt, dataSize); 6425040Sgblack@eecs.umich.edu ''' 6435076Sgblack@eecs.umich.edu flag_code = ''' 6445076Sgblack@eecs.umich.edu // If the shift amount is zero, no flags should be modified. 6455076Sgblack@eecs.umich.edu if (shiftAmt) { 6465076Sgblack@eecs.umich.edu //Zero out any flags we might modify. This way we only have to 6475076Sgblack@eecs.umich.edu //worry about setting them. 6485076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & (CFBit | ECFBit | OFBit)); 6495076Sgblack@eecs.umich.edu int CFBits = 0; 6505076Sgblack@eecs.umich.edu //Figure out if we -would- set the CF bits if requested. 6516441Sgblack@eecs.umich.edu if (shiftAmt <= dataSize * 8 && 6526441Sgblack@eecs.umich.edu bits(SrcReg1, dataSize * 8 - shiftAmt)) { 6535076Sgblack@eecs.umich.edu CFBits = 1; 6546441Sgblack@eecs.umich.edu } 6555076Sgblack@eecs.umich.edu //If some combination of the CF bits need to be set, set them. 6565076Sgblack@eecs.umich.edu if ((ext & (CFBit | ECFBit)) && CFBits) 6575076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & (CFBit | ECFBit)); 6585076Sgblack@eecs.umich.edu //Figure out what the OF bit should be. 6595076Sgblack@eecs.umich.edu if ((ext & OFBit) && (CFBits ^ bits(DestReg, dataSize * 8 - 1))) 6605076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | OFBit; 6615076Sgblack@eecs.umich.edu //Use the regular mechanisms to calculate the other flags. 6625076Sgblack@eecs.umich.edu ccFlagBits = genFlags(ccFlagBits, ext & ~(CFBit | ECFBit | OFBit), 6635076Sgblack@eecs.umich.edu DestReg, psrc1, op2); 6645076Sgblack@eecs.umich.edu } 6655076Sgblack@eecs.umich.edu ''' 6665040Sgblack@eecs.umich.edu 6675076Sgblack@eecs.umich.edu class Srl(RegOp): 6685040Sgblack@eecs.umich.edu code = ''' 6694756Sgblack@eecs.umich.edu uint8_t shiftAmt = (op2 & ((dataSize == 8) ? mask(6) : mask(5))); 6704732Sgblack@eecs.umich.edu // Because what happens to the bits shift -in- on a right shift 6714732Sgblack@eecs.umich.edu // is not defined in the C/C++ standard, we have to mask them out 6724732Sgblack@eecs.umich.edu // to be sure they're zero. 6734732Sgblack@eecs.umich.edu uint64_t logicalMask = mask(dataSize * 8 - shiftAmt); 6744823Sgblack@eecs.umich.edu DestReg = merge(DestReg, (psrc1 >> shiftAmt) & logicalMask, dataSize); 6755040Sgblack@eecs.umich.edu ''' 6765076Sgblack@eecs.umich.edu flag_code = ''' 6775076Sgblack@eecs.umich.edu // If the shift amount is zero, no flags should be modified. 6785076Sgblack@eecs.umich.edu if (shiftAmt) { 6795076Sgblack@eecs.umich.edu //Zero out any flags we might modify. This way we only have to 6805076Sgblack@eecs.umich.edu //worry about setting them. 6815076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & (CFBit | ECFBit | OFBit)); 6825076Sgblack@eecs.umich.edu //If some combination of the CF bits need to be set, set them. 6836442Sgblack@eecs.umich.edu if ((ext & (CFBit | ECFBit)) && 6846442Sgblack@eecs.umich.edu shiftAmt <= dataSize * 8 && 6856442Sgblack@eecs.umich.edu bits(SrcReg1, shiftAmt - 1)) { 6865076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & (CFBit | ECFBit)); 6876442Sgblack@eecs.umich.edu } 6885076Sgblack@eecs.umich.edu //Figure out what the OF bit should be. 6895076Sgblack@eecs.umich.edu if ((ext & OFBit) && bits(SrcReg1, dataSize * 8 - 1)) 6905076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | OFBit; 6915076Sgblack@eecs.umich.edu //Use the regular mechanisms to calculate the other flags. 6925076Sgblack@eecs.umich.edu ccFlagBits = genFlags(ccFlagBits, ext & ~(CFBit | ECFBit | OFBit), 6935076Sgblack@eecs.umich.edu DestReg, psrc1, op2); 6945076Sgblack@eecs.umich.edu } 6955076Sgblack@eecs.umich.edu ''' 6965040Sgblack@eecs.umich.edu 6975076Sgblack@eecs.umich.edu class Sra(RegOp): 6985040Sgblack@eecs.umich.edu code = ''' 6994756Sgblack@eecs.umich.edu uint8_t shiftAmt = (op2 & ((dataSize == 8) ? mask(6) : mask(5))); 7004732Sgblack@eecs.umich.edu // Because what happens to the bits shift -in- on a right shift 7014732Sgblack@eecs.umich.edu // is not defined in the C/C++ standard, we have to sign extend 7024732Sgblack@eecs.umich.edu // them manually to be sure. 7036443Sgblack@eecs.umich.edu uint64_t arithMask = (shiftAmt == 0) ? 0 : 7045032Sgblack@eecs.umich.edu -bits(psrc1, dataSize * 8 - 1) << (dataSize * 8 - shiftAmt); 7054823Sgblack@eecs.umich.edu DestReg = merge(DestReg, (psrc1 >> shiftAmt) | arithMask, dataSize); 7065040Sgblack@eecs.umich.edu ''' 7075076Sgblack@eecs.umich.edu flag_code = ''' 7085076Sgblack@eecs.umich.edu // If the shift amount is zero, no flags should be modified. 7095076Sgblack@eecs.umich.edu if (shiftAmt) { 7105076Sgblack@eecs.umich.edu //Zero out any flags we might modify. This way we only have to 7115076Sgblack@eecs.umich.edu //worry about setting them. 7125076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & (CFBit | ECFBit | OFBit)); 7135076Sgblack@eecs.umich.edu //If some combination of the CF bits need to be set, set them. 7146444Sgblack@eecs.umich.edu uint8_t effectiveShift = 7156444Sgblack@eecs.umich.edu (shiftAmt <= dataSize * 8) ? shiftAmt : (dataSize * 8); 7166444Sgblack@eecs.umich.edu if ((ext & (CFBit | ECFBit)) && 7176444Sgblack@eecs.umich.edu bits(SrcReg1, effectiveShift - 1)) { 7185076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & (CFBit | ECFBit)); 7196444Sgblack@eecs.umich.edu } 7205076Sgblack@eecs.umich.edu //Use the regular mechanisms to calculate the other flags. 7215076Sgblack@eecs.umich.edu ccFlagBits = genFlags(ccFlagBits, ext & ~(CFBit | ECFBit | OFBit), 7225076Sgblack@eecs.umich.edu DestReg, psrc1, op2); 7235076Sgblack@eecs.umich.edu } 7245076Sgblack@eecs.umich.edu ''' 7255040Sgblack@eecs.umich.edu 7265076Sgblack@eecs.umich.edu class Ror(RegOp): 7275040Sgblack@eecs.umich.edu code = ''' 7284732Sgblack@eecs.umich.edu uint8_t shiftAmt = 7294756Sgblack@eecs.umich.edu (op2 & ((dataSize == 8) ? mask(6) : mask(5))); 7306449Sgblack@eecs.umich.edu uint8_t realShiftAmt = shiftAmt % (dataSize * 8); 7316449Sgblack@eecs.umich.edu if(realShiftAmt) 7324732Sgblack@eecs.umich.edu { 7336449Sgblack@eecs.umich.edu uint64_t top = psrc1 << (dataSize * 8 - realShiftAmt); 7346449Sgblack@eecs.umich.edu uint64_t bottom = bits(psrc1, dataSize * 8, realShiftAmt); 7354732Sgblack@eecs.umich.edu DestReg = merge(DestReg, top | bottom, dataSize); 7364732Sgblack@eecs.umich.edu } 7374732Sgblack@eecs.umich.edu else 7386447Sgblack@eecs.umich.edu DestReg = merge(DestReg, DestReg, dataSize); 7395040Sgblack@eecs.umich.edu ''' 7405076Sgblack@eecs.umich.edu flag_code = ''' 7415076Sgblack@eecs.umich.edu // If the shift amount is zero, no flags should be modified. 7425076Sgblack@eecs.umich.edu if (shiftAmt) { 7435076Sgblack@eecs.umich.edu //Zero out any flags we might modify. This way we only have to 7445076Sgblack@eecs.umich.edu //worry about setting them. 7455076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & (CFBit | ECFBit | OFBit)); 7465076Sgblack@eecs.umich.edu //Find the most and second most significant bits of the result. 7475076Sgblack@eecs.umich.edu int msb = bits(DestReg, dataSize * 8 - 1); 7485076Sgblack@eecs.umich.edu int smsb = bits(DestReg, dataSize * 8 - 2); 7495076Sgblack@eecs.umich.edu //If some combination of the CF bits need to be set, set them. 7505076Sgblack@eecs.umich.edu if ((ext & (CFBit | ECFBit)) && msb) 7515076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & (CFBit | ECFBit)); 7525076Sgblack@eecs.umich.edu //Figure out what the OF bit should be. 7535076Sgblack@eecs.umich.edu if ((ext & OFBit) && (msb ^ smsb)) 7545076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | OFBit; 7555076Sgblack@eecs.umich.edu //Use the regular mechanisms to calculate the other flags. 7565076Sgblack@eecs.umich.edu ccFlagBits = genFlags(ccFlagBits, ext & ~(CFBit | ECFBit | OFBit), 7575076Sgblack@eecs.umich.edu DestReg, psrc1, op2); 7585076Sgblack@eecs.umich.edu } 7595076Sgblack@eecs.umich.edu ''' 7605040Sgblack@eecs.umich.edu 7615076Sgblack@eecs.umich.edu class Rcr(RegOp): 7625040Sgblack@eecs.umich.edu code = ''' 7634733Sgblack@eecs.umich.edu uint8_t shiftAmt = 7644756Sgblack@eecs.umich.edu (op2 & ((dataSize == 8) ? mask(6) : mask(5))); 7656454Sgblack@eecs.umich.edu uint8_t realShiftAmt = shiftAmt % (dataSize * 8 + 1); 7666454Sgblack@eecs.umich.edu if(realShiftAmt) 7674733Sgblack@eecs.umich.edu { 7684733Sgblack@eecs.umich.edu CCFlagBits flags = ccFlagBits; 7696454Sgblack@eecs.umich.edu uint64_t top = flags.cf << (dataSize * 8 - realShiftAmt); 7706454Sgblack@eecs.umich.edu if (realShiftAmt > 1) 7716454Sgblack@eecs.umich.edu top |= psrc1 << (dataSize * 8 - realShiftAmt + 1); 7726454Sgblack@eecs.umich.edu uint64_t bottom = bits(psrc1, dataSize * 8 - 1, realShiftAmt); 7734733Sgblack@eecs.umich.edu DestReg = merge(DestReg, top | bottom, dataSize); 7744733Sgblack@eecs.umich.edu } 7754733Sgblack@eecs.umich.edu else 7766447Sgblack@eecs.umich.edu DestReg = merge(DestReg, DestReg, dataSize); 7775040Sgblack@eecs.umich.edu ''' 7785076Sgblack@eecs.umich.edu flag_code = ''' 7795076Sgblack@eecs.umich.edu // If the shift amount is zero, no flags should be modified. 7805076Sgblack@eecs.umich.edu if (shiftAmt) { 7816453Sgblack@eecs.umich.edu int origCFBit = (ccFlagBits & CFBit) ? 1 : 0; 7825076Sgblack@eecs.umich.edu //Zero out any flags we might modify. This way we only have to 7835076Sgblack@eecs.umich.edu //worry about setting them. 7845076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & (CFBit | ECFBit | OFBit)); 7855076Sgblack@eecs.umich.edu //Figure out what the OF bit should be. 7866453Sgblack@eecs.umich.edu if ((ext & OFBit) && (origCFBit ^ 7876453Sgblack@eecs.umich.edu bits(SrcReg1, dataSize * 8 - 1))) { 7885076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | OFBit; 7896453Sgblack@eecs.umich.edu } 7905076Sgblack@eecs.umich.edu //If some combination of the CF bits need to be set, set them. 7916454Sgblack@eecs.umich.edu if ((ext & (CFBit | ECFBit)) && 7926454Sgblack@eecs.umich.edu (realShiftAmt == 0) ? origCFBit : 7936454Sgblack@eecs.umich.edu bits(SrcReg1, realShiftAmt - 1)) { 7945076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & (CFBit | ECFBit)); 7956454Sgblack@eecs.umich.edu } 7965076Sgblack@eecs.umich.edu //Use the regular mechanisms to calculate the other flags. 7975076Sgblack@eecs.umich.edu ccFlagBits = genFlags(ccFlagBits, ext & ~(CFBit | ECFBit | OFBit), 7985076Sgblack@eecs.umich.edu DestReg, psrc1, op2); 7995076Sgblack@eecs.umich.edu } 8005076Sgblack@eecs.umich.edu ''' 8015040Sgblack@eecs.umich.edu 8025076Sgblack@eecs.umich.edu class Rol(RegOp): 8035040Sgblack@eecs.umich.edu code = ''' 8044732Sgblack@eecs.umich.edu uint8_t shiftAmt = 8054756Sgblack@eecs.umich.edu (op2 & ((dataSize == 8) ? mask(6) : mask(5))); 8066446Sgblack@eecs.umich.edu uint8_t realShiftAmt = shiftAmt % (dataSize * 8); 8076446Sgblack@eecs.umich.edu if(realShiftAmt) 8084732Sgblack@eecs.umich.edu { 8096446Sgblack@eecs.umich.edu uint64_t top = psrc1 << realShiftAmt; 8104732Sgblack@eecs.umich.edu uint64_t bottom = 8116446Sgblack@eecs.umich.edu bits(psrc1, dataSize * 8 - 1, dataSize * 8 - realShiftAmt); 8124732Sgblack@eecs.umich.edu DestReg = merge(DestReg, top | bottom, dataSize); 8134732Sgblack@eecs.umich.edu } 8144732Sgblack@eecs.umich.edu else 8156447Sgblack@eecs.umich.edu DestReg = merge(DestReg, DestReg, dataSize); 8165040Sgblack@eecs.umich.edu ''' 8175076Sgblack@eecs.umich.edu flag_code = ''' 8185076Sgblack@eecs.umich.edu // If the shift amount is zero, no flags should be modified. 8195076Sgblack@eecs.umich.edu if (shiftAmt) { 8205076Sgblack@eecs.umich.edu //Zero out any flags we might modify. This way we only have to 8215076Sgblack@eecs.umich.edu //worry about setting them. 8225076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & (CFBit | ECFBit | OFBit)); 8235076Sgblack@eecs.umich.edu //The CF bits, if set, would be set to the lsb of the result. 8245076Sgblack@eecs.umich.edu int lsb = DestReg & 0x1; 8255076Sgblack@eecs.umich.edu int msb = bits(DestReg, dataSize * 8 - 1); 8265076Sgblack@eecs.umich.edu //If some combination of the CF bits need to be set, set them. 8275076Sgblack@eecs.umich.edu if ((ext & (CFBit | ECFBit)) && lsb) 8285076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & (CFBit | ECFBit)); 8295076Sgblack@eecs.umich.edu //Figure out what the OF bit should be. 8305076Sgblack@eecs.umich.edu if ((ext & OFBit) && (msb ^ lsb)) 8315076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | OFBit; 8325076Sgblack@eecs.umich.edu //Use the regular mechanisms to calculate the other flags. 8335076Sgblack@eecs.umich.edu ccFlagBits = genFlags(ccFlagBits, ext & ~(CFBit | ECFBit | OFBit), 8345076Sgblack@eecs.umich.edu DestReg, psrc1, op2); 8355076Sgblack@eecs.umich.edu } 8365076Sgblack@eecs.umich.edu ''' 8375040Sgblack@eecs.umich.edu 8385076Sgblack@eecs.umich.edu class Rcl(RegOp): 8395040Sgblack@eecs.umich.edu code = ''' 8404733Sgblack@eecs.umich.edu uint8_t shiftAmt = 8414756Sgblack@eecs.umich.edu (op2 & ((dataSize == 8) ? mask(6) : mask(5))); 8426456Sgblack@eecs.umich.edu uint8_t realShiftAmt = shiftAmt % (dataSize * 8 + 1); 8436456Sgblack@eecs.umich.edu if(realShiftAmt) 8444733Sgblack@eecs.umich.edu { 8454733Sgblack@eecs.umich.edu CCFlagBits flags = ccFlagBits; 8466456Sgblack@eecs.umich.edu uint64_t top = psrc1 << realShiftAmt; 8476456Sgblack@eecs.umich.edu uint64_t bottom = flags.cf << (realShiftAmt - 1); 8484733Sgblack@eecs.umich.edu if(shiftAmt > 1) 8494733Sgblack@eecs.umich.edu bottom |= 8504823Sgblack@eecs.umich.edu bits(psrc1, dataSize * 8 - 1, 8516456Sgblack@eecs.umich.edu dataSize * 8 - realShiftAmt + 1); 8524733Sgblack@eecs.umich.edu DestReg = merge(DestReg, top | bottom, dataSize); 8534733Sgblack@eecs.umich.edu } 8544733Sgblack@eecs.umich.edu else 8556447Sgblack@eecs.umich.edu DestReg = merge(DestReg, DestReg, dataSize); 8565040Sgblack@eecs.umich.edu ''' 8575076Sgblack@eecs.umich.edu flag_code = ''' 8585076Sgblack@eecs.umich.edu // If the shift amount is zero, no flags should be modified. 8595076Sgblack@eecs.umich.edu if (shiftAmt) { 8606456Sgblack@eecs.umich.edu int origCFBit = (ccFlagBits & CFBit) ? 1 : 0; 8615076Sgblack@eecs.umich.edu //Zero out any flags we might modify. This way we only have to 8625076Sgblack@eecs.umich.edu //worry about setting them. 8635076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & (CFBit | ECFBit | OFBit)); 8645076Sgblack@eecs.umich.edu int msb = bits(DestReg, dataSize * 8 - 1); 8656456Sgblack@eecs.umich.edu int CFBits = bits(SrcReg1, dataSize * 8 - realShiftAmt); 8665076Sgblack@eecs.umich.edu //If some combination of the CF bits need to be set, set them. 8676456Sgblack@eecs.umich.edu if ((ext & (CFBit | ECFBit)) && 8686456Sgblack@eecs.umich.edu (realShiftAmt == 0) ? origCFBit : CFBits) 8695076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & (CFBit | ECFBit)); 8705076Sgblack@eecs.umich.edu //Figure out what the OF bit should be. 8715076Sgblack@eecs.umich.edu if ((ext & OFBit) && (msb ^ CFBits)) 8725076Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | OFBit; 8735076Sgblack@eecs.umich.edu //Use the regular mechanisms to calculate the other flags. 8745076Sgblack@eecs.umich.edu ccFlagBits = genFlags(ccFlagBits, ext & ~(CFBit | ECFBit | OFBit), 8755076Sgblack@eecs.umich.edu DestReg, psrc1, op2); 8765076Sgblack@eecs.umich.edu } 8775076Sgblack@eecs.umich.edu ''' 8784732Sgblack@eecs.umich.edu 8795040Sgblack@eecs.umich.edu class Wrip(WrRegOp, CondRegOp): 8805246Sgblack@eecs.umich.edu code = 'RIP = psrc1 + sop2 + CSBase' 8815040Sgblack@eecs.umich.edu else_code="RIP = RIP;" 8825040Sgblack@eecs.umich.edu 8835040Sgblack@eecs.umich.edu class Wruflags(WrRegOp): 8845040Sgblack@eecs.umich.edu code = 'ccFlagBits = psrc1 ^ op2' 8855040Sgblack@eecs.umich.edu 8865426Sgblack@eecs.umich.edu class Wrflags(WrRegOp): 8875426Sgblack@eecs.umich.edu code = ''' 8885426Sgblack@eecs.umich.edu MiscReg newFlags = psrc1 ^ op2; 8895426Sgblack@eecs.umich.edu MiscReg userFlagMask = 0xDD5; 8905426Sgblack@eecs.umich.edu // Get only the user flags 8915426Sgblack@eecs.umich.edu ccFlagBits = newFlags & userFlagMask; 8925426Sgblack@eecs.umich.edu // Get everything else 8935426Sgblack@eecs.umich.edu nccFlagBits = newFlags & ~userFlagMask; 8945426Sgblack@eecs.umich.edu ''' 8955426Sgblack@eecs.umich.edu 8965040Sgblack@eecs.umich.edu class Rdip(RdRegOp): 8975246Sgblack@eecs.umich.edu code = 'DestReg = RIP - CSBase' 8985040Sgblack@eecs.umich.edu 8995040Sgblack@eecs.umich.edu class Ruflags(RdRegOp): 9005040Sgblack@eecs.umich.edu code = 'DestReg = ccFlagBits' 9015040Sgblack@eecs.umich.edu 9025426Sgblack@eecs.umich.edu class Rflags(RdRegOp): 9035426Sgblack@eecs.umich.edu code = 'DestReg = ccFlagBits | nccFlagBits' 9045426Sgblack@eecs.umich.edu 9055040Sgblack@eecs.umich.edu class Ruflag(RegOp): 9065040Sgblack@eecs.umich.edu code = ''' 9075116Sgblack@eecs.umich.edu int flag = bits(ccFlagBits, imm8); 9084951Sgblack@eecs.umich.edu DestReg = merge(DestReg, flag, dataSize); 9095011Sgblack@eecs.umich.edu ccFlagBits = (flag == 0) ? (ccFlagBits | EZFBit) : 9105011Sgblack@eecs.umich.edu (ccFlagBits & ~EZFBit); 9115040Sgblack@eecs.umich.edu ''' 9125040Sgblack@eecs.umich.edu def __init__(self, dest, imm, flags=None, \ 9135040Sgblack@eecs.umich.edu dataSize="env.dataSize"): 9145040Sgblack@eecs.umich.edu super(Ruflag, self).__init__(dest, \ 9156345Sgblack@eecs.umich.edu "InstRegIndex(NUM_INTREGS)", imm, flags, dataSize) 9164732Sgblack@eecs.umich.edu 9175426Sgblack@eecs.umich.edu class Rflag(RegOp): 9185426Sgblack@eecs.umich.edu code = ''' 9195426Sgblack@eecs.umich.edu MiscReg flagMask = 0x3F7FDD5; 9205426Sgblack@eecs.umich.edu MiscReg flags = (nccFlagBits | ccFlagBits) & flagMask; 9215426Sgblack@eecs.umich.edu int flag = bits(flags, imm8); 9225426Sgblack@eecs.umich.edu DestReg = merge(DestReg, flag, dataSize); 9235426Sgblack@eecs.umich.edu ccFlagBits = (flag == 0) ? (ccFlagBits | EZFBit) : 9245426Sgblack@eecs.umich.edu (ccFlagBits & ~EZFBit); 9255426Sgblack@eecs.umich.edu ''' 9265426Sgblack@eecs.umich.edu def __init__(self, dest, imm, flags=None, \ 9275426Sgblack@eecs.umich.edu dataSize="env.dataSize"): 9285426Sgblack@eecs.umich.edu super(Rflag, self).__init__(dest, \ 9296345Sgblack@eecs.umich.edu "InstRegIndex(NUM_INTREGS)", imm, flags, dataSize) 9305426Sgblack@eecs.umich.edu 9315040Sgblack@eecs.umich.edu class Sext(RegOp): 9325040Sgblack@eecs.umich.edu code = ''' 9334823Sgblack@eecs.umich.edu IntReg val = psrc1; 9345239Sgblack@eecs.umich.edu // Mask the bit position so that it wraps. 9355239Sgblack@eecs.umich.edu int bitPos = op2 & (dataSize * 8 - 1); 9365239Sgblack@eecs.umich.edu int sign_bit = bits(val, bitPos, bitPos); 9375239Sgblack@eecs.umich.edu uint64_t maskVal = mask(bitPos+1); 9385007Sgblack@eecs.umich.edu val = sign_bit ? (val | ~maskVal) : (val & maskVal); 9395007Sgblack@eecs.umich.edu DestReg = merge(DestReg, val, dataSize); 9405040Sgblack@eecs.umich.edu ''' 9415239Sgblack@eecs.umich.edu flag_code = ''' 9425239Sgblack@eecs.umich.edu if (!sign_bit) 9435239Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & 9445239Sgblack@eecs.umich.edu ~(ext & (CFBit | ECFBit | ZFBit | EZFBit)); 9455239Sgblack@eecs.umich.edu else 9465239Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | 9475239Sgblack@eecs.umich.edu (ext & (CFBit | ECFBit | ZFBit | EZFBit)); 9485239Sgblack@eecs.umich.edu ''' 9494714Sgblack@eecs.umich.edu 9505040Sgblack@eecs.umich.edu class Zext(RegOp): 9515927Sgblack@eecs.umich.edu code = 'DestReg = merge(DestReg, bits(psrc1, op2, 0), dataSize);' 9525241Sgblack@eecs.umich.edu 9535926Sgblack@eecs.umich.edu class Rddr(RegOp): 9545926Sgblack@eecs.umich.edu def __init__(self, dest, src1, flags=None, dataSize="env.dataSize"): 9555926Sgblack@eecs.umich.edu super(Rddr, self).__init__(dest, \ 9566345Sgblack@eecs.umich.edu src1, "InstRegIndex(NUM_INTREGS)", flags, dataSize) 9575926Sgblack@eecs.umich.edu code = ''' 9585926Sgblack@eecs.umich.edu CR4 cr4 = CR4Op; 9595926Sgblack@eecs.umich.edu DR7 dr7 = DR7Op; 9605926Sgblack@eecs.umich.edu if ((cr4.de == 1 && (src1 == 4 || src1 == 5)) || src1 >= 8) { 9615926Sgblack@eecs.umich.edu fault = new InvalidOpcode(); 9625926Sgblack@eecs.umich.edu } else if (dr7.gd) { 9635926Sgblack@eecs.umich.edu fault = new DebugException(); 9645926Sgblack@eecs.umich.edu } else { 9655926Sgblack@eecs.umich.edu DestReg = merge(DestReg, DebugSrc1, dataSize); 9665926Sgblack@eecs.umich.edu } 9675926Sgblack@eecs.umich.edu ''' 9685926Sgblack@eecs.umich.edu 9695926Sgblack@eecs.umich.edu class Wrdr(RegOp): 9705926Sgblack@eecs.umich.edu def __init__(self, dest, src1, flags=None, dataSize="env.dataSize"): 9715926Sgblack@eecs.umich.edu super(Wrdr, self).__init__(dest, \ 9726345Sgblack@eecs.umich.edu src1, "InstRegIndex(NUM_INTREGS)", flags, dataSize) 9735926Sgblack@eecs.umich.edu code = ''' 9745926Sgblack@eecs.umich.edu CR4 cr4 = CR4Op; 9755926Sgblack@eecs.umich.edu DR7 dr7 = DR7Op; 9765926Sgblack@eecs.umich.edu if ((cr4.de == 1 && (dest == 4 || dest == 5)) || dest >= 8) { 9775926Sgblack@eecs.umich.edu fault = new InvalidOpcode(); 9786345Sgblack@eecs.umich.edu } else if ((dest == 6 || dest == 7) && bits(psrc1, 63, 32) && 9795926Sgblack@eecs.umich.edu machInst.mode.mode == LongMode) { 9805926Sgblack@eecs.umich.edu fault = new GeneralProtection(0); 9815926Sgblack@eecs.umich.edu } else if (dr7.gd) { 9825926Sgblack@eecs.umich.edu fault = new DebugException(); 9835926Sgblack@eecs.umich.edu } else { 9845926Sgblack@eecs.umich.edu DebugDest = psrc1; 9855926Sgblack@eecs.umich.edu } 9865926Sgblack@eecs.umich.edu ''' 9875926Sgblack@eecs.umich.edu 9885296Sgblack@eecs.umich.edu class Rdcr(RegOp): 9895296Sgblack@eecs.umich.edu def __init__(self, dest, src1, flags=None, dataSize="env.dataSize"): 9905296Sgblack@eecs.umich.edu super(Rdcr, self).__init__(dest, \ 9916345Sgblack@eecs.umich.edu src1, "InstRegIndex(NUM_INTREGS)", flags, dataSize) 9925296Sgblack@eecs.umich.edu code = ''' 9935924Sgblack@eecs.umich.edu if (src1 == 1 || (src1 > 4 && src1 < 8) || (src1 > 8)) { 9945296Sgblack@eecs.umich.edu fault = new InvalidOpcode(); 9955296Sgblack@eecs.umich.edu } else { 9965934Sgblack@eecs.umich.edu DestReg = merge(DestReg, ControlSrc1, dataSize); 9975296Sgblack@eecs.umich.edu } 9985296Sgblack@eecs.umich.edu ''' 9995296Sgblack@eecs.umich.edu 10005241Sgblack@eecs.umich.edu class Wrcr(RegOp): 10015241Sgblack@eecs.umich.edu def __init__(self, dest, src1, flags=None, dataSize="env.dataSize"): 10025241Sgblack@eecs.umich.edu super(Wrcr, self).__init__(dest, \ 10036345Sgblack@eecs.umich.edu src1, "InstRegIndex(NUM_INTREGS)", flags, dataSize) 10045241Sgblack@eecs.umich.edu code = ''' 10055241Sgblack@eecs.umich.edu if (dest == 1 || (dest > 4 && dest < 8) || (dest > 8)) { 10065241Sgblack@eecs.umich.edu fault = new InvalidOpcode(); 10075241Sgblack@eecs.umich.edu } else { 10085241Sgblack@eecs.umich.edu // There are *s in the line below so it doesn't confuse the 10095241Sgblack@eecs.umich.edu // parser. They may be unnecessary. 10105241Sgblack@eecs.umich.edu //Mis*cReg old*Val = pick(Cont*rolDest, 0, dat*aSize); 10115241Sgblack@eecs.umich.edu MiscReg newVal = psrc1; 10125241Sgblack@eecs.umich.edu 10135241Sgblack@eecs.umich.edu // Check for any modifications that would cause a fault. 10145241Sgblack@eecs.umich.edu switch(dest) { 10155241Sgblack@eecs.umich.edu case 0: 10165241Sgblack@eecs.umich.edu { 10175241Sgblack@eecs.umich.edu Efer efer = EferOp; 10185241Sgblack@eecs.umich.edu CR0 cr0 = newVal; 10195241Sgblack@eecs.umich.edu CR4 oldCr4 = CR4Op; 10205241Sgblack@eecs.umich.edu if (bits(newVal, 63, 32) || 10215241Sgblack@eecs.umich.edu (!cr0.pe && cr0.pg) || 10225241Sgblack@eecs.umich.edu (!cr0.cd && cr0.nw) || 10235241Sgblack@eecs.umich.edu (cr0.pg && efer.lme && !oldCr4.pae)) 10245241Sgblack@eecs.umich.edu fault = new GeneralProtection(0); 10255241Sgblack@eecs.umich.edu } 10265241Sgblack@eecs.umich.edu break; 10275241Sgblack@eecs.umich.edu case 2: 10285241Sgblack@eecs.umich.edu break; 10295241Sgblack@eecs.umich.edu case 3: 10305241Sgblack@eecs.umich.edu break; 10315241Sgblack@eecs.umich.edu case 4: 10325241Sgblack@eecs.umich.edu { 10335241Sgblack@eecs.umich.edu CR4 cr4 = newVal; 10345241Sgblack@eecs.umich.edu // PAE can't be disabled in long mode. 10355241Sgblack@eecs.umich.edu if (bits(newVal, 63, 11) || 10365241Sgblack@eecs.umich.edu (machInst.mode.mode == LongMode && !cr4.pae)) 10375241Sgblack@eecs.umich.edu fault = new GeneralProtection(0); 10385241Sgblack@eecs.umich.edu } 10395241Sgblack@eecs.umich.edu break; 10405241Sgblack@eecs.umich.edu case 8: 10415241Sgblack@eecs.umich.edu { 10425241Sgblack@eecs.umich.edu if (bits(newVal, 63, 4)) 10435241Sgblack@eecs.umich.edu fault = new GeneralProtection(0); 10445241Sgblack@eecs.umich.edu } 10455241Sgblack@eecs.umich.edu default: 10465241Sgblack@eecs.umich.edu panic("Unrecognized control register %d.\\n", dest); 10475241Sgblack@eecs.umich.edu } 10485241Sgblack@eecs.umich.edu ControlDest = newVal; 10495241Sgblack@eecs.umich.edu } 10505241Sgblack@eecs.umich.edu ''' 10515290Sgblack@eecs.umich.edu 10525294Sgblack@eecs.umich.edu # Microops for manipulating segmentation registers 10535672Sgblack@eecs.umich.edu class SegOp(CondRegOp): 10545294Sgblack@eecs.umich.edu abstract = True 10555290Sgblack@eecs.umich.edu def __init__(self, dest, src1, flags=None, dataSize="env.dataSize"): 10565294Sgblack@eecs.umich.edu super(SegOp, self).__init__(dest, \ 10576345Sgblack@eecs.umich.edu src1, "InstRegIndex(NUM_INTREGS)", flags, dataSize) 10585294Sgblack@eecs.umich.edu 10595294Sgblack@eecs.umich.edu class Wrbase(SegOp): 10605290Sgblack@eecs.umich.edu code = ''' 10615294Sgblack@eecs.umich.edu SegBaseDest = psrc1; 10625290Sgblack@eecs.umich.edu ''' 10635290Sgblack@eecs.umich.edu 10645294Sgblack@eecs.umich.edu class Wrlimit(SegOp): 10655290Sgblack@eecs.umich.edu code = ''' 10665294Sgblack@eecs.umich.edu SegLimitDest = psrc1; 10675294Sgblack@eecs.umich.edu ''' 10685294Sgblack@eecs.umich.edu 10695294Sgblack@eecs.umich.edu class Wrsel(SegOp): 10705294Sgblack@eecs.umich.edu code = ''' 10715294Sgblack@eecs.umich.edu SegSelDest = psrc1; 10725294Sgblack@eecs.umich.edu ''' 10735294Sgblack@eecs.umich.edu 10745905Sgblack@eecs.umich.edu class WrAttr(SegOp): 10755905Sgblack@eecs.umich.edu code = ''' 10765905Sgblack@eecs.umich.edu SegAttrDest = psrc1; 10775905Sgblack@eecs.umich.edu ''' 10785905Sgblack@eecs.umich.edu 10795294Sgblack@eecs.umich.edu class Rdbase(SegOp): 10805294Sgblack@eecs.umich.edu code = ''' 10815932Sgblack@eecs.umich.edu DestReg = merge(DestReg, SegBaseSrc1, dataSize); 10825294Sgblack@eecs.umich.edu ''' 10835294Sgblack@eecs.umich.edu 10845294Sgblack@eecs.umich.edu class Rdlimit(SegOp): 10855294Sgblack@eecs.umich.edu code = ''' 10865932Sgblack@eecs.umich.edu DestReg = merge(DestReg, SegLimitSrc1, dataSize); 10875294Sgblack@eecs.umich.edu ''' 10885294Sgblack@eecs.umich.edu 10895427Sgblack@eecs.umich.edu class RdAttr(SegOp): 10905427Sgblack@eecs.umich.edu code = ''' 10915932Sgblack@eecs.umich.edu DestReg = merge(DestReg, SegAttrSrc1, dataSize); 10925427Sgblack@eecs.umich.edu ''' 10935427Sgblack@eecs.umich.edu 10945294Sgblack@eecs.umich.edu class Rdsel(SegOp): 10955294Sgblack@eecs.umich.edu code = ''' 10965932Sgblack@eecs.umich.edu DestReg = merge(DestReg, SegSelSrc1, dataSize); 10975294Sgblack@eecs.umich.edu ''' 10985294Sgblack@eecs.umich.edu 10995682Sgblack@eecs.umich.edu class Rdval(RegOp): 11005682Sgblack@eecs.umich.edu def __init__(self, dest, src1, flags=None, dataSize="env.dataSize"): 11016345Sgblack@eecs.umich.edu super(Rdval, self).__init__(dest, src1, \ 11026345Sgblack@eecs.umich.edu "InstRegIndex(NUM_INTREGS)", flags, dataSize) 11035682Sgblack@eecs.umich.edu code = ''' 11045682Sgblack@eecs.umich.edu DestReg = MiscRegSrc1; 11055682Sgblack@eecs.umich.edu ''' 11065682Sgblack@eecs.umich.edu 11075682Sgblack@eecs.umich.edu class Wrval(RegOp): 11085682Sgblack@eecs.umich.edu def __init__(self, dest, src1, flags=None, dataSize="env.dataSize"): 11096345Sgblack@eecs.umich.edu super(Wrval, self).__init__(dest, src1, \ 11106345Sgblack@eecs.umich.edu "InstRegIndex(NUM_INTREGS)", flags, dataSize) 11115682Sgblack@eecs.umich.edu code = ''' 11125682Sgblack@eecs.umich.edu MiscRegDest = SrcReg1; 11135682Sgblack@eecs.umich.edu ''' 11145682Sgblack@eecs.umich.edu 11155428Sgblack@eecs.umich.edu class Chks(RegOp): 11165428Sgblack@eecs.umich.edu def __init__(self, dest, src1, src2=0, 11175428Sgblack@eecs.umich.edu flags=None, dataSize="env.dataSize"): 11185428Sgblack@eecs.umich.edu super(Chks, self).__init__(dest, 11195428Sgblack@eecs.umich.edu src1, src2, flags, dataSize) 11205294Sgblack@eecs.umich.edu code = ''' 11215424Sgblack@eecs.umich.edu // The selector is in source 1 and can be at most 16 bits. 11225433Sgblack@eecs.umich.edu SegSelector selector = DestReg; 11235433Sgblack@eecs.umich.edu SegDescriptor desc = SrcReg1; 11245433Sgblack@eecs.umich.edu HandyM5Reg m5reg = M5Reg; 11255294Sgblack@eecs.umich.edu 11265428Sgblack@eecs.umich.edu switch (imm8) 11275428Sgblack@eecs.umich.edu { 11285428Sgblack@eecs.umich.edu case SegNoCheck: 11295428Sgblack@eecs.umich.edu break; 11305428Sgblack@eecs.umich.edu case SegCSCheck: 11316060Sgblack@eecs.umich.edu // Make sure it's the right type 11326060Sgblack@eecs.umich.edu if (desc.s == 0 || desc.type.codeOrData != 1) { 11336060Sgblack@eecs.umich.edu fault = new GeneralProtection(0); 11346060Sgblack@eecs.umich.edu } else if (m5reg.cpl != desc.dpl) { 11356060Sgblack@eecs.umich.edu fault = new GeneralProtection(0); 11366060Sgblack@eecs.umich.edu } 11375428Sgblack@eecs.umich.edu break; 11385428Sgblack@eecs.umich.edu case SegCallGateCheck: 11395428Sgblack@eecs.umich.edu panic("CS checks for far calls/jumps through call gates" 11405428Sgblack@eecs.umich.edu "not implemented.\\n"); 11415428Sgblack@eecs.umich.edu break; 11425855Sgblack@eecs.umich.edu case SegSoftIntGateCheck: 11435853Sgblack@eecs.umich.edu // Check permissions. 11445674Sgblack@eecs.umich.edu if (desc.dpl < m5reg.cpl) { 11455857Sgblack@eecs.umich.edu fault = new GeneralProtection(selector); 11466058Sgblack@eecs.umich.edu break; 11475674Sgblack@eecs.umich.edu } 11485855Sgblack@eecs.umich.edu // Fall through on purpose 11495855Sgblack@eecs.umich.edu case SegIntGateCheck: 11505853Sgblack@eecs.umich.edu // Make sure the gate's the right type. 11515861Snate@binkert.org if ((m5reg.mode == LongMode && (desc.type & 0xe) != 0xe) || 11525853Sgblack@eecs.umich.edu ((desc.type & 0x6) != 0x6)) { 11535853Sgblack@eecs.umich.edu fault = new GeneralProtection(0); 11545853Sgblack@eecs.umich.edu } 11555674Sgblack@eecs.umich.edu break; 11565428Sgblack@eecs.umich.edu case SegSSCheck: 11575433Sgblack@eecs.umich.edu if (selector.si || selector.ti) { 11585433Sgblack@eecs.umich.edu if (!desc.p) { 11595857Sgblack@eecs.umich.edu fault = new StackFault(selector); 11605433Sgblack@eecs.umich.edu } 11615433Sgblack@eecs.umich.edu } else { 11625673Sgblack@eecs.umich.edu if ((m5reg.submode != SixtyFourBitMode || 11635673Sgblack@eecs.umich.edu m5reg.cpl == 3) || 11645433Sgblack@eecs.umich.edu !(desc.s == 1 && 11655433Sgblack@eecs.umich.edu desc.type.codeOrData == 0 && desc.type.w) || 11665433Sgblack@eecs.umich.edu (desc.dpl != m5reg.cpl) || 11675433Sgblack@eecs.umich.edu (selector.rpl != m5reg.cpl)) { 11685857Sgblack@eecs.umich.edu fault = new GeneralProtection(selector); 11695433Sgblack@eecs.umich.edu } 11705433Sgblack@eecs.umich.edu } 11715428Sgblack@eecs.umich.edu break; 11725428Sgblack@eecs.umich.edu case SegIretCheck: 11735428Sgblack@eecs.umich.edu { 11745433Sgblack@eecs.umich.edu if ((!selector.si && !selector.ti) || 11755433Sgblack@eecs.umich.edu (selector.rpl < m5reg.cpl) || 11765433Sgblack@eecs.umich.edu !(desc.s == 1 && desc.type.codeOrData == 1) || 11775433Sgblack@eecs.umich.edu (!desc.type.c && desc.dpl != selector.rpl) || 11785679Sgblack@eecs.umich.edu (desc.type.c && desc.dpl > selector.rpl)) { 11795857Sgblack@eecs.umich.edu fault = new GeneralProtection(selector); 11805679Sgblack@eecs.umich.edu } else if (!desc.p) { 11815857Sgblack@eecs.umich.edu fault = new SegmentNotPresent(selector); 11825679Sgblack@eecs.umich.edu } 11835428Sgblack@eecs.umich.edu break; 11845428Sgblack@eecs.umich.edu } 11855428Sgblack@eecs.umich.edu case SegIntCSCheck: 11865675Sgblack@eecs.umich.edu if (m5reg.mode == LongMode) { 11875675Sgblack@eecs.umich.edu if (desc.l != 1 || desc.d != 0) { 11885679Sgblack@eecs.umich.edu fault = new GeneralProtection(selector); 11895675Sgblack@eecs.umich.edu } 11905675Sgblack@eecs.umich.edu } else { 11915675Sgblack@eecs.umich.edu panic("Interrupt CS checks not implemented " 11925675Sgblack@eecs.umich.edu "in legacy mode.\\n"); 11935675Sgblack@eecs.umich.edu } 11945428Sgblack@eecs.umich.edu break; 11955899Sgblack@eecs.umich.edu case SegTRCheck: 11965899Sgblack@eecs.umich.edu if (!selector.si || selector.ti) { 11975899Sgblack@eecs.umich.edu fault = new GeneralProtection(selector); 11985899Sgblack@eecs.umich.edu } 11995899Sgblack@eecs.umich.edu break; 12005900Sgblack@eecs.umich.edu case SegTSSCheck: 12015900Sgblack@eecs.umich.edu if (!desc.p) { 12025900Sgblack@eecs.umich.edu fault = new SegmentNotPresent(selector); 12035900Sgblack@eecs.umich.edu } else if (!(desc.type == 0x9 || 12045900Sgblack@eecs.umich.edu (desc.type == 1 && 12055900Sgblack@eecs.umich.edu m5reg.mode != LongMode))) { 12065935Sgblack@eecs.umich.edu fault = new GeneralProtection(selector); 12075900Sgblack@eecs.umich.edu } 12085900Sgblack@eecs.umich.edu break; 12095936Sgblack@eecs.umich.edu case SegInGDTCheck: 12105936Sgblack@eecs.umich.edu if (selector.ti) { 12115936Sgblack@eecs.umich.edu fault = new GeneralProtection(selector); 12125936Sgblack@eecs.umich.edu } 12135936Sgblack@eecs.umich.edu break; 12145936Sgblack@eecs.umich.edu case SegLDTCheck: 12155936Sgblack@eecs.umich.edu if (!desc.p) { 12165936Sgblack@eecs.umich.edu fault = new SegmentNotPresent(selector); 12175936Sgblack@eecs.umich.edu } else if (desc.type != 0x2) { 12185936Sgblack@eecs.umich.edu fault = new GeneralProtection(selector); 12195936Sgblack@eecs.umich.edu } 12205936Sgblack@eecs.umich.edu break; 12215428Sgblack@eecs.umich.edu default: 12225428Sgblack@eecs.umich.edu panic("Undefined segment check type.\\n"); 12235428Sgblack@eecs.umich.edu } 12245294Sgblack@eecs.umich.edu ''' 12255294Sgblack@eecs.umich.edu flag_code = ''' 12265294Sgblack@eecs.umich.edu // Check for a NULL selector and set ZF,EZF appropriately. 12275294Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits & ~(ext & (ZFBit | EZFBit)); 12285424Sgblack@eecs.umich.edu if (!selector.si && !selector.ti) 12295294Sgblack@eecs.umich.edu ccFlagBits = ccFlagBits | (ext & (ZFBit | EZFBit)); 12305294Sgblack@eecs.umich.edu ''' 12315294Sgblack@eecs.umich.edu 12325294Sgblack@eecs.umich.edu class Wrdh(RegOp): 12335294Sgblack@eecs.umich.edu code = ''' 12345678Sgblack@eecs.umich.edu SegDescriptor desc = SrcReg1; 12355294Sgblack@eecs.umich.edu 12365678Sgblack@eecs.umich.edu uint64_t target = bits(SrcReg2, 31, 0) << 32; 12375678Sgblack@eecs.umich.edu switch(desc.type) { 12385678Sgblack@eecs.umich.edu case LDT64: 12395678Sgblack@eecs.umich.edu case AvailableTSS64: 12405678Sgblack@eecs.umich.edu case BusyTSS64: 12415678Sgblack@eecs.umich.edu replaceBits(target, 23, 0, desc.baseLow); 12425678Sgblack@eecs.umich.edu replaceBits(target, 31, 24, desc.baseHigh); 12435678Sgblack@eecs.umich.edu break; 12445678Sgblack@eecs.umich.edu case CallGate64: 12455678Sgblack@eecs.umich.edu case IntGate64: 12465678Sgblack@eecs.umich.edu case TrapGate64: 12475678Sgblack@eecs.umich.edu replaceBits(target, 15, 0, bits(desc, 15, 0)); 12485678Sgblack@eecs.umich.edu replaceBits(target, 31, 16, bits(desc, 63, 48)); 12495678Sgblack@eecs.umich.edu break; 12505678Sgblack@eecs.umich.edu default: 12515678Sgblack@eecs.umich.edu panic("Wrdh used with wrong descriptor type!\\n"); 12525678Sgblack@eecs.umich.edu } 12535678Sgblack@eecs.umich.edu DestReg = target; 12545294Sgblack@eecs.umich.edu ''' 12555294Sgblack@eecs.umich.edu 12565409Sgblack@eecs.umich.edu class Wrtsc(WrRegOp): 12575409Sgblack@eecs.umich.edu code = ''' 12585409Sgblack@eecs.umich.edu TscOp = psrc1; 12595409Sgblack@eecs.umich.edu ''' 12605409Sgblack@eecs.umich.edu 12615409Sgblack@eecs.umich.edu class Rdtsc(RdRegOp): 12625409Sgblack@eecs.umich.edu code = ''' 12635409Sgblack@eecs.umich.edu DestReg = TscOp; 12645409Sgblack@eecs.umich.edu ''' 12655409Sgblack@eecs.umich.edu 12665429Sgblack@eecs.umich.edu class Rdm5reg(RdRegOp): 12675429Sgblack@eecs.umich.edu code = ''' 12685429Sgblack@eecs.umich.edu DestReg = M5Reg; 12695429Sgblack@eecs.umich.edu ''' 12705429Sgblack@eecs.umich.edu 12715294Sgblack@eecs.umich.edu class Wrdl(RegOp): 12725294Sgblack@eecs.umich.edu code = ''' 12735294Sgblack@eecs.umich.edu SegDescriptor desc = SrcReg1; 12745433Sgblack@eecs.umich.edu SegSelector selector = SrcReg2; 12755433Sgblack@eecs.umich.edu if (selector.si || selector.ti) { 12766222Sgblack@eecs.umich.edu if (!desc.p) 12776222Sgblack@eecs.umich.edu panic("Segment not present.\\n"); 12785433Sgblack@eecs.umich.edu SegAttr attr = 0; 12795433Sgblack@eecs.umich.edu attr.dpl = desc.dpl; 12806222Sgblack@eecs.umich.edu attr.unusable = 0; 12815433Sgblack@eecs.umich.edu attr.defaultSize = desc.d; 12826222Sgblack@eecs.umich.edu attr.longMode = desc.l; 12836222Sgblack@eecs.umich.edu attr.avl = desc.avl; 12846222Sgblack@eecs.umich.edu attr.granularity = desc.g; 12856222Sgblack@eecs.umich.edu attr.present = desc.p; 12866222Sgblack@eecs.umich.edu attr.system = desc.s; 12876222Sgblack@eecs.umich.edu attr.type = desc.type; 12885433Sgblack@eecs.umich.edu if (!desc.s) { 12895901Sgblack@eecs.umich.edu // The expand down bit happens to be set for gates. 12905901Sgblack@eecs.umich.edu if (desc.type.e) { 12915901Sgblack@eecs.umich.edu panic("Gate descriptor encountered.\\n"); 12925901Sgblack@eecs.umich.edu } 12935901Sgblack@eecs.umich.edu attr.readable = 1; 12945901Sgblack@eecs.umich.edu attr.writable = 1; 12956222Sgblack@eecs.umich.edu attr.expandDown = 0; 12965433Sgblack@eecs.umich.edu } else { 12975433Sgblack@eecs.umich.edu if (desc.type.codeOrData) { 12986222Sgblack@eecs.umich.edu attr.expandDown = 0; 12995433Sgblack@eecs.umich.edu attr.readable = desc.type.r; 13006222Sgblack@eecs.umich.edu attr.writable = 0; 13015433Sgblack@eecs.umich.edu } else { 13025433Sgblack@eecs.umich.edu attr.expandDown = desc.type.e; 13035433Sgblack@eecs.umich.edu attr.readable = 1; 13045433Sgblack@eecs.umich.edu attr.writable = desc.type.w; 13055433Sgblack@eecs.umich.edu } 13065433Sgblack@eecs.umich.edu } 13075901Sgblack@eecs.umich.edu Addr base = desc.baseLow | (desc.baseHigh << 24); 13085901Sgblack@eecs.umich.edu Addr limit = desc.limitLow | (desc.limitHigh << 16); 13095901Sgblack@eecs.umich.edu if (desc.g) 13105901Sgblack@eecs.umich.edu limit = (limit << 12) | mask(12); 13115901Sgblack@eecs.umich.edu SegBaseDest = base; 13125901Sgblack@eecs.umich.edu SegLimitDest = limit; 13135901Sgblack@eecs.umich.edu SegAttrDest = attr; 13145433Sgblack@eecs.umich.edu } else { 13155295Sgblack@eecs.umich.edu SegBaseDest = SegBaseDest; 13165295Sgblack@eecs.umich.edu SegLimitDest = SegLimitDest; 13175295Sgblack@eecs.umich.edu SegAttrDest = SegAttrDest; 13185294Sgblack@eecs.umich.edu } 13195290Sgblack@eecs.umich.edu ''' 13204519Sgblack@eecs.umich.edu}}; 1321