2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Nathan Binkert
33 #include "arch/mips/isa_traits.hh"
34 #include "arch/mips/stacktrace.hh"
35 #include "arch/mips/vtophys.hh"
36 #include "base/bitfield.hh"
37 #include "base/trace.hh"
38 #include "cpu/base.hh"
39 #include "cpu/thread_context.hh"
40 #include "mem/fs_translating_port_proxy.hh"
41 #include "sim/system.hh"
44 using namespace MipsISA
;
46 ProcessInfo::ProcessInfo(ThreadContext
*_tc
) : tc(_tc
)
50 ProcessInfo::task(Addr ksp
) const
52 Addr base
= ksp
& ~0x3fff;
53 if (base
== ULL(0xfffffc0000000000))
58 FSTranslatingPortProxy
&vp
= tc
->getVirtProxy();
59 tsk
= vp
.readGtoH
<Addr
>(base
+ task_off
);
65 ProcessInfo::pid(Addr ksp
) const
67 Addr task
= this->task(ksp
);
73 FSTranslatingPortProxy
&vp
= tc
->getVirtProxy();
74 pd
= vp
.readGtoH
<uint16_t>(task
+ pid_off
);
80 ProcessInfo::name(Addr ksp
) const
82 Addr task
= this->task(ksp
);
87 CopyStringOut(tc
, comm
, task
+ name_off
, sizeof(comm
));
94 StackTrace::StackTrace()
99 StackTrace::StackTrace(ThreadContext
*_tc
, StaticInstPtr inst
)
105 StackTrace::~StackTrace()
110 StackTrace::trace(ThreadContext
*_tc
, bool is_call
)
116 stack
.push_back(user
);
122 StackTrace::isEntry(Addr addr
)
128 StackTrace::decodeStack(MachInst inst
, int &disp
)
130 // lda $sp, -disp($sp)
132 // Opcode<31:26> == 0x08
136 const MachInst mem_mask
= 0xffff0000;
137 const MachInst lda_pattern
= 0x23de0000;
138 const MachInst lda_disp_mask
= 0x0000ffff;
140 // subq $sp, disp, $sp
141 // addq $sp, disp, $sp
143 // Opcode<31:26> == 0x10
147 // Func<11:5> == 0x20 (addq)
148 // Func<11:5> == 0x29 (subq)
150 const MachInst intop_mask
= 0xffe01fff;
151 const MachInst addq_pattern
= 0x43c0141e;
152 const MachInst subq_pattern
= 0x43c0153e;
153 const MachInst intop_disp_mask
= 0x001fe000;
154 const int intop_disp_shift
= 13;
156 if ((inst
& mem_mask
) == lda_pattern
)
157 disp
= -sext
<16>(inst
& lda_disp_mask
);
158 else if ((inst
& intop_mask
) == addq_pattern
)
159 disp
= -int((inst
& intop_disp_mask
) >> intop_disp_shift
);
160 else if ((inst
& intop_mask
) == subq_pattern
)
161 disp
= int((inst
& intop_disp_mask
) >> intop_disp_shift
);
169 StackTrace::decodeSave(MachInst inst
, int ®
, int &disp
)
171 // lda $stq, disp($sp)
173 // Opcode<31:26> == 0x08
177 const MachInst stq_mask
= 0xfc1f0000;
178 const MachInst stq_pattern
= 0xb41e0000;
179 const MachInst stq_disp_mask
= 0x0000ffff;
180 const MachInst reg_mask
= 0x03e00000;
181 const int reg_shift
= 21;
183 if ((inst
& stq_mask
) == stq_pattern
) {
184 reg
= (inst
& reg_mask
) >> reg_shift
;
185 disp
= sext
<16>(inst
& stq_disp_mask
);
194 * Decode the function prologue for the function we're in, and note
195 * which registers are stored where, and how large the stack frame is.
198 StackTrace::decodePrologue(Addr sp
, Addr callpc
, Addr func
,
204 for (Addr pc
= func
; pc
< callpc
; pc
+= sizeof(MachInst
)) {
206 CopyOut(tc
, (uint8_t *)&inst
, pc
, sizeof(MachInst
));
209 if (decodeStack(inst
, disp
)) {
214 } else if (decodeSave(inst
, reg
, disp
)) {
215 if (!ra
&& reg
== ReturnAddressReg
) {
216 CopyOut(tc
, (uint8_t *)&ra
, sp
+ disp
, sizeof(Addr
));
231 panic("Stack trace dump not implemented.\n");