提交 1d6ed6cc 编写于 作者: Y Yinan Xu

ram: support simulating larger RAM by using mmap

上级 6be8443d
...@@ -125,9 +125,8 @@ Emulator::Emulator(int argc, const char *argv[]): ...@@ -125,9 +125,8 @@ Emulator::Emulator(int argc, const char *argv[]):
} }
Emulator::~Emulator() { Emulator::~Emulator() {
#ifdef WITH_DRAMSIM3 ram_finish();
dramsim3_finish();
#endif
#ifdef VM_SAVABLE #ifdef VM_SAVABLE
snapshot_slot[0].save(); snapshot_slot[0].save();
snapshot_slot[1].save(); snapshot_slot[1].save();
......
#include <sys/mman.h>
#include <zlib.h>
#include "common.h" #include "common.h"
#include "ram.h" #include "ram.h"
#include <zlib.h> #define RAMSIZE (256 * 1024 * 1024UL)
#define RAMSIZE (256 * 1024 * 1024)
#ifdef WITH_DRAMSIM3 #ifdef WITH_DRAMSIM3
#include "cosimulation.h" #include "cosimulation.h"
CoDRAMsim3 *dram = NULL; CoDRAMsim3 *dram = NULL;
#endif #endif
static uint64_t ram[RAMSIZE / sizeof(uint64_t)]; static uint64_t *ram;
static long img_size = 0; static long img_size = 0;
void* get_img_start() { return &ram[0]; } void* get_img_start() { return &ram[0]; }
long get_img_size() { return img_size; } long get_img_size() { return img_size; }
void* get_ram_start() { return &ram[0]; } void* get_ram_start() { return &ram[0]; }
long get_ram_size() { return RAMSIZE; } long get_ram_size() { return RAMSIZE; }
#ifdef TLB_UNITTEST
void addpageSv39() { void addpageSv39() {
//three layers //three layers
//addr range: 0x0000000080000000 - 0x0000000088000000 for 128MB from 2GB - 2GB128MB //addr range: 0x0000000080000000 - 0x0000000088000000 for 128MB from 2GB - 2GB128MB
...@@ -99,6 +101,7 @@ void addpageSv39() { ...@@ -99,6 +101,7 @@ void addpageSv39() {
memcpy((char *)ram+(RAMSIZE-PAGESIZE*(PTENUM+PDENUM)), pde, PAGESIZE*PDENUM); memcpy((char *)ram+(RAMSIZE-PAGESIZE*(PTENUM+PDENUM)), pde, PAGESIZE*PDENUM);
memcpy((char *)ram+(RAMSIZE-PAGESIZE*PTENUM), pte, PAGESIZE*PTENUM); memcpy((char *)ram+(RAMSIZE-PAGESIZE*PTENUM), pte, PAGESIZE*PTENUM);
} }
#endif
// Return whether the file is a gz file // Return whether the file is a gz file
int isGzFile(const char *img) { int isGzFile(const char *img) {
...@@ -153,9 +156,17 @@ void init_ram(const char *img) { ...@@ -153,9 +156,17 @@ void init_ram(const char *img) {
printf("The image is %s\n", img); printf("The image is %s\n", img);
// initialize memory using Linux mmap
printf("Using simulated %luMB RAM\n", RAMSIZE / (1024 * 1024));
ram = (uint64_t *)mmap(NULL, RAMSIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (ram == (uint64_t *)MAP_FAILED) {
printf("Cound not mmap 0x%lx bytes\n", RAMSIZE);
assert(0);
}
int ret; int ret;
if (isGzFile(img)) { if (isGzFile(img)) {
printf("Gzip file detected. Loading image from extracted gz file.\n"); printf("Gzip file detected and loading image from extracted gz file\n");
img_size = readFromGz(ram, img); img_size = readFromGz(ram, img);
assert(img_size >= 0); assert(img_size >= 0);
} }
...@@ -179,9 +190,11 @@ void init_ram(const char *img) { ...@@ -179,9 +190,11 @@ void init_ram(const char *img) {
fclose(fp); fclose(fp);
} }
#ifdef TLB_UNITTEST
//new add //new add
addpageSv39(); addpageSv39();
//new end //new end
#endif
#ifdef WITH_DRAMSIM3 #ifdef WITH_DRAMSIM3
#if !defined(DRAMSIM3_CONFIG) || !defined(DRAMSIM3_OUTDIR) #if !defined(DRAMSIM3_CONFIG) || !defined(DRAMSIM3_OUTDIR)
...@@ -193,6 +206,13 @@ void init_ram(const char *img) { ...@@ -193,6 +206,13 @@ void init_ram(const char *img) {
} }
void ram_finish() {
munmap(ram, RAMSIZE);
#ifdef WITH_DRAMSIM3
dramsim3_finish();
#endif
}
extern "C" uint64_t ram_read_helper(uint8_t en, uint64_t rIdx) { extern "C" uint64_t ram_read_helper(uint8_t en, uint64_t rIdx) {
if (en && rIdx >= RAMSIZE / sizeof(uint64_t)) { if (en && rIdx >= RAMSIZE / sizeof(uint64_t)) {
printf("ERROR: ram idx = 0x%lx out of bound!\n", rIdx); printf("ERROR: ram idx = 0x%lx out of bound!\n", rIdx);
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
#include "common.h" #include "common.h"
// #define WITH_DRAMSIM3
void init_ram(const char *img); void init_ram(const char *img);
void ram_finish();
#ifdef WITH_DRAMSIM3 #ifdef WITH_DRAMSIM3
// 4*64 bits // 4*64 bits
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册