VirtualBox

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

Last change on this file was 108669, checked in by vboxsync, 7 weeks ago

include/iprt/asmdefs-arm.h,bldprogs/VBoxDef2LazyLoad.cpp: Make the lazy loader work in PIC mode where we need to go through global offset table (GOT) while keeping it working for non PIC code (guest additions), bugref:10391

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 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.215389.xyz.
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# define PAGE_GOT(a_Symbol) :got: ## a_Symbol
180#else
181# error "Port me!"
182#endif
183
184/**
185 * Returns the offset inside the page of the given symbol.
186 *
187 * @returns Page offset of the given symbol inside a page.
188 * @param a_Symbol The symbol to get the page offset from.
189 */
190#if defined(ASM_FORMAT_MACHO) || defined(ASM_FORMAT_PE)
191# define PAGEOFF(a_Symbol) a_Symbol ## @PAGEOFF
192#elif defined(ASM_FORMAT_ELF)
193# define PAGEOFF(a_Symbol) :lo12: ## a_Symbol
194# define PAGEOFF_GOT(a_Symbol) :got_lo12: ## a_Symbol
195#else
196# error "Port me!"
197#endif
198
199
200/**
201 * Starts an externally visible procedure.
202 *
203 * @param a_Name The unmangled symbol name.
204 */
205.macro BEGINPROC, a_Name
206#if defined(ASM_FORMAT_PE)
207 .def NAME(\a_Name)
208 .scl IMAGE_SYM_CLASS_EXTERNAL
209 .type IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT
210 .endef
211#endif
212 .globl NAME(\a_Name)
213NAME(\a_Name):
214.endm
215
216
217/**
218 * Starts a procedure with hidden visibility.
219 *
220 * @param a_Name The unmangled symbol name.
221 */
222.macro BEGINPROC_HIDDEN, a_Name
223#ifdef ASM_FORMAT_MACHO
224 .private_extern NAME(\a_Name)
225#elif defined(ASM_FORMAT_ELF)
226 .hidden NAME(\a_Name)
227#elif defined(ASM_FORMAT_PE)
228 .def NAME(\a_Name)
229 .scl IMAGE_SYM_CLASS_EXTERNAL
230 .type IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT
231 .endef
232#endif
233 .globl NAME(\a_Name)
234NAME(\a_Name):
235.endm
236
237
238/**
239 * Starts an exported procedure.
240 *
241 * @param a_Name The unmangled symbol name.
242 */
243.macro BEGINPROC_EXPORTED, a_Name
244#ifdef ASM_FORMAT_MACHO
245 //.private_extern NAME(\a_Name)
246#elif defined(ASM_FORMAT_ELF)
247 //.hidden NAME(\a_Name)
248#elif defined(ASM_FORMAT_PE)
249 .pushsection .drectve
250 .string "-export:\a_Name"
251 .popsection
252 .def NAME(\a_Name)
253 .scl IMAGE_SYM_CLASS_EXTERNAL
254 .type IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT
255 .endef
256#endif
257 .globl NAME(\a_Name)
258NAME(\a_Name):
259.endm
260
261
262/**
263 * Ends a procedure.
264 *
265 * @param a_Name The unmangled symbol name.
266 */
267.macro ENDPROC, a_Name
268NAME(\a_Name)\()_EndProc:
269.endm
270
271
272/** @} */
273
274#endif /* !IPRT_INCLUDED_asmdefs_arm_h */
275
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