static void network_to_register(RDMARegister *reg) { reg->key.current_addr = ntohll(reg->key.current_addr); reg->current_index = ntohl(reg->current_index); reg->chunks = ntohll(reg->chunks); }


ogg_get_length (AVFormatContext * s) { ogg_t *ogg = s->priv_data; int idx = -1, i; offset_t size, end; if(s->pb.is_streamed) return 0; // already set if (s->duration != AV_NOPTS_VALUE) return 0; size = url_fsize(&s->pb); if(size < 0) return 0; end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: size; ogg_save (s); url_fseek (&s->pb, end, SEEK_SET); while (!ogg_read_page (s, &i)){ if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0) idx = i; } if (idx != -1){ s->streams[idx]->duration = ogg_gptopts (s, idx, ogg->streams[idx].granule); } ogg->size = size; ogg_restore (s, 0); ogg_save (s); while (!ogg_read_page (s, &i)) { if (i == idx && ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0) break; } if (i == idx) { s->streams[idx]->start_time = ogg_gptopts (s, idx, ogg->streams[idx].granule); s->streams[idx]->duration -= s->streams[idx]->start_time; } ogg_restore (s, 0); return 0; }


static void qemu_event_increment(void) { SetEvent(qemu_event_handle); }


static int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque) { if (!balloon_event_fn) { return 0; } trace_balloon_event(balloon_opaque, target); balloon_event_fn(balloon_opaque, target, cb, opaque); return 1; }


void helper_wrmsr(void) { uint64_t val; helper_svm_check_intercept_param(SVM_EXIT_MSR, 1); val = ((uint32_t)EAX) | ((uint64_t)((uint32_t)EDX) << 32); switch((uint32_t)ECX) { case MSR_IA32_SYSENTER_CS: env->sysenter_cs = val & 0xffff; case MSR_IA32_SYSENTER_ESP: env->sysenter_esp = val; case MSR_IA32_SYSENTER_EIP: env->sysenter_eip = val; case MSR_IA32_APICBASE: cpu_set_apic_base(env, val); case MSR_EFER: { uint64_t update_mask; update_mask = 0; if (env->cpuid_ext2_features & CPUID_EXT2_SYSCALL) update_mask |= MSR_EFER_SCE; if (env->cpuid_ext2_features & CPUID_EXT2_LM) update_mask |= MSR_EFER_LME; if (env->cpuid_ext2_features & CPUID_EXT2_FFXSR) update_mask |= MSR_EFER_FFXSR; if (env->cpuid_ext2_features & CPUID_EXT2_NX) update_mask |= MSR_EFER_NXE; if (env->cpuid_ext3_features & CPUID_EXT3_SVM) update_mask |= MSR_EFER_SVME; cpu_load_efer(env, (env->efer & ~update_mask) | (val & update_mask)); } case MSR_STAR: env->star = val; case MSR_PAT: env->pat = val; case MSR_VM_HSAVE_PA: env->vm_hsave = val; #ifdef TARGET_X86_64 case MSR_LSTAR: env->lstar = val; case MSR_CSTAR: env->cstar = val; case MSR_FMASK: env->fmask = val; case MSR_FSBASE: env->segs[R_FS].base = val; case MSR_GSBASE: env->segs[R_GS].base = val; case MSR_KERNELGSBASE: env->kernelgsbase = val; #endif default: /* XXX: exception ? */ } }


static int rm_write_header(AVFormatContext *s) { RMMuxContext *rm = s->priv_data; StreamInfo *stream; int n; AVCodecContext *codec; for(n=0;n<s->nb_streams;n++) { s->streams[n]->id = n; codec = s->streams[n]->codec; stream = &rm->streams[n]; memset(stream, 0, sizeof(StreamInfo)); stream->num = n; stream->bit_rate = codec->bit_rate; stream->enc = codec; switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: rm->audio_stream = stream; stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size; /* XXX: dummy values */ stream->packet_max_size = 1024; stream->nb_packets = 0; stream->total_frames = stream->nb_packets; break; case AVMEDIA_TYPE_VIDEO: rm->video_stream = stream; stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num; /* XXX: dummy values */ stream->packet_max_size = 4096; stream->nb_packets = 0; stream->total_frames = stream->nb_packets; break; default: return -1; if (rv10_write_header(s, 0, 0)) return AVERROR_INVALIDDATA; avio_flush(s->pb); return 0;


static inline void mix_stereo_to_mono(AC3DecodeContext *ctx) { int i; float (*output)[256] = ctx->audio_block.block_output; for (i = 0; i < 256; i++) output[1][i] += output[2][i]; memset(output[2], 0, sizeof(output[2])); }


static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) { int level, pred; if(s->msmpeg4_version<=2){ if (n < 4) { level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, DC_VLC_BITS, 3); } else { level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, DC_VLC_BITS, 3); } if (level < 0) return -1; level-=256; }else{ //FIXME optimize use unified tables & index if (n < 4) { level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); } else { level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); } if (level < 0){ av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); return -1; } if (level == DC_MAX) { level = get_bits(&s->gb, 8); if (get_bits1(&s->gb)) level = -level; } else if (level != 0) { if (get_bits1(&s->gb)) level = -level; } } if(s->msmpeg4_version==1){ int32_t *dc_val; pred = msmpeg4v1_pred_dc(s, n, &dc_val); level += pred; /* update predictor */ *dc_val= level; }else{ int16_t *dc_val; pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr); level += pred; /* update predictor */ if (n < 4) { *dc_val = level * s->y_dc_scale; } else { *dc_val = level * s->c_dc_scale; } } return level; }


void ff_put_h264_qpel16_mc21_msa(uint8_t *dst, const uint8_t *src, ptrdiff_t stride) { avc_luma_midv_qrt_16w_msa(src - (2 * stride) - 2, stride, dst, stride, 16, 0); }


av_cold int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height) { int p, b, x, y, x_tiles, y_tiles, t_width, t_height; IVIBandDesc *band; IVITile *tile, *ref_tile; for (p = 0; p < 3; p++) { t_width = !p ? tile_width : (tile_width + 3) >> 2; t_height = !p ? tile_height : (tile_height + 3) >> 2; if (!p && planes[0].num_bands == 4) { t_width >>= 1; t_height >>= 1; } if(t_width<=0 || t_height<=0) return AVERROR(EINVAL); for (b = 0; b < planes[p].num_bands; b++) { band = &planes[p].bands[b]; x_tiles = IVI_NUM_TILES(band->width, t_width); y_tiles = IVI_NUM_TILES(band->height, t_height); band->num_tiles = x_tiles * y_tiles; av_freep(&band->tiles); band->tiles = av_mallocz(band->num_tiles * sizeof(IVITile)); if (!band->tiles) return AVERROR(ENOMEM); tile = band->tiles; /* use the first luma band as reference for motion vectors * and quant */ ref_tile = planes[0].bands[0].tiles; for (y = 0; y < band->height; y += t_height) { for (x = 0; x < band->width; x += t_width) { tile->xpos = x; tile->ypos = y; tile->mb_size = band->mb_size; tile->width = FFMIN(band->width - x, t_width); tile->height = FFMIN(band->height - y, t_height); tile->is_empty = tile->data_size = 0; /* calculate number of macroblocks */ tile->num_MBs = IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size); av_freep(&tile->mbs); tile->mbs = av_malloc(tile->num_MBs * sizeof(IVIMbInfo)); if (!tile->mbs) return AVERROR(ENOMEM); tile->ref_mbs = 0; if (p || b) { tile->ref_mbs = ref_tile->mbs; ref_tile++; } tile++; } } }// for b }// for p return 0; }


static int mxf_read_content_storage(void *arg, AVIOContext *pb, int tag, int size, UID uid) { MXFContext *mxf = arg; switch (tag) { case 0x1901: mxf->packages_count = avio_rb32(pb); if (mxf->packages_count >= UINT_MAX / sizeof(UID)) return -1; mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID)); if (!mxf->packages_refs) return -1; avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ avio_read(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID)); break; } return 0; }


int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd) { int64_t r = 0; av_assert2(c > 0); av_assert2(b >=0); av_assert2((unsigned)(rnd&~AV_ROUND_PASS_MINMAX)<=5 && (rnd&~AV_ROUND_PASS_MINMAX)!=4); if (c <= 0 || b < 0 || !((unsigned)(rnd&~AV_ROUND_PASS_MINMAX)<=5 && (rnd&~AV_ROUND_PASS_MINMAX)!=4)) return INT64_MIN; if (rnd & AV_ROUND_PASS_MINMAX) { if (a == INT64_MIN || a == INT64_MAX) return a; rnd -= AV_ROUND_PASS_MINMAX; } if (a < 0) return -(uint64_t)av_rescale_rnd(-FFMAX(a, -INT64_MAX), b, c, rnd ^ ((rnd >> 1) & 1)); if (rnd == AV_ROUND_NEAR_INF) r = c / 2; else if (rnd & 1) r = c - 1; if (b <= INT_MAX && c <= INT_MAX) { if (a <= INT_MAX) return (a * b + r) / c; else { int64_t ad = a / c; int64_t a2 = (a % c * b + r) / c; if (ad >= INT32_MAX && ad > (INT64_MAX - a2) / b) return INT64_MIN; return ad * b + a2; } } else { #if 1 uint64_t a0 = a & 0xFFFFFFFF; uint64_t a1 = a >> 32; uint64_t b0 = b & 0xFFFFFFFF; uint64_t b1 = b >> 32; uint64_t t1 = a0 * b1 + a1 * b0; uint64_t t1a = t1 << 32; int i; a0 = a0 * b0 + t1a; a1 = a1 * b1 + (t1 >> 32) + (a0 < t1a); a0 += r; a1 += a0 < r; for (i = 63; i >= 0; i--) { a1 += a1 + ((a0 >> i) & 1); t1 += t1; if (c <= a1) { a1 -= c; t1++; } } if (t1 > INT64_MAX) return INT64_MIN; return t1; } #else AVInteger ai; ai = av_mul_i(av_int2i(a), av_int2i(b)); ai = av_add_i(ai, av_int2i(r)); return av_i2int(av_div_i(ai, av_int2i(c))); } #endif }


static void gen_check_cpenable(DisasContext *dc, unsigned cp) { if (option_enabled(dc, XTENSA_OPTION_COPROCESSOR) && !(dc->cpenable & (1 << cp))) { gen_exception_cause(dc, COPROCESSOR0_DISABLED + cp); dc->is_jmp = DISAS_UPDATE; } }


static void gen_write_xer(TCGv src) { tcg_gen_andi_tl(cpu_xer, src, ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA))); tcg_gen_extract_tl(cpu_so, src, XER_SO, 1); tcg_gen_extract_tl(cpu_ov, src, XER_OV, 1); tcg_gen_extract_tl(cpu_ca, src, XER_CA, 1); }


