Skip to content

Commit

Permalink
Merge pull request #61 from yamam/support-elf-entry-point
Browse files Browse the repository at this point in the history
ELFのEntry Point Addressから実行開始する
  • Loading branch information
tmori authored Jun 25, 2022
2 parents 8c3732f + 7b81485 commit 868448e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/device/mpu/loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/device/mpu/loader/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
1 change: 1 addition & 0 deletions src/inc/cpuemu_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion src/main/cpuemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 868448e

Please sign in to comment.