Added basic SBI support

master
vhaudiquet 11 months ago
parent 31941c0813
commit d7e684ad91
  1. 2
      src/cpu/instruction.h
  2. 3
      src/cpu/rv32cpu.c
  3. 27
      src/devices/sbi/sbi.c
  4. 11
      src/devices/sbi/sbi.h
  5. 2
      src/main.c

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

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

@ -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;
}
}
}

@ -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

@ -52,7 +52,7 @@ int main(int argc, char** argv)
pthread_mutex_unlock(&cpu0_mutex); 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; return cpu0->regs.a0;
} }

Loading…
Cancel
Save