|
|
@ -417,19 +417,47 @@ static void cpu_execute(rv32_cpu_t* cpu, instruction_t* instruction) |
|
|
|
} |
|
|
|
} |
|
|
|
case OPCODE_SYSTEM: |
|
|
|
case OPCODE_SYSTEM: |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch(instruction->immediate) |
|
|
|
switch(instruction->func3) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case IMM_ECALL: |
|
|
|
case FUNC3_ECALL_EBREAK: |
|
|
|
fprintf(stderr, "ECALL: a7(sbi ext id) = %d, a6(sbi funct id) = %d\n", cpu->regs.a7, cpu->regs.a6); |
|
|
|
switch(instruction->immediate) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case IMM_ECALL: |
|
|
|
|
|
|
|
fprintf(stderr, "ECALL: a7(sbi ext id) = %d, a6(sbi funct id) = %d\n", cpu->regs.a7, cpu->regs.a6); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case IMM_EBREAK: |
|
|
|
|
|
|
|
fprintf(stderr, "EBREAK\n"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
fprintf(stderr, "FATAL: Unknown IMM for ECALL/EBREAK instruction while executing (IMM=0x%x)\n", instruction->immediate); |
|
|
|
|
|
|
|
exit(EXIT_FAILURE); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRW: |
|
|
|
|
|
|
|
fprintf(stderr, "CSRRW\n"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRS: |
|
|
|
|
|
|
|
fprintf(stderr, "CSRRS\n"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRC: |
|
|
|
|
|
|
|
fprintf(stderr, "CSRRC\n"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRWI: |
|
|
|
|
|
|
|
fprintf(stderr, "CSRRWI\n"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRSI: |
|
|
|
|
|
|
|
fprintf(stderr, "CSRRSI\n"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case IMM_EBREAK: |
|
|
|
case FUNC3_CSRRCI: |
|
|
|
fprintf(stderr, "EBREAK\n"); |
|
|
|
fprintf(stderr, "CSRRCI\n"); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
fprintf(stderr, "FATAL: Unknown SYSTEM instruction while executing (IMM=0x%x)\n", instruction->immediate); |
|
|
|
fprintf(stderr, "FATAL: Unknown func3 0x%x for SYSTEM instruction while executing\n", instruction->func3); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
@ -456,6 +484,7 @@ void cpu_loop(rv32_cpu_t* cpu) |
|
|
|
instruction_t instruction; |
|
|
|
instruction_t instruction; |
|
|
|
cpu_decode(raw_instruction, &instruction); |
|
|
|
cpu_decode(raw_instruction, &instruction); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("0x%x: ", cpu->pc); |
|
|
|
cpu_print_instruction(&instruction); |
|
|
|
cpu_print_instruction(&instruction); |
|
|
|
|
|
|
|
|
|
|
|
// Execute
|
|
|
|
// Execute
|
|
|
@ -730,16 +759,42 @@ static void cpu_print_instruction(instruction_t* instruction) |
|
|
|
} |
|
|
|
} |
|
|
|
case OPCODE_SYSTEM: |
|
|
|
case OPCODE_SYSTEM: |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch(instruction->immediate) |
|
|
|
switch(instruction->func3) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case IMM_ECALL: |
|
|
|
case FUNC3_ECALL_EBREAK: |
|
|
|
printf("ecall\n"); |
|
|
|
switch(instruction->immediate) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case IMM_ECALL: |
|
|
|
|
|
|
|
printf("ecall\n"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case IMM_EBREAK: |
|
|
|
|
|
|
|
printf("ebreak\n"); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
fprintf(stderr, "Warning: Unknown IMM for ECALL/EBREAK instruction (IMM=0x%x)\n", instruction->immediate); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRW: |
|
|
|
|
|
|
|
printf("csrrw csr[0x%x], x%u, x%u\n", instruction->immediate, instruction->rd, instruction->rs1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRS: |
|
|
|
|
|
|
|
printf("csrrs csr[0x%x], x%u, x%u\n", instruction->immediate, instruction->rd, instruction->rs1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRC: |
|
|
|
|
|
|
|
printf("csrrc csr[0x%x], x%u, x%u\n", instruction->immediate, instruction->rd, instruction->rs1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRWI: |
|
|
|
|
|
|
|
printf("csrrwi csr[0x%x], x%u, 0x%x\n", instruction->immediate, instruction->rd, instruction->rs1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case FUNC3_CSRRSI: |
|
|
|
|
|
|
|
printf("csrrsi csr[0x%x], x%u, 0x%x\n", instruction->immediate, instruction->rd, instruction->rs1); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case IMM_EBREAK: |
|
|
|
case FUNC3_CSRRCI: |
|
|
|
printf("ebreak\n"); |
|
|
|
printf("csrrci csr[0x%x], x%u, 0x%x\n", instruction->immediate, instruction->rd, instruction->rs1); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
fprintf(stderr, "Warning: Unknown SYSTEM instruction (IMM=0x%x)\n", instruction->immediate); |
|
|
|
fprintf(stderr, "Warning: Unknown func3 0x%x for SYSTEM instruction\n", instruction->func3); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|