| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: SS_GoodBadTrap.cc |
| 4 | // Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 5 | // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
| 6 | // |
| 7 | // The above named program is free software; you can redistribute it and/or |
| 8 | // modify it under the terms of the GNU General Public |
| 9 | // License version 2 as published by the Free Software Foundation. |
| 10 | // |
| 11 | // The above named program is distributed in the hope that it will be |
| 12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | // General Public License for more details. |
| 15 | // |
| 16 | // You should have received a copy of the GNU General Public |
| 17 | // License along with this work; if not, write to the Free Software |
| 18 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | // |
| 20 | // ========== Copyright Header End ============================================ |
| 21 | |
| 22 | #include "SS_GoodBadTrap.h" |
| 23 | |
| 24 | SS_GoodBadTrap::SS_GoodBadTrap( )/*{{{*/ |
| 25 | : |
| 26 | good_trap_count(0), |
| 27 | bad_trap_count(0) |
| 28 | {} |
| 29 | /*}}}*/ |
| 30 | |
| 31 | void SS_GoodBadTrap::read_good_bad_trap( int va_bits )/*{{{*/ |
| 32 | { |
| 33 | // extract good/bad trap addresses from symbol.tbl |
| 34 | |
| 35 | // N2 sample: |
| 36 | // .HTRAPS.HT0_GoodTrap_0x100 0000000000082000 X 0000082000 |
| 37 | // .HTRAPS.HT0_GoodTrap_0x1a0 0000000000083400 X 0000083400 |
| 38 | // .HTRAPS.old_good_trap 0000000000083400 X 0000083400 |
| 39 | // .HTRAPS.good_trap 0000000000083400 X 0000083400 |
| 40 | // .TRAPS.T0_GoodTrap_0x100 0000000000122000 0000122000 0200122000 |
| 41 | // .TRAPS.T1_GoodTrap_0x100 0000000000126000 0000126000 0200126000 |
| 42 | // .HTRAPS.HT0_BadTrap_0x101 0000000000082020 X 0000082020 |
| 43 | // .HTRAPS.HT0_BadTrap_0x1a1 0000000000083420 X 0000083420 |
| 44 | // .HTRAPS.bad_trap 0000000000083420 X 0000083420 |
| 45 | // .TRAPS.T0_BadTrap_0x101 0000000000122020 0000122020 0200122020 |
| 46 | // .TRAPS.T1_BadTrap_0x101 0000000000126020 0000126020 0200126020 |
| 47 | |
| 48 | // N3 sample: |
| 49 | // .RED_SEC.good_trap fffffffff000013c X fff000013c |
| 50 | // .RED_SEC.bad_trap fffffffff0000140 X fff0000140 |
| 51 | // N3 sample, of a different diag |
| 52 | // .RED_SEC.good_trap fffffffff0005138 X fff0005138 |
| 53 | // .RED_SEC.bad_trap fffffffff000514c X fff000514c |
| 54 | |
| 55 | char l[256]; |
| 56 | char *s1, *s2; |
| 57 | SS_Vaddr n; |
| 58 | FILE *f = fopen("symbol.tbl", "r"); |
| 59 | if (f == NULL) |
| 60 | { |
| 61 | // file is not available for read |
| 62 | fprintf(stderr, "WARNING: symbol.tbl is not loaded\n"); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | while (fgets(l, sizeof(l), f)) |
| 67 | { |
| 68 | s1 = strtok(l, " \t\n"); |
| 69 | while (s1) |
| 70 | { |
| 71 | if (strstr(s1, "GoodTrap") || |
| 72 | strstr(s1, "good_trap")) |
| 73 | { |
| 74 | s2 = strtok(NULL, " \t\n"); |
| 75 | if (s2) { |
| 76 | n = strtoull(s2, NULL, 16); |
| 77 | //fprintf(stderr, "GOOD %s %llx\n", s1, n); |
| 78 | // sign extends the given virtual address from VA_BITS to 64 bits |
| 79 | n = (n << (64 - va_bits)) >> (64 - va_bits); |
| 80 | int match = 0; |
| 81 | for (int i = 0; i < good_trap_count; i++) |
| 82 | { |
| 83 | if (n == good_traps[i]) |
| 84 | { |
| 85 | match = 1; |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | if (match == 0) |
| 90 | { |
| 91 | good_traps[good_trap_count] = n; |
| 92 | good_trap_count++; |
| 93 | } |
| 94 | // done with this line, go read the next line |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | else if (strstr(s1, "BadTrap") || |
| 99 | strstr(s1, "bad_trap")) |
| 100 | { |
| 101 | s2 = strtok(NULL, " \t\n"); |
| 102 | if (s2) { |
| 103 | n = strtoull(s2, NULL, 16); |
| 104 | //fprintf(stderr, "BAD %s %llx\n", s1, n); |
| 105 | // sign extends the given virtual address from VA_BITS to 64 bits |
| 106 | n = (n << (64 - va_bits)) >> (64 - va_bits); |
| 107 | int match = 0; |
| 108 | for (int i = 0; i < bad_trap_count; i++) |
| 109 | { |
| 110 | if (n == bad_traps[i]) |
| 111 | { |
| 112 | match = 1; |
| 113 | break; |
| 114 | } |
| 115 | } |
| 116 | if (match == 0) |
| 117 | { |
| 118 | bad_traps[bad_trap_count] = n; |
| 119 | bad_trap_count++; |
| 120 | } |
| 121 | // done with this line, go read the next line |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | s1 = strtok(NULL, " \t\n"); |
| 126 | } |
| 127 | } |
| 128 | fclose(f); |
| 129 | } |
| 130 | /*}}}*/ |
| 131 | |
| 132 | int SS_GoodBadTrap::hit_good_bad_trap( SS_Vaddr pc )/*{{{*/ |
| 133 | { |
| 134 | for (int i = 0; i < good_trap_count; i++) |
| 135 | { |
| 136 | if (pc == good_traps[i]) |
| 137 | { |
| 138 | fflush(stdout); |
| 139 | fprintf(stdout, "\nHit good trap %#llx\n\n", pc); |
| 140 | return -1; |
| 141 | } |
| 142 | } |
| 143 | for (int i = 0; i < bad_trap_count; i++) |
| 144 | { |
| 145 | if (pc == bad_traps[i]) |
| 146 | { |
| 147 | // .RED_SEC.bad_trap fffffffff0000140 X fff0000140 |
| 148 | fflush(stdout); |
| 149 | fprintf(stdout, "\nHit bad trap %#llx\n\n", pc); |
| 150 | return -1; |
| 151 | } |
| 152 | } |
| 153 | // no match |
| 154 | return 0; |
| 155 | } |
| 156 | /*}}}*/ |