1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 * Copyright (C) 2016-2021 Paul Cercueil <paul@crapouillou.net>
18 # ifdef lightrec_EXPORTS
19 # define __api __declspec(dllexport)
20 # elif !defined(LIGHTREC_STATIC)
21 # define __api __declspec(dllimport)
26 # define __api __attribute__((visibility ("default")))
33 # define __cnst __attribute__((const))
40 # define __pure __attribute__((pure))
56 struct lightrec_state;
57 struct lightrec_mem_map;
60 #define LIGHTREC_EXIT_NORMAL (0)
61 #define LIGHTREC_EXIT_CHECK_INTERRUPT (1 << 0)
62 #define LIGHTREC_EXIT_BREAK (1 << 1)
63 #define LIGHTREC_EXIT_SYSCALL (1 << 2)
64 #define LIGHTREC_EXIT_SEGFAULT (1 << 3)
65 #define LIGHTREC_EXIT_NOMEM (1 << 4)
66 #define LIGHTREC_EXIT_UNKNOWN_OP (1 << 5)
68 /* Unsafe optimizations flags */
69 #define LIGHTREC_OPT_INV_DMA_ONLY (1 << 0)
70 #define LIGHTREC_OPT_SP_GP_HIT_RAM (1 << 1)
73 PSX_MAP_KERNEL_USER_RAM,
76 PSX_MAP_PARALLEL_PORT,
78 PSX_MAP_CACHE_CONTROL,
88 struct lightrec_mem_map_ops {
89 void (*sb)(struct lightrec_state *, u32 opcode,
90 void *host, u32 addr, u32 data);
91 void (*sh)(struct lightrec_state *, u32 opcode,
92 void *host, u32 addr, u32 data);
93 void (*sw)(struct lightrec_state *, u32 opcode,
94 void *host, u32 addr, u32 data);
95 u8 (*lb)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
96 u16 (*lh)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
97 u32 (*lw)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
98 u32 (*lwu)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
99 void (*swu)(struct lightrec_state *, u32 opcode,
100 void *host, u32 addr, u32 data);
103 struct lightrec_mem_map {
107 const struct lightrec_mem_map_ops *ops;
108 const struct lightrec_mem_map *mirror_of;
111 struct lightrec_ops {
112 void (*cop2_notify)(struct lightrec_state *state, u32 op, u32 data);
113 void (*cop2_op)(struct lightrec_state *state, u32 op);
114 void (*enable_ram)(struct lightrec_state *state, _Bool enable);
115 _Bool (*hw_direct)(u32 kaddr, _Bool is_write, u8 size);
116 void (*code_inv)(void *addr, u32 len);
119 struct lightrec_registers {
126 __api struct lightrec_state *lightrec_init(char *argv0,
127 const struct lightrec_mem_map *map,
129 const struct lightrec_ops *ops);
131 __api void lightrec_destroy(struct lightrec_state *state);
133 __api u32 lightrec_execute(struct lightrec_state *state,
134 u32 pc, u32 target_cycle);
135 __api u32 lightrec_run_interpreter(struct lightrec_state *state,
136 u32 pc, u32 target_cycle);
138 __api void lightrec_invalidate(struct lightrec_state *state, u32 addr, u32 len);
139 __api void lightrec_invalidate_all(struct lightrec_state *state);
141 __api void lightrec_set_exit_flags(struct lightrec_state *state, u32 flags);
142 __api u32 lightrec_exit_flags(struct lightrec_state *state);
144 __api void lightrec_set_unsafe_opt_flags(struct lightrec_state *state, u32 flags);
146 __api __cnst struct lightrec_registers *
147 lightrec_get_registers(struct lightrec_state *state);
149 __api u32 lightrec_current_cycle_count(const struct lightrec_state *state);
150 __api void lightrec_reset_cycle_count(struct lightrec_state *state, u32 cycles);
151 __api void lightrec_set_target_cycle_count(struct lightrec_state *state,
153 __api void lightrec_set_cycles_per_opcode(struct lightrec_state *state, u32 cycles);
159 #endif /* __LIGHTREC_H__ */