static void result_to_network(RDMARegisterResult *result) { result->rkey = htonl(result->rkey); result->host_addr = htonll(result->host_addr); };


static int nprobe(AVFormatContext *s, uint8_t *enc_header, int size, const uint8_t *n_val) { OMAContext *oc = s->priv_data; uint32_t pos, taglen, datalen; struct AVDES av_des; if (!enc_header || !n_val) return -1; pos = OMA_ENC_HEADER_SIZE + oc->k_size; if (!memcmp(&enc_header[pos], "EKB ", 4)) pos += 32; if (AV_RB32(&enc_header[pos]) != oc->rid) av_log(s, AV_LOG_DEBUG, "Mismatching RID\n"); taglen = AV_RB32(&enc_header[pos + 32]); datalen = AV_RB32(&enc_header[pos + 36]) >> 4; if (taglen + (((uint64_t)datalen) << 4) + 44 > size) return -1; pos += 44 + taglen; av_des_init(&av_des, n_val, 192, 1); while (datalen-- > 0) { av_des_crypt(&av_des, oc->r_val, &enc_header[pos], 2, NULL, 1); kset(s, oc->r_val, NULL, 16); if (!rprobe(s, enc_header, oc->r_val)) return 0; pos += 16; } return -1; }


static AVFrame *do_vmaf(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref) { LIBVMAFContext *s = ctx->priv; pthread_mutex_lock(&s->lock); while (s->frame_set != 0) { pthread_cond_wait(&s->cond, &s->lock); } av_frame_ref(s->gref, ref); av_frame_ref(s->gmain, main); s->frame_set = 1; pthread_cond_signal(&s->cond); pthread_mutex_unlock(&s->lock); return main; }


int ff_audio_interleave_init(AVFormatContext *s, const int *samples_per_frame, AVRational time_base) { int i; if (!samples_per_frame) return -1; if (!time_base.num) { av_log(s, AV_LOG_ERROR, "timebase not set for audio interleave\n"); return -1; } for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; AudioInterleaveContext *aic = st->priv_data; if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { aic->sample_size = (st->codec->channels * av_get_bits_per_sample(st->codec->codec_id)) / 8; if (!aic->sample_size) { av_log(s, AV_LOG_ERROR, "could not compute sample size\n"); return -1; } aic->samples_per_frame = samples_per_frame; aic->samples = aic->samples_per_frame; aic->time_base = time_base; aic->fifo_size = 100* *aic->samples; aic->fifo= av_fifo_alloc_array(100, *aic->samples); } } return 0; }


static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path, const char *name, FsCred *credp) { char *path; int err = -1; int serrno = 0; V9fsString fullname; char *buffer = NULL; v9fs_string_init(&fullname); v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name); path = fullname.data; /* Determine the security model */ if (fs_ctx->export_flags & V9FS_SM_MAPPED) { buffer = rpath(fs_ctx, path); err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS); if (err == -1) { goto out; } credp->fc_mode = credp->fc_mode|S_IFDIR; err = local_set_xattr(buffer, credp); if (err == -1) { serrno = errno; goto err_end; } } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { buffer = rpath(fs_ctx, path); err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS); if (err == -1) { goto out; } credp->fc_mode = credp->fc_mode|S_IFDIR; err = local_set_mapped_file_attr(fs_ctx, path, credp); if (err == -1) { serrno = errno; goto err_end; } } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) || (fs_ctx->export_flags & V9FS_SM_NONE)) { buffer = rpath(fs_ctx, path); err = mkdir(buffer, credp->fc_mode); if (err == -1) { goto out; } err = local_post_create_passthrough(fs_ctx, path, credp); if (err == -1) { serrno = errno; goto err_end; } } goto out; err_end: remove(buffer); errno = serrno; out: g_free(buffer); v9fs_string_free(&fullname); return err; }


static void fd_revalidate(FDrive *drv) { int rc; FLOPPY_DPRINTF("revalidate\n"); if (drv->blk != NULL) { drv->ro = blk_is_read_only(drv->blk); if (!blk_is_inserted(drv->blk)) { FLOPPY_DPRINTF("No disk in drive\n"); drv->disk = FLOPPY_DRIVE_TYPE_NONE; } else if (!drv->media_validated) { rc = pick_geometry(drv); if (rc) { FLOPPY_DPRINTF("Could not validate floppy drive media"); } else { drv->media_validated = true; FLOPPY_DPRINTF("Floppy disk (%d h %d t %d s) %s\n", (drv->flags & FDISK_DBL_SIDES) ? 2 : 1, drv->max_track, drv->last_sect, drv->ro ? "ro" : "rw"); } } } else { FLOPPY_DPRINTF("No drive connected\n"); drv->last_sect = 0; drv->max_track = 0; drv->flags &= ~FDISK_DBL_SIDES; drv->drive = FLOPPY_DRIVE_TYPE_NONE; drv->disk = FLOPPY_DRIVE_TYPE_NONE; } }


static coroutine_fn void reconnect_to_sdog(void *opaque) { Error *local_err = NULL; BDRVSheepdogState *s = opaque; AIOReq *aio_req, *next; aio_set_fd_handler(s->aio_context, s->fd, NULL, NULL, NULL); close(s->fd); s->fd = -1; /* Wait for outstanding write requests to be completed. */ while (s->co_send != NULL) { co_write_request(opaque); } /* Try to reconnect the sheepdog server every one second. */ while (s->fd < 0) { s->fd = get_sheep_fd(s, &local_err); if (s->fd < 0) { DPRINTF("Wait for connection to be established\n"); error_report("%s", error_get_pretty(local_err)); error_free(local_err); co_aio_sleep_ns(bdrv_get_aio_context(s->bs), QEMU_CLOCK_REALTIME, 1000000000ULL); } }; /* * Now we have to resend all the request in the inflight queue. However, * resend_aioreq() can yield and newly created requests can be added to the * inflight queue before the coroutine is resumed. To avoid mixing them, we * have to move all the inflight requests to the failed queue before * resend_aioreq() is called. */ QLIST_FOREACH_SAFE(aio_req, &s->inflight_aio_head, aio_siblings, next) { QLIST_REMOVE(aio_req, aio_siblings); QLIST_INSERT_HEAD(&s->failed_aio_head, aio_req, aio_siblings); } /* Resend all the failed aio requests. */ while (!QLIST_EMPTY(&s->failed_aio_head)) { aio_req = QLIST_FIRST(&s->failed_aio_head); QLIST_REMOVE(aio_req, aio_siblings); QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); resend_aioreq(s, aio_req); } }


static void set_frame_distances(MpegEncContext * s){ assert(s->current_picture_ptr->f.pts != AV_NOPTS_VALUE); s->time = s->current_picture_ptr->f.pts * s->avctx->time_base.num; if(s->pict_type==AV_PICTURE_TYPE_B){ s->pb_time= s->pp_time - (s->last_non_b_time - s->time); assert(s->pb_time > 0 && s->pb_time < s->pp_time); }else{ s->pp_time= s->time - s->last_non_b_time; s->last_non_b_time= s->time; assert(s->picture_number==0 || s->pp_time > 0); } }


static void load_tc(QEMUFile *f, TCState *tc) { int i; /* Save active TC */ for(i = 0; i < 32; i++) qemu_get_betls(f, &tc->gpr[i]); qemu_get_betls(f, &tc->PC); for(i = 0; i < MIPS_DSP_ACC; i++) qemu_get_betls(f, &tc->HI[i]); for(i = 0; i < MIPS_DSP_ACC; i++) qemu_get_betls(f, &tc->LO[i]); for(i = 0; i < MIPS_DSP_ACC; i++) qemu_get_betls(f, &tc->ACX[i]); qemu_get_betls(f, &tc->DSPControl); qemu_get_sbe32s(f, &tc->CP0_TCStatus); qemu_get_sbe32s(f, &tc->CP0_TCBind); qemu_get_betls(f, &tc->CP0_TCHalt); qemu_get_betls(f, &tc->CP0_TCContext); qemu_get_betls(f, &tc->CP0_TCSchedule); qemu_get_betls(f, &tc->CP0_TCScheFBack); qemu_get_sbe32s(f, &tc->CP0_Debug_tcstatus); }


