static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) {

    GetBitContext *gb=&vc->gb;

    uint_fast8_t i, j;

    vc->mapping_count=get_bits(gb, 6)+1;

    vc->mappings=(vorbis_mapping *)av_mallocz(vc->mapping_count * sizeof(vorbis_mapping));

    AV_DEBUG(" There are %d mappings. \n", vc->mapping_count);

    for(i=0;i<vc->mapping_count;++i) {

        vorbis_mapping *mapping_setup=&vc->mappings[i];

        if (get_bits(gb, 16)) {

            av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n");

            return 1;

        }

        if (get_bits1(gb)) {

            mapping_setup->submaps=get_bits(gb, 4)+1;

        } else {

            mapping_setup->submaps=1;

        }

        if (get_bits1(gb)) {

            mapping_setup->coupling_steps=get_bits(gb, 8)+1;

            mapping_setup->magnitude=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));

            mapping_setup->angle=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t));

            for(j=0;j<mapping_setup->coupling_steps;++j) {

                mapping_setup->magnitude[j]=get_bits(gb, ilog(vc->audio_channels-1));

                mapping_setup->angle[j]=get_bits(gb, ilog(vc->audio_channels-1));

                // FIXME: sanity checks

            }

        } else {

            mapping_setup->coupling_steps=0;

        }

        AV_DEBUG("   %d mapping coupling steps: %d \n", i, mapping_setup->coupling_steps);

        if(get_bits(gb, 2)) {

            av_log(vc->avccontext, AV_LOG_ERROR, "%d. mapping setup data invalid. \n", i);

            return 1; // following spec.

        }

        if (mapping_setup->submaps>1) {

            mapping_setup->mux=(uint_fast8_t *)av_mallocz(vc->audio_channels * sizeof(uint_fast8_t));

            for(j=0;j<vc->audio_channels;++j) {

                mapping_setup->mux[j]=get_bits(gb, 4);

            }

        }

        for(j=0;j<mapping_setup->submaps;++j) {

            skip_bits(gb, 8); // FIXME check?

            mapping_setup->submap_floor[j]=get_bits(gb, 8);

            mapping_setup->submap_residue[j]=get_bits(gb, 8);

            AV_DEBUG("   %d mapping %d submap : floor %d, residue %d \n", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]);

        }

    }

    return 0;

}


void stq_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint64_t val)

{

    val = tswap64(val);

    spapr_tce_dma_write(dev, taddr, &val, sizeof(val));

}


static void vp6_parse_coeff_models(VP56Context *s)

{

    VP56RangeCoder *c = &s->c;

    VP56Model *model = s->modelp;

    int def_prob[11];

    int node, cg, ctx, pos;

    int ct;    /* code type */

    int pt;    /* plane type (0 for Y, 1 for U or V) */

    memset(def_prob, 0x80, sizeof(def_prob));

    for (pt=0; pt<2; pt++)

        for (node=0; node<11; node++)

            if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) {

                def_prob[node] = vp56_rac_gets_nn(c, 7);

                model->coeff_dccv[pt][node] = def_prob[node];

            } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {

                model->coeff_dccv[pt][node] = def_prob[node];

            }

    if (vp56_rac_get(c)) {

        for (pos=1; pos<64; pos++)

            if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos]))

                model->coeff_reorder[pos] = vp56_rac_gets(c, 4);

        vp6_coeff_order_table_init(s);

    }

    for (cg=0; cg<2; cg++)

        for (node=0; node<14; node++)

            if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node]))

                model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7);

    for (ct=0; ct<3; ct++)

        for (pt=0; pt<2; pt++)

            for (cg=0; cg<6; cg++)

                for (node=0; node<11; node++)

                    if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) {

                        def_prob[node] = vp56_rac_gets_nn(c, 7);

                        model->coeff_ract[pt][ct][cg][node] = def_prob[node];

                    } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) {

                        model->coeff_ract[pt][ct][cg][node] = def_prob[node];

                    }

    if (s->use_huffman) {

        for (pt=0; pt<2; pt++) {

            vp6_build_huff_tree(s, model->coeff_dccv[pt],

                                vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]);

            vp6_build_huff_tree(s, model->coeff_runv[pt],

                                vp6_huff_run_map, 9, &s->runv_vlc[pt]);

            for (ct=0; ct<3; ct++)

                for (cg = 0; cg < 6; cg++)

                    vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg],

                                        vp6_huff_coeff_map, 12,

                                        &s->ract_vlc[pt][ct][cg]);

        }

        memset(s->nb_null, 0, sizeof(s->nb_null));

    } else {

    /* coeff_dcct is a linear combination of coeff_dccv */

    for (pt=0; pt<2; pt++)

        for (ctx=0; ctx<3; ctx++)

            for (node=0; node<5; node++)

                model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255);

    }

}


test_opts_dict_unvisited(void)

{

    QemuOpts *opts;

    Visitor *v;

    UserDefOptions *userdef;

    opts = qemu_opts_parse(qemu_find_opts("userdef"), "i64x=0,bogus=1", false,

                           &error_abort);

    v = opts_visitor_new(opts);

    /* BUG: bogus should be diagnosed */

    visit_type_UserDefOptions(v, NULL, &userdef, &error_abort);

    visit_free(v);

    qemu_opts_del(opts);

    qapi_free_UserDefOptions(userdef);

}


static int64_t coroutine_fn parallels_co_get_block_status(BlockDriverState *bs,

        int64_t sector_num, int nb_sectors, int *pnum)

{

    BDRVParallelsState *s = bs->opaque;

    int64_t offset;

    qemu_co_mutex_lock(&s->lock);

    offset = block_status(s, sector_num, nb_sectors, pnum);

    qemu_co_mutex_unlock(&s->lock);

    if (offset < 0) {

        return 0;

    }

    return (offset << BDRV_SECTOR_BITS) |

        BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID;

}


void helper_4xx_tlbwe_hi (target_ulong entry, target_ulong val)

{

    ppcemb_tlb_t *tlb;

    target_ulong page, end;

    LOG_SWTLB("%s entry %d val " TARGET_FMT_lx "\n", __func__, (int)entry,

              val);

    entry &= 0x3F;

    tlb = &env->tlb[entry].tlbe;

    /* Invalidate previous TLB (if it's valid) */

    if (tlb->prot & PAGE_VALID) {

        end = tlb->EPN + tlb->size;

        LOG_SWTLB("%s: invalidate old TLB %d start " TARGET_FMT_lx " end "

                  TARGET_FMT_lx "\n", __func__, (int)entry, tlb->EPN, end);

        for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)

            tlb_flush_page(env, page);

    }

    tlb->size = booke_tlb_to_page_size((val >> 7) & 0x7);

    /* We cannot handle TLB size < TARGET_PAGE_SIZE.

     * If this ever occurs, one should use the ppcemb target instead

     * of the ppc or ppc64 one

     */

    if ((val & 0x40) && tlb->size < TARGET_PAGE_SIZE) {

        cpu_abort(env, "TLB size " TARGET_FMT_lu " < %u "

                  "are not supported (%d)\n",

                  tlb->size, TARGET_PAGE_SIZE, (int)((val >> 7) & 0x7));

    }

    tlb->EPN = val & ~(tlb->size - 1);

    if (val & 0x40)

        tlb->prot |= PAGE_VALID;

    else

        tlb->prot &= ~PAGE_VALID;

    if (val & 0x20) {

        /* XXX: TO BE FIXED */

        cpu_abort(env, "Little-endian TLB entries are not supported by now\n");

    }

    tlb->PID = env->spr[SPR_40x_PID]; /* PID */

    LOG_SWTLB("%s: set up TLB %d RPN " TARGET_FMT_plx " EPN " TARGET_FMT_lx

              " size " TARGET_FMT_lx " prot %c%c%c%c PID %d\n", __func__,

              (int)entry, tlb->RPN, tlb->EPN, tlb->size,

              tlb->prot & PAGE_READ ? 'r' : '-',

              tlb->prot & PAGE_WRITE ? 'w' : '-',

              tlb->prot & PAGE_EXEC ? 'x' : '-',

              tlb->prot & PAGE_VALID ? 'v' : '-', (int)tlb->PID);

    /* Invalidate new TLB (if valid) */

    if (tlb->prot & PAGE_VALID) {

        end = tlb->EPN + tlb->size;

        LOG_SWTLB("%s: invalidate TLB %d start " TARGET_FMT_lx " end "

                  TARGET_FMT_lx "\n", __func__, (int)entry, tlb->EPN, end);

        for (page = tlb->EPN; page < end; page += TARGET_PAGE_SIZE)

            tlb_flush_page(env, page);

    }

}


static void kvm_update_msi_routes_all(void *private, bool global,

                                      uint32_t index, uint32_t mask)

{

    int cnt = 0;

    MSIRouteEntry *entry;

    MSIMessage msg;

    /* TODO: explicit route update */

    QLIST_FOREACH(entry, &msi_route_list, list) {

        cnt++;

        msg = pci_get_msi_message(entry->dev, entry->vector);

        kvm_irqchip_update_msi_route(kvm_state, entry->virq,

                                     msg, entry->dev);

    }

    kvm_irqchip_commit_routes(kvm_state);

    trace_kvm_x86_update_msi_routes(cnt);

}


static void spr_write_601_ubatu (void *opaque, int sprn)

{

    DisasContext *ctx = opaque;

    gen_op_store_601_batu((sprn - SPR_IBAT0U) / 2);

    RET_STOP(ctx);

}


static void ide_sector_write(IDEState *s)

{

    int64_t sector_num;

    int ret, n, n1;

    s->status = READY_STAT | SEEK_STAT;

    sector_num = ide_get_sector(s);

#if defined(DEBUG_IDE)

    printf("write sector=%Ld\n", sector_num);

#endif

    n = s->nsector;

    if (n > s->req_nb_sectors)

        n = s->req_nb_sectors;

    ret = bdrv_write(s->bs, sector_num, s->io_buffer, n);

    s->nsector -= n;

    if (s->nsector == 0) {

        /* no more sector to write */

        ide_transfer_stop(s);

    } else {

        n1 = s->nsector;

        if (n1 > s->req_nb_sectors)

            n1 = s->req_nb_sectors;

        ide_transfer_start(s, s->io_buffer, 512 * n1, ide_sector_write);

    }

    ide_set_sector(s, sector_num + n);

#ifdef TARGET_I386

    if (win2k_install_hack) {

        /* It seems there is a bug in the Windows 2000 installer HDD

           IDE driver which fills the disk with empty logs when the

           IDE write IRQ comes too early. This hack tries to correct

           that at the expense of slower write performances. Use this

           option _only_ to install Windows 2000. You must disable it

           for normal use. */

        qemu_mod_timer(s->sector_write_timer,

                       qemu_get_clock(vm_clock) + (ticks_per_sec / 1000));

    } else

#endif

    {

        ide_set_irq(s);

    }

}


AioContext *iohandler_get_aio_context(void)

{

    iohandler_init();

    return iohandler_ctx;

}