git subrepo pull --force deps/lightning
[pcsx_rearmed.git] / deps / lightrec / lightrec.h
CommitLineData
98fa08a5 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
d16005f8 2/*
98fa08a5 3 * Copyright (C) 2016-2021 Paul Cercueil <paul@crapouillou.net>
d16005f8
PC
4 */
5
6#ifndef __LIGHTREC_H__
7#define __LIGHTREC_H__
8
9#ifdef __cplusplus
10#define _Bool bool
11extern "C" {
12#endif
13
14#include <stddef.h>
15#include <stdint.h>
16
17#ifdef _WIN32
18# ifdef lightrec_EXPORTS
19# define __api __declspec(dllexport)
20# elif !defined(LIGHTREC_STATIC)
21# define __api __declspec(dllimport)
22# else
23# define __api
24# endif
25#elif __GNUC__ >= 4
26# define __api __attribute__((visibility ("default")))
27#else
28# define __api
29#endif
30
31typedef uint64_t u64;
32typedef uint32_t u32;
33typedef uint16_t u16;
34typedef uint8_t u8;
35
36typedef int64_t s64;
37typedef int32_t s32;
38typedef int16_t s16;
39typedef int8_t s8;
40
41struct lightrec_state;
42struct lightrec_mem_map;
43
44/* Exit flags */
45#define LIGHTREC_EXIT_NORMAL (0)
98fa08a5 46#define LIGHTREC_EXIT_CHECK_INTERRUPT (1 << 0)
d16005f8 47#define LIGHTREC_EXIT_BREAK (1 << 1)
98fa08a5 48#define LIGHTREC_EXIT_SYSCALL (1 << 2)
d16005f8 49#define LIGHTREC_EXIT_SEGFAULT (1 << 3)
d8b04acd 50#define LIGHTREC_EXIT_NOMEM (1 << 4)
d16005f8
PC
51
52enum psx_map {
53 PSX_MAP_KERNEL_USER_RAM,
54 PSX_MAP_BIOS,
55 PSX_MAP_SCRATCH_PAD,
56 PSX_MAP_PARALLEL_PORT,
57 PSX_MAP_HW_REGISTERS,
58 PSX_MAP_CACHE_CONTROL,
59 PSX_MAP_MIRROR1,
60 PSX_MAP_MIRROR2,
61 PSX_MAP_MIRROR3,
02487de7
PC
62 PSX_MAP_CODE_BUFFER,
63
64 PSX_MAP_UNKNOWN,
d16005f8
PC
65};
66
d16005f8 67struct lightrec_mem_map_ops {
a59e5536 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);
d16005f8
PC
77};
78
79struct lightrec_mem_map {
80 u32 pc;
81 u32 length;
82 void *address;
83 const struct lightrec_mem_map_ops *ops;
84 const struct lightrec_mem_map *mirror_of;
85};
86
98fa08a5 87struct lightrec_ops {
fdf33147 88 void (*cop2_notify)(struct lightrec_state *state, u32 op, u32 data);
98fa08a5
PC
89 void (*cop2_op)(struct lightrec_state *state, u32 op);
90 void (*enable_ram)(struct lightrec_state *state, _Bool enable);
ba3814c1 91 _Bool (*hw_direct)(u32 kaddr, _Bool is_write, u8 size);
d16005f8
PC
92};
93
98fa08a5
PC
94struct lightrec_registers {
95 u32 gpr[34];
96 u32 cp0[32];
97 u32 cp2d[32];
98 u32 cp2c[32];
d16005f8
PC
99};
100
101__api struct lightrec_state *lightrec_init(char *argv0,
102 const struct lightrec_mem_map *map,
103 size_t nb,
104 const struct lightrec_ops *ops);
105
106__api void lightrec_destroy(struct lightrec_state *state);
107
108__api u32 lightrec_execute(struct lightrec_state *state,
109 u32 pc, u32 target_cycle);
ba3814c1
PC
110__api u32 lightrec_run_interpreter(struct lightrec_state *state,
111 u32 pc, u32 target_cycle);
d16005f8
PC
112
113__api void lightrec_invalidate(struct lightrec_state *state, u32 addr, u32 len);
114__api void lightrec_invalidate_all(struct lightrec_state *state);
115__api void lightrec_set_invalidate_mode(struct lightrec_state *state,
116 _Bool dma_only);
117
118__api void lightrec_set_exit_flags(struct lightrec_state *state, u32 flags);
119__api u32 lightrec_exit_flags(struct lightrec_state *state);
120
98fa08a5 121__api struct lightrec_registers * lightrec_get_registers(struct lightrec_state *state);
d16005f8
PC
122
123__api u32 lightrec_current_cycle_count(const struct lightrec_state *state);
124__api void lightrec_reset_cycle_count(struct lightrec_state *state, u32 cycles);
125__api void lightrec_set_target_cycle_count(struct lightrec_state *state,
126 u32 cycles);
127
d16005f8
PC
128#ifdef __cplusplus
129};
130#endif
131
132#endif /* __LIGHTREC_H__ */