static void icount_adjust_rt(void * opaque) { qemu_mod_timer(icount_rt_timer, qemu_get_clock(rt_clock) + 1000); icount_adjust(); }


static void virtio_blk_migration_state_changed(Notifier *notifier, void *data) { VirtIOBlock *s = container_of(notifier, VirtIOBlock, migration_state_notifier); MigrationState *mig = data; Error *err = NULL; if (migration_in_setup(mig)) { if (!s->dataplane) { return; } virtio_blk_data_plane_destroy(s->dataplane); s->dataplane = NULL; } else if (migration_has_finished(mig) || migration_has_failed(mig)) { if (s->dataplane) { return; } bdrv_drain_all(); /* complete in-flight non-dataplane requests */ virtio_blk_data_plane_create(VIRTIO_DEVICE(s), &s->conf, &s->dataplane, &err); if (err != NULL) { error_report("%s", error_get_pretty(err)); error_free(err); } } }


CaptureVoiceOut *AUD_add_capture ( struct audsettings *as, struct audio_capture_ops *ops, void *cb_opaque ) { AudioState *s = &glob_audio_state; CaptureVoiceOut *cap; struct capture_callback *cb; if (audio_validate_settings (as)) { dolog ("Invalid settings were passed when trying to add capture\n"); audio_print_settings (as); goto err0; } cb = audio_calloc (AUDIO_FUNC, 1, sizeof (*cb)); if (!cb) { dolog ("Could not allocate capture callback information, size %zu\n", sizeof (*cb)); goto err0; } cb->ops = *ops; cb->opaque = cb_opaque; cap = audio_pcm_capture_find_specific (as); if (cap) { LIST_INSERT_HEAD (&cap->cb_head, cb, entries); return cap; } else { HWVoiceOut *hw; CaptureVoiceOut *cap; cap = audio_calloc (AUDIO_FUNC, 1, sizeof (*cap)); if (!cap) { dolog ("Could not allocate capture voice, size %zu\n", sizeof (*cap)); goto err1; } hw = &cap->hw; LIST_INIT (&hw->sw_head); LIST_INIT (&cap->cb_head); /* XXX find a more elegant way */ hw->samples = 4096 * 4; hw->mix_buf = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (struct st_sample)); if (!hw->mix_buf) { dolog ("Could not allocate capture mix buffer (%d samples)\n", hw->samples); goto err2; } audio_pcm_init_info (&hw->info, as); cap->buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift); if (!cap->buf) { dolog ("Could not allocate capture buffer " "(%d samples, each %d bytes)\n", hw->samples, 1 << hw->info.shift); goto err3; } hw->clip = mixeng_clip [hw->info.nchannels == 2] [hw->info.sign] [hw->info.swap_endianness] [audio_bits_to_index (hw->info.bits)]; LIST_INSERT_HEAD (&s->cap_head, cap, entries); LIST_INSERT_HEAD (&cap->cb_head, cb, entries); hw = NULL; while ((hw = audio_pcm_hw_find_any_out (hw))) { audio_attach_capture (hw); } return cap; err3: qemu_free (cap->hw.mix_buf); err2: qemu_free (cap); err1: qemu_free (cb); err0: return NULL; } }


const char *bdrv_get_encrypted_filename(BlockDriverState *bs) { if (bs->backing_hd && bs->backing_hd->encrypted) return bs->backing_file; else if (bs->encrypted) return bs->filename; else return NULL; }


static inline void tcg_out_goto(TCGContext *s, tcg_insn_unit *target) { ptrdiff_t offset = target - s->code_ptr; assert(offset == sextract64(offset, 0, 26)); tcg_out_insn(s, 3206, B, offset); }


void qapi_copy_SocketAddress(SocketAddress **p_dest, SocketAddress *src) { QmpOutputVisitor *qov; Visitor *ov, *iv; QObject *obj; *p_dest = NULL; qov = qmp_output_visitor_new(); ov = qmp_output_get_visitor(qov); visit_type_SocketAddress(ov, NULL, &src, &error_abort); obj = qmp_output_get_qobject(qov); visit_free(ov); if (!obj) { return; } iv = qmp_input_visitor_new(obj, true); visit_type_SocketAddress(iv, NULL, p_dest, &error_abort); visit_free(iv); qobject_decref(obj); }


static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata) { AVFormatContext *is = ifile->ctx; AVFormatContext *os = ofile->ctx; AVChapter **tmp; int i; tmp = av_realloc(os->chapters, sizeof(*os->chapters) * (is->nb_chapters + os->nb_chapters)); if (!tmp) return AVERROR(ENOMEM); os->chapters = tmp; for (i = 0; i < is->nb_chapters; i++) { AVChapter *in_ch = is->chapters[i], *out_ch; int64_t ts_off = av_rescale_q(ofile->start_time - ifile->ts_offset, AV_TIME_BASE_Q, in_ch->time_base); int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX : av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base); if (in_ch->end < ts_off) continue; if (rt != INT64_MAX && in_ch->start > rt + ts_off) break; out_ch = av_mallocz(sizeof(AVChapter)); if (!out_ch) return AVERROR(ENOMEM); out_ch->id = in_ch->id; out_ch->time_base = in_ch->time_base; out_ch->start = FFMAX(0, in_ch->start - ts_off); out_ch->end = FFMIN(rt, in_ch->end - ts_off); if (copy_metadata) av_dict_copy(&out_ch->metadata, in_ch->metadata, 0); os->chapters[os->nb_chapters++] = out_ch; } return 0; }


