aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mvp/mvpkm/arm_gcc_inline.h
blob: 33ffe69af662e48863a49f9053f9e2053aee0fc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * Linux 2.6.32 and later Kernel module for VMware MVP Hypervisor Support
 *
 * Copyright (C) 2010-2012 VMware, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; see the file COPYING.  If not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#line 5

/**
 * @file
 *
 * @brief GCC inline stubs for ARM assembler instructions.
 */

#ifndef _ARM_GCC_INLINE_H_
#define _ARM_GCC_INLINE_H_

#define INCLUDE_ALLOW_MVPD
#define INCLUDE_ALLOW_VMX
#define INCLUDE_ALLOW_MODULE
#define INCLUDE_ALLOW_MONITOR
#define INCLUDE_ALLOW_PV
#define INCLUDE_ALLOW_GPL
#include "include_check.h"

#include "coproc_defs.h"

/*
 * Macros for accessing CP10.
 */
#define _ARM_CP10_MRCMCR_STR(_op1,_cr1,_cr2,_op2,_var) \
   " p10, " #_op1 ","#_var"," #_cr1 "," #_cr2 "," #_op2 "\n\t"

#define _ARM_MRC_CP10(_op1,_cr1,_cr2,_op2,_var) \
   asm volatile ("mrc" _ARM_CP10_MRCMCR_STR(_op1,_cr1,_cr2,_op2,%0) \
                 : "=r" (_var) )

#define ARM_MRC_CP10(_cp_reg,_var) _ARM_MRC_CP10(_cp_reg,_var)

#define _ARM_MCR_CP10(_op1,_cr1,_cr2,_op2,_val) \
   asm volatile ("mcr" _ARM_CP10_MRCMCR_STR(_op1,_cr1,_cr2,_op2,%0) \
                 : \
                 : "r" (_val) )

#define ARM_MCR_CP10(_cp_reg,_val) _ARM_MCR_CP10(_cp_reg,_val)


/*
 * Macros for accessing CP15.
 */
#define _ARM_CP15_MRCMCR_STR(_op1,_cr1,_cr2,_op2,_var) \
   " p15, " #_op1 ","#_var"," #_cr1 "," #_cr2 "," #_op2 "\n\t"

#define ARM_CP15_MRCMCR_STR(_cp_reg,_var) _ARM_CP15_MRCMCR_STR(_cp_reg,_var)

#ifdef __COVERITY__
static uint32 __cp15;
#define _ARM_MRC_CP15(_op1,_cr1,_cr2,_op2,_var) \
    (_var) = (uint32)__cp15
#else
#define _ARM_MRC_CP15(_op1,_cr1,_cr2,_op2,_var) \
   asm volatile ("mrc" _ARM_CP15_MRCMCR_STR(_op1,_cr1,_cr2,_op2,%0) \
                 : "=r" (_var) \
                 : \
                 : "memory")
#endif

#define ARM_MRC_CP15(_cp_reg,_var) _ARM_MRC_CP15(_cp_reg,_var)


#ifdef __COVERITY__
#define _ARM_MCR_CP15(_op1,_cr1,_cr2,_op2,_val) \
   __cp15 = (_val)
#else
#define _ARM_MCR_CP15(_op1,_cr1,_cr2,_op2,_val) \
   asm volatile ("mcr" _ARM_CP15_MRCMCR_STR(_op1,_cr1,_cr2,_op2,%0) \
                 : \
                 : "r" (_val)\
                 : "memory")
#endif

#define ARM_MCR_CP15(_cp_reg,_val) _ARM_MCR_CP15(_cp_reg,_val)

#define _ARM_MRRC_CP15(_op,_cr,_val1,_val2) \
   asm volatile ("mrrc p15, " #_op ",%0,%1," #_cr "\n\t" \
                 : "=r" (_val1), "=r" (_val2) \
                 : \
                 : "memory")

#define ARM_MRRC_CP15(_cp_reg,_val1,_val2) _ARM_MRRC_CP15(_cp_reg,_val1,_val2)

#define ARM_MRRC64_CP15(_cp_reg,_val) \
   _ARM_MRRC_CP15(_cp_reg,_val,*((uint8 *)&(_val) + 4))

#define _ARM_MCRR_CP15(_op,_cr,_val1,_val2) \
   asm volatile ("mcrr p15, " #_op ",%0,%1," #_cr "\n\t" \
                 : \
                 : "r" (_val1), "r" (_val2) \
                 : "memory")

#define ARM_MCRR_CP15(_cp_reg,_val1,_val2) _ARM_MCRR_CP15(_cp_reg,_val1,_val2)

#define ARM_MCRR64_CP15(_cp_reg,_val) \
   _ARM_MCRR_CP15(_cp_reg,_val,*((uint8 *)&(_val) + 4))

#define DMB() asm volatile ("dmb" : : : "memory")
#define DSB() asm volatile ("dsb" : : : "memory")
#define ISB() asm volatile ("isb" : : : "memory")

/**
 * @name 64-bit multiplies
 * @{
 */

// rdhi:rdlo = rm * rs + rdhi + rdlo
#define ARM_UMAAL(rdlo,rdhi,rm,rs) asm ("umaal %0,%1,%2,%3" \
                                        : "+r" (rdlo), "+r" (rdhi) \
                                        :  "r" (rm),    "r" (rs))

// rdhi:rdlo += rm * rs
#define ARM_UMLAL(rdlo,rdhi,rm,rs) asm ("umlal %0,%1,%2,%3" \
                                        : "+r" (rdlo), "+r" (rdhi) \
                                        :  "r" (rm),    "r" (rs))

// rdhi:rdlo = rm * rs
#define ARM_UMULL(rdlo,rdhi,rm,rs) asm ("umull %0,%1,%2,%3" \
                                        : "=r" (rdlo), "=r" (rdhi) \
                                        :  "r" (rm),    "r" (rs))
/*@}*/

/**
 * @brief Disable interrupts (IRQ + FIQ)
 *
 * @return CPSR status prior to disabling - suitable for passing to
 *         ARM_RestoreInterrupts() to restore IRQ/FIQ levels to
 *         pre-call values
 */
static inline uint32
ARM_DisableInterrupts(void)
{
   register uint32 status;

   asm volatile ("mrs    %0,     cpsr            \n\t"
                 "orr    r1,     %0,     %1      \n\t"
                 "msr    cpsr_c, r1              \n\t"
                 : "=&r" (status)
                 : "i" (ARM_PSR_I | ARM_PSR_F)
                 : "r1", "memory");

   return status;
}

/**
 * @brief Restore interrupts
 *
 * @param status return value from a previous call to ARM_DisableInterrupts()
 */
static inline void
ARM_RestoreInterrupts(uint32 status)
{
   asm volatile ("msr cpsr_c, %0 \n\t" : : "r" (status) : "memory");
}

/**
 * @brief Read current CPSR value
 *
 * @return current CPSR value
 */
static inline uint32
ARM_ReadCPSR(void)
{
   uint32 status;

   asm volatile ("mrs %0, cpsr \n\t" : "=r" (status));

   return status;
}

/**
 * @brief Read current stack pointer
 *
 * @return stack pointer value
 */
static inline uint32
ARM_ReadSP(void)
{
   uint32 sp;

   asm volatile ("mov %0, sp \n\t" : "=r" (sp));

   return sp;
}

#endif /// ifndef _ARM_GCC_INLINE_H_