mmixlib.h 7.94 KB
Newer Older
1
2
#ifndef _MMIXLIB_H_
#define _MMIXLIB_H_
3

4
5
6
#include <stdio.h>

/* auxiliar functions provided by the library  but without a prototype here*/
7
8
9
10
11
#if 0
extern void free_tree(trie_node *root);

#endif

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
#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,FREM,FINT,
MUL,MULI,MULU,MULUI,DIV,DIVI,DIVU,DIVUI,
ADD,ADDI,ADDU,ADDUI,SUB,SUBI,SUBU,SUBUI,
IIADDU,IIADDUI,IVADDU,IVADDUI,VIIIADDU,VIIIADDUI,XVIADDU,XVIADDUI,
CMP,CMPI,CMPU,CMPUI,NEG,NEGI,NEGU,NEGUI,
SL,SLI,SLU,SLUI,SR,SRI,SRU,SRUI,
BN,BNB,BZ,BZB,BP,BPB,BOD,BODB,
BNN,BNNB,BNZ,BNZB,BNP,BNPB,BEV,BEVB,
PBN,PBNB,PBZ,PBZB,PBP,PBPB,PBOD,PBODB,
PBNN,PBNNB,PBNZ,PBNZB,PBNP,PBNPB,PBEV,PBEVB,
CSN,CSNI,CSZ,CSZI,CSP,CSPI,CSOD,CSODI,
CSNN,CSNNI,CSNZ,CSNZI,CSNP,CSNPI,CSEV,CSEVI,
ZSN,ZSNI,ZSZ,ZSZI,ZSP,ZSPI,ZSOD,ZSODI,
ZSNN,ZSNNI,ZSNZ,ZSNZI,ZSNP,ZSNPI,ZSEV,ZSEVI,
LDB,LDBI,LDBU,LDBUI,LDW,LDWI,LDWU,LDWUI,
LDT,LDTI,LDTU,LDTUI,LDO,LDOI,LDOU,LDOUI,
LDSF,LDSFI,LDHT,LDHTI,CSWAP,CSWAPI,LDUNC,LDUNCI,
LDVTS,LDVTSI,PRELD,PRELDI,PREGO,PREGOI,GO,GOI,
STB,STBI,STBU,STBUI,STW,STWI,STWU,STWUI,
STT,STTI,STTU,STTUI,STO,STOI,STOU,STOUI,
STSF,STSFI,STHT,STHTI,STCO,STCOI,STUNC,STUNCI,
SYNCD,SYNCDI,PREST,PRESTI,SYNCID,SYNCIDI,PUSHGO,PUSHGOI,
OR,ORI,ORN,ORNI,NOR,NORI,XOR,XORI,
AND,ANDI,ANDN,ANDNI,NAND,NANDI,NXOR,NXORI,
BDIF,BDIFI,WDIF,WDIFI,TDIF,TDIFI,ODIF,ODIFI,
MUX,MUXI,SADD,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) 


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;
char*special_name[32];


117
118
extern void mmputchars(unsigned char *buf,int size,octa addr);
extern int mmgetchars(unsigned char *buf, int size, octa addr, int stop);
119
120


Martin Ruckert's avatar
Martin Ruckert committed
121
extern FILE*fake_stdin;
122
123
124
125
126
127
128

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);
129
130
131
132
133
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);
134
135
136
137
138
139
140





extern void show_line(void);

141
extern void show_breaks(mem_node *p);
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



/* 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 int	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(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 void mmix_dynamic_trap(void);
/* check for dynamic traps */
extern void mmix_profile(void);
/* print the profile */
179
180
extern void show_stats(bool verbose);
/* show statistics */
181

182
extern int mmix_printf(FILE *f, char *format,...);
183
184
185
/* printf replacement */
extern int mmix_fputc(int c, FILE *f);
/* fputc replacement */
186
187
void mmix_stack_trace(char *format,...);
/* function to do the stack trace */
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

extern bool halted;
extern bool breakpoint;
extern bool interrupt;
extern bool interacting;
extern octa rOlimit;
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 rw_break;
extern bool show_operating_system;
extern bool trace_once;
extern bool resuming;
extern mmix_opcode op;
extern bool profiling;
extern bool showing_stats;
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
#if 0

extern int cur_file; /* index of the current file in |filename| */
extern int line_no; /* current position in the file */


extern int err_count; /* this many errors were found */
extern char *src_file_name; /* name of the \MMIXAL\ input file */
extern Char *filename[257];
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 void flush_listing_line(char *s);
extern int mmixal(void);

extern int mmo_ptr;

extern int mmix_status; 

extern char full_mmo_name[];
extern void mmix_status(int status);



#endif

Martin Ruckert's avatar
Martin Ruckert committed
236
237
/* function from mmix-io */
void mmix_fake_stdin(FILE *f);
238
239
240
241
242
243
244
/* functions that mmixal provides */

extern int mmixal(char *mms_name, char *mmo_name, char *mml_name, int x_option, int b_option);
/* returns zero on success, 
           negative values on fatal errors, 
		   otherwise the number of errors found in the input
*/
245

246
extern void report_error(char *message, int file_no, int line_no);
247
248
249
250
251
252
/* report an error in the given file and line. 
 */

extern void add_line_loc(int file_no, int line_no, octa loc);
/* report the association of a file/line with a location */

253
254
255
256
257
258
259
260
261
262
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 mmixal(char *mms_name, char *mmo_name, char *mml_name, int x_option, int b_option);
263
extern int err_count; /* the error count */
264
extern void flush_listing_line(char*line);
265
266
267

extern char *file2filename(int file_no);
extern int filename2file(char *filename);
268
#endif