void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, int layout) { VP8Macroblock *mb_edge[3] = { 0 /* top */, mb - 1 /* left */, 0 /* top-left */ }; enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV }; enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT }; int idx = CNT_ZERO; int cur_sign_bias = s->sign_bias[mb->ref_frame]; int8_t *sign_bias = s->sign_bias; VP56mv near_mv[4]; uint8_t cnt[4] = { 0 }; VP56RangeCoder *c = &s->c; if (!layout) { // layout is inlined (s->mb_layout is not) mb_edge[0] = mb + 2; mb_edge[2] = mb + 1; } else { mb_edge[0] = mb - s->mb_width - 1; mb_edge[2] = mb - s->mb_width - 2; } AV_ZERO32(&near_mv[0]); AV_ZERO32(&near_mv[1]); AV_ZERO32(&near_mv[2]); /* Process MB on top, left and top-left */ #define MV_EDGE_CHECK(n) \ { \ VP8Macroblock *edge = mb_edge[n]; \ int edge_ref = edge->ref_frame; \ if (edge_ref != VP56_FRAME_CURRENT) { \ uint32_t mv = AV_RN32A(&edge->mv); \ if (mv) { \ if (cur_sign_bias != sign_bias[edge_ref]) { \ /* SWAR negate of the values in mv. */ \ mv = ~mv; \ mv = ((mv & 0x7fff7fff) + \ 0x00010001) ^ (mv & 0x80008000); \ } \ if (!n || mv != AV_RN32A(&near_mv[idx])) \ AV_WN32A(&near_mv[++idx], mv); \ cnt[idx] += 1 + (n != 2); \ } else \ cnt[CNT_ZERO] += 1 + (n != 2); \ } \ } MV_EDGE_CHECK(0) MV_EDGE_CHECK(1) MV_EDGE_CHECK(2) mb->partitioning = VP8_SPLITMVMODE_NONE; if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_ZERO]][0])) { mb->mode = VP8_MVMODE_MV; /* If we have three distinct MVs, merge first and last if they're the same */ if (cnt[CNT_SPLITMV] && AV_RN32A(&near_mv[1 + VP8_EDGE_TOP]) == AV_RN32A(&near_mv[1 + VP8_EDGE_TOPLEFT])) cnt[CNT_NEAREST] += 1; /* Swap near and nearest if necessary */ if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) { FFSWAP(uint8_t, cnt[CNT_NEAREST], cnt[CNT_NEAR]); FFSWAP( VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]); } if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAREST]][1])) { if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAR]][2])) { /* Choose the best mv out of 0,0 and the nearest mv */ clamp_mv(s, &mb->mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])]); cnt[CNT_SPLITMV] = ((mb_edge[VP8_EDGE_LEFT]->mode == VP8_MVMODE_SPLIT) + (mb_edge[VP8_EDGE_TOP]->mode == VP8_MVMODE_SPLIT)) * 2 + (mb_edge[VP8_EDGE_TOPLEFT]->mode == VP8_MVMODE_SPLIT); if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) { mb->mode = VP8_MVMODE_SPLIT; mb->mv = mb->bmv[decode_splitmvs(s, c, mb, layout) - 1]; } else { mb->mv.y += read_mv_component(c, s->prob->mvc[0]); mb->mv.x += read_mv_component(c, s->prob->mvc[1]); mb->bmv[0] = mb->mv; } } else { clamp_mv(s, &mb->mv, &near_mv[CNT_NEAR]); mb->bmv[0] = mb->mv; } } else { clamp_mv(s, &mb->mv, &near_mv[CNT_NEAREST]); mb->bmv[0] = mb->mv; } } else { mb->mode = VP8_MVMODE_ZERO; AV_ZERO32(&mb->mv); mb->bmv[0] = mb->mv; } }


static void fw_cfg_initfn(Object *obj) { SysBusDevice *sbd = SYS_BUS_DEVICE(obj); FWCfgState *s = FW_CFG(obj); memory_region_init_io(&s->ctl_iomem, OBJECT(s), &fw_cfg_ctl_mem_ops, s, "fwcfg.ctl", FW_CFG_SIZE); sysbus_init_mmio(sbd, &s->ctl_iomem); memory_region_init_io(&s->data_iomem, OBJECT(s), &fw_cfg_data_mem_ops, s, "fwcfg.data", FW_CFG_DATA_SIZE); sysbus_init_mmio(sbd, &s->data_iomem); /* In case ctl and data overlap: */ memory_region_init_io(&s->comb_iomem, OBJECT(s), &fw_cfg_comb_mem_ops, s, "fwcfg", FW_CFG_SIZE); }


int av_get_cpu_flags(void) { int flags = cpu_flags; if (flags == -1) { flags = get_cpu_flags(); cpu_flags = flags; } return flags; }


static ExitStatus trans_fop_weww_0c(DisasContext *ctx, uint32_t insn, const DisasInsn *di) { unsigned rt = extract32(insn, 0, 5); unsigned rb = extract32(insn, 16, 5); unsigned ra = extract32(insn, 21, 5); return do_fop_weww(ctx, rt, ra, rb, di->f_weww); }


static int inc_refcounts(BlockDriverState *bs, BdrvCheckResult *res, void **refcount_table, int64_t *refcount_table_size, int64_t offset, int64_t size) { BDRVQcow2State *s = bs->opaque; uint64_t start, last, cluster_offset, k, refcount; int ret; if (size <= 0) { return 0; } start = start_of_cluster(s, offset); last = start_of_cluster(s, offset + size - 1); for(cluster_offset = start; cluster_offset <= last; cluster_offset += s->cluster_size) { k = cluster_offset >> s->cluster_bits; if (k >= *refcount_table_size) { ret = realloc_refcount_array(s, refcount_table, refcount_table_size, k + 1); if (ret < 0) { res->check_errors++; return ret; } } refcount = s->get_refcount(*refcount_table, k); if (refcount == s->refcount_max) { fprintf(stderr, "ERROR: overflow cluster offset=0x%" PRIx64 "\n", cluster_offset); res->corruptions++; continue; } s->set_refcount(*refcount_table, k, refcount + 1); } return 0; }


static int gdb_get_avr_reg(CPUState *env, uint8_t *mem_buf, int n) { if (n < 32) { #ifdef WORDS_BIGENDIAN stq_p(mem_buf, env->avr[n].u64[0]); stq_p(mem_buf+8, env->avr[n].u64[1]); #else stq_p(mem_buf, env->avr[n].u64[1]); stq_p(mem_buf+8, env->avr[n].u64[0]); #endif return 16; } if (n == 33) { stl_p(mem_buf, env->vscr); return 4; } if (n == 34) { stl_p(mem_buf, (uint32_t)env->spr[SPR_VRSAVE]); return 4; } return 0; }


static void tpm_backend_worker_thread(gpointer data, gpointer user_data) { TPMBackend *s = TPM_BACKEND(user_data); TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); assert(k->handle_request != NULL); k->handle_request(s, (TPMBackendCmd *)data); qemu_bh_schedule(s->bh); }


static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc, vorbis_floor_data *vfu, float *vec) { vorbis_floor0 *vf = &vfu->t0; float *lsp = vf->lsp; uint_fast32_t amplitude; uint_fast32_t book_idx; uint_fast8_t blockflag = vc->modes[vc->mode_number].blockflag; amplitude = get_bits(&vc->gb, vf->amplitude_bits); if (amplitude > 0) { float last = 0; uint_fast16_t lsp_len = 0; uint_fast16_t idx; vorbis_codebook codebook; book_idx = get_bits(&vc->gb, ilog(vf->num_books)); if (book_idx >= vf->num_books) { av_log(vc->avccontext, AV_LOG_ERROR, "floor0 dec: booknumber too high!\n"); book_idx = 0; //FIXME: look above } AV_DEBUG("floor0 dec: booknumber: %u\n", book_idx); codebook = vc->codebooks[vf->book_list[book_idx]]; while (lsp_len<vf->order) { int vec_off; AV_DEBUG("floor0 dec: book dimension: %d\n", codebook.dimensions); AV_DEBUG("floor0 dec: maximum depth: %d\n", codebook.maxdepth); /* read temp vector */ vec_off = get_vlc2(&vc->gb, codebook.vlc.table, codebook.nb_bits, codebook.maxdepth) * codebook.dimensions; AV_DEBUG("floor0 dec: vector offset: %d\n", vec_off); /* copy each vector component and add last to it */ for (idx = 0; idx < codebook.dimensions; ++idx) lsp[lsp_len+idx] = codebook.codevectors[vec_off+idx] + last; last = lsp[lsp_len+idx-1]; /* set last to last vector component */ lsp_len += codebook.dimensions; } #ifdef V_DEBUG /* DEBUG: output lsp coeffs */ { int idx; for (idx = 0; idx < lsp_len; ++idx) AV_DEBUG("floor0 dec: coeff at %d is %f\n", idx, lsp[idx]); } #endif /* synthesize floor output vector */ { int i; int order = vf->order; float wstep = M_PI / vf->bark_map_size; for (i = 0; i < order; i++) lsp[i] = 2.0f * cos(lsp[i]); AV_DEBUG("floor0 synth: map_size = %d; m = %d; wstep = %f\n", vf->map_size, order, wstep); i = 0; while (i < vf->map_size[blockflag]) { int j, iter_cond = vf->map[blockflag][i]; float p = 0.5f; float q = 0.5f; float two_cos_w = 2.0f * cos(wstep * iter_cond); // needed all times /* similar part for the q and p products */ for (j = 0; j + 1 < order; j += 2) { q *= lsp[j] - two_cos_w; p *= lsp[j + 1] - two_cos_w; } if (j == order) { // even order p *= p * (2.0f - two_cos_w); q *= q * (2.0f + two_cos_w); } else { // odd order q *= two_cos_w-lsp[j]; // one more time for q /* final step and square */ p *= p * (4.f - two_cos_w * two_cos_w); q *= q; } /* calculate linear floor value */ { q = exp((((amplitude*vf->amplitude_offset) / (((1 << vf->amplitude_bits) - 1) * sqrt(p + q))) - vf->amplitude_offset) * .11512925f); } /* fill vector */ do { vec[i] = q; ++i; } while (vf->map[blockflag][i] == iter_cond); } } } else { /* this channel is unused */ return 1; } AV_DEBUG(" Floor0 decoded\n"); return 0; }


static void add_entry(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int count, const void *ptr_val) { uint8_t *entries_ptr = s->entries + 12 * s->num_entries; assert(s->num_entries < TIFF_MAX_ENTRY); bytestream_put_le16(&entries_ptr, tag); bytestream_put_le16(&entries_ptr, type); bytestream_put_le32(&entries_ptr, count); if (type_sizes[type] * count <= 4) { tnput(&entries_ptr, count, ptr_val, type, 0); } else { bytestream_put_le32(&entries_ptr, *s->buf - s->buf_start); check_size(s, count * type_sizes2[type]); tnput(s->buf, count, ptr_val, type, 0); } s->num_entries++; }


static int set_hwframe_ctx(AVCodecContext *ctx, AVBufferRef *hw_device_ctx) { AVBufferRef *hw_frames_ref; AVHWFramesContext *frames_ctx = NULL; int err = 0; if (!(hw_frames_ref = av_hwframe_ctx_alloc(hw_device_ctx))) { fprintf(stderr, "Failed to create VAAPI frame context.\n"); return -1; } frames_ctx = (AVHWFramesContext *)(hw_frames_ref->data); frames_ctx->format = AV_PIX_FMT_VAAPI; frames_ctx->sw_format = AV_PIX_FMT_NV12; frames_ctx->width = width; frames_ctx->height = height; frames_ctx->initial_pool_size = 20; if ((err = av_hwframe_ctx_init(hw_frames_ref)) < 0) { fprintf(stderr, "Failed to initialize VAAPI frame context." "Error code: %s\n",av_err2str(err)); return err; } ctx->hw_frames_ctx = av_buffer_ref(hw_frames_ref); if (!ctx->hw_frames_ctx) err = AVERROR(ENOMEM); return err; }


static int dnxhd_init_vlc(DNXHDContext *ctx, int cid) { if (cid != ctx->cid) { int index; if ((index = ff_dnxhd_get_cid_table(cid)) < 0) { av_log(ctx->avctx, AV_LOG_ERROR, "unsupported cid %d\n", cid); return -1; } if (ff_dnxhd_cid_table[index].bit_depth != ctx->bit_depth) { av_log(ctx->avctx, AV_LOG_ERROR, "bit depth mismatches %d %d\n", ff_dnxhd_cid_table[index].bit_depth, ctx->bit_depth); return AVERROR_INVALIDDATA; } ctx->cid_table = &ff_dnxhd_cid_table[index]; ff_free_vlc(&ctx->ac_vlc); ff_free_vlc(&ctx->dc_vlc); ff_free_vlc(&ctx->run_vlc); init_vlc(&ctx->ac_vlc, DNXHD_VLC_BITS, 257, ctx->cid_table->ac_bits, 1, 1, ctx->cid_table->ac_codes, 2, 2, 0); init_vlc(&ctx->dc_vlc, DNXHD_DC_VLC_BITS, ctx->bit_depth + 4, ctx->cid_table->dc_bits, 1, 1, ctx->cid_table->dc_codes, 1, 1, 0); init_vlc(&ctx->run_vlc, DNXHD_VLC_BITS, 62, ctx->cid_table->run_bits, 1, 1, ctx->cid_table->run_codes, 2, 2, 0); ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, ff_zigzag_direct); ctx->cid = cid; } return 0; }


static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid) { AVCodecContext *vcodec = vstream->codec; switch(flv_codecid) { case FLV_CODECID_H263 : vcodec->codec_id = CODEC_ID_FLV1 ; break; case FLV_CODECID_REALH263: vcodec->codec_id = CODEC_ID_H263 ; break; // Really mean it this time case FLV_CODECID_SCREEN: vcodec->codec_id = CODEC_ID_FLASHSV; break; case FLV_CODECID_SCREEN2: vcodec->codec_id = CODEC_ID_FLASHSV2; break; case FLV_CODECID_VP6 : vcodec->codec_id = CODEC_ID_VP6F ; case FLV_CODECID_VP6A : if(flv_codecid == FLV_CODECID_VP6A) vcodec->codec_id = CODEC_ID_VP6A; if(vcodec->extradata_size != 1) { vcodec->extradata_size = 1; vcodec->extradata = av_malloc(1); } vcodec->extradata[0] = avio_r8(s->pb); return 1; // 1 byte body size adjustment for flv_read_packet() case FLV_CODECID_H264: vcodec->codec_id = CODEC_ID_H264; return 3; // not 4, reading packet type will consume one byte case FLV_CODECID_MPEG4: vcodec->codec_id = CODEC_ID_MPEG4; return 3; default: av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid); vcodec->codec_tag = flv_codecid; } return 0; }


static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int mode, int rnd) { int i, j; uint8_t tmp[8*11], *tptr; int m, r; m = (mode & 3); r = rnd; src -= stride; tptr = tmp; for(j = 0; j < 11; j++) { for(i = 0; i < 8; i++) tptr[i] = vc1_mspel_filter(src + i, 1, m, r); src += stride; tptr += 8; } r = 1 - rnd; m = (mode >> 2) & 3; tptr = tmp + 8; for(j = 0; j < 8; j++) { for(i = 0; i < 8; i++) dst[i] = vc1_mspel_filter(tptr + i, 8, m, r); dst += stride; tptr += 8; } }


static av_cold int bfi_decode_init(AVCodecContext *avctx) { BFIContext *bfi = avctx->priv_data; avctx->pix_fmt = AV_PIX_FMT_PAL8; bfi->dst = av_mallocz(avctx->width * avctx->height); return 0; }


static void vmxnet3_set_events(VMXNET3State *s, uint32_t val) { uint32_t events; VMW_CBPRN("Setting events: 0x%x", val); events = VMXNET3_READ_DRV_SHARED32(s->drv_shmem, ecr) | val; VMXNET3_WRITE_DRV_SHARED32(s->drv_shmem, ecr, events); }


static int qemu_rbd_send_pipe(BDRVRBDState *s, RADOSCB *rcb) { int ret = 0; while (1) { fd_set wfd; int fd = s->fds[RBD_FD_WRITE]; /* send the op pointer to the qemu thread that is responsible for the aio/op completion. Must do it in a qemu thread context */ ret = write(fd, (void *)&rcb, sizeof(rcb)); if (ret >= 0) { break; } if (errno == EINTR) { continue; } if (errno != EAGAIN) { break; } FD_ZERO(&wfd); FD_SET(fd, &wfd); do { ret = select(fd + 1, NULL, &wfd, NULL, NULL); } while (ret < 0 && errno == EINTR); } return ret; }


static void tcx_init(target_phys_addr_t addr, int vram_size, int width, int height, int depth) { DeviceState *dev; SysBusDevice *s; dev = qdev_create(NULL, "SUNW,tcx"); qdev_prop_set_taddr(dev, "addr", addr); qdev_prop_set_uint32(dev, "vram_size", vram_size); qdev_prop_set_uint16(dev, "width", width); qdev_prop_set_uint16(dev, "height", height); qdev_prop_set_uint16(dev, "depth", depth); qdev_init(dev); s = sysbus_from_qdev(dev); /* 8-bit plane */ sysbus_mmio_map(s, 0, addr + 0x00800000ULL); /* DAC */ sysbus_mmio_map(s, 1, addr + 0x00200000ULL); /* TEC (dummy) */ sysbus_mmio_map(s, 2, addr + 0x00700000ULL); /* THC 24 bit: NetBSD writes here even with 8-bit display: dummy */ sysbus_mmio_map(s, 3, addr + 0x00301000ULL); if (depth == 24) { /* 24-bit plane */ sysbus_mmio_map(s, 4, addr + 0x02000000ULL); /* Control plane */ sysbus_mmio_map(s, 5, addr + 0x0a000000ULL); } else { /* THC 8 bit (dummy) */ sysbus_mmio_map(s, 4, addr + 0x00300000ULL); } }


int kvm_init_vcpu(CPUState *env) { KVMState *s = kvm_state; long mmap_size; int ret; DPRINTF("kvm_init_vcpu\n"); ret = kvm_vm_ioctl(s, KVM_CREATE_VCPU, env->cpu_index); if (ret < 0) { DPRINTF("kvm_create_vcpu failed\n"); goto err; } env->kvm_fd = ret; env->kvm_state = s; mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0); if (mmap_size < 0) { DPRINTF("KVM_GET_VCPU_MMAP_SIZE failed\n"); goto err; } env->kvm_run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, env->kvm_fd, 0); if (env->kvm_run == MAP_FAILED) { ret = -errno; DPRINTF("mmap'ing vcpu state failed\n"); goto err; } #ifdef KVM_CAP_COALESCED_MMIO if (s->coalesced_mmio && !s->coalesced_mmio_ring) { s->coalesced_mmio_ring = (void *)env->kvm_run + s->coalesced_mmio * PAGE_SIZE; } #endif ret = kvm_arch_init_vcpu(env); if (ret == 0) { qemu_register_reset(kvm_reset_vcpu, env); kvm_arch_reset_vcpu(env); } err: return ret; }


static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, int width, uint32_t *unused) { #if COMPILE_TEMPLATE_MMX assert(src1==src2); RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24); #else int i; assert(src1==src2); for (i=0; i<width; i++) { int r= src1[3*i + 0]; int g= src1[3*i + 1]; int b= src1[3*i + 2]; dstU[i]= (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT; dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT; } #endif }


int net_init_tap(const NetClientOptions *opts, const char *name, NetClientState *peer) { const NetdevTapOptions *tap; int fd, vnet_hdr = 0, i = 0, queues; /* for the no-fd, no-helper case */ const char *script = NULL; /* suppress wrong "uninit'd use" gcc warning */ const char *downscript = NULL; const char *vhostfdname; char ifname[128]; assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP); tap = opts->tap; queues = tap->has_queues ? tap->queues : 1; vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL; /* QEMU vlans does not support multiqueue tap, in this case peer is set. * For -netdev, peer is always NULL. */ if (peer && (tap->has_queues || tap->has_fds || tap->has_vhostfds)) { error_report("Multiqueue tap cannot be used with QEMU vlans"); return -1; } if (tap->has_fd) { if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_helper || tap->has_queues || tap->has_fds) { error_report("ifname=, script=, downscript=, vnet_hdr=, " "helper=, queues=, and fds= are invalid with fd="); return -1; } fd = monitor_handle_fd_param(cur_mon, tap->fd); if (fd == -1) { return -1; } fcntl(fd, F_SETFL, O_NONBLOCK); vnet_hdr = tap_probe_vnet_hdr(fd); if (net_init_tap_one(tap, peer, "tap", name, NULL, script, downscript, vhostfdname, vnet_hdr, fd)) { return -1; } } else if (tap->has_fds) { char *fds[MAX_TAP_QUEUES]; char *vhost_fds[MAX_TAP_QUEUES]; int nfds, nvhosts; if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_helper || tap->has_queues || tap->has_fd) { error_report("ifname=, script=, downscript=, vnet_hdr=, " "helper=, queues=, and fd= are invalid with fds="); return -1; } nfds = get_fds(tap->fds, fds, MAX_TAP_QUEUES); if (tap->has_vhostfds) { nvhosts = get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES); if (nfds != nvhosts) { error_report("The number of fds passed does not match the " "number of vhostfds passed"); return -1; } } for (i = 0; i < nfds; i++) { fd = monitor_handle_fd_param(cur_mon, fds[i]); if (fd == -1) { return -1; } fcntl(fd, F_SETFL, O_NONBLOCK); if (i == 0) { vnet_hdr = tap_probe_vnet_hdr(fd); } else if (vnet_hdr != tap_probe_vnet_hdr(fd)) { error_report("vnet_hdr not consistent across given tap fds"); return -1; } if (net_init_tap_one(tap, peer, "tap", name, ifname, script, downscript, tap->has_vhostfds ? vhost_fds[i] : NULL, vnet_hdr, fd)) { return -1; } } } else if (tap->has_helper) { if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_queues || tap->has_fds) { error_report("ifname=, script=, downscript=, and vnet_hdr= " "queues=, and fds= are invalid with helper="); return -1; } fd = net_bridge_run_helper(tap->helper, DEFAULT_BRIDGE_INTERFACE); if (fd == -1) { return -1; } fcntl(fd, F_SETFL, O_NONBLOCK); vnet_hdr = tap_probe_vnet_hdr(fd); if (net_init_tap_one(tap, peer, "bridge", name, ifname, script, downscript, vhostfdname, vnet_hdr, fd)) { return -1; } } else { script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT; downscript = tap->has_downscript ? tap->downscript : DEFAULT_NETWORK_DOWN_SCRIPT; if (tap->has_ifname) { pstrcpy(ifname, sizeof ifname, tap->ifname); } else { ifname[0] = '\0'; } for (i = 0; i < queues; i++) { fd = net_tap_init(tap, &vnet_hdr, i >= 1 ? "no" : script, ifname, sizeof ifname, queues > 1); if (fd == -1) { return -1; } if (queues > 1 && i == 0 && !tap->has_ifname) { if (tap_fd_get_ifname(fd, ifname)) { error_report("Fail to get ifname"); return -1; } } if (net_init_tap_one(tap, peer, "tap", name, ifname, i >= 1 ? "no" : script, i >= 1 ? "no" : downscript, vhostfdname, vnet_hdr, fd)) { return -1; } } } return 0; }


