From 1a3c90281c61bec2b5b6c8294468df8728b9af80 Mon Sep 17 00:00:00 2001 From: Khalil Estell Date: Tue, 23 Jul 2024 13:07:31 -0700 Subject: [PATCH] :zap: Cache & Use the personality pointer --- demos/applications/multi_levels.cpp | 22 +++++++--------------- notes.md | 2 +- src/arm_cortex/estell/exception.cpp | 12 +++++++++--- src/arm_cortex/estell/internal.hpp | 20 +++++++++++--------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/demos/applications/multi_levels.cpp b/demos/applications/multi_levels.cpp index 37a38e5..f2cf87a 100644 --- a/demos/applications/multi_levels.cpp +++ b/demos/applications/multi_levels.cpp @@ -51,17 +51,14 @@ std::array functions = { &funct_group3_0, &funct_group4_0, &funct_group5_0, &funct_group6_0, &funct_group7_0, &funct_group8_0, #if 0 - funct_group9_0, funct_group10_0, funct_group11_0, - funct_group12_0, funct_group13_0, funct_group14_0, funct_group15_0, - funct_group16_0, - funct_group17_0, funct_group18_0, funct_group19_0, - funct_group20_0, funct_group21_0, funct_group22_0, funct_group23_0, - funct_group24_0 + &funct_group9_0, + &funct_group10_0, &funct_group11_0, &funct_group12_0, &funct_group13_0, + &funct_group14_0, &funct_group15_0, &funct_group16_0, &funct_group17_0, + &funct_group18_0, &funct_group19_0, &funct_group20_0, &funct_group21_0, + &funct_group22_0, &funct_group23_0, &funct_group24_0 #endif }; -std::uint64_t allocation_cycles = 0; - void application(resource_list& p_resources) { resources = &p_resources; @@ -71,17 +68,12 @@ void application(resource_list& p_resources) for (std::size_t i = 0; i < functions.size(); i++) { try { functions.at(i)(); - // NOTE to Khalil before submission. Something is wrong with the unwinder - // and we are jumping to different locations when it completes the first - // time. Local variables are probably being damaged or the stack pointer - // is not in the correct location. } catch ([[maybe_unused]] my_error_t const& p_error) { end_cycles = resources->clock->uptime(); cycle_map[i] = end_cycles - start_cycles; } } -#if 1 for (std::size_t i = 0; i < functions.size(); i++) { bool was_caught = false; try { @@ -96,7 +88,6 @@ void application(resource_list& p_resources) happy_cycle_map[i] = end_cycles - start_cycles; } } -#endif while (true) { continue; @@ -11407,4 +11398,5 @@ int funct_group24_95() return side_effect; } -#endif \ No newline at end of file + +#endif diff --git a/notes.md b/notes.md index 955f09f..5ed7c58 100644 --- a/notes.md +++ b/notes.md @@ -7,4 +7,4 @@ - Reduce the instructions for `restore_cpu_state` - Remove shift variable in `read_uleb128` -- I've turned destructors back on and we are terminating. Looks like the encoding byte has 0x15 which we don't support. 0x5 for the encoding type is not present. So we need to figure out what that is. Its either us reading the wrong data OR a new format we need to handle. \ No newline at end of file +- I've turned destructors back on and we are terminating. Looks like the encoding byte has 0x15 which we don't support. 0x5 for the encoding type is not present. So we need to figure out what that is. Its either us reading the wrong data OR a new format we need to handle. diff --git a/src/arm_cortex/estell/exception.cpp b/src/arm_cortex/estell/exception.cpp index 9768cb4..dc514e9 100644 --- a/src/arm_cortex/estell/exception.cpp +++ b/src/arm_cortex/estell/exception.cpp @@ -495,7 +495,8 @@ inline void restore_cpu_core(ke::cortex_m_cpu& p_cpu_core) inline void enter_function(exception_object& p_exception_object) { - auto const* lsda_word = p_exception_object.cache.entry_ptr->lsda_data(); + auto const* lsda_word = + index_entry_t::lsda_data(p_exception_object.cache.personality); auto const* lsda_data = reinterpret_cast(lsda_word); #if 0 @@ -630,7 +631,7 @@ inline lsda_header_info parse_header(std::uint8_t const** p_lsda) inline auto const* to_lsda(exception_object& p_exception_object) { return reinterpret_cast( - p_exception_object.cache.entry_ptr->lsda_data()); + index_entry_t::lsda_data(p_exception_object.cache.personality)); } inline auto calculate_relative_pc(exception_object& p_exception_object) @@ -1973,15 +1974,20 @@ void raise_exception(exception_object& p_exception_object) case runtime_state::get_next_frame: { auto const& index_entry = get_index_entry(p_exception_object.cpu.pc); p_exception_object.cache.entry_ptr = &index_entry; + // SU16 data if (index_entry.has_inlined_personality()) { p_exception_object.cache.state(runtime_state::unwind_frame); break; } - auto const* descriptor_start = index_entry.descriptor_start(); + p_exception_object.cache.personality = index_entry.personality(); + auto const* descriptor_start = + index_entry_t::descriptor_start(p_exception_object.cache.personality); + // LU16 data no LSDA if (*descriptor_start == 0x0000'0000) { p_exception_object.cache.state(runtime_state::unwind_frame); break; } + // LSDA p_exception_object.cache.relative_address( (p_exception_object.cpu.pc - index_entry.function())); p_exception_object.cache.state(runtime_state::enter_function); diff --git a/src/arm_cortex/estell/internal.hpp b/src/arm_cortex/estell/internal.hpp index d639151..dc0eed9 100644 --- a/src/arm_cortex/estell/internal.hpp +++ b/src/arm_cortex/estell/internal.hpp @@ -133,7 +133,7 @@ struct function_t bool operator<(function_t const& p_other) const { - return address < p_other.address; + return address < p_other.address; // NOLINT } bool operator==(function_t const& p_other) const @@ -182,11 +182,12 @@ struct index_entry_t return to_absolute_address_ptr(&personality_offset); } - [[gnu::always_inline]] inline std::uint32_t const* lsda_data() const + [[gnu::always_inline]] static inline std::uint32_t const* lsda_data( + std::uint32_t const* p_personality) { constexpr auto personality_type = hal::bit_mask::from<24, 27>(); // +1 to skip the prel31 offset to the personality function - auto const* header = personality() + 1; + auto const* header = p_personality + 1; if (hal::bit_extract(*header) == 0x0) { return header + 1; } @@ -199,22 +200,22 @@ struct index_entry_t return header + 3; } - [[gnu::always_inline]] inline std::uint32_t const* descriptor_start() const + [[gnu::always_inline]] inline static std::uint32_t const* descriptor_start( + std::uint32_t const* p_personality) { constexpr auto type_mask = hal::bit_mask{ .position = 24, .width = 8 }; - auto* personality_address = personality(); - auto type = hal::bit_extract(*personality_address); + auto type = hal::bit_extract(*p_personality); // TODO(kammce): comment why each of these works! if (type == 0x0) { - return personality_address + 1; + return p_personality + 1; } // The limit for ARM exceptions instructions is 7. LD optimizes the ARM // exception spec by removing the "word length" specifier allowing the // instructions to fit in 2 words. - return personality_address + 2; + return p_personality + 2; } [[gnu::always_inline]] function_t function() const @@ -262,8 +263,9 @@ enum class runtime_state : std::uint8_t struct cache_t { - std::uint32_t rel_address; index_entry_t const* entry_ptr = nullptr; + std::uint32_t const* personality = nullptr; + std::uint32_t rel_address; runtime_state inner_state; bool previously_rethrown = false;