Revision 854e42f3

b/hw/s390-virtio.c
121 121
    return r;
122 122
}
123 123

  
124
/*
125
 * The number of running CPUs. On s390 a shutdown is the state of all CPUs
126
 * being either stopped or disabled (for interrupts) waiting. We have to
127
 * track this number to call the shutdown sequence accordingly. This
128
 * number is modified either on startup or while holding the big qemu lock.
129
 */
130
static unsigned s390_running_cpus;
131

  
132
void s390_add_running_cpu(CPUState *env)
133
{
134
    if (env->halted) {
135
        s390_running_cpus++;
136
        env->halted = 0;
137
        env->exception_index = -1;
138
    }
139
}
140

  
141
unsigned s390_del_running_cpu(CPUState *env)
142
{
143
    if (env->halted == 0) {
144
        assert(s390_running_cpus >= 1);
145
        s390_running_cpus--;
146
        env->halted = 1;
147
        env->exception_index = EXCP_HLT;
148
    }
149
    return s390_running_cpus;
150
}
151

  
124 152
/* PC hardware initialisation */
125 153
static void s390_init(ram_addr_t my_ram_size,
126 154
                      const char *boot_device,
......
179 207
        tmp_env->storage_keys = storage_keys;
180 208
    }
181 209

  
182
    env->halted = 0;
183
    env->exception_index = 0;
210
    /* One CPU has to run */
211
    s390_add_running_cpu(env);
184 212

  
185 213
    if (kernel_filename) {
186 214
        kernel_size = load_image(kernel_filename, qemu_get_ram_ptr(0));
b/target-s390x/cpu.h
309 309
}
310 310
#endif
311 311
CPUState *s390_cpu_addr2state(uint16_t cpu_addr);
312
void s390_add_running_cpu(CPUState *env);
313
unsigned s390_del_running_cpu(CPUState *env);
312 314

  
313 315
/* from s390-virtio-bus */
314 316
extern const target_phys_addr_t virtio_size;
b/target-s390x/kvm.c
185 185
        return;
186 186
    }
187 187

  
188
    env->halted = 0;
189
    env->exception_index = -1;
188
    s390_add_running_cpu(env);
190 189
    qemu_cpu_kick(env);
191 190

  
192 191
    kvmint.type = type;
......
299 298
static int s390_cpu_restart(CPUState *env)
300 299
{
301 300
    kvm_s390_interrupt(env, KVM_S390_RESTART, 0);
302
    env->halted = 0;
303
    env->exception_index = -1;
301
    s390_add_running_cpu(env);
304 302
    qemu_cpu_kick(env);
305 303
    dprintf("DONE: SIGP cpu restart: %p\n", env);
306 304
    return 0;
......
425 423
            r = handle_instruction(env, run);
426 424
            break;
427 425
        case ICPT_WAITPSW:
428
            /* XXX What to do on system shutdown? */
429
            env->halted = 1;
430
            env->exception_index = EXCP_HLT;
426
        case ICPT_CPU_STOP:
427
            if (s390_del_running_cpu(env) == 0) {
428
                qemu_system_shutdown_request();
429
            }
430
            r = EXCP_HALTED;
431 431
            break;
432 432
        case ICPT_SOFT_INTERCEPT:
433 433
            fprintf(stderr, "KVM unimplemented icpt SOFT\n");
434 434
            exit(1);
435 435
            break;
436
        case ICPT_CPU_STOP:
437
            qemu_system_shutdown_request();
438
            break;
439 436
        case ICPT_IO:
440 437
            fprintf(stderr, "KVM unimplemented icpt IO\n");
441 438
            exit(1);
......
468 465

  
469 466
    if (ret == 0) {
470 467
        ret = EXCP_INTERRUPT;
471
    } else if (ret > 0) {
472
        ret = 0;
473 468
    }
474 469
    return ret;
475 470
}

Also available in: Unified diff