-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmmixlib.h
More file actions
252 lines (211 loc) · 7.49 KB
/
mmixlib.h
File metadata and controls
252 lines (211 loc) · 7.49 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#ifndef _MMIXLIB_H_
#define _MMIXLIB_H_
#include <stdio.h>
/* auxiliar functions provided by the library but without a prototype here*/
#if 0
extern void free_tree(trie_node *root);
#endif
#ifndef _LIBTYPE_H_
typedef enum{false,true}bool;
typedef unsigned int tetra;
typedef struct{tetra h,l;} octa;
typedef char Char;
typedef enum{
rB,rD,rE,rH,rJ,rM,rR,rBB,
rC,rN,rO,rS,rI,rT,rTT,rK,rQ,rU,rV,rG,rL,
rA,rF,rP,rW,rX,rY,rZ,rWW,rXX,rYY,rZZ}special_reg;
typedef enum{
TRAP,FCMP,FUN,FEQL,FADD,FIX,FSUB,FIXU,
FLOT,FLOTI,FLOTU,FLOTUI,SFLOT,SFLOTI,SFLOTU,SFLOTUI,
FMUL,FCMPE,FUNE,FEQLE,FDIV,FSQRT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SADDI,MOR,MORI,MXOR,MXORI,
SETH,SETMH,SETML,SETL,INCH,INCMH,INCML,INCL,
ORH,ORMH,ORML,ORL,ANDNH,ANDNMH,ANDNML,ANDNL,
JMP,JMPB,PUSHJ,PUSHJB,GETA,GETAB,PUT,PUTI,
POP,RESUME,SAVE,UNSAVE,SYNC,SWYM,GET,TRIP}mmix_opcode;
#define trace_bit (1<<3)
#define read_bit (1<<2)
#define write_bit (1<<1)
#define exec_bit (1<<0) \
#define RESUME_AGAIN 0
#define RESUME_CONT 1
#define RESUME_SET 2
#define RESUME_TRANS 3
#define P_BIT (1<<0)
#define S_BIT (1<<1)
#define B_BIT (1<<2)
#define K_BIT (1<<3)
#define N_BIT (1<<4)
#define PX_BIT (1<<5)
#define PW_BIT (1<<6)
#define PR_BIT (1<<7)
#define PF_BIT (1<<0)
#define MP_BIT (1<<1)
#define NM_BIT (1<<2)
#define YY_BIT (1<<3)
#define RE_BIT (1<<4)
#define CP_BIT (1<<5)
#define PT_BIT (1<<6)
#define IN_BIT (1<<7)
#define X_BIT (1<<8)
#define Z_BIT (1<<9)
#define U_BIT (1<<10)
#define O_BIT (1<<11)
#define I_BIT (1<<12)
#define W_BIT (1<<13)
#define V_BIT (1<<14)
#define D_BIT (1<<15)
#define H_BIT (1<<16)
typedef struct{
#ifndef VMB
tetra tet;
#endif
tetra freq;
unsigned char bkpt;
unsigned char file_no;
unsigned short line_no;
} mem_tetra;
typedef struct mem_node_struct{
octa loc;
tetra stamp;
struct mem_node_struct*left,*right;
mem_tetra dat[512];
} mem_node;
#endif
extern bool show_operating_system;
extern unsigned int tracing_exceptions;
extern int G,L,O;
extern octa g[256];
extern octa*l;
extern int lring_size;
extern int lring_mask;
extern int S;
extern char*special_name[32];
extern octa new_Q;
extern void mmputchars(unsigned char *buf,int size,octa addr);
extern int mmgetchars(unsigned char *buf, int size, octa addr, int stop);
extern FILE*fake_stdin;
extern mem_tetra* mem_find(octa addr);
extern mem_node*mem_root;
extern mem_node* new_mem(void);
extern octa incr(octa y,int delta);
extern void free_file_info(void);
extern void scan_option(char *arg, /* command-line argument (without the `\.-') */
bool usage); /* should we exit with usage note if unrecognized? */
extern void print_hex(octa o);
extern void print_int(octa o);
extern void print_string(octa o);
extern void show_line(void);
extern void show_breaks(mem_node *p);
/* functions provided by mmix-lib */
extern int mmix_main(int argc, char *argv[],char *mmo_file_name);
/* the mmix main program */
extern int mmix_lib_initialize(void);
/* call to initialize the library */
extern int mmix_lib_finalize(void);
/* call to clean up, relase memory after the library has been used */
extern int mmix_initialize(void);
/* call to initialize global variables needed for mmix sim to run */
extern int mmix_finalize(void);
/* call to clean up, relase memory after mmix sim has run */
extern void mmix_boot(void);
/* call to bring the simulated mmix cpu into the fresh state after boot/reset */
extern int mmix_load_file(char *mmo_file_name);
/* call to load a file */
extern int mmix_commandline(int argc, char *argv[]);
/* call to provide a commandline to mmix (call after loading files!)*/
extern void mmix_interact(void);
/* mmix user interaction */
extern int mmix_fetch_instruction(void);
/* called to fetch one instruction returns zero on error */
extern int mmix_resume(void);
/* called instead of mmix_fetch_insruction after a RESUME */
extern int mmix_perform_instruction(void);
/* called to execute one instruction */
extern void mmix_trace_fetch(void);
/* Print the frequency count, the location, and the instruction*/
extern void mmix_trace_perform(void);
/* Print a stream-of-consciousness description of the instruction */
extern void mmix_trace(void);
/* tests for tracing and outputs a trace of the instruction */
/* extern void mmix_exit(int returncode); */
/* call to cause a running mmix simulator to return*/
extern bool mmix_dynamic_trap(void);
/* check for dynamic traps return true if switching to trap handler */
extern void mmix_profile(void);
/* print the profile */
extern void show_stats(bool verbose);
/* show statistics */
extern int mmix_printf(FILE *f, char *format,...);
/* printf replacement */
extern int mmix_vprintf(char *format, va_list vargs);
extern int mmix_fputc(int c, FILE *f);
/* fputc replacement */
void mmix_stack_trace(char *format,...);
/* function to do the stack trace */
extern bool halted;
extern int breakpoint;
extern bool interrupt;
extern bool interacting;
extern bool line_listed; /* have we listed the buffer contents? */
extern octa neg_one;
extern bool tracing;
extern bool stack_tracing;
extern octa loc;
extern octa inst_ptr;
extern tetra inst;
extern bool show_operating_system;
extern bool resuming;
extern mmix_opcode op;
extern bool profiling;
extern bool showing_stats;
/* function from mmix-io */
void mmix_fake_stdin(FILE *f);
/* functions that mmixal provides */
extern int mmixal(char *mms_name, char *mmo_name, char *mml_name);
/* returns zero on success,
negative values on fatal errors,
otherwise the number of errors found in the input
*/
extern void report_error(char *message, int file_no, int line_no);
/* report an error in the given file and line.
*/
extern int mmoimg_main(int argc, char *argv[]);
/* global variables of mmixal */
extern char *src_file_name; /* name of the \MMIXAL\ input file */
extern char obj_file_name[FILENAME_MAX+1]; /* name of the binary output file */
extern char listing_name[FILENAME_MAX+1]; /* name of the optional listing file */
extern FILE *src_file, *obj_file, *listing_file;
extern int expanding; /* are we expanding instructions when base address fail? */
extern int buf_size; /* maximum number of characters per line of input */
extern int check_X_BIT; /* whether checking for imprecise floating point constants */
extern int mmixal(char *mms_name, char *mmo_name, char *mml_name);
extern int err_count; /* the error count */
extern void flush_listing_line(char*line);
extern char *file2filename(int file_no);
extern int filename2file(char *filename);
#endif