decoder.cc revision 9377:6f294e7a93d1
1/* 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 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 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 "debug/Decoder.hh" 36 37namespace ArmISA 38{ 39 40GenericISA::BasicDecodeCache Decoder::defaultCache; 41 42void 43Decoder::process() 44{ 45 // emi is typically ready, with some caveats below... 46 instDone = true; 47 48 if (!emi.thumb) { 49 emi.instBits = data; 50 emi.sevenAndFour = bits(data, 7) && bits(data, 4); 51 emi.isMisc = (bits(data, 24, 23) == 0x2 && 52 bits(data, 20) == 0); 53 consumeBytes(4); 54 DPRINTF(Decoder, "Arm inst: %#x.\n", (uint64_t)emi); 55 } else { 56 uint16_t word = (data >> (offset * 8)); 57 if (bigThumb) { 58 // A 32 bit thumb inst is half collected. 59 emi.instBits = emi.instBits | word; 60 bigThumb = false; 61 consumeBytes(2); 62 DPRINTF(Decoder, "Second half of 32 bit Thumb: %#x.\n", 63 emi.instBits); 64 } else { 65 uint16_t highBits = word & 0xF800; 66 if (highBits == 0xE800 || highBits == 0xF000 || 67 highBits == 0xF800) { 68 // The start of a 32 bit thumb inst. 69 emi.bigThumb = 1; 70 if (offset == 0) { 71 // We've got the whole thing. 72 emi.instBits = (data >> 16) | (data << 16); 73 DPRINTF(Decoder, "All of 32 bit Thumb: %#x.\n", 74 emi.instBits); 75 consumeBytes(4); 76 } else { 77 // We only have the first half word. 78 DPRINTF(Decoder, 79 "First half of 32 bit Thumb.\n"); 80 emi.instBits = (uint32_t)word << 16; 81 bigThumb = true; 82 consumeBytes(2); 83 // emi not ready yet. 84 instDone = false; 85 } 86 } else { 87 // A 16 bit thumb inst. 88 consumeBytes(2); 89 emi.instBits = word; 90 // Set the condition code field artificially. 91 emi.condCode = COND_UC; 92 DPRINTF(Decoder, "16 bit Thumb: %#x.\n", 93 emi.instBits); 94 if (bits(word, 15, 8) == 0xbf && 95 bits(word, 3, 0) != 0x0) { 96 foundIt = true; 97 itBits = bits(word, 7, 0); 98 DPRINTF(Decoder, 99 "IT detected, cond = %#x, mask = %#x\n", 100 itBits.cond, itBits.mask); 101 } 102 } 103 } 104 } 105} 106 107//Use this to give data to the decoder. This should be used 108//when there is control flow. 109void 110Decoder::moreBytes(const PCState &pc, Addr fetchPC, MachInst inst) 111{ 112 data = inst; 113 offset = (fetchPC >= pc.instAddr()) ? 0 : pc.instAddr() - fetchPC; 114 emi.thumb = pc.thumb(); 115 emi.fpscrLen = fpscrLen; 116 emi.fpscrStride = fpscrStride; 117 118 outOfBytes = false; 119 process(); 120} 121 122} 123