static void slavio_timer_mem_writel(void *opaque, target_phys_addr_t addr,

                                    uint32_t val)

{

    SLAVIO_TIMERState *s = opaque;

    uint32_t saddr;

    int reload = 0;



    DPRINTF("write " TARGET_FMT_plx " %08x\n", addr, val);

    saddr = (addr & TIMER_MAXADDR) >> 2;

    switch (saddr) {

    case TIMER_LIMIT:

        if (slavio_timer_is_user(s)) {

            // set user counter MSW, reset counter

            qemu_irq_lower(s->irq);

            s->limit = TIMER_MAX_COUNT64;

            DPRINTF("processor %d user timer reset\n", s->slave_index);

            ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1);

        } else {

            // set limit, reset counter

            qemu_irq_lower(s->irq);

            s->limit = val & TIMER_MAX_COUNT32;

            if (!s->limit)

                s->limit = TIMER_MAX_COUNT32;

            ptimer_set_limit(s->timer, s->limit >> 9, 1);

        }

        break;

    case TIMER_COUNTER:

        if (slavio_timer_is_user(s)) {

            // set user counter LSW, reset counter

            qemu_irq_lower(s->irq);

            s->limit = TIMER_MAX_COUNT64;

            DPRINTF("processor %d user timer reset\n", s->slave_index);

            ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1);

        } else

            DPRINTF("not user timer\n");

        break;

    case TIMER_COUNTER_NORST:

        // set limit without resetting counter

        s->limit = val & TIMER_MAX_COUNT32;

        if (!s->limit)

            s->limit = TIMER_MAX_COUNT32;

        ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), reload);

        break;

    case TIMER_STATUS:

        if (slavio_timer_is_user(s)) {

            // start/stop user counter

            if ((val & 1) && !s->running) {

                DPRINTF("processor %d user timer started\n", s->slave_index);

                ptimer_run(s->timer, 0);

                s->running = 1;

            } else if (!(val & 1) && s->running) {

                DPRINTF("processor %d user timer stopped\n", s->slave_index);

                ptimer_stop(s->timer);

                s->running = 0;

            }

        }

        break;

    case TIMER_MODE:

        if (s->master == NULL) {

            unsigned int i;



            for (i = 0; i < s->num_slaves; i++) {

                if (val & (1 << i)) {

                    qemu_irq_lower(s->slave[i]->irq);

                    s->slave[i]->limit = -1ULL;

                }

                if ((val & (1 << i)) != (s->slave_mode & (1 << i))) {

                    ptimer_stop(s->slave[i]->timer);

                    ptimer_set_limit(s->slave[i]->timer,

                                     LIMIT_TO_PERIODS(s->slave[i]->limit), 1);

                    DPRINTF("processor %d timer changed\n",

                            s->slave[i]->slave_index);

                    ptimer_run(s->slave[i]->timer, 0);

                }

            }

            s->slave_mode = val & ((1 << s->num_slaves) - 1);

        } else

            DPRINTF("not system timer\n");

        break;

    default:

        DPRINTF("invalid write address " TARGET_FMT_plx "\n", addr);

        break;

    }

}

static void slavio_timer_mem_writel(void *opaque, target_phys_addr_t addr,

                                    uint32_t val)

