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")))
41 struct lightrec_state;
42 struct lightrec_mem_map;
45 #define LIGHTREC_EXIT_NORMAL (0)
46 #define LIGHTREC_EXIT_CHECK_INTERRUPT (1 << 0)
47 #define LIGHTREC_EXIT_BREAK (1 << 1)
48 #define LIGHTREC_EXIT_SYSCALL (1 << 2)
49 #define LIGHTREC_EXIT_SEGFAULT (1 << 3)
50 #define LIGHTREC_EXIT_NOMEM (1 << 4)
53 PSX_MAP_KERNEL_USER_RAM,
56 PSX_MAP_PARALLEL_PORT,
58 PSX_MAP_CACHE_CONTROL,
67 struct lightrec_mem_map_ops {
68 void (*sb)(struct lightrec_state *, u32 opcode,
69 void *host, u32 addr, u8 data);
70 void (*sh)(struct lightrec_state *, u32 opcode,
71 void *host, u32 addr, u16 data);
72 void (*sw)(struct lightrec_state *, u32 opcode,
73 void *host, u32 addr, u32 data);
74 u8 (*lb)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
75 u16 (*lh)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
76 u32 (*lw)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
79 struct lightrec_mem_map {
83 const struct lightrec_mem_map_ops *ops;
84 const struct lightrec_mem_map *mirror_of;
88 void (*cop2_op)(struct lightrec_state *state, u32 op);
89 void (*enable_ram)(struct lightrec_state *state, _Bool enable);
92 struct lightrec_registers {
99 __api struct lightrec_state *lightrec_init(char *argv0,
100 const struct lightrec_mem_map *map,
102 const struct lightrec_ops *ops);
104 __api void lightrec_destroy(struct lightrec_state *state);
106 __api u32 lightrec_execute(struct lightrec_state *state,
107 u32 pc, u32 target_cycle);
108 __api u32 lightrec_execute_one(struct lightrec_state *state, u32 pc);
109 __api u32 lightrec_run_interpreter(struct lightrec_state *state, u32 pc);
111 __api void lightrec_invalidate(struct lightrec_state *state, u32 addr, u32 len);
112 __api void lightrec_invalidate_all(struct lightrec_state *state);
113 __api void lightrec_set_invalidate_mode(struct lightrec_state *state,
116 __api void lightrec_set_exit_flags(struct lightrec_state *state, u32 flags);
117 __api u32 lightrec_exit_flags(struct lightrec_state *state);
119 __api struct lightrec_registers * lightrec_get_registers(struct lightrec_state *state);
121 __api u32 lightrec_current_cycle_count(const struct lightrec_state *state);
122 __api void lightrec_reset_cycle_count(struct lightrec_state *state, u32 cycles);
123 __api void lightrec_set_target_cycle_count(struct lightrec_state *state,
130 #endif /* __LIGHTREC_H__ */