| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: tso_n1_indirection1.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 tmp0 %i0 |
| 39 | #define tmp1 %i1 |
| 40 | #define tmp2 %i2 |
| 41 | #define tmp3 %i3 |
| 42 | |
| 43 | #define global_cnt_reg %i4 |
| 44 | |
| 45 | #define addrA_reg %l0 |
| 46 | #define addrB_reg %l1 |
| 47 | #define addrC_reg %l2 |
| 48 | #define result0_reg %l3 |
| 49 | #define result1_reg %l4 |
| 50 | #define ready0_reg %l5 |
| 51 | #define ready1_reg %l6 |
| 52 | #define finish_reg %l7 |
| 53 | |
| 54 | #define test_reg %o4 |
| 55 | #define test2_reg %o5 |
| 56 | |
| 57 | #define ITERATIONS 0x4 |
| 58 | |
| 59 | #include "hboot.s" |
| 60 | |
| 61 | .global main |
| 62 | |
| 63 | main: |
| 64 | |
| 65 | setx addrA, tmp0, addrA_reg |
| 66 | setx addrB, tmp0, addrB_reg |
| 67 | setx addrC, tmp0, addrC_reg |
| 68 | setx result0, tmp0, result0_reg |
| 69 | setx result1, tmp0, result1_reg |
| 70 | setx ready0, tmp0, ready0_reg |
| 71 | setx ready1, tmp0, ready1_reg |
| 72 | setx finish_area, tmp0, finish_reg |
| 73 | |
| 74 | set ITERATIONS, global_cnt_reg |
| 75 | |
| 76 | th_fork(th_main,tmp1) |
| 77 | |
| 78 | !===================================================== |
| 79 | th_main_0: |
| 80 | loop00: |
| 81 | |
| 82 | mov 0x21, tmp1 |
| 83 | mov 0x1, tmp2 |
| 84 | st tmp1, [addrA_reg] |
| 85 | st tmp2, [addrB_reg] ! store non-zero to B |
| 86 | |
| 87 | ! BARRIER here |
| 88 | !============= |
| 89 | set barrier_code, tmp0 |
| 90 | jmpl tmp0,%o7 |
| 91 | nop |
| 92 | |
| 93 | dec global_cnt_reg |
| 94 | brz global_cnt_reg, good_end |
| 95 | nop |
| 96 | |
| 97 | ba loop00 ! loop |
| 98 | nop |
| 99 | |
| 100 | !========================================================= |
| 101 | |
| 102 | #ifdef ZERO_THREE_SIX |
| 103 | th_main_3: |
| 104 | #else |
| 105 | th_main_1: |
| 106 | #endif |
| 107 | th_main_4: |
| 108 | loop10: ! wait for B to be non-zero |
| 109 | ld [addrA_reg], test_reg |
| 110 | ld [addrB_reg], test_reg |
| 111 | brz test_reg, loop10 |
| 112 | nop |
| 113 | |
| 114 | st test_reg, [addrC_reg] ! store non-zero to C |
| 115 | |
| 116 | ! BARRIER here |
| 117 | !============= |
| 118 | set barrier_code, tmp0 |
| 119 | jmpl tmp0,%o7 |
| 120 | nop |
| 121 | |
| 122 | dec global_cnt_reg |
| 123 | brz global_cnt_reg, good_end |
| 124 | nop |
| 125 | ba loop10 ! loop |
| 126 | nop |
| 127 | |
| 128 | !========================================================= |
| 129 | #ifdef ZERO_THREE_SIX |
| 130 | th_main_6: |
| 131 | #else |
| 132 | th_main_2: |
| 133 | #endif |
| 134 | th_main_8: |
| 135 | |
| 136 | loop30: |
| 137 | ld [addrC_reg], test_reg ! load C until set |
| 138 | brz test_reg, loop30 |
| 139 | nop |
| 140 | |
| 141 | ld [addrA_reg], tmp1 ! check A |
| 142 | mov 0x21, tmp2 |
| 143 | subcc tmp2, tmp1, %g0 |
| 144 | bne bad_end |
| 145 | nop |
| 146 | |
| 147 | st %g0, [addrC_reg] ! clear |
| 148 | st %g0, [addrB_reg] |
| 149 | st %g0, [addrA_reg] |
| 150 | |
| 151 | ! barrier here |
| 152 | !============= |
| 153 | set barrier_code,tmp0 |
| 154 | jmpl tmp0,%o7 |
| 155 | nop |
| 156 | |
| 157 | dec global_cnt_reg |
| 158 | brz global_cnt_reg, good_end |
| 159 | nop |
| 160 | |
| 161 | ba loop30 ! loop |
| 162 | nop |
| 163 | |
| 164 | !=x======================================================================== |
| 165 | |
| 166 | ! all threads synchronize at this point. |
| 167 | barrier_code: |
| 168 | setx barrier_data, tmp1, tmp2 |
| 169 | sll global_cnt_reg, 0x3, tmp1 |
| 170 | add tmp1, tmp2, tmp2 |
| 171 | bloop1: ! get lock of barrier count |
| 172 | mov 0xff, tmp1 |
| 173 | cas [tmp2], %g0, tmp1 |
| 174 | brnz tmp1, bloop1 |
| 175 | #ifdef PREFETCH |
| 176 | prefetch [tmp2], #n_reads |
| 177 | #else |
| 178 | nop |
| 179 | #endif |
| 180 | ld [tmp2 + 4], tmp3 ! increment |
| 181 | inc tmp3 |
| 182 | st tmp3, [tmp2 + 4] |
| 183 | |
| 184 | st %g0, [tmp2] ! unlock |
| 185 | |
| 186 | bloop2: ! check the barrier count |
| 187 | ld [tmp2 + 4], tmp3 ! if 0 -> |
| 188 | brz tmp3, bout2 ! somebody already reset it |
| 189 | sub tmp3, THREAD_COUNT, tmp3 ! subtract THREAD_COUNT |
| 190 | brnz tmp3, bloop2 ! if 0 -> we are out. |
| 191 | #ifdef PREFETCH |
| 192 | prefetch [tmp2], #n_reads |
| 193 | #else |
| 194 | nop |
| 195 | #endif |
| 196 | |
| 197 | st %g0, [tmp2 + 4] ! clear the barrier counter |
| 198 | bout2: |
| 199 | jmpl %o7+8, %g0 ! return |
| 200 | nop |
| 201 | |
| 202 | good_end: |
| 203 | ta T_GOOD_TRAP |
| 204 | bad_end: |
| 205 | ta T_BAD_TRAP |
| 206 | |
| 207 | !================================================== |
| 208 | |
| 209 | .data |
| 210 | |
| 211 | .global addrA |
| 212 | .align 0x40 |
| 213 | addrA: |
| 214 | .word 0x0 |
| 215 | .skip 0x100 |
| 216 | .global result0 |
| 217 | result0: |
| 218 | .word 0x0 |
| 219 | .global ready0 |
| 220 | ready0: |
| 221 | .word 0x0 |
| 222 | |
| 223 | .global addrB |
| 224 | addrB: |
| 225 | .word 0x0 |
| 226 | .skip 0x100 |
| 227 | .global result1 |
| 228 | result1: |
| 229 | .word 0x0 |
| 230 | .global ready1 |
| 231 | ready1: |
| 232 | .word 0x0 |
| 233 | |
| 234 | .global finish_area |
| 235 | finish_area: |
| 236 | .word 0x0 |
| 237 | |
| 238 | .align 0x40 |
| 239 | .global addrC |
| 240 | addrC: |
| 241 | .word 0x0 |
| 242 | .skip 0x100 |
| 243 | |
| 244 | .global barrier_data |
| 245 | barrier_data: |
| 246 | .skip 0x100 |
| 247 | |
| 248 | .end |