arm: Add support for filtering in the PMU
[gem5.git] / src / arch / arm / decoder.cc
1 /*
2 * Copyright (c) 2012-2013 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2012 Google
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Gabe Black
41 */
42
43 #include "arch/arm/decoder.hh"
44 #include "arch/arm/isa_traits.hh"
45 #include "arch/arm/utility.hh"
46 #include "base/trace.hh"
47 #include "debug/Decoder.hh"
48
49 namespace ArmISA
50 {
51
52 GenericISA::BasicDecodeCache Decoder::defaultCache;
53
54 void
55 Decoder::process()
56 {
57 // emi is typically ready, with some caveats below...
58 instDone = true;
59
60 if (!emi.thumb) {
61 emi.instBits = data;
62 if (!emi.aarch64) {
63 emi.sevenAndFour = bits(data, 7) && bits(data, 4);
64 emi.isMisc = (bits(data, 24, 23) == 0x2 &&
65 bits(data, 20) == 0);
66 }
67 consumeBytes(4);
68 DPRINTF(Decoder, "Arm inst: %#x.\n", (uint64_t)emi);
69 } else {
70 uint16_t word = (data >> (offset * 8));
71 if (bigThumb) {
72 // A 32 bit thumb inst is half collected.
73 emi.instBits = emi.instBits | word;
74 bigThumb = false;
75 consumeBytes(2);
76 DPRINTF(Decoder, "Second half of 32 bit Thumb: %#x.\n",
77 emi.instBits);
78 } else {
79 uint16_t highBits = word & 0xF800;
80 if (highBits == 0xE800 || highBits == 0xF000 ||
81 highBits == 0xF800) {
82 // The start of a 32 bit thumb inst.
83 emi.bigThumb = 1;
84 if (offset == 0) {
85 // We've got the whole thing.
86 emi.instBits = (data >> 16) | (data << 16);
87 DPRINTF(Decoder, "All of 32 bit Thumb: %#x.\n",
88 emi.instBits);
89 consumeBytes(4);
90 } else {
91 // We only have the first half word.
92 DPRINTF(Decoder,
93 "First half of 32 bit Thumb.\n");
94 emi.instBits = (uint32_t)word << 16;
95 bigThumb = true;
96 consumeBytes(2);
97 // emi not ready yet.
98 instDone = false;
99 }
100 } else {
101 // A 16 bit thumb inst.
102 consumeBytes(2);
103 emi.instBits = word;
104 // Set the condition code field artificially.
105 emi.condCode = COND_UC;
106 DPRINTF(Decoder, "16 bit Thumb: %#x.\n",
107 emi.instBits);
108 if (bits(word, 15, 8) == 0xbf &&
109 bits(word, 3, 0) != 0x0) {
110 foundIt = true;
111 itBits = bits(word, 7, 0);
112 DPRINTF(Decoder,
113 "IT detected, cond = %#x, mask = %#x\n",
114 itBits.cond, itBits.mask);
115 }
116 }
117 }
118 }
119 }
120
121 //Use this to give data to the decoder. This should be used
122 //when there is control flow.
123 void
124 Decoder::moreBytes(const PCState &pc, Addr fetchPC, MachInst inst)
125 {
126 data = inst;
127 offset = (fetchPC >= pc.instAddr()) ? 0 : pc.instAddr() - fetchPC;
128 emi.thumb = pc.thumb();
129 emi.aarch64 = pc.aarch64();
130 emi.fpscrLen = fpscrLen;
131 emi.fpscrStride = fpscrStride;
132
133 outOfBytes = false;
134 process();
135 }
136
137 }