-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmachine.h
More file actions
185 lines (160 loc) · 4.29 KB
/
Copy pathmachine.h
File metadata and controls
185 lines (160 loc) · 4.29 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
#ifndef XSM_MACHINE_H
#define XSM_MACHINE_H
#include <setjmp.h>
#include "debug.h"
#include "disk.h"
#include "exception.h"
#include "memory.h"
#include "registers.h"
#include "tokenize.h"
#include "types.h"
#define XSM_ADDR_DREF 0
#define XSM_ADDR_NODREF 1
#define PRIVILEGE_USER 0
#define PRIVILEGE_KERNEL 1
#define DUAL_BOOTSTRAP 128 * XSM_PAGE_SIZE
#define XSM_EXCEPTION_OCCURED -1
/* Operation codes. */
#define MOV 0
#define ADD 1
#define SUB 2
#define MUL 3
#define DIV 4
#define MOD 5
#define INR 6
#define DCR 7
#define LT 8
#define GT 9
#define EQ 10
#define NE 11
#define GE 12
#define LE 13
#define JZ 14
#define JNZ 15
#define JMP 16
#define PUSH 17
#define POP 18
#define CALL 19
#define RET 20
#define BRKP 21
#define INT 22
#define LOADI 23
#define LOAD 24
#define STORE 25
#define ENCRYPT 26
#define BACKUP 27
#define RESTORE 28
#define PORT 29
#define IN 30
#define INI 31
#define OUT 32
#define IRET 33
#define START 34
#define RESET 35
#define TSL 36
#define HALT 37
#define NOP 38
/* Between these values are the privileged instructions. */
#define TOKEN_KERN_LOW 23
#define TOKEN_KERN_HIGH 37
#define INTERRUPT_LOW 4
#define INTERRUPT_HIGH 19
#define XSM_INSTRUCTION_COUNT 39
#define XSM_DISKOP_LOAD 0
#define XSM_DISKOP_STORE 1
#define XSM_CONSOLE_PRINT 0
#define XSM_CONSOLE_READ 1
#define XSM_INTERRUPT_EXHANDLER 0
#define XSM_HALT -1
typedef struct _disk_operation
{
int src_block;
int dest_page;
int operation;
} disk_operation;
typedef struct _console_operation
{
xsm_word word;
int operation;
} console_operation;
typedef struct _xsm_cpu
{
int timer[2], mode[2];
int core, core_state;
int disk_state, disk_wait;
int console_state, console_wait;
int mem_left, mem_right;
disk_operation disk_op;
console_operation console_op;
/* Exception point */
jmp_buf h_exp_point;
} xsm_cpu;
typedef struct _xsm_options
{
int timer;
int debug;
int disk;
int console;
} xsm_options;
int machine_init(xsm_options *options);
int machine_init_dual();
int machine_get_opcode(const char *instr);
xsm_word *machine_get_ipreg();
xsm_word *machine_get_spreg();
xsm_word *machine_get_register(const char *name);
xsm_word *machine_read_register(const char *name);
int machine_instr_req_privilege(int opcode);
int machine_serve_instruction(char *buffer, unsigned long *read_bytes, int max);
int machine_run();
void machine_change_core();
void machine_register_exception(char *message, int code);
int machine_handle_exception();
void machine_get_mem_access(int *mem_left, int *mem_right);
void machine_pre_execute(int ip_val);
void machine_post_execute();
int machine_execute_instruction(int opcode);
xsm_word *machine_get_address(int write);
int machine_get_address_int(int write);
int machine_translate_address(int address, int write, int type, int core, int mode);
xsm_word *machine_memory_get_word(int address);
int machine_execute_mov();
int machine_execute_arith(int opcode);
int machine_execute_unary(int opcode);
int machine_execute_logical(int opcode);
int machine_execute_jump(int opcode);
int machine_execute_stack(int opcode);
int machine_push_do(xsm_word *reg);
int machine_pop_do(xsm_word *dest);
xsm_word *machine_stack_pointer(int write);
int machine_execute_call_do(int target);
int machine_execute_call();
int machine_execute_ret();
int machine_execute_brkp();
int machine_execute_interrupt();
int machine_execute_interrupt_do(int interrupt);
int machine_interrupt_address(int int_num);
int machine_execute_disk(int operation, int immediate);
int machine_read_disk_arg();
int machine_schedule_disk(int page_num, int block_num, int firetime, int operation);
int machine_execute_load_do(int page_num, int block_num);
int machine_execute_store_do(int page_num, int block_num);
int machine_execute_encrypt();
int machine_execute_backup();
int machine_execute_restore();
int machine_execute_print_do(xsm_word *word);
int machine_execute_print();
int machine_schedule_in(int firetime);
int machine_execute_ini();
int machine_execute_in_do(xsm_word *word);
int machine_execute_iret();
int machine_execute_tsl();
int machine_execute_start();
int machine_execute_reset();
int machine_get_mode();
void machine_set_mode(int mode);
int machine_get_core();
void machine_set_core(int core);
int machine_get_core_state();
void machine_set_core_state(int mode);
void machine_destroy();
#endif