Skip to content

Commit

Permalink
⚡ Cache & Use the personality pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
kammce committed Jul 23, 2024
1 parent bb00c65 commit 1a3c902
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
22 changes: 7 additions & 15 deletions demos/applications/multi_levels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,14 @@ std::array<signature*, 9> 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;
Expand All @@ -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 {
Expand All @@ -96,7 +88,6 @@ void application(resource_list& p_resources)
happy_cycle_map[i] = end_cycles - start_cycles;
}
}
#endif

while (true) {
continue;
Expand Down Expand Up @@ -11407,4 +11398,5 @@ int funct_group24_95()

return side_effect;
}
#endif

#endif
2 changes: 1 addition & 1 deletion notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- 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.
12 changes: 9 additions & 3 deletions src/arm_cortex/estell/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::uint8_t const*>(lsda_word);

#if 0
Expand Down Expand Up @@ -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<std::uint8_t const*>(
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)
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 11 additions & 9 deletions src/arm_cortex/estell/internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<personality_type>(*header) == 0x0) {
return header + 1;
}
Expand All @@ -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<type_mask>(*personality_address);
auto type = hal::bit_extract<type_mask>(*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
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 1a3c902

Please sign in to comment.