microasm.isa revision 5121
111106Spower.jg@gmail.com// -*- mode:c++ -*- 211106Spower.jg@gmail.com 311390Ssteve.reinhardt@amd.com// Copyright (c) 2007 The Hewlett-Packard Development Company 411390Ssteve.reinhardt@amd.com// All rights reserved. 511390Ssteve.reinhardt@amd.com// 611106Spower.jg@gmail.com// Redistribution and use of this software in source and binary forms, 711530Sandreas.sandberg@arm.com// with or without modification, are permitted provided that the 811530Sandreas.sandberg@arm.com// following conditions are met: 911530Sandreas.sandberg@arm.com// 1011530Sandreas.sandberg@arm.com// The software must be used only for Non-Commercial Use which means any 1111456Sandreas.hansson@arm.com// use which is NOT directed to receiving any direct monetary 1211390Ssteve.reinhardt@amd.com// compensation for, or commercial advantage from such use. Illustrative 1311390Ssteve.reinhardt@amd.com// examples of non-commercial use are academic research, personal study, 1411106Spower.jg@gmail.com// teaching, education and corporate research & development. 1511106Spower.jg@gmail.com// Illustrative examples of commercial use are distributing products for 1611530Sandreas.sandberg@arm.com// commercial advantage and providing services using the software for 1711106Spower.jg@gmail.com// commercial advantage. 1811106Spower.jg@gmail.com// 1911106Spower.jg@gmail.com// If you wish to use this software or functionality therein that may be 2011106Spower.jg@gmail.com// covered by patents for commercial use, please contact: 2111106Spower.jg@gmail.com// Director of Intellectual Property Licensing 2211106Spower.jg@gmail.com// Office of Strategy and Technology 2311106Spower.jg@gmail.com// Hewlett-Packard Company 2411106Spower.jg@gmail.com// 1501 Page Mill Road 2511390Ssteve.reinhardt@amd.com// Palo Alto, California 94304 2611390Ssteve.reinhardt@amd.com// 2711390Ssteve.reinhardt@amd.com// Redistributions of source code must retain the above copyright notice, 2811390Ssteve.reinhardt@amd.com// this list of conditions and the following disclaimer. Redistributions 2911390Ssteve.reinhardt@amd.com// in binary form must reproduce the above copyright notice, this list of 3011390Ssteve.reinhardt@amd.com// conditions and the following disclaimer in the documentation and/or 3111390Ssteve.reinhardt@amd.com// other materials provided with the distribution. Neither the name of 3211390Ssteve.reinhardt@amd.com// the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 3311106Spower.jg@gmail.com// contributors may be used to endorse or promote products derived from 3411106Spower.jg@gmail.com// this software without specific prior written permission. No right of 3511106Spower.jg@gmail.com// sublicense is granted herewith. Derivatives of the software and 3611106Spower.jg@gmail.com// output created using the software may be prepared, but only for 3711106Spower.jg@gmail.com// Non-Commercial Uses. Derivatives of the software may be shared with 3811106Spower.jg@gmail.com// others provided: (i) the others agree to abide by the list of 3911106Spower.jg@gmail.com// conditions herein which includes the Non-Commercial Use restrictions; 4011106Spower.jg@gmail.com// and (ii) such Derivatives of the software include the above copyright 4111106Spower.jg@gmail.com// notice to acknowledge the contribution from this software where 4211106Spower.jg@gmail.com// applicable, this list of conditions and the disclaimer below. 4311106Spower.jg@gmail.com// 4411106Spower.jg@gmail.com// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4511106Spower.jg@gmail.com// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 4611106Spower.jg@gmail.com// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 4711106Spower.jg@gmail.com// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 4811106Spower.jg@gmail.com// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4911106Spower.jg@gmail.com// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 5011106Spower.jg@gmail.com// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 5111106Spower.jg@gmail.com// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 5211106Spower.jg@gmail.com// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 5311106Spower.jg@gmail.com// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 5411106Spower.jg@gmail.com// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 5511106Spower.jg@gmail.com// 5611106Spower.jg@gmail.com// Authors: Gabe Black 5711106Spower.jg@gmail.com 5811106Spower.jg@gmail.com//Include the definitions of the micro ops. 5911106Spower.jg@gmail.com//These are python representations of static insts which stand on their own 6011106Spower.jg@gmail.com//and make up an internal instruction set. They are used by the micro 6111106Spower.jg@gmail.com//assembler. 6211106Spower.jg@gmail.com##include "microops/microops.isa" 6311106Spower.jg@gmail.com 6411106Spower.jg@gmail.com//Include code to build macroops in both C++ and python. 6511106Spower.jg@gmail.com##include "macroop.isa" 6611106Spower.jg@gmail.com 6711106Spower.jg@gmail.comlet {{ 6811106Spower.jg@gmail.com import sys 6911106Spower.jg@gmail.com sys.path[0:0] = ["src/arch/x86/isa/"] 7011106Spower.jg@gmail.com from insts import microcode 7111106Spower.jg@gmail.com # print microcode 7211106Spower.jg@gmail.com from micro_asm import MicroAssembler, Rom_Macroop, Rom 7311106Spower.jg@gmail.com mainRom = Rom('main ROM') 7411106Spower.jg@gmail.com assembler = MicroAssembler(X86Macroop, microopClasses, mainRom, Rom_Macroop) 7511106Spower.jg@gmail.com # Add in symbols for the microcode registers 7611106Spower.jg@gmail.com for num in range(15): 7711106Spower.jg@gmail.com assembler.symbols["t%d" % num] = "NUM_INTREGS+%d" % num 7811106Spower.jg@gmail.com for num in range(7): 7911390Ssteve.reinhardt@amd.com assembler.symbols["ufp%d" % num] = "FLOATREG_MICROFP(%d)" % num 8011106Spower.jg@gmail.com # Add in symbols for the segment descriptor registers 8111106Spower.jg@gmail.com for letter in ("C", "D", "E", "F", "G", "S"): 8211106Spower.jg@gmail.com assembler.symbols["%ss" % letter.lower()] = "SEGMENT_REG_%sS" % letter 8311106Spower.jg@gmail.com # Miscellaneous symbols 8411106Spower.jg@gmail.com symbols = { 8511106Spower.jg@gmail.com "reg" : "env.reg", 8611106Spower.jg@gmail.com "xmml" : "FLOATREG_XMM_LOW(env.reg)", 8711106Spower.jg@gmail.com "xmmh" : "FLOATREG_XMM_HIGH(env.reg)", 8811106Spower.jg@gmail.com "regm" : "env.regm", 8911106Spower.jg@gmail.com "xmmlm" : "FLOATREG_XMM_LOW(env.regm)", 9011106Spower.jg@gmail.com "xmmhm" : "FLOATREG_XMM_HIGH(env.regm)", 9111106Spower.jg@gmail.com "imm" : "IMMEDIATE", 9211106Spower.jg@gmail.com "disp" : "DISPLACEMENT", 9311106Spower.jg@gmail.com "seg" : "env.seg", 9411106Spower.jg@gmail.com "scale" : "env.scale", 9511106Spower.jg@gmail.com "index" : "env.index", 9611106Spower.jg@gmail.com "base" : "env.base", 9711106Spower.jg@gmail.com "dsz" : "env.dataSize", 9811106Spower.jg@gmail.com "asz" : "env.addressSize", 9911106Spower.jg@gmail.com "ssz" : "env.stackSize" 10011106Spower.jg@gmail.com } 10111106Spower.jg@gmail.com assembler.symbols.update(symbols) 10211106Spower.jg@gmail.com 10311106Spower.jg@gmail.com # Short hand for common scale-index-base combinations. 10411106Spower.jg@gmail.com assembler.symbols["sib"] = \ 10511106Spower.jg@gmail.com [symbols["scale"], symbols["index"], symbols["base"]] 10611106Spower.jg@gmail.com assembler.symbols["riprel"] = \ 10711106Spower.jg@gmail.com ["1", assembler.symbols["t0"], assembler.symbols["t7"]] 10811106Spower.jg@gmail.com 10911106Spower.jg@gmail.com for reg in ('ax', 'bx', 'cx', 'dx', 'sp', 'bp', 'si', 'di'): 11011106Spower.jg@gmail.com assembler.symbols["r%s" % reg] = "INTREG_R%s" % reg.upper() 11111106Spower.jg@gmail.com 11211106Spower.jg@gmail.com for flag in ('CF', 'PF', 'ECF', 'AF', 'EZF', 'ZF', 'SF', 'OF'): 11311106Spower.jg@gmail.com assembler.symbols[flag] = flag + "Bit" 11411106Spower.jg@gmail.com 11511106Spower.jg@gmail.com for cond in ('True', 'False', 'ECF', 'EZF', 'SZnZF', 11611106Spower.jg@gmail.com 'MSTRZ', 'STRZ', 'MSTRC', 11711106Spower.jg@gmail.com 'OF', 'CF', 'ZF', 'CvZF', 11811106Spower.jg@gmail.com 'SF', 'PF', 'SxOF', 'SxOvZF'): 11911106Spower.jg@gmail.com assembler.symbols["C%s" % cond] = "ConditionTests::%s" % cond 12011106Spower.jg@gmail.com assembler.symbols["nC%s" % cond] = "ConditionTests::Not%s" % cond 12111106Spower.jg@gmail.com assembler.symbols["CSTRZnEZF"] = "ConditionTests::STRZnEZF" 12211106Spower.jg@gmail.com assembler.symbols["CSTRnZnEZF"] = "ConditionTests::STRnZnEZF" 12311106Spower.jg@gmail.com 12411106Spower.jg@gmail.com assembler.symbols["CTrue"] = "ConditionTests::True" 12511106Spower.jg@gmail.com assembler.symbols["CFalse"] = "ConditionTests::False" 12611106Spower.jg@gmail.com 12711106Spower.jg@gmail.com # Code literal which forces a default 64 bit operand size in 64 bit mode. 12811106Spower.jg@gmail.com assembler.symbols["oszIn64Override"] = ''' 12911106Spower.jg@gmail.com if (machInst.mode.submode == SixtyFourBitMode && 13011106Spower.jg@gmail.com env.dataSize == 4) 13111106Spower.jg@gmail.com env.dataSize = 8; 13211106Spower.jg@gmail.com ''' 13311106Spower.jg@gmail.com 13411106Spower.jg@gmail.com def labeler(labelStr): 13511106Spower.jg@gmail.com return "label_%s" % labelStr 13611106Spower.jg@gmail.com 13711106Spower.jg@gmail.com assembler.symbols["label"] = labeler 13811106Spower.jg@gmail.com 13911106Spower.jg@gmail.com def stack_index(index): 14011106Spower.jg@gmail.com return "(NUM_FLOATREGS + (((%s) + 8) %% 8))" % index 14111106Spower.jg@gmail.com 14211106Spower.jg@gmail.com assembler.symbols["st"] = stack_index 14311106Spower.jg@gmail.com 14411106Spower.jg@gmail.com macroopDict = assembler.assemble(microcode) 14511106Spower.jg@gmail.com}}; 14611106Spower.jg@gmail.com