2007-09-17 05:08:06 +08:00
|
|
|
/*
|
2007-06-03 19:13:39 +08:00
|
|
|
* ColdFire Interrupt Controller emulation.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 CodeSourcery.
|
|
|
|
*
|
2011-06-26 10:21:35 +08:00
|
|
|
* This code is licensed under the GPL
|
2007-06-03 19:13:39 +08:00
|
|
|
*/
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/hw.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/m68k/mcf.h"
|
2012-12-18 01:19:49 +08:00
|
|
|
#include "exec/address-spaces.h"
|
2007-06-03 19:13:39 +08:00
|
|
|
|
|
|
|
typedef struct {
|
2011-11-24 21:31:15 +08:00
|
|
|
MemoryRegion iomem;
|
2007-06-03 19:13:39 +08:00
|
|
|
uint64_t ipr;
|
|
|
|
uint64_t imr;
|
|
|
|
uint64_t ifr;
|
|
|
|
uint64_t enabled;
|
|
|
|
uint8_t icr[64];
|
2013-01-18 21:15:09 +08:00
|
|
|
M68kCPU *cpu;
|
2007-06-03 19:13:39 +08:00
|
|
|
int active_vector;
|
|
|
|
} mcf_intc_state;
|
|
|
|
|
|
|
|
static void mcf_intc_update(mcf_intc_state *s)
|
|
|
|
{
|
|
|
|
uint64_t active;
|
|
|
|
int i;
|
|
|
|
int best;
|
|
|
|
int best_level;
|
|
|
|
|
|
|
|
active = (s->ipr | s->ifr) & s->enabled & ~s->imr;
|
|
|
|
best_level = 0;
|
|
|
|
best = 64;
|
|
|
|
if (active) {
|
|
|
|
for (i = 0; i < 64; i++) {
|
|
|
|
if ((active & 1) != 0 && s->icr[i] >= best_level) {
|
|
|
|
best_level = s->icr[i];
|
|
|
|
best = i;
|
|
|
|
}
|
|
|
|
active >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->active_vector = ((best == 64) ? 24 : (best + 64));
|
2013-01-18 21:20:52 +08:00
|
|
|
m68k_set_irq_level(s->cpu, best_level, s->active_vector);
|
2007-06-03 19:13:39 +08:00
|
|
|
}
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static uint64_t mcf_intc_read(void *opaque, hwaddr addr,
|
2011-11-24 21:31:15 +08:00
|
|
|
unsigned size)
|
2007-06-03 19:13:39 +08:00
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
mcf_intc_state *s = (mcf_intc_state *)opaque;
|
|
|
|
offset = addr & 0xff;
|
|
|
|
if (offset >= 0x40 && offset < 0x80) {
|
|
|
|
return s->icr[offset - 0x40];
|
|
|
|
}
|
|
|
|
switch (offset) {
|
|
|
|
case 0x00:
|
|
|
|
return (uint32_t)(s->ipr >> 32);
|
|
|
|
case 0x04:
|
|
|
|
return (uint32_t)s->ipr;
|
|
|
|
case 0x08:
|
|
|
|
return (uint32_t)(s->imr >> 32);
|
|
|
|
case 0x0c:
|
|
|
|
return (uint32_t)s->imr;
|
|
|
|
case 0x10:
|
|
|
|
return (uint32_t)(s->ifr >> 32);
|
|
|
|
case 0x14:
|
|
|
|
return (uint32_t)s->ifr;
|
|
|
|
case 0xe0: /* SWIACK. */
|
|
|
|
return s->active_vector;
|
|
|
|
case 0xe1: case 0xe2: case 0xe3: case 0xe4:
|
|
|
|
case 0xe5: case 0xe6: case 0xe7:
|
|
|
|
/* LnIACK */
|
2009-05-08 09:35:15 +08:00
|
|
|
hw_error("mcf_intc_read: LnIACK not implemented\n");
|
2007-06-03 19:13:39 +08:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 18:30:10 +08:00
|
|
|
static void mcf_intc_write(void *opaque, hwaddr addr,
|
2011-11-24 21:31:15 +08:00
|
|
|
uint64_t val, unsigned size)
|
2007-06-03 19:13:39 +08:00
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
mcf_intc_state *s = (mcf_intc_state *)opaque;
|
|
|
|
offset = addr & 0xff;
|
|
|
|
if (offset >= 0x40 && offset < 0x80) {
|
|
|
|
int n = offset - 0x40;
|
|
|
|
s->icr[n] = val;
|
|
|
|
if (val == 0)
|
|
|
|
s->enabled &= ~(1ull << n);
|
|
|
|
else
|
|
|
|
s->enabled |= (1ull << n);
|
|
|
|
mcf_intc_update(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (offset) {
|
|
|
|
case 0x00: case 0x04:
|
|
|
|
/* Ignore IPR writes. */
|
|
|
|
return;
|
|
|
|
case 0x08:
|
|
|
|
s->imr = (s->imr & 0xffffffff) | ((uint64_t)val << 32);
|
|
|
|
break;
|
|
|
|
case 0x0c:
|
|
|
|
s->imr = (s->imr & 0xffffffff00000000ull) | (uint32_t)val;
|
|
|
|
break;
|
|
|
|
default:
|
2009-05-08 09:35:15 +08:00
|
|
|
hw_error("mcf_intc_write: Bad write offset %d\n", offset);
|
2007-06-03 19:13:39 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
mcf_intc_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcf_intc_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
mcf_intc_state *s = (mcf_intc_state *)opaque;
|
|
|
|
if (irq >= 64)
|
|
|
|
return;
|
|
|
|
if (level)
|
|
|
|
s->ipr |= 1ull << irq;
|
|
|
|
else
|
|
|
|
s->ipr &= ~(1ull << irq);
|
|
|
|
mcf_intc_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcf_intc_reset(mcf_intc_state *s)
|
|
|
|
{
|
|
|
|
s->imr = ~0ull;
|
|
|
|
s->ipr = 0;
|
|
|
|
s->ifr = 0;
|
|
|
|
s->enabled = 0;
|
|
|
|
memset(s->icr, 0, 64);
|
|
|
|
s->active_vector = 24;
|
|
|
|
}
|
|
|
|
|
2011-11-24 21:31:15 +08:00
|
|
|
static const MemoryRegionOps mcf_intc_ops = {
|
|
|
|
.read = mcf_intc_read,
|
|
|
|
.write = mcf_intc_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-06-03 19:13:39 +08:00
|
|
|
};
|
|
|
|
|
2011-11-24 21:31:15 +08:00
|
|
|
qemu_irq *mcf_intc_init(MemoryRegion *sysmem,
|
2012-10-23 18:30:10 +08:00
|
|
|
hwaddr base,
|
2013-01-18 21:15:09 +08:00
|
|
|
M68kCPU *cpu)
|
2007-06-03 19:13:39 +08:00
|
|
|
{
|
|
|
|
mcf_intc_state *s;
|
|
|
|
|
2011-08-21 11:09:37 +08:00
|
|
|
s = g_malloc0(sizeof(mcf_intc_state));
|
2013-01-18 21:15:09 +08:00
|
|
|
s->cpu = cpu;
|
2007-06-03 19:13:39 +08:00
|
|
|
mcf_intc_reset(s);
|
|
|
|
|
2013-06-06 17:41:28 +08:00
|
|
|
memory_region_init_io(&s->iomem, NULL, &mcf_intc_ops, s, "mcf", 0x100);
|
2011-11-24 21:31:15 +08:00
|
|
|
memory_region_add_subregion(sysmem, base, &s->iomem);
|
2007-06-03 19:13:39 +08:00
|
|
|
|
|
|
|
return qemu_allocate_irqs(mcf_intc_set_irq, s, 64);
|
|
|
|
}
|