OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [cpu/] [i387.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: i387.h 10208 2011-02-24 21:54:04Z sshwarts $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//   Copyright (c) 2004-2009 Stanislav Shwartsman
6
//          Written by Stanislav Shwartsman [sshwarts at sourceforge net]
7
//
8
//  This library is free software; you can redistribute it and/or
9
//  modify it under the terms of the GNU Lesser General Public
10
//  License as published by the Free Software Foundation; either
11
//  version 2 of the License, or (at your option) any later version.
12
//
13
//  This library is distributed in the hope that it will be useful,
14
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
//  Lesser General Public License for more details.
17
//
18
//  You should have received a copy of the GNU Lesser General Public
19
//  License along with this library; if not, write to the Free Software
20
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
21
//
22
/////////////////////////////////////////////////////////////////////////
23
 
24
#ifndef _BX_I387_RELATED_EXTENSIONS_H_
25
#define _BX_I387_RELATED_EXTENSIONS_H_
26
 
27
#if BX_SUPPORT_FPU
28
 
29
#include "fpu/softfloat.h"
30
 
31
#define BX_FPU_REG(index) \
32
    (BX_CPU_THIS_PTR the_i387.st_space[index & 0x7])
33
 
34
#if defined(NEED_CPU_REG_SHORTCUTS)
35
#define FPU_PARTIAL_STATUS     (BX_CPU_THIS_PTR the_i387.swd)
36
#define FPU_CONTROL_WORD       (BX_CPU_THIS_PTR the_i387.cwd)
37
#define FPU_TAG_WORD           (BX_CPU_THIS_PTR the_i387.twd)
38
#define FPU_TOS                (BX_CPU_THIS_PTR the_i387.tos)
39
#endif
40
 
41
#include "fpu/tag_w.h"
42
#include "fpu/status_w.h"
43
#include "fpu/control_w.h"
44
 
45
extern int FPU_tagof(const floatx80 &reg);
46
 
47
//
48
// Minimal i387 structure
49
//
50
struct BOCHSAPI_MSVCONLY i387_t
51
{
52
    i387_t() {}
53
 
54
public:
55
    void        init();         // used by FINIT/FNINIT instructions
56
    void        reset();        // called on CPU reset
57
 
58
    int         is_IA_masked() const { return (cwd & FPU_CW_Invalid); }
59
 
60
    Bit16u      get_control_word() const { return cwd; }
61
    Bit16u      get_tag_word() const { return twd; }
62
    Bit16u      get_status_word() const { return (swd & ~FPU_SW_Top & 0xFFFF) | ((tos << 11) & FPU_SW_Top); }
63
    Bit16u      get_partial_status() const { return swd; }
64
 
65
    void        FPU_pop ();
66
    void        FPU_push();
67
 
68
    void        FPU_settagi(int tag, int stnr);
69
    void        FPU_settagi_valid(int stnr);
70
    int         FPU_gettagi(int stnr);
71
 
72
    floatx80    FPU_read_regi(int stnr) { return st_space[(tos+stnr) & 7]; }
73
    void        FPU_save_regi(floatx80 reg, int stnr);
74
    void        FPU_save_regi(floatx80 reg, int tag, int stnr);
75
 
76
public:
77
    Bit16u cwd;         // control word
78
    Bit16u swd;         // status word
79
    Bit16u twd;         // tag word
80
    Bit16u foo;         // last instruction opcode
81
 
82
    bx_address fip;
83
    bx_address fdp;
84
    Bit16u fcs;
85
    Bit16u fds;
86
 
87
    floatx80 st_space[8];
88
 
89
    unsigned char tos;
90
    unsigned char align1;
91
    unsigned char align2;
92
    unsigned char align3;
93
};
94
 
95
#define IS_TAG_EMPTY(i)                                                 \
96
  ((BX_CPU_THIS_PTR the_i387.FPU_gettagi(i)) == FPU_Tag_Empty)
97
 
98
#define BX_READ_FPU_REG(i)                                              \
99
  (BX_CPU_THIS_PTR the_i387.FPU_read_regi(i))
100
 
101
#define BX_WRITE_FPU_REG(value, i)                                      \
102
    BX_CPU_THIS_PTR the_i387.FPU_save_regi((value), (i));
103
 
104
#define BX_WRITE_FPU_REGISTER_AND_TAG(value, tag, i)                    \
105
    BX_CPU_THIS_PTR the_i387.FPU_save_regi((value), (tag), (i));
106
 
107
BX_CPP_INLINE int i387_t::FPU_gettagi(int stnr)
108
{
109
  return (twd >> (((stnr+tos) & 7)*2)) & 3;
110
}
111
 
112
BX_CPP_INLINE void i387_t::FPU_settagi_valid(int stnr)
113
{
114
  int regnr = (stnr + tos) & 7;
115
  twd &= ~(3 << (regnr*2));     // FPU_Tag_Valid == '00
116
}
117
 
118
BX_CPP_INLINE void i387_t::FPU_settagi(int tag, int stnr)
119
{
120
  int regnr = (stnr + tos) & 7;
121
  twd &= ~(3 << (regnr*2));
122
  twd |= (tag & 3) << (regnr*2);
123
}
124
 
125
BX_CPP_INLINE void i387_t::FPU_push(void)
126
{
127
  tos = (tos - 1) & 7;
128
}
129
 
130
BX_CPP_INLINE void i387_t::FPU_pop(void)
131
{
132
  twd |= 3 << (tos*2);
133
  tos = (tos + 1) & 7;
134
}
135
 
136
// it is only possisble to read FPU tag word through certain
137
// instructions like FNSAVE, and they update tag word to its
138
// real value anyway
139
BX_CPP_INLINE void i387_t::FPU_save_regi(floatx80 reg, int stnr)
140
{
141
  st_space[(stnr+tos) & 7] = reg;
142
  FPU_settagi_valid(stnr);
143
}
144
 
145
BX_CPP_INLINE void i387_t::FPU_save_regi(floatx80 reg, int tag, int stnr)
146
{
147
  st_space[(stnr+tos) & 7] = reg;
148
  FPU_settagi(tag, stnr);
149
}
150
 
151
#include <string.h>
152
 
153
BX_CPP_INLINE void i387_t::init()
154
{
155
  cwd = 0x037F;
156
  swd = 0;
157
  tos = 0;
158
  twd = 0xFFFF;
159
  foo = 0;
160
  fip = 0;
161
  fcs = 0;
162
  fds = 0;
163
  fdp = 0;
164
}
165
 
166
BX_CPP_INLINE void i387_t::reset()
167
{
168
  cwd = 0x0040;
169
  swd = 0;
170
  tos = 0;
171
  twd = 0x5555;
172
  foo = 0;
173
  fip = 0;
174
  fcs = 0;
175
  fds = 0;
176
  fdp = 0;
177
 
178
  memset(st_space, 0, sizeof(floatx80)*8);
179
}
180
 
181
typedef union bx_packed_mmx_reg_t {
182
   Bit8s   mmx_sbyte[8];
183
   Bit16s  mmx_s16[4];
184
   Bit32s  mmx_s32[2];
185
   Bit64s  mmx_s64;
186
   Bit8u   mmx_ubyte[8];
187
   Bit16u  mmx_u16[4];
188
   Bit32u  mmx_u32[2];
189
   Bit64u  mmx_u64;
190
} BxPackedMmxRegister;
191
 
192
#ifdef BX_BIG_ENDIAN
193
#define mmx64s(i)   mmx_s64
194
#define mmx32s(i)   mmx_s32[1 - (i)]
195
#define mmx16s(i)   mmx_s16[3 - (i)]
196
#define mmxsbyte(i) mmx_sbyte[7 - (i)]
197
#define mmxubyte(i) mmx_ubyte[7 - (i)]
198
#define mmx16u(i)   mmx_u16[3 - (i)]
199
#define mmx32u(i)   mmx_u32[1 - (i)]
200
#define mmx64u      mmx_u64
201
#else
202
#define mmx64s(i)   mmx_s64
203
#define mmx32s(i)   mmx_s32[(i)]
204
#define mmx16s(i)   mmx_s16[(i)]
205
#define mmxsbyte(i) mmx_sbyte[(i)]
206
#define mmxubyte(i) mmx_ubyte[(i)]
207
#define mmx16u(i)   mmx_u16[(i)]
208
#define mmx32u(i)   mmx_u32[(i)]
209
#define mmx64u      mmx_u64
210
#endif
211
 
212
/* for compatability with already written code */
213
#define MMXSB0(reg) (reg.mmxsbyte(0))
214
#define MMXSB1(reg) (reg.mmxsbyte(1))
215
#define MMXSB2(reg) (reg.mmxsbyte(2))
216
#define MMXSB3(reg) (reg.mmxsbyte(3))
217
#define MMXSB4(reg) (reg.mmxsbyte(4))
218
#define MMXSB5(reg) (reg.mmxsbyte(5))
219
#define MMXSB6(reg) (reg.mmxsbyte(6))
220
#define MMXSB7(reg) (reg.mmxsbyte(7))
221
 
222
#define MMXSW0(reg) (reg.mmx16s(0))
223
#define MMXSW1(reg) (reg.mmx16s(1))
224
#define MMXSW2(reg) (reg.mmx16s(2))
225
#define MMXSW3(reg) (reg.mmx16s(3))
226
 
227
#define MMXSD0(reg) (reg.mmx32s(0))
228
#define MMXSD1(reg) (reg.mmx32s(1))
229
 
230
#define MMXSQ(reg)  (reg.mmx64s)
231
#define MMXUQ(reg)  (reg.mmx64u)
232
 
233
#define MMXUD0(reg) (reg.mmx32u(0))
234
#define MMXUD1(reg) (reg.mmx32u(1))
235
 
236
#define MMXUW0(reg) (reg.mmx16u(0))
237
#define MMXUW1(reg) (reg.mmx16u(1))
238
#define MMXUW2(reg) (reg.mmx16u(2))
239
#define MMXUW3(reg) (reg.mmx16u(3))
240
 
241
#define MMXUB0(reg) (reg.mmxubyte(0))
242
#define MMXUB1(reg) (reg.mmxubyte(1))
243
#define MMXUB2(reg) (reg.mmxubyte(2))
244
#define MMXUB3(reg) (reg.mmxubyte(3))
245
#define MMXUB4(reg) (reg.mmxubyte(4))
246
#define MMXUB5(reg) (reg.mmxubyte(5))
247
#define MMXUB6(reg) (reg.mmxubyte(6))
248
#define MMXUB7(reg) (reg.mmxubyte(7))
249
 
250
#define BX_MMX_REG(index) (BX_FPU_REG(index).fraction)
251
 
252
#define BX_READ_MMX_REG(index)                                          \
253
    (*((const BxPackedMmxRegister*)(&(BX_MMX_REG(index)))))
254
 
255
#define BX_WRITE_MMX_REG(index, value)                                  \
256
{                                                                       \
257
   (BX_FPU_REG(index)).fraction = MMXUQ(value);                         \
258
   (BX_FPU_REG(index)).exp = 0xffff;                                    \
259
}
260
 
261
#endif          /* BX_SUPPORT_FPU */
262
 
263
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.