Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: tso_n1_mutex3_cas.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 | ||
45 | #define TIMEOUT 0x1000 | |
46 | #define ITERATIONS 0x2 | |
47 | ||
48 | ||
49 | #include "hboot.s" | |
50 | ||
51 | .global main | |
52 | ||
53 | main: | |
54 | ||
55 | setx spinlock_address, %l0, spinlock_addr_reg ! spinlock address | |
56 | set TIMEOUT, to_reg ! set timeout count | |
57 | set ITERATIONS, global_cnt_reg | |
58 | ||
59 | or spinlock_addr_reg, %g0, my_id_reg | |
60 | ||
61 | th_fork(th_main,%l0) | |
62 | ||
63 | th_main_0: | |
64 | add my_id_reg, 0x20, my_id_reg ! my ID address | |
65 | stb %g0, [my_id_reg] ! clear it | |
66 | ba getlock | |
67 | nop | |
68 | ||
69 | th_main_1: | |
70 | add my_id_reg, 0x24, my_id_reg | |
71 | stb %g0, [my_id_reg] | |
72 | ba getlock | |
73 | nop | |
74 | ||
75 | ||
76 | th_main_2: | |
77 | add my_id_reg, 0x28, my_id_reg | |
78 | stb %g0, [my_id_reg] | |
79 | ba getlock | |
80 | nop | |
81 | ||
82 | th_main_3: | |
83 | add my_id_reg, 0x2c, my_id_reg | |
84 | stb %g0, [my_id_reg] | |
85 | ba getlock | |
86 | nop | |
87 | ||
88 | th_main_4: | |
89 | add my_id_reg, 0x30, my_id_reg | |
90 | stb %g0, [my_id_reg] | |
91 | ba getlock | |
92 | nop | |
93 | ||
94 | th_main_5: | |
95 | add my_id_reg, 0x34, my_id_reg | |
96 | stb %g0, [my_id_reg] | |
97 | ba getlock | |
98 | nop | |
99 | ||
100 | th_main_6: | |
101 | add my_id_reg, 0x38, my_id_reg | |
102 | stb %g0, [my_id_reg] | |
103 | ba getlock | |
104 | nop | |
105 | ||
106 | th_main_7: | |
107 | add my_id_reg, 0x3c, my_id_reg | |
108 | stb %g0, [my_id_reg] | |
109 | ba getlock | |
110 | nop | |
111 | ||
112 | getlock: | |
113 | deccc to_reg ! dec timeout count | |
114 | be bad_end ! branch if no timeout | |
115 | nop | |
116 | or %g0, my_id_reg, test_reg ! | |
117 | cas [spinlock_addr_reg], %g0, test_reg ! try to acquire lock | |
118 | tst test_reg ! did we get it? | |
119 | bne getlock | |
120 | nop | |
121 | ||
122 | gotlock: ! do something | |
123 | set TIMEOUT, to_reg ! set to count again | |
124 | setx protected_area, %l0, data_base_reg | |
125 | ||
126 | set 100, %l0 | |
127 | loop1: | |
128 | st my_id_reg, [data_base_reg] ! store my ID in there | |
129 | add data_base_reg, 8, data_base_reg ! increment the address | |
130 | deccc %l0 | |
131 | bne loop1 ! repeat | |
132 | nop | |
133 | ||
134 | set 100, %l0 | |
135 | loop2: | |
136 | sub data_base_reg, 8, data_base_reg | |
137 | ld [data_base_reg], %l1 ! read the data area | |
138 | subcc %l1, my_id_reg, %l1 ! should be my ID | |
139 | bne bad_end | |
140 | nop | |
141 | deccc %l0 ! repeat | |
142 | bne loop2 | |
143 | nop | |
144 | ||
145 | clearlock: | |
146 | st %g0, [spinlock_addr_reg] ! unlock | |
147 | ||
148 | check_done: ! finish or iterate | |
149 | deccc global_cnt_reg | |
150 | be good_end | |
151 | nop | |
152 | ba getlock | |
153 | nop | |
154 | ||
155 | good_end: | |
156 | ta T_GOOD_TRAP | |
157 | bad_end: | |
158 | ta T_BAD_TRAP | |
159 | ||
160 | !========================== | |
161 | .data | |
162 | ||
163 | .align 0x40 | |
164 | user_data_start: | |
165 | spinlock_address: | |
166 | .word 0x0 | |
167 | .skip 0x1000 | |
168 | protected_area: | |
169 | .word 0xbeef | |
170 | .skip 0x1000 | |
171 | .word 0xbeef | |
172 | ||
173 | ! do some post-processing | |
174 | ||
175 |