Skip to content

Commit 48a92cf

Browse files
committed
wraper for functions that break ABI
1 parent 2cfeaa1 commit 48a92cf

File tree

6 files changed

+41
-25
lines changed

6 files changed

+41
-25
lines changed

include/ctr/test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ctr/rng.h>
99
#include <ctr/coll.h>
1010

11+
void TEST_WRAPPER();
1112
void LoadTestPatches();
1213
u32 PatchFunction_Beg(u32* index);
1314
void PatchFunction_End(u32 index);

rewrite/scripts/codeflow/output.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,27 @@ main()
106106
ND_COLL_FIXED_TRIANGL_GetNormVec()
107107
ND_COLL_FIXED_TRIANGL_GetNormVec()
108108
ND_COLL_MOVED_TRIANGL_TestPoint()
109-
FUN_8001f928()
109+
ND_COLL_BarycentricTest()
110110
ND_COLL_MOVED_TRIANGL_TestPoint()
111-
FUN_8001f928()
112-
ND_COLL_FIXED_TRIANGL_Barycentrics()
111+
ND_COLL_BarycentricTest()
112+
ND_COLL_ProjectPointToEdge()
113113
ND_COLL_MOVED_TRIANGL_TestPoint()
114-
FUN_8001f928()
115-
ND_COLL_FIXED_TRIANGL_Barycentrics()
114+
ND_COLL_BarycentricTest()
115+
ND_COLL_ProjectPointToEdge()
116116
ND_COLL_MOVED_TRIANGL_TestPoint()
117-
FUN_8001f928()
118-
ND_COLL_FIXED_TRIANGL_Barycentrics()
117+
ND_COLL_BarycentricTest()
118+
ND_COLL_ProjectPointToEdge()
119119
ND_COLL_MOVED_TRIANGL_TestPoint()
120-
FUN_8001f928()
120+
ND_COLL_BarycentricTest()
121121
ND_COLL_MOVED_TRIANGL_TestPoint()
122-
FUN_8001f928()
123-
ND_COLL_FIXED_TRIANGL_Barycentrics()
122+
ND_COLL_BarycentricTest()
123+
ND_COLL_ProjectPointToEdge()
124124
ND_COLL_MOVED_TRIANGL_TestPoint()
125-
FUN_8001f928()
126-
ND_COLL_FIXED_TRIANGL_Barycentrics()
125+
ND_COLL_BarycentricTest()
126+
ND_COLL_ProjectPointToEdge()
127127
ND_COLL_MOVED_TRIANGL_TestPoint()
128-
FUN_8001f928()
129-
ND_COLL_FIXED_TRIANGL_Barycentrics()
128+
ND_COLL_BarycentricTest()
129+
ND_COLL_ProjectPointToEdge()
130130
ND_COLL_MOVED_QUADBLK_TestTriangles()
131131
ND_COLL_FIXED_BSPLEAF_TestInstance()
132132
FUN_80020334()

rewrite/src/exe/coll.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ void COLL_ProjectPointToEdge(SVec3* out, const SVec3* v1, const SVec3* v2, const
3636
out->y = coords.y;
3737
out->z = coords.z;
3838
TEST_COLL_ProjectPointToEdge(v1, v2, point, out);
39+
#ifdef TEST_COLL_IMPL
40+
__asm__ volatile("move $a0, %0" : : "r"((u32)out));
41+
__asm__ volatile("move $a1, %0" : : "r"((u32)v1));
42+
__asm__ volatile("move $a2, %0" : : "r"((u32)v2));
43+
__asm__ volatile("move $a3, %0" : : "r"((u32)point));
44+
#endif
3945
}
4046

4147
/* Address: 0x8001f928 */

rewrite/src/tests/test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ void LoadTestPatches()
5050

5151
u32 PatchFunction_Beg(u32* address)
5252
{
53+
u32 addr = (u32)address;
54+
__asm__ volatile("move $k1, %0" : : "r"(addr));
55+
5356
u32 index = 0;
5457
const u32 funcCount = ARR_LEN(s_functions);
5558
for (u32 i = 0; i < funcCount; i++)

rewrite/src/tests/test_coll.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ void TEST_COLL_ProjectPointToEdge(const SVec3* v1, const SVec3* v2, const SVec3*
66
{
77
const u32 index = PatchFunction_Beg((u32*)(&ND_COLL_ProjectPointToEdge));
88
SVec3 expected;
9-
ND_COLL_ProjectPointToEdge(&expected, v1, v2, point);
9+
typedef void (*Func)(SVec3* out, const SVec3* v1, const SVec3* v2, const SVec3* point);
10+
Func func = (Func) TEST_WRAPPER;
11+
func(&expected, v1, v2, point);
1012
PrintSVectorDiff("COLL_ProjectPointToEdge", &expected, ret);
1113
PatchFunction_End(index);
1214
}
1315

14-
s32 WRAPPER_ND_COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
1516

1617
void TEST_COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3, const SVec3* pos, s32 ret)
1718
{
1819
const u32 index = PatchFunction_Beg((u32*)(&ND_COLL_BarycentricTest));
19-
const s32 expected = WRAPPER_ND_COLL_BarycentricTest(t, v1, v2, v3);
20+
typedef s32 (*Func)(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3);
21+
Func func = (Func) TEST_WRAPPER;
22+
const s32 expected = func(t, v1, v2, v3);
2023
PrintSVectorDiff("COLL_BarycentricTest", &t->pos, pos);
2124
if (expected != ret) { ND_printf("[COLL_BarycentricTest] Test Failed:\nExpected: %d\nResult: %d\n", expected, ret); }
2225
PatchFunction_End(index);

rewrite/src/tests/test_wrappers.s

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.set noreorder
2+
.set noat
23
.align 2
34
.macro SAVE_CONTEXT
4-
addiu $sp, $sp, -44
5+
addiu $sp, $sp, -48
56
sw $s0, 0($sp)
67
sw $s1, 4($sp)
78
sw $s2, 8($sp)
@@ -12,11 +13,13 @@
1213
sw $s7, 28($sp)
1314
sw $fp, 32($sp)
1415
sw $gp, 36($sp)
15-
sw $ra, 40($sp)
16+
sw $at, 40($sp)
17+
sw $ra, 44($sp)
1618
.endm
1719

1820
.macro RESTORE_CONTEXT
19-
lw $ra, 40($sp)
21+
lw $ra, 44($sp)
22+
lw $at, 40($sp)
2023
lw $gp, 36($sp)
2124
lw $fp, 32($sp)
2225
lw $s7, 28($sp)
@@ -27,14 +30,14 @@
2730
lw $s2, 8($sp)
2831
lw $s1, 4($sp)
2932
lw $s0, 0($sp)
30-
addiu $sp, $sp, 44
33+
addiu $sp, $sp, 48
3134
.endm
3235

33-
.global WRAPPER_ND_COLL_BarycentricTest
34-
.type WRAPPER_ND_COLL_BarycentricTest, @function
35-
WRAPPER_ND_COLL_BarycentricTest:
36+
.global TEST_WRAPPER
37+
.type TEST_WRAPPER, @function
38+
TEST_WRAPPER:
3639
SAVE_CONTEXT
37-
jal ND_COLL_BarycentricTest
40+
jalr $k1
3841
nop
3942
RESTORE_CONTEXT
4043
jr $ra

0 commit comments

Comments
 (0)