From c1abac8c9e6d40f73846a73b8e3b14377521e68a Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 7 Sep 2022 21:51:31 -0700 Subject: [PATCH] Minor cleanup, move files to --- .../os/__ppc_eabi_init.s} | 33 +++++++- asm/os/__ppc_eabi_init.s | 31 -------- obj_files.mk | 4 +- src/Dolphin/os/__ppc_eabi_init.cpp | 76 +++++++++++++++++++ src/{ => Dolphin}/os/__start.c | 0 5 files changed, 109 insertions(+), 35 deletions(-) rename asm/{os/__ppc_eabi_init_text.s => Dolphin/os/__ppc_eabi_init.s} (63%) delete mode 100644 asm/os/__ppc_eabi_init.s create mode 100644 src/Dolphin/os/__ppc_eabi_init.cpp rename src/{ => Dolphin}/os/__start.c (100%) diff --git a/asm/os/__ppc_eabi_init_text.s b/asm/Dolphin/os/__ppc_eabi_init.s similarity index 63% rename from asm/os/__ppc_eabi_init_text.s rename to asm/Dolphin/os/__ppc_eabi_init.s index 88209d03..2cdcbbb8 100644 --- a/asm/os/__ppc_eabi_init_text.s +++ b/asm/Dolphin/os/__ppc_eabi_init.s @@ -1,8 +1,37 @@ .include "macros.inc" +.section .init, "ax" # 0x80003100 - 0x80005620 + +.global __init_hardware +__init_hardware: +/* 80003354 00000354 7C 00 00 A6 */ mfmsr r0 +/* 80003358 00000358 60 00 20 00 */ ori r0, r0, 0x2000 +/* 8000335C 0000035C 7C 00 01 24 */ mtmsr r0 +/* 80003360 00000360 7F E8 02 A6 */ mflr r31 +/* 80003364 00000364 48 0B 19 49 */ bl __OSPSInit +/* 80003368 00000368 48 0B 32 8D */ bl __OSCacheInit +/* 8000336C 0000036C 7F E8 03 A6 */ mtlr r31 +/* 80003370 00000370 4E 80 00 20 */ blr + +.global __flush_cache +__flush_cache: +/* 80003374 00000374 3C A0 FF FF */ lis r5, 0xFFFFFFF1@h +/* 80003378 00000378 60 A5 FF F1 */ ori r5, r5, 0xFFFFFFF1@l +/* 8000337C 0000037C 7C A5 18 38 */ and r5, r5, r3 +/* 80003380 00000380 7C 65 18 50 */ subf r3, r5, r3 +/* 80003384 00000384 7C 84 1A 14 */ add r4, r4, r3 +lbl_80003388: +/* 80003388 00000388 7C 00 28 6C */ dcbst r0, r5 +/* 8000338C 0000038C 7C 00 04 AC */ sync +/* 80003390 00000390 7C 00 2F AC */ icbi r0, r5 +/* 80003394 00000394 30 A5 00 08 */ addic r5, r5, 8 +/* 80003398 00000398 34 84 FF F8 */ addic. r4, r4, -8 +/* 8000339C 0000039C 40 80 FF EC */ bge lbl_80003388 +/* 800033A0 000003A0 4C 00 01 2C */ isync +/* 800033A4 000003A4 4E 80 00 20 */ blr + .section .text, "ax" -.if 0 .global __init_user __init_user: /* 80385824 00382784 7C 08 02 A6 */ mflr r0 @@ -13,7 +42,6 @@ __init_user: /* 80385838 00382798 38 21 00 08 */ addi r1, r1, 8 /* 8038583C 0038279C 7C 08 03 A6 */ mtlr r0 /* 80385840 003827A0 4E 80 00 20 */ blr -.endif .global __init_cpp __init_cpp: @@ -53,3 +81,4 @@ _ExitProcess: /* 803858AC 0038280C 38 21 00 08 */ addi r1, r1, 8 /* 803858B0 00382810 7C 08 03 A6 */ mtlr r0 /* 803858B4 00382814 4E 80 00 20 */ blr + diff --git a/asm/os/__ppc_eabi_init.s b/asm/os/__ppc_eabi_init.s deleted file mode 100644 index 806c9c05..00000000 --- a/asm/os/__ppc_eabi_init.s +++ /dev/null @@ -1,31 +0,0 @@ -.include "macros.inc" - -.section .init, "ax" # 0x80003100 - 0x80005620 - -.global __init_hardware -__init_hardware: -/* 80003354 00000354 7C 00 00 A6 */ mfmsr r0 -/* 80003358 00000358 60 00 20 00 */ ori r0, r0, 0x2000 -/* 8000335C 0000035C 7C 00 01 24 */ mtmsr r0 -/* 80003360 00000360 7F E8 02 A6 */ mflr r31 -/* 80003364 00000364 48 0B 19 49 */ bl __OSPSInit -/* 80003368 00000368 48 0B 32 8D */ bl __OSCacheInit -/* 8000336C 0000036C 7F E8 03 A6 */ mtlr r31 -/* 80003370 00000370 4E 80 00 20 */ blr - -.global __flush_cache -__flush_cache: -/* 80003374 00000374 3C A0 FF FF */ lis r5, 0xFFFFFFF1@h -/* 80003378 00000378 60 A5 FF F1 */ ori r5, r5, 0xFFFFFFF1@l -/* 8000337C 0000037C 7C A5 18 38 */ and r5, r5, r3 -/* 80003380 00000380 7C 65 18 50 */ subf r3, r5, r3 -/* 80003384 00000384 7C 84 1A 14 */ add r4, r4, r3 -lbl_80003388: -/* 80003388 00000388 7C 00 28 6C */ dcbst r0, r5 -/* 8000338C 0000038C 7C 00 04 AC */ sync -/* 80003390 00000390 7C 00 2F AC */ icbi r0, r5 -/* 80003394 00000394 30 A5 00 08 */ addic r5, r5, 8 -/* 80003398 00000398 34 84 FF F8 */ addic. r4, r4, -8 -/* 8000339C 0000039C 40 80 FF EC */ bge lbl_80003388 -/* 800033A0 000003A0 4C 00 01 2C */ isync -/* 800033A4 000003A4 4E 80 00 20 */ blr diff --git a/obj_files.mk b/obj_files.mk index 3b9fe4f4..647d16a5 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -684,7 +684,7 @@ MTX_FILES :=\ # TODO: Move __ppc_eabi_init_text into the same source files as __ppc_eabi_init OS_FILES :=\ - $(BUILD_DIR)/src/os/__start.o\ + $(BUILD_DIR)/src/Dolphin/os/__start.o\ $(BUILD_DIR)/asm/Dolphin/os/OS.o\ $(BUILD_DIR)/asm/Dolphin/os/OSAlarm.o\ $(BUILD_DIR)/asm/Dolphin/os/OSArena.o\ @@ -705,7 +705,7 @@ OS_FILES :=\ $(BUILD_DIR)/asm/Dolphin/os/OSSync.o\ $(BUILD_DIR)/asm/Dolphin/os/OSThread.o\ $(BUILD_DIR)/asm/Dolphin/os/OSTime.o\ - $(BUILD_DIR)/src/os/__ppc_eabi_init.o\ + $(BUILD_DIR)/src/Dolphin/os/__ppc_eabi_init.o\ PAD_FILES :=\ $(BUILD_DIR)/asm/Dolphin/pad/PadClamp.o\ diff --git a/src/Dolphin/os/__ppc_eabi_init.cpp b/src/Dolphin/os/__ppc_eabi_init.cpp new file mode 100644 index 00000000..bac0598e --- /dev/null +++ b/src/Dolphin/os/__ppc_eabi_init.cpp @@ -0,0 +1,76 @@ +#include "dolphin/__ppc_eabi_init.h" +#include "dolphin/PPCArch.h" + +#ifdef __cplusplus +extern "C" { +#endif +void __OSPSInit(); +void __OSCacheInit(); + +asm void __init_hardware(void) { +// clang-format off + nofralloc + mfmsr r0 + ori r0, r0, 0x2000 + mtmsr r0 + + mflr r31 + bl __OSPSInit + bl __OSCacheInit + mtlr r31 + blr +// clang-format on +} + +asm void __flush_cache(register void* address, register unsigned int size) { +// clang-format off + nofralloc + lis r5, 0xFFFF + ori r5, r5, 0xFFF1 + and r5, r5, r3 + subf r3, r5, r3 + add r4, r4, r3 + +loop: + dcbst r0, r5 + sync + icbi r0, r5 + addic r5, r5, 8 + subic. r4, r4, 8 + bge loop + isync + blr +// clang-format on +} + + +void __init_user() { + __init_cpp(); +} + +typedef void (*voidfunctionptr)(void); // pointer to function returning void +__declspec(section ".init") extern voidfunctionptr _ctors[]; +__declspec(section ".init") extern voidfunctionptr _dtors[]; + +#pragma push +#pragma peephole off +void __init_cpp(void) +{ + voidfunctionptr *constructor; + + /* + * call static initializers + */ + for (constructor = _ctors; *constructor; constructor++) { + (*constructor)(); + } +} +#pragma pop + +void _ExitProcess(void) { + PPCHalt(); +} + +#ifdef __cplusplus +} +#endif diff --git a/src/os/__start.c b/src/Dolphin/os/__start.c similarity index 100% rename from src/os/__start.c rename to src/Dolphin/os/__start.c