| 1 |
17 |
julius |
/*
|
| 2 |
|
|
Or1K instruction set-specific decoding and analysis functions.
|
| 3 |
16 |
julius |
|
| 4 |
17 |
julius |
Julius Baxter, julius.baxter@orsoc.se
|
| 5 |
16 |
julius |
|
| 6 |
17 |
julius |
*/
|
| 7 |
16 |
julius |
|
| 8 |
|
|
|
| 9 |
25 |
julius |
// Enable debug printf'ing straight to stdout -- will be a LOT of output
|
| 10 |
|
|
#define DEBUG_PRINT 0
|
| 11 |
17 |
julius |
|
| 12 |
25 |
julius |
// Choose the output format, uncomment only one
|
| 13 |
26 |
julius |
#define DISPLAY_STRING
|
| 14 |
|
|
//#define DISPLAY_CSV
|
| 15 |
25 |
julius |
|
| 16 |
|
|
|
| 17 |
16 |
julius |
// Struct for information about the register to be confugred
|
| 18 |
|
|
// Set to 1 to enable
|
| 19 |
|
|
struct or1k_32_instruction_properties
|
| 20 |
|
|
{
|
| 21 |
|
|
int has_jumptarg;
|
| 22 |
|
|
int has_branchtarg;
|
| 23 |
|
|
|
| 24 |
|
|
int has_imm;
|
| 25 |
|
|
int has_split_imm;
|
| 26 |
|
|
|
| 27 |
|
|
int has_rD;
|
| 28 |
|
|
int has_rA;
|
| 29 |
|
|
int has_rB;
|
| 30 |
|
|
|
| 31 |
|
|
char *insn_string;
|
| 32 |
18 |
julius |
int insn_index;
|
| 33 |
16 |
julius |
|
| 34 |
|
|
};
|
| 35 |
|
|
|
| 36 |
19 |
julius |
|
| 37 |
|
|
// Structs for internal statistics keeping
|
| 38 |
|
|
|
| 39 |
|
|
struct or1k_value_list
|
| 40 |
|
|
{
|
| 41 |
|
|
|
| 42 |
|
|
#define OR1K_VALUE_MAX_ENTRIES 64
|
| 43 |
|
|
int count;
|
| 44 |
|
|
// [value][occurances_of_value]
|
| 45 |
|
|
int32_t values[OR1K_VALUE_MAX_ENTRIES][2];
|
| 46 |
|
|
|
| 47 |
|
|
};
|
| 48 |
|
|
|
| 49 |
|
|
struct or1k_insn_info
|
| 50 |
|
|
{
|
| 51 |
|
|
char* insn_string;
|
| 52 |
|
|
|
| 53 |
|
|
int count;
|
| 54 |
|
|
|
| 55 |
|
|
int has_branchtarg;
|
| 56 |
|
|
struct or1k_value_list branch_info;
|
| 57 |
|
|
|
| 58 |
|
|
int has_imm;
|
| 59 |
|
|
struct or1k_value_list imm_info;
|
| 60 |
|
|
|
| 61 |
|
|
int has_rD;
|
| 62 |
|
|
int rD_use_freq[32];
|
| 63 |
|
|
int has_rA;
|
| 64 |
|
|
int rA_use_freq[32];
|
| 65 |
|
|
int has_rB;
|
| 66 |
|
|
int rB_use_freq[32];
|
| 67 |
|
|
|
| 68 |
|
|
// Set maximum instructions in a row we'll keep track of, starting at pairs
|
| 69 |
|
|
#define OR1K_MAX_GROUPINGS_ANALYSIS 4
|
| 70 |
22 |
julius |
#define OR1K_MAX_ENTRIES_PER_GROUP 500
|
| 71 |
19 |
julius |
// Format of grouping data:
|
| 72 |
|
|
//
|
| 73 |
|
|
// 1st dimension: A list for each n-tuple group we're keeping track of
|
| 74 |
|
|
// (starting at pairs of instructions)
|
| 75 |
|
|
//
|
| 76 |
|
|
// 2nd dimension: Stores the list entries for the 1st dimension-tuple
|
| 77 |
|
|
// grouping. The number in [x][0][0] is the number of entries in the list so
|
| 78 |
|
|
// far, beginning at 0. The actual entries with data for grouping x start at
|
| 79 |
|
|
// [x][1][], where that entry holds the 1st x+2-tuple grouping information
|
| 80 |
|
|
// (eg. at x=0, [0][1][] is the first entry for/ pair instruction
|
| 81 |
|
|
// information, x=1, is for triples, x=2 quadruples, etc)
|
| 82 |
|
|
//
|
| 83 |
|
|
// 3rd dimension: Store up to x+2 instruction indexes (where x is the first
|
| 84 |
|
|
// dimension index, meaning this particular data is for a (x+2)-tuple set)
|
| 85 |
|
|
// and then a frequency count for this set (in index (x+2) of the third
|
| 86 |
|
|
// dimension array). Note we will have the index for the instruction this
|
| 87 |
|
|
// struct corresponds to in [x][n][(x+2)-1], which seems redundant, but can
|
| 88 |
|
|
// help processing later on. The final entry after the instruction indexes
|
| 89 |
|
|
// is the occurance count for this particular set (at [x][n][x+2])
|
| 90 |
|
|
//
|
| 91 |
|
|
// Note that we will have empty entries in the third dimension arrays for all
|
| 92 |
|
|
// but the last in the list of n-tuples. This is to save doing tricky naming
|
| 93 |
|
|
// defines and, in the future, if we would like to analyse sets that are
|
| 94 |
|
|
// bigger or smaller, hopefully all we need to do is change a single define.
|
| 95 |
|
|
//
|
| 96 |
|
|
int groupings[OR1K_MAX_GROUPINGS_ANALYSIS][OR1K_MAX_ENTRIES_PER_GROUP+1][OR1K_MAX_GROUPINGS_ANALYSIS+1];
|
| 97 |
|
|
|
| 98 |
|
|
};
|
| 99 |
|
|
|
| 100 |
|
|
// This number should correspond to the maximum insn_index we assign in the
|
| 101 |
|
|
// analyse function
|
| 102 |
26 |
julius |
#define OR1K_32_MAX_INSNS 118
|
| 103 |
19 |
julius |
extern struct or1k_insn_info * or1k_32_insns[OR1K_32_MAX_INSNS];
|
| 104 |
|
|
|
| 105 |
|
|
|
| 106 |
17 |
julius |
// OpenRISC 1000 32-bit instruction defines, helping us
|
| 107 |
|
|
// extract fields of the instructions
|
| 108 |
|
|
|
| 109 |
16 |
julius |
// Instruction decode/set its options
|
| 110 |
|
|
int or1k_32_analyse_insn(uint32_t insn,
|
| 111 |
|
|
struct or1k_32_instruction_properties *insn_props);
|
| 112 |
|
|
|
| 113 |
|
|
|
| 114 |
|
|
// Stat collection entry-oint
|
| 115 |
|
|
void or1k_32_collect_stats(uint32_t insn,
|
| 116 |
|
|
struct or1k_32_instruction_properties * insn_props);
|
| 117 |
|
|
|
| 118 |
|
|
|
| 119 |
|
|
// List management/analysis functions
|
| 120 |
|
|
// Reset lists
|
| 121 |
|
|
void or1k_32_insn_lists_init(void);
|
| 122 |
|
|
|
| 123 |
|
|
// Add the stats for this one
|
| 124 |
18 |
julius |
void or1k_32_insn_lists_add(uint32_t insn,
|
| 125 |
16 |
julius |
struct or1k_32_instruction_properties *insn_props);
|
| 126 |
|
|
|
| 127 |
19 |
julius |
// Record the occurance of a group of instructions
|
| 128 |
|
|
void or1k_32_ntuple_add(int n,
|
| 129 |
|
|
struct or1k_32_instruction_properties *insn_props);
|
| 130 |
|
|
|
| 131 |
17 |
julius |
// Print out some useful information
|
| 132 |
|
|
void or1k_32_generate_stats(FILE * stream);
|
| 133 |
|
|
|
| 134 |
16 |
julius |
// Free lists
|
| 135 |
|
|
void or1k_32_insn_lists_free(void);
|
| 136 |
|
|
|
| 137 |
|
|
#define JUMPTARG_MASK 0x3ffffff
|
| 138 |
|
|
|
| 139 |
|
|
#define insn_or1k_opcode(x) (x>>26 & 0x3f)
|
| 140 |
|
|
|
| 141 |
|
|
#define insn_or1k_32_rD(x) (((x>>21)&0x1f))
|
| 142 |
|
|
#define insn_or1k_32_rA(x) (((x>>16)&0x1f))
|
| 143 |
|
|
#define insn_or1k_32_rB(x) (((x>>11)&0x1f))
|
| 144 |
|
|
#define insn_or1k_32_imm(x) (x&0xffff)
|
| 145 |
|
|
#define insn_or1k_32_split_imm(x) ((((x>>21)&0x1f)<<11)|(x&0x7ff))
|
| 146 |
|
|
|
| 147 |
|
|
#define insn_or1k_opcode_0x00_get_jumptarg(x) (x&JUMPTARG_MASK)
|
| 148 |
|
|
|
| 149 |
|
|
#define insn_or1k_opcode_0x01_get_jumptarg(x) (x&JUMPTARG_MASK)
|
| 150 |
|
|
|
| 151 |
|
|
#define insn_or1k_opcode_0x03_get_branchoff(x) (x&JUMPTARG_MASK)
|
| 152 |
|
|
|
| 153 |
|
|
#define insn_or1k_opcode_0x04_get_branchoff(x) (x&JUMPTARG_MASK)
|
| 154 |
|
|
|
| 155 |
|
|
#define insn_or1k_opcode_0x05_get_noop_id(x) ((x>>24) & 0x3)
|
| 156 |
|
|
#define insn_or1k_opcode_0x05_get_imm(x) insn_or1k_32_imm(x)
|
| 157 |
|
|
|
| 158 |
|
|
#define insn_or1k_opcode_0x06_get_rD(x) insn_or1k_32_rD(x)
|
| 159 |
|
|
#define insn_or1k_opcode_0x06_get_id(x) ((x>>16) & 0x1)
|
| 160 |
|
|
#define insn_or1k_opcode_0x06_get_imm(x) insn_or1k_32_imm(x)
|
| 161 |
|
|
|
| 162 |
|
|
/* N/A: opcode 0x7 */
|
| 163 |
|
|
|
| 164 |
|
|
#define insn_or1k_opcode_0x08_get_id(x) ((x>>23)&0x7)
|
| 165 |
|
|
#define insn_or1k_opcode_0x08_get_imm(x) insn_or1k_32_imm(x)
|
| 166 |
|
|
|
| 167 |
|
|
#define insn_or1k_opcode_0x0a_get_rD(x) insn_or1k_32_rD(x)
|
| 168 |
|
|
#define insn_or1k_opcode_0x0a_get_rA(x) insn_or1k_32_rA(x)
|
| 169 |
|
|
#define insn_or1k_opcode_0x0a_get_rB(x) insn_or1k_32_rB(x)
|
| 170 |
|
|
#define insn_or1k_opcode_0x0a_get_op_hi(x) ((x>>4)&0xf)
|
| 171 |
|
|
#define insn_or1k_opcode_0x0a_get_op_lo(x) (x&0xf)
|
| 172 |
|
|
|
| 173 |
|
|
/* N/A: opcodes 0xb,c,d,e,f,10 */
|
| 174 |
|
|
|
| 175 |
|
|
#define insn_or1k_opcode_0x11_get_rB(x) insn_or1k_32_rB(x)
|
| 176 |
|
|
|
| 177 |
|
|
#define insn_or1k_opcode_0x12_get_rB(x) insn_or1k_32_rB(x)
|
| 178 |
|
|
|
| 179 |
|
|
#define insn_or1k_opcode_0x13_get_rA(x) insn_or1k_32_rA(x)
|
| 180 |
|
|
#define insn_or1k_opcode_0x13_get_imm(x) insn_or1k_32_split_imm(x)
|
| 181 |
|
|
|
| 182 |
|
|
/* N/A: opcodes 0x14,15, 16, 17, 18, 19, 1a, 1b */
|
| 183 |
|
|
|
| 184 |
|
|
#define insn_or1k_opcode_0x20_get_rD(x) insn_or1k_32_rD(x)
|
| 185 |
|
|
#define insn_or1k_opcode_0x20_get_rA(x) insn_or1k_32_rA(x)
|
| 186 |
|
|
#define insn_or1k_opcode_0x20_get_imm(x) insn_or1k_32_imm(x)
|
| 187 |
|
|
|
| 188 |
|
|
|
| 189 |
|
|
#define insn_or1k_opcode_0x21_get_rD(x) insn_or1k_32_rD(x)
|
| 190 |
|
|
#define insn_or1k_opcode_0x21_get_rA(x) insn_or1k_32_rA(x)
|
| 191 |
|
|
#define insn_or1k_opcode_0x21_get_imm(x) insn_or1k_32_imm(x)
|
| 192 |
|
|
|
| 193 |
|
|
|
| 194 |
|
|
#define insn_or1k_opcode_0x22_get_rD(x) insn_or1k_32_rD(x)
|
| 195 |
|
|
#define insn_or1k_opcode_0x22_get_rA(x) insn_or1k_32_rA(x)
|
| 196 |
|
|
#define insn_or1k_opcode_0x22_get_imm(x) insn_or1k_32_imm(x)
|
| 197 |
|
|
|
| 198 |
|
|
|
| 199 |
|
|
#define insn_or1k_opcode_0x23_get_rD(x) insn_or1k_32_rD(x)
|
| 200 |
|
|
#define insn_or1k_opcode_0x23_get_rA(x) insn_or1k_32_rA(x)
|
| 201 |
|
|
#define insn_or1k_opcode_0x23_get_imm(x) insn_or1k_32_imm(x)
|
| 202 |
|
|
|
| 203 |
|
|
|
| 204 |
|
|
#define insn_or1k_opcode_0x24_get_rD(x) insn_or1k_32_rD(x)
|
| 205 |
|
|
#define insn_or1k_opcode_0x24_get_rA(x) insn_or1k_32_rA(x)
|
| 206 |
|
|
#define insn_or1k_opcode_0x24_get_imm(x) insn_or1k_32_imm(x)
|
| 207 |
|
|
|
| 208 |
|
|
|
| 209 |
|
|
#define insn_or1k_opcode_0x25_get_rD(x) insn_or1k_32_rD(x)
|
| 210 |
|
|
#define insn_or1k_opcode_0x25_get_rA(x) insn_or1k_32_rA(x)
|
| 211 |
|
|
#define insn_or1k_opcode_0x25_get_imm(x) insn_or1k_32_imm(x)
|
| 212 |
|
|
|
| 213 |
|
|
|
| 214 |
|
|
#define insn_or1k_opcode_0x26_get_rD(x) insn_or1k_32_rD(x)
|
| 215 |
|
|
#define insn_or1k_opcode_0x26_get_rA(x) insn_or1k_32_rA(x)
|
| 216 |
|
|
#define insn_or1k_opcode_0x26_get_imm(x) insn_or1k_32_imm(x)
|
| 217 |
|
|
|
| 218 |
|
|
|
| 219 |
|
|
#define insn_or1k_opcode_0x27_get_rD(x) insn_or1k_32_rD(x)
|
| 220 |
|
|
#define insn_or1k_opcode_0x27_get_rA(x) insn_or1k_32_rA(x)
|
| 221 |
|
|
#define insn_or1k_opcode_0x27_get_imm(x) insn_or1k_32_imm(x)
|
| 222 |
|
|
|
| 223 |
|
|
#define insn_or1k_opcode_0x28_get_rD(x) insn_or1k_32_rD(x)
|
| 224 |
|
|
#define insn_or1k_opcode_0x28_get_rA(x) insn_or1k_32_rA(x)
|
| 225 |
|
|
#define insn_or1k_opcode_0x28_get_imm(x) insn_or1k_32_imm(x)
|
| 226 |
|
|
|
| 227 |
|
|
|
| 228 |
|
|
#define insn_or1k_opcode_0x29_get_rD(x) insn_or1k_32_rD(x)
|
| 229 |
|
|
#define insn_or1k_opcode_0x29_get_rA(x) insn_or1k_32_rA(x)
|
| 230 |
|
|
#define insn_or1k_opcode_0x29_get_imm(x) insn_or1k_32_imm(x)
|
| 231 |
|
|
|
| 232 |
|
|
|
| 233 |
|
|
#define insn_or1k_opcode_0x2a_get_rD(x) insn_or1k_32_rD(x)
|
| 234 |
|
|
#define insn_or1k_opcode_0x2a_get_rA(x) insn_or1k_32_rA(x)
|
| 235 |
|
|
#define insn_or1k_opcode_0x2a_get_imm(x) insn_or1k_32_imm(x)
|
| 236 |
|
|
|
| 237 |
|
|
|
| 238 |
|
|
#define insn_or1k_opcode_0x2b_get_rD(x) insn_or1k_32_rD(x)
|
| 239 |
|
|
#define insn_or1k_opcode_0x2b_get_rA(x) insn_or1k_32_rA(x)
|
| 240 |
|
|
#define insn_or1k_opcode_0x2b_get_imm(x) insn_or1k_32_imm(x)
|
| 241 |
|
|
|
| 242 |
|
|
|
| 243 |
|
|
#define insn_or1k_opcode_0x2c_get_rD(x) insn_or1k_32_rD(x)
|
| 244 |
|
|
#define insn_or1k_opcode_0x2c_get_rA(x) insn_or1k_32_rA(x)
|
| 245 |
|
|
#define insn_or1k_opcode_0x2c_get_imm(x) insn_or1k_32_imm(x)
|
| 246 |
|
|
|
| 247 |
|
|
|
| 248 |
|
|
#define insn_or1k_opcode_0x2d_get_rD(x) insn_or1k_32_rD(x)
|
| 249 |
|
|
#define insn_or1k_opcode_0x2d_get_rA(x) insn_or1k_32_rA(x)
|
| 250 |
|
|
#define insn_or1k_opcode_0x2d_get_imm(x) insn_or1k_32_imm(x)
|
| 251 |
|
|
|
| 252 |
|
|
|
| 253 |
|
|
#define insn_or1k_opcode_0x2e_get_rD(x) insn_or1k_32_rD(x)
|
| 254 |
|
|
#define insn_or1k_opcode_0x2e_get_rA(x) insn_or1k_32_rA(x)
|
| 255 |
|
|
#define insn_or1k_opcode_0x2e_get_op(x) ((x>>6)&0x3)
|
| 256 |
|
|
#define insn_or1k_opcode_0x2e_get_imm(x) ((x&3f))
|
| 257 |
|
|
|
| 258 |
|
|
|
| 259 |
|
|
#define insn_or1k_opcode_0x2f_get_op(x) insn_or1k_32_rD(x)
|
| 260 |
|
|
#define insn_or1k_opcode_0x2f_get_rA(x) insn_or1k_32_rA(x)
|
| 261 |
|
|
#define insn_or1k_opcode_0x2f_get_imm(x) insn_or1k_32_imm(x)
|
| 262 |
|
|
|
| 263 |
|
|
|
| 264 |
|
|
#define insn_or1k_opcode_0x30_get_rA(x) insn_or1k_32_rA(x)
|
| 265 |
|
|
#define insn_or1k_opcode_0x30_get_rB(x) insn_or1k_32_rB(x)
|
| 266 |
|
|
#define insn_or1k_opcode_0x30_get_imm(x) insn_or1k_32_split_imm(x)
|
| 267 |
|
|
|
| 268 |
|
|
|
| 269 |
|
|
#define insn_or1k_opcode_0x31_get_rA(x) insn_or1k_32_rA(x)
|
| 270 |
|
|
#define insn_or1k_opcode_0x31_get_rB(x) insn_or1k_32_rB(x)
|
| 271 |
|
|
#define insn_or1k_opcode_0x31_get_op(x) (x&0xf)
|
| 272 |
|
|
|
| 273 |
|
|
|
| 274 |
|
|
#define insn_or1k_opcode_0x32_get_rD(x) insn_or1k_32_rD(x)
|
| 275 |
|
|
#define insn_or1k_opcode_0x32_get_rA(x) insn_or1k_32_rA(x)
|
| 276 |
|
|
#define insn_or1k_opcode_0x32_get_rB(x) insn_or1k_32_rB(x)
|
| 277 |
|
|
#define insn_or1k_opcode_0x32_get_op_hi(x) ((x>>4)&0xf)
|
| 278 |
|
|
#define insn_or1k_opcode_0x32_get_op_lo(x) ((x&0xf))
|
| 279 |
|
|
|
| 280 |
|
|
/* N/A: opcodes 0x33 */
|
| 281 |
|
|
|
| 282 |
|
|
#define insn_or1k_opcode_0x34_get_rD(x) insn_or1k_32_rA(x)
|
| 283 |
|
|
#define insn_or1k_opcode_0x34_get_rB(x) insn_or1k_32_rB(x)
|
| 284 |
|
|
#define insn_or1k_opcode_0x34_get_imm(x) insn_or1k_32_split_imm(x)
|
| 285 |
|
|
|
| 286 |
|
|
|
| 287 |
|
|
#define insn_or1k_opcode_0x35_get_rD(x) insn_or1k_32_rA(x)
|
| 288 |
|
|
#define insn_or1k_opcode_0x35_get_rB(x) insn_or1k_32_rB(x)
|
| 289 |
|
|
#define insn_or1k_opcode_0x35_get_imm(x) insn_or1k_32_split_imm(x)
|
| 290 |
|
|
|
| 291 |
|
|
|
| 292 |
|
|
#define insn_or1k_opcode_0x36_get_rD(x) insn_or1k_32_rA(x)
|
| 293 |
|
|
#define insn_or1k_opcode_0x36_get_rB(x) insn_or1k_32_rB(x)
|
| 294 |
|
|
#define insn_or1k_opcode_0x36_get_imm(x) insn_or1k_32_split_imm(x)
|
| 295 |
|
|
|
| 296 |
|
|
|
| 297 |
|
|
#define insn_or1k_opcode_0x37_get_rD(x) insn_or1k_32_rA(x)
|
| 298 |
|
|
#define insn_or1k_opcode_0x37_get_rB(x) insn_or1k_32_rB(x)
|
| 299 |
|
|
#define insn_or1k_opcode_0x37_get_imm(x) insn_or1k_32_split_imm(x)
|
| 300 |
|
|
|
| 301 |
|
|
|
| 302 |
|
|
#define insn_or1k_opcode_0x38_get_rD(x) insn_or1k_32_rD(x)
|
| 303 |
|
|
#define insn_or1k_opcode_0x38_get_rA(x) insn_or1k_32_rA(x)
|
| 304 |
|
|
#define insn_or1k_opcode_0x38_get_rB(x) insn_or1k_32_rB(x)
|
| 305 |
|
|
#define insn_or1k_opcode_0x38_get_op_hi_2bit(x) ((x>>8)&0x3)
|
| 306 |
|
|
#define insn_or1k_opcode_0x38_get_op_hi_4bit(x) ((x>>6)&0xf)
|
| 307 |
|
|
#define insn_or1k_opcode_0x38_get_op_lo(x) ((x&0xf))
|
| 308 |
|
|
|
| 309 |
|
|
#define insn_or1k_opcode_0x39_get_op(x) insn_or1k_32_rD(x)
|
| 310 |
|
|
#define insn_or1k_opcode_0x39_get_rA(x) insn_or1k_32_rA(x)
|
| 311 |
|
|
#define insn_or1k_opcode_0x39_get_rB(x) insn_or1k_32_rB(x)
|
| 312 |
|
|
|
| 313 |
|
|
/* N/A: opcodes 0x3a,3b */
|