diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2008-01-30 07:30:07 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:30:07 -0500 |
commit | d94448b1fdc91ee1d235607f6bbe595464e4fbb9 (patch) | |
tree | 594a451b936fe3332009fd40d6e182b5629a69ed /arch | |
parent | 7b11fb51567dedeaf6dc03f0135c0a8bb2399818 (diff) |
x86: clean up arch/x86/ia32/fpu32.c
White space and coding style clenaup.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/ia32/fpu32.c | 134 |
1 files changed, 67 insertions, 67 deletions
diff --git a/arch/x86/ia32/fpu32.c b/arch/x86/ia32/fpu32.c index 2c8209a3605a..459bf743128f 100644 --- a/arch/x86/ia32/fpu32.c +++ b/arch/x86/ia32/fpu32.c | |||
@@ -1,8 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright 2002 Andi Kleen, SuSE Labs. | 2 | * Copyright 2002 Andi Kleen, SuSE Labs. |
3 | * FXSAVE<->i387 conversion support. Based on code by Gareth Hughes. | 3 | * FXSAVE<->i387 conversion support. Based on code by Gareth Hughes. |
4 | * This is used for ptrace, signals and coredumps in 32bit emulation. | 4 | * This is used for ptrace, signals and coredumps in 32bit emulation. |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include <linux/sched.h> | 7 | #include <linux/sched.h> |
8 | #include <asm/sigcontext32.h> | 8 | #include <asm/sigcontext32.h> |
@@ -13,96 +13,97 @@ | |||
13 | static inline unsigned short twd_i387_to_fxsr(unsigned short twd) | 13 | static inline unsigned short twd_i387_to_fxsr(unsigned short twd) |
14 | { | 14 | { |
15 | unsigned int tmp; /* to avoid 16 bit prefixes in the code */ | 15 | unsigned int tmp; /* to avoid 16 bit prefixes in the code */ |
16 | 16 | ||
17 | /* Transform each pair of bits into 01 (valid) or 00 (empty) */ | 17 | /* Transform each pair of bits into 01 (valid) or 00 (empty) */ |
18 | tmp = ~twd; | 18 | tmp = ~twd; |
19 | tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */ | 19 | tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */ |
20 | /* and move the valid bits to the lower byte. */ | 20 | /* and move the valid bits to the lower byte. */ |
21 | tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */ | 21 | tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */ |
22 | tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */ | 22 | tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */ |
23 | tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */ | 23 | tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */ |
24 | return tmp; | 24 | return tmp; |
25 | } | 25 | } |
26 | 26 | ||
27 | #define FPREG_ADDR(f, n) ((void *)&(f)->st_space + (n) * 16); | ||
28 | #define FP_EXP_TAG_VALID 0 | ||
29 | #define FP_EXP_TAG_ZERO 1 | ||
30 | #define FP_EXP_TAG_SPECIAL 2 | ||
31 | #define FP_EXP_TAG_EMPTY 3 | ||
32 | |||
27 | static inline unsigned long twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave) | 33 | static inline unsigned long twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave) |
28 | { | 34 | { |
29 | struct _fpxreg *st = NULL; | 35 | struct _fpxreg *st; |
30 | unsigned long tos = (fxsave->swd >> 11) & 7; | 36 | unsigned long tos = (fxsave->swd >> 11) & 7; |
31 | unsigned long twd = (unsigned long) fxsave->twd; | 37 | unsigned long twd = (unsigned long) fxsave->twd; |
32 | unsigned long tag; | 38 | unsigned long tag; |
33 | unsigned long ret = 0xffff0000; | 39 | unsigned long ret = 0xffff0000; |
34 | int i; | 40 | int i; |
35 | 41 | ||
36 | #define FPREG_ADDR(f, n) ((void *)&(f)->st_space + (n) * 16); | 42 | for (i = 0; i < 8; i++, twd >>= 1) { |
37 | |||
38 | for (i = 0 ; i < 8 ; i++) { | ||
39 | if (twd & 0x1) { | 43 | if (twd & 0x1) { |
40 | st = FPREG_ADDR( fxsave, (i - tos) & 7 ); | 44 | st = FPREG_ADDR(fxsave, (i - tos) & 7); |
41 | 45 | ||
42 | switch (st->exponent & 0x7fff) { | 46 | switch (st->exponent & 0x7fff) { |
43 | case 0x7fff: | 47 | case 0x7fff: |
44 | tag = 2; /* Special */ | 48 | tag = FP_EXP_TAG_SPECIAL; |
45 | break; | 49 | break; |
46 | case 0x0000: | 50 | case 0x0000: |
47 | if ( !st->significand[0] && | 51 | if (!st->significand[0] && |
48 | !st->significand[1] && | 52 | !st->significand[1] && |
49 | !st->significand[2] && | 53 | !st->significand[2] && |
50 | !st->significand[3] ) { | 54 | !st->significand[3]) |
51 | tag = 1; /* Zero */ | 55 | tag = FP_EXP_TAG_ZERO; |
52 | } else { | 56 | else |
53 | tag = 2; /* Special */ | 57 | tag = FP_EXP_TAG_SPECIAL; |
54 | } | ||
55 | break; | 58 | break; |
56 | default: | 59 | default: |
57 | if (st->significand[3] & 0x8000) { | 60 | if (st->significand[3] & 0x8000) |
58 | tag = 0; /* Valid */ | 61 | tag = FP_EXP_TAG_VALID; |
59 | } else { | 62 | else |
60 | tag = 2; /* Special */ | 63 | tag = FP_EXP_TAG_SPECIAL; |
61 | } | ||
62 | break; | 64 | break; |
63 | } | 65 | } |
64 | } else { | 66 | } else { |
65 | tag = 3; /* Empty */ | 67 | tag = FP_EXP_TAG_EMPTY; |
66 | } | 68 | } |
67 | ret |= (tag << (2 * i)); | 69 | ret |= tag << (2 * i); |
68 | twd = twd >> 1; | ||
69 | } | 70 | } |
70 | return ret; | 71 | return ret; |
71 | } | 72 | } |
72 | 73 | ||
74 | #define G(num, val) err |= __get_user(val, num + (u32 __user *)buf) | ||
73 | 75 | ||
74 | static inline int convert_fxsr_from_user(struct i387_fxsave_struct *fxsave, | 76 | static inline int convert_fxsr_from_user(struct i387_fxsave_struct *fxsave, |
75 | struct _fpstate_ia32 __user *buf) | 77 | struct _fpstate_ia32 __user *buf) |
76 | { | 78 | { |
77 | struct _fpxreg *to; | 79 | struct _fpxreg *to; |
78 | struct _fpreg __user *from; | 80 | struct _fpreg __user *from; |
79 | int i; | 81 | int i, err = 0; |
80 | u32 v; | 82 | u32 v; |
81 | int err = 0; | ||
82 | 83 | ||
83 | #define G(num,val) err |= __get_user(val, num + (u32 __user *)buf) | ||
84 | G(0, fxsave->cwd); | 84 | G(0, fxsave->cwd); |
85 | G(1, fxsave->swd); | 85 | G(1, fxsave->swd); |
86 | G(2, fxsave->twd); | 86 | G(2, fxsave->twd); |
87 | fxsave->twd = twd_i387_to_fxsr(fxsave->twd); | 87 | fxsave->twd = twd_i387_to_fxsr(fxsave->twd); |
88 | G(3, fxsave->rip); | 88 | G(3, fxsave->rip); |
89 | G(4, v); | 89 | G(4, v); |
90 | fxsave->fop = v>>16; /* cs ignored */ | 90 | /* cs ignored */ |
91 | fxsave->fop = v>>16; | ||
91 | G(5, fxsave->rdp); | 92 | G(5, fxsave->rdp); |
92 | /* 6: ds ignored */ | 93 | /* 6: ds ignored */ |
93 | #undef G | 94 | if (err) |
94 | if (err) | 95 | return -1; |
95 | return -1; | ||
96 | 96 | ||
97 | to = (struct _fpxreg *)&fxsave->st_space[0]; | 97 | to = (struct _fpxreg *)&fxsave->st_space[0]; |
98 | from = &buf->_st[0]; | 98 | from = &buf->_st[0]; |
99 | for (i = 0 ; i < 8 ; i++, to++, from++) { | 99 | for (i = 0; i < 8; i++, to++, from++) { |
100 | if (__copy_from_user(to, from, sizeof(*from))) | 100 | if (__copy_from_user(to, from, sizeof(*from))) |
101 | return -1; | 101 | return -1; |
102 | } | 102 | } |
103 | return 0; | 103 | return 0; |
104 | } | 104 | } |
105 | 105 | ||
106 | #define P(num, val) err |= __put_user(val, num + (u32 __user *)buf) | ||
106 | 107 | ||
107 | static inline int convert_fxsr_to_user(struct _fpstate_ia32 __user *buf, | 108 | static inline int convert_fxsr_to_user(struct _fpstate_ia32 __user *buf, |
108 | struct i387_fxsave_struct *fxsave, | 109 | struct i387_fxsave_struct *fxsave, |
@@ -111,60 +112,59 @@ static inline int convert_fxsr_to_user(struct _fpstate_ia32 __user *buf, | |||
111 | { | 112 | { |
112 | struct _fpreg __user *to; | 113 | struct _fpreg __user *to; |
113 | struct _fpxreg *from; | 114 | struct _fpxreg *from; |
114 | int i; | 115 | int i, err = 0; |
115 | u16 cs,ds; | 116 | u16 cs, ds; |
116 | int err = 0; | ||
117 | 117 | ||
118 | if (tsk == current) { | 118 | if (tsk == current) { |
119 | /* should be actually ds/cs at fpu exception time, | 119 | /* |
120 | but that information is not available in 64bit mode. */ | 120 | * should be actually ds/cs at fpu exception time, but |
121 | asm("movw %%ds,%0 " : "=r" (ds)); | 121 | * that information is not available in 64bit mode. |
122 | asm("movw %%cs,%0 " : "=r" (cs)); | 122 | */ |
123 | } else { /* ptrace. task has stopped. */ | 123 | asm("movw %%ds,%0 " : "=r" (ds)); |
124 | asm("movw %%cs,%0 " : "=r" (cs)); | ||
125 | } else { | ||
126 | /* ptrace. task has stopped. */ | ||
124 | ds = tsk->thread.ds; | 127 | ds = tsk->thread.ds; |
125 | cs = regs->cs; | 128 | cs = regs->cs; |
126 | } | 129 | } |
127 | 130 | ||
128 | #define P(num,val) err |= __put_user(val, num + (u32 __user *)buf) | ||
129 | P(0, (u32)fxsave->cwd | 0xffff0000); | 131 | P(0, (u32)fxsave->cwd | 0xffff0000); |
130 | P(1, (u32)fxsave->swd | 0xffff0000); | 132 | P(1, (u32)fxsave->swd | 0xffff0000); |
131 | P(2, twd_fxsr_to_i387(fxsave)); | 133 | P(2, twd_fxsr_to_i387(fxsave)); |
132 | P(3, (u32)fxsave->rip); | 134 | P(3, (u32)fxsave->rip); |
133 | P(4, cs | ((u32)fxsave->fop) << 16); | 135 | P(4, cs | ((u32)fxsave->fop) << 16); |
134 | P(5, fxsave->rdp); | 136 | P(5, fxsave->rdp); |
135 | P(6, 0xffff0000 | ds); | 137 | P(6, 0xffff0000 | ds); |
136 | #undef P | ||
137 | 138 | ||
138 | if (err) | 139 | if (err) |
139 | return -1; | 140 | return -1; |
140 | 141 | ||
141 | to = &buf->_st[0]; | 142 | to = &buf->_st[0]; |
142 | from = (struct _fpxreg *) &fxsave->st_space[0]; | 143 | from = (struct _fpxreg *) &fxsave->st_space[0]; |
143 | for ( i = 0 ; i < 8 ; i++, to++, from++ ) { | 144 | for (i = 0; i < 8; i++, to++, from++) { |
144 | if (__copy_to_user(to, from, sizeof(*to))) | 145 | if (__copy_to_user(to, from, sizeof(*to))) |
145 | return -1; | 146 | return -1; |
146 | } | 147 | } |
147 | return 0; | 148 | return 0; |
148 | } | 149 | } |
149 | 150 | ||
150 | int restore_i387_ia32(struct task_struct *tsk, struct _fpstate_ia32 __user *buf, int fsave) | 151 | int restore_i387_ia32(struct task_struct *tsk, |
151 | { | 152 | struct _fpstate_ia32 __user *buf, int fsave) |
153 | { | ||
152 | clear_fpu(tsk); | 154 | clear_fpu(tsk); |
153 | if (!fsave) { | 155 | if (!fsave) { |
154 | if (__copy_from_user(&tsk->thread.i387.fxsave, | 156 | if (__copy_from_user(&tsk->thread.i387.fxsave, |
155 | &buf->_fxsr_env[0], | 157 | &buf->_fxsr_env[0], |
156 | sizeof(struct i387_fxsave_struct))) | 158 | sizeof(struct i387_fxsave_struct))) |
157 | return -1; | 159 | return -1; |
158 | tsk->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask; | 160 | tsk->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask; |
159 | set_stopped_child_used_math(tsk); | 161 | set_stopped_child_used_math(tsk); |
160 | } | 162 | } |
161 | return convert_fxsr_from_user(&tsk->thread.i387.fxsave, buf); | 163 | return convert_fxsr_from_user(&tsk->thread.i387.fxsave, buf); |
162 | } | 164 | } |
163 | 165 | ||
164 | int save_i387_ia32(struct task_struct *tsk, | 166 | int save_i387_ia32(struct task_struct *tsk, struct _fpstate_ia32 __user *buf, |
165 | struct _fpstate_ia32 __user *buf, | 167 | struct pt_regs *regs, int fsave) |
166 | struct pt_regs *regs, | ||
167 | int fsave) | ||
168 | { | 168 | { |
169 | int err = 0; | 169 | int err = 0; |
170 | 170 | ||
@@ -174,8 +174,8 @@ int save_i387_ia32(struct task_struct *tsk, | |||
174 | if (fsave) | 174 | if (fsave) |
175 | return 0; | 175 | return 0; |
176 | err |= __put_user(tsk->thread.i387.fxsave.swd, &buf->status); | 176 | err |= __put_user(tsk->thread.i387.fxsave.swd, &buf->status); |
177 | if (fsave) | 177 | if (fsave) |
178 | return err ? -1 : 1; | 178 | return err ? -1 : 1; |
179 | err |= __put_user(X86_FXSR_MAGIC, &buf->magic); | 179 | err |= __put_user(X86_FXSR_MAGIC, &buf->magic); |
180 | err |= __copy_to_user(&buf->_fxsr_env[0], &tsk->thread.i387.fxsave, | 180 | err |= __copy_to_user(&buf->_fxsr_env[0], &tsk->thread.i387.fxsave, |
181 | sizeof(struct i387_fxsave_struct)); | 181 | sizeof(struct i387_fxsave_struct)); |