branch.isa revision 6253:988a001820f8
1// -*- mode:c++ -*- 2 3// Copyright (c) 2007-2008 The Florida State University 4// All rights reserved. 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions are 8// met: redistributions of source code must retain the above copyright 9// notice, this list of conditions and the following disclaimer; 10// redistributions in binary form must reproduce the above copyright 11// notice, this list of conditions and the following disclaimer in the 12// documentation and/or other materials provided with the distribution; 13// neither the name of the copyright holders nor the names of its 14// contributors may be used to endorse or promote products derived from 15// this software without specific prior written permission. 16// 17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28// 29// Authors: Stephen Hines 30 31//////////////////////////////////////////////////////////////////// 32// 33// Control transfer instructions 34// 35 36def format Branch(code,*opt_flags) {{ 37 38 #Build Instruction Flags 39 #Use Link & Likely Flags to Add Link/Condition Code 40 inst_flags = ('IsDirectControl', ) 41 for x in opt_flags: 42 if x == 'Link': 43 code += 'LR = NPC;\n' 44 else: 45 inst_flags += (x, ) 46 47 #Take into account uncond. branch instruction 48 if 'cond == 1' in code: 49 inst_flags += ('IsUnCondControl', ) 50 else: 51 inst_flags += ('IsCondControl', ) 52 53 icode = 'if (testPredicate(Cpsr, condCode)) {\n' 54 icode += code 55 icode += ' NPC = NPC + 4 + disp;\n' 56 icode += '} else {\n' 57 icode += ' NPC = NPC;\n' 58 icode += '};\n' 59 60 code = icode 61 62 iop = InstObjParams(name, Name, 'Branch', code, inst_flags) 63 header_output = BasicDeclare.subst(iop) 64 decoder_output = BasicConstructor.subst(iop) 65 decode_block = BasicDecode.subst(iop) 66 exec_output = BasicExecute.subst(iop) 67}}; 68 69def format BranchExchange(code,*opt_flags) {{ 70 #Build Instruction Flags 71 #Use Link & Likely Flags to Add Link/Condition Code 72 inst_flags = ('IsIndirectControl', ) 73 for x in opt_flags: 74 if x == 'Link': 75 code += 'LR = NPC;\n' 76 else: 77 inst_flags += (x, ) 78 79 #Take into account uncond. branch instruction 80 if 'cond == 1' in code: 81 inst_flags += ('IsUnCondControl', ) 82 else: 83 inst_flags += ('IsCondControl', ) 84 85 #Condition code 86 87 icode = 'if (testPredicate(Cpsr, condCode)) {\n' 88 icode += code 89 icode += ' NPC = Rm & 0xfffffffe; // Masks off bottom bit\n' 90 icode += '} else {\n' 91 icode += ' NPC = NPC;\n' 92 icode += '};\n' 93 94 code = icode 95 96 iop = InstObjParams(name, Name, 'BranchExchange', code, inst_flags) 97 header_output = BasicDeclare.subst(iop) 98 decoder_output = BasicConstructor.subst(iop) 99 decode_block = BasicDecode.subst(iop) 100 exec_output = BasicExecute.subst(iop) 101}}; 102 103def format Jump(code, *opt_flags) {{ 104 #Build Instruction Flags 105 #Use Link Flag to Add Link Code 106 inst_flags = ('IsIndirectControl', 'IsUncondControl') 107 for x in opt_flags: 108 if x == 'Link': 109 code = 'LR = NPC;\n' + code 110 elif x == 'ClearHazards': 111 code += '/* Code Needed to Clear Execute & Inst Hazards */\n' 112 else: 113 inst_flags += (x, ) 114 115 iop = InstObjParams(name, Name, 'Jump', code, inst_flags) 116 header_output = BasicDeclare.subst(iop) 117 decoder_output = BasicConstructor.subst(iop) 118 decode_block = BasicDecode.subst(iop) 119 exec_output = BasicExecute.subst(iop) 120 #exec_output = PredOpExecute.subst(iop) 121}}; 122 123 124