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