Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / fm / lib / sparc / ctrace.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: ctrace.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)ctrace.fth 2.5 04/04/15 19:10:01
43purpose:
44copyright: Copyright 1990-2004 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46\ Copyright 1985-1990 Bradley Forthware
47
48\ After a crash, displays a backtrace of C stack frames.
49\ This assumes the stack format used by the Sun SPARC C compiler.
50
51only forth also hidden also forth definitions
52
53headerless
54defer .subname ( adr -- )
55\ : .8x ( n -- ) push-hex 8 u.r pop-base ;
56' .x is .subname
57
58: >reg ( reg# -- addr )
59 dup 3 >> case
60 0 of addr %g0 endof
61 1 of addr %o0 endof
62 2 of addr %l0 endof
63 3 of addr %i0 endof
64 endcase ( reg# base )
65 swap h# 7 and la+
66;
67: >ea ( instruction -- address )
68 dup h# 1000 and if ( instruction ) \ Immediate
69 dup d# 20 << d# 12 >>a ( instruction immediate )
70 else
71 dup h# 1f and >reg l@ ( instruction regval )
72 then
73 swap d# 14 >> h# 1f and >reg l@ + ( target-address )
74;
75: decode-jmpl ( instruction -- false | target true )
76 dup h# 81f80000 and h# 81c00000 = if >ea true else drop false then
77;
78: .subroutine ( return-adr -- ) \ Show subroutine address
79 dup pointer-bad? over 0= or if drop ." XXXXXXX " exit then
80 dup l@ th c000.0000 and th 4000.0000 = if \ call instruction ?
81 ." call " dup l@ th 3fff.ffff and 2 << + .subname
82 else
83 \ XXX decode the address specification from the jmpl
84 \ if that address spec references OUT's or GLOBAL's, we can't
85 \ be sure that it is correct. The next window context contains
86 \ the relevant registers.
87 l@ decode-jmpl if
88 ." jmpl " .subname \ indirect call (jmpl)
89 else
90 ." ???? "
91 then
92 then
93;
94: .2x ( n -- ) push-hex 2 u.r pop-base ;
95: .c-call ( -- exit? )
96 %o7 .subroutine ." from " %o7 .subname cr
97 ." " window# .2x ." w %o0-%o5: (" addr %o0 6 .ndump ." )" cr
98 cr exit?
99;
100
101headers
102: ctrace ( -- ) \ C stack backtrace
103 state-valid @ 0= if ." No saved state" exit then
104 ." PC: " %pc .subname cr
105 ." Last leaf: "
106
107 window# ( previous-window# )
108 0w begin .c-call (+w) or until ( previous-window# )
109 set-window
110;