709e0a610cb9dcebdb2d8491afa717cbd13405c0
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"
42 #include "arch/x86/regs/segment.hh"
43 #include "cpu/reg_class.hh"
47 void X86StaticInst::printMnemonic(std::ostream
&os
,
48 const char * mnemonic
) const
50 ccprintf(os
, " %s ", mnemonic
);
53 void X86StaticInst::printMnemonic(std::ostream
&os
,
54 const char * instMnemonic
, const char * mnemonic
) const
56 ccprintf(os
, " %s : %s ", instMnemonic
, mnemonic
);
59 void X86StaticInst::printSegment(std::ostream
&os
, int segment
) const
96 case SYS_SEGMENT_REG_TR
:
99 case SYS_SEGMENT_REG_IDTR
:
100 ccprintf(os
, "IDTR");
103 panic("Unrecognized segment %d\n", segment
);
108 X86StaticInst::printSrcReg(std::ostream
&os
, int reg
, int size
) const
110 if (_numSrcRegs
> reg
)
111 printReg(os
, _srcRegIdx
[reg
], size
);
115 X86StaticInst::printDestReg(std::ostream
&os
, int reg
, int size
) const
117 if (_numDestRegs
> reg
)
118 printReg(os
, _destRegIdx
[reg
], size
);
122 X86StaticInst::printReg(std::ostream
&os
, int reg
, int size
) const
124 assert(size
== 1 || size
== 2 || size
== 4 || size
== 8);
125 static const char * abcdFormats
[9] =
126 {"", "%s", "%sx", "", "e%sx", "", "", "", "r%sx"};
127 static const char * piFormats
[9] =
128 {"", "%s", "%s", "", "e%s", "", "", "", "r%s"};
129 static const char * longFormats
[9] =
130 {"", "r%sb", "r%sw", "", "r%sd", "", "", "", "r%s"};
131 static const char * microFormats
[9] =
132 {"", "t%db", "t%dw", "", "t%dd", "", "", "", "t%d"};
136 switch (regIdxToClass(reg
, &rel_reg
)) {
138 const char * suffix
= "";
139 bool fold
= rel_reg
& IntFoldBit
;
140 rel_reg
&= ~IntFoldBit
;
144 else if (rel_reg
< 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
], rel_reg
- NUM_INTREGS
);
199 ccprintf(os
, suffix
);
203 case FloatRegClass
: {
204 if (rel_reg
< NumMMXRegs
) {
205 ccprintf(os
, "%%mmx%d", rel_reg
);
208 rel_reg
-= NumMMXRegs
;
209 if (rel_reg
< NumXMMRegs
* 2) {
210 ccprintf(os
, "%%xmm%d_%s", rel_reg
/ 2,
211 (rel_reg
% 2) ? "high": "low");
214 rel_reg
-= NumXMMRegs
* 2;
215 if (rel_reg
< NumMicroFpRegs
) {
216 ccprintf(os
, "%%ufp%d", rel_reg
);
219 rel_reg
-= NumMicroFpRegs
;
220 ccprintf(os
, "%%st(%d)", rel_reg
);
225 ccprintf(os
, "%%cc%d", rel_reg
);
231 ccprintf(os
, "%%ctrl%d", rel_reg
);
237 void X86StaticInst::printMem(std::ostream
&os
, uint8_t segment
,
238 uint8_t scale
, RegIndex index
, RegIndex base
,
239 uint64_t disp
, uint8_t addressSize
, bool rip
) const
241 bool someAddr
= false;
242 printSegment(os
, segment
);
248 if (scale
!= 0 && index
!= ZeroReg
)
251 ccprintf(os
, "%d*", scale
);
252 printReg(os
, index
, addressSize
);
259 printReg(os
, base
, addressSize
);
267 ccprintf(os
, "%#x", disp
);
275 std::string
X86StaticInst::generateDisassembly(Addr pc
,
276 const SymbolTable
*symtab
) const
278 std::stringstream ss
;
280 printMnemonic(ss
, mnemonic
);