gen_intermediate_code_internal(CPUState * env, TranslationBlock * tb, int search_pc) { DisasContext ctx; target_ulong pc_start; static uint16_t *gen_opc_end; CPUBreakpoint *bp; int i, ii; int num_insns; int max_insns; pc_start = tb->pc; gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; ctx.pc = pc_start; ctx.flags = (uint32_t)tb->flags; ctx.bstate = BS_NONE; ctx.sr = env->sr; ctx.fpscr = env->fpscr; ctx.memidx = (env->sr & SR_MD) ? 1 : 0; /* We don't know if the delayed pc came from a dynamic or static branch, so assume it is a dynamic branch. */ ctx.delayed_pc = -1; /* use delayed pc from env pointer */ ctx.tb = tb; ctx.singlestep_enabled = env->singlestep_enabled; ctx.features = env->features; ctx.has_movcal = (tb->flags & TB_FLAG_PENDING_MOVCA); #ifdef DEBUG_DISAS qemu_log_mask(CPU_LOG_TB_CPU, "------------------------------------------------\n"); log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0); #endif ii = -1; num_insns = 0; max_insns = tb->cflags & CF_COUNT_MASK; if (max_insns == 0) max_insns = CF_COUNT_MASK; gen_icount_start(); while (ctx.bstate == BS_NONE && gen_opc_ptr < gen_opc_end) { if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) { TAILQ_FOREACH(bp, &env->breakpoints, entry) { if (ctx.pc == bp->pc) { /* We have hit a breakpoint - make sure PC is up-to-date */ tcg_gen_movi_i32(cpu_pc, ctx.pc); gen_helper_debug(); ctx.bstate = BS_EXCP; break; } } } if (search_pc) { i = gen_opc_ptr - gen_opc_buf; if (ii < i) { ii++; while (ii < i) gen_opc_instr_start[ii++] = 0; } gen_opc_pc[ii] = ctx.pc; gen_opc_hflags[ii] = ctx.flags; gen_opc_instr_start[ii] = 1; gen_opc_icount[ii] = num_insns; } if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) gen_io_start(); #if 0 fprintf(stderr, "Loading opcode at address 0x%08x\n", ctx.pc); fflush(stderr); #endif ctx.opcode = lduw_code(ctx.pc); decode_opc(&ctx); num_insns++; ctx.pc += 2; if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0) break; if (env->singlestep_enabled) break; if (num_insns >= max_insns) break; if (singlestep) break; } if (tb->cflags & CF_LAST_IO) gen_io_end(); if (env->singlestep_enabled) { tcg_gen_movi_i32(cpu_pc, ctx.pc); gen_helper_debug(); } else { switch (ctx.bstate) { case BS_STOP: /* gen_op_interrupt_restart(); */ /* fall through */ case BS_NONE: if (ctx.flags) { gen_store_flags(ctx.flags | DELAY_SLOT_CLEARME); } gen_goto_tb(&ctx, 0, ctx.pc); break; case BS_EXCP: /* gen_op_interrupt_restart(); */ tcg_gen_exit_tb(0); break; case BS_BRANCH: default: break; } } gen_icount_end(tb, num_insns); *gen_opc_ptr = INDEX_op_end; if (search_pc) { i = gen_opc_ptr - gen_opc_buf; ii++; while (ii <= i) gen_opc_instr_start[ii++] = 0; } else { tb->size = ctx.pc - pc_start; tb->icount = num_insns; } #ifdef DEBUG_DISAS #ifdef SH4_DEBUG_DISAS qemu_log_mask(CPU_LOG_TB_IN_ASM, "\n"); #endif if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("IN:\n"); /* , lookup_symbol(pc_start)); */ log_target_disas(pc_start, ctx.pc - pc_start, 0); qemu_log("\n"); } #endif }


int cpu_x86_register(X86CPU *cpu, const char *cpu_model) { CPUX86State *env = &cpu->env; x86_def_t def1, *def = &def1; Error *error = NULL; memset(def, 0, sizeof(*def)); if (cpu_x86_find_by_name(def, cpu_model) < 0) return -1; if (def->vendor1) { env->cpuid_vendor1 = def->vendor1; env->cpuid_vendor2 = def->vendor2; env->cpuid_vendor3 = def->vendor3; } else { env->cpuid_vendor1 = CPUID_VENDOR_INTEL_1; env->cpuid_vendor2 = CPUID_VENDOR_INTEL_2; env->cpuid_vendor3 = CPUID_VENDOR_INTEL_3; } env->cpuid_vendor_override = def->vendor_override; object_property_set_int(OBJECT(cpu), def->level, "level", &error); object_property_set_int(OBJECT(cpu), def->family, "family", &error); object_property_set_int(OBJECT(cpu), def->model, "model", &error); object_property_set_int(OBJECT(cpu), def->stepping, "stepping", &error); env->cpuid_features = def->features; env->cpuid_ext_features = def->ext_features; env->cpuid_ext2_features = def->ext2_features; env->cpuid_ext3_features = def->ext3_features; object_property_set_int(OBJECT(cpu), def->xlevel, "xlevel", &error); env->cpuid_kvm_features = def->kvm_features; env->cpuid_svm_features = def->svm_features; env->cpuid_ext4_features = def->ext4_features; env->cpuid_7_0_ebx = def->cpuid_7_0_ebx_features; env->cpuid_xlevel2 = def->xlevel2; object_property_set_int(OBJECT(cpu), (int64_t)def->tsc_khz * 1000, "tsc-frequency", &error); /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on * CPUID[1].EDX. */ if (env->cpuid_vendor1 == CPUID_VENDOR_AMD_1 && env->cpuid_vendor2 == CPUID_VENDOR_AMD_2 && env->cpuid_vendor3 == CPUID_VENDOR_AMD_3) { env->cpuid_ext2_features &= ~CPUID_EXT2_AMD_ALIASES; env->cpuid_ext2_features |= (def->features & CPUID_EXT2_AMD_ALIASES); } if (!kvm_enabled()) { env->cpuid_features &= TCG_FEATURES; env->cpuid_ext_features &= TCG_EXT_FEATURES; env->cpuid_ext2_features &= (TCG_EXT2_FEATURES #ifdef TARGET_X86_64 | CPUID_EXT2_SYSCALL | CPUID_EXT2_LM #endif ); env->cpuid_ext3_features &= TCG_EXT3_FEATURES; env->cpuid_svm_features &= TCG_SVM_FEATURES; } object_property_set_str(OBJECT(cpu), def->model_id, "model-id", &error); if (error_is_set(&error)) { error_free(error); return -1; } return 0; }


static void init_proc_e500 (CPUPPCState *env, int version) { uint32_t tlbncfg[2]; uint64_t ivor_mask = 0x0000000F0000FFFFULL; uint32_t l1cfg0 = 0x3800 /* 8 ways */ | 0x0020; /* 32 kb */ #if !defined(CONFIG_USER_ONLY) int i; #endif /* Time base */ gen_tbl(env); /* * XXX The e500 doesn't implement IVOR7 and IVOR9, but doesn't * complain when accessing them. * gen_spr_BookE(env, 0x0000000F0000FD7FULL); */ if (version == fsl_e500mc) { ivor_mask = 0x000003FE0000FFFFULL; } gen_spr_BookE(env, ivor_mask); /* Processor identification */ spr_register(env, SPR_BOOKE_PIR, "PIR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_pir, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_BOOKE_SPEFSCR, "SPEFSCR", &spr_read_spefscr, &spr_write_spefscr, &spr_read_spefscr, &spr_write_spefscr, 0x00000000); /* Memory management */ #if defined(CONFIG_USER_ONLY) env->dcache_line_size = 32; env->icache_line_size = 32; #else /* !defined(CONFIG_USER_ONLY) */ env->nb_pids = 3; env->nb_ways = 2; env->id_tlbs = 0; switch (version) { case fsl_e500v1: /* e500v1 */ tlbncfg[0] = gen_tlbncfg(2, 1, 1, 0, 256); tlbncfg[1] = gen_tlbncfg(16, 1, 9, TLBnCFG_AVAIL | TLBnCFG_IPROT, 16); env->dcache_line_size = 32; env->icache_line_size = 32; break; case fsl_e500v2: /* e500v2 */ tlbncfg[0] = gen_tlbncfg(4, 1, 1, 0, 512); tlbncfg[1] = gen_tlbncfg(16, 1, 12, TLBnCFG_AVAIL | TLBnCFG_IPROT, 16); env->dcache_line_size = 32; env->icache_line_size = 32; break; case fsl_e500mc: /* e500mc */ tlbncfg[0] = gen_tlbncfg(4, 1, 1, 0, 512); tlbncfg[1] = gen_tlbncfg(64, 1, 12, TLBnCFG_AVAIL | TLBnCFG_IPROT, 64); env->dcache_line_size = 64; env->icache_line_size = 64; l1cfg0 |= 0x1000000; /* 64 byte cache block size */ break; default: cpu_abort(env, "Unknown CPU: " TARGET_FMT_lx "\n", env->spr[SPR_PVR]); } #endif gen_spr_BookE206(env, 0x000000DF, tlbncfg); /* XXX : not implemented */ spr_register(env, SPR_HID0, "HID0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_HID1, "HID1", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_Exxx_BBEAR, "BBEAR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_Exxx_BBTAR, "BBTAR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_Exxx_MCAR, "MCAR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_BOOKE_MCSR, "MCSR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_Exxx_NPIDR, "NPIDR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_Exxx_BUCSR, "BUCSR", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_Exxx_L1CFG0, "L1CFG0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, l1cfg0); /* XXX : not implemented */ spr_register(env, SPR_Exxx_L1CSR0, "L1CSR0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_e500_l1csr0, 0x00000000); /* XXX : not implemented */ spr_register(env, SPR_Exxx_L1CSR1, "L1CSR1", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); spr_register(env, SPR_BOOKE_MCSRR0, "MCSRR0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); spr_register(env, SPR_BOOKE_MCSRR1, "MCSRR1", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0x00000000); spr_register(env, SPR_MMUCSR0, "MMUCSR0", SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_booke206_mmucsr0, 0x00000000); #if !defined(CONFIG_USER_ONLY) env->nb_tlb = 0; env->tlb_type = TLB_MAS; for (i = 0; i < BOOKE206_MAX_TLBN; i++) { env->nb_tlb += booke206_tlb_size(env, i); } #endif init_excp_e200(env); /* Allocate hardware IRQ controller */ ppce500_irq_init(env); }


int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t size) { target_phys_addr_t end = addr + size; uint8_t *s, *d = dest; size_t l = 0; Rom *rom; QTAILQ_FOREACH(rom, &roms, next) { if (rom->fw_file) { continue; } if (rom->addr + rom->romsize < addr) continue; if (rom->addr > end) break; if (!rom->data) continue; d = dest + (rom->addr - addr); s = rom->data; l = rom->romsize; if (rom->addr < addr) { d = dest; s += (addr - rom->addr); l -= (addr - rom->addr); } if ((d + l) > (dest + size)) { l = dest - d; } memcpy(d, s, l); } return (d + l) - dest; }


static int default_qemu_set_fd_handler2(int fd, IOCanReadHandler *fd_read_poll, IOHandler *fd_read, IOHandler *fd_write, void *opaque) { abort(); }


struct omap_eac_s *omap_eac_init(struct omap_target_agent_s *ta, qemu_irq irq, qemu_irq *drq, omap_clk fclk, omap_clk iclk) { int iomemtype; struct omap_eac_s *s = (struct omap_eac_s *) qemu_mallocz(sizeof(struct omap_eac_s)); s->irq = irq; s->codec.rxdrq = *drq ++; s->codec.txdrq = *drq; omap_eac_reset(s); #ifdef HAS_AUDIO AUD_register_card("OMAP EAC", &s->codec.card); iomemtype = cpu_register_io_memory(omap_eac_readfn, omap_eac_writefn, s); omap_l4_attach(ta, 0, iomemtype); #endif return s; }


static void intel_hda_response(HDACodecDevice *dev, bool solicited, uint32_t response) { HDACodecBus *bus = HDA_BUS(dev->qdev.parent_bus); IntelHDAState *d = container_of(bus, IntelHDAState, codecs); hwaddr addr; uint32_t wp, ex; if (d->ics & ICH6_IRS_BUSY) { dprint(d, 2, "%s: [irr] response 0x%x, cad 0x%x\n", __FUNCTION__, response, dev->cad); d->irr = response; d->ics &= ~(ICH6_IRS_BUSY | 0xf0); d->ics |= (ICH6_IRS_VALID | (dev->cad << 4)); return; } if (!(d->rirb_ctl & ICH6_RBCTL_DMA_EN)) { dprint(d, 1, "%s: rirb dma disabled, drop codec response\n", __FUNCTION__); return; } ex = (solicited ? 0 : (1 << 4)) | dev->cad; wp = (d->rirb_wp + 1) & 0xff; addr = intel_hda_addr(d->rirb_lbase, d->rirb_ubase); stl_le_pci_dma(&d->pci, addr + 8*wp, response); stl_le_pci_dma(&d->pci, addr + 8*wp + 4, ex); d->rirb_wp = wp; dprint(d, 2, "%s: [wp 0x%x] response 0x%x, extra 0x%x\n", __FUNCTION__, wp, response, ex); d->rirb_count++; if (d->rirb_count == d->rirb_cnt) { dprint(d, 2, "%s: rirb count reached (%d)\n", __FUNCTION__, d->rirb_count); if (d->rirb_ctl & ICH6_RBCTL_IRQ_EN) { d->rirb_sts |= ICH6_RBSTS_IRQ; intel_hda_update_irq(d); } } else if ((d->corb_rp & 0xff) == d->corb_wp) { dprint(d, 2, "%s: corb ring empty (%d/%d)\n", __FUNCTION__, d->rirb_count, d->rirb_cnt); if (d->rirb_ctl & ICH6_RBCTL_IRQ_EN) { d->rirb_sts |= ICH6_RBSTS_IRQ; intel_hda_update_irq(d); } } }


static void as_memory_range_add(AddressSpace *as, FlatRange *fr) { ram_addr_t phys_offset, region_offset; memory_region_prepare_ram_addr(fr->mr); phys_offset = fr->mr->ram_addr; region_offset = fr->offset_in_region; /* cpu_register_physical_memory_log() wants region_offset for * mmio, but prefers offseting phys_offset for RAM. Humour it. */ if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM) { phys_offset += region_offset; region_offset = 0; } if (!fr->readable) { phys_offset &= ~TARGET_PAGE_MASK & ~IO_MEM_ROMD; } if (fr->readonly) { phys_offset |= IO_MEM_ROM; } cpu_register_physical_memory_log(int128_get64(fr->addr.start), int128_get64(fr->addr.size), phys_offset, region_offset, fr->dirty_log_mask); }


static int flashsv_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { int buf_size = avpkt->size; FlashSVContext *s = avctx->priv_data; int h_blocks, v_blocks, h_part, v_part, i, j, ret; GetBitContext gb; /* no supplementary picture */ if (buf_size == 0) return 0; if (buf_size < 4) return -1; init_get_bits(&gb, avpkt->data, buf_size * 8); /* start to parse the bitstream */ s->block_width = 16 * (get_bits(&gb, 4) + 1); s->image_width = get_bits(&gb, 12); s->block_height = 16 * (get_bits(&gb, 4) + 1); s->image_height = get_bits(&gb, 12); if (s->ver == 2) { skip_bits(&gb, 6); if (get_bits1(&gb)) { avpriv_request_sample(avctx, "iframe"); return AVERROR_PATCHWELCOME; } if (get_bits1(&gb)) { avpriv_request_sample(avctx, "Custom palette"); return AVERROR_PATCHWELCOME; } } /* calculate number of blocks and size of border (partial) blocks */ h_blocks = s->image_width / s->block_width; h_part = s->image_width % s->block_width; v_blocks = s->image_height / s->block_height; v_part = s->image_height % s->block_height; /* the block size could change between frames, make sure the buffer * is large enough, if not, get a larger one */ if (s->block_size < s->block_width * s->block_height) { int tmpblock_size = 3 * s->block_width * s->block_height, err; if ((err = av_reallocp(&s->tmpblock, tmpblock_size)) < 0) { s->block_size = 0; av_log(avctx, AV_LOG_ERROR, "Cannot allocate decompression buffer.\n"); return err; } if (s->ver == 2) { s->deflate_block_size = calc_deflate_block_size(tmpblock_size); if (s->deflate_block_size <= 0) { av_log(avctx, AV_LOG_ERROR, "Cannot determine deflate buffer size.\n"); return -1; } if ((err = av_reallocp(&s->deflate_block, s->deflate_block_size)) < 0) { s->block_size = 0; av_log(avctx, AV_LOG_ERROR, "Cannot allocate deflate buffer.\n"); return err; } } } s->block_size = s->block_width * s->block_height; /* initialize the image size once */ if (avctx->width == 0 && avctx->height == 0) { avctx->width = s->image_width; avctx->height = s->image_height; } /* check for changes of image width and image height */ if (avctx->width != s->image_width || avctx->height != s->image_height) { av_log(avctx, AV_LOG_ERROR, "Frame width or height differs from first frame!\n"); av_log(avctx, AV_LOG_ERROR, "fh = %d, fv %d vs ch = %d, cv = %d\n", avctx->height, avctx->width, s->image_height, s->image_width); return AVERROR_INVALIDDATA; } /* we care for keyframes only in Screen Video v2 */ s->is_keyframe = (avpkt->flags & AV_PKT_FLAG_KEY) && (s->ver == 2); if (s->is_keyframe) { int err; if ((err = av_reallocp(&s->keyframedata, avpkt->size)) < 0) return err; memcpy(s->keyframedata, avpkt->data, avpkt->size); if ((err = av_reallocp(&s->blocks, (v_blocks + !!v_part) * (h_blocks + !!h_part) * sizeof(s->blocks[0]))) < 0) return err; } ff_dlog(avctx, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n", s->image_width, s->image_height, s->block_width, s->block_height, h_blocks, v_blocks, h_part, v_part); if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return ret; } /* loop over all block columns */ for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) { int y_pos = j * s->block_height; // vertical position in frame int cur_blk_height = (j < v_blocks) ? s->block_height : v_part; /* loop over all block rows */ for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) { int x_pos = i * s->block_width; // horizontal position in frame int cur_blk_width = (i < h_blocks) ? s->block_width : h_part; int has_diff = 0; /* get the size of the compressed zlib chunk */ int size = get_bits(&gb, 16); s->color_depth = 0; s->zlibprime_curr = 0; s->zlibprime_prev = 0; s->diff_start = 0; s->diff_height = cur_blk_height; if (8 * size > get_bits_left(&gb)) { av_frame_unref(s->frame); return AVERROR_INVALIDDATA; } if (s->ver == 2 && size) { skip_bits(&gb, 3); s->color_depth = get_bits(&gb, 2); has_diff = get_bits1(&gb); s->zlibprime_curr = get_bits1(&gb); s->zlibprime_prev = get_bits1(&gb); if (s->color_depth != 0 && s->color_depth != 2) { av_log(avctx, AV_LOG_ERROR, "%dx%d invalid color depth %d\n", i, j, s->color_depth); return AVERROR_INVALIDDATA; } if (has_diff) { if (!s->keyframe) { av_log(avctx, AV_LOG_ERROR, "Inter frame without keyframe\n"); return AVERROR_INVALIDDATA; } s->diff_start = get_bits(&gb, 8); s->diff_height = get_bits(&gb, 8); if (s->diff_start + s->diff_height > cur_blk_height) { av_log(avctx, AV_LOG_ERROR, "Block parameters invalid: %d + %d > %d\n", s->diff_start, s->diff_height, cur_blk_height); return AVERROR_INVALIDDATA; } av_log(avctx, AV_LOG_DEBUG, "%dx%d diff start %d height %d\n", i, j, s->diff_start, s->diff_height); size -= 2; } if (s->zlibprime_prev) av_log(avctx, AV_LOG_DEBUG, "%dx%d zlibprime_prev\n", i, j); if (s->zlibprime_curr) { int col = get_bits(&gb, 8); int row = get_bits(&gb, 8); av_log(avctx, AV_LOG_DEBUG, "%dx%d zlibprime_curr %dx%d\n", i, j, col, row); size -= 2; avpriv_request_sample(avctx, "zlibprime_curr"); return AVERROR_PATCHWELCOME; } if (!s->blocks && (s->zlibprime_curr || s->zlibprime_prev)) { av_log(avctx, AV_LOG_ERROR, "no data available for zlib priming\n"); return AVERROR_INVALIDDATA; } size--; // account for flags byte } if (has_diff) { int k; int off = (s->image_height - y_pos - 1) * s->frame->linesize[0]; for (k = 0; k < cur_blk_height; k++) { int x = off - k * s->frame->linesize[0] + x_pos * 3; memcpy(s->frame->data[0] + x, s->keyframe + x, cur_blk_width * 3); } } /* skip unchanged blocks, which have size 0 */ if (size) { if (flashsv_decode_block(avctx, avpkt, &gb, size, cur_blk_width, cur_blk_height, x_pos, y_pos, i + j * (h_blocks + !!h_part))) av_log(avctx, AV_LOG_ERROR, "error in decompression of block %dx%d\n", i, j); } } } if (s->is_keyframe && s->ver == 2) { if (!s->keyframe) { s->keyframe = av_malloc(s->frame->linesize[0] * avctx->height); if (!s->keyframe) { av_log(avctx, AV_LOG_ERROR, "Cannot allocate image data\n"); return AVERROR(ENOMEM); } } memcpy(s->keyframe, s->frame->data[0], s->frame->linesize[0] * avctx->height); } if ((ret = av_frame_ref(data, s->frame)) < 0) return ret; *got_frame = 1; if ((get_bits_count(&gb) / 8) != buf_size) av_log(avctx, AV_LOG_ERROR, "buffer not fully consumed (%d != %d)\n", buf_size, (get_bits_count(&gb) / 8)); /* report that the buffer was completely consumed */ return buf_size; }


static void t_gen_mulu(TCGv d, TCGv d2, TCGv a, TCGv b) { TCGv t0, t1; t0 = tcg_temp_new(TCG_TYPE_I64); t1 = tcg_temp_new(TCG_TYPE_I64); tcg_gen_extu_i32_i64(t0, a); tcg_gen_extu_i32_i64(t1, b); tcg_gen_mul_i64(t0, t0, t1); tcg_gen_trunc_i64_i32(d, t0); tcg_gen_shri_i64(t0, t0, 32); tcg_gen_trunc_i64_i32(d2, t0); tcg_temp_free(t0); tcg_temp_free(t1); }


static int pte64_check(struct mmu_ctx_hash64 *ctx, target_ulong pte0, target_ulong pte1, int h, int rw, int type) { target_ulong mmask; int access, ret, pp; ret = -1; /* Check validity and table match */ if ((pte0 & HPTE64_V_VALID) && (h == !!(pte0 & HPTE64_V_SECONDARY))) { /* Check vsid & api */ mmask = PTE64_CHECK_MASK; pp = (pte1 & HPTE64_R_PP) | ((pte1 & HPTE64_R_PP0) >> 61); /* No execute if either noexec or guarded bits set */ ctx->nx = (pte1 & HPTE64_R_N) || (pte1 & HPTE64_R_G); if (HPTE64_V_COMPARE(pte0, ctx->ptem)) { if (ctx->raddr != (hwaddr)-1ULL) { /* all matches should have equal RPN, WIMG & PP */ if ((ctx->raddr & mmask) != (pte1 & mmask)) { qemu_log("Bad RPN/WIMG/PP\n"); return -3; } } /* Compute access rights */ access = ppc_hash64_pp_check(ctx->key, pp, ctx->nx); /* Keep the matching PTE informations */ ctx->raddr = pte1; ctx->prot = access; ret = ppc_hash64_check_prot(ctx->prot, rw, type); if (ret == 0) { /* Access granted */ LOG_MMU("PTE access granted !\n"); } else { /* Access right violation */ LOG_MMU("PTE access rejected\n"); } } } return ret; }


static void coroutine_fn nest(void *opaque) { NestData *nd = opaque; nd->n_enter++; if (nd->n_enter < nd->max) { Coroutine *child; child = qemu_coroutine_create(nest); qemu_coroutine_enter(child, nd); } nd->n_return++; }


static int vp8_lossless_decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, uint8_t *data_start, unsigned int data_size, int is_alpha_chunk) { WebPContext *s = avctx->priv_data; int w, h, ret, i; if (!is_alpha_chunk) { s->lossless = 1; avctx->pix_fmt = AV_PIX_FMT_ARGB; } ret = init_get_bits8(&s->gb, data_start, data_size); if (ret < 0) return ret; if (!is_alpha_chunk) { if (get_bits(&s->gb, 8) != 0x2F) { av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless signature\n"); return AVERROR_INVALIDDATA; } w = get_bits(&s->gb, 14) + 1; h = get_bits(&s->gb, 14) + 1; if (s->width && s->width != w) { av_log(avctx, AV_LOG_WARNING, "Width mismatch. %d != %d\n", s->width, w); } s->width = w; if (s->height && s->height != h) { av_log(avctx, AV_LOG_WARNING, "Height mismatch. %d != %d\n", s->width, w); } s->height = h; ret = ff_set_dimensions(avctx, s->width, s->height); if (ret < 0) return ret; s->has_alpha = get_bits1(&s->gb); if (get_bits(&s->gb, 3) != 0x0) { av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless version\n"); return AVERROR_INVALIDDATA; } } else { if (!s->width || !s->height) return AVERROR_BUG; w = s->width; h = s->height; } /* parse transformations */ s->nb_transforms = 0; s->reduced_width = 0; while (get_bits1(&s->gb)) { enum TransformType transform = get_bits(&s->gb, 2); s->transforms[s->nb_transforms++] = transform; switch (transform) { case PREDICTOR_TRANSFORM: ret = parse_transform_predictor(s); break; case COLOR_TRANSFORM: ret = parse_transform_color(s); break; case COLOR_INDEXING_TRANSFORM: ret = parse_transform_color_indexing(s); break; } if (ret < 0) goto free_and_return; } /* decode primary image */ s->image[IMAGE_ROLE_ARGB].frame = p; if (is_alpha_chunk) s->image[IMAGE_ROLE_ARGB].is_alpha_primary = 1; ret = decode_entropy_coded_image(s, IMAGE_ROLE_ARGB, w, h); if (ret < 0) goto free_and_return; /* apply transformations */ for (i = s->nb_transforms - 1; i >= 0; i--) { switch (s->transforms[i]) { case PREDICTOR_TRANSFORM: ret = apply_predictor_transform(s); break; case COLOR_TRANSFORM: ret = apply_color_transform(s); break; case SUBTRACT_GREEN: ret = apply_subtract_green_transform(s); break; case COLOR_INDEXING_TRANSFORM: ret = apply_color_indexing_transform(s); break; } if (ret < 0) goto free_and_return; } *got_frame = 1; p->pict_type = AV_PICTURE_TYPE_I; p->key_frame = 1; ret = data_size; free_and_return: for (i = 0; i < IMAGE_ROLE_NB; i++) image_ctx_free(&s->image[i]); return ret; }


static int check_bd(VIOsPAPRVLANDevice *dev, vlan_bd_t bd, target_ulong alignment) { if ((VLAN_BD_ADDR(bd) % alignment) || (VLAN_BD_LEN(bd) % alignment)) { return -1; } if (spapr_vio_check_tces(&dev->sdev, VLAN_BD_ADDR(bd), VLAN_BD_LEN(bd), SPAPR_TCE_RW) != 0) { return -1; } return 0; }


int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu) { if (cap_has_mp_state) { struct kvm_mp_state mp_state; int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MP_STATE, &mp_state); if (ret) { fprintf(stderr, "%s: failed to get MP_STATE %d/%s\n", __func__, ret, strerror(-ret)); abort(); } cpu->powered_off = (mp_state.mp_state == KVM_MP_STATE_STOPPED); } return 0; }


static int a64_write_packet(struct AVFormatContext *s, AVPacket *pkt) { AVCodecContext *avctx = s->streams[0]->codec; A64MuxerContext *c = s->priv_data; int i, j; int ch_chunksize; int lifetime; int frame_count; int charset_size; int frame_size; int num_frames; /* fetch values from extradata */ switch (avctx->codec->id) { case CODEC_ID_A64_MULTI: case CODEC_ID_A64_MULTI5: if(c->interleaved) { /* Write interleaved, means we insert chunks of the future charset before each current frame. * Reason: if we load 1 charset + corresponding frames in one block on c64, we need to store * them first and then display frame by frame to keep in sync. Thus we would read and write * the data for colram from/to ram first and waste too much time. If we interleave and send the * charset beforehand, we assemble a new charset chunk by chunk, write current screen data to * screen-ram to be displayed and decode the colram directly to colram-location $d800 during * the overscan, while reading directly from source * This is the only way so far, to achieve 25fps on c64 */ if(avctx->extradata) { /* fetch values from extradata */ lifetime = AV_RB32(avctx->extradata + 0); frame_count = AV_RB32(avctx->extradata + 4); charset_size = AV_RB32(avctx->extradata + 8); frame_size = AV_RB32(avctx->extradata + 12); /* TODO: sanity checks? */ } else { av_log(avctx, AV_LOG_ERROR, "extradata not set\n"); return AVERROR(EINVAL); } ch_chunksize=charset_size/lifetime; /* TODO: check if charset/size is % lifetime, but maybe check in codec */ if(pkt->data) num_frames = lifetime; else num_frames = c->prev_frame_count; for(i = 0; i < num_frames; i++) { if(pkt->data) { /* if available, put newest charset chunk into buffer */ put_buffer(s->pb, pkt->data + ch_chunksize * i, ch_chunksize); } else { /* a bit ugly, but is there an alternative to put many zeros? */ for(j = 0; j < ch_chunksize; j++) put_byte(s->pb, 0); } if(c->prev_pkt.data) { /* put frame (screen + colram) from last packet into buffer */ put_buffer(s->pb, c->prev_pkt.data + charset_size + frame_size * i, frame_size); } else { /* a bit ugly, but is there an alternative to put many zeros? */ for(j = 0; j < frame_size; j++) put_byte(s->pb, 0); } } /* backup current packet for next turn */ if(pkt->data) { av_new_packet(&c->prev_pkt, pkt->size); memcpy(c->prev_pkt.data, pkt->data, pkt->size); } c->prev_frame_count = frame_count; break; } default: /* Write things as is. Nice for self-contained frames from non-multicolor modes or if played * directly from ram and not from a streaming device (rrnet/mmc) */ if(pkt) put_buffer(s->pb, pkt->data, pkt->size); break; } put_flush_packet(s->pb); return 0; }


static int decode_pce(AACContext * ac, enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], GetBitContext * gb) { int num_front, num_side, num_back, num_lfe, num_assoc_data, num_cc; skip_bits(gb, 2); // object_type ac->m4ac.sampling_index = get_bits(gb, 4); if(ac->m4ac.sampling_index > 11) { av_log(ac->avccontext, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->m4ac.sampling_index); return -1; } ac->m4ac.sample_rate = ff_mpeg4audio_sample_rates[ac->m4ac.sampling_index]; num_front = get_bits(gb, 4); num_side = get_bits(gb, 4); num_back = get_bits(gb, 4); num_lfe = get_bits(gb, 2); num_assoc_data = get_bits(gb, 3); num_cc = get_bits(gb, 4); if (get_bits1(gb)) skip_bits(gb, 4); // mono_mixdown_tag if (get_bits1(gb)) skip_bits(gb, 4); // stereo_mixdown_tag if (get_bits1(gb)) skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_FRONT, gb, num_front); decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_SIDE, gb, num_side ); decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_BACK, gb, num_back ); decode_channel_map(NULL, new_che_pos[TYPE_LFE], AAC_CHANNEL_LFE, gb, num_lfe ); skip_bits_long(gb, 4 * num_assoc_data); decode_channel_map(new_che_pos[TYPE_CCE], new_che_pos[TYPE_CCE], AAC_CHANNEL_CC, gb, num_cc ); align_get_bits(gb); /* comment field, first byte is length */ skip_bits_long(gb, 8 * get_bits(gb, 8)); return 0; }


void start_ahci_device(AHCIQState *ahci) { /* Map AHCI's ABAR (BAR5) */ ahci->hba_base = qpci_iomap(ahci->dev, 5, &ahci->barsize); g_assert(ahci->hba_base); /* turns on pci.cmd.iose, pci.cmd.mse and pci.cmd.bme */ qpci_device_enable(ahci->dev); }


void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque) { balloon_event_fn = func; balloon_opaque = opaque; }


void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd) { qemu_mutex_init(&ssd->lock); QTAILQ_INIT(&ssd->updates); ssd->mouse_x = -1; ssd->mouse_y = -1; if (ssd->num_surfaces == 0) { ssd->num_surfaces = 1024; } ssd->bufsize = (16 * 1024 * 1024); ssd->buf = g_malloc(ssd->bufsize); }


