git subrepo clone https://github.com/pcercuei/lightrec.git deps/lightrec
[pcsx_rearmed.git] / deps / lightrec / lightrec.h
CommitLineData
d16005f8
PC
1/*
2 * Copyright (C) 2016 Paul Cercueil <paul@crapouillou.net>
3 *
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.
8 *
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.
13 */
14
15#ifndef __LIGHTREC_H__
16#define __LIGHTREC_H__
17
18#ifdef __cplusplus
19#define _Bool bool
20extern "C" {
21#endif
22
23#include <stddef.h>
24#include <stdint.h>
25
26#ifdef _WIN32
27# ifdef lightrec_EXPORTS
28# define __api __declspec(dllexport)
29# elif !defined(LIGHTREC_STATIC)
30# define __api __declspec(dllimport)
31# else
32# define __api
33# endif
34#elif __GNUC__ >= 4
35# define __api __attribute__((visibility ("default")))
36#else
37# define __api
38#endif
39
40typedef uint64_t u64;
41typedef uint32_t u32;
42typedef uint16_t u16;
43typedef uint8_t u8;
44
45typedef int64_t s64;
46typedef int32_t s32;
47typedef int16_t s16;
48typedef int8_t s8;
49
50struct lightrec_state;
51struct lightrec_mem_map;
52
53/* Exit flags */
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)
59
60enum psx_map {
61 PSX_MAP_KERNEL_USER_RAM,
62 PSX_MAP_BIOS,
63 PSX_MAP_SCRATCH_PAD,
64 PSX_MAP_PARALLEL_PORT,
65 PSX_MAP_HW_REGISTERS,
66 PSX_MAP_CACHE_CONTROL,
67 PSX_MAP_MIRROR1,
68 PSX_MAP_MIRROR2,
69 PSX_MAP_MIRROR3,
70};
71
72enum mem_type {
73 MEM_FOR_CODE,
74 MEM_FOR_MIPS_CODE,
75 MEM_FOR_IR,
76 MEM_FOR_LIGHTREC,
77 MEM_TYPE_END,
78};
79
80struct 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);
87};
88
89struct lightrec_mem_map {
90 u32 pc;
91 u32 length;
92 void *address;
93 const struct lightrec_mem_map_ops *ops;
94 const struct lightrec_mem_map *mirror_of;
95};
96
97struct 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);
103};
104
105struct lightrec_ops {
106 struct lightrec_cop_ops cop0_ops;
107 struct lightrec_cop_ops cop2_ops;
108};
109
110__api struct lightrec_state *lightrec_init(char *argv0,
111 const struct lightrec_mem_map *map,
112 size_t nb,
113 const struct lightrec_ops *ops);
114
115__api void lightrec_destroy(struct lightrec_state *state);
116
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);
121
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,
125 _Bool dma_only);
126
127__api void lightrec_set_exit_flags(struct lightrec_state *state, u32 flags);
128__api u32 lightrec_exit_flags(struct lightrec_state *state);
129
130__api void lightrec_dump_registers(struct lightrec_state *state, u32 regs[34]);
131__api void lightrec_restore_registers(struct lightrec_state *state,
132 u32 regs[34]);
133
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,
137 u32 cycles);
138
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);
142
143#ifdef __cplusplus
144};
145#endif
146
147#endif /* __LIGHTREC_H__ */