static inline void RENAME(rgb16to24)(const uint8_t *src, uint8_t *dst, long src_size) { const uint16_t *end; #ifdef HAVE_MMX const uint16_t *mm_end; #endif uint8_t *d = (uint8_t *)dst; const uint16_t *s = (const uint16_t *)src; end = s + src_size/2; #ifdef HAVE_MMX __asm __volatile(PREFETCH" %0"::"m"(*s):"memory"); mm_end = end - 7; while(s < mm_end) { __asm __volatile( PREFETCH" 32%1\n\t" "movq %1, %%mm0\n\t" "movq %1, %%mm1\n\t" "movq %1, %%mm2\n\t" "pand %2, %%mm0\n\t" "pand %3, %%mm1\n\t" "pand %4, %%mm2\n\t" "psllq $3, %%mm0\n\t" "psrlq $3, %%mm1\n\t" "psrlq $8, %%mm2\n\t" "movq %%mm0, %%mm3\n\t" "movq %%mm1, %%mm4\n\t" "movq %%mm2, %%mm5\n\t" "punpcklwd %5, %%mm0\n\t" "punpcklwd %5, %%mm1\n\t" "punpcklwd %5, %%mm2\n\t" "punpckhwd %5, %%mm3\n\t" "punpckhwd %5, %%mm4\n\t" "punpckhwd %5, %%mm5\n\t" "psllq $8, %%mm1\n\t" "psllq $16, %%mm2\n\t" "por %%mm1, %%mm0\n\t" "por %%mm2, %%mm0\n\t" "psllq $8, %%mm4\n\t" "psllq $16, %%mm5\n\t" "por %%mm4, %%mm3\n\t" "por %%mm5, %%mm3\n\t" "movq %%mm0, %%mm6\n\t" "movq %%mm3, %%mm7\n\t" "movq 8%1, %%mm0\n\t" "movq 8%1, %%mm1\n\t" "movq 8%1, %%mm2\n\t" "pand %2, %%mm0\n\t" "pand %3, %%mm1\n\t" "pand %4, %%mm2\n\t" "psllq $3, %%mm0\n\t" "psrlq $3, %%mm1\n\t" "psrlq $8, %%mm2\n\t" "movq %%mm0, %%mm3\n\t" "movq %%mm1, %%mm4\n\t" "movq %%mm2, %%mm5\n\t" "punpcklwd %5, %%mm0\n\t" "punpcklwd %5, %%mm1\n\t" "punpcklwd %5, %%mm2\n\t" "punpckhwd %5, %%mm3\n\t" "punpckhwd %5, %%mm4\n\t" "punpckhwd %5, %%mm5\n\t" "psllq $8, %%mm1\n\t" "psllq $16, %%mm2\n\t" "por %%mm1, %%mm0\n\t" "por %%mm2, %%mm0\n\t" "psllq $8, %%mm4\n\t" "psllq $16, %%mm5\n\t" "por %%mm4, %%mm3\n\t" "por %%mm5, %%mm3\n\t" :"=m"(*d) :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null) :"memory"); /* Borrowed 32 to 24 */ __asm __volatile( "movq %%mm0, %%mm4\n\t" "movq %%mm3, %%mm5\n\t" "movq %%mm6, %%mm0\n\t" "movq %%mm7, %%mm1\n\t" "movq %%mm4, %%mm6\n\t" "movq %%mm5, %%mm7\n\t" "movq %%mm0, %%mm2\n\t" "movq %%mm1, %%mm3\n\t" "psrlq $8, %%mm2\n\t" "psrlq $8, %%mm3\n\t" "psrlq $8, %%mm6\n\t" "psrlq $8, %%mm7\n\t" "pand %2, %%mm0\n\t" "pand %2, %%mm1\n\t" "pand %2, %%mm4\n\t" "pand %2, %%mm5\n\t" "pand %3, %%mm2\n\t" "pand %3, %%mm3\n\t" "pand %3, %%mm6\n\t" "pand %3, %%mm7\n\t" "por %%mm2, %%mm0\n\t" "por %%mm3, %%mm1\n\t" "por %%mm6, %%mm4\n\t" "por %%mm7, %%mm5\n\t" "movq %%mm1, %%mm2\n\t" "movq %%mm4, %%mm3\n\t" "psllq $48, %%mm2\n\t" "psllq $32, %%mm3\n\t" "pand %4, %%mm2\n\t" "pand %5, %%mm3\n\t" "por %%mm2, %%mm0\n\t" "psrlq $16, %%mm1\n\t" "psrlq $32, %%mm4\n\t" "psllq $16, %%mm5\n\t" "por %%mm3, %%mm1\n\t" "pand %6, %%mm5\n\t" "por %%mm5, %%mm4\n\t" MOVNTQ" %%mm0, %0\n\t" MOVNTQ" %%mm1, 8%0\n\t" MOVNTQ" %%mm4, 16%0" :"=m"(*d) :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) :"memory"); d += 24; s += 8; } __asm __volatile(SFENCE:::"memory"); __asm __volatile(EMMS:::"memory"); #endif while(s < end) { register uint16_t bgr; bgr = *s++; *d++ = (bgr&0x1F)<<3; *d++ = (bgr&0x7E0)>>3; *d++ = (bgr&0xF800)>>8; } }


int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps) { HEVCSPS *sps = NULL; int i, ret = 0; unsigned int pps_id = 0; ptrdiff_t nal_size; AVBufferRef *pps_buf; HEVCPPS *pps = av_mallocz(sizeof(*pps)); if (!pps) return AVERROR(ENOMEM); pps_buf = av_buffer_create((uint8_t *)pps, sizeof(*pps), hevc_pps_free, NULL, 0); if (!pps_buf) { av_freep(&pps); return AVERROR(ENOMEM); } av_log(avctx, AV_LOG_DEBUG, "Decoding PPS\n"); nal_size = gb->buffer_end - gb->buffer; if (nal_size > sizeof(pps->data)) { av_log(avctx, AV_LOG_WARNING, "Truncating likely oversized PPS " "(%"PTRDIFF_SPECIFIER" > %"SIZE_SPECIFIER")\n", nal_size, sizeof(pps->data)); pps->data_size = sizeof(pps->data); } else { pps->data_size = nal_size; } memcpy(pps->data, gb->buffer, pps->data_size); // Default values pps->loop_filter_across_tiles_enabled_flag = 1; pps->num_tile_columns = 1; pps->num_tile_rows = 1; pps->uniform_spacing_flag = 1; pps->disable_dbf = 0; pps->beta_offset = 0; pps->tc_offset = 0; pps->log2_max_transform_skip_block_size = 2; // Coded parameters pps_id = get_ue_golomb_long(gb); if (pps_id >= HEVC_MAX_PPS_COUNT) { av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); ret = AVERROR_INVALIDDATA; goto err; } pps->sps_id = get_ue_golomb_long(gb); if (pps->sps_id >= HEVC_MAX_SPS_COUNT) { av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id); ret = AVERROR_INVALIDDATA; goto err; } if (!ps->sps_list[pps->sps_id]) { av_log(avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id); ret = AVERROR_INVALIDDATA; goto err; } sps = (HEVCSPS *)ps->sps_list[pps->sps_id]->data; pps->dependent_slice_segments_enabled_flag = get_bits1(gb); pps->output_flag_present_flag = get_bits1(gb); pps->num_extra_slice_header_bits = get_bits(gb, 3); pps->sign_data_hiding_flag = get_bits1(gb); pps->cabac_init_present_flag = get_bits1(gb); pps->num_ref_idx_l0_default_active = get_ue_golomb_long(gb) + 1; pps->num_ref_idx_l1_default_active = get_ue_golomb_long(gb) + 1; pps->pic_init_qp_minus26 = get_se_golomb(gb); pps->constrained_intra_pred_flag = get_bits1(gb); pps->transform_skip_enabled_flag = get_bits1(gb); pps->cu_qp_delta_enabled_flag = get_bits1(gb); pps->diff_cu_qp_delta_depth = 0; if (pps->cu_qp_delta_enabled_flag) pps->diff_cu_qp_delta_depth = get_ue_golomb_long(gb); if (pps->diff_cu_qp_delta_depth < 0 || pps->diff_cu_qp_delta_depth > sps->log2_diff_max_min_coding_block_size) { av_log(avctx, AV_LOG_ERROR, "diff_cu_qp_delta_depth %d is invalid\n", pps->diff_cu_qp_delta_depth); ret = AVERROR_INVALIDDATA; goto err; } pps->cb_qp_offset = get_se_golomb(gb); if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) { av_log(avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n", pps->cb_qp_offset); ret = AVERROR_INVALIDDATA; goto err; } pps->cr_qp_offset = get_se_golomb(gb); if (pps->cr_qp_offset < -12 || pps->cr_qp_offset > 12) { av_log(avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n", pps->cr_qp_offset); ret = AVERROR_INVALIDDATA; goto err; } pps->pic_slice_level_chroma_qp_offsets_present_flag = get_bits1(gb); pps->weighted_pred_flag = get_bits1(gb); pps->weighted_bipred_flag = get_bits1(gb); pps->transquant_bypass_enable_flag = get_bits1(gb); pps->tiles_enabled_flag = get_bits1(gb); pps->entropy_coding_sync_enabled_flag = get_bits1(gb); if (pps->tiles_enabled_flag) { pps->num_tile_columns = get_ue_golomb_long(gb) + 1; pps->num_tile_rows = get_ue_golomb_long(gb) + 1; if (pps->num_tile_columns <= 0 || pps->num_tile_columns >= sps->width) { av_log(avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n", pps->num_tile_columns - 1); ret = AVERROR_INVALIDDATA; goto err; } if (pps->num_tile_rows <= 0 || pps->num_tile_rows >= sps->height) { av_log(avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n", pps->num_tile_rows - 1); ret = AVERROR_INVALIDDATA; goto err; } pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width)); pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height)); if (!pps->column_width || !pps->row_height) { ret = AVERROR(ENOMEM); goto err; } pps->uniform_spacing_flag = get_bits1(gb); if (!pps->uniform_spacing_flag) { uint64_t sum = 0; for (i = 0; i < pps->num_tile_columns - 1; i++) { pps->column_width[i] = get_ue_golomb_long(gb) + 1; sum += pps->column_width[i]; } if (sum >= sps->ctb_width) { av_log(avctx, AV_LOG_ERROR, "Invalid tile widths.\n"); ret = AVERROR_INVALIDDATA; goto err; } pps->column_width[pps->num_tile_columns - 1] = sps->ctb_width - sum; sum = 0; for (i = 0; i < pps->num_tile_rows - 1; i++) { pps->row_height[i] = get_ue_golomb_long(gb) + 1; sum += pps->row_height[i]; } if (sum >= sps->ctb_height) { av_log(avctx, AV_LOG_ERROR, "Invalid tile heights.\n"); ret = AVERROR_INVALIDDATA; goto err; } pps->row_height[pps->num_tile_rows - 1] = sps->ctb_height - sum; } pps->loop_filter_across_tiles_enabled_flag = get_bits1(gb); } pps->seq_loop_filter_across_slices_enabled_flag = get_bits1(gb); pps->deblocking_filter_control_present_flag = get_bits1(gb); if (pps->deblocking_filter_control_present_flag) { pps->deblocking_filter_override_enabled_flag = get_bits1(gb); pps->disable_dbf = get_bits1(gb); if (!pps->disable_dbf) { int beta_offset_div2 = get_se_golomb(gb); int tc_offset_div2 = get_se_golomb(gb) ; if (beta_offset_div2 < -6 || beta_offset_div2 > 6) { av_log(avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n", beta_offset_div2); ret = AVERROR_INVALIDDATA; goto err; } if (tc_offset_div2 < -6 || tc_offset_div2 > 6) { av_log(avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n", tc_offset_div2); ret = AVERROR_INVALIDDATA; goto err; } pps->beta_offset = 2 * beta_offset_div2; pps->tc_offset = 2 * tc_offset_div2; } } pps->scaling_list_data_present_flag = get_bits1(gb); if (pps->scaling_list_data_present_flag) { set_default_scaling_list_data(&pps->scaling_list); ret = scaling_list_data(gb, avctx, &pps->scaling_list, sps); if (ret < 0) goto err; } pps->lists_modification_present_flag = get_bits1(gb); pps->log2_parallel_merge_level = get_ue_golomb_long(gb) + 2; if (pps->log2_parallel_merge_level > sps->log2_ctb_size) { av_log(avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n", pps->log2_parallel_merge_level - 2); ret = AVERROR_INVALIDDATA; goto err; } pps->slice_header_extension_present_flag = get_bits1(gb); if (get_bits1(gb)) { // pps_extension_present_flag int pps_range_extensions_flag = get_bits1(gb); /* int pps_extension_7bits = */ get_bits(gb, 7); if (sps->ptl.general_ptl.profile_idc == FF_PROFILE_HEVC_REXT && pps_range_extensions_flag) { if ((ret = pps_range_extensions(gb, avctx, pps, sps)) < 0) goto err; } } ret = setup_pps(avctx, gb, pps, sps); if (ret < 0) goto err; if (get_bits_left(gb) < 0) { av_log(avctx, AV_LOG_ERROR, "Overread PPS by %d bits\n", -get_bits_left(gb)); goto err; } remove_pps(ps, pps_id); ps->pps_list[pps_id] = pps_buf; return 0; err: av_buffer_unref(&pps_buf); return ret; }


static inline int onenand_erase(OneNANDState *s, int sec, int num) { uint8_t *blankbuf, *tmpbuf; blankbuf = g_malloc(512); tmpbuf = g_malloc(512); memset(blankbuf, 0xff, 512); for (; num > 0; num--, sec++) { if (s->blk_cur) { int erasesec = s->secs_cur + (sec >> 5); if (blk_write(s->blk_cur, sec, blankbuf, 1) < 0) { goto fail; } if (blk_read(s->blk_cur, erasesec, tmpbuf, 1) < 0) { goto fail; } memcpy(tmpbuf + ((sec & 31) << 4), blankbuf, 1 << 4); if (blk_write(s->blk_cur, erasesec, tmpbuf, 1) < 0) { goto fail; } } else { if (sec + 1 > s->secs_cur) { goto fail; } memcpy(s->current + (sec << 9), blankbuf, 512); memcpy(s->current + (s->secs_cur << 9) + (sec << 4), blankbuf, 1 << 4); } } g_free(tmpbuf); g_free(blankbuf); return 0; fail: g_free(tmpbuf); g_free(blankbuf); return 1; }


static av_cold int cinepak_encode_init(AVCodecContext *avctx) { CinepakEncContext *s = avctx->priv_data; int x, mb_count, strip_buf_size, frame_buf_size; if (avctx->width & 3 || avctx->height & 3) { av_log(avctx, AV_LOG_ERROR, "width and height must be multiples of four (got %ix%i)\n", avctx->width, avctx->height); return AVERROR(EINVAL); } if (!(s->codebook_input = av_malloc(sizeof(int) * (avctx->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4) * (avctx->width * avctx->height) >> 2))) return AVERROR(ENOMEM); if (!(s->codebook_closest = av_malloc(sizeof(int) * (avctx->width * avctx->height) >> 2))) goto enomem; for(x = 0; x < 3; x++) if(!(s->pict_bufs[x] = av_malloc((avctx->pix_fmt == AV_PIX_FMT_YUV420P ? 6 : 4) * (avctx->width * avctx->height) >> 2))) goto enomem; mb_count = avctx->width * avctx->height / MB_AREA; //the largest possible chunk is 0x31 with all MBs encoded in V4 mode, which is 34 bits per MB strip_buf_size = STRIP_HEADER_SIZE + 3 * CHUNK_HEADER_SIZE + 2 * VECTOR_MAX * CODEBOOK_MAX + 4 * (mb_count + (mb_count + 15) / 16); frame_buf_size = CVID_HEADER_SIZE + MAX_STRIPS * strip_buf_size; if (!(s->strip_buf = av_malloc(strip_buf_size))) goto enomem; if (!(s->frame_buf = av_malloc(frame_buf_size))) goto enomem; if (!(s->mb = av_malloc(mb_count*sizeof(mb_info)))) goto enomem; #ifdef CINEPAKENC_DEBUG if (!(s->best_mb = av_malloc(mb_count*sizeof(mb_info)))) goto enomem; #endif av_lfg_init(&s->randctx, 1); s->avctx = avctx; s->w = avctx->width; s->h = avctx->height; s->curframe = 0; s->keyint = avctx->keyint_min; s->pix_fmt = avctx->pix_fmt; //set up AVFrames s->last_frame.data[0] = s->pict_bufs[0]; s->last_frame.linesize[0] = s->w; s->best_frame.data[0] = s->pict_bufs[1]; s->best_frame.linesize[0] = s->w; s->scratch_frame.data[0] = s->pict_bufs[2]; s->scratch_frame.linesize[0] = s->w; if(s->pix_fmt == AV_PIX_FMT_YUV420P) { s->last_frame.data[1] = s->last_frame.data[0] + s->w * s->h; s->last_frame.data[2] = s->last_frame.data[1] + ((s->w * s->h) >> 2); s->last_frame.linesize[1] = s->last_frame.linesize[2] = s->w >> 1; s->best_frame.data[1] = s->best_frame.data[0] + s->w * s->h; s->best_frame.data[2] = s->best_frame.data[1] + ((s->w * s->h) >> 2); s->best_frame.linesize[1] = s->best_frame.linesize[2] = s->w >> 1; s->scratch_frame.data[1] = s->scratch_frame.data[0] + s->w * s->h; s->scratch_frame.data[2] = s->scratch_frame.data[1] + ((s->w * s->h) >> 2); s->scratch_frame.linesize[1] = s->scratch_frame.linesize[2] = s->w >> 1; } s->num_v1_mode = s->num_v4_mode = s->num_mc_mode = s->num_v1_encs = s->num_v4_encs = s->num_skips = 0; return 0; enomem: av_free(s->codebook_input); av_free(s->codebook_closest); av_free(s->strip_buf); av_free(s->frame_buf); av_free(s->mb); #ifdef CINEPAKENC_DEBUG av_free(s->best_mb); #endif for(x = 0; x < 3; x++) av_free(s->pict_bufs[x]); return AVERROR(ENOMEM); }


static int count_contiguous_clusters(int nb_clusters, int cluster_size, uint64_t *l2_table, uint64_t stop_flags) { int i; uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED; uint64_t first_entry = be64_to_cpu(l2_table[0]); uint64_t offset = first_entry & mask; if (!offset) return 0; assert(qcow2_get_cluster_type(first_entry) != QCOW2_CLUSTER_COMPRESSED); for (i = 0; i < nb_clusters; i++) { uint64_t l2_entry = be64_to_cpu(l2_table[i]) & mask; if (offset + (uint64_t) i * cluster_size != l2_entry) { break; } } return i; }


static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *devaddr, const char *opts_str) { Error *local_err = NULL; QemuOpts *opts; PCIBus *root = pci_find_primary_bus(); PCIBus *bus; int ret, devfn; if (!root) { monitor_printf(mon, "no primary PCI bus (if there are multiple" " PCI roots, you must use device_add instead)"); return NULL; } bus = pci_get_bus_devfn(&devfn, root, devaddr); if (!bus) { monitor_printf(mon, "Invalid PCI device address %s\n", devaddr); return NULL; } if (!qbus_is_hotpluggable(BUS(bus))) { monitor_printf(mon, "PCI bus doesn't support hotplug\n"); return NULL; } opts = qemu_opts_parse(qemu_find_opts("net"), opts_str ? opts_str : "", 0); if (!opts) { return NULL; } qemu_opt_set(opts, "type", "nic"); ret = net_client_init(opts, 0, &local_err); if (local_err) { qerror_report_err(local_err); error_free(local_err); return NULL; } if (nd_table[ret].devaddr) { monitor_printf(mon, "Parameter addr not supported\n"); return NULL; } return pci_nic_init(&nd_table[ret], root, "rtl8139", devaddr); }


void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp) { MigrationState *s = opaque; Error *local_err = NULL, **temp = &local_err; RDMAContext *rdma = qemu_rdma_data_init(host_port, &local_err); int ret = 0; if (rdma == NULL) { ERROR(temp, "Failed to initialize RDMA data structures! %d", ret); goto err; } ret = qemu_rdma_source_init(rdma, &local_err, s->enabled_capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL]); if (ret) { goto err; } trace_rdma_start_outgoing_migration_after_rdma_source_init(); ret = qemu_rdma_connect(rdma, &local_err); if (ret) { goto err; } trace_rdma_start_outgoing_migration_after_rdma_connect(); s->to_dst_file = qemu_fopen_rdma(rdma, "wb"); migrate_fd_connect(s); return; err: error_propagate(errp, local_err); g_free(rdma); migrate_fd_error(s); }


grlib_irqmp_writel(void *opaque, target_phys_addr_t addr, uint32_t value) { IRQMP *irqmp = opaque; IRQMPState *state; assert(irqmp != NULL); state = irqmp->state; assert(state != NULL); addr &= 0xff; /* global registers */ switch (addr) { case LEVEL_OFFSET: value &= 0xFFFF << 1; /* clean up the value */ state->level = value; return; case PENDING_OFFSET: /* Read Only */ return; case FORCE0_OFFSET: /* This register is an "alias" for the force register of CPU 0 */ value &= 0xFFFE; /* clean up the value */ state->force[0] = value; grlib_irqmp_check_irqs(irqmp->state); return; case CLEAR_OFFSET: value &= ~1; /* clean up the value */ state->pending &= ~value; return; case MP_STATUS_OFFSET: /* Read Only (no SMP support) */ return; case BROADCAST_OFFSET: value &= 0xFFFE; /* clean up the value */ state->broadcast = value; return; default: break; } /* mask registers */ if (addr >= MASK_OFFSET && addr < FORCE_OFFSET) { int cpu = (addr - MASK_OFFSET) / 4; assert(cpu >= 0 && cpu < IRQMP_MAX_CPU); value &= ~1; /* clean up the value */ state->mask[cpu] = value; grlib_irqmp_check_irqs(irqmp->state); return; } /* force registers */ if (addr >= FORCE_OFFSET && addr < EXTENDED_OFFSET) { int cpu = (addr - FORCE_OFFSET) / 4; assert(cpu >= 0 && cpu < IRQMP_MAX_CPU); uint32_t force = value & 0xFFFE; uint32_t clear = (value >> 16) & 0xFFFE; uint32_t old = state->force[cpu]; state->force[cpu] = (old | force) & ~clear; grlib_irqmp_check_irqs(irqmp->state); return; } /* extended (not supported) */ if (addr >= EXTENDED_OFFSET && addr < IRQMP_REG_SIZE) { int cpu = (addr - EXTENDED_OFFSET) / 4; assert(cpu >= 0 && cpu < IRQMP_MAX_CPU); value &= 0xF; /* clean up the value */ state->extended[cpu] = value; return; } trace_grlib_irqmp_unknown_register("write", addr); }


