diff --git a/libexosphere/include/exosphere/hw/hw_arm64_system_registers.hpp b/libexosphere/include/exosphere/hw/hw_arm64_system_registers.hpp index 5792ee71..26f7298b 100644 --- a/libexosphere/include/exosphere/hw/hw_arm64_system_registers.hpp +++ b/libexosphere/include/exosphere/hw/hw_arm64_system_registers.hpp @@ -43,6 +43,15 @@ namespace ams::hw::arch::arm64 { #define HW_CPU_GET_VBAR_EL3(value) HW_CPU_GET_SYSREG(vbar_el3, value) #define HW_CPU_SET_VBAR_EL3(value) HW_CPU_SET_SYSREG(vbar_el3, value) + #define HW_CPU_GET_ELR_EL3(value) HW_CPU_GET_SYSREG(elr_el3, value) + #define HW_CPU_SET_ELR_EL3(value) HW_CPU_SET_SYSREG(elr_el3, value) + + #define HW_CPU_GET_FAR_EL3(value) HW_CPU_GET_SYSREG(far_el3, value) + #define HW_CPU_SET_FAR_EL3(value) HW_CPU_SET_SYSREG(far_el3, value) + + #define HW_CPU_GET_ESR_EL3(value) HW_CPU_GET_SYSREG(esr_el3, value) + #define HW_CPU_SET_ESR_EL3(value) HW_CPU_SET_SYSREG(esr_el3, value) + #define HW_CPU_GET_CLIDR_EL1(value) HW_CPU_GET_SYSREG(clidr_el1, value) #define HW_CPU_SET_CLIDR_EL1(value) HW_CPU_SET_SYSREG(clidr_el1, value) @@ -84,6 +93,9 @@ namespace ams::hw::arch::arm64 { #define HW_CPU_GET_DBGCLAIMCLR_EL1(value) HW_CPU_GET_SYSREG(dbgclaimclr_el1, value) #define HW_CPU_SET_DBGCLAIMCLR_EL1(value) HW_CPU_SET_SYSREG(dbgclaimclr_el1, value) + #define HW_CPU_GET_FAR_EL1(value) HW_CPU_GET_SYSREG(far_el1, value) + #define HW_CPU_SET_FAR_EL1(value) HW_CPU_SET_SYSREG(far_el1, value) + #define HW_CPU_GET_DBGVCR32_EL2(value) HW_CPU_GET_SYSREG(dbgvcr32_el2, value) #define HW_CPU_SET_DBGVCR32_EL2(value) HW_CPU_SET_SYSREG(dbgvcr32_el2, value) @@ -327,4 +339,10 @@ namespace ams::hw::arch::arm64 { using Rw = util::BitPack64::Field<31, 1>; }; + struct EsrEl3 { + using Iss = util::BitPack32::Field< 0, 25>; + using Il = util::BitPack32::Field<25, 1>; + using Ec = util::BitPack32::Field<26, 6>; + }; + } diff --git a/libexosphere/include/exosphere/secmon/secmon_memory_layout.hpp b/libexosphere/include/exosphere/secmon/secmon_memory_layout.hpp index 620b0886..fb9f3575 100644 --- a/libexosphere/include/exosphere/secmon/secmon_memory_layout.hpp +++ b/libexosphere/include/exosphere/secmon/secmon_memory_layout.hpp @@ -143,7 +143,8 @@ namespace ams::secmon { HANDLER(I2c1, Gpio, UINT64_C(0x7000C000), UINT64_C(0x1000), true, ## __VA_ARGS__) \ HANDLER(ExceptionVectors, I2c1, UINT64_C(0x6000F000), UINT64_C(0x1000), true, ## __VA_ARGS__) \ HANDLER(MemoryController0, ExceptionVectors, UINT64_C(0x7001C000), UINT64_C(0x1000), true, ## __VA_ARGS__) \ - HANDLER(MemoryController1, MemoryController0, UINT64_C(0x7001D000), UINT64_C(0x1000), true, ## __VA_ARGS__) + HANDLER(MemoryController1, MemoryController0, UINT64_C(0x7001D000), UINT64_C(0x1000), true, ## __VA_ARGS__) \ + HANDLER(Sdmmc, MemoryController1, UINT64_C(0x700B0000), UINT64_C(0x1000), true, ## __VA_ARGS__) #define DEFINE_DEVICE_REGION(_NAME_, _PREV_, _ADDRESS_, _SIZE_, _SECURE_) \ constexpr inline const MemoryRegion MemoryRegionVirtualDevice##_NAME_ = MemoryRegion(MemoryRegionVirtualDevice##_PREV_.GetEndAddress() + 0x1000, _SIZE_); \ @@ -258,6 +259,15 @@ namespace ams::secmon { static_assert(MemoryRegionVirtual.Contains(MemoryRegionVirtualDramSecureDataStore)); static_assert(MemoryRegionDram.Contains(MemoryRegionPhysicalDramSecureDataStore)); + constexpr inline const MemoryRegion MemoryRegionVirtualDramSdmmc1L0DevicePageTable = MemoryRegion(UINT64_C(0x1F010F000), 0x1000); + constexpr inline const MemoryRegion MemoryRegionPhysicalDramSdmmc1L0DevicePageTable = MemoryRegion( UINT64_C(0x8001F000), 0x1000); + + constexpr inline const MemoryRegion MemoryRegionVirtualDramSdmmc1L1DevicePageTable = MemoryRegion(UINT64_C(0x1F010E000), 0x1000); + constexpr inline const MemoryRegion MemoryRegionPhysicalDramSdmmc1L1DevicePageTable = MemoryRegion( UINT64_C(0x8001E000), 0x1000); + + constexpr inline const MemoryRegion MemoryRegionVirtualDramSdmmcMappedData = MemoryRegion(UINT64_C(0x1F0100000), 0xE000); + constexpr inline const MemoryRegion MemoryRegionPhysicalDramSdmmcMappedData = MemoryRegion(UINT64_C(0x80010000), 0xE000); + constexpr inline const MemoryRegion MemoryRegionVirtualDramSecureDataStoreTzram = MemoryRegion(UINT64_C(0x1F0100000), 0xE000); constexpr inline const MemoryRegion MemoryRegionVirtualDramSecureDataStoreWarmbootFirmware = MemoryRegion(UINT64_C(0x1F010E000), 0x17C0); constexpr inline const MemoryRegion MemoryRegionVirtualDramSecureDataStoreSecurityEngineState = MemoryRegion(UINT64_C(0x1F010F7C0), 0x0840); diff --git a/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp b/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp index bc0efd13..69bbb4d8 100644 --- a/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp +++ b/libstratosphere/include/stratosphere/ams/ams_exosphere_api.hpp @@ -23,6 +23,7 @@ namespace ams::exosphere { void ForceRebootToRcm(); void ForceRebootToIramPayload(); + void ForceRebootToFatalError(); void ForceShutdown(); bool IsRcmBugPatched(); diff --git a/libstratosphere/source/ams/ams_exosphere_api.cpp b/libstratosphere/source/ams/ams_exosphere_api.cpp index a8cf21b9..502288b9 100644 --- a/libstratosphere/source/ams/ams_exosphere_api.cpp +++ b/libstratosphere/source/ams/ams_exosphere_api.cpp @@ -36,6 +36,10 @@ namespace ams::exosphere { R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(spl::ConfigItem::ExosphereNeedsReboot, 2))); } + void ForceRebootToFatalError() { + R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(spl::ConfigItem::ExosphereNeedsReboot, 3))); + } + void ForceShutdown() { R_ABORT_UNLESS(spl::smc::ConvertResult(spl::smc::SetConfig(spl::ConfigItem::ExosphereNeedsShutdown, 1))); } diff --git a/libvapours/source/dd/dd_io_mapping.cpp b/libvapours/source/dd/dd_io_mapping.cpp index 1bbdeb8c..966de2fb 100644 --- a/libvapours/source/dd/dd_io_mapping.cpp +++ b/libvapours/source/dd/dd_io_mapping.cpp @@ -28,9 +28,20 @@ namespace ams::dd { uintptr_t QueryIoMapping(dd::PhysicalAddress phys_addr, size_t size) { #if defined(ATMOSPHERE_IS_EXOSPHERE) #if defined(ATMOSPHERE_ARCH_ARM64) - /* TODO: Secure Monitor translation? */ - AMS_UNUSED(size); - return static_cast(phys_addr); + /* TODO: Do this in a less shitty way. */ + if (secmon::MemoryRegionPhysicalDeviceClkRst.Contains(phys_addr, size)) { + return secmon::MemoryRegionVirtualDeviceClkRst.GetAddress() + phys_addr - secmon::MemoryRegionPhysicalDeviceClkRst.GetAddress(); + } else if (secmon::MemoryRegionPhysicalDeviceGpio.Contains(phys_addr, size)) { + return secmon::MemoryRegionVirtualDeviceGpio.GetAddress() + phys_addr - secmon::MemoryRegionPhysicalDeviceGpio.GetAddress(); + } else if (secmon::MemoryRegionPhysicalDeviceApbMisc.Contains(phys_addr, size)) { + return secmon::MemoryRegionVirtualDeviceApbMisc.GetAddress() + phys_addr - secmon::MemoryRegionPhysicalDeviceApbMisc.GetAddress(); + } else if (secmon::MemoryRegionPhysicalDeviceSdmmc.Contains(phys_addr, size)) { + return secmon::MemoryRegionVirtualDeviceSdmmc.GetAddress() + phys_addr - secmon::MemoryRegionPhysicalDeviceSdmmc.GetAddress(); + } else { + AMS_UNUSED(size); + return static_cast(phys_addr); + } + #elif defined(ATMOSPHERE_ARCH_ARM) /* TODO: BPMP translation? */ AMS_UNUSED(size); diff --git a/libvapours/source/sdmmc/impl/sdmmc_i_host_controller.hpp b/libvapours/source/sdmmc/impl/sdmmc_i_host_controller.hpp index 3ac28576..f4439bb7 100644 --- a/libvapours/source/sdmmc/impl/sdmmc_i_host_controller.hpp +++ b/libvapours/source/sdmmc/impl/sdmmc_i_host_controller.hpp @@ -143,9 +143,9 @@ namespace ams::sdmmc::impl { virtual void SetWorkBuffer(void *wb, size_t wb_size) = 0; virtual Result Startup(BusPower bus_power, BusWidth bus_width, SpeedMode speed_mode, bool power_saving_enable) = 0; - virtual void Shutdown(); - virtual void PutToSleep(); - virtual Result Awaken(); + virtual void Shutdown() = 0; + virtual void PutToSleep() = 0; + virtual Result Awaken() = 0; virtual Result SwitchToSdr12();