From a26c3e56204c05e288e03c3925cb982a511182cf Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 26 Sep 2024 16:28:45 +1000 Subject: [PATCH] System: Add new 'Type 1B' fast boot This saves approximately 2 seconds of boot time, as it no longer copies the shell from ROM to RAM. The actual byte reads only take in the order of 75ms, but because the BIOS executes the memcpy() out of uncached ROM, the repeated instruction fetches take it up to almost 2 seconds... It would be faster to read it from the CD-ROM... --- src/core/bios.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/core/bios.cpp b/src/core/bios.cpp index f7926df68..fed9491b8 100644 --- a/src/core/bios.cpp +++ b/src/core/bios.cpp @@ -251,8 +251,28 @@ bool BIOS::PatchBIOSFastBoot(u8* image, u32 image_size, ImageInfo::FastBootPatch u32 patch_offset; if (type == ImageInfo::FastBootPatch::Type1) { - patch_offset = 0x18000; - INFO_LOG("Using Type 1 fast boot patch at offset 0x{:08X}.", patch_offset); + // Try the "new" fast boot (Type 1B), where we patch the routine that copies/decompresses the shell. + // This saves approximately 2 seconds of fast boot time, because the memcpy() executes out of uncached ROM... + static constexpr const char* search_pattern = "e0 ff bd 27" // add sp, sp, -20 + "1c 00 bf af" // sw ra, 0xc(sp) + "20 00 a4 af" // sw a0, 0x20(sp) + "?? ?? 05 3c" // lui a1, 0xbfc1 + "?? ?? 06 3c" // lui a2, 0x6 + "?? ?? c6 34" // ori a2, a2, 0x7ff0 + "?? ?? a5 34" // ori a1, a1, 0x8000 + "?? ?? ?? 0f"; // jal 0xbfc02b50 + const std::optional offset = + StringUtil::BytePatternSearch(std::span(image, image_size), search_pattern); + if (offset.has_value()) + { + patch_offset = static_cast(offset.value()); + VERBOSE_LOG("Found Type 1B pattern at offset 0x{:08X}", patch_offset); + } + else + { + patch_offset = 0x18000; + INFO_LOG("Using Type 1A fast boot patch at offset 0x{:08X}.", patch_offset); + } } else if (type == ImageInfo::FastBootPatch::Type2) {