Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / fm / lib / sparc / cpubpsup.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: cpubpsup.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 ============================================
42\ cpubpsup.fth 2.10 97/07/17
43\ Copyright 1985-1990 Bradley Forthware
44\ SPARC-specific breakpoint support routines.
45
46\ Processor-dependent definitions for breakpoints on the SPARC
47
48headerless
490 value breakpoint-opcode
50defer breakpoint-trap?
51
52headers
53defer op!
54defer op@
55
56: .instruction ( -- ) %pc [ disassembler ] pc! dis1 ;
57
58headerless
59: bp-address-valid? ( adr -- flag ) 3 and 0= ;
60: at-breakpoint? ( adr -- flag ) op@ breakpoint-opcode = ;
61: put-breakpoint ( adr -- ) breakpoint-opcode swap op! ;
62
63\ Find the places to set the next breakpoint for single stepping.
64\ Usually the right place is at nPC . However, for annulled branch
65\ instructions, we have to cope with the possibility that the delay
66\ instruction, which is where nPC points, won't be executed. Annulled
67\ unconditional branches never execute the delay instruction, so we have
68\ to put the breakpoint at the branch target. Annulled conditional
69\ branches will either execute the delay instruction or the one right
70\ after it.
71
72: disp16 ( opcode -- disp16 )
73 dup h# 3fff and swap 3 d# 20 lshift and 6 rshift or
74 dup h# 8000 and if h# ffff.0000 or then
75;
76: disp19 ( opcode -- disp19 )
77 h# 07.ffff and
78 dup h# 04.0000 and if h# fff8.0000 or then
79;
80: disp22 ( opcode -- disp22 )
81 h# 003f.ffff and
82 dup h# 20.0000 and if h# ffc0.0000 or then
83;
84
85: next-instruction ( stepping? -- next-adr branch-target|0 )
86 0= if %pc la1+ 0 exit then \ May not work for annulled branches
87 %pc op@ ( opcode )
88 \ not format 2 (op=0)
89 dup h# c000.0000 and ( opcode flag1 )
90 \ sethi
91 over h# 01c0.0000 and h# 0100.0000 = or ( opcode flag2 )
92 \ non an annulled branch
93 over h# 2000.0000 and 0= or if ( opcode )
94 drop %npc 0 exit
95 then ( opcode )
96
97 dup h# 1e00.0000 and h# 1000.0000 <> if ( opcode )
98 \ It's a conditional branch
99 drop %npc %npc 4 + exit
100 then ( opcode )
101
102 \ Unconditional branch. Need branch offset ( opcode )
103 dup h# 01c0.0000 and d# 22 rshift case ( opcode op2 )
104 b# 011 of disp16 endof
105 b# 101 of disp19 endof
106 b# 001 of disp19 endof
107 \ default
108 ( opcode op2 )
109 swap disp22 swap ( disp22 op2 )
110 endcase ( dispXX )
111 2 lshift l->n %pc + 0 ( branch-target 0 )
112;
113headers
114: bumppc ( -- ) %pc la1+ to %pc %pc la1+ to %npc ;
115alias rpc %pc
116
117code goto ( adr -- )
118 tos scr move
119 sp tos get
120 scr %g0 %g0 jmpl
121 sp /n sp add
122end-code
123
124headerless
125: return-adr ( -- adr ) 0 w %i7 8 + ;
126: leaf-return-adr ( -- adr ) 0 w %o7 8 + ;
127: backward-branch? ( adr -- flag ) \ True if adr points to a backward branch
128 l@ ( instruction )
129 dup h# c000.0000 and 0= ( instruction flag ) \ Must be format 0
130 over h# 01c0.0000 and case \ Must be a branch
131 h# 0080.0000 of true endof \ bcc
132 h# 0180.0000 of true endof \ bfcc
133 h# 01c0.0000 of true endof \ bccc
134 ( else ) false swap
135 endcase and ( instruction flag )
136 swap h# 0020.0000 and 0<> and ( flag ) \ Offset must be < 0
137;
138: loop-exit-adr ( -- adr )
139 \ Start at PC-4 in case we're sitting on a delay instruction at the loop end
140 %pc 4 - begin dup backward-branch? 0= while 4 + repeat 8 +
141;
142
143headers
144: set-pc ( adr -- ) dup to %pc 4 + to %npc ;