diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/elf_load.cpp | 13 | ||||
-rw-r--r-- | source/elf_load.hpp | 7 | ||||
-rw-r--r-- | source/main.cpp | 14 |
3 files changed, 27 insertions, 7 deletions
diff --git a/source/elf_load.cpp b/source/elf_load.cpp index 661dbc3..8149e8a 100644 --- a/source/elf_load.cpp +++ b/source/elf_load.cpp @@ -4,7 +4,6 @@ #include <algorithm> #include <cstring> -extern void *elf_load_offset; static const unsigned char elf_header[] = { '\177', 'E', 'L', 'F' }; template<typename T> @@ -17,10 +16,10 @@ static Elf32_Shdr *find_section(Elf32_Ehdr *ehdr, const char *name); namespace elf { -entry_t elf_load(void *elf_data) +entry_t load(void *elf_data, void *elf_load_offset) { auto ehdr = reinterpret_cast<Elf32_Ehdr *>(elf_data); - if (std::equal(ehdr->e_ident, ehdr->e_ident + 4, elf_header)) + if (!std::equal(ehdr->e_ident, ehdr->e_ident + 4, elf_header)) return nullptr; auto phdr = ptr_from_offset<Elf32_Phdr *>(elf_data, ehdr->e_phoff); @@ -31,6 +30,8 @@ entry_t elf_load(void *elf_data) phdr->p_filesz); //break; } + + phdr = ptr_from_offset<Elf32_Phdr *>(phdr, ehdr->e_phentsize); } // Zero .bss section @@ -53,7 +54,11 @@ entry_t elf_load(void *elf_data) // [elf_load_offset](auto func) { (func + elf_load_offset)(); }); //} - return ptr_from_offset<entry_t>(elf_load_offset, ehdr->e_entry); + // Find filter code start + if (auto filter = find_section(ehdr, ".process_data"); filter) + return ptr_from_offset<entry_t>(elf_load_offset, filter->sh_addr | 1); // OR 1 to enable thumb + else + return nullptr; } } // namespace elf diff --git a/source/elf_load.hpp b/source/elf_load.hpp index 722b19b..3e03f1d 100644 --- a/source/elf_load.hpp +++ b/source/elf_load.hpp @@ -1,11 +1,14 @@ #ifndef ELF_LOAD_HPP_ #define ELF_LOAD_HPP_ +#include <cstddef> +#include <cstdint> + namespace elf { - using entry_t = void (*)(); + using entry_t = void (*)(uint16_t *, size_t); - entry_t load(void *file_data); + entry_t load(void *elf_data, void *elf_load_offset); } #endif // ELF_LOAD_HPP_ diff --git a/source/main.cpp b/source/main.cpp index 162771a..6c418ce 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -14,6 +14,7 @@ #include "adc.hpp" #include "dac.hpp" +#include "elf_load.hpp" #include "usbserial.hpp" #include <array> @@ -30,6 +31,10 @@ CC_ALIGN(CACHE_LINE_SIZE) #endif static std::array<dacsample_t, CACHE_SIZE_ALIGN(dacsample_t, 2048)> dac_samples; +static uint8_t elf_file_store[2048]; +static uint8_t elf_exec_store[2048]; +static elf::entry_t elf_entry = nullptr; + static volatile bool signal_operate_done = false; static void signal_operate(adcsample_t *buffer, size_t count); @@ -73,7 +78,12 @@ int main() adc::read_stop(); break; case 'e': - + if (usbserial::read(&cmd[1], 2) < 2) + break; + if (unsigned int count = cmd[1] | (cmd[2] << 8); count < sizeof(elf_file_store)) { + usbserial::read(elf_file_store, count); + elf_entry = elf::load(elf_file_store, elf_exec_store); + } break; case 'W': if (usbserial::read(&cmd[1], 2) < 2) @@ -103,6 +113,8 @@ int main() void signal_operate(adcsample_t *buffer, size_t count) { + if (elf_entry) + elf_entry(buffer, count); auto dac_buffer = &dac_samples[buffer == &adc_samples[0] ? 0 : 1024]; std::copy(buffer, buffer + count, dac_buffer); signal_operate_done = buffer == &adc_samples[1024]; |