tracechild.hh revision 4125
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2006-2007 The Regents of The University of Michigan 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are 712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1412855Sgabeblack@google.com * this software without specific prior written permission. 1512855Sgabeblack@google.com * 1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712855Sgabeblack@google.com * 2812855Sgabeblack@google.com * Authors: Gabe Black 2912855Sgabeblack@google.com */ 3012855Sgabeblack@google.com 3112855Sgabeblack@google.com#ifndef TRACECHILD_SPARC_HH 3212855Sgabeblack@google.com#define TRACECHILD_SPARC_HH 3312855Sgabeblack@google.com 3412855Sgabeblack@google.com#include <asm-sparc64/reg.h> 3512855Sgabeblack@google.com#include <assert.h> 3612855Sgabeblack@google.com#include <ostream> 3712855Sgabeblack@google.com#include <stdint.h> 3812855Sgabeblack@google.com#include <string> 3912855Sgabeblack@google.com#include <sys/ptrace.h> 4012855Sgabeblack@google.com#include <sys/types.h> 4112855Sgabeblack@google.com 4212855Sgabeblack@google.com#include "tracechild.hh" 4312855Sgabeblack@google.com 4412855Sgabeblack@google.comstruct regs; 4512855Sgabeblack@google.com 4612855Sgabeblack@google.comclass SparcTraceChild : public TraceChild 4712855Sgabeblack@google.com{ 4812855Sgabeblack@google.compublic: 4912855Sgabeblack@google.com enum RegNum 5012855Sgabeblack@google.com { 5112855Sgabeblack@google.com //Global registers 5212855Sgabeblack@google.com G0, G1, G2, G3, G4, G5, G6, G7, 5312855Sgabeblack@google.com //Output registers 5412855Sgabeblack@google.com O0, O1, O2, O3, O4, O5, O6, O7, 5512855Sgabeblack@google.com //Local registers 5612855Sgabeblack@google.com L0, L1, L2, L3, L4, L5, L6, L7, 5712855Sgabeblack@google.com //Input registers 5812855Sgabeblack@google.com I0, I1, I2, I3, I4, I5, I6, I7, 5912855Sgabeblack@google.com //Floating point 6012855Sgabeblack@google.com F0, F2, F4, F6, F8, F10, F12, F14, 6112855Sgabeblack@google.com F16, F18, F20, F22, F24, F26, F28, F30, 6212855Sgabeblack@google.com F32, F34, F36, F38, F40, F42, F44, F46, 6312855Sgabeblack@google.com F48, F50, F52, F54, F56, F58, F60, F62, 6412855Sgabeblack@google.com //Miscelaneous 6512855Sgabeblack@google.com FSR, FPRS, PC, NPC, Y, CWP, PSTATE, ASI, CCR, 6612855Sgabeblack@google.com numregs 6712855Sgabeblack@google.com }; 6812855Sgabeblack@google.comprivate: 6912855Sgabeblack@google.com char printBuffer[256]; 7012855Sgabeblack@google.com static std::string regNames[numregs]; 7112855Sgabeblack@google.com regs theregs; 7212855Sgabeblack@google.com regs oldregs; 7312855Sgabeblack@google.com fpu thefpregs; 7412855Sgabeblack@google.com fpu oldfpregs; 7512855Sgabeblack@google.com int64_t locals[8]; 7612855Sgabeblack@google.com int64_t oldLocals[8]; 7712855Sgabeblack@google.com int64_t inputs[8]; 7812855Sgabeblack@google.com int64_t oldInputs[8]; 7912855Sgabeblack@google.com bool regDiffSinceUpdate[numregs]; 8012855Sgabeblack@google.com 8112855Sgabeblack@google.com //This calculates where the pc might go after the current instruction. 8212855Sgabeblack@google.com //while this equals npc for most instructions, it doesn't for all of 8312855Sgabeblack@google.com //them. The return value is the number of actual potential targets. 8412855Sgabeblack@google.com int getTargets(uint32_t inst, uint64_t pc, uint64_t npc, 8512855Sgabeblack@google.com uint64_t &target1, uint64_t &target2); 8612855Sgabeblack@google.com 8712855Sgabeblack@google.comprotected: 8812855Sgabeblack@google.com bool update(int pid); 8912855Sgabeblack@google.com 9012855Sgabeblack@google.compublic: 9112855Sgabeblack@google.com SparcTraceChild(); 9212855Sgabeblack@google.com 9312855Sgabeblack@google.com int getNumRegs() 9412855Sgabeblack@google.com { 9512855Sgabeblack@google.com return numregs; 9612855Sgabeblack@google.com } 9712855Sgabeblack@google.com 9812855Sgabeblack@google.com bool diffSinceUpdate(int num) 9912855Sgabeblack@google.com { 10012855Sgabeblack@google.com assert(num < numregs && num >= 0); 10112855Sgabeblack@google.com return regDiffSinceUpdate[num]; 102 } 103 104 std::string getRegName(int num) 105 { 106 assert(num < numregs && num >= 0); 107 return regNames[num]; 108 } 109 110 int64_t getRegVal(int num); 111 112 int64_t getOldRegVal(int num); 113 114 bool step(); 115 116 uint64_t getPC() 117 { 118 return getRegVal(PC); 119 } 120 121 uint64_t getSP() 122 { 123 return getRegVal(O6); 124 } 125 126 char * printReg(int num); 127 128 std::ostream & outputStartState(std::ostream & os); 129}; 130 131#endif 132