1 /*---------------------------------------------------------------------------+
4 | Code to implement some of the FPU auxiliary instructions. |
6 | Copyright (C) 1992,1993,1994,1997 |
7 | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
8 | E-mail billm@suburbia.net |
11 +---------------------------------------------------------------------------*/
13 #include "fpu_system.h"
14 #include "exception.h"
17 #include "control_w.h"
19 static void fnop(void)
23 static void fclex(void)
26 ~(SW_Backward
| SW_Summary
| SW_Stack_Fault
| SW_Precision
|
27 SW_Underflow
| SW_Overflow
| SW_Zero_Div
| SW_Denorm_Op
|
32 /* Needs to be externally visible */
33 void finit_task(struct task_struct
*tsk
)
35 struct i387_soft_struct
*soft
= &tsk
->thread
.xstate
->soft
;
36 struct address
*oaddr
, *iaddr
;
39 soft
->ftop
= 0; /* We don't keep top in the status word internally. */
41 /* The behaviour is different from that detailed in
42 Section 15.1.6 of the Intel manual */
43 oaddr
= (struct address
*)&soft
->foo
;
46 iaddr
= (struct address
*)&soft
->fip
;
59 * These are nops on the i387..
65 static FUNC
const finit_table
[] = {
66 feni
, fdisi
, fclex
, finit
,
67 fsetpm
, FPU_illegal
, FPU_illegal
, FPU_illegal
72 (finit_table
[FPU_rm
]) ();
75 static void fstsw_ax(void)
77 *(short *)&FPU_EAX
= status_word();
81 static FUNC
const fstsw_table
[] = {
82 fstsw_ax
, FPU_illegal
, FPU_illegal
, FPU_illegal
,
83 FPU_illegal
, FPU_illegal
, FPU_illegal
, FPU_illegal
88 (fstsw_table
[FPU_rm
]) ();
91 static FUNC
const fp_nop_table
[] = {
92 fnop
, FPU_illegal
, FPU_illegal
, FPU_illegal
,
93 FPU_illegal
, FPU_illegal
, FPU_illegal
, FPU_illegal
98 (fp_nop_table
[FPU_rm
]) ();
107 if (STACK_OVERFLOW
) {
108 FPU_stack_overflow();
115 reg_copy(&st(i
), st_new_ptr
);
116 tag
= FPU_gettagi(i
);
120 if (control_word
& CW_Invalid
) {
121 /* The masked response */
122 FPU_stack_underflow();
124 EXCEPTION(EX_StackUnder
);
134 FPU_REG
*st0_ptr
= &st(0), *sti_ptr
= &st(i
);
135 long tag_word
= fpu_tag_word
;
136 int regnr
= top
& 7, regnri
= ((regnr
+ i
) & 7);
137 u_char st0_tag
= (tag_word
>> (regnr
* 2)) & 3;
138 u_char sti_tag
= (tag_word
>> (regnri
* 2)) & 3;
140 if (st0_tag
== TAG_Empty
) {
141 if (sti_tag
== TAG_Empty
) {
142 FPU_stack_underflow();
143 FPU_stack_underflow_i(i
);
146 if (control_word
& CW_Invalid
) {
147 /* Masked response */
148 FPU_copy_to_reg0(sti_ptr
, sti_tag
);
150 FPU_stack_underflow_i(i
);
153 if (sti_tag
== TAG_Empty
) {
154 if (control_word
& CW_Invalid
) {
155 /* Masked response */
156 FPU_copy_to_regi(st0_ptr
, st0_tag
, i
);
158 FPU_stack_underflow();
163 reg_copy(st0_ptr
, &t
);
164 reg_copy(sti_ptr
, st0_ptr
);
165 reg_copy(&t
, sti_ptr
);
167 tag_word
&= ~(3 << (regnr
* 2)) & ~(3 << (regnri
* 2));
168 tag_word
|= (sti_tag
<< (regnr
* 2)) | (st0_tag
<< (regnri
* 2));
169 fpu_tag_word
= tag_word
;
175 FPU_settagi(FPU_rm
, TAG_Empty
);
180 /* ffree st(i) + pop - unofficial code */
181 FPU_settagi(FPU_rm
, TAG_Empty
);
188 FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm
);
194 FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm
);