1 | /** @file
|
---|
2 | * IPRT - ARM Specific Assembly Macros.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2023-2024 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef IPRT_INCLUDED_asmdefs_arm_h
|
---|
37 | #define IPRT_INCLUDED_asmdefs_arm_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/cdefs.h>
|
---|
43 |
|
---|
44 |
|
---|
45 | #if !defined(RT_ARCH_ARM64) && !defined(RT_ARCH_ARM32)
|
---|
46 | # error "Not on ARM64 or ARM32"
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | /** @defgroup grp_rt_asmdefs_arm ARM Specific ASM (Clang and gcc) Macros
|
---|
50 | * @ingroup grp_rt_asm
|
---|
51 | * @{
|
---|
52 | */
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Align code, pad with BRK. */
|
---|
56 | #define ALIGNCODE(alignment) .balignl alignment, 0xd42000cc
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Align data, pad with ZEROs. */
|
---|
60 | #define ALIGNDATA(alignment) .balign alignment
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Align BSS, pad with ZEROs. */
|
---|
64 | #define ALIGNBSS(alignment) .balign alignment
|
---|
65 |
|
---|
66 |
|
---|
67 | /** Marks the beginning of a code section. */
|
---|
68 | #ifdef ASM_FORMAT_MACHO
|
---|
69 | # define BEGINCODE .section __TEXT,__text,regular,pure_instructions
|
---|
70 | #elif defined(ASM_FORMAT_ELF)
|
---|
71 | # define BEGINCODE .section .text
|
---|
72 | #else
|
---|
73 | # error "Port me!"
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | /** Marks the end of a code section. */
|
---|
77 | #ifdef ASM_FORMAT_MACHO
|
---|
78 | # define ENDCODE
|
---|
79 | #elif defined(ASM_FORMAT_ELF)
|
---|
80 | # define ENDCODE
|
---|
81 | #else
|
---|
82 | # error "Port me!"
|
---|
83 | #endif
|
---|
84 |
|
---|
85 |
|
---|
86 | /** Marks the beginning of a data section. */
|
---|
87 | #ifdef ASM_FORMAT_MACHO
|
---|
88 | # define BEGINDATA .section __DATA,__data
|
---|
89 | #elif defined(ASM_FORMAT_ELF)
|
---|
90 | # define BEGINDATA .section .data
|
---|
91 | #else
|
---|
92 | # error "Port me!"
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | /** Marks the end of a data section. */
|
---|
96 | #ifdef ASM_FORMAT_MACHO
|
---|
97 | # define ENDDATA
|
---|
98 | #elif defined(ASM_FORMAT_ELF)
|
---|
99 | # define ENDDATA
|
---|
100 | #else
|
---|
101 | # error "Port me!"
|
---|
102 | #endif
|
---|
103 |
|
---|
104 |
|
---|
105 | /** Marks the beginning of a readonly data section. */
|
---|
106 | #ifdef ASM_FORMAT_MACHO
|
---|
107 | # define BEGINCONST .section __RODATA,__rodata
|
---|
108 | #elif defined(ASM_FORMAT_ELF)
|
---|
109 | # define BEGINCONST .section .rodata
|
---|
110 | #else
|
---|
111 | # error "Port me!"
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | /** Marks the end of a readonly data section. */
|
---|
115 | #ifdef ASM_FORMAT_MACHO
|
---|
116 | # define ENDCONST
|
---|
117 | #elif defined(ASM_FORMAT_ELF)
|
---|
118 | # define ENDCONST
|
---|
119 | #else
|
---|
120 | # error "Port me!"
|
---|
121 | #endif
|
---|
122 |
|
---|
123 |
|
---|
124 | /** Marks the beginning of a readonly C strings section. */
|
---|
125 | #ifdef ASM_FORMAT_MACHO
|
---|
126 | # define BEGINCONSTSTRINGS .section __TEXT,__cstring,cstring_literals
|
---|
127 | #elif defined(ASM_FORMAT_ELF)
|
---|
128 | # define BEGINCONSTSTRINGS .section .rodata
|
---|
129 | #else
|
---|
130 | # error "Port me!"
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | /** Marks the end of a readonly C strings section. */
|
---|
134 | #ifdef ASM_FORMAT_MACHO
|
---|
135 | # define ENDCONSTSTRINGS
|
---|
136 | #elif defined(ASM_FORMAT_ELF)
|
---|
137 | # define ENDCONSTSTRINGS
|
---|
138 | #else
|
---|
139 | # error "Port me!"
|
---|
140 | #endif
|
---|
141 |
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Mangles the name so it can be referenced using DECLASM() in the C/C++ world.
|
---|
145 | *
|
---|
146 | * @returns a_SymbolC with the necessary prefix/postfix.
|
---|
147 | * @param a_SymbolC A C symbol name to mangle as needed.
|
---|
148 | */
|
---|
149 | #if defined(RT_OS_DARWIN)
|
---|
150 | # define NAME(a_SymbolC) _ ## a_SymbolC
|
---|
151 | #else
|
---|
152 | # define NAME(a_SymbolC) a_SymbolC
|
---|
153 | #endif
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Returns the page address of the given symbol (used with the adrp instruction primarily).
|
---|
157 | *
|
---|
158 | * @returns Page aligned address of the given symbol
|
---|
159 | * @param a_Symbol The symbol to get the page address from.
|
---|
160 | */
|
---|
161 | #if defined(__clang__)
|
---|
162 | # define PAGE(a_Symbol) a_Symbol ## @PAGE
|
---|
163 | #elif defined(__GNUC__) && defined(ASM_FORMAT_ELF)
|
---|
164 | # define PAGE(a_Symbol) :got: ## a_Symbol
|
---|
165 | #else
|
---|
166 | # error "Port me!"
|
---|
167 | #endif
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * Returns the offset inside the page of the given symbol.
|
---|
171 | *
|
---|
172 | * @returns Page offset of the given symbol inside a page.
|
---|
173 | * @param a_Symbol The symbol to get the page offset from.
|
---|
174 | */
|
---|
175 | #if defined(__clang__)
|
---|
176 | # define PAGEOFF(a_Symbol) a_Symbol ## @PAGEOFF
|
---|
177 | #elif defined(__GNUC__) && defined(ASM_FORMAT_ELF)
|
---|
178 | # define PAGEOFF(a_Symbol) :got_lo12: ## a_Symbol
|
---|
179 | #else
|
---|
180 | # error "Port me!"
|
---|
181 | #endif
|
---|
182 |
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Starts an externally visible procedure.
|
---|
186 | *
|
---|
187 | * @param a_Name The unmangled symbol name.
|
---|
188 | */
|
---|
189 | .macro BEGINPROC, a_Name
|
---|
190 | NAME(\a_Name):
|
---|
191 | .endm
|
---|
192 |
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Starts a procedure with hidden visibility.
|
---|
196 | *
|
---|
197 | * @param a_Name The unmangled symbol name.
|
---|
198 | */
|
---|
199 | .macro BEGINPROC_HIDDEN, a_Name
|
---|
200 | #ifndef ASM_FORMAT_ELF
|
---|
201 | .private_extern NAME(\a_Name)
|
---|
202 | #else
|
---|
203 | .hidden NAME(\a_Name)
|
---|
204 | #endif
|
---|
205 | .globl NAME(\a_Name)
|
---|
206 | NAME(\a_Name):
|
---|
207 | .endm
|
---|
208 |
|
---|
209 |
|
---|
210 | /** @} */
|
---|
211 |
|
---|
212 | #endif /* !IPRT_INCLUDED_asmdefs_arm_h */
|
---|
213 |
|
---|