Skip to content

Enhance Trap class #602

Closed
pavelkryukov opened this issue Oct 4, 2018 · 8 comments
Closed

Enhance Trap class #602

pavelkryukov opened this issue Oct 4, 2018 · 8 comments
Assignees
Labels
2 Small features, tests coverage, simple laboratory works code Enhances infrastructure or refines, Requires almost no knowledge in CPU microarchitecture. good first issue Good task to start with MIPT-MIPS development S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA

Comments

@pavelkryukov
Copy link
Member

pavelkryukov commented Oct 4, 2018

#601 introduces a Trap enumeration.

We need to extend it to contain a class, similarly to MIPSRegister:

@pavelkryukov pavelkryukov added code Enhances infrastructure or refines, Requires almost no knowledge in CPU microarchitecture. 2 Small features, tests coverage, simple laboratory works S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA good first issue Good task to start with MIPT-MIPS development labels Oct 4, 2018
@davtyan-arsen davtyan-arsen self-assigned this Oct 7, 2018
@davtyan-arsen davtyan-arsen removed their assignment Oct 28, 2018
@pukhovv pukhovv self-assigned this Nov 23, 2018
pukhovv added a commit to pukhovv/mipt-mips that referenced this issue Feb 27, 2019
@pukhovv
Copy link
Contributor

pukhovv commented Feb 28, 2019

How should I implement any of these conversions?

Create macro list from MIPS traps enumeration (trap_types.h), separate it.
Create template classes for RISC-V and MIPS traps using macro.

Is it correct?

@pavelkryukov
Copy link
Member Author

First of all, I think it should be ISA-agnostic.
For implementation of GDB conversion, you may use a switch/case. We cannot copy signals.def as it is GPL, and we cannot guarantee that Binutils repository is cloned somewhere.

For RISC-V converter, the macro should be the best option.

@pavelkryukov
Copy link
Member Author

Any progress?

@pukhovv
Copy link
Contributor

pukhovv commented Mar 28, 2019

Just finished CS coursework. I plan to finish this issue this week.

pukhovv added a commit to pukhovv/mipt-mips that referenced this issue Mar 31, 2019
@pukhovv
Copy link
Contributor

pukhovv commented Mar 31, 2019

I wrote a RISC-V-like enumeration for MIPS traps. Can I do something similar for GDB-exceptions without copying signals.def? Or I have to write switch/case for from_gdb method without any defines.

@pavelkryukov
Copy link
Member Author

pavelkryukov commented Mar 31, 2019

No, no, that's not what we need, at all, completely.

We need a single Trap enumeration for all purposes, abstracted out of kernels, GDB, ISA etc.
For instance: unaligned address. In RISC-V convention, that is encoded with 4. In GNU convention, that is coded with 145.

We generate exception while executing instruction:

void executer_load_addr( Instr* instr)
{
// ..
  if (!aligned(instr->mem_addr))
    trap = Trap( UNALIGNED_ADDRESS);
}

If we need to intergrate RISC-V simulator to the RISC-V toolchain, we'll convert trap result to RISC-V format:

int execute_risc_v_simulation_step( Simulator* s)
{
    auto trap = s->step(); // returns UNALIGNED_ADDRESS
    retrun trap.to_riscv_format(); // returns 4
}

Same for GDB. We have the following code now:

static GDBTrap translate_trap( Trap mipt_trap, int exit_code)
{
static const std::unordered_map<Trap, GDBTrap> trap_converter =
{
{ Trap::HALT, { sim_exited, 0 } },
{ Trap::BREAKPOINT, { sim_stopped, GDB_SIGNAL_TRAP } },
{ Trap::EXPLICIT_TRAP, { sim_stopped, GDB_SIGNAL_TRAP } },
{ Trap::UNALIGNED_ADDRESS, { sim_stopped, GDB_SIGNAL_BUS } },
};
auto it = trap_converter.find( mipt_trap);
if ( it == trap_converter.end())
return GDBTrap( sim_polling, 0);
if ( it->second.first == sim_exited)
return GDBTrap( sim_exited, exit_code);
return it->second;
}

Instead, that function should use only Trap internal convertions:

using GDBTrap = std::pair<enum sim_stop, int>;
static GDBTrap translate_trap( Trap mipt_trap, int exit_code)
{
    if ( mipt_trap != HALT)
        return GDBTrap( sim_stopped, mipt_trap.to_gdb_format());
}

pukhovv added a commit to pukhovv/mipt-mips that referenced this issue Mar 31, 2019
@pukhovv
Copy link
Contributor

pukhovv commented Mar 31, 2019

There are no enumeration for GDB-signals in mipt-mips. I've temporary created one. What is the best way to do this?

Should I move internal conversion and dump methods to another file?

There are no one-to-one correspondence between trap types (BREAKPOINT, EXPLICIT_TRAP and GDB_SIGNAL_TRAP). Can I resolve this in BREAKPOINT favor?

pukhovv added a commit to pukhovv/mipt-mips that referenced this issue Mar 31, 2019
@pavelkryukov
Copy link
Member Author

There are no enumeration for GDB-signals in mipt-mips. I've temporary created one. What is the best way to do this?

Any working way is good.

Should I move internal conversion and dump methods to another file?

That should be in trap.cc

There are no one-to-one correspondence between trap types (BREAKPOINT, EXPLICIT_TRAP and GDB_SIGNAL_TRAP). Can I resolve this in BREAKPOINT favor?

In the most reasonable way.

pukhovv added a commit to pukhovv/mipt-mips that referenced this issue Apr 7, 2019
From/to riscv and gdb conversion methods.
Dumping method.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2 Small features, tests coverage, simple laboratory works code Enhances infrastructure or refines, Requires almost no knowledge in CPU microarchitecture. good first issue Good task to start with MIPT-MIPS development S1 — ISA To solve the issue, you need knowledge about MIPS or RISC-V ISA
Projects
None yet
Development

No branches or pull requests

3 participants