Added basic SBI support

This commit is contained in:
vhaudiquet 2023-10-11 19:48:01 +02:00
parent 31941c0813
commit d7e684ad91
5 changed files with 43 additions and 2 deletions

View File

@ -97,6 +97,8 @@
#define IMM_ECALL 0x0
#define IMM_EBREAK 0x1
/* RISC-V Privileged Instructions */
#define IMM_SRET 0x102
#define IMM_MRET 0x302
#define FUNC7_SFENCEVMA 0x9
#define FUNC7_WFI 0x8
#define FUNC7_SINVALVMA 0x11

View File

@ -1,6 +1,7 @@
#include "rv32cpu.h"
#include "instruction.h"
#include "csr.h"
#include "devices/sbi/sbi.h"
#include "memory/memory.h"
#include "memory/mmu/mmu.h"
@ -510,7 +511,7 @@ static void cpu_execute(rv32_cpu_t* cpu, instruction_t* instruction)
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);
sbi_call(cpu, cpu->regs.a7, cpu->regs.a6);
break;
case IMM_EBREAK:
// EBREAK : on debug, give back hand to debugger ; without debug, end simulation

27
src/devices/sbi/sbi.c Normal file
View File

@ -0,0 +1,27 @@
#include "sbi.h"
#include <stdio.h>
void sbi_call(rv32_cpu_t* cpu, uint32_t extension_id, uint32_t func_id)
{
switch(extension_id)
{
case SBI_EXTENSION_LEGACY_CONSOLE_PUTCHAR:
{
printf("%c", cpu->regs.a0);
cpu->regs.a0 = 0;
break;
}
case SBI_EXTENSION_LEGACY_SHUTDOWN:
{
printf("sbi_call: shutdown, goodbye !\n");
cpu->sim_ticks_left = 1;
break;
}
default:
{
fprintf(stderr, "sbi_call: unknown extension id 0x%x\n", extension_id);
break;
}
}
}

11
src/devices/sbi/sbi.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef SBI_H
#define SBI_H
#include "cpu/rv32cpu.h"
#define SBI_EXTENSION_LEGACY_CONSOLE_PUTCHAR 0x1
#define SBI_EXTENSION_LEGACY_SHUTDOWN 0x8
void sbi_call(rv32_cpu_t* cpu, uint32_t extension_id, uint32_t func_id);
#endif

View File

@ -52,7 +52,7 @@ int main(int argc, char** argv)
pthread_mutex_unlock(&cpu0_mutex);
}
fprintf(stderr, "Simulation ended in a non-debug environment\n");
fprintf(stderr, "Simulation ended (in a non-debug environment)\n");
return cpu0->regs.a0;
}