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"
17 #include "exec/address-spaces.h"
18 #include "exec/exec-all.h"
19 #include "hw/watchdog/wdt_diag288.h"
20 #include "sysemu/cpus.h"
21 #include "hw/s390x/ipl.h"
23 static int modified_clear_reset(S390CPU
*cpu
)
25 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
29 cpu_synchronize_all_states();
31 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
36 scc
->load_normal(CPU(cpu
));
37 cpu_synchronize_all_post_reset();
42 static int load_normal_reset(S390CPU
*cpu
)
44 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
48 cpu_synchronize_all_states();
50 run_on_cpu(t
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
54 scc
->initial_cpu_reset(CPU(cpu
));
55 scc
->load_normal(CPU(cpu
));
56 cpu_synchronize_all_post_reset();
61 int handle_diag_288(CPUS390XState
*env
, uint64_t r1
, uint64_t r3
)
63 uint64_t func
= env
->regs
[r1
];
64 uint64_t timeout
= env
->regs
[r1
+ 1];
65 uint64_t action
= env
->regs
[r3
];
67 DIAG288State
*diag288
;
68 DIAG288Class
*diag288_class
;
70 if (r1
% 2 || action
!= 0) {
74 /* Timeout must be more than 15 seconds except for timer deletion */
75 if (func
!= WDT_DIAG288_CANCEL
&& timeout
< 15) {
79 obj
= object_resolve_path_type("", TYPE_WDT_DIAG288
, NULL
);
84 diag288
= DIAG288(obj
);
85 diag288_class
= DIAG288_GET_CLASS(diag288
);
86 return diag288_class
->handle_timer(diag288
, func
, timeout
);
89 #define DIAG_308_RC_OK 0x0001
90 #define DIAG_308_RC_NO_CONF 0x0102
91 #define DIAG_308_RC_INVALID 0x0402
93 void handle_diag_308(CPUS390XState
*env
, uint64_t r1
, uint64_t r3
)
95 uint64_t addr
= env
->regs
[r1
];
96 uint64_t subcode
= env
->regs
[r3
];
97 IplParameterBlock
*iplb
;
99 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
100 program_interrupt(env
, PGM_PRIVILEGED
, ILEN_AUTO
);
104 if ((subcode
& ~0x0ffffULL
) || (subcode
> 6)) {
105 program_interrupt(env
, PGM_SPECIFICATION
, ILEN_AUTO
);
111 modified_clear_reset(s390_env_get_cpu(env
));
113 cpu_loop_exit(CPU(s390_env_get_cpu(env
)));
117 load_normal_reset(s390_env_get_cpu(env
));
119 cpu_loop_exit(CPU(s390_env_get_cpu(env
)));
123 s390_reipl_request();
125 cpu_loop_exit(CPU(s390_env_get_cpu(env
)));
129 if ((r1
& 1) || (addr
& 0x0fffULL
)) {
130 program_interrupt(env
, PGM_SPECIFICATION
, ILEN_AUTO
);
133 if (!address_space_access_valid(&address_space_memory
, addr
,
134 sizeof(IplParameterBlock
), false)) {
135 program_interrupt(env
, PGM_ADDRESSING
, ILEN_AUTO
);
138 iplb
= g_malloc0(sizeof(IplParameterBlock
));
139 cpu_physical_memory_read(addr
, iplb
, sizeof(iplb
->len
));
140 if (!iplb_valid_len(iplb
)) {
141 env
->regs
[r1
+ 1] = DIAG_308_RC_INVALID
;
145 cpu_physical_memory_read(addr
, iplb
, be32_to_cpu(iplb
->len
));
147 if (!iplb_valid_ccw(iplb
) && !iplb_valid_fcp(iplb
)) {
148 env
->regs
[r1
+ 1] = DIAG_308_RC_INVALID
;
152 s390_ipl_update_diag308(iplb
);
153 env
->regs
[r1
+ 1] = DIAG_308_RC_OK
;
158 if ((r1
& 1) || (addr
& 0x0fffULL
)) {
159 program_interrupt(env
, PGM_SPECIFICATION
, ILEN_AUTO
);
162 if (!address_space_access_valid(&address_space_memory
, addr
,
163 sizeof(IplParameterBlock
), true)) {
164 program_interrupt(env
, PGM_ADDRESSING
, ILEN_AUTO
);
167 iplb
= s390_ipl_get_iplb();
169 cpu_physical_memory_write(addr
, iplb
, be32_to_cpu(iplb
->len
));
170 env
->regs
[r1
+ 1] = DIAG_308_RC_OK
;
172 env
->regs
[r1
+ 1] = DIAG_308_RC_NO_CONF
;
176 hw_error("Unhandled diag308 subcode %" PRIx64
, subcode
);