2 * S390x DIAG instruction helper functions
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include "qemu/osdep.h"
18 #include "exec/address-spaces.h"
19 #include "exec/exec-all.h"
20 #include "hw/watchdog/wdt_diag288.h"
21 #include "sysemu/cpus.h"
22 #include "hw/s390x/ipl.h"
23 #include "hw/s390x/s390-virtio-ccw.h"
25 static int modified_clear_reset(S390CPU
*cpu
)
27 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
31 cpu_synchronize_all_states();
33 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
38 scc
->load_normal(CPU(cpu
));
39 cpu_synchronize_all_post_reset();
44 static inline void s390_do_cpu_reset(CPUState
*cs
, run_on_cpu_data arg
)
46 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cs
);
51 static int load_normal_reset(S390CPU
*cpu
)
53 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
57 cpu_synchronize_all_states();
59 run_on_cpu(t
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
63 scc
->initial_cpu_reset(CPU(cpu
));
64 scc
->load_normal(CPU(cpu
));
65 cpu_synchronize_all_post_reset();
70 int handle_diag_288(CPUS390XState
*env
, uint64_t r1
, uint64_t r3
)
72 uint64_t func
= env
->regs
[r1
];
73 uint64_t timeout
= env
->regs
[r1
+ 1];
74 uint64_t action
= env
->regs
[r3
];
76 DIAG288State
*diag288
;
77 DIAG288Class
*diag288_class
;
79 if (r1
% 2 || action
!= 0) {
83 /* Timeout must be more than 15 seconds except for timer deletion */
84 if (func
!= WDT_DIAG288_CANCEL
&& timeout
< 15) {
88 obj
= object_resolve_path_type("", TYPE_WDT_DIAG288
, NULL
);
93 diag288
= DIAG288(obj
);
94 diag288_class
= DIAG288_GET_CLASS(diag288
);
95 return diag288_class
->handle_timer(diag288
, func
, timeout
);
98 #define DIAG_308_RC_OK 0x0001
99 #define DIAG_308_RC_NO_CONF 0x0102
100 #define DIAG_308_RC_INVALID 0x0402
102 void handle_diag_308(CPUS390XState
*env
, uint64_t r1
, uint64_t r3
, uintptr_t ra
)
104 uint64_t addr
= env
->regs
[r1
];
105 uint64_t subcode
= env
->regs
[r3
];
106 IplParameterBlock
*iplb
;
108 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
109 s390_program_interrupt(env
, PGM_PRIVILEGED
, ILEN_AUTO
, ra
);
113 if ((subcode
& ~0x0ffffULL
) || (subcode
> 6)) {
114 s390_program_interrupt(env
, PGM_SPECIFICATION
, ILEN_AUTO
, ra
);
120 modified_clear_reset(s390_env_get_cpu(env
));
122 cpu_loop_exit(CPU(s390_env_get_cpu(env
)));
126 load_normal_reset(s390_env_get_cpu(env
));
128 cpu_loop_exit(CPU(s390_env_get_cpu(env
)));
132 s390_reipl_request();
134 cpu_loop_exit(CPU(s390_env_get_cpu(env
)));
138 if ((r1
& 1) || (addr
& 0x0fffULL
)) {
139 s390_program_interrupt(env
, PGM_SPECIFICATION
, ILEN_AUTO
, ra
);
142 if (!address_space_access_valid(&address_space_memory
, addr
,
143 sizeof(IplParameterBlock
), false)) {
144 s390_program_interrupt(env
, PGM_ADDRESSING
, ILEN_AUTO
, ra
);
147 iplb
= g_new0(IplParameterBlock
, 1);
148 cpu_physical_memory_read(addr
, iplb
, sizeof(iplb
->len
));
149 if (!iplb_valid_len(iplb
)) {
150 env
->regs
[r1
+ 1] = DIAG_308_RC_INVALID
;
154 cpu_physical_memory_read(addr
, iplb
, be32_to_cpu(iplb
->len
));
156 if (!iplb_valid_ccw(iplb
) && !iplb_valid_fcp(iplb
)) {
157 env
->regs
[r1
+ 1] = DIAG_308_RC_INVALID
;
161 s390_ipl_update_diag308(iplb
);
162 env
->regs
[r1
+ 1] = DIAG_308_RC_OK
;
167 if ((r1
& 1) || (addr
& 0x0fffULL
)) {
168 s390_program_interrupt(env
, PGM_SPECIFICATION
, ILEN_AUTO
, ra
);
171 if (!address_space_access_valid(&address_space_memory
, addr
,
172 sizeof(IplParameterBlock
), true)) {
173 s390_program_interrupt(env
, PGM_ADDRESSING
, ILEN_AUTO
, ra
);
176 iplb
= s390_ipl_get_iplb();
178 cpu_physical_memory_write(addr
, iplb
, be32_to_cpu(iplb
->len
));
179 env
->regs
[r1
+ 1] = DIAG_308_RC_OK
;
181 env
->regs
[r1
+ 1] = DIAG_308_RC_NO_CONF
;
185 hw_error("Unhandled diag308 subcode %" PRIx64
, subcode
);