From 87050e5f8500184a605332f38074145aef29a5c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Mon, 3 Jan 2022 09:59:10 +0100 Subject: [PATCH] Add __OSFPRInit(), __OSGetIOSRev() --- .vscode/settings.json | 3 +- data/ranges.csv | 2 +- data/symbols.csv | 2 +- include/os.h | 11 ++++ include/types.h | 13 ++++ include/util/PlacementNew.hpp | 2 +- sdk/rvl/os/OS.c | 116 ++++++++++++++++++++++++++++++++++ sdk/rvl/os/OSCache.c | 2 +- 8 files changed, 146 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7baf837c..3e57c050 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,6 +18,7 @@ "future": "cpp", "iosfwd": "cpp", "sstream": "cpp", - "tuple": "cpp" + "tuple": "cpp", + "defines.h": "c" }, } \ No newline at end of file diff --git a/data/ranges.csv b/data/ranges.csv index ed67844d..52f9122c 100644 --- a/data/ranges.csv +++ b/data/ranges.csv @@ -4,7 +4,7 @@ ,,,,,,80007214,800079fc,,,,,80406580,80406598,,,,,,,,,,,,,sdk/msl/runtime/runtime.o 80004380,800062c0,,,,,,,,,,,,,,,,,,,,,,,,,sdk/trk/__exception.o ,,,,,,8001a0b0,8001a2c0,,,,,,,80421da0,80421dd7,,,,,,,,,,,sdk/rvl/base/PPCArch.o -,,,,,,8001b670,8001b6c4,,,,,,,,,,,,,,,,,,,sdk/rvl/os/OS.o +,,,,,,8001a2c0,8001a45c,,,,,,,,,,,,,8055c778,8055c798,,,,,sdk/rvl/os/OS.o ,,,,,,8001c930,8001cf90,,,,,,,80422278,80422400,,,,,,,,,,,sdk/rvl/os/OSCache.o ,,,,,,8001cf90,8001d98c,,,,,,,80422400,804225b8,,,,,,,,,,,sdk/rvl/os/OSContext.o 800062c0,80006620,,,,,,,,,,,,,,,,,,,8055c878,8055c879,,,,,sdk/rvl/os/__start.o diff --git a/data/symbols.csv b/data/symbols.csv index e2ef7228..20bf5aaa 100644 --- a/data/symbols.csv +++ b/data/symbols.csv @@ -8,9 +8,9 @@ Address,SymbolName 80015aac,InitMetroTRK_BBA 80015d28,__TRKreset 800190a0,TRK_InterruptHandler -8001a2c0,__OSFPRInit 8001ad80,OSInit 8001b540,__OSSetExceptionHandler +8001b670,__OSPSInit 8001c370,OSGetMEM1ArenaHi 8001c380,OSGetMEM2ArenaHi 8001c390,OSGetMEM1ArenaLo diff --git a/include/os.h b/include/os.h index f23edfdf..4bfeb981 100644 --- a/include/os.h +++ b/include/os.h @@ -19,6 +19,17 @@ void *OSGetMEM2ArenaLo(); void *OSAllocFromMEM1ArenaLo(u32 size, u32 align); void *OSAllocFromMEM2ArenaLo(u32 size, u32 align); +typedef struct OSIOSRev { + u8 unk; + u8 branch; + u8 major; + u8 minor; + /* please, broad-on, it's year-month-day */ + u8 month; + u8 day; + u16 year; +} OSIOSRev; + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/include/types.h b/include/types.h index dcfadfe1..a91702d2 100644 --- a/include/types.h +++ b/include/types.h @@ -13,6 +13,19 @@ typedef long long s64; typedef float f32; typedef double f64; +typedef volatile u8 vu8; +typedef volatile u16 vu16; +typedef volatile u32 vu32; +typedef volatile u64 vu64; + +typedef volatile s8 vs8; +typedef volatile s16 vs16; +typedef volatile s32 vs32; +typedef volatile s64 vs64; + +typedef volatile f32 vf32; +typedef volatile f64 vf64; + typedef int BOOL; #define NULL 0 \ No newline at end of file diff --git a/include/util/PlacementNew.hpp b/include/util/PlacementNew.hpp index eb67cf15..1beb6b2e 100644 --- a/include/util/PlacementNew.hpp +++ b/include/util/PlacementNew.hpp @@ -3,7 +3,7 @@ namespace util { template struct PlacementNew { T *ptr_; - alignas(T) char data_[sizeof(T)]; + char data_[sizeof(T)]; inline PlacementNew() : ptr_(0) {} inline ~PlacementNew(); diff --git a/sdk/rvl/os/OS.c b/sdk/rvl/os/OS.c index 41fba62f..ef6a586d 100644 --- a/sdk/rvl/os/OS.c +++ b/sdk/rvl/os/OS.c @@ -1,6 +1,113 @@ #include +#include +#include #include +USED BOOL __OSInIPL = 0; +USED BOOL __OSInNandBoot = 0; +USED BOOL __OSIsGcam = 0; +static f64 ZeroF = 0.0; +static f32 ZeroPS[2] = {0.0f, 0.0f}; + +#ifdef __CWCC__ + +USED asm void __OSFPRInit(void) { + // clang-format off + nofralloc; + mfmsr r3; + ori r3, r3, 0x2000; + mtmsr r3; + mfspr r3, 920; + rlwinm. r3, r3, 3, 31, 31; + beq LAB_8001a360; + lis r3, ZeroPS@ha; + addi r3, r3, ZeroPS@l; + psq_l f0, 0(r3), 0, 0; + ps_mr f1, f0; + ps_mr f2, f0; + ps_mr f3, f0; + ps_mr f4, f0; + ps_mr f5, f0; + ps_mr f6, f0; + ps_mr f7, f0; + ps_mr f8, f0; + ps_mr f9, f0; + ps_mr f10, f0; + ps_mr f11, f0; + ps_mr f12, f0; + ps_mr f13, f0; + ps_mr f14, f0; + ps_mr f15, f0; + ps_mr f16, f0; + ps_mr f17, f0; + ps_mr f18, f0; + ps_mr f19, f0; + ps_mr f20, f0; + ps_mr f21, f0; + ps_mr f22, f0; + ps_mr f23, f0; + ps_mr f24, f0; + ps_mr f25, f0; + ps_mr f26, f0; + ps_mr f27, f0; + ps_mr f28, f0; + ps_mr f29, f0; + ps_mr f30, f0; + ps_mr f31, f0; +LAB_8001a360: + lfd f0, ZeroF; + fmr f1, f0; + fmr f2, f0; + fmr f3, f0; + fmr f4, f0; + fmr f5, f0; + fmr f6, f0; + fmr f7, f0; + fmr f8, f0; + fmr f9, f0; + fmr f10, f0; + fmr f11, f0; + fmr f12, f0; + fmr f13, f0; + fmr f14, f0; + fmr f15, f0; + fmr f16, f0; + fmr f17, f0; + fmr f18, f0; + fmr f19, f0; + fmr f20, f0; + fmr f21, f0; + fmr f22, f0; + fmr f23, f0; + fmr f24, f0; + fmr f25, f0; + fmr f26, f0; + fmr f27, f0; + fmr f28, f0; + fmr f29, f0; + fmr f30, f0; + fmr f31, f0; + mtfsf 255, f0; + blr; + // clang-format on +} +#endif + +USED void __OSGetIOSRev(OSIOSRev *rev) { + u32 version = *(u32 *)0xc0003140; + u32 date = *(u32 *)0xc0003144; + + rev->unk = (u8)(version >> 24); + rev->branch = (u8)(version >> 16); + rev->major = (u8)(version >> 8); + rev->minor = (u8)(version); + rev->month = (u8)((date >> 20) & 0xf) * 10 + (u8)((date >> 16) & 0xf); + rev->day = (u8)((date >> 12) & 0xf) * 10 + (u8)((date >> 8) & 0xf); + rev->year = (u16)((date >> 4) & 0xf) * 10 + (u16)(date & 0xf) + 2000; +} + +#if 0 + #ifdef __CWCC__ void __OSPSInit(void) { PPCMthid2(PPCMfhid2() | 0xA0000000); @@ -18,4 +125,13 @@ void __OSPSInit(void) { mtspr 919, r3; } } +#endif + +USED u8 __OSGetDIConfig(void) { + u32 val = *(vu32 *)0xcd006024; + return (u8)val; +} + +USED void OSRegisterVersion(const char *version) { OSReport("%s\n", version); } + #endif \ No newline at end of file diff --git a/sdk/rvl/os/OSCache.c b/sdk/rvl/os/OSCache.c index 65432666..6ff3d79e 100644 --- a/sdk/rvl/os/OSCache.c +++ b/sdk/rvl/os/OSCache.c @@ -162,7 +162,7 @@ LAB_8001ca8c: #endif #ifdef __CWCC__ -asm void ICFlashInvalidate(void) { +USED asm void ICFlashInvalidate(void) { // clang-format off nofralloc; mfspr r3, 1008;