| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: seeding.vri |
| 4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved |
| 5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. |
| 6 | // |
| 7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 8 | // |
| 9 | // This program is free software; you can redistribute it and/or modify |
| 10 | // it under the terms of the GNU General Public License as published by |
| 11 | // the Free Software Foundation; version 2 of the License. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | // |
| 22 | // For the avoidance of doubt, and except that if any non-GPL license |
| 23 | // choice is available it will apply instead, Sun elects to use only |
| 24 | // the General Public License version 2 (GPLv2) at this time for any |
| 25 | // software where a choice of GPL license versions is made |
| 26 | // available with the language indicating that GPLv2 or any later version |
| 27 | // may be used, or where a choice of which version of the GPL is applied is |
| 28 | // otherwise unspecified. |
| 29 | // |
| 30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 31 | // CA 95054 USA or visit www.sun.com if you need additional information or |
| 32 | // have any questions. |
| 33 | // |
| 34 | // ========== Copyright Header End ============================================ |
| 35 | #include "plusArgMacros.vri" |
| 36 | |
| 37 | |
| 38 | //----------------------------------------------------------------------------- |
| 39 | // You must seed the random number generators from the vera program file |
| 40 | // (*top.vr) *BEFORE* class instantiations and forks. YES, this matters |
| 41 | // in vera > V5, see vera docs. If you don't seed before instantiating a |
| 42 | // class, that class ALWAYS repeats the same random numbers which is NOT |
| 43 | // what you want. (you have been warned :^)) |
| 44 | //----------------------------------------------------------------------------- |
| 45 | |
| 46 | //----------------------------------------------------------------------------- |
| 47 | // NOTE: random() always returns a positive integer. bit 31 ALWAYS ZERO. |
| 48 | // urandom() always returns a unsigned integer. bit 31 ALWAYS RANDOM. |
| 49 | // If you do myInt = urandom(); you will get a negetive integer 50% of the time! |
| 50 | // If you do myReg[31:0] = random(); you will always have [31] = 0. |
| 51 | // Read this again... |
| 52 | //----------------------------------------------------------------------------- |
| 53 | |
| 54 | |
| 55 | /* |
| 56 | |
| 57 | Example: |
| 58 | |
| 59 | program bench_top { |
| 60 | |
| 61 | MyClass hndl; |
| 62 | integer otherStuff; |
| 63 | integer gSeed; |
| 64 | integer gSeedFileHndl; |
| 65 | |
| 66 | // The var name I picked else gSeed will be the defaulted to name |
| 67 | #define SEEDNAME gSeed |
| 68 | // The name I picked for a file handle name else gSeedFileHndl will be the defaulted to name |
| 69 | #define HDNLNAME gSeedFileHndl |
| 70 | // I want to force the seed to 1 for development, remember to REMOVE LATER. |
| 71 | #define SEEDFORCE 1 |
| 72 | // Get the seeding code |
| 73 | #include "seeding.vri" |
| 74 | |
| 75 | hndl = new(); |
| 76 | |
| 77 | } |
| 78 | |
| 79 | */ |
| 80 | |
| 81 | |
| 82 | reg [31:0] seedingtmpseed = 0; |
| 83 | string which; |
| 84 | |
| 85 | #ifdef NTB |
| 86 | string gTestNameAsm, gTestNameVera, gAltTestname; |
| 87 | which = "NTB"; |
| 88 | #else |
| 89 | reg [1024:0] gTestNameAsm, gTestNameVera, gAltTestname; |
| 90 | which = "VERA"; |
| 91 | #endif |
| 92 | |
| 93 | |
| 94 | gTestNameAsm = ""; |
| 95 | gTestNameVera = ""; |
| 96 | gAltTestname = ""; |
| 97 | |
| 98 | #ifndef HDNLNAME |
| 99 | #define HDNLNAME gSeedFileHndl |
| 100 | #endif |
| 101 | |
| 102 | #ifndef SEEDNAME |
| 103 | #define SEEDNAME gSeed |
| 104 | #endif |
| 105 | |
| 106 | #ifdef SEEDFORCE |
| 107 | SEEDNAME = SEEDFORCE; |
| 108 | #else |
| 109 | mGetPlusargDec(tg_seed=,seedingtmpseed); |
| 110 | if (seedingtmpseed[31]) { |
| 111 | seedingtmpseed[31] = 0; // don't want negative integer |
| 112 | printf("SEED---> sims +tg_seed: was modified to not be a negative integer\n"); |
| 113 | } |
| 114 | SEEDNAME = seedingtmpseed; // cast reg to positive integer |
| 115 | printf("SEED---> sims +tg_seed: %d", SEEDNAME); |
| 116 | // |
| 117 | // NOTE: use sims -tg_seed= to pass in a seed. |
| 118 | // DO NOT use sims -vcs_run_args=+tg_seed=, it will not work! |
| 119 | // |
| 120 | #endif |
| 121 | |
| 122 | |
| 123 | // +vera_diag_name= |
| 124 | // +asm_diag_name= |
| 125 | // +sjm_diag_name= |
| 126 | // +tap_diag_name= |
| 127 | // +tpt_diag_name= |
| 128 | // +pci_diag_name= |
| 129 | // +image_diag_name= |
| 130 | // +efuse_image_name= |
| 131 | // +vera_config_name= |
| 132 | if (mChkPlusarg(vera_diag_name=)) mGetPlusargStr(vera_diag_name=,gTestNameVera); |
| 133 | if (mChkPlusarg(asm_diag_name=)) mGetPlusargStr(asm_diag_name=,gTestNameAsm); |
| 134 | if (mChkPlusarg(test=)) mGetPlusargStr(test=,gAltTestname); |
| 135 | |
| 136 | // NOTE: random always returns a positive integer. bit 31 ALWAYS ZERO. |
| 137 | // urandom always returns a unsigned integer. bit 31 ALWAYS RANDOM. |
| 138 | // If you do myInt = urandom(); you will get a negetive integer 50% of time! |
| 139 | // If you do myReg[31:0] = random(); you will always have [31] = 0. |
| 140 | // Read this again... |
| 141 | |
| 142 | rand48(SEEDNAME);urand48(SEEDNAME); // do not use these 48 calls |
| 143 | urandom(SEEDNAME);random(SEEDNAME); // not really needed but safe |
| 144 | srandom(SEEDNAME); // seeds main generator and random and urandom |
| 145 | |
| 146 | // store the seed. Lost seeds after re-runs are a real bummer! |
| 147 | HDNLNAME = fopen( "./seeds.log", "a" ); |
| 148 | if ( HDNLNAME == 0 ) { |
| 149 | printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); |
| 150 | printf("The %s random generators have just been seeded with %d\n", which, SEEDNAME); |
| 151 | printf("You need to know this SEED if you want to reproduce failures!\n"); |
| 152 | printf("Use sims -tg_seed=%0d to reproduce this run.\n",SEEDNAME); |
| 153 | printf("Seed not saved to file!!! Make sure that you are the owner of seeds.log and that it has 664 protection.\n"); |
| 154 | printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); |
| 155 | } else { |
| 156 | printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); |
| 157 | printf("The %s random generators have just been seeded with %d\n",which, SEEDNAME); |
| 158 | printf("You need to know this SEED if you want to reproduce failures!\n"); |
| 159 | printf("Use sims -tg_seed=%0d to reproduce this run!\n",SEEDNAME); |
| 160 | printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); |
| 161 | fprintf(HDNLNAME, "---------------------------------------------------------------------\n"); |
| 162 | fprintf(HDNLNAME, "Test %s %s %s is using seed %d\n", gTestNameAsm, gTestNameVera, gAltTestname, SEEDNAME); |
| 163 | fprintf(HDNLNAME, "Test completion message should follow indicating passed/failed/stopped!\n"); |
| 164 | fclose(HDNLNAME); |
| 165 | // NOTE: 'end of test' code should update this file to indicate status, |
| 166 | // that way you know which seed was the failing one, which is the one |
| 167 | // you are looking for... I need to make a seedingEnd.vri to do that. jp |
| 168 | } |