Better print :)
This commit is contained in:
parent
0adbd15225
commit
89744626a7
@ -616,6 +616,9 @@ static void cpu_print_instruction(instruction_t* instruction)
|
|||||||
// Jump And Link Register
|
// Jump And Link Register
|
||||||
// Sign extend immediate from 12 bits to 32 bits
|
// Sign extend immediate from 12 bits to 32 bits
|
||||||
uint32_t immediate = (instruction->immediate & 0xFFF) | (instruction->immediate & 0x800 ? 0xFFFFF000 : 0);
|
uint32_t immediate = (instruction->immediate & 0xFFF) | (instruction->immediate & 0x800 ? 0xFFFFF000 : 0);
|
||||||
|
if(immediate == 0x0 && instruction->rd == 0 && instruction->rs1 == 1)
|
||||||
|
printf("ret\n");
|
||||||
|
else
|
||||||
printf("jalr x%u, x%u, 0x%x\n", instruction->rd, instruction->rs1, immediate);
|
printf("jalr x%u, x%u, 0x%x\n", instruction->rd, instruction->rs1, immediate);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -666,23 +669,23 @@ static void cpu_print_instruction(instruction_t* instruction)
|
|||||||
switch(instruction->func3)
|
switch(instruction->func3)
|
||||||
{
|
{
|
||||||
case FUNC3_LB:
|
case FUNC3_LB:
|
||||||
printf("lb x%u, x%u, 0x%x\n", instruction->rd, instruction->rs1, immediate);
|
printf("lb x%u, %d(x%u)\n", instruction->rd, immediate, instruction->rs1);
|
||||||
break;
|
break;
|
||||||
case FUNC3_LH:
|
case FUNC3_LH:
|
||||||
// Load Halfword (16-bits)
|
// Load Halfword (16-bits)
|
||||||
printf("lh x%u, x%u, 0x%x\n", instruction->rd, instruction->rs1, immediate);
|
printf("lh x%u, %d(x%u)\n", instruction->rd, immediate, instruction->rs1);
|
||||||
break;
|
break;
|
||||||
case FUNC3_LW:
|
case FUNC3_LW:
|
||||||
// Load Word (32-bits)
|
// Load Word (32-bits)
|
||||||
printf("lw x%u, x%u, 0x%x\n", instruction->rd, instruction->rs1, immediate);
|
printf("lw x%u, %d(x%u)\n", instruction->rd, immediate, instruction->rs1);
|
||||||
break;
|
break;
|
||||||
case FUNC3_LBU:
|
case FUNC3_LBU:
|
||||||
// Load Byte Unsigned (8-bits)
|
// Load Byte Unsigned (8-bits)
|
||||||
printf("lbu x%u, x%u, 0x%x\n", instruction->rd, instruction->rs1, immediate);
|
printf("lbu x%u, %d(x%u)\n", instruction->rd, immediate, instruction->rs1);
|
||||||
break;
|
break;
|
||||||
case FUNC3_LHU:
|
case FUNC3_LHU:
|
||||||
// Load Halfword Unsigned (16-bits)
|
// Load Halfword Unsigned (16-bits)
|
||||||
printf("lhu x%u, x%u, 0x%x\n", instruction->rd, instruction->rs1, immediate);
|
printf("lhu x%u, %d(x%u)\n", instruction->rd, immediate, instruction->rs1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Warning: Unknown func3 0x%x for load instruction\n", instruction->func3);
|
fprintf(stderr, "Warning: Unknown func3 0x%x for load instruction\n", instruction->func3);
|
||||||
@ -700,15 +703,15 @@ static void cpu_print_instruction(instruction_t* instruction)
|
|||||||
{
|
{
|
||||||
case FUNC3_SB:
|
case FUNC3_SB:
|
||||||
// Store Byte (8-bits)
|
// Store Byte (8-bits)
|
||||||
printf("sb x%u, x%u, 0x%x\n", instruction->rs1, instruction->rs2, immediate);
|
printf("sb x%u, %d(x%u)\n", instruction->rs1, immediate, instruction->rs2);
|
||||||
break;
|
break;
|
||||||
case FUNC3_SH:
|
case FUNC3_SH:
|
||||||
// Store Halfword (16-bits)
|
// Store Halfword (16-bits)
|
||||||
printf("sh x%u, x%u, 0x%x\n", instruction->rs1, instruction->rs2, immediate);
|
printf("sh x%u, %d(x%u)\n", instruction->rs1, immediate, instruction->rs2);
|
||||||
break;
|
break;
|
||||||
case FUNC3_SW:
|
case FUNC3_SW:
|
||||||
// Store Word (32-bits)
|
// Store Word (32-bits)
|
||||||
printf("sw x%u, x%u, 0x%x\n", instruction->rs1, instruction->rs2, immediate);
|
printf("sw x%u, %d(x%u)\n", instruction->rs1, immediate, instruction->rs2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Warning: Unknown func3 0x%x for store instruction\n", instruction->func3);
|
fprintf(stderr, "Warning: Unknown func3 0x%x for store instruction\n", instruction->func3);
|
||||||
@ -728,7 +731,7 @@ static void cpu_print_instruction(instruction_t* instruction)
|
|||||||
{
|
{
|
||||||
case FUNC3_ADDI:
|
case FUNC3_ADDI:
|
||||||
// ADD Immediate
|
// ADD Immediate
|
||||||
printf("addi x%u, x%u, 0x%x\n", instruction->rd, instruction->rs1, immediate);
|
printf("addi x%u, x%u, %d\n", instruction->rd, instruction->rs1, immediate);
|
||||||
break;
|
break;
|
||||||
case FUNC3_SLTI:
|
case FUNC3_SLTI:
|
||||||
// Set Less Than Immediate
|
// Set Less Than Immediate
|
||||||
|
Loading…
x
Reference in New Issue
Block a user