static void qvirtio_pci_queue_select(QVirtioDevice *d, uint16_t index) { QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; qpci_io_writeb(dev->pdev, dev->addr + VIRTIO_PCI_QUEUE_SEL, index); }


static int cbr_bit_allocation(AC3EncodeContext *s) { int ch; int bits_left; int snr_offset, snr_incr; bits_left = 8 * s->frame_size - (s->frame_bits + s->exponent_bits); snr_offset = s->coarse_snr_offset << 4; while (snr_offset >= 0 && bit_alloc(s, snr_offset) > bits_left) { snr_offset -= 64; } if (snr_offset < 0) return AVERROR(EINVAL); FFSWAP(uint8_t *, s->bap_buffer, s->bap1_buffer); for (snr_incr = 64; snr_incr > 0; snr_incr >>= 2) { while (snr_offset + 64 <= 1023 && bit_alloc(s, snr_offset + snr_incr) <= bits_left) { snr_offset += snr_incr; FFSWAP(uint8_t *, s->bap_buffer, s->bap1_buffer); } } FFSWAP(uint8_t *, s->bap_buffer, s->bap1_buffer); reset_block_bap(s); s->coarse_snr_offset = snr_offset >> 4; for (ch = 0; ch < s->channels; ch++) s->fine_snr_offset[ch] = snr_offset & 0xF; return 0; }


