| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: stackinit_mt.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 | #include "defines.h" |
| 39 | |
| 40 | #define ZERO_OFFSET 48 |
| 41 | |
| 42 | !--------------------------------------------------- |
| 43 | ! Number of arguments passed to the diag |
| 44 | ! We have a CONVENTION: |
| 45 | ! argv[1] is THREAD ID |
| 46 | ! argv[2] is number of threads |
| 47 | ! argv[3] is USER DEFINED |
| 48 | ! argv[4] is USER DEFINED |
| 49 | ! currently we support up to argv[4] |
| 50 | !--------------------------------------------------- |
| 51 | #ifndef C_ARGNUM |
| 52 | #define C_ARGNUM 5 |
| 53 | #endif |
| 54 | |
| 55 | #ifndef C_ARG3 |
| 56 | #define C_ARG3 0 |
| 57 | #endif |
| 58 | |
| 59 | #ifndef C_ARG4 |
| 60 | #define C_ARG4 0 |
| 61 | #endif |
| 62 | |
| 63 | !--------------------------------------------------- |
| 64 | ! stack pointer offset per Sparc V9 rules |
| 65 | !--------------------------------------------------- |
| 66 | #define SP_OFFSET (STACKSIZE-4095) |
| 67 | |
| 68 | |
| 69 | !--------------------------------------------------- |
| 70 | ! some macros |
| 71 | !--------------------------------------------------- |
| 72 | #define INIT_LOCAL_REGS \ |
| 73 | set 0x0, %l0; \ |
| 74 | set 0x0, %l1; \ |
| 75 | set 0x0, %l2; \ |
| 76 | set 0x0, %l3; \ |
| 77 | set 0x0, %l4; \ |
| 78 | set 0x0, %l5; \ |
| 79 | set 0x0, %l6; \ |
| 80 | set 0x0, %l7; \ |
| 81 | set 0x0, %i0; \ |
| 82 | set 0x0, %i1; \ |
| 83 | set 0x0, %i2; \ |
| 84 | set 0x0, %i3; \ |
| 85 | set 0x0, %i4; \ |
| 86 | set 0x0, %i5; \ |
| 87 | set 0x0, %i6; \ |
| 88 | set 0x0, %i7; |
| 89 | |
| 90 | !--------------------------------------------------- |
| 91 | |
| 92 | !--------------------------------------------------- |
| 93 | .section .text |
| 94 | |
| 95 | !--------------------------------------------------- |
| 96 | ! the start of the C program |
| 97 | !--------------------------------------------------- |
| 98 | .align 4 |
| 99 | .global c_start |
| 100 | c_start: |
| 101 | |
| 102 | !--------------------------------------------------- |
| 103 | ! register init - avoid mismatches in spill/fill traps |
| 104 | !--------------------------------------------------- |
| 105 | ta T_CHANGE_PRIV |
| 106 | wrpr %g0, 0, %cwp |
| 107 | INIT_LOCAL_REGS |
| 108 | wrpr %g0, 1, %cwp |
| 109 | INIT_LOCAL_REGS |
| 110 | wrpr %g0, 2, %cwp |
| 111 | INIT_LOCAL_REGS |
| 112 | wrpr %g0, 3, %cwp |
| 113 | INIT_LOCAL_REGS |
| 114 | wrpr %g0, 4, %cwp |
| 115 | INIT_LOCAL_REGS |
| 116 | wrpr %g0, 5, %cwp |
| 117 | INIT_LOCAL_REGS |
| 118 | wrpr %g0, 6, %cwp |
| 119 | INIT_LOCAL_REGS |
| 120 | wrpr %g0, 7, %cwp |
| 121 | INIT_LOCAL_REGS |
| 122 | wrpr %g0, 0, %cwp |
| 123 | ta T_CHANGE_NONPRIV |
| 124 | |
| 125 | !--------------------------------------------------- |
| 126 | ! set up stack per thread for all threads |
| 127 | !--------------------------------------------------- |
| 128 | th_fork(prepare_thread, %l0); |
| 129 | |
| 130 | changequote([, ])dnl |
| 131 | forloop([i], 0, eval(THREAD_COUNT-1), [ |
| 132 | [prepare_thread_]eval(i*THREAD_STRIDE): |
| 133 | !--------------------------------------------------- |
| 134 | ! Setting up the C args costs a fair bit, define SKIP_C_ARGS to skip this. |
| 135 | !--------------------------------------------------- |
| 136 | #ifndef SKIP_C_ARGS |
| 137 | setx [hs]eval(i*THREAD_STRIDE), %l0, %o2 ! pointer to help string per thread |
| 138 | |
| 139 | setx [arg1t]eval(i*THREAD_STRIDE), %l0, %o0 ! a pointer to arg1tN |
| 140 | set eval(i*THREAD_STRIDE), %o1 ! arg1 is the thread ID |
| 141 | call itos, 0 |
| 142 | nop |
| 143 | setx [arg2t]eval(i*THREAD_STRIDE), %l0, %o0 ! a pointer to arg2tN |
| 144 | set THREAD_COUNT, %o1 ! arg2 is the thread count |
| 145 | call itos, 0 |
| 146 | nop |
| 147 | setx [arg3t]eval(i*THREAD_STRIDE), %l0, %o0 |
| 148 | set C_ARG3, %o1 ! USER defined |
| 149 | call itos, 0 |
| 150 | nop |
| 151 | setx [arg4t]eval(i*THREAD_STRIDE), %l0, %o0 |
| 152 | set C_ARG4, %o1 ! user defined |
| 153 | call itos, 0 |
| 154 | nop |
| 155 | #endif |
| 156 | setx [stack]eval(i*THREAD_STRIDE), %l5, %sp |
| 157 | setx SP_OFFSET, %l0, %l1 |
| 158 | add %sp, %l1, %sp ! set and adjust the stack pointer |
| 159 | |
| 160 | #ifndef SKIP_C_ARGS |
| 161 | set C_ARGNUM, %o0 ! argc ! %o0 is argc |
| 162 | setx [argvp]eval(i*THREAD_STRIDE), %l0, %o1 ! %o1 is a ponter of array of arrays |
| 163 | #else |
| 164 | clr %o0 |
| 165 | clr %o1 |
| 166 | #endif |
| 167 | ba call_main ! now go to call_main... |
| 168 | nop |
| 169 | ])dnl |
| 170 | changequote(`,')dnl' |
| 171 | |
| 172 | |
| 173 | !--------------------------------------- |
| 174 | call_main: ! call the C program |
| 175 | #ifndef MAIN_INIT |
| 176 | setx main, %l0, %l1 |
| 177 | #else |
| 178 | setx MAIN_INIT, %l0, %l1 |
| 179 | #endif |
| 180 | jmpl %l1,%o7 |
| 181 | nop |
| 182 | |
| 183 | brnz %o0, c_fail |
| 184 | nop |
| 185 | c_pass: |
| 186 | ta T_GOOD_TRAP |
| 187 | nop |
| 188 | |
| 189 | c_fail: |
| 190 | ta T_BAD_TRAP |
| 191 | nop |
| 192 | !-------------------------------------------------------------------------- |
| 193 | !-------------------------------------------------------------------------- |
| 194 | !-------------------------------------------------------------------------- |
| 195 | |
| 196 | !-------------------------------------------------------------------------- |
| 197 | ! the itos - integer to string function below - is implemented in assembly |
| 198 | ! based on the C implementation in the comments |
| 199 | !-------------------------------------------------------------------------- |
| 200 | !void itos (char *s, int a){ |
| 201 | ! if(a ==0){ |
| 202 | ! s[0] = '0'; |
| 203 | ! s[1] = 0; |
| 204 | ! return; |
| 205 | ! } |
| 206 | ! count = 0; |
| 207 | ! result = a; |
| 208 | ! while(result >0){ |
| 209 | ! hs[count++] = result % 10 + '0'; |
| 210 | ! result = result /10; |
| 211 | ! } |
| 212 | ! if(a<0) hs[count] = '-'; |
| 213 | ! else count--; |
| 214 | ! for(iter= count; iter>=0; iter--) s[count-iter] = hs[iter]; |
| 215 | ! s[count+1] = 0; |
| 216 | !} |
| 217 | !-------------------------------------------------------------------------- |
| 218 | itos: |
| 219 | mov %g0, %l7 ! count |
| 220 | brnz %o1, itos_proceed ! o1 is the number |
| 221 | nop |
| 222 | mov ZERO_OFFSET, %l0 ! number is 0 |
| 223 | stb %l0, [%o0] ! return '0', 0 |
| 224 | retl |
| 225 | stb %g0, [%o0 +1] |
| 226 | |
| 227 | itos_proceed: ! check for sign |
| 228 | brgz %o1, itos_positive |
| 229 | nop |
| 230 | ba itos_while_entry |
| 231 | mulx %o1, -1, %i4 |
| 232 | itos_positive: |
| 233 | mov %o1, %i4 ! result |
| 234 | itos_while_entry: |
| 235 | brgz %i4, itos_while_body |
| 236 | nop |
| 237 | ba itos_while_exit |
| 238 | nop |
| 239 | itos_while_body: |
| 240 | sdivx %i4, 10, %i3 ! divide by 10 |
| 241 | sllx %i3, 2, %i5 ! multiply result by 4 |
| 242 | add %i5, %i3, %i5 ! add it once -> multipy by 5 by now. |
| 243 | add %i5, %i5, %i5 ! multiply by 10 overall |
| 244 | sub %i4, %i5, %l4 ! l4 is the remainder now. |
| 245 | add %l4, ZERO_OFFSET, %l4 |
| 246 | stb %l4, [%o2 + %l7] |
| 247 | mov %i3, %i4 |
| 248 | inc %l7 |
| 249 | ba itos_while_entry |
| 250 | nop |
| 251 | itos_while_exit: |
| 252 | brgz %o1, itos_positive2 |
| 253 | nop |
| 254 | set 45, %i2 ! 45 is the value of the '-' character |
| 255 | stb %i2, [%o2 + %l7] |
| 256 | mov %g0, %l0 |
| 257 | ba itos_for_entry |
| 258 | nop |
| 259 | itos_positive2: |
| 260 | dec %l7 |
| 261 | mov %g0, %l0 |
| 262 | itos_for_entry: |
| 263 | brgez %l7, itos_for_body |
| 264 | nop |
| 265 | ba itos_for_exit |
| 266 | nop |
| 267 | itos_for_body: |
| 268 | ldub [%o2 + %l7], %l4 |
| 269 | stb %l4, [%o0 +%l0] |
| 270 | inc %l0 |
| 271 | dec %l7 |
| 272 | ba itos_for_entry |
| 273 | nop |
| 274 | itos_for_exit: |
| 275 | retl |
| 276 | stb %g0, [%o0 +%l0] |
| 277 | !-------------------------------------------------------------------------------------------- |
| 278 | |
| 279 | |
| 280 | !-------------------------------------------------------------------------------------------- |
| 281 | !-------------------------------------------------------------------------------------------- |
| 282 | .section .data |
| 283 | |
| 284 | .global shared_memory |
| 285 | shared_memory: |
| 286 | .skip 0x1000 |
| 287 | |
| 288 | .global shared_memory_buffers |
| 289 | shared_memory_buffers: |
| 290 | init_mem(0x0101010101010101, 8192, 8, +, 0, +, 0) |
| 291 | .skip 0xc000 |
| 292 | |
| 293 | .global barp |
| 294 | barp: |
| 295 | .skip 0x100 |
| 296 | |
| 297 | .global barrier_lock |
| 298 | barrier_lock: |
| 299 | .skip 0x100 |
| 300 | |
| 301 | changequote([, ])dnl |
| 302 | forloop([i], 0, eval(THREAD_COUNT-1), [ |
| 303 | .global [argvp]eval(i*THREAD_STRIDE) |
| 304 | [argvp]eval(i*THREAD_STRIDE): |
| 305 | .xword arg0 |
| 306 | .xword [arg1t]eval(i*THREAD_STRIDE) |
| 307 | .xword [arg2t]eval(i*THREAD_STRIDE) |
| 308 | .xword [arg3t]eval(i*THREAD_STRIDE) |
| 309 | .xword [arg4t]eval(i*THREAD_STRIDE) |
| 310 | .xword [arg5t]eval(i*THREAD_STRIDE) |
| 311 | .xword [arg6t]eval(i*THREAD_STRIDE) |
| 312 | .xword [arg7t]eval(i*THREAD_STRIDE) |
| 313 | .xword 0 |
| 314 | |
| 315 | .global [arg1t]eval(i*THREAD_STRIDE) |
| 316 | [arg1t]eval(i*THREAD_STRIDE): |
| 317 | .skip 128 |
| 318 | |
| 319 | .global [arg2t]eval(i*THREAD_STRIDE) |
| 320 | [arg2t]eval(i*THREAD_STRIDE): |
| 321 | .skip 128 |
| 322 | |
| 323 | .global [arg3t]eval(i*THREAD_STRIDE) |
| 324 | [arg3t]eval(i*THREAD_STRIDE): |
| 325 | .skip 128 |
| 326 | |
| 327 | .global [arg4t]eval(i*THREAD_STRIDE) |
| 328 | [arg4t]eval(i*THREAD_STRIDE): |
| 329 | .skip 128 |
| 330 | |
| 331 | .global [arg5t]eval(i*THREAD_STRIDE) |
| 332 | [arg5t]eval(i*THREAD_STRIDE): |
| 333 | .skip 128 |
| 334 | |
| 335 | .global [arg6t]eval(i*THREAD_STRIDE) |
| 336 | [arg6t]eval(i*THREAD_STRIDE): |
| 337 | .skip 128 |
| 338 | |
| 339 | .global [arg7t]eval(i*THREAD_STRIDE) |
| 340 | [arg7t]eval(i*THREAD_STRIDE): |
| 341 | .skip 128 |
| 342 | |
| 343 | .global [hs]eval(i*THREAD_STRIDE) |
| 344 | [hs]eval(i*THREAD_STRIDE): |
| 345 | .skip 128 |
| 346 | ])dnl |
| 347 | changequote(`,')dnl' |
| 348 | |
| 349 | |
| 350 | .global arg0 |
| 351 | arg0: |
| 352 | .ascii "mycmain" |
| 353 | .byte 0 |
| 354 | .global shm_sync |
| 355 | shm_sync: |
| 356 | .word 0 |
| 357 | .word 0 |
| 358 | .word 0 |
| 359 | .word 0 |
| 360 | .word 0 |
| 361 | .word 0 |
| 362 | .word 0 |
| 363 | .word 0 |
| 364 | .word 0 |
| 365 | .word 0 |
| 366 | .word 0 |
| 367 | .word 0 |
| 368 | .word 0 |
| 369 | .word 0 |
| 370 | .word 0 |
| 371 | .word 0 |
| 372 | .word 0 |
| 373 | .word 0 |
| 374 | .word 0 |
| 375 | .word 0 |
| 376 | .word 0 |
| 377 | .word 0 |
| 378 | .word 0 |
| 379 | .word 0 |
| 380 | .word 0 |
| 381 | .word 0 |
| 382 | .word 0 |
| 383 | .word 0 |
| 384 | .word 0 |
| 385 | .word 0 |
| 386 | .word 0 |
| 387 | .word 0 |
| 388 | .word 0 |
| 389 | .word 0 |
| 390 | .word 0 |
| 391 | .word 0 |
| 392 | .word 0 |
| 393 | .word 0 |
| 394 | .word 0 |
| 395 | .word 0 |
| 396 | .word 0 |
| 397 | .word 0 |
| 398 | .word 0 |
| 399 | .word 0 |
| 400 | .word 0 |
| 401 | .word 0 |
| 402 | .word 0 |
| 403 | .word 0 |
| 404 | .word 0 |
| 405 | .word 0 |
| 406 | .word 0 |
| 407 | .word 0 |
| 408 | .word 0 |
| 409 | .word 0 |
| 410 | .word 0 |
| 411 | .word 0 |
| 412 | .word 0 |
| 413 | .word 0 |
| 414 | .word 0 |
| 415 | .word 0 |
| 416 | .word 0 |
| 417 | .word 0 |
| 418 | .word 0 |
| 419 | .word 0 |
| 420 | !---------------------------------------------------------------------------------------------- |