source: mainline/kernel/arch/ia32/src/fpu_context.c@ f1380b7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f1380b7 was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Vana
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup ia32
30 * @{
31 */
32/** @file
33 *
34 */
35
36#include <fpu_context.h>
37#include <arch.h>
38#include <cpu.h>
39
40/** x87 FPU scr values (P3+ MMX2) */
41enum {
42 X87_FLUSH_ZERO_FLAG = (1 << 15),
43 X87_ROUND_CONTROL_MASK = (0x3 << 13),
44 x87_ROUND_TO_NEAREST_EVEN = (0x0 << 13),
45 X87_ROUND_DOWN_TO_NEG_INF = (0x1 << 13),
46 X87_ROUND_UP_TO_POS_INF = (0x2 << 13),
47 X87_ROUND_TO_ZERO = (0x3 << 13),
48 X87_PRECISION_MASK = (1 << 12),
49 X87_UNDERFLOW_MASK = (1 << 11),
50 X87_OVERFLOW_MASK = (1 << 10),
51 X87_ZERO_DIV_MASK = (1 << 9),
52 X87_DENORMAL_OP_MASK = (1 << 8),
53 X87_INVALID_OP_MASK = (1 << 7),
54 X87_DENOM_ZERO_FLAG = (1 << 6),
55 X87_PRECISION_EXC_FLAG = (1 << 5),
56 X87_UNDERFLOW_EXC_FLAG = (1 << 4),
57 X87_OVERFLOW_EXC_FLAG = (1 << 3),
58 X87_ZERO_DIV_EXC_FLAG = (1 << 2),
59 X87_DENORMAL_EXC_FLAG = (1 << 1),
60 X87_INVALID_OP_EXC_FLAG = (1 << 0),
61
62 X87_ALL_MASK = X87_PRECISION_MASK | X87_UNDERFLOW_MASK | X87_OVERFLOW_MASK | X87_ZERO_DIV_MASK | X87_DENORMAL_OP_MASK | X87_INVALID_OP_MASK,
63};
64
65typedef void (*fpu_context_function)(fpu_context_t *fctx);
66
67static fpu_context_function fpu_save;
68static fpu_context_function fpu_restore;
69
70static void fpu_context_f_save(fpu_context_t *fctx)
71{
72 asm volatile (
73 "fnsave %[fctx]"
74 : [fctx] "=m" (fctx->fpu)
75 );
76}
77
78static void fpu_context_f_restore(fpu_context_t *fctx)
79{
80 asm volatile (
81 "frstor %[fctx]"
82 : [fctx] "=m" (fctx->fpu)
83 );
84}
85
86static void fpu_context_fx_save(fpu_context_t *fctx)
87{
88 asm volatile (
89 "fxsave %[fctx]"
90 : [fctx] "=m" (fctx->fpu)
91 );
92}
93
94static void fpu_context_fx_restore(fpu_context_t *fctx)
95{
96 asm volatile (
97 "fxrstor %[fctx]"
98 : [fctx] "=m" (fctx->fpu)
99 );
100}
101
102/* Setup using fxsr instruction */
103void fpu_fxsr(void)
104{
105 fpu_save = fpu_context_fx_save;
106 fpu_restore = fpu_context_fx_restore;
107}
108
109/* Setup using not fxsr instruction */
110void fpu_fsr(void)
111{
112 fpu_save = fpu_context_f_save;
113 fpu_restore = fpu_context_f_restore;
114}
115
116void fpu_context_save(fpu_context_t *fctx)
117{
118 fpu_save(fctx);
119}
120
121void fpu_context_restore(fpu_context_t *fctx)
122{
123 fpu_restore(fctx);
124}
125
126/** Initialize x87 FPU. Mask all exceptions. */
127void fpu_init(void)
128{
129 uint32_t help0 = 0;
130 uint32_t help1 = 0;
131
132 asm volatile (
133 "fninit\n"
134 "stmxcsr %[help0]\n"
135 "mov %[help0], %[help1]\n"
136 "or %[magic], %[help1]\n"
137 "mov %[help1], %[help0]\n"
138 "ldmxcsr %[help0]\n"
139 : [help0] "+m" (help0), [help1] "+r" (help1)
140 : [magic] "i" (X87_ALL_MASK)
141 );
142}
143
144/** @}
145 */
Note: See TracBrowser for help on using the repository browser.