VirtualBox

source: vbox/trunk/include/iprt/asmdefs-arm.h@ 108539

Last change on this file since 108539 was 108478, checked in by vboxsync, 3 months ago

iprt/asmdefs-arm.h: The syntax for the PAGE() and PAGEOFF() macros doesn't so much depend on the compiler but on the output binary format. clang when compiling for elf.arm64 targets will only support the second variant and error out on the first one, bugref:10874 [forgot about win.arm64]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
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#ifdef ASM_FORMAT_PE
44# include <iprt/formats/pecoff.h>
45#endif
46
47/* Quick hack for #defines from pecoff.h */
48#define UINT8_C(v) v
49#define UINT16_C(v) v
50#define UINT32_C(v) v
51#define UINT64_C(v) v
52#define INT8_C(v) v
53#define INT16_C(v) v
54#define INT32_C(v) v
55#define INT64_C(v) v
56
57
58#if !defined(RT_ARCH_ARM64) && !defined(RT_ARCH_ARM32)
59# error "Not on ARM64 or ARM32"
60#endif
61
62/** @defgroup grp_rt_asmdefs_arm ARM Specific ASM (Clang and gcc) Macros
63 * @ingroup grp_rt_asm
64 * @{
65 */
66
67/**
68 * Align code, pad with BRK. */
69#define ALIGNCODE(alignment) .balignl alignment, 0xd4201980
70
71/**
72 * Align data, pad with ZEROs. */
73#define ALIGNDATA(alignment) .balign alignment
74
75/**
76 * Align BSS, pad with ZEROs. */
77#define ALIGNBSS(alignment) .balign alignment
78
79
80/** Marks the beginning of a code section. */
81#ifdef ASM_FORMAT_MACHO
82# define BEGINCODE .section __TEXT,__text,regular,pure_instructions
83#elif defined(ASM_FORMAT_ELF) || defined(ASM_FORMAT_PE)
84# define BEGINCODE .section .text
85#else
86# error "Port me!"
87#endif
88
89/** Marks the end of a code section. */
90#ifdef ASM_FORMAT_MACHO
91# define ENDCODE
92#elif defined(ASM_FORMAT_ELF) || defined(ASM_FORMAT_PE)
93# define ENDCODE
94#else
95# error "Port me!"
96#endif
97
98
99/** Marks the beginning of a data section. */
100#ifdef ASM_FORMAT_MACHO
101# define BEGINDATA .section __DATA,__data
102#elif defined(ASM_FORMAT_ELF) || defined(ASM_FORMAT_PE)
103# define BEGINDATA .section .data
104#else
105# error "Port me!"
106#endif
107
108/** Marks the end of a data section. */
109#ifdef ASM_FORMAT_MACHO
110# define ENDDATA
111#elif defined(ASM_FORMAT_ELF) || defined(ASM_FORMAT_PE)
112# define ENDDATA
113#else
114# error "Port me!"
115#endif
116
117
118/** Marks the beginning of a readonly data section. */
119#ifdef ASM_FORMAT_MACHO
120# define BEGINCONST .section __RODATA,__rodata
121#elif defined(ASM_FORMAT_ELF) || defined(ASM_FORMAT_PE)
122# define BEGINCONST .section .rodata
123#else
124# error "Port me!"
125#endif
126
127/** Marks the end of a readonly data section. */
128#ifdef ASM_FORMAT_MACHO
129# define ENDCONST
130#elif defined(ASM_FORMAT_ELF) || defined(ASM_FORMAT_PE)
131# define ENDCONST
132#else
133# error "Port me!"
134#endif
135
136
137/** Marks the beginning of a readonly C strings section. */
138#ifdef ASM_FORMAT_MACHO
139# define BEGINCONSTSTRINGS .section __TEXT,__cstring,cstring_literals
140#elif defined(ASM_FORMAT_ELF) || defined(ASM_FORMAT_PE)
141# define BEGINCONSTSTRINGS .section .rodata
142#else
143# error "Port me!"
144#endif
145
146/** Marks the end of a readonly C strings section. */
147#ifdef ASM_FORMAT_MACHO
148# define ENDCONSTSTRINGS
149#elif defined(ASM_FORMAT_ELF) || defined(ASM_FORMAT_PE)
150# define ENDCONSTSTRINGS
151#else
152# error "Port me!"
153#endif
154
155
156/**
157 * Mangles the name so it can be referenced using DECLASM() in the C/C++ world.
158 *
159 * @returns a_SymbolC with the necessary prefix/postfix.
160 * @param a_SymbolC A C symbol name to mangle as needed.
161 */
162#if defined(RT_OS_DARWIN)
163# define NAME(a_SymbolC) _ ## a_SymbolC
164#else
165# define NAME(a_SymbolC) a_SymbolC
166#endif
167
168
169/**
170 * Returns the page address of the given symbol (used with the adrp instruction primarily).
171 *
172 * @returns Page aligned address of the given symbol
173 * @param a_Symbol The symbol to get the page address from.
174 */
175#if defined(ASM_FORMAT_MACHO) || defined(ASM_FORMAT_PE)
176# define PAGE(a_Symbol) a_Symbol ## @PAGE
177#elif defined(ASM_FORMAT_ELF)
178# define PAGE(a_Symbol) a_Symbol
179#else
180# error "Port me!"
181#endif
182
183/**
184 * Returns the offset inside the page of the given symbol.
185 *
186 * @returns Page offset of the given symbol inside a page.
187 * @param a_Symbol The symbol to get the page offset from.
188 */
189#if defined(ASM_FORMAT_MACHO) || defined(ASM_FORMAT_PE)
190# define PAGEOFF(a_Symbol) a_Symbol ## @PAGEOFF
191#elif defined(ASM_FORMAT_ELF)
192# define PAGEOFF(a_Symbol) :lo12: ## a_Symbol
193#else
194# error "Port me!"
195#endif
196
197
198/**
199 * Starts an externally visible procedure.
200 *
201 * @param a_Name The unmangled symbol name.
202 */
203.macro BEGINPROC, a_Name
204#if defined(ASM_FORMAT_PE)
205 .def NAME(\a_Name)
206 .scl IMAGE_SYM_CLASS_EXTERNAL
207 .type IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT
208 .endef
209#endif
210 .globl NAME(\a_Name)
211NAME(\a_Name):
212.endm
213
214
215/**
216 * Starts a procedure with hidden visibility.
217 *
218 * @param a_Name The unmangled symbol name.
219 */
220.macro BEGINPROC_HIDDEN, a_Name
221#ifdef ASM_FORMAT_MACHO
222 .private_extern NAME(\a_Name)
223#elif defined(ASM_FORMAT_ELF)
224 .hidden NAME(\a_Name)
225#elif defined(ASM_FORMAT_PE)
226 .def NAME(\a_Name)
227 .scl IMAGE_SYM_CLASS_EXTERNAL
228 .type IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT
229 .endef
230#endif
231 .globl NAME(\a_Name)
232NAME(\a_Name):
233.endm
234
235
236/**
237 * Starts an exported procedure.
238 *
239 * @param a_Name The unmangled symbol name.
240 */
241.macro BEGINPROC_EXPORTED, a_Name
242#ifdef ASM_FORMAT_MACHO
243 //.private_extern NAME(\a_Name)
244#elif defined(ASM_FORMAT_ELF)
245 //.hidden NAME(\a_Name)
246#elif defined(ASM_FORMAT_PE)
247 .pushsection .drectve
248 .string "-export:\a_Name"
249 .popsection
250 .def NAME(\a_Name)
251 .scl IMAGE_SYM_CLASS_EXTERNAL
252 .type IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT
253 .endef
254#endif
255 .globl NAME(\a_Name)
256NAME(\a_Name):
257.endm
258
259
260/**
261 * Ends a procedure.
262 *
263 * @param a_Name The unmangled symbol name.
264 */
265.macro ENDPROC, a_Name
266NAME(\a_Name)\()_EndProc:
267.endm
268
269
270/** @} */
271
272#endif /* !IPRT_INCLUDED_asmdefs_arm_h */
273
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette