This commit is contained in:
2024-05-12 17:02:54 +02:00
parent 8ebaea4583
commit f9541157b6
2 changed files with 93 additions and 2 deletions

View File

@ -220,7 +220,7 @@ static void execute_op(Hart* hart, uint32_t instruction)
}
else if (bank == 1)
{
if ((inst.funct3 & 0x8) == 0)
if ((inst.funct3 & 0x4) == 0)
{
uint64_t a = hart->regs[inst.rs1];
uint64_t b = hart->regs[inst.rs2];
@ -241,7 +241,68 @@ static void execute_op(Hart* hart, uint32_t instruction)
}
else
{
assert(!"Unhandled M OP");
uint32_t a = hart->regs[inst.rs1];
uint32_t b = hart->regs[inst.rs2];
switch (inst.funct3 & 0x3)
{
case 0: // DIV
{
if (b == 0)
{
hart->regs[inst.rd] = 0xFFFFFFFF;
}
else if (a == 0x80000000 && b == 0xFFFFFFFF)
{
hart->regs[inst.rd] = 0x80000000;
}
else
{
hart->regs[inst.rd] = (uint32_t)((int32_t)a / (int32_t)b);
}
break;
}
case 1: // DIVU
{
if (b == 0)
{
hart->regs[inst.rd] = 0xFFFFFFFF;
}
else
{
hart->regs[inst.rd] = a / b;
}
break;
}
case 2: // REM
{
if (b == 0)
{
hart->regs[inst.rd] = a;
}
else if (a == 0x80000000 && b == 0xFFFFFFFF)
{
hart->regs[inst.rd] = 0;
}
else
{
hart->regs[inst.rd] = (uint32_t)((int32_t)a % (int32_t)b);
}
break;
}
case 3: // REMU
{
if (b == 0)
{
hart->regs[inst.rd] = a;
}
else
{
hart->regs[inst.rd] = a % b;
}
break;
}
}
}
}
else