1 /****************************************************************************** 2 * 3 * Name: acwin.h - OS specific defines, etc. 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2020, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 #ifndef __ACWIN_H__ 45 #define __ACWIN_H__ 46 47 #include <io.h> 48 49 #define ACPI_USE_STANDARD_HEADERS 50 #define ACPI_USE_SYSTEM_CLIBRARY 51 52 /* Note: do not include any C library headers here */ 53 54 /* 55 * Note: MSVC project files should define ACPI_DEBUGGER and ACPI_DISASSEMBLER 56 * as appropriate to enable editor functions like "Find all references". 57 * The editor isn't smart enough to dig through the include files to find 58 * out if these are actually defined. 59 */ 60 61 /* Eliminate warnings for "old" (non-secure) versions of clib functions */ 62 63 #ifndef _CRT_SECURE_NO_WARNINGS 64 #define _CRT_SECURE_NO_WARNINGS 65 #endif 66 67 /* Eliminate warnings for POSIX clib function names (open, write, etc.) */ 68 69 #ifndef _CRT_NONSTDC_NO_DEPRECATE 70 #define _CRT_NONSTDC_NO_DEPRECATE 71 #endif 72 73 74 #define ACPI_MACHINE_WIDTH 32 75 #define ACPI_USE_NATIVE_DIVIDE 76 #define ACPI_USE_NATIVE_MATH64 77 78 #ifdef ACPI_DEFINE_ALTERNATE_TYPES 79 /* 80 * Types used only in (Linux) translated source, defined here to enable 81 * cross-platform compilation (i.e., generate the Linux code on Windows, 82 * for test purposes only) 83 */ 84 typedef int s32; 85 typedef unsigned char u8; 86 typedef unsigned short u16; 87 typedef unsigned int u32; 88 typedef COMPILER_DEPENDENT_UINT64 u64; 89 #endif 90 91 /* 92 * Map low I/O functions for MS. This allows us to disable MS language 93 * extensions for maximum portability. 94 */ 95 #define open _open 96 #define read _read 97 #define write _write 98 #define close _close 99 #define stat _stat 100 #define fstat _fstat 101 #define mkdir _mkdir 102 #define fileno _fileno 103 #define isatty _isatty 104 105 #if _MSC_VER <= 1200 /* Versions below VC++ 6 */ 106 #define vsnprintf _vsnprintf 107 #endif 108 #define O_RDONLY _O_RDONLY 109 #define O_BINARY _O_BINARY 110 #define O_CREAT _O_CREAT 111 #define O_WRONLY _O_WRONLY 112 #define O_TRUNC _O_TRUNC 113 #define S_IREAD _S_IREAD 114 #define S_IWRITE _S_IWRITE 115 #define S_IFDIR _S_IFDIR 116 #if _MSC_VER < 1900 117 #define snprintf _snprintf 118 #endif 119 120 121 /* 122 * Handle platform- and compiler-specific assembly language differences. 123 * 124 * Notes: 125 * 1) Interrupt 3 is used to break into a debugger 126 * 2) Interrupts are turned off during ACPI register setup 127 */ 128 129 /*! [Begin] no source code translation */ 130 131 #ifndef __REACTOS__ 132 #ifdef ACPI_APPLICATION 133 #define ACPI_FLUSH_CPU_CACHE() 134 #else 135 #define ACPI_FLUSH_CPU_CACHE() __asm {WBINVD} 136 #endif 137 #endif /* __REACTOS__ */ 138 139 #ifdef _DEBUG 140 #define ACPI_SIMPLE_RETURN_MACROS 141 #endif 142 143 /*! [End] no source code translation !*/ 144 145 #ifndef __REACTOS__ 146 /* 147 * Global Lock acquire/release code 148 * 149 * Note: Handles case where the FACS pointer is null 150 */ 151 #define ACPI_ACQUIRE_GLOBAL_LOCK(FacsPtr, Acq) __asm \ 152 { \ 153 __asm mov eax, 0xFF \ 154 __asm mov ecx, FacsPtr \ 155 __asm or ecx, ecx \ 156 __asm jz exit_acq \ 157 __asm lea ecx, [ecx].GlobalLock \ 158 \ 159 __asm acq10: \ 160 __asm mov eax, [ecx] \ 161 __asm mov edx, eax \ 162 __asm and edx, 0xFFFFFFFE \ 163 __asm bts edx, 1 \ 164 __asm adc edx, 0 \ 165 __asm lock cmpxchg dword ptr [ecx], edx \ 166 __asm jnz acq10 \ 167 \ 168 __asm cmp dl, 3 \ 169 __asm sbb eax, eax \ 170 \ 171 __asm exit_acq: \ 172 __asm mov Acq, al \ 173 } 174 175 #define ACPI_RELEASE_GLOBAL_LOCK(FacsPtr, Pnd) __asm \ 176 { \ 177 __asm xor eax, eax \ 178 __asm mov ecx, FacsPtr \ 179 __asm or ecx, ecx \ 180 __asm jz exit_rel \ 181 __asm lea ecx, [ecx].GlobalLock \ 182 \ 183 __asm Rel10: \ 184 __asm mov eax, [ecx] \ 185 __asm mov edx, eax \ 186 __asm and edx, 0xFFFFFFFC \ 187 __asm lock cmpxchg dword ptr [ecx], edx \ 188 __asm jnz Rel10 \ 189 \ 190 __asm cmp dl, 3 \ 191 __asm and eax, 1 \ 192 \ 193 __asm exit_rel: \ 194 __asm mov Pnd, al \ 195 } 196 #endif /* __REACTOS__ */ 197 198 #endif /* __ACWIN_H__ */ 199