From 693954930ac116b14ad8b78ef2f2e862469b3dd8 Mon Sep 17 00:00:00 2001 From: Lightos1 <124387232+Lightos1@users.noreply.github.com> Date: Wed, 29 Apr 2026 18:55:14 +0200 Subject: [PATCH] remove oc_test --- .../stratosphere/loader/source/oc/Makefile | 51 ----- .../loader/source/oc/oc_common.hpp | 14 +- .../stratosphere/loader/source/oc/oc_test.cpp | 214 ------------------ .../stratosphere/loader/source/oc/oc_test.hpp | 81 ------- .../stratosphere/loader/source/oc/pcv/pcv.cpp | 3 - .../stratosphere/loader/source/oc/ptm/ptm.cpp | 8 - 6 files changed, 4 insertions(+), 367 deletions(-) delete mode 100644 Source/Atmosphere/stratosphere/loader/source/oc/Makefile delete mode 100644 Source/Atmosphere/stratosphere/loader/source/oc/oc_test.cpp delete mode 100644 Source/Atmosphere/stratosphere/loader/source/oc/oc_test.hpp diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/Makefile b/Source/Atmosphere/stratosphere/loader/source/oc/Makefile deleted file mode 100644 index c1a527b7..00000000 --- a/Source/Atmosphere/stratosphere/loader/source/oc/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -TARGET_EXEC := test - -BUILD_DIR := ./build -SRC_DIRS := ./ - -# CXX := clang++ g++-12 - -# Find all the C and C++ files we want to compile -# Note the single quotes around the * expressions. Make will incorrectly expand these otherwise. -SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s') - -# String substitution for every C/C++ file. -# As an example, hello.cpp turns into ./build/hello.cpp.o -OBJS := $(SRCS:%=$(BUILD_DIR)/%.o) - -# String substitution (suffix version without %). -# As an example, ./build/hello.cpp.o turns into ./build/hello.cpp.d -DEPS := $(OBJS:.o=.d) - -# Every folder in ./src will need to be passed to GCC so that it can find header files -INC_DIRS := $(shell find $(SRC_DIRS) -type d) -# Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag -INC_FLAGS := $(addprefix -I,$(INC_DIRS)) - -CPPFLAGS := $(INC_FLAGS) -Wall -Werror -Wno-unused-result -std=c++20 -Og -g - -# The final build step. -$(TARGET_EXEC): $(OBJS) - @echo "Linking $@" - @$(CXX) $(OBJS) -o $@ $(LDFLAGS) - -# Build step for C source -$(BUILD_DIR)/%.c.o: %.c - @mkdir -p $(dir $@) - @echo "$<" - @$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ - -# Build step for C++ source -$(BUILD_DIR)/%.cpp.o: %.cpp - @mkdir -p $(dir $@) - @echo "$<" - @$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@ - -.PHONY: clean -clean: - @rm -r $(BUILD_DIR) $(TARGET_EXEC) - -# Include the .d makefiles. The - at the front suppresses the errors of missing -# Makefiles. Initially, all the .d files will be missing, and we don't want those -# errors to show up. --include $(DEPS) \ No newline at end of file diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp index d1aad2cb..80d2db11 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/oc_common.hpp @@ -18,14 +18,10 @@ #pragma once -#ifdef ATMOSPHERE_IS_STRATOSPHERE - #include - #include - #define LOGGING(fmt, ...) ((void)0) - #define CRASH(msg, ...) { ams::diag::AbortImpl(msg, __PRETTY_FUNCTION__, "", 0); __builtin_unreachable(); } -#else - #include "oc_test.hpp" -#endif +#include +#include +#define LOGGING(fmt, ...) ((void)0) +#define CRASH(msg, ...) { ams::diag::AbortImpl(msg, __PRETTY_FUNCTION__, "", 0); __builtin_unreachable(); } #include "customize.hpp" @@ -96,9 +92,7 @@ namespace ams::ldr::hoc { } Result CheckResult() { - #ifndef ATMOSPHERE_IS_STRATOSPHERE R_UNLESS(patched_count > 0, ldr::ResultUnsuccessfulPatcher()); - #endif if (maximum_patched_count) R_UNLESS(patched_count <= maximum_patched_count, ldr::ResultUnsuccessfulPatcher()); diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.cpp deleted file mode 100644 index aac74454..00000000 --- a/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) Switch-OC-Suite - * - * Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef ATMOSPHERE_IS_STRATOSPHERE -#include "oc_test.hpp" -#include "oc_loader.hpp" - -void* loadExec(const char* file_loc, size_t* out_size) { - FILE* fp = fopen(file_loc, "rb"); - if (!fp) { - fprintf(stderr, "Cannot open file: \"%s\"\n", file_loc); - exit(-1); - } - - if (fseek(fp, 0, SEEK_END) < 0) { - fprintf(stderr, "fseek error\n"); - exit(-1); - } - - long size = ftell(fp); - if (size == -1L) { - fprintf(stderr, "\"%s\" is a directory", file_loc); - exit(-1); - } - - fseek(fp, 0, SEEK_SET); - void* buf = malloc(size); - - fread(buf, size, 1, fp); - fclose(fp); - - if (size < 8192) { - fprintf(stderr, "File is too small to process: \"%s\" (%ld B)\n", file_loc, size); - exit(-1); - } - - *out_size = size; - return buf; -} - -void saveExec(const char* file_loc, const void* buf, size_t size) { - FILE* fp = fopen(file_loc, "wb"); - if (!fp) { - fprintf(stderr, "Cannot write to \"%s\"\n", file_loc); - exit(-1); - } - printf("Saving to \"%s\"...\n", file_loc); - fwrite(buf, size, 1, fp); - fclose(fp); -} - -Result Test_PcvDvfsTable() { - using namespace ams::ldr::hoc::pcv; - - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&mariko::CpuCvbTableDefault)) == 18); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&erista::CpuCvbTableDefault)) == 16); - - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&mariko::GpuCvbTableDefault)) == 17); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&erista::GpuCvbTableDefault)) == 12); - - cvb_entry_t last_mariko_cpu_cvb_entry_default = { 1963500, { 1675751, -38635, 27 }, { 1120000 } }; - assert(memcmp(GetDvfsTableLastEntry((cvb_entry_t *)(&mariko::CpuCvbTableDefault)), (void *)&last_mariko_cpu_cvb_entry_default, sizeof(last_mariko_cpu_cvb_entry_default)) == 0); - assert(GetDvfsTableLastEntry((cvb_entry_t *)(&erista::GpuCvbTableDefault))->freq == 921600); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoCpuDvfsTableSLT)) == 25); - - // Customized table default - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.eristaCpuDvfsTable)) == 19); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoCpuDvfsTable)) == 21); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoCpuDvfsTableSLT)) == 22); - - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.eristaGpuDvfsTable)) == 12); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoGpuDvfsTable)) == 17); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoGpuDvfsTableSLT)) == 17); - assert(GetDvfsTableEntryCount((cvb_entry_t *)(&ams::ldr::hoc::C.marikoGpuDvfsTableHiOPT)) == 17); - - constexpr size_t limit = ams::ldr::hoc::pcv::DvfsTableEntryLimit; - cvb_entry_t customized_table[limit] = {}; - for (size_t i = 0; i < limit; i++) { - assert(GetDvfsTableEntryCount(customized_table) == i); - auto p = GetDvfsTableLastEntry(customized_table); - if (p) - assert(p->freq == i); - - customized_table[i].freq = i + 1; - } - - R_SUCCEED(); -} - -void unitTest() { - UnitTest test[] = { - { "PCV DVFS Table", &Test_PcvDvfsTable } - }; - - for (auto &t : test) { - t.Test(); - } -} - -int main(int argc, char** argv) { - unitTest(); - - const char* pcv_opt = "pcv"; - const char* ptm_opt = "ptm"; - const char* save_opt = "-s"; - const char* mariko_ext = ".mariko"; - const char* erista_ext = ".erista"; - enum EXE_OPTION { - EXE_PCV, - EXE_PTM, - UNKNOWN - }; - EXE_OPTION exe_opt = UNKNOWN; - if (argc > 2) { - if (!strcmp(argv[1], pcv_opt)) - exe_opt = EXE_PCV; - - if (!strcmp(argv[1], ptm_opt)) - exe_opt = EXE_PTM; - } - if ((argc != 3 && argc != 4) || exe_opt == UNKNOWN) { - fprintf(stderr, "Usage:\n"\ - " %s %s | %s [%s] \n\n"\ - " %s : Save patched executable with extension \"%s\" / \"%s\"\n" - , argv[0], pcv_opt, ptm_opt, save_opt - , save_opt, mariko_ext, erista_ext); - return -1; - } - - bool save_patched = false; - char* exec_path = argv[2]; - if (argc == 4 && !strcmp(argv[2], save_opt)) { - save_patched = true; - exec_path = argv[3]; - } - - size_t file_size; - void* file_buffer = loadExec(exec_path, &file_size); - - size_t exec_path_len = strlen(reinterpret_cast(exec_path)); - size_t exec_path_patched_len = exec_path_len + std::max(strlen(mariko_ext), strlen(erista_ext)) + 1; - - if (exe_opt == EXE_PCV) { - ams::ldr::hoc::pcv::SafetyCheck(); - - { - void* erista_buf = malloc(file_size); - std::memcpy(erista_buf, file_buffer, file_size); - - printf("Patching %s for Erista...\n", pcv_opt); - ams::ldr::hoc::pcv::erista::Patch(reinterpret_cast(erista_buf), file_size); - if (save_patched) { - char* exec_path_erista = reinterpret_cast(malloc(exec_path_patched_len)); - strncpy(exec_path_erista, exec_path, exec_path_patched_len); - strncat(exec_path_erista, erista_ext, exec_path_patched_len); - saveExec(exec_path_erista, erista_buf, file_size); - free(exec_path_erista); - } - free(erista_buf); - } - - { - void* mariko_buf = malloc(file_size); - std::memcpy(mariko_buf, file_buffer, file_size); - - printf("Patching %s for Mariko...\n", pcv_opt); - ams::ldr::hoc::pcv::mariko::Patch(reinterpret_cast(mariko_buf), file_size); - if (save_patched) { - char* exec_path_mariko = reinterpret_cast(malloc(exec_path_patched_len)); - strncpy(exec_path_mariko, exec_path, exec_path_patched_len); - strncat(exec_path_mariko, mariko_ext, exec_path_patched_len); - saveExec(exec_path_mariko, mariko_buf, file_size); - free(exec_path_mariko); - } - free(mariko_buf); - } - } - - if (exe_opt == EXE_PTM) { - void* mariko_buf = malloc(file_size); - std::memcpy(mariko_buf, file_buffer, file_size); - - printf("Patching %s (Mariko Only)...\n", ptm_opt); - ams::ldr::hoc::ptm::Patch(reinterpret_cast(mariko_buf), file_size); - if (save_patched) { - char* exec_path_mariko = reinterpret_cast(malloc(exec_path_patched_len)); - strncpy(exec_path_mariko, exec_path, exec_path_patched_len); - strncat(exec_path_mariko, mariko_ext, exec_path_patched_len); - saveExec(exec_path_mariko, mariko_buf, file_size); - free(exec_path_mariko); - } - free(mariko_buf); - } - - free(file_buffer); - printf("Passed!\n\n"); - return 0; -} -#endif diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.hpp b/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.hpp deleted file mode 100644 index 4d1423de..00000000 --- a/Source/Atmosphere/stratosphere/loader/source/oc/oc_test.hpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) Switch-OC-Suite - * - * Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#ifndef ATMOSPHERE_IS_STRATOSPHERE -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef int32_t s32; -typedef uint64_t u64; -typedef int Result; - -#define R_SUCCEEDED(arg) (arg == 0) -#define R_FAILED(arg) (arg != 0) -#define LOGGING(fmt, ...) { printf(fmt "\n", ##__VA_ARGS__); } -#define CRASH(msg, ...) { fprintf(stderr, "%s\nFailed in %s!\n", msg, __PRETTY_FUNCTION__); exit(-1); } -#define R_SUCCEED() { return 0; } -#define R_THROW(err) { return err; } -#define R_TRY(expr) { Result _rc = (expr); if (R_FAILED(_rc)) { return _rc; } } -#define R_UNLESS(expr, rc) { if (!(expr)) { return rc; } } - -#define R_DEFINE_ERROR_RESULT(name, rc) \ - inline Result Result##name() { return rc; } - -#define HEXDUMP(ptr, len) \ - { \ - const uint8_t* p = reinterpret_cast(ptr); \ - size_t i, j; \ - for (i = 0; i < len; i += 16) { \ - printf("%06zx: ", i); \ - for (j = 0; j < 16 && i + j < len; j++) \ - printf("%02x ", p[i + j]); \ - for (; j < 16; j++) \ - printf(" "); \ - for (j = 0; j < 16 && i + j < len; j++) \ - printf("%c", isprint(p[i + j]) ? p[i + j] : '.'); \ - printf("\n"); \ - } \ - } \ - -typedef struct UnitTest { - using Func = Result(*)(); - - const char* description; - Func fun = nullptr; - - void Test() { - Result res = fun(); - if (R_FAILED(res)) { - CRASH(description); - } - } -} UnitTest; - -#endif diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.cpp index 7a3563ef..60083f5e 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/pcv/pcv.cpp @@ -169,7 +169,6 @@ namespace ams::ldr::hoc::pcv { } void Patch(uintptr_t mapped_nso, size_t nso_size) { - #ifdef ATMOSPHERE_IS_STRATOSPHERE SafetyCheck(); bool isMariko = (spl::GetSocType() == spl::SocType_Mariko); @@ -178,8 +177,6 @@ namespace ams::ldr::hoc::pcv { } else { erista::Patch(mapped_nso, nso_size); } - - #endif } } diff --git a/Source/Atmosphere/stratosphere/loader/source/oc/ptm/ptm.cpp b/Source/Atmosphere/stratosphere/loader/source/oc/ptm/ptm.cpp index dbafea57..7ae9183a 100644 --- a/Source/Atmosphere/stratosphere/loader/source/oc/ptm/ptm.cpp +++ b/Source/Atmosphere/stratosphere/loader/source/oc/ptm/ptm.cpp @@ -21,11 +21,7 @@ namespace ams::ldr::hoc::ptm { Result CpuPtmBoost(perf_conf_entry* entry) { - #ifdef ATMOSPHERE_IS_STRATOSPHERE bool isMariko = (spl::GetSocType() == spl::SocType_Mariko); - #else - bool isMariko = true; - #endif if (!C.eristaCpuBoostClock || !C.marikoCpuBoostClock) { R_SUCCEED(); @@ -76,11 +72,7 @@ namespace ams::ldr::hoc::ptm { PatcherEntry cpuPtmBoostPatch = { "CPU Ptm Boost", &CpuPtmBoost, 2, }; PatcherEntry memPtmPatch = { "MEM Ptm", &MemPtm, 16, }; - #ifdef ATMOSPHERE_IS_STRATOSPHERE bool isMariko = (spl::GetSocType() == spl::SocType_Mariko); - #else - bool isMariko = true; - #endif for (u32 i = 0; i < entryCnt; i++) { perf_conf_entry *entry = confTable + i;