static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict, APNGFctlChunk *best_fctl_chunk, APNGFctlChunk *best_last_fctl_chunk) { PNGEncContext *s = avctx->priv_data; int ret; unsigned int y; AVFrame* diffFrame; uint8_t bpp = (s->bits_per_pixel + 7) >> 3; uint8_t *original_bytestream, *original_bytestream_end; uint8_t *temp_bytestream = 0, *temp_bytestream_end; uint32_t best_sequence_number; uint8_t *best_bytestream; size_t best_bytestream_size = SIZE_MAX; APNGFctlChunk last_fctl_chunk = *best_last_fctl_chunk; APNGFctlChunk fctl_chunk = *best_fctl_chunk; if (avctx->frame_number == 0) { best_fctl_chunk->width = pict->width; best_fctl_chunk->height = pict->height; best_fctl_chunk->x_offset = 0; best_fctl_chunk->y_offset = 0; best_fctl_chunk->blend_op = APNG_BLEND_OP_SOURCE; return encode_frame(avctx, pict); } diffFrame = av_frame_alloc(); if (!diffFrame) return AVERROR(ENOMEM); diffFrame->format = pict->format; diffFrame->width = pict->width; diffFrame->height = pict->height; if ((ret = av_frame_get_buffer(diffFrame, 32)) < 0) goto fail; original_bytestream = s->bytestream; original_bytestream_end = s->bytestream_end; temp_bytestream = av_malloc(original_bytestream_end - original_bytestream); temp_bytestream_end = temp_bytestream + (original_bytestream_end - original_bytestream); if (!temp_bytestream) { ret = AVERROR(ENOMEM); goto fail; } for (last_fctl_chunk.dispose_op = 0; last_fctl_chunk.dispose_op < 3; ++last_fctl_chunk.dispose_op) { // 0: APNG_DISPOSE_OP_NONE // 1: APNG_DISPOSE_OP_BACKGROUND // 2: APNG_DISPOSE_OP_PREVIOUS for (fctl_chunk.blend_op = 0; fctl_chunk.blend_op < 2; ++fctl_chunk.blend_op) { // 0: APNG_BLEND_OP_SOURCE // 1: APNG_BLEND_OP_OVER uint32_t original_sequence_number = s->sequence_number, sequence_number; uint8_t *bytestream_start = s->bytestream; size_t bytestream_size; // Do disposal if (last_fctl_chunk.dispose_op != APNG_DISPOSE_OP_PREVIOUS) { diffFrame->width = pict->width; diffFrame->height = pict->height; av_frame_copy(diffFrame, s->last_frame); if (last_fctl_chunk.dispose_op == APNG_DISPOSE_OP_BACKGROUND) { for (y = last_fctl_chunk.y_offset; y < last_fctl_chunk.y_offset + last_fctl_chunk.height; ++y) { size_t row_start = diffFrame->linesize[0] * y + bpp * last_fctl_chunk.x_offset; memset(diffFrame->data[0] + row_start, 0, bpp * last_fctl_chunk.width); } } } else { if (!s->prev_frame) continue; diffFrame->width = pict->width; diffFrame->height = pict->height; av_frame_copy(diffFrame, s->prev_frame); } // Do inverse blending if (apng_do_inverse_blend(diffFrame, pict, &fctl_chunk, bpp) < 0) continue; // Do encoding ret = encode_frame(avctx, diffFrame); sequence_number = s->sequence_number; s->sequence_number = original_sequence_number; bytestream_size = s->bytestream - bytestream_start; s->bytestream = bytestream_start; if (ret < 0) goto fail; if (bytestream_size < best_bytestream_size) { *best_fctl_chunk = fctl_chunk; *best_last_fctl_chunk = last_fctl_chunk; best_sequence_number = sequence_number; best_bytestream = s->bytestream; best_bytestream_size = bytestream_size; if (best_bytestream == original_bytestream) { s->bytestream = temp_bytestream; s->bytestream_end = temp_bytestream_end; } else { s->bytestream = original_bytestream; s->bytestream_end = original_bytestream_end; } } } } s->sequence_number = best_sequence_number; s->bytestream = original_bytestream + best_bytestream_size; s->bytestream_end = original_bytestream_end; if (best_bytestream != original_bytestream) memcpy(original_bytestream, best_bytestream, best_bytestream_size); ret = 0; fail: av_freep(&temp_bytestream); av_frame_free(&diffFrame); return ret; }


static inline void transpose4x4(uint8_t *dst, uint8_t *src, x86_reg dst_stride, x86_reg src_stride){ __asm__ volatile( //FIXME could save 1 instruction if done as 8x4 ... "movd (%1), %%mm0 \n\t" "add %3, %1 \n\t" "movd (%1), %%mm1 \n\t" "movd (%1,%3,1), %%mm2 \n\t" "movd (%1,%3,2), %%mm3 \n\t" "punpcklbw %%mm1, %%mm0 \n\t" "punpcklbw %%mm3, %%mm2 \n\t" "movq %%mm0, %%mm1 \n\t" "punpcklwd %%mm2, %%mm0 \n\t" "punpckhwd %%mm2, %%mm1 \n\t" "movd %%mm0, (%0) \n\t" "add %2, %0 \n\t" "punpckhdq %%mm0, %%mm0 \n\t" "movd %%mm0, (%0) \n\t" "movd %%mm1, (%0,%2,1) \n\t" "punpckhdq %%mm1, %%mm1 \n\t" "movd %%mm1, (%0,%2,2) \n\t" : "+&r" (dst), "+&r" (src) : "r" (dst_stride), "r" (src_stride) : "memory" ); }


uint64_t helper_ld_asi(target_ulong addr, int asi, int size, int sign) { uint64_t ret = 0; #if defined(DEBUG_ASI) target_ulong last_addr = addr; #endif asi &= 0xff; if ((asi < 0x80 && (env->pstate & PS_PRIV) == 0) || ((env->def->features & CPU_FEATURE_HYPV) && asi >= 0x30 && asi < 0x80 && !(env->hpstate & HS_PRIV))) raise_exception(TT_PRIV_ACT); helper_check_align(addr, size - 1); switch (asi) { case 0x82: // Primary no-fault case 0x8a: // Primary no-fault LE case 0x83: // Secondary no-fault case 0x8b: // Secondary no-fault LE { /* secondary space access has lowest asi bit equal to 1 */ int access_mmu_idx = ( asi & 1 ) ? MMU_KERNEL_IDX : MMU_KERNEL_SECONDARY_IDX; if (cpu_get_phys_page_nofault(env, addr, access_mmu_idx) == -1ULL) { #ifdef DEBUG_ASI dump_asi("read ", last_addr, asi, size, ret); #endif return 0; } } // Fall through case 0x10: // As if user primary case 0x11: // As if user secondary case 0x18: // As if user primary LE case 0x19: // As if user secondary LE case 0x80: // Primary case 0x81: // Secondary case 0x88: // Primary LE case 0x89: // Secondary LE case 0xe2: // UA2007 Primary block init case 0xe3: // UA2007 Secondary block init if ((asi & 0x80) && (env->pstate & PS_PRIV)) { if ((env->def->features & CPU_FEATURE_HYPV) && env->hpstate & HS_PRIV) { switch(size) { case 1: ret = ldub_hypv(addr); break; case 2: ret = lduw_hypv(addr); break; case 4: ret = ldl_hypv(addr); break; default: case 8: ret = ldq_hypv(addr); break; } } else { /* secondary space access has lowest asi bit equal to 1 */ if (asi & 1) { switch(size) { case 1: ret = ldub_kernel_secondary(addr); break; case 2: ret = lduw_kernel_secondary(addr); break; case 4: ret = ldl_kernel_secondary(addr); break; default: case 8: ret = ldq_kernel_secondary(addr); break; } } else { switch(size) { case 1: ret = ldub_kernel(addr); break; case 2: ret = lduw_kernel(addr); break; case 4: ret = ldl_kernel(addr); break; default: case 8: ret = ldq_kernel(addr); break; } } } } else { /* secondary space access has lowest asi bit equal to 1 */ if (asi & 1) { switch(size) { case 1: ret = ldub_user_secondary(addr); break; case 2: ret = lduw_user_secondary(addr); break; case 4: ret = ldl_user_secondary(addr); break; default: case 8: ret = ldq_user_secondary(addr); break; } } else { switch(size) { case 1: ret = ldub_user(addr); break; case 2: ret = lduw_user(addr); break; case 4: ret = ldl_user(addr); break; default: case 8: ret = ldq_user(addr); break; } } } break; case 0x14: // Bypass case 0x15: // Bypass, non-cacheable case 0x1c: // Bypass LE case 0x1d: // Bypass, non-cacheable LE { switch(size) { case 1: ret = ldub_phys(addr); break; case 2: ret = lduw_phys(addr); break; case 4: ret = ldl_phys(addr); break; default: case 8: ret = ldq_phys(addr); break; } break; } case 0x24: // Nucleus quad LDD 128 bit atomic case 0x2c: // Nucleus quad LDD 128 bit atomic LE // Only ldda allowed raise_exception(TT_ILL_INSN); return 0; case 0x04: // Nucleus case 0x0c: // Nucleus Little Endian (LE) { switch(size) { case 1: ret = ldub_nucleus(addr); break; case 2: ret = lduw_nucleus(addr); break; case 4: ret = ldl_nucleus(addr); break; default: case 8: ret = ldq_nucleus(addr); break; } break; } case 0x4a: // UPA config // XXX break; case 0x45: // LSU ret = env->lsu; break; case 0x50: // I-MMU regs { int reg = (addr >> 3) & 0xf; if (reg == 0) { // I-TSB Tag Target register ret = ultrasparc_tag_target(env->immu.tag_access); } else { ret = env->immuregs[reg]; } break; } case 0x51: // I-MMU 8k TSB pointer { // env->immuregs[5] holds I-MMU TSB register value // env->immuregs[6] holds I-MMU Tag Access register value ret = ultrasparc_tsb_pointer(env->immu.tsb, env->immu.tag_access, 8*1024); break; } case 0x52: // I-MMU 64k TSB pointer { // env->immuregs[5] holds I-MMU TSB register value // env->immuregs[6] holds I-MMU Tag Access register value ret = ultrasparc_tsb_pointer(env->immu.tsb, env->immu.tag_access, 64*1024); break; } case 0x55: // I-MMU data access { int reg = (addr >> 3) & 0x3f; ret = env->itlb[reg].tte; break; } case 0x56: // I-MMU tag read { int reg = (addr >> 3) & 0x3f; ret = env->itlb[reg].tag; break; } case 0x58: // D-MMU regs { int reg = (addr >> 3) & 0xf; if (reg == 0) { // D-TSB Tag Target register ret = ultrasparc_tag_target(env->dmmu.tag_access); } else { ret = env->dmmuregs[reg]; } break; } case 0x59: // D-MMU 8k TSB pointer { // env->dmmuregs[5] holds D-MMU TSB register value // env->dmmuregs[6] holds D-MMU Tag Access register value ret = ultrasparc_tsb_pointer(env->dmmu.tsb, env->dmmu.tag_access, 8*1024); break; } case 0x5a: // D-MMU 64k TSB pointer { // env->dmmuregs[5] holds D-MMU TSB register value // env->dmmuregs[6] holds D-MMU Tag Access register value ret = ultrasparc_tsb_pointer(env->dmmu.tsb, env->dmmu.tag_access, 64*1024); break; } case 0x5d: // D-MMU data access { int reg = (addr >> 3) & 0x3f; ret = env->dtlb[reg].tte; break; } case 0x5e: // D-MMU tag read { int reg = (addr >> 3) & 0x3f; ret = env->dtlb[reg].tag; break; } case 0x46: // D-cache data case 0x47: // D-cache tag access case 0x4b: // E-cache error enable case 0x4c: // E-cache asynchronous fault status case 0x4d: // E-cache asynchronous fault address case 0x4e: // E-cache tag data case 0x66: // I-cache instruction access case 0x67: // I-cache tag access case 0x6e: // I-cache predecode case 0x6f: // I-cache LRU etc. case 0x76: // E-cache tag case 0x7e: // E-cache tag break; case 0x5b: // D-MMU data pointer case 0x48: // Interrupt dispatch, RO case 0x49: // Interrupt data receive case 0x7f: // Incoming interrupt vector, RO // XXX break; case 0x54: // I-MMU data in, WO case 0x57: // I-MMU demap, WO case 0x5c: // D-MMU data in, WO case 0x5f: // D-MMU demap, WO case 0x77: // Interrupt vector, WO default: do_unassigned_access(addr, 0, 0, 1, size); ret = 0; break; } /* Convert from little endian */ switch (asi) { case 0x0c: // Nucleus Little Endian (LE) case 0x18: // As if user primary LE case 0x19: // As if user secondary LE case 0x1c: // Bypass LE case 0x1d: // Bypass, non-cacheable LE case 0x88: // Primary LE case 0x89: // Secondary LE case 0x8a: // Primary no-fault LE case 0x8b: // Secondary no-fault LE switch(size) { case 2: ret = bswap16(ret); break; case 4: ret = bswap32(ret); break; case 8: ret = bswap64(ret); break; default: break; } default: break; } /* Convert to signed number */ if (sign) { switch(size) { case 1: ret = (int8_t) ret; break; case 2: ret = (int16_t) ret; break; case 4: ret = (int32_t) ret; break; default: break; } } #ifdef DEBUG_ASI dump_asi("read ", last_addr, asi, size, ret); #endif return ret; }


static AVIOContext * wtvfile_open_sector(int first_sector, uint64_t length, int depth, AVFormatContext *s) { AVIOContext *pb; WtvFile *wf; uint8_t *buffer; if (avio_seek(s->pb, (int64_t)first_sector << WTV_SECTOR_BITS, SEEK_SET) < 0) return NULL; wf = av_mallocz(sizeof(WtvFile)); if (!wf) return NULL; if (depth == 0) { wf->sectors = av_malloc(sizeof(uint32_t)); if (!wf->sectors) { av_free(wf); return NULL; } wf->sectors[0] = first_sector; wf->nb_sectors = 1; } else if (depth == 1) { wf->sectors = av_malloc(WTV_SECTOR_SIZE); if (!wf->sectors) { av_free(wf); return NULL; } wf->nb_sectors = read_ints(s->pb, wf->sectors, WTV_SECTOR_SIZE / 4); } else if (depth == 2) { uint32_t sectors1[WTV_SECTOR_SIZE / 4]; int nb_sectors1 = read_ints(s->pb, sectors1, WTV_SECTOR_SIZE / 4); int i; wf->sectors = av_malloc(nb_sectors1 << WTV_SECTOR_BITS); if (!wf->sectors) { av_free(wf); return NULL; } wf->nb_sectors = 0; for (i = 0; i < nb_sectors1; i++) { if (avio_seek(s->pb, (int64_t)sectors1[i] << WTV_SECTOR_BITS, SEEK_SET) < 0) break; wf->nb_sectors += read_ints(s->pb, wf->sectors + i * WTV_SECTOR_SIZE / 4, WTV_SECTOR_SIZE / 4); } } else { av_log(s, AV_LOG_ERROR, "unsupported file allocation table depth (0x%x)\n", depth); av_free(wf); return NULL; } wf->sector_bits = length & (1ULL<<63) ? WTV_SECTOR_BITS : WTV_BIGSECTOR_BITS; if (!wf->nb_sectors) { av_free(wf->sectors); av_free(wf); return NULL; } if (wf->sectors[wf->nb_sectors - 1] << WTV_SECTOR_BITS > avio_tell(s->pb)) av_log(s, AV_LOG_WARNING, "truncated file\n"); /* check length */ length &= 0xFFFFFFFFFFFF; if (length > ((int64_t)wf->nb_sectors << wf->sector_bits)) { av_log(s, AV_LOG_WARNING, "reported file length (0x%"PRIx64") exceeds number of available sectors (0x%"PRIx64")\n", length, (int64_t)wf->nb_sectors << wf->sector_bits); length = (int64_t)wf->nb_sectors << wf->sector_bits; } wf->length = length; /* seek to initial sector */ wf->position = 0; if (avio_seek(s->pb, (int64_t)wf->sectors[0] << WTV_SECTOR_BITS, SEEK_SET) < 0) { av_free(wf->sectors); av_free(wf); return NULL; } wf->pb_filesystem = s->pb; buffer = av_malloc(1 << wf->sector_bits); if (!buffer) { av_free(wf->sectors); av_free(wf); return NULL; } pb = avio_alloc_context(buffer, 1 << wf->sector_bits, 0, wf, wtvfile_read_packet, NULL, wtvfile_seek); if (!pb) { av_free(buffer); av_free(wf->sectors); av_free(wf); } return pb; }


static uint32_t ehci_mem_readb(void *ptr, target_phys_addr_t addr) { EHCIState *s = ptr; uint32_t val; val = s->mmio[addr]; return val; }


static void gen_tlbli_74xx(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_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); #endif }


int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){ int i, j; uint32_t c; if (bits < 8 || bits > 32 || poly >= (1LL<<bits)) return -1; if (ctx_size != sizeof(AVCRC)*257 && ctx_size != sizeof(AVCRC)*1024) return -1; for (i = 0; i < 256; i++) { if (le) { for (c = i, j = 0; j < 8; j++) c = (c>>1)^(poly & (-(c&1))); ctx[i] = c; } else { for (c = i << 24, j = 0; j < 8; j++) c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) ); ctx[i] = av_bswap32(c); } } ctx[256]=1; #if !CONFIG_SMALL if(ctx_size >= sizeof(AVCRC)*1024) for (i = 0; i < 256; i++) for(j=0; j<3; j++) ctx[256*(j+1) + i]= (ctx[256*j + i]>>8) ^ ctx[ ctx[256*j + i]&0xFF ]; #endif return 0; }


static void sbr_gain_calc(AACContext *ac, SpectralBandReplication *sbr, SBRData *ch_data, const int e_a[2]) { int e, k, m; // max gain limits : -3dB, 0dB, 3dB, inf dB (limiter off) static const SoftFloat limgain[4] = { { 760155524, 0 }, { 0x20000000, 1 }, { 758351638, 1 }, { 625000000, 34 } }; for (e = 0; e < ch_data->bs_num_env; e++) { int delta = !((e == e_a[1]) || (e == e_a[0])); for (k = 0; k < sbr->n_lim; k++) { SoftFloat gain_boost, gain_max; SoftFloat sum[2]; sum[0] = sum[1] = FLOAT_0; for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { const SoftFloat temp = av_div_sf(sbr->e_origmapped[e][m], av_add_sf(FLOAT_1, sbr->q_mapped[e][m])); sbr->q_m[e][m] = av_sqrt_sf(av_mul_sf(temp, sbr->q_mapped[e][m])); sbr->s_m[e][m] = av_sqrt_sf(av_mul_sf(temp, av_int2sf(ch_data->s_indexmapped[e + 1][m], 0))); if (!sbr->s_mapped[e][m]) { if (delta) { sbr->gain[e][m] = av_sqrt_sf(av_div_sf(sbr->e_origmapped[e][m], av_mul_sf(av_add_sf(FLOAT_1, sbr->e_curr[e][m]), av_add_sf(FLOAT_1, sbr->q_mapped[e][m])))); } else { sbr->gain[e][m] = av_sqrt_sf(av_div_sf(sbr->e_origmapped[e][m], av_add_sf(FLOAT_1, sbr->e_curr[e][m]))); } } else { sbr->gain[e][m] = av_sqrt_sf( av_div_sf( av_mul_sf(sbr->e_origmapped[e][m], sbr->q_mapped[e][m]), av_mul_sf( av_add_sf(FLOAT_1, sbr->e_curr[e][m]), av_add_sf(FLOAT_1, sbr->q_mapped[e][m])))); } } for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { sum[0] = av_add_sf(sum[0], sbr->e_origmapped[e][m]); sum[1] = av_add_sf(sum[1], sbr->e_curr[e][m]); } gain_max = av_mul_sf(limgain[sbr->bs_limiter_gains], av_sqrt_sf( av_div_sf( av_add_sf(FLOAT_EPSILON, sum[0]), av_add_sf(FLOAT_EPSILON, sum[1])))); if (av_gt_sf(gain_max, FLOAT_100000)) gain_max = FLOAT_100000; for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { SoftFloat q_m_max = av_div_sf( av_mul_sf(sbr->q_m[e][m], gain_max), sbr->gain[e][m]); if (av_gt_sf(sbr->q_m[e][m], q_m_max)) sbr->q_m[e][m] = q_m_max; if (av_gt_sf(sbr->gain[e][m], gain_max)) sbr->gain[e][m] = gain_max; } sum[0] = sum[1] = FLOAT_0; for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { sum[0] = av_add_sf(sum[0], sbr->e_origmapped[e][m]); sum[1] = av_add_sf(sum[1], av_mul_sf( av_mul_sf(sbr->e_curr[e][m], sbr->gain[e][m]), sbr->gain[e][m])); sum[1] = av_add_sf(sum[1], av_mul_sf(sbr->s_m[e][m], sbr->s_m[e][m])); if (delta && !sbr->s_m[e][m].mant) sum[1] = av_add_sf(sum[1], av_mul_sf(sbr->q_m[e][m], sbr->q_m[e][m])); } gain_boost = av_sqrt_sf( av_div_sf( av_add_sf(FLOAT_EPSILON, sum[0]), av_add_sf(FLOAT_EPSILON, sum[1]))); if (av_gt_sf(gain_boost, FLOAT_1584893192)) gain_boost = FLOAT_1584893192; for (m = sbr->f_tablelim[k] - sbr->kx[1]; m < sbr->f_tablelim[k + 1] - sbr->kx[1]; m++) { sbr->gain[e][m] = av_mul_sf(sbr->gain[e][m], gain_boost); sbr->q_m[e][m] = av_mul_sf(sbr->q_m[e][m], gain_boost); sbr->s_m[e][m] = av_mul_sf(sbr->s_m[e][m], gain_boost); } } } }


void tcg_dump_ops(TCGContext *s) { char buf[128]; TCGOp *op; int oi; for (oi = s->gen_op_buf[0].next; oi != 0; oi = op->next) { int i, k, nb_oargs, nb_iargs, nb_cargs; const TCGOpDef *def; TCGOpcode c; int col = 0; op = &s->gen_op_buf[oi]; c = op->opc; def = &tcg_op_defs[c]; if (c == INDEX_op_insn_start) { col += qemu_log("%s ----", oi != s->gen_op_buf[0].next ? "\n" : ""); for (i = 0; i < TARGET_INSN_START_WORDS; ++i) { target_ulong a; #if TARGET_LONG_BITS > TCG_TARGET_REG_BITS a = deposit64(op->args[i * 2], 32, 32, op->args[i * 2 + 1]); #else a = op->args[i]; #endif col += qemu_log(" " TARGET_FMT_lx, a); } } else if (c == INDEX_op_call) { /* variable number of arguments */ nb_oargs = op->callo; nb_iargs = op->calli; nb_cargs = def->nb_cargs; /* function name, flags, out args */ col += qemu_log(" %s %s,$0x%" TCG_PRIlx ",$%d", def->name, tcg_find_helper(s, op->args[nb_oargs + nb_iargs]), op->args[nb_oargs + nb_iargs + 1], nb_oargs); for (i = 0; i < nb_oargs; i++) { col += qemu_log(",%s", tcg_get_arg_str(s, buf, sizeof(buf), op->args[i])); } for (i = 0; i < nb_iargs; i++) { TCGArg arg = op->args[nb_oargs + i]; const char *t = "<dummy>"; if (arg != TCG_CALL_DUMMY_ARG) { t = tcg_get_arg_str(s, buf, sizeof(buf), arg); } col += qemu_log(",%s", t); } } else { col += qemu_log(" %s ", def->name); nb_oargs = def->nb_oargs; nb_iargs = def->nb_iargs; nb_cargs = def->nb_cargs; k = 0; for (i = 0; i < nb_oargs; i++) { if (k != 0) { col += qemu_log(","); } col += qemu_log("%s", tcg_get_arg_str(s, buf, sizeof(buf), op->args[k++])); } for (i = 0; i < nb_iargs; i++) { if (k != 0) { col += qemu_log(","); } col += qemu_log("%s", tcg_get_arg_str(s, buf, sizeof(buf), op->args[k++])); } switch (c) { case INDEX_op_brcond_i32: case INDEX_op_setcond_i32: case INDEX_op_movcond_i32: case INDEX_op_brcond2_i32: case INDEX_op_setcond2_i32: case INDEX_op_brcond_i64: case INDEX_op_setcond_i64: case INDEX_op_movcond_i64: if (op->args[k] < ARRAY_SIZE(cond_name) && cond_name[op->args[k]]) { col += qemu_log(",%s", cond_name[op->args[k++]]); } else { col += qemu_log(",$0x%" TCG_PRIlx, op->args[k++]); } i = 1; break; case INDEX_op_qemu_ld_i32: case INDEX_op_qemu_st_i32: case INDEX_op_qemu_ld_i64: case INDEX_op_qemu_st_i64: { TCGMemOpIdx oi = op->args[k++]; TCGMemOp op = get_memop(oi); unsigned ix = get_mmuidx(oi); if (op & ~(MO_AMASK | MO_BSWAP | MO_SSIZE)) { col += qemu_log(",$0x%x,%u", op, ix); } else { const char *s_al, *s_op; s_al = alignment_name[(op & MO_AMASK) >> MO_ASHIFT]; s_op = ldst_name[op & (MO_BSWAP | MO_SSIZE)]; col += qemu_log(",%s%s,%u", s_al, s_op, ix); } i = 1; } break; default: i = 0; break; } switch (c) { case INDEX_op_set_label: case INDEX_op_br: case INDEX_op_brcond_i32: case INDEX_op_brcond_i64: case INDEX_op_brcond2_i32: col += qemu_log("%s$L%d", k ? "," : "", arg_label(op->args[k])->id); i++, k++; break; default: break; } for (; i < nb_cargs; i++, k++) { col += qemu_log("%s$0x%" TCG_PRIlx, k ? "," : "", op->args[k]); } } if (op->life) { unsigned life = op->life; for (; col < 48; ++col) { putc(' ', qemu_logfile); } if (life & (SYNC_ARG * 3)) { qemu_log(" sync:"); for (i = 0; i < 2; ++i) { if (life & (SYNC_ARG << i)) { qemu_log(" %d", i); } } } life /= DEAD_ARG; if (life) { qemu_log(" dead:"); for (i = 0; life; ++i, life >>= 1) { if (life & 1) { qemu_log(" %d", i); } } } } qemu_log("\n"); } }


static int vtd_remap_irq_get(IntelIOMMUState *iommu, uint16_t index, VTDIrq *irq) { VTD_IRTE irte = { 0 }; int ret = 0; ret = vtd_irte_get(iommu, index, &irte); if (ret) { return ret; } irq->trigger_mode = irte.trigger_mode; irq->vector = irte.vector; irq->delivery_mode = irte.delivery_mode; /* Not support EIM yet: please refer to vt-d 9.10 DST bits */ #define VTD_IR_APIC_DEST_MASK (0xff00ULL) #define VTD_IR_APIC_DEST_SHIFT (8) irq->dest = (le32_to_cpu(irte.dest_id) & VTD_IR_APIC_DEST_MASK) >> \ VTD_IR_APIC_DEST_SHIFT; irq->dest_mode = irte.dest_mode; irq->redir_hint = irte.redir_hint; VTD_DPRINTF(IR, "remapping interrupt index %d: trig:%u,vec:%u," "deliver:%u,dest:%u,dest_mode:%u", index, irq->trigger_mode, irq->vector, irq->delivery_mode, irq->dest, irq->dest_mode); return 0; }


void exynos4210_init_board_irqs(Exynos4210Irq *s) { uint32_t grp, bit, irq_id, n; for (n = 0; n < EXYNOS4210_MAX_EXT_COMBINER_IN_IRQ; n++) { s->board_irqs[n] = qemu_irq_split(s->int_combiner_irq[n], s->ext_combiner_irq[n]); irq_id = 0; if (n == EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 4) || n == EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 4)) { /* MCT_G0 is passed to External GIC */ irq_id = EXT_GIC_ID_MCT_G0; } if (n == EXYNOS4210_COMBINER_GET_IRQ_NUM(1, 5) || n == EXYNOS4210_COMBINER_GET_IRQ_NUM(12, 5)) { /* MCT_G1 is passed to External and GIC */ irq_id = EXT_GIC_ID_MCT_G1; } if (irq_id) { s->board_irqs[n] = qemu_irq_split(s->int_combiner_irq[n], s->ext_gic_irq[irq_id-32]); } } for (; n < EXYNOS4210_MAX_INT_COMBINER_IN_IRQ; n++) { /* these IDs are passed to Internal Combiner and External GIC */ grp = EXYNOS4210_COMBINER_GET_GRP_NUM(n); bit = EXYNOS4210_COMBINER_GET_BIT_NUM(n); irq_id = combiner_grp_to_gic_id[grp - EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ][bit]; if (irq_id) { s->board_irqs[n] = qemu_irq_split(s->int_combiner_irq[n], s->ext_gic_irq[irq_id-32]); } } }


static BlockDriverAIOCB *bdrv_aio_rw_vector(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *iov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque, int is_write) { VectorTranslationAIOCB *s = qemu_aio_get_pool(&vectored_aio_pool, bs, cb, opaque); s->iov = iov; s->bounce = qemu_memalign(512, nb_sectors * 512); s->is_write = is_write; if (is_write) { qemu_iovec_to_buffer(s->iov, s->bounce); s->aiocb = bdrv_aio_write(bs, sector_num, s->bounce, nb_sectors, bdrv_aio_rw_vector_cb, s); } else { s->aiocb = bdrv_aio_read(bs, sector_num, s->bounce, nb_sectors, bdrv_aio_rw_vector_cb, s); return &s->common;


int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec) { if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE || !codec->init) return 0; if (ff_mutex_lock(&codec_mutex)) return -1; if (atomic_fetch_add(&entangled_thread_counter, 1)) { av_log(log_ctx, AV_LOG_ERROR, "Insufficient thread locking. At least %d threads are " "calling avcodec_open2() at the same time right now.\n", atomic_load(&entangled_thread_counter)); ff_avcodec_locked = 1; ff_unlock_avcodec(codec); return AVERROR(EINVAL); } av_assert0(!ff_avcodec_locked); ff_avcodec_locked = 1; return 0; }


static void do_mchk_interrupt(CPUS390XState *env) { S390CPU *cpu = s390_env_get_cpu(env); uint64_t mask, addr; LowCore *lowcore; MchkQueue *q; int i; if (!(env->psw.mask & PSW_MASK_MCHECK)) { cpu_abort(CPU(cpu), "Machine check w/o mchk mask\n"); } if (env->mchk_index < 0 || env->mchk_index > MAX_MCHK_QUEUE) { cpu_abort(CPU(cpu), "Mchk queue overrun: %d\n", env->mchk_index); } q = &env->mchk_queue[env->mchk_index]; if (q->type != 1) { /* Don't know how to handle this... */ cpu_abort(CPU(cpu), "Unknown machine check type %d\n", q->type); } if (!(env->cregs[14] & (1 << 28))) { /* CRW machine checks disabled */ return; } lowcore = cpu_map_lowcore(env); for (i = 0; i < 16; i++) { lowcore->floating_pt_save_area[i] = cpu_to_be64(env->fregs[i].ll); lowcore->gpregs_save_area[i] = cpu_to_be64(env->regs[i]); lowcore->access_regs_save_area[i] = cpu_to_be32(env->aregs[i]); lowcore->cregs_save_area[i] = cpu_to_be64(env->cregs[i]); } lowcore->prefixreg_save_area = cpu_to_be32(env->psa); lowcore->fpt_creg_save_area = cpu_to_be32(env->fpc); lowcore->tod_progreg_save_area = cpu_to_be32(env->todpr); lowcore->cpu_timer_save_area[0] = cpu_to_be32(env->cputm >> 32); lowcore->cpu_timer_save_area[1] = cpu_to_be32((uint32_t)env->cputm); lowcore->clock_comp_save_area[0] = cpu_to_be32(env->ckc >> 32); lowcore->clock_comp_save_area[1] = cpu_to_be32((uint32_t)env->ckc); lowcore->mcck_interruption_code[0] = cpu_to_be32(0x00400f1d); lowcore->mcck_interruption_code[1] = cpu_to_be32(0x40330000); lowcore->mcck_old_psw.mask = cpu_to_be64(get_psw_mask(env)); lowcore->mcck_old_psw.addr = cpu_to_be64(env->psw.addr); mask = be64_to_cpu(lowcore->mcck_new_psw.mask); addr = be64_to_cpu(lowcore->mcck_new_psw.addr); cpu_unmap_lowcore(lowcore); env->mchk_index--; if (env->mchk_index == -1) { env->pending_int &= ~INTERRUPT_MCHK; } DPRINTF("%s: %" PRIx64 " %" PRIx64 "\n", __func__, env->psw.mask, env->psw.addr); load_psw(env, mask, addr); }


uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar, int64_t overflow_time) { int64_t d = acpi_pm_tmr_get_clock(); if (d >= overflow_time) { ar->pm1.evt.sts |= ACPI_BITMASK_TIMER_STATUS; } return ar->pm1.evt.sts; }


static int ide_drive_pio_post_load(void *opaque, int version_id) { IDEState *s = opaque; if (s->end_transfer_fn_idx > ARRAY_SIZE(transfer_end_table)) { return -EINVAL; } s->end_transfer_func = transfer_end_table[s->end_transfer_fn_idx]; s->data_ptr = s->io_buffer + s->cur_io_buffer_offset; s->data_end = s->data_ptr + s->cur_io_buffer_len; return 0; }


int av_get_packet(AVIOContext *s, AVPacket *pkt, int size) { int ret= av_new_packet(pkt, size); if(ret<0) return ret; pkt->pos= avio_tell(s); ret= avio_read(s, pkt->data, size); if(ret<=0) av_free_packet(pkt); else av_shrink_packet(pkt, ret); return ret; }


void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size) { RTPMuxContext *s = s1->priv_data; int len, max_packet_size; uint8_t *p; /* skip ADTS header, if present */ if ((s1->streams[0]->codec->extradata_size) == 0) { size -= 7; buff += 7; } max_packet_size = s->max_payload_size - MAX_AU_HEADERS_SIZE; /* test if the packet must be sent */ len = (s->buf_ptr - s->buf); if ((s->num_frames == MAX_FRAMES_PER_PACKET) || (len && (len + size) > s->max_payload_size)) { int au_size = s->num_frames * 2; p = s->buf + MAX_AU_HEADERS_SIZE - au_size - 2; if (p != s->buf) { memmove(p + 2, s->buf + 2, au_size); } /* Write the AU header size */ p[0] = ((au_size * 8) & 0xFF) >> 8; p[1] = (au_size * 8) & 0xFF; ff_rtp_send_data(s1, p, s->buf_ptr - p, 1); s->num_frames = 0; } if (s->num_frames == 0) { s->buf_ptr = s->buf + MAX_AU_HEADERS_SIZE; s->timestamp = s->cur_timestamp; } if (size <= max_packet_size) { p = s->buf + s->num_frames++ * 2 + 2; *p++ = size >> 5; *p = (size & 0x1F) << 3; memcpy(s->buf_ptr, buff, size); s->buf_ptr += size; } else { if (s->buf_ptr != s->buf + MAX_AU_HEADERS_SIZE) { av_log(s1, AV_LOG_ERROR, "Strange...\n"); av_abort(); } max_packet_size = s->max_payload_size - 4; p = s->buf; p[0] = 0; p[1] = 16; while (size > 0) { len = FFMIN(size, max_packet_size); p[2] = len >> 5; p[3] = (size & 0x1F) << 3; memcpy(p + 4, buff, len); ff_rtp_send_data(s1, p, len + 4, len == size); size -= len; buff += len; } } }


static int dpcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; const uint8_t *buf_end = buf + buf_size; DPCMContext *s = avctx->priv_data; int out = 0; int predictor[2]; int ch = 0; int stereo = s->channels - 1; int16_t *output_samples = data; if (!buf_size) return 0; /* calculate output size */ switch(avctx->codec->id) { case CODEC_ID_ROQ_DPCM: out = buf_size - 8; break; case CODEC_ID_INTERPLAY_DPCM: out = buf_size - 6 - s->channels; break; case CODEC_ID_XAN_DPCM: out = buf_size - 2 * s->channels; break; case CODEC_ID_SOL_DPCM: if (avctx->codec_tag != 3) out = buf_size * 2; else out = buf_size; break; } out *= av_get_bytes_per_sample(avctx->sample_fmt); if (out < 0) { av_log(avctx, AV_LOG_ERROR, "packet is too small\n"); return AVERROR(EINVAL); } if (*data_size < out) { av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n"); return AVERROR(EINVAL); } switch(avctx->codec->id) { case CODEC_ID_ROQ_DPCM: buf += 6; if (stereo) { predictor[1] = (int16_t)(bytestream_get_byte(&buf) << 8); predictor[0] = (int16_t)(bytestream_get_byte(&buf) << 8); } else { predictor[0] = (int16_t)bytestream_get_le16(&buf); } /* decode the samples */ while (buf < buf_end) { predictor[ch] += s->roq_square_array[*buf++]; predictor[ch] = av_clip_int16(predictor[ch]); *output_samples++ = predictor[ch]; /* toggle channel */ ch ^= stereo; } break; case CODEC_ID_INTERPLAY_DPCM: buf += 6; /* skip over the stream mask and stream length */ for (ch = 0; ch < s->channels; ch++) { predictor[ch] = (int16_t)bytestream_get_le16(&buf); *output_samples++ = predictor[ch]; } ch = 0; while (buf < buf_end) { predictor[ch] += interplay_delta_table[*buf++]; predictor[ch] = av_clip_int16(predictor[ch]); *output_samples++ = predictor[ch]; /* toggle channel */ ch ^= stereo; } break; case CODEC_ID_XAN_DPCM: { int shift[2] = { 4, 4 }; for (ch = 0; ch < s->channels; ch++) predictor[ch] = (int16_t)bytestream_get_le16(&buf); ch = 0; while (buf < buf_end) { uint8_t n = *buf++; int16_t diff = (n & 0xFC) << 8; if ((n & 0x03) == 3) shift[ch]++; else shift[ch] -= (2 * (n & 3)); /* saturate the shifter to a lower limit of 0 */ if (shift[ch] < 0) shift[ch] = 0; diff >>= shift[ch]; predictor[ch] += diff; predictor[ch] = av_clip_int16(predictor[ch]); *output_samples++ = predictor[ch]; /* toggle channel */ ch ^= stereo; } break; } case CODEC_ID_SOL_DPCM: if (avctx->codec_tag != 3) { uint8_t *output_samples_u8 = data; while (buf < buf_end) { uint8_t n = *buf++; s->sample[0] += s->sol_table[n >> 4]; s->sample[0] = av_clip_uint8(s->sample[0]); *output_samples_u8++ = s->sample[0]; s->sample[stereo] += s->sol_table[n & 0x0F]; s->sample[stereo] = av_clip_uint8(s->sample[stereo]); *output_samples_u8++ = s->sample[stereo]; } } else { while (buf < buf_end) { uint8_t n = *buf++; if (n & 0x80) s->sample[ch] -= sol_table_16[n & 0x7F]; else s->sample[ch] += sol_table_16[n & 0x7F]; s->sample[ch] = av_clip_int16(s->sample[ch]); *output_samples++ = s->sample[ch]; /* toggle channel */ ch ^= stereo; } } break; } *data_size = out; return buf_size; }


static void gen_logicq_cc(TCGv_i64 val) { TCGv tmp = new_tmp(); gen_helper_logicq_cc(tmp, val); gen_logic_CC(tmp); dead_tmp(tmp); }


static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) { BDRVQcow2State *s = bs->opaque; int offset_in_cluster; int ret; unsigned int cur_bytes; /* number of sectors in current iteration */ uint64_t cluster_offset; QEMUIOVector hd_qiov; uint64_t bytes_done = 0; uint8_t *cluster_data = NULL; QCowL2Meta *l2meta = NULL; trace_qcow2_writev_start_req(qemu_coroutine_self(), offset, bytes); qemu_iovec_init(&hd_qiov, qiov->niov); s->cluster_cache_offset = -1; /* disable compressed cache */ qemu_co_mutex_lock(&s->lock); while (bytes != 0) { l2meta = NULL; trace_qcow2_writev_start_part(qemu_coroutine_self()); offset_in_cluster = offset_into_cluster(s, offset); cur_bytes = MIN(bytes, INT_MAX); if (bs->encrypted) { cur_bytes = MIN(cur_bytes, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size - offset_in_cluster); } ret = qcow2_alloc_cluster_offset(bs, offset, &cur_bytes, &cluster_offset, &l2meta); if (ret < 0) { goto fail; } assert((cluster_offset & 511) == 0); qemu_iovec_reset(&hd_qiov); qemu_iovec_concat(&hd_qiov, qiov, bytes_done, cur_bytes); if (bs->encrypted) { Error *err = NULL; assert(s->crypto); if (!cluster_data) { cluster_data = qemu_try_blockalign(bs->file->bs, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); if (cluster_data == NULL) { ret = -ENOMEM; goto fail; } } assert(hd_qiov.size <= QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); qemu_iovec_to_buf(&hd_qiov, 0, cluster_data, hd_qiov.size); if (qcrypto_block_encrypt(s->crypto, offset >> BDRV_SECTOR_BITS, cluster_data, cur_bytes, &err) < 0) { error_free(err); ret = -EIO; goto fail; } qemu_iovec_reset(&hd_qiov); qemu_iovec_add(&hd_qiov, cluster_data, cur_bytes); } ret = qcow2_pre_write_overlap_check(bs, 0, cluster_offset + offset_in_cluster, cur_bytes); if (ret < 0) { goto fail; } /* If we need to do COW, check if it's possible to merge the * writing of the guest data together with that of the COW regions. * If it's not possible (or not necessary) then write the * guest data now. */ if (!merge_cow(offset, cur_bytes, &hd_qiov, l2meta)) { qemu_co_mutex_unlock(&s->lock); BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO); trace_qcow2_writev_data(qemu_coroutine_self(), cluster_offset + offset_in_cluster); ret = bdrv_co_pwritev(bs->file, cluster_offset + offset_in_cluster, cur_bytes, &hd_qiov, 0); qemu_co_mutex_lock(&s->lock); if (ret < 0) { goto fail; } } while (l2meta != NULL) { QCowL2Meta *next; ret = qcow2_alloc_cluster_link_l2(bs, l2meta); if (ret < 0) { goto fail; } /* Take the request off the list of running requests */ if (l2meta->nb_clusters != 0) { QLIST_REMOVE(l2meta, next_in_flight); } qemu_co_queue_restart_all(&l2meta->dependent_requests); next = l2meta->next; g_free(l2meta); l2meta = next; } bytes -= cur_bytes; offset += cur_bytes; bytes_done += cur_bytes; trace_qcow2_writev_done_part(qemu_coroutine_self(), cur_bytes); } ret = 0; fail: qemu_co_mutex_unlock(&s->lock); while (l2meta != NULL) { QCowL2Meta *next; if (l2meta->nb_clusters != 0) { QLIST_REMOVE(l2meta, next_in_flight); } qemu_co_queue_restart_all(&l2meta->dependent_requests); next = l2meta->next; g_free(l2meta); l2meta = next; } qemu_iovec_destroy(&hd_qiov); qemu_vfree(cluster_data); trace_qcow2_writev_done_req(qemu_coroutine_self(), ret); return ret; }


static int ape_probe(AVProbeData * p) { if (p->buf[0] == 'M' && p->buf[1] == 'A' && p->buf[2] == 'C' && p->buf[3] == ' ') return AVPROBE_SCORE_MAX; return 0; }


static void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc) { int16_t *filterPos = c->hChrFilterPos; int16_t *filter = c->hChrFilter; void *mmx2FilterCode= c->chrMmx2FilterCode; int i; #if defined(PIC) DECLARE_ALIGNED(8, uint64_t, ebxsave); #endif #if ARCH_X86_64 DECLARE_ALIGNED(8, uint64_t, retsave); #endif __asm__ volatile( #if defined(PIC) "mov %%"REG_b", %7 \n\t" #if ARCH_X86_64 "mov -8(%%rsp), %%"REG_a" \n\t" "mov %%"REG_a", %8 \n\t" #endif #else #if ARCH_X86_64 "mov -8(%%rsp), %%"REG_a" \n\t" "mov %%"REG_a", %7 \n\t" #endif #endif "pxor %%mm7, %%mm7 \n\t" "mov %0, %%"REG_c" \n\t" "mov %1, %%"REG_D" \n\t" "mov %2, %%"REG_d" \n\t" "mov %3, %%"REG_b" \n\t" "xor %%"REG_a", %%"REG_a" \n\t" // i PREFETCH" (%%"REG_c") \n\t" PREFETCH" 32(%%"REG_c") \n\t" PREFETCH" 64(%%"REG_c") \n\t" CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE "xor %%"REG_a", %%"REG_a" \n\t" // i "mov %5, %%"REG_c" \n\t" // src "mov %6, %%"REG_D" \n\t" // buf2 PREFETCH" (%%"REG_c") \n\t" PREFETCH" 32(%%"REG_c") \n\t" PREFETCH" 64(%%"REG_c") \n\t" CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE CALL_MMX2_FILTER_CODE #if defined(PIC) "mov %7, %%"REG_b" \n\t" #if ARCH_X86_64 "mov %8, %%"REG_a" \n\t" "mov %%"REG_a", -8(%%rsp) \n\t" #endif #else #if ARCH_X86_64 "mov %7, %%"REG_a" \n\t" "mov %%"REG_a", -8(%%rsp) \n\t" #endif #endif :: "m" (src1), "m" (dst1), "m" (filter), "m" (filterPos), "m" (mmx2FilterCode), "m" (src2), "m"(dst2) #if defined(PIC) ,"m" (ebxsave) #endif #if ARCH_X86_64 ,"m"(retsave) #endif : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D #if !defined(PIC) ,"%"REG_b #endif ); for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) { dst1[i] = src1[srcW-1]*128; dst2[i] = src2[srcW-1]*128; } }


static void ide_device_class_init(ObjectClass *klass, void *data) { DeviceClass *k = DEVICE_CLASS(klass); k->init = ide_qdev_init; set_bit(DEVICE_CATEGORY_STORAGE, k->categories); k->bus_type = TYPE_IDE_BUS; k->props = ide_props; }


void memory_region_del_eventfd(MemoryRegion *mr, hwaddr addr, unsigned size, bool match_data, uint64_t data, EventNotifier *e) { MemoryRegionIoeventfd mrfd = { .addr.start = int128_make64(addr), .addr.size = int128_make64(size), .match_data = match_data, .data = data, .e = e, }; unsigned i; adjust_endianness(mr, &mrfd.data, size); memory_region_transaction_begin(); for (i = 0; i < mr->ioeventfd_nb; ++i) { if (memory_region_ioeventfd_equal(mrfd, mr->ioeventfds[i])) { break; } } assert(i != mr->ioeventfd_nb); memmove(&mr->ioeventfds[i], &mr->ioeventfds[i+1], sizeof(*mr->ioeventfds) * (mr->ioeventfd_nb - (i+1))); --mr->ioeventfd_nb; mr->ioeventfds = g_realloc(mr->ioeventfds, sizeof(*mr->ioeventfds)*mr->ioeventfd_nb + 1); ioeventfd_update_pending |= mr->enabled; memory_region_transaction_commit(); }


void pc_system_firmware_init(MemoryRegion *rom_memory) { DriveInfo *pflash_drv; PcSysFwDevice *sysfw_dev; /* * TODO This device exists only so that users can switch between * use of flash and ROM for the BIOS. The ability to switch was * created because flash doesn't work with KVM. Once it does, we * should drop this device for new machine types. */ sysfw_dev = (PcSysFwDevice*) qdev_create(NULL, "pc-sysfw"); qdev_init_nofail(DEVICE(sysfw_dev)); if (sysfw_dev->rom_only) { old_pc_system_rom_init(rom_memory); return; } pflash_drv = drive_get(IF_PFLASH, 0, 0); /* Currently KVM cannot execute from device memory. Use old rom based firmware initialization for KVM. */ /* * This is a Bad Idea, because it makes enabling/disabling KVM * guest-visible. Do it only in bug-compatibility mode. */ if (pc_sysfw_flash_vs_rom_bug_compatible && kvm_enabled()) { if (pflash_drv != NULL) { fprintf(stderr, "qemu: pflash cannot be used with kvm enabled\n"); exit(1); } else { sysfw_dev->rom_only = 1; old_pc_system_rom_init(rom_memory); return; } } /* If a pflash drive is not found, then create one using the bios filename. */ if (pflash_drv == NULL) { pc_fw_add_pflash_drv(); pflash_drv = drive_get(IF_PFLASH, 0, 0); } if (pflash_drv != NULL) { pc_system_flash_init(rom_memory, pflash_drv); } else { fprintf(stderr, "qemu: PC system firmware (pflash) not available\n"); exit(1); } }


static int32_t scalarproduct_and_madd_int32_c(int16_t *v1, const int32_t *v2, const int16_t *v3, int order, int mul) { int res = 0; while (order--) { res += *v1 * *v2++; *v1++ += mul * *v3++; } return res; }


static int spapr_nvram_init(VIOsPAPRDevice *dev) { sPAPRNVRAM *nvram = VIO_SPAPR_NVRAM(dev); if (nvram->drive) { nvram->size = bdrv_getlength(nvram->drive); } else { nvram->size = DEFAULT_NVRAM_SIZE; nvram->buf = g_malloc0(nvram->size); } if ((nvram->size < MIN_NVRAM_SIZE) || (nvram->size > MAX_NVRAM_SIZE)) { fprintf(stderr, "spapr-nvram must be between %d and %d bytes in size\n", MIN_NVRAM_SIZE, MAX_NVRAM_SIZE); return -1; } spapr_rtas_register("nvram-fetch", rtas_nvram_fetch); spapr_rtas_register("nvram-store", rtas_nvram_store); return 0; }


static CharDriverState *qemu_chr_open_pp(QemuOpts *opts) { const char *filename = qemu_opt_get(opts, "path"); CharDriverState *chr; int fd; fd = open(filename, O_RDWR); if (fd < 0) return NULL; chr = g_malloc0(sizeof(CharDriverState)); chr->opaque = (void *)(intptr_t)fd; chr->chr_write = null_chr_write; chr->chr_ioctl = pp_ioctl; return chr; }


static void pvpanic_fw_cfg(ISADevice *dev, FWCfgState *fw_cfg) { PVPanicState *s = ISA_PVPANIC_DEVICE(dev); fw_cfg_add_file(fw_cfg, "etc/pvpanic-port", g_memdup(&s->ioport, sizeof(s->ioport)), sizeof(s->ioport)); }


int net_client_init(Monitor *mon, const char *device, const char *p) { char buf[1024]; int vlan_id, ret; VLANState *vlan; char *name = NULL; vlan_id = 0; if (get_param_value(buf, sizeof(buf), "vlan", p)) { vlan_id = strtol(buf, NULL, 0); } vlan = qemu_find_vlan(vlan_id, 1); if (get_param_value(buf, sizeof(buf), "name", p)) { name = qemu_strdup(buf); } if (!strcmp(device, "nic")) { static const char * const nic_params[] = { "vlan", "name", "macaddr", "model", "addr", "id", "vectors", NULL }; NICInfo *nd; uint8_t *macaddr; int idx = nic_get_free_idx(); if (check_params(buf, sizeof(buf), nic_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p); ret = -1; goto out; } if (idx == -1 || nb_nics >= MAX_NICS) { config_error(mon, "Too Many NICs\n"); ret = -1; goto out; } nd = &nd_table[idx]; memset(nd, 0, sizeof(*nd)); macaddr = nd->macaddr; macaddr[0] = 0x52; macaddr[1] = 0x54; macaddr[2] = 0x00; macaddr[3] = 0x12; macaddr[4] = 0x34; macaddr[5] = 0x56 + idx; if (get_param_value(buf, sizeof(buf), "macaddr", p)) { if (parse_macaddr(macaddr, buf) < 0) { config_error(mon, "invalid syntax for ethernet address\n"); ret = -1; goto out; } } if (get_param_value(buf, sizeof(buf), "model", p)) { nd->model = qemu_strdup(buf); } if (get_param_value(buf, sizeof(buf), "addr", p)) { nd->devaddr = qemu_strdup(buf); } if (get_param_value(buf, sizeof(buf), "id", p)) { nd->id = qemu_strdup(buf); } nd->nvectors = NIC_NVECTORS_UNSPECIFIED; if (get_param_value(buf, sizeof(buf), "vectors", p)) { char *endptr; long vectors = strtol(buf, &endptr, 0); if (*endptr) { config_error(mon, "invalid syntax for # of vectors\n"); ret = -1; goto out; } if (vectors < 0 || vectors > 0x7ffffff) { config_error(mon, "invalid # of vectors\n"); ret = -1; goto out; } nd->nvectors = vectors; } nd->vlan = vlan; nd->name = name; nd->used = 1; name = NULL; nb_nics++; vlan->nb_guest_devs++; ret = idx; } else if (!strcmp(device, "none")) { if (*p != '\0') { config_error(mon, "'none' takes no parameters\n"); ret = -1; goto out; } /* does nothing. It is needed to signal that no network cards are wanted */ ret = 0; } else #ifdef CONFIG_SLIRP if (!strcmp(device, "user")) { static const char * const slirp_params[] = { "vlan", "name", "hostname", "restrict", "ip", "net", "host", "tftp", "bootfile", "dhcpstart", "dns", "smb", "smbserver", "hostfwd", "guestfwd", NULL }; struct slirp_config_str *config; int restricted = 0; char *vnet = NULL; char *vhost = NULL; char *vhostname = NULL; char *tftp_export = NULL; char *bootfile = NULL; char *vdhcp_start = NULL; char *vnamesrv = NULL; char *smb_export = NULL; char *vsmbsrv = NULL; const char *q; if (check_params(buf, sizeof(buf), slirp_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p); ret = -1; goto out; } if (get_param_value(buf, sizeof(buf), "ip", p)) { int vnet_buflen = strlen(buf) + strlen("/24") + 1; /* emulate legacy parameter */ vnet = qemu_malloc(vnet_buflen); pstrcpy(vnet, vnet_buflen, buf); pstrcat(vnet, vnet_buflen, "/24"); } if (get_param_value(buf, sizeof(buf), "net", p)) { vnet = qemu_strdup(buf); } if (get_param_value(buf, sizeof(buf), "host", p)) { vhost = qemu_strdup(buf); } if (get_param_value(buf, sizeof(buf), "hostname", p)) { vhostname = qemu_strdup(buf); } if (get_param_value(buf, sizeof(buf), "restrict", p)) { restricted = (buf[0] == 'y') ? 1 : 0; } if (get_param_value(buf, sizeof(buf), "dhcpstart", p)) { vdhcp_start = qemu_strdup(buf); } if (get_param_value(buf, sizeof(buf), "dns", p)) { vnamesrv = qemu_strdup(buf); } if (get_param_value(buf, sizeof(buf), "tftp", p)) { tftp_export = qemu_strdup(buf); } if (get_param_value(buf, sizeof(buf), "bootfile", p)) { bootfile = qemu_strdup(buf); } if (get_param_value(buf, sizeof(buf), "smb", p)) { smb_export = qemu_strdup(buf); if (get_param_value(buf, sizeof(buf), "smbserver", p)) { vsmbsrv = qemu_strdup(buf); } } q = p; while (1) { config = qemu_malloc(sizeof(*config)); if (!get_next_param_value(config->str, sizeof(config->str), "hostfwd", &q)) { break; } config->flags = SLIRP_CFG_HOSTFWD; config->next = slirp_configs; slirp_configs = config; config = NULL; } q = p; while (1) { config = qemu_malloc(sizeof(*config)); if (!get_next_param_value(config->str, sizeof(config->str), "guestfwd", &q)) { break; } config->flags = 0; config->next = slirp_configs; slirp_configs = config; config = NULL; } qemu_free(config); vlan->nb_host_devs++; ret = net_slirp_init(mon, vlan, device, name, restricted, vnet, vhost, vhostname, tftp_export, bootfile, vdhcp_start, vnamesrv, smb_export, vsmbsrv); while (slirp_configs) { config = slirp_configs; slirp_configs = config->next; qemu_free(config); } qemu_free(vnet); qemu_free(vhost); qemu_free(vhostname); qemu_free(tftp_export); qemu_free(bootfile); qemu_free(vdhcp_start); qemu_free(vnamesrv); qemu_free(smb_export); qemu_free(vsmbsrv); } else if (!strcmp(device, "channel")) { if (QTAILQ_EMPTY(&slirp_stacks)) { struct slirp_config_str *config; config = qemu_malloc(sizeof(*config)); pstrcpy(config->str, sizeof(config->str), p); config->flags = SLIRP_CFG_LEGACY; config->next = slirp_configs; slirp_configs = config; } else { slirp_guestfwd(QTAILQ_FIRST(&slirp_stacks), mon, p, 1); } ret = 0; } else #endif #ifdef _WIN32 if (!strcmp(device, "tap")) { static const char * const tap_params[] = { "vlan", "name", "ifname", NULL }; char ifname[64]; if (check_params(buf, sizeof(buf), tap_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p); ret = -1; goto out; } if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { config_error(mon, "tap: no interface name\n"); ret = -1; goto out; } vlan->nb_host_devs++; ret = tap_win32_init(vlan, device, name, ifname); } else #elif defined (_AIX) #else if (!strcmp(device, "tap")) { char ifname[64], chkbuf[64]; char setup_script[1024], down_script[1024]; TAPState *s; int fd; vlan->nb_host_devs++; if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { static const char * const fd_params[] = { "vlan", "name", "fd", "sndbuf", NULL }; ret = -1; if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); goto out; } fd = net_handle_fd_param(mon, buf); if (fd == -1) { goto out; } fcntl(fd, F_SETFL, O_NONBLOCK); s = net_tap_fd_init(vlan, device, name, fd); if (!s) { close(fd); } } else { static const char * const tap_params[] = { "vlan", "name", "ifname", "script", "downscript", "sndbuf", NULL }; if (check_params(chkbuf, sizeof(chkbuf), tap_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); ret = -1; goto out; } if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { ifname[0] = '\0'; } if (get_param_value(setup_script, sizeof(setup_script), "script", p) == 0) { pstrcpy(setup_script, sizeof(setup_script), DEFAULT_NETWORK_SCRIPT); } if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) { pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT); } s = net_tap_init(vlan, device, name, ifname, setup_script, down_script); } if (s != NULL) { const char *sndbuf_str = NULL; if (get_param_value(buf, sizeof(buf), "sndbuf", p)) { sndbuf_str = buf; } tap_set_sndbuf(s, sndbuf_str, mon); ret = 0; } else { ret = -1; } } else #endif if (!strcmp(device, "socket")) { char chkbuf[64]; if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { static const char * const fd_params[] = { "vlan", "name", "fd", NULL }; int fd; ret = -1; if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); goto out; } fd = net_handle_fd_param(mon, buf); if (fd == -1) { goto out; } if (!net_socket_fd_init(vlan, device, name, fd, 1)) { close(fd); goto out; } ret = 0; } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) { static const char * const listen_params[] = { "vlan", "name", "listen", NULL }; if (check_params(chkbuf, sizeof(chkbuf), listen_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); ret = -1; goto out; } ret = net_socket_listen_init(vlan, device, name, buf); } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) { static const char * const connect_params[] = { "vlan", "name", "connect", NULL }; if (check_params(chkbuf, sizeof(chkbuf), connect_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); ret = -1; goto out; } ret = net_socket_connect_init(vlan, device, name, buf); } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) { static const char * const mcast_params[] = { "vlan", "name", "mcast", NULL }; if (check_params(chkbuf, sizeof(chkbuf), mcast_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p); ret = -1; goto out; } ret = net_socket_mcast_init(vlan, device, name, buf); } else { config_error(mon, "Unknown socket options: %s\n", p); ret = -1; goto out; } vlan->nb_host_devs++; } else #ifdef CONFIG_VDE if (!strcmp(device, "vde")) { static const char * const vde_params[] = { "vlan", "name", "sock", "port", "group", "mode", NULL }; char vde_sock[1024], vde_group[512]; int vde_port, vde_mode; if (check_params(buf, sizeof(buf), vde_params, p) < 0) { config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p); ret = -1; goto out; } vlan->nb_host_devs++; if (get_param_value(vde_sock, sizeof(vde_sock), "sock", p) <= 0) { vde_sock[0] = '\0'; } if (get_param_value(buf, sizeof(buf), "port", p) > 0) { vde_port = strtol(buf, NULL, 10); } else { vde_port = 0; } if (get_param_value(vde_group, sizeof(vde_group), "group", p) <= 0) { vde_group[0] = '\0'; } if (get_param_value(buf, sizeof(buf), "mode", p) > 0) { vde_mode = strtol(buf, NULL, 8); } else { vde_mode = 0700; } ret = net_vde_init(vlan, device, name, vde_sock, vde_port, vde_group, vde_mode); } else #endif if (!strcmp(device, "dump")) { int len = 65536; if (get_param_value(buf, sizeof(buf), "len", p) > 0) { len = strtol(buf, NULL, 0); } if (!get_param_value(buf, sizeof(buf), "file", p)) { snprintf(buf, sizeof(buf), "qemu-vlan%d.pcap", vlan_id); } ret = net_dump_init(mon, vlan, device, name, buf, len); } else { config_error(mon, "Unknown network device: %s\n", device); ret = -1; goto out; } if (ret < 0) { config_error(mon, "Could not initialize device '%s'\n", device); } out: qemu_free(name); return ret; }


static void cmv_decode_intra(CmvContext * s, const uint8_t *buf, const uint8_t *buf_end){ unsigned char *dst = s->frame.data[0]; int i; for (i=0; i < s->avctx->height && buf+s->avctx->width<=buf_end; i++) { memcpy(dst, buf, s->avctx->width); dst += s->frame.linesize[0]; buf += s->avctx->width; } }


int av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags) { BufferSinkContext *buf = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; int ret; AVFrame *cur_frame; /* no picref available, fetch it from the filterchain */ if (!av_fifo_size(buf->fifo)) { if (flags & AV_BUFFERSINK_FLAG_NO_REQUEST) return AVERROR(EAGAIN); if ((ret = ff_request_frame(inlink)) < 0) return ret; } if (!av_fifo_size(buf->fifo)) return AVERROR(EINVAL); if (flags & AV_BUFFERSINK_FLAG_PEEK) { cur_frame = *((AVFrame **)av_fifo_peek2(buf->fifo, 0)); av_frame_ref(frame, cur_frame); /* TODO check failure */ } else { av_fifo_generic_read(buf->fifo, &cur_frame, sizeof(cur_frame), NULL); av_frame_move_ref(frame, cur_frame); av_frame_free(&cur_frame); } return 0; }


static int dump_iterate(DumpState *s) { RAMBlock *block; int64_t size; int ret; while (1) { block = s->block; size = block->length; if (s->has_filter) { size -= s->start; if (s->begin + s->length < block->offset + block->length) { size -= block->offset + block->length - (s->begin + s->length); } } ret = write_memory(s, block, s->start, size); if (ret == -1) { return ret; } ret = get_next_block(s, block); if (ret == 1) { dump_completed(s); return 0; } } }


static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val) { #define CASE_SET_REG24(name, addr) \ case addr : s->name &= 0xffffff00; s->name |= val; break; \ case addr + 1: s->name &= 0xffff00ff; s->name |= val << 8; break; \ case addr + 2: s->name &= 0xff00ffff; s->name |= val << 16; break; #define CASE_SET_REG32(name, addr) \ case addr : s->name &= 0xffffff00; s->name |= val; break; \ case addr + 1: s->name &= 0xffff00ff; s->name |= val << 8; break; \ case addr + 2: s->name &= 0xff00ffff; s->name |= val << 16; break; \ case addr + 3: s->name &= 0x00ffffff; s->name |= val << 24; break; #ifdef DEBUG_LSI_REG DPRINTF("Write reg %x = %02x\n", offset, val); #endif switch (offset) { case 0x00: /* SCNTL0 */ s->scntl0 = val; if (val & LSI_SCNTL0_START) { BADF("Start sequence not implemented\n"); } break; case 0x01: /* SCNTL1 */ s->scntl1 = val & ~LSI_SCNTL1_SST; if (val & LSI_SCNTL1_IARB) { BADF("Immediate Arbritration not implemented\n"); } if (val & LSI_SCNTL1_RST) { if (!(s->sstat0 & LSI_SSTAT0_RST)) { BusChild *kid; QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) { DeviceState *dev = kid->child; device_reset(dev); } s->sstat0 |= LSI_SSTAT0_RST; lsi_script_scsi_interrupt(s, LSI_SIST0_RST, 0); } } else { s->sstat0 &= ~LSI_SSTAT0_RST; } break; case 0x02: /* SCNTL2 */ val &= ~(LSI_SCNTL2_WSR | LSI_SCNTL2_WSS); s->scntl2 = val; break; case 0x03: /* SCNTL3 */ s->scntl3 = val; break; case 0x04: /* SCID */ s->scid = val; break; case 0x05: /* SXFER */ s->sxfer = val; break; case 0x06: /* SDID */ if ((val & 0xf) != (s->ssid & 0xf)) BADF("Destination ID does not match SSID\n"); s->sdid = val & 0xf; break; case 0x07: /* GPREG0 */ break; case 0x08: /* SFBR */ /* The CPU is not allowed to write to this register. However the SCRIPTS register move instructions are. */ s->sfbr = val; break; case 0x0a: case 0x0b: /* Openserver writes to these readonly registers on startup */ return; case 0x0c: case 0x0d: case 0x0e: case 0x0f: /* Linux writes to these readonly registers on startup. */ return; CASE_SET_REG32(dsa, 0x10) case 0x14: /* ISTAT0 */ s->istat0 = (s->istat0 & 0x0f) | (val & 0xf0); if (val & LSI_ISTAT0_ABRT) { lsi_script_dma_interrupt(s, LSI_DSTAT_ABRT); } if (val & LSI_ISTAT0_INTF) { s->istat0 &= ~LSI_ISTAT0_INTF; lsi_update_irq(s); } if (s->waiting == 1 && val & LSI_ISTAT0_SIGP) { DPRINTF("Woken by SIGP\n"); s->waiting = 0; s->dsp = s->dnad; lsi_execute_script(s); } if (val & LSI_ISTAT0_SRST) { lsi_soft_reset(s); } break; case 0x16: /* MBOX0 */ s->mbox0 = val; break; case 0x17: /* MBOX1 */ s->mbox1 = val; break; case 0x1a: /* CTEST2 */ s->ctest2 = val & LSI_CTEST2_PCICIE; break; case 0x1b: /* CTEST3 */ s->ctest3 = val & 0x0f; break; CASE_SET_REG32(temp, 0x1c) case 0x21: /* CTEST4 */ if (val & 7) { BADF("Unimplemented CTEST4-FBL 0x%x\n", val); } s->ctest4 = val; break; case 0x22: /* CTEST5 */ if (val & (LSI_CTEST5_ADCK | LSI_CTEST5_BBCK)) { BADF("CTEST5 DMA increment not implemented\n"); } s->ctest5 = val; break; CASE_SET_REG24(dbc, 0x24) CASE_SET_REG32(dnad, 0x28) case 0x2c: /* DSP[0:7] */ s->dsp &= 0xffffff00; s->dsp |= val; break; case 0x2d: /* DSP[8:15] */ s->dsp &= 0xffff00ff; s->dsp |= val << 8; break; case 0x2e: /* DSP[16:23] */ s->dsp &= 0xff00ffff; s->dsp |= val << 16; break; case 0x2f: /* DSP[24:31] */ s->dsp &= 0x00ffffff; s->dsp |= val << 24; if ((s->dmode & LSI_DMODE_MAN) == 0 && (s->istat1 & LSI_ISTAT1_SRUN) == 0) lsi_execute_script(s); break; CASE_SET_REG32(dsps, 0x30) CASE_SET_REG32(scratch[0], 0x34) case 0x38: /* DMODE */ if (val & (LSI_DMODE_SIOM | LSI_DMODE_DIOM)) { BADF("IO mappings not implemented\n"); } s->dmode = val; break; case 0x39: /* DIEN */ s->dien = val; lsi_update_irq(s); break; case 0x3a: /* SBR */ s->sbr = val; break; case 0x3b: /* DCNTL */ s->dcntl = val & ~(LSI_DCNTL_PFF | LSI_DCNTL_STD); if ((val & LSI_DCNTL_STD) && (s->istat1 & LSI_ISTAT1_SRUN) == 0) lsi_execute_script(s); break; case 0x40: /* SIEN0 */ s->sien0 = val; lsi_update_irq(s); break; case 0x41: /* SIEN1 */ s->sien1 = val; lsi_update_irq(s); break; case 0x47: /* GPCNTL0 */ break; case 0x48: /* STIME0 */ s->stime0 = val; break; case 0x49: /* STIME1 */ if (val & 0xf) { DPRINTF("General purpose timer not implemented\n"); /* ??? Raising the interrupt immediately seems to be sufficient to keep the FreeBSD driver happy. */ lsi_script_scsi_interrupt(s, 0, LSI_SIST1_GEN); } break; case 0x4a: /* RESPID0 */ s->respid0 = val; break; case 0x4b: /* RESPID1 */ s->respid1 = val; break; case 0x4d: /* STEST1 */ s->stest1 = val; break; case 0x4e: /* STEST2 */ if (val & 1) { BADF("Low level mode not implemented\n"); } s->stest2 = val; break; case 0x4f: /* STEST3 */ if (val & 0x41) { BADF("SCSI FIFO test mode not implemented\n"); } s->stest3 = val; break; case 0x56: /* CCNTL0 */ s->ccntl0 = val; break; case 0x57: /* CCNTL1 */ s->ccntl1 = val; break; CASE_SET_REG32(mmrs, 0xa0) CASE_SET_REG32(mmws, 0xa4) CASE_SET_REG32(sfs, 0xa8) CASE_SET_REG32(drs, 0xac) CASE_SET_REG32(sbms, 0xb0) CASE_SET_REG32(dbms, 0xb4) CASE_SET_REG32(dnad64, 0xb8) CASE_SET_REG32(pmjad1, 0xc0) CASE_SET_REG32(pmjad2, 0xc4) CASE_SET_REG32(rbc, 0xc8) CASE_SET_REG32(ua, 0xcc) CASE_SET_REG32(ia, 0xd4) CASE_SET_REG32(sbc, 0xd8) CASE_SET_REG32(csbc, 0xdc) default: if (offset >= 0x5c && offset < 0xa0) { int n; int shift; n = (offset - 0x58) >> 2; shift = (offset & 3) * 8; s->scratch[n] &= ~(0xff << shift); s->scratch[n] |= (val & 0xff) << shift; } else { BADF("Unhandled writeb 0x%x = 0x%x\n", offset, val); } } #undef CASE_SET_REG24 #undef CASE_SET_REG32 }


static inline void tcg_out_op(TCGContext *s, int opc, const TCGArg *args, const int *const_args) { int c; switch (opc) { case INDEX_op_exit_tb: tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I0, args[0]); tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I7) | INSN_IMM13(8)); tcg_out32(s, RESTORE | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_G0) | INSN_RS2(TCG_REG_G0)); break; case INDEX_op_goto_tb: if (s->tb_jmp_offset) { /* direct jump method */ if (ABS(args[0] - (unsigned long)s->code_ptr) == (ABS(args[0] - (unsigned long)s->code_ptr) & 0x1fffff)) { tcg_out32(s, BA | INSN_OFF22(args[0] - (unsigned long)s->code_ptr)); } else { tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, args[0]); tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) | INSN_RS2(TCG_REG_G0)); } s->tb_jmp_offset[args[0]] = s->code_ptr - s->code_buf; } else { /* indirect jump method */ tcg_out_ld_ptr(s, TCG_REG_I5, (tcg_target_long)(s->tb_next + args[0])); tcg_out32(s, JMPL | INSN_RD(TCG_REG_G0) | INSN_RS1(TCG_REG_I5) | INSN_RS2(TCG_REG_G0)); } tcg_out_nop(s); s->tb_next_offset[args[0]] = s->code_ptr - s->code_buf; break; case INDEX_op_call: if (const_args[0]) { tcg_out32(s, CALL | ((((tcg_target_ulong)args[0] - (tcg_target_ulong)s->code_ptr) >> 2) & 0x3fffffff)); tcg_out_nop(s); } else { tcg_out_ld_ptr(s, TCG_REG_O7, (tcg_target_long)(s->tb_next + args[0])); tcg_out32(s, JMPL | INSN_RD(TCG_REG_O7) | INSN_RS1(TCG_REG_O7) | INSN_RS2(TCG_REG_G0)); tcg_out_nop(s); } break; case INDEX_op_jmp: fprintf(stderr, "unimplemented jmp\n"); break; case INDEX_op_br: fprintf(stderr, "unimplemented br\n"); break; case INDEX_op_movi_i32: tcg_out_movi(s, TCG_TYPE_I32, args[0], (uint32_t)args[1]); break; #if defined(__sparc_v9__) && !defined(__sparc_v8plus__) #define OP_32_64(x) \ glue(glue(case INDEX_op_, x), _i32:) \ glue(glue(case INDEX_op_, x), _i64:) #else #define OP_32_64(x) \ glue(glue(case INDEX_op_, x), _i32:) #endif OP_32_64(ld8u); tcg_out_ldst(s, args[0], args[1], args[2], LDUB); break; OP_32_64(ld8s); tcg_out_ldst(s, args[0], args[1], args[2], LDSB); break; OP_32_64(ld16u); tcg_out_ldst(s, args[0], args[1], args[2], LDUH); break; OP_32_64(ld16s); tcg_out_ldst(s, args[0], args[1], args[2], LDSH); break; case INDEX_op_ld_i32: #if defined(__sparc_v9__) && !defined(__sparc_v8plus__) case INDEX_op_ld32u_i64: #endif tcg_out_ldst(s, args[0], args[1], args[2], LDUW); break; OP_32_64(st8); tcg_out_ldst(s, args[0], args[1], args[2], STB); break; OP_32_64(st16); tcg_out_ldst(s, args[0], args[1], args[2], STH); break; case INDEX_op_st_i32: #if defined(__sparc_v9__) && !defined(__sparc_v8plus__) case INDEX_op_st32_i64: #endif tcg_out_ldst(s, args[0], args[1], args[2], STW); break; OP_32_64(add); c = ARITH_ADD; goto gen_arith32; OP_32_64(sub); c = ARITH_SUB; goto gen_arith32; OP_32_64(and); c = ARITH_AND; goto gen_arith32; OP_32_64(or); c = ARITH_OR; goto gen_arith32; OP_32_64(xor); c = ARITH_XOR; goto gen_arith32; case INDEX_op_shl_i32: c = SHIFT_SLL; goto gen_arith32; case INDEX_op_shr_i32: c = SHIFT_SRL; goto gen_arith32; case INDEX_op_sar_i32: c = SHIFT_SRA; goto gen_arith32; case INDEX_op_mul_i32: c = ARITH_UMUL; goto gen_arith32; case INDEX_op_div2_i32: #if defined(__sparc_v9__) || defined(__sparc_v8plus__) c = ARITH_SDIVX; goto gen_arith32; #else tcg_out_sety(s, 0); c = ARITH_SDIV; goto gen_arith32; #endif case INDEX_op_divu2_i32: #if defined(__sparc_v9__) || defined(__sparc_v8plus__) c = ARITH_UDIVX; goto gen_arith32; #else tcg_out_sety(s, 0); c = ARITH_UDIV; goto gen_arith32; #endif case INDEX_op_brcond_i32: fprintf(stderr, "unimplemented brcond\n"); break; case INDEX_op_qemu_ld8u: fprintf(stderr, "unimplemented qld\n"); break; case INDEX_op_qemu_ld8s: fprintf(stderr, "unimplemented qld\n"); break; case INDEX_op_qemu_ld16u: fprintf(stderr, "unimplemented qld\n"); break; case INDEX_op_qemu_ld16s: fprintf(stderr, "unimplemented qld\n"); break; case INDEX_op_qemu_ld32u: fprintf(stderr, "unimplemented qld\n"); break; case INDEX_op_qemu_ld32s: fprintf(stderr, "unimplemented qld\n"); break; case INDEX_op_qemu_st8: fprintf(stderr, "unimplemented qst\n"); break; case INDEX_op_qemu_st16: fprintf(stderr, "unimplemented qst\n"); break; case INDEX_op_qemu_st32: fprintf(stderr, "unimplemented qst\n"); break; #if defined(__sparc_v9__) && !defined(__sparc_v8plus__) case INDEX_op_movi_i64: tcg_out_movi(s, TCG_TYPE_I64, args[0], args[1]); break; case INDEX_op_ld32s_i64: tcg_out_ldst(s, args[0], args[1], args[2], LDSW); break; case INDEX_op_ld_i64: tcg_out_ldst(s, args[0], args[1], args[2], LDX); break; case INDEX_op_st_i64: tcg_out_ldst(s, args[0], args[1], args[2], STX); break; case INDEX_op_shl_i64: c = SHIFT_SLLX; goto gen_arith32; case INDEX_op_shr_i64: c = SHIFT_SRLX; goto gen_arith32; case INDEX_op_sar_i64: c = SHIFT_SRAX; goto gen_arith32; case INDEX_op_mul_i64: c = ARITH_MULX; goto gen_arith32; case INDEX_op_div2_i64: c = ARITH_SDIVX; goto gen_arith32; case INDEX_op_divu2_i64: c = ARITH_UDIVX; goto gen_arith32; case INDEX_op_brcond_i64: fprintf(stderr, "unimplemented brcond\n"); break; case INDEX_op_qemu_ld64: fprintf(stderr, "unimplemented qld\n"); break; case INDEX_op_qemu_st64: fprintf(stderr, "unimplemented qst\n"); break; #endif gen_arith32: if (const_args[2]) { tcg_out_arithi(s, args[0], args[1], args[2], c); } else { tcg_out_arith(s, args[0], args[1], args[2], c); } break; default: fprintf(stderr, "unknown opcode 0x%x\n", opc); tcg_abort(); } }


void os_mem_prealloc(int fd, char *area, size_t memory) { int ret; struct sigaction act, oldact; sigset_t set, oldset; memset(&act, 0, sizeof(act)); act.sa_handler = &sigbus_handler; act.sa_flags = 0; ret = sigaction(SIGBUS, &act, &oldact); if (ret) { perror("os_mem_prealloc: failed to install signal handler"); exit(1); } /* unblock SIGBUS */ sigemptyset(&set); sigaddset(&set, SIGBUS); pthread_sigmask(SIG_UNBLOCK, &set, &oldset); if (sigsetjmp(sigjump, 1)) { fprintf(stderr, "os_mem_prealloc: Insufficient free host memory " "pages available to allocate guest RAM\n"); exit(1); } else { int i; size_t hpagesize = fd_getpagesize(fd); size_t numpages = DIV_ROUND_UP(memory, hpagesize); /* MAP_POPULATE silently ignores failures */ for (i = 0; i < numpages; i++) { memset(area + (hpagesize * i), 0, 1); } ret = sigaction(SIGBUS, &oldact, NULL); if (ret) { perror("os_mem_prealloc: failed to reinstall signal handler"); exit(1); } pthread_sigmask(SIG_SETMASK, &oldset, NULL); } }


int usb_handle_packet(USBDevice *dev, USBPacket *p) { int ret; if (dev == NULL) { return USB_RET_NODEV; } assert(dev->addr == p->devaddr); assert(dev->state == USB_STATE_DEFAULT); assert(p->state == USB_PACKET_SETUP); if (p->devep == 0) { /* control pipe */ switch (p->pid) { case USB_TOKEN_SETUP: ret = do_token_setup(dev, p); break; case USB_TOKEN_IN: ret = do_token_in(dev, p); break; case USB_TOKEN_OUT: ret = do_token_out(dev, p); break; default: ret = USB_RET_STALL; break; } } else { /* data pipe */ ret = usb_device_handle_data(dev, p); } if (ret == USB_RET_ASYNC) { p->ep = usb_ep_get(dev, p->pid, p->devep); p->state = USB_PACKET_ASYNC; } return ret; }


build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offset) { AcpiRsdpDescriptor *rsdp = acpi_data_push(rsdp_table, sizeof *rsdp); unsigned rsdt_pa_size = sizeof(rsdp->rsdt_physical_address); unsigned rsdt_pa_offset = (char *)&rsdp->rsdt_physical_address - rsdp_table->data; bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16, true /* fseg memory */); memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature)); memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, sizeof(rsdp->oem_id)); rsdp->length = cpu_to_le32(sizeof(*rsdp)); rsdp->revision = 0x02; /* Address to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size, ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset); rsdp->checksum = 0; /* Checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, rsdp, sizeof *rsdp, &rsdp->checksum); return rsdp_table; }


static inline uint32_t vmsvga_fifo_read_raw(struct vmsvga_state_s *s) { uint32_t cmd = s->fifo[CMD(stop) >> 2]; s->cmd->stop = cpu_to_le32(CMD(stop) + 4); if (CMD(stop) >= CMD(max)) s->cmd->stop = s->cmd->min; return cmd; }


static void rv40_loop_filter(RV34DecContext *r, int row) { MpegEncContext *s = &r->s; int mb_pos, mb_x; int i, j, k; uint8_t *Y, *C; int alpha, beta, betaY, betaC; int q; int mbtype[4]; ///< current macroblock and its neighbours types /** * flags indicating that macroblock can be filtered with strong filter * it is set only for intra coded MB and MB with DCs coded separately */ int mb_strong[4]; int clip[4]; ///< MB filter clipping value calculated from filtering strength /** * coded block patterns for luma part of current macroblock and its neighbours * Format: * LSB corresponds to the top left block, * each nibble represents one row of subblocks. */ int cbp[4]; /** * coded block patterns for chroma part of current macroblock and its neighbours * Format is the same as for luma with two subblocks in a row. */ int uvcbp[4][2]; /** * This mask represents the pattern of luma subblocks that should be filtered * in addition to the coded ones because because they lie at the edge of * 8x8 block with different enough motion vectors */ int mvmasks[4]; mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int mbtype = s->current_picture_ptr->f.mb_type[mb_pos]; if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype)) r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF; if(IS_INTRA(mbtype)) r->cbp_chroma[mb_pos] = 0xFF; } mb_pos = row * s->mb_stride; for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ int y_h_deblock, y_v_deblock; int c_v_deblock[2], c_h_deblock[2]; int clip_left; int avail[4]; int y_to_deblock, c_to_deblock[2]; q = s->current_picture_ptr->f.qscale_table[mb_pos]; alpha = rv40_alpha_tab[q]; beta = rv40_beta_tab [q]; betaY = betaC = beta * 3; if(s->width * s->height <= 176*144) betaY += beta; avail[0] = 1; avail[1] = row; avail[2] = mb_x; avail[3] = row < s->mb_height - 1; for(i = 0; i < 4; i++){ if(avail[i]){ int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride; mvmasks[i] = r->deblock_coefs[pos]; mbtype [i] = s->current_picture_ptr->f.mb_type[pos]; cbp [i] = r->cbp_luma[pos]; uvcbp[i][0] = r->cbp_chroma[pos] & 0xF; uvcbp[i][1] = r->cbp_chroma[pos] >> 4; }else{ mvmasks[i] = 0; mbtype [i] = mbtype[0]; cbp [i] = 0; uvcbp[i][0] = uvcbp[i][1] = 0; } mb_strong[i] = IS_INTRA(mbtype[i]) || IS_SEPARATE_DC(mbtype[i]); clip[i] = rv40_filter_clip_tbl[mb_strong[i] + 1][q]; } y_to_deblock = mvmasks[POS_CUR] | (mvmasks[POS_BOTTOM] << 16); /* This pattern contains bits signalling that horizontal edges of * the current block can be filtered. * That happens when either of adjacent subblocks is coded or lies on * the edge of 8x8 blocks with motion vectors differing by more than * 3/4 pel in any component (any edge orientation for some reason). */ y_h_deblock = y_to_deblock | ((cbp[POS_CUR] << 4) & ~MASK_Y_TOP_ROW) | ((cbp[POS_TOP] & MASK_Y_LAST_ROW) >> 12); /* This pattern contains bits signalling that vertical edges of * the current block can be filtered. * That happens when either of adjacent subblocks is coded or lies on * the edge of 8x8 blocks with motion vectors differing by more than * 3/4 pel in any component (any edge orientation for some reason). */ y_v_deblock = y_to_deblock | ((cbp[POS_CUR] << 1) & ~MASK_Y_LEFT_COL) | ((cbp[POS_LEFT] & MASK_Y_RIGHT_COL) >> 3); if(!mb_x) y_v_deblock &= ~MASK_Y_LEFT_COL; if(!row) y_h_deblock &= ~MASK_Y_TOP_ROW; if(row == s->mb_height - 1 || (mb_strong[POS_CUR] || mb_strong[POS_BOTTOM])) y_h_deblock &= ~(MASK_Y_TOP_ROW << 16); /* Calculating chroma patterns is similar and easier since there is * no motion vector pattern for them. */ for(i = 0; i < 2; i++){ c_to_deblock[i] = (uvcbp[POS_BOTTOM][i] << 4) | uvcbp[POS_CUR][i]; c_v_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_CUR] [i] << 1) & ~MASK_C_LEFT_COL) | ((uvcbp[POS_LEFT][i] & MASK_C_RIGHT_COL) >> 1); c_h_deblock[i] = c_to_deblock[i] | ((uvcbp[POS_TOP][i] & MASK_C_LAST_ROW) >> 2) | (uvcbp[POS_CUR][i] << 2); if(!mb_x) c_v_deblock[i] &= ~MASK_C_LEFT_COL; if(!row) c_h_deblock[i] &= ~MASK_C_TOP_ROW; if(row == s->mb_height - 1 || mb_strong[POS_CUR] || mb_strong[POS_BOTTOM]) c_h_deblock[i] &= ~(MASK_C_TOP_ROW << 4); } for(j = 0; j < 16; j += 4){ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize; for(i = 0; i < 4; i++, Y += 4){ int ij = i + j; int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0; int dither = j ? ij : i*4; // if bottom block is coded then we can filter its top edge // (or bottom edge of this block, which is the same) if(y_h_deblock & (MASK_BOTTOM << ij)){ r->rdsp.rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither, y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0, clip_cur, alpha, beta, betaY, 0, 0); } // filter left block edge in ordinary mode (with low filtering strength) if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; else clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; r->rdsp.rv40_v_loop_filter(Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 0); } // filter top edge of the current macroblock when filtering strength is high if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ r->rdsp.rv40_h_loop_filter(Y, s->linesize, dither, clip_cur, mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0, alpha, beta, betaY, 0, 1); } // filter left block edge in edge mode (with high filtering strength) if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; r->rdsp.rv40_v_loop_filter(Y, s->linesize, dither, clip_cur, clip_left, alpha, beta, betaY, 0, 1); } } } for(k = 0; k < 2; k++){ for(j = 0; j < 2; j++){ C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize; for(i = 0; i < 2; i++, C += 4){ int ij = i + j*2; int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0; if(c_h_deblock[k] & (MASK_CUR << (ij+2))){ int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0; r->rdsp.rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8, clip_bot, clip_cur, alpha, beta, betaC, 1, 0); } if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ if(!i) clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; else clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; r->rdsp.rv40_v_loop_filter(C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 0); } if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0; r->rdsp.rv40_h_loop_filter(C, s->uvlinesize, i*8, clip_cur, clip_top, alpha, beta, betaC, 1, 1); } if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; r->rdsp.rv40_v_loop_filter(C, s->uvlinesize, j*8, clip_cur, clip_left, alpha, beta, betaC, 1, 1); } } } } } }


static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) { BlockDriverState *old_bs = child->bs; if (old_bs) { if (old_bs->quiesce_counter && child->role->drained_end) { child->role->drained_end(child); } QLIST_REMOVE(child, next_parent); } child->bs = new_bs; if (new_bs) { QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); if (new_bs->quiesce_counter && child->role->drained_begin) { child->role->drained_begin(child); } } }


void qemu_ram_free(ram_addr_t addr) { RAMBlock *block; /* This assumes the iothread lock is taken here too. */ qemu_mutex_lock_ramlist(); QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (addr == block->offset) { QTAILQ_REMOVE(&ram_list.blocks, block, next); ram_list.mru_block = NULL; ram_list.version++; if (block->flags & RAM_PREALLOC_MASK) { ; } else if (xen_enabled()) { xen_invalidate_map_cache_entry(block->host); } else if (mem_path) { #if defined (__linux__) && !defined(TARGET_S390X) if (block->fd) { munmap(block->host, block->length); close(block->fd); } else { qemu_anon_ram_free(block->host, block->length); } #else abort(); #endif } else { qemu_anon_ram_free(block->host, block->length); } g_free(block); break; } } qemu_mutex_unlock_ramlist(); }