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"
24 static int modified_clear_reset(S390CPU
*cpu
)
26 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
30 cpu_synchronize_all_states();
32 run_on_cpu(t
, s390_do_cpu_full_reset
, RUN_ON_CPU_NULL
);
37 scc
->load_normal(CPU(cpu
));
38 cpu_synchronize_all_post_reset();
43 static inline void s390_do_cpu_reset(CPUState
*cs
, run_on_cpu_data arg
)
45 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cs
);
50 static int load_normal_reset(S390CPU
*cpu
)
52 S390CPUClass
*scc
= S390_CPU_GET_CLASS(cpu
);
56 cpu_synchronize_all_states();
58 run_on_cpu(t
, s390_do_cpu_reset
, RUN_ON_CPU_NULL
);
62 scc
->initial_cpu_reset(CPU(cpu
));
63 scc
->load_normal(CPU(cpu
));
64 cpu_synchronize_all_post_reset();
69 int handle_diag_288(CPUS390XState
*env
, uint64_t r1
, uint64_t r3
)
71 uint64_t func
= env
->regs
[r1
];
72 uint64_t timeout
= env
->regs
[r1
+ 1];
73 uint64_t action
= env
->regs
[r3
];
75 DIAG288State
*diag288
;
76 DIAG288Class
*diag288_class
;
78 if (r1
% 2 || action
!= 0) {
82 /* Timeout must be more than 15 seconds except for timer deletion */
83 if (func
!= WDT_DIAG288_CANCEL
&& timeout
< 15) {
87 obj
= object_resolve_path_type("", TYPE_WDT_DIAG288
, NULL
);
92 diag288
= DIAG288(obj
);
93 diag288_class
= DIAG288_GET_CLASS(diag288
);
94 return diag288_class
->handle_timer(diag288
, func
, timeout
);
97 #define DIAG_308_RC_OK 0x0001
98 #define DIAG_308_RC_NO_CONF 0x0102
99 #define DIAG_308_RC_INVALID 0x0402
101 void handle_diag_308(CPUS390XState
*env
, uint64_t r1
, uint64_t r3
)
103 uint64_t addr
= env
->regs
[r1
];
104 uint64_t subcode
= env
->regs
[r3
];
105 IplParameterBlock
*iplb
;
107 if (env
->psw
.mask
& PSW_MASK_PSTATE
) {
108 program_interrupt(env
, PGM_PRIVILEGED
, ILEN_AUTO
);
112 if ((subcode
& ~0x0ffffULL
) || (subcode
> 6)) {
113 program_interrupt(env
, PGM_SPECIFICATION
, ILEN_AUTO
);
119 modified_clear_reset(s390_env_get_cpu(env
));
121 cpu_loop_exit(CPU(s390_env_get_cpu(env
)));
125 load_normal_reset(s390_env_get_cpu(env
));
127 cpu_loop_exit(CPU(s390_env_get_cpu(env
)));
131 s390_reipl_request();
133 cpu_loop_exit(CPU(s390_env_get_cpu(env
)));
137 if ((r1
& 1) || (addr
& 0x0fffULL
)) {
138 program_interrupt(env
, PGM_SPECIFICATION
, ILEN_AUTO
);
141 if (!address_space_access_valid(&address_space_memory
, addr
,
142 sizeof(IplParameterBlock
), false)) {
143 program_interrupt(env
, PGM_ADDRESSING
, ILEN_AUTO
);
146 iplb
= g_malloc0(sizeof(IplParameterBlock
));
147 cpu_physical_memory_read(addr
, iplb
, sizeof(iplb
->len
));
148 if (!iplb_valid_len(iplb
)) {
149 env
->regs
[r1
+ 1] = DIAG_308_RC_INVALID
;
153 cpu_physical_memory_read(addr
, iplb
, be32_to_cpu(iplb
->len
));
155 if (!iplb_valid_ccw(iplb
) && !iplb_valid_fcp(iplb
)) {
156 env
->regs
[r1
+ 1] = DIAG_308_RC_INVALID
;
160 s390_ipl_update_diag308(iplb
);
161 env
->regs
[r1
+ 1] = DIAG_308_RC_OK
;
166 if ((r1
& 1) || (addr
& 0x0fffULL
)) {
167 program_interrupt(env
, PGM_SPECIFICATION
, ILEN_AUTO
);
170 if (!address_space_access_valid(&address_space_memory
, addr
,
171 sizeof(IplParameterBlock
), true)) {
172 program_interrupt(env
, PGM_ADDRESSING
, ILEN_AUTO
);
175 iplb
= s390_ipl_get_iplb();
177 cpu_physical_memory_write(addr
, iplb
, be32_to_cpu(iplb
->len
));
178 env
->regs
[r1
+ 1] = DIAG_308_RC_OK
;
180 env
->regs
[r1
+ 1] = DIAG_308_RC_NO_CONF
;
184 hw_error("Unhandled diag308 subcode %" PRIx64
, subcode
);