static av_cold int sonic_decode_init(AVCodecContext *avctx) { SonicContext *s = avctx->priv_data; GetBitContext gb; int i; s->channels = avctx->channels; s->samplerate = avctx->sample_rate; if (!avctx->extradata) { av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n"); return AVERROR_INVALIDDATA; } init_get_bits8(&gb, avctx->extradata, avctx->extradata_size); s->version = get_bits(&gb, 2); if (s->version >= 2) { s->version = get_bits(&gb, 8); s->minor_version = get_bits(&gb, 8); } if (s->version != 2) { av_log(avctx, AV_LOG_ERROR, "Unsupported Sonic version, please report\n"); return AVERROR_INVALIDDATA; } if (s->version >= 1) { int sample_rate_index; s->channels = get_bits(&gb, 2); sample_rate_index = get_bits(&gb, 4); if (sample_rate_index >= FF_ARRAY_ELEMS(samplerate_table)) { av_log(avctx, AV_LOG_ERROR, "Invalid sample_rate_index %d\n", sample_rate_index); return AVERROR_INVALIDDATA; } s->samplerate = samplerate_table[sample_rate_index]; av_log(avctx, AV_LOG_INFO, "Sonicv2 chans: %d samprate: %d\n", s->channels, s->samplerate); } if (s->channels > MAX_CHANNELS || s->channels < 1) { av_log(avctx, AV_LOG_ERROR, "Only mono and stereo streams are supported by now\n"); return AVERROR_INVALIDDATA; } s->lossless = get_bits1(&gb); if (!s->lossless) skip_bits(&gb, 3); // XXX FIXME s->decorrelation = get_bits(&gb, 2); if (s->decorrelation != 3 && s->channels != 2) { av_log(avctx, AV_LOG_ERROR, "invalid decorrelation %d\n", s->decorrelation); return AVERROR_INVALIDDATA; } s->downsampling = get_bits(&gb, 2); if (!s->downsampling) { av_log(avctx, AV_LOG_ERROR, "invalid downsampling value\n"); return AVERROR_INVALIDDATA; } s->num_taps = (get_bits(&gb, 5)+1)<<5; if (get_bits1(&gb)) // XXX FIXME av_log(avctx, AV_LOG_INFO, "Custom quant table\n"); s->block_align = 2048LL*s->samplerate/(44100*s->downsampling); s->frame_size = s->channels*s->block_align*s->downsampling; // avctx->frame_size = s->block_align; av_log(avctx, AV_LOG_INFO, "Sonic: ver: %d.%d ls: %d dr: %d taps: %d block: %d frame: %d downsamp: %d\n", s->version, s->minor_version, s->lossless, s->decorrelation, s->num_taps, s->block_align, s->frame_size, s->downsampling); // generate taps s->tap_quant = av_calloc(s->num_taps, sizeof(*s->tap_quant)); if (!s->tap_quant) return AVERROR(ENOMEM); for (i = 0; i < s->num_taps; i++) s->tap_quant[i] = ff_sqrt(i+1); s->predictor_k = av_calloc(s->num_taps, sizeof(*s->predictor_k)); for (i = 0; i < s->channels; i++) { s->predictor_state[i] = av_calloc(s->num_taps, sizeof(**s->predictor_state)); if (!s->predictor_state[i]) return AVERROR(ENOMEM); } for (i = 0; i < s->channels; i++) { s->coded_samples[i] = av_calloc(s->block_align, sizeof(**s->coded_samples)); if (!s->coded_samples[i]) return AVERROR(ENOMEM); } s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples)); if (!s->int_samples) return AVERROR(ENOMEM); avctx->sample_fmt = AV_SAMPLE_FMT_S16; return 0; }


static void init_vlcs(FourXContext *f){ static int done = 0; int i; if (!done) { done = 1; for(i=0; i<4; i++){ init_vlc(&block_type_vlc[i], BLOCK_TYPE_VLC_BITS, 7, &block_type_tab[i][0][1], 2, 1, &block_type_tab[i][0][0], 2, 1); } } }


static inline int draw_glyph_yuv(AVFilterBufferRef *picref, FT_Bitmap *bitmap, unsigned int x, unsigned int y, unsigned int width, unsigned int height, const uint8_t yuva_color[4], int hsub, int vsub) { int r, c, alpha; unsigned int luma_pos, chroma_pos1, chroma_pos2; uint8_t src_val; for (r = 0; r < bitmap->rows && r+y < height; r++) { for (c = 0; c < bitmap->width && c+x < width; c++) { /* get intensity value in the glyph bitmap (source) */ src_val = GET_BITMAP_VAL(r, c); if (!src_val) continue; SET_PIXEL_YUV(picref, yuva_color, src_val, c+x, y+r, hsub, vsub); } } return 0; }


static void remote_block_to_network(RDMARemoteBlock *rb) { rb->remote_host_addr = htonll(rb->remote_host_addr); rb->offset = htonll(rb->offset); rb->length = htonll(rb->length); rb->remote_rkey = htonl(rb->remote_rkey); }


int clp_service_call(S390CPU *cpu, uint8_t r2) { ClpReqHdr *reqh; ClpRspHdr *resh; S390PCIBusDevice *pbdev; uint32_t req_len; uint32_t res_len; uint8_t buffer[4096 * 2]; uint8_t cc = 0; CPUS390XState *env = &cpu->env; int i; cpu_synchronize_state(CPU(cpu)); if (env->psw.mask & PSW_MASK_PSTATE) { program_interrupt(env, PGM_PRIVILEGED, 4); return 0; } if (s390_cpu_virt_mem_read(cpu, env->regs[r2], r2, buffer, sizeof(*reqh))) { return 0; } reqh = (ClpReqHdr *)buffer; req_len = lduw_p(&reqh->len); if (req_len < 16 || req_len > 8184 || (req_len % 8 != 0)) { program_interrupt(env, PGM_OPERAND, 4); return 0; } if (s390_cpu_virt_mem_read(cpu, env->regs[r2], r2, buffer, req_len + sizeof(*resh))) { return 0; } resh = (ClpRspHdr *)(buffer + req_len); res_len = lduw_p(&resh->len); if (res_len < 8 || res_len > 8176 || (res_len % 8 != 0)) { program_interrupt(env, PGM_OPERAND, 4); return 0; } if ((req_len + res_len) > 8192) { program_interrupt(env, PGM_OPERAND, 4); return 0; } if (s390_cpu_virt_mem_read(cpu, env->regs[r2], r2, buffer, req_len + res_len)) { return 0; } if (req_len != 32) { stw_p(&resh->rsp, CLP_RC_LEN); goto out; } switch (lduw_p(&reqh->cmd)) { case CLP_LIST_PCI: { ClpReqRspListPci *rrb = (ClpReqRspListPci *)buffer; list_pci(rrb, &cc); break; } case CLP_SET_PCI_FN: { ClpReqSetPci *reqsetpci = (ClpReqSetPci *)reqh; ClpRspSetPci *ressetpci = (ClpRspSetPci *)resh; pbdev = s390_pci_find_dev_by_fh(ldl_p(&reqsetpci->fh)); if (!pbdev) { stw_p(&ressetpci->hdr.rsp, CLP_RC_SETPCIFN_FH); goto out; } switch (reqsetpci->oc) { case CLP_SET_ENABLE_PCI_FN: pbdev->fh |= FH_MASK_ENABLE; pbdev->state = ZPCI_FS_ENABLED; stl_p(&ressetpci->fh, pbdev->fh); stw_p(&ressetpci->hdr.rsp, CLP_RC_OK); break; case CLP_SET_DISABLE_PCI_FN: pbdev->fh &= ~FH_MASK_ENABLE; pbdev->state = ZPCI_FS_DISABLED; stl_p(&ressetpci->fh, pbdev->fh); stw_p(&ressetpci->hdr.rsp, CLP_RC_OK); break; default: DPRINTF("unknown set pci command\n"); stw_p(&ressetpci->hdr.rsp, CLP_RC_SETPCIFN_FHOP); break; } break; } case CLP_QUERY_PCI_FN: { ClpReqQueryPci *reqquery = (ClpReqQueryPci *)reqh; ClpRspQueryPci *resquery = (ClpRspQueryPci *)resh; pbdev = s390_pci_find_dev_by_fh(ldl_p(&reqquery->fh)); if (!pbdev) { DPRINTF("query pci no pci dev\n"); stw_p(&resquery->hdr.rsp, CLP_RC_SETPCIFN_FH); goto out; } for (i = 0; i < PCI_BAR_COUNT; i++) { uint32_t data = pci_get_long(pbdev->pdev->config + PCI_BASE_ADDRESS_0 + (i * 4)); stl_p(&resquery->bar[i], data); resquery->bar_size[i] = pbdev->pdev->io_regions[i].size ? ctz64(pbdev->pdev->io_regions[i].size) : 0; DPRINTF("bar %d addr 0x%x size 0x%" PRIx64 "barsize 0x%x\n", i, ldl_p(&resquery->bar[i]), pbdev->pdev->io_regions[i].size, resquery->bar_size[i]); } stq_p(&resquery->sdma, ZPCI_SDMA_ADDR); stq_p(&resquery->edma, ZPCI_EDMA_ADDR); stl_p(&resquery->fid, pbdev->fid); stw_p(&resquery->pchid, 0); stw_p(&resquery->ug, 1); stl_p(&resquery->uid, pbdev->fid); stw_p(&resquery->hdr.rsp, CLP_RC_OK); break; } case CLP_QUERY_PCI_FNGRP: { ClpRspQueryPciGrp *resgrp = (ClpRspQueryPciGrp *)resh; resgrp->fr = 1; stq_p(&resgrp->dasm, 0); stq_p(&resgrp->msia, ZPCI_MSI_ADDR); stw_p(&resgrp->mui, 0); stw_p(&resgrp->i, 128); resgrp->version = 0; stw_p(&resgrp->hdr.rsp, CLP_RC_OK); break; } default: DPRINTF("unknown clp command\n"); stw_p(&resh->rsp, CLP_RC_CMD); break; } out: if (s390_cpu_virt_mem_write(cpu, env->regs[r2], r2, buffer, req_len + res_len)) { return 0; } setcc(cpu, cc); return 0; }


static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; ADPCMDecodeContext *c = avctx->priv_data; ADPCMChannelStatus *cs; int n, m, channel, i; short *samples; int16_t **samples_p; int st; /* stereo */ int count1, count2; int nb_samples, coded_samples, ret; GetByteContext gb; bytestream2_init(&gb, buf, buf_size); nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples); if (nb_samples <= 0) { av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n"); return AVERROR_INVALIDDATA; } /* get output buffer */ c->frame.nb_samples = nb_samples; if ((ret = ff_get_buffer(avctx, &c->frame)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return ret; } samples = (short *)c->frame.data[0]; samples_p = (int16_t **)c->frame.extended_data; /* use coded_samples when applicable */ /* it is always <= nb_samples, so the output buffer will be large enough */ if (coded_samples) { if (coded_samples != nb_samples) av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n"); c->frame.nb_samples = nb_samples = coded_samples; } st = avctx->channels == 2 ? 1 : 0; switch(avctx->codec->id) { case AV_CODEC_ID_ADPCM_IMA_QT: /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples). Channel data is interleaved per-chunk. */ for (channel = 0; channel < avctx->channels; channel++) { int predictor; int step_index; cs = &(c->status[channel]); /* (pppppp) (piiiiiii) */ /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */ predictor = sign_extend(bytestream2_get_be16u(&gb), 16); step_index = predictor & 0x7F; predictor &= ~0x7F; if (cs->step_index == step_index) { int diff = predictor - cs->predictor; if (diff < 0) diff = - diff; if (diff > 0x7f) goto update; } else { update: cs->step_index = step_index; cs->predictor = predictor; } if (cs->step_index > 88u){ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n", channel, cs->step_index); return AVERROR_INVALIDDATA; } samples = samples_p[channel]; for (m = 0; m < 64; m += 2) { int byte = bytestream2_get_byteu(&gb); samples[m ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3); samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4 , 3); } } break; case AV_CODEC_ID_ADPCM_IMA_WAV: for(i=0; i<avctx->channels; i++){ cs = &(c->status[i]); cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16); cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); if (cs->step_index > 88u){ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n", i, cs->step_index); return AVERROR_INVALIDDATA; } } for (n = 0; n < (nb_samples - 1) / 8; n++) { for (i = 0; i < avctx->channels; i++) { cs = &c->status[i]; samples = &samples_p[i][1 + n * 8]; for (m = 0; m < 8; m += 2) { int v = bytestream2_get_byteu(&gb); samples[m ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3); samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4 , 3); } } } break; case AV_CODEC_ID_ADPCM_4XM: for (i = 0; i < avctx->channels; i++) c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); for (i = 0; i < avctx->channels; i++) { c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16); if (c->status[i].step_index > 88u) { av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n", i, c->status[i].step_index); return AVERROR_INVALIDDATA; } } for (i = 0; i < avctx->channels; i++) { samples = (int16_t *)c->frame.data[i]; cs = &c->status[i]; for (n = nb_samples >> 1; n > 0; n--) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4); *samples++ = adpcm_ima_expand_nibble(cs, v >> 4 , 4); } } break; case AV_CODEC_ID_ADPCM_MS: { int block_predictor; block_predictor = bytestream2_get_byteu(&gb); if (block_predictor > 6) { av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n", block_predictor); return AVERROR_INVALIDDATA; } c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor]; c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor]; if (st) { block_predictor = bytestream2_get_byteu(&gb); if (block_predictor > 6) { av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n", block_predictor); return AVERROR_INVALIDDATA; } c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor]; c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor]; } c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16); if (st){ c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16); } c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16); if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16); c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16); if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16); *samples++ = c->status[0].sample2; if (st) *samples++ = c->status[1].sample2; *samples++ = c->status[0].sample1; if (st) *samples++ = c->status[1].sample1; for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) { int byte = bytestream2_get_byteu(&gb); *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4 ); *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F); } break; } case AV_CODEC_ID_ADPCM_IMA_DK4: for (channel = 0; channel < avctx->channels; channel++) { cs = &c->status[channel]; cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16); cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); if (cs->step_index > 88u){ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n", channel, cs->step_index); return AVERROR_INVALIDDATA; } } for (n = nb_samples >> (1 - st); n > 0; n--) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3); *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3); } break; case AV_CODEC_ID_ADPCM_IMA_DK3: { int last_byte = 0; int nibble; int decode_top_nibble_next = 0; int diff_channel; const int16_t *samples_end = samples + avctx->channels * nb_samples; bytestream2_skipu(&gb, 10); c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); c->status[1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); c->status[0].step_index = bytestream2_get_byteu(&gb); c->status[1].step_index = bytestream2_get_byteu(&gb); if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n", c->status[0].step_index, c->status[1].step_index); return AVERROR_INVALIDDATA; } /* sign extend the predictors */ diff_channel = c->status[1].predictor; /* DK3 ADPCM support macro */ #define DK3_GET_NEXT_NIBBLE() \ if (decode_top_nibble_next) { \ nibble = last_byte >> 4; \ decode_top_nibble_next = 0; \ } else { \ last_byte = bytestream2_get_byteu(&gb); \ nibble = last_byte & 0x0F; \ decode_top_nibble_next = 1; \ } while (samples < samples_end) { /* for this algorithm, c->status[0] is the sum channel and * c->status[1] is the diff channel */ /* process the first predictor of the sum channel */ DK3_GET_NEXT_NIBBLE(); adpcm_ima_expand_nibble(&c->status[0], nibble, 3); /* process the diff channel predictor */ DK3_GET_NEXT_NIBBLE(); adpcm_ima_expand_nibble(&c->status[1], nibble, 3); /* process the first pair of stereo PCM samples */ diff_channel = (diff_channel + c->status[1].predictor) / 2; *samples++ = c->status[0].predictor + c->status[1].predictor; *samples++ = c->status[0].predictor - c->status[1].predictor; /* process the second predictor of the sum channel */ DK3_GET_NEXT_NIBBLE(); adpcm_ima_expand_nibble(&c->status[0], nibble, 3); /* process the second pair of stereo PCM samples */ diff_channel = (diff_channel + c->status[1].predictor) / 2; *samples++ = c->status[0].predictor + c->status[1].predictor; *samples++ = c->status[0].predictor - c->status[1].predictor; } break; } case AV_CODEC_ID_ADPCM_IMA_ISS: for (channel = 0; channel < avctx->channels; channel++) { cs = &c->status[channel]; cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16); cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16); if (cs->step_index > 88u){ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n", channel, cs->step_index); return AVERROR_INVALIDDATA; } } for (n = nb_samples >> (1 - st); n > 0; n--) { int v1, v2; int v = bytestream2_get_byteu(&gb); /* nibbles are swapped for mono */ if (st) { v1 = v >> 4; v2 = v & 0x0F; } else { v2 = v >> 4; v1 = v & 0x0F; } *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3); *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3); } break; case AV_CODEC_ID_ADPCM_IMA_APC: while (bytestream2_get_bytes_left(&gb) > 0) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3); *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3); } break; case AV_CODEC_ID_ADPCM_IMA_OKI: while (bytestream2_get_bytes_left(&gb) > 0) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0], v >> 4 ); *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F); } break; case AV_CODEC_ID_ADPCM_IMA_WS: if (c->vqa_version == 3) { for (channel = 0; channel < avctx->channels; channel++) { int16_t *smp = samples_p[channel]; for (n = nb_samples / 2; n > 0; n--) { int v = bytestream2_get_byteu(&gb); *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); } } } else { for (n = nb_samples / 2; n > 0; n--) { for (channel = 0; channel < avctx->channels; channel++) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); } samples += avctx->channels; } } bytestream2_seek(&gb, 0, SEEK_END); break; case AV_CODEC_ID_ADPCM_XA: { int16_t *out0 = samples_p[0]; int16_t *out1 = samples_p[1]; int samples_per_block = 28 * (3 - avctx->channels) * 4; int sample_offset = 0; while (bytestream2_get_bytes_left(&gb) >= 128) { if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb), &c->status[0], &c->status[1], avctx->channels, sample_offset)) < 0) return ret; bytestream2_skipu(&gb, 128); sample_offset += samples_per_block; } break; } case AV_CODEC_ID_ADPCM_IMA_EA_EACS: for (i=0; i<=st; i++) { c->status[i].step_index = bytestream2_get_le32u(&gb); if (c->status[i].step_index > 88u) { av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n", i, c->status[i].step_index); return AVERROR_INVALIDDATA; } } for (i=0; i<=st; i++) c->status[i].predictor = bytestream2_get_le32u(&gb); for (n = nb_samples >> (1 - st); n > 0; n--) { int byte = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 3); *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3); } break; case AV_CODEC_ID_ADPCM_IMA_EA_SEAD: for (n = nb_samples >> (1 - st); n > 0; n--) { int byte = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_expand_nibble(&c->status[0], byte >> 4, 6); *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6); } break; case AV_CODEC_ID_ADPCM_EA: { int previous_left_sample, previous_right_sample; int current_left_sample, current_right_sample; int next_left_sample, next_right_sample; int coeff1l, coeff2l, coeff1r, coeff2r; int shift_left, shift_right; /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces, each coding 28 stereo samples. */ if(avctx->channels != 2) return AVERROR_INVALIDDATA; current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16); previous_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16); current_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16); previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16); for (count1 = 0; count1 < nb_samples / 28; count1++) { int byte = bytestream2_get_byteu(&gb); coeff1l = ea_adpcm_table[ byte >> 4 ]; coeff2l = ea_adpcm_table[(byte >> 4 ) + 4]; coeff1r = ea_adpcm_table[ byte & 0x0F]; coeff2r = ea_adpcm_table[(byte & 0x0F) + 4]; byte = bytestream2_get_byteu(&gb); shift_left = 20 - (byte >> 4); shift_right = 20 - (byte & 0x0F); for (count2 = 0; count2 < 28; count2++) { byte = bytestream2_get_byteu(&gb); next_left_sample = sign_extend(byte >> 4, 4) << shift_left; next_right_sample = sign_extend(byte, 4) << shift_right; next_left_sample = (next_left_sample + (current_left_sample * coeff1l) + (previous_left_sample * coeff2l) + 0x80) >> 8; next_right_sample = (next_right_sample + (current_right_sample * coeff1r) + (previous_right_sample * coeff2r) + 0x80) >> 8; previous_left_sample = current_left_sample; current_left_sample = av_clip_int16(next_left_sample); previous_right_sample = current_right_sample; current_right_sample = av_clip_int16(next_right_sample); *samples++ = current_left_sample; *samples++ = current_right_sample; } } bytestream2_skip(&gb, 2); // Skip terminating 0x0000 break; } case AV_CODEC_ID_ADPCM_EA_MAXIS_XA: { int coeff[2][2], shift[2]; for(channel = 0; channel < avctx->channels; channel++) { int byte = bytestream2_get_byteu(&gb); for (i=0; i<2; i++) coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i]; shift[channel] = 20 - (byte & 0x0F); } for (count1 = 0; count1 < nb_samples / 2; count1++) { int byte[2]; byte[0] = bytestream2_get_byteu(&gb); if (st) byte[1] = bytestream2_get_byteu(&gb); for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */ for(channel = 0; channel < avctx->channels; channel++) { int sample = sign_extend(byte[channel] >> i, 4) << shift[channel]; sample = (sample + c->status[channel].sample1 * coeff[channel][0] + c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8; c->status[channel].sample2 = c->status[channel].sample1; c->status[channel].sample1 = av_clip_int16(sample); *samples++ = c->status[channel].sample1; } } } bytestream2_seek(&gb, 0, SEEK_END); break; } case AV_CODEC_ID_ADPCM_EA_R1: case AV_CODEC_ID_ADPCM_EA_R2: case AV_CODEC_ID_ADPCM_EA_R3: { /* channel numbering 2chan: 0=fl, 1=fr 4chan: 0=fl, 1=rl, 2=fr, 3=rr 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */ const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3; int previous_sample, current_sample, next_sample; int coeff1, coeff2; int shift; unsigned int channel; uint16_t *samplesC; int count = 0; int offsets[6]; for (channel=0; channel<avctx->channels; channel++) offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) : bytestream2_get_le32(&gb)) + (avctx->channels + 1) * 4; for (channel=0; channel<avctx->channels; channel++) { bytestream2_seek(&gb, offsets[channel], SEEK_SET); samplesC = samples_p[channel]; if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) { current_sample = sign_extend(bytestream2_get_le16(&gb), 16); previous_sample = sign_extend(bytestream2_get_le16(&gb), 16); } else { current_sample = c->status[channel].predictor; previous_sample = c->status[channel].prev_sample; } for (count1 = 0; count1 < nb_samples / 28; count1++) { int byte = bytestream2_get_byte(&gb); if (byte == 0xEE) { /* only seen in R2 and R3 */ current_sample = sign_extend(bytestream2_get_be16(&gb), 16); previous_sample = sign_extend(bytestream2_get_be16(&gb), 16); for (count2=0; count2<28; count2++) *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16); } else { coeff1 = ea_adpcm_table[ byte >> 4 ]; coeff2 = ea_adpcm_table[(byte >> 4) + 4]; shift = 20 - (byte & 0x0F); for (count2=0; count2<28; count2++) { if (count2 & 1) next_sample = sign_extend(byte, 4) << shift; else { byte = bytestream2_get_byte(&gb); next_sample = sign_extend(byte >> 4, 4) << shift; } next_sample += (current_sample * coeff1) + (previous_sample * coeff2); next_sample = av_clip_int16(next_sample >> 8); previous_sample = current_sample; current_sample = next_sample; *samplesC++ = current_sample; } } } if (!count) { count = count1; } else if (count != count1) { av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n"); count = FFMAX(count, count1); } if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) { c->status[channel].predictor = current_sample; c->status[channel].prev_sample = previous_sample; } } c->frame.nb_samples = count * 28; bytestream2_seek(&gb, 0, SEEK_END); break; } case AV_CODEC_ID_ADPCM_EA_XAS: for (channel=0; channel<avctx->channels; channel++) { int coeff[2][4], shift[4]; int16_t *s = samples_p[channel]; for (n = 0; n < 4; n++, s += 32) { int val = sign_extend(bytestream2_get_le16u(&gb), 16); for (i=0; i<2; i++) coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i]; s[0] = val & ~0x0F; val = sign_extend(bytestream2_get_le16u(&gb), 16); shift[n] = 20 - (val & 0x0F); s[1] = val & ~0x0F; } for (m=2; m<32; m+=2) { s = &samples_p[channel][m]; for (n = 0; n < 4; n++, s += 32) { int level, pred; int byte = bytestream2_get_byteu(&gb); level = sign_extend(byte >> 4, 4) << shift[n]; pred = s[-1] * coeff[0][n] + s[-2] * coeff[1][n]; s[0] = av_clip_int16((level + pred + 0x80) >> 8); level = sign_extend(byte, 4) << shift[n]; pred = s[0] * coeff[0][n] + s[-1] * coeff[1][n]; s[1] = av_clip_int16((level + pred + 0x80) >> 8); } } } break; case AV_CODEC_ID_ADPCM_IMA_AMV: c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16); c->status[0].step_index = bytestream2_get_le16u(&gb); bytestream2_skipu(&gb, 4); if (c->status[0].step_index > 88u) { av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", c->status[0].step_index); return AVERROR_INVALIDDATA; } for (n = nb_samples >> (1 - st); n > 0; n--) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3); *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3); } break; case AV_CODEC_ID_ADPCM_IMA_SMJPEG: for (i = 0; i < avctx->channels; i++) { c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16); c->status[i].step_index = bytestream2_get_byteu(&gb); bytestream2_skipu(&gb, 1); if (c->status[i].step_index > 88u) { av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", c->status[i].step_index); return AVERROR_INVALIDDATA; } } for (n = nb_samples >> (1 - st); n > 0; n--) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4, 3); *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf, 3); } break; case AV_CODEC_ID_ADPCM_CT: for (n = nb_samples >> (1 - st); n > 0; n--) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 ); *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F); } break; case AV_CODEC_ID_ADPCM_SBPRO_4: case AV_CODEC_ID_ADPCM_SBPRO_3: case AV_CODEC_ID_ADPCM_SBPRO_2: if (!c->status[0].step_index) { /* the first byte is a raw sample */ *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80); if (st) *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80); c->status[0].step_index = 1; nb_samples--; } if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) { for (n = nb_samples >> (1 - st); n > 0; n--) { int byte = bytestream2_get_byteu(&gb); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], byte >> 4, 4, 0); *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], byte & 0x0F, 4, 0); } } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) { for (n = nb_samples / 3; n > 0; n--) { int byte = bytestream2_get_byteu(&gb); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], byte >> 5 , 3, 0); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], (byte >> 2) & 0x07, 3, 0); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], byte & 0x03, 2, 0); } } else { for (n = nb_samples >> (2 - st); n > 0; n--) { int byte = bytestream2_get_byteu(&gb); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], byte >> 6 , 2, 2); *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], (byte >> 4) & 0x03, 2, 2); *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], (byte >> 2) & 0x03, 2, 2); *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], byte & 0x03, 2, 2); } } break; case AV_CODEC_ID_ADPCM_SWF: adpcm_swf_decode(avctx, buf, buf_size, samples); bytestream2_seek(&gb, 0, SEEK_END); break; case AV_CODEC_ID_ADPCM_YAMAHA: for (n = nb_samples >> (1 - st); n > 0; n--) { int v = bytestream2_get_byteu(&gb); *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F); *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 ); } break; case AV_CODEC_ID_ADPCM_AFC: { int samples_per_block; int blocks; if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) { samples_per_block = avctx->extradata[0] / 16; blocks = nb_samples / avctx->extradata[0]; } else { samples_per_block = nb_samples / 16; blocks = 1; } for (m = 0; m < blocks; m++) { for (channel = 0; channel < avctx->channels; channel++) { int prev1 = c->status[channel].sample1; int prev2 = c->status[channel].sample2; samples = samples_p[channel] + m * 16; /* Read in every sample for this channel. */ for (i = 0; i < samples_per_block; i++) { int byte = bytestream2_get_byteu(&gb); int scale = 1 << (byte >> 4); int index = byte & 0xf; int factor1 = ff_adpcm_afc_coeffs[0][index]; int factor2 = ff_adpcm_afc_coeffs[1][index]; /* Decode 16 samples. */ for (n = 0; n < 16; n++) { int32_t sampledat; if (n & 1) { sampledat = sign_extend(byte, 4); } else { byte = bytestream2_get_byteu(&gb); sampledat = sign_extend(byte >> 4, 4); } sampledat = ((prev1 * factor1 + prev2 * factor2) + ((sampledat * scale) << 11)) >> 11; *samples = av_clip_int16(sampledat); prev2 = prev1; prev1 = *samples++; } } c->status[channel].sample1 = prev1; c->status[channel].sample2 = prev2; } } bytestream2_seek(&gb, 0, SEEK_END); break; } case AV_CODEC_ID_ADPCM_THP: { int table[6][16]; int ch; for (i = 0; i < avctx->channels; i++) for (n = 0; n < 16; n++) table[i][n] = sign_extend(bytestream2_get_be16u(&gb), 16); /* Initialize the previous sample. */ for (i = 0; i < avctx->channels; i++) { c->status[i].sample1 = sign_extend(bytestream2_get_be16u(&gb), 16); c->status[i].sample2 = sign_extend(bytestream2_get_be16u(&gb), 16); } for (ch = 0; ch < avctx->channels; ch++) { samples = samples_p[ch]; /* Read in every sample for this channel. */ for (i = 0; i < nb_samples / 14; i++) { int byte = bytestream2_get_byteu(&gb); int index = (byte >> 4) & 7; unsigned int exp = byte & 0x0F; int factor1 = table[ch][index * 2]; int factor2 = table[ch][index * 2 + 1]; /* Decode 14 samples. */ for (n = 0; n < 14; n++) { int32_t sampledat; if (n & 1) { sampledat = sign_extend(byte, 4); } else { byte = bytestream2_get_byteu(&gb); sampledat = sign_extend(byte >> 4, 4); } sampledat = ((c->status[ch].sample1 * factor1 + c->status[ch].sample2 * factor2) >> 11) + (sampledat << exp); *samples = av_clip_int16(sampledat); c->status[ch].sample2 = c->status[ch].sample1; c->status[ch].sample1 = *samples++; } } } break; } default: return -1; } if (avpkt->size && bytestream2_tell(&gb) == 0) { av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n"); return AVERROR_INVALIDDATA; } *got_frame_ptr = 1; *(AVFrame *)data = c->frame; return bytestream2_tell(&gb); }


static void usbredir_interrupt_packet(void *priv, uint32_t id, struct usb_redir_interrupt_packet_header *interrupt_packet, uint8_t *data, int data_len) { USBRedirDevice *dev = priv; uint8_t ep = interrupt_packet->endpoint; DPRINTF("interrupt-in status %d ep %02X len %d id %u\n", interrupt_packet->status, ep, data_len, id); if (dev->endpoint[EP2I(ep)].type != USB_ENDPOINT_XFER_INT) { ERROR("received int packet for non interrupt endpoint %02X\n", ep); free(data); return; } if (ep & USB_DIR_IN) { if (dev->endpoint[EP2I(ep)].interrupt_started == 0) { DPRINTF("received int packet while not started ep %02X\n", ep); free(data); return; } /* bufp_alloc also adds the packet to the ep queue */ bufp_alloc(dev, data, data_len, interrupt_packet->status, ep); } else { int len = interrupt_packet->length; AsyncURB *aurb = async_find(dev, id); if (!aurb) { return; } if (aurb->interrupt_packet.endpoint != interrupt_packet->endpoint) { ERROR("return int packet mismatch, please report this!\n"); len = USB_RET_NAK; } if (aurb->packet) { aurb->packet->result = usbredir_handle_status(dev, interrupt_packet->status, len); usb_packet_complete(&dev->dev, aurb->packet); } async_free(dev, aurb); } }


static int coroutine_fn nfs_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *iov) { NFSClient *client = bs->opaque; NFSRPC task; nfs_co_init_task(client, &task); task.iov = iov; if (nfs_pread_async(client->context, client->fh, sector_num * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE, nfs_co_generic_cb, &task) != 0) { return -ENOMEM; } while (!task.complete) { nfs_set_events(client); qemu_coroutine_yield(); } if (task.ret < 0) { return task.ret; } /* zero pad short reads */ if (task.ret < iov->size) { qemu_iovec_memset(iov, task.ret, 0, iov->size - task.ret); } return 0; }


