-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlightrec.h
159 lines (133 loc) · 4.09 KB
/
lightrec.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
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
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2016-2021 Paul Cercueil <[email protected]>
*/
#ifndef __LIGHTREC_H__
#define __LIGHTREC_H__
#ifdef __cplusplus
#define _Bool bool
extern "C" {
#endif
#include <stddef.h>
#include <stdint.h>
#ifdef _WIN32
# ifdef lightrec_EXPORTS
# define __api __declspec(dllexport)
# elif !defined(LIGHTREC_STATIC)
# define __api __declspec(dllimport)
# else
# define __api
# endif
#elif __GNUC__ >= 4
# define __api __attribute__((visibility ("default")))
#else
# define __api
#endif
#ifndef __cnst
# ifdef __GNUC__
# define __cnst __attribute__((const))
# else
# define __cnst
# endif
#endif
#ifndef __pure
# ifdef __GNUC__
# define __pure __attribute__((pure))
# else
# define __pure
# endif
#endif
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef int64_t s64;
typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8;
struct lightrec_state;
struct lightrec_mem_map;
/* Exit flags */
#define LIGHTREC_EXIT_NORMAL (0)
#define LIGHTREC_EXIT_CHECK_INTERRUPT (1 << 0)
#define LIGHTREC_EXIT_BREAK (1 << 1)
#define LIGHTREC_EXIT_SYSCALL (1 << 2)
#define LIGHTREC_EXIT_SEGFAULT (1 << 3)
#define LIGHTREC_EXIT_NOMEM (1 << 4)
#define LIGHTREC_EXIT_UNKNOWN_OP (1 << 5)
/* Unsafe optimizations flags */
#define LIGHTREC_OPT_INV_DMA_ONLY (1 << 0)
#define LIGHTREC_OPT_SP_GP_HIT_RAM (1 << 1)
enum psx_map {
PSX_MAP_KERNEL_USER_RAM,
PSX_MAP_BIOS,
PSX_MAP_SCRATCH_PAD,
PSX_MAP_PARALLEL_PORT,
PSX_MAP_HW_REGISTERS,
PSX_MAP_CACHE_CONTROL,
PSX_MAP_MIRROR1,
PSX_MAP_MIRROR2,
PSX_MAP_MIRROR3,
PSX_MAP_CODE_BUFFER,
PSX_MAP_PPORT_MIRROR,
PSX_MAP_UNKNOWN,
};
struct lightrec_mem_map_ops {
void (*sb)(struct lightrec_state *, u32 opcode,
void *host, u32 addr, u32 data);
void (*sh)(struct lightrec_state *, u32 opcode,
void *host, u32 addr, u32 data);
void (*sw)(struct lightrec_state *, u32 opcode,
void *host, u32 addr, u32 data);
u8 (*lb)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
u16 (*lh)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
u32 (*lw)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
u32 (*lwu)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
void (*swu)(struct lightrec_state *, u32 opcode,
void *host, u32 addr, u32 data);
};
struct lightrec_mem_map {
u32 pc;
u32 length;
void *address;
const struct lightrec_mem_map_ops *ops;
const struct lightrec_mem_map *mirror_of;
};
struct lightrec_ops {
void (*cop2_notify)(struct lightrec_state *state, u32 op, u32 data);
void (*cop2_op)(struct lightrec_state *state, u32 op);
void (*enable_ram)(struct lightrec_state *state, _Bool enable);
_Bool (*hw_direct)(u32 kaddr, _Bool is_write, u8 size);
void (*code_inv)(void *addr, u32 len);
};
struct lightrec_registers {
u32 gpr[34];
u32 cp0[32];
u32 cp2d[32];
u32 cp2c[32];
};
__api struct lightrec_state *lightrec_init(char *argv0,
const struct lightrec_mem_map *map,
size_t nb,
const struct lightrec_ops *ops);
__api void lightrec_destroy(struct lightrec_state *state);
__api u32 lightrec_execute(struct lightrec_state *state,
u32 pc, u32 target_cycle);
__api u32 lightrec_run_interpreter(struct lightrec_state *state,
u32 pc, u32 target_cycle);
__api void lightrec_invalidate(struct lightrec_state *state, u32 addr, u32 len);
__api void lightrec_invalidate_all(struct lightrec_state *state);
__api void lightrec_set_exit_flags(struct lightrec_state *state, u32 flags);
__api u32 lightrec_exit_flags(struct lightrec_state *state);
__api void lightrec_set_unsafe_opt_flags(struct lightrec_state *state, u32 flags);
__api __cnst struct lightrec_registers *
lightrec_get_registers(struct lightrec_state *state);
__api u32 lightrec_current_cycle_count(const struct lightrec_state *state);
__api void lightrec_reset_cycle_count(struct lightrec_state *state, u32 cycles);
__api void lightrec_set_target_cycle_count(struct lightrec_state *state,
u32 cycles);
__api void lightrec_set_cycles_per_opcode(struct lightrec_state *state, u32 cycles);
#ifdef __cplusplus
};
#endif
#endif /* __LIGHTREC_H__ */