ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
June
May
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
August 2006
----- 2025 -----
June 2025
May 2025
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
19 participants
447 discussions
Start a n
N
ew thread
[ion] 23637: - Delete bios.c and usertrap.c - Add Ke entries to KernelFun!
by ion@svn.reactos.org
Author: ion Date: Mon Aug 21 07:49:02 2006 New Revision: 23637 URL:
http://svn.reactos.org/svn/reactos?rev=23637&view=rev
Log: - Delete bios.c and usertrap.c - Add Ke entries to KernelFun! Removed: trunk/reactos/ntoskrnl/ke/i386/bios.c trunk/reactos/ntoskrnl/ke/i386/usertrap.c Modified: trunk/reactos/ntoskrnl/KrnlFun.c trunk/reactos/ntoskrnl/ke/i386/trap.s trunk/reactos/ntoskrnl/ke/i386/v86m.c trunk/reactos/ntoskrnl/ntoskrnl.rbuild Modified: trunk/reactos/ntoskrnl/KrnlFun.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/KrnlFun.c?rev=236…
============================================================================== --- trunk/reactos/ntoskrnl/KrnlFun.c (original) +++ trunk/reactos/ntoskrnl/KrnlFun.c Mon Aug 21 07:49:02 2006 @@ -24,6 +24,20 @@ // - Add Directory Lock. // - Use Object Type Mutex/Lock. // +// Ke: +// - Make sure IRQ trap code is synchronized with current trap code. +// - Reimplement the V86 support using a mode that will be compatible with +// VDM and the future and use ABIOS gates. +// - Implement Invalid Opcode and GPD handlers for V86-mode. +// - Implement stack fault and segment fault handlers. +// - Implement kernel-mode GPF handler, possibly fixing below: +// - Figure out why ES/DS gets messed up in VMWare, when doing KiServiceExit only, +// and only when called from user-mode, and returning to user-mode. +// - Figure out what the DEBUGEIP hack is for and how it can be moved away. +// - Add DR macro/save and VM macro/save. +// - Implement KiCallbackReturn, KiGetTickCount, KiRaiseAssertion. +// +// // Ex: // - Use pushlocks for handle implementation. // Removed: trunk/reactos/ntoskrnl/ke/i386/bios.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/bios.c?re…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/bios.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/bios.c (removed) @@ -1,78 +1,0 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/ke/i386/bios.c - * PURPOSE: Support for calling the BIOS in v86 mode - * - * PROGRAMMERS: David Welch (welch(a)cwcom.net) - */ - -/* INCLUDES *****************************************************************/ - -#include <ntoskrnl.h> -#define NDEBUG -#include <internal/debug.h> - -/* GLOBALS *******************************************************************/ - -#define TRAMPOLINE_BASE (0x10000) - -extern VOID Ki386RetToV86Mode(PKV86M_REGISTERS InRegs, - PKV86M_REGISTERS OutRegs); - -/* FUNCTIONS *****************************************************************/ - -NTSTATUS STDCALL -Ke386CallBios(ULONG Int, PCONTEXT regs) -{ - PUCHAR Ip; - KV86M_REGISTERS ORegs; - NTSTATUS Status; - PKV86M_REGISTERS Regs = (PKV86M_REGISTERS)regs; - - /* - * Set up a trampoline for executing the BIOS interrupt - */ - Ip = (PUCHAR)TRAMPOLINE_BASE; - Ip[0] = 0xCD; /* int XX */ - Ip[1] = Int; - Ip[2] = 0x63; /* arpl ax, ax */ - Ip[3] = 0xC0; - Ip[4] = 0x90; /* nop */ - Ip[5] = 0x90; /* nop */ - - /* - * Munge the registers - */ - Regs->Eip = 0; - Regs->Cs = TRAMPOLINE_BASE / 16; - Regs->Esp = 0xFFFF; - Regs->Ss = TRAMPOLINE_BASE / 16; - Regs->Eflags = (1 << 1) | (1 << 17) | (1 << 9); /* VM, IF */ - Regs->RecoveryAddress = TRAMPOLINE_BASE + 2; - Regs->RecoveryInstruction[0] = 0x63; /* arpl ax, ax */ - Regs->RecoveryInstruction[1] = 0xC0; - Regs->RecoveryInstruction[2] = 0x90; /* nop */ - Regs->RecoveryInstruction[3] = 0x90; /* nop */ - Regs->Flags = KV86M_EMULATE_CLI_STI | KV86M_ALLOW_IO_PORT_ACCESS; - Regs->Vif = 1; - Regs->PStatus = &Status; - - /* - * Execute the BIOS interrupt - */ - Ki386RetToV86Mode(Regs, &ORegs); - - /* - * Copy the return values back to the caller - */ - memcpy(Regs, &ORegs, sizeof(KV86M_REGISTERS)); - - return(Status); -} - - - - - Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?re…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/trap.s (original) +++ trunk/reactos/ntoskrnl/ke/i386/trap.s Mon Aug 21 07:49:02 2006 @@ -11,17 +11,6 @@ #include <asm.h> #include <internal/i386/asmmacro.S> .intel_syntax noprefix - -/* - * FIXMEs: - * - Implement kernel-mode GPF handler, possibly fixing below: - * - Figure out why ES/DS gets messed up in VMWare, when doing KiServiceExit only, - * and only when called from user-mode, and returning to user-mode. - * - Implement Invalid Opcode handler. - * - Figure out what the DEBUGEIP hack is for and how it can be moved away. - * - Add DR macro/save and VM macro/save. - * - Implement KiCallbackReturn, KiGetTickCount, KiRaiseAssertion. - */ /* GLOBALS ******************************************************************/ Removed: trunk/reactos/ntoskrnl/ke/i386/usertrap.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/usertrap.…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/usertrap.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/usertrap.c (removed) @@ -1,1 +1,0 @@ - Modified: trunk/reactos/ntoskrnl/ke/i386/v86m.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/v86m.c?re…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/v86m.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/v86m.c Mon Aug 21 07:49:02 2006 @@ -23,6 +23,10 @@ #define VALID_FLAGS (0xDFF) +#define TRAMPOLINE_BASE (0x10000) + +VOID Ki386RetToV86Mode(KV86M_REGISTERS* InRegs, + KV86M_REGISTERS* OutRegs); /* FUNCTIONS *****************************************************************/ ULONG @@ -807,5 +811,52 @@ } } - - +NTSTATUS STDCALL +Ke386CallBios(ULONG Int, PCONTEXT regs) +{ + PUCHAR Ip; + KV86M_REGISTERS ORegs; + NTSTATUS Status; + PKV86M_REGISTERS Regs = (PKV86M_REGISTERS)regs; + + /* + * Set up a trampoline for executing the BIOS interrupt + */ + Ip = (PUCHAR)TRAMPOLINE_BASE; + Ip[0] = 0xCD; /* int XX */ + Ip[1] = Int; + Ip[2] = 0x63; /* arpl ax, ax */ + Ip[3] = 0xC0; + Ip[4] = 0x90; /* nop */ + Ip[5] = 0x90; /* nop */ + + /* + * Munge the registers + */ + Regs->Eip = 0; + Regs->Cs = TRAMPOLINE_BASE / 16; + Regs->Esp = 0xFFFF; + Regs->Ss = TRAMPOLINE_BASE / 16; + Regs->Eflags = (1 << 1) | (1 << 17) | (1 << 9); /* VM, IF */ + Regs->RecoveryAddress = TRAMPOLINE_BASE + 2; + Regs->RecoveryInstruction[0] = 0x63; /* arpl ax, ax */ + Regs->RecoveryInstruction[1] = 0xC0; + Regs->RecoveryInstruction[2] = 0x90; /* nop */ + Regs->RecoveryInstruction[3] = 0x90; /* nop */ + Regs->Flags = KV86M_EMULATE_CLI_STI | KV86M_ALLOW_IO_PORT_ACCESS; + Regs->Vif = 1; + Regs->PStatus = &Status; + + /* + * Execute the BIOS interrupt + */ + Ki386RetToV86Mode(Regs, &ORegs); + + /* + * Copy the return values back to the caller + */ + memcpy(Regs, &ORegs, sizeof(KV86M_REGISTERS)); + + return(Status); +} + Modified: trunk/reactos/ntoskrnl/ntoskrnl.rbuild URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl.rbuild?r…
============================================================================== --- trunk/reactos/ntoskrnl/ntoskrnl.rbuild (original) +++ trunk/reactos/ntoskrnl/ntoskrnl.rbuild Mon Aug 21 07:49:02 2006 @@ -27,7 +27,6 @@ <if property="ARCH" value="i386"> <directory name="i386"> <file first="true">main_asm.S</file> - <file>bios.c</file> <file>cpu.S</file> <file>ctxswitch.S</file> <file>exp.c</file> @@ -41,7 +40,6 @@ <file>trap.s</file> <file>tss.c</file> <file>usercall_asm.S</file> - <file>usertrap.c</file> <file>v86m.c</file> <file>v86m_sup.S</file> <file>vdm.c</file>
18 years, 10 months
1
0
0
0
[ion] 23636: - Gutted out KiTrapHandler. Now it is only a gateway for GPF/UD for V86 mode. - Removed all the code in userptrap.c and removed KiKernelTrapHandler. - Set Traps 11, 12, 16 and 17 as unhandled for now(Segment fault, stack fault, fpu fault and alignment fault). We weren't really "handling" them in the past either. - I probably need to implement GPF handler for non-V86 mode to support Lazy segment loading and fix the vmware syscall bug that has been haunting me for two years.
by ion@svn.reactos.org
Author: ion Date: Mon Aug 21 07:31:53 2006 New Revision: 23636 URL:
http://svn.reactos.org/svn/reactos?rev=23636&view=rev
Log: - Gutted out KiTrapHandler. Now it is only a gateway for GPF/UD for V86 mode. - Removed all the code in userptrap.c and removed KiKernelTrapHandler. - Set Traps 11, 12, 16 and 17 as unhandled for now(Segment fault, stack fault, fpu fault and alignment fault). We weren't really "handling" them in the past either. - I probably need to implement GPF handler for non-V86 mode to support Lazy segment loading and fix the vmware syscall bug that has been haunting me for two years. Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c trunk/reactos/ntoskrnl/ke/i386/trap.s trunk/reactos/ntoskrnl/ke/i386/usertrap.c trunk/reactos/ntoskrnl/mm/i386/pfault.c Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/exp.c?rev…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/exp.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/exp.c Mon Aug 21 07:31:53 2006 @@ -142,43 +142,6 @@ } while(++i <= 1); return(FALSE); -} - -ULONG -KiKernelTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2) -{ - EXCEPTION_RECORD Er; - - Er.ExceptionFlags = 0; - Er.ExceptionRecord = NULL; - Er.ExceptionAddress = (PVOID)Tf->Eip; - - if (ExceptionNr == 14) - { - Er.ExceptionCode = STATUS_ACCESS_VIOLATION; - Er.NumberParameters = 2; - Er.ExceptionInformation[0] = Tf->ErrCode & 0x1; - Er.ExceptionInformation[1] = (ULONG)Cr2; - } - else - { - if (ExceptionNr < ARRAY_SIZE(ExceptionToNtStatus)) - { - Er.ExceptionCode = ExceptionToNtStatus[ExceptionNr]; - } - else - { - Er.ExceptionCode = STATUS_ACCESS_VIOLATION; - } - Er.NumberParameters = 0; - } - - /* FIXME: Which exceptions are noncontinuable? */ - Er.ExceptionFlags = 0; - - KiDispatchException(&Er, NULL, Tf, KernelMode, TRUE); - - return(0); } VOID @@ -266,13 +229,7 @@ */ { ULONG_PTR cr2; - ULONG Esp0; - - ASSERT(ExceptionNr != 14); - ASSERT((ExceptionNr != 7 && ExceptionNr != 16 && ExceptionNr != 19)); - - /* Use the address of the trap frame as approximation to the ring0 esp */ - Esp0 = (ULONG)&Tf->Eip; + ASSERT(ExceptionNr == 13 || ExceptionNr == 6); /* Get CR2 */ cr2 = Ke386GetCr2(); @@ -286,56 +243,7 @@ DPRINT("Tf->Eflags, %x, Tf->Eip %x, ExceptionNr: %d\n", Tf->EFlags, Tf->Eip, ExceptionNr); return(KeV86Exception(ExceptionNr, Tf, cr2)); } - - /* - * Check for stack underflow, this may be obsolete - */ - DPRINT1("Exception: %x\n", ExceptionNr); - if (PsGetCurrentThread() != NULL && - Esp0 < (ULONG)PsGetCurrentThread()->Tcb.StackLimit) - { - DPRINT1("Stack underflow (tf->esp %x Limit %x Eip %x)\n", - Esp0, (ULONG)PsGetCurrentThread()->Tcb.StackLimit, Tf->Eip); - ExceptionNr = 12; - } - - if (ExceptionNr == 15) - { - /* - * FIXME: - * This exception should never occur. The P6 has a bug, which does sometimes deliver - * the apic spurious interrupt as exception 15. On an athlon64, I get one exception - * in the early boot phase in apic mode (using the smp build). I've looked to the linux - * sources. Linux does ignore this exception. - * - */ - DPRINT1("Ignoring P6 Local APIC Spurious Interrupt Bug...\n"); - return(0); - } - - /* - * Check for a breakpoint that was only for the attention of the debugger. - */ - if (ExceptionNr == 3 && Tf->Eip == ((ULONG)DbgBreakPointNoBugCheck) + 1) - { - /* - EIP is already adjusted by the processor to point to the instruction - after the breakpoint. - */ - return(0); - } - - /* - * Handle user exceptions differently - */ - if ((Tf->SegCs & 0xFFFF) == (KGDT_R3_CODE | RPL_MASK)) - { - return(KiUserTrapHandler(Tf, ExceptionNr, (PVOID)cr2)); - } - else - { - return(KiKernelTrapHandler(Tf, ExceptionNr, (PVOID)cr2)); - } + return 0; } ULONG Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?re…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/trap.s (original) +++ trunk/reactos/ntoskrnl/ke/i386/trap.s Mon Aug 21 07:31:53 2006 @@ -14,8 +14,10 @@ /* * FIXMEs: + * - Implement kernel-mode GPF handler, possibly fixing below: * - Figure out why ES/DS gets messed up in VMWare, when doing KiServiceExit only, * and only when called from user-mode, and returning to user-mode. + * - Implement Invalid Opcode handler. * - Figure out what the DEBUGEIP hack is for and how it can be moved away. * - Add DR macro/save and VM macro/save. * - Implement KiCallbackReturn, KiGetTickCount, KiRaiseAssertion. @@ -977,6 +979,7 @@ int 3 .endfunc +.func KiTrap6 _KiTrap6: /* Push error code */ push 0 @@ -996,6 +999,7 @@ /* Return to caller */ jne _Kei386EoiHelper@0 jmp _KiV86Complete +.endfunc .func KiTrap7 _KiTrap7: @@ -1186,40 +1190,27 @@ jmp _KiSystemFatalException .endfunc +.func KiTrap11 _KiTrap11: /* Enter trap */ TRAP_PROLOG(11) - /* Call the C exception handler */ - push 11 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete - + /* FIXME: ROS Doesn't handle segment faults yet */ + mov eax, 11 + jmp _KiSystemFatalException +.endfunc + +.func KiTrap12 _KiTrap12: /* Enter trap */ TRAP_PROLOG(12) - /* Call the C exception handler */ - push 12 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete - + /* FIXME: ROS Doesn't handle stack faults yet */ + mov eax, 12 + jmp _KiSystemFatalException +.endfunc + +.func KiTrap13 _KiTrap13: /* Enter trap */ TRAP_PROLOG(13) @@ -1236,7 +1227,9 @@ /* Return to caller */ jne _Kei386EoiHelper@0 jmp _KiV86Complete - +.endfunc + +.func KiTrap14 _KiTrap14: /* Enter trap */ TRAP_PROLOG(14) @@ -1247,13 +1240,11 @@ call _KiPageFaultHandler add esp, 8 - /* Check for v86 recovery */ - cmp eax, 1 - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete - + jmp _Kei386EoiHelper@0 +.endfunc + +.func KiTrap0F _KiTrap0F: /* Push error code */ push 0 @@ -1265,7 +1256,9 @@ /* Raise a fatal exception */ mov eax, 15 jmp _KiSystemFatalException - +.endfunc + +.func KiTrap16 _KiTrap16: /* Push error code */ push 0 @@ -1273,19 +1266,12 @@ /* Enter trap */ TRAP_PROLOG(16) - /* Call the C exception handler */ - push 16 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete - + /* FIXME: ROS Doesn't handle FPU faults yet */ + mov eax, 16 + jmp _KiSystemFatalException +.endfunc + +.func KiTrap17 _KiTrap17: /* Push error code */ push 0 @@ -1293,18 +1279,10 @@ /* Enter trap */ TRAP_PROLOG(17) - /* Call the C exception handler */ - push 17 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete + /* FIXME: ROS Doesn't handle alignment faults yet */ + mov eax, 17 + jmp _KiSystemFatalException +.endfunc .func KiSystemFatalException _KiSystemFatalException: Modified: trunk/reactos/ntoskrnl/ke/i386/usertrap.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/usertrap.…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/usertrap.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/usertrap.c Mon Aug 21 07:31:53 2006 @@ -1,133 +1,1 @@ -/* $Id$ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/ke/i386/usertrap.c - * PURPOSE: Handling usermode exceptions. - * - * PROGRAMMERS: David Welch (welch(a)cwcom.net) - */ -/* INCLUDES *****************************************************************/ - -#include <ntoskrnl.h> -#define NDEBUG -#include <internal/debug.h> - -/* FUNCTIONS ****************************************************************/ - -BOOLEAN -print_user_address(PVOID address) -{ - PLIST_ENTRY current_entry; - PLDR_DATA_TABLE_ENTRY current; - PEPROCESS CurrentProcess; - PPEB Peb = NULL; - ULONG_PTR RelativeAddress; - PPEB_LDR_DATA Ldr; - NTSTATUS Status = STATUS_SUCCESS; - - CurrentProcess = PsGetCurrentProcess(); - if (NULL != CurrentProcess) - { - Peb = CurrentProcess->Peb; - } - - if (NULL == Peb) - { - DbgPrint("<%x>", address); - return(TRUE); - } - - _SEH_TRY - { - RtlCopyMemory(&Ldr, - &Peb->Ldr, - sizeof(PPEB_LDR_DATA)); - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - if (!NT_SUCCESS(Status)) - { - DbgPrint("<%x>", address); - return(TRUE); - } - current_entry = Ldr->InLoadOrderModuleList.Flink; - - while (current_entry != &Ldr->InLoadOrderModuleList && - current_entry != NULL) - { - current = - CONTAINING_RECORD(current_entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); - - if (address >= (PVOID)current->DllBase && - address < (PVOID)((char*)current->DllBase + current->SizeOfImage)) - { - RelativeAddress = - (ULONG_PTR) address - (ULONG_PTR)current->DllBase; - DbgPrint("<%wZ: %x>", ¤t->BaseDllName, RelativeAddress); - return(TRUE); - } - - current_entry = current_entry->Flink; - } - return(FALSE); -} - -ULONG -NTAPI -KiUserTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2) -{ - EXCEPTION_RECORD Er; - - if (ExceptionNr == 0) - { - Er.ExceptionCode = STATUS_INTEGER_DIVIDE_BY_ZERO; - } - else if (ExceptionNr == 1) - { - Er.ExceptionCode = STATUS_SINGLE_STEP; - } - else if (ExceptionNr == 3) - { - Er.ExceptionCode = STATUS_BREAKPOINT; - } - else if (ExceptionNr == 4) - { - Er.ExceptionCode = STATUS_INTEGER_OVERFLOW; - } - else if (ExceptionNr == 5) - { - Er.ExceptionCode = STATUS_ARRAY_BOUNDS_EXCEEDED; - } - else if (ExceptionNr == 6) - { - Er.ExceptionCode = STATUS_ILLEGAL_INSTRUCTION; - } - else - { - Er.ExceptionCode = STATUS_ACCESS_VIOLATION; - } - Er.ExceptionFlags = 0; - Er.ExceptionRecord = NULL; - Er.ExceptionAddress = (PVOID)Tf->Eip; - if (ExceptionNr == 14) - { - Er.NumberParameters = 2; - Er.ExceptionInformation[0] = Tf->ErrCode & 0x1; - Er.ExceptionInformation[1] = (ULONG)Cr2; - } - else - { - Er.NumberParameters = 0; - } - - /* FIXME: Which exceptions are noncontinuable? */ - Er.ExceptionFlags = 0; - - KiDispatchException(&Er, 0, Tf, UserMode, TRUE); - return(0); -} Modified: trunk/reactos/ntoskrnl/mm/i386/pfault.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/i386/pfault.c?…
============================================================================== --- trunk/reactos/ntoskrnl/mm/i386/pfault.c (original) +++ trunk/reactos/ntoskrnl/mm/i386/pfault.c Mon Aug 21 07:31:53 2006 @@ -32,6 +32,7 @@ ULONG_PTR cr2; NTSTATUS Status; KPROCESSOR_MODE Mode; + EXCEPTION_RECORD Er; ASSERT(ExceptionNr == 14); @@ -120,16 +121,18 @@ return 0; } - /* - * Handle user exceptions differently - */ - if (Mode == KernelMode) - { - return(KiKernelTrapHandler(Tf, 14, (PVOID)cr2)); - } - else - { - return(KiUserTrapHandler(Tf, 14, (PVOID)cr2)); - } + Er.ExceptionCode = STATUS_ACCESS_VIOLATION; + Er.ExceptionFlags = 0; + Er.ExceptionRecord = NULL; + Er.ExceptionAddress = (PVOID)Tf->Eip; + Er.NumberParameters = 2; + Er.ExceptionInformation[0] = Tf->ErrCode & 0x1; + Er.ExceptionInformation[1] = (ULONG)cr2; + + /* FIXME: Which exceptions are noncontinuable? */ + Er.ExceptionFlags = 0; + + KiDispatchException(&Er, 0, Tf, Mode, TRUE); + return 0; }
18 years, 10 months
1
0
0
0
[ion] 23635: - Call KiSystemFatalException directly instead of duplicating the code 5 times.
by ion@svn.reactos.org
Author: ion Date: Mon Aug 21 07:03:52 2006 New Revision: 23635 URL:
http://svn.reactos.org/svn/reactos?rev=23635&view=rev
Log: - Call KiSystemFatalException directly instead of duplicating the code 5 times. Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?re…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/trap.s (original) +++ trunk/reactos/ntoskrnl/ke/i386/trap.s Mon Aug 21 07:03:52 2006 @@ -841,12 +841,8 @@ _KiTrap2: /* FIXME: This is an NMI, nothing like a normal exception */ - push 0 - push 0 - push 0 - push 2 - push UNEXPECTED_KERNEL_MODE_TRAP - call _KeBugCheckEx@20 + mov eax, 2 + jmp _KiSystemFatalException .endfunc .func KiTrap3 @@ -954,12 +950,8 @@ jnz CheckMode /* It did, and this should never happen */ - push 0 - push 0 - push 0 - push 5 - push UNEXPECTED_KERNEL_MODE_TRAP - call _KeBugCheckEx@20 + mov eax, 5 + jmp _KiSystemFatalException /* Check the old mode */ CheckMode: @@ -1147,12 +1139,8 @@ _KiTrap8: /* Can't really do too much */ - push 0 - push 0 - push 0 - push 8 - push UNEXPECTED_KERNEL_MODE_TRAP - call _KeBugCheckEx@20 + mov eax, 8 + jmp _KiSystemFatalException .endfunc .func KiTrap9 @@ -1165,12 +1153,8 @@ /* Enable interrupts and bugcheck */ sti - push 0 - push 0 - push 0 - push 9 - push UNEXPECTED_KERNEL_MODE_TRAP - call _KeBugCheckEx@20 + mov eax, 9 + jmp _KiSystemFatalException .endfunc .func KiTrap10 @@ -1198,12 +1182,8 @@ Fatal: /* TSS failure for some other reason: crash */ - push 0 - push 0 - push 0 - push 10 - push UNEXPECTED_KERNEL_MODE_TRAP - call _KeBugCheckEx@20 + mov eax, 10 + jmp _KiSystemFatalException .endfunc _KiTrap11:
18 years, 10 months
1
0
0
0
[ion] 23634: - Convert 8, 9, 10, 15/F
by ion@svn.reactos.org
Author: ion Date: Mon Aug 21 07:01:47 2006 New Revision: 23634 URL:
http://svn.reactos.org/svn/reactos?rev=23634&view=rev
Log: - Convert 8, 9, 10, 15/F Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c trunk/reactos/ntoskrnl/ke/i386/trap.s Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/exp.c?rev…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/exp.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/exp.c Mon Aug 21 07:01:47 2006 @@ -179,215 +179,6 @@ KiDispatchException(&Er, NULL, Tf, KernelMode, TRUE); return(0); -} - -VOID -KiDoubleFaultHandler(VOID) -{ -#if 0 - unsigned int cr2; - ULONG StackLimit; - ULONG StackBase; - ULONG Esp0; - ULONG ExceptionNr = 8; - KTSS* OldTss; - PULONG Frame; - ULONG OldCr3; -#if 0 - ULONG i, j; - static PVOID StackTrace[MM_STACK_SIZE / sizeof(PVOID)]; - static ULONG StackRepeatCount[MM_STACK_SIZE / sizeof(PVOID)]; - static ULONG StackRepeatLength[MM_STACK_SIZE / sizeof(PVOID)]; - ULONG TraceLength; - BOOLEAN FoundRepeat; -#endif - - OldTss = KeGetCurrentKPCR()->TSS; - Esp0 = OldTss->Esp0; - - /* Get CR2 */ - cr2 = Ke386GetCr2(); - if (PsGetCurrentThread() != NULL && - PsGetCurrentThread()->ThreadsProcess != NULL) - { - OldCr3 = (ULONG) - PsGetCurrentThread()->ThreadsProcess->Pcb.DirectoryTableBase.QuadPart; - } - else - { - OldCr3 = 0xBEADF0AL; - } - - /* - * Check for stack underflow - */ - if (PsGetCurrentThread() != NULL && - Esp0 < (ULONG)PsGetCurrentThread()->Tcb.StackLimit) - { - DbgPrint("Stack underflow (tf->esp %x Limit %x)\n", - Esp0, (ULONG)PsGetCurrentThread()->Tcb.StackLimit); - ExceptionNr = 12; - } - - /* - * Print out the CPU registers - */ - if (ExceptionNr < ARRAY_SIZE(ExceptionTypeStrings)) - { - DbgPrint("%s Exception: %d(%x)\n", ExceptionTypeStrings[ExceptionNr], - ExceptionNr, 0); - } - else - { - DbgPrint("Exception: %d(%x)\n", ExceptionNr, 0); - } - DbgPrint("CS:EIP %x:%x ", OldTss->Cs, OldTss->Eip); - KeRosPrintAddress((PVOID)OldTss->Eip); - DbgPrint("\n"); - DbgPrint("cr2 %x cr3 %x ", cr2, OldCr3); - DbgPrint("Proc: %x ",PsGetCurrentProcess()); - if (PsGetCurrentProcess() != NULL) - { - DbgPrint("Pid: %x <", PsGetCurrentProcess()->UniqueProcessId); - DbgPrint("%.16s> ", PsGetCurrentProcess()->ImageFileName); - } - if (PsGetCurrentThread() != NULL) - { - DbgPrint("Thrd: %x Tid: %x", - PsGetCurrentThread(), - PsGetCurrentThread()->Cid.UniqueThread); - } - DbgPrint("\n"); - DbgPrint("DS %x ES %x FS %x GS %x\n", OldTss->Ds, OldTss->Es, - OldTss->Fs, OldTss->Gs); - DbgPrint("EAX: %.8x EBX: %.8x ECX: %.8x\n", OldTss->Eax, OldTss->Ebx, - OldTss->Ecx); - DbgPrint("EDX: %.8x EBP: %.8x ESI: %.8x\nESP: %.8x ", OldTss->Edx, - OldTss->Ebp, OldTss->Esi, Esp0); - DbgPrint("EDI: %.8x EFLAGS: %.8x ", OldTss->Edi, OldTss->Eflags); - if (OldTss->Cs == KGDT_R0_CODE) - { - DbgPrint("kESP %.8x ", Esp0); - if (PsGetCurrentThread() != NULL) - { - DbgPrint("kernel stack base %x\n", - PsGetCurrentThread()->Tcb.StackLimit); - - } - } - else - { - DbgPrint("User ESP %.8x\n", OldTss->Esp); - } - if ((OldTss->Cs & 0xffff) == KGDT_R0_CODE) - { - if (PsGetCurrentThread() != NULL) - { - StackLimit = (ULONG)PsGetCurrentThread()->Tcb.StackBase; - StackBase = (ULONG)PsGetCurrentThread()->Tcb.StackLimit; - } - else - { - StackLimit = (ULONG)init_stack_top; - StackBase = (ULONG)init_stack; - } - - /* - Change to an #if 0 to reduce the amount of information printed on - a recursive stack trace. - */ -#if 1 - DbgPrint("Frames: "); - Frame = (PULONG)OldTss->Ebp; - while (Frame != NULL && (ULONG)Frame >= StackBase) - { - KeRosPrintAddress((PVOID)Frame[1]); - Frame = (PULONG)Frame[0]; - DbgPrint("\n"); - } -#else - DbgPrint("Frames: "); - i = 0; - Frame = (PULONG)OldTss->Ebp; - while (Frame != NULL && (ULONG)Frame >= StackBase) - { - StackTrace[i] = (PVOID)Frame[1]; - Frame = (PULONG)Frame[0]; - i++; - } - TraceLength = i; - - i = 0; - while (i < TraceLength) - { - StackRepeatCount[i] = 0; - j = i + 1; - FoundRepeat = FALSE; - while ((j - i) <= (TraceLength - j) && FoundRepeat == FALSE) - { - if (memcmp(&StackTrace[i], &StackTrace[j], - (j - i) * sizeof(PVOID)) == 0) - { - StackRepeatCount[i] = 2; - StackRepeatLength[i] = j - i; - FoundRepeat = TRUE; - } - else - { - j++; - } - } - if (FoundRepeat == FALSE) - { - i++; - continue; - } - j = j + StackRepeatLength[i]; - while ((TraceLength - j) >= StackRepeatLength[i] && - FoundRepeat == TRUE) - { - if (memcmp(&StackTrace[i], &StackTrace[j], - StackRepeatLength[i] * sizeof(PVOID)) == 0) - { - StackRepeatCount[i]++; - j = j + StackRepeatLength[i]; - } - else - { - FoundRepeat = FALSE; - } - } - i = j; - } - - i = 0; - while (i < TraceLength) - { - if (StackRepeatCount[i] == 0) - { - KeRosPrintAddress(StackTrace[i]); - i++; - } - else - { - DbgPrint("{"); - if (StackRepeatLength[i] == 0) - { - for(;;); -} - for (j = 0; j < StackRepeatLength[i]; j++) - { - KeRosPrintAddress(StackTrace[i + j]); - } - DbgPrint("}*%d", StackRepeatCount[i]); - i = i + StackRepeatLength[i] * StackRepeatCount[i]; - } - } -#endif - } -#endif - DbgPrint("\n"); - for(;;); } VOID Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?re…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/trap.s (original) +++ trunk/reactos/ntoskrnl/ke/i386/trap.s Mon Aug 21 07:01:47 2006 @@ -41,7 +41,7 @@ idt _KiTrap12, INT_32_DPL0 /* INT 0C: Stack Fault Exception (#SS) */ idt _KiTrap13, INT_32_DPL0 /* INT 0D: General Protection (#GP) */ idt _KiTrap14, INT_32_DPL0 /* INT 0E: Page-Fault Exception (#PF) */ -idt _KiTrap15, INT_32_DPL0 /* INT 0F: RESERVED [FIXME: HBIRR HACK] */ +idt _KiTrap0F, INT_32_DPL0 /* INT 0F: RESERVED */ idt _KiTrap16, INT_32_DPL0 /* INT 10: x87 FPU Error (#MF) */ idt _KiTrap17, INT_32_DPL0 /* INT 11: Align Check Exception (#AC) */ idt _KiTrap0F, INT_32_DPL0 /* INT 12: Machine Check Exception (#MC)*/ @@ -1143,10 +1143,19 @@ .endfunc .globl _KiTrap8 +.func KiTrap8 _KiTrap8: - call _KiDoubleFaultHandler - iret - + + /* Can't really do too much */ + push 0 + push 0 + push 0 + push 8 + push UNEXPECTED_KERNEL_MODE_TRAP + call _KeBugCheckEx@20 +.endfunc + +.func KiTrap9 _KiTrap9: /* Push error code */ push 0 @@ -1154,37 +1163,48 @@ /* Enter trap */ TRAP_PROLOG(9) - /* Call the C exception handler */ + /* Enable interrupts and bugcheck */ + sti + push 0 + push 0 + push 0 push 9 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete - -#if 1 + push UNEXPECTED_KERNEL_MODE_TRAP + call _KeBugCheckEx@20 +.endfunc + +.func KiTrap10 _KiTrap10: /* Enter trap */ TRAP_PROLOG(10) - /* Call the C exception handler */ + /* Check for V86 */ + test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK + jnz V86IntA + + /* Check if the frame was from kernelmode */ + test word ptr [ebp+KTRAP_FRAME_CS], MODE_MASK + jz Fatal + +V86IntA: + /* Check if OF was set during iretd */ + test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAG_ZERO + sti + jz Fatal + + /* It was, just mask it out */ + and dword ptr [ebp+KTRAP_FRAME_EFLAGS], ~EFLAG_ZERO + jmp _Kei386EoiHelper@0 + +Fatal: + /* TSS failure for some other reason: crash */ + push 0 + push 0 + push 0 push 10 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete -#endif + push UNEXPECTED_KERNEL_MODE_TRAP + call _KeBugCheckEx@20 +.endfunc _KiTrap11: /* Enter trap */ @@ -1220,7 +1240,6 @@ jne _Kei386EoiHelper@0 jmp _KiV86Complete -#if 1 _KiTrap13: /* Enter trap */ TRAP_PROLOG(13) @@ -1237,7 +1256,6 @@ /* Return to caller */ jne _Kei386EoiHelper@0 jmp _KiV86Complete -#endif _KiTrap14: /* Enter trap */ @@ -1256,25 +1274,17 @@ jne _Kei386EoiHelper@0 jmp _KiV86Complete -_KiTrap15: +_KiTrap0F: /* Push error code */ push 0 /* Enter trap */ TRAP_PROLOG(15) - - /* Call the C exception handler */ - push 15 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete + sti + + /* Raise a fatal exception */ + mov eax, 15 + jmp _KiSystemFatalException _KiTrap16: /* Push error code */ @@ -1316,18 +1326,6 @@ jne _Kei386EoiHelper@0 jmp _KiV86Complete -_KiTrap0F: - /* Push error code */ - push 0 - - /* Enter trap */ - TRAP_PROLOG(15) - sti - - /* Raise a fatal exception */ - mov eax, 15 - jmp _KiSystemFatalException - .func KiSystemFatalException _KiSystemFatalException:
18 years, 10 months
1
0
0
0
[ion] 23633: - Switch 4, 5, 6 to common ASM dispatcher as well.
by ion@svn.reactos.org
Author: ion Date: Mon Aug 21 06:32:08 2006 New Revision: 23633 URL:
http://svn.reactos.org/svn/reactos?rev=23633&view=rev
Log: - Switch 4, 5, 6 to common ASM dispatcher as well. Modified: trunk/reactos/include/ndk/asm.h trunk/reactos/ntoskrnl/ke/i386/trap.s Modified: trunk/reactos/include/ndk/asm.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/asm.h?rev=2363…
============================================================================== --- trunk/reactos/include/ndk/asm.h (original) +++ trunk/reactos/include/ndk/asm.h Mon Aug 21 06:32:08 2006 @@ -383,6 +383,9 @@ #define STATUS_ACCESS_VIOLATION 0xC0000005 #define STATUS_INVALID_SYSTEM_SERVICE 0xC000001C #define STATUS_NO_CALLBACK_ACTIVE 0xC0000258 +#define STATUS_ARRAY_BOUNDS_EXCEEDED 0xC000008C +#define STATUS_ILLEGAL_INSTRUCTION 0xC000001D +#define STATUS_BREAKPOINT 0x80000003 #define STATUS_SINGLE_STEP 0x80000004 #define STATUS_INTEGER_DIVIDE_BY_ZERO 0xC0000094 #define STATUS_INTEGER_OVERFLOW 0xC0000095 Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?re…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/trap.s (original) +++ trunk/reactos/ntoskrnl/ke/i386/trap.s Mon Aug 21 06:32:08 2006 @@ -770,7 +770,7 @@ /* Check if the frame was from kernelmode */ test word ptr [ebp+KTRAP_FRAME_CS], MODE_MASK - jz EnableInterrupts + jz SendException /* Check the old mode */ cmp word ptr [ebp+KTRAP_FRAME_CS], KGDT_R3_CODE + RPL_MASK @@ -849,6 +849,7 @@ call _KeBugCheckEx@20 .endfunc +.func KiTrap3 _KiTrap3: /* Push error code */ push 0 @@ -856,19 +857,47 @@ /* Enter trap */ TRAP_PROLOG(3) - /* Call the C exception handler */ - push 3 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete - + /* Check for V86 */ + test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK + jnz V86Int3 + + /* Check if the frame was from kernelmode */ + test word ptr [ebp+KTRAP_FRAME_CS], MODE_MASK + jz PrepInt3 + + /* Check the old mode */ + cmp word ptr [ebp+KTRAP_FRAME_CS], KGDT_R3_CODE + RPL_MASK + jne V86Int3 + +EnableInterrupts3: + /* Enable interrupts for user-mode */ + sti + +PrepInt3: + /* Prepare the exception */ + mov esi, ecx + mov edi, edx + mov edx, eax + + /* Setup EIP, NTSTATUS and parameter count, then dispatch */ + mov ebx, [ebp+KTRAP_FRAME_EIP] + dec ebx + mov eax, STATUS_BREAKPOINT + mov ecx, 3 + call _CommonDispatchException + +V86Int3: + /* Check if this is a VDM process */ + mov ebx, [fs:KPCR_CURRENT_THREAD] + mov ebx, [ebx+KTHREAD_APCSTATE_PROCESS] + cmp dword ptr [ebx+EPROCESS_VDM_OBJECTS], 0 + jz EnableInterrupts3 + + /* We don't support VDM! */ + int 3 +.endfunc + +.func KiTrap4 _KiTrap4: /* Push error code */ push 0 @@ -876,19 +905,39 @@ /* Enter trap */ TRAP_PROLOG(4) - /* Call the C exception handler */ - push 4 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete - + /* Check for V86 */ + test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK + jnz V86Int4 + + /* Check if the frame was from kernelmode */ + test word ptr [ebp+KTRAP_FRAME_CS], MODE_MASK + jz SendException4 + + /* Check the old mode */ + cmp word ptr [ebp+KTRAP_FRAME_CS], KGDT_R3_CODE + RPL_MASK + jne VdmCheck4 + +SendException4: + /* Re-enable interrupts for user-mode and send the exception */ + sti + mov eax, STATUS_INTEGER_OVERFLOW + mov ebx, [ebp+KTRAP_FRAME_EIP] + dec ebx + jmp _DispatchNoParam + +VdmCheck4: + /* Check if this is a VDM process */ + mov ebx, [fs:KPCR_CURRENT_THREAD] + mov ebx, [ebx+KTHREAD_APCSTATE_PROCESS] + cmp dword ptr [ebx+EPROCESS_VDM_OBJECTS], 0 + jz SendException4 + + /* We don't support this yet! */ +V86Int4: + int 3 +.endfunc + +.func KiTrap5 _KiTrap5: /* Push error code */ push 0 @@ -896,18 +945,45 @@ /* Enter trap */ TRAP_PROLOG(5) - /* Call the C exception handler */ + /* Check for V86 */ + test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK + jnz V86Int5 + + /* Check if the frame was from kernelmode */ + test word ptr [ebp+KTRAP_FRAME_CS], MODE_MASK + jnz CheckMode + + /* It did, and this should never happen */ + push 0 + push 0 + push 0 push 5 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete + push UNEXPECTED_KERNEL_MODE_TRAP + call _KeBugCheckEx@20 + + /* Check the old mode */ +CheckMode: + cmp word ptr [ebp+KTRAP_FRAME_CS], KGDT_R3_CODE + RPL_MASK + jne VdmCheck5 + + /* Re-enable interrupts for user-mode and send the exception */ +SendException5: + sti + mov eax, STATUS_ARRAY_BOUNDS_EXCEEDED + mov ebx, [ebp+KTRAP_FRAME_EIP] + jmp _DispatchNoParam + +VdmCheck5: + /* Check if this is a VDM process */ + mov ebx, [fs:KPCR_CURRENT_THREAD] + mov ebx, [ebx+KTHREAD_APCSTATE_PROCESS] + cmp dword ptr [ebx+EPROCESS_VDM_OBJECTS], 0 + jz SendException5 + + /* We don't support this yet! */ +V86Int5: + int 3 +.endfunc _KiTrap6: /* Push error code */
18 years, 10 months
1
0
0
0
[ion] 23632: - Implement generic exception dispatcher for traps (kind-of analogous to KiKernelTrapHandler/KiUserTrapHandler but in assembly and more generic/compact). - Switch Traps 0, 1 to it. - Trap 2 is NMI, bugcheck immediately since we can't handle them yet.
by ion@svn.reactos.org
Author: ion Date: Mon Aug 21 06:01:07 2006 New Revision: 23632 URL:
http://svn.reactos.org/svn/reactos?rev=23632&view=rev
Log: - Implement generic exception dispatcher for traps (kind-of analogous to KiKernelTrapHandler/KiUserTrapHandler but in assembly and more generic/compact). - Switch Traps 0, 1 to it. - Trap 2 is NMI, bugcheck immediately since we can't handle them yet. Modified: trunk/reactos/include/ndk/asm.h trunk/reactos/ntoskrnl/ke/i386/exp.c trunk/reactos/ntoskrnl/ke/i386/trap.s Modified: trunk/reactos/include/ndk/asm.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/asm.h?rev=2363…
============================================================================== --- trunk/reactos/include/ndk/asm.h (original) +++ trunk/reactos/include/ndk/asm.h Mon Aug 21 06:01:07 2006 @@ -120,6 +120,7 @@ #define KPROCESS_INT21_DESCRIPTOR1 0x2C #define KPROCESS_IOPM_OFFSET 0x30 #define KPROCESS_ACTIVE_PROCESSORS 0x34 +#define EPROCESS_VDM_OBJECTS 0x144 // // KPCR Offsets @@ -272,6 +273,7 @@ #define EXCEPTION_RECORD_EXCEPTION_ADDRESS 0xC #define EXCEPTION_RECORD_NUMBER_PARAMETERS 0x10 #define SIZEOF_EXCEPTION_RECORD 0x14 +#define EXCEPTION_RECORD_LENGTH 0x50 // // TEB Offsets @@ -381,6 +383,9 @@ #define STATUS_ACCESS_VIOLATION 0xC0000005 #define STATUS_INVALID_SYSTEM_SERVICE 0xC000001C #define STATUS_NO_CALLBACK_ACTIVE 0xC0000258 +#define STATUS_SINGLE_STEP 0x80000004 +#define STATUS_INTEGER_DIVIDE_BY_ZERO 0xC0000094 +#define STATUS_INTEGER_OVERFLOW 0xC0000095 #define APC_INDEX_MISMATCH 0x01 #define TRAP_CAUSE_UNKNOWN 0x12 #define IRQL_GT_ZERO_AT_SYSTEM_SERVICE 0x4A Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/exp.c?rev…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/exp.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/exp.c Mon Aug 21 06:01:07 2006 @@ -499,6 +499,7 @@ /* * Check for stack underflow, this may be obsolete */ + DPRINT1("Exception: %x\n", ExceptionNr); if (PsGetCurrentThread() != NULL && Esp0 < (ULONG)PsGetCurrentThread()->Tcb.StackLimit) { Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?re…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/trap.s (original) +++ trunk/reactos/ntoskrnl/ke/i386/trap.s Mon Aug 21 06:01:07 2006 @@ -679,6 +679,84 @@ jmp _KiServiceExit .endfunc +.func CommonDispatchException +_CommonDispatchException: + + /* Make space for an exception record */ + sub esp, EXCEPTION_RECORD_LENGTH + + /* Set it up */ + mov [esp+EXCEPTION_RECORD_EXCEPTION_CODE], eax + xor eax, eax + mov [esp+EXCEPTION_RECORD_EXCEPTION_FLAGS], eax + mov [esp+EXCEPTION_RECORD_EXCEPTION_RECORD], eax + mov [esp+EXCEPTION_RECORD_EXCEPTION_ADDRESS], ebx + mov [esp+EXCEPTION_RECORD_NUMBER_PARAMETERS], ecx + + /* Check parameter count */ + cmp eax, 0 + jz NoParams + + /* Get information */ + lea ebx, [esp+SIZEOF_EXCEPTION_RECORD] + mov [ebx], edx + mov [ebx+4], esi + mov [ebx+8], edi + +NoParams: + + /* Set the record in ECX and check if this was V86 */ + mov ecx, esp + test dword ptr [esp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK + jz SetPreviousMode + + /* Set V86 mode */ + mov eax, 0xFFFF + jmp MaskMode + +SetPreviousMode: + + /* Calculate the previous mode */ + mov eax, [ebp+KTRAP_FRAME_CS] +MaskMode: + and eax, MODE_MASK + + /* Dispatch the exception */ + push 1 + push eax + push ebp + push 0 + push ecx + call _KiDispatchException@20 + + /* End the trap */ + jmp _Kei386EoiHelper@0 +.endfunc + +.func DispatchNoParam +_DispatchNoParam: + /* Call the common dispatcher */ + xor ecx, ecx + call _CommonDispatchException +.endfunc + +.func DispatchOneParam +_DispatchOneParam: + /* Call the common dispatcher */ + xor edx, edx + mov ecx, 1 + call _CommonDispatchException +.endfunc + +.func DispatchTwoParam +_DispatchTwoParam: + /* Call the common dispatcher */ + xor edx, edx + mov ecx, 2 + call _CommonDispatchException +.endfunc + +.func KiTrap0 _KiTrap0: /* Push error code */ push 0 @@ -686,19 +764,38 @@ /* Enter trap */ TRAP_PROLOG(0) - /* Call the C exception handler */ - push 0 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete - + /* Check for V86 */ + test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK + jnz V86Int0 + + /* Check if the frame was from kernelmode */ + test word ptr [ebp+KTRAP_FRAME_CS], MODE_MASK + jz EnableInterrupts + + /* Check the old mode */ + cmp word ptr [ebp+KTRAP_FRAME_CS], KGDT_R3_CODE + RPL_MASK + jne VdmCheck + +SendException: + /* Re-enable interrupts for user-mode and send the exception */ + sti + mov eax, STATUS_INTEGER_DIVIDE_BY_ZERO + mov ebx, [ebp+KTRAP_FRAME_EIP] + jmp _DispatchNoParam + +VdmCheck: + /* Check if this is a VDM process */ + mov ebx, [fs:KPCR_CURRENT_THREAD] + mov ebx, [ebx+KTHREAD_APCSTATE_PROCESS] + cmp dword ptr [ebx+EPROCESS_VDM_OBJECTS], 0 + jz SendException + + /* We don't support this yet! */ +V86Int0: + int 3 +.endfunc + +.func KiTrap1 _KiTrap1: /* Push error code */ push 0 @@ -706,38 +803,51 @@ /* Enter trap */ TRAP_PROLOG(1) - /* Call the C exception handler */ - push 1 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete - + /* Check for V86 */ + test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK + jnz V86Int1 + + /* Check if the frame was from kernelmode */ + test word ptr [ebp+KTRAP_FRAME_CS], MODE_MASK + jz PrepInt1 + + /* Check the old mode */ + cmp word ptr [ebp+KTRAP_FRAME_CS], KGDT_R3_CODE + RPL_MASK + jne V86Int1 + +EnableInterrupts: + /* Enable interrupts for user-mode */ + sti + +PrepInt1: + /* Prepare the exception */ + and dword ptr [ebp+KTRAP_FRAME_EFLAGS], ~EFLAGS_TF + mov ebx, [ebp+KTRAP_FRAME_EIP] + mov eax, STATUS_SINGLE_STEP + jmp _DispatchNoParam + +V86Int1: + /* Check if this is a VDM process */ + mov ebx, [fs:KPCR_CURRENT_THREAD] + mov ebx, [ebx+KTHREAD_APCSTATE_PROCESS] + cmp dword ptr [ebx+EPROCESS_VDM_OBJECTS], 0 + jz EnableInterrupts + + /* We don't support VDM! */ + int 3 +.endfunc + +.func KiTrap2 _KiTrap2: - /* Push error code */ - push 0 - - /* Enter trap */ - TRAP_PROLOG(2) - - /* Call the C exception handler */ + + /* FIXME: This is an NMI, nothing like a normal exception */ + push 0 + push 0 + push 0 push 2 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete + push UNEXPECTED_KERNEL_MODE_TRAP + call _KeBugCheckEx@20 +.endfunc _KiTrap3: /* Push error code */
18 years, 10 months
1
0
0
0
[ion] 23631: - Fixes to CONTEXT<->KTRAP_FRAME conversion.
by ion@svn.reactos.org
Author: ion Date: Mon Aug 21 05:07:01 2006 New Revision: 23631 URL:
http://svn.reactos.org/svn/reactos?rev=23631&view=rev
Log: - Fixes to CONTEXT<->KTRAP_FRAME conversion. Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/exp.c?rev…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/exp.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/exp.c Mon Aug 21 05:07:01 2006 @@ -551,7 +551,8 @@ KiEspFromTrapFrame(IN PKTRAP_FRAME TrapFrame) { /* Check if this is user-mode or V86 */ - if ((TrapFrame->SegCs & MODE_MASK) || (TrapFrame->EFlags & X86_EFLAGS_VM)) + if ((TrapFrame->SegCs & MODE_MASK) || + (TrapFrame->EFlags & EFLAGS_V86_MASK)) { /* Return it directly */ return TrapFrame->HardwareEsp; @@ -580,7 +581,7 @@ ULONG Previous = KiEspFromTrapFrame(TrapFrame); /* Check if this is user-mode or V86 */ - if ((TrapFrame->SegCs & MODE_MASK) || (TrapFrame->EFlags & X86_EFLAGS_VM)) + if ((TrapFrame->SegCs & MODE_MASK) || (TrapFrame->EFlags & EFLAGS_V86_MASK)) { /* Write it directly */ TrapFrame->HardwareEsp = Esp; @@ -588,10 +589,7 @@ else { /* Don't allow ESP to be lowered, this is illegal */ - if (Esp < Previous) - { - KeBugCheck(SET_OF_INVALID_CONTEXT); - } + if (Esp < Previous) KeBugCheck(SET_OF_INVALID_CONTEXT); /* Create an edit frame, check if it was alrady */ if (!(TrapFrame->SegCs & FRAME_EDITED)) @@ -620,7 +618,7 @@ KiSsFromTrapFrame(IN PKTRAP_FRAME TrapFrame) { /* If this was V86 Mode */ - if (TrapFrame->EFlags & X86_EFLAGS_VM) + if (TrapFrame->EFlags & EFLAGS_V86_MASK) { /* Just return it */ return TrapFrame->HardwareSegSs; @@ -646,7 +644,7 @@ Ss &= 0xFFFF; /* If this was V86 Mode */ - if (TrapFrame->EFlags & X86_EFLAGS_VM) + if (TrapFrame->EFlags & EFLAGS_V86_MASK) { /* Just write it */ TrapFrame->HardwareSegSs = Ss; @@ -686,13 +684,17 @@ PFX_SAVE_AREA FxSaveArea; ULONG i; BOOLEAN V86Switch = FALSE; + KIRQL OldIrql = APC_LEVEL; + + /* Do this at APC_LEVEL */ + if (KeGetCurrentIrql() < APC_LEVEL) KeRaiseIrql(APC_LEVEL, &OldIrql); /* Start with the basic Registers */ if ((ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL) { /* Check if we went through a V86 switch */ - if ((Context->EFlags & X86_EFLAGS_VM) != - (TrapFrame->EFlags & X86_EFLAGS_VM)) + if ((Context->EFlags & EFLAGS_V86_MASK) != + (TrapFrame->EFlags & EFLAGS_V86_MASK)) { /* We did, remember this for later */ V86Switch = TRUE; @@ -706,7 +708,7 @@ TrapFrame->Eip = Context->Eip; /* Check if we were in V86 Mode */ - if (TrapFrame->EFlags & X86_EFLAGS_VM) + if (TrapFrame->EFlags & EFLAGS_V86_MASK) { /* Simply copy the CS value */ TrapFrame->SegCs = Context->SegCs; @@ -737,6 +739,7 @@ /* Process the Integer Registers */ if ((ContextFlags & CONTEXT_INTEGER) == CONTEXT_INTEGER) { + /* Copy them manually */ TrapFrame->Eax = Context->Eax; TrapFrame->Ebx = Context->Ebx; TrapFrame->Ecx = Context->Ecx; @@ -749,7 +752,7 @@ if ((ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS) { /* Check if we were in V86 Mode */ - if (TrapFrame->EFlags & X86_EFLAGS_VM) + if (TrapFrame->EFlags & EFLAGS_V86_MASK) { /* Copy the V86 Segments directlry */ TrapFrame->V86Ds = Context->SegDs; @@ -788,8 +791,7 @@ /* Handle the extended registers */ if (((ContextFlags & CONTEXT_EXTENDED_REGISTERS) == - CONTEXT_EXTENDED_REGISTERS) && - ((TrapFrame->SegCs & MODE_MASK) == UserMode)) + CONTEXT_EXTENDED_REGISTERS) && (TrapFrame->SegCs & MODE_MASK)) { /* Get the FX Area */ FxSaveArea = (PFX_SAVE_AREA)(TrapFrame + 1); @@ -817,8 +819,7 @@ /* Handle the floating point state */ if (((ContextFlags & CONTEXT_FLOATING_POINT) == - CONTEXT_FLOATING_POINT) && - ((TrapFrame->SegCs & MODE_MASK) == UserMode)) + CONTEXT_FLOATING_POINT) && (TrapFrame->SegCs & MODE_MASK)) { /* Get the FX Area */ FxSaveArea = (PFX_SAVE_AREA)(TrapFrame + 1); @@ -840,7 +841,7 @@ FxSaveArea->U.FxArea.TagWord = KiTagWordFnsaveToFxsave((USHORT)Context->FloatSave.TagWord); FxSaveArea->U.FxArea.ErrorOpcode = - (USHORT)(Context->FloatSave.ErrorSelector >> 16); + (USHORT)((Context->FloatSave.ErrorSelector >> 16) & 0xFFFF); FxSaveArea->U.FxArea.ErrorOffset = Context->FloatSave.ErrorOffset; FxSaveArea->U.FxArea.ErrorSelector = @@ -848,10 +849,11 @@ FxSaveArea->U.FxArea.DataOffset = Context->FloatSave.DataOffset; FxSaveArea->U.FxArea.DataSelector = - Context->FloatSave.DataSelector & 0xFFFF; + Context->FloatSave.DataSelector; /* Clear out the Register Area */ - RtlZeroMemory(&FxSaveArea->U.FxArea.RegisterArea[0], SIZE_OF_FX_REGISTERS); + RtlZeroMemory(&FxSaveArea->U.FxArea.RegisterArea[0], + SIZE_OF_FX_REGISTERS); /* Loop the 8 floating point registers */ for (i = 0; i < 8; i++) @@ -878,6 +880,7 @@ else { /* FIXME: Handle FPU Emulation */ + ASSERT(FALSE); } } @@ -900,6 +903,9 @@ (Context->Dr7 & DR7_ACTIVE); } } + + /* Restore IRQL */ + if (OldIrql < APC_LEVEL) KeLowerIrql(OldIrql); } VOID @@ -915,6 +921,10 @@ FLOATING_SAVE_AREA UnalignedArea; } FloatSaveBuffer; FLOATING_SAVE_AREA *FloatSaveArea; + KIRQL OldIrql = APC_LEVEL; + + /* Do this at APC_LEVEL */ + if (KeGetCurrentIrql() < APC_LEVEL) KeRaiseIrql(APC_LEVEL, &OldIrql); /* Start with the Control flags */ if ((Context->ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL) @@ -926,7 +936,7 @@ /* Return the correct CS */ if (!(TrapFrame->SegCs & FRAME_EDITED) && - !(TrapFrame->EFlags & X86_EFLAGS_VM)) + !(TrapFrame->EFlags & EFLAGS_V86_MASK)) { /* Get it from the Temp location */ Context->SegCs = TrapFrame->TempSegCs & 0xFFFF; @@ -946,7 +956,7 @@ if ((Context->ContextFlags & CONTEXT_SEGMENTS) == CONTEXT_SEGMENTS) { /* Do V86 Mode first */ - if (TrapFrame->EFlags & X86_EFLAGS_VM) + if (TrapFrame->EFlags & EFLAGS_V86_MASK) { /* Return from the V86 location */ Context->SegGs = TrapFrame->V86Gs & 0xFFFF; @@ -988,8 +998,7 @@ /* Handle extended registers */ if (((Context->ContextFlags & CONTEXT_EXTENDED_REGISTERS) == - CONTEXT_EXTENDED_REGISTERS) && - ((TrapFrame->SegCs & MODE_MASK) == UserMode)) + CONTEXT_EXTENDED_REGISTERS) && (TrapFrame->SegCs & MODE_MASK)) { /* Get the FX Save Area */ FxSaveArea = (PFX_SAVE_AREA)(TrapFrame + 1); @@ -1009,8 +1018,7 @@ /* Handle Floating Point */ if (((Context->ContextFlags & CONTEXT_FLOATING_POINT) == - CONTEXT_FLOATING_POINT) && - ((TrapFrame->SegCs & MODE_MASK) == UserMode)) + CONTEXT_FLOATING_POINT) && (TrapFrame->SegCs & MODE_MASK)) { /* Get the FX Save Area */ FxSaveArea = (PFX_SAVE_AREA)(TrapFrame + 1); @@ -1037,13 +1045,13 @@ /* Copy into the Context */ RtlCopyMemory(&Context->FloatSave, - &FxSaveArea->U.FnArea, + FloatSaveArea, sizeof(FNSAVE_FORMAT)); } else { /* FIXME: Handle Emulation */ - Context->ContextFlags &= (~CONTEXT_FLOATING_POINT) | CONTEXT_i386; + ASSERT(FALSE); } } @@ -1072,6 +1080,9 @@ Context->Dr7 = 0; } } + + /* Restore IRQL */ + if (OldIrql < APC_LEVEL) KeLowerIrql(OldIrql); } VOID
18 years, 10 months
1
0
0
0
[turner] 23630: Label NtReadFileScatter as unimplemented.
by turner@svn.reactos.org
Author: turner Date: Mon Aug 21 04:02:33 2006 New Revision: 23630 URL:
http://svn.reactos.org/svn/reactos?rev=23630&view=rev
Log: Label NtReadFileScatter as unimplemented. Modified: trunk/reactos/ntoskrnl/io/iomgr/iofunc.c Modified: trunk/reactos/ntoskrnl/io/iomgr/iofunc.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/iofunc.c…
============================================================================== --- trunk/reactos/ntoskrnl/io/iomgr/iofunc.c (original) +++ trunk/reactos/ntoskrnl/io/iomgr/iofunc.c Mon Aug 21 04:02:33 2006 @@ -1979,6 +1979,9 @@ IopReadTransfer); } +/* + * @unimplemented + */ NTSTATUS NTAPI NtReadFileScatter(IN HANDLE FileHandle,
18 years, 10 months
1
0
0
0
[janderwald] 23629: * colors.c: implement color dialog (reading from registry is not yet supported) * font.c/layout.c/console.c/options.c: add UNREFERENCED_PARAMETER macros, fix sharing of global struct * console.def: fix building with MSVC
by janderwald@svn.reactos.org
Author: janderwald Date: Mon Aug 21 03:55:08 2006 New Revision: 23629 URL:
http://svn.reactos.org/svn/reactos?rev=23629&view=rev
Log: * colors.c: implement color dialog (reading from registry is not yet supported) * font.c/layout.c/console.c/options.c: add UNREFERENCED_PARAMETER macros, fix sharing of global struct * console.def: fix building with MSVC Modified: trunk/reactos/dll/win32/console/colors.c trunk/reactos/dll/win32/console/console.c trunk/reactos/dll/win32/console/console.def trunk/reactos/dll/win32/console/console.h trunk/reactos/dll/win32/console/en.rc trunk/reactos/dll/win32/console/font.c trunk/reactos/dll/win32/console/layout.c trunk/reactos/dll/win32/console/options.c trunk/reactos/dll/win32/console/resource.h Modified: trunk/reactos/dll/win32/console/colors.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/console/colors.c…
============================================================================== --- trunk/reactos/dll/win32/console/colors.c (original) +++ trunk/reactos/dll/win32/console/colors.c Mon Aug 21 03:55:08 2006 @@ -8,6 +8,80 @@ */ #include "console.h" + + +static COLORREF s_Colors[] = +{ + RGB(0, 0, 0), + RGB(0, 0, 128), + RGB(0, 128, 0), + RGB(0, 128, 128), + RGB(128, 0, 0), + RGB(128, 0, 128), + RGB(128, 128, 0), + RGB(192, 192, 192), + RGB(128, 128, 128), + RGB(0, 0, 255), + RGB(0, 255, 0), + RGB(0, 255, 255), + RGB(255, 0, 0), + RGB(255, 0, 255), + RGB(255, 255, 0), + RGB(255, 255, 255) +}; + +static TCHAR szText[1024]; + + +static +BOOL +PaintStaticControls(HWND hwndDlg, PConsoleInfo pConInfo, LPDRAWITEMSTRUCT drawItem) +{ + HBRUSH hBrush; + DWORD index; + + if (drawItem->CtlID < IDC_STATIC_COLOR1 || drawItem->CtlID > IDC_STATIC_COLOR16) + { + COLORREF pbkColor, ptColor; + COLORREF nbkColor, ntColor; + /* draw static controls */ + if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR) + { + nbkColor = pConInfo->ScreenBackground; + hBrush = CreateSolidBrush(nbkColor); + ntColor = pConInfo->ScreenText; + } + else + { + nbkColor = pConInfo->PopupBackground; + hBrush = CreateSolidBrush(nbkColor); + ntColor = pConInfo->PopupText; + } + FillRect(drawItem->hDC, &drawItem->rcItem, hBrush); + DeleteObject((HGDIOBJ)hBrush); + ptColor = SetTextColor(drawItem->hDC, ntColor); + pbkColor = SetBkColor(drawItem->hDC, nbkColor); + if (ntColor != nbkColor) + { + /* hide text when it has same background color as text color */ + DrawText(drawItem->hDC, szText, _tcslen(szText), &drawItem->rcItem, 0); + } + SetTextColor(drawItem->hDC, ptColor); + SetBkColor(drawItem->hDC, pbkColor); + return TRUE; + } + + index = drawItem->CtlID - IDC_STATIC_COLOR1; + hBrush = CreateSolidBrush(s_Colors[index]); + if (!hBrush) + { + return FALSE; + } + + FillRect(drawItem->hDC, &drawItem->rcItem, hBrush); + DeleteObject((HGDIOBJ)hBrush); + return TRUE; +} INT_PTR CALLBACK @@ -18,14 +92,160 @@ LPARAM lParam ) { - UNREFERENCED_PARAMETER(hwndDlg) - UNREFERENCED_PARAMETER(wParam) - UNREFERENCED_PARAMETER(lParam) + PConsoleInfo pConInfo; + LPNMUPDOWN lpnmud; + + pConInfo = (PConsoleInfo) GetWindowLongPtr(hwndDlg, DWLP_USER); switch(uMsg) { case WM_INITDIALOG: + { + pConInfo = (PConsoleInfo) ((LPPROPSHEETPAGE)lParam)->lParam; + SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo); + ZeroMemory(szText, sizeof(szText)); + LoadString(hApplet, IDS_SCREEN_TEXT, szText, sizeof(szText) / sizeof(TCHAR)); + SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_SCREEN_BACKGROUND), BM_SETCHECK, BST_CHECKED, 0); + SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_RED), UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0)); + SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_GREEN), UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0)); + SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_BLUE), UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0)); + InvalidateRect(hwndDlg, NULL, TRUE); return TRUE; + } + case WM_DRAWITEM: + { + return PaintStaticControls(hwndDlg, pConInfo, (LPDRAWITEMSTRUCT) lParam); + } + case WM_NOTIFY: + { + DWORD red = -1; + DWORD green = -1; + DWORD blue = -1; + + lpnmud = (LPNMUPDOWN) lParam; + + if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_RED) + { + red = lpnmud->iPos; + } + else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_GREEN) + { + green = lpnmud->iPos; + } + else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_BLUE) + { + blue = lpnmud->iPos; + } + + if (red == -1) + { + red = SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_RED), UDM_GETPOS, 0, 0); + if (HIWORD(red)) + { + //TODO: handle error + break; + } + red = LOBYTE(red); + } + + if (green == -1) + { + green = SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_GREEN), UDM_GETPOS, 0, 0); + if (HIWORD(green)) + { + //TODO: handle error + break; + } + green = LOBYTE(green); + } + + if (blue == -1) + { + blue = SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_BLUE), UDM_GETPOS, 0, 0); + if (HIWORD(blue)) + { + //TODO: handle error + break; + } + blue = LOBYTE(blue); + } + s_Colors[pConInfo->ActiveStaticControl] = RGB(red, green, blue); + InvalidateRect(hwndDlg, NULL, TRUE); //FIXME + break; + } + case WM_COMMAND: + { + switch(LOWORD(wParam)) + { + case IDC_RADIO_SCREEN_TEXT: + { + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->ScreenText), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->ScreenText), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->ScreenText), FALSE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE); + break; + } + case IDC_RADIO_SCREEN_BACKGROUND: + { + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->ScreenBackground), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->ScreenBackground), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->ScreenBackground), FALSE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE); + break; + } + case IDC_RADIO_POPUP_TEXT: + { + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->PopupText), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->PopupText), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->PopupText), FALSE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE); + break; + } + case IDC_RADIO_POPUP_BACKGROUND: + { + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->PopupBackground), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->PopupBackground), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->PopupBackground), FALSE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE); + break; + } + } + if (HIWORD(wParam) == STN_CLICKED && LOWORD(wParam) >= IDC_STATIC_COLOR1 && LOWORD(wParam) <= IDC_STATIC_COLOR16) + { + DWORD index = LOWORD(wParam) - IDC_STATIC_COLOR1; + + pConInfo->ActiveStaticControl = index; + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(s_Colors[index]), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(s_Colors[index]), FALSE); + SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(s_Colors[index]), FALSE); + + /* update global struct */ + if (SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_SCREEN_TEXT), BM_GETCHECK, 0, 0) & BST_CHECKED) + { + pConInfo->ScreenText = s_Colors[index]; + } + else if (SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_SCREEN_BACKGROUND), BM_GETCHECK, 0, 0) & BST_CHECKED) + { + pConInfo->ScreenBackground = s_Colors[index]; + } + else if (SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_POPUP_TEXT), BM_GETCHECK, 0, 0) & BST_CHECKED) + { + pConInfo->PopupText = s_Colors[index]; + } + else if (SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_POPUP_BACKGROUND), BM_GETCHECK, 0, 0) & BST_CHECKED) + { + pConInfo->PopupBackground = s_Colors[index]; + } + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE); + InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE); + break; + } + } + default: break; Modified: trunk/reactos/dll/win32/console/console.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/console/console.…
============================================================================== --- trunk/reactos/dll/win32/console/console.c (original) +++ trunk/reactos/dll/win32/console/console.c Mon Aug 21 03:55:08 2006 @@ -26,7 +26,7 @@ }; static void -InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc) +InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam) { ZeroMemory(psp, sizeof(PROPSHEETPAGE)); psp->dwSize = sizeof(PROPSHEETPAGE); @@ -34,10 +34,11 @@ psp->hInstance = hApplet; psp->pszTemplate = MAKEINTRESOURCE(idDlg); psp->pfnDlgProc = DlgProc; -} - -BOOL -InitConsoleInfo(HWND hwnd) + psp->lParam = lParam; +} + +PConsoleInfo +InitConsoleInfo() { PConsoleInfo pConInfo; STARTUPINFO StartupInfo; @@ -46,14 +47,26 @@ pConInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ConsoleInfo)); if (!pConInfo) - return FALSE; + { + return NULL; + } /* initialize struct */ pConInfo->InsertMode = TRUE; pConInfo->HistoryBufferSize = 50; pConInfo->NumberOfHistoryBuffers = 5; + pConInfo->ScreenText = RGB(192, 192, 192); + pConInfo->ScreenBackground = RGB(0, 0, 0); + pConInfo->PopupText = RGB(128, 0, 128); + pConInfo->PopupBackground = RGB(255, 255, 255); + + + GetModuleFileName(NULL, pConInfo->szProcessName, MAX_PATH); + //MessageBox(hwnd, pConInfo->szProcessName, _T("GetModuleFileName"), MB_OK); GetStartupInfo(&StartupInfo); + + if ( StartupInfo.lpTitle ) { @@ -89,11 +102,7 @@ { _tcscpy(pConInfo->szProcessName, _T("Console")); } - - SetWindowText(hwnd, pConInfo->szProcessName); - SetWindowLongPtr(hwnd, DWLP_USER , (LONG)pConInfo); - - return TRUE; + return pConInfo; } INT_PTR @@ -107,7 +116,7 @@ { HWND hDlgCtrl; - UNREFERENCED_PARAMETER(lParam) + UNREFERENCED_PARAMETER(lParam); switch(uMsg) { @@ -168,7 +177,7 @@ LPARAM lParam ) { - PConsoleInfo pConInfo = (PConsoleInfo) GetWindowLongPtr(hwndDlg, DWLP_USER); + PConsoleInfo pConInfo = (PConsoleInfo) GetWindowLongPtr(GetParent(hwndDlg), DWLP_USER); switch(uMsg) { @@ -197,10 +206,7 @@ } break; } - case PSCB_INITIALIZED: - { - break; - } + default: break; } @@ -214,13 +220,14 @@ PROPSHEETPAGE psp[4]; PROPSHEETHEADER psh; INT i=0; - - UNREFERENCED_PARAMETER(hwnd) - UNREFERENCED_PARAMETER(uMsg) - UNREFERENCED_PARAMETER(wParam) - UNREFERENCED_PARAMETER(lParam) - - + PConsoleInfo pConInfo; + + UNREFERENCED_PARAMETER(hwnd); + UNREFERENCED_PARAMETER(uMsg); + UNREFERENCED_PARAMETER(wParam); + UNREFERENCED_PARAMETER(lParam); + + pConInfo = InitConsoleInfo(); ZeroMemory(&psh, sizeof(PROPSHEETHEADER)); psh.dwSize = sizeof(PROPSHEETHEADER); @@ -234,10 +241,10 @@ psh.ppsp = psp; psh.pfnCallback = PropSheetProc; - InitPropSheetPage(&psp[i++], IDD_PROPPAGEOPTIONS, (DLGPROC) OptionsProc); - InitPropSheetPage(&psp[i++], IDD_PROPPAGEFONT, (DLGPROC) FontProc); - InitPropSheetPage(&psp[i++], IDD_PROPPAGELAYOUT, (DLGPROC) LayoutProc); - InitPropSheetPage(&psp[i++], IDD_PROPPAGECOLORS, (DLGPROC) ColorsProc); + InitPropSheetPage(&psp[i++], IDD_PROPPAGEOPTIONS, (DLGPROC) OptionsProc, (LPARAM)pConInfo); + InitPropSheetPage(&psp[i++], IDD_PROPPAGEFONT, (DLGPROC) FontProc, (LPARAM)pConInfo); + InitPropSheetPage(&psp[i++], IDD_PROPPAGELAYOUT, (DLGPROC) LayoutProc, (LPARAM)pConInfo); + InitPropSheetPage(&psp[i++], IDD_PROPPAGECOLORS, (DLGPROC) ColorsProc, (LPARAM)pConInfo); return (PropertySheet(&psh) != -1); } @@ -287,7 +294,7 @@ DWORD dwReason, LPVOID lpvReserved) { - UNREFERENCED_PARAMETER(lpvReserved) + UNREFERENCED_PARAMETER(lpvReserved); switch(dwReason) { Modified: trunk/reactos/dll/win32/console/console.def URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/console/console.…
============================================================================== --- trunk/reactos/dll/win32/console/console.def (original) +++ trunk/reactos/dll/win32/console/console.def Mon Aug 21 03:55:08 2006 @@ -1,6 +1,6 @@ LIBRARY console.dll EXPORTS -CPlApplet@16 +CPlApplet ; EOF Modified: trunk/reactos/dll/win32/console/console.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/console/console.…
============================================================================== --- trunk/reactos/dll/win32/console/console.h (original) +++ trunk/reactos/dll/win32/console/console.h Mon Aug 21 03:55:08 2006 @@ -29,9 +29,17 @@ DWORD QuickEdit; DWORD InsertMode; + DWORD ActiveStaticControl; + COLORREF ScreenText; + COLORREF ScreenBackground; + COLORREF PopupText; + COLORREF PopupBackground; + } ConsoleInfo, *PConsoleInfo; BOOL WriteConsoleOptions(PConsoleInfo pConInfo); -BOOL InitConsoleInfo(HWND hwnd); + +//globals +extern HINSTANCE hApplet; #endif /* CONSOLE_H__ */ Modified: trunk/reactos/dll/win32/console/en.rc URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/console/en.rc?re…
============================================================================== --- trunk/reactos/dll/win32/console/en.rc (original) +++ trunk/reactos/dll/win32/console/en.rc Mon Aug 21 03:55:08 2006 @@ -6,6 +6,8 @@ * PURPOSE: English resource file * PROGRAMMERS: Johannes Anderwald (johannes.anderwald(a)student.tugraz.at) */ + +#include <commctrl.h> LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US @@ -24,10 +26,10 @@ GROUPBOX "Command History:", -1, 15, 90, 120, 70, WS_CHILD | WS_VISIBLE | WS_GROUP LTEXT "&Buffer Size", -1, 25, 100, 60, 15 EDITTEXT IDC_EDIT_BUFFER_SIZE, 90, 100, 30, 15, ES_RIGHT | WS_GROUP -CONTROL "", IDC_UPDOWN_BUFFER_SIZE, UPDOWN_CLASS,UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 115, 100, 12, 12 +CONTROL "", IDC_UPDOWN_BUFFER_SIZE, UPDOWN_CLASS, UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 115, 100, 12, 12 LTEXT "&Number of Buffers:", -1, 25, 120, 80, 15 EDITTEXT IDC_EDIT_NUM_BUFFER, 90, 120, 30, 15, ES_RIGHT | WS_GROUP -CONTROL "", IDC_UPDOWN_NUM_BUFFER, UPDOWN_CLASS,UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 115, 120, 12, 12 +CONTROL "", IDC_UPDOWN_NUM_BUFFER, UPDOWN_CLASS, UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 115, 120, 12, 12 CHECKBOX "&Discard Old Duplicates", IDC_CHECK_DISCARD_DUPLICATES, 25, 140, 100, 15 @@ -101,31 +103,31 @@ EDITTEXT IDC_EDIT_COLOR_RED, 150, 25, 30, 10, ES_RIGHT | WS_GROUP CONTROL "", IDC_UPDOWN_COLOR_RED, UPDOWN_CLASS, UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 165, 25, 30, 10 LTEXT "&Green:", -1, 125, 35, 30, 10 -EDITTEXT IDC_EDIT_COLOR_BLUE, 150, 35, 30, 10, ES_RIGHT | WS_GROUP +EDITTEXT IDC_EDIT_COLOR_GREEN, 150, 35, 30, 10, ES_RIGHT | WS_GROUP CONTROL "", IDC_UPDOWN_COLOR_GREEN, UPDOWN_CLASS, UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 165, 35, 30, 10 LTEXT "&Blue:", -1, 125, 45, 30, 10 EDITTEXT IDC_EDIT_COLOR_BLUE, 150, 45, 30, 10, ES_RIGHT | WS_GROUP CONTROL "", IDC_UPDOWN_COLOR_BLUE, UPDOWN_CLASS, UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_BORDER | WS_GROUP, 165, 45, 30, 10 -CONTROL "", IDC_STATIC_COLOR1, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 15, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR2, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 27, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR3, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 39, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR4, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 51, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR5, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 63, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR6, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 75, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR7, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 87, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR8, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 99, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR9, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 111, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR10, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 123, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR11, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 135, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR12, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 147, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR13, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 159, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR14, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 171, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR15, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 183, 90, 10, 10 -CONTROL "", IDC_STATIC_COLOR16, "Static", SS_BLACKRECT | SS_NOTIFY | SS_SUNKEN, 195, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR1, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 15, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR2, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 27, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR3, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 39, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR4, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 51, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR5, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 63, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR6, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 75, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR7, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 87, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR8, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 99, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR9, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 111, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR10, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 123, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR11, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 135, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR12, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 147, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR13, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 159, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR14, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 171, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR15, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 183, 90, 10, 10 +CONTROL "", IDC_STATIC_COLOR16, "Static", SS_NOTIFY | SS_SUNKEN | SS_OWNERDRAW, 195, 90, 10, 10 GROUPBOX "Selected Screen Colors", -1, 10, 110, 200, 40 -CONTROL "", IDC_STATIC_SCREEN_COLOR, "Static", SS_BLACKRECT | SS_SUNKEN, 15, 120, 180, 20 +CONTROL "", IDC_STATIC_SCREEN_COLOR, "Static", SS_OWNERDRAW | SS_SUNKEN, 15, 120, 180, 20 GROUPBOX "Selected Popup Colors", -1, 10, 155, 200, 40 -CONTROL "", IDC_STATIC_POPUP_COLOR, "Static", SS_BLACKRECT | SS_SUNKEN, 15, 165, 180, 20 +CONTROL "", IDC_STATIC_POPUP_COLOR, "Static", SS_OWNERDRAW | SS_SUNKEN, 15, 165, 180, 20 END IDD_APPLYOPTIONS DIALOGEX 0, 0, 220, 100 @@ -144,4 +146,5 @@ IDS_CPLNAME "Console" IDS_CPLDESCRIPTION "Configures console properties." IDS_APPLY_SHORTCUT_ALL "Modify &shortcut that started this window" + IDS_SCREEN_TEXT "C:\ReactOS> dir\nSYSTEM <DIR> 10-01-99 5:00\nSYSTEM32 <DIR> 10-01-99 5:00" END Modified: trunk/reactos/dll/win32/console/font.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/console/font.c?r…
============================================================================== --- trunk/reactos/dll/win32/console/font.c (original) +++ trunk/reactos/dll/win32/console/font.c Mon Aug 21 03:55:08 2006 @@ -19,9 +19,9 @@ LPARAM lParam ) { - UNREFERENCED_PARAMETER(hwndDlg) - UNREFERENCED_PARAMETER(wParam) - UNREFERENCED_PARAMETER(lParam) + UNREFERENCED_PARAMETER(hwndDlg); + UNREFERENCED_PARAMETER(wParam); + switch(uMsg) { Modified: trunk/reactos/dll/win32/console/layout.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/console/layout.c…
============================================================================== --- trunk/reactos/dll/win32/console/layout.c (original) +++ trunk/reactos/dll/win32/console/layout.c Mon Aug 21 03:55:08 2006 @@ -18,15 +18,19 @@ LPARAM lParam ) { - UNREFERENCED_PARAMETER(hwndDlg) - UNREFERENCED_PARAMETER(wParam) - UNREFERENCED_PARAMETER(lParam) + PConsoleInfo pConInfo = (PConsoleInfo)GetWindowLongPtr(hwndDlg, DWLP_USER); + + UNREFERENCED_PARAMETER(hwndDlg); + UNREFERENCED_PARAMETER(wParam); switch(uMsg) { case WM_INITDIALOG: + { + pConInfo = (PConsoleInfo) ((LPPROPSHEETPAGE)lParam)->lParam; + SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo); return TRUE; - + } default: break; } Modified: trunk/reactos/dll/win32/console/options.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/console/options.…
============================================================================== --- trunk/reactos/dll/win32/console/options.c (original) +++ trunk/reactos/dll/win32/console/options.c Mon Aug 21 03:55:08 2006 @@ -9,7 +9,13 @@ #include "console.h" -BOOLEAN InitializeOptionsDialog(); +static +void +UpdateDialogElements(HWND hwndDlg, PConsoleInfo pConInfo); + +static +BOOL +InitializeOptionsFromReg(TCHAR * Path, PConsoleInfo pConInfo); INT_PTR CALLBACK @@ -25,13 +31,17 @@ HWND hDlgCtrl; LPPSHNOTIFY lppsn; - pConInfo = (PConsoleInfo) GetWindowLongPtr(GetParent(hwndDlg), DWLP_USER); + pConInfo = (PConsoleInfo) GetWindowLongPtr(hwndDlg, DWLP_USER); switch(uMsg) { case WM_INITDIALOG: { - return InitializeOptionsDialog(hwndDlg); + pConInfo = (PConsoleInfo) ((LPPROPSHEETPAGE)lParam)->lParam; + SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo); + InitializeOptionsFromReg(pConInfo->szProcessName, pConInfo); + UpdateDialogElements(hwndDlg, pConInfo); + return TRUE; } case WM_NOTIFY: { @@ -149,6 +159,7 @@ return FALSE; } +static BOOL InitializeOptionsFromReg(TCHAR * Path, PConsoleInfo pConInfo) { HKEY hKey; @@ -157,7 +168,9 @@ DWORD dwIndex; DWORD dwValueName; DWORD dwValue; + DWORD dwType; TCHAR szValueName[MAX_PATH]; + TCHAR szValue[MAX_PATH]; DWORD Value; if ( RegOpenCurrentUser(KEY_READ, &hKey) != ERROR_SUCCESS ) @@ -170,26 +183,39 @@ return FALSE; } - RegQueryInfoKey(hKey, NULL, NULL, NULL, &dwNumSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); + RegQueryInfoKey(hSubKey, NULL, NULL, NULL, &dwNumSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); for (dwIndex = 0; dwIndex < dwNumSubKeys; dwIndex++) { dwValue = sizeof(Value); dwValueName = MAX_PATH; - if ( RegEnumValue(hSubKey, dwIndex, szValueName, &dwValueName, NULL, NULL, (BYTE*)&Value, &dwValue) != ERROR_SUCCESS) - break; - - if ( !_tcscmp(szValueName, _T("CursorSize")) ) - { - if ( Value == 0x32) - pConInfo->CursorSize = Value; - else if ( Value == 0x64 ) - pConInfo->CursorSize = Value; - } - else if ( !_tcscmp(szValueName, _T("NumberOfHistoryBuffers")) ) - { - pConInfo->NumberOfHistoryBuffers = Value; + if ( RegEnumValue(hSubKey, dwIndex, szValueName, &dwValueName, NULL, &dwType, (BYTE*)&Value, &dwValue) != ERROR_SUCCESS) + { + if (dwType == REG_SZ) + { + /* + * retry in case of string value + */ + dwValue = sizeof(szValue); + dwValueName = MAX_PATH; + if (RegEnumValue(hSubKey, dwIndex, szValueName, &dwValueName, NULL, NULL, (BYTE*)szValue, &dwValue) != ERROR_SUCCESS) + break; + } + else + break; + } + + if ( !_tcscmp(szValueName, _T("CursorSize")) ) + { + if ( Value == 0x32) + pConInfo->CursorSize = Value; + else if ( Value == 0x64 ) + pConInfo->CursorSize = Value; + } + else if ( !_tcscmp(szValueName, _T("NumberOfHistoryBuffers")) ) + { + pConInfo->NumberOfHistoryBuffers = Value; } else if ( !_tcscmp(szValueName, _T("HistoryBufferSize")) ) { @@ -218,6 +244,7 @@ return TRUE; } +static void UpdateDialogElements(HWND hwndDlg, PConsoleInfo pConInfo) { @@ -321,8 +348,7 @@ if (!pConInfo) return FALSE; - InitializeOptionsFromReg(pConInfo->szProcessName, pConInfo); - UpdateDialogElements(hwndDlg, pConInfo); + return TRUE; } Modified: trunk/reactos/dll/win32/console/resource.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/console/resource…
============================================================================== --- trunk/reactos/dll/win32/console/resource.h (original) +++ trunk/reactos/dll/win32/console/resource.h Mon Aug 21 03:55:08 2006 @@ -88,4 +88,8 @@ #define IDC_STATIC_COLOR15 626 #define IDC_STATIC_COLOR16 627 + +//string ids +#define IDS_SCREEN_TEXT 700 + #endif
18 years, 10 months
1
0
0
0
[ion] 23628: - Detect NPX/FPU in simple assembly and XMMI/SSE2 by using CPU Feature flags, replacing the old asm+c mess. - Handle FPU/SSE saving in the CONTEXT<->KTRAP_FRAME routines directly, and using KiFlushNPXState assembly function. - Implement a naive Trap 7 (FPU Fault) handler in assembly that properly does most of the work required to handle an FPU fault. Not yet complete however since it almost ignores user-mode faults (just like trunk). FPU isn't done in ctx switching yet. - Remove all
by ion@svn.reactos.org
Author: ion Date: Mon Aug 21 03:53:07 2006 New Revision: 23628 URL:
http://svn.reactos.org/svn/reactos?rev=23628&view=rev
Log: - Detect NPX/FPU in simple assembly and XMMI/SSE2 by using CPU Feature flags, replacing the old asm+c mess. - Handle FPU/SSE saving in the CONTEXT<->KTRAP_FRAME routines directly, and using KiFlushNPXState assembly function. - Implement a naive Trap 7 (FPU Fault) handler in assembly that properly does most of the work required to handle an FPU fault. Not yet complete however since it almost ignores user-mode faults (just like trunk). FPU isn't done in ctx switching yet. - Remove all the other .c code that dealt with FPU stuff and had become incompatible since more then a year ago. Modified: trunk/reactos/include/ndk/asm.h trunk/reactos/ntoskrnl/include/internal/i386/fpu.h trunk/reactos/ntoskrnl/ke/i386/ctxswitch.S trunk/reactos/ntoskrnl/ke/i386/exp.c trunk/reactos/ntoskrnl/ke/i386/fpu.c trunk/reactos/ntoskrnl/ke/i386/kernel.c trunk/reactos/ntoskrnl/ke/i386/trap.s Modified: trunk/reactos/include/ndk/asm.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/asm.h?rev=2362…
============================================================================== --- trunk/reactos/include/ndk/asm.h (original) +++ trunk/reactos/include/ndk/asm.h Mon Aug 21 03:53:07 2006 @@ -382,9 +382,16 @@ #define STATUS_INVALID_SYSTEM_SERVICE 0xC000001C #define STATUS_NO_CALLBACK_ACTIVE 0xC0000258 #define APC_INDEX_MISMATCH 0x01 +#define TRAP_CAUSE_UNKNOWN 0x12 #define IRQL_GT_ZERO_AT_SYSTEM_SERVICE 0x4A #define UNEXPECTED_KERNEL_MODE_TRAP 0x7F #define ATTEMPTED_SWITCH_FROM_DPC 0xB8 + +// +// IRQL Levels +// +#define PASSIVE_LEVEL 0x0 +#define APC_LEVEL 0x1 #endif // Modified: trunk/reactos/ntoskrnl/include/internal/i386/fpu.h URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
============================================================================== --- trunk/reactos/ntoskrnl/include/internal/i386/fpu.h (original) +++ trunk/reactos/ntoskrnl/include/internal/i386/fpu.h Mon Aug 21 03:53:07 2006 @@ -1,24 +1,5 @@ #ifndef __NTOSKRNL_INCLUDE_INTERNAL_I386_FPU_H #define __NTOSKRNL_INCLUDE_INTERNAL_I386_FPU_H -#include <internal/i386/ke.h> - -extern ULONG HardwareMathSupport; - -VOID -KiCheckFPU(VOID); - -NTSTATUS -KiHandleFpuFault(PKTRAP_FRAME Tf, ULONG ExceptionNr); - -VOID -KiFxSaveAreaToFloatingSaveArea(FLOATING_SAVE_AREA *FloatingSaveArea, CONST PFX_SAVE_AREA FxSaveArea); - -BOOL -KiContextToFxSaveArea(PFX_SAVE_AREA FxSaveArea, PCONTEXT Context); - -PFX_SAVE_AREA -KiGetFpuState(PKTHREAD Thread); - #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_FPU_H */ Modified: trunk/reactos/ntoskrnl/ke/i386/ctxswitch.S URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/ctxswitch…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/ctxswitch.S (original) +++ trunk/reactos/ntoskrnl/ke/i386/ctxswitch.S Mon Aug 21 03:53:07 2006 @@ -15,15 +15,190 @@ #include <ndk/asm.h> .intel_syntax noprefix -#define Running 2 -#define SIZEOF_TRAP_FRAME 0x8c -#define APC_LEVEL 1 - -/* GLOBALS ****************************************************************/ - -.extern _DispatcherDatabaseLock +#define Running 2 /* FUNCTIONS ****************************************************************/ + +.globl _KiIsNpxPresent@0 +.func KiIsNpxPresent@0 +_KiIsNpxPresent@0: + + /* Save stack */ + push ebp + + /* Get CR0 and mask out FPU flags */ + mov eax, cr0 + and eax, ~(CR0_MP + CR0_TS + CR0_EM + CR0_ET) + + /* Initialize the FPU and assume FALSE for return */ + xor edx, edx + fninit + + /* Save magic value on stack */ + mov ecx, 0x42424242 + push ecx + + /* Setup stack for FPU store */ + mov ebp ,esp + fnstsw [ebp] + + /* Now check if our magic got cleared */ + cmp byte ptr [ebp], 0 + jnz NoFpu + + /* Enable FPU, set return to TRUE */ + or eax, CR0_ET + mov edx, 1 + + /* If this is a 486 or higher, enable INT 16 as well */ + cmp dword ptr fs:KPCR_PRCB_CPU_TYPE, 3 + jbe NoFpu + or eax, CR0_NE + +NoFpu: + /* Set emulation enabled during the first boot phase and set the CR0 */ + or eax, (CR0_EM + CR0_TS) + mov cr0, eax + + /* Restore stack */ + pop eax + pop ebp + + /* Return true or false */ + mov eax, edx + ret +.endfunc + +.globl _KiFlushNPXState@4 +.func KiFlushNPXState@4 +_KiFlushNPXState@4: + + /* Save volatiles and disable interrupts */ + push esi + push edi + push ebx + pushfd + cli + + /* Save the PCR and get the current thread */ + mov edi, fs:[KPCR_SELF] + mov esi, [edi+KPCR_CURRENT_THREAD] + + /* Check if we're already loaded */ + cmp byte ptr [esi+KTHREAD_NPX_STATE], NPX_STATE_LOADED + je IsValid + + /* Check if we're supposed to get it */ + cmp dword ptr [esp+20], 0 + je Return + +#ifdef DBG + /* Assert Fxsr support */ + test byte ptr _KeI386FxsrPresent, 1 + jnz AssertOk + int 3 +AssertOk: +#endif + + /* Get CR0 and test if it's valid */ + mov ebx, cr0 + test bl, CR0_MP + CR0_TS + CR0_EM + jz Cr0OK + + /* Enable fnsave to work */ + and ebx, ~(CR0_MP + CR0_TS + CR0_EM) + mov cr0, ebx + +Cr0OK: + /* Check if we are the NPX Thread */ + mov eax, [edi+KPCR_NPX_THREAD] + or eax, eax + jz DontSave + + /* Check if it's not loaded */ + cmp byte ptr [eax+KTHREAD_NPX_STATE], NPX_STATE_NOT_LOADED + jnz DontSave + +#ifdef DBG + /* We are the NPX Thread with an unloaded NPX State... this isn't normal! */ + int 3 +#endif + + /* Save the NPX State */ + mov ecx, [eax+KTHREAD_INITIAL_STACK] + sub ecx, NPX_FRAME_LENGTH + fxsave [ecx] + mov byte ptr [eax+KTHREAD_NPX_STATE], NPX_STATE_NOT_LOADED + +DontSave: + /* Load the NPX State */ + mov ecx, [esi+KTHREAD_INITIAL_STACK] + sub ecx, NPX_FRAME_LENGTH + fxrstor [ecx] + + /* Get the CR0 state and destination */ + mov edx, [ecx+FN_CR0_NPX_STATE] + mov ecx, [esp+20] + jmp DoneLoad + +IsValid: + /* We already have a valid state, flush it */ + mov ebx, cr0 + test bl, CR0_MP + CR0_TS + CR0_EM + jz Cr0OK2 + + /* Enable fnsave to work */ + and ebx, ~(CR0_MP + CR0_TS + CR0_EM) + mov cr0, ebx + +Cr0OK2: + /* Get the kernel stack */ + mov ecx, [esi+KTHREAD_INITIAL_STACK] + test byte ptr _KeI386FxsrPresent, 1 + lea ecx, [ecx-NPX_FRAME_LENGTH] + + /* Set the NPX State */ + mov byte ptr [esi+KTHREAD_NPX_STATE], NPX_STATE_NOT_LOADED + + /* Get Cr0 */ + mov edx, [ecx+FN_CR0_NPX_STATE] + jz DoneLoad + + /* Save the FX State */ + fxsave [ecx] + + /* Check if we also have to save it in the parameter */ + mov ecx, [esp+20] + jecxz NoSave + +DoneLoad: + /* Save the Fn state in the parameter we got */ + fnsave [ecx] + fwait + +NoSave: + /* Clear eax */ + xor eax, eax + + /* Add NPX State */ + or ebx, NPX_STATE_NOT_LOADED + + /* Clear the NPX thread */ + mov [edi+KPCR_NPX_THREAD], eax + + /* Add saved CR0 into NPX State, and set it */ + or ebx, edx + mov cr0, ebx + + /* Re-enable interrupts and return */ +Return: + popf + pop ebx + pop edi + pop esi + ret 4 + +.endfunc /*++ * KiThreadStartup Modified: trunk/reactos/ntoskrnl/ke/i386/exp.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/exp.c?rev…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/exp.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/exp.c Mon Aug 21 03:53:07 2006 @@ -28,10 +28,18 @@ #pragma alloc_text(INIT, KeInitExceptions) #endif +#define SIZE_OF_FX_REGISTERS 32 + VOID NTAPI Ki386AdjustEsp0( IN PKTRAP_FRAME TrapFrame +); + +VOID +NTAPI +KiFlushNPXState( + IN FLOATING_SAVE_AREA *SaveArea ); extern KIDTENTRY KiIdt[]; @@ -467,10 +475,10 @@ */ { ULONG_PTR cr2; - NTSTATUS Status; ULONG Esp0; ASSERT(ExceptionNr != 14); + ASSERT((ExceptionNr != 7 && ExceptionNr != 16 && ExceptionNr != 19)); /* Use the address of the trap frame as approximation to the ring0 esp */ Esp0 = (ULONG)&Tf->Eip; @@ -526,18 +534,6 @@ } /* - * Try to handle device-not-present, math-fault and xmm-fault exceptions. - */ - if (ExceptionNr == 7 || ExceptionNr == 16 || ExceptionNr == 19) - { - Status = KiHandleFpuFault(Tf, ExceptionNr); - if (NT_SUCCESS(Status)) - { - return(0); - } - } - - /* * Handle user exceptions differently */ if ((Tf->SegCs & 0xFFFF) == (KGDT_R3_CODE | RPL_MASK)) @@ -660,6 +656,23 @@ /* Usermode, save the User SS */ TrapFrame->HardwareSegSs = Ss | RPL_MASK; } +} + +USHORT +NTAPI +KiTagWordFnsaveToFxsave(USHORT TagWord) +{ + INT FxTagWord = ~TagWord; + + /* + * Empty is now 00, any 2 bits containing 1 mean valid + * Now convert the rest (11->0 and the rest to 1) + */ + FxTagWord = (FxTagWord | (FxTagWord >> 1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */ + FxTagWord = (FxTagWord | (FxTagWord >> 1)) & 0x3333; /* 00VV00VV00VV00VV */ + FxTagWord = (FxTagWord | (FxTagWord >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */ + FxTagWord = (FxTagWord | (FxTagWord >> 4)) & 0x00ff; /* 00000000VVVVVVVV */ + return FxTagWord; } VOID @@ -671,7 +684,7 @@ IN KPROCESSOR_MODE PreviousMode) { PFX_SAVE_AREA FxSaveArea; - //ULONG i; Future Use + ULONG i; BOOLEAN V86Switch = FALSE; /* Start with the basic Registers */ @@ -784,7 +797,21 @@ /* Check if NPX is present */ if (KeI386NpxPresent) { - /* Future use */ + /* Flush the NPX State */ + KiFlushNPXState(NULL); + + /* Copy the FX State */ + RtlCopyMemory(&FxSaveArea->U.FxArea, + &Context->ExtendedRegisters[0], + MAXIMUM_SUPPORTED_EXTENSION); + + /* Remove reserved bits from MXCSR */ + FxSaveArea->U.FxArea.MXCsr &= ~0xFFBF; + + /* Mask out any invalid flags */ + FxSaveArea->Cr0NpxState &= ~(CR0_EM | CR0_MP | CR0_TS); + + /* FIXME: Check if this is a VDM app */ } } @@ -799,11 +826,58 @@ /* Check if NPX is present */ if (KeI386NpxPresent) { - /* Future use */ + /* Flush the NPX State */ + KiFlushNPXState(NULL); + + /* Check if we have Fxsr support */ + if (KeI386FxsrPresent) + { + /* Convert the Fn Floating Point state to Fx */ + FxSaveArea->U.FxArea.ControlWord = + (USHORT)Context->FloatSave.ControlWord; + FxSaveArea->U.FxArea.StatusWord = + (USHORT)Context->FloatSave.StatusWord; + FxSaveArea->U.FxArea.TagWord = + KiTagWordFnsaveToFxsave((USHORT)Context->FloatSave.TagWord); + FxSaveArea->U.FxArea.ErrorOpcode = + (USHORT)(Context->FloatSave.ErrorSelector >> 16); + FxSaveArea->U.FxArea.ErrorOffset = + Context->FloatSave.ErrorOffset; + FxSaveArea->U.FxArea.ErrorSelector = + Context->FloatSave.ErrorSelector & 0xFFFF; + FxSaveArea->U.FxArea.DataOffset = + Context->FloatSave.DataOffset; + FxSaveArea->U.FxArea.DataSelector = + Context->FloatSave.DataSelector & 0xFFFF; + + /* Clear out the Register Area */ + RtlZeroMemory(&FxSaveArea->U.FxArea.RegisterArea[0], SIZE_OF_FX_REGISTERS); + + /* Loop the 8 floating point registers */ + for (i = 0; i < 8; i++) + { + /* Copy from Fn to Fx */ + RtlCopyMemory(FxSaveArea->U.FxArea.RegisterArea + (i * 16), + Context->FloatSave.RegisterArea + (i * 10), + 10); + } + } + else + { + /* Just dump the Fn state in */ + RtlCopyMemory(&FxSaveArea->U.FnArea, + &Context->FloatSave, + sizeof(FNSAVE_FORMAT)); + } + + /* Mask out any invalid flags */ + FxSaveArea->Cr0NpxState &= ~(CR0_EM | CR0_MP | CR0_TS); + + /* FIXME: Check if this is a VDM app */ } else { - /* Future use */ + /* FIXME: Handle FPU Emulation */ } } @@ -826,9 +900,6 @@ (Context->Dr7 & DR7_ACTIVE); } } - - /* Handle FPU and Extended Registers */ - KiContextToFxSaveArea((PFX_SAVE_AREA)(TrapFrame + 1), Context); } VOID @@ -837,7 +908,13 @@ IN PKEXCEPTION_FRAME ExceptionFrame, IN OUT PCONTEXT Context) { - PFX_SAVE_AREA FxSaveArea = NULL; + PFX_SAVE_AREA FxSaveArea; + struct _AlignHack + { + UCHAR Hack[15]; + FLOATING_SAVE_AREA UnalignedArea; + } FloatSaveBuffer; + FLOATING_SAVE_AREA *FloatSaveArea; /* Start with the Control flags */ if ((Context->ContextFlags & CONTEXT_CONTROL) == CONTEXT_CONTROL) @@ -920,19 +997,13 @@ /* Make sure NPX is present */ if (KeI386NpxPresent) { - /* Future use */ - } - - /* Old code */ - FxSaveArea = KiGetFpuState(KeGetCurrentThread()); - if (FxSaveArea != NULL) - { - memcpy(Context->ExtendedRegisters, &FxSaveArea->U.FxArea, - min(sizeof (Context->ExtendedRegisters), sizeof (FxSaveArea->U.FxArea)) ); - } - else - { - Context->ContextFlags &= (~CONTEXT_EXTENDED_REGISTERS) | CONTEXT_i386; + /* Flush the NPX State */ + KiFlushNPXState(NULL); + + /* Copy the registers */ + RtlCopyMemory(&Context->ExtendedRegisters[0], + &FxSaveArea->U.FxArea, + MAXIMUM_SUPPORTED_EXTENSION); } } @@ -946,24 +1017,34 @@ /* Make sure we have an NPX */ if (KeI386NpxPresent) - { - /* Future use */ - } - else - { - /* Future Use */ - } - - /* Old code */ - FxSaveArea = KiGetFpuState(KeGetCurrentThread()); - if (FxSaveArea != NULL) - { - KiFxSaveAreaToFloatingSaveArea(&Context->FloatSave, FxSaveArea); - } - else - { - Context->ContextFlags &= (~CONTEXT_FLOATING_POINT) | CONTEXT_i386; - } + { + /* Check if we have Fxsr support */ + if (KeI386FxsrPresent) + { + /* Align the floating area to 16-bytes */ + FloatSaveArea = (FLOATING_SAVE_AREA*) + ((ULONG_PTR)&FloatSaveBuffer.UnalignedArea &~ 0xF); + + /* Get the State */ + KiFlushNPXState(FloatSaveArea); + } + else + { + /* We don't, use the FN area and flush the NPX State */ + FloatSaveArea = (FLOATING_SAVE_AREA*)&FxSaveArea->U.FnArea; + KiFlushNPXState(NULL); + } + + /* Copy into the Context */ + RtlCopyMemory(&Context->FloatSave, + &FxSaveArea->U.FnArea, + sizeof(FNSAVE_FORMAT)); + } + else + { + /* FIXME: Handle Emulation */ + Context->ContextFlags &= (~CONTEXT_FLOATING_POINT) | CONTEXT_i386; + } } /* Handle debug registers */ Modified: trunk/reactos/ntoskrnl/ke/i386/fpu.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/fpu.c?rev…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/fpu.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/fpu.c Mon Aug 21 03:53:07 2006 @@ -14,462 +14,7 @@ #define NDEBUG #include <internal/debug.h> -/* DEFINES *******************************************************************/ - -/* x87 Status Word exception flags */ -#define X87_SW_IE (1<<0) /* Invalid Operation */ -#define X87_SW_DE (1<<1) /* Denormalized Operand */ -#define X87_SW_ZE (1<<2) /* Zero Devide */ -#define X87_SW_OE (1<<3) /* Overflow */ -#define X87_SW_UE (1<<4) /* Underflow */ -#define X87_SW_PE (1<<5) /* Precision */ -#define X87_SW_SE (1<<6) /* Stack Fault */ - -#define X87_SW_ES (1<<7) /* Error Summary */ - -/* MXCSR exception flags */ -#define MXCSR_IE (1<<0) /* Invalid Operation */ -#define MXCSR_DE (1<<1) /* Denormalized Operand */ -#define MXCSR_ZE (1<<2) /* Zero Devide */ -#define MXCSR_OE (1<<3) /* Overflow */ -#define MXCSR_UE (1<<4) /* Underflow */ -#define MXCSR_PE (1<<5) /* Precision */ -#define MXCSR_DAZ (1<<6) /* Denormals Are Zeros (P4 only) */ - -/* GLOBALS *******************************************************************/ - -extern ULONG KeI386NpxPresent; -extern ULONG KeI386XMMIPresent; -extern ULONG KeI386FxsrPresent; - -static ULONG MxcsrFeatureMask = 0; - /* FUNCTIONS *****************************************************************/ - -STATIC USHORT -KiTagWordFnsaveToFxsave(USHORT TagWord) -{ - INT tmp; - - /* - * Converts the tag-word. 11 (Empty) is converted into 0, everything else into 1 - */ - tmp = ~TagWord; /* Empty is now 00, any 2 bits containing 1 mean valid */ - tmp = (tmp | (tmp >> 1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */ - tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */ - tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */ - tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */ - - return tmp; -} - - -STATIC USHORT -KiTagWordFxsaveToFnsave(PFXSAVE_FORMAT FxSave) -{ - USHORT TagWord = 0; - UCHAR Tag; - INT i; - struct FPREG { USHORT Significand[4]; USHORT Exponent; } *FpReg; - - for (i = 0; i < 8; i++) - { - if (FxSave->TagWord & (1 << i)) /* valid */ - { - FpReg = (struct FPREG *)(FxSave->RegisterArea + (i * 16)); - switch (FpReg->Exponent & 0x00007fff) - { - case 0x0000: - if (FpReg->Significand[0] == 0 && FpReg->Significand[1] == 0 && - FpReg->Significand[2] == 0 && FpReg->Significand[3] == 0) - Tag = 1; /* Zero */ - else - Tag = 2; /* Special */ - break; - - case 0x7fff: - Tag = 2; /* Special */ - break; - - default: - if (FpReg->Significand[3] & 0x00008000) - Tag = 0; /* Valid */ - else - Tag = 2; /* Special */ - break; - } - } - else /* empty */ - { - Tag = 3; - } - TagWord |= Tag << (i * 2); - } - - return TagWord; -} - - -STATIC VOID -KiFnsaveToFxsaveFormat(PFXSAVE_FORMAT FxSave, PFNSAVE_FORMAT FnSave) -{ - INT i; - - FxSave->ControlWord = (USHORT)FnSave->ControlWord; - FxSave->StatusWord = (USHORT)FnSave->StatusWord; - FxSave->TagWord = KiTagWordFnsaveToFxsave((USHORT)FnSave->TagWord); - FxSave->ErrorOpcode = (USHORT)(FnSave->ErrorSelector >> 16); - FxSave->ErrorOffset = FnSave->ErrorOffset; - FxSave->ErrorSelector = FnSave->ErrorSelector & 0x0000ffff; - FxSave->DataOffset = FnSave->DataOffset; - FxSave->DataSelector = FnSave->DataSelector & 0x0000ffff; - if (KeI386XMMIPresent) - FxSave->MXCsr = 0x00001f80 & MxcsrFeatureMask; - else - FxSave->MXCsr = 0; - FxSave->MXCsrMask = MxcsrFeatureMask; - memset(FxSave->Reserved3, 0, sizeof(FxSave->Reserved3) + - sizeof(FxSave->Reserved4)); /* Don't zero Align16Byte because Context->ExtendedRegisters - is only 512 bytes, not 520 */ - for (i = 0; i < 8; i++) - { - memcpy(FxSave->RegisterArea + (i * 16), FnSave->RegisterArea + (i * 10), 10); - memset(FxSave->RegisterArea + (i * 16) + 10, 0, 6); - } -} - -STATIC VOID -KiFxsaveToFnsaveFormat(PFNSAVE_FORMAT FnSave, PFXSAVE_FORMAT FxSave) -{ - INT i; - - FnSave->ControlWord = 0xffff0000 | FxSave->ControlWord; - FnSave->StatusWord = 0xffff0000 | FxSave->StatusWord; - FnSave->TagWord = 0xffff0000 | KiTagWordFxsaveToFnsave(FxSave); - FnSave->ErrorOffset = FxSave->ErrorOffset; - FnSave->ErrorSelector = FxSave->ErrorSelector & 0x0000ffff; - FnSave->ErrorSelector |= FxSave->ErrorOpcode << 16; - FnSave->DataOffset = FxSave->DataOffset; - FnSave->DataSelector = FxSave->DataSelector | 0xffff0000; - for (i = 0; i < 8; i++) - { - memcpy(FnSave->RegisterArea + (i * 10), FxSave->RegisterArea + (i * 16), 10); - } -} - - -STATIC VOID -KiFloatingSaveAreaToFxSaveArea(PFX_SAVE_AREA FxSaveArea, FLOATING_SAVE_AREA *FloatingSaveArea) -{ - if (KeI386FxsrPresent) - { - KiFnsaveToFxsaveFormat(&FxSaveArea->U.FxArea, (PFNSAVE_FORMAT)FloatingSaveArea); - } - else - { - memcpy(&FxSaveArea->U.FnArea, FloatingSaveArea, sizeof(FxSaveArea->U.FnArea)); - } - FxSaveArea->NpxSavedCpu = 0; - FxSaveArea->Cr0NpxState = FloatingSaveArea->Cr0NpxState; -} - - -VOID -KiFxSaveAreaToFloatingSaveArea(FLOATING_SAVE_AREA *FloatingSaveArea, CONST PFX_SAVE_AREA FxSaveArea) -{ - if (KeI386FxsrPresent) - { - KiFxsaveToFnsaveFormat((PFNSAVE_FORMAT)FloatingSaveArea, &FxSaveArea->U.FxArea); - } - else - { - memcpy(FloatingSaveArea, &FxSaveArea->U.FnArea, sizeof(FxSaveArea->U.FnArea)); - } - FloatingSaveArea->Cr0NpxState = FxSaveArea->Cr0NpxState; -} - - -BOOL -KiContextToFxSaveArea(PFX_SAVE_AREA FxSaveArea, PCONTEXT Context) -{ - BOOL FpuContextChanged = FALSE; - - /* First of all convert the FLOATING_SAVE_AREA into the FX_SAVE_AREA */ - if ((Context->ContextFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT) - { - KiFloatingSaveAreaToFxSaveArea(FxSaveArea, &Context->FloatSave); - FpuContextChanged = TRUE; - } - - /* Now merge the FX_SAVE_AREA from the context with the destination area */ - if ((Context->ContextFlags & CONTEXT_EXTENDED_REGISTERS) == CONTEXT_EXTENDED_REGISTERS) - { - if (KeI386FxsrPresent) - { - PFXSAVE_FORMAT src = (PFXSAVE_FORMAT)Context->ExtendedRegisters; - PFXSAVE_FORMAT dst = &FxSaveArea->U.FxArea; - dst->MXCsr = src->MXCsr & MxcsrFeatureMask; - memcpy(dst->Reserved3, src->Reserved3, - sizeof(src->Reserved3) + sizeof(src->Reserved4)); - - if ((Context->ContextFlags & CONTEXT_FLOATING_POINT) != CONTEXT_FLOATING_POINT) - { - dst->ControlWord = src->ControlWord; - dst->StatusWord = src->StatusWord; - dst->TagWord = src->TagWord; - dst->ErrorOpcode = src->ErrorOpcode; - dst->ErrorOffset = src->ErrorOffset; - dst->ErrorSelector = src->ErrorSelector; - dst->DataOffset = src->DataOffset; - dst->DataSelector = src->DataSelector; - memcpy(dst->RegisterArea, src->RegisterArea, sizeof(src->RegisterArea)); - - FxSaveArea->NpxSavedCpu = 0; - FxSaveArea->Cr0NpxState = 0; - } - FpuContextChanged = TRUE; - } - } - - return FpuContextChanged; -} - - -VOID INIT_FUNCTION -KiCheckFPU(VOID) -{ - unsigned short int status; - int cr0; - ULONG Flags; - PKPRCB Prcb = KeGetCurrentPrcb(); - - Ke386SaveFlags(Flags); - Ke386DisableInterrupts(); - - KeI386NpxPresent = 0; - KeI386FxsrPresent = 0; - KeI386XMMIPresent = 0; - - cr0 = Ke386GetCr0(); - cr0 |= X86_CR0_NE | X86_CR0_MP; - cr0 &= ~(X86_CR0_EM | X86_CR0_TS); - Ke386SetCr0(cr0); - -#if defined(__GNUC__) - asm volatile("fninit\n\t"); - asm volatile("fstsw %0\n\t" : "=a" (status)); -#elif defined(_MSC_VER) - __asm - { - fninit; - fstsw status - } -#else -#error Unknown compiler for inline assembler -#endif - - if (status != 0) - { - /* Set the EM flag in CR0 so any FPU instructions cause a trap. */ - Ke386SetCr0(Ke386GetCr0() | X86_CR0_EM); - Ke386RestoreFlags(Flags); - return; - } - - /* fsetpm for i287, ignored by i387 */ -#if defined(__GNUC__) - asm volatile(".byte 0xDB, 0xE4\n\t"); -#elif defined(_MSC_VER) - __asm _emit 0xDB __asm _emit 0xe4 -#else -#error Unknown compiler for inline assembler -#endif - - KeI386NpxPresent = 1; - - /* check for and enable MMX/SSE support if possible */ - if ((Prcb->FeatureBits & X86_FEATURE_FXSR) != 0) - { - BYTE DummyArea[sizeof(FX_SAVE_AREA) + 15]; - PFX_SAVE_AREA FxSaveArea; - - /* enable FXSR */ - KeI386FxsrPresent = 1; - - /* we need a 16 byte aligned FX_SAVE_AREA */ - FxSaveArea = (PFX_SAVE_AREA)(((ULONG_PTR)DummyArea + 0xf) & (~0x0f)); - - Ke386SetCr4(Ke386GetCr4() | X86_CR4_OSFXSR); - memset(&FxSaveArea->U.FxArea, 0, sizeof(FxSaveArea->U.FxArea)); - asm volatile("fxsave %0" : : "m"(FxSaveArea->U.FxArea)); - MxcsrFeatureMask = FxSaveArea->U.FxArea.MXCsrMask; - if (MxcsrFeatureMask == 0) - { - MxcsrFeatureMask = 0x0000ffbf; - } - } - /* FIXME: Check for SSE3 in Ke386CpuidFlags2! */ - if (Prcb->FeatureBits & (X86_FEATURE_SSE | X86_FEATURE_SSE2)) - { - Ke386SetCr4(Ke386GetCr4() | X86_CR4_OSXMMEXCPT); - - /* enable SSE */ - KeI386XMMIPresent = 1; - } - - Ke386SetCr0(Ke386GetCr0() | X86_CR0_TS); - Ke386RestoreFlags(Flags); -} - - -PFX_SAVE_AREA -KiGetFpuState(PKTHREAD Thread) -{ - PFX_SAVE_AREA FxSaveArea = NULL; - KIRQL OldIrql; - ULONG Cr0; - - KeRaiseIrql(DISPATCH_LEVEL, &OldIrql); - if (Thread->NpxState & NPX_STATE_LOADED) - { - FxSaveArea = (PFX_SAVE_AREA)((ULONG_PTR)Thread->InitialStack - sizeof (FX_SAVE_AREA)); - if (Thread->NpxState & NPX_STATE_NOT_LOADED) - { - ASSERT(KeGetCurrentPrcb()->NpxThread == Thread); - - Cr0 = Ke386GetCr0(); - asm volatile("clts"); - if (KeI386FxsrPresent) - asm volatile("fxsave %0" : : "m"(FxSaveArea->U.FxArea)); - else - { - asm volatile("fnsave %0" : : "m"(FxSaveArea->U.FnArea)); - /* FPU state has to be reloaded because fnsave changes it. */ - Cr0 |= X86_CR0_TS; - KeGetCurrentPrcb()->NpxThread = NULL; - } - Ke386SetCr0(Cr0); - Thread->NpxState = NPX_STATE_LOADED; - } - } - KeLowerIrql(OldIrql); - - return FxSaveArea; -} - - -NTSTATUS -KiHandleFpuFault(PKTRAP_FRAME Tf, ULONG ExceptionNr) -{ - if (ExceptionNr == 7) /* device not present */ - { - //BOOL FpuInitialized = FALSE; - unsigned int cr0 = Ke386GetCr0(); - PKTHREAD CurrentThread; - //PFX_SAVE_AREA FxSaveArea; - KIRQL oldIrql; - - (void) cr0; - ASSERT((cr0 & X86_CR0_TS) == X86_CR0_TS); - ASSERT((Tf->EFlags & X86_EFLAGS_VM) == 0); - ASSERT((cr0 & X86_CR0_EM) == 0); - - /* disable scheduler, clear TS in cr0 */ - ASSERT_IRQL(DISPATCH_LEVEL); - KeRaiseIrql(DISPATCH_LEVEL, &oldIrql); - asm volatile("clts"); - - CurrentThread = KeGetCurrentThread(); - ASSERT(CurrentThread != NULL); - - CurrentThread->NpxState |= NPX_STATE_NOT_LOADED; - KeLowerIrql(oldIrql); - DPRINT("Device not present exception handled!\n"); - - return STATUS_SUCCESS; - } - else /* ExceptionNr == 16 || ExceptionNr == 19 */ - { - EXCEPTION_RECORD Er; - KPROCESSOR_MODE PreviousMode; - PKTHREAD CurrentThread, NpxThread; - KIRQL OldIrql; - ULONG FpuEnvBuffer[7]; - PFNSAVE_FORMAT FpuEnv = (PFNSAVE_FORMAT)FpuEnvBuffer; - - ASSERT(ExceptionNr == 16 || ExceptionNr == 19); /* math fault or XMM fault*/ - - KeRaiseIrql(DISPATCH_LEVEL, &OldIrql); - - NpxThread = KeGetCurrentPrcb()->NpxThread; - CurrentThread = KeGetCurrentThread(); - if (NpxThread == NULL) - { - KeLowerIrql(OldIrql); - DPRINT("Math/Xmm fault ignored! (NpxThread == NULL)\n"); - return STATUS_SUCCESS; - } - if (ExceptionNr == 16) - { - asm volatile("fnstenv %0" : : "m"(*FpuEnv)); - asm volatile("fldenv %0" : : "m"(*FpuEnv)); /* Stupid x87... */ - FpuEnv->StatusWord &= 0xffff; - } - KeLowerIrql(OldIrql); - - PreviousMode = ((Tf->SegCs & 0xffff) == (KGDT_R3_CODE | RPL_MASK)) ? (UserMode) : (KernelMode); - DPRINT("Math/Xmm fault happened! (PreviousMode = %s)\n", - (PreviousMode != KernelMode) ? ("UserMode") : ("KernelMode")); - - ASSERT(NpxThread == CurrentThread); /* FIXME: Is not always true I think */ - - /* Get FPU/XMM state */ - KeLowerIrql(OldIrql); - - /* Determine exception code */ - if (ExceptionNr == 16) - { - DPRINT("FpuStatusWord = 0x%04x\n", FpuStatusWord); - - if (FpuEnv->StatusWord & X87_SW_IE) - Er.ExceptionCode = STATUS_FLOAT_INVALID_OPERATION; - else if (FpuEnv->StatusWord & X87_SW_DE) - Er.ExceptionCode = STATUS_FLOAT_DENORMAL_OPERAND; - else if (FpuEnv->StatusWord & X87_SW_ZE) - Er.ExceptionCode = STATUS_FLOAT_DIVIDE_BY_ZERO; - else if (FpuEnv->StatusWord & X87_SW_OE) - Er.ExceptionCode = STATUS_FLOAT_OVERFLOW; - else if (FpuEnv->StatusWord & X87_SW_UE) - Er.ExceptionCode = STATUS_FLOAT_UNDERFLOW; - else if (FpuEnv->StatusWord & X87_SW_PE) - Er.ExceptionCode = STATUS_FLOAT_INEXACT_RESULT; - else if (FpuEnv->StatusWord & X87_SW_SE) - Er.ExceptionCode = STATUS_FLOAT_STACK_CHECK; - else - ASSERT(0); /* not reached */ - Er.ExceptionAddress = (PVOID)FpuEnv->ErrorOffset; - } - else /* ExceptionNr == 19 */ - { - Er.ExceptionCode = STATUS_FLOAT_MULTIPLE_TRAPS; - Er.ExceptionAddress = (PVOID)Tf->Eip; - } - - Er.ExceptionFlags = 0; - Er.ExceptionRecord = NULL; - Er.NumberParameters = 0; - - /* Dispatch exception */ - DPRINT("Dispatching exception (ExceptionCode = 0x%08x)\n", Er.ExceptionCode); - KiDispatchException(&Er, NULL, Tf, PreviousMode, TRUE); - - DPRINT("Math-fault handled!\n"); - return STATUS_SUCCESS; - } - - return STATUS_UNSUCCESSFUL; -} - /* This is a rather naive implementation of Ke(Save/Restore)FloatingPointState which will not work for WDM drivers. Please feel free to improve */ Modified: trunk/reactos/ntoskrnl/ke/i386/kernel.c URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/kernel.c?…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/kernel.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/kernel.c Mon Aug 21 03:53:07 2006 @@ -31,6 +31,7 @@ BOOLEAN Ke386GlobalPagesEnabled = FALSE; ULONG KiFastSystemCallDisable = 1; ULONG KeI386NpxPresent = 0; +ULONG MxcsrFeatureMask = 0; ULONG KeI386XMMIPresent = 0; ULONG KeI386FxsrPresent = 0; extern PVOID Ki386InitialStackArray[MAXIMUM_PROCESSORS]; @@ -47,7 +48,46 @@ #pragma alloc_text(INIT, Ki386SetProcessorFeatures) #endif +BOOLEAN +NTAPI +KiIsNpxPresent( + VOID +); + /* FUNCTIONS *****************************************************************/ + +VOID +INIT_FUNCTION +NTAPI +KiCheckFPU(VOID) +{ + PKPRCB Prcb = KeGetCurrentPrcb(); + + /* Check for a math co-processor (NPX) */ + KeI386NpxPresent = KiIsNpxPresent(); + + /* Check for and enable MMX/SSE support if possible */ + KeI386FxsrPresent = Prcb->FeatureBits & X86_FEATURE_FXSR ? TRUE : FALSE; + + /* Check for SSE (2 and 3 should have this set too) */ + KeI386XMMIPresent = Prcb->FeatureBits & X86_FEATURE_SSE ? TRUE : FALSE; + + /* Check if Fxsr was found */ + if (KeI386FxsrPresent) + { + /* Enable it. FIXME: Send an IPI */ + Ke386SetCr4(Ke386GetCr4() | X86_CR4_OSFXSR); + + /* Check if XMM was found too */ + if (KeI386XMMIPresent) + { + /* Enable it: FIXME: Send an IPI. */ + Ke386SetCr4(Ke386GetCr4() | X86_CR4_OSXMMEXCPT); + + /* FIXME: Implement and enable XMM Page Zeroing for Mm */ + } + } +} static VOID INIT_FUNCTION Ki386GetCpuId(VOID) Modified: trunk/reactos/ntoskrnl/ke/i386/trap.s URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/trap.s?re…
============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/trap.s (original) +++ trunk/reactos/ntoskrnl/ke/i386/trap.s Mon Aug 21 03:53:07 2006 @@ -819,6 +819,7 @@ jne _Kei386EoiHelper@0 jmp _KiV86Complete +.func KiTrap7 _KiTrap7: /* Push error code */ push 0 @@ -826,18 +827,134 @@ /* Enter trap */ TRAP_PROLOG(7) - /* Call the C exception handler */ - push 7 - push ebp - call _KiTrapHandler - add esp, 8 - - /* Check for v86 recovery */ - cmp eax, 1 - - /* Return to caller */ - jne _Kei386EoiHelper@0 - jmp _KiV86Complete + /* Get the current thread and stack */ +StartTrapHandle: + mov eax, [fs:KPCR_CURRENT_THREAD] + mov ecx, [eax+KTHREAD_INITIAL_STACK] + sub ecx, NPX_FRAME_LENGTH + + /* Check if emulation is enabled */ + test dword ptr [ecx+FN_CR0_NPX_STATE], CR0_EM + jnz EmulationEnabled + +CheckState: + /* Check if the NPX state is loaded */ + cmp byte ptr [eax+KTHREAD_NPX_STATE], NPX_STATE_LOADED + mov ebx, cr0 + jz IsLoaded + + /* Remove flags */ + and ebx, ~(CR0_MP + CR0_TS + CR0_EM) + mov cr0, ebx + + /* Check the NPX thread */ + mov edx, [fs:KPCR_NPX_THREAD] + or edx, edx + jz NoNpxThread + + /* Get the NPX Stack */ + mov esi, [edx+KTHREAD_INITIAL_STACK] + sub esi, NPX_FRAME_LENGTH + + /* Check if we have FXSR and check which operand to use */ + test byte ptr _KeI386FxsrPresent, 1 + jz FnSave + fxsave [esi] + jmp AfterSave + +FnSave: + fnsave [esi] + +AfterSave: + /* Set the thread's state to dirty */ + mov byte ptr [edx+KTHREAD_NPX_STATE], NPX_STATE_NOT_LOADED + +NoNpxThread: + /* Check if we have FXSR and choose which operand to use */ + test byte ptr _KeI386FxsrPresent, 1 + jz FrRestore + fxrstor [ecx] + jmp AfterRestore + +FrRestore: + frstor [esi] + +AfterRestore: + /* Set state loaded */ + mov byte ptr [eax+KTHREAD_NPX_STATE], NPX_STATE_LOADED + mov [fs:KPCR_NPX_THREAD], eax + + /* Enable interrupts to happen now */ + sti + nop + + /* Check if CR0 needs to be reloaded due to a context switch */ + cmp dword ptr [ecx+FN_CR0_NPX_STATE], 0 + jz _Kei386EoiHelper@0 + + /* We have to reload CR0... disable interrupts */ + cli + + /* Get CR0 and update it */ + mov ebx, cr0 + or ebx, [ecx+FN_CR0_NPX_STATE] + mov cr0, ebx + + /* Restore interrupts and check if TS is back on */ + sti + test bl, CR0_TS + jz _Kei386EoiHelper@0 + + /* Clear TS, and loop handling again */ + clts + cli + jmp StartTrapHandle + +IsLoaded: + /* Check if TS is set */ + test bl, CR0_TS + jnz TsSetOnLoadedState + + /* Check if the trap came from user-mode */ + int 3 + +EmulationEnabled: + /* Did this come from kernel-mode? */ + cmp word ptr [ebp+KTRAP_FRAME_CS], KGDT_R0_CODE + jz CheckState + + /* It came from user-mode, so this would only be valid inside a VDM */ + /* Since we don't actually have VDMs in ROS, bugcheck. */ + jmp BogusTrap2 + +TsSetOnLoadedState: + /* TS shouldn't be set, unless this we don't have a Math Processor */ + test bl, CR0_MP + jnz BogusTrap + + /* Strange that we got a trap at all, but ignore and continue */ + clts + jmp _Kei386EoiHelper@0 + +BogusTrap2: + /* Cause a bugcheck */ + sti + push 0 + push 0 + push eax + push 1 + push TRAP_CAUSE_UNKNOWN + call _KeBugCheckEx@20 + +BogusTrap: + /* Cause a bugcheck */ + push 0 + push 0 + push ebx + push 2 + push TRAP_CAUSE_UNKNOWN + call _KeBugCheckEx@20 +.endfunc .globl _KiTrap8 _KiTrap8: @@ -864,6 +981,7 @@ jne _Kei386EoiHelper@0 jmp _KiV86Complete +#if 1 _KiTrap10: /* Enter trap */ TRAP_PROLOG(10) @@ -880,6 +998,7 @@ /* Return to caller */ jne _Kei386EoiHelper@0 jmp _KiV86Complete +#endif _KiTrap11: /* Enter trap */ @@ -915,6 +1034,7 @@ jne _Kei386EoiHelper@0 jmp _KiV86Complete +#if 1 _KiTrap13: /* Enter trap */ TRAP_PROLOG(13) @@ -931,6 +1051,7 @@ /* Return to caller */ jne _Kei386EoiHelper@0 jmp _KiV86Complete +#endif _KiTrap14: /* Enter trap */
18 years, 10 months
1
0
0
0
← Newer
1
...
19
20
21
22
23
24
25
...
45
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Results per page:
10
25
50
100
200