summaryrefslogtreecommitdiffhomepage
path: root/mixlib/mix_vm.h
blob: ac734d72855bb2e00ffb9d0f5d5cf3ceefb582f4 (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
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
/* ---------------------- mix_vm.h :
 * Types and functions implementing the MIX virtual machine
 * ------------------------------------------------------------------
 * Copyright (C) 2000, 2001 Free Software Foundation, Inc.
 *  
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *  
 */


#ifndef MIX_VM_H
#define MIX_VM_H

#include "mix_types.h"
#include "mix_ins.h"
#include "mix_code_file.h"
#include "mix_src_file.h"
#include "mix_symbol_table.h"
#include "mix_vm_clock.h"

/* Comparison flag */
typedef enum { mix_LESS, mix_EQ, mix_GREAT } mix_cmpflag_t;

/* Number of memory cells in the virtual machine */
enum { MIX_VM_CELL_NO = 4000 };

/* Opaque type for the mix virtual machine */
typedef struct mix_vm_t mix_vm_t;

/* Create/destroy a mix vm */
extern mix_vm_t *
mix_vm_new(void);

extern void
mix_vm_delete(mix_vm_t * vm);

/* Reset a vm (set state as of a newly created one) */
extern void
mix_vm_reset(mix_vm_t * vm);

/* Set start address for execution */
extern void
mix_vm_set_start_addr(mix_vm_t *vm, mix_address_t addr);

/* Access to the vm's registers */
extern mix_word_t
mix_vm_get_rA(const mix_vm_t *vm);

extern mix_word_t
mix_vm_get_rX(const mix_vm_t *vm);

extern mix_short_t
mix_vm_get_rJ(const mix_vm_t *vm);

extern mix_short_t
mix_vm_get_rI(const mix_vm_t *vm, guint idx);

extern void 
mix_vm_set_rA(mix_vm_t *vm, mix_word_t value);

extern void
mix_vm_set_rX(mix_vm_t *vm, mix_word_t value);

extern void 
mix_vm_set_rJ(mix_vm_t *vm, mix_short_t value);

extern void 
mix_vm_set_rI(mix_vm_t *vm, guint idx, mix_short_t value);


/* Access to the comparison flag and overflow toggle */
extern mix_cmpflag_t
mix_vm_get_cmpflag(const mix_vm_t *vm);

extern void
mix_vm_set_cmpflag(mix_vm_t *vm, mix_cmpflag_t value);

extern gboolean
mix_vm_get_overflow(const mix_vm_t *vm);

extern void
mix_vm_set_overflow(mix_vm_t *vm, gboolean value);

extern void
mix_vm_toggle_overflow(mix_vm_t *vm);

extern gboolean
mix_vm_is_halted(const mix_vm_t *vm);

/* Access to memory cells */
extern mix_word_t
mix_vm_get_addr_contents(const mix_vm_t *vm, mix_address_t addr);

extern void
mix_vm_set_addr_contents(mix_vm_t *vm, mix_address_t addr, mix_word_t value);

/* Execution of instructions and programs */
extern gboolean /* TRUE if success */
mix_vm_exec_ins(mix_vm_t *vm, const mix_ins_t *ins);

/* Load a code file into memory (-name- does not need the default extension) 
 * resetting the vm's state
 */
extern gboolean
mix_vm_load_file(mix_vm_t *vm, const gchar *name);

/* Get the source file object corresponding to the last loaded code file */
extern const mix_src_file_t *
mix_vm_get_src_file (const mix_vm_t *vm);

/* Get symbol table of loaded file */
extern const mix_symbol_table_t *
mix_vm_get_symbol_table (const mix_vm_t *vm);

/* Get current program counter */
extern mix_address_t 
mix_vm_get_prog_count (const mix_vm_t *vm);

/* Get the source line number for a given address */
extern guint
mix_vm_get_address_lineno (const mix_vm_t *vm, mix_address_t addr);

/* Reposition program counter and reset state so that a loaded
   program can be restarted.
*/
extern void
mix_vm_reset_program (mix_vm_t *vm);

/* continue execution of instructions in memory */
/* Possible outcomes */
enum {
  MIX_VM_ERROR,		/* error executing instructions */
  MIX_VM_BREAK,		/* breakpoint found */
  MIX_VM_HALT,		/* end of execution */
  MIX_VM_OK		/* successful instruction execution */
};

extern int
mix_vm_run (mix_vm_t *vm);

/* execute next memory instruction */
extern int
mix_vm_exec_next (mix_vm_t *vm);

/* get the line no. of the last break or 0 if not found */
extern gulong
mix_vm_get_break_lineno (const mix_vm_t *vm);

/* Breakpoints */
/* possible error outcomes */
enum {
  MIX_VM_BP_ERROR = -4,		/* internal error */
  MIX_VM_BP_NDEBUG = -3,	/* no debug info */
  MIX_VM_BP_INV_ADDRESS = -2,   /* address out of range */
  MIX_VM_BP_INV_LINE = -1,	/* invalid line no. */
  MIX_VM_BP_OK = 0		/* success */
};

extern gint /* if >0 the line no. of the break point */
mix_vm_set_breakpoint (mix_vm_t *vm, guint lineno);

extern gint /* one of MIX_VM_BP_ */
mix_vm_set_breakpoint_address (mix_vm_t *vm, guint address);

extern gint /* one of MIX_VM_BP_ */
mix_vm_clear_breakpoint (mix_vm_t *vm, guint lineno);

extern gint /* one of MIX_VM_BP_ */
mix_vm_clear_breakpoint_address (mix_vm_t *vm, guint address) ;

extern void
mix_vm_clear_all_breakpoints (mix_vm_t *vm);

/* Get the vm uptime, defined as the time spent executing instructions */
extern mix_time_t
mix_vm_get_uptime (const mix_vm_t *vm);


#endif /* MIX_VM_H */