Merge trunk HEAD (r46369)
[reactos.git] / reactos / drivers / bus / acpi / include / platform / acgcc.h
1 /******************************************************************************
2 *
3 * Name: acgcc.h - GCC specific defines, etc.
4 * $Revision: 1.1 $
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000, 2001 R. Byron Moore
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU 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, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26 #ifndef __ACGCC_H__
27 #define __ACGCC_H__
28
29
30 #ifdef __ia64__
31 #define _IA64
32
33 #define COMPILER_DEPENDENT_UINT64 unsigned long
34 /* Single threaded */
35 #define ACPI_APPLICATION
36
37 #define ACPI_ASM_MACROS
38 #define causeinterrupt(level)
39 #define BREAKPOINT3
40 #define disable() __cli()
41 #define enable() __sti()
42 #define wbinvd()
43
44 /*! [Begin] no source code translation */
45
46 #include <asm/pal.h>
47
48 #define halt() ia64_pal_halt_light() /* PAL_HALT[_LIGHT] */
49 #define safe_halt() ia64_pal_halt(1) /* PAL_HALT */
50
51
52 #define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
53 do { \
54 __asm__ volatile ("1: ld4 r29=%1\n" \
55 ";;\n" \
56 "mov ar.ccv=r29\n" \
57 "mov r2=r29\n" \
58 "shr.u r30=r29,1\n" \
59 "and r29=-4,r29\n" \
60 ";;\n" \
61 "add r29=2,r29\n" \
62 "and r30=1,r30\n" \
63 ";;\n" \
64 "add r29=r29,r30\n" \
65 ";;\n" \
66 "cmpxchg4.acq r30=%1,r29,ar.ccv\n" \
67 ";;\n" \
68 "cmp.eq p6,p7=r2,r30\n" \
69 "(p7) br.dpnt.few 1b\n" \
70 "cmp.gt p8,p9=3,r29\n" \
71 ";;\n" \
72 "(p8) mov %0=-1\n" \
73 "(p9) mov %0=r0\n" \
74 :"=r"(Acq):"m"(GLptr):"r2","r29","r30","memory"); \
75 } while (0)
76
77 #define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
78 do { \
79 __asm__ volatile ("1: ld4 r29=%1\n" \
80 ";;\n" \
81 "mov ar.ccv=r29\n" \
82 "mov r2=r29\n" \
83 "and r29=-4,r29\n" \
84 ";;\n" \
85 "cmpxchg4.acq r30=%1,r29,ar.ccv\n" \
86 ";;\n" \
87 "cmp.eq p6,p7=r2,r30\n" \
88 "(p7) br.dpnt.few 1b\n" \
89 "and %0=1,r2\n" \
90 ";;\n" \
91 :"=r"(Acq):"m"(GLptr):"r2","r29","r30","memory"); \
92 } while (0)
93 /*! [End] no source code translation !*/
94
95 #elif defined (_AMD64_)
96
97 #define COMPILER_DEPENDENT_UINT64 unsigned long long
98 #define ACPI_ASM_MACROS
99 #define causeinterrupt(level)
100 #define BREAKPOINT3
101 #define disable() __cli()
102 #define enable() __sti()
103 #define halt() __asm__ __volatile__ ("sti; hlt":::"memory")
104 #define wbinvd()
105
106 /*! [Begin] no source code translation
107 *
108 * A brief explanation as GNU inline assembly is a bit hairy
109 * %0 is the output parameter in EAX ("=a")
110 * %1 and %2 are the input parameters in ECX ("c")
111 * and an immediate value ("i") respectively
112 * All actual register references are preceded with "%%" as in "%%edx"
113 * Immediate values in the assembly are preceded by "$" as in "$0x1"
114 * The final asm parameter are the operation altered non-output registers.
115 */
116
117 // FIXME: These are only sonly stubs to make it compile
118
119 #define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
120 do { \
121 int dummy; \
122 asm("1: movl (%1),%%eax;" \
123 "movl %%eax,%%edx;" \
124 :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~1L):"dx"); \
125 } while(0)
126
127 #define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
128 do { \
129 int dummy; \
130 asm("1: movl (%1),%%eax;" \
131 "movl %%eax,%%edx;" \
132 :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~3L):"dx"); \
133 } while(0)
134
135 /*! [End] no source code translation !*/
136
137 #else /* DO IA32 */
138
139 #define COMPILER_DEPENDENT_UINT64 unsigned long long
140 #define ACPI_ASM_MACROS
141 #define causeinterrupt(level)
142 #define BREAKPOINT3
143 #define disable() __cli()
144 #define enable() __sti()
145 #define halt() __asm__ __volatile__ ("sti; hlt":::"memory")
146 #define wbinvd()
147
148 /*! [Begin] no source code translation
149 *
150 * A brief explanation as GNU inline assembly is a bit hairy
151 * %0 is the output parameter in EAX ("=a")
152 * %1 and %2 are the input parameters in ECX ("c")
153 * and an immediate value ("i") respectively
154 * All actual register references are preceded with "%%" as in "%%edx"
155 * Immediate values in the assembly are preceded by "$" as in "$0x1"
156 * The final asm parameter are the operation altered non-output registers.
157 */
158 #define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \
159 do { \
160 int dummy; \
161 asm("1: movl (%1),%%eax;" \
162 "movl %%eax,%%edx;" \
163 "andl %2,%%edx;" \
164 "btsl $0x1,%%edx;" \
165 "adcl $0x0,%%edx;" \
166 "lock; cmpxchgl %%edx,(%1);" \
167 "jnz 1b;" \
168 "cmpb $0x3,%%dl;" \
169 "sbbl %%eax,%%eax" \
170 :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~1L):"dx"); \
171 } while(0)
172
173 #define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \
174 do { \
175 int dummy; \
176 asm("1: movl (%1),%%eax;" \
177 "movl %%eax,%%edx;" \
178 "andl %2,%%edx;" \
179 "lock; cmpxchgl %%edx,(%1);" \
180 "jnz 1b;" \
181 "andl $0x1,%%eax" \
182 :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~3L):"dx"); \
183 } while(0)
184
185 /*! [End] no source code translation !*/
186
187 #endif /* IA 32 */
188
189 #endif /* __ACGCC_H__ */