Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / diag / assembly / arch / prm / tso / tso_directed / tso_n1_mutex5_swap_casx.s
CommitLineData
86530b38
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: tso_n1_mutex5_swap_casx.s
5* Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
6* 4150 Network Circle, Santa Clara, California 95054, U.S.A.
7*
8* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9*
10* This program is free software; you can redistribute it and/or modify
11* it under the terms of the GNU General Public License as published by
12* the Free Software Foundation; version 2 of the License.
13*
14* This program is distributed in the hope that it will be useful,
15* but WITHOUT ANY WARRANTY; without even the implied warranty of
16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17* GNU General Public License for more details.
18*
19* You should have received a copy of the GNU General Public License
20* along with this program; if not, write to the Free Software
21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*
23* For the avoidance of doubt, and except that if any non-GPL license
24* choice is available it will apply instead, Sun elects to use only
25* the General Public License version 2 (GPLv2) at this time for any
26* software where a choice of GPL license versions is made
27* available with the language indicating that GPLv2 or any later version
28* may be used, or where a choice of which version of the GPL is applied is
29* otherwise unspecified.
30*
31* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
32* CA 95054 USA or visit www.sun.com if you need additional information or
33* have any questions.
34*
35*
36* ========== Copyright Header End ============================================
37*/
38#define spinlock_addr_reg %o0
39#define data_base_reg %o1
40#define to_reg %o2
41#define my_id_reg %o3
42#define test_reg %o4
43#define global_cnt_reg %o5
44#define tmp1 %i1
45#define tmp2 %i2
46
47#define TIMEOUT 0x1000
48#define ITERATIONS 0x2
49
50#include "hboot.s"
51
52.global main
53
54main:
55
56 wr %g0, 0x4, %fprs ! make sure fef is 1
57 setx spinlock_address, tmp1, spinlock_addr_reg ! spinlock address
58 set TIMEOUT, to_reg ! set timeout count
59 set ITERATIONS, global_cnt_reg ! set iterations
60
61 or spinlock_addr_reg, %g0, my_id_reg
62
63th_fork(th_main,tmp1)
64
65th_main_0:
66 add my_id_reg, 0x10, my_id_reg ! this is my ID address
67 stb my_id_reg, [my_id_reg] ! write my ID there
68 ba getlock
69 nop
70
71th_main_1:
72 add my_id_reg, 0x18, my_id_reg
73 stb my_id_reg, [my_id_reg]
74 ba getlock
75 nop
76
77
78th_main_2:
79 add my_id_reg, 0x20, my_id_reg
80 stb my_id_reg, [my_id_reg]
81 ba getlock
82 nop
83
84th_main_3:
85 add my_id_reg, 0x28, my_id_reg
86 stb my_id_reg, [my_id_reg]
87 ba getlock
88 nop
89
90th_main_4:
91 add my_id_reg, 0x30, my_id_reg
92 stb my_id_reg, [my_id_reg]
93 ba getlock
94 nop
95
96th_main_5:
97 add my_id_reg, 0x38, my_id_reg
98 stb my_id_reg, [my_id_reg]
99 ba getlock
100 nop
101
102th_main_6:
103 add my_id_reg, 0x40, my_id_reg
104 stb my_id_reg, [my_id_reg]
105 ba getlock
106 nop
107
108th_main_7:
109 add my_id_reg, 0x48, my_id_reg
110 stb my_id_reg, [my_id_reg]
111 ba getlock
112 nop
113
114 ba bad_end
115 nop
116
117
118getlock:
119 deccc to_reg ! dec timeout count
120 be bad_end ! branch if no timeout
121 nop
122 set 1, tmp1 ! some threads do
123 andcc tmp1, my_id_reg, tmp2 ! swap_lock
124 be swap_lock ! some do cas_lock
125 nop
126cas_lock:
127 or %g0, my_id_reg, test_reg ! use cas
128 cas [spinlock_addr_reg], %g0, test_reg ! try to acquire lock
129 tst test_reg ! did we get it?
130 bne getlock
131 nop
132swap_lock:
133 or %g0, my_id_reg, test_reg ! use swap
134 swap [spinlock_addr_reg], test_reg ! try to acquire lock
135 tst test_reg ! did we get it?
136 bne getlock
137 nop
138
139
140gotlock: ! do soemthing
141 set TIMEOUT, to_reg ! set to count again
142 setx protected_area, tmp1, data_base_reg
143
144 set 20, %l0
145loop1:
146 ldd [my_id_reg], %d16 ! read the ID
147 std %d16, [data_base_reg] ! store my ID in there
148 add data_base_reg, 8, data_base_reg ! increment the address
149 deccc %l0
150 bne loop1 ! repeat
151 nop
152
153 set 20, %l0
154loop2:
155 sub data_base_reg, 8, data_base_reg
156 ldd [my_id_reg], %f16 ! read the ID
157 ldd [data_base_reg], %f0 ! read the data area
158 fcmps %fcc0, %f0, %f16 ! should be my ID
159 fbne %fcc0, bad_end
160 nop
161 deccc %l0 ! repeat
162 bne loop2
163 nop
164
165clearlock:
166 st %g0, [spinlock_addr_reg] ! unlock
167
168check_done:
169 deccc global_cnt_reg
170 be good_end
171 nop
172 ba getlock
173 nop
174
175good_end:
176 ta T_GOOD_TRAP
177bad_end:
178 ta T_BAD_TRAP
179
180!==========================
181 .data
182
183user_data_start:
184
185spinlock_address:
186 .word 0x0
187 .skip 0x1000
188.align 0x100
189protected_area:
190 .word 0xbeef
191 .skip 0x1000
192 .word 0xbeef
193
194
195! some post-processing
196