Skip to content

Commit b683456

Browse files
ewlurbertran
authored andcommitted
RISC-V: Add banana pi target
Add support targeting the RISC-V Banana Pi 3 board. Assembly generated by this target will automatically be compilable without additional modifications Signed-off-by: Edwin Lu <ewlu@rivosinc.com>
1 parent ffb07ec commit b683456

4 files changed

Lines changed: 238 additions & 0 deletions

File tree

targets/generic/tools/mp_seq.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ def _generic_policy_wrapper(all_arguments: Tuple[List[InstructionType], str,
114114
wrapper = wrapper_class(endless=kwargs['endless'],
115115
reset=kwargs['reset'])
116116

117+
elif target.name.endswith("riscv64_bp3"):
118+
119+
wrapper_name = "RiscvBP3"
120+
extension = "S"
121+
wrapper_class = _get_wrapper(wrapper_name)
122+
wrapper = wrapper_class(endless=kwargs['endless'],
123+
reset=kwargs['reset'])
124+
117125
elif target.environment.default_wrapper:
118126

119127
wrapper_name = target.environment.default_wrapper

targets/riscv/env/riscv_bp3.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2011-2021 IBM Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""
15+
Docstring
16+
"""
17+
18+
# Futures
19+
from __future__ import absolute_import
20+
21+
# Own modules
22+
from microprobe.code.address import InstructionAddress
23+
from microprobe.target.env import GenericEnvironment
24+
25+
# Constants
26+
27+
# Functions
28+
29+
30+
# Classes
31+
class riscv64_bp3(GenericEnvironment):
32+
33+
_elf_code = ""\
34+
""\
35+
""
36+
37+
def __init__(self, isa):
38+
super(
39+
riscv64_bp3,
40+
self).__init__(
41+
"riscv64_bp3",
42+
"RISC-V architecture (64bit addressing mode), "
43+
"Assembly using RISC-V Banana Pi 3",
44+
isa,
45+
little_endian=True
46+
)
47+
48+
self._default_wrapper = "RiscvBP3"
49+
50+
@property
51+
def stack_pointer(self):
52+
""" """
53+
return self.isa.registers["X2"]
54+
55+
@property
56+
def stack_direction(self):
57+
""" """
58+
return "increase"
59+
60+
def elf_abi(self, stack_size, start_symbol, **kwargs):
61+
62+
return super(riscv64_bp3, self).elf_abi(stack_size,
63+
start_symbol,
64+
stack_alignment=16,
65+
**kwargs)
66+
67+
def function_call(self, target,
68+
return_address_reg=None,
69+
long_jump=False):
70+
71+
if return_address_reg is None:
72+
return_address_reg = self.target.isa.registers["X1"]
73+
74+
if isinstance(target, str):
75+
target = InstructionAddress(base_address=target)
76+
77+
jal_ins = self.target.new_instruction("JAL_V0")
78+
jal_ins.set_operands([target, return_address_reg])
79+
80+
return [jal_ins]
81+
82+
def function_return(self,
83+
return_address_reg=None):
84+
85+
if return_address_reg is None:
86+
return_address_reg = self.target.isa.registers["X1"]
87+
88+
ret_ins = self.target.new_instruction("JALR_V0")
89+
ret_ins.set_operands([0,
90+
return_address_reg,
91+
self.target.isa.registers["X0"]])
92+
return [ret_ins]
93+
94+
@property
95+
def volatile_registers(self):
96+
97+
rlist = []
98+
for idx in [
99+
1, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17,
100+
28, 29, 30, 31]:
101+
rlist += [self.target.registers['X%d' % idx]]
102+
103+
for idx in [
104+
0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17,
105+
28, 29, 30, 31]:
106+
rlist += [self.target.registers['F%d' % idx]]
107+
108+
return rlist

targets/riscv/policies/seq.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
SUPPORTED_TARGETS = [
4848
"riscv_v22-riscv_generic-riscv64_linux_gcc",
4949
"riscv_v22-riscv_generic-riscv64_test_p",
50+
"riscv_v22-riscv_generic-riscv64_bp3",
5051
]
5152

5253

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Copyright 2011-2021 IBM Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# Futures
15+
from __future__ import absolute_import
16+
17+
18+
# Own modules
19+
from microprobe.code import get_wrapper
20+
from microprobe.utils.logger import get_logger
21+
22+
23+
# Constants
24+
LOG = get_logger(__name__)
25+
__all__ = ["RiscvBP3"]
26+
27+
# Functions
28+
29+
30+
# Classes
31+
class RiscvBP3(get_wrapper("Assembly")):
32+
33+
def __init__(self, endless=False, reset=False):
34+
self._endless = endless
35+
self._reset = reset
36+
super(RiscvBP3, self).__init__()
37+
38+
# def headers(self):
39+
# return """\
40+
#
41+
# /* Headers */
42+
# #include "riscv_test.h"
43+
# #include "riscv-tests/isa/macros/scalar/test_macros.h"
44+
#
45+
# """
46+
47+
def start_main(self):
48+
return """\
49+
.global main
50+
51+
/* Start Main */
52+
.section .text
53+
main:
54+
"""
55+
56+
def outputname(self, name):
57+
"""
58+
59+
:param name:
60+
61+
"""
62+
if not name.endswith(".S"):
63+
return "%s.S" % name
64+
return name
65+
66+
def post_var(self):
67+
return "".join("reset:")
68+
69+
def start_loop(self, instr, instr_reset, dummy_aligned=True):
70+
"""
71+
72+
:param instr:
73+
:param instr_reset:
74+
:param dummy_aligned: (Default value = True)
75+
76+
"""
77+
78+
start_loop = ["/* Building block start */\n"]
79+
if not self._endless:
80+
return "\n".join(start_loop)
81+
82+
if self._reset:
83+
instr_reset.add_comment("Loop start reseting")
84+
if not instr_reset.label:
85+
instr_reset.set_label("reset")
86+
self._loop_label = "reset"
87+
else:
88+
self._loop_label = instr_reset.label
89+
90+
else:
91+
instr.add_comment("Loop start")
92+
if not instr.label:
93+
instr.set_label("infloop")
94+
self._loop_label = "infloop"
95+
else:
96+
self._loop_label = instr.label
97+
98+
return "\n".join(start_loop)
99+
100+
def end_loop(self, dummy_instr):
101+
"""
102+
"""
103+
if not self._endless:
104+
return "/* Loop End */"
105+
106+
loop = ["/* Loop End */"]
107+
loop.append(self.wrap_ins("j %s" % self._loop_label))
108+
return "\n".join(loop)
109+
110+
def end_main(self):
111+
return """\
112+
113+
/* End Main */
114+
115+
"""
116+
117+
def declare_global_var(self, var):
118+
if var.align:
119+
return ".comm %s, %d, %d\n" % (var.name, var.size, var.align)
120+
else:
121+
return ".comm %s, %d\n" % (var.name, var.size)

0 commit comments

Comments
 (0)