PowerPC fixes (Jocelyn Mayer)
[qemu] / target-ppc / exec.h
1 /*
2  *  PPC emulation definitions for qemu.
3  * 
4  *  Copyright (c) 2003 Jocelyn Mayer
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #if !defined (__PPC_H__)
21 #define __PPC_H__
22
23 #include "dyngen-exec.h"
24
25 register struct CPUPPCState *env asm(AREG0);
26 register uint32_t T0 asm(AREG1);
27 register uint32_t T1 asm(AREG2);
28 register uint32_t T2 asm(AREG3);
29
30 #define PARAM(n) ((uint32_t)PARAM##n)
31 #define SPARAM(n) ((int32_t)PARAM##n)
32 #define FT0 (env->ft0)
33 #define FT1 (env->ft1)
34 #define FT2 (env->ft2)
35 #define FTS0 ((float)env->ft0)
36 #define FTS1 ((float)env->ft1)
37 #define FTS2 ((float)env->ft2)
38
39 #define RETURN() __asm__ __volatile__("");
40
41 #include "cpu.h"
42 #include "exec-all.h"
43
44 static inline uint8_t ld8 (uint32_t EA)
45 {
46     return *((uint8_t *)EA);
47 }
48
49 static inline uint16_t ld16 (uint32_t EA)
50 {
51     return __be16_to_cpu(*((uint16_t *)EA));
52 }
53
54 static inline uint16_t ld16r (uint32_t EA)
55 {
56     return __le16_to_cpu(*((uint16_t *)EA));
57 }
58
59 static inline uint32_t ld32 (uint32_t EA)
60 {
61     return __be32_to_cpu(*((uint32_t *)EA));
62 }
63
64 static inline uint32_t ld32r (uint32_t EA)
65 {
66     return __le32_to_cpu(*((uint32_t *)EA));
67 }
68
69 static inline uint64_t ld64 (uint32_t EA)
70 {
71     return __be64_to_cpu(*((uint64_t *)EA));
72 }
73
74 static inline uint64_t ld64r (uint32_t EA)
75 {
76     return __le64_to_cpu(*((uint64_t *)EA));
77 }
78
79 static inline void st8 (uint32_t EA, uint8_t data)
80 {
81     *((uint8_t *)EA) = data;
82 }
83
84 static inline void st16 (uint32_t EA, uint16_t data)
85 {
86     *((uint16_t *)EA) = __cpu_to_be16(data);
87 }
88
89 static inline void st16r (uint32_t EA, uint16_t data)
90 {
91     *((uint16_t *)EA) = __cpu_to_le16(data);
92 }
93
94 static inline void st32 (uint32_t EA, uint32_t data)
95 {
96     *((uint32_t *)EA) = __cpu_to_be32(data);
97 }
98
99 static inline void st32r (uint32_t EA, uint32_t data)
100 {
101     *((uint32_t *)EA) = __cpu_to_le32(data);
102 }
103
104 static inline void st64 (uint32_t EA, uint64_t data)
105 {
106     *((uint64_t *)EA) = __cpu_to_be64(data);
107 }
108
109 static inline void st64r (uint32_t EA, uint64_t data)
110 {
111     *((uint64_t *)EA) = __cpu_to_le64(data);
112 }
113
114 static inline void set_CRn(int n, uint8_t value)
115 {
116     env->crf[n] = value;
117 }
118
119 static inline void set_carry (void)
120 {
121     xer_ca = 1;
122 }
123
124 static inline void reset_carry (void)
125 {
126     xer_ca = 0;
127 }
128
129 static inline void set_overflow (void)
130 {
131     xer_so = 1;
132     xer_ov = 1;
133 }
134
135 static inline void reset_overflow (void)
136 {
137     xer_ov = 0;
138 }
139
140 static inline uint32_t rotl (uint32_t i, int n)
141 {
142     return ((i << n) | (i >> (32 - n)));
143 }
144
145 void raise_exception (int exception_index);
146 void raise_exception_err (int exception_index, int error_code);
147
148 uint32_t do_load_cr (void);
149 void do_store_cr (uint32_t crn, uint32_t value);
150 uint32_t do_load_xer (void);
151 void do_store_xer (uint32_t value);
152 uint32_t do_load_msr (void);
153 void do_store_msr (uint32_t msr_value);
154 void do_load_fpscr (void);
155 void do_store_fpscr (uint32_t mask);
156
157 int32_t do_sraw(int32_t Ta, uint32_t Tb);
158 void do_lmw (int reg, uint32_t src);
159 void do_stmw (int reg, uint32_t dest);
160 void do_lsw (uint32_t reg, int count, uint32_t src);
161 void do_stsw (uint32_t reg, int count, uint32_t dest);
162
163 void do_dcbz (void);
164 void do_icbi (void);
165
166 #endif /* !defined (__PPC_H__) */