Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
cester-cop0.c
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27// This file isn't to be compiled directly. It's to be included in every
28// sub test .c file that requires access to the exception handler test system.
29
30// clang-format off
31
33 static int s_got40;
34 static int s_got80;
35 static uint32_t s_cause;
36 static uint32_t s_epc;
37 static uint32_t s_from;
38 static uint32_t * s_resume;
39 static uint32_t * s_regs;
40 static uint32_t (*s_customhandler)() = NULL;
41 static uint32_t s_oldIMASK;
42 static uint32_t s_oldDPCR;
43 static uint32_t s_oldDICR;
44 uint32_t handler(uint32_t * regs, uint32_t from) {
45 if (from == 0x40) s_got40 = 1;
46 if (from == 0x80) s_got80 = 1;
47
48 uint32_t cause;
49 uint32_t epc;
50
51 s_from = from;
52
53 asm("mfc0 %0, $13\nnop\nmfc0 %1, $14\nnop" : "=r"(cause), "=r"(epc));
54
55 s_cause = cause;
56 s_epc = epc;
57
58 if (s_customhandler) {
59 return s_customhandler();
60 } else {
61 return s_resume ? ((uint32_t)s_resume) : (epc + 4);
62 }
63 }
64 void installExceptionHandlers(uint32_t (*handler)(uint32_t * regs, uint32_t from));
66
67 uint32_t branchbranch1();
68 uint32_t branchbranch2();
69 uint32_t jumpjump1();
70 uint32_t jumpjump2();
71 uint32_t delayslot_add();
72 uint32_t delayslot_syscall();
73 uint32_t delayslot_break();
74 uint32_t delayslot_bc2f();
75 uint32_t delayslot_swi();
76 uint32_t delayslot_nested();
77 uint32_t plain_swi();
78 extern volatile uint32_t delayslot_taken;
79 void delayslot_resume();
80 void delayslot_mark();
81 uint32_t cpu_LWR_LWL_half(uint32_t buff[], uint32_t initial);
82 uint32_t cpu_LWR_LWL_nodelay(uint32_t buff[], uint32_t initial);
83 uint32_t cpu_LWR_LWL_delayed(uint32_t buff[], uint32_t initial);
84 uint32_t cpu_LWR_LWL_load_different(uint32_t buff[], uint32_t initial);
85 uint32_t cpu_LW_LWR(uint32_t buff[], uint32_t initial);
86 uint32_t cpu_delayed_load(uint32_t buff[], uint32_t override);
87 uint32_t cpu_delayed_load_cancelled(uint32_t buff[], uint32_t override);
88 uint64_t cpu_delayed_load_load(uint32_t buff[], uint32_t override);
89 uint32_t linkandload();
90 uint32_t lwandlink();
91 uint32_t nolink();
92 void delayslot_load_first_entry(const uint32_t buff[2], uint32_t out[6]);
93
94 static int s_interruptsWereEnabled;
95)
96
97CESTER_BEFORE_EACH(cpu_tests, testname, testindex,
101 IMASK = 0;
102 IREG = 0;
103 for (unsigned i = 0; i < 7; i++) {
104 DMA_CTRL[i].CHCR = 0;
105 DMA_CTRL[i].BCR = 0;
106 DMA_CTRL[i].MADR = 0;
107 }
108 DPCR = 0;
109 uint32_t dicr = DICR;
111 DICR = 0;
115 s_epc = 0;
117 s_resume = NULL;
118 s_regs = NULL;
120)
121
124 DPCR = s_oldDPCR;
125 DICR = s_oldDICR;
126)
127
129 s_interruptsWereEnabled = enterCriticalSection();
132)
133
137 if (s_interruptsWereEnabled) leaveCriticalSection();
138)
139
uint8_t cause
Definition cdltest.c:207
s_got80
Definition cester-cop0.c:113
s_got40
Definition cester-cop0.c:112
testname
Definition cester-cop0.c:97
s_regs
Definition cester-cop0.c:118
s_from
Definition cester-cop0.c:116
IREG
Definition cester-cop0.c:102
s_customhandler
Definition cester-cop0.c:119
s_epc
Definition cester-cop0.c:115
s_oldDPCR
Definition cester-cop0.c:99
CESTER_BODY(static int s_got40;static int s_got80;static uint32_t s_cause;static uint32_t s_epc;static uint32_t s_from;static uint32_t *s_resume;static uint32_t *s_regs;static uint32_t(*s_customhandler)()=NULL;static uint32_t s_oldIMASK;static uint32_t s_oldDPCR;static uint32_t s_oldDICR;uint32_t handler(uint32_t *regs, uint32_t from) { if(from==0x40) s_got40=1;if(from==0x80) s_got80=1;uint32_t cause;uint32_t epc;s_from=from;asm("mfc0 %0, $13\nnop\nmfc0 %1, $14\nnop" :"=r"(cause), "=r"(epc));s_cause=cause;s_epc=epc;if(s_customhandler) { return s_customhandler();} else { return s_resume ?((uint32_t) s_resume) :(epc+4);} } void installExceptionHandlers(uint32_t(*handler)(uint32_t *regs, uint32_t from));void uninstallExceptionHandlers();uint32_t branchbranch1();uint32_t branchbranch2();uint32_t jumpjump1();uint32_t jumpjump2();uint32_t delayslot_add();uint32_t delayslot_syscall();uint32_t delayslot_break();uint32_t delayslot_bc2f();uint32_t delayslot_swi();uint32_t delayslot_nested();uint32_t plain_swi();extern volatile uint32_t delayslot_taken;void delayslot_resume();void delayslot_mark();uint32_t cpu_LWR_LWL_half(uint32_t buff[], uint32_t initial);uint32_t cpu_LWR_LWL_nodelay(uint32_t buff[], uint32_t initial);uint32_t cpu_LWR_LWL_delayed(uint32_t buff[], uint32_t initial);uint32_t cpu_LWR_LWL_load_different(uint32_t buff[], uint32_t initial);uint32_t cpu_LW_LWR(uint32_t buff[], uint32_t initial);uint32_t cpu_delayed_load(uint32_t buff[], uint32_t override);uint32_t cpu_delayed_load_cancelled(uint32_t buff[], uint32_t override);uint64_t cpu_delayed_load_load(uint32_t buff[], uint32_t override);uint32_t linkandload();uint32_t lwandlink();uint32_t nolink();void delayslot_load_first_entry(const uint32_t buff[2], uint32_t out[6]);static int s_interruptsWereEnabled;) CESTER_BEFORE_EACH(cpu_tests
DICR
Definition cester-cop0.c:110
testindex
Definition cester-cop0.c:97
uint32_t dicr
Definition cester-cop0.c:109
IMASK
Definition cester-cop0.c:101
DPCR
Definition cester-cop0.c:108
s_resume
Definition cester-cop0.c:117
s_cause
Definition cester-cop0.c:114
s_oldDICR
Definition cester-cop0.c:100
s_oldIMASK
Definition cester-cop0.c:98
s_interruptsWereEnabled
Definition cester-hw.c:291
cpu_tests
Definition cop-branch.c:118
void installExceptionHandlers(uint32_t(*handler)(uint32_t *regs, uint32_t from))
Definition exceptions.cpp:70
void uninstallExceptionHandlers(void)
Definition exceptions.cpp:84
delayslot_swi()
uint32_t buff[2]
Definition cpu.c:77
uint32_t out
Definition cpu.c:62
#define DMA_CTRL
Definition dma.h:36
CESTER_AFTER_ALL(CESTER_TEST(gpudmaloop, GPU_STATUS=0x00000000;if(s_interruptsWereEnabled) leaveCriticalSection();)
Definition gpu-dma-loop.c:133
CESTER_BEFORE_ALL(CESTER_TEST(gte_latency_tests, gte_enable();)
Definition gte-latency.c:115
int i
Definition gte-regio.c:299
syscall_flushCache()
CESTER_AFTER_EACH(CESTER_TEST(load_tests, testname, testindex)
Definition load-timings.c:708
static uint32_t uint32_t void(* handler)())
Definition syscalls.h:401