target: Do not include "exec/exec-all.h" if it is not necessary
[qemu/kevin.git] / target / s390x / diag.c
blob0a1fabee51f2070ef32b7d4ebcd70bc407c3104e
1 /*
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"
16 #include "cpu.h"
17 #include "internal.h"
18 #include "exec/address-spaces.h"
19 #include "hw/watchdog/wdt_diag288.h"
20 #include "sysemu/cpus.h"
21 #include "hw/s390x/ipl.h"
22 #include "hw/s390x/s390-virtio-ccw.h"
24 int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3)
26 uint64_t func = env->regs[r1];
27 uint64_t timeout = env->regs[r1 + 1];
28 uint64_t action = env->regs[r3];
29 Object *obj;
30 DIAG288State *diag288;
31 DIAG288Class *diag288_class;
33 if (r1 % 2 || action != 0) {
34 return -1;
37 /* Timeout must be more than 15 seconds except for timer deletion */
38 if (func != WDT_DIAG288_CANCEL && timeout < 15) {
39 return -1;
42 obj = object_resolve_path_type("", TYPE_WDT_DIAG288, NULL);
43 if (!obj) {
44 return -1;
47 diag288 = DIAG288(obj);
48 diag288_class = DIAG288_GET_CLASS(diag288);
49 return diag288_class->handle_timer(diag288, func, timeout);
52 #define DIAG_308_RC_OK 0x0001
53 #define DIAG_308_RC_NO_CONF 0x0102
54 #define DIAG_308_RC_INVALID 0x0402
56 void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
58 CPUState *cs = CPU(s390_env_get_cpu(env));
59 uint64_t addr = env->regs[r1];
60 uint64_t subcode = env->regs[r3];
61 IplParameterBlock *iplb;
63 if (env->psw.mask & PSW_MASK_PSTATE) {
64 s390_program_interrupt(env, PGM_PRIVILEGED, ILEN_AUTO, ra);
65 return;
68 if ((subcode & ~0x0ffffULL) || (subcode > 6)) {
69 s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
70 return;
73 switch (subcode) {
74 case 0:
75 s390_ipl_reset_request(cs, S390_RESET_MODIFIED_CLEAR);
76 break;
77 case 1:
78 s390_ipl_reset_request(cs, S390_RESET_LOAD_NORMAL);
79 break;
80 case 3:
81 s390_ipl_reset_request(cs, S390_RESET_REIPL);
82 break;
83 case 5:
84 if ((r1 & 1) || (addr & 0x0fffULL)) {
85 s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
86 return;
88 if (!address_space_access_valid(&address_space_memory, addr,
89 sizeof(IplParameterBlock), false)) {
90 s390_program_interrupt(env, PGM_ADDRESSING, ILEN_AUTO, ra);
91 return;
93 iplb = g_new0(IplParameterBlock, 1);
94 cpu_physical_memory_read(addr, iplb, sizeof(iplb->len));
95 if (!iplb_valid_len(iplb)) {
96 env->regs[r1 + 1] = DIAG_308_RC_INVALID;
97 goto out;
100 cpu_physical_memory_read(addr, iplb, be32_to_cpu(iplb->len));
102 if (!iplb_valid_ccw(iplb) && !iplb_valid_fcp(iplb)) {
103 env->regs[r1 + 1] = DIAG_308_RC_INVALID;
104 goto out;
107 s390_ipl_update_diag308(iplb);
108 env->regs[r1 + 1] = DIAG_308_RC_OK;
109 out:
110 g_free(iplb);
111 return;
112 case 6:
113 if ((r1 & 1) || (addr & 0x0fffULL)) {
114 s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
115 return;
117 if (!address_space_access_valid(&address_space_memory, addr,
118 sizeof(IplParameterBlock), true)) {
119 s390_program_interrupt(env, PGM_ADDRESSING, ILEN_AUTO, ra);
120 return;
122 iplb = s390_ipl_get_iplb();
123 if (iplb) {
124 cpu_physical_memory_write(addr, iplb, be32_to_cpu(iplb->len));
125 env->regs[r1 + 1] = DIAG_308_RC_OK;
126 } else {
127 env->regs[r1 + 1] = DIAG_308_RC_NO_CONF;
129 return;
130 default:
131 hw_error("Unhandled diag308 subcode %" PRIx64, subcode);
132 break;