-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfu.h
executable file
·164 lines (131 loc) · 3.89 KB
/
fu.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
*
* fu.h
This module was originally written by Paul Kohout and adapted for
this simulator.
*
* Donald Yeung
*/
#include <stdio.h>
#define MAXMEMORY 65536 /* maximum number of data words in memory */
#define NUMREGS 32 /* number of machine registers */
#define FIELD_OPCODE(instr) ((unsigned int)(((instr)>>26)&0x003F))
#define FIELD_FUNC(instr) ((unsigned int)((instr)&0x07FF))
#define FIELD_R1(instr) ((unsigned int)(((instr)>>21)&0x001F))
#define FIELD_R2(instr) ((unsigned int)(((instr)>>16)&0x001F))
#define FIELD_R3(instr) ((unsigned int)(((instr)>>11)&0x001F))
#define FIELD_IMM(instr) ((signed short)((instr)&0xFFFF))
#define FIELD_IMMU(instr) ((unsigned short)((instr)&0xFFFF))
#define FIELD_OFFSET(instr) ((signed int)(((instr)&0x02000000)?((instr)|0xFC000000):((instr)&0x03FFFFFF)))
#define FU_GROUP_INT 0
#define FU_GROUP_ADD 1
#define FU_GROUP_MULT 2
#define FU_GROUP_DIV 3
#define FU_GROUP_MEM 4
#define FU_GROUP_BRANCH 5
#define FU_GROUP_NONE -1
#define FU_GROUP_INVALID -2
#define FU_GROUP_HALT -3
#define OPERATION_ADD 0
#define OPERATION_ADDU 1
#define OPERATION_SUB 2
#define OPERATION_SUBU 3
#define OPERATION_MULT 4
#define OPERATION_DIV 5
#define OPERATION_SLL 6
#define OPERATION_SRL 7
#define OPERATION_AND 8
#define OPERATION_OR 9
#define OPERATION_XOR 10
#define OPERATION_LOAD 11
#define OPERATION_STORE 12
#define OPERATION_J 13
#define OPERATION_JAL 14
#define OPERATION_JR 15
#define OPERATION_JALR 16
#define OPERATION_BEQZ 17
#define OPERATION_BNEZ 18
#define OPERATION_SLT 19
#define OPERATION_SGT 20
#define OPERATION_SLTU 21
#define OPERATION_SGTU 22
#define OPERATION_NONE -1
#define DATA_TYPE_W 1
#define DATA_TYPE_F 2
#define DATA_TYPE_NONE -1
typedef struct _op_info_t {
const char *name;
const int fu_group_num;
const int operation;
const int data_type;
} op_info_t;
typedef struct _op_t {
const struct _op_info_t info;
const struct _sub_op_t * const sub_table;
} op_t;
typedef struct _sub_op_t {
const struct _op_info_t info;
} sub_op_t;
extern const op_t op_table[];
extern const sub_op_t op_special_table[];
extern const sub_op_t op_fparith_table[];
extern const char fu_group_int_name[];
extern const char fu_group_add_name[];
extern const char fu_group_mult_name[];
extern const char fu_group_div_name[];
/* union to handle multiple fixed-point types */
typedef union _int_t {
signed long w;
unsigned long wu;
} int_t;
typedef union _operand_t {
int_t integer;
float flt;
} operand_t;
/* functional unit and memory port structures */
typedef struct _fu_int_stage_t {
int num_cycles;
int current_cycle;
int instr;
operand_t op1;
operand_t op2;
struct _fu_int_stage_t *prev;
} fu_int_stage_t;
typedef struct _fu_int_t {
char *name;
fu_int_stage_t *stage_list;
struct _fu_int_t *next;
} fu_int_t;
typedef struct _fu_fp_stage_t {
int num_cycles;
int current_cycle;
int instr;
operand_t op1;
operand_t op2;
struct _fu_fp_stage_t *prev;
} fu_fp_stage_t;
typedef struct _fu_fp_t {
char *name;
fu_fp_stage_t *stage_list;
struct _fu_fp_t *next;
} fu_fp_t;
/* writeback pipeline register */
typedef struct _wb_t {
int instr;
operand_t op1;
operand_t op2;
} wb_t;
extern int fu_int_read(fu_int_t **, FILE *);
extern int fu_fp_read(fu_fp_t **, FILE *);
extern int issue_fu_int(fu_int_t *, int, operand_t, operand_t);
extern int issue_fu_fp(fu_fp_t *, int, operand_t, operand_t);
extern void advance_fu_int(fu_int_t *, wb_t *);
extern void advance_fu_fp(fu_fp_t *, wb_t *);
extern int fu_int_done(fu_int_t *);
extern int fu_fp_done(fu_fp_t *);
extern int fu_int_all_cycles(fu_int_t *);
extern int fu_fp_all_cycles(fu_fp_t *);
extern int fu_int_match_cycles(fu_int_t *, int);
extern int fu_fp_match_cycles(fu_fp_t *, int);
const op_info_t *decode_instr(int, int *);
extern void perform_operation(int, unsigned long*, operand_t, operand_t, operand_t *);