summaryrefslogtreecommitdiff
path: root/inc/utils.h
blob: 7fed1570592a7cdc72436456e07341046a02ef94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef UTILS_H
#define UTILS_H
#include <string>

/**
 * Parse an address into a tag, index into the cache table, and a line
 * offset.
 * @param the address to be parsed
 * @param the resulting tag
 * @param the resulting index
 * @param the resulting 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.
 * @param an object that represents the format string
 * @param arguments to be formatted
 * @return a string object holding the formatted result
 */
const std::string string_format(const char *const zcFormat, ...);

/**
 * Given `address`, returns an address that is within the current memory size
 * using a clean wrap.
 * @param an address
 * @return an address guaranteed to be within range.
 */
int wrap_address(int address);

/**
 * Given `address`, returns the line and word it is in.
 * @param an address
 * @param the line (row) `address` is in
 * @param the word (column) `address` corresponds to
 */
void get_memory_index(int address, int &line, int &word);

#endif /* UTILS_H_INCLUDED */