aboutsummaryrefslogtreecommitdiff
path: root/target-sparc/op_helper.c
blob: 253bcff6f15f095664f37afa61d4ba406f1dd176 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <math.h>
#include <fenv.h>
#include "exec.h"

void OPPROTO do_fabss(void)
{
    FT0 = fabsf(FT1);
}

void OPPROTO do_fsqrts(void)
{
    FT0 = sqrtf(FT1);
}

void OPPROTO do_fsqrtd(void)
{
    DT0 = sqrt(DT1);
}

void OPPROTO do_fcmps (void)
{
    if (isnan(FT0) || isnan(FT1)) {
        T0 = FSR_FCC1 | FSR_FCC0;
    } else if (FT0 < FT1) {
        T0 = FSR_FCC0;
    } else if (FT0 > FT1) {
        T0 = FSR_FCC1;
    } else {
        T0 = 0;
    }
    env->fsr = T0;
}

void OPPROTO do_fcmpd (void)
{
    if (isnan(DT0) || isnan(DT1)) {
        T0 = FSR_FCC1 | FSR_FCC0;
    } else if (DT0 < DT1) {
        T0 = FSR_FCC0;
    } else if (DT0 > DT1) {
        T0 = FSR_FCC1;
    } else {
        T0 = 0;
    }
    env->fsr = T0;
}

void OPPROTO helper_ld_asi(int asi, int size, int sign)
{
    switch(asi) {
    case 3: /* MMU probe */
	T1 = 0;
	return;
    case 4: /* read MMU regs */
	{
	    int temp, reg = (T0 >> 8) & 0xf;
	    
	    temp = env->mmuregs[reg];
	    if (reg == 3 || reg == 4) /* Fault status, addr cleared on read*/
		env->mmuregs[reg] = 0;
	    T1 = temp;
	}
	return;
    case 0x20 ... 0x2f: /* MMU passthrough */
	{
	    int temp;
	    
	    cpu_physical_memory_read(T0, (void *) &temp, size);
	    bswap32s(&temp);
	    T1 = temp;
	}
	return;
    default:
	T1 = 0;
	return;
    }
}

void OPPROTO helper_st_asi(int asi, int size, int sign)
{
    switch(asi) {
    case 3: /* MMU flush */
	return;
    case 4: /* write MMU regs */
	{
	    int reg = (T0 >> 8) & 0xf;
	    if (reg == 0) {
		env->mmuregs[reg] &= ~(MMU_E | MMU_NF);
		env->mmuregs[reg] |= T1 & (MMU_E | MMU_NF);
	    } else
		env->mmuregs[reg] = T1;
	    return;
	}
    case 0x20 ... 0x2f: /* MMU passthrough */
	{
	    int temp = T1;
	    
	    bswap32s(&temp);
	    cpu_physical_memory_write(T0, (void *) &temp, size);
	}
	return;
    default:
	return;
    }
}

void OPPROTO helper_rett()
{
    int cwp;
    env->psret = 1;
    cwp = (env->cwp + 1) & (NWINDOWS - 1); 
    if (env->wim & (1 << cwp)) {
        raise_exception(TT_WIN_UNF);
    }
    set_cwp(cwp);
    env->psrs = env->psrps;
}

void helper_stfsr(void)
{
    switch (env->fsr & FSR_RD_MASK) {
    case FSR_RD_NEAREST:
	fesetround(FE_TONEAREST);
	break;
    case FSR_RD_ZERO:
	fesetround(FE_TOWARDZERO);
	break;
    case FSR_RD_POS:
	fesetround(FE_UPWARD);
	break;
    case FSR_RD_NEG:
	fesetround(FE_DOWNWARD);
	break;
    }
}