diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/definitions.h | 27 | ||||
-rw-r--r-- | inc/utils.h | 20 |
2 files changed, 45 insertions, 2 deletions
diff --git a/inc/definitions.h b/inc/definitions.h index ff2f7c6..c9367ff 100644 --- a/inc/definitions.h +++ b/inc/definitions.h @@ -11,6 +11,10 @@ * The total number of words in a line */ #define LINE_SIZE static_cast<int>(pow(2, 2)) +/** + * Number of bits in a word + */ +#define WORD_SPEC 32 /** * The number of bits to specify a memory word @@ -28,7 +32,8 @@ * The total number of lines in l1 cache */ #define L1_CACHE_WORD_SPEC 7 -#define L1_CACHE_LINE_SPEC static_cast<unsigned int>(L1_CACHE_WORD_SPEC - LINE_SPEC) +#define L1_CACHE_LINE_SPEC \ + static_cast<unsigned int>(L1_CACHE_WORD_SPEC - LINE_SPEC) #define L1_CACHE_LINES static_cast<int>(pow(2, L1_CACHE_LINE_SPEC)) /** @@ -47,6 +52,26 @@ #define GPR_NUM 16 /** + * The number of bits to specify an instruction type + */ +#define TYPE_SIZE 2 + +/** + * The number of bits to specify a register + */ +#define REG_SIZE 5 + +/** + * The number of bits to specify an R-Type opcode. + */ +#define R_OPCODE_SIZE 5 + +/** + * The number of bits to specify an opcode. + */ +#define OPCODE_SIZE 4 + +/** * Return the N least-significant bits from integer K using a bit mask * @param the integer to be parsed * @param the number of bits to be parsed diff --git a/inc/utils.h b/inc/utils.h index df8d374..7fed157 100644 --- a/inc/utils.h +++ b/inc/utils.h @@ -10,7 +10,25 @@ * @param the resulting index * @param the resulting offset */ -void get_bit_fields(int address, int *tag, int *index, int *offset); +void get_cache_fields(int address, int *tag, int *index, int *offset); + +/** + * Parse an instruction into a type, opcode, and fields. If the type is invalid, + * only the type field will be set. + * @param the resulting first field, which varies per type. To call this + * function properly, this field must contain the full instruction bytes on + * function entry. + * @param the resulting second field, which varies per type. + * @param the resulting third field, which varies per type. + * @param the resulting type. + * @param the resulting opcode. + */ +void get_instr_fields( + signed int &s1, + signed int &s2, + signed int &s3, + unsigned int &type, + unsigned int &opcode); /** * Formats a string using snprintf. |