-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.h
92 lines (72 loc) · 2.4 KB
/
cpu.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
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <setjmp.h>
#define FOX32_MEMORY_RAM 0x00100000 // 1 MiB
#define FOX32_MEMORY_ROM 0x00004000 // 16 KiB
#define FOX32_MEMORY_ROM_START 0xF0000000
#define FOX32_POINTER_DEFAULT_INSTR FOX32_MEMORY_ROM_START
#define FOX32_POINTER_DEFAULT_STACK 0x00000000
#define FOX32_POINTER_INTERRUPTVECS 0x00000000
#define FOX32_REGISTER_LOOP 31
#define FOX32_REGISTER_COUNT 32
typedef enum {
FOX32_ERR_OK,
FOX32_ERR_INTERNAL,
FOX32_ERR_DEBUGGER,
FOX32_ERR_FAULT_RD,
FOX32_ERR_FAULT_WR,
FOX32_ERR_BADOPCODE,
FOX32_ERR_BADCONDITION,
FOX32_ERR_BADREGISTER,
FOX32_ERR_BADIMMEDIATE,
FOX32_ERR_DIVZERO,
FOX32_ERR_IOREAD,
FOX32_ERR_IOWRITE,
FOX32_ERR_NOINTERRUPTS,
FOX32_ERR_CANTRECOVER
} fox32_err_t;
const char *fox32_strerr(fox32_err_t err);
typedef int fox32_io_read_t(void *user, uint32_t *value, uint32_t port);
typedef int fox32_io_write_t(void *user, uint32_t value, uint32_t port);
typedef struct {
uint32_t pointer_instr_mut;
uint32_t pointer_instr;
uint32_t pointer_stack;
uint32_t pointer_exception_stack;
uint32_t pointer_frame;
uint32_t pointer_page_directory;
uint32_t registers[FOX32_REGISTER_COUNT];
bool flag_zero;
bool flag_carry;
bool flag_interrupt;
bool flag_swap_sp;
bool halted;
bool soft_halted;
bool debug;
bool headless;
bool mmu_enabled;
bool is_consecutive_read;
uint32_t previous_read_address;
uint8_t page_is_in_memory_bitmap[32];
uint8_t physical_memory_bitmap[4];
uint8_t page_on_disk_is_at[256];
jmp_buf panic_jmp;
fox32_err_t panic_err;
uint32_t exception_operand;
void *io_user;
fox32_io_read_t *io_read;
fox32_io_write_t *io_write;
} fox32_vm_t;
void fox32_init(fox32_vm_t *vm);
fox32_err_t fox32_step(fox32_vm_t *vm);
fox32_err_t fox32_resume(fox32_vm_t *vm, uint32_t count, uint32_t *executed);
fox32_err_t fox32_raise(fox32_vm_t *vm, uint16_t vector);
fox32_err_t fox32_recover(fox32_vm_t *vm, fox32_err_t err);
fox32_err_t fox32_push_byte(fox32_vm_t *vm, uint8_t value);
fox32_err_t fox32_push_half(fox32_vm_t *vm, uint16_t value);
fox32_err_t fox32_push_word(fox32_vm_t *vm, uint32_t value);
fox32_err_t fox32_pop_byte(fox32_vm_t *vm, uint8_t *value);
fox32_err_t fox32_pop_half(fox32_vm_t *vm, uint16_t *value);
fox32_err_t fox32_pop_word(fox32_vm_t *vm, uint32_t *value);