2 * Copyright (C) 2016 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 addr, u8 data);
82 void (*sh)(struct lightrec_state *, u32 addr, u16 data);
83 void (*sw)(struct lightrec_state *, u32 addr, u32 data);
84 u8 (*lb)(struct lightrec_state *, u32 addr);
85 u16 (*lh)(struct lightrec_state *, u32 addr);
86 u32 (*lw)(struct lightrec_state *, u32 addr);
89 struct lightrec_mem_map {
93 const struct lightrec_mem_map_ops *ops;
94 const struct lightrec_mem_map *mirror_of;
97 struct lightrec_cop_ops {
98 u32 (*mfc)(struct lightrec_state *state, u8 reg);
99 u32 (*cfc)(struct lightrec_state *state, u8 reg);
100 void (*mtc)(struct lightrec_state *state, u8 reg, u32 value);
101 void (*ctc)(struct lightrec_state *state, u8 reg, u32 value);
102 void (*op)(struct lightrec_state *state, u32 opcode);
105 struct lightrec_ops {
106 struct lightrec_cop_ops cop0_ops;
107 struct lightrec_cop_ops cop2_ops;
110 __api struct lightrec_state *lightrec_init(char *argv0,
111 const struct lightrec_mem_map *map,
113 const struct lightrec_ops *ops);
115 __api void lightrec_destroy(struct lightrec_state *state);
117 __api u32 lightrec_execute(struct lightrec_state *state,
118 u32 pc, u32 target_cycle);
119 __api u32 lightrec_execute_one(struct lightrec_state *state, u32 pc);
120 __api u32 lightrec_run_interpreter(struct lightrec_state *state, u32 pc);
122 __api void lightrec_invalidate(struct lightrec_state *state, u32 addr, u32 len);
123 __api void lightrec_invalidate_all(struct lightrec_state *state);
124 __api void lightrec_set_invalidate_mode(struct lightrec_state *state,
127 __api void lightrec_set_exit_flags(struct lightrec_state *state, u32 flags);
128 __api u32 lightrec_exit_flags(struct lightrec_state *state);
130 __api void lightrec_dump_registers(struct lightrec_state *state, u32 regs[34]);
131 __api void lightrec_restore_registers(struct lightrec_state *state,
134 __api u32 lightrec_current_cycle_count(const struct lightrec_state *state);
135 __api void lightrec_reset_cycle_count(struct lightrec_state *state, u32 cycles);
136 __api void lightrec_set_target_cycle_count(struct lightrec_state *state,
139 __api unsigned int lightrec_get_mem_usage(enum mem_type type);
140 __api unsigned int lightrec_get_total_mem_usage(void);
141 __api float lightrec_get_average_ipi(void);
147 #endif /* __LIGHTREC_H__ */