Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenXiangShan
NEMU
提交
de417dff
N
NEMU
项目概览
OpenXiangShan
/
NEMU
11 个月 前同步成功
通知
7
Star
171
Fork
67
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
NEMU
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
de417dff
编写于
9月 09, 2019
作者:
Z
Zihao Yu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'fix-ISA64' into 'rv64'
Fix isa64 See merge request projectn/nemu!3
上级
f5a90928
bfdb1e17
变更
33
隐藏空白更改
内联
并排
Showing
33 changed file
with
87 addition
and
211 deletion
+87
-211
Makefile
Makefile
+1
-1
include/common.h
include/common.h
+12
-9
include/cpu/decode.h
include/cpu/decode.h
+2
-11
include/device/map.h
include/device/map.h
+2
-2
include/memory/memory.h
include/memory/memory.h
+4
-16
include/monitor/diff-test.h
include/monitor/diff-test.h
+1
-6
include/monitor/expr.h
include/monitor/expr.h
+1
-1
include/monitor/watchpoint.h
include/monitor/watchpoint.h
+2
-2
include/rtl/rtl.h
include/rtl/rtl.h
+2
-12
src/cpu/inv.c
src/cpu/inv.c
+2
-9
src/cpu/relop.c
src/cpu/relop.c
+4
-4
src/device/io/map.c
src/device/io/map.c
+9
-15
src/isa/mips32/decode.c
src/isa/mips32/decode.c
+1
-1
src/isa/mips32/mmu.c
src/isa/mips32/mmu.c
+2
-2
src/isa/mips32/reg.c
src/isa/mips32/reg.c
+1
-1
src/isa/riscv32/decode.c
src/isa/riscv32/decode.c
+3
-3
src/isa/riscv32/mmu.c
src/isa/riscv32/mmu.c
+2
-2
src/isa/riscv32/reg.c
src/isa/riscv32/reg.c
+1
-1
src/isa/riscv64/decode.c
src/isa/riscv64/decode.c
+3
-3
src/isa/riscv64/exec/compute.c
src/isa/riscv64/exec/compute.c
+1
-9
src/isa/riscv64/exec/exec.c
src/isa/riscv64/exec/exec.c
+1
-1
src/isa/riscv64/exec/ldst.c
src/isa/riscv64/exec/ldst.c
+4
-10
src/isa/riscv64/mmu.c
src/isa/riscv64/mmu.c
+2
-12
src/isa/x86/decode/modrm.c
src/isa/x86/decode/modrm.c
+1
-1
src/isa/x86/mmu.c
src/isa/x86/mmu.c
+3
-3
src/isa/x86/reg.c
src/isa/x86/reg.c
+3
-3
src/memory/memory.c
src/memory/memory.c
+5
-29
src/monitor/cpu-exec.c
src/monitor/cpu-exec.c
+2
-13
src/monitor/debug/expr.c
src/monitor/debug/expr.c
+2
-2
src/monitor/debug/log.c
src/monitor/debug/log.c
+1
-6
src/monitor/debug/ui.c
src/monitor/debug/ui.c
+4
-13
src/monitor/debug/watchpoint.c
src/monitor/debug/watchpoint.c
+2
-3
src/monitor/diff-test/diff-test.c
src/monitor/diff-test/diff-test.c
+1
-5
未找到文件。
Makefile
浏览文件 @
de417dff
...
...
@@ -30,7 +30,7 @@ include Makefile.git
CC
=
gcc
LD
=
gcc
INCLUDES
=
$(
addprefix
-I
,
$(INC_DIR)
)
CFLAGS
+=
-O2
-MMD
-Wall
-Werror
-ggdb3
$(INCLUDES)
-D__ISA__
=
$(ISA)
-fomit-frame-pointer
CFLAGS
+=
-O2
-MMD
-Wall
-Werror
-ggdb3
$(INCLUDES)
-D__ISA__
=
$(ISA)
-
D__ISA_
$(ISA)
__
-
fomit-frame-pointer
QEMU_DIFF_PATH
=
$(NEMU_HOME)
/tools/qemu-diff
QEMU_SO
=
$(QEMU_DIFF_PATH)
/build/
$(ISA)
-qemu-so
...
...
include/common.h
浏览文件 @
de417dff
...
...
@@ -4,7 +4,9 @@
//#define DEBUG
//#define DIFF_TEST
#define ISA64
#ifdef __ISA_riscv64__
# define ISA64
#endif
#if _SHARE
// do not enable these features while building a reference design
...
...
@@ -22,17 +24,18 @@
typedef
uint8_t
bool
;
#ifdef ISA64
typedef
uint64_t
rtlreg_t
;
typedef
uint32_t
paddr_t
;
typedef
uint64_t
vaddr_t
;
typedef
uint64_t
word_t
;
typedef
int64_t
sword_t
;
#define FMT_WORD "0x%016lx"
#else
typedef
uint32_t
rtlreg_t
;
typedef
uint32_t
paddr_t
;
typedef
uint32_t
vaddr_t
;
typedef
uint32_t
word_t
;
typedef
int32_t
sword_t
;
#define FMT_WORD "0x%08x"
#endif
typedef
word_t
rtlreg_t
;
typedef
word_t
vaddr_t
;
typedef
uint32_t
paddr_t
;
typedef
uint16_t
ioaddr_t
;
#define false 0
...
...
include/cpu/decode.h
浏览文件 @
de417dff
...
...
@@ -12,21 +12,12 @@ enum { OP_TYPE_REG, OP_TYPE_MEM, OP_TYPE_IMM };
typedef
struct
{
uint32_t
type
;
int
width
;
#ifdef ISA64
union
{
uint64_t
reg
;
rtlreg_t
addr
;
uint64_t
imm
;
int64_t
simm
;
};
#else
union
{
uint32_t
reg
;
rtlreg_t
addr
;
uint32
_t
imm
;
int32
_t
simm
;
word
_t
imm
;
sword
_t
simm
;
};
#endif
rtlreg_t
val
;
char
str
[
OP_STR_SIZE
];
}
Operand
;
...
...
include/device/map.h
浏览文件 @
de417dff
...
...
@@ -34,7 +34,7 @@ static inline int find_mapid_by_addr(IOMap *maps, int size, paddr_t addr) {
void
add_pio_map
(
char
*
name
,
ioaddr_t
addr
,
uint8_t
*
space
,
int
len
,
io_callback_t
callback
);
void
add_mmio_map
(
char
*
name
,
paddr_t
addr
,
uint8_t
*
space
,
int
len
,
io_callback_t
callback
);
uint32
_t
map_read
(
paddr_t
addr
,
int
len
,
IOMap
*
map
);
void
map_write
(
paddr_t
addr
,
uint32
_t
data
,
int
len
,
IOMap
*
map
);
word
_t
map_read
(
paddr_t
addr
,
int
len
,
IOMap
*
map
);
void
map_write
(
paddr_t
addr
,
word
_t
data
,
int
len
,
IOMap
*
map
);
#endif
include/memory/memory.h
浏览文件 @
de417dff
...
...
@@ -15,26 +15,14 @@ extern uint8_t pmem[];
void
register_pmem
(
paddr_t
base
);
uint32_t
isa_vaddr_read
(
vaddr_t
,
int
);
void
isa_vaddr_write
(
vaddr_t
,
uint32_t
,
int
);
#ifdef ISA64
uint64_t
isa_vaddr_read64
(
vaddr_t
,
int
);
void
isa_vaddr_write64
(
vaddr_t
,
uint64_t
,
int
);
#endif
word_t
isa_vaddr_read
(
vaddr_t
,
int
);
void
isa_vaddr_write
(
vaddr_t
,
word_t
,
int
);
#define vaddr_read isa_vaddr_read
#define vaddr_write isa_vaddr_write
#ifdef ISA64
#define vaddr_read64 isa_vaddr_read64
#define vaddr_write64 isa_vaddr_write64
#endif
uint32_t
paddr_read
(
paddr_t
,
int
);
void
paddr_write
(
paddr_t
,
uint32_t
,
int
);
#ifdef ISA64
uint64_t
paddr_read64
(
paddr_t
,
int
);
void
paddr_write64
(
paddr_t
,
uint64_t
,
int
);
#endif
word_t
paddr_read
(
paddr_t
,
int
);
void
paddr_write
(
paddr_t
,
word_t
,
int
);
#define PAGE_SIZE 4096
#define PAGE_MASK (PAGE_SIZE - 1)
...
...
include/monitor/diff-test.h
浏览文件 @
de417dff
...
...
@@ -21,13 +21,8 @@ extern void (*ref_difftest_exec)(uint64_t n);
static
inline
bool
difftest_check_reg
(
const
char
*
name
,
vaddr_t
pc
,
rtlreg_t
ref
,
rtlreg_t
dut
)
{
if
(
ref
!=
dut
)
{
#ifdef ISA64
Log
(
"%s is different after executing instruction at pc = 0x%016lx, right = 0x%016lx, wrong = 0x%016lx"
,
Log
(
"%s is different after executing instruction at pc = "
FMT_WORD
", right = "
FMT_WORD
", wrong = "
FMT_WORD
,
name
,
pc
,
ref
,
dut
);
#else
Log
(
"%s is different after executing instruction at pc = 0x%08x, right = 0x%08x, wrong = 0x%08x"
,
name
,
pc
,
ref
,
dut
);
#endif
return
false
;
}
return
true
;
...
...
include/monitor/expr.h
浏览文件 @
de417dff
...
...
@@ -3,6 +3,6 @@
#include "common.h"
uint32
_t
expr
(
char
*
,
bool
*
);
word
_t
expr
(
char
*
,
bool
*
);
#endif
include/monitor/watchpoint.h
浏览文件 @
de417dff
...
...
@@ -10,8 +10,8 @@ typedef struct watchpoint {
/* TODO: Add more members if necessary */
char
*
expr
;
uint32
_t
new_val
;
uint32
_t
old_val
;
word
_t
new_val
;
word
_t
old_val
;
}
WP
;
int
set_watchpoint
(
char
*
e
);
...
...
include/rtl/rtl.h
浏览文件 @
de417dff
...
...
@@ -87,21 +87,11 @@ static inline void interpret_rtl_idiv64_r(rtlreg_t* dest,
}
static
inline
void
interpret_rtl_lm
(
rtlreg_t
*
dest
,
const
rtlreg_t
*
addr
,
int
len
)
{
#ifdef ISA64
if
(
len
==
8
)
*
dest
=
vaddr_read64
(
*
addr
,
len
);
else
#endif
*
dest
=
vaddr_read
(
*
addr
,
len
);
*
dest
=
vaddr_read
(
*
addr
,
len
);
}
static
inline
void
interpret_rtl_sm
(
const
rtlreg_t
*
addr
,
const
rtlreg_t
*
src1
,
int
len
)
{
#ifdef ISA64
if
(
len
==
8
)
vaddr_write64
(
*
addr
,
*
src1
,
len
);
else
#endif
vaddr_write
(
*
addr
,
*
src1
,
len
);
vaddr_write
(
*
addr
,
*
src1
,
len
);
}
static
inline
void
interpret_rtl_host_lm
(
rtlreg_t
*
dest
,
const
void
*
addr
,
int
len
)
{
...
...
src/cpu/inv.c
浏览文件 @
de417dff
...
...
@@ -3,17 +3,10 @@
void
display_inv_msg
(
vaddr_t
pc
)
{
extern
char
isa_logo
[];
#ifdef ISA64
printf
(
"There are two cases which will trigger this unexpected exception:
\n
"
"1. The instruction at PC =
0x%016lx
is not implemented.
\n
"
"1. The instruction at PC =
"
FMT_WORD
"
is not implemented.
\n
"
"2. Something is implemented incorrectly.
\n
"
,
pc
);
printf
(
"Find this PC(0x%016lx) in the disassembling result to distinguish which case it is.
\n\n
"
,
pc
);
#else
printf
(
"There are two cases which will trigger this unexpected exception:
\n
"
"1. The instruction at PC = 0x%08x is not implemented.
\n
"
"2. Something is implemented incorrectly.
\n
"
,
pc
);
printf
(
"Find this PC(0x%08x) in the disassembling result to distinguish which case it is.
\n\n
"
,
pc
);
#endif
printf
(
"Find this PC("
FMT_WORD
") in the disassembling result to distinguish which case it is.
\n\n
"
,
pc
);
printf
(
"
\33
[1;31mIf it is the first case, see
\n
%s
\n
for more details.
\n\n
If it is the second case, remember:
\n
"
"* The machine is always right!
\n
"
"* Every line of untested code is always wrong!
\33
[0m
\n\n
"
,
isa_logo
);
...
...
src/cpu/relop.c
浏览文件 @
de417dff
...
...
@@ -7,10 +7,10 @@ bool interpret_relop(uint32_t relop, const rtlreg_t src1, const rtlreg_t src2) {
case
RELOP_TRUE
:
return
true
;
case
RELOP_EQ
:
return
src1
==
src2
;
case
RELOP_NE
:
return
src1
!=
src2
;
case
RELOP_LT
:
return
(
int32_t
)
src1
<
(
int32
_t
)
src2
;
case
RELOP_LE
:
return
(
int32_t
)
src1
<=
(
int32
_t
)
src2
;
case
RELOP_GT
:
return
(
int32_t
)
src1
>
(
int32
_t
)
src2
;
case
RELOP_GE
:
return
(
int32_t
)
src1
>=
(
int32
_t
)
src2
;
case
RELOP_LT
:
return
(
sword_t
)
src1
<
(
sword
_t
)
src2
;
case
RELOP_LE
:
return
(
sword_t
)
src1
<=
(
sword
_t
)
src2
;
case
RELOP_GT
:
return
(
sword_t
)
src1
>
(
sword
_t
)
src2
;
case
RELOP_GE
:
return
(
sword_t
)
src1
>=
(
sword
_t
)
src2
;
case
RELOP_LTU
:
return
src1
<
src2
;
case
RELOP_LEU
:
return
src1
<=
src2
;
case
RELOP_GTU
:
return
src1
>
src2
;
...
...
src/device/io/map.c
浏览文件 @
de417dff
...
...
@@ -17,35 +17,29 @@ uint8_t* new_space(int size) {
}
static
inline
void
check_bound
(
IOMap
*
map
,
paddr_t
addr
)
{
#ifdef ISA64
Assert
(
map
!=
NULL
&&
addr
<=
map
->
high
&&
addr
>=
map
->
low
,
"address (0x%08x) is out of bound {%s} [0x%08x, 0x%08x] at pc =
0x%016lx"
,
"address (0x%08x) is out of bound {%s} [0x%08x, 0x%08x] at pc =
"
FMT_WORD
,
addr
,
(
map
?
map
->
name
:
"???"
),
(
map
?
map
->
low
:
0
),
(
map
?
map
->
high
:
0
),
cpu
.
pc
);
#else
Assert
(
map
!=
NULL
&&
addr
<=
map
->
high
&&
addr
>=
map
->
low
,
"address (0x%08x) is out of bound {%s} [0x%08x, 0x%08x] at pc = 0x%08x"
,
addr
,
(
map
?
map
->
name
:
"???"
),
(
map
?
map
->
low
:
0
),
(
map
?
map
->
high
:
0
),
cpu
.
pc
);
#endif
}
static
inline
void
invoke_callback
(
io_callback_t
c
,
uint32
_t
offset
,
int
len
,
bool
is_write
)
{
static
inline
void
invoke_callback
(
io_callback_t
c
,
paddr
_t
offset
,
int
len
,
bool
is_write
)
{
if
(
c
!=
NULL
)
{
c
(
offset
,
len
,
is_write
);
}
}
uint32
_t
map_read
(
paddr_t
addr
,
int
len
,
IOMap
*
map
)
{
assert
(
len
>=
1
&&
len
<=
4
);
word
_t
map_read
(
paddr_t
addr
,
int
len
,
IOMap
*
map
)
{
assert
(
len
>=
1
&&
len
<=
8
);
check_bound
(
map
,
addr
);
uint32
_t
offset
=
addr
-
map
->
low
;
paddr
_t
offset
=
addr
-
map
->
low
;
invoke_callback
(
map
->
callback
,
offset
,
len
,
false
);
// prepare data to read
uint32_t
data
=
*
(
uint32_t
*
)(
map
->
space
+
offset
)
&
(
~
0u
>>
((
4
-
len
)
<<
3
));
word_t
data
=
*
(
word_t
*
)(
map
->
space
+
offset
)
&
(
~
0u
>>
((
8
-
len
)
<<
3
));
return
data
;
}
void
map_write
(
paddr_t
addr
,
uint32
_t
data
,
int
len
,
IOMap
*
map
)
{
assert
(
len
>=
1
&&
len
<=
4
);
void
map_write
(
paddr_t
addr
,
word
_t
data
,
int
len
,
IOMap
*
map
)
{
assert
(
len
>=
1
&&
len
<=
8
);
check_bound
(
map
,
addr
);
uint32
_t
offset
=
addr
-
map
->
low
;
paddr
_t
offset
=
addr
-
map
->
low
;
memcpy
(
map
->
space
+
offset
,
&
data
,
len
);
...
...
src/isa/mips32/decode.c
浏览文件 @
de417dff
...
...
@@ -70,7 +70,7 @@ make_DHelper(st) {
}
make_DHelper
(
B
)
{
int32
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm
<<
2
);
sword
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm
<<
2
);
decinfo
.
jmp_pc
=
cpu
.
pc
+
offset
+
4
;
decinfo
.
seq_pc
+=
4
;
// skip the delay slot
...
...
src/isa/mips32/mmu.c
浏览文件 @
de417dff
...
...
@@ -107,10 +107,10 @@ static inline paddr_t va2pa(vaddr_t addr, bool write) {
return
addr
;
}
uint32
_t
isa_vaddr_read
(
vaddr_t
addr
,
int
len
)
{
word
_t
isa_vaddr_read
(
vaddr_t
addr
,
int
len
)
{
return
paddr_read
(
va2pa
(
addr
,
false
),
len
);
}
void
isa_vaddr_write
(
vaddr_t
addr
,
uint32
_t
data
,
int
len
)
{
void
isa_vaddr_write
(
vaddr_t
addr
,
word
_t
data
,
int
len
)
{
paddr_write
(
va2pa
(
addr
,
true
),
data
,
len
);
}
src/isa/mips32/reg.c
浏览文件 @
de417dff
...
...
@@ -18,7 +18,7 @@ void isa_reg_display() {
printf
(
"pc: 0x%08x
\n
"
,
cpu
.
pc
);
}
uint32
_t
isa_reg_str2val
(
const
char
*
s
,
bool
*
success
)
{
word
_t
isa_reg_str2val
(
const
char
*
s
,
bool
*
success
)
{
int
i
;
*
success
=
true
;
for
(
i
=
0
;
i
<
32
;
i
++
)
{
...
...
src/isa/riscv32/decode.c
浏览文件 @
de417dff
...
...
@@ -42,7 +42,7 @@ make_DHelper(U) {
}
make_DHelper
(
J
)
{
int32
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm20
<<
20
)
|
(
decinfo
.
isa
.
instr
.
imm19_12
<<
12
)
|
sword
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm20
<<
20
)
|
(
decinfo
.
isa
.
instr
.
imm19_12
<<
12
)
|
(
decinfo
.
isa
.
instr
.
imm11_
<<
11
)
|
(
decinfo
.
isa
.
instr
.
imm10_1
<<
1
);
decinfo
.
jmp_pc
=
cpu
.
pc
+
offset
;
decode_op_i
(
id_src
,
decinfo
.
jmp_pc
,
true
);
...
...
@@ -52,7 +52,7 @@ make_DHelper(J) {
}
make_DHelper
(
B
)
{
int32
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm12
<<
12
)
|
(
decinfo
.
isa
.
instr
.
imm11
<<
11
)
|
sword
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm12
<<
12
)
|
(
decinfo
.
isa
.
instr
.
imm11
<<
11
)
|
(
decinfo
.
isa
.
instr
.
imm10_5
<<
5
)
|
(
decinfo
.
isa
.
instr
.
imm4_1
<<
1
);
decinfo
.
jmp_pc
=
cpu
.
pc
+
offset
;
decode_op_i
(
id_dest
,
decinfo
.
jmp_pc
,
true
);
...
...
@@ -75,7 +75,7 @@ make_DHelper(ld) {
make_DHelper
(
st
)
{
decode_op_r
(
id_src
,
decinfo
.
isa
.
instr
.
rs1
,
true
);
int32
_t
simm
=
(
decinfo
.
isa
.
instr
.
simm11_5
<<
5
)
|
decinfo
.
isa
.
instr
.
imm4_0
;
sword
_t
simm
=
(
decinfo
.
isa
.
instr
.
simm11_5
<<
5
)
|
decinfo
.
isa
.
instr
.
imm4_0
;
decode_op_i
(
id_src2
,
simm
,
true
);
print_Dop
(
id_src
->
str
,
OP_STR_SIZE
,
"%d(%s)"
,
id_src2
->
val
,
reg_name
(
id_src
->
reg
,
4
));
...
...
src/isa/riscv32/mmu.c
浏览文件 @
de417dff
...
...
@@ -57,12 +57,12 @@ static inline paddr_t page_translate(vaddr_t addr, bool is_write) {
return
page_walk
(
addr
,
is_write
)
|
(
addr
&
PAGE_MASK
);
}
uint32
_t
isa_vaddr_read
(
vaddr_t
addr
,
int
len
)
{
word
_t
isa_vaddr_read
(
vaddr_t
addr
,
int
len
)
{
paddr_t
paddr
=
(
cpu
.
satp
.
mode
?
page_translate
(
addr
,
false
)
:
addr
);
return
paddr_read
(
paddr
,
len
);
}
void
isa_vaddr_write
(
vaddr_t
addr
,
uint32
_t
data
,
int
len
)
{
void
isa_vaddr_write
(
vaddr_t
addr
,
word
_t
data
,
int
len
)
{
paddr_t
paddr
=
(
cpu
.
satp
.
mode
?
page_translate
(
addr
,
true
)
:
addr
);
paddr_write
(
paddr
,
data
,
len
);
}
src/isa/riscv32/reg.c
浏览文件 @
de417dff
...
...
@@ -18,7 +18,7 @@ void isa_reg_display() {
printf
(
"pc: 0x%08x
\n
"
,
cpu
.
pc
);
}
uint32
_t
isa_reg_str2val
(
const
char
*
s
,
bool
*
success
)
{
word
_t
isa_reg_str2val
(
const
char
*
s
,
bool
*
success
)
{
int
i
;
*
success
=
true
;
for
(
i
=
0
;
i
<
32
;
i
++
)
{
...
...
src/isa/riscv64/decode.c
浏览文件 @
de417dff
...
...
@@ -42,7 +42,7 @@ make_DHelper(U) {
}
make_DHelper
(
J
)
{
int32
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm20
<<
20
)
|
(
decinfo
.
isa
.
instr
.
imm19_12
<<
12
)
|
sword
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm20
<<
20
)
|
(
decinfo
.
isa
.
instr
.
imm19_12
<<
12
)
|
(
decinfo
.
isa
.
instr
.
imm11_
<<
11
)
|
(
decinfo
.
isa
.
instr
.
imm10_1
<<
1
);
decinfo
.
jmp_pc
=
cpu
.
pc
+
offset
;
decode_op_i
(
id_src
,
decinfo
.
jmp_pc
,
true
);
...
...
@@ -52,7 +52,7 @@ make_DHelper(J) {
}
make_DHelper
(
B
)
{
int32
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm12
<<
12
)
|
(
decinfo
.
isa
.
instr
.
imm11
<<
11
)
|
sword
_t
offset
=
(
decinfo
.
isa
.
instr
.
simm12
<<
12
)
|
(
decinfo
.
isa
.
instr
.
imm11
<<
11
)
|
(
decinfo
.
isa
.
instr
.
imm10_5
<<
5
)
|
(
decinfo
.
isa
.
instr
.
imm4_1
<<
1
);
decinfo
.
jmp_pc
=
cpu
.
pc
+
offset
;
decode_op_i
(
id_dest
,
decinfo
.
jmp_pc
,
true
);
...
...
@@ -75,7 +75,7 @@ make_DHelper(ld) {
make_DHelper
(
st
)
{
decode_op_r
(
id_src
,
decinfo
.
isa
.
instr
.
rs1
,
true
);
int32
_t
simm
=
(
decinfo
.
isa
.
instr
.
simm11_5
<<
5
)
|
decinfo
.
isa
.
instr
.
imm4_0
;
sword
_t
simm
=
(
decinfo
.
isa
.
instr
.
simm11_5
<<
5
)
|
decinfo
.
isa
.
instr
.
imm4_0
;
decode_op_i
(
id_src2
,
simm
,
true
);
print_Dop
(
id_src
->
str
,
OP_STR_SIZE
,
"%ld(%s)"
,
id_src2
->
val
,
reg_name
(
id_src
->
reg
,
4
));
...
...
src/isa/riscv64/exec/compute.c
浏览文件 @
de417dff
...
...
@@ -15,11 +15,7 @@ make_EHelper(sub) {
}
make_EHelper
(
sll
)
{
#ifdef ISA64
rtl_andi
(
&
id_src2
->
val
,
&
id_src2
->
val
,
0x3f
);
#else
rtl_andi
(
&
id_src2
->
val
,
&
id_src2
->
val
,
0x1f
);
#endif
rtl_shl
(
&
s0
,
&
id_src
->
val
,
&
id_src2
->
val
);
rtl_sr
(
id_dest
->
reg
,
&
s0
,
4
);
...
...
@@ -27,11 +23,7 @@ make_EHelper(sll) {
}
make_EHelper
(
srl
)
{
#ifdef ISA64
rtl_andi
(
&
id_src2
->
val
,
&
id_src2
->
val
,
0x3f
);
#else
rtl_andi
(
&
id_src2
->
val
,
&
id_src2
->
val
,
0x1f
);
#endif
if
(
decinfo
.
isa
.
instr
.
funct7
==
32
)
{
// sra
...
...
@@ -145,4 +137,4 @@ make_EHelper(srlw) {
make_EHelper
(
sraw
)
{
exec_srlw
(
NULL
);
}
\ No newline at end of file
}
src/isa/riscv64/exec/exec.c
浏览文件 @
de417dff
...
...
@@ -2,7 +2,7 @@
#include "all-instr.h"
static
OpcodeEntry
load_table
[
8
]
=
{
EXW
(
lds
,
1
),
EXW
(
lds
,
2
),
EXW
(
ld
,
4
),
EXW
(
ld
,
8
),
EXW
(
ld
,
1
),
EXW
(
ld
,
2
),
EMPTY
,
EMPTY
EXW
(
lds
,
1
),
EXW
(
lds
,
2
),
EXW
(
ld
s
,
4
),
EXW
(
ld
,
8
),
EXW
(
ld
,
1
),
EXW
(
ld
,
2
),
EXW
(
ld
,
4
)
,
EMPTY
};
static
make_EHelper
(
load
)
{
...
...
src/isa/riscv64/exec/ldst.c
浏览文件 @
de417dff
...
...
@@ -2,18 +2,11 @@
make_EHelper
(
ld
)
{
rtl_lm
(
&
s0
,
&
id_src
->
addr
,
decinfo
.
width
);
#ifdef ISA64
if
(
decinfo
.
width
==
4
)
{
// for lw
rtl_sext
(
&
s0
,
&
s0
,
4
);
}
#endif
rtl_sr
(
id_dest
->
reg
,
&
s0
,
4
);
rtl_sr
(
id_dest
->
reg
,
&
s0
,
0
);
switch
(
decinfo
.
width
)
{
case
8
:
print_asm_template2
(
ld
);
break
;
case
4
:
print_asm_template2
(
lw
);
break
;
case
4
:
print_asm_template2
(
lw
u
);
break
;
case
2
:
print_asm_template2
(
lhu
);
break
;
case
1
:
print_asm_template2
(
lbu
);
break
;
default:
assert
(
0
);
...
...
@@ -24,9 +17,10 @@ make_EHelper(ld) {
make_EHelper
(
lds
)
{
rtl_lm
(
&
s0
,
&
id_src
->
addr
,
decinfo
.
width
);
rtl_sext
(
&
s0
,
&
s0
,
decinfo
.
width
);
rtl_sr
(
id_dest
->
reg
,
&
s0
,
4
);
rtl_sr
(
id_dest
->
reg
,
&
s0
,
0
);
switch
(
decinfo
.
width
)
{
case
4
:
print_asm_template2
(
lw
);
break
;
case
2
:
print_asm_template2
(
lh
);
break
;
case
1
:
print_asm_template2
(
lb
);
break
;
default:
assert
(
0
);
...
...
src/isa/riscv64/mmu.c
浏览文件 @
de417dff
...
...
@@ -58,22 +58,12 @@ static inline paddr_t page_translate(vaddr_t addr, bool is_write) {
return
page_walk
(
addr
,
is_write
)
|
(
addr
&
PAGE_MASK
);
}
uint32
_t
isa_vaddr_read
(
vaddr_t
addr
,
int
len
)
{
word
_t
isa_vaddr_read
(
vaddr_t
addr
,
int
len
)
{
paddr_t
paddr
=
(
cpu
.
satp
.
mode
?
page_translate
(
addr
,
false
)
:
addr
);
return
paddr_read
(
paddr
,
len
);
}
void
isa_vaddr_write
(
vaddr_t
addr
,
uint32
_t
data
,
int
len
)
{
void
isa_vaddr_write
(
vaddr_t
addr
,
word
_t
data
,
int
len
)
{
paddr_t
paddr
=
(
cpu
.
satp
.
mode
?
page_translate
(
addr
,
true
)
:
addr
);
paddr_write
(
paddr
,
data
,
len
);
}
uint64_t
isa_vaddr_read64
(
vaddr_t
addr
,
int
len
)
{
paddr_t
paddr
=
(
cpu
.
satp
.
mode
?
page_translate
(
addr
,
false
)
:
addr
);
return
paddr_read64
(
paddr
,
len
);
}
void
isa_vaddr_write64
(
vaddr_t
addr
,
uint64_t
data
,
int
len
)
{
paddr_t
paddr
=
(
cpu
.
satp
.
mode
?
page_translate
(
addr
,
true
)
:
addr
);
paddr_write64
(
paddr
,
data
,
len
);
}
\ No newline at end of file
src/isa/x86/decode/modrm.c
浏览文件 @
de417dff
...
...
@@ -3,7 +3,7 @@
void
load_addr
(
vaddr_t
*
pc
,
ModR_M
*
m
,
Operand
*
rm
)
{
assert
(
m
->
mod
!=
3
);
int32
_t
disp
=
0
;
sword
_t
disp
=
0
;
int
disp_size
=
4
;
int
base_reg
=
-
1
,
index_reg
=
-
1
,
scale
=
0
;
rtl_li
(
&
s0
,
0
);
...
...
src/isa/x86/mmu.c
浏览文件 @
de417dff
...
...
@@ -44,8 +44,8 @@ static inline paddr_t page_translate(vaddr_t addr, bool is_write) {
return
page_walk
(
addr
,
is_write
)
|
(
addr
&
PAGE_MASK
);
}
uint32
_t
isa_vaddr_read
(
vaddr_t
addr
,
int
len
)
{
uint32
_t
data
;
word
_t
isa_vaddr_read
(
vaddr_t
addr
,
int
len
)
{
word
_t
data
;
if
(
cpu
.
cr0
.
paging
)
{
paddr_t
paddr
=
page_translate
(
addr
,
false
);
uint32_t
remain_byte
=
PAGE_SIZE
-
(
addr
&
PAGE_MASK
);
...
...
@@ -67,7 +67,7 @@ uint32_t isa_vaddr_read(vaddr_t addr, int len) {
return
data
;
}
void
isa_vaddr_write
(
vaddr_t
addr
,
uint32
_t
data
,
int
len
)
{
void
isa_vaddr_write
(
vaddr_t
addr
,
word
_t
data
,
int
len
)
{
if
(
cpu
.
cr0
.
paging
)
{
paddr_t
paddr
=
page_translate
(
addr
,
true
);
uint32_t
remain_byte
=
PAGE_SIZE
-
(
addr
&
PAGE_MASK
);
...
...
src/isa/x86/reg.c
浏览文件 @
de417dff
...
...
@@ -8,8 +8,8 @@ const char *regsb[] = {"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh"};
void
reg_test
()
{
srand
(
time
(
0
));
uint32
_t
sample
[
8
];
uint32
_t
pc_sample
=
rand
();
word
_t
sample
[
8
];
word
_t
pc_sample
=
rand
();
cpu
.
pc
=
pc_sample
;
int
i
;
...
...
@@ -48,7 +48,7 @@ void isa_reg_display() {
printf
(
"pc: 0x%08x
\n
"
,
cpu
.
pc
);
}
uint32
_t
isa_reg_str2val
(
const
char
*
s
,
bool
*
success
)
{
word
_t
isa_reg_str2val
(
const
char
*
s
,
bool
*
success
)
{
int
i
;
*
success
=
true
;
for
(
i
=
0
;
i
<
8
;
i
++
)
{
...
...
src/memory/memory.c
浏览文件 @
de417dff
...
...
@@ -20,46 +20,22 @@ IOMap* fetch_mmio_map(paddr_t addr);
/* Memory accessing interfaces */
uint32
_t
paddr_read
(
paddr_t
addr
,
int
len
)
{
word
_t
paddr_read
(
paddr_t
addr
,
int
len
)
{
if
(
map_inside
(
&
pmem_map
,
addr
))
{
uint32
_t
offset
=
addr
-
pmem_map
.
low
;
return
*
(
uint
32_t
*
)(
pmem
+
offset
)
&
(
~
0u
>>
((
4
-
len
)
<<
3
));
paddr
_t
offset
=
addr
-
pmem_map
.
low
;
return
*
(
uint
64_t
*
)(
pmem
+
offset
)
&
(
~
0LLu
>>
((
8
-
len
)
<<
3
));
}
else
{
return
map_read
(
addr
,
len
,
fetch_mmio_map
(
addr
));
}
}
void
paddr_write
(
paddr_t
addr
,
uint32
_t
data
,
int
len
)
{
void
paddr_write
(
paddr_t
addr
,
word
_t
data
,
int
len
)
{
if
(
map_inside
(
&
pmem_map
,
addr
))
{
uint32
_t
offset
=
addr
-
pmem_map
.
low
;
paddr
_t
offset
=
addr
-
pmem_map
.
low
;
memcpy
(
pmem
+
offset
,
&
data
,
len
);
}
else
{
return
map_write
(
addr
,
data
,
len
,
fetch_mmio_map
(
addr
));
}
}
uint64_t
paddr_read64
(
paddr_t
addr
,
int
len
)
{
if
(
map_inside
(
&
pmem_map
,
addr
))
{
uint64_t
offset
=
addr
-
pmem_map
.
low
;
return
*
(
uint64_t
*
)(
pmem
+
offset
);
}
else
{
// TODO
printf
(
"TODO"
);
return
0
;
}
}
void
paddr_write64
(
paddr_t
addr
,
uint64_t
data
,
int
len
)
{
if
(
map_inside
(
&
pmem_map
,
addr
))
{
uint64_t
offset
=
addr
-
pmem_map
.
low
;
memcpy
(
pmem
+
offset
,
&
data
,
len
);
}
else
{
// TODO
printf
(
"TODO"
);
return
;
}
}
\ No newline at end of file
src/monitor/cpu-exec.c
浏览文件 @
de417dff
...
...
@@ -61,11 +61,7 @@ void cpu_exec(uint64_t n) {
/* TODO: check watchpoints here. */
WP
*
wp
=
scan_watchpoint
();
if
(
wp
!=
NULL
)
{
#ifdef ISA64
printf
(
"
\n\n
Hint watchpoint %d at address 0x%016lx, expr = %s
\n
"
,
wp
->
NO
,
ori_pc
,
wp
->
expr
);
#else
printf
(
"
\n\n
Hint watchpoint %d at address 0x%08x, expr = %s
\n
"
,
wp
->
NO
,
ori_pc
,
wp
->
expr
);
#endif
printf
(
"
\n\n
Hint watchpoint %d at address "
FMT_WORD
", expr = %s
\n
"
,
wp
->
NO
,
ori_pc
,
wp
->
expr
);
printf
(
"old value = %#08x
\n
new value = %#08x
\n
"
,
wp
->
old_val
,
wp
->
new_val
);
wp
->
old_val
=
wp
->
new_val
;
return
;
...
...
@@ -87,17 +83,10 @@ void cpu_exec(uint64_t n) {
case
NEMU_RUNNING
:
nemu_state
.
state
=
NEMU_STOP
;
break
;
case
NEMU_END
:
case
NEMU_ABORT
:
#ifdef ISA64
_Log
(
"nemu: %s
\33
[0m at pc = 0x%016lx
\n\n
"
,
_Log
(
"nemu: %s
\33
[0m at pc = "
FMT_WORD
"
\n\n
"
,
(
nemu_state
.
state
==
NEMU_ABORT
?
"
\33
[1;31mABORT"
:
(
nemu_state
.
halt_ret
==
0
?
"
\33
[1;32mHIT GOOD TRAP"
:
"
\33
[1;31mHIT BAD TRAP"
)),
nemu_state
.
halt_pc
);
#else
_Log
(
"nemu: %s
\33
[0m at pc = 0x%08x
\n\n
"
,
(
nemu_state
.
state
==
NEMU_ABORT
?
"
\33
[1;31mABORT"
:
(
nemu_state
.
halt_ret
==
0
?
"
\33
[1;32mHIT GOOD TRAP"
:
"
\33
[1;31mHIT BAD TRAP"
)),
nemu_state
.
halt_pc
);
#endif
monitor_statistic
();
}
}
src/monitor/debug/expr.c
浏览文件 @
de417dff
...
...
@@ -173,7 +173,7 @@ static int find_dominated_op(int s, int e, bool *success) {
return
dominated_op
;
}
uint32
_t
isa_reg_str2val
(
const
char
*
,
bool
*
);
word
_t
isa_reg_str2val
(
const
char
*
,
bool
*
);
static
rtlreg_t
eval
(
int
s
,
int
e
,
bool
*
success
)
{
if
(
s
>
e
)
{
...
...
@@ -236,7 +236,7 @@ static rtlreg_t eval(int s, int e, bool *success) {
}
}
rtlreg
_t
expr
(
char
*
e
,
bool
*
success
)
{
word
_t
expr
(
char
*
e
,
bool
*
success
)
{
if
(
!
make_token
(
e
))
{
*
success
=
false
;
return
0
;
...
...
src/monitor/debug/log.c
浏览文件 @
de417dff
...
...
@@ -22,13 +22,8 @@ void strcatf(char *buf, const char *fmt, ...) {
}
void
asm_print
(
vaddr_t
ori_pc
,
int
instr_len
,
bool
print_flag
)
{
#ifdef ISA64
snprintf
(
tempbuf
,
sizeof
(
tempbuf
),
"%016lx: %s%*.s%s"
,
ori_pc
,
log_bytebuf
,
snprintf
(
tempbuf
,
sizeof
(
tempbuf
),
FMT_WORD
": %s%*.s%s"
,
ori_pc
,
log_bytebuf
,
50
-
(
12
+
3
*
instr_len
),
""
,
log_asmbuf
);
#else
snprintf
(
tempbuf
,
sizeof
(
tempbuf
),
"%8x: %s%*.s%s"
,
ori_pc
,
log_bytebuf
,
50
-
(
12
+
3
*
instr_len
),
""
,
log_asmbuf
);
#endif
log_write
(
"%s
\n
"
,
tempbuf
);
if
(
print_flag
)
{
puts
(
tempbuf
);
...
...
src/monitor/debug/ui.c
浏览文件 @
de417dff
...
...
@@ -88,13 +88,8 @@ static int cmd_d(char *args) {
static
int
cmd_p
(
char
*
args
)
{
if
(
args
!=
NULL
)
{
bool
success
;
#ifdef ISA64
uint64_t
r
=
expr
(
args
,
&
success
);
if
(
success
)
{
printf
(
"0x%lx
\n
"
,
r
);
}
#else
uint32_t
r
=
expr
(
args
,
&
success
);
if
(
success
)
{
printf
(
"%d
\n
"
,
r
);
}
#endif
word_t
r
=
expr
(
args
,
&
success
);
if
(
success
)
{
printf
(
FMT_WORD
"
\n
"
,
r
);
}
else
{
printf
(
"Bad expression
\n
"
);
}
}
return
0
;
...
...
@@ -127,14 +122,10 @@ static int cmd_x(char *args) {
if
(
success
)
{
for
(
i
=
0
;
i
<
n
;
i
++
)
{
if
(
i
%
4
==
0
)
{
#ifdef ISA64
printf
(
"0x%016lx: "
,
addr
);
#else
printf
(
"0x%08x: "
,
addr
);
#endif
printf
(
FMT_WORD
": "
,
addr
);
}
printf
(
"0x%08x "
,
vaddr_read
(
addr
,
4
));
printf
(
"0x%08x "
,
(
uint32_t
)
vaddr_read
(
addr
,
4
));
addr
+=
4
;
if
(
i
%
4
==
3
)
{
printf
(
"
\n
"
);
...
...
src/monitor/debug/watchpoint.c
浏览文件 @
de417dff
...
...
@@ -36,9 +36,8 @@ static void free_WP(WP *p) {
}
int
set_watchpoint
(
char
*
e
)
{
uint32_t
val
;
bool
success
;
val
=
expr
(
e
,
&
success
);
word_t
val
=
expr
(
e
,
&
success
);
if
(
!
success
)
return
-
1
;
WP
*
p
=
new_WP
();
...
...
@@ -74,7 +73,7 @@ void list_watchpoint() {
printf
(
"%8s
\t
%8s
\t
%8s
\n
"
,
"NO"
,
"Address"
,
"Enable"
);
WP
*
p
;
for
(
p
=
head
;
p
!=
NULL
;
p
=
p
->
next
)
{
printf
(
"%8d
\t
%s
\t
%#08x
\n
"
,
p
->
NO
,
p
->
expr
,
p
->
old_val
);
printf
(
"%8d
\t
%s
\t
"
FMT_WORD
"
\n
"
,
p
->
NO
,
p
->
expr
,
p
->
old_val
);
}
}
...
...
src/monitor/diff-test/diff-test.c
浏览文件 @
de417dff
...
...
@@ -95,11 +95,7 @@ void difftest_step(vaddr_t ori_pc, vaddr_t next_pc) {
}
skip_dut_nr_instr
--
;
if
(
skip_dut_nr_instr
==
0
)
#ifdef ISA64
panic
(
"can not catch up with ref.pc = %lx at pc = %lx"
,
ref_r
.
pc
,
ori_pc
);
#else
panic
(
"can not catch up with ref.pc = %x at pc = %x"
,
ref_r
.
pc
,
ori_pc
);
#endif
panic
(
"can not catch up with ref.pc = "
FMT_WORD
" at pc = "
FMT_WORD
,
ref_r
.
pc
,
ori_pc
);
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录