forked from TueHaulund/PendVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pendvm.h
169 lines (142 loc) · 4.1 KB
/
pendvm.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
165
166
167
168
169
/* $Id: pendvm.h,v 1.2 1997/07/03 19:51:03 deberg Exp $ */
/* pendsim.h - include file, defines a bunch of stuff */
/* prevent multiple inclusions */
#ifndef PENDSIM_H
#define PENDSIM_H
#define WORD unsigned int
#include "memory.h"
#include "pal_parse.h"
#ifdef DEBUG
#define IF_DEBUG(x) if (debug) x;
#else
#define IF_DEBUG(x) ;
#endif
#define VERSION "2.0"
#define PENDASM "/home/joule/deberg/pendulum/pendasm/pendasm"
/* some random types */
#define BOOL char
#define BYTE unsigned char
#define TRUE 1
#define FALSE 0
/* processor directions */
#define FORWARD 1
#define REVERSE -1
/* execute_instruction return codes */
#define EXEC_NORMAL 1
#define EXEC_BREAK 2
#define EXEC_FINISH 3
#define EXEC_ERROR 4
#define EXEC_INVALID_INST 5
#define EXEC_REV_BROKEN 6
/* output type specifiers */
#define PTYPE_MASK 0xFF00
#define PTYPE_NONE -1
#define PTYPE_INT 0x0000
#define INT_SIGN_MASK 0x01
#define INT_SIGNED 0x00
#define INT_UNSIGNED 0x01
#define INT_BASE_MASK 0x10
#define INT_BASE_10 0x00
#define INT_BASE_16 0x10
#define PTYPE_FLOAT 0x0200
#define FLOAT_NOTATION_MASK 0x01
#define FLOAT_FIXED 0x00
#define FLOAT_EXP 0x01
#define PTYPE_STRING 0x0100
#define STRING_CHAR0 0x000000FF
#define STRING_CHAR1 0x0000FF00
#define STRING_CHAR2 0x00FF0000
#define STRING_CHAR3 0xFF000000
#define PTYPE_NEWLINE 0xFF00
/* command line options */
#define OPTION_DEBUG "--debug"
#define OPTION_HELP "--help"
#define OPTION_VERSION "--version"
/* define some machine constants */
#define MAX_REG 32 /* number of GPR's */
/* snag bits from instruction */
/* #define EXTRACT(num,low,high) (num % power(2,high+1)) / power(2,(low)) */
/* machine structure */
typedef struct {
unsigned int PC;
unsigned int BR;
BOOL dir,externaldir;
BOOL reset;
int reg[MAX_REG];
int time;
} MACHINE;
/* structure for pendsim commands */
typedef struct {
char *name; /* name that the user types in */
int (*func)(char args[][64], int); /* function to call */
char *help; /* short information for help */
} COMMAND;
/* machine.c */
void init_machine(void);
void load_imem(char *);
void loop(void);
void pendsim_error(char *);
void display_state(void);
int step_processor(int);
int adjust_pc(void);
int execute_instruction(void);
/* instruction handlers (in machine.c) */
int i_add(WORD, WORD, WORD);
int i_addi(WORD, WORD, WORD);
int i_andx(WORD, WORD, WORD);
int i_andix(WORD, WORD, WORD);
int i_beq(WORD, WORD, WORD);
int i_bgez(WORD, WORD, WORD);
int i_bgtz(WORD, WORD, WORD);
int i_blez(WORD, WORD, WORD);
int i_bltz(WORD, WORD, WORD);
int i_bne(WORD, WORD, WORD);
int i_bra(WORD, WORD, WORD);
int i_exch(WORD, WORD, WORD);
int i_norx(WORD, WORD, WORD);
int i_neg(WORD, WORD, WORD);
int i_orx(WORD, WORD, WORD);
int i_orix(WORD, WORD, WORD);
int i_rl(WORD, WORD, WORD);
int i_rlv(WORD, WORD, WORD);
int i_rr(WORD, WORD, WORD);
int i_rrv(WORD, WORD, WORD);
int i_sllx(WORD, WORD, WORD);
int i_sllvx(WORD, WORD, WORD);
int i_sltx(WORD, WORD, WORD);
int i_sltix(WORD, WORD, WORD);
int i_srax(WORD, WORD, WORD);
int i_sravx(WORD, WORD, WORD);
int i_srlx(WORD, WORD, WORD);
int i_srlvx(WORD, WORD, WORD);
int i_sub(WORD, WORD, WORD);
int i_xorx(WORD, WORD, WORD);
int i_xorix(WORD, WORD, WORD);
int i_swapbr(WORD, WORD, WORD);
int i_rbra(WORD, WORD, WORD);
int i_show(WORD, WORD, WORD);
int i_emit(WORD, WORD, WORD);
int i_start(WORD, WORD, WORD);
int i_finish(WORD, WORD, WORD);
/* pendsim command functions */
int com_break(char args[][64], int);
int com_clear(char args[][64], int);
int com_continue(char args[][64], int);
int com_dir(char args[][64], int);
int com_read(char args[][64], int);
int com_reg(char args[][64], int);
int com_run(char args[][64], int);
int com_set(char args[][64], int);
int com_state(char args[][64], int);
int com_step(char args[][64], int);
int com_unbreak(char args[][64], int);
int com_write(char args[][64], int);
int com_help(char args[][64], int);
int com_quit(char args[][64], int);
/* main.c */
unsigned int power(unsigned int, unsigned int);
int sign_extend(int, int);
void *my_malloc(size_t);
char *parse_command_line(int, char**);
int usage(void);
#endif /* ifndef PENDSIM_H */