static void spr_read_decr(DisasContext *ctx, int gprn, int sprn) { if (ctx->tb->cflags & CF_USE_ICOUNT) { gen_io_start(); } gen_helper_load_decr(cpu_gpr[gprn], cpu_env); if (ctx->tb->cflags & CF_USE_ICOUNT) { gen_io_end(); gen_stop_exception(ctx); } }


static double get_scene_score(AVFilterContext *ctx, AVFilterBufferRef *picref) { double ret = 0; SelectContext *select = ctx->priv; AVFilterBufferRef *prev_picref = select->prev_picref; if (prev_picref && picref->video->h == prev_picref->video->h && picref->video->w == prev_picref->video->w && picref->linesize[0] == prev_picref->linesize[0]) { int x, y; int64_t sad = 0; double mafd, diff; uint8_t *p1 = picref->data[0]; uint8_t *p2 = prev_picref->data[0]; const int linesize = picref->linesize[0]; for (y = 0; y < picref->video->h; y += 8) for (x = 0; x < linesize; x += 8) sad += select->c.sad[1](select, p1 + y * linesize + x, p2 + y * linesize + x, linesize, 8); emms_c(); mafd = sad / (picref->video->h * picref->video->w * 3); diff = fabs(mafd - select->prev_mafd); ret = av_clipf(FFMIN(mafd, diff) / 100., 0, 1); select->prev_mafd = mafd; avfilter_unref_buffer(prev_picref); } select->prev_picref = avfilter_ref_buffer(picref, ~0); return ret; }


