cp: guest layer revamp, part 1
[hvf.git] / cp / include / vcpu.h
blob585a9a2d41f2c8c480bc02aaa722696338cbe3d3
1 /*
2 * (C) Copyright 2007-2011 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 * This file is released under the GPLv2. See the COPYING file for more
5 * details.
6 */
8 #ifndef __VCPU_H
9 #define __VCPU_H
11 #include <list.h>
12 #include <console.h>
13 #include <mutex.h>
16 * saved registers for guests
18 * NOTE: some registers are saved in the SIE control block!
20 struct guest_regs {
21 u64 gpr[16];
22 u32 ar[16];
23 u64 fpr[64];
24 u32 fpcr;
28 * These states mirror those described in chapter 4 of SA22-7832-06
30 enum virt_cpustate {
31 GUEST_STOPPED = 0,
32 GUEST_OPERATING,
33 GUEST_LOAD,
34 GUEST_CHECKSTOP,
37 #include <sie.h>
39 struct vio_int {
40 struct list_head list;
42 u32 ssid;
43 u32 param;
44 u32 intid;
47 struct virt_cpu {
48 /* the SIE control block is picky about alignment */
49 struct sie_cb sie_cb;
51 struct guest_regs regs;
52 u64 cpuid;
54 enum virt_cpustate state;
56 mutex_t int_lock;
57 struct list_head int_io[8]; /* I/O interrupts */
60 struct virt_cons {
61 struct device *dev; /* the real device */
63 struct spool_file *wlines;
64 struct spool_file *rlines;
66 u8 *bigbuf;
69 struct virt_sys {
70 struct task *task; /* the virtual CPU task */
71 struct user *directory; /* the directory information */
73 struct virt_cons console; /* the console */
74 struct virt_cons *con; /* convenience pointer to the
75 console struct */
76 int print_ts; /* print timestamps */
78 struct list_head guest_pages; /* list of guest pages */
79 struct list_head virt_devs; /* list of guest virtual devs */
80 struct list_head online_users; /* list of online users */
82 struct address_space as; /* the guest storage */
85 /*****************************************************************************/
86 /* Guest exception queuing */
88 enum PROG_EXCEPTION {
89 PROG_OPERAND = 0x0001,
90 PROG_PRIV = 0x0002,
91 PROG_EXEC = 0x0003,
92 PROG_PROT = 0x0004,
93 PROG_ADDR = 0x0005,
94 PROG_SPEC = 0x0006,
95 PROG_DATA = 0x0007,
98 extern void queue_prog_exception(struct virt_sys *sys, enum PROG_EXCEPTION type, u64 param);
99 extern void queue_io_interrupt(struct virt_sys *sys, u32 ssid, u32 param, u32 a, u32 isc);
101 /*****************************************************************************/
102 /* Guest register reading & address calculation */
104 static inline u64 __guest_gpr(struct virt_cpu *cpu, int gpr)
106 u64 ret = cpu->regs.gpr[gpr];
108 if (!(atomic_read(&cpu->sie_cb.cpuflags) & CPUSTAT_ZARCH))
109 ret &= 0xffffffffULL;
111 return ret;
114 static inline u64 __guest_addr(struct virt_cpu *cpu, u64 disp, int x, int b)
116 u64 mask = 0;
118 switch((cpu->sie_cb.gpsw.ea << 1) | cpu->sie_cb.gpsw.ba) {
119 case 3:
120 mask = ~0;
121 break;
122 case 1:
123 mask = 0x7fffffff;
124 break;
125 case 0:
126 mask = 0x00ffffff;
127 break;
128 default:
129 BUG();
130 break;
133 return (disp +
134 (x ? __guest_gpr(cpu, x) : 0) +
135 (b ? __guest_gpr(cpu, b) : 0)) & mask;
138 /*****************************************************************************/
139 /* SIE Interception Param parsing & instruction decode */
141 #define IP_TO_RAW(sie) ((((u64)(sie).ipa) << 32) | ((u64)(sie).ipb))
143 static inline u64 RAW_S_1(struct virt_cpu *cpu)
145 u64 raw = IP_TO_RAW(cpu->sie_cb);
147 return __guest_addr(cpu,
148 (raw >> 16) & 0xfff,
149 (raw) >> 28 & 0xf,
153 /*****************************************************************************/
154 /* All the different ways to reset the system */
155 extern void guest_power_on_reset(struct virt_sys *sys);
156 extern void guest_system_reset_normal(struct virt_sys *sys);
157 extern void guest_system_reset_clear(struct virt_sys *sys);
158 extern void guest_load_normal(struct virt_sys *sys);
159 extern void guest_load_clear(struct virt_sys *sys);
161 extern void run_guest(struct virt_sys *sys);
162 extern void handle_interception(struct virt_sys *sys);
164 extern int handle_instruction(struct virt_sys *sys);
165 extern int handle_instruction_priv(struct virt_sys *sys);
167 typedef int (*intercept_handler_t)(struct virt_sys *sys);
169 #endif