2 * S/390 virtual CPU header
4 * Copyright (c) 2009 Ulrich Hecht
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.
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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #define TARGET_LONG_BITS 64
24 #define ELF_MACHINE EM_S390
26 #define CPUState struct CPUS390XState
30 #include "softfloat.h"
32 #define NB_MMU_MODES 2
36 #ifdef WORDS_BIGENDIAN
48 typedef struct CPUS390XState
{
49 uint64_t regs
[16]; /* GP registers */
51 uint32_t aregs
[16]; /* access registers */
53 uint32_t fpc
; /* floating-point control register */
54 FPReg fregs
[16]; /* FP registers */
55 float_status fpu_status
; /* passed to softfloat lib */
62 int cc
; /* condition code (0-3) */
69 #if defined(CONFIG_USER_ONLY)
70 static inline void cpu_clone_regs(CPUState
*env
, target_ulong newsp
)
73 env
->regs
[15] = newsp
;
78 #define MMU_MODE0_SUFFIX _kernel
79 #define MMU_MODE1_SUFFIX _user
80 #define MMU_USER_IDX 1
81 static inline int cpu_mmu_index (CPUState
*env
)
83 /* XXX: Currently we don't implement virtual memory */
87 CPUS390XState
*cpu_s390x_init(const char *cpu_model
);
88 int cpu_s390x_exec(CPUS390XState
*s
);
89 void cpu_s390x_close(CPUS390XState
*s
);
91 /* you can call this signal handler from your SIGBUS and SIGSEGV
92 signal handlers to inform the virtual CPU of exceptions. non zero
93 is returned if the signal was handled by the virtual CPU. */
94 int cpu_s390x_signal_handler(int host_signum
, void *pinfo
,
96 int cpu_s390x_handle_mmu_fault (CPUS390XState
*env
, target_ulong address
, int rw
,
97 int mmu_idx
, int is_softmuu
);
98 #define cpu_handle_mmu_fault cpu_s390x_handle_mmu_fault
100 #define TARGET_PAGE_BITS 12
102 /* ??? This is certainly wrong for 64-bit s390x, but given that only KVM
103 emulation actually works, this is good enough for a placeholder. */
104 #define TARGET_PHYS_ADDR_SPACE_BITS 32
105 #define TARGET_VIRT_ADDR_SPACE_BITS 32
107 #ifndef CONFIG_USER_ONLY
108 extern int s390_virtio_hypercall(CPUState
*env
);
109 extern void kvm_s390_virtio_irq(CPUState
*env
, int config_change
, uint64_t token
);
110 extern CPUState
*s390_cpu_addr2state(uint16_t cpu_addr
);
114 #define cpu_init cpu_s390x_init
115 #define cpu_exec cpu_s390x_exec
116 #define cpu_gen_code cpu_s390x_gen_code
119 #include "exec-all.h"
121 #define EXCP_OPEX 1 /* operation exception (sigill) */
122 #define EXCP_SVC 2 /* supervisor call (syscall) */
123 #define EXCP_ADDR 5 /* addressing exception */
124 #define EXCP_EXECUTE_SVC 0xff00000 /* supervisor call via execute insn */
126 static inline void cpu_pc_from_tb(CPUState
*env
, TranslationBlock
* tb
)
128 env
->psw
.addr
= tb
->pc
;
131 static inline void cpu_get_tb_cpu_state(CPUState
* env
, target_ulong
*pc
,
132 target_ulong
*cs_base
, int *flags
)
135 /* XXX this is correct for user-mode emulation, but needs
136 * the asce register information as well when softmmu
137 * is implemented in the future */
139 *flags
= env
->psw
.mask
;
142 /* Program Status Word. */
143 #define S390_PSWM_REGNUM 0
144 #define S390_PSWA_REGNUM 1
145 /* General Purpose Registers. */
146 #define S390_R0_REGNUM 2
147 #define S390_R1_REGNUM 3
148 #define S390_R2_REGNUM 4
149 #define S390_R3_REGNUM 5
150 #define S390_R4_REGNUM 6
151 #define S390_R5_REGNUM 7
152 #define S390_R6_REGNUM 8
153 #define S390_R7_REGNUM 9
154 #define S390_R8_REGNUM 10
155 #define S390_R9_REGNUM 11
156 #define S390_R10_REGNUM 12
157 #define S390_R11_REGNUM 13
158 #define S390_R12_REGNUM 14
159 #define S390_R13_REGNUM 15
160 #define S390_R14_REGNUM 16
161 #define S390_R15_REGNUM 17
162 /* Access Registers. */
163 #define S390_A0_REGNUM 18
164 #define S390_A1_REGNUM 19
165 #define S390_A2_REGNUM 20
166 #define S390_A3_REGNUM 21
167 #define S390_A4_REGNUM 22
168 #define S390_A5_REGNUM 23
169 #define S390_A6_REGNUM 24
170 #define S390_A7_REGNUM 25
171 #define S390_A8_REGNUM 26
172 #define S390_A9_REGNUM 27
173 #define S390_A10_REGNUM 28
174 #define S390_A11_REGNUM 29
175 #define S390_A12_REGNUM 30
176 #define S390_A13_REGNUM 31
177 #define S390_A14_REGNUM 32
178 #define S390_A15_REGNUM 33
179 /* Floating Point Control Word. */
180 #define S390_FPC_REGNUM 34
181 /* Floating Point Registers. */
182 #define S390_F0_REGNUM 35
183 #define S390_F1_REGNUM 36
184 #define S390_F2_REGNUM 37
185 #define S390_F3_REGNUM 38
186 #define S390_F4_REGNUM 39
187 #define S390_F5_REGNUM 40
188 #define S390_F6_REGNUM 41
189 #define S390_F7_REGNUM 42
190 #define S390_F8_REGNUM 43
191 #define S390_F9_REGNUM 44
192 #define S390_F10_REGNUM 45
193 #define S390_F11_REGNUM 46
194 #define S390_F12_REGNUM 47
195 #define S390_F13_REGNUM 48
196 #define S390_F14_REGNUM 49
197 #define S390_F15_REGNUM 50
199 #define S390_NUM_REGS 51
201 /* Pseudo registers -- PC and condition code. */
202 #define S390_PC_REGNUM S390_NUM_REGS
203 #define S390_CC_REGNUM (S390_NUM_REGS+1)
204 #define S390_NUM_PSEUDO_REGS 2
205 #define S390_NUM_TOTAL_REGS (S390_NUM_REGS+2)
209 /* Program Status Word. */
210 #define S390_PSWM_REGNUM 0
211 #define S390_PSWA_REGNUM 1
212 /* General Purpose Registers. */
213 #define S390_R0_REGNUM 2
214 #define S390_R1_REGNUM 3
215 #define S390_R2_REGNUM 4
216 #define S390_R3_REGNUM 5
217 #define S390_R4_REGNUM 6
218 #define S390_R5_REGNUM 7
219 #define S390_R6_REGNUM 8
220 #define S390_R7_REGNUM 9
221 #define S390_R8_REGNUM 10
222 #define S390_R9_REGNUM 11
223 #define S390_R10_REGNUM 12
224 #define S390_R11_REGNUM 13
225 #define S390_R12_REGNUM 14
226 #define S390_R13_REGNUM 15
227 #define S390_R14_REGNUM 16
228 #define S390_R15_REGNUM 17
229 /* Access Registers. */
230 #define S390_A0_REGNUM 18
231 #define S390_A1_REGNUM 19
232 #define S390_A2_REGNUM 20
233 #define S390_A3_REGNUM 21
234 #define S390_A4_REGNUM 22
235 #define S390_A5_REGNUM 23
236 #define S390_A6_REGNUM 24
237 #define S390_A7_REGNUM 25
238 #define S390_A8_REGNUM 26
239 #define S390_A9_REGNUM 27
240 #define S390_A10_REGNUM 28
241 #define S390_A11_REGNUM 29
242 #define S390_A12_REGNUM 30
243 #define S390_A13_REGNUM 31
244 #define S390_A14_REGNUM 32
245 #define S390_A15_REGNUM 33
246 /* Floating Point Control Word. */
247 #define S390_FPC_REGNUM 34
248 /* Floating Point Registers. */
249 #define S390_F0_REGNUM 35
250 #define S390_F1_REGNUM 36
251 #define S390_F2_REGNUM 37
252 #define S390_F3_REGNUM 38
253 #define S390_F4_REGNUM 39
254 #define S390_F5_REGNUM 40
255 #define S390_F6_REGNUM 41
256 #define S390_F7_REGNUM 42
257 #define S390_F8_REGNUM 43
258 #define S390_F9_REGNUM 44
259 #define S390_F10_REGNUM 45
260 #define S390_F11_REGNUM 46
261 #define S390_F12_REGNUM 47
262 #define S390_F13_REGNUM 48
263 #define S390_F14_REGNUM 49
264 #define S390_F15_REGNUM 50
266 #define S390_NUM_REGS 51
268 /* Pseudo registers -- PC and condition code. */
269 #define S390_PC_REGNUM S390_NUM_REGS
270 #define S390_CC_REGNUM (S390_NUM_REGS+1)
271 #define S390_NUM_PSEUDO_REGS 2
272 #define S390_NUM_TOTAL_REGS (S390_NUM_REGS+2)