| 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Name: acwin.h - OS specific defines, etc. |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2026, 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 MERCHANTABILITY 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 | /* Disable these warnings under Windows and MSVC since C4201: nameless |
| 74 | * structs/unions are needed as ACPI event-handling under Linux/GCC breaks |
| 75 | * with named and nested structs/unions while C4068: unknown pragma |
| 76 | * complains of GCC pragmas in use to disable dangling ptr warnings |
| 77 | */ |
| 78 | |
| 79 | #pragma warning( disable: 4201) |
| 80 | #pragma warning( disable: 4068) |
| 81 | #pragma warning( disable: 4214) |
| 82 | #pragma warning( push) |
| 83 | |
| 84 | #define ACPI_MACHINE_WIDTH 32 |
| 85 | #define ACPI_USE_NATIVE_DIVIDE |
| 86 | #define ACPI_USE_NATIVE_MATH64 |
| 87 | |
| 88 | #ifdef ACPI_DEFINE_ALTERNATE_TYPES |
| 89 | /* |
| 90 | * Types used only in (Linux) translated source, defined here to enable |
| 91 | * cross-platform compilation (i.e., generate the Linux code on Windows, |
| 92 | * for test purposes only) |
| 93 | */ |
| 94 | typedef int s32; |
| 95 | typedef unsigned char u8; |
| 96 | typedef unsigned short u16; |
| 97 | typedef unsigned int u32; |
| 98 | typedef COMPILER_DEPENDENT_UINT64 u64; |
| 99 | #endif |
| 100 | |
| 101 | /* |
| 102 | * Map low I/O functions for MS. This allows us to disable MS language |
| 103 | * extensions for maximum portability. |
| 104 | */ |
| 105 | #define open _open |
| 106 | #define read _read |
| 107 | #define write _write |
| 108 | #define close _close |
| 109 | #define stat _stat |
| 110 | #define fstat _fstat |
| 111 | #define mkdir _mkdir |
| 112 | #define fileno _fileno |
| 113 | #define isatty _isatty |
| 114 | |
| 115 | #if _MSC_VER <= 1200 /* Versions below VC++ 6 */ |
| 116 | #define vsnprintf _vsnprintf |
| 117 | #endif |
| 118 | #define O_RDONLY _O_RDONLY |
| 119 | #define O_BINARY _O_BINARY |
| 120 | #define O_CREAT _O_CREAT |
| 121 | #define O_WRONLY _O_WRONLY |
| 122 | #define O_TRUNC _O_TRUNC |
| 123 | #define S_IREAD _S_IREAD |
| 124 | #define S_IWRITE _S_IWRITE |
| 125 | #define S_IFDIR _S_IFDIR |
| 126 | #if _MSC_VER < 1900 |
| 127 | #define snprintf _snprintf |
| 128 | #endif |
| 129 | |
| 130 | |
| 131 | /* |
| 132 | * Handle platform- and compiler-specific assembly language differences. |
| 133 | * |
| 134 | * Notes: |
| 135 | * 1) Interrupt 3 is used to break into a debugger |
| 136 | * 2) Interrupts are turned off during ACPI register setup |
| 137 | */ |
| 138 | |
| 139 | /*! [Begin] no source code translation */ |
| 140 | |
| 141 | #ifdef ACPI_APPLICATION |
| 142 | #define ACPI_FLUSH_CPU_CACHE() |
| 143 | #else |
| 144 | #define ACPI_FLUSH_CPU_CACHE() __asm {WBINVD} |
| 145 | #endif |
| 146 | |
| 147 | #ifdef _DEBUG |
| 148 | #define ACPI_SIMPLE_RETURN_MACROS |
| 149 | #endif |
| 150 | |
| 151 | /*! [End] no source code translation !*/ |
| 152 | |
| 153 | /* |
| 154 | * Global Lock acquire/release code |
| 155 | * |
| 156 | * Note: Handles case where the FACS pointer is null |
| 157 | */ |
| 158 | #define ACPI_ACQUIRE_GLOBAL_LOCK(FacsPtr, Acq) __asm \ |
| 159 | { \ |
| 160 | __asm mov eax, 0xFF \ |
| 161 | __asm mov ecx, FacsPtr \ |
| 162 | __asm or ecx, ecx \ |
| 163 | __asm jz exit_acq \ |
| 164 | __asm lea ecx, [ecx].GlobalLock \ |
| 165 | \ |
| 166 | __asm acq10: \ |
| 167 | __asm mov eax, [ecx] \ |
| 168 | __asm mov edx, eax \ |
| 169 | __asm and edx, 0xFFFFFFFE \ |
| 170 | __asm bts edx, 1 \ |
| 171 | __asm adc edx, 0 \ |
| 172 | __asm lock cmpxchg dword ptr [ecx], edx \ |
| 173 | __asm jnz acq10 \ |
| 174 | \ |
| 175 | __asm cmp dl, 3 \ |
| 176 | __asm sbb eax, eax \ |
| 177 | \ |
| 178 | __asm exit_acq: \ |
| 179 | __asm mov Acq, al \ |
| 180 | } |
| 181 | |
| 182 | #define ACPI_RELEASE_GLOBAL_LOCK(FacsPtr, Pnd) __asm \ |
| 183 | { \ |
| 184 | __asm xor eax, eax \ |
| 185 | __asm mov ecx, FacsPtr \ |
| 186 | __asm or ecx, ecx \ |
| 187 | __asm jz exit_rel \ |
| 188 | __asm lea ecx, [ecx].GlobalLock \ |
| 189 | \ |
| 190 | __asm Rel10: \ |
| 191 | __asm mov eax, [ecx] \ |
| 192 | __asm mov edx, eax \ |
| 193 | __asm and edx, 0xFFFFFFFC \ |
| 194 | __asm lock cmpxchg dword ptr [ecx], edx \ |
| 195 | __asm jnz Rel10 \ |
| 196 | \ |
| 197 | __asm cmp dl, 3 \ |
| 198 | __asm and eax, 1 \ |
| 199 | \ |
| 200 | __asm exit_rel: \ |
| 201 | __asm mov Pnd, al \ |
| 202 | } |
| 203 | |
| 204 | #endif /* __ACWIN_H__ */ |