1 // SPDX-License-Identifier: GPL-2.0
2 /*---------------------------------------------------------------------------+
5 | Code to implement some of the FPU auxiliary instructions. |
7 | Copyright (C) 1992,1993,1994,1997 |
8 | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
9 | E-mail billm@suburbia.net |
12 +---------------------------------------------------------------------------*/
14 #include "fpu_system.h"
15 #include "exception.h"
18 #include "control_w.h"
20 static void fnop(void)
24 static void fclex(void)
27 ~(SW_Backward | SW_Summary | SW_Stack_Fault | SW_Precision |
28 SW_Underflow | SW_Overflow | SW_Zero_Div | SW_Denorm_Op |
33 /* Needs to be externally visible */
34 void fpstate_init_soft(struct swregs_state *soft)
36 struct address *oaddr, *iaddr;
37 memset(soft, 0, sizeof(*soft));
40 soft->ftop = 0; /* We don't keep top in the status word internally. */
42 /* The behaviour is different from that detailed in
43 Section 15.1.6 of the Intel manual */
44 oaddr = (struct address *)&soft->foo;
47 iaddr = (struct address *)&soft->fip;
56 fpstate_init_soft(¤t->thread.fpu.state.soft);
60 * These are nops on the i387..
66 static FUNC const finit_table[] = {
67 feni, fdisi, fclex, finit,
68 fsetpm, FPU_illegal, FPU_illegal, FPU_illegal
73 (finit_table[FPU_rm]) ();
76 static void fstsw_ax(void)
78 *(short *)&FPU_EAX = status_word();
82 static FUNC const fstsw_table[] = {
83 fstsw_ax, FPU_illegal, FPU_illegal, FPU_illegal,
84 FPU_illegal, FPU_illegal, FPU_illegal, FPU_illegal
89 (fstsw_table[FPU_rm]) ();
92 static FUNC const fp_nop_table[] = {
93 fnop, FPU_illegal, FPU_illegal, FPU_illegal,
94 FPU_illegal, FPU_illegal, FPU_illegal, FPU_illegal
99 (fp_nop_table[FPU_rm]) ();
108 if (STACK_OVERFLOW) {
109 FPU_stack_overflow();
116 reg_copy(&st(i), st_new_ptr);
117 tag = FPU_gettagi(i);
121 if (control_word & CW_Invalid) {
122 /* The masked response */
123 FPU_stack_underflow();
125 EXCEPTION(EX_StackUnder);
135 FPU_REG *st0_ptr = &st(0), *sti_ptr = &st(i);
136 long tag_word = fpu_tag_word;
137 int regnr = top & 7, regnri = ((regnr + i) & 7);
138 u_char st0_tag = (tag_word >> (regnr * 2)) & 3;
139 u_char sti_tag = (tag_word >> (regnri * 2)) & 3;
141 if (st0_tag == TAG_Empty) {
142 if (sti_tag == TAG_Empty) {
143 FPU_stack_underflow();
144 FPU_stack_underflow_i(i);
147 if (control_word & CW_Invalid) {
148 /* Masked response */
149 FPU_copy_to_reg0(sti_ptr, sti_tag);
151 FPU_stack_underflow_i(i);
154 if (sti_tag == TAG_Empty) {
155 if (control_word & CW_Invalid) {
156 /* Masked response */
157 FPU_copy_to_regi(st0_ptr, st0_tag, i);
159 FPU_stack_underflow();
164 reg_copy(st0_ptr, &t);
165 reg_copy(sti_ptr, st0_ptr);
166 reg_copy(&t, sti_ptr);
168 tag_word &= ~(3 << (regnr * 2)) & ~(3 << (regnri * 2));
169 tag_word |= (sti_tag << (regnr * 2)) | (st0_tag << (regnri * 2));
170 fpu_tag_word = tag_word;
173 static void fcmovCC(void)
177 FPU_REG *st0_ptr = &st(0);
178 FPU_REG *sti_ptr = &st(i);
179 long tag_word = fpu_tag_word;
181 int regnri = (top + i) & 7;
182 u_char sti_tag = (tag_word >> (regnri * 2)) & 3;
184 if (sti_tag == TAG_Empty) {
185 FPU_stack_underflow();
189 reg_copy(sti_ptr, st0_ptr);
190 tag_word &= ~(3 << (regnr * 2));
191 tag_word |= (sti_tag << (regnr * 2));
192 fpu_tag_word = tag_word;
197 if (FPU_EFLAGS & X86_EFLAGS_CF)
203 if (FPU_EFLAGS & X86_EFLAGS_ZF)
209 if (FPU_EFLAGS & (X86_EFLAGS_CF|X86_EFLAGS_ZF))
215 if (FPU_EFLAGS & X86_EFLAGS_PF)
221 if (!(FPU_EFLAGS & X86_EFLAGS_CF))
227 if (!(FPU_EFLAGS & X86_EFLAGS_ZF))
233 if (!(FPU_EFLAGS & (X86_EFLAGS_CF|X86_EFLAGS_ZF)))
239 if (!(FPU_EFLAGS & X86_EFLAGS_PF))
246 FPU_settagi(FPU_rm, TAG_Empty);
251 /* ffree st(i) + pop - unofficial code */
252 FPU_settagi(FPU_rm, TAG_Empty);
259 FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm);
265 FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm);