mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-17 08:34:23 -04:00
exo2: implement SmcComputeAes, SmcGetResult, SmcGetResultData
This commit is contained in:
parent
b6b114ec40
commit
e0dbfc69a8
16 changed files with 486 additions and 24 deletions
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
#include <exosphere.hpp>
|
||||
#include "secmon_cache.hpp"
|
||||
#include "secmon_setup.hpp"
|
||||
#include "secmon_map.hpp"
|
||||
|
||||
namespace ams::secmon {
|
||||
|
@ -24,8 +25,12 @@ namespace ams::secmon {
|
|||
constexpr inline const uintptr_t BootCodeAddress = MemoryRegionVirtualTzramBootCode.GetAddress();
|
||||
constexpr inline const size_t BootCodeSize = MemoryRegionVirtualTzramBootCode.GetSize();
|
||||
|
||||
constinit uintptr_t g_smc_user_page_physical_address = 0;
|
||||
|
||||
using namespace ams::mmu;
|
||||
|
||||
constexpr inline PageTableMappingAttribute MappingAttributesEl3NonSecureRwData = AddMappingAttributeIndex(PageTableMappingAttributes_El3NonSecureRwData, MemoryAttributeIndexNormal);
|
||||
|
||||
constexpr void UnmapBootCodeImpl(u64 *l1, u64 *l2, u64 *l3, uintptr_t boot_code, size_t boot_code_size) {
|
||||
/* Unmap the L3 entries corresponding to the boot code. */
|
||||
InvalidateL3Entries(l3, boot_code, boot_code_size);
|
||||
|
@ -42,6 +47,16 @@ namespace ams::secmon {
|
|||
InvalidateL1Entries(l1, MemoryRegionPhysical.GetAddress(), MemoryRegionPhysical.GetSize());
|
||||
}
|
||||
|
||||
constexpr void MapSmcUserPageImpl(u64 *l3, uintptr_t address) {
|
||||
/* Set the L3 entry. */
|
||||
SetL3BlockEntry(l3, MemoryRegionVirtualSmcUserPage.GetAddress(), address, MemoryRegionVirtualSmcUserPage.GetSize(), MappingAttributesEl3NonSecureRwData);
|
||||
}
|
||||
|
||||
constexpr void UnmapSmcUserPageImpl(u64 *l3) {
|
||||
/* Unmap the L3 entry. */
|
||||
InvalidateL3Entries(l3, MemoryRegionVirtualSmcUserPage.GetAddress(), MemoryRegionVirtualSmcUserPage.GetSize());
|
||||
}
|
||||
|
||||
void ClearLow(uintptr_t address, size_t size) {
|
||||
/* Clear the low part. */
|
||||
util::ClearMemory(reinterpret_cast<void *>(address), size / 2);
|
||||
|
@ -85,4 +100,43 @@ namespace ams::secmon {
|
|||
secmon::EnsureMappingConsistency();
|
||||
}
|
||||
|
||||
uintptr_t MapSmcUserPage(uintptr_t address) {
|
||||
if (g_smc_user_page_physical_address != 0) {
|
||||
if (!(MemoryRegionDram.GetAddress() <= address && address <= MemoryRegionDramHigh.GetEndAddress() - MemoryRegionVirtualSmcUserPage.GetSize())) {
|
||||
return 0;
|
||||
}
|
||||
if (!util::IsAligned(address, 4_KB)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_smc_user_page_physical_address = address;
|
||||
|
||||
u64 * const l2_l3 = MemoryRegionVirtualTzramL2L3PageTable.GetPointer<u64>();
|
||||
|
||||
MapSmcUserPageImpl(l2_l3, address);
|
||||
|
||||
/* Ensure the mappings are consistent. */
|
||||
secmon::EnsureMappingConsistency(MemoryRegionVirtualSmcUserPage.GetAddress());
|
||||
} else {
|
||||
AMS_ABORT_UNLESS(address == g_smc_user_page_physical_address);
|
||||
}
|
||||
|
||||
return MemoryRegionVirtualSmcUserPage.GetAddress();
|
||||
}
|
||||
|
||||
void UnmapSmcUserPage() {
|
||||
if (g_smc_user_page_physical_address == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
u64 * const l2_l3 = MemoryRegionVirtualTzramL2L3PageTable.GetPointer<u64>();
|
||||
|
||||
UnmapSmcUserPageImpl(l2_l3);
|
||||
|
||||
/* Ensure the mappings are consistent. */
|
||||
secmon::EnsureMappingConsistency(MemoryRegionVirtualSmcUserPage.GetAddress());
|
||||
|
||||
g_smc_user_page_physical_address = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue