tracechild.hh revision 8108
110448Snilay@cs.wisc.edu/*
210448Snilay@cs.wisc.edu * Copyright (c) 2010 ARM Limited
310448Snilay@cs.wisc.edu * All rights reserved
410448Snilay@cs.wisc.edu *
510448Snilay@cs.wisc.edu * The license below extends only to copyright in the software and shall
610448Snilay@cs.wisc.edu * not be construed as granting a license to any other intellectual
710448Snilay@cs.wisc.edu * property including but not limited to intellectual property relating
810448Snilay@cs.wisc.edu * to a hardware implementation of the functionality of the software
910448Snilay@cs.wisc.edu * licensed hereunder.  You may use the software subject to the license
1010448Snilay@cs.wisc.edu * terms below provided that you ensure that this notice is replicated
1110448Snilay@cs.wisc.edu * unmodified and in its entirety in all distributions of the software,
1210448Snilay@cs.wisc.edu * modified or unmodified, in source code or in binary form.
1310448Snilay@cs.wisc.edu *
1410448Snilay@cs.wisc.edu * Copyright (c) 2009 The Regents of The University of Michigan
1510448Snilay@cs.wisc.edu * All rights reserved.
1610448Snilay@cs.wisc.edu *
1710448Snilay@cs.wisc.edu * Redistribution and use in source and binary forms, with or without
1810448Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions are
1910448Snilay@cs.wisc.edu * met: redistributions of source code must retain the above copyright
2010448Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer;
2110448Snilay@cs.wisc.edu * redistributions in binary form must reproduce the above copyright
2210447Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the
2310447Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution;
2410447Snilay@cs.wisc.edu * neither the name of the copyright holders nor the names of its
2510447Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from
2610447Snilay@cs.wisc.edu * this software without specific prior written permission.
2710447Snilay@cs.wisc.edu *
2810447Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2910447Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3010447Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3110447Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3210447Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3310447Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3410447Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3510447Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3610447Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3710447Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3810447Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3910447Snilay@cs.wisc.edu *
4010447Snilay@cs.wisc.edu * Authors: Ali Saidi
4110447Snilay@cs.wisc.edu *          Gabe Black
4210447Snilay@cs.wisc.edu */
4310447Snilay@cs.wisc.edu
4410447Snilay@cs.wisc.edu#ifndef TRACECHILD_ARM_HH
4510447Snilay@cs.wisc.edu#define TRACECHILD_ARM_HH
4610447Snilay@cs.wisc.edu
4710447Snilay@cs.wisc.edu#include <cassert>
4810447Snilay@cs.wisc.edu#include <string>
4910447Snilay@cs.wisc.edu#include <sys/user.h>
5010447Snilay@cs.wisc.edu#include <sys/ptrace.h>
5110447Snilay@cs.wisc.edu#include "tracechild.hh"
5210447Snilay@cs.wisc.edu
5310447Snilay@cs.wisc.edu
54class ARMTraceChild : public TraceChild
55{
56  public:
57    enum RegNum
58    {
59        // r0 - r3 argument, temp, caller save
60        // r4 - r10 callee save
61        // r11 - FP
62        // r12 - temp
63        // r13 - stack
64        // r14 - link
65        // r15 - pc
66        R0, R1, R2, R3, R4, R5, R6, R7,
67        R8, R9, R10, FP, R12, SP, LR, PC,
68        CPSR,
69        numregs
70    };
71  private:
72    char printBuffer[256];
73    static const char *regNames[numregs];
74    uint32_t getRegs(user_regs& myregs, int num);
75    user_regs regs;
76    user_regs oldregs;
77    bool regDiffSinceUpdate[numregs];
78    bool foundMvn;
79
80  protected:
81    bool update(int pid);
82
83  public:
84    ARMTraceChild();
85    bool sendState(int socket);
86
87    int
88    getNumRegs()
89    {
90        return numregs;
91    }
92
93    bool
94    diffSinceUpdate(int num)
95    {
96        assert(num < numregs && num >= 0);
97        return regDiffSinceUpdate[num];
98    }
99
100    std::string
101    getRegName(int num)
102    {
103        assert(num < numregs && num >= 0);
104        return regNames[num];
105    }
106
107    int64_t getRegVal(int num);
108    int64_t getOldRegVal(int num);
109
110    bool step();
111
112    uint64_t
113    getPC()
114    {
115        return getRegVal(PC);
116    }
117
118    uint64_t
119    getSP()
120    {
121        return getRegVal(SP);
122    }
123
124    char * printReg(int num);
125
126    std::ostream & outputStartState(std::ostream & os);
127
128};
129
130#endif
131
132