fpu_aux.c 4.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*---------------------------------------------------------------------------+
 |  fpu_aux.c                                                                |
 |                                                                           |
 | Code to implement some of the FPU auxiliary instructions.                 |
 |                                                                           |
 | Copyright (C) 1992,1993,1994,1997                                         |
 |                  W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
 |                  E-mail   billm@suburbia.net                              |
 |                                                                           |
 |                                                                           |
 +---------------------------------------------------------------------------*/

#include "fpu_system.h"
#include "exception.h"
#include "fpu_emu.h"
#include "status_w.h"
#include "control_w.h"

static void fnop(void)
{
}

static void fclex(void)
{
I
Ingo Molnar 已提交
25 26 27 28 29
	partial_status &=
	    ~(SW_Backward | SW_Summary | SW_Stack_Fault | SW_Precision |
	      SW_Underflow | SW_Overflow | SW_Zero_Div | SW_Denorm_Op |
	      SW_Invalid);
	no_ip_update = 1;
L
Linus Torvalds 已提交
30 31 32 33 34
}

/* Needs to be externally visible */
void finit(void)
{
I
Ingo Molnar 已提交
35 36 37 38 39 40 41 42 43 44 45 46
	control_word = 0x037f;
	partial_status = 0;
	top = 0;		/* We don't keep top in the status word internally. */
	fpu_tag_word = 0xffff;
	/* The behaviour is different from that detailed in
	   Section 15.1.6 of the Intel manual */
	operand_address.offset = 0;
	operand_address.selector = 0;
	instruction_address.offset = 0;
	instruction_address.selector = 0;
	instruction_address.opcode = 0;
	no_ip_update = 1;
L
Linus Torvalds 已提交
47 48 49 50 51 52 53 54 55 56
}

/*
 * These are nops on the i387..
 */
#define feni fnop
#define fdisi fnop
#define fsetpm fnop

static FUNC const finit_table[] = {
I
Ingo Molnar 已提交
57 58
	feni, fdisi, fclex, finit,
	fsetpm, FPU_illegal, FPU_illegal, FPU_illegal
L
Linus Torvalds 已提交
59 60 61 62
};

void finit_(void)
{
I
Ingo Molnar 已提交
63
	(finit_table[FPU_rm]) ();
L
Linus Torvalds 已提交
64 65 66 67
}

static void fstsw_ax(void)
{
I
Ingo Molnar 已提交
68 69
	*(short *)&FPU_EAX = status_word();
	no_ip_update = 1;
L
Linus Torvalds 已提交
70 71 72
}

static FUNC const fstsw_table[] = {
I
Ingo Molnar 已提交
73 74
	fstsw_ax, FPU_illegal, FPU_illegal, FPU_illegal,
	FPU_illegal, FPU_illegal, FPU_illegal, FPU_illegal
L
Linus Torvalds 已提交
75 76 77 78
};

void fstsw_(void)
{
I
Ingo Molnar 已提交
79
	(fstsw_table[FPU_rm]) ();
L
Linus Torvalds 已提交
80 81 82
}

static FUNC const fp_nop_table[] = {
I
Ingo Molnar 已提交
83 84
	fnop, FPU_illegal, FPU_illegal, FPU_illegal,
	FPU_illegal, FPU_illegal, FPU_illegal, FPU_illegal
L
Linus Torvalds 已提交
85 86 87 88
};

void fp_nop(void)
{
I
Ingo Molnar 已提交
89
	(fp_nop_table[FPU_rm]) ();
L
Linus Torvalds 已提交
90 91 92 93
}

void fld_i_(void)
{
I
Ingo Molnar 已提交
94 95 96 97 98 99 100
	FPU_REG *st_new_ptr;
	int i;
	u_char tag;

	if (STACK_OVERFLOW) {
		FPU_stack_overflow();
		return;
L
Linus Torvalds 已提交
101 102
	}

I
Ingo Molnar 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116
	/* fld st(i) */
	i = FPU_rm;
	if (NOT_EMPTY(i)) {
		reg_copy(&st(i), st_new_ptr);
		tag = FPU_gettagi(i);
		push();
		FPU_settag0(tag);
	} else {
		if (control_word & CW_Invalid) {
			/* The masked response */
			FPU_stack_underflow();
		} else
			EXCEPTION(EX_StackUnder);
	}
L
Linus Torvalds 已提交
117

I
Ingo Molnar 已提交
118
}
L
Linus Torvalds 已提交
119 120 121

void fxch_i(void)
{
I
Ingo Molnar 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
	/* fxch st(i) */
	FPU_REG t;
	int i = FPU_rm;
	FPU_REG *st0_ptr = &st(0), *sti_ptr = &st(i);
	long tag_word = fpu_tag_word;
	int regnr = top & 7, regnri = ((regnr + i) & 7);
	u_char st0_tag = (tag_word >> (regnr * 2)) & 3;
	u_char sti_tag = (tag_word >> (regnri * 2)) & 3;

	if (st0_tag == TAG_Empty) {
		if (sti_tag == TAG_Empty) {
			FPU_stack_underflow();
			FPU_stack_underflow_i(i);
			return;
		}
		if (control_word & CW_Invalid) {
			/* Masked response */
			FPU_copy_to_reg0(sti_ptr, sti_tag);
		}
		FPU_stack_underflow_i(i);
		return;
L
Linus Torvalds 已提交
143
	}
I
Ingo Molnar 已提交
144 145 146 147 148 149 150
	if (sti_tag == TAG_Empty) {
		if (control_word & CW_Invalid) {
			/* Masked response */
			FPU_copy_to_regi(st0_ptr, st0_tag, i);
		}
		FPU_stack_underflow();
		return;
L
Linus Torvalds 已提交
151
	}
I
Ingo Molnar 已提交
152
	clear_C1();
L
Linus Torvalds 已提交
153

I
Ingo Molnar 已提交
154 155 156 157 158 159 160 161
	reg_copy(st0_ptr, &t);
	reg_copy(sti_ptr, st0_ptr);
	reg_copy(&t, sti_ptr);

	tag_word &= ~(3 << (regnr * 2)) & ~(3 << (regnri * 2));
	tag_word |= (sti_tag << (regnr * 2)) | (st0_tag << (regnri * 2));
	fpu_tag_word = tag_word;
}
L
Linus Torvalds 已提交
162 163 164

void ffree_(void)
{
I
Ingo Molnar 已提交
165 166
	/* ffree st(i) */
	FPU_settagi(FPU_rm, TAG_Empty);
L
Linus Torvalds 已提交
167 168 169 170
}

void ffreep(void)
{
I
Ingo Molnar 已提交
171 172 173
	/* ffree st(i) + pop - unofficial code */
	FPU_settagi(FPU_rm, TAG_Empty);
	FPU_pop();
L
Linus Torvalds 已提交
174 175 176 177
}

void fst_i_(void)
{
I
Ingo Molnar 已提交
178 179
	/* fst st(i) */
	FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm);
L
Linus Torvalds 已提交
180 181 182 183
}

void fstp_i(void)
{
I
Ingo Molnar 已提交
184 185 186
	/* fstp st(i) */
	FPU_copy_to_regi(&st(0), FPU_gettag0(), FPU_rm);
	FPU_pop();
L
Linus Torvalds 已提交
187
}