Skip to content

Add RISC-V exception handler for MARS Kernel #1140

Closed
pavelkryukov opened this issue Nov 15, 2019 · 9 comments
Closed

Add RISC-V exception handler for MARS Kernel #1140

pavelkryukov opened this issue Nov 15, 2019 · 9 comments
Assignees
Labels
4 Features of medium complexity which usually require infrastructure enhancements. enhancement Adds a new feature to simulation. S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA

Comments

@pavelkryukov
Copy link
Member

Currently our MARS kernel mode handles expections by loading MIPS32 code into memory.

ElfLoader elf_loader( KERNEL_IMAGES "mars32_le.bin");

The MIPS32 code is generated from MARS Assembler:
https://github.com/MIPT-ILab/mipt-mips/blob/master/kernels/exceptions.s

Your goal is to re-write the exception handling code for RISC-V and load it depending on modeled ISA.

@pavelkryukov pavelkryukov added enhancement Adds a new feature to simulation. 4 Features of medium complexity which usually require infrastructure enhancements. S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA labels Nov 15, 2019
@exucutional exucutional self-assigned this Jan 27, 2020
@pavelkryukov
Copy link
Member Author

@exucutional Eric, could you please share your plan regarding this assignment?

@exucutional
Copy link
Contributor

Firstly I'll write riscv-driver to handle traps in the same manner as mips-driver

class DriverRISCV32 : public Driver
{
public:
    explicit DriverRISCV32( Simulator* sim) : cpu( sim) { }
    Trap handle_trap( const Operation& instr) const final 
    {
        auto trap = instr.trap_type();
        if ( trap == Trap::NO_TRAP || trap == Trap::HALT)
            return trap;

        auto tvec = cpu->read_csr_register( "mtvec");
        cpu->write_csr_register( "mcause", ...);
        cpu->write_csr_register( "mepc", ...);
        cpu->set_pc( ...);
        return Trap( Trap::NO_TRAP);
    }
    std::unique_ptr<Driver> clone() const final { return std::make_unique<DriverRISCV32>( cpu); }
private:
    Simulator* const cpu;
};

Also I'll implement get_isa() method for

class CPUModel
to let MARS kernel knows connected simulator's isa.

What should the handler do? Without #920 it cannot even print information about exception. It can extract exception code, make some checks, clear CSRs and return.
After implementing RISC-V syscalls, the functionality of handler may be expanded.

@pavelkryukov
Copy link
Member Author

Looks good.

Without #920 it cannot even print information about exception.

The idea is that we use MARS kernel and not RISC-V PK.
I/O will be handled by MARS kernel similarly to MIPS.

@pavelkryukov
Copy link
Member Author

Firstly I'll write riscv-driver to handle traps in the same manner as mips-driver

I suggest to start with unit tests.
For MIPS, I had test binaries which I used to verify correctness — here they are likely to appear after the task completion.

@pavelkryukov
Copy link
Member Author

Do I understand correctly the task is close to completion?

If yes, please provide an example of interactive RISC-V program (welcome message, input two numbers, print the sum – would be enough) and describe interfaces here: https://github.com/MIPT-ILab/mipt-mips/wiki/MARS-syscalls

@exucutional
Copy link
Contributor

If yes, please provide an example of interactive RISC-V program

Where should I put the code?
Also I am trying to figure out where is the bug in performance simulator. Program works only with -f option.

Usually it indicates a bug in performance simulator
The different instructions are:	
Checker output: 0x1008c: {6}	addi $t1, $sp, 0	 [ $t1 = 0x1 ]
PerfSim output: 0x1008c: {6}	addi $t1, $sp, 0	 [ $t1 = 0x5 ]

@pavelkryukov
Copy link
Member Author

where is the bug in performance simulato

Let's focus on functional simulation. I'll check performance simulation later.

@pavelkryukov
Copy link
Member Author

Where should I put the code?

I think we may have a dedicated repo: https://github.com/MIPT-ILab/riscv-mars-examples

@pavelkryukov
Copy link
Member Author

@exucutional I appreciate the way you completed this task, with good balance of independency, involvement, and quality. Please keep that level and do not forget to move forward!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4 Features of medium complexity which usually require infrastructure enhancements. enhancement Adds a new feature to simulation. S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA
Projects
None yet
Development

No branches or pull requests

2 participants