Giter Site home page Giter Site logo

Comments (8)

tvlad1234 avatar tvlad1234 commented on July 18, 2024

I tried the file-backed RAM approach on an x86 Linux system (same code, only difference being file access as I use FatFS on the Pico) and it worked. I am pretty sure that the RAM access on the Pico works properly, as I've tried multiple approaches and all of them had the same result (same access fault at the same address every time). The project I am working on can be found here: pico-rv32ima

from mini-rv32ima.

tvlad1234 avatar tvlad1234 commented on July 18, 2024

I tried compiling and running mini-rv32ima (the regular version provided in this repository) on a Pi 4 running Pi OS Lite. The emulator crashed in the exact same way as it did with my version on the Pi Pico. I suspect there's some code in mini-rv32ima.h that behaves differently on ARM than it does on x86.

from mini-rv32ima.

cnlohr avatar cnlohr commented on July 18, 2024

Would you mind running it in valgrind by saying valgrind ./minir....

Additionally, can you build the kernel + image to see where the call stack is actually failing?

from mini-rv32ima.

tvlad1234 avatar tvlad1234 commented on July 18, 2024

I'm building the kernel right now. On a side note, I also compiled and ran mini-rv32ima on 64-bit ARM (a Mac and an Oracle Cloud VM) and it worked without any issues, so I'm guessing it's 32-bit ARM related. I also compiled with clang on ARM32, with the same issues.

from mini-rv32ima.

tvlad1234 avatar tvlad1234 commented on July 18, 2024

I've rebuilt the image and ran mini-rv32ima in Valgrind. I'm getting a different error message in the kernel with this image (but it's still the same every time I run the emulator). After looking at the assembly listing, it seems that it faults at an ebreak in init_pwq. Also, if I run the emulator with the -d parameter, it faults and exits at the address the kernel is reporting in the panic message.

I am attaching the Valgrind output, kernel listing and kernel image below.
valgrindOutput.txt
imageAndListing.zip

from mini-rv32ima.

tvlad1234 avatar tvlad1234 commented on July 18, 2024

I have added a printf in the emulator code which prints the memory address it loads from when it executes the instruction that triggers the access fault in the provided prebuilt image:

                               case 0b0000011: // Load
                               {
                                       uint32_t rs1 = REG((ir >> 15) & 0x1f);
                                       uint32_t imm = ir >> 20;
                                       int32_t imm_se = imm | (( imm & 0x800 )?0xfffff000:0);
                                       uint32_t rsval = rs1 + imm_se;

                                       // vlads modification
                                       // see what address we try to access at the instruction which fails
                                        if(pc == 0x8006f1fc){
                                               printf("\n\nrsval = %08x", rsval); getchar(); }

On x86 the emulator outputs:

[    0.000000] Memory: 61936K/65532K available (1346K kernel code, 271K rwdata, 149K rodata, 1105K init, 108K bss, 3596K reserved, 0K cma-reserved)


rsval = 83f84d88

rsval = 83f84da8[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] riscv-intc: 32 local interrupts mapped
[    0.000000] clint: clint@11000000: timer running at 1000000 Hz
[    0.000000] clocksource: clint_clocksource: mask: 0xffffffffffffffff max_cycles: 0x1d854df40, max_idle_ns: 3526361616960 ns
[    0.000000] sched_clock: 64 bits at 1000kHz, resolution 1000ns, wraps every 2199023255500ns


rsval = 83f84dc8[    0.443526] Console: colour dummy device 80x25
[    0.443855] Calibrating delay loop (skipped), value calculated using timer frequency.. 2.00 BogoMIPS (lpj=4000)
[    0.444364] pid_max: default: 4096 minimum: 301


rsval = 83f84de8

On ARM32 it outputs:

  GNU nano 6.4                                                             on_arm.txt                                                                      
[    0.000000] Memory: 61936K/65532K available (1346K kernel code, 271K rwdata, 149K rodata, 1105K init, 108K bss, 3596K reserved, 0K cma-reserved)


rsval = 83ffba48

rsval = 83ffbce8[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] riscv-intc: 32 local interrupts mapped
[    0.000000] clint: clint@11000000: timer running at 1000000 Hz
[    0.000000] clocksource: clint_clocksource: mask: 0xffffffffffffffff max_cycles: 0x1d854df40, max_idle_ns: 3526361616960 ns
[    0.000000] sched_clock: 64 bits at 1000kHz, resolution 1000ns, wraps every 2199023255500ns


rsval = 83ffba08[    2.711267] Console: colour dummy device 80x25
[    2.716250] Calibrating delay loop (skipped), value calculated using timer frequency.. 2.00 BogoMIPS (lpj=4000)
[    2.725399] pid_max: default: 4096 minimum: 301


rsval = 00000004

from mini-rv32ima.

tvlad1234 avatar tvlad1234 commented on July 18, 2024

After a lot of debugging, it turns out that the following lines in mini-rv32ima.h behave differently on x86 and ARM:

case 0b001: rval = rs1 << rs2; break;

case 0b101: rval = (ir & 0x40000000 ) ? ( ((int32_t)rs1) >> rs2 ) : ( rs1 >> rs2 ); break;

This is due to the fact that shifts on x86 are automatically limited to 5bit values, but on ARM they aren't. In this case, there is a chance that the shift result might get fully zeroed, even though it's not supposed to be.

This issue seems to be solved by and'ing the rs2 value with 0x1F before using it in the bitshift.

from mini-rv32ima.

cnlohr avatar cnlohr commented on July 18, 2024

Thank you for doing all this work. It is all resolved now.

from mini-rv32ima.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.