PowerPC support (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
33 #define RETURN() __asm__ __volatile__("");
34
35 #include "cpu.h"
36 #include "exec-all.h"
37
38 static inline uint8_t ld8 (uint32_t EA)
39 {
40     return *((uint8_t *)EA);
41 }
42
43 static inline uint16_t ld16 (uint32_t EA)
44 {
45     return __be16_to_cpu(*((uint16_t *)EA));
46 }
47
48 static inline uint16_t ld16r (uint32_t EA)
49 {
50     return __le16_to_cpu(*((uint16_t *)EA));
51 }
52
53 static inline uint32_t ld32 (uint32_t EA)
54 {
55     return __be32_to_cpu(*((uint32_t *)EA));
56 }
57
58 static inline uint32_t ld32r (uint32_t EA)
59 {
60     return __le32_to_cpu(*((uint32_t *)EA));
61 }
62
63 static inline uint64_t ld64 (uint32_t EA)
64 {
65     return __be64_to_cpu(*((uint64_t *)EA));
66 }
67
68 static inline uint64_t ld64r (uint32_t EA)
69 {
70     return __le64_to_cpu(*((uint64_t *)EA));
71 }
72
73 static inline void st8 (uint32_t EA, uint8_t data)
74 {
75     *((uint8_t *)EA) = data;
76 }
77
78 static inline void st16 (uint32_t EA, uint16_t data)
79 {
80     *((uint16_t *)EA) = __cpu_to_be16(data);
81 }
82
83 static inline void st16r (uint32_t EA, uint16_t data)
84 {
85     *((uint16_t *)EA) = __cpu_to_le16(data);
86 }
87
88 static inline void st32 (uint32_t EA, uint32_t data)
89 {
90     *((uint32_t *)EA) = __cpu_to_be32(data);
91 }
92
93 static inline void st32r (uint32_t EA, uint32_t data)
94 {
95     *((uint32_t *)EA) = __cpu_to_le32(data);
96 }
97
98 static inline void st64 (uint32_t EA, uint64_t data)
99 {
100     *((uint64_t *)EA) = __cpu_to_be64(data);
101 }
102
103 static inline void st64r (uint32_t EA, uint64_t data)
104 {
105     *((uint64_t *)EA) = __cpu_to_le64(data);
106 }
107
108 static inline void set_CRn(int n, uint8_t value)
109 {
110     env->crf[n] = value;
111 }
112
113 static inline void set_carry (void)
114 {
115     xer_ca = 1;
116 }
117
118 static inline void reset_carry (void)
119 {
120     xer_ca = 0;
121 }
122
123 static inline void set_overflow (void)
124 {
125     xer_so = 1;
126     xer_ov = 1;
127 }
128
129 static inline void reset_overflow (void)
130 {
131     xer_ov = 0;
132 }
133
134 static inline uint32_t rotl (uint32_t i, int n)
135 {
136     return ((i << n) | (i >> (32 - n)));
137 }
138
139 void raise_exception (int exception_index);
140 void raise_exception_err (int exception_index, int error_code);
141
142 uint32_t do_load_cr (void);
143 void do_store_cr (uint32_t crn, uint32_t value);
144 uint32_t do_load_xer (void);
145 void do_store_xer (uint32_t value);
146 uint32_t do_load_msr (void);
147 void do_store_msr (uint32_t msr_value);
148 uint32_t do_load_fpscr (void);
149 void do_store_fpscr (uint8_t mask, uint32_t fp);
150
151 int32_t do_sraw(int32_t Ta, uint32_t Tb);
152 void do_lmw (int reg, uint32_t src);
153 void do_stmw (int reg, uint32_t dest);
154 void do_lsw (uint32_t reg, int count, uint32_t src);
155 void do_stsw (uint32_t reg, int count, uint32_t dest);
156
157 #endif /* !defined (__PPC_H__) */