xref: /openbmc/qemu/linux-user/arm/nwfpe/fpa11.h (revision 1d6198c3b01619151f3227c6461b3d53eeb711e5)
1 /*
2     NetWinder Floating Point Emulator
3     (c) Rebel.com, 1998-1999
4 
5     Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
6 
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21 
22 #ifndef __FPA11_H__
23 #define __FPA11_H__
24 
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <errno.h>
28 
29 #include <cpu.h>
30 
31 #define GET_FPA11() (qemufpa)
32 
33 /*
34  * The processes registers are always at the very top of the 8K
35  * stack+task struct.  Use the same method as 'current' uses to
36  * reach them.
37  */
38 extern CPUARMState *user_registers;
39 
40 #define GET_USERREG() (user_registers)
41 
42 /* Need task_struct */
43 //#include <linux/sched.h>
44 
45 /* includes */
46 #include "fpsr.h"		/* FP control and status register definitions */
47 #include "softfloat.h"
48 
49 #define		typeNone		0x00
50 #define		typeSingle		0x01
51 #define		typeDouble		0x02
52 #define		typeExtended		0x03
53 
54 /*
55  * This must be no more and no less than 12 bytes.
56  */
57 typedef union tagFPREG {
58    floatx80 fExtended;
59    float64  fDouble;
60    float32  fSingle;
61 } FPREG;
62 
63 /*
64  * FPA11 device model.
65  *
66  * This structure is exported to user space.  Do not re-order.
67  * Only add new stuff to the end, and do not change the size of
68  * any element.  Elements of this structure are used by user
69  * space, and must match struct user_fp in include/asm-arm/user.h.
70  * We include the byte offsets below for documentation purposes.
71  *
72  * The size of this structure and FPREG are checked by fpmodule.c
73  * on initialisation.  If the rules have been broken, NWFPE will
74  * not initialise.
75  */
76 typedef struct tagFPA11 {
77 /*   0 */  FPREG fpreg[8];		/* 8 floating point registers */
78 /*  96 */  FPSR fpsr;			/* floating point status register */
79 /* 100 */  FPCR fpcr;			/* floating point control register */
80 /* 104 */  unsigned char fType[8];	/* type of floating point value held in
81 					   floating point registers.  One of none
82 					   single, double or extended. */
83 /* 112 */  int initflag;		/* this is special.  The kernel guarantees
84 					   to set it to 0 when a thread is launched,
85 					   so we can use it to detect whether this
86 					   instance of the emulator needs to be
87 					   initialised. */
88     float_status fp_status;      /* QEMU float emulator status */
89 } FPA11;
90 
91 extern FPA11* qemufpa;
92 
93 extern void resetFPA11(void);
94 extern void SetRoundingMode(const unsigned int);
95 extern void SetRoundingPrecision(const unsigned int);
96 
97 static inline unsigned int readRegister(unsigned int reg)
98 {
99     return (user_registers->regs[(reg)]);
100 }
101 
102 static inline void writeRegister(unsigned int x, unsigned int y)
103 {
104 #if 0
105 	printf("writing %d to r%d\n",y,x);
106 #endif
107         user_registers->regs[(x)]=(y);
108 }
109 
110 static inline void writeConditionCodes(unsigned int x)
111 {
112         cpsr_write(user_registers,x,CPSR_NZCV);
113 }
114 
115 #define REG_PC 15
116 
117 unsigned int EmulateAll(unsigned int opcode, FPA11* qfpa, CPUARMState* qregs);
118 
119 /* included only for get_user/put_user macros */
120 #include "qemu.h"
121 
122 #endif
123