2 * Copyright (c) 2007 The Hewlett-Packard Development Company
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions are
17 * met: redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer;
19 * redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution;
22 * neither the name of the copyright holders nor the names of its
23 * contributors may be used to endorse or promote products derived from
24 * this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include "arch/x86/insts/static_inst.hh"
43 #include "arch/x86/regs/segment.hh"
44 #include "cpu/reg_class.hh"
48 void X86StaticInst::printMnemonic(std::ostream
&os
,
49 const char * mnemonic
) const
51 ccprintf(os
, " %s ", mnemonic
);
54 void X86StaticInst::printMnemonic(std::ostream
&os
,
55 const char * instMnemonic
, const char * mnemonic
) const
57 ccprintf(os
, " %s : %s ", instMnemonic
, mnemonic
);
60 void X86StaticInst::printSegment(std::ostream
&os
, int segment
) const
97 case SYS_SEGMENT_REG_TR
:
100 case SYS_SEGMENT_REG_IDTR
:
101 ccprintf(os
, "IDTR");
104 panic("Unrecognized segment %d\n", segment
);
109 X86StaticInst::printSrcReg(std::ostream
&os
, int reg
, int size
) const
111 if (_numSrcRegs
> reg
)
112 printReg(os
, _srcRegIdx
[reg
], size
);
116 X86StaticInst::printDestReg(std::ostream
&os
, int reg
, int size
) const
118 if (_numDestRegs
> reg
)
119 printReg(os
, _destRegIdx
[reg
], size
);
123 X86StaticInst::printReg(std::ostream
&os
, RegId reg
, int size
) const
125 assert(size
== 1 || size
== 2 || size
== 4 || size
== 8);
126 static const char * abcdFormats
[9] =
127 {"", "%s", "%sx", "", "e%sx", "", "", "", "r%sx"};
128 static const char * piFormats
[9] =
129 {"", "%s", "%s", "", "e%s", "", "", "", "r%s"};
130 static const char * longFormats
[9] =
131 {"", "r%sb", "r%sw", "", "r%sd", "", "", "", "r%s"};
132 static const char * microFormats
[9] =
133 {"", "t%db", "t%dw", "", "t%dd", "", "", "", "t%d"};
135 RegIndex reg_idx
= reg
.index();
137 if (reg
.isIntReg()) {
138 const char * suffix
= "";
139 bool fold
= reg_idx
& IntFoldBit
;
140 reg_idx
&= ~IntFoldBit
;
144 else if (reg_idx
< 8 && size
== 1)
149 ccprintf(os
, abcdFormats
[size
], "a");
152 ccprintf(os
, abcdFormats
[size
], "b");
155 ccprintf(os
, abcdFormats
[size
], "c");
158 ccprintf(os
, abcdFormats
[size
], "d");
161 ccprintf(os
, piFormats
[size
], "sp");
164 ccprintf(os
, piFormats
[size
], "bp");
167 ccprintf(os
, piFormats
[size
], "si");
170 ccprintf(os
, piFormats
[size
], "di");
173 ccprintf(os
, longFormats
[size
], "8");
176 ccprintf(os
, longFormats
[size
], "9");
179 ccprintf(os
, longFormats
[size
], "10");
182 ccprintf(os
, longFormats
[size
], "11");
185 ccprintf(os
, longFormats
[size
], "12");
188 ccprintf(os
, longFormats
[size
], "13");
191 ccprintf(os
, longFormats
[size
], "14");
194 ccprintf(os
, longFormats
[size
], "15");
197 ccprintf(os
, microFormats
[size
], reg_idx
- NUM_INTREGS
);
199 ccprintf(os
, suffix
);
201 } else if (reg
.isFloatReg()) {
202 if (reg_idx
< NumMMXRegs
) {
203 ccprintf(os
, "%%mmx%d", reg_idx
);
206 reg_idx
-= NumMMXRegs
;
207 if (reg_idx
< NumXMMRegs
* 2) {
208 ccprintf(os
, "%%xmm%d_%s", reg_idx
/ 2,
209 (reg_idx
% 2) ? "high": "low");
212 reg_idx
-= NumXMMRegs
* 2;
213 if (reg_idx
< NumMicroFpRegs
) {
214 ccprintf(os
, "%%ufp%d", reg_idx
);
217 reg_idx
-= NumMicroFpRegs
;
218 ccprintf(os
, "%%st(%d)", reg_idx
);
220 } else if (reg
.isCCReg()) {
221 ccprintf(os
, "%%cc%d", reg_idx
);
223 } else if (reg
.isMiscReg()) {
226 ccprintf(os
, "%%ctrl%d", reg_idx
);
231 void X86StaticInst::printMem(std::ostream
&os
, uint8_t segment
,
232 uint8_t scale
, RegIndex index
, RegIndex base
,
233 uint64_t disp
, uint8_t addressSize
, bool rip
) const
235 bool someAddr
= false;
236 printSegment(os
, segment
);
242 if (scale
!= 0 && index
!= ZeroReg
)
245 ccprintf(os
, "%d*", scale
);
246 printReg(os
, InstRegIndex(index
), addressSize
);
253 printReg(os
, InstRegIndex(base
), addressSize
);
261 ccprintf(os
, "%#x", disp
);
269 std::string
X86StaticInst::generateDisassembly(Addr pc
,
270 const SymbolTable
*symtab
) const
272 std::stringstream ss
;
274 printMnemonic(ss
, mnemonic
);