branch.isa revision 6259:71dd4e07e626
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    linking = False
42    for x in opt_flags:
43        if x == 'Link':
44            linking = True
45            code += 'LR = NPC;\n'
46        else:
47            inst_flags += (x, )
48
49    #Take into account uncond. branch instruction
50    if 'cond == 1' in code:
51         inst_flags += ('IsUnCondControl', )
52    else:
53         inst_flags += ('IsCondControl', )
54
55    icode =  'if (testPredicate(Cpsr, condCode)) {\n'
56    icode += code
57    icode += '  NPC = NPC + 4 + disp;\n'
58    icode += '} else {\n'
59    icode += '  NPC = NPC;\n'
60    if linking:
61        icode += '  LR = LR;\n'
62    icode += '};\n'
63
64    code = icode
65
66    iop = InstObjParams(name, Name, 'Branch', code, inst_flags)
67    header_output = BasicDeclare.subst(iop)
68    decoder_output = BasicConstructor.subst(iop)
69    decode_block = BasicDecode.subst(iop)
70    exec_output = BasicExecute.subst(iop)
71}};
72
73def format BranchExchange(code,*opt_flags) {{
74    #Build Instruction Flags
75    #Use Link & Likely Flags to Add Link/Condition Code
76    inst_flags = ('IsIndirectControl', )
77    linking = False
78    for x in opt_flags:
79        if x == 'Link':
80            linking = True
81            code += 'LR = NPC;\n'
82        else:
83            inst_flags += (x, )
84
85    #Take into account uncond. branch instruction
86    if 'cond == 1' in code:
87         inst_flags += ('IsUnCondControl', )
88    else:
89         inst_flags += ('IsCondControl', )
90
91    #Condition code
92
93    icode =  'if (testPredicate(Cpsr, condCode)) {\n'
94    icode += code
95    icode += '  NPC = Rm & 0xfffffffe; // Masks off bottom bit\n'
96    icode += '} else {\n'
97    icode += '  NPC = NPC;\n'
98    if linking:
99        icode += '  LR = LR;\n'
100    icode += '};\n'
101
102    code = icode
103
104    iop = InstObjParams(name, Name, 'BranchExchange', code, inst_flags)
105    header_output = BasicDeclare.subst(iop)
106    decoder_output = BasicConstructor.subst(iop)
107    decode_block = BasicDecode.subst(iop)
108    exec_output = BasicExecute.subst(iop)
109}};
110
111def format Jump(code, *opt_flags) {{
112    #Build Instruction Flags
113    #Use Link Flag to Add Link Code
114    inst_flags = ('IsIndirectControl', 'IsUncondControl')
115    for x in opt_flags:
116        if x == 'Link':
117            code = 'LR = NPC;\n' + code
118        elif x == 'ClearHazards':
119            code += '/* Code Needed to Clear Execute & Inst Hazards */\n'
120        else:
121            inst_flags += (x, )
122
123    iop = InstObjParams(name, Name, 'Jump', code, inst_flags)
124    header_output = BasicDeclare.subst(iop)
125    decoder_output = BasicConstructor.subst(iop)
126    decode_block = BasicDecode.subst(iop)
127    exec_output = BasicExecute.subst(iop)
128    #exec_output = PredOpExecute.subst(iop)
129}};
130
131
132