| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: tso_n2_prod_cons_intr3.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 MAIN_PAGE_HV_ALSO |
| 39 | #define BUFFERSIZE 64 /*in bytes*/ |
| 40 | #define myIdReg %o0 |
| 41 | #define phyCoreIdReg %o1 |
| 42 | #define thrdIdReg %o2 |
| 43 | #define ITERATIONS 0x4 |
| 44 | #define bufferSizeReg %g1 |
| 45 | #define prodCntReg %g2 |
| 46 | #define consCntReg %g3 |
| 47 | #define ASI_SWVR_UDB_INTR_W 0x73 |
| 48 | #define ASI_SWVR_UDB_INTR_R 0x74 |
| 49 | |
| 50 | #define H_HT0_Interrupt_0x60 |
| 51 | #define My_HT0_Interrupt_0x60 \ |
| 52 | call My_interrupt_0x60_handler; \ |
| 53 | nop; \ |
| 54 | nop; \ |
| 55 | nop; |
| 56 | |
| 57 | #include "hboot.s" |
| 58 | |
| 59 | .global main |
| 60 | |
| 61 | main: |
| 62 | ta T_CHANGE_HPRIV ! change to hyper mode |
| 63 | nop |
| 64 | mov BUFFERSIZE, %g1 !Bounded Buffer Size |
| 65 | mov ITERATIONS, prodCntReg !no of iterations to produce |
| 66 | mov ITERATIONS, consCntReg !no of iterations to produce |
| 67 | setx boundedBufferSize, %g5, %g6 |
| 68 | mov 0x40, %g7 |
| 69 | st %g7, [%g6] |
| 70 | setx prodCnt, %g5, %g6 |
| 71 | mov 0x04, %g7 |
| 72 | st %g7, [%g6] |
| 73 | setx consCnt, %g5, %g6 |
| 74 | mov 0x04, %g7 |
| 75 | st %g7, [%g6] |
| 76 | setx consumedData, %g5, %g6 |
| 77 | mov 0x0, %g7 |
| 78 | st %g7, [%g6] |
| 79 | setx producedData, %g5, %g6 |
| 80 | mov 0x0, %g7 |
| 81 | st %g7, [%g6] |
| 82 | |
| 83 | |
| 84 | th_fork(th_main,%l0) |
| 85 | |
| 86 | ! Some of the threads are producers, some are consumers |
| 87 | ! A pair of producer and consumer has the same ID. |
| 88 | !===================================================== |
| 89 | th_main_0: |
| 90 | add %g0, 0x1, myIdReg ! this is my ID address |
| 91 | add %g0, 0x0, phyCoreIdReg |
| 92 | add %g0, 0x0, thrdIdReg |
| 93 | ba producer |
| 94 | nop |
| 95 | |
| 96 | th_main_1: |
| 97 | add %g0, 0x1, myIdReg |
| 98 | add %g0, 0x0, phyCoreIdReg |
| 99 | add %g0, 0x1, thrdIdReg |
| 100 | ba consumer |
| 101 | nop |
| 102 | |
| 103 | th_main_2: |
| 104 | add %g0, 0x3, myIdReg |
| 105 | add %g0, 0x0, phyCoreIdReg |
| 106 | add %g0, 0x2, thrdIdReg |
| 107 | ! ba producer |
| 108 | ! nop |
| 109 | call goodEnd |
| 110 | nop |
| 111 | |
| 112 | th_main_3: |
| 113 | add %g0, 0x2, myIdReg |
| 114 | add %g0, 0x0, phyCoreIdReg |
| 115 | add %g0, 0x3, thrdIdReg |
| 116 | ! ba producer |
| 117 | ! nop |
| 118 | call goodEnd |
| 119 | nop |
| 120 | |
| 121 | th_main_4: |
| 122 | add %g0, 0x0, myIdReg |
| 123 | add %g0, 0x0, phyCoreIdReg |
| 124 | add %g0, 0x4, thrdIdReg |
| 125 | ! ba consumer |
| 126 | ! nop |
| 127 | call goodEnd |
| 128 | nop |
| 129 | |
| 130 | th_main_5: |
| 131 | add %g0, 0x1, myIdReg |
| 132 | add %g0, 0x0, phyCoreIdReg |
| 133 | add %g0, 0x5, thrdIdReg |
| 134 | ! ba producer |
| 135 | ! nop |
| 136 | call goodEnd |
| 137 | nop |
| 138 | |
| 139 | th_main_6: |
| 140 | add %g0, 0x3, myIdReg |
| 141 | add %g0, 0x0, phyCoreIdReg |
| 142 | add %g0, 0x6, thrdIdReg |
| 143 | ! ba consumer |
| 144 | ! nop |
| 145 | call goodEnd |
| 146 | nop |
| 147 | |
| 148 | th_main_7: |
| 149 | add %g0, 0x2, myIdReg |
| 150 | add %g0, 0x0, phyCoreIdReg |
| 151 | add %g0, 0x7, thrdIdReg |
| 152 | ! ba consumer |
| 153 | ! nop |
| 154 | call goodEnd |
| 155 | nop |
| 156 | |
| 157 | goodEnd: |
| 158 | ta T_GOOD_TRAP |
| 159 | |
| 160 | !============================================================== |
| 161 | !Producer code |
| 162 | !============================================================== |
| 163 | producer: |
| 164 | nop |
| 165 | wakeProducer: |
| 166 | setx prodCnt , %l0, %l2 |
| 167 | lduw [%l2], %l3 |
| 168 | subcc %l3, 0x1, %l3 |
| 169 | subcc %l3, %g0, %g0 |
| 170 | bz productionComplete |
| 171 | st %l3, [%l2] |
| 172 | |
| 173 | call produceData !will produce one set of data |
| 174 | nop |
| 175 | |
| 176 | !dispatch interrupt |
| 177 | setx 0x102, %g6, %g7 ! send to thread 1 vector number 1 |
| 178 | stxa %g7, [%g0]ASI_SWVR_UDB_INTR_W ! no membar sync needed after this reg |
| 179 | |
| 180 | |
| 181 | snoozeProducer: |
| 182 | setx consumedData, %l0, %l2 |
| 183 | lduw [%l2], %l4 |
| 184 | subcc %l4, 1, %l4 |
| 185 | bz,a wakeProducer |
| 186 | st %g0, [%l2] |
| 187 | ba snoozeProducer |
| 188 | nop |
| 189 | |
| 190 | productionComplete: |
| 191 | ta T_GOOD_TRAP |
| 192 | |
| 193 | !produce data function |
| 194 | produceData: |
| 195 | save |
| 196 | !find the buffer size |
| 197 | setx dataBufferBase, %l0, %l1 |
| 198 | setx boundedBufferSize , %l0, %l2 |
| 199 | lduw [%l2] , %l0 !has buffer size |
| 200 | mov %g0, %l4 |
| 201 | !pair id available in global myIdReg |
| 202 | umul %i0, %l0, %l3 |
| 203 | add %l3, %l1, %l1 !has the base addr for this pair |
| 204 | |
| 205 | dataProduction: |
| 206 | mov %i0, %l5 !after save o0 becomes i0 |
| 207 | sllx %l5, 16, %l5 |
| 208 | or %l5, %l4, %l5 |
| 209 | stx %l5, [%l1 + %l4] |
| 210 | subcc %l4, %l0, %g0 |
| 211 | add %l4, 8, %l4 |
| 212 | bnz,a dataProduction |
| 213 | ldx [%l1 + %l4], %g0 |
| 214 | dataProductionDone: |
| 215 | restore |
| 216 | retl |
| 217 | nop |
| 218 | |
| 219 | |
| 220 | !============================================================== |
| 221 | !ConsumerCode: |
| 222 | !============================================================== |
| 223 | consumer: |
| 224 | nop |
| 225 | snoozeConsumer: |
| 226 | setx producedData, %l0, %l2 |
| 227 | lduw [%l2], %l4 |
| 228 | subcc %l4, 1, %l4 |
| 229 | bz,a wakeConsumer |
| 230 | st %g0, [%l2] |
| 231 | ba snoozeConsumer |
| 232 | nop |
| 233 | |
| 234 | wakeConsumer: |
| 235 | setx consCnt , %l0, %l2 |
| 236 | lduw [%l2], %l3 |
| 237 | subcc %l3, 0x1, %l3 |
| 238 | subcc %l3, 0x1, %g0 |
| 239 | bz consumeComplete |
| 240 | st %l3, [%l2] |
| 241 | |
| 242 | call consumeData |
| 243 | nop |
| 244 | |
| 245 | !dispacth interrrupt to producer |
| 246 | mov 0x001, %g7 ! send to thread 0 vector number 1 |
| 247 | stxa %g7, [%g0]ASI_SWVR_UDB_INTR_W ! no membar sync needed after this reg |
| 248 | |
| 249 | ba snoozeConsumer |
| 250 | nop |
| 251 | consumeComplete: |
| 252 | mov 0x001, %g7 ! send to thread 0 vector number 1 |
| 253 | stxa %g7, [%g0]ASI_SWVR_UDB_INTR_W ! no membar sync needed after this reg |
| 254 | ta T_GOOD_TRAP |
| 255 | |
| 256 | !consume data function |
| 257 | consumeData: |
| 258 | save |
| 259 | !find the buffer size |
| 260 | setx dataBufferBase, %l0, %l1 |
| 261 | setx boundedBufferSize , %l0, %l2 |
| 262 | lduw [%l2] , %l0 !has buffer size |
| 263 | mov %g0, %l4 |
| 264 | !pair id available in global myIdReg |
| 265 | umul %i0, %l0, %l3 |
| 266 | add %l3, %l1, %l1 !has the base addr for this pair |
| 267 | |
| 268 | consumingData: |
| 269 | mov %i0, %l5 |
| 270 | sllx %l5, 16, %l5 |
| 271 | or %l5, %l4, %l5 |
| 272 | ldx [%l1 + %l4], %l6 |
| 273 | subcc %l6, %l5, %l6 |
| 274 | bnz badDataConsumed |
| 275 | nop |
| 276 | subcc %l4, %l0, %g0 |
| 277 | add %l4, 0x8, %l4 |
| 278 | bnz,a consumingData |
| 279 | ldx [%l1 + %l4], %g0 |
| 280 | consumeDone: |
| 281 | restore |
| 282 | retl |
| 283 | nop |
| 284 | |
| 285 | badDataConsumed: |
| 286 | ta T_BAD_TRAP |
| 287 | |
| 288 | |
| 289 | !============================================================== |
| 290 | !interrupt handler |
| 291 | !============================================================== |
| 292 | .global My_interrupt_0x60_handler |
| 293 | My_interrupt_0x60_handler: |
| 294 | !First figure out wether the consumer interrupting producer |
| 295 | !or Producer interrupting Consumer |
| 296 | !if the vector is 1 then consumer interrupting producer |
| 297 | !if the vector is 2 then producer interrupting consumer |
| 298 | !In interrupts Interrupt Globals are used IG |
| 299 | |
| 300 | !read the ASI_SWVR_UDB_INTR_R ASI=0x74 VA=0x0 |
| 301 | ldxa [%g0]0x74, %g1 |
| 302 | subcc %g1, 0x1, %g0 |
| 303 | bz consumerToProducer |
| 304 | nop |
| 305 | subcc %g1, 0x2, %g0 |
| 306 | bz producerToConsumer |
| 307 | consumerToProducer: |
| 308 | setx consumedData, %l0, %g2 |
| 309 | mov 0x1, %g3 |
| 310 | st %g3, [%g2] |
| 311 | ba returnToSnooze |
| 312 | nop |
| 313 | |
| 314 | producerToConsumer: |
| 315 | setx producedData, %l0, %g2 |
| 316 | mov 0x1, %g3 |
| 317 | st %g3, [%g2] |
| 318 | ba returnToSnooze |
| 319 | nop |
| 320 | |
| 321 | returnToSnooze: |
| 322 | retry |
| 323 | nop |
| 324 | |
| 325 | !=============================================================== |
| 326 | SECTION .MY_DATA0 TEXT_VA=0xf0100000, DATA_VA=0xd0100000 |
| 327 | attr_data { |
| 328 | Name = .MY_DATA0, |
| 329 | VA= 0x0d0100000 |
| 330 | RA= 0x1d0100000 |
| 331 | PA= ra2pa(0x1d0100000,0), |
| 332 | part_0_ctx_nonzero_tsb_config_0, |
| 333 | TTE_G=1, TTE_Context=0x44, TTE_V=1, TTE_Size=0, TTE_NFO=0, |
| 334 | TTE_IE=0, TTE_Soft2=0, TTE_Diag=0, TTE_Soft=0, |
| 335 | TTE_L=0, TTE_CP=1, TTE_CV=1, TTE_E=0, TTE_P=0, TTE_W=1 |
| 336 | } |
| 337 | |
| 338 | attr_text { |
| 339 | Name = .MY_DATA0, |
| 340 | VA= 0x0f0100000 |
| 341 | RA= 0x1f0100000 |
| 342 | PA= ra2pa(0x1f0100000,0), |
| 343 | part_0_ctx_nonzero_tsb_config_0, |
| 344 | TTE_G=1, TTE_Context=0x44, TTE_V=1, TTE_Size=0, TTE_NFO=0, |
| 345 | TTE_IE=0, TTE_Soft2=0, TTE_Diag=0, TTE_Soft=0, |
| 346 | TTE_L=0, TTE_CP=1, TTE_CV=1, TTE_E=0, TTE_P=0, TTE_W=1 |
| 347 | } |
| 348 | |
| 349 | |
| 350 | .data |
| 351 | .global parameters |
| 352 | parameters: |
| 353 | .word 0x0 |
| 354 | .global boundedBufferSize |
| 355 | boundedBufferSize: |
| 356 | .word 0x40 |
| 357 | .global prodCnt |
| 358 | prodCnt: |
| 359 | .word 0x4 |
| 360 | .global consCnt |
| 361 | consCnt: |
| 362 | .word 0x4 |
| 363 | .global consumedData |
| 364 | consumedData: |
| 365 | .word 0x0 |
| 366 | .global producedData |
| 367 | producedData: |
| 368 | .word 0x0 |
| 369 | strnId0: |
| 370 | .word 0x1 |
| 371 | strnId1: |
| 372 | .word 0x1 |
| 373 | strnId2: |
| 374 | .word 0x0 |
| 375 | strnId3: |
| 376 | .word 0x0 |
| 377 | strnId4: |
| 378 | .word 0x0 |
| 379 | strnId5: |
| 380 | .word 0x0 |
| 381 | strnId6: |
| 382 | .word 0x0 |
| 383 | strnId7: |
| 384 | .word 0x0 |
| 385 | .word 0x0 |
| 386 | .word 0x0 |
| 387 | .word 0x0 |
| 388 | .word 0x0 |
| 389 | .word 0x0 |
| 390 | .word 0x0 |
| 391 | .word 0x0 |
| 392 | .word 0x0 |
| 393 | .word 0x0 |
| 394 | .word 0x0 |
| 395 | .word 0x0 |
| 396 | .word 0x0 |
| 397 | .word 0x0 |
| 398 | .word 0x0 |
| 399 | .word 0x0 |
| 400 | .word 0x0 |
| 401 | .word 0x0 |
| 402 | .word 0x0 |
| 403 | .word 0x0 |
| 404 | .word 0x0 |
| 405 | .word 0x0 |
| 406 | .word 0x0 |
| 407 | .word 0x0 |
| 408 | .word 0x0 |
| 409 | .word 0x0 |
| 410 | .word 0x0 |
| 411 | .word 0x0 |
| 412 | .word 0x0 |
| 413 | .word 0x0 |
| 414 | .word 0x0 |
| 415 | .word 0x0 |
| 416 | .word 0x0 |
| 417 | .word 0x0 |
| 418 | .word 0x0 |
| 419 | .word 0x0 |
| 420 | .word 0x0 |
| 421 | .word 0x0 |
| 422 | .word 0x0 |
| 423 | .word 0x0 |
| 424 | .word 0x0 |
| 425 | .word 0x0 |
| 426 | .word 0x0 |
| 427 | .word 0x0 |
| 428 | .word 0x0 |
| 429 | .word 0x0 |
| 430 | .word 0x0 |
| 431 | .word 0x0 |
| 432 | .word 0x0 |
| 433 | .word 0x0 |
| 434 | .word 0x0 |
| 435 | .word 0x0 |
| 436 | .word 0x0 |
| 437 | .word 0x0 |
| 438 | .word 0x0 |
| 439 | .word 0x0 |
| 440 | .word 0x0 |
| 441 | .word 0x0 |
| 442 | .word 0x0 |
| 443 | .word 0x0 |
| 444 | .word 0x0 |
| 445 | .word 0x0 |
| 446 | .word 0x0 |
| 447 | .word 0x0 |
| 448 | .word 0x0 |
| 449 | .word 0x0 |
| 450 | .word 0x0 |
| 451 | .word 0x0 |
| 452 | .word 0x0 |
| 453 | .word 0x0 |
| 454 | .word 0x0 |
| 455 | .word 0x0 |
| 456 | |
| 457 | SECTION .MY_DATA1 TEXT_VA=0xf1110000, DATA_VA=0xd1110000 |
| 458 | attr_data { |
| 459 | Name = .MY_DATA1, |
| 460 | VA= 0x0d1110000, |
| 461 | RA= 0x1d1110000, |
| 462 | PA= ra2pa(0x1d1110000,0), |
| 463 | part_0_ctx_nonzero_tsb_config_0, |
| 464 | TTE_G=1, TTE_Context=0x44, TTE_V=1, TTE_Size=0, TTE_NFO=0, |
| 465 | TTE_IE=0, TTE_Soft2=0, TTE_Diag=0, TTE_Soft=0, |
| 466 | TTE_L=0, TTE_CP=1, TTE_CV=1, TTE_E=0, TTE_P=0, TTE_W=1 |
| 467 | } |
| 468 | |
| 469 | attr_text { |
| 470 | Name = .MY_DATA1, |
| 471 | VA= 0x0f1110000, |
| 472 | RA= 0x1f1110000, |
| 473 | PA= ra2pa(0x1f1110000,0), |
| 474 | part_0_ctx_nonzero_tsb_config_0, |
| 475 | TTE_G=1, TTE_Context=0x44, TTE_V=1, TTE_Size=0, TTE_NFO=0, |
| 476 | TTE_IE=0, TTE_Soft2=0, TTE_Diag=0, TTE_Soft=0, |
| 477 | TTE_L=0, TTE_CP=1, TTE_CV=1, TTE_E=0, TTE_P=0, TTE_W=1 |
| 478 | } |
| 479 | |
| 480 | |
| 481 | .data |
| 482 | .global dataBufferBase |
| 483 | dataBufferBase: |
| 484 | .word 0xbeef |
| 485 | .skip 0x1000 |
| 486 | .word 0xbeef |
| 487 | .end |