decoder.cc (9022:bb25e7646c41) decoder.cc (9023:e9201a7bce59)
1/*
1/*
2 * Copyright (c) 2011 Google
2 * Copyright (c) 2012 Google
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the

--- 13 unchanged lines hidden (view full) ---

24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Gabe Black
29 */
30
31#include "arch/arm/decoder.hh"
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the

--- 13 unchanged lines hidden (view full) ---

24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Gabe Black
29 */
30
31#include "arch/arm/decoder.hh"
32#include "arch/arm/isa_traits.hh"
33#include "arch/arm/utility.hh"
34#include "base/trace.hh"
35#include "cpu/thread_context.hh"
36#include "debug/Decoder.hh"
32
33namespace ArmISA
34{
35
36DecodeCache Decoder::defaultCache;
37
37
38namespace ArmISA
39{
40
41DecodeCache Decoder::defaultCache;
42
43void
44Decoder::process()
45{
46 // emi is typically ready, with some caveats below...
47 instDone = true;
48
49 if (!emi.thumb) {
50 emi.instBits = data;
51 emi.sevenAndFour = bits(data, 7) && bits(data, 4);
52 emi.isMisc = (bits(data, 24, 23) == 0x2 &&
53 bits(data, 20) == 0);
54 consumeBytes(4);
55 DPRINTF(Decoder, "Arm inst: %#x.\n", (uint64_t)emi);
56 } else {
57 uint16_t word = (data >> (offset * 8));
58 if (bigThumb) {
59 // A 32 bit thumb inst is half collected.
60 emi.instBits = emi.instBits | word;
61 bigThumb = false;
62 consumeBytes(2);
63 DPRINTF(Decoder, "Second half of 32 bit Thumb: %#x.\n",
64 emi.instBits);
65 } else {
66 uint16_t highBits = word & 0xF800;
67 if (highBits == 0xE800 || highBits == 0xF000 ||
68 highBits == 0xF800) {
69 // The start of a 32 bit thumb inst.
70 emi.bigThumb = 1;
71 if (offset == 0) {
72 // We've got the whole thing.
73 emi.instBits = (data >> 16) | (data << 16);
74 DPRINTF(Decoder, "All of 32 bit Thumb: %#x.\n",
75 emi.instBits);
76 consumeBytes(4);
77 } else {
78 // We only have the first half word.
79 DPRINTF(Decoder,
80 "First half of 32 bit Thumb.\n");
81 emi.instBits = (uint32_t)word << 16;
82 bigThumb = true;
83 consumeBytes(2);
84 // emi not ready yet.
85 instDone = false;
86 }
87 } else {
88 // A 16 bit thumb inst.
89 consumeBytes(2);
90 emi.instBits = word;
91 // Set the condition code field artificially.
92 emi.condCode = COND_UC;
93 DPRINTF(Decoder, "16 bit Thumb: %#x.\n",
94 emi.instBits);
95 if (bits(word, 15, 8) == 0xbf &&
96 bits(word, 3, 0) != 0x0) {
97 foundIt = true;
98 itBits = bits(word, 7, 0);
99 DPRINTF(Decoder,
100 "IT detected, cond = %#x, mask = %#x\n",
101 itBits.cond, itBits.mask);
102 }
103 }
104 }
105 }
38}
106}
107
108//Use this to give data to the decoder. This should be used
109//when there is control flow.
110void
111Decoder::moreBytes(const PCState &pc, Addr fetchPC, MachInst inst)
112{
113 data = inst;
114 offset = (fetchPC >= pc.instAddr()) ? 0 : pc.instAddr() - fetchPC;
115 emi.thumb = pc.thumb();
116 FPSCR fpscr = tc->readMiscReg(MISCREG_FPSCR);
117 emi.fpscrLen = fpscr.len;
118 emi.fpscrStride = fpscr.stride;
119
120 outOfBytes = false;
121 process();
122}
123
124}