commit a67f2fcdcd5d5cc91b1aac7a4c600482f600a732 from: Benjamin Stürz date: Tue Feb 20 18:17:24 2024 UTC fix memory segment loading commit - d83e2c2bfa0da3e560fb2531756425b8fa7b00b1 commit + a67f2fcdcd5d5cc91b1aac7a4c600482f600a732 blob - dda54ef21b86d17b849a365a3e017cd10a0b0e91 blob + c1b64dea367cf49f7f9f16f859eb4ff99407573e --- Makefile +++ Makefile @@ -14,6 +14,9 @@ PROGS = test.elf hello.elf all: rvemu ${PROGS} +od: test.elf + ${CROSS}-objdump -d test.elf | less + clean: rm -f rvemu *.o *.elf *.core syscalls.h rm -rf rootfs blob - 01a083c40878b0008d9c60680e2858af82eab131 blob + 6d0a65ab8870c771e0c20ac41212797db275fd74 --- cpu.c +++ cpu.c @@ -69,11 +69,6 @@ void cpu_exec (u32 instr) case 0b1100111: // jalr rd, rs1, iimm switch (funct3) { case 0b000: - // XXX: Fix broken musl - if (cpu_get (rs1) == 0) { - warnx ("%08llx: tried to jump to address 0!", pc - 4); - return; - } log ("jalr x%u, x%u, %lld", (uint)rd, (uint)rs1, imm_i); cpu_set (rd, pc); pc = cpu_get (rs1); blob - 016725c65ba8bd0ec68749e033a54b366ba424b9 blob + 23cc40c4b208dbd67a50dac13bd9cf0784df78eb --- rvemu.c +++ rvemu.c @@ -40,7 +40,7 @@ static void load_segment (int fd, Elf64_Phdr phdr) if (phdr.p_filesz > 0) { lseek (fd, phdr.p_offset, SEEK_SET); - read (fd, ptr, phdr.p_filesz); + read (fd, (void *)phdr.p_vaddr, phdr.p_filesz); } if (phdr.p_flags & (PF_R | PF_X)) blob - f1fa870f78600a53528abcc226d280124e392286 blob + 4cb95aa505e1a5d33bd0d37ed1fb0f4f115b2b67 --- rvemu.h +++ rvemu.h @@ -4,7 +4,7 @@ #include #include -#define DEBUG 0 +#define DEBUG 1 #if DEBUG # define eprintf(...) fprintf (stderr, __VA_ARGS__) blob - e61a4cd6fefd3e020aa5e35cc33c1a32f776730d blob + 70f3e50ce557283d9025cf3c7e821c05c080395b --- test.c +++ test.c @@ -1,8 +1,16 @@ #include #include +const char *volatile str = "Hello World!\n"; + +size_t my_strlen (const char *s) +{ + size_t i; + for (i = 0; s[i] != '\0'; ++i); + return i; +} + int main (void) { - const char str[] = "Hello, World\n"; - write (1, str, sizeof (str) - 1); - return 0; + const size_t len = my_strlen (str); + return len; }