int scsi_req_parse(SCSIRequest *req, uint8_t *buf) { int rc; if (req->dev->type == TYPE_TAPE) { rc = scsi_req_stream_length(&req->cmd, req->dev, buf); } else { rc = scsi_req_length(&req->cmd, req->dev, buf); } if (rc != 0) return rc; assert(buf == req->cmd.buf); scsi_cmd_xfer_mode(&req->cmd); req->cmd.lba = scsi_cmd_lba(&req->cmd); trace_scsi_req_parsed(req->dev->id, req->lun, req->tag, buf[0], req->cmd.mode, req->cmd.xfer); if (req->cmd.lba != -1) { trace_scsi_req_parsed_lba(req->dev->id, req->lun, req->tag, buf[0], req->cmd.lba); } return 0; }


void virtqueue_map_sg(struct iovec *sg, hwaddr *addr, size_t num_sg, int is_write) { unsigned int i; hwaddr len; if (num_sg >= VIRTQUEUE_MAX_SIZE) { error_report("virtio: map attempt out of bounds: %zd > %d", num_sg, VIRTQUEUE_MAX_SIZE); exit(1); } for (i = 0; i < num_sg; i++) { len = sg[i].iov_len; sg[i].iov_base = cpu_physical_memory_map(addr[i], &len, is_write); if (sg[i].iov_base == NULL || len != sg[i].iov_len) { error_report("virtio: trying to map MMIO memory"); exit(1); } } }


