diff --git a/reactos/hal/halx86/beep.c b/reactos/hal/halx86/beep.c index 4bc08daf467..08b3adf2cd2 100644 --- a/reactos/hal/halx86/beep.c +++ b/reactos/hal/halx86/beep.c @@ -11,6 +11,7 @@ /* INCLUDES *****************************************************************/ #include +#include #define NDEBUG #include @@ -38,18 +39,12 @@ HalMakeBeep ( ULONG Frequency ) { - UCHAR b; + UCHAR b; + ULONG flags; /* save flags and disable interrupts */ -#if defined(__GNUC__) - __asm__("pushf\n\t" \ - "cli\n\t"); -#elif defined(_MSC_VER) - __asm pushfd - __asm cli -#else -#error Unknown compiler for inline assembler -#endif + Ki386SaveFlags(flags); + Ki386DisableInterrupts(); /* speaker off */ b = READ_PORT_UCHAR((PUCHAR)PORT_B); @@ -62,13 +57,7 @@ HalMakeBeep ( if (Divider > 0x10000) { /* restore flags */ -#if defined(__GNUC__) - __asm__("popf\n\t"); -#elif defined(_MSC_VER) - __asm popfd -#else -#error Unknown compiler for inline assembler -#endif + Ki386RestoreFlags(flags); return FALSE; } @@ -83,13 +72,7 @@ HalMakeBeep ( } /* restore flags */ -#if defined(__GNUC__) - __asm__("popf\n\t"); -#elif defined(_MSC_VER) - __asm popfd -#else -#error Unknown compiler for inline assembler -#endif + Ki386RestoreFlags(flags); return TRUE; } diff --git a/reactos/hal/halx86/display.c b/reactos/hal/halx86/display.c index 2ba9975658c..e632cf8ceac 100644 --- a/reactos/hal/halx86/display.c +++ b/reactos/hal/halx86/display.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: display.c,v 1.14 2004/03/16 22:45:55 dwelch Exp $ +/* $Id: display.c,v 1.15 2004/07/20 21:25:36 hbirr Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -122,7 +122,7 @@ */ #include -#include +#include #define SCREEN_SYNCHRONIZATION @@ -681,18 +681,12 @@ HalDisplayString(IN PCH String) pch = String; - pushfl(Flags); - -#if defined(__GNUC__) - __asm__ ("cli\n\t"); -#elif defined(_MSC_VER) - __asm cli -#else -#error Unknown compiler for inline assembler -#endif - KiAcquireSpinLock(&Lock); + Ki386SaveFlags(Flags); + Ki386DisableInterrupts(); + + #if 0 if (HalOwnsDisplay == FALSE) { @@ -753,8 +747,8 @@ HalDisplayString(IN PCH String) WRITE_PORT_UCHAR((PUCHAR)VGA_CRTC_INDEX, CRTC_CURHI); WRITE_PORT_UCHAR((PUCHAR)VGA_CRTC_DATA, (UCHAR)((offset >> 8) & 0xff)); #endif + Ki386RestoreFlags(Flags); KiReleaseSpinLock(&Lock); - popfl(Flags); } VOID STDCALL diff --git a/reactos/hal/halx86/include/hal.h b/reactos/hal/halx86/include/hal.h index d6cce42a725..f0c198fc244 100644 --- a/reactos/hal/halx86/include/hal.h +++ b/reactos/hal/halx86/include/hal.h @@ -76,5 +76,24 @@ HalReleaseDisplayOwnership(); BOOLEAN STDCALL HalQueryDisplayOwnership(); +#if defined(__GNUC__) +#define Ki386SaveFlags(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */) +#define Ki386RestoreFlags(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory") +#define Ki386DisableInterrupts() __asm__ __volatile__("cli\n\t") +#define Ki386EnableInterrupts() __asm__ __volatile__("sti\n\t") +#define Ki386HaltProcessor() __asm__ __volatile__("hlt\n\t") +#elif defined(_MSC_VER) +#define Ki386SaveFlags(x) __asm pushfd __asm pop x; +#define Ki386RestoreFlags(x) __asm push x __asm popfd; +#define Ki386DisableInterrupts() __asm cli +#define Ki386EnableInterrupts() __asm sti +#define Ki386HaltProcessor() __asm hlt +#else +#error Unknown compiler for inline assembler +#endif + + + + #endif /* __INTERNAL_HAL_HAL_H */ diff --git a/reactos/hal/halx86/include/mps.h b/reactos/hal/halx86/include/mps.h index 0c9466b2836..519d88c0f24 100644 --- a/reactos/hal/halx86/include/mps.h +++ b/reactos/hal/halx86/include/mps.h @@ -423,17 +423,6 @@ typedef enum { } APIC_MODE; -#if defined(__GNUC__) -#define pushfl(x) __asm__ __volatile__("pushfl ; popl %0":"=g" (x): /* no input */) -#define popfl(x) __asm__ __volatile__("pushl %0 ; popfl": /* no output */ :"g" (x):"memory") -#elif defined(_MSC_VER) -#define pushfl(x) __asm pushfd __asm pop x; -#define popfl(x) __asm push x __asm popfd; -#else -#error Unknown compiler for inline assembler -#endif - - #define PIC_IRQS 16 /* Prototypes */ diff --git a/reactos/hal/halx86/irql.c b/reactos/hal/halx86/irql.c index 527a42a6f55..a3f4d1f8d48 100644 --- a/reactos/hal/halx86/irql.c +++ b/reactos/hal/halx86/irql.c @@ -1,4 +1,4 @@ -/* $Id: irql.c,v 1.14 2003/12/28 22:38:09 fireball Exp $ +/* $Id: irql.c,v 1.15 2004/07/20 21:25:36 hbirr Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -10,9 +10,9 @@ /* INCLUDES *****************************************************************/ #include -#include #include #include +#include #define NDEBUG #include @@ -103,13 +103,7 @@ VOID HalpInitPICs(VOID) WRITE_PORT_UCHAR((PUCHAR)0xa1, pic_mask.slave); /* We can now enable interrupts */ -#if defined(__GNUC__) - __asm__ __volatile__ ("sti\n\t"); -#elif defined(_MSC_VER) - __asm sti -#else -#error Unknown compiler for inline assembler -#endif + Ki386EnableInterrupts(); } VOID HalpEndSystemInterrupt(KIRQL Irql) @@ -117,6 +111,7 @@ VOID HalpEndSystemInterrupt(KIRQL Irql) * FUNCTION: Enable all irqs with higher priority. */ { + ULONG flags; const USHORT mask[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -126,26 +121,15 @@ VOID HalpEndSystemInterrupt(KIRQL Irql) }; /* Interrupts should be disable while enabling irqs of both pics */ -#if defined(__GNUC__) - __asm__("pushf\n\t"); - __asm__("cli\n\t"); -#elif defined(_MSC_VER) - __asm pushfd - __asm cli -#else -#error Unknown compiler for inline assembler -#endif + Ki386SaveFlags(flags); + Ki386DisableInterrupts(); pic_mask_intr.both &= mask[Irql]; WRITE_PORT_UCHAR((PUCHAR)0x21, (UCHAR)(pic_mask.master|pic_mask_intr.master)); WRITE_PORT_UCHAR((PUCHAR)0xa1, (UCHAR)(pic_mask.slave|pic_mask_intr.slave)); -#if defined(__GNUC__) - __asm__("popf\n\t"); -#elif defined(_MSC_VER) - __asm popfd -#else -#error Unknown compiler for inline assembler -#endif + + /* restore flags */ + Ki386RestoreFlags(flags); } VOID STATIC diff --git a/reactos/hal/halx86/misc.c b/reactos/hal/halx86/misc.c index 0f2874f06f0..26957184dee 100644 --- a/reactos/hal/halx86/misc.c +++ b/reactos/hal/halx86/misc.c @@ -1,4 +1,4 @@ -/* $Id: misc.c,v 1.4 2003/12/28 22:38:09 fireball Exp $ +/* $Id: misc.c,v 1.5 2004/07/20 21:25:36 hbirr Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -39,19 +39,8 @@ HalProcessorIdle (VOID) { #if 1 -#if defined(__GNUC__) - - __asm__("sti\n\t" \ - "hlt\n\t"); - -#elif defined(_MSC_VER) - - __asm sti - __asm hlt - -#else -#error Unknown compiler for inline assembler -#endif + Ki386EnableInterrupts(); + Ki386HaltProcessor(); #else diff --git a/reactos/hal/halx86/mp.c b/reactos/hal/halx86/mp.c index c3b814f8b52..7cb7853a974 100644 --- a/reactos/hal/halx86/mp.c +++ b/reactos/hal/halx86/mp.c @@ -1,4 +1,4 @@ -/* $Id: mp.c,v 1.9 2003/12/28 22:38:09 fireball Exp $ +/* $Id: mp.c,v 1.10 2004/07/20 21:25:36 hbirr Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -724,7 +724,7 @@ static VOID IOAPICSetup( VOID IOAPICDump(VOID) { ULONG apic, i; - ULONG reg0, reg1, reg2; + ULONG reg0, reg1, reg2=0; DbgPrint("Number of MP IRQ sources: %d.\n", IRQCount); for (i = 0; i < IOAPICCount; i++) { @@ -1046,7 +1046,7 @@ static VOID APICDumpBit(ULONG base) DbgPrint("0123456789abcdef0123456789abcdef\n"); for (i = 0; i < 8; i++) { - APICRead(base + i*0x10); + v = APICRead(base + i*0x10); for (j = 0; j < 32; j++) { if (v & (1<Feature2 & FEATURE2_IMCRP) { APICMode = amPIC; - DPRINT("Running in IMCR and PIC compatibility mode.\n") + DPRINT("Running in IMCR and PIC compatibility mode.\n"); } else { APICMode = amVWIRE; DPRINT("Running in Virtual Wire compatibility mode.\n"); @@ -2415,13 +2398,7 @@ HalpInitMPS( HalpCalibrateStallExecution(); /* We can now enable interrupts */ -#if defined(__GNUC__) - __asm__ __volatile__ ("sti\n\t"); -#elif defined(_MSC_VER) - __asm sti -#else -#error Unknown compiler for inline assembler -#endif + Ki386EnableInterrupts(); NextCPU = 0; } diff --git a/reactos/hal/halx86/mpsirql.c b/reactos/hal/halx86/mpsirql.c index 7f6b8f7c801..b7669505850 100644 --- a/reactos/hal/halx86/mpsirql.c +++ b/reactos/hal/halx86/mpsirql.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #define NDEBUG @@ -76,20 +77,12 @@ VOID HalpEndSystemInterrupt (KIRQL Irql) * FUNCTION: Enable all irqs with higher priority. */ { + ULONG flags; /* Interrupts should be disabled while enabling irqs */ -#if defined(__GNUC__) - __asm__("pushf\n\t"); - __asm__("cli\n\t"); + Ki386SaveFlags(flags); + Ki386DisableInterrupts(); APICWrite (APIC_TPR, IRQL2TPR (Irql) & APIC_TPR_PRI); - __asm__("popf\n\t"); -#elif defined(_MSC_VER) - __asm pushfd - __asm cli - APICWrite (APIC_TPR, IRQL2TPR (Irql) & APIC_TPR_PRI); - __asm popfd -#else -#error Unknown compiler for inline assembler -#endif + Ki386RestoreFlags(flags); } diff --git a/reactos/hal/halx86/reboot.c b/reactos/hal/halx86/reboot.c index 20aa51cd9c9..76f444ceb7d 100644 --- a/reactos/hal/halx86/reboot.c +++ b/reactos/hal/halx86/reboot.c @@ -1,4 +1,4 @@ -/* $Id: reboot.c,v 1.6 2004/03/18 19:58:35 dwelch Exp $ +/* $Id: reboot.c,v 1.7 2004/07/20 21:25:36 hbirr Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -25,13 +25,7 @@ HalReboot (VOID) ((PUCHAR)HalpZeroPageMapping)[0x473] = 0x12; /* disable interrupts */ -#if defined(__GNUC__) - __asm__("cli\n"); -#elif defined(_MSC_VER) - __asm cli -#else -#error Unknown compiler for inline assembler -#endif + Ki386DisableInterrupts(); /* disable periodic interrupt (RTC) */ @@ -52,15 +46,8 @@ HalReboot (VOID) /* stop the processor */ #if 1 -#if defined(__GNUC__) - __asm__("hlt\n"); -#elif defined(_MSC_VER) - __asm hlt -#else -#error Unknown compiler for inline assembler -#endif -#else - for(;;); + Ki386HaltProcessor(); + for(;;); #endif } diff --git a/reactos/hal/halx86/time.c b/reactos/hal/halx86/time.c index 8ae5d063d18..8641bfffc6f 100644 --- a/reactos/hal/halx86/time.c +++ b/reactos/hal/halx86/time.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include #define NDEBUG @@ -46,18 +46,17 @@ HalpQueryCMOS(UCHAR Reg) ULONG Flags; Reg |= 0x80; - pushfl(Flags); -#if defined(__GNUC__) - __asm__("cli\n"); // AP unsure as to whether to do this here -#elif defined(_MSC_VER) - __asm cli -#else -#error Unknown compiler for inline assembler -#endif + + /* save flags and disable interrupts */ + Ki386SaveFlags(Flags); + Ki386DisableInterrupts(); + WRITE_PORT_UCHAR((PUCHAR)0x70, Reg); Val = READ_PORT_UCHAR((PUCHAR)0x71); WRITE_PORT_UCHAR((PUCHAR)0x70, 0); - popfl(Flags); + + /* restore flags */ + Ki386RestoreFlags(Flags); return(Val); } @@ -70,18 +69,17 @@ HalpSetCMOS(UCHAR Reg, ULONG Flags; Reg |= 0x80; - pushfl(Flags); -#if defined(__GNUC__) - __asm__("cli\n"); // AP unsure as to whether to do this here -#elif defined(_MSC_VER) - __asm cli -#else -#error Unknown compiler for inline assembler -#endif + + /* save flags and disable interrupts */ + Ki386SaveFlags(Flags); + Ki386DisableInterrupts(); + WRITE_PORT_UCHAR((PUCHAR)0x70, Reg); WRITE_PORT_UCHAR((PUCHAR)0x71, Val); WRITE_PORT_UCHAR((PUCHAR)0x70, 0); - popfl(Flags); + + /* restore flags */ + Ki386RestoreFlags(Flags); } @@ -91,18 +89,16 @@ HalpQueryECMOS(USHORT Reg) UCHAR Val; ULONG Flags; - pushfl(Flags); -#if defined(__GNUC__) - __asm__("cli\n"); // AP unsure as to whether to do this here -#elif defined(_MSC_VER) - __asm cli -#else -#error Unknown compiler for inline assembler -#endif + /* save flags and disable interrupts */ + Ki386SaveFlags(Flags); + Ki386DisableInterrupts(); + WRITE_PORT_UCHAR((PUCHAR)0x74, (UCHAR)(Reg & 0x00FF)); WRITE_PORT_UCHAR((PUCHAR)0x75, (UCHAR)(Reg>>8)); Val = READ_PORT_UCHAR((PUCHAR)0x76); - popfl(Flags); + + /* restore flags */ + Ki386RestoreFlags(Flags); return(Val); } @@ -114,18 +110,16 @@ HalpSetECMOS(USHORT Reg, { ULONG Flags; - pushfl(Flags); -#if defined(__GNUC__) - __asm__("cli\n"); // AP unsure as to whether to do this here -#elif defined(_MSC_VER) - __asm cli -#else -#error Unknown compiler for inline assembler -#endif + /* save flags and disable interrupts */ + Ki386SaveFlags(Flags); + Ki386DisableInterrupts(); + WRITE_PORT_UCHAR((PUCHAR)0x74, (UCHAR)(Reg & 0x00FF)); WRITE_PORT_UCHAR((PUCHAR)0x75, (UCHAR)(Reg>>8)); WRITE_PORT_UCHAR((PUCHAR)0x76, Val); - popfl(Flags); + + /* restore flags */ + Ki386RestoreFlags(Flags); } diff --git a/reactos/hal/halx86/timer.c b/reactos/hal/halx86/timer.c index 05255bebaca..186df53c363 100644 --- a/reactos/hal/halx86/timer.c +++ b/reactos/hal/halx86/timer.c @@ -20,7 +20,7 @@ * MA 02139, USA. * */ -/* $Id: timer.c,v 1.4 2004/05/10 11:13:15 gvg Exp $ +/* $Id: timer.c,v 1.5 2004/07/20 21:25:36 hbirr Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/hal/x86/udelay.c @@ -33,6 +33,7 @@ /* INCLUDES ***************************************************************/ #include +#include #define NDEBUG #include @@ -132,30 +133,18 @@ VOID STDCALL KeStallExecutionProcessor(ULONG Microseconds) static ULONG Read8254Timer(VOID) { ULONG Count; + ULONG flags; /* save flags and disable interrupts */ -#if defined(__GNUC__) - __asm__("pushf\n\t" \ - "cli\n\t"); -#elif defined(_MSC_VER) - __asm pushfd - __asm cli -#else -#error Unknown compiler for inline assembler -#endif + Ki386SaveFlags(flags); + Ki386DisableInterrupts(); WRITE_PORT_UCHAR((PUCHAR) TMR_CTRL, TMR_SC0 | TMR_LATCH); Count = READ_PORT_UCHAR((PUCHAR) TMR_CNT0); Count |= READ_PORT_UCHAR((PUCHAR) TMR_CNT0) << 8; /* restore flags */ -#if defined(__GNUC__) - __asm__("popf\n\t"); -#elif defined(_MSC_VER) - __asm popfd -#else -#error Unknown compiler for inline assembler -#endif + Ki386RestoreFlags(flags); return Count; } @@ -274,28 +263,16 @@ VOID STDCALL HalCalibratePerformanceCounter(ULONG Count) { ULONG i; + ULONG flags; /* save flags and disable interrupts */ -#if defined(__GNUC__) - __asm__("pushf\n\t" \ - "cli\n\t"); -#elif defined(_MSC_VER) - __asm pushfd - __asm cli -#else -#error Unknown compiler for inline assembler -#endif + Ki386SaveFlags(flags); + Ki386DisableInterrupts(); for (i = 0; i < Count; i++); /* restore flags */ -#if defined(__GNUC__) - __asm__("popf\n\t"); -#elif defined(_MSC_VER) - __asm popfd -#else -#error Unknown compiler for inline assembler -#endif + Ki386RestoreFlags(flags); }