1 /*
 2  * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
 3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
 4  * Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. All rights reserved.
 5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 6  *
 7  * This code is free software; you can redistribute it and/or modify it
 8  * under the terms of the GNU General Public License version 2 only, as
 9  * published by the Free Software Foundation.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  *
25  */
26 
27 #ifndef CPU_RISCV_STUBROUTINES_RISCV_HPP
28 #define CPU_RISCV_STUBROUTINES_RISCV_HPP
29 
30 // This file holds the platform specific parts of the StubRoutines
31 // definition. See stubRoutines.hpp for a description on how to
32 // extend it.
33 
34 static bool returns_to_call_stub(address return_pc) {
35   return return_pc == _call_stub_return_address;
36 }
37 
38 // emit enum used to size per-blob code buffers
39 
40 #define DEFINE_BLOB_SIZE(blob_name, size) \
41   _ ## blob_name ## _code_size = size,
42 
43 enum platform_dependent_constants {
44   STUBGEN_ARCH_BLOBS_DO(DEFINE_BLOB_SIZE)
45 };
46 
47 #undef DEFINE_BLOB_SIZE
48 
49 class riscv {
50  friend class StubGenerator;
51  friend class StubRoutines;
52 #if INCLUDE_JVMCI
53   friend class JVMCIVMStructs;
54 #endif
55 
56   // declare fields for arch-specific entries
57 
58 #define DECLARE_ARCH_ENTRY(arch, blob_name, stub_name, field_name, getter_name) \
59   static address STUB_FIELD_NAME(field_name) ;
60 
61 #define DECLARE_ARCH_ENTRY_INIT(arch, blob_name, stub_name, field_name, getter_name, init_function) \
62   DECLARE_ARCH_ENTRY(arch, blob_name, stub_name, field_name, getter_name)
63 
64 private:
65   STUBGEN_ARCH_ENTRIES_DO(DECLARE_ARCH_ENTRY, DECLARE_ARCH_ENTRY_INIT)
66 
67 #undef DECLARE_ARCH_ENTRY_INIT
68 #undef DECLARE_ARCH_ENTRY
69 
70   static bool _completed;
71 
72  public:
73 
74   // declare getters for arch-specific entries
75 
76 #define DEFINE_ARCH_ENTRY_GETTER(arch, blob_name, stub_name, field_name, getter_name) \
77   static address getter_name() { return STUB_FIELD_NAME(field_name) ; }
78 
79 #define DEFINE_ARCH_ENTRY_GETTER_INIT(arch, blob_name, stub_name, field_name, getter_name, init_function) \
80   DEFINE_ARCH_ENTRY_GETTER(arch, blob_name, stub_name, field_name, getter_name)
81 
82   STUBGEN_ARCH_ENTRIES_DO(DEFINE_ARCH_ENTRY_GETTER, DEFINE_ARCH_ENTRY_GETTER_INIT)
83 
84 #undef DEFINE_ARCH_ENTRY_GETTER_INIT
85 #undef DEFINE_ARCH_ENTRY_GETTER
86 
87   static bool complete() {
88     return _completed;
89   }
90 
91   static void set_completed() {
92     _completed = true;
93   }
94 
95 private:
96   static juint    _crc_table[];
97 };
98 
99 #endif // CPU_RISCV_STUBROUTINES_RISCV_HPP