2 * Copyright (c) 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.
31 #include "arch/alpha/isa_traits.hh"
32 #include "arch/alpha/stacktrace.hh"
33 #include "arch/alpha/vtophys.hh"
34 #include "base/bitfield.hh"
35 #include "base/trace.hh"
36 #include "cpu/base.hh"
37 #include "cpu/exec_context.hh"
40 using namespace AlphaISA
;
42 ProcessInfo::ProcessInfo(ExecContext
*_xc
)
47 if (!xc
->system
->kernelSymtab
->findAddress("thread_info_size", addr
))
48 panic("thread info not compiled into kernel\n");
49 thread_info_size
= *(int32_t *)vtomem(xc
, addr
, sizeof(int32_t));
51 if (!xc
->system
->kernelSymtab
->findAddress("task_struct_size", addr
))
52 panic("thread info not compiled into kernel\n");
53 task_struct_size
= *(int32_t *)vtomem(xc
, addr
, sizeof(int32_t));
55 if (!xc
->system
->kernelSymtab
->findAddress("thread_info_task", addr
))
56 panic("thread info not compiled into kernel\n");
57 task_off
= *(int32_t *)vtomem(xc
, addr
, sizeof(int32_t));
59 if (!xc
->system
->kernelSymtab
->findAddress("task_struct_pid", addr
))
60 panic("thread info not compiled into kernel\n");
61 pid_off
= *(int32_t *)vtomem(xc
, addr
, sizeof(int32_t));
63 if (!xc
->system
->kernelSymtab
->findAddress("task_struct_comm", addr
))
64 panic("thread info not compiled into kernel\n");
65 name_off
= *(int32_t *)vtomem(xc
, addr
, sizeof(int32_t));
69 ProcessInfo::task(Addr ksp
) const
71 Addr base
= ksp
& ~0x3fff;
72 if (base
== ULL(0xfffffc0000000000))
76 CopyOut(xc
, &task
, base
+ task_off
, sizeof(task
));
81 ProcessInfo::pid(Addr ksp
) const
83 Addr task
= this->task(ksp
);
88 CopyOut(xc
, &pid
, task
+ pid_off
, sizeof(pid
));
93 ProcessInfo::name(Addr ksp
) const
95 Addr task
= this->task(ksp
);
100 CopyString(xc
, comm
, task
+ name_off
, sizeof(comm
));
107 StackTrace::StackTrace()
112 StackTrace::StackTrace(ExecContext
*_xc
, StaticInstPtr inst
)
118 StackTrace::~StackTrace()
123 StackTrace::trace(ExecContext
*_xc
, bool is_call
)
127 bool usermode
= (xc
->regs
.ipr
[AlphaISA::IPR_DTB_CM
] & 0x18) != 0;
129 Addr pc
= xc
->regs
.npc
;
130 bool kernel
= xc
->system
->kernelStart
<= pc
&& pc
<= xc
->system
->kernelEnd
;
133 stack
.push_back(user
);
138 stack
.push_back(console
);
142 SymbolTable
*symtab
= xc
->system
->kernelSymtab
;
143 Addr ksp
= xc
->regs
.intRegFile
[TheISA::StackPointerReg
];
144 Addr bottom
= ksp
& ~0x3fff;
148 if (!symtab
->findNearestAddr(pc
, addr
))
149 panic("could not find address %#x", pc
);
151 stack
.push_back(addr
);
158 while (ksp
> bottom
) {
159 if (!symtab
->findNearestAddr(pc
, addr
))
160 panic("could not find symbol for pc=%#x", pc
);
161 assert(pc
>= addr
&& "symbol botch: callpc < func");
163 stack
.push_back(addr
);
168 if (decodePrologue(ksp
, pc
, addr
, size
, ra
)) {
173 stack
.push_back(unknown
);
180 stack
.push_back(unknown
);
184 bool kernel
= xc
->system
->kernelStart
<= pc
&&
185 pc
<= xc
->system
->kernelEnd
;
189 if (stack
.size() >= 1000)
190 panic("unwinding too far");
193 panic("unwinding too far");
197 StackTrace::isEntry(Addr addr
)
199 if (addr
== xc
->regs
.ipr
[AlphaISA::IPR_PALtemp12
])
202 if (addr
== xc
->regs
.ipr
[AlphaISA::IPR_PALtemp7
])
205 if (addr
== xc
->regs
.ipr
[AlphaISA::IPR_PALtemp11
])
208 if (addr
== xc
->regs
.ipr
[AlphaISA::IPR_PALtemp21
])
211 if (addr
== xc
->regs
.ipr
[AlphaISA::IPR_PALtemp9
])
214 if (addr
== xc
->regs
.ipr
[AlphaISA::IPR_PALtemp2
])
221 StackTrace::decodeStack(MachInst inst
, int &disp
)
223 // lda $sp, -disp($sp)
225 // Opcode<31:26> == 0x08
229 const MachInst mem_mask
= 0xffff0000;
230 const MachInst lda_pattern
= 0x23de0000;
231 const MachInst lda_disp_mask
= 0x0000ffff;
233 // subq $sp, disp, $sp
234 // addq $sp, disp, $sp
236 // Opcode<31:26> == 0x10
240 // Func<11:5> == 0x20 (addq)
241 // Func<11:5> == 0x29 (subq)
243 const MachInst intop_mask
= 0xffe01fff;
244 const MachInst addq_pattern
= 0x43c0141e;
245 const MachInst subq_pattern
= 0x43c0153e;
246 const MachInst intop_disp_mask
= 0x001fe000;
247 const int intop_disp_shift
= 13;
249 if ((inst
& mem_mask
) == lda_pattern
)
250 disp
= -sext
<16>(inst
& lda_disp_mask
);
251 else if ((inst
& intop_mask
) == addq_pattern
)
252 disp
= -int((inst
& intop_disp_mask
) >> intop_disp_shift
);
253 else if ((inst
& intop_mask
) == subq_pattern
)
254 disp
= int((inst
& intop_disp_mask
) >> intop_disp_shift
);
262 StackTrace::decodeSave(MachInst inst
, int ®
, int &disp
)
264 // lda $stq, disp($sp)
266 // Opcode<31:26> == 0x08
270 const MachInst stq_mask
= 0xfc1f0000;
271 const MachInst stq_pattern
= 0xb41e0000;
272 const MachInst stq_disp_mask
= 0x0000ffff;
273 const MachInst reg_mask
= 0x03e00000;
274 const int reg_shift
= 21;
276 if ((inst
& stq_mask
) == stq_pattern
) {
277 reg
= (inst
& reg_mask
) >> reg_shift
;
278 disp
= sext
<16>(inst
& stq_disp_mask
);
287 * Decode the function prologue for the function we're in, and note
288 * which registers are stored where, and how large the stack frame is.
291 StackTrace::decodePrologue(Addr sp
, Addr callpc
, Addr func
,
297 for (Addr pc
= func
; pc
< callpc
; pc
+= sizeof(MachInst
)) {
299 CopyOut(xc
, (uint8_t *)&inst
, pc
, sizeof(MachInst
));
302 if (decodeStack(inst
, disp
)) {
304 // panic("decoding frame size again");
308 } else if (decodeSave(inst
, reg
, disp
)) {
309 if (!ra
&& reg
== ReturnAddressReg
) {
310 CopyOut(xc
, (uint8_t *)&ra
, sp
+ disp
, sizeof(Addr
));
312 // panic("no return address value pc=%#x\n", pc);
326 StringWrap
name(xc
->cpu
->name());
327 SymbolTable
*symtab
= xc
->system
->kernelSymtab
;
329 DPRINTFN("------ Stack ------\n");
332 for (int i
= 0, size
= stack
.size(); i
< size
; ++i
) {
333 Addr addr
= stack
[size
- i
- 1];
336 else if (addr
== console
)
338 else if (addr
== unknown
)
341 symtab
->findSymbol(addr
, symbol
);
343 DPRINTFN("%#x: %s\n", addr
, symbol
);