1 /* $Id: fpu.c,v 1.11 2003/11/06 20:40:25 gvg Exp $
4 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/ke/i386/fpu.c
23 * PURPOSE: Handles the FPU
24 * PROGRAMMER: David Welch (welch@mcmail.com)
29 /* INCLUDES *****************************************************************/
31 #include <ddk/ntddk.h>
32 #include <internal/ke.h>
33 #include <internal/mm.h>
34 #include <internal/ps.h>
37 #include <internal/debug.h>
39 /* GLOBALS *******************************************************************/
41 ULONG HardwareMathSupport
;
43 /* FUNCTIONS *****************************************************************/
48 unsigned short int status
;
51 HardwareMathSupport
= 0;
53 __asm__("movl %%cr0, %0\n\t" : "=a" (cr0
));
58 __asm__("movl %0, %%cr0\n\t" : : "a" (cr0
));
61 __asm__("fninit\n\t");
62 __asm__("fstsw %0\n\t" : "=a" (status
));
65 __asm__("movl %%cr0, %0\n\t" : "=a" (cr0
));
66 /* Set the EM flag in CR0 so any FPU instructions cause a trap. */
68 __asm__("movl %0, %%cr0\n\t" :
72 /* fsetpm for i287, ignored by i387 */
73 __asm__(".byte 0xDB, 0xE4\n\t");
74 HardwareMathSupport
= 1;
77 /* This is a rather naive implementation of Ke(Save/Restore)FloatingPointState
78 which will not work for WDM drivers. Please feel free to improve */
80 #define FPU_STATE_SIZE 108
83 KeSaveFloatingPointState(OUT PKFLOATING_SAVE Save
)
87 FpState
= ExAllocatePool(PagedPool
, FPU_STATE_SIZE
);
90 return STATUS_INSUFFICIENT_RESOURCES
;
92 *((PVOID
*) Save
) = FpState
;
94 __asm__("fsave %0\n\t" : "=m" (*FpState
));
96 return STATUS_SUCCESS
;
100 KeRestoreFloatingPointState(IN PKFLOATING_SAVE Save
)
102 char *FpState
= *((PVOID
*) Save
);
104 __asm__("frstor %0\n\t" : "=m" (*FpState
));
107 return STATUS_SUCCESS
;