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, 0xd4201980
|
---|
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) || defined(ASM_FORMAT_PE)
|
---|
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) || defined(ASM_FORMAT_PE)
|
---|
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) || defined(ASM_FORMAT_PE)
|
---|
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) || defined(ASM_FORMAT_PE)
|
---|
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) || defined(ASM_FORMAT_PE)
|
---|
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) || defined(ASM_FORMAT_PE)
|
---|
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) || defined(ASM_FORMAT_PE)
|
---|
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) || defined(ASM_FORMAT_PE)
|
---|
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 | #ifndef RT_OS_WINDOWS
|
---|
156 | /**
|
---|
157 | * Returns the page address of the given symbol (used with the adrp instruction primarily).
|
---|
158 | *
|
---|
159 | * @returns Page aligned address of the given symbol
|
---|
160 | * @param a_Symbol The symbol to get the page address from.
|
---|
161 | */
|
---|
162 | #if defined(__clang__)
|
---|
163 | # define PAGE(a_Symbol) a_Symbol ## @PAGE
|
---|
164 | #elif defined(__GNUC__)
|
---|
165 | # define PAGE(a_Symbol) a_Symbol
|
---|
166 | #else
|
---|
167 | # error "Port me!"
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Returns the offset inside the page of the given symbol.
|
---|
172 | *
|
---|
173 | * @returns Page offset of the given symbol inside a page.
|
---|
174 | * @param a_Symbol The symbol to get the page offset from.
|
---|
175 | */
|
---|
176 | #if defined(__clang__)
|
---|
177 | # define PAGEOFF(a_Symbol) a_Symbol ## @PAGEOFF
|
---|
178 | #elif defined(__GNUC__)
|
---|
179 | # define PAGEOFF(a_Symbol) :lo12: ## a_Symbol
|
---|
180 | #else
|
---|
181 | # error "Port me!"
|
---|
182 | #endif
|
---|
183 |
|
---|
184 | #endif /* RT_OS_WINDOWS */
|
---|
185 |
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Starts an externally visible procedure.
|
---|
189 | *
|
---|
190 | * @param a_Name The unmangled symbol name.
|
---|
191 | */
|
---|
192 | .macro BEGINPROC, a_Name
|
---|
193 | NAME(\a_Name):
|
---|
194 | .endm
|
---|
195 |
|
---|
196 |
|
---|
197 | /**
|
---|
198 | * Starts a procedure with hidden visibility.
|
---|
199 | *
|
---|
200 | * @param a_Name The unmangled symbol name.
|
---|
201 | */
|
---|
202 | .macro BEGINPROC_HIDDEN, a_Name
|
---|
203 | #ifdef ASM_FORMAT_MACHO
|
---|
204 | .private_extern NAME(\a_Name)
|
---|
205 | #elif defined(ASM_FORMAT_ELF)
|
---|
206 | .hidden NAME(\a_Name)
|
---|
207 | #endif
|
---|
208 | .globl NAME(\a_Name)
|
---|
209 | NAME(\a_Name):
|
---|
210 | .endm
|
---|
211 |
|
---|
212 |
|
---|
213 | /** @} */
|
---|
214 |
|
---|
215 | #endif /* !IPRT_INCLUDED_asmdefs_arm_h */
|
---|
216 |
|
---|