Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | : |
2 | :#define addrA_reg %l0 | |
3 | :#define turn_reg %l1 | |
4 | :#define alive_reg %l2 | |
5 | :#define data_base_reg %l3 | |
6 | :#define my_id_reg %l4 | |
7 | :#define global_cnt_reg %l5 | |
8 | :#define prot_area_reg %l6 | |
9 | : | |
10 | :#define test_reg1 %i0 | |
11 | :#define test_reg2 %i1 | |
12 | :#define test_reg3 %i2 | |
13 | : | |
14 | :#define TIMEOUT 0x1000 | |
15 | :#define ITERATIONS 0x10 | |
16 | : | |
17 | :#include "hboot.s" | |
18 | : | |
19 | :.global main | |
20 | :main: | |
21 | : | |
22 | :th_fork(th_main,test_reg1) | |
23 | : | |
24 | $proc_num = 8; | |
25 | if(scalar(@ARGV)){ | |
26 | $proc_num = $ARGV[0]; | |
27 | if($proc_num >8){ | |
28 | :#define ITERATIONS 0x2 | |
29 | } | |
30 | } | |
31 | ||
32 | for ( $c = 0; $c < $proc_num; $c++ ){ | |
33 | $offs = 4 * $c; # threads own offset | |
34 | ||
35 | :th_main_${c}: | |
36 | : setx addrA, test_reg1, addrA_reg ! | |
37 | : setx alive, test_reg1, alive_reg ! | |
38 | : setx turn, test_reg1, turn_reg ! | |
39 | : setx prot_area, test_reg1, prot_area_reg ! | |
40 | : set ITERATIONS, global_cnt_reg | |
41 | : set ${c}, my_id_reg ! my ID | |
42 | : | |
43 | :getlock${c}: | |
44 | : set 1, test_reg1 ! store 1 into lock | |
45 | : st test_reg1, [alive_reg + ${offs}] ! alive flag | |
46 | : st test_reg1, [addrA_reg + ${offs}] ! | |
47 | : membar 0x40 ! IMPORTANT in TSO! | |
48 | : | |
49 | : mov %g0, test_reg2 | |
50 | for ( $k = 0; $k < ${proc_num} * 4; $k = $k + 4) { | |
51 | : ld [addrA_reg + ${k}], test_reg1 ! accumulate flags | |
52 | : add test_reg1, test_reg2, test_reg2 ! in test_reg2 | |
53 | } | |
54 | : | |
55 | : subcc test_reg2, 0x1, %g0 ! if result = 1 -> | |
56 | : be gotlock${c} ! got lock | |
57 | : nop | |
58 | : | |
59 | : st %g0, [addrA_reg + ${offs}] ! else release. | |
60 | : ! note alive stays on. | |
61 | : | |
62 | :wait_turn${c}: ! while not my turn | |
63 | : ld [turn_reg], test_reg3 ! read the turn reg. | |
64 | : subcc my_id_reg, test_reg3, %g0 ! and check | |
65 | : bne wait_turn${c} | |
66 | : nop | |
67 | : ! try to get lock again | |
68 | : ba getlock${c} | |
69 | : nop | |
70 | : | |
71 | :gotlock${c}: ! do something | |
72 | : set 1, test_reg1 ! store 1 in lock area | |
73 | : st test_reg1, [addrA_reg + ${offs}] ! | |
74 | : | |
75 | : ld [prot_area_reg], test_reg1 | |
76 | : inc test_reg1 | |
77 | : st test_reg1, [prot_area_reg] | |
78 | : | |
79 | : ld [prot_area_reg + 0xc], test_reg1 | |
80 | : inc test_reg1 | |
81 | : st test_reg1, [prot_area_reg + 0xc] | |
82 | : | |
83 | : ld [prot_area_reg + 0x10], test_reg1 | |
84 | : inc test_reg1 | |
85 | : st test_reg1, [prot_area_reg + 0x10] | |
86 | : | |
87 | : ld [prot_area_reg + 0x1c], test_reg1 | |
88 | : inc test_reg1 | |
89 | : st test_reg1, [prot_area_reg + 0x1c] | |
90 | : | |
91 | : ld [prot_area_reg + 0x20], test_reg1 | |
92 | : inc test_reg1 | |
93 | : st test_reg1, [prot_area_reg + 0x20] | |
94 | : | |
95 | :clearlock${c}: ! needs some work | |
96 | for($next = ($c+1) % ${proc_num}; $next != $c; $next = ($next+1) % ${proc_num}){ | |
97 | $tempoffs = 4 * $next; | |
98 | : mov ${next}, test_reg2 ! find next alive | |
99 | : ld [alive_reg + ${tempoffs}], test_reg1 | |
100 | : brnz test_reg1, foundnext${c} | |
101 | : nop | |
102 | } | |
103 | :foundnext${c}: | |
104 | : st test_reg2, [turn_reg] ! give it the turn | |
105 | : | |
106 | :check_done${c}: | |
107 | : deccc global_cnt_reg | |
108 | : be will_release${c} ! done | |
109 | : nop | |
110 | : st %g0, [addrA_reg + ${offs}] ! release | |
111 | : ba getlock${c} ! and iterate | |
112 | : nop | |
113 | :will_release${c}: | |
114 | : st %g0, [alive_reg + ${offs}] ! clear alive flag | |
115 | : st %g0, [addrA_reg + ${offs}] ! release... | |
116 | : ba good_end | |
117 | : nop | |
118 | : | |
119 | } | |
120 | :!--------------------------------------------------------------------- | |
121 | : | |
122 | :good_end: | |
123 | : ta T_GOOD_TRAP | |
124 | :bad_end: | |
125 | : ta T_BAD_TRAP | |
126 | : | |
127 | :!========================== | |
128 | : | |
129 | : | |
130 | :SECTION .MY_DATA0 TEXT_VA=0xf0100000, DATA_VA=0xd0100000 | |
131 | :attr_data { | |
132 | : Name = .MY_DATA0, | |
133 | : VA= 0x0d0100000 | |
134 | : RA= 0x1d0100000 | |
135 | : PA= ra2pa(0x1d0100000,0), | |
136 | : part_0_ctx_nonzero_tsb_config_0, | |
137 | : TTE_G=1, TTE_Context=0x44, TTE_V=1, TTE_Size=0, TTE_NFO=0, | |
138 | : TTE_IE=0, TTE_Soft2=0, TTE_Diag=0, TTE_Soft=0, | |
139 | : TTE_L=0, TTE_CP=1, TTE_CV=1, TTE_E=0, TTE_P=0, TTE_W=1 | |
140 | : } | |
141 | : | |
142 | :attr_text { | |
143 | : Name = .MY_DATA0, | |
144 | : VA= 0x0f0100000 | |
145 | : RA= 0x1f0100000 | |
146 | : PA= ra2pa(0x1f0100000,0), | |
147 | : part_0_ctx_nonzero_tsb_config_0, | |
148 | : TTE_G=1, TTE_Context=0x44, TTE_V=1, TTE_Size=0, TTE_NFO=0, | |
149 | : TTE_IE=0, TTE_Soft2=0, TTE_Diag=0, TTE_Soft=0, | |
150 | : TTE_L=0, TTE_CP=1, TTE_CV=1, TTE_E=0, TTE_P=0, TTE_W=1 | |
151 | : } | |
152 | : | |
153 | : .data | |
154 | : | |
155 | :.global addrA | |
156 | :.global turn | |
157 | :.align 0x4 | |
158 | :addrA: | |
159 | for ( $k = 0; $k < 32; $k++) { | |
160 | : .word 0x0 | |
161 | : .word 0x0 | |
162 | } | |
163 | : | |
164 | :.skip 0x1000 | |
165 | :.align 0x4 | |
166 | :turn: | |
167 | : .word 0x0 | |
168 | : .word 0x0 | |
169 | : .word 0x0 | |
170 | : | |
171 | :SECTION .MY_DATA1 TEXT_VA=0xf1110000, DATA_VA=0xd1110000 | |
172 | :attr_data { | |
173 | : Name = .MY_DATA1, | |
174 | : VA= 0x0d1110000, | |
175 | : RA= 0x1d1110000, | |
176 | : PA= ra2pa(0x1d1110000,0), | |
177 | : part_0_ctx_nonzero_tsb_config_0, | |
178 | : TTE_G=1, TTE_Context=0x44, TTE_V=1, TTE_Size=0, TTE_NFO=0, | |
179 | : TTE_IE=0, TTE_Soft2=0, TTE_Diag=0, TTE_Soft=0, | |
180 | : TTE_L=0, TTE_CP=1, TTE_CV=1, TTE_E=0, TTE_P=0, TTE_W=1 | |
181 | : } | |
182 | : | |
183 | :attr_text { | |
184 | : Name = .MY_DATA1, | |
185 | : VA= 0x0f1110000, | |
186 | : RA= 0x1f1110000, | |
187 | : PA= ra2pa(0x1f1110000,0), | |
188 | : part_0_ctx_nonzero_tsb_config_0, | |
189 | : TTE_G=1, TTE_Context=0x44, TTE_V=1, TTE_Size=0, TTE_NFO=0, | |
190 | : TTE_IE=0, TTE_Soft2=0, TTE_Diag=0, TTE_Soft=0, | |
191 | : TTE_L=0, TTE_CP=1, TTE_CV=1, TTE_E=0, TTE_P=0, TTE_W=1 | |
192 | : } | |
193 | : | |
194 | : .data | |
195 | :.global prot_area | |
196 | :prot_area: | |
197 | : .word 0xbeef | |
198 | : .skip 0x1000 | |
199 | : .word 0xbeef | |
200 | :.global alive | |
201 | :alive: | |
202 | : .word 0x0 | |
203 | : .word 0x0 | |
204 | : .word 0x0 | |
205 | : .word 0x0 | |
206 | : .word 0x0 | |
207 | : .word 0x0 | |
208 | : .word 0x0 | |
209 | : | |
210 | :.end |