| 1 | /* |
| 2 | * ========== Copyright Header Begin ========================================== |
| 3 | * |
| 4 | * OpenSPARC T2 Processor File: rz3_section.h |
| 5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. |
| 6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. |
| 7 | * |
| 8 | * The above named program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public |
| 10 | * License version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * The above named program is distributed in the hope that it will be |
| 13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public |
| 18 | * License along with this work; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | * ========== Copyright Header End ============================================ |
| 22 | */ |
| 23 | /* rz3_section.h |
| 24 | * rz3 section header, section data etc. |
| 25 | */ |
| 26 | |
| 27 | #ifndef _rz3_section_h_ |
| 28 | #define _rz3_section_h_ |
| 29 | |
| 30 | #include <stdio.h> |
| 31 | #include <strings.h> |
| 32 | |
| 33 | #include "rz3utils.h" |
| 34 | |
| 35 | /* we use a 16-character magic string to identify an rz3 compressed trace |
| 36 | * starting with "RZ3 " and ending with a $ and the null-terminator (\0). |
| 37 | * The remainder (16-4-2) is a 10-digit random integer |
| 38 | */ |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | /* rz3 section header magic: "RZ3 SHDR<int6>$" */ |
| 44 | #define rz3_shdr_magic "3ZR SHDR297302$" |
| 45 | struct rz3_section_header { |
| 46 | char magic[16]; |
| 47 | |
| 48 | // other meta data about the section |
| 49 | int nrecords; |
| 50 | |
| 51 | uint64_t CompressedBufferSize; |
| 52 | |
| 53 | int rz3_bitarray_counts[rstzip3::bitarray_count]; |
| 54 | |
| 55 | class rstzip3 * rz3obj; |
| 56 | |
| 57 | rz3_section_header(class rstzip3 * arg_rz3obj) { |
| 58 | rz3obj = arg_rz3obj; |
| 59 | } |
| 60 | |
| 61 | void clear(); |
| 62 | |
| 63 | bool write(gzFile gzf); |
| 64 | |
| 65 | bool read(gzFile gzf); |
| 66 | |
| 67 | bool write(FILE * fp); |
| 68 | |
| 69 | bool read(FILE * fp); |
| 70 | |
| 71 | bool sanity_check(); |
| 72 | |
| 73 | #if defined(ARCH_AMD64) |
| 74 | void flip_endianess(); |
| 75 | #endif |
| 76 | }; // struct rz3_section_header |
| 77 | struct rz3_section_header_file { |
| 78 | char magic[16]; |
| 79 | int nrecords; |
| 80 | uint64_t CompressedBufferSize; |
| 81 | int rz3_bitarray_counts[rstzip3::bitarray_count]; |
| 82 | }; |
| 83 | |
| 84 | |
| 85 | #if 0 |
| 86 | enum rz3_instr_pred_mask_e { |
| 87 | rz3_instr_pred_cpuid = 0x1, |
| 88 | rz3_instr_pred_pc = 0x2, |
| 89 | rz3_instr_pred_instr = 0x4, |
| 90 | rz3_instr_pred_bt = 0x8, |
| 91 | rz3_instr_pred_an = 0x10, |
| 92 | rz3_instr_pred_tr = 0x20, |
| 93 | rz3_instr_pred_pr = 0x40, |
| 94 | rz3_instr_pred_ea_valid = 0x80, |
| 95 | |
| 96 | rz3_instr_pred_all = 0xff |
| 97 | }; |
| 98 | |
| 99 | union rz3_instr_pred_u { |
| 100 | |
| 101 | struct { |
| 102 | unsigned char cpuid: 1; |
| 103 | unsigned char pc: 1; |
| 104 | unsigned char instr: 1; |
| 105 | unsigned char bt: 1; |
| 106 | unsigned char an: 1; |
| 107 | unsigned char tr: 1; |
| 108 | unsigned char pr: 1; |
| 109 | unsigned char ea_valid: 1; |
| 110 | } pred; |
| 111 | |
| 112 | unsigned char b; |
| 113 | |
| 114 | }; // union rz3_instr_pred_u |
| 115 | #endif // #if 0 |
| 116 | |
| 117 | /* the order in which the compressed data arrays are stored |
| 118 | * NOTE: this struct is NOT read or written to/from an rz3 compressed file |
| 119 | * it is included here to indicate the *order* in which the data arrays are stored |
| 120 | */ |
| 121 | struct rz3_section_data { |
| 122 | |
| 123 | // rz3_rst_array * raw_records_array; // records that we do not try to compress |
| 124 | |
| 125 | rz3_bitarray * bitarrays[rstzip3::bitarray_count]; |
| 126 | |
| 127 | // we read(write) section header to determine (based on) section data |
| 128 | // note: some bitarray sizes changed in v3.20 |
| 129 | // the pre320 flag is used to determine version-specific bitarray sizes |
| 130 | rz3_section_data(rz3_section_header * arg_shdr, bool pre320); |
| 131 | |
| 132 | ~rz3_section_data(); |
| 133 | |
| 134 | void clear(); |
| 135 | |
| 136 | void update_counts(); |
| 137 | |
| 138 | void print(); // print stats |
| 139 | |
| 140 | void print_totals(); |
| 141 | |
| 142 | // bool write(FILE * fp); // returns false on error |
| 143 | bool write(gzFile gzf); // returns false on error |
| 144 | |
| 145 | bool read(gzFile gzf); |
| 146 | |
| 147 | bool write(FILE * fp); |
| 148 | |
| 149 | bool read(FILE * fp); |
| 150 | |
| 151 | rz3_section_header * shdr; |
| 152 | |
| 153 | uint64_t total_nrecords; |
| 154 | uint64_t total_CompressedBufferSize; |
| 155 | uint64_t total_rz3_bitarray_counts[rstzip3::bitarray_count]; |
| 156 | uint64_t total_rz3_bitarray_sums[rstzip3::bitarray_count]; |
| 157 | }; // struct rz3_section_data |
| 158 | |
| 159 | |
| 160 | |
| 161 | // this struct contains temp state variables used to compress/decompress records |
| 162 | struct rz3_percpu_data { |
| 163 | int cpuid; |
| 164 | |
| 165 | uint64_t pred_pc; |
| 166 | uint64_t pred_npc; |
| 167 | |
| 168 | uint16_t pred_icontext; |
| 169 | uint16_t pred_dcontext; |
| 170 | |
| 171 | int pred_amask; |
| 172 | int pred_an; |
| 173 | int pred_hpriv; |
| 174 | int pred_pr; |
| 175 | |
| 176 | bool call_delay_slot; |
| 177 | |
| 178 | int pending_pavadiff_idx; // -1 implies invalid |
| 179 | bool pending_pavadiff_pc_pa_va_pred; |
| 180 | bool pending_pavadiff_ea_pa_va_pred; |
| 181 | |
| 182 | uint64_t prev_pc; // for regval predictor lookup |
| 183 | |
| 184 | uint64_t rfs_prev_npc; // for rfs branch trace records |
| 185 | |
| 186 | rz3_valuecache * valuecache; |
| 187 | |
| 188 | rz3iu_icache * icache; |
| 189 | |
| 190 | rz3iu_brpred * bp; |
| 191 | |
| 192 | rz3_ras * ras; |
| 193 | |
| 194 | rz3_table<uint64_t> * jmpl_table; |
| 195 | |
| 196 | rz3_table<uint64_t> * itlb; |
| 197 | rz3_table<uint64_t> * dtlb; |
| 198 | |
| 199 | rz3_table<uint64_t> * rfs_pc_pred_table; |
| 200 | |
| 201 | uint8_t * regval_regtype_tbl[2]; |
| 202 | uint8_t * regval_regid_tbl[2]; |
| 203 | |
| 204 | |
| 205 | uint32_t last_instr; |
| 206 | |
| 207 | uint64_t * regs; |
| 208 | uint8_t ccr; |
| 209 | |
| 210 | enum consts { |
| 211 | rz3_tdata_jmpl_table_size = 2<<10, |
| 212 | rz3_tdata_regval_regtype_tbl_size = 1<<16, |
| 213 | rz3_tdata_regval_regid_tbl_size = 1<<16, |
| 214 | rz3_tdata_itlb_size = 512, |
| 215 | rz3_tdata_dtlb_size = 2048, |
| 216 | rz3_tdata_rfs_pc_pred_table_size = 1<<16 |
| 217 | }; |
| 218 | |
| 219 | |
| 220 | rz3_percpu_data(int arg_cpuid); |
| 221 | ~rz3_percpu_data(); |
| 222 | void clear(); |
| 223 | |
| 224 | |
| 225 | }; // rz3_percpu_data |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | #endif // _rz3_section_h_ |