Skip to content
GitLab
菜单
项目
群组
代码片段
帮助
帮助
支持
社区论坛
快捷键
?
提交反馈
登录/注册
切换导航
菜单
打开侧边栏
Panda
TinyCC
提交
0b1cc489
提交
0b1cc489
编辑于
4月 06, 2021
作者:
Danny Milosavljevic
浏览文件
riscv64-asm: Add lui, auipc
上级
e5a898e5
变更
2
Hide whitespace changes
Inline
Side-by-side
riscv64-asm.c
浏览文件 @
0b1cc489
...
...
@@ -179,6 +179,49 @@ static void asm_unary_opcode(TCCState *s1, int token)
}
}
static
void
asm_emit_u
(
int
token
,
uint32_t
opcode
,
const
Operand
*
rd
,
const
Operand
*
rs2
)
{
if
(
rd
->
type
!=
OP_REG
)
{
tcc_error
(
"'%s': Expected destination operand that is a register"
,
get_tok_str
(
token
,
NULL
));
return
;
}
if
(
rs2
->
type
!=
OP_IM12S
&&
rs2
->
type
!=
OP_IM32
)
{
tcc_error
(
"'%s': Expected second source operand that is an immediate value"
,
get_tok_str
(
token
,
NULL
));
return
;
}
else
if
(
rs2
->
e
.
v
>=
0x100000
)
{
tcc_error
(
"'%s': Expected second source operand that is an immediate value between 0 and 0xfffff"
,
get_tok_str
(
token
,
NULL
));
return
;
}
/* U-type instruction:
31...12 imm[31:12]
11...7 rd
6...0 opcode */
gen_le32
(
opcode
|
ENCODE_RD
(
rd
->
reg
)
|
(
rs2
->
e
.
v
<<
12
));
}
static
void
asm_binary_opcode
(
TCCState
*
s1
,
int
token
)
{
Operand
ops
[
2
];
parse_operand
(
s1
,
&
ops
[
0
]);
if
(
tok
==
','
)
next
();
else
expect
(
"','"
);
parse_operand
(
s1
,
&
ops
[
1
]);
switch
(
token
)
{
case
TOK_ASM_lui
:
asm_emit_u
(
token
,
(
0xD
<<
2
)
|
3
,
&
ops
[
0
],
&
ops
[
1
]);
return
;
case
TOK_ASM_auipc
:
asm_emit_u
(
token
,
(
0x05
<<
2
)
|
3
,
&
ops
[
0
],
&
ops
[
1
]);
return
;
default:
expect
(
"binary instruction"
);
}
}
ST_FUNC
void
asm_opcode
(
TCCState
*
s1
,
int
token
)
{
switch
(
token
)
{
...
...
@@ -204,6 +247,11 @@ ST_FUNC void asm_opcode(TCCState *s1, int token)
asm_unary_opcode
(
s1
,
token
);
return
;
case
TOK_ASM_lui
:
case
TOK_ASM_auipc
:
asm_binary_opcode
(
s1
,
token
);
return
;
default:
expect
(
"known instruction"
);
}
...
...
riscv64-tok.h
浏览文件 @
0b1cc489
...
...
@@ -82,6 +82,11 @@
#define DEF_ASM_WITH_SUFFIX(x, y) \
DEF(TOK_ASM_ ## x ## _ ## y, #x #y)
/* Arithmetic */
DEF_ASM
(
lui
)
DEF_ASM
(
auipc
)
/* Sync */
DEF_ASM
(
fence
)
...
...
编辑
预览
Supports
Markdown
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录