static inline void gen_op_fcmpeq(int fccno) { switch (fccno) { case 0: gen_helper_fcmpeq(cpu_env); break; case 1: gen_helper_fcmpeq_fcc1(cpu_env); break; case 2: gen_helper_fcmpeq_fcc2(cpu_env); break; case 3: gen_helper_fcmpeq_fcc3(cpu_env); break; } }


static bool pc_machine_get_vmport(Object *obj, Error **errp) { PCMachineState *pcms = PC_MACHINE(obj); return pcms->vmport; }


pvscsi_convert_sglist(PVSCSIRequest *r) { int chunk_size; uint64_t data_length = r->req.dataLen; PVSCSISGState sg = r->sg; while (data_length) { while (!sg.resid) { pvscsi_get_next_sg_elem(&sg); trace_pvscsi_convert_sglist(r->req.context, r->sg.dataAddr, r->sg.resid); } assert(data_length > 0); chunk_size = MIN((unsigned) data_length, sg.resid); if (chunk_size) { qemu_sglist_add(&r->sgl, sg.dataAddr, chunk_size); } sg.dataAddr += chunk_size; data_length -= chunk_size; sg.resid -= chunk_size; } }


static void av_estimate_timings_from_pts(AVFormatContext *ic) { AVPacket pkt1, *pkt = &pkt1; AVStream *st; int read_size, i, ret; int64_t start_time, end_time, end_time1; int64_t filesize, offset, duration; /* we read the first packets to get the first PTS (not fully accurate, but it is enough now) */ url_fseek(&ic->pb, 0, SEEK_SET); read_size = 0; for(;;) { if (read_size >= DURATION_MAX_READ_SIZE) break; /* if all info is available, we can stop */ for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time == AV_NOPTS_VALUE) break; } if (i == ic->nb_streams) break; ret = av_read_packet(ic, pkt); if (ret != 0) break; read_size += pkt->size; st = ic->streams[pkt->stream_index]; if (pkt->pts != AV_NOPTS_VALUE) { if (st->start_time == AV_NOPTS_VALUE) st->start_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den); } av_free_packet(pkt); } /* we compute the minimum start_time and use it as default */ start_time = MAXINT64; for(i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time != AV_NOPTS_VALUE && st->start_time < start_time) start_time = st->start_time; } fprintf(stderr, "start=%lld\n", start_time); if (start_time != MAXINT64) ic->start_time = start_time; /* estimate the end time (duration) */ /* XXX: may need to support wrapping */ filesize = ic->file_size; offset = filesize - DURATION_MAX_READ_SIZE; if (offset < 0) offset = 0; /* flush packet queue */ flush_packet_queue(ic); url_fseek(&ic->pb, offset, SEEK_SET); read_size = 0; for(;;) { if (read_size >= DURATION_MAX_READ_SIZE) break; /* if all info is available, we can stop */ for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->duration == AV_NOPTS_VALUE) break; } if (i == ic->nb_streams) break; ret = av_read_packet(ic, pkt); if (ret != 0) break; read_size += pkt->size; st = ic->streams[pkt->stream_index]; if (pkt->pts != AV_NOPTS_VALUE) { end_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den); duration = end_time - st->start_time; if (duration > 0) { if (st->duration == AV_NOPTS_VALUE || st->duration < duration) st->duration = duration; } } av_free_packet(pkt); } /* estimate total duration */ end_time = MININT64; for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->duration != AV_NOPTS_VALUE) { end_time1 = st->start_time + st->duration; if (end_time1 > end_time) end_time = end_time1; } } /* update start_time (new stream may have been created, so we do it at the end */ if (ic->start_time != AV_NOPTS_VALUE) { for(i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->start_time == AV_NOPTS_VALUE) st->start_time = ic->start_time; } } if (end_time != MININT64) { /* put dummy values for duration if needed */ for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; if (st->duration == AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE) st->duration = end_time - st->start_time; } ic->duration = end_time - ic->start_time; } url_fseek(&ic->pb, 0, SEEK_SET); }


