__mem.c
This commit is contained in:
parent
fd8f8a4cee
commit
d049f2f0d1
11 changed files with 372 additions and 9 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"editor.tabSize": 2
|
||||
"editor.tabSize": 2,
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
build/obj/0.o
|
||||
build/obj/sdk/msl/runtime/__mem.o
|
||||
build/obj/1.o
|
||||
build/obj/sdk/rvl/os/__start.o
|
||||
build/obj/sdk/rvl/os/__ppc_eabi_init.o
|
||||
build/obj/3.o
|
||||
build/obj/4.o
|
||||
build/obj/5.o
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
.init start,.init end,extab start,extab end,extabindex start,extabindex end,.text start,.text end,.ctors start,.ctors end,.dtors start,.dtors end,.rodata start,.rodata end,.data start,.data end,.bss start,.bss end,.sdata start,.sdata end,.sbss start,.sbss end,.sdata2 start,.sdata2 end,.sbss2 start,.sbss2 end,File
|
||||
800062f0,80006620,,,,,,,,,,,,,,,,,,,8055c878,8055c879,,,,,sdk/rvl/os/__start.o
|
||||
80004000,80004380,,,,,,,,,,,,,,,,,,,,,,,,,sdk/msl/runtime/__mem.o
|
||||
800062c0,80006620,,,,,,,,,,,,,,,,,,,8055c878,8055c879,,,,,sdk/rvl/os/__start.o
|
||||
80006620,80006684,,,,,,,,,,,,,,,,,,,,,,,,,sdk/rvl/os/__ppc_eabi_init.o
|
||||
,,,,,,,,80406540,80406544,,,,,,,,,,,,,,,,,Linker generated symbol file
|
||||
80006684,80006728,,,,,,,8040652c,80406530,80406548,8040654c,,,,,,,,,,,,,,,Linker generated symbol file
|
||||
|
|
|
|
@ -1,8 +1,6 @@
|
|||
Address,SymbolName
|
||||
80004000,memcpy
|
||||
80004350,memset
|
||||
80006310,__start
|
||||
800062c0,__check_pad3
|
||||
80006b88,__destroy_global_chain
|
||||
800079fc,__init_cpp_exceptions
|
||||
80007a38,__fini_cpp_exceptions
|
||||
|
@ -12,6 +10,7 @@ Address,SymbolName
|
|||
8001ad80,OSInit
|
||||
8001b670,__OSPSInit
|
||||
8001cea0,__OSCacheInit
|
||||
80023820,OSResetSystem
|
||||
80028530,__init_user
|
||||
800285a0,exit
|
||||
80174ad8,main
|
||||
|
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <size_t.h>
|
||||
#include "size_t.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -10,5 +10,5 @@ set -e
|
|||
#if [[ $OSTYPE == 'darwin' ]]; then
|
||||
# docker run -it --rm --volume $PWD/build/wine:/home/wineuser/.wine --volume $PWD:$PWD -w $PWD scottyhardy/docker-wine wine "$@"
|
||||
#else
|
||||
wine "$@"
|
||||
WINEARCH=win32 WINEPREFIX=$HOME/.wine32 wine "$@"
|
||||
#fi
|
265
sdk/msl/runtime/__mem.c
Normal file
265
sdk/msl/runtime/__mem.c
Normal file
|
@ -0,0 +1,265 @@
|
|||
// Source:
|
||||
// https://github.com/doldecomp/ogws/blob/82dbeac2267170fc5cef7e67a6d8c31c5ff45d69/src/RevoSDK/TRK/__mem.c
|
||||
// Decompiled by GibHaltmannKill.
|
||||
|
||||
#include <string.h>
|
||||
|
||||
__declspec(section ".init") static asm void *memcpy(register void *dest,
|
||||
register const void *src,
|
||||
register size_t size) {
|
||||
// clang-format off
|
||||
nofralloc;
|
||||
cmplwi cr1, size, 0x0;
|
||||
beqlr cr1
|
||||
cmplw cr1, src, dest;
|
||||
blt cr1, LAB_80004178;
|
||||
beqlr cr1;
|
||||
li r6, 0x80;
|
||||
cmplw cr5, size, r6;
|
||||
blt cr5, LAB_800040c0;
|
||||
rlwinm r9, src, 0x0, 0x1d, 0x1f;
|
||||
rlwinm r10, dest, 0x0, 0x1d, 0x1f;
|
||||
subf r8, r10, dest;
|
||||
dcbt 0, src;
|
||||
xor. r11, r10, r9;
|
||||
bne LAB_8000415c;
|
||||
andi. r10, r10, 0x7;
|
||||
beq LAB_80004068;
|
||||
li r6, 0x8;
|
||||
subf r9, r9, r6;
|
||||
addi r8, dest, 0x0;
|
||||
mtctr r9;
|
||||
subf size, r9, size;
|
||||
LAB_80004054:
|
||||
lbz r9, 0x0(src);
|
||||
addi src, src, 0x1;
|
||||
stb r9, 0x0(r8);
|
||||
addi r8, r8, 0x1;
|
||||
bdnz LAB_80004054;
|
||||
LAB_80004068:
|
||||
rlwinm r6, size, 0x1b, 0x5, 0x1f;
|
||||
mtctr r6;
|
||||
LAB_80004070:
|
||||
lfd f1, 0x0(src);
|
||||
lfd f2, 0x8(src);
|
||||
lfd f3, 0x10(src);
|
||||
lfd f4, 0x18(src);
|
||||
addi src, src, 0x20;
|
||||
stfd f1, 0x0(r8);
|
||||
stfd f2, 0x8(r8);
|
||||
stfd f3, 0x10(r8);
|
||||
stfd f4, 0x18(r8);
|
||||
addi r8, r8, 0x20;
|
||||
bdnz LAB_80004070;
|
||||
andi. r6, size, 0x1f;
|
||||
beqlr;
|
||||
subi src, src, 0x1;
|
||||
mtctr r6;
|
||||
subi r8, r8, 0x1;
|
||||
LAB_800040b0:
|
||||
lbzu r9, 1(src);
|
||||
stbu r9, 1(r8);
|
||||
bdnz LAB_800040b0;
|
||||
blr;
|
||||
LAB_800040c0:
|
||||
li r6, 0x14;
|
||||
cmplw cr5, size, r6;
|
||||
ble cr5, LAB_8000415c;
|
||||
rlwinm r9, src, 0x0, 0x1e, 0x1f;
|
||||
rlwinm r10, dest, 0x0, 0x1e, 0x1f;
|
||||
xor. r11, r10, r9;
|
||||
bne LAB_8000415c;
|
||||
li r6, 0x4;
|
||||
subf r9, r9, r6;
|
||||
addi r8, dest, 0x0;
|
||||
subf size, r9, size;
|
||||
mtctr r9;
|
||||
LAB_800040f0:
|
||||
lbz r9, 0x0(src);
|
||||
addi src, src, 0x1;
|
||||
stb r9, 0x0(r8);
|
||||
addi r8, r8, 0x1;
|
||||
bdnz LAB_800040f0;
|
||||
rlwinm r6, size, 0x1c, 0x4, 0x1f;
|
||||
mtctr r6;
|
||||
LAB_8000410c:
|
||||
lwz r9, 0x0(src);
|
||||
lwz r10, 0x4(src);
|
||||
lwz r11, 0x8(src);
|
||||
lwz r12, 0xc(src);
|
||||
addi src, src, 0x10;
|
||||
stw r9, 0x0(r8);
|
||||
stw r10, 0x4(r8);
|
||||
stw r11, 0x8(r8);
|
||||
stw r12, 0xc(r8);
|
||||
addi r8, r8, 0x10;
|
||||
bdnz LAB_8000410c;
|
||||
andi. r6, size, 0xf;
|
||||
beqlr;
|
||||
subi src, src, 0x1;
|
||||
mtctr r6;
|
||||
subi r8, r8, 0x1;
|
||||
LAB_8000414c:
|
||||
lbzu r9, 0x1(src);
|
||||
stbu r9, 0x1(r8);
|
||||
bdnz LAB_8000414c;
|
||||
blr
|
||||
LAB_8000415c:
|
||||
subi r7, src, 0x1;
|
||||
subi r8, dest, 0x1;
|
||||
mtctr size;
|
||||
LAB_80004168:
|
||||
lbzu r9, 0x1(r7);
|
||||
stbu r9, 0x1(r8);
|
||||
bdnz LAB_80004168;
|
||||
blr;
|
||||
LAB_80004178:
|
||||
add src, src, size;
|
||||
add r12, dest, size;
|
||||
li r6, 0x80;
|
||||
cmplw cr5, size, r6;
|
||||
blt cr5, LAB_80004204;
|
||||
rlwinm r9, src, 0, 0x1d, 0x1f;
|
||||
rlwinm r10, r12, 0, 0x1d, 0x1f;
|
||||
xor. r11, r10, r9;
|
||||
bne LAB_80004288;
|
||||
andi. r10, r10, 0x7;
|
||||
beq LAB_800041b4;
|
||||
mtctr r10;
|
||||
LAB_800041a8:
|
||||
lbzu r9, -1(src);
|
||||
stbu r9, -1(r12);
|
||||
bdnz LAB_800041a8;
|
||||
LAB_800041b4:
|
||||
subf size, r10, size;
|
||||
rlwinm r6, size, 0x1b, 0x5, 0x1f;
|
||||
mtctr r6;
|
||||
LAB_800041c0:
|
||||
lfd f1, -0x8(src);
|
||||
lfd f2, -0x10(src);
|
||||
lfd f3, -0x18(src);
|
||||
lfd f4, -0x20(src);
|
||||
subi src, src, 0x20;
|
||||
stfd f1, -0x8(r12);
|
||||
stfd f2, -0x10(r12);
|
||||
stfd f3, -0x18(r12);
|
||||
stfdu f4, -0x20(r12);
|
||||
bdnz LAB_800041c0;
|
||||
andi. r6, size, 0x1f;
|
||||
beqlr;
|
||||
mtctr r6;
|
||||
LAB_800041f4:
|
||||
lbzu r9, -1(src);
|
||||
stbu r9, -1(r12);
|
||||
bdnz LAB_800041f4;
|
||||
blr;
|
||||
LAB_80004204:
|
||||
li r6, 0x14;
|
||||
cmplw cr5, size, r6;
|
||||
ble cr5, LAB_80004288;
|
||||
rlwinm r9, src, 0x0, 0x1e, 0x1f;
|
||||
rlwinm r10, r12, 0, 0x1e, 0x1f;
|
||||
xor. r11, r10, r9;
|
||||
bne LAB_80004288;
|
||||
andi. r10, r10, 0x7;
|
||||
beq LAB_80004238;
|
||||
mtctr r10;
|
||||
LAB_8000422c:
|
||||
lbzu r9, -1(src);
|
||||
stbu r9, -1(r12);
|
||||
bdnz LAB_8000422c;
|
||||
LAB_80004238:
|
||||
subf size, r10, size;
|
||||
rlwinm r6, size, 0x1c, 0x4, 0x1f;
|
||||
mtctr r6;
|
||||
LAB_80004244:
|
||||
lwz r9, -0x4(src);
|
||||
lwz r10, -0x8(src);
|
||||
lwz r11, -0xc(src);
|
||||
lwz r8, -0x10(src);
|
||||
subi src, src, 0x10;
|
||||
stw r9, -0x4(r12);
|
||||
stw r10, -0x8(r12);
|
||||
stw r11, -0xc(r12);
|
||||
stwu r8, -0x10(r12);
|
||||
bdnz LAB_80004244;
|
||||
andi. r6, size, 0xf;
|
||||
beqlr;
|
||||
mtctr r6;
|
||||
LAB_80004278:
|
||||
lbzu r9, -1(src);
|
||||
stbu r9, -1(r12);
|
||||
bdnz LAB_80004278;
|
||||
blr;
|
||||
LAB_80004288:
|
||||
mtctr size;
|
||||
LAB_8000428c:
|
||||
lbzu r9, -1(src);
|
||||
stbu r9, -1(r12);
|
||||
bdnz LAB_8000428c;
|
||||
blr;
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
__declspec(section ".init") static void __fill_mem(void *dest, int val,
|
||||
size_t count) {
|
||||
char *cdest = (char *)dest;
|
||||
int cval = (unsigned char)val;
|
||||
int *idest = (int *)dest;
|
||||
int r0;
|
||||
cdest--;
|
||||
if (count >= 0x20) {
|
||||
r0 = ~(int)(cdest)&3;
|
||||
|
||||
if (r0) {
|
||||
count -= r0;
|
||||
|
||||
do {
|
||||
*++cdest = cval;
|
||||
} while (--r0);
|
||||
}
|
||||
|
||||
if (cval) {
|
||||
cval = (cval << 0x18) | (cval << 0x10) | (cval << 0x8) | cval;
|
||||
}
|
||||
|
||||
r0 = count >> 5;
|
||||
idest = (int *)(cdest - 3);
|
||||
|
||||
if (r0) {
|
||||
do {
|
||||
idest[1] = cval; // 4
|
||||
--r0;
|
||||
idest[2] = cval; // 8
|
||||
idest[3] = cval; // c
|
||||
idest[4] = cval; // 10
|
||||
idest[5] = cval; // 14
|
||||
idest[6] = cval; // 18
|
||||
idest[7] = cval; // 1c
|
||||
*(idest += 8) = cval; // 20
|
||||
} while (r0);
|
||||
}
|
||||
|
||||
r0 = (count >> 2) & 7;
|
||||
|
||||
if (r0) {
|
||||
do {
|
||||
*++idest = cval;
|
||||
} while (--r0);
|
||||
}
|
||||
|
||||
cdest = (char *)idest + 3;
|
||||
count &= 3;
|
||||
}
|
||||
|
||||
if (count) {
|
||||
do {
|
||||
*++cdest = cval;
|
||||
} while (--count);
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(section ".init") void *memset(void *dest, int val, size_t count) {
|
||||
__fill_mem(dest, val, count);
|
||||
return dest;
|
||||
}
|
|
@ -12,6 +12,7 @@ int main(int argc, char **argv);
|
|||
void exit(int res);
|
||||
void __flush_cache(void *dst, unsigned long size);
|
||||
void __my_flush_cache(void *dst, unsigned long size);
|
||||
void OSResetSystem(int, int, int);
|
||||
|
||||
extern int _stack_addr;
|
||||
extern int _SDA2_BASE_;
|
||||
|
@ -32,6 +33,13 @@ extern __rom_copy_info _rom_copy_info[];
|
|||
extern __bss_init_info _bss_init_info[];
|
||||
|
||||
static char Debug_BBA;
|
||||
unsigned short Pad3 : 0x800030e4;
|
||||
|
||||
__declspec(section ".init") void __check_pad3(void) {
|
||||
if ((Pad3 & 0xEEF) != 0xEEF)
|
||||
return;
|
||||
OSResetSystem(0, 0, 0);
|
||||
}
|
||||
|
||||
__declspec(section ".init") void __set_debug_bba() { Debug_BBA = 1; }
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ fn parse_hex(s: &str) -> Result<u32, ParseIntError> {
|
|||
}
|
||||
|
||||
const SOURCES: &[(&str, &str)] = &[
|
||||
("sdk/msl/runtime/__mem.c", "msl"),
|
||||
("sdk/rvl/os/__start.c", "sdk"),
|
||||
("sdk/rvl/os/__ppc_eabi_init.c", "sdk"),
|
||||
];
|
||||
|
|
|
@ -34,6 +34,32 @@ static CFLAGS: Lazy<HashMap<&'static str, &'static [&'static str]>> = Lazy::new(
|
|||
"-gdwarf-2",
|
||||
][..],
|
||||
);
|
||||
hm.insert(
|
||||
"msl",
|
||||
&[
|
||||
"-ipa",
|
||||
"file",
|
||||
"-O4,p",
|
||||
"-inline",
|
||||
"auto",
|
||||
"-gccinc",
|
||||
"-i",
|
||||
"./include",
|
||||
"-proc",
|
||||
"gekko",
|
||||
"-enum",
|
||||
"int",
|
||||
"-fp",
|
||||
"hardware",
|
||||
"-Cpp_exceptions",
|
||||
"off",
|
||||
"-RTTI",
|
||||
"off",
|
||||
"-gdwarf-2",
|
||||
"-func_align",
|
||||
"4",
|
||||
][..],
|
||||
);
|
||||
hm
|
||||
});
|
||||
|
||||
|
|
62
stats.py
Normal file
62
stats.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env python3
|
||||
# Calculate decompilation statistics
|
||||
|
||||
import csv
|
||||
|
||||
section_sizes = [
|
||||
0x2728, # .init
|
||||
0x18c, # extab
|
||||
0x104, # extabindex
|
||||
0x3ff844, # .text
|
||||
0x2d0, # .ctors
|
||||
0xc, # .dtors
|
||||
0x1aad0, # .rodata
|
||||
0x756bc, # .data
|
||||
0xbfd0c, # .bss
|
||||
0x62b0, # .sdata
|
||||
0x1894, # .sbss
|
||||
0x6430, # .sdata2
|
||||
0x3c, # .sbss2
|
||||
]
|
||||
|
||||
decompiled = [0] * len(section_sizes)
|
||||
|
||||
section_names = [
|
||||
".init",
|
||||
"extab",
|
||||
"extabindex",
|
||||
".text",
|
||||
".ctors",
|
||||
".dtors",
|
||||
".rodata",
|
||||
".data",
|
||||
".bss",
|
||||
".sdata",
|
||||
".sbss",
|
||||
".sdata2",
|
||||
".sbss2",
|
||||
]
|
||||
|
||||
with open("data/ranges.csv") as f:
|
||||
data = list(csv.reader(f))[1:]
|
||||
|
||||
for line in data:
|
||||
for section in range(len(section_sizes)):
|
||||
if line[section * 2] == '':
|
||||
continue
|
||||
start = int(line[section * 2], 16)
|
||||
end = int(line[section * 2 + 1], 16)
|
||||
decompiled[section] += end - start
|
||||
|
||||
print("Completion status by section:")
|
||||
for (full, decomp, name) in zip(section_sizes, decompiled, section_names):
|
||||
print(f" {name}: {decomp}/{full} ({decomp / full * 100}%)")
|
||||
|
||||
print()
|
||||
print("Completion status:")
|
||||
print(f" {sum(decompiled)}/{sum(section_sizes)} ({sum(decompiled) / sum(section_sizes) * 100}%)")
|
||||
print()
|
||||
print("Completion status (code only)")
|
||||
decompiled_code = decompiled[0] + decompiled[3]
|
||||
decompiled_size = section_sizes[0] + section_sizes[3]
|
||||
print(f" {decompiled_code}/{decompiled_size} ({decompiled_code / decompiled_size * 100}%)")
|
Loading…
Reference in a new issue