From 7b814855b46f2f62e1d20235b53ab33a2d687910 Mon Sep 17 00:00:00 2001 From: Yamamoto Masanari Date: Sat, 25 Jun 2022 10:16:05 +0900 Subject: [PATCH] Initialize PC with ELF entry point address --- src/device/mpu/loader/loader.c | 4 +++- src/device/mpu/loader/loader.h | 2 +- src/inc/cpuemu_ops.h | 1 + src/main/cpuemu.c | 9 ++++++++- src/main/main.c | 4 +++- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/device/mpu/loader/loader.c b/src/device/mpu/loader/loader.c index 4a422325..c7961c9b 100644 --- a/src/device/mpu/loader/loader.c +++ b/src/device/mpu/loader/loader.c @@ -32,11 +32,13 @@ Std_ReturnType binary_load(uint8 *binary_data, uint32 load_addr, uint32 binary_d return STD_E_OK; } -Std_ReturnType elf_load(uint8 *elf_data, MemoryAddressMapType *memap) +Std_ReturnType elf_load(uint8 *elf_data, MemoryAddressMapType *memap, uint32* entry_addr) { Std_ReturnType err; uint32 disable_debug_data_type = 0; + *entry_addr = ((const Elf32_Ehdr*)elf_data)->e_entry; + err = Elf_Check((const Elf32_Ehdr*)elf_data); if (err != STD_E_OK) { return err; diff --git a/src/device/mpu/loader/loader.h b/src/device/mpu/loader/loader.h index 3bd694f1..692b7e03 100644 --- a/src/device/mpu/loader/loader.h +++ b/src/device/mpu/loader/loader.h @@ -6,6 +6,6 @@ #include "cpuemu_ops.h" extern Std_ReturnType binary_load(uint8 *binary_data, uint32 load_addr, uint32 binary_data_len); -extern Std_ReturnType elf_load(uint8 *elf_data, MemoryAddressMapType *memap); +extern Std_ReturnType elf_load(uint8 *elf_data, MemoryAddressMapType *memap, uint32* entry_addr); #endif /* _LOADER_H_ */ diff --git a/src/inc/cpuemu_ops.h b/src/inc/cpuemu_ops.h index b1fe6b1b..d3ba269b 100644 --- a/src/inc/cpuemu_ops.h +++ b/src/inc/cpuemu_ops.h @@ -31,6 +31,7 @@ extern void cpuemu_get_register(CoreIdType core_id, TargetCoreType *cpu); extern void *cpuemu_thread_run(void* arg); extern uint64 cpuemu_get_cpu_end_clock(void); extern void cpuemu_set_cpu_end_clock(uint64 clock); +extern void cpuemu_set_entry_addr(uint32 entry_addr); extern Std_ReturnType cpuemu_set_comm_fifocfg(const char* fifocfg); diff --git a/src/main/cpuemu.c b/src/main/cpuemu.c index f8cfe41a..181e65df 100644 --- a/src/main/cpuemu.c +++ b/src/main/cpuemu.c @@ -34,6 +34,7 @@ static DeviceClockType cpuemu_dev_clock; std_bool private_cpuemu_is_cui_mode = FALSE; static uint64 cpuemu_cpu_end_clock = -1LLU; +static uint32 cpuemu_cpu_entry_addr = 0U; static void cpuemu_env_parse_devcfg_string(TokenStringType* strp); Std_ReturnType cpuemu_symbol_set(void) @@ -147,6 +148,12 @@ void cpuemu_set_cpu_end_clock(uint64 clock) return; } +void cpuemu_set_entry_addr(uint32 entry_addr) +{ + cpuemu_cpu_entry_addr = entry_addr; + return; +} + void cpuemu_get_elaps(CpuEmuElapsType *elaps) { int core_id; @@ -439,7 +446,7 @@ void *cpuemu_thread_run(void* arg) enable_dbg.enable_watch = TRUE; enable_dbg.enable_prof = TRUE; enable_dbg.enable_sync_time = FALSE; - enable_dbg.reset_pc = 0x0; + enable_dbg.reset_pc = cpuemu_cpu_entry_addr; cpuemu_dev_clock.enable_skip = FALSE; (void)cpuemu_get_devcfg_value("DEBUG_FUNC_ENABLE_BT", &enable_dbg.enable_bt); diff --git a/src/main/main.c b/src/main/main.c index e381502b..fb8acd1c 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -156,6 +156,7 @@ int main(int argc, const char *argv[]) Std_ReturnType err; CmdOptionType *opt; MemoryAddressMapType memmap; + uint32 entry_addr; memset(&memmap, 0, sizeof(MemoryAddressMapType)); if (argc == 1) { @@ -218,13 +219,14 @@ int main(int argc, const char *argv[]) binary_load((uint8*)opt->load_file.buffer, 0U, opt->load_file.size); } else { - elf_load((uint8*)opt->load_file.buffer, &memmap); + elf_load((uint8*)opt->load_file.buffer, &memmap, &entry_addr); if (cpuemu_symbol_set() != STD_E_OK) { return -1; } file_address_mapping_init(); } + cpuemu_set_entry_addr(entry_addr); if (opt->is_interaction == TRUE) { if (opt->is_remote == TRUE) { uint32 athrill_listen_port = CPUEMU_CONFIG_CUI_EMULATOR_PORTNO;