2020-05-05 08:33:16 +02:00
|
|
|
/*
|
2021-10-04 21:59:10 +02:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-05-05 08:33:16 +02:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <exosphere.hpp>
|
|
|
|
#include "secmon_loader_uncompress.hpp"
|
|
|
|
#include "program_lz4.h"
|
|
|
|
#include "boot_code_lz4.h"
|
|
|
|
|
|
|
|
namespace ams::secmon::loader {
|
|
|
|
|
2021-08-20 22:13:29 +02:00
|
|
|
NORETURN void UncompressAndExecute(const void *program, const void *boot_code) {
|
2020-05-05 08:33:16 +02:00
|
|
|
/* Uncompress the program image. */
|
2021-08-20 22:13:29 +02:00
|
|
|
Uncompress(secmon::MemoryRegionPhysicalTzramFullProgramImage.GetPointer(), secmon::MemoryRegionPhysicalTzramFullProgramImage.GetSize(), program, program_lz4_size);
|
2020-05-05 08:33:16 +02:00
|
|
|
|
|
|
|
/* Copy the boot image to the end of IRAM */
|
|
|
|
u8 *relocated_boot_code = secmon::MemoryRegionPhysicalIramBootCodeImage.GetEndPointer<u8>() - boot_code_lz4_size;
|
2021-08-20 22:13:29 +02:00
|
|
|
std::memcpy(relocated_boot_code, boot_code, boot_code_lz4_size);
|
2020-05-05 08:33:16 +02:00
|
|
|
|
|
|
|
/* Uncompress the boot image. */
|
|
|
|
Uncompress(secmon::MemoryRegionPhysicalIramBootCodeImage.GetPointer(), secmon::MemoryRegionPhysicalIramBootCodeImage.GetSize(), relocated_boot_code, boot_code_lz4_size);
|
|
|
|
|
|
|
|
/* Jump to the boot image. */
|
|
|
|
reinterpret_cast<void (*)()>(secmon::MemoryRegionPhysicalIramBootCodeImage.GetAddress())();
|
|
|
|
|
|
|
|
/* We will never reach this point. */
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|