{

    SLAVIO_TIMERState *s = opaque;

    uint32_t saddr;

    int reload = 0;



    DPRINTF("write " TARGET_FMT_plx " %08x\n", addr, val);

    saddr = (addr & TIMER_MAXADDR) >> 2;

    switch (saddr) {

    case TIMER_LIMIT:

        if (slavio_timer_is_user(s)) {

            

            qemu_irq_lower(s->irq);

            s->limit = TIMER_MAX_COUNT64;

            DPRINTF("processor %d user timer reset\n", s->slave_index);

            ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1);

        } else {

            

            qemu_irq_lower(s->irq);

            s->limit = val & TIMER_MAX_COUNT32;

            if (!s->limit)

                s->limit = TIMER_MAX_COUNT32;

            ptimer_set_limit(s->timer, s->limit >> 9, 1);

        }

        break;

    case TIMER_COUNTER:

        if (slavio_timer_is_user(s)) {

            

            qemu_irq_lower(s->irq);

            s->limit = TIMER_MAX_COUNT64;

            DPRINTF("processor %d user timer reset\n", s->slave_index);

            ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1);

        } else

            DPRINTF("not user timer\n");

        break;

    case TIMER_COUNTER_NORST:

        

        s->limit = val & TIMER_MAX_COUNT32;

        if (!s->limit)

            s->limit = TIMER_MAX_COUNT32;

        ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), reload);

        break;

    case TIMER_STATUS:

        if (slavio_timer_is_user(s)) {

            

            if ((val & 1) && !s->running) {

                DPRINTF("processor %d user timer started\n", s->slave_index);

                ptimer_run(s->timer, 0);

                s->running = 1;

            } else if (!(val & 1) && s->running) {

                DPRINTF("processor %d user timer stopped\n", s->slave_index);

                ptimer_stop(s->timer);

                s->running = 0;

            }

        }

        break;

    case TIMER_MODE:

        if (s->master == NULL) {

            unsigned int i;



            for (i = 0; i < s->num_slaves; i++) {

                if (val & (1 << i)) {

                    qemu_irq_lower(s->slave[i]->irq);

                    s->slave[i]->limit = -1ULL;

                }

                if ((val & (1 << i)) != (s->slave_mode & (1 << i))) {

                    ptimer_stop(s->slave[i]->timer);

                    ptimer_set_limit(s->slave[i]->timer,

                                     LIMIT_TO_PERIODS(s->slave[i]->limit), 1);

                    DPRINTF("processor %d timer changed\n",

                            s->slave[i]->slave_index);

                    ptimer_run(s->slave[i]->timer, 0);

                }

            }

            s->slave_mode = val & ((1 << s->num_slaves) - 1);

        } else

            DPRINTF("not system timer\n");

        break;

    default:

        DPRINTF("invalid write address " TARGET_FMT_plx "\n", addr);

        break;

    }

}

static void FUNC_0(void *VAR_0, target_phys_addr_t VAR_1,

                                    uint32_t VAR_2)

{

    SLAVIO_TIMERState *s = VAR_0;

    uint32_t saddr;

    int VAR_3 = 0;



    DPRINTF("write " TARGET_FMT_plx " %08x\n", VAR_1, VAR_2);

    saddr = (VAR_1 & TIMER_MAXADDR) >> 2;

    switch (saddr) {

    case TIMER_LIMIT:

        if (slavio_timer_is_user(s)) {

            

            qemu_irq_lower(s->irq);

            s->limit = TIMER_MAX_COUNT64;

            DPRINTF("processor %d user timer reset\n", s->slave_index);

            ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1);

        } else {

            

            qemu_irq_lower(s->irq);

            s->limit = VAR_2 & TIMER_MAX_COUNT32;

            if (!s->limit)

                s->limit = TIMER_MAX_COUNT32;

            ptimer_set_limit(s->timer, s->limit >> 9, 1);

        }

        break;

    case TIMER_COUNTER:

        if (slavio_timer_is_user(s)) {

            

            qemu_irq_lower(s->irq);

            s->limit = TIMER_MAX_COUNT64;

            DPRINTF("processor %d user timer reset\n", s->slave_index);

            ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1);

        } else

            DPRINTF("not user timer\n");

        break;

    case TIMER_COUNTER_NORST:

        

        s->limit = VAR_2 & TIMER_MAX_COUNT32;

        if (!s->limit)

            s->limit = TIMER_MAX_COUNT32;

        ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), VAR_3);

        break;

    case TIMER_STATUS:

        if (slavio_timer_is_user(s)) {

            

            if ((VAR_2 & 1) && !s->running) {

                DPRINTF("processor %d user timer started\n", s->slave_index);

                ptimer_run(s->timer, 0);

                s->running = 1;

            } else if (!(VAR_2 & 1) && s->running) {

                DPRINTF("processor %d user timer stopped\n", s->slave_index);

                ptimer_stop(s->timer);

                s->running = 0;

            }

        }

        break;

    case TIMER_MODE:

        if (s->master == NULL) {

            unsigned int VAR_4;



            for (VAR_4 = 0; VAR_4 < s->num_slaves; VAR_4++) {

                if (VAR_2 & (1 << VAR_4)) {

                    qemu_irq_lower(s->slave[VAR_4]->irq);

                    s->slave[VAR_4]->limit = -1ULL;

                }

                if ((VAR_2 & (1 << VAR_4)) != (s->slave_mode & (1 << VAR_4))) {

                    ptimer_stop(s->slave[VAR_4]->timer);

                    ptimer_set_limit(s->slave[VAR_4]->timer,

                                     LIMIT_TO_PERIODS(s->slave[VAR_4]->limit), 1);

                    DPRINTF("processor %d timer changed\n",

                            s->slave[VAR_4]->slave_index);

                    ptimer_run(s->slave[VAR_4]->timer, 0);

                }

            }

            s->slave_mode = VAR_2 & ((1 << s->num_slaves) - 1);

        } else

            DPRINTF("not system timer\n");

        break;

    default:

        DPRINTF("invalid write address " TARGET_FMT_plx "\n", VAR_1);

        break;

    }

}

static void FUNC_0(void *VAR_0, target_phys_addr_t VAR_1,
uint32_t VAR_2)
{ SLAVIO_TIMERState *s = VAR_0; uint32_t saddr; int VAR_3 = 0; DPRINTF("write " TARGET_FMT_plx " %08x\n", VAR_1, VAR_2); saddr = (VAR_1 & TIMER_MAXADDR) >> 2; switch (saddr) { case TIMER_LIMIT:
if (slavio_timer_is_user(s)) { qemu_irq_lower(s->irq); s->limit = TIMER_MAX_COUNT64; DPRINTF("processor %d user timer reset\n", s->slave_index); ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1); } else { qemu_irq_lower(s->irq); s->limit = VAR_2 & TIMER_MAX_COUNT32; if (!s->limit)
s->limit = TIMER_MAX_COUNT32; ptimer_set_limit(s->timer, s->limit >> 9, 1); } break; case TIMER_COUNTER:
if (slavio_timer_is_user(s)) { qemu_irq_lower(s->irq); s->limit = TIMER_MAX_COUNT64; DPRINTF("processor %d user timer reset\n", s->slave_index); ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), 1); } else DPRINTF("not user timer\n"); break; case TIMER_COUNTER_NORST:
s->limit = VAR_2 & TIMER_MAX_COUNT32; if (!s->limit)
s->limit = TIMER_MAX_COUNT32; ptimer_set_limit(s->timer, LIMIT_TO_PERIODS(s->limit), VAR_3); break; case TIMER_STATUS:
if (slavio_timer_is_user(s)) { if ((VAR_2 & 1) && !s->running) { DPRINTF("processor %d user timer started\n", s->slave_index); ptimer_run(s->timer, 0); s->running = 1; } else if (!(VAR_2 & 1) && s->running) { DPRINTF("processor %d user timer stopped\n", s->slave_index); ptimer_stop(s->timer); s->running = 0; } } break; case TIMER_MODE:
if (s->master == NULL) { unsigned int VAR_4; for (VAR_4 = 0; VAR_4 < s->num_slaves; VAR_4++) { if (VAR_2 & (1 << VAR_4)) { qemu_irq_lower(s->slave[VAR_4]->irq); s->slave[VAR_4]->limit = -1ULL; } if ((VAR_2 & (1 << VAR_4)) != (s->slave_mode & (1 << VAR_4))) { ptimer_stop(s->slave[VAR_4]->timer); ptimer_set_limit(s->slave[VAR_4]->timer,
LIMIT_TO_PERIODS(s->slave[VAR_4]->limit), 1); DPRINTF("processor %d timer changed\n",
s->slave[VAR_4]->slave_index); ptimer_run(s->slave[VAR_4]->timer, 0); } } s->slave_mode = VAR_2 & ((1 << s->num_slaves) - 1); } else DPRINTF("not system timer\n"); break; default:
DPRINTF("invalid write address " TARGET_FMT_plx "\n", VAR_1); break; } }