Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / arch / sun4v / forthint.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: forthint.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: @(#)forthint.fth 1.3 07/06/22
43purpose:
44copyright: Copyright 2007 Sun Microsystems, Inc. All rights reserved.
45copyright: Use is subject to license terms.
46
47headerless
480 value tick-ival
49
50code interrupt-return ( abort? -- )
51 tos %l1 move
52 h# 4000 %g1 set
53 %g1 0 %r21 wrasr \ Clear SOFT INT. Reg
54 #Sync membar
55
56 h# 10001 %g4 set \ STICK | TICK
57 %r22 %g1 rdasr
58 %g1 %g4 %g0 andcc
59 0<> if
60 nop
61 h# 10001 %g4 set \ STICK | TICK
62 %g4 0 %r21 wrasr \ Clear
63 #Sync membar
64
65 \ Only re-arm alarms if we arent aborted.
66 %l1 %g0 cmp
67 0= if
68 'user# tick-ival %g4 set
69 %g4 up %g4 nget \ Get interval incr
70 %r24 %g7 rdasr \ get Stick
71 %g7 1 %g7 sllx
72 %g7 1 %g7 srlx
73 %g7 %g4 %g7 add
74 %g7 %g0 %r25 wrasr \ Set StickCompare
75 #Sync membar
76 then
77 then
78
79 %g0 h# 38 %l5 add
80 %l5 %g0 h# 20 %l5 ldxa \ CPU struct PA
81 0 >intr-state %l0 set
82 %l0 %l5 %g5 add \ CPU save area
83 %l1 %g0 cmp
84 restore-cpu-state 0= brif \ Not aborted resume
85 %g0 %g4 move
86
87 %g0 2 %g4 add \ restore and cont.
88 restore-cpu-state always brif
89 %g7 rdpc
90
91 %g0 2 wrgl \ ok goto savestate
92 0 >intr-state %g1 set
93 small-forth-save-state always brif
94 nop
95c;
96
97: interrupt-handler
98 my-self >r \ XXX Need this??
99 check-alarm
100 r> is my-self \ XXX Need this??
101 aborted? @ interrupt-return
102;
103
104label interrupt-preamble
105 %g0 h# 38 %g1 add
106 %g1 %g0 h# 20 %g1 ldxa \ CPU struct PA
107 0 >intr-state %g5 set
108 %g5 %g1 %g5 add \ DMMU stacks
109 %g0 %g6 move \ Small Save
110 save-cpu-state always brif
111 %g7 rdpc
112
113 \ We are now in a normal TL=0, IE=1, CWP=0 environment
114 \ Set up Forth Machine
115 0 >intr-state %l0 set
116 'body interrupt-handler %l7 set
117 setup-small-forth-engine always brif nop
118c;
119
120: set-next-tick ( -- )
121 system-tick-speed d# 100 / dup to tick-ival
122 stick@ -1 1 >> and + stick-compare!
123;
124' set-next-tick is rearm-alarms
125
126: install-nmi ( -- )
127 d# 15 pil!
128 lock[
129 set-next-tick
130 interrupt-preamble h# 4e vector!
131 ]unlock
132 d# 13 pil!
133;
134
135stand-init: Installing Simple Ticker
136 init-alarm-list
137 install-nmi
138;
139
140: memory-warning ( request-size -- adr actual-size false | error true )
141 ." Rejecting alloc-mem!"
142 drop 0 true
143;
144
145headers
146
147cif: SUNW,heartbeat ( msecs -- abort? )
148 check-alarm aborted? @ 0<>
149;
150
151headerless
152
153defer guest-state-boot-hook ( -- ) ' noop is guest-state-boot-hook
154
155: set-trap-table ( [mmu-area-ra] virt -- )
156 obp-control-relinquished? 0= if client-starting-chain then
157 lock[
158
159 swap set-cpu-miss-area
160
161 \ Save current %pstate and %pil
162 pstate@ >r pil@ >r
163
164 \ Stop the L14 Timer
165 1 d# 63 << stick-compare! ( virt )
166
167 \ Clear Soft Interrupts
168 -1 clear-softint! ( virt )
169
170 \ Set New %TBA
171 tba! ]unlock
172
173 \ we don't permit more dynamic allocation.
174 ['] memory-warning is more-memory
175
176 \ Client has now officially "taken over"
177 true to obp-control-relinquished?
178
179 guest-state-boot-hook
180
181 \ Restore previous %pil and %pstate
182 r> pil! r> pstate!
183;
184
185headers
186
187cif: SUNW,sun4v-set-trap-table ( [mmu-area-ra] virt -- ) set-trap-table ;
188cif: SUNW,set-trap-table ( [mmu-area-ra] virt -- ) set-trap-table ;