Skip to content

Commit

Permalink
Feature/ppc runtime (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathHound6 authored Nov 4, 2024
2 parents 79fc65e + 9d9cabf commit 656d550
Show file tree
Hide file tree
Showing 24 changed files with 1,857 additions and 378 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ __pycache__
build
build.ninja
objdiff.json
compile_commands.json
orig/*/**/*.dol
/*.txt
ctx.c
!requirements*.txt
powerpc*
split
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ This will also generate `.s` (assembly) files inside the `build/[GAME ID]/asm` f
- Place the function contents into a new scratch in [decomp.me](https://decomp.me)
- Write C++ code that creates matching assembly code
- Use the following string as the build flags
- `-O2,p -lang=c++ -RTTI off -enum int -fp hard -enc SJIS -fp_contract on -str reuse -inline auto -use_lmw_stmw on`
- Compiler `4.3 build 188 (Wii MW 1.5)`
- `-O4,s -lang=c++ -RTTI off -enum int -fp hard -enc SJIS -fp_contract on -str reuse -inline auto -use_lmw_stmw on`
- When placing the function or variable into this repository, mark in a comment the address of the symbol
- For example `// symbol 0x80395304`

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ Download the latest release from [encounter/objdiff](https://github.com/encounte
Select an object from the left sidebar to begin diffing. Changes to the project will rebuild automatically: changes to source files, headers, `configure.py`, `splits.txt` or `symbols.txt`.

![](assets/objdiff.png)

## References
- [Decomp Toolkit](https://github.com/encounter/dtk-template) (repo template)
- [Dolphin 2001 SDK](https://github.com/doldecomp/dolsdk2001)
- Alice uses Revolution SDK of a currently unknown version or release, however, dolsdk can be used as a basis
47 changes: 46 additions & 1 deletion config/SALP4Q/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,54 @@ Sections:
.sdata2 type:rodata align:16
.sbss2 type:bss align:32

Runtime.PPCEABI.H/__init_cpp_exceptions.cpp:
Revolution/OS/__start.c:
.init start:0x80004000 end:0x80006618

Alice/Objects/Groups/CKGrpAliceHero.cpp:
.text start:0x8000DBF0 end:0x8000E264

Alice/Objects/Hooks/CKHkAliceHero.cpp:
.text start:0x8001D894 end:0x8001E9E8

Alice/Objects/Components/CKAliceHeroConfig.cpp:
.text start:0x800539D4 end:0x80055528

Alice/Objects/Logic/CKAliceGameSpawnPoint.cpp:
.text start:0x800EEFBC end:0x800EF814

Alice/Objects/Geometries/CSkinGeometry.cpp:
.text start:0x801DB1A8 end:0x801DB6D8

Alice/Objects/Graphics/CLightManager.cpp:
.text start:0x801E3D88 end:0x801E76B4

Alice/Objects/Nodes/CSpawnNode.cpp:
.text start:0x80211C1C end:0x80212060

Alice/Objects/Services/CKSrvTrigger.cpp:
.text start:0x8022CE90 end:0x8022D744

Alice/Objects/Camera/CKCameraFixTrack.cpp:
.text start:0x80238574 end:0x802388B4

Alice/Objects/Cinematics/CKStartDoor.cpp:
.text start:0x80266000 end:0x802662AC

Alice/Objects/Dictionaries/CKSoundDictionary.cpp:
.text start:0x802B9360 end:0x802B9A70

Alice/Objects/Managers/CKSoundManager.cpp:
.text start:0x802BA0DC end:0x802BAEA0

PowerPC_EABI_Support/Runtime/global_destructor_chain.c:
.text start:0x80368C58 end:0x80394124

PowerPC_EABI_Support/Runtime/__init_cpp_exceptions.cpp:
.text start:0x80395304 end:0x80395374
.ctors start:0x804D3540 end:0x804D3544 rename:.ctors$10
.dtors start:0x804D41E0 end:0x804D41E4 rename:.dtors$10
.dtors start:0x804D41E4 end:0x804D41E8 rename:.dtors$15
.sdata start:0x805F3828 end:0x805F3830

PowerPC_EABI_Support/Runtime/Gecko_ExceptionPPC.cpp:
.text start:0x80395374 end:0x80395480
8 changes: 4 additions & 4 deletions config/SALP4Q/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37233,7 +37233,7 @@ fn_80394874 = .text:0x80394874; // type:function size:0x25C
fn_80394AD0 = .text:0x80394AD0; // type:function size:0x40
fn_80394B10 = .text:0x80394B10; // type:function size:0xC
fn_80394B1C = .text:0x80394B1C; // type:function size:0x5C
fn_80394B78 = .text:0x80394B78; // type:function size:0x4C
__save_fpr = .text:0x80394B78; // type:function size:0x4C scope:global
_savefpr_14 = .text:0x80394B78; // type:label scope:global
_savefpr_15 = .text:0x80394B7C; // type:label scope:global
_savefpr_16 = .text:0x80394B80; // type:label scope:global
Expand All @@ -37252,7 +37252,7 @@ _savefpr_28 = .text:0x80394BB0; // type:label scope:global
_savefpr_29 = .text:0x80394BB4; // type:label scope:global
_savefpr_30 = .text:0x80394BB8; // type:label scope:global
_savefpr_31 = .text:0x80394BBC; // type:label scope:global
fn_80394BC4 = .text:0x80394BC4; // type:function size:0x4C
__restore_fpr = .text:0x80394BC4; // type:function size:0x4C scope:global
_restfpr_14 = .text:0x80394BC4; // type:label scope:global
_restfpr_15 = .text:0x80394BC8; // type:label scope:global
_restfpr_16 = .text:0x80394BCC; // type:label scope:global
Expand All @@ -37271,7 +37271,7 @@ _restfpr_28 = .text:0x80394BFC; // type:label scope:global
_restfpr_29 = .text:0x80394C00; // type:label scope:global
_restfpr_30 = .text:0x80394C04; // type:label scope:global
_restfpr_31 = .text:0x80394C08; // type:label scope:global
fn_80394C10 = .text:0x80394C10; // type:function size:0x4C
__save_gpr = .text:0x80394C10; // type:function size:0x4C scope:global
_savegpr_14 = .text:0x80394C10; // type:label scope:global
_savegpr_15 = .text:0x80394C14; // type:label scope:global
_savegpr_16 = .text:0x80394C18; // type:label scope:global
Expand All @@ -37290,7 +37290,7 @@ _savegpr_28 = .text:0x80394C48; // type:label scope:global
_savegpr_29 = .text:0x80394C4C; // type:label scope:global
_savegpr_30 = .text:0x80394C50; // type:label scope:global
_savegpr_31 = .text:0x80394C54; // type:label scope:global
fn_80394C5C = .text:0x80394C5C; // type:function size:0x4C
__restore_gpr = .text:0x80394C5C; // type:function size:0x4C scope:global
_restgpr_14 = .text:0x80394C5C; // type:label scope:global
_restgpr_15 = .text:0x80394C60; // type:label scope:global
_restgpr_16 = .text:0x80394C64; // type:label scope:global
Expand Down
131 changes: 94 additions & 37 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from tools.project import (
Object,
ProgressCategory,
ProjectConfig,
calculate_progress,
generate_build,
Expand Down Expand Up @@ -113,6 +114,12 @@
action="store_true",
help="builds equivalent (but non-matching) or modded objects",
)
parser.add_argument(
"--no-progress",
dest="progress",
action="store_false",
help="disable progress calculation",
)
args = parser.parse_args()

config = ProjectConfig()
Expand All @@ -125,10 +132,10 @@
config.objdiff_path = args.objdiff
config.binutils_path = args.binutils
config.compilers_path = args.compilers
config.debug = args.debug
config.generate_map = args.map
config.non_matching = args.non_matching
config.sjiswrap_path = args.sjiswrap
config.progress = args.progress
if not is_windows():
config.wrapper = args.wrapper
# Don't build asm unless we're --non-matching
Expand All @@ -138,8 +145,8 @@
# Tool versions
config.binutils_tag = "2.42-1"
config.compilers_tag = "20240706"
config.dtk_tag = "v0.9.4"
config.objdiff_tag = "v2.0.0-beta.4"
config.dtk_tag = "v1.1.2"
config.objdiff_tag = "v2.3.2"
config.sjiswrap_tag = "v1.1.1"
config.wibo_tag = "0.6.11"

Expand All @@ -157,9 +164,13 @@
config.ldflags = [
"-fp hardware",
"-nodefaults",
# "-warn off",
"-listclosure", # Uncomment for Wii linkers
]
if args.debug:
config.ldflags.append("-gdwarf-2") # Or -gdwarf-2 for Wii linkers
if args.map:
config.ldflags.append("-mapunused")
config.ldflags.append("-listclosure") # For Wii linkers

# Use for any additional files that should cause a re-configure when modified
config.reconfig_deps = []

Expand All @@ -173,7 +184,7 @@
"-fp hardware",
"-Cpp_exceptions off",
# "-W all",
"-O2,p",
"-O4,s",
"-inline auto",
'-pragma "cats off"',
'-pragma "warn_notinlined off"',
Expand All @@ -189,7 +200,7 @@
]

# Debug flags
if config.debug:
if args.debug:
cflags_base.extend(["-sym on", "-DDEBUG=1"])
else:
cflags_base.append("-DNDEBUG=1")
Expand All @@ -204,56 +215,102 @@
"-inline auto",
]

# REL flags
# cflags_rel = [
# *cflags_base,
# "-sdata 0",
# "-sdata2 0",
# ]

config.linker_version = "Wii/1.3"
config.linker_version = "Wii/1.5"


# Helper function for Dolphin libraries
# def DolphinLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
# return {
# "lib": lib_name,
# "mw_version": "GC/1.2.5n",
# "cflags": cflags_base,
# "host": False,
# "objects": objects,
# }


# Helper function for REL script objects
# def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
# return {
# "lib": lib_name,
# "mw_version": "GC/1.3.2",
# "cflags": cflags_rel,
# "host": True,
# "objects": objects,
# }
def DolphinLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
return {
"lib": lib_name,
"mw_version": config.linker_version,
"cflags": cflags_base,
"host": False,
"progress_category": "sdk",
"objects": objects,
}


Matching = True # Object matches and should be linked
NonMatching = False # Object does not match and should not be linked
Equivalent = config.non_matching # Object should be linked when configured with --non-matching


# Object is only matching for specific versions
def MatchingFor(*versions):
return config.version in versions


config.warn_missing_config = True
config.warn_missing_source = False
config.libs = [
{
"lib": "Runtime.PPCEABI.H",
"lib": "PowerPC_EABI_Support/Runtime",
"mw_version": config.linker_version,
"cflags": cflags_runtime,
"host": False,
"progress_category": "sdk", # str | List[str]
"objects": [
Object(NonMatching, "Runtime.PPCEABI.H/global_destructor_chain.c"),
Object(NonMatching, "Runtime.PPCEABI.H/__init_cpp_exceptions.cpp"),
Object(MatchingFor(), "PowerPC_EABI_Support/Runtime/__init_cpp_exceptions.cpp"),
Object(MatchingFor(), "PowerPC_EABI_Support/Runtime/Gecko_ExceptionPPC.cpp"),
Object(MatchingFor(), "PowerPC_EABI_Support/Runtime/global_destructor_chain.c")
],
},
{
"lib": "PowerPC_EABI_Support/MSL",
"mw_version": config.linker_version,
"cflags": cflags_runtime,
"host": False,
"progress_category": "sdk", # str | List[str]
"objects": [],
},
{
"lib": "PowerPC_EABI_Support/MetroTRK",
"mw_version": config.linker_version,
"cflags": cflags_runtime,
"host": False,
"progress_category": "sdk", # str | List[str]
"objects": [],
},
{
"lib": "Revolution",
"mw_version": config.linker_version,
"cflags": cflags_runtime,
"host": False,
"progress_category": "sdk", # str | List[str]
"objects": [
Object(MatchingFor(), "Revolution/OS/__start.c")
],
},
{
"lib": "Alice",
"mw_version": config.linker_version,
"cflags": cflags_base,
"host": False,
"progress_category": "game", # str | List[str]
"objects": [
Object(MatchingFor(), "Alice/Objects/Managers/CKSoundManager.cpp"),
Object(MatchingFor(), "Alice/Objects/Services/CKSrvTrigger.cpp"),
Object(MatchingFor(), "Alice/Objects/Hooks/CKHkAliceHero.cpp"),
Object(MatchingFor(), "Alice/Objects/Groups/CKGrpAliceHero.cpp"),
Object(MatchingFor(), "Alice/Objects/Components/CKAliceHeroConfig.cpp"),
Object(MatchingFor(), "Alice/Objects/Camera/CKCameraFixTrack.cpp"),
Object(MatchingFor(), "Alice/Objects/Cinematics/CKStartDoor.cpp"),
Object(MatchingFor(), "Alice/Objects/Dictionaries/CKSoundDictionary.cpp"),
Object(MatchingFor(), "Alice/Objects/Geometries/CSkinGeometry.cpp"),
Object(MatchingFor(), "Alice/Objects/Nodes/CSpawnNode.cpp"),
Object(MatchingFor(), "Alice/Objects/Logic/CKAliceGameSpawnPoint.cpp"),
Object(MatchingFor(), "Alice/Objects/Graphics/CLightManager.cpp")
],
}
]

# Optional extra categories for progress tracking
# Adjust as desired for your project
config.progress_categories = [
ProgressCategory("game", "Game Code"),
ProgressCategory("sdk", "SDK Code"),
]
config.progress_each_module = args.verbose

if args.mode == "configure":
# Write build.ninja and objdiff.json
Expand Down
10 changes: 10 additions & 0 deletions include/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/restrict_def.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _MSL_RESTRICT_DEF_H
#define _MSL_RESTRICT_DEF_H

#if !defined(__cplusplus) && __STDC_VERSION__ >= 199901L
#define RESTRICT restrict
#else
#define RESTRICT
#endif

#endif
35 changes: 35 additions & 0 deletions include/PowerPC_EABI_Support/Runtime/Gecko_ExceptionPPC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef RUNTIME_GECKO_EXCEPTIONPPC_H
#define RUNTIME_GECKO_EXCEPTIONPPC_H

#include "types.h"
#include "PowerPC_EABI_Support/Runtime/__ppc_eabi_linker.h"
#define MAXFRAGMENTS 0x1F

typedef struct ExceptionTableIndex {
u32 functionoffset;
u32 eti_field;
u32 exceptionoffset;
} ExceptionTableIndex;

typedef struct FragmentInfo {
ExceptionTableIndex* exception_start;
ExceptionTableIndex* exception_end;
char* code_start;
char* code_end;
char* data_start;
char* data_end;
char* TOC;
s32 active;
} FragmentInfo;

typedef struct ProcessInfo {
__eti_init_info* exception_info;
char* TOC;
u32 active;
} ProcessInfo;

u32 __register_fragment(struct __eti_init_info*, char*);
void __unregister_fragment(u32);
s32 ExPPC_FindExceptionFragment(char*, FragmentInfo*);

#endif
16 changes: 16 additions & 0 deletions include/PowerPC_EABI_Support/Runtime/__init_cpp_exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __INIT_CPP_EXCEPTIONS_H
#define __INIT_CPP_EXCEPTIONS_H

#ifdef __cplusplus
extern "C" {
#endif

extern void __init_cpp_exceptions(void);
extern void __fini_cpp_exceptions(void);

#ifdef __cplusplus
}
#endif


#endif
Loading

0 comments on commit 656d550

Please sign in to comment.