VirtualBox

source: vbox/trunk/include/iprt/asm-arm.h@ 87230

Last change on this file since 87230 was 87218, checked in by vboxsync, 4 years ago

iprt/asm-arm.h: Fix include guard and add #pragma once to make scm happy.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/** @file
2 * IPRT - ARM Specific Assembly Functions.
3 */
4
5/*
6 * Copyright (C) 2015-2021 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_asm_arm_h
27#define IPRT_INCLUDED_asm_arm_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/types.h>
33#if !defined(RT_ARCH_ARM64) && !defined(RT_ARCH_ARM32)
34# error "Not on ARM64 or ARM32"
35#endif
36
37/** @defgroup grp_rt_asm_arm ARM Specific ASM Routines
38 * @ingroup grp_rt_asm
39 * @{
40 */
41
42
43#if 0 /* figure out arm64 */
44
45/**
46 * Get the CPSR (Current Program Status) register.
47 * @returns CPSR.
48 */
49#if RT_INLINE_ASM_EXTERNAL
50DECLASM(RTCCUINTREG) ASMGetFlags(void);
51#else
52DECLINLINE(RTCCUINTREG) ASMGetFlags(void)
53{
54 RTCCUINTREG uFlags;
55# if RT_INLINE_ASM_GNU_STYLE
56# ifdef RT_ARCH_ARM64
57 __asm__ __volatile__("mrs %0, nzcv\n\t" : "=r" (uFlags));
58# else
59 __asm__ __volatile__("mrs %0, cpsr\n\t" : "=r" (uFlags));
60# endif
61# else
62# error "Unsupported compiler"
63# endif
64 return uFlags;
65}
66#endif
67
68
69/**
70 * Set the CPSR register.
71 * @param uFlags The new CPSR value.
72 */
73#if RT_INLINE_ASM_EXTERNAL
74DECLASM(void) ASMSetFlags(RTCCUINTREG uFlags);
75#else
76DECLINLINE(void) ASMSetFlags(RTCCUINTREG uFlags)
77{
78# if RT_INLINE_ASM_GNU_STYLE
79 __asm__ __volatile__("msr cpsr_c, %0\n\t"
80 : : "r" (uFlags));
81# else
82# error "Unsupported compiler"
83# endif
84}
85#endif
86
87#endif
88
89#if 0
90/**
91 * Gets the content of the CPU timestamp counter register.
92 *
93 * @returns TSC.
94 */
95#if RT_INLINE_ASM_EXTERNAL
96DECLASM(uint64_t) ASMReadTSC(void);
97#else
98DECLINLINE(uint64_t) ASMReadTSC(void)
99{
100 RTUINT64U u;
101# if RT_INLINE_ASM_GNU_STYLE
102# else
103# error "Unsupported compiler"
104# endif
105 return u.u;
106}
107#endif
108#endif
109
110#if 0 /* port to arm64, armv7 and check */
111
112/**
113 * Enables interrupts (IRQ and FIQ).
114 */
115#if RT_INLINE_ASM_EXTERNAL
116DECLASM(void) ASMIntEnable(void);
117#else
118DECLINLINE(void) ASMIntEnable(void)
119{
120 RTCCUINTREG uFlags;
121# if RT_INLINE_ASM_GNU_STYLE
122 __asm__ __volatile__("mrs %0, cpsr\n\t"
123 "bic %0, %0, #0xc0\n\t"
124 "msr cpsr_c, %0\n\t"
125 : "=r" (uFlags));
126# else
127# error "Unsupported compiler"
128# endif
129}
130#endif
131
132
133/**
134 * Disables interrupts (IRQ and FIQ).
135 */
136#if RT_INLINE_ASM_EXTERNAL
137DECLASM(void) ASMIntDisable(void);
138#else
139DECLINLINE(void) ASMIntDisable(void)
140{
141 RTCCUINTREG uFlags;
142# if RT_INLINE_ASM_GNU_STYLE
143 __asm__ __volatile__("mrs %0, cpsr\n\t"
144 "orr %0, %0, #0xc0\n\t"
145 "msr cpsr_c, %0\n\t"
146 : "=r" (uFlags));
147# else
148# error "Unsupported compiler"
149# endif
150}
151#endif
152
153
154/**
155 * Disables interrupts and returns previous uFLAGS.
156 */
157#if RT_INLINE_ASM_EXTERNAL
158DECLASM(RTCCUINTREG) ASMIntDisableFlags(void);
159#else
160DECLINLINE(RTCCUINTREG) ASMIntDisableFlags(void)
161{
162 RTCCUINTREG uFlags;
163# if RT_INLINE_ASM_GNU_STYLE
164 RTCCUINTREG uNewFlags;
165 __asm__ __volatile__("mrs %0, cpsr\n\t"
166 "orr %1, %0, #0xc0\n\t"
167 "msr cpsr_c, %1\n\t"
168 : "=r" (uFlags)
169 , "=r" (uNewFlags));
170# else
171# error "Unsupported compiler"
172# endif
173 return uFlags;
174}
175#endif
176
177
178/**
179 * Are interrupts enabled?
180 *
181 * @returns true / false.
182 */
183DECLINLINE(bool) ASMIntAreEnabled(void)
184{
185/** @todo r=bird: reversed, but does both need to be enabled? */
186 return ASMGetFlags() & 0xc0 /* IRQ and FIQ bits */ ? true : false;
187}
188
189#endif
190
191/**
192 * Halts the CPU until interrupted.
193 */
194#if RT_INLINE_ASM_EXTERNAL
195DECLASM(void) ASMHalt(void);
196#else
197DECLINLINE(void) ASMHalt(void)
198{
199# if RT_INLINE_ASM_GNU_STYLE
200 __asm__ __volatile__ ("wfi\n\t"); /* wait for interrupt */
201# else
202# error "Unsupported compiler"
203# endif
204}
205#endif
206
207#if 0
208/**
209 * Gets the CPU ID of the current CPU.
210 *
211 * @returns the CPU ID.
212 * @note the name of this method is a bit misleading but serves the purpose
213 * and prevents #ifdef orgies in other places.
214 */
215#if RT_INLINE_ASM_EXTERNAL
216DECLASM(uint8_t) ASMGetApicId(void);
217#else
218DECLINLINE(uint8_t) ASMGetApicId(void)
219{
220# if RT_INLINE_ASM_GNU_STYLE
221 RTCCUINTREG uCpuId;
222 __asm__ ("mrc p15, 0, %0, c0, c0, 5\n\t" /* CPU ID Register, privileged */
223 : "=r" (uCpuId));
224 return uCpuId;
225# else
226# error "Unsupported compiler"
227# endif
228}
229#endif
230#endif
231
232#if 0
233
234/**
235 * Invalidate page.
236 *
237 * @param pv Address of the page to invalidate.
238 */
239#if RT_INLINE_ASM_EXTERNAL
240DECLASM(void) ASMInvalidatePage(void *pv);
241#else
242DECLINLINE(void) ASMInvalidatePage(void *pv)
243{
244# if RT_INLINE_ASM_GNU_STYLE
245
246# else
247# error "Unsupported compiler"
248# endif
249}
250#endif
251
252
253/**
254 * Write back the internal caches and invalidate them.
255 */
256#if RT_INLINE_ASM_EXTERNAL
257DECLASM(void) ASMWriteBackAndInvalidateCaches(void);
258#else
259DECLINLINE(void) ASMWriteBackAndInvalidateCaches(void)
260{
261# if RT_INLINE_ASM_GNU_STYLE
262
263# else
264# error "Unsupported compiler"
265# endif
266}
267#endif
268
269
270/**
271 * Invalidate internal and (perhaps) external caches without first
272 * flushing dirty cache lines. Use with extreme care.
273 */
274#if RT_INLINE_ASM_EXTERNAL
275DECLASM(void) ASMInvalidateInternalCaches(void);
276#else
277DECLINLINE(void) ASMInvalidateInternalCaches(void)
278{
279# if RT_INLINE_ASM_GNU_STYLE
280
281# else
282# error "Unsupported compiler"
283# endif
284}
285#endif
286
287#endif
288
289
290/** @} */
291#endif /* !IPRT_INCLUDED_asm_arm_h */
292
Note: See TracBrowser for help on using the repository browser.

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