Match __mem.c and ptmf.c

This commit is contained in:
LagoLunatic
2023-11-08 22:48:15 -05:00
parent 0fed096c00
commit 1f4c0de0c6
5 changed files with 157 additions and 2 deletions
+2 -2
View File
@@ -1066,12 +1066,12 @@ config.libs = [
"cflags": cflags_runtime,
"host": False,
"objects": [
Object(NonMatching, "Runtime.PPCEABI.H/__mem.c"),
Object(Matching, "Runtime.PPCEABI.H/__mem.c"),
Object(Matching, "Runtime.PPCEABI.H/__va_arg.c"),
Object(Matching, "Runtime.PPCEABI.H/global_destructor_chain.c"),
Object(Matching, "Runtime.PPCEABI.H/CPlusLibPPC.cp"),
Object(NonMatching, "Runtime.PPCEABI.H/NMWException.cp"),
Object(NonMatching, "Runtime.PPCEABI.H/ptmf.c"),
Object(Matching, "Runtime.PPCEABI.H/ptmf.c"),
Object(NonMatching, "Runtime.PPCEABI.H/runtime.c"),
Object(Matching, "Runtime.PPCEABI.H/__init_cpp_exceptions.cpp"),
Object(Matching, "Runtime.PPCEABI.H/Gecko_ExceptionPPC.cp"),
+16
View File
@@ -0,0 +1,16 @@
#ifndef RUNTIME_MEM_H
#define RUNTIME_MEM_H
#ifdef __cplusplus
extern "C" {
#endif
__declspec(section ".init") void* memcpy(void* dest, const void* src, size_t n);
__declspec(section ".init") void __fill_mem(void* dest, int val, size_t count);
__declspec(section ".init") void* memset(void* dest, int val, size_t count);
#ifdef __cplusplus
}
#endif
#endif /* RUNTIME_MEM_H */
+5
View File
@@ -10,4 +10,9 @@ typedef struct __ptmf {
} f_data;
} __ptmf;
const __ptmf __ptmf_null;
long __ptmf_test(__ptmf* ptmf);
void __ptmf_cmpr(register __ptmf* this, register __ptmf* other);
void __ptmf_scall(...);
#endif /* PTMF_H */
+84
View File
@@ -0,0 +1,84 @@
#include "dolphin/types.h"
#include "Runtime.PPCEABI.H/__mem.h"
void* memcpy(void* dst, const void* src, size_t n)
{
const char* p;
char* q;
int rev = ((u32)src < (u32)dst);
if (!rev) {
for (p = (const char*)src - 1, q = (char*)dst - 1, n++; --n;)
*++q = *++p;
} else {
for (p = (const char*)src + n, q = (char*)dst + n, n++; --n;)
*--q = *--p;
}
return (dst);
}
void __fill_mem(void* dst, int val, u32 n)
{
u32 v = (u8)val;
u32 i;
((u8*)dst) = ((u8*)dst) - 1;
if (n >= 32) {
i = (~(u32)dst) & 3;
if (i) {
n -= i;
do
*++(((u8*)dst)) = v;
while (--i);
}
if (v)
v |= v << 24 | v << 16 | v << 8;
((u32*)dst) = ((u32*)(((u8*)dst) + 1)) - 1;
i = n >> 5;
if (i)
do {
*++(((u32*)dst)) = v;
*++(((u32*)dst)) = v;
*++(((u32*)dst)) = v;
*++(((u32*)dst)) = v;
*++(((u32*)dst)) = v;
*++(((u32*)dst)) = v;
*++(((u32*)dst)) = v;
*++(((u32*)dst)) = v;
} while (--i);
i = (n & 31) >> 2;
if (i)
do
*++(((u32*)dst)) = v;
while (--i);
((u8*)dst) = ((u8*)(((u32*)dst) + 1)) - 1;
n &= 3;
}
if (n)
do
*++(((u8*)dst)) = v;
while (--n);
return;
}
void* memset(void* dst, int val, size_t n)
{
__fill_mem(dst, val, n);
return (dst);
}
+50
View File
@@ -1 +1,51 @@
#include "Runtime.PPCEABI.H/ptmf.h"
const __ptmf __ptmf_null = { 0, 0, 0 };
asm long __ptmf_test(register __ptmf* ptmf) {
lwz r5, __ptmf.this_delta(ptmf)
lwz r6, __ptmf.v_offset(ptmf)
lwz r7, __ptmf.f_data(ptmf)
li r3, 0x1
cmpwi r5, 0x0
cmpwi cr6, r6, 0x0
cmpwi cr7, r7, 0x0
bnelr
bnelr cr6
bnelr cr7
li r3, 0x0
blr
};
asm void __ptmf_cmpr(register __ptmf* lhs, register __ptmf* rhs) {
lwz r5, __ptmf.this_delta(lhs)
lwz r6, __ptmf.this_delta(rhs)
lwz r7, __ptmf.v_offset(lhs)
lwz r8, __ptmf.v_offset(rhs)
lwz r9, __ptmf.f_data(lhs)
lwz r10, __ptmf.f_data(rhs)
li r3, 0x1
cmpw r5, r6
cmpw cr6, r7, r8
cmpw cr7, r9, r10
bnelr
bnelr cr6
bnelr cr7
li r3, 0x0
blr
};
asm void __ptmf_scall(...) {
nofralloc;
lwz r0, __ptmf.this_delta(r12)
lwz r11, __ptmf.v_offset(r12)
lwz r12, __ptmf.f_data(r12)
add r3, r3, r0
cmpwi r11, 0x0
blt do_call
lwzx r12, r3, r12
lwzx r12, r12, r11
do_call:
mtctr r12
bctr
};