Added MMU
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
#include "exception.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void exception_trigger(rv32_cpu_t* cpu, uint32_t scause)
|
||||
{
|
||||
// An exception can only be triggered by the CPU itself,
|
||||
// so we know we already own the mutex
|
||||
// We are in the CPU thread itself, but we need
|
||||
// the return of this function to be the beginning of
|
||||
// the cpu loop
|
||||
// To achieve that, we can just call cpu_loop (noreturn)
|
||||
// at the end of this function
|
||||
|
||||
// Save execution context, so that 'mret/sret/..' can restore it
|
||||
// TODO
|
||||
|
||||
// Set PC to STVEC, and set SCAUSE
|
||||
// TODO: If PC cannot be mmu_resolved, throw a 'double fault' ?
|
||||
cpu->pc = cpu->csr[CSR_STVEC];
|
||||
cpu->csr[CSR_SCAUSE] = scause;
|
||||
|
||||
pthread_mutex_unlock(&cpu0_mutex);
|
||||
cpu_loop(cpu);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef EXCEPTION_H
|
||||
#define EXCEPTION_H
|
||||
|
||||
#include "rv32cpu.h"
|
||||
|
||||
void exception_trigger(rv32_cpu_t* cpu, uint32_t scause);
|
||||
|
||||
#define SCAUSE_INSTRUCTION_MISSALIGNED 0x0
|
||||
#define SCAUSE_INSTRUCTION_ACCESS_FAULT 0x1
|
||||
#define SCAUSE_ILLEGAL_INSTRUCTION 0x2
|
||||
#define SCAUSE_BREAKPOINT 0x3
|
||||
#define SCAUSE_LOAD_ACCESS_FAULT 0x5
|
||||
#define SCAUSE_AMO_ADDRESS_MISALIGNED 0x6
|
||||
#define SCAUSE_ENVIRONMENT_CALL 0x8
|
||||
#define SCAUSE_INSTRUCTION_PAGE_FAULT 0xC
|
||||
#define SCAUSE_LOAD_PAGE_FAULT 0xD
|
||||
#define SCAUSE_STORE_AMO_PAGE_FAULT 0xF
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -531,7 +531,7 @@ static void cpu_execute(rv32_cpu_t* cpu, instruction_t* instruction)
|
||||
switch(instruction->func7)
|
||||
{
|
||||
case FUNC7_SFENCEVMA:
|
||||
fprintf(stderr, "SFENCE.VMA: Guest kernel must think we have an MMU. We have none.\n");
|
||||
// TODO : Check if we really need to do something on SFENCE.VMA ?
|
||||
break;
|
||||
case FUNC7_WFI:
|
||||
fprintf(stderr, "WFI: Guest kernel must think we have interrupts. We have none. Halting simulation.\n");
|
||||
|
||||
Reference in New Issue
Block a user