|
| 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 |
0 commit comments