216
197
return kernel_size;
219
void cpu_check_irqs(CPUSPARCState *env)
222
uint32_t pil = env->pil_in |
223
(env->softint & ~(SOFTINT_TIMER | SOFTINT_STIMER));
225
/* TT_IVEC has a higher priority (16) than TT_EXTINT (31..17) */
226
if (env->ivec_status & 0x20) {
229
cs = CPU(sparc_env_get_cpu(env));
230
/* check if TM or SM in SOFTINT are set
231
setting these also causes interrupt 14 */
232
if (env->softint & (SOFTINT_TIMER | SOFTINT_STIMER)) {
236
/* The bit corresponding to psrpil is (1<< psrpil), the next bit
238
if (pil < (2 << env->psrpil)){
239
if (cs->interrupt_request & CPU_INTERRUPT_HARD) {
240
CPUIRQ_DPRINTF("Reset CPU IRQ (current interrupt %x)\n",
241
env->interrupt_index);
242
env->interrupt_index = 0;
243
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
248
if (cpu_interrupts_enabled(env)) {
252
for (i = 15; i > env->psrpil; i--) {
253
if (pil & (1 << i)) {
254
int old_interrupt = env->interrupt_index;
255
int new_interrupt = TT_EXTINT | i;
257
if (unlikely(env->tl > 0 && cpu_tsptr(env)->tt > new_interrupt
258
&& ((cpu_tsptr(env)->tt & 0x1f0) == TT_EXTINT))) {
259
CPUIRQ_DPRINTF("Not setting CPU IRQ: TL=%d "
260
"current %x >= pending %x\n",
261
env->tl, cpu_tsptr(env)->tt, new_interrupt);
262
} else if (old_interrupt != new_interrupt) {
263
env->interrupt_index = new_interrupt;
264
CPUIRQ_DPRINTF("Set CPU IRQ %d old=%x new=%x\n", i,
265
old_interrupt, new_interrupt);
266
cpu_interrupt(cs, CPU_INTERRUPT_HARD);
271
} else if (cs->interrupt_request & CPU_INTERRUPT_HARD) {
272
CPUIRQ_DPRINTF("Interrupts disabled, pil=%08x pil_in=%08x softint=%08x "
273
"current interrupt %x\n",
274
pil, env->pil_in, env->softint, env->interrupt_index);
275
env->interrupt_index = 0;
276
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
280
static void cpu_kick_irq(SPARCCPU *cpu)
282
CPUState *cs = CPU(cpu);
283
CPUSPARCState *env = &cpu->env;
290
static void cpu_set_ivec_irq(void *opaque, int irq, int level)
292
SPARCCPU *cpu = opaque;
293
CPUSPARCState *env = &cpu->env;
297
if (!(env->ivec_status & 0x20)) {
298
CPUIRQ_DPRINTF("Raise IVEC IRQ %d\n", irq);
301
env->interrupt_index = TT_IVEC;
302
env->ivec_status |= 0x20;
303
env->ivec_data[0] = (0x1f << 6) | irq;
304
env->ivec_data[1] = 0;
305
env->ivec_data[2] = 0;
306
cpu_interrupt(cs, CPU_INTERRUPT_HARD);
309
if (env->ivec_status & 0x20) {
310
CPUIRQ_DPRINTF("Lower IVEC IRQ %d\n", irq);
312
env->ivec_status &= ~0x20;
313
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
318
200
typedef struct ResetData {
320
202
uint64_t prom_addr;
323
static CPUTimer *cpu_timer_create(const char *name, SPARCCPU *cpu,
324
QEMUBHFunc *cb, uint32_t frequency,
325
uint64_t disabled_mask, uint64_t npt_mask)
327
CPUTimer *timer = g_malloc0(sizeof (CPUTimer));
330
timer->frequency = frequency;
331
timer->disabled_mask = disabled_mask;
332
timer->npt_mask = npt_mask;
336
timer->clock_offset = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
338
timer->qtimer = timer_new_ns(QEMU_CLOCK_VIRTUAL, cb, cpu);
343
static void cpu_timer_reset(CPUTimer *timer)
346
timer->clock_offset = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
348
timer_del(timer->qtimer);
351
static void main_cpu_reset(void *opaque)
353
ResetData *s = (ResetData *)opaque;
354
CPUSPARCState *env = &s->cpu->env;
355
static unsigned int nr_resets;
357
cpu_reset(CPU(s->cpu));
359
cpu_timer_reset(env->tick);
360
cpu_timer_reset(env->stick);
361
cpu_timer_reset(env->hstick);
363
env->gregs[1] = 0; // Memory start
364
env->gregs[2] = ram_size; // Memory size
365
env->gregs[3] = 0; // Machine description XXX
366
if (nr_resets++ == 0) {
368
env->pc = s->prom_addr + 0x20ULL;
370
env->pc = s->prom_addr + 0x40ULL;
372
env->npc = env->pc + 4;
375
static void tick_irq(void *opaque)
377
SPARCCPU *cpu = opaque;
378
CPUSPARCState *env = &cpu->env;
380
CPUTimer* timer = env->tick;
382
if (timer->disabled) {
383
CPUIRQ_DPRINTF("tick_irq: softint disabled\n");
386
CPUIRQ_DPRINTF("tick: fire\n");
389
env->softint |= SOFTINT_TIMER;
393
static void stick_irq(void *opaque)
395
SPARCCPU *cpu = opaque;
396
CPUSPARCState *env = &cpu->env;
398
CPUTimer* timer = env->stick;
400
if (timer->disabled) {
401
CPUIRQ_DPRINTF("stick_irq: softint disabled\n");
404
CPUIRQ_DPRINTF("stick: fire\n");
407
env->softint |= SOFTINT_STIMER;
411
static void hstick_irq(void *opaque)
413
SPARCCPU *cpu = opaque;
414
CPUSPARCState *env = &cpu->env;
416
CPUTimer* timer = env->hstick;
418
if (timer->disabled) {
419
CPUIRQ_DPRINTF("hstick_irq: softint disabled\n");
422
CPUIRQ_DPRINTF("hstick: fire\n");
425
env->softint |= SOFTINT_STIMER;
429
static int64_t cpu_to_timer_ticks(int64_t cpu_ticks, uint32_t frequency)
431
return muldiv64(cpu_ticks, NANOSECONDS_PER_SECOND, frequency);
434
static uint64_t timer_to_cpu_ticks(int64_t timer_ticks, uint32_t frequency)
436
return muldiv64(timer_ticks, frequency, NANOSECONDS_PER_SECOND);
439
void cpu_tick_set_count(CPUTimer *timer, uint64_t count)
441
uint64_t real_count = count & ~timer->npt_mask;
442
uint64_t npt_bit = count & timer->npt_mask;
444
int64_t vm_clock_offset = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) -
445
cpu_to_timer_ticks(real_count, timer->frequency);
447
TIMER_DPRINTF("%s set_count count=0x%016lx (npt %s) p=%p\n",
448
timer->name, real_count,
449
timer->npt ? "disabled" : "enabled", timer);
451
timer->npt = npt_bit ? 1 : 0;
452
timer->clock_offset = vm_clock_offset;
455
uint64_t cpu_tick_get_count(CPUTimer *timer)
457
uint64_t real_count = timer_to_cpu_ticks(
458
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - timer->clock_offset,
461
TIMER_DPRINTF("%s get_count count=0x%016lx (npt %s) p=%p\n",
462
timer->name, real_count,
463
timer->npt ? "disabled" : "enabled", timer);
466
real_count |= timer->npt_mask;
472
void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit)
474
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
476
uint64_t real_limit = limit & ~timer->disabled_mask;
477
timer->disabled = (limit & timer->disabled_mask) ? 1 : 0;
479
int64_t expires = cpu_to_timer_ticks(real_limit, timer->frequency) +
486
TIMER_DPRINTF("%s set_limit limit=0x%016lx (%s) p=%p "
487
"called with limit=0x%016lx at 0x%016lx (delta=0x%016lx)\n",
488
timer->name, real_limit,
489
timer->disabled?"disabled":"enabled",
491
timer_to_cpu_ticks(now - timer->clock_offset,
493
timer_to_cpu_ticks(expires - now, timer->frequency));
496
TIMER_DPRINTF("%s set_limit limit=ZERO - not starting timer\n",
498
timer_del(timer->qtimer);
499
} else if (timer->disabled) {
500
timer_del(timer->qtimer);
502
timer_mod(timer->qtimer, expires);
506
205
static void isa_irq_handler(void *opaque, int n, int level)
508
207
static const int isa_irq_to_ivec[16] = {
723
422
.class_init = ram_class_init,
726
static SPARCCPU *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef)
730
ResetData *reset_info;
732
uint32_t tick_frequency = 100*1000000;
733
uint32_t stick_frequency = 100*1000000;
734
uint32_t hstick_frequency = 100*1000000;
736
if (cpu_model == NULL) {
737
cpu_model = hwdef->default_cpu_model;
739
cpu = cpu_sparc_init(cpu_model);
741
fprintf(stderr, "Unable to find Sparc CPU definition\n");
746
env->tick = cpu_timer_create("tick", cpu, tick_irq,
747
tick_frequency, TICK_INT_DIS,
750
env->stick = cpu_timer_create("stick", cpu, stick_irq,
751
stick_frequency, TICK_INT_DIS,
754
env->hstick = cpu_timer_create("hstick", cpu, hstick_irq,
755
hstick_frequency, TICK_INT_DIS,
758
reset_info = g_malloc0(sizeof(ResetData));
759
reset_info->cpu = cpu;
760
reset_info->prom_addr = hwdef->prom_addr;
761
qemu_register_reset(main_cpu_reset, reset_info);
766
425
static void sun4uv_init(MemoryRegion *address_space_mem,
767
426
MachineState *machine,
768
427
const struct hwdef *hwdef)