From 7ffce2077e4d1ee30308e539aca38c05152e7aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Thu, 3 Apr 2014 22:03:14 +0000 Subject: [PATCH] [ACPICA] Do not assume that, when compiling from Windows, we cannot use GCC. In fact we can, and this is what we did before... Move asm-specific code to where it should belong. I've checked that: MSVC_asm_code(old_acpica_version) == MSVC_asm_code(new_acpica_version), so that I took its GCC equivalent from our old version of ACPICA and placed it there. Part 1 of our modifications to ACPICA code. CORE-8044 svn path=/trunk/; revision=62605 --- .../bus/acpi/acpica/include/platform/acgcc.h | 61 ++++++++++++++++++ .../bus/acpi/acpica/include/platform/acmsvc.h | 61 ++++++++++++++++++ .../bus/acpi/acpica/include/platform/acwin.h | 63 ++----------------- 3 files changed, 126 insertions(+), 59 deletions(-) diff --git a/reactos/drivers/bus/acpi/acpica/include/platform/acgcc.h b/reactos/drivers/bus/acpi/acpica/include/platform/acgcc.h index 9cb3cbe5c00..e03b9bace60 100644 --- a/reactos/drivers/bus/acpi/acpica/include/platform/acgcc.h +++ b/reactos/drivers/bus/acpi/acpica/include/platform/acgcc.h @@ -147,4 +147,65 @@ #undef strchr #endif + +/* Flush CPU cache - used when going to sleep. Wbinvd or similar. */ + +#ifdef ACPI_APPLICATION +#define ACPI_FLUSH_CPU_CACHE() +#else +#define ACPI_FLUSH_CPU_CACHE() asm ("WBINVD") +#endif + +/* + * Global Lock acquire/release code + * + * Note: Taken from our old adaptation. + * TODO: Check whether it is equivalent to the MSVC code + * (which was also the same in the older version). + */ +#define ACPI_ACQUIRE_GLOBAL_LOCK(GLptr, Acq) \ +do { \ + int dummy; \ + asm("1: movl (%1),%%eax;" \ + "movl %%eax,%%edx;" \ + "andl %2,%%edx;" \ + "btsl $0x1,%%edx;" \ + "adcl $0x0,%%edx;" \ + "lock; cmpxchgl %%edx,(%1);" \ + "jnz 1b;" \ + "cmpb $0x3,%%dl;" \ + "sbbl %%eax,%%eax" \ + :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~1L):"dx"); \ +} while(0) + +#define ACPI_RELEASE_GLOBAL_LOCK(GLptr, Acq) \ +do { \ + int dummy; \ + asm("1: movl (%1),%%eax;" \ + "movl %%eax,%%edx;" \ + "andl %2,%%edx;" \ + "lock; cmpxchgl %%edx,(%1);" \ + "jnz 1b;" \ + "andl $0x1,%%eax" \ + :"=a"(Acq),"=c"(dummy):"c"(GLptr),"i"(~3L):"dx"); \ +} while(0) + + +/* + * Note: This is also taken from our old adaptation. + * See acmsvc.h for where it came originally. + */ +#define ACPI_DIV_64_BY_32(n_hi, n_lo, d32, q32, r32) \ +{ \ + q32 = n_hi / d32; \ + r32 = n_lo / d32; \ +} + +#define ACPI_SHIFT_RIGHT_64(n_hi, n_lo) \ +{ \ + n_hi >>= 1; \ + n_lo >>= 1; \ +} + + #endif /* __ACGCC_H__ */ diff --git a/reactos/drivers/bus/acpi/acpica/include/platform/acmsvc.h b/reactos/drivers/bus/acpi/acpica/include/platform/acmsvc.h index c9475eadd3c..1748c9a65fc 100644 --- a/reactos/drivers/bus/acpi/acpica/include/platform/acmsvc.h +++ b/reactos/drivers/bus/acpi/acpica/include/platform/acmsvc.h @@ -202,6 +202,67 @@ } #endif + +/* Flush CPU cache - used when going to sleep. Wbinvd or similar. */ + +#ifdef ACPI_APPLICATION +#define ACPI_FLUSH_CPU_CACHE() +#else +#define ACPI_FLUSH_CPU_CACHE() __asm {WBINVD} +#endif + +/* + * Global Lock acquire/release code + * + * Note: Handles case where the FACS pointer is null + */ +#define ACPI_ACQUIRE_GLOBAL_LOCK(FacsPtr, Acq) __asm \ +{ \ + __asm mov eax, 0xFF \ + __asm mov ecx, FacsPtr \ + __asm or ecx, ecx \ + __asm jz exit_acq \ + __asm lea ecx, [ecx].GlobalLock \ + \ + __asm acq10: \ + __asm mov eax, [ecx] \ + __asm mov edx, eax \ + __asm and edx, 0xFFFFFFFE \ + __asm bts edx, 1 \ + __asm adc edx, 0 \ + __asm lock cmpxchg dword ptr [ecx], edx \ + __asm jnz acq10 \ + \ + __asm cmp dl, 3 \ + __asm sbb eax, eax \ + \ + __asm exit_acq: \ + __asm mov Acq, al \ +} + +#define ACPI_RELEASE_GLOBAL_LOCK(FacsPtr, Pnd) __asm \ +{ \ + __asm xor eax, eax \ + __asm mov ecx, FacsPtr \ + __asm or ecx, ecx \ + __asm jz exit_rel \ + __asm lea ecx, [ecx].GlobalLock \ + \ + __asm Rel10: \ + __asm mov eax, [ecx] \ + __asm mov edx, eax \ + __asm and edx, 0xFFFFFFFC \ + __asm lock cmpxchg dword ptr [ecx], edx \ + __asm jnz Rel10 \ + \ + __asm cmp dl, 3 \ + __asm and eax, 1 \ + \ + __asm exit_rel: \ + __asm mov Pnd, al \ +} + + /* warn C4100: unreferenced formal parameter */ #pragma warning(disable:4100) diff --git a/reactos/drivers/bus/acpi/acpica/include/platform/acwin.h b/reactos/drivers/bus/acpi/acpica/include/platform/acwin.h index cf1a5eea2ea..d6645ab5bd9 100644 --- a/reactos/drivers/bus/acpi/acpica/include/platform/acwin.h +++ b/reactos/drivers/bus/acpi/acpica/include/platform/acwin.h @@ -118,9 +118,11 @@ /*! [Begin] no source code translation (Keep the include) */ -/* Windows uses VC */ -#ifdef _MSC_VER +/* Windows uses VC or GCC */ +#if defined(_MSC_VER) #include "acmsvc.h" +#elif defined(__GNUC__) +#include "acgcc.h" #endif /*! [End] no source code translation !*/ @@ -152,67 +154,10 @@ typedef COMPILER_DEPENDENT_UINT64 u64; /*! [Begin] no source code translation */ -#ifdef ACPI_APPLICATION -#define ACPI_FLUSH_CPU_CACHE() -#else -#define ACPI_FLUSH_CPU_CACHE() __asm {WBINVD} -#endif - #ifdef _DEBUG #define ACPI_SIMPLE_RETURN_MACROS #endif /*! [End] no source code translation !*/ -/* - * Global Lock acquire/release code - * - * Note: Handles case where the FACS pointer is null - */ -#define ACPI_ACQUIRE_GLOBAL_LOCK(FacsPtr, Acq) __asm \ -{ \ - __asm mov eax, 0xFF \ - __asm mov ecx, FacsPtr \ - __asm or ecx, ecx \ - __asm jz exit_acq \ - __asm lea ecx, [ecx].GlobalLock \ - \ - __asm acq10: \ - __asm mov eax, [ecx] \ - __asm mov edx, eax \ - __asm and edx, 0xFFFFFFFE \ - __asm bts edx, 1 \ - __asm adc edx, 0 \ - __asm lock cmpxchg dword ptr [ecx], edx \ - __asm jnz acq10 \ - \ - __asm cmp dl, 3 \ - __asm sbb eax, eax \ - \ - __asm exit_acq: \ - __asm mov Acq, al \ -} - -#define ACPI_RELEASE_GLOBAL_LOCK(FacsPtr, Pnd) __asm \ -{ \ - __asm xor eax, eax \ - __asm mov ecx, FacsPtr \ - __asm or ecx, ecx \ - __asm jz exit_rel \ - __asm lea ecx, [ecx].GlobalLock \ - \ - __asm Rel10: \ - __asm mov eax, [ecx] \ - __asm mov edx, eax \ - __asm and edx, 0xFFFFFFFC \ - __asm lock cmpxchg dword ptr [ecx], edx \ - __asm jnz Rel10 \ - \ - __asm cmp dl, 3 \ - __asm and eax, 1 \ - \ - __asm exit_rel: \ - __asm mov Pnd, al \ -} - #endif /* __ACWIN_H__ */