1/*
2 * Copyright (c) 2006-2007 The Regents of The University of Michigan
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#ifndef TRACECHILD_SPARC_HH
32#define TRACECHILD_SPARC_HH
33
34#include <asm-sparc64/reg.h>
35#include <sys/ptrace.h>
36#include <sys/types.h>
37#include <stdint.h>
38
39#include <cassert>
40#include <ostream>
41#include <string>
42
43#include "base/tracechild.hh"
44
45struct regs;
46
47class SparcTraceChild : public TraceChild
48{
49  public:
50    enum RegNum
51    {
52        //Global registers
53        G0, G1, G2, G3, G4, G5, G6, G7,
54        //Output registers
55        O0, O1, O2, O3, O4, O5, O6, O7,
56        //Local registers
57        L0, L1, L2, L3, L4, L5, L6, L7,
58        //Input registers
59        I0, I1, I2, I3, I4, I5, I6, I7,
60        //Floating point
61        F0, F2, F4, F6, F8, F10, F12, F14,
62        F16, F18, F20, F22, F24, F26, F28, F30,
63        F32, F34, F36, F38, F40, F42, F44, F46,
64        F48, F50, F52, F54, F56, F58, F60, F62,
65        //Miscelaneous
66        FSR, FPRS, PC, NPC, Y, CWP, PSTATE, ASI, CCR,
67        numregs
68    };
69  private:
70    regs theregs;
71    regs oldregs;
72    fpu thefpregs;
73    fpu oldfpregs;
74    uint64_t locals[8];
75    uint64_t oldLocals[8];
76    uint64_t inputs[8];
77    uint64_t oldInputs[8];
78    bool regDiffSinceUpdate[numregs];
79
80    //This calculates where the pc might go after the current instruction.
81    //while this equals npc for most instructions, it doesn't for all of
82    //them. The return value is the number of actual potential targets.
83    int getTargets(uint32_t inst, uint64_t pc, uint64_t npc,
84            uint64_t &target1, uint64_t &target2);
85
86  protected:
87    bool update(int pid);
88
89  public:
90    SparcTraceChild();
91
92    bool sendState(int socket);
93
94    int64_t getRegVal(int num);
95
96    int64_t getOldRegVal(int num);
97
98    bool step();
99
100    uint64_t
101    getPC()
102    {
103        return getRegVal(PC);
104    }
105
106    uint64_t
107    getSP()
108    {
109        return getRegVal(O6);
110    }
111
112    std::ostream & outputStartState(std::ostream & os);
113};
114
115#endif
116