2 * Copyright (C) 2016-2020 Paul Cercueil <paul@crapouillou.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
15 #ifndef __LIGHTREC_H__
16 #define __LIGHTREC_H__
27 # ifdef lightrec_EXPORTS
28 # define __api __declspec(dllexport)
29 # elif !defined(LIGHTREC_STATIC)
30 # define __api __declspec(dllimport)
35 # define __api __attribute__((visibility ("default")))
50 struct lightrec_state;
51 struct lightrec_mem_map;
54 #define LIGHTREC_EXIT_NORMAL (0)
55 #define LIGHTREC_EXIT_SYSCALL (1 << 0)
56 #define LIGHTREC_EXIT_BREAK (1 << 1)
57 #define LIGHTREC_EXIT_CHECK_INTERRUPT (1 << 2)
58 #define LIGHTREC_EXIT_SEGFAULT (1 << 3)
61 PSX_MAP_KERNEL_USER_RAM,
64 PSX_MAP_PARALLEL_PORT,
66 PSX_MAP_CACHE_CONTROL,
80 struct lightrec_mem_map_ops {
81 void (*sb)(struct lightrec_state *, u32 opcode,
82 void *host, u32 addr, u8 data);
83 void (*sh)(struct lightrec_state *, u32 opcode,
84 void *host, u32 addr, u16 data);
85 void (*sw)(struct lightrec_state *, u32 opcode,
86 void *host, u32 addr, u32 data);
87 u8 (*lb)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
88 u16 (*lh)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
89 u32 (*lw)(struct lightrec_state *, u32 opcode, void *host, u32 addr);
92 struct lightrec_mem_map {
96 const struct lightrec_mem_map_ops *ops;
97 const struct lightrec_mem_map *mirror_of;
100 struct lightrec_cop_ops {
101 u32 (*mfc)(struct lightrec_state *state, u32 op, u8 reg);
102 u32 (*cfc)(struct lightrec_state *state, u32 op, u8 reg);
103 void (*mtc)(struct lightrec_state *state, u32 op, u8 reg, u32 value);
104 void (*ctc)(struct lightrec_state *state, u32 op, u8 reg, u32 value);
105 void (*op)(struct lightrec_state *state, u32 op);
108 struct lightrec_ops {
109 struct lightrec_cop_ops cop0_ops;
110 struct lightrec_cop_ops cop2_ops;
113 __api struct lightrec_state *lightrec_init(char *argv0,
114 const struct lightrec_mem_map *map,
116 const struct lightrec_ops *ops);
118 __api void lightrec_destroy(struct lightrec_state *state);
120 __api u32 lightrec_execute(struct lightrec_state *state,
121 u32 pc, u32 target_cycle);
122 __api u32 lightrec_execute_one(struct lightrec_state *state, u32 pc);
123 __api u32 lightrec_run_interpreter(struct lightrec_state *state, u32 pc);
125 __api void lightrec_invalidate(struct lightrec_state *state, u32 addr, u32 len);
126 __api void lightrec_invalidate_all(struct lightrec_state *state);
127 __api void lightrec_set_invalidate_mode(struct lightrec_state *state,
130 __api void lightrec_set_exit_flags(struct lightrec_state *state, u32 flags);
131 __api u32 lightrec_exit_flags(struct lightrec_state *state);
133 __api void lightrec_dump_registers(struct lightrec_state *state, u32 regs[34]);
134 __api void lightrec_restore_registers(struct lightrec_state *state,
137 __api u32 lightrec_current_cycle_count(const struct lightrec_state *state);
138 __api void lightrec_reset_cycle_count(struct lightrec_state *state, u32 cycles);
139 __api void lightrec_set_target_cycle_count(struct lightrec_state *state,
142 __api unsigned int lightrec_get_mem_usage(enum mem_type type);
143 __api unsigned int lightrec_get_total_mem_usage(void);
144 __api float lightrec_get_average_ipi(void);
150 #endif /* __LIGHTREC_H__ */