|
|
|
@ -616,7 +616,10 @@ static void cpu_print_instruction(instruction_t* instruction) |
|
|
|
|
// Jump And Link Register
|
|
|
|
|
// Sign extend immediate from 12 bits to 32 bits
|
|
|
|
|
uint32_t immediate = (instruction->immediate & 0xFFF) | (instruction->immediate & 0x800 ? 0xFFFFF000 : 0); |
|
|
|
|
printf("jalr x%u, x%u, 0x%x\n", instruction->rd, instruction->rs1, immediate); |
|
|
|
|
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); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case OPCODE_BRANCH: |
|
|
|
@ -666,23 +669,23 @@ static void cpu_print_instruction(instruction_t* instruction) |
|
|
|
|
switch(instruction->func3) |
|
|
|
|
{ |
|
|
|
|
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; |
|
|
|
|
case FUNC3_LH: |
|
|
|
|
// 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; |
|
|
|
|
case FUNC3_LW: |
|
|
|
|
// 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; |
|
|
|
|
case FUNC3_LBU: |
|
|
|
|
// 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; |
|
|
|
|
case FUNC3_LHU: |
|
|
|
|
// 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; |
|
|
|
|
default: |
|
|
|
|
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: |
|
|
|
|
// 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; |
|
|
|
|
case FUNC3_SH: |
|
|
|
|
// 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; |
|
|
|
|
case FUNC3_SW: |
|
|
|
|
// 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; |
|
|
|
|
default: |
|
|
|
|
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: |
|
|
|
|
// 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; |
|
|
|
|
case FUNC3_SLTI: |
|
|
|
|
// Set Less Than Immediate
|
|
|
|
|