Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenXiangShan
XiangShan
提交
a8359f39
X
XiangShan
项目概览
OpenXiangShan
/
XiangShan
12 个月 前同步成功
通知
1183
Star
3914
Fork
526
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
XiangShan
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a8359f39
编写于
11月 26, 2020
作者:
Y
Yinan Xu
提交者:
GitHub
11月 26, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #278 from RISCVERS/ram-gz
Read image from .gz file
上级
9e1063e7
2e4b12ad
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
76 addition
and
15 deletion
+76
-15
Makefile
Makefile
+1
-1
src/test/csrc/ram.cpp
src/test/csrc/ram.cpp
+75
-14
未找到文件。
Makefile
浏览文件 @
a8359f39
...
@@ -66,7 +66,7 @@ EMU_VFILES = $(shell find $(EMU_VSRC_DIR) -name "*.v" -or -name "*.sv")
...
@@ -66,7 +66,7 @@ EMU_VFILES = $(shell find $(EMU_VSRC_DIR) -name "*.v" -or -name "*.sv")
EMU_CXXFLAGS
+=
-std
=
c++11
-static
-Wall
-I
$(EMU_CSRC_DIR)
EMU_CXXFLAGS
+=
-std
=
c++11
-static
-Wall
-I
$(EMU_CSRC_DIR)
EMU_CXXFLAGS
+=
-DVERILATOR
-Wno-maybe-uninitialized
EMU_CXXFLAGS
+=
-DVERILATOR
-Wno-maybe-uninitialized
EMU_LDFLAGS
+=
-lpthread
-lSDL2
-ldl
EMU_LDFLAGS
+=
-lpthread
-lSDL2
-ldl
-lz
VEXTRA_FLAGS
=
-I
$(
abspath
$(BUILD_DIR)
)
--x-assign
unique
-O3
-CFLAGS
"
$(EMU_CXXFLAGS)
"
-LDFLAGS
"
$(EMU_LDFLAGS)
"
VEXTRA_FLAGS
=
-I
$(
abspath
$(BUILD_DIR)
)
--x-assign
unique
-O3
-CFLAGS
"
$(EMU_CXXFLAGS)
"
-LDFLAGS
"
$(EMU_LDFLAGS)
"
...
...
src/test/csrc/ram.cpp
浏览文件 @
a8359f39
#include "common.h"
#include "common.h"
#include "ram.h"
#include "ram.h"
#define RAMSIZE (128 * 1024 * 1024)
#include <zlib.h>
#define RAMSIZE (256 * 1024 * 1024)
#ifdef WITH_DRAMSIM3
#ifdef WITH_DRAMSIM3
#include "cosimulation.h"
#include "cosimulation.h"
...
@@ -98,26 +100,85 @@ void addpageSv39() {
...
@@ -98,26 +100,85 @@ void addpageSv39() {
memcpy
((
char
*
)
ram
+
(
RAMSIZE
-
PAGESIZE
*
PTENUM
),
pte
,
PAGESIZE
*
PTENUM
);
memcpy
((
char
*
)
ram
+
(
RAMSIZE
-
PAGESIZE
*
PTENUM
),
pte
,
PAGESIZE
*
PTENUM
);
}
}
// Return whether the file is a gz file
int
isGzFile
(
const
char
*
img
)
{
assert
(
img
!=
NULL
&&
strlen
(
img
)
>=
4
);
return
!
strcmp
(
img
+
(
strlen
(
img
)
-
3
),
".gz"
);
}
// Read binary from .gz file
int
readFromGz
(
void
*
ptr
,
const
char
*
file_name
)
{
gzFile
compressed_mem
=
gzopen
(
file_name
,
"rb"
);
if
(
compressed_mem
==
NULL
)
{
printf
(
"Can't open compressed binary file '%s'"
,
file_name
);
return
-
1
;
}
uint64_t
curr_size
=
0
;
const
uint32_t
chunk_size
=
16384
;
long
*
temp_page
=
new
long
[
chunk_size
];
long
*
pmem_current
=
(
long
*
)
ptr
;
while
(
curr_size
<
RAMSIZE
)
{
uint32_t
bytes_read
=
gzread
(
compressed_mem
,
temp_page
,
chunk_size
);
if
(
bytes_read
==
0
)
{
break
;
}
assert
(
bytes_read
%
sizeof
(
long
)
==
0
);
for
(
uint32_t
x
=
0
;
x
<
bytes_read
/
sizeof
(
long
);
x
++
)
{
if
(
*
(
temp_page
+
x
)
!=
0
)
{
pmem_current
=
(
long
*
)((
uint8_t
*
)
ptr
+
curr_size
+
x
*
sizeof
(
long
));
*
pmem_current
=
*
(
temp_page
+
x
);
}
}
curr_size
+=
bytes_read
;
}
printf
(
"Read %lu bytes from gz stream in total"
,
curr_size
);
delete
[]
temp_page
;
if
(
gzclose
(
compressed_mem
))
{
printf
(
"Error closing '%s'
\n
"
,
file_name
);
return
-
1
;
}
return
curr_size
;
}
void
init_ram
(
const
char
*
img
)
{
void
init_ram
(
const
char
*
img
)
{
assert
(
img
!=
NULL
);
assert
(
img
!=
NULL
);
FILE
*
fp
=
fopen
(
img
,
"rb"
);
if
(
fp
==
NULL
)
{
printf
(
"Can not open '%s'
\n
"
,
img
);
assert
(
0
);
}
printf
(
"The image is %s
\n
"
,
img
);
printf
(
"The image is %s
\n
"
,
img
);
fseek
(
fp
,
0
,
SEEK_END
);
int
ret
;
img_size
=
ftell
(
fp
);
if
(
isGzFile
(
img
))
{
if
(
img_size
>
RAMSIZE
)
{
printf
(
"Read from gz file
\n
"
);
img_size
=
RAMSIZE
;
img_size
=
readFromGz
(
ram
,
img
);
if
(
img_size
>
RAMSIZE
)
{
img_size
=
RAMSIZE
;
}
assert
(
img_size
>=
0
);
}
}
else
{
printf
(
"Read from bin file
\n
"
);
fseek
(
fp
,
0
,
SEEK_SET
);
FILE
*
fp
=
fopen
(
img
,
"rb"
);
int
ret
=
fread
(
ram
,
img_size
,
1
,
fp
);
if
(
fp
==
NULL
)
{
assert
(
ret
==
1
);
printf
(
"Can not open '%s'
\n
"
,
img
);
fclose
(
fp
);
assert
(
0
);
}
fseek
(
fp
,
0
,
SEEK_END
);
img_size
=
ftell
(
fp
);
if
(
img_size
>
RAMSIZE
)
{
img_size
=
RAMSIZE
;
}
fseek
(
fp
,
0
,
SEEK_SET
);
ret
=
fread
(
ram
,
img_size
,
1
,
fp
);
assert
(
ret
==
1
);
fclose
(
fp
);
}
//new add
//new add
addpageSv39
();
addpageSv39
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录