static int do_req(int sockfd, AioContext *aio_context, SheepdogReq *hdr, void *data, unsigned int *wlen, unsigned int *rlen) { Coroutine *co; SheepdogReqCo srco = { .sockfd = sockfd, .aio_context = aio_context, .hdr = hdr, .data = data, .wlen = wlen, .rlen = rlen, .ret = 0, .finished = false, }; if (qemu_in_coroutine()) { do_co_req(&srco); } else { co = qemu_coroutine_create(do_co_req); qemu_coroutine_enter(co, &srco); while (!srco.finished) { aio_poll(aio_context, true); } } return srco.ret; }


static void gen_mtsrin(DisasContext *ctx) { #if defined(CONFIG_USER_ONLY) gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); #else TCGv t0; if (unlikely(ctx->pr)) { gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); return; } t0 = tcg_temp_new(); tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); tcg_gen_andi_tl(t0, t0, 0xF); gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]); tcg_temp_free(t0); #endif }


void s390_pci_iommu_enable(S390PCIBusDevice *pbdev) { uint64_t size = pbdev->pal - pbdev->pba + 1; memory_region_init_iommu(&pbdev->iommu_mr, OBJECT(&pbdev->mr), &s390_iommu_ops, "iommu-s390", size); memory_region_add_subregion(&pbdev->mr, pbdev->pba, &pbdev->iommu_mr); pbdev->iommu_enabled = true; }


strdup(str) const char *str; { char *bptr; bptr = (char *)malloc(strlen(str)+1); strcpy(bptr, str); return bptr; }


static void gen_tlbli_6xx(DisasContext *ctx) { #if defined(CONFIG_USER_ONLY) gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); #else if (unlikely(ctx->pr)) { gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; } gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); #endif }


QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev) { const char *firstname; char value[1024], *id = NULL; const char *p; QemuOpts *opts; assert(!permit_abbrev || list->implied_opt_name); firstname = permit_abbrev ? list->implied_opt_name : NULL; if (strncmp(params, "id=", 3) == 0) { get_opt_value(value, sizeof(value), params+3); id = qemu_strdup(value); } else if ((p = strstr(params, ",id=")) != NULL) { get_opt_value(value, sizeof(value), p+4); id = qemu_strdup(value); } opts = qemu_opts_create(list, id, 1); if (opts == NULL) return NULL; if (qemu_opts_do_parse(opts, params, firstname) != 0) { qemu_opts_del(opts); return NULL; } return opts; }


static always_inline int get_segment (CPUState *env, mmu_ctx_t *ctx, target_ulong eaddr, int rw, int type) { target_phys_addr_t sdr, hash, mask, sdr_mask, htab_mask; target_ulong sr, vsid, vsid_mask, pgidx, page_mask; #if defined(TARGET_PPC64) int attr; #endif int ds, vsid_sh, sdr_sh, pr; int ret, ret2; pr = msr_pr; #if defined(TARGET_PPC64) if (env->mmu_model == POWERPC_MMU_64B) { #if defined (DEBUG_MMU) if (loglevel != 0) { fprintf(logfile, "Check SLBs\n"); } #endif ret = slb_lookup(env, eaddr, &vsid, &page_mask, &attr); if (ret < 0) return ret; ctx->key = ((attr & 0x40) && (pr != 0)) || ((attr & 0x80) && (pr == 0)) ? 1 : 0; ds = 0; ctx->nx = attr & 0x20 ? 1 : 0; vsid_mask = 0x00003FFFFFFFFF80ULL; vsid_sh = 7; sdr_sh = 18; sdr_mask = 0x3FF80; } else #endif /* defined(TARGET_PPC64) */ { sr = env->sr[eaddr >> 28]; page_mask = 0x0FFFFFFF; ctx->key = (((sr & 0x20000000) && (pr != 0)) || ((sr & 0x40000000) && (pr == 0))) ? 1 : 0; ds = sr & 0x80000000 ? 1 : 0; ctx->nx = sr & 0x10000000 ? 1 : 0; vsid = sr & 0x00FFFFFF; vsid_mask = 0x01FFFFC0; vsid_sh = 6; sdr_sh = 16; sdr_mask = 0xFFC0; #if defined (DEBUG_MMU) if (loglevel != 0) { fprintf(logfile, "Check segment v=0x" ADDRX " %d 0x" ADDRX " nip=0x" ADDRX " lr=0x" ADDRX " ir=%d dr=%d pr=%d %d t=%d\n", eaddr, (int)(eaddr >> 28), sr, env->nip, env->lr, (int)msr_ir, (int)msr_dr, pr != 0 ? 1 : 0, rw, type); } #endif } #if defined (DEBUG_MMU) if (loglevel != 0) { fprintf(logfile, "pte segment: key=%d ds %d nx %d vsid " ADDRX "\n", ctx->key, ds, ctx->nx, vsid); } #endif ret = -1; if (!ds) { /* Check if instruction fetch is allowed, if needed */ if (type != ACCESS_CODE || ctx->nx == 0) { /* Page address translation */ /* Primary table address */ sdr = env->sdr1; pgidx = (eaddr & page_mask) >> TARGET_PAGE_BITS; #if defined(TARGET_PPC64) if (env->mmu_model == POWERPC_MMU_64B) { htab_mask = 0x0FFFFFFF >> (28 - (sdr & 0x1F)); /* XXX: this is false for 1 TB segments */ hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask; } else #endif { htab_mask = sdr & 0x000001FF; hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask; } mask = (htab_mask << sdr_sh) | sdr_mask; #if defined (DEBUG_MMU) if (loglevel != 0) { fprintf(logfile, "sdr " PADDRX " sh %d hash " PADDRX " mask " PADDRX " " ADDRX "\n", sdr, sdr_sh, hash, mask, page_mask); } #endif ctx->pg_addr[0] = get_pgaddr(sdr, sdr_sh, hash, mask); /* Secondary table address */ hash = (~hash) & vsid_mask; #if defined (DEBUG_MMU) if (loglevel != 0) { fprintf(logfile, "sdr " PADDRX " sh %d hash " PADDRX " mask " PADDRX "\n", sdr, sdr_sh, hash, mask); } #endif ctx->pg_addr[1] = get_pgaddr(sdr, sdr_sh, hash, mask); #if defined(TARGET_PPC64) if (env->mmu_model == POWERPC_MMU_64B) { /* Only 5 bits of the page index are used in the AVPN */ ctx->ptem = (vsid << 12) | ((pgidx >> 4) & 0x0F80); } else #endif { ctx->ptem = (vsid << 7) | (pgidx >> 10); } /* Initialize real address with an invalid value */ ctx->raddr = (target_ulong)-1; if (unlikely(env->mmu_model == POWERPC_MMU_SOFT_6xx || env->mmu_model == POWERPC_MMU_SOFT_74xx)) { /* Software TLB search */ ret = ppc6xx_tlb_check(env, ctx, eaddr, rw, type); } else { #if defined (DEBUG_MMU) if (loglevel != 0) { fprintf(logfile, "0 sdr1=0x" PADDRX " vsid=0x%06x " "api=0x%04x hash=0x%07x pg_addr=0x" PADDRX "\n", sdr, (uint32_t)vsid, (uint32_t)pgidx, (uint32_t)hash, ctx->pg_addr[0]); } #endif /* Primary table lookup */ ret = find_pte(env, ctx, 0, rw, type); if (ret < 0) { /* Secondary table lookup */ #if defined (DEBUG_MMU) if (eaddr != 0xEFFFFFFF && loglevel != 0) { fprintf(logfile, "1 sdr1=0x" PADDRX " vsid=0x%06x api=0x%04x " "hash=0x%05x pg_addr=0x" PADDRX "\n", sdr, (uint32_t)vsid, (uint32_t)pgidx, (uint32_t)hash, ctx->pg_addr[1]); } #endif ret2 = find_pte(env, ctx, 1, rw, type); if (ret2 != -1) ret = ret2; } } #if defined (DUMP_PAGE_TABLES) if (loglevel != 0) { target_phys_addr_t curaddr; uint32_t a0, a1, a2, a3; fprintf(logfile, "Page table: " PADDRX " len " PADDRX "\n", sdr, mask + 0x80); for (curaddr = sdr; curaddr < (sdr + mask + 0x80); curaddr += 16) { a0 = ldl_phys(curaddr); a1 = ldl_phys(curaddr + 4); a2 = ldl_phys(curaddr + 8); a3 = ldl_phys(curaddr + 12); if (a0 != 0 || a1 != 0 || a2 != 0 || a3 != 0) { fprintf(logfile, PADDRX ": %08x %08x %08x %08x\n", curaddr, a0, a1, a2, a3); } } } #endif } else { #if defined (DEBUG_MMU) if (loglevel != 0) fprintf(logfile, "No access allowed\n"); #endif ret = -3; } } else { #if defined (DEBUG_MMU) if (loglevel != 0) fprintf(logfile, "direct store...\n"); #endif /* Direct-store segment : absolutely *BUGGY* for now */ switch (type) { case ACCESS_INT: /* Integer load/store : only access allowed */ break; case ACCESS_CODE: /* No code fetch is allowed in direct-store areas */ return -4; case ACCESS_FLOAT: /* Floating point load/store */ return -4; case ACCESS_RES: /* lwarx, ldarx or srwcx. */ return -4; case ACCESS_CACHE: /* dcba, dcbt, dcbtst, dcbf, dcbi, dcbst, dcbz, or icbi */ /* Should make the instruction do no-op. * As it already do no-op, it's quite easy :-) */ ctx->raddr = eaddr; return 0; case ACCESS_EXT: /* eciwx or ecowx */ return -4; default: if (logfile) { fprintf(logfile, "ERROR: instruction should not need " "address translation\n"); } return -4; } if ((rw == 1 || ctx->key != 1) && (rw == 0 || ctx->key != 0)) { ctx->raddr = eaddr; ret = 2; } else { ret = -2; } } return ret; }


AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame, int perms) { AVFilterBufferRef *samplesref = avfilter_get_audio_buffer_ref_from_arrays((uint8_t **)frame->data, frame->linesize[0], perms, frame->nb_samples, frame->format, av_frame_get_channel_layout(frame)); if (!samplesref) return NULL; if (avfilter_copy_frame_props(samplesref, frame) < 0) { samplesref->buf->data[0] = NULL; avfilter_unref_bufferp(&samplesref); } return samplesref; }


int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) { Wmv2Context *const w = (Wmv2Context *) s; if (s->pict_type == AV_PICTURE_TYPE_I) { if (w->j_type_bit) w->j_type = get_bits1(&s->gb); else w->j_type = 0; // FIXME check if (!w->j_type) { if (w->per_mb_rl_bit) s->per_mb_rl_table = get_bits1(&s->gb); else s->per_mb_rl_table = 0; if (!s->per_mb_rl_table) { s->rl_chroma_table_index = decode012(&s->gb); s->rl_table_index = decode012(&s->gb); } s->dc_table_index = get_bits1(&s->gb); } s->inter_intra_pred = 0; s->no_rounding = 1; if (s->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n", s->qscale, s->rl_chroma_table_index, s->rl_table_index, s->dc_table_index, s->per_mb_rl_table, w->j_type); } } else { int cbp_index; w->j_type = 0; parse_mb_skip(w); cbp_index = decode012(&s->gb); w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index); if (w->mspel_bit) s->mspel = get_bits1(&s->gb); else s->mspel = 0; // FIXME check if (w->abt_flag) { w->per_mb_abt = get_bits1(&s->gb) ^ 1; if (!w->per_mb_abt) w->abt_type = decode012(&s->gb); } if (w->per_mb_rl_bit) s->per_mb_rl_table = get_bits1(&s->gb); else s->per_mb_rl_table = 0; if (!s->per_mb_rl_table) { s->rl_table_index = decode012(&s->gb); s->rl_chroma_table_index = s->rl_table_index; } s->dc_table_index = get_bits1(&s->gb); s->mv_table_index = get_bits1(&s->gb); s->inter_intra_pred = 0; // (s->width * s->height < 320 * 240 && s->bit_rate <= II_BITRATE); s->no_rounding ^= 1; if (s->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(s->avctx, AV_LOG_DEBUG, "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d " "per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n", s->rl_table_index, s->rl_chroma_table_index, s->dc_table_index, s->mv_table_index, s->per_mb_rl_table, s->qscale, s->mspel, w->per_mb_abt, w->abt_type, w->cbp_table_index, s->inter_intra_pred); } } s->esc3_level_length = 0; s->esc3_run_length = 0; s->picture_number++; // FIXME ? if (w->j_type) { ff_intrax8_decode_picture(&w->x8, &s->current_picture, &s->gb, &s->mb_x, &s->mb_y, 2 * s->qscale, (s->qscale - 1) | 1, s->loop_filter, s->low_delay); ff_er_add_slice(&w->s.er, 0, 0, (w->s.mb_x >> 1) - 1, (w->s.mb_y >> 1) - 1, ER_MB_END); return 1; } return 0; }


static void vp8_decode_flush_impl(AVCodecContext *avctx, int force, int is_close) { VP8Context *s = avctx->priv_data; int i; if (!avctx->is_copy || force) { for (i = 0; i < 5; i++) if (s->frames[i].data[0]) vp8_release_frame(s, &s->frames[i], is_close); } memset(s->framep, 0, sizeof(s->framep)); free_buffers(s); s->maps_are_invalid = 1; }


static CharDriverState *qemu_chr_open_stdio(QemuOpts *opts) { CharDriverState *chr; if (stdio_nb_clients >= STDIO_MAX_CLIENTS) { if (stdio_nb_clients == 0) { old_fd0_flags = fcntl(0, F_GETFL); tcgetattr (0, &oldtty); fcntl(0, F_SETFL, O_NONBLOCK); atexit(term_exit); chr = qemu_chr_open_fd(0, 1); chr->chr_close = qemu_chr_close_stdio; chr->chr_set_echo = qemu_chr_set_echo_stdio; qemu_set_fd_handler2(0, stdio_read_poll, stdio_read, NULL, chr); stdio_nb_clients++; stdio_allow_signal = qemu_opt_get_bool(opts, "signal", display_type != DT_NOGRAPHIC); qemu_chr_fe_set_echo(chr, false); return chr;


static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { LclContext * const c = (LclContext *)avctx->priv_data; unsigned char *encoded = (unsigned char *)buf; int pixel_ptr; int row, col; unsigned char *outptr; unsigned int width = avctx->width; // Real image width unsigned int height = avctx->height; // Real image height unsigned int mszh_dlen; unsigned char yq, y1q, uq, vq; int uqvq; unsigned int mthread_inlen, mthread_outlen; #ifdef CONFIG_ZLIB int zret; // Zlib return code #endif int len = buf_size; /* no supplementary picture */ if (buf_size == 0) return 0; if(c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); c->pic.reference = 0; c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; if(avctx->get_buffer(avctx, &c->pic) < 0){ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } outptr = c->pic.data[0]; // Output image pointer /* Decompress frame */ switch (avctx->codec_id) { case CODEC_ID_MSZH: switch (c->compression) { case COMP_MSZH: if (c->flags & FLAG_MULTITHREAD) { mthread_inlen = *((unsigned int*)encoded); mthread_outlen = *((unsigned int*)(encoded+4)); mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf); if (mthread_outlen != mszh_dlen) { av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", mthread_outlen, mszh_dlen); } mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen, c->decomp_buf + mthread_outlen); if ((c->decomp_size - mthread_outlen) != mszh_dlen) { av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", c->decomp_size - mthread_outlen, mszh_dlen); } encoded = c->decomp_buf; len = c->decomp_size; } else { mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf); if (c->decomp_size != mszh_dlen) { av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", c->decomp_size, mszh_dlen); } encoded = c->decomp_buf; len = mszh_dlen; } break; case COMP_MSZH_NOCOMP: break; default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); return -1; } break; case CODEC_ID_ZLIB: #ifdef CONFIG_ZLIB /* Using the original dll with normal compression (-1) and RGB format * gives a file with ZLIB fourcc, but frame is really uncompressed. * To be sure that's true check also frame size */ if ((c->compression == COMP_ZLIB_NORMAL) && (c->imgtype == IMGTYPE_RGB24) && (len == width * height * 3)) break; zret = inflateReset(&(c->zstream)); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return -1; } if (c->flags & FLAG_MULTITHREAD) { mthread_inlen = *((unsigned int*)encoded); mthread_outlen = *((unsigned int*)(encoded+4)); c->zstream.next_in = encoded + 8; c->zstream.avail_in = mthread_inlen; c->zstream.next_out = c->decomp_buf; c->zstream.avail_out = mthread_outlen; zret = inflate(&(c->zstream), Z_FINISH); if ((zret != Z_OK) && (zret != Z_STREAM_END)) { av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret); return -1; } if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n", mthread_outlen, c->zstream.total_out); } zret = inflateReset(&(c->zstream)); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret); return -1; } c->zstream.next_in = encoded + 8 + mthread_inlen; c->zstream.avail_in = len - mthread_inlen; c->zstream.next_out = c->decomp_buf + mthread_outlen; c->zstream.avail_out = mthread_outlen; zret = inflate(&(c->zstream), Z_FINISH); if ((zret != Z_OK) && (zret != Z_STREAM_END)) { av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret); return -1; } if ((c->decomp_size - mthread_outlen) != (unsigned int)(c->zstream.total_out)) { av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n", c->decomp_size - mthread_outlen, c->zstream.total_out); } } else { c->zstream.next_in = encoded; c->zstream.avail_in = len; c->zstream.next_out = c->decomp_buf; c->zstream.avail_out = c->decomp_size; zret = inflate(&(c->zstream), Z_FINISH); if ((zret != Z_OK) && (zret != Z_STREAM_END)) { av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); return -1; } if (c->decomp_size != (unsigned int)(c->zstream.total_out)) { av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", c->decomp_size, c->zstream.total_out); } } encoded = c->decomp_buf; len = c->decomp_size;; #else av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n"); return -1; #endif break; default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); return -1; } /* Apply PNG filter */ if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) { switch (c->imgtype) { case IMGTYPE_YUV111: case IMGTYPE_RGB24: for (row = 0; row < height; row++) { pixel_ptr = row * width * 3; yq = encoded[pixel_ptr++]; uqvq = encoded[pixel_ptr++]; uqvq+=(encoded[pixel_ptr++] << 8); for (col = 1; col < width; col++) { encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8)); encoded[pixel_ptr+1] = (uqvq) & 0xff; encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff; pixel_ptr += 3; } } break; case IMGTYPE_YUV422: for (row = 0; row < height; row++) { pixel_ptr = row * width * 2; yq = uq = vq =0; for (col = 0; col < width/4; col++) { encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; pixel_ptr += 8; } } break; case IMGTYPE_YUV411: for (row = 0; row < height; row++) { pixel_ptr = row * width / 2 * 3; yq = uq = vq =0; for (col = 0; col < width/4; col++) { encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; pixel_ptr += 6; } } break; case IMGTYPE_YUV211: for (row = 0; row < height; row++) { pixel_ptr = row * width * 2; yq = uq = vq =0; for (col = 0; col < width/2; col++) { encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; pixel_ptr += 4; } } break; case IMGTYPE_YUV420: for (row = 0; row < height/2; row++) { pixel_ptr = row * width * 3; yq = y1q = uq = vq =0; for (col = 0; col < width/2; col++) { encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2]; encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; pixel_ptr += 6; } } break; default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); return -1; } } /* Convert colorspace */ switch (c->imgtype) { case IMGTYPE_YUV111: for (row = height - 1; row >= 0; row--) { pixel_ptr = row * c->pic.linesize[0]; for (col = 0; col < width; col++) { outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]); outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]); outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]); encoded += 3; } } break; case IMGTYPE_YUV422: for (row = height - 1; row >= 0; row--) { pixel_ptr = row * c->pic.linesize[0]; for (col = 0; col < width/4; col++) { outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]); outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]); outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]); outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]); outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]); outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]); outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]); outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]); outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]); outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]); encoded += 8; } } break; case IMGTYPE_RGB24: for (row = height - 1; row >= 0; row--) { pixel_ptr = row * c->pic.linesize[0]; for (col = 0; col < width; col++) { outptr[pixel_ptr++] = encoded[0]; outptr[pixel_ptr++] = encoded[1]; outptr[pixel_ptr++] = encoded[2]; encoded += 3; } } break; case IMGTYPE_YUV411: for (row = height - 1; row >= 0; row--) { pixel_ptr = row * c->pic.linesize[0]; for (col = 0; col < width/4; col++) { outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]); outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]); outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]); outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]); outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]); outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]); outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]); outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]); outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]); outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]); encoded += 6; } } break; case IMGTYPE_YUV211: for (row = height - 1; row >= 0; row--) { pixel_ptr = row * c->pic.linesize[0]; for (col = 0; col < width/2; col++) { outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]); outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]); outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]); outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]); outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]); outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]); encoded += 4; } } break; case IMGTYPE_YUV420: for (row = height / 2 - 1; row >= 0; row--) { pixel_ptr = 2 * row * c->pic.linesize[0]; for (col = 0; col < width/2; col++) { outptr[pixel_ptr] = get_b(encoded[0], encoded[4]); outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]); outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]); outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]); outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]); outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]); outptr[pixel_ptr-c->pic.linesize[0]] = get_b(encoded[2], encoded[4]); outptr[pixel_ptr-c->pic.linesize[0]+1] = get_g(encoded[2], encoded[4], encoded[5]); outptr[pixel_ptr-c->pic.linesize[0]+2] = get_r(encoded[2], encoded[5]); outptr[pixel_ptr-c->pic.linesize[0]+3] = get_b(encoded[3], encoded[4]); outptr[pixel_ptr-c->pic.linesize[0]+4] = get_g(encoded[3], encoded[4], encoded[5]); outptr[pixel_ptr-c->pic.linesize[0]+5] = get_r(encoded[3], encoded[5]); pixel_ptr += 6; encoded += 6; } } break; default: av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); return -1; } *data_size = sizeof(AVFrame); *(AVFrame*)data = c->pic; /* always report that the buffer was completely consumed */ return buf_size; }


static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss, bool last_stage) { int tmppages, pages = 0; size_t pagesize_bits = qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS; do { tmppages = ram_save_target_page(rs, pss, last_stage); if (tmppages < 0) { return tmppages; } pages += tmppages; pss->page++; } while (pss->page & (pagesize_bits - 1)); /* The offset we leave with is the last one we looked at */ pss->page--; return pages; }


static int qemu_rdma_exchange_recv(RDMAContext *rdma, RDMAControlHeader *head, int expecting) { RDMAControlHeader ready = { .len = 0, .type = RDMA_CONTROL_READY, .repeat = 1, }; int ret; /* * Inform the source that we're ready to receive a message. */ ret = qemu_rdma_post_send_control(rdma, NULL, &ready); if (ret < 0) { fprintf(stderr, "Failed to send control buffer!\n"); return ret; } /* * Block and wait for the message. */ ret = qemu_rdma_exchange_get_response(rdma, head, expecting, RDMA_WRID_READY); if (ret < 0) { return ret; } qemu_rdma_move_header(rdma, RDMA_WRID_READY, head); /* * Post a new RECV work request to replace the one we just consumed. */ ret = qemu_rdma_post_recv_control(rdma, RDMA_WRID_READY); if (ret) { fprintf(stderr, "rdma migration: error posting second control recv!"); return ret; } return 0; }


static int qxl_track_command(PCIQXLDevice *qxl, struct QXLCommandExt *ext) { switch (le32_to_cpu(ext->cmd.type)) { case QXL_CMD_SURFACE: { QXLSurfaceCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id); if (!cmd) { uint32_t id = le32_to_cpu(cmd->surface_id); if (id >= qxl->ssd.num_surfaces) { qxl_set_guest_bug(qxl, "QXL_CMD_SURFACE id %d >= %d", id, qxl->ssd.num_surfaces); qemu_mutex_lock(&qxl->track_lock); if (cmd->type == QXL_SURFACE_CMD_CREATE) { qxl->guest_surfaces.cmds[id] = ext->cmd.data; qxl->guest_surfaces.count++; if (qxl->guest_surfaces.max < qxl->guest_surfaces.count) qxl->guest_surfaces.max = qxl->guest_surfaces.count; if (cmd->type == QXL_SURFACE_CMD_DESTROY) { qxl->guest_surfaces.cmds[id] = 0; qxl->guest_surfaces.count--; qemu_mutex_unlock(&qxl->track_lock); break; case QXL_CMD_CURSOR: { QXLCursorCmd *cmd = qxl_phys2virt(qxl, ext->cmd.data, ext->group_id); if (!cmd) { if (cmd->type == QXL_CURSOR_SET) { qemu_mutex_lock(&qxl->track_lock); qxl->guest_cursor = ext->cmd.data; qemu_mutex_unlock(&qxl->track_lock); break; return 0;


int tcp_fconnect(struct socket *so) { Slirp *slirp = so->slirp; int ret=0; DEBUG_CALL("tcp_fconnect"); DEBUG_ARG("so = %lx", (long )so); if( (ret=so->s=socket(AF_INET,SOCK_STREAM,0)) >= 0) { int opt, s=so->s; struct sockaddr_in addr; fd_nonblock(s); opt = 1; setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(opt )); opt = 1; setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(opt )); addr.sin_family = AF_INET; if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) == slirp->vnetwork_addr.s_addr) { /* It's an alias */ if (so->so_faddr.s_addr == slirp->vnameserver_addr.s_addr) { if (get_dns_addr(&addr.sin_addr) < 0) addr.sin_addr = loopback_addr; } else { addr.sin_addr = loopback_addr; } } else addr.sin_addr = so->so_faddr; addr.sin_port = so->so_fport; DEBUG_MISC((dfd, " connect()ing, addr.sin_port=%d, " "addr.sin_addr.s_addr=%.16s\n", ntohs(addr.sin_port), inet_ntoa(addr.sin_addr))); /* We don't care what port we get */ ret = connect(s,(struct sockaddr *)&addr,sizeof (addr)); /* * If it's not in progress, it failed, so we just return 0, * without clearing SS_NOFDREF */ soisfconnecting(so); } return(ret); }


static void cloop_close(BlockDriverState *bs) { BDRVCloopState *s = bs->opaque; if (s->n_blocks > 0) { g_free(s->offsets); } g_free(s->compressed_block); g_free(s->uncompressed_block); inflateEnd(&s->zstream); }


PROTO4(_pack_2ch_) PROTO4(_pack_6ch_) PROTO4(_pack_8ch_) PROTO4(_unpack_2ch_) PROTO4(_unpack_6ch_) av_cold void swri_audio_convert_init_x86(struct AudioConvert *ac, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels){ int mm_flags = av_get_cpu_flags(); ac->simd_f= NULL; //FIXME add memcpy case #define MULTI_CAPS_FUNC(flag, cap) \ if (EXTERNAL_##flag(mm_flags)) {\ if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16 || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16P)\ ac->simd_f = ff_int16_to_int32_a_ ## cap;\ if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S32P)\ ac->simd_f = ff_int32_to_int16_a_ ## cap;\ } MULTI_CAPS_FUNC(MMX, mmx) MULTI_CAPS_FUNC(SSE2, sse2) if(EXTERNAL_MMX(mm_flags)) { if(channels == 6) { if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_6ch_float_to_float_a_mmx; } } if(EXTERNAL_SSE(mm_flags)) { if(channels == 6) { if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_6ch_float_to_float_a_sse; if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32) ac->simd_f = ff_unpack_6ch_float_to_float_a_sse; } } if(EXTERNAL_SSE2(mm_flags)) { if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_int32_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16P) ac->simd_f = ff_int16_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLTP) ac->simd_f = ff_float_to_int32_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLTP) ac->simd_f = ff_float_to_int16_a_sse2; if(channels == 2) { if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_2ch_int32_to_int32_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S16P) ac->simd_f = ff_pack_2ch_int16_to_int16_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S16P) ac->simd_f = ff_pack_2ch_int16_to_int32_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_2ch_int32_to_int16_a_sse2; if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32) ac->simd_f = ff_unpack_2ch_int32_to_int32_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16) ac->simd_f = ff_unpack_2ch_int16_to_int16_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16) ac->simd_f = ff_unpack_2ch_int16_to_int32_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S32) ac->simd_f = ff_unpack_2ch_int32_to_int16_a_sse2; if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_2ch_int32_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP) ac->simd_f = ff_pack_2ch_float_to_int32_a_sse2; if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S16P) ac->simd_f = ff_pack_2ch_int16_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S16 && in_fmt == AV_SAMPLE_FMT_FLTP) ac->simd_f = ff_pack_2ch_float_to_int16_a_sse2; if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32) ac->simd_f = ff_unpack_2ch_int32_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT) ac->simd_f = ff_unpack_2ch_float_to_int32_a_sse2; if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16) ac->simd_f = ff_unpack_2ch_int16_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_FLT) ac->simd_f = ff_unpack_2ch_float_to_int16_a_sse2; } if(channels == 6) { if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_6ch_int32_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP) ac->simd_f = ff_pack_6ch_float_to_int32_a_sse2; if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32) ac->simd_f = ff_unpack_6ch_int32_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT) ac->simd_f = ff_unpack_6ch_float_to_int32_a_sse2; } if(channels == 8) { if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_8ch_float_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_8ch_int32_to_float_a_sse2; if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP) ac->simd_f = ff_pack_8ch_float_to_int32_a_sse2; } } if(EXTERNAL_SSSE3(mm_flags)) { if(channels == 2) { if( out_fmt == AV_SAMPLE_FMT_S16P && in_fmt == AV_SAMPLE_FMT_S16) ac->simd_f = ff_unpack_2ch_int16_to_int16_a_ssse3; if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S16) ac->simd_f = ff_unpack_2ch_int16_to_int32_a_ssse3; if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S16) ac->simd_f = ff_unpack_2ch_int16_to_float_a_ssse3; } } if(EXTERNAL_AVX(mm_flags)) { if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32 || out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_int32_to_float_a_avx; if(channels == 6) { if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_6ch_float_to_float_a_avx; if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_6ch_int32_to_float_a_avx; if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP) ac->simd_f = ff_pack_6ch_float_to_int32_a_avx; if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_S32) ac->simd_f = ff_unpack_6ch_float_to_float_a_avx; if( out_fmt == AV_SAMPLE_FMT_FLTP && in_fmt == AV_SAMPLE_FMT_S32) ac->simd_f = ff_unpack_6ch_int32_to_float_a_avx; if( out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLT) ac->simd_f = ff_unpack_6ch_float_to_int32_a_avx; } if(channels == 8) { if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_FLTP || out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_8ch_float_to_float_a_avx; if( out_fmt == AV_SAMPLE_FMT_FLT && in_fmt == AV_SAMPLE_FMT_S32P) ac->simd_f = ff_pack_8ch_int32_to_float_a_avx; if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLTP) ac->simd_f = ff_pack_8ch_float_to_int32_a_avx; } } if(EXTERNAL_AVX2(mm_flags)) { if( out_fmt == AV_SAMPLE_FMT_S32 && in_fmt == AV_SAMPLE_FMT_FLT || out_fmt == AV_SAMPLE_FMT_S32P && in_fmt == AV_SAMPLE_FMT_FLTP) ac->simd_f = ff_float_to_int32_a_avx2; } }


int ff_unlock_avcodec(const AVCodec *codec) { _Bool exp = 1; if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init) return 0; av_assert0(atomic_compare_exchange_strong(&ff_avcodec_locked, &exp, 0)); atomic_fetch_add(&entangled_thread_counter, -1); if (lockmgr_cb) { if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE)) return -1; } return 0; }


static int ivi_decode_coded_blocks(GetBitContext *gb, IVIBandDesc *band, ivi_mc_func mc, int mv_x, int mv_y, int *prev_dc, int is_intra, int mc_type, uint32_t quant, int offs, AVCodecContext *avctx) { const uint16_t *base_tab = is_intra ? band->intra_base : band->inter_base; RVMapDesc *rvmap = band->rv_map; uint8_t col_flags[8]; int32_t trvec[64]; uint32_t sym = 0, lo, hi, q; int pos, run, val; int blk_size = band->blk_size; int num_coeffs = blk_size * blk_size; int col_mask = blk_size - 1; int scan_pos = -1; int min_size = band->pitch * (band->transform_size - 1) + band->transform_size; int buf_size = band->pitch * band->aheight - offs; if (min_size > buf_size) return AVERROR_INVALIDDATA; if (!band->scan) { av_log(avctx, AV_LOG_ERROR, "Scan pattern is not set.\n"); return AVERROR_INVALIDDATA; } /* zero transform vector */ memset(trvec, 0, num_coeffs * sizeof(trvec[0])); /* zero column flags */ memset(col_flags, 0, sizeof(col_flags)); while (scan_pos <= num_coeffs) { sym = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1); if (sym == rvmap->eob_sym) break; /* End of block */ /* Escape - run/val explicitly coded using 3 vlc codes */ if (sym == rvmap->esc_sym) { run = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1) + 1; lo = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1); hi = get_vlc2(gb, band->blk_vlc.tab->table, IVI_VLC_BITS, 1); /* merge them and convert into signed val */ val = IVI_TOSIGNED((hi << 6) | lo); } else { if (sym >= 256U) { av_log(avctx, AV_LOG_ERROR, "Invalid sym encountered: %d.\n", sym); return AVERROR_INVALIDDATA; } run = rvmap->runtab[sym]; val = rvmap->valtab[sym]; } /* de-zigzag and dequantize */ scan_pos += run; if (scan_pos >= num_coeffs || scan_pos < 0) break; pos = band->scan[scan_pos]; if (!val) av_dlog(avctx, "Val = 0 encountered!\n"); q = (base_tab[pos] * quant) >> 9; if (q > 1) val = val * q + FFSIGN(val) * (((q ^ 1) - 1) >> 1); trvec[pos] = val; /* track columns containing non-zero coeffs */ col_flags[pos & col_mask] |= !!val; } if (scan_pos < 0 || scan_pos >= num_coeffs && sym != rvmap->eob_sym) return AVERROR_INVALIDDATA; /* corrupt block data */ /* undoing DC coeff prediction for intra-blocks */ if (is_intra && band->is_2d_trans) { *prev_dc += trvec[0]; trvec[0] = *prev_dc; col_flags[0] |= !!*prev_dc; } /* apply inverse transform */ band->inv_transform(trvec, band->buf + offs, band->pitch, col_flags); /* apply motion compensation */ if (!is_intra) return ivi_mc(mc, band->buf, band->ref_buf, offs, mv_x, mv_y, band->pitch, mc_type); return 0; }


static void continue_send(IPMIBmcExtern *ibe) { if (ibe->outlen == 0) { goto check_reset; } send: ibe->outpos += qemu_chr_fe_write(ibe->chr, ibe->outbuf + ibe->outpos, ibe->outlen - ibe->outpos); if (ibe->outpos < ibe->outlen) { /* Not fully transmitted, try again in a 10ms */ timer_mod_ns(ibe->extern_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 10000000); } else { /* Sent */ ibe->outlen = 0; ibe->outpos = 0; if (!ibe->sending_cmd) { ibe->waiting_rsp = true; } else { ibe->sending_cmd = false; } check_reset: if (ibe->connected && ibe->send_reset) { /* Send the reset */ ibe->outbuf[0] = VM_CMD_RESET; ibe->outbuf[1] = VM_CMD_CHAR; ibe->outlen = 2; ibe->outpos = 0; ibe->send_reset = false; ibe->sending_cmd = true; goto send; } if (ibe->waiting_rsp) { /* Make sure we get a response within 4 seconds. */ timer_mod_ns(ibe->extern_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 4000000000ULL); } } return; }


static void sdhci_do_adma(SDHCIState *s) { unsigned int n, begin, length; const uint16_t block_size = s->blksize & 0x0fff; ADMADescr dscr; int i; for (i = 0; i < SDHC_ADMA_DESCS_PER_DELAY; ++i) { s->admaerr &= ~SDHC_ADMAERR_LENGTH_MISMATCH; get_adma_description(s, &dscr); DPRINT_L2("ADMA loop: addr=" TARGET_FMT_plx ", len=%d, attr=%x\n", dscr.addr, dscr.length, dscr.attr); if ((dscr.attr & SDHC_ADMA_ATTR_VALID) == 0) { /* Indicate that error occurred in ST_FDS state */ s->admaerr &= ~SDHC_ADMAERR_STATE_MASK; s->admaerr |= SDHC_ADMAERR_STATE_ST_FDS; /* Generate ADMA error interrupt */ if (s->errintstsen & SDHC_EISEN_ADMAERR) { s->errintsts |= SDHC_EIS_ADMAERR; s->norintsts |= SDHC_NIS_ERR; } sdhci_update_irq(s); return; } length = dscr.length ? dscr.length : 65536; switch (dscr.attr & SDHC_ADMA_ATTR_ACT_MASK) { case SDHC_ADMA_ATTR_ACT_TRAN: /* data transfer */ if (s->trnmod & SDHC_TRNS_READ) { while (length) { if (s->data_count == 0) { for (n = 0; n < block_size; n++) { s->fifo_buffer[n] = sdbus_read_data(&s->sdbus); } } begin = s->data_count; if ((length + begin) < block_size) { s->data_count = length + begin; length = 0; } else { s->data_count = block_size; length -= block_size - begin; } dma_memory_write(&address_space_memory, dscr.addr, &s->fifo_buffer[begin], s->data_count - begin); dscr.addr += s->data_count - begin; if (s->data_count == block_size) { s->data_count = 0; if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { s->blkcnt--; if (s->blkcnt == 0) { break; } } } } } else { while (length) { begin = s->data_count; if ((length + begin) < block_size) { s->data_count = length + begin; length = 0; } else { s->data_count = block_size; length -= block_size - begin; } dma_memory_read(&address_space_memory, dscr.addr, &s->fifo_buffer[begin], s->data_count - begin); dscr.addr += s->data_count - begin; if (s->data_count == block_size) { for (n = 0; n < block_size; n++) { sdbus_write_data(&s->sdbus, s->fifo_buffer[n]); } s->data_count = 0; if (s->trnmod & SDHC_TRNS_BLK_CNT_EN) { s->blkcnt--; if (s->blkcnt == 0) { break; } } } } } s->admasysaddr += dscr.incr; break; case SDHC_ADMA_ATTR_ACT_LINK: /* link to next descriptor table */ s->admasysaddr = dscr.addr; DPRINT_L1("ADMA link: admasysaddr=0x%" PRIx64 "\n", s->admasysaddr); break; default: s->admasysaddr += dscr.incr; break; } if (dscr.attr & SDHC_ADMA_ATTR_INT) { DPRINT_L1("ADMA interrupt: admasysaddr=0x%" PRIx64 "\n", s->admasysaddr); if (s->norintstsen & SDHC_NISEN_DMA) { s->norintsts |= SDHC_NIS_DMA; } sdhci_update_irq(s); } /* ADMA transfer terminates if blkcnt == 0 or by END attribute */ if (((s->trnmod & SDHC_TRNS_BLK_CNT_EN) && (s->blkcnt == 0)) || (dscr.attr & SDHC_ADMA_ATTR_END)) { DPRINT_L2("ADMA transfer completed\n"); if (length || ((dscr.attr & SDHC_ADMA_ATTR_END) && (s->trnmod & SDHC_TRNS_BLK_CNT_EN) && s->blkcnt != 0)) { ERRPRINT("SD/MMC host ADMA length mismatch\n"); s->admaerr |= SDHC_ADMAERR_LENGTH_MISMATCH | SDHC_ADMAERR_STATE_ST_TFR; if (s->errintstsen & SDHC_EISEN_ADMAERR) { ERRPRINT("Set ADMA error flag\n"); s->errintsts |= SDHC_EIS_ADMAERR; s->norintsts |= SDHC_NIS_ERR; } sdhci_update_irq(s); } sdhci_end_transfer(s); return; } } /* we have unfinished business - reschedule to continue ADMA */ timer_mod(s->transfer_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + SDHC_TRANSFER_DELAY); }


static int copy_sectors(BlockDriverState *bs, uint64_t start_sect, uint64_t cluster_offset, int n_start, int n_end) { BDRVQcowState *s = bs->opaque; int n, ret; void *buf; /* * If this is the last cluster and it is only partially used, we must only * copy until the end of the image, or bdrv_check_request will fail for the * bdrv_read/write calls below. */ if (start_sect + n_end > bs->total_sectors) { n_end = bs->total_sectors - start_sect; } n = n_end - n_start; if (n <= 0) { return 0; } buf = qemu_blockalign(bs, n * BDRV_SECTOR_SIZE); BLKDBG_EVENT(bs->file, BLKDBG_COW_READ); ret = bdrv_read(bs, start_sect + n_start, buf, n); if (ret < 0) { goto out; } if (s->crypt_method) { qcow2_encrypt_sectors(s, start_sect + n_start, buf, buf, n, 1, &s->aes_encrypt_key); } BLKDBG_EVENT(bs->file, BLKDBG_COW_WRITE); ret = bdrv_write(bs->file, (cluster_offset >> 9) + n_start, buf, n); if (ret < 0) { goto out; } ret = 0; out: qemu_vfree(buf); return ret; }


void arm_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr, unsigned size, MMUAccessType access_type, int mmu_idx, MemTxAttrs attrs, MemTxResult response, uintptr_t retaddr) { ARMCPU *cpu = ARM_CPU(cs); ARMMMUFaultInfo fi = {}; /* now we have a real cpu fault */ cpu_restore_state(cs, retaddr); /* The EA bit in syndromes and fault status registers is an * IMPDEF classification of external aborts. ARM implementations * usually use this to indicate AXI bus Decode error (0) or * Slave error (1); in QEMU we follow that. */ fi.ea = (response != MEMTX_DECODE_ERROR); fi.type = ARMFault_SyncExternal; deliver_fault(cpu, addr, access_type, mmu_idx, &fi); }


static int truemotion1_decode_header(TrueMotion1Context *s) { int i, ret; int width_shift = 0; int new_pix_fmt; struct frame_header header; uint8_t header_buffer[128] = { 0 }; /* logical maximum size of the header */ const uint8_t *sel_vector_table; header.header_size = ((s->buf[0] >> 5) | (s->buf[0] << 3)) & 0x7f; if (s->buf[0] < 0x10) { av_log(s->avctx, AV_LOG_ERROR, "invalid header size (%d)\n", s->buf[0]); /* unscramble the header bytes with a XOR operation */ for (i = 1; i < header.header_size; i++) header_buffer[i - 1] = s->buf[i] ^ s->buf[i + 1]; header.compression = header_buffer[0]; header.deltaset = header_buffer[1]; header.vectable = header_buffer[2]; header.ysize = AV_RL16(&header_buffer[3]); header.xsize = AV_RL16(&header_buffer[5]); header.checksum = AV_RL16(&header_buffer[7]); header.version = header_buffer[9]; header.header_type = header_buffer[10]; header.flags = header_buffer[11]; header.control = header_buffer[12]; /* Version 2 */ if (header.version >= 2) { if (header.header_type > 3) { av_log(s->avctx, AV_LOG_ERROR, "invalid header type (%d)\n", header.header_type); } else if ((header.header_type == 2) || (header.header_type == 3)) { s->flags = header.flags; if (!(s->flags & FLAG_INTERFRAME)) s->flags |= FLAG_KEYFRAME; } else s->flags = FLAG_KEYFRAME; } else /* Version 1 */ s->flags = FLAG_KEYFRAME; if (s->flags & FLAG_SPRITE) { avpriv_request_sample(s->avctx, "Frame with sprite"); /* FIXME header.width, height, xoffset and yoffset aren't initialized */ return AVERROR_PATCHWELCOME; } else { s->w = header.xsize; s->h = header.ysize; if (header.header_type < 2) { if ((s->w < 213) && (s->h >= 176)) { s->flags |= FLAG_INTERPOLATED; avpriv_request_sample(s->avctx, "Interpolated frame"); if (header.compression >= 17) { av_log(s->avctx, AV_LOG_ERROR, "invalid compression type (%d)\n", header.compression); if ((header.deltaset != s->last_deltaset) || (header.vectable != s->last_vectable)) select_delta_tables(s, header.deltaset); if ((header.compression & 1) && header.header_type) sel_vector_table = pc_tbl2; else { if (header.vectable > 0 && header.vectable < 4) sel_vector_table = tables[header.vectable - 1]; else { av_log(s->avctx, AV_LOG_ERROR, "invalid vector table id (%d)\n", header.vectable); if (compression_types[header.compression].algorithm == ALGO_RGB24H) { new_pix_fmt = AV_PIX_FMT_RGB32; width_shift = 1; } else new_pix_fmt = AV_PIX_FMT_RGB555; // RGB565 is supported as well s->w >>= width_shift; if (s->w != s->avctx->width || s->h != s->avctx->height || new_pix_fmt != s->avctx->pix_fmt) { av_frame_unref(s->frame); s->avctx->sample_aspect_ratio = (AVRational){ 1 << width_shift, 1 }; s->avctx->pix_fmt = new_pix_fmt; if ((ret = ff_set_dimensions(s->avctx, s->w, s->h)) < 0) return ret; av_fast_malloc(&s->vert_pred, &s->vert_pred_size, s->avctx->width * sizeof(unsigned int)); /* There is 1 change bit per 4 pixels, so each change byte represents * 32 pixels; divide width by 4 to obtain the number of change bits and * then round up to the nearest byte. */ s->mb_change_bits_row_size = ((s->avctx->width >> (2 - width_shift)) + 7) >> 3; if ((header.deltaset != s->last_deltaset) || (header.vectable != s->last_vectable)) { if (compression_types[header.compression].algorithm == ALGO_RGB24H) gen_vector_table24(s, sel_vector_table); else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB555) gen_vector_table15(s, sel_vector_table); else gen_vector_table16(s, sel_vector_table); /* set up pointers to the other key data chunks */ s->mb_change_bits = s->buf + header.header_size; if (s->flags & FLAG_KEYFRAME) { /* no change bits specified for a keyframe; only index bytes */ s->index_stream = s->mb_change_bits; } else { /* one change bit per 4x4 block */ s->index_stream = s->mb_change_bits + (s->mb_change_bits_row_size * (s->avctx->height >> 2)); s->index_stream_size = s->size - (s->index_stream - s->buf); s->last_deltaset = header.deltaset; s->last_vectable = header.vectable; s->compression = header.compression; s->block_width = compression_types[header.compression].block_width; s->block_height = compression_types[header.compression].block_height; s->block_type = compression_types[header.compression].block_type; if (s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_INFO, "tables: %d / %d c:%d %dx%d t:%d %s%s%s%s\n", s->last_deltaset, s->last_vectable, s->compression, s->block_width, s->block_height, s->block_type, s->flags & FLAG_KEYFRAME ? " KEY" : "", s->flags & FLAG_INTERFRAME ? " INTER" : "", s->flags & FLAG_SPRITE ? " SPRITE" : "", s->flags & FLAG_INTERPOLATED ? " INTERPOL" : ""); return header.header_size;


static av_always_inline void RENAME(decode_line)(FFV1Context *s, int w, TYPE *sample[2], int plane_index, int bits) { PlaneContext *const p = &s->plane[plane_index]; RangeCoder *const c = &s->c; int x; int run_count = 0; int run_mode = 0; int run_index = s->run_index; if (s->slice_coding_mode == 1) { int i; for (x = 0; x < w; x++) { int v = 0; for (i=0; i<bits; i++) { uint8_t state = 128; v += v + get_rac(c, &state); } sample[1][x] = v; } return; } for (x = 0; x < w; x++) { int diff, context, sign; context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x); if (context < 0) { context = -context; sign = 1; } else sign = 0; av_assert2(context < p->context_count); if (s->ac != AC_GOLOMB_RICE) { diff = get_symbol_inline(c, p->state[context], 1); } else { if (context == 0 && run_mode == 0) run_mode = 1; if (run_mode) { if (run_count == 0 && run_mode == 1) { if (get_bits1(&s->gb)) { run_count = 1 << ff_log2_run[run_index]; if (x + run_count <= w) run_index++; } else { if (ff_log2_run[run_index]) run_count = get_bits(&s->gb, ff_log2_run[run_index]); else run_count = 0; if (run_index) run_index--; run_mode = 2; } } run_count--; if (run_count < 0) { run_mode = 0; run_count = 0; diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits); if (diff >= 0) diff++; } else diff = 0; } else diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits); ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", run_count, run_index, run_mode, x, get_bits_count(&s->gb)); } if (sign) diff = -diff; sample[1][x] = av_mod_uintp2(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits); } s->run_index = run_index; }


static int bochs_open(BlockDriverState *bs, int flags) { BDRVBochsState *s = bs->opaque; int i; struct bochs_header bochs; struct bochs_header_v1 header_v1; bs->read_only = 1; // no write support yet if (bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)) != sizeof(bochs)) { goto fail; } if (strcmp(bochs.magic, HEADER_MAGIC) || strcmp(bochs.type, REDOLOG_TYPE) || strcmp(bochs.subtype, GROWING_TYPE) || ((le32_to_cpu(bochs.version) != HEADER_VERSION) && (le32_to_cpu(bochs.version) != HEADER_V1))) { return -EMEDIUMTYPE; } if (le32_to_cpu(bochs.version) == HEADER_V1) { memcpy(&header_v1, &bochs, sizeof(bochs)); bs->total_sectors = le64_to_cpu(header_v1.extra.redolog.disk) / 512; } else { bs->total_sectors = le64_to_cpu(bochs.extra.redolog.disk) / 512; } s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog); s->catalog_bitmap = g_malloc(s->catalog_size * 4); if (bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap, s->catalog_size * 4) != s->catalog_size * 4) goto fail; for (i = 0; i < s->catalog_size; i++) le32_to_cpus(&s->catalog_bitmap[i]); s->data_offset = le32_to_cpu(bochs.header) + (s->catalog_size * 4); s->bitmap_blocks = 1 + (le32_to_cpu(bochs.extra.redolog.bitmap) - 1) / 512; s->extent_blocks = 1 + (le32_to_cpu(bochs.extra.redolog.extent) - 1) / 512; s->extent_size = le32_to_cpu(bochs.extra.redolog.extent); qemu_co_mutex_init(&s->lock); return 0; fail: return -1; }


static void set_alarm (m48t59_t *NVRAM, struct tm *tm) { NVRAM->alarm = mktime(tm); if (NVRAM->alrm_timer != NULL) { qemu_del_timer(NVRAM->alrm_timer); NVRAM->alrm_timer = NULL; } if (NVRAM->alarm - time(NULL) > 0) qemu_mod_timer(NVRAM->alrm_timer, NVRAM->alarm * 1000); }


static void i440fx_pcihost_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass); hc->root_bus_path = i440fx_pcihost_root_bus_path; dc->realize = i440fx_pcihost_realize; dc->fw_name = "pci"; dc->props = i440fx_props; }


static void init_parse_context(OptionParseContext *octx, const OptionGroupDef *groups, int nb_groups) { static const OptionGroupDef global_group = { "global" }; int i; memset(octx, 0, sizeof(*octx)); octx->nb_groups = nb_groups; octx->groups = av_mallocz(sizeof(*octx->groups) * octx->nb_groups); if (!octx->groups) exit(1); for (i = 0; i < octx->nb_groups; i++) octx->groups[i].group_def = &groups[i]; octx->global_opts.group_def = &global_group; octx->global_opts.arg = ""; init_opts(); }


int ff_mov_read_chan(AVFormatContext *s, AVStream *st, int64_t size) { AVIOContext *pb = s->pb; uint32_t layout_tag, bitmap, num_descr, label_mask; int i; if (size < 12) return AVERROR_INVALIDDATA; layout_tag = avio_rb32(pb); bitmap = avio_rb32(pb); num_descr = avio_rb32(pb); av_dlog(s, "chan: layout=%u bitmap=%u num_descr=%u\n", layout_tag, bitmap, num_descr); if (size < 12ULL + num_descr * 20ULL) return 0; label_mask = 0; for (i = 0; i < num_descr; i++) { uint32_t label; label = avio_rb32(pb); // mChannelLabel avio_rb32(pb); // mChannelFlags avio_rl32(pb); // mCoordinates[0] avio_rl32(pb); // mCoordinates[1] avio_rl32(pb); // mCoordinates[2] if (layout_tag == 0) { uint32_t mask_incr = mov_get_channel_label(label); if (mask_incr == 0) { label_mask = 0; break; } label_mask |= mask_incr; } } if (layout_tag == 0) st->codec->channel_layout = label_mask; else st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap); return 0; }


void microblaze_load_kernel(MicroBlazeCPU *cpu, hwaddr ddr_base, uint32_t ramsize, const char *initrd_filename, const char *dtb_filename, void (*machine_cpu_reset)(MicroBlazeCPU *)) { QemuOpts *machine_opts; const char *kernel_filename; const char *kernel_cmdline; const char *dtb_arg; machine_opts = qemu_get_machine_opts(); kernel_filename = qemu_opt_get(machine_opts, "kernel"); kernel_cmdline = qemu_opt_get(machine_opts, "append"); dtb_arg = qemu_opt_get(machine_opts, "dtb"); if (dtb_arg) { /* Preference a -dtb argument */ dtb_filename = dtb_arg; } else { /* default to pcbios dtb as passed by machine_init */ dtb_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, dtb_filename); } boot_info.machine_cpu_reset = machine_cpu_reset; qemu_register_reset(main_cpu_reset, cpu); if (kernel_filename) { int kernel_size; uint64_t entry, low, high; uint32_t base32; int big_endian = 0; #ifdef TARGET_WORDS_BIGENDIAN big_endian = 1; #endif /* Boots a kernel elf binary. */ kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, &low, &high, big_endian, ELF_MACHINE, 0); base32 = entry; if (base32 == 0xc0000000) { kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL, &entry, NULL, NULL, big_endian, ELF_MACHINE, 0); } /* Always boot into physical ram. */ boot_info.bootstrap_pc = ddr_base + (entry & 0x0fffffff); /* If it wasn't an ELF image, try an u-boot image. */ if (kernel_size < 0) { hwaddr uentry, loadaddr; kernel_size = load_uimage(kernel_filename, &uentry, &loadaddr, 0); boot_info.bootstrap_pc = uentry; high = (loadaddr + kernel_size + 3) & ~3; } /* Not an ELF image nor an u-boot image, try a RAW image. */ if (kernel_size < 0) { kernel_size = load_image_targphys(kernel_filename, ddr_base, ram_size); boot_info.bootstrap_pc = ddr_base; high = (ddr_base + kernel_size + 3) & ~3; } if (initrd_filename) { int initrd_size; uint32_t initrd_offset; high = ROUND_UP(high + kernel_size, 4); boot_info.initrd_start = high; initrd_offset = boot_info.initrd_start - ddr_base; initrd_size = load_ramdisk(initrd_filename, boot_info.initrd_start, ram_size - initrd_offset); if (initrd_size < 0) { initrd_size = load_image_targphys(initrd_filename, boot_info.initrd_start, ram_size - initrd_offset); } if (initrd_size < 0) { error_report("qemu: could not load initrd '%s'\n", initrd_filename); exit(EXIT_FAILURE); } boot_info.initrd_end = boot_info.initrd_start + initrd_size; high = ROUND_UP(high + initrd_size, 4); } boot_info.cmdline = high + 4096; if (kernel_cmdline && strlen(kernel_cmdline)) { pstrcpy_targphys("cmdline", boot_info.cmdline, 256, kernel_cmdline); } /* Provide a device-tree. */ boot_info.fdt = boot_info.cmdline + 4096; microblaze_load_dtb(boot_info.fdt, ram_size, boot_info.initrd_start, boot_info.initrd_end, kernel_cmdline, dtb_filename); } }


static int kvm_ppc_register_host_cpu_type(void) { TypeInfo type_info = { .name = TYPE_HOST_POWERPC_CPU, .class_init = kvmppc_host_cpu_class_init, }; PowerPCCPUClass *pvr_pcc; DeviceClass *dc; int i; pvr_pcc = kvm_ppc_get_host_cpu_class(); if (pvr_pcc == NULL) { return -1; } type_info.parent = object_class_get_name(OBJECT_CLASS(pvr_pcc)); type_register(&type_info); #if defined(TARGET_PPC64) type_info.name = g_strdup_printf("%s-"TYPE_SPAPR_CPU_CORE, "host"); type_info.parent = TYPE_SPAPR_CPU_CORE, type_info.instance_size = sizeof(sPAPRCPUCore); type_info.instance_init = NULL; type_info.class_init = spapr_cpu_core_class_init; type_info.class_data = (void *) "host"; type_register(&type_info); g_free((void *)type_info.name); #endif /* * Update generic CPU family class alias (e.g. on a POWER8NVL host, * we want "POWER8" to be a "family" alias that points to the current * host CPU type, too) */ dc = DEVICE_CLASS(ppc_cpu_get_family_class(pvr_pcc)); for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) { if (strcmp(ppc_cpu_aliases[i].alias, dc->desc) == 0) { ObjectClass *oc = OBJECT_CLASS(pvr_pcc); char *suffix; ppc_cpu_aliases[i].model = g_strdup(object_class_get_name(oc)); suffix = strstr(ppc_cpu_aliases[i].model, "-"TYPE_POWERPC_CPU); if (suffix) { *suffix = 0; } ppc_cpu_aliases[i].oc = oc; break; } } return 0; }