1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // Assembler to produce RV32 instructions (UABI version). Somewhat influenced by V8 assembler. 18 19 #ifndef BERBERIS_ASSEMBLER_RV32I_H_ 20 #define BERBERIS_ASSEMBLER_RV32I_H_ 21 22 #include <type_traits> // std::is_same 23 24 #include "berberis/assembler/rv32.h" 25 26 namespace berberis { 27 28 namespace rv32i { 29 30 class Assembler : public ::berberis::rv32::Assembler { 31 public: 32 using BaseAssembler = riscv::Assembler<::berberis::rv32::Assembler>; 33 using FinalAssembler = ::berberis::rv32::Assembler; 34 Assembler(MachineCode * code)35 explicit Assembler(MachineCode* code) : berberis::rv32::Assembler(code) {} 36 37 static constexpr Register ra{1}; 38 static constexpr Register sp{2}; 39 static constexpr Register gp{3}; 40 static constexpr Register tp{4}; 41 static constexpr Register t0{5}; 42 static constexpr Register t1{6}; 43 static constexpr Register t2{7}; 44 static constexpr Register s0{8}; 45 static constexpr Register s1{9}; 46 static constexpr Register a0{10}; 47 static constexpr Register a1{11}; 48 static constexpr Register a2{12}; 49 static constexpr Register a3{13}; 50 static constexpr Register a4{14}; 51 static constexpr Register a5{15}; 52 static constexpr Register a6{16}; 53 static constexpr Register a7{17}; 54 static constexpr Register s2{18}; 55 static constexpr Register s3{19}; 56 static constexpr Register s4{20}; 57 static constexpr Register s5{21}; 58 static constexpr Register s6{22}; 59 static constexpr Register s7{23}; 60 static constexpr Register s8{24}; 61 static constexpr Register s9{25}; 62 static constexpr Register s10{26}; 63 static constexpr Register s11{27}; 64 static constexpr Register t3{28}; 65 static constexpr Register t4{29}; 66 static constexpr Register t5{30}; 67 static constexpr Register t6{31}; 68 69 private: 70 Assembler() = delete; 71 Assembler(const Assembler&) = delete; 72 Assembler(Assembler&&) = delete; 73 void operator=(const Assembler&) = delete; 74 void operator=(Assembler&&) = delete; 75 }; 76 77 } // namespace rv32i 78 79 } // namespace berberis 80 81 #endif // BERBERIS_ASSEMBLER_RV32I_H_ 82