bool qemu_clock_run_all_timers(void) { bool progress = false; QEMUClockType type; for (type = 0; type < QEMU_CLOCK_MAX; type++) { progress |= qemu_clock_run_timers(type); } return progress; }


static int put_uint64_as_uint32(QEMUFile *f, void *pv, size_t size, VMStateField *field, QJSON *vmdesc) { uint64_t *v = pv; qemu_put_be32(f, *v); return 0; }


static void scsi_dma_restart_bh(void *opaque) { SCSIDevice *s = opaque; SCSIRequest *req, *next; qemu_bh_delete(s->bh); s->bh = NULL; QTAILQ_FOREACH_SAFE(req, &s->requests, next, next) { scsi_req_ref(req); if (req->retry) { req->retry = false; switch (req->cmd.mode) { case SCSI_XFER_FROM_DEV: case SCSI_XFER_TO_DEV: scsi_req_continue(req); break; case SCSI_XFER_NONE: assert(!req->sg); scsi_req_dequeue(req); scsi_req_enqueue(req); break; } } scsi_req_unref(req); } }


static uint64_t get_guest_rtc_ns(RTCState *s) { uint64_t guest_rtc; uint64_t guest_clock = qemu_clock_get_ns(rtc_clock); guest_rtc = s->base_rtc * NANOSECONDS_PER_SECOND + guest_clock - s->last_update + s->offset; return guest_rtc; }


static void openpic_reset(DeviceState *d) { OpenPICState *opp = FROM_SYSBUS(typeof (*opp), sysbus_from_qdev(d)); int i; opp->glbc = GLBC_RESET; /* Initialise controller registers */ opp->frep = ((opp->nb_irqs -1) << FREP_NIRQ_SHIFT) | ((opp->nb_cpus -1) << FREP_NCPU_SHIFT) | (opp->vid << FREP_VID_SHIFT); opp->pint = 0; opp->spve = -1 & opp->spve_mask; opp->tifr = opp->tifr_reset; /* Initialise IRQ sources */ for (i = 0; i < opp->max_irq; i++) { opp->src[i].ipvp = opp->ipvp_reset; opp->src[i].ide = opp->ide_reset; } /* Initialise IRQ destinations */ for (i = 0; i < MAX_CPU; i++) { opp->dst[i].pctp = 15; opp->dst[i].pcsr = 0x00000000; memset(&opp->dst[i].raised, 0, sizeof(IRQ_queue_t)); opp->dst[i].raised.next = -1; memset(&opp->dst[i].servicing, 0, sizeof(IRQ_queue_t)); opp->dst[i].servicing.next = -1; } /* Initialise timers */ for (i = 0; i < MAX_TMR; i++) { opp->timers[i].ticc = 0; opp->timers[i].tibc = TIBC_CI; } /* Go out of RESET state */ opp->glbc = 0; }


static inline int handle_cpu_signal(unsigned long pc, unsigned long address, int is_write, sigset_t *old_set, void *puc) { TranslationBlock *tb; int ret; if (cpu_single_env) env = cpu_single_env; /* XXX: find a correct solution for multithread */ #if defined(DEBUG_SIGNAL) printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n", pc, address, is_write, *(unsigned long *)old_set); #endif /* XXX: locking issue */ if (is_write && page_unprotect(h2g(address), pc, puc)) { return 1; } /* see if it is an MMU fault */ ret = cpu_mb_handle_mmu_fault(env, address, is_write, MMU_USER_IDX, 0); if (ret < 0) return 0; /* not an MMU fault */ if (ret == 0) return 1; /* the MMU fault was handled without causing real CPU fault */ /* now we have a real cpu fault */ tb = tb_find_pc(pc); if (tb) { /* the PC is inside the translated code. It means that we have a virtual CPU fault */ cpu_restore_state(tb, env, pc, puc); } if (ret == 1) { #if 0 printf("PF exception: PC=0x" TARGET_FMT_lx " error=0x%x %p\n", env->PC, env->error_code, tb); #endif /* we restore the process signal mask as the sigreturn should do it (XXX: use sigsetjmp) */ sigprocmask(SIG_SETMASK, old_set, NULL); cpu_loop_exit(); } else { /* activate soft MMU for this block */ cpu_resume_from_signal(env, puc); } /* never comes here */ return 1; }


static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb) { H264PredWeightTable pwt; int slice_type_nos = s->pict_type & 3; H264ParseContext *p = s->priv_data; H264Context *h = &p->h; int list_count, ref_count[2]; if (h->pps.redundant_pic_cnt_present) get_ue_golomb(gb); // redundant_pic_count if (slice_type_nos == AV_PICTURE_TYPE_B) get_bits1(gb); // direct_spatial_mv_pred if (ff_h264_parse_ref_count(&list_count, ref_count, gb, &h->pps, slice_type_nos, h->picture_structure) < 0) return AVERROR_INVALIDDATA; if (slice_type_nos != AV_PICTURE_TYPE_I) { int list; for (list = 0; list < list_count; list++) { if (get_bits1(gb)) { int index; for (index = 0; ; index++) { unsigned int reordering_of_pic_nums_idc = get_ue_golomb_31(gb); if (reordering_of_pic_nums_idc < 3) get_ue_golomb(gb); else if (reordering_of_pic_nums_idc > 3) { av_log(h->avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc %d\n", reordering_of_pic_nums_idc); return AVERROR_INVALIDDATA; } else break; if (index >= ref_count[list]) { av_log(h->avctx, AV_LOG_ERROR, "reference count %d overflow\n", index); return AVERROR_INVALIDDATA; } } } } } if ((h->pps.weighted_pred && slice_type_nos == AV_PICTURE_TYPE_P) || (h->pps.weighted_bipred_idc == 1 && slice_type_nos == AV_PICTURE_TYPE_B)) ff_h264_pred_weight_table(gb, &h->sps, ref_count, slice_type_nos, &pwt); if (get_bits1(gb)) { // adaptive_ref_pic_marking_mode_flag int i; for (i = 0; i < MAX_MMCO_COUNT; i++) { MMCOOpcode opcode = get_ue_golomb_31(gb); if (opcode > (unsigned) MMCO_LONG) { av_log(h->avctx, AV_LOG_ERROR, "illegal memory management control operation %d\n", opcode); return AVERROR_INVALIDDATA; } if (opcode == MMCO_END) return 0; else if (opcode == MMCO_RESET) return 1; if (opcode == MMCO_SHORT2UNUSED || opcode == MMCO_SHORT2LONG) get_ue_golomb(gb); if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED || opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG) get_ue_golomb_31(gb); } } return 0; }


void helper_memalign(uint32_t addr, uint32_t dr, uint32_t wr, uint32_t size) { uint32_t mask; switch (size) { case 4: mask = 3; break; case 2: mask = 1; break; default: case 1: mask = 0; break; } if (addr & mask) { qemu_log("unaligned access addr=%x size=%d, wr=%d\n", addr, size, wr); if (!(env->sregs[SR_MSR] & MSR_EE)) { return; } env->sregs[SR_ESR] = ESR_EC_UNALIGNED_DATA | (wr << 10) \ | (dr & 31) << 5; if (size == 4) { env->sregs[SR_ESR] |= 1 << 11; } helper_raise_exception(EXCP_HW_EXCP); } }


static inline bool bdrv_req_is_aligned(BlockDriverState *bs, int64_t offset, size_t bytes) { int64_t align = bdrv_get_align(bs); return !(offset & (align - 1) || (bytes & (align - 1))); }


static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf, long search_pc) { int opc, op_index, macro_op_index; const TCGOpDef *def; unsigned int dead_iargs; const TCGArg *args; #ifdef DEBUG_DISAS if (unlikely(loglevel & CPU_LOG_TB_OP)) { fprintf(logfile, "OP:\n"); tcg_dump_ops(s, logfile); fprintf(logfile, "\n"); } #endif tcg_liveness_analysis(s); #ifdef DEBUG_DISAS if (unlikely(loglevel & CPU_LOG_TB_OP_OPT)) { fprintf(logfile, "OP after la:\n"); tcg_dump_ops(s, logfile); fprintf(logfile, "\n"); } #endif tcg_reg_alloc_start(s); s->code_buf = gen_code_buf; s->code_ptr = gen_code_buf; macro_op_index = -1; args = gen_opparam_buf; op_index = 0; for(;;) { opc = gen_opc_buf[op_index]; #ifdef CONFIG_PROFILER dyngen_table_op_count[opc]++; #endif def = &tcg_op_defs[opc]; #if 0 printf("%s: %d %d %d\n", def->name, def->nb_oargs, def->nb_iargs, def->nb_cargs); // dump_regs(s); #endif switch(opc) { case INDEX_op_mov_i32: #if TCG_TARGET_REG_BITS == 64 case INDEX_op_mov_i64: #endif dead_iargs = s->op_dead_iargs[op_index]; tcg_reg_alloc_mov(s, def, args, dead_iargs); break; case INDEX_op_nop: case INDEX_op_nop1: case INDEX_op_nop2: case INDEX_op_nop3: break; case INDEX_op_nopn: args += args[0]; goto next; case INDEX_op_discard: { TCGTemp *ts; ts = &s->temps[args[0]]; /* mark the temporary as dead */ if (ts->val_type != TEMP_VAL_CONST && !ts->fixed_reg) { if (ts->val_type == TEMP_VAL_REG) s->reg_to_temp[ts->reg] = -1; ts->val_type = TEMP_VAL_DEAD; } } break; case INDEX_op_macro_goto: macro_op_index = op_index; /* only used for exceptions */ op_index = args[0] - 1; args = gen_opparam_buf + args[1]; goto next; case INDEX_op_macro_end: macro_op_index = -1; /* only used for exceptions */ op_index = args[0] - 1; args = gen_opparam_buf + args[1]; goto next; case INDEX_op_macro_start: /* must never happen here */ tcg_abort(); case INDEX_op_set_label: tcg_reg_alloc_bb_end(s); tcg_out_label(s, args[0], (long)s->code_ptr); break; case INDEX_op_call: dead_iargs = s->op_dead_iargs[op_index]; args += tcg_reg_alloc_call(s, def, opc, args, dead_iargs); goto next; case INDEX_op_end: goto the_end; #ifndef CONFIG_NO_DYNGEN_OP case 0 ... INDEX_op_end - 1: /* legacy dyngen ops */ #ifdef CONFIG_PROFILER { extern int64_t dyngen_old_op_count; dyngen_old_op_count++; } #endif tcg_reg_alloc_bb_end(s); if (search_pc >= 0) { s->code_ptr += def->copy_size; args += def->nb_args; } else { args = dyngen_op(s, opc, args); } goto next; #endif default: /* Note: in order to speed up the code, it would be much faster to have specialized register allocator functions for some common argument patterns */ dead_iargs = s->op_dead_iargs[op_index]; tcg_reg_alloc_op(s, def, opc, args, dead_iargs); break; } args += def->nb_args; next: ; if (search_pc >= 0 && search_pc < s->code_ptr - gen_code_buf) { if (macro_op_index >= 0) return macro_op_index; else return op_index; } op_index++; #ifndef NDEBUG check_regs(s); #endif } the_end: return -1; }


static uint32_t set_isolation_state(sPAPRDRConnector *drc, sPAPRDRIsolationState state) { trace_spapr_drc_set_isolation_state(spapr_drc_index(drc), state); /* if the guest is configuring a device attached to this DRC, we * should reset the configuration state at this point since it may * no longer be reliable (guest released device and needs to start * over, or unplug occurred so the FDT is no longer valid) */ if (state == SPAPR_DR_ISOLATION_STATE_ISOLATED) { g_free(drc->ccs); drc->ccs = NULL; } if (state == SPAPR_DR_ISOLATION_STATE_UNISOLATED) { /* cannot unisolate a non-existent resource, and, or resources * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, 13.5.3.5) */ if (!drc->dev || drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { return RTAS_OUT_NO_SUCH_INDICATOR; } } /* * Fail any requests to ISOLATE the LMB DRC if this LMB doesn't * belong to a DIMM device that is marked for removal. * * Currently the guest userspace tool drmgr that drives the memory * hotplug/unplug will just try to remove a set of 'removable' LMBs * in response to a hot unplug request that is based on drc-count. * If the LMB being removed doesn't belong to a DIMM device that is * actually being unplugged, fail the isolation request here. */ if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_LMB) { if ((state == SPAPR_DR_ISOLATION_STATE_ISOLATED) && !drc->awaiting_release) { return RTAS_OUT_HW_ERROR; } } drc->isolation_state = state; if (drc->isolation_state == SPAPR_DR_ISOLATION_STATE_ISOLATED) { /* if we're awaiting release, but still in an unconfigured state, * it's likely the guest is still in the process of configuring * the device and is transitioning the devices to an ISOLATED * state as a part of that process. so we only complete the * removal when this transition happens for a device in a * configured state, as suggested by the state diagram from * PAPR+ 2.7, 13.4 */ if (drc->awaiting_release) { uint32_t drc_index = spapr_drc_index(drc); if (drc->configured) { trace_spapr_drc_set_isolation_state_finalizing(drc_index); spapr_drc_detach(drc, DEVICE(drc->dev), NULL); } else { trace_spapr_drc_set_isolation_state_deferring(drc_index); } } drc->configured = false; } return RTAS_OUT_SUCCESS; }


static void vnc_listen_read(void *opaque) { VncDisplay *vs = opaque; struct sockaddr_in addr; socklen_t addrlen = sizeof(addr); /* Catch-up */ vga_hw_update(); int csock = accept(vs->lsock, (struct sockaddr *)&addr, &addrlen); if (csock != -1) { vnc_connect(vs, csock); } }


static av_cold int qdm2_decode_init(AVCodecContext *avctx) { QDM2Context *s = avctx->priv_data; uint8_t *extradata; int extradata_size; int tmp_val, tmp, size; /* extradata parsing Structure: wave { frma (QDM2) QDCA QDCP } 32 size (including this field) 32 tag (=frma) 32 type (=QDM2 or QDMC) 32 size (including this field, in bytes) 32 tag (=QDCA) // maybe mandatory parameters 32 unknown (=1) 32 channels (=2) 32 samplerate (=44100) 32 bitrate (=96000) 32 block size (=4096) 32 frame size (=256) (for one channel) 32 packet size (=1300) 32 size (including this field, in bytes) 32 tag (=QDCP) // maybe some tuneable parameters 32 float1 (=1.0) 32 zero ? 32 float2 (=1.0) 32 float3 (=1.0) 32 unknown (27) 32 unknown (8) 32 zero ? */ if (!avctx->extradata || (avctx->extradata_size < 48)) { av_log(avctx, AV_LOG_ERROR, "extradata missing or truncated\n"); return -1; } extradata = avctx->extradata; extradata_size = avctx->extradata_size; while (extradata_size > 7) { if (!memcmp(extradata, "frmaQDM", 7)) break; extradata++; extradata_size--; } if (extradata_size < 12) { av_log(avctx, AV_LOG_ERROR, "not enough extradata (%i)\n", extradata_size); return -1; } if (memcmp(extradata, "frmaQDM", 7)) { av_log(avctx, AV_LOG_ERROR, "invalid headers, QDM? not found\n"); return -1; } if (extradata[7] == 'C') { // s->is_qdmc = 1; av_log(avctx, AV_LOG_ERROR, "stream is QDMC version 1, which is not supported\n"); return -1; } extradata += 8; extradata_size -= 8; size = AV_RB32(extradata); if(size > extradata_size){ av_log(avctx, AV_LOG_ERROR, "extradata size too small, %i < %i\n", extradata_size, size); return -1; } extradata += 4; av_log(avctx, AV_LOG_DEBUG, "size: %d\n", size); if (AV_RB32(extradata) != MKBETAG('Q','D','C','A')) { av_log(avctx, AV_LOG_ERROR, "invalid extradata, expecting QDCA\n"); return -1; } extradata += 8; avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata); extradata += 4; if (s->channels > MPA_MAX_CHANNELS) return AVERROR_INVALIDDATA; avctx->sample_rate = AV_RB32(extradata); extradata += 4; avctx->bit_rate = AV_RB32(extradata); extradata += 4; s->group_size = AV_RB32(extradata); extradata += 4; s->fft_size = AV_RB32(extradata); extradata += 4; s->checksum_size = AV_RB32(extradata); if (s->checksum_size >= 1U << 28) { av_log(avctx, AV_LOG_ERROR, "data block size too large (%u)\n", s->checksum_size); return AVERROR_INVALIDDATA; } s->fft_order = av_log2(s->fft_size) + 1; s->fft_frame_size = 2 * s->fft_size; // complex has two floats // something like max decodable tones s->group_order = av_log2(s->group_size) + 1; s->frame_size = s->group_size / 16; // 16 iterations per super block if (s->frame_size > QDM2_MAX_FRAME_SIZE) return AVERROR_INVALIDDATA; s->sub_sampling = s->fft_order - 7; s->frequency_range = 255 / (1 << (2 - s->sub_sampling)); switch ((s->sub_sampling * 2 + s->channels - 1)) { case 0: tmp = 40; break; case 1: tmp = 48; break; case 2: tmp = 56; break; case 3: tmp = 72; break; case 4: tmp = 80; break; case 5: tmp = 100;break; default: tmp=s->sub_sampling; break; } tmp_val = 0; if ((tmp * 1000) < avctx->bit_rate) tmp_val = 1; if ((tmp * 1440) < avctx->bit_rate) tmp_val = 2; if ((tmp * 1760) < avctx->bit_rate) tmp_val = 3; if ((tmp * 2240) < avctx->bit_rate) tmp_val = 4; s->cm_table_select = tmp_val; if (s->sub_sampling == 0) tmp = 7999; else tmp = ((-(s->sub_sampling -1)) & 8000) + 20000; /* 0: 7999 -> 0 1: 20000 -> 2 2: 28000 -> 2 */ if (tmp < 8000) s->coeff_per_sb_select = 0; else if (tmp <= 16000) s->coeff_per_sb_select = 1; else s->coeff_per_sb_select = 2; // Fail on unknown fft order if ((s->fft_order < 7) || (s->fft_order > 9)) { av_log(avctx, AV_LOG_ERROR, "Unknown FFT order (%d), contact the developers!\n", s->fft_order); return -1; } ff_rdft_init(&s->rdft_ctx, s->fft_order, IDFT_C2R); ff_mpadsp_init(&s->mpadsp); qdm2_init(s); avctx->sample_fmt = AV_SAMPLE_FMT_S16; avcodec_get_frame_defaults(&s->frame); avctx->coded_frame = &s->frame; // dump_context(s); return 0; }


void MPV_frame_end(MpegEncContext *s) { /* draw edge for correct motion prediction if outside */ if (s->pict_type != B_TYPE && !s->intra_only) { if(s->avctx==NULL || s->avctx->codec->id!=CODEC_ID_MPEG4 || s->divx_version==500){ draw_edges(s->current_picture[0], s->linesize, s->mb_width*16, s->mb_height*16, EDGE_WIDTH); draw_edges(s->current_picture[1], s->linesize/2, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); draw_edges(s->current_picture[2], s->linesize/2, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); }else{ /* mpeg4? / opendivx / xvid */ draw_edges(s->current_picture[0], s->linesize, s->width, s->height, EDGE_WIDTH); draw_edges(s->current_picture[1], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2); draw_edges(s->current_picture[2], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2); } } emms_c(); if(s->pict_type!=B_TYPE){ s->last_non_b_pict_type= s->pict_type; s->last_non_b_qscale= s->qscale; s->last_non_b_mc_mb_var= s->mc_mb_var; s->num_available_buffers++; if(s->num_available_buffers>2) s->num_available_buffers= 2; } }


void qmp_memchar_write(const char *device, int64_t size, const char *data, bool has_format, enum DataFormat format, Error **errp) { CharDriverState *chr; guchar *write_data; int ret; gsize write_count; chr = qemu_chr_find(device); if (!chr) { error_set(errp, QERR_DEVICE_NOT_FOUND, device); return; } if (qemu_is_chr(chr, "memory")) { error_setg(errp,"%s is not memory char device", device); return; } write_count = (gsize)size; if (has_format && (format == DATA_FORMAT_BASE64)) { write_data = g_base64_decode(data, &write_count); } else { write_data = (uint8_t *)data; } ret = cirmem_chr_write(chr, write_data, write_count); if (ret < 0) { error_setg(errp, "Failed to write to device %s", device); return; } }


kern_return_t GetBSDPath( io_iterator_t mediaIterator, char *bsdPath, CFIndex maxPathSize ) { io_object_t nextMedia; kern_return_t kernResult = KERN_FAILURE; *bsdPath = '\0'; nextMedia = IOIteratorNext( mediaIterator ); if ( nextMedia ) { CFTypeRef bsdPathAsCFString; bsdPathAsCFString = IORegistryEntryCreateCFProperty( nextMedia, CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, 0 ); if ( bsdPathAsCFString ) { size_t devPathLength; strcpy( bsdPath, _PATH_DEV ); strcat( bsdPath, "r" ); devPathLength = strlen( bsdPath ); if ( CFStringGetCString( bsdPathAsCFString, bsdPath + devPathLength, maxPathSize - devPathLength, kCFStringEncodingASCII ) ) { kernResult = KERN_SUCCESS; } CFRelease( bsdPathAsCFString ); } IOObjectRelease( nextMedia ); } return kernResult; }


static void host_x86_cpu_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); X86CPUClass *xcc = X86_CPU_CLASS(oc); uint32_t eax = 0, ebx = 0, ecx = 0, edx = 0; xcc->kvm_required = true; host_cpuid(0x0, 0, &eax, &ebx, &ecx, &edx); x86_cpu_vendor_words2str(host_cpudef.vendor, ebx, edx, ecx); host_cpuid(0x1, 0, &eax, &ebx, &ecx, &edx); host_cpudef.family = ((eax >> 8) & 0x0F) + ((eax >> 20) & 0xFF); host_cpudef.model = ((eax >> 4) & 0x0F) | ((eax & 0xF0000) >> 12); host_cpudef.stepping = eax & 0x0F; cpu_x86_fill_model_id(host_cpudef.model_id); xcc->cpu_def = &host_cpudef; host_cpudef.cache_info_passthrough = true; /* level, xlevel, xlevel2, and the feature words are initialized on * instance_init, because they require KVM to be initialized. */ dc->props = host_x86_cpu_properties; }


int ff_http_do_new_request(URLContext *h, const char *uri) { HTTPContext *s = h->priv_data; AVDictionary *options = NULL; int ret; ret = http_shutdown(h, h->flags); if (ret < 0) return ret; s->end_chunked_post = 0; s->chunkend = 0; s->off = 0; s->icy_data_read = 0; av_free(s->location); s->location = av_strdup(uri); if (!s->location) return AVERROR(ENOMEM); ret = http_open_cnx(h, &options); av_dict_free(&options); return ret;


uint_fast16_t float32_to_uint16_round_to_zero(float32 a STATUS_PARAM) { int64_t v; uint_fast16_t res; v = float32_to_int64_round_to_zero(a STATUS_VAR); if (v < 0) { res = 0; float_raise( float_flag_invalid STATUS_VAR); } else if (v > 0xffff) { res = 0xffff; float_raise( float_flag_invalid STATUS_VAR); } else { res = v; } return res; }


static int hda_codec_dev_init(DeviceState *qdev, DeviceInfo *base) { HDACodecBus *bus = DO_UPCAST(HDACodecBus, qbus, qdev->parent_bus); HDACodecDevice *dev = DO_UPCAST(HDACodecDevice, qdev, qdev); HDACodecDeviceInfo *info = DO_UPCAST(HDACodecDeviceInfo, qdev, base); dev->info = info; if (dev->cad == -1) { dev->cad = bus->next_cad; } if (dev->cad > 15) return -1; bus->next_cad = dev->cad + 1; return info->init(dev); }


static void setup_frame_v1(int usig, struct target_sigaction *ka, target_sigset_t *set, CPUARMState *regs) { struct sigframe_v1 *frame; abi_ulong frame_addr = get_sigframe(ka, regs, sizeof(*frame)); int i; if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) return; setup_sigcontext(&frame->sc, regs, set->sig[0]); for(i = 1; i < TARGET_NSIG_WORDS; i++) { if (__put_user(set->sig[i], &frame->extramask[i - 1])) goto end; } setup_return(regs, ka, &frame->retcode, frame_addr, usig, frame_addr + offsetof(struct sigframe_v1, retcode)); end: unlock_user_struct(frame, frame_addr, 1); }


qcrypto_tls_creds_x509_init(Object *obj) { object_property_add_bool(obj, "loaded", qcrypto_tls_creds_x509_prop_get_loaded, qcrypto_tls_creds_x509_prop_set_loaded, }


int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset, int n_start, int n_end, int *num, uint64_t *host_offset, QCowL2Meta **m) { BDRVQcowState *s = bs->opaque; uint64_t start, remaining; uint64_t cluster_offset; uint64_t cur_bytes; int ret; trace_qcow2_alloc_clusters_offset(qemu_coroutine_self(), offset, n_start, n_end); assert(n_start * BDRV_SECTOR_SIZE == offset_into_cluster(s, offset)); offset = start_of_cluster(s, offset); again: start = offset + (n_start << BDRV_SECTOR_BITS); remaining = (n_end - n_start) << BDRV_SECTOR_BITS; cluster_offset = 0; *host_offset = 0; while (true) { /* * Now start gathering as many contiguous clusters as possible: * * 1. Check for overlaps with in-flight allocations * * a) Overlap not in the first cluster -> shorten this request and * let the caller handle the rest in its next loop iteration. * * b) Real overlaps of two requests. Yield and restart the search * for contiguous clusters (the situation could have changed * while we were sleeping) * * c) TODO: Request starts in the same cluster as the in-flight * allocation ends. Shorten the COW of the in-fight allocation, * set cluster_offset to write to the same cluster and set up * the right synchronisation between the in-flight request and * the new one. */ cur_bytes = remaining; ret = handle_dependencies(bs, start, &cur_bytes); if (ret == -EAGAIN) { goto again; } else if (ret < 0) { return ret; } else { /* handle_dependencies() may have decreased cur_bytes (shortened * the allocations below) so that the next dependency is processed * correctly during the next loop iteration. */ } /* * 2. Count contiguous COPIED clusters. */ ret = handle_copied(bs, start, &cluster_offset, &cur_bytes, m); if (ret < 0) { return ret; } else if (ret) { if (!*host_offset) { *host_offset = start_of_cluster(s, cluster_offset); } start += cur_bytes; remaining -= cur_bytes; cluster_offset += cur_bytes; cur_bytes = remaining; } else if (cur_bytes == 0) { break; } /* If there is something left to allocate, do that now */ if (remaining == 0) { break; } /* * 3. If the request still hasn't completed, allocate new clusters, * considering any cluster_offset of steps 1c or 2. */ ret = handle_alloc(bs, start, &cluster_offset, &cur_bytes, m); if (ret < 0) { return ret; } else if (ret) { if (!*host_offset) { *host_offset = start_of_cluster(s, cluster_offset); } start += cur_bytes; remaining -= cur_bytes; cluster_offset += cur_bytes; break; } else { assert(cur_bytes == 0); break; } } *num = (n_end - n_start) - (remaining >> BDRV_SECTOR_BITS); assert(*num > 0); assert(*host_offset != 0); return 0; }


static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int flags) { PerThreadContext *p = avctx->thread_opaque; int err; f->owner = avctx; ff_init_buffer_info(avctx, f->f); if (!(avctx->active_thread_type & FF_THREAD_FRAME)) return ff_get_buffer(avctx, f->f, flags); if (p->state != STATE_SETTING_UP && (avctx->codec->update_thread_context || (!avctx->thread_safe_callbacks && avctx->get_buffer != avcodec_default_get_buffer))) { av_log(avctx, AV_LOG_ERROR, "get_buffer() cannot be called after ff_thread_finish_setup()\n"); return -1; } if (avctx->internal->allocate_progress) { int *progress; f->progress = av_buffer_alloc(2 * sizeof(int)); if (!f->progress) { return AVERROR(ENOMEM); } progress = (int*)f->progress->data; progress[0] = progress[1] = -1; } pthread_mutex_lock(&p->parent->buffer_mutex); if (avctx->thread_safe_callbacks || ( #if FF_API_GET_BUFFER !avctx->get_buffer && #endif avctx->get_buffer2 == avcodec_default_get_buffer2)) { err = ff_get_buffer(avctx, f->f, flags); } else { pthread_mutex_lock(&p->progress_mutex); p->requested_frame = f->f; p->requested_flags = flags; p->state = STATE_GET_BUFFER; pthread_cond_broadcast(&p->progress_cond); while (p->state != STATE_SETTING_UP) pthread_cond_wait(&p->progress_cond, &p->progress_mutex); err = p->result; pthread_mutex_unlock(&p->progress_mutex); if (!avctx->codec->update_thread_context) ff_thread_finish_setup(avctx); } if (err) av_buffer_unref(&f->progress); pthread_mutex_unlock(&p->parent->buffer_mutex); return err; }


static void xio3130_downstream_realize(PCIDevice *d, Error **errp) { PCIEPort *p = PCIE_PORT(d); PCIESlot *s = PCIE_SLOT(d); int rc; pci_bridge_initfn(d, TYPE_PCIE_BUS); pcie_port_init_reg(d); rc = msi_init(d, XIO3130_MSI_OFFSET, XIO3130_MSI_NR_VECTOR, XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT, XIO3130_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT, errp); if (rc < 0) { assert(rc == -ENOTSUP); goto err_bridge; } rc = pci_bridge_ssvid_init(d, XIO3130_SSVID_OFFSET, XIO3130_SSVID_SVID, XIO3130_SSVID_SSID, errp); if (rc < 0) { goto err_bridge; } rc = pcie_cap_init(d, XIO3130_EXP_OFFSET, PCI_EXP_TYPE_DOWNSTREAM, p->port, errp); if (rc < 0) { goto err_msi; } pcie_cap_flr_init(d); pcie_cap_deverr_init(d); pcie_cap_slot_init(d, s->slot); pcie_cap_arifwd_init(d); pcie_chassis_create(s->chassis); rc = pcie_chassis_add_slot(s); if (rc < 0) { goto err_pcie_cap; } rc = pcie_aer_init(d, PCI_ERR_VER, XIO3130_AER_OFFSET, PCI_ERR_SIZEOF, errp); if (rc < 0) { goto err; } return; err: pcie_chassis_del_slot(s); err_pcie_cap: pcie_cap_exit(d); err_msi: msi_uninit(d); err_bridge: pci_bridge_exitfn(d); }


static int qcow_write(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors) { BDRVQcowState *s = bs->opaque; int ret, index_in_cluster, n; uint64_t cluster_offset; int n_end; while (nb_sectors > 0) { index_in_cluster = sector_num & (s->cluster_sectors - 1); n_end = index_in_cluster + nb_sectors; if (s->crypt_method && n_end > QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors) n_end = QCOW_MAX_CRYPT_CLUSTERS * s->cluster_sectors; cluster_offset = alloc_cluster_offset(bs, sector_num << 9, index_in_cluster, n_end, &n); if (!cluster_offset) return -1; if (s->crypt_method) { encrypt_sectors(s, sector_num, s->cluster_data, buf, n, 1, &s->aes_encrypt_key); ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, s->cluster_data, n * 512); } else { ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512); } if (ret != n * 512) return -1; nb_sectors -= n; sector_num += n; buf += n * 512; } s->cluster_cache_offset = -1; /* disable compressed cache */ return 0; }


static void vnc_dpy_resize(DisplayState *ds) { int size_changed; VncState *vs = ds->opaque; vs->old_data = qemu_realloc(vs->old_data, ds_get_linesize(ds) * ds_get_height(ds)); if (vs->old_data == NULL) { fprintf(stderr, "vnc: memory allocation failed\n"); exit(1); } if (ds_get_bytes_per_pixel(ds) != vs->depth) console_color_init(ds); vnc_colordepth(ds); size_changed = ds_get_width(ds) != vs->width || ds_get_height(ds) != vs->height; if (size_changed) { vs->width = ds_get_width(ds); vs->height = ds_get_height(ds); if (vs->csock != -1 && vs->has_resize) { vnc_write_u8(vs, 0); /* msg id */ vnc_write_u8(vs, 0); vnc_write_u16(vs, 1); /* number of rects */ vnc_framebuffer_update(vs, 0, 0, ds_get_width(ds), ds_get_height(ds), -223); vnc_flush(vs); } } memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row)); memset(vs->old_data, 42, ds_get_linesize(vs->ds) * ds_get_height(vs->ds)); }


static inline int cris_bound_b(int v, int b) { int r = v; asm ("bound.b\t%1, %0\n" : "+r" (r) : "ri" (b)); return r; }


static int virtio_ccw_hcall_notify(const uint64_t *args) { uint64_t subch_id = args[0]; uint64_t queue = args[1]; SubchDev *sch; int cssid, ssid, schid, m; if (ioinst_disassemble_sch_ident(subch_id, &m, &cssid, &ssid, &schid)) { sch = css_find_subch(m, cssid, ssid, schid); if (!sch || !css_subch_visible(sch)) { virtio_queue_notify(virtio_ccw_get_vdev(sch), queue); return 0;