--- /dev/null
+;------------------------------------------------------------------------------\r
+;*\r
+;* Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+;* This program and the accompanying materials\r
+;* are licensed and made available under the terms and conditions of the BSD License\r
+;* which accompanies this distribution. The full text of the license may be found at\r
+;* http://opensource.org/licenses/bsd-license.php\r
+;*\r
+;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;*\r
+;*\r
+;------------------------------------------------------------------------------\r
+\r
+ SECTION .rdata\r
+;\r
+; Float control word initial value:\r
+; all exceptions masked, double-extended-precision, round-to-nearest\r
+;\r
+mFpuControlWord: DW 0x37F\r
+;\r
+; Multimedia-extensions control word:\r
+; all exceptions masked, round-to-nearest, flush to zero for masked underflow\r
+;\r
+mMmxControlWord: DD 0x1F80\r
+\r
+DEFAULT REL\r
+SECTION .text\r
+\r
+;\r
+; Initializes floating point units for requirement of UEFI specification.\r
+;\r
+; This function initializes floating-point control word to 0x027F (all exceptions\r
+; masked,double-precision, round-to-nearest) and multimedia-extensions control word\r
+; (if supported) to 0x1F80 (all exceptions masked, round-to-nearest, flush to zero\r
+; for masked underflow).\r
+;\r
+global ASM_PFX(InitializeFloatingPointUnits)\r
+ASM_PFX(InitializeFloatingPointUnits):\r
+\r
+ ;\r
+ ; Initialize floating point units\r
+ ;\r
+ ; The following opcodes stand for instruction 'finit'\r
+ ; to be supported by some 64-bit assemblers\r
+ ;\r
+ DB 0x9B, 0xDB, 0xE3\r
+ fldcw [mFpuControlWord]\r
+\r
+ ;\r
+ ; Set OSFXSR bit 9 in CR4\r
+ ;\r
+ mov rax, cr4\r
+ or rax, BIT9\r
+ mov cr4, rax\r
+\r
+ ldmxcsr [mMmxControlWord]\r
+\r
+ ret\r
+\r