From 5de853b6625b260de62acbc9df9ad349988471fe Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 29 Jul 2020 15:29:01 -0700 Subject: [PATCH] kern: fix ARM vs THUMB mode selection on 32-bit entry --- .../arch/arm64/kern_k_process_page_table.hpp | 4 ++++ .../include/mesosphere/kern_k_page_table_base.hpp | 10 ++++++++++ .../source/arch/arm64/kern_exception_handlers.cpp | 1 + .../source/arch/arm64/kern_k_thread_context.cpp | 5 +++-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_process_page_table.hpp b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_process_page_table.hpp index 71ed1d3bb..6bbe2ac32 100644 --- a/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_process_page_table.hpp +++ b/libraries/libmesosphere/include/mesosphere/arch/arm64/kern_k_process_page_table.hpp @@ -220,6 +220,10 @@ namespace ams::kern::arch::arm64 { return this->page_table.DumpTable(); } + void DumpMemoryBlocks() const { + return this->page_table.DumpMemoryBlocks(); + } + bool GetPhysicalAddress(KPhysicalAddress *out, KProcessAddress address) const { return this->page_table.GetPhysicalAddress(out, address); } diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp index 983c852d0..b2a65143d 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_page_table_base.hpp @@ -355,6 +355,16 @@ namespace ams::kern { KScopedLightLock lk(this->general_lock); this->GetImpl().Dump(GetInteger(this->address_space_start), this->address_space_end - this->address_space_start); } + + void DumpMemoryBlocks() const { + KScopedLightLock lk(this->general_lock); + this->DumpMemoryBlocksLocked(); + } + + void DumpMemoryBlocksLocked() const { + MESOSPHERE_ASSERT(this->IsLockedByCurrentThread()); + this->memory_block_manager.DumpBlocks(); + } public: KProcessAddress GetAddressSpaceStart() const { return this->address_space_start; } KProcessAddress GetHeapRegionStart() const { return this->heap_region_start; } diff --git a/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp b/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp index ef0c2633b..963a017c9 100644 --- a/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp +++ b/libraries/libmesosphere/source/arch/arm64/kern_exception_handlers.cpp @@ -48,6 +48,7 @@ namespace ams::kern::arch::arm64 { /* Dump the page tables. */ /* GetCurrentProcess().GetPageTable().DumpTable(); */ + GetCurrentProcess().GetPageTable().DumpMemoryBlocks(); MESOSPHERE_PANIC("Unhandled Exception in User Mode\n"); diff --git a/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp b/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp index 09169ba5d..4ba9028ac 100644 --- a/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp +++ b/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp @@ -77,9 +77,10 @@ namespace ams::kern::arch::arm64 { if (is_64_bit) { ctx->psr = 0; } else { - constexpr u64 PsrArmValue = 0x20; - constexpr u64 PsrThumbValue = 0x00; + constexpr u64 PsrArmValue = 0x00; + constexpr u64 PsrThumbValue = 0x20; ctx->psr = ((pc & 1) == 0 ? PsrArmValue : PsrThumbValue) | (0x10); + MESOSPHERE_LOG("Creating User 32-Thread, %016lx\n", GetInteger(pc)); } /* Set stack pointer. */