Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
饶先宏
hdl4se
提交
37264416
H
hdl4se
项目概览
饶先宏
/
hdl4se
通知
12
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hdl4se
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
37264416
编写于
8月 28, 2021
作者:
饶先宏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
202108280727
上级
c4750924
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
20 deletion
+59
-20
examples/hdl4se_riscv/hdl4se_riscv_sim/hdl4se_riscv_core_v2.c
...ples/hdl4se_riscv/hdl4se_riscv_sim/hdl4se_riscv_core_v2.c
+58
-20
examples/hdl4se_riscv/verilog/riscv_core.v
examples/hdl4se_riscv/verilog/riscv_core.v
+1
-0
未找到文件。
examples/hdl4se_riscv/hdl4se_riscv_sim/hdl4se_riscv_core_v2.c
浏览文件 @
37264416
...
...
@@ -70,16 +70,18 @@ IDLIST
VID
(
pc
),
VID
(
instr
),
VID
(
rs1
),
VID
(
imm
),
VID
(
rs2
),
VID
(
write
),
VID
(
writeaddr
),
VID
(
writedata
),
VID
(
writemask
),
VID
(
readreg
),
VID
(
state
),
VID
(
imm
),
VID
(
dstreg
),
VID
(
dstvalue
),
VID
(
ldaddr
),
VID
(
divclk
),
END_IDLIST
enum
riscv_core_state
{
...
...
@@ -88,10 +90,12 @@ enum riscv_core_state {
RISCVSTATE_READ_INST
,
RISCVSTATE_READ_RS1
,
RISCVSTATE_READ_RS2
,
RISCVSTATE_STORE_RS2
,
RISCVSTATE_WRITE_RD
,
RISCVSTATE_EXEC_INST
,
RISCVSTATE_WAIT_LD
,
RISCVSTATE_WAIT_ST
,
RISCVSTATE_WAIT_DIV
};
MODULE_DECLARE
(
riscv_core
)
...
...
@@ -115,7 +119,7 @@ DEFINE_FUNC(riscv_core_wr_sig, "write, writeaddr, writedata, writemask") {
VAssign
(
bWriteMask
,
writemask
);
}
END_DEFINE_FUNC
DEFINE_FUNC
(
riscv_core_read_sig
,
"state, pc, i
nstr, bReadData
, rs1"
)
{
DEFINE_FUNC
(
riscv_core_read_sig
,
"state, pc, i
mm, instr
, rs1"
)
{
unsigned
int
state
;
state
=
vget
(
state
);
vput
(
wRead
,
0
);
...
...
@@ -131,9 +135,8 @@ DEFINE_FUNC(riscv_core_read_sig, "state, pc, instr, bReadData, rs1") {
unsigned
int
imm
;
unsigned
int
rs1
;
unsigned
int
rdaddr
;
imm
=
instr
>>
20
;
rs1
=
vget
(
rs1
);
imm
=
sign_expand
(
imm
,
11
);
imm
=
vget
(
imm
);
rdaddr
=
rs1
+
imm
;
vput
(
wRead
,
1
);
vput
(
bReadAddr
,
rdaddr
);
...
...
@@ -141,7 +144,7 @@ DEFINE_FUNC(riscv_core_read_sig, "state, pc, instr, bReadData, rs1") {
}
}
END_DEFINE_FUNC
DEFINE_FUNC
(
riscv_core_gen_ldaddr
,
"state, pc, instr, rs1"
)
{
DEFINE_FUNC
(
riscv_core_gen_ldaddr
,
"state, pc, instr, rs1
, imm
"
)
{
unsigned
int
state
;
state
=
vget
(
state
);
if
(
state
==
RISCVSTATE_READ_INST
)
{
...
...
@@ -155,9 +158,8 @@ DEFINE_FUNC(riscv_core_gen_ldaddr, "state, pc, instr, rs1") {
unsigned
int
imm
;
unsigned
int
rs1
;
unsigned
int
rdaddr
;
imm
=
instr
>>
20
;
rs1
=
vget
(
rs1
);
imm
=
sign_expand
(
imm
,
11
);
imm
=
vget
(
imm
);
rdaddr
=
rs1
+
imm
;
vput
(
ldaddr
,
rdaddr
);
}
...
...
@@ -386,7 +388,7 @@ DEFINE_FUNC(riscv_core_exec_inst, "") {
unsigned
int
pc
=
vget
(
pc
);
unsigned
int
instr
=
vget
(
instr
);
unsigned
int
rs1
=
vget
(
rs1
);
unsigned
int
rs2
=
vget
(
regrddata
);
unsigned
int
rs2
=
vget
(
r
s2
);
//vget(r
egrddata);
unsigned
int
opcode
=
instr
&
0x7f
;
if
(
((
opcode
&
0x3
)
!=
3
)
||
(
(
opcode
>>
2
)
&
0x7
)
==
0x7
)
{
printf
(
"instruction format error, we support 32bit instruction only: pc=%08x: %x"
,
pc
,
instr
);
...
...
@@ -412,7 +414,7 @@ DEFINE_FUNC(riscv_core_exec_inst, "") {
}
}
END_DEFINE_FUNC
DEFINE_FUNC
(
riscv_core_gen_dstreg
,
"state, instr, ldaddr, readreg, bReadData, pc, rs1, r
egrddata
, imm"
)
{
DEFINE_FUNC
(
riscv_core_gen_dstreg
,
"state, instr, ldaddr, readreg, bReadData, pc, rs1, r
s2
, imm"
)
{
switch
(
vget
(
state
))
{
case
RISCVSTATE_INIT_REGX1
:
{
RISCV_SETDSTREG
(
1
,
0x8c
);
...
...
@@ -488,7 +490,7 @@ DEFINE_FUNC(riscv_core_gen_dstreg, "state, instr, ldaddr, readreg, bReadData, pc
unsigned
int
pc
=
vget
(
pc
);
unsigned
int
instr
=
vget
(
instr
);
unsigned
int
rs1
=
vget
(
rs1
);
unsigned
int
rs2
=
vget
(
r
egrddata
);
unsigned
int
rs2
=
vget
(
r
s2
);
unsigned
int
imm
=
vget
(
imm
);
unsigned
int
opcode
=
instr
&
0x7f
;
unsigned
int
rd
=
(
instr
>>
7
)
&
0x1f
;
...
...
@@ -498,13 +500,8 @@ DEFINE_FUNC(riscv_core_gen_dstreg, "state, instr, ldaddr, readreg, bReadData, pc
case
0x05
:
RISCV_SETDSTREG
(
rd
,
imm
+
pc
);
break
;
case
0x1b
:
RISCV_SETDSTREG
(
rd
,
pc
+
4
);
break
;
case
0x19
:
RISCV_SETDSTREG
(
rd
,
pc
+
4
);
break
;
case
0x18
:
RISCV_SETDSTREG
(
0
,
0
);
break
;
case
0x00
:
RISCV_SETDSTREG
(
0
,
0
);
break
;
case
0x08
:
RISCV_SETDSTREG
(
0
,
0
);
break
;
case
0x04
:
riscv_core_exec_alui_inst
(
pobj
,
pc
,
instr
,
rs1
,
rs2
);
break
;
case
0x0c
:
riscv_core_exec_alu_inst
(
pobj
,
pc
,
instr
,
rs1
,
rs2
);
break
;
case
0x03
:
RISCV_SETDSTREG
(
0
,
0
);
break
;
case
0x1c
:
RISCV_SETDSTREG
(
0
,
0
);
break
;
default:
{
RISCV_SETDSTREG
(
0
,
0
);
}
...
...
@@ -602,6 +599,9 @@ DEFINE_FUNC(riscv_core_gen_state, "state, instr, nwReset") {
vput
(
state
,
RISCVSTATE_READ_RS2
);
}
break
;
case
RISCVSTATE_READ_RS2
:
{
vput
(
state
,
RISCVSTATE_STORE_RS2
);
}
break
;
case
RISCVSTATE_STORE_RS2
:
{
vput
(
state
,
RISCVSTATE_EXEC_INST
);
}
break
;
case
RISCVSTATE_WRITE_RD
:
{
...
...
@@ -610,12 +610,17 @@ DEFINE_FUNC(riscv_core_gen_state, "state, instr, nwReset") {
case
RISCVSTATE_EXEC_INST
:
{
unsigned
int
instr
=
vget
(
instr
);
unsigned
int
opcode
=
instr
&
0x7f
;
unsigned
int
func3
=
(
instr
>>
12
)
&
0x7
;
opcode
>>=
2
;
if
(
opcode
==
0x00
)
vput
(
state
,
RISCVSTATE_WAIT_LD
);
//ld
else
if
(
opcode
==
0x08
)
else
if
(
opcode
==
0x08
)
vput
(
state
,
RISCVSTATE_WAIT_ST
);
//st
else
else
if
(
opcode
==
0x0c
&&
(
instr
&
(
1
<<
15
))
&&
(
func3
&
4
))
{
vput
(
state
,
RISCVSTATE_WAIT_DIV
);
//divclk <= 11;
}
else
vput
(
state
,
RISCVSTATE_WRITE_RD
);
}
break
;
case
RISCVSTATE_WAIT_LD
:
{
...
...
@@ -624,6 +629,10 @@ DEFINE_FUNC(riscv_core_gen_state, "state, instr, nwReset") {
case
RISCVSTATE_WAIT_ST
:
{
vput
(
state
,
RISCVSTATE_READ_INST
);
}
break
;
case
RISCVSTATE_WAIT_DIV
:
{
if
(
vget
(
divclk
)
==
0
)
vput
(
state
,
RISCVSTATE_WRITE_RD
);
}
break
;
}
}
}
END_DEFINE_FUNC
...
...
@@ -705,6 +714,13 @@ DEFINE_FUNC(riscv_core_reg_gen_rs1, "state, regrddata") {
}
}
END_DEFINE_FUNC
DEFINE_FUNC
(
riscv_core_reg_gen_rs2
,
"state, regrddata"
)
{
int
state
=
vget
(
state
);
if
(
state
==
RISCVSTATE_STORE_RS2
)
{
vput
(
rs2
,
vget
(
regrddata
));
}
}
END_DEFINE_FUNC
DEFINE_FUNC
(
riscv_core_reg_gen_readreg
,
"state, instr"
)
{
int
state
=
vget
(
state
);
if
(
state
==
RISCVSTATE_EXEC_INST
)
{
...
...
@@ -727,7 +743,26 @@ DEFINE_FUNC(riscv_core_reg_gen_instr, "state, bReadData") {
}
}
END_DEFINE_FUNC
DEFINE_FUNC
(
riscv_core_reg_gen_pc
,
"nwReset, state, instr, pc, rs1, imm, regrddata"
)
{
DEFINE_FUNC
(
riscv_core_reg_gen_divclk
,
"state, instr, divclk"
)
{
int
state
=
vget
(
state
);
if
(
state
==
RISCVSTATE_EXEC_INST
)
{
unsigned
int
instr
=
vget
(
instr
);
unsigned
int
opcode
=
instr
&
0x7f
;
unsigned
int
func3
=
(
instr
>>
12
)
&
0x7
;
opcode
>>=
2
;
if
(
opcode
==
0x0c
&&
(
instr
&
(
1
<<
15
))
&&
(
func3
&
4
))
{
vput
(
divclk
,
11
);
}
}
else
if
(
state
==
RISCVSTATE_WAIT_DIV
)
{
if
(
vget
(
divclk
)
!=
0
)
{
vput
(
divclk
,
vget
(
divclk
)
-
1
);
}
}
}
END_DEFINE_FUNC
DEFINE_FUNC
(
riscv_core_reg_gen_pc
,
"nwReset, state, instr, pc, rs1, rs2, imm"
)
{
if
(
vget
(
nwReset
)
==
0
)
{
vput
(
pc
,
0x74
);
}
...
...
@@ -746,7 +781,7 @@ DEFINE_FUNC(riscv_core_reg_gen_pc, "nwReset, state, instr, pc, rs1, imm, regrdda
case
0x19
:
vput
(
pc
,
rs1
+
imm
);
break
;
case
0x18
:
{
unsigned
int
func3
;
unsigned
int
rs2
=
vget
(
r
egrddata
);
unsigned
int
rs2
=
vget
(
r
s2
);
int
cond
;
func3
=
(
instr
>>
12
)
&
0x7
;
cond
=
0
;
...
...
@@ -790,6 +825,8 @@ DEFINE_FUNC(riscv_core_clktick, "") {
}
}
END_DEFINE_FUNC
MODULE_INIT
(
riscv_core
)
PORT_IN
(
wClk
,
1
);
PORT_IN
(
nwReset
,
1
);
...
...
@@ -808,6 +845,7 @@ MODULE_INIT(riscv_core)
GREG
(
pc
,
32
,
riscv_core_reg_gen_pc
);
GREG
(
instr
,
32
,
riscv_core_reg_gen_instr
);
GREG
(
rs1
,
32
,
riscv_core_reg_gen_rs1
);
GREG
(
rs2
,
32
,
riscv_core_reg_gen_rs2
);
GREG
(
write
,
1
,
riscv_core_gen_write
);
GREG
(
writeaddr
,
32
,
riscv_core_gen_write
);
GREG
(
writedata
,
32
,
riscv_core_gen_write
);
...
...
@@ -818,6 +856,6 @@ MODULE_INIT(riscv_core)
GREG
(
dstreg
,
5
,
riscv_core_gen_dstreg
);
GREG
(
dstvalue
,
32
,
riscv_core_gen_dstreg
);
GREG
(
ldaddr
,
2
,
riscv_core_gen_ldaddr
);
GREG
(
divclk
,
4
,
riscv_core_reg_gen_divclk
);
CLKTICK_FUNC
(
riscv_core_clktick
);
END_MODULE_INIT
(
riscv_core
)
examples/hdl4se_riscv/verilog/riscv_core.v
浏览文件 @
37264416
...
...
@@ -101,6 +101,7 @@ module riscv_core(
wire
[
71
:
0
]
mulsu_result
;
wire
[
31
:
0
]
div_result_r
,
mod_result_r
,
divs_result_r
,
mods_result_r
;
wire
[
31
:
0
]
div_result
,
mod_result
,
divs_result
,
mods_result
;
adder
add
(
rs1
,
rs2
,
add_result
);
suber
sub
(
rs1
,
rs2
,
sub_result
);
mult
mul
(
rs1
,
rs2
,
mul_result
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录