From 9d7a708c8c1069d89555bf665d1479ef9667b919 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Wed, 31 Jan 2024 07:25:22 +0800 Subject: [PATCH 1/7] Pass ELF Data --- jsemu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jsemu.c b/jsemu.c index 3641db4..5a5cf82 100644 --- a/jsemu.c +++ b/jsemu.c @@ -181,8 +181,13 @@ static void init_vm_fs(void *arg); static void init_vm_drive(void *arg); void vm_start(const char *url, int ram_size, const char *cmdline, - const char *pwd, int width, int height, BOOL has_network) + const char *pwd, int width, int height, BOOL has_network, + const char *drive_url, const char *elf_data) { + //// Begin Test + printf("elf_data=%s\n", elf_data); + //// End Test + VMStartState *s; s = mallocz(sizeof(*s)); From 7c06787cb35e62acf92ab0a873cd094f52c06716 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Wed, 31 Jan 2024 07:42:27 +0800 Subject: [PATCH 2/7] Pass ELF Data --- jsemu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jsemu.c b/jsemu.c index 5a5cf82..b374c43 100644 --- a/jsemu.c +++ b/jsemu.c @@ -182,10 +182,13 @@ static void init_vm_drive(void *arg); void vm_start(const char *url, int ram_size, const char *cmdline, const char *pwd, int width, int height, BOOL has_network, - const char *drive_url, const char *elf_data) + const char *drive_url, const char *elf_data, int elf_len) { //// Begin Test - printf("elf_data=%s\n", elf_data); + printf("elf_len=%d\n", elf_len); + for (int i = 0; i < elf_len; i++) { + printf("elf_data[%d]=0x%x\n", i, elf_data[i]); + } //// End Test VMStartState *s; From 71ee7eaba3e85e3f7ae4520ada53e290f64be711 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Wed, 31 Jan 2024 09:25:07 +0800 Subject: [PATCH 3/7] Patch a.out is OK --- jsemu.c | 2 +- riscv_machine.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/jsemu.c b/jsemu.c index b374c43..db7f391 100644 --- a/jsemu.c +++ b/jsemu.c @@ -182,7 +182,7 @@ static void init_vm_drive(void *arg); void vm_start(const char *url, int ram_size, const char *cmdline, const char *pwd, int width, int height, BOOL has_network, - const char *drive_url, const char *elf_data, int elf_len) + const char *drive_url, uint8_t *elf_data, int elf_len) { //// Begin Test printf("elf_len=%d\n", elf_len); diff --git a/riscv_machine.c b/riscv_machine.c index bdd3668..02eabbb 100644 --- a/riscv_machine.c +++ b/riscv_machine.c @@ -43,6 +43,77 @@ #define _info(...) {} //// // #define _info printf //// +uint8_t elf_data[] = { //// + 0x7F, 0x45, 0x4C, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0xF3, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x09, 0x00, 0x08, 0x00, + 0x13, 0x01, 0x01, 0xFA, 0x23, 0x3C, 0x11, 0x04, 0x23, 0x38, 0x81, 0x04, 0x13, 0x04, 0x01, 0x06, + 0x13, 0x00, 0x00, 0x00, 0x23, 0x34, 0xA4, 0xFE, 0x23, 0x30, 0xB4, 0xFE, 0x1B, 0x05, 0xD0, 0x03, + 0x23, 0x2E, 0xA4, 0xFC, 0x1B, 0x05, 0x10, 0x00, 0x23, 0x38, 0xA4, 0xFC, 0x17, 0x05, 0x00, 0x00, + 0x13, 0x05, 0x05, 0x00, 0x23, 0x34, 0xA4, 0xFC, 0x1B, 0x05, 0xF0, 0x00, 0x23, 0x30, 0xA4, 0xFC, + 0x03, 0x25, 0xC4, 0xFD, 0x13, 0x15, 0x05, 0x02, 0x13, 0x55, 0x05, 0x02, 0x23, 0x3C, 0xA4, 0xFA, + 0x03, 0x35, 0x04, 0xFD, 0x23, 0x38, 0xA4, 0xFA, 0x03, 0x35, 0x84, 0xFC, 0x23, 0x34, 0xA4, 0xFA, + 0x03, 0x35, 0x04, 0xFC, 0x23, 0x30, 0xA4, 0xFA, 0x13, 0x05, 0xD0, 0x03, 0x93, 0x05, 0x10, 0x00, + 0x37, 0x06, 0x08, 0x00, 0x1B, 0x06, 0x16, 0x10, 0x13, 0x16, 0xC6, 0x00, 0x93, 0x06, 0xF0, 0x00, + 0x73, 0x00, 0x00, 0x00, 0x01, 0x00, 0x6F, 0x00, 0x00, 0x00, 0x83, 0x30, 0x81, 0x05, 0x03, 0x34, + 0x01, 0x05, 0x13, 0x01, 0x01, 0x06, 0x67, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x21, 0x0A, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0xF1, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0E, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x12, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x2E, 0x63, 0x00, 0x6D, 0x61, 0x69, 0x6E, 0x00, 0x4C, 0x2E, + 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x2E, 0x74, 0x65, 0x78, 0x74, 0x00, 0x2E, 0x64, 0x61, 0x74, 0x61, 0x00, 0x2E, 0x64, 0x61, + 0x74, 0x61, 0x2E, 0x72, 0x6F, 0x00, 0x2E, 0x62, 0x73, 0x73, 0x00, 0x2E, 0x73, 0x79, 0x6D, 0x74, + 0x61, 0x62, 0x00, 0x2E, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, 0x2E, 0x72, 0x65, 0x6C, 0x61, + 0x2E, 0x74, 0x65, 0x78, 0x74, 0x00, 0x2E, 0x73, 0x68, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0D, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x1B, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x23, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x2B, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; //// + /* RISCV machine */ typedef struct RISCVMachine { @@ -955,6 +1026,21 @@ static void copy_bios(RISCVMachine *s, const uint8_t *buf, int buf_len, printf("Patched SYNC.S (Ensure that all Cache Operations are completed) at %p\n", sync_s_addr); } } + + // Patch the ELF Data to a.out + uint64_t elf_addr = 0; + const int elf_len = sizeof(elf_data); //// TODO + printf("elf_len=%d\n", elf_len); + for (int i = 0; i < 0xD61680; i++) { //// TODO: Fix the Image Size + const uint8_t pattern[] = { 0x22, 0x05, 0x69, 0x00 }; + if (memcmp(&kernel_ptr[i], pattern, sizeof(pattern)) == 0) { + memcpy(&kernel_ptr[i], elf_data, elf_len); + elf_addr = RAM_BASE_ADDR + i; + printf("Patched ELF Data to a.out at %p\n", elf_addr); + break; + } + } + if (elf_addr == 0) { puts("*** ERROR: Pattern for ELF Data a.out is missing"); } //// End Test } From c2f2e5b373e884c9997d083200c9db1539c0940c Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Wed, 31 Jan 2024 11:00:29 +0800 Subject: [PATCH 4/7] ELF Data tested OK --- jsemu.c | 13 ++++++++----- riscv_machine.c | 37 ++++++++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/jsemu.c b/jsemu.c index db7f391..36065b3 100644 --- a/jsemu.c +++ b/jsemu.c @@ -182,13 +182,16 @@ static void init_vm_drive(void *arg); void vm_start(const char *url, int ram_size, const char *cmdline, const char *pwd, int width, int height, BOOL has_network, - const char *drive_url, uint8_t *elf_data, int elf_len) + const char *drive_url, uint8_t *elf_data0, int elf_len0) { - //// Begin Test + //// Begin Test: Patch the ELF Data to a.out in Initial RAM Disk + extern uint8_t elf_data[]; + extern int elf_len; + elf_len = elf_len0; + printf("elf_len=%d\n", elf_len); - for (int i = 0; i < elf_len; i++) { - printf("elf_data[%d]=0x%x\n", i, elf_data[i]); - } + if (elf_len > 4096) { puts("*** ERROR: elf_len exceeds 4096, increase elf_data and a.out size"); } + memcpy(elf_data, elf_data0, elf_len); //// End Test VMStartState *s; diff --git a/riscv_machine.c b/riscv_machine.c index 02eabbb..d19173f 100644 --- a/riscv_machine.c +++ b/riscv_machine.c @@ -43,7 +43,8 @@ #define _info(...) {} //// // #define _info printf //// -uint8_t elf_data[] = { //// +#ifndef NOTUSED +uint8_t elf_data2[] = { //// 0x7F, 0x45, 0x4C, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xF3, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -113,6 +114,8 @@ uint8_t elf_data[] = { //// 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; //// +const int elf_len2 = sizeof(elf_data2); //// TODO +#endif // NOTUSED /* RISCV machine */ @@ -162,6 +165,8 @@ uint64_t rdtime_addr = 0; uint64_t dcache_iall_addr = 0; uint64_t sync_s_addr = 0; uint64_t real_time = 0; +uint8_t elf_data[4096]; +int elf_len = 0; static uint64_t rtc_get_real_time(RISCVMachine *s) { @@ -1027,20 +1032,30 @@ static void copy_bios(RISCVMachine *s, const uint8_t *buf, int buf_len, } } - // Patch the ELF Data to a.out + // Patch the ELF Data to a.out in Initial RAM Disk uint64_t elf_addr = 0; - const int elf_len = sizeof(elf_data); //// TODO printf("elf_len=%d\n", elf_len); - for (int i = 0; i < 0xD61680; i++) { //// TODO: Fix the Image Size - const uint8_t pattern[] = { 0x22, 0x05, 0x69, 0x00 }; - if (memcmp(&kernel_ptr[i], pattern, sizeof(pattern)) == 0) { - memcpy(&kernel_ptr[i], elf_data, elf_len); - elf_addr = RAM_BASE_ADDR + i; - printf("Patched ELF Data to a.out at %p\n", elf_addr); - break; + for (int i = 0; i < elf_len; i++) { + printf("elf_data[%d]=0x%x\n", i, elf_data[i]); + if (elf_data[i] != elf_data2[i]) { + printf("*** elf_data2[%d]=0x%x\n", i, elf_data2[i]); + } + } + if (elf_len > 0) { + printf("memcmp=%d\n", memcmp(elf_data, elf_data2, elf_len)); //// + //// TODO: Fix the Image Size + for (int i = 0; i < 0xD61680; i++) { + const uint8_t pattern[] = { 0x22, 0x05, 0x69, 0x00 }; + if (memcmp(&kernel_ptr[i], pattern, sizeof(pattern)) == 0) { + //// TODO: Catch overflow of a.out + memcpy(&kernel_ptr[i], elf_data, elf_len); + elf_addr = RAM_BASE_ADDR + i; + printf("Patched ELF Data to a.out at %p\n", elf_addr); + break; + } } + if (elf_addr == 0) { puts("*** ERROR: Pattern for ELF Data a.out is missing"); } } - if (elf_addr == 0) { puts("*** ERROR: Pattern for ELF Data a.out is missing"); } //// End Test } From 704be7eb899d2051ae91af75949958350dc8f3b2 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Wed, 31 Jan 2024 11:04:20 +0800 Subject: [PATCH 5/7] ELF Data tested OK --- riscv_machine.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/riscv_machine.c b/riscv_machine.c index d19173f..316f557 100644 --- a/riscv_machine.c +++ b/riscv_machine.c @@ -43,7 +43,7 @@ #define _info(...) {} //// // #define _info printf //// -#ifndef NOTUSED +#ifdef NOTUSED uint8_t elf_data2[] = { //// 0x7F, 0x45, 0x4C, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xF3, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -1035,14 +1035,7 @@ static void copy_bios(RISCVMachine *s, const uint8_t *buf, int buf_len, // Patch the ELF Data to a.out in Initial RAM Disk uint64_t elf_addr = 0; printf("elf_len=%d\n", elf_len); - for (int i = 0; i < elf_len; i++) { - printf("elf_data[%d]=0x%x\n", i, elf_data[i]); - if (elf_data[i] != elf_data2[i]) { - printf("*** elf_data2[%d]=0x%x\n", i, elf_data2[i]); - } - } if (elf_len > 0) { - printf("memcmp=%d\n", memcmp(elf_data, elf_data2, elf_len)); //// //// TODO: Fix the Image Size for (int i = 0; i < 0xD61680; i++) { const uint8_t pattern[] = { 0x22, 0x05, 0x69, 0x00 }; From b664995a5abe47914e68143ab2779daaa11380ed Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Wed, 31 Jan 2024 11:30:02 +0800 Subject: [PATCH 6/7] ELF Data tested OK yay! --- jsemu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jsemu.c b/jsemu.c index 36065b3..3ae8889 100644 --- a/jsemu.c +++ b/jsemu.c @@ -185,10 +185,11 @@ void vm_start(const char *url, int ram_size, const char *cmdline, const char *drive_url, uint8_t *elf_data0, int elf_len0) { //// Begin Test: Patch the ELF Data to a.out in Initial RAM Disk - extern uint8_t elf_data[]; + extern uint8_t elf_data[]; // From riscv_machine.c extern int elf_len; elf_len = elf_len0; + // Must copy ELF Data to Local Buffer because it will get overwritten printf("elf_len=%d\n", elf_len); if (elf_len > 4096) { puts("*** ERROR: elf_len exceeds 4096, increase elf_data and a.out size"); } memcpy(elf_data, elf_data0, elf_len); From 139e62d321773a517e1effb7e6b1d7a25d965d86 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Sun, 4 Feb 2024 10:17:14 +0800 Subject: [PATCH 7/7] Add article --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 431eca6..b1ffa97 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Read the articles... +- ["TCC RISC-V Compiler runs in the Web Browser (thanks to Zig Compiler)"](https://lupyuen.github.io/articles/tcc) + - ["Automated Testing with Ox64 BL808 Emulator (Apache NuttX RTOS)"](https://lupyuen.github.io/articles/tinyemu3) - ["Emulate Ox64 BL808 in the Web Browser: Experiments with TinyEMU RISC-V Emulator and Apache NuttX RTOS"](https://lupyuen.github.io/articles/tinyemu2)