Skip to content

Commit

Permalink
VirtualToPhysical32 is moved to Mmu class.
Browse files Browse the repository at this point in the history
  • Loading branch information
moizumi99 committed May 10, 2020
1 parent 5ac0384 commit 6378cff
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ add_executable(cpu_test
cpu_test.cc
RISCV_cpu.cc
RISCV_cpu.h
memory_wrapper.cpp memory_wrapper.h system_call_emulator.cpp system_call_emulator.h pte.cpp pte.h)
memory_wrapper.cpp memory_wrapper.h
system_call_emulator.cpp system_call_emulator.h
pte.cpp pte.h
Mmu.cpp Mmu.h
riscv_cpu_common.h)

add_executable(RISCV_Emulator
assembler.cc
Expand All @@ -47,13 +51,19 @@ add_executable(RISCV_Emulator
RISCV_cpu.h
RISCV_Emulator.cc
RISCV_Emulator.h
memory_wrapper.cpp memory_wrapper.h system_call_emulator.cpp system_call_emulator.h pte.cpp pte.h)
memory_wrapper.cpp
memory_wrapper.h
system_call_emulator.cpp
system_call_emulator.h
pte.cpp pte.h
Mmu.cpp Mmu.h
riscv_cpu_common.h)

add_executable(memory_wrapper_test
memory_wrapper.cpp
memory_wrapper.h
memory_wrapper_test.cpp
)
)

add_executable(pte_test
pte.cpp
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
CXX = g++
CPPFLAGS = -Wall -g
TARGET = RISCV_Emulator
CPU_OBJS = RISCV_cpu.o load_assembler.o assembler.o bit_tools.o instruction_encdec.o memory_wrapper.o system_call_emulator.o pte.o
CPU_OBJS = RISCV_cpu.o load_assembler.o assembler.o bit_tools.o \
instruction_encdec.o memory_wrapper.o system_call_emulator.o pte.o Mmu.o
OBJS = RISCV_Emulator.o $(CPU_OBJS)
TEST_TARGETS = cpu_test pte_test
WRAPPER_TESTS = memory_wrapper_test load_assembler_test
Expand Down
10 changes: 9 additions & 1 deletion RISCV_cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "memory_wrapper.h"
#include "system_call_emulator.h"
#include "pte.h"
#include "Mmu.h"
#include <iostream>
#include <tuple>
#include <stdint.h>
Expand Down Expand Up @@ -45,7 +46,14 @@ RiscvCpu::VirtualToPhysical(uint64_t virtual_address, bool write_access) {
return virtual_address;
}
if (xlen_ == 32) {
return VirtualToPhysical32(virtual_address, write_access);
Mmu mmu;
mmu.memory_ = memory_;
mmu.page_fault_ = page_fault_;
mmu.faulting_address_ = faulting_address_;
uint64_t physical_address = VirtualToPhysical32(virtual_address, write_access);
page_fault_ = page_fault_;
faulting_address_ = faulting_address_;
return physical_address;
} else {
// if (xlen == 64) {
return VirtualToPhysical64(virtual_address, write_access);
Expand Down
8 changes: 1 addition & 7 deletions RISCV_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
#include <utility>
#include <vector>
#include <memory>
#include "riscv_cpu_common.h"
#include "bit_tools.h"
#include "memory_wrapper.h"

enum class PrivilegeMode {
USER_MODE = 0,
SUPERVISOR_MODE = 1,
MACHINE_MODE = 3
};


class RiscvCpu {
static constexpr int kCsrSize = 4096;
static constexpr int kRegSize = 32;
Expand Down
8 changes: 8 additions & 0 deletions RiscvCpuCommon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Created by moiz on 5/10/20.
//

#ifndef ASSEMBLER_TEST_RISCVCPUCOMMON_H
#define ASSEMBLER_TEST_RISCVCPUCOMMON_H

#endif //ASSEMBLER_TEST_RISCVCPUCOMMON_H
14 changes: 14 additions & 0 deletions riscv_cpu_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Created by moiz on 5/10/20.
//

#ifndef RISCV_CPU_RISCV_CPU_COMMON_H
#define RISCV_CPU_RISCV_CPU_COMMON_H

enum class PrivilegeMode {
USER_MODE = 0,
SUPERVISOR_MODE = 1,
MACHINE_MODE = 3
};

#endif //RISCV_CPU_RISCV_CPU_COMMON_H

0 comments on commit 6378cff

Please sign in to comment.