static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, int64_t pos, uint64_t cluster_time, uint64_t duration, int is_keyframe, int64_t cluster_pos) { uint64_t timecode = AV_NOPTS_VALUE; MatroskaTrack *track; int res = 0; AVStream *st; AVPacket *pkt; int16_t block_time; uint32_t *lace_size = NULL; int n, flags, laces = 0; uint64_t num; if ((n = matroska_ebmlnum_uint(matroska, data, size, &num)) < 0) { av_log(matroska->ctx, AV_LOG_ERROR, "EBML block data error\n"); return res; } data += n; size -= n; track = matroska_find_track_by_num(matroska, num); if (size <= 3 || !track || !track->stream) { av_log(matroska->ctx, AV_LOG_INFO, "Invalid stream %"PRIu64" or size %u\n", num, size); return res; } st = track->stream; if (st->discard >= AVDISCARD_ALL) return res; if (duration == AV_NOPTS_VALUE) duration = track->default_duration / matroska->time_scale; block_time = AV_RB16(data); data += 2; flags = *data++; size -= 3; if (is_keyframe == -1) is_keyframe = flags & 0x80 ? PKT_FLAG_KEY : 0; if (cluster_time != (uint64_t)-1 && (block_time >= 0 || cluster_time >= -block_time)) { timecode = cluster_time + block_time; if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE && timecode < track->end_timecode) is_keyframe = 0; /* overlapping subtitles are not key frame */ if (is_keyframe) av_add_index_entry(st, cluster_pos, timecode, 0,0,AVINDEX_KEYFRAME); track->end_timecode = FFMAX(track->end_timecode, timecode+duration); } if (matroska->skip_to_keyframe && track->type != MATROSKA_TRACK_TYPE_SUBTITLE) { if (!is_keyframe || timecode < matroska->skip_to_timecode) return res; matroska->skip_to_keyframe = 0; } switch ((flags & 0x06) >> 1) { case 0x0: /* no lacing */ laces = 1; lace_size = av_mallocz(sizeof(int)); lace_size[0] = size; break; case 0x1: /* Xiph lacing */ case 0x2: /* fixed-size lacing */ case 0x3: /* EBML lacing */ assert(size>0); // size <=3 is checked before size-=3 above laces = (*data) + 1; data += 1; size -= 1; lace_size = av_mallocz(laces * sizeof(int)); switch ((flags & 0x06) >> 1) { case 0x1: /* Xiph lacing */ { uint8_t temp; uint32_t total = 0; for (n = 0; res == 0 && n < laces - 1; n++) { while (1) { if (size == 0) { res = -1; break; } temp = *data; lace_size[n] += temp; data += 1; size -= 1; if (temp != 0xff) break; } total += lace_size[n]; } lace_size[n] = size - total; break; } case 0x2: /* fixed-size lacing */ for (n = 0; n < laces; n++) lace_size[n] = size / laces; break; case 0x3: /* EBML lacing */ { uint32_t total; n = matroska_ebmlnum_uint(matroska, data, size, &num); if (n < 0) { av_log(matroska->ctx, AV_LOG_INFO, "EBML block data error\n"); break; } data += n; size -= n; total = lace_size[0] = num; for (n = 1; res == 0 && n < laces - 1; n++) { int64_t snum; int r; r = matroska_ebmlnum_sint(matroska, data, size, &snum); if (r < 0) { av_log(matroska->ctx, AV_LOG_INFO, "EBML block data error\n"); break; } data += r; size -= r; lace_size[n] = lace_size[n - 1] + snum; total += lace_size[n]; } lace_size[n] = size - total; break; } } break; } if (res == 0) { for (n = 0; n < laces; n++) { if (st->codec->codec_id == CODEC_ID_RA_288 || st->codec->codec_id == CODEC_ID_COOK || st->codec->codec_id == CODEC_ID_ATRAC3) { int a = st->codec->block_align; int sps = track->audio.sub_packet_size; int cfs = track->audio.coded_framesize; int h = track->audio.sub_packet_h; int y = track->audio.sub_packet_cnt; int w = track->audio.frame_size; int x; if (!track->audio.pkt_cnt) { if (st->codec->codec_id == CODEC_ID_RA_288) for (x=0; x<h/2; x++) memcpy(track->audio.buf+x*2*w+y*cfs, data+x*cfs, cfs); else for (x=0; x<w/sps; x++) memcpy(track->audio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps); if (++track->audio.sub_packet_cnt >= h) { track->audio.sub_packet_cnt = 0; track->audio.pkt_cnt = h*w / a; } } while (track->audio.pkt_cnt) { pkt = av_mallocz(sizeof(AVPacket)); av_new_packet(pkt, a); memcpy(pkt->data, track->audio.buf + a * (h*w / a - track->audio.pkt_cnt--), a); pkt->pos = pos; pkt->stream_index = st->index; dynarray_add(&matroska->packets,&matroska->num_packets,pkt); } } else { MatroskaTrackEncoding *encodings = track->encodings.elem; int offset = 0, pkt_size = lace_size[n]; uint8_t *pkt_data = data; if (encodings && encodings->scope & 1) { offset = matroska_decode_buffer(&pkt_data,&pkt_size, track); if (offset < 0) continue; } pkt = av_mallocz(sizeof(AVPacket)); /* XXX: prevent data copy... */ if (av_new_packet(pkt, pkt_size+offset) < 0) { av_free(pkt); res = AVERROR(ENOMEM); break; } if (offset) memcpy (pkt->data, encodings->compression.settings.data, offset); memcpy (pkt->data+offset, pkt_data, pkt_size); if (pkt_data != data) av_free(pkt_data); if (n == 0) pkt->flags = is_keyframe; pkt->stream_index = st->index; pkt->pts = timecode; pkt->pos = pos; if (st->codec->codec_id == CODEC_ID_TEXT) pkt->convergence_duration = duration; else if (track->type != MATROSKA_TRACK_TYPE_SUBTITLE) pkt->duration = duration; if (st->codec->codec_id == CODEC_ID_SSA) matroska_fix_ass_packet(matroska, pkt, duration); if (matroska->prev_pkt && timecode != AV_NOPTS_VALUE && matroska->prev_pkt->pts == timecode && matroska->prev_pkt->stream_index == st->index) matroska_merge_packets(matroska->prev_pkt, pkt); else { dynarray_add(&matroska->packets,&matroska->num_packets,pkt); matroska->prev_pkt = pkt; } } if (timecode != AV_NOPTS_VALUE) timecode = duration ? timecode + duration : AV_NOPTS_VALUE; data += lace_size[n]; } } av_free(lace_size); return res; }


static int coroutine_fn backup_do_cow(BlockDriverState *bs, int64_t sector_num, int nb_sectors, bool *error_is_read, bool is_write_notifier) { BackupBlockJob *job = (BackupBlockJob *)bs->job; CowRequest cow_request; struct iovec iov; QEMUIOVector bounce_qiov; void *bounce_buffer = NULL; int ret = 0; int64_t sectors_per_cluster = cluster_size_sectors(job); int64_t start, end; int n; qemu_co_rwlock_rdlock(&job->flush_rwlock); start = sector_num / sectors_per_cluster; end = DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster); trace_backup_do_cow_enter(job, start, sector_num, nb_sectors); wait_for_overlapping_requests(job, start, end); cow_request_begin(&cow_request, job, start, end); for (; start < end; start++) { if (hbitmap_get(job->bitmap, start)) { trace_backup_do_cow_skip(job, start); continue; /* already copied */ } trace_backup_do_cow_process(job, start); n = MIN(sectors_per_cluster, job->common.len / BDRV_SECTOR_SIZE - start * sectors_per_cluster); if (!bounce_buffer) { bounce_buffer = qemu_blockalign(bs, job->cluster_size); } iov.iov_base = bounce_buffer; iov.iov_len = n * BDRV_SECTOR_SIZE; qemu_iovec_init_external(&bounce_qiov, &iov, 1); if (is_write_notifier) { ret = bdrv_co_readv_no_serialising(bs, start * sectors_per_cluster, n, &bounce_qiov); } else { ret = bdrv_co_readv(bs, start * sectors_per_cluster, n, &bounce_qiov); } if (ret < 0) { trace_backup_do_cow_read_fail(job, start, ret); if (error_is_read) { *error_is_read = true; } goto out; } if (buffer_is_zero(iov.iov_base, iov.iov_len)) { ret = bdrv_co_write_zeroes(job->target, start * sectors_per_cluster, n, BDRV_REQ_MAY_UNMAP); } else { ret = bdrv_co_writev(job->target, start * sectors_per_cluster, n, &bounce_qiov); } if (ret < 0) { trace_backup_do_cow_write_fail(job, start, ret); if (error_is_read) { *error_is_read = false; } goto out; } hbitmap_set(job->bitmap, start, 1); /* Publish progress, guest I/O counts as progress too. Note that the * offset field is an opaque progress value, it is not a disk offset. */ job->sectors_read += n; job->common.offset += n * BDRV_SECTOR_SIZE; } out: if (bounce_buffer) { qemu_vfree(bounce_buffer); } cow_request_end(&cow_request); trace_backup_do_cow_return(job, sector_num, nb_sectors, ret); qemu_co_rwlock_unlock(&job->flush_rwlock); return ret; }


static void gen_dcbz(DisasContext *ctx) { TCGv tcgv_addr; TCGv_i32 tcgv_is_dcbzl; int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0; gen_set_access_type(ctx, ACCESS_CACHE); tcgv_addr = tcg_temp_new(); tcgv_is_dcbzl = tcg_const_i32(is_dcbzl); gen_addr_reg_index(ctx, tcgv_addr); gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl); tcg_temp_free(tcgv_addr); tcg_temp_free_i32(tcgv_is_dcbzl); }


static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPHeader *h) { HTTPContext *rtp_c; rtp_c = find_rtp_session_with_url(url, h->session_id); if (!rtp_c) { rtsp_reply_error(c, RTSP_STATUS_SESSION); return; } if (rtp_c->state != HTTPSTATE_SEND_DATA && rtp_c->state != HTTPSTATE_WAIT_FEED) { rtsp_reply_error(c, RTSP_STATUS_STATE); return; } rtp_c->state = HTTPSTATE_READY; /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id); url_fprintf(c->pb, "\r\n"); }


static void spapr_vio_quiesce_one(VIOsPAPRDevice *dev) { if (dev->tcet) { spapr_tce_reset(dev->tcet); } free_crq(dev); }


PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem, hwaddr base, BlockDriverState *bd, qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma) { PXA2xxMMCIState *s; s = (PXA2xxMMCIState *) g_malloc0(sizeof(PXA2xxMMCIState)); s->irq = irq; s->rx_dma = rx_dma; s->tx_dma = tx_dma; memory_region_init_io(&s->iomem, NULL, &pxa2xx_mmci_ops, s, "pxa2xx-mmci", 0x00100000); memory_region_add_subregion(sysmem, base, &s->iomem); /* Instantiate the actual storage */ s->card = sd_init(bd, false); if (s->card == NULL) { exit(1); } register_savevm(NULL, "pxa2xx_mmci", 0, 0, pxa2xx_mmci_save, pxa2xx_mmci_load, s); return s; }


int64_t timerlist_deadline_ns(QEMUTimerList *timer_list) { int64_t delta; if (!timer_list->clock->enabled || !timer_list->active_timers) { return -1; } delta = timer_list->active_timers->expire_time - qemu_clock_get_ns(timer_list->clock->type); if (delta <= 0) { return 0; } return delta; }


void *qemu_mallocz(size_t size) { void *ptr; ptr = qemu_malloc(size); if (!ptr) return NULL; memset(ptr, 0, size); return ptr; }


sosendoob(struct socket *so) { struct sbuf *sb = &so->so_rcv; char buff[2048]; /* XXX Shouldn't be sending more oob data than this */ int n, len; DEBUG_CALL("sosendoob"); DEBUG_ARG("so = %p", so); DEBUG_ARG("sb->sb_cc = %d", sb->sb_cc); if (so->so_urgc > 2048) so->so_urgc = 2048; /* XXXX */ if (sb->sb_rptr < sb->sb_wptr) { /* We can send it directly */ n = slirp_send(so, sb->sb_rptr, so->so_urgc, (MSG_OOB)); /* |MSG_DONTWAIT)); */ so->so_urgc -= n; DEBUG_MISC((dfd, " --- sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc)); } else { /* * Since there's no sendv or sendtov like writev, * we must copy all data to a linear buffer then * send it all */ len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr; if (len > so->so_urgc) len = so->so_urgc; memcpy(buff, sb->sb_rptr, len); so->so_urgc -= len; if (so->so_urgc) { n = sb->sb_wptr - sb->sb_data; if (n > so->so_urgc) n = so->so_urgc; memcpy((buff + len), sb->sb_data, n); so->so_urgc -= n; len += n; } n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */ #ifdef DEBUG if (n != len) DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n")); #endif DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc)); } sb->sb_cc -= n; sb->sb_rptr += n; if (sb->sb_rptr >= (sb->sb_data + sb->sb_datalen)) sb->sb_rptr -= sb->sb_datalen; return n; }


AVParserState *ff_store_parser_state(AVFormatContext *s) { int i; AVStream *st; AVParserStreamState *ss; AVParserState *state = av_malloc(sizeof(AVParserState)); if (!state) return NULL; state->stream_states = av_malloc(sizeof(AVParserStreamState) * s->nb_streams); if (!state->stream_states) { av_free(state); return NULL; } state->fpos = avio_tell(s->pb); // copy context structures state->cur_st = s->cur_st; state->packet_buffer = s->packet_buffer; state->raw_packet_buffer = s->raw_packet_buffer; state->raw_packet_buffer_remaining_size = s->raw_packet_buffer_remaining_size; s->cur_st = NULL; s->packet_buffer = NULL; s->raw_packet_buffer = NULL; s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; // copy stream structures state->nb_streams = s->nb_streams; for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; ss = &state->stream_states[i]; ss->parser = st->parser; ss->last_IP_pts = st->last_IP_pts; ss->cur_dts = st->cur_dts; ss->reference_dts = st->reference_dts; ss->cur_ptr = st->cur_ptr; ss->cur_len = st->cur_len; ss->probe_packets = st->probe_packets; ss->cur_pkt = st->cur_pkt; st->parser = NULL; st->last_IP_pts = AV_NOPTS_VALUE; st->cur_dts = AV_NOPTS_VALUE; st->reference_dts = AV_NOPTS_VALUE; st->cur_ptr = NULL; st->cur_len = 0; st->probe_packets = MAX_PROBE_PACKETS; av_init_packet(&st->cur_pkt); } return state; }


void ff_mpegts_parse_close(MpegTSContext *ts) { int i; for(i=0;i<NB_PID_MAX;i++) av_free(ts->pids[i]); av_free(ts); }


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


static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; PadContext *s = ctx->priv; const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); uint8_t rgba_color[4]; int ret, is_packed_rgba; double var_values[VARS_NB], res; char *expr; s->hsub = pix_desc->log2_chroma_w; s->vsub = pix_desc->log2_chroma_h; var_values[VAR_PI] = M_PI; var_values[VAR_PHI] = M_PHI; var_values[VAR_E] = M_E; var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN; var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN; var_values[VAR_A] = (double) inlink->w / inlink->h; var_values[VAR_HSUB] = 1<<s->hsub; var_values[VAR_VSUB] = 1<<s->vsub; /* evaluate width and height */ if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = s->h_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res; /* evaluate the width again, as it may depend on the evaluated output height */ if ((ret = av_expr_parse_and_eval(&res, (expr = s->w_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; /* evaluate x and y */ if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->x = var_values[VAR_X] = res; if ((ret = av_expr_parse_and_eval(&res, (expr = s->y_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->y = var_values[VAR_Y] = res; /* evaluate x again, as it may depend on the evaluated y value */ if ((ret = av_expr_parse_and_eval(&res, (expr = s->x_expr), var_names, var_values, NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) goto eval_fail; s->x = var_values[VAR_X] = res; /* sanity check params */ if (s->w < 0 || s->h < 0 || s->x < 0 || s->y < 0) { av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n"); return AVERROR(EINVAL); } if (!s->w) s->w = inlink->w; if (!s->h) s->h = inlink->h; s->w &= ~((1 << s->hsub) - 1); s->h &= ~((1 << s->vsub) - 1); s->x &= ~((1 << s->hsub) - 1); s->y &= ~((1 << s->vsub) - 1); s->in_w = inlink->w & ~((1 << s->hsub) - 1); s->in_h = inlink->h & ~((1 << s->vsub) - 1); memcpy(rgba_color, s->color, sizeof(rgba_color)); ff_fill_line_with_color(s->line, s->line_step, s->w, s->color, inlink->format, rgba_color, &is_packed_rgba, NULL); av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\n", inlink->w, inlink->h, s->w, s->h, s->x, s->y, s->color[0], s->color[1], s->color[2], s->color[3], is_packed_rgba ? "rgba" : "yuva"); if (s->x < 0 || s->y < 0 || s->w <= 0 || s->h <= 0 || (unsigned)s->x + (unsigned)inlink->w > s->w || (unsigned)s->y + (unsigned)inlink->h > s->h) { av_log(ctx, AV_LOG_ERROR, "Input area %d:%d:%d:%d not within the padded area 0:0:%d:%d or zero-sized\n", s->x, s->y, s->x + inlink->w, s->y + inlink->h, s->w, s->h); return AVERROR(EINVAL); } return 0; eval_fail: av_log(NULL, AV_LOG_ERROR, "Error when evaluating the expression '%s'\n", expr); return ret; }


static void local_mapped_file_attr(FsContext *ctx, const char *path, struct stat *stbuf) { FILE *fp; char buf[ATTR_MAX]; char *attr_path; attr_path = local_mapped_attr_path(ctx, path); fp = local_fopen(attr_path, "r"); g_free(attr_path); if (!fp) { return; } memset(buf, 0, ATTR_MAX); while (fgets(buf, ATTR_MAX, fp)) { if (!strncmp(buf, "virtfs.uid", 10)) { stbuf->st_uid = atoi(buf+11); } else if (!strncmp(buf, "virtfs.gid", 10)) { stbuf->st_gid = atoi(buf+11); } else if (!strncmp(buf, "virtfs.mode", 11)) { stbuf->st_mode = atoi(buf+12); } else if (!strncmp(buf, "virtfs.rdev", 11)) { stbuf->st_rdev = atoi(buf+12); } memset(buf, 0, ATTR_MAX); } fclose(fp); }


AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame) { AVRational fr = st->r_frame_rate; AVRational codec_fr = st->codec->framerate; AVRational avg_fr = st->avg_frame_rate; if (avg_fr.num > 0 && avg_fr.den > 0 && fr.num > 0 && fr.den > 0 && av_q2d(avg_fr) < 70 && av_q2d(fr) > 210) { fr = avg_fr; } if (st->codec->ticks_per_frame > 1) { if ( codec_fr.num > 0 && codec_fr.den > 0 && av_q2d(codec_fr) < av_q2d(fr)*0.7 && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1) fr = codec_fr; } return fr; }


static void apply_mid_side_stereo(ChannelElement *cpe) { int w, w2, g, i; IndividualChannelStream *ics = &cpe->ch[0].ics; if (!cpe->common_window) return; for (w = 0; w < ics->num_windows; w += ics->group_len[w]) { for (w2 = 0; w2 < ics->group_len[w]; w2++) { int start = (w+w2) * 128; for (g = 0; g < ics->num_swb; g++) { if (!cpe->ms_mask[w*16 + g]) { start += ics->swb_sizes[g]; continue; } for (i = 0; i < ics->swb_sizes[g]; i++) { float L = (cpe->ch[0].coeffs[start+i] + cpe->ch[1].coeffs[start+i]) * 0.5f; float R = L - cpe->ch[1].coeffs[start+i]; cpe->ch[0].coeffs[start+i] = L; cpe->ch[1].coeffs[start+i] = R; } start += ics->swb_sizes[g]; } } } }


static int ea_read_header(AVFormatContext *s, AVFormatParameters *ap) { EaDemuxContext *ea = s->priv_data; AVStream *st; if (!process_ea_header(s)) return AVERROR(EIO); if (ea->time_base.num && ea->time_base.den) { /* initialize the video decoder stream */ st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); ea->video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = ea->video_codec; st->codec->codec_tag = 0; /* no fourcc */ st->codec->time_base = ea->time_base; } if (ea->audio_codec) { /* initialize the audio decoder stream */ st = av_new_stream(s, 0); if (!st) return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, ea->sample_rate); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = ea->audio_codec; st->codec->codec_tag = 0; /* no tag */ st->codec->channels = ea->num_channels; st->codec->sample_rate = ea->sample_rate; st->codec->bits_per_sample = ea->bytes * 8; st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_sample / 4; st->codec->block_align = st->codec->channels*st->codec->bits_per_sample; ea->audio_stream_index = st->index; ea->audio_frame_counter = 0; } return 1; }


static int ppc_hash32_get_bat(CPUPPCState *env, struct mmu_ctx_hash32 *ctx, target_ulong virtual, int rwx) { target_ulong *BATlt, *BATut; target_ulong BEPIl, BEPIu, bl; int i, valid, prot; int ret = -1; LOG_BATS("%s: %cBAT v " TARGET_FMT_lx "\n", __func__, rwx == 2 ? 'I' : 'D', virtual); if (rwx == 2) { BATlt = env->IBAT[1]; BATut = env->IBAT[0]; } else { BATlt = env->DBAT[1]; BATut = env->DBAT[0]; } for (i = 0; i < env->nb_BATs; i++) { target_ulong batu = BATut[i]; target_ulong batl = BATlt[i]; BEPIu = batu & BATU32_BEPIU; BEPIl = batu & BATU32_BEPIL; if (unlikely(env->mmu_model == POWERPC_MMU_601)) { hash32_bat_601_size(env, &bl, &valid, batu, batl); prot = hash32_bat_601_prot(env, batu, batl); } else { hash32_bat_size(env, &bl, &valid, batu, batl); prot = hash32_bat_prot(env, batu, batl); } LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx " BATl " TARGET_FMT_lx "\n", __func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual, batu, batl); if ((virtual & BATU32_BEPIU) == BEPIu && ((virtual & BATU32_BEPIL) & ~bl) == BEPIl) { /* BAT matches */ if (valid != 0) { /* Get physical address */ ctx->raddr = (batl & BATL32_BRPNU) | ((virtual & BATU32_BEPIL & bl) | (batl & BATL32_BRPNL)) | (virtual & 0x0001F000); /* Compute access rights */ ctx->prot = prot; ret = ppc_hash32_check_prot(ctx->prot, rwx); if (ret == 0) { LOG_BATS("BAT %d match: r " TARGET_FMT_plx " prot=%c%c\n", i, ctx->raddr, ctx->prot & PAGE_READ ? 'R' : '-', ctx->prot & PAGE_WRITE ? 'W' : '-'); } break; } } } if (ret < 0) { #if defined(DEBUG_BATS) if (qemu_log_enabled()) { LOG_BATS("no BAT match for " TARGET_FMT_lx ":\n", virtual); for (i = 0; i < 4; i++) { BATu = &BATut[i]; BATl = &BATlt[i]; BEPIu = *BATu & BATU32_BEPIU; BEPIl = *BATu & BATU32_BEPIL; bl = (*BATu & 0x00001FFC) << 15; LOG_BATS("%s: %cBAT%d v " TARGET_FMT_lx " BATu " TARGET_FMT_lx " BATl " TARGET_FMT_lx "\n\t" TARGET_FMT_lx " " TARGET_FMT_lx " " TARGET_FMT_lx "\n", __func__, type == ACCESS_CODE ? 'I' : 'D', i, virtual, *BATu, *BATl, BEPIu, BEPIl, bl); } } #endif } /* No hit */ return ret; }


static QOSState *qvirtio_scsi_start(const char *extra_opts) { const char *cmd = "-drive id=drv0,if=none,file=/dev/null,format=raw " "-device virtio-scsi-pci,id=vs0 " "-device scsi-hd,bus=vs0.0,drive=drv0 %s"; return qtest_pc_boot(cmd, extra_opts ? : ""); }


int fread_targphys_ok(target_phys_addr_t dst_addr, size_t nbytes, FILE *f) { return fread_targphys(dst_addr, nbytes, f) == nbytes; }


static int set_format(void *obj, const char *name, int fmt, int search_flags, enum AVOptionType type, const char *desc, int max) { void *target_obj; const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); if (!o || !target_obj) return AVERROR_OPTION_NOT_FOUND; if (o->type != type) { av_log(obj, AV_LOG_ERROR, "The value set by option '%s' is not a %s format", name, desc); return AVERROR(EINVAL); } if (fmt < -1 || fmt > max) { av_log(obj, AV_LOG_ERROR, "Value %d for parameter '%s' out of %s format range [-1 - %d]\n", fmt, name, desc, max); return AVERROR(ERANGE); } *(int *)(((uint8_t *)target_obj) + o->offset) = fmt; return 0; }


static CharDriverState *qemu_chr_open_stdio(const char *id, ChardevBackend *backend, ChardevReturn *ret, Error **errp) { ChardevStdio *opts = backend->u.stdio.data; CharDriverState *chr; struct sigaction act; ChardevCommon *common = qapi_ChardevStdio_base(opts); if (is_daemonized()) { error_setg(errp, "cannot use stdio with -daemonize"); if (stdio_in_use) { error_setg(errp, "cannot use stdio by multiple character devices"); stdio_in_use = true; old_fd0_flags = fcntl(0, F_GETFL); tcgetattr(0, &oldtty); qemu_set_nonblock(0); atexit(term_exit); memset(&act, 0, sizeof(act)); act.sa_handler = term_stdio_handler; sigaction(SIGCONT, &act, NULL); chr = qemu_chr_open_fd(0, 1, common, errp); chr->chr_close = qemu_chr_close_stdio; chr->chr_set_echo = qemu_chr_set_echo_stdio; if (opts->has_signal) { stdio_allow_signal = opts->signal; qemu_chr_fe_set_echo(chr, false); return chr;


static int ape_read_packet(AVFormatContext * s, AVPacket * pkt) { int ret; int nblocks; APEContext *ape = s->priv_data; uint32_t extra_size = 8; if (url_feof(s->pb)) return AVERROR_EOF; if (ape->currentframe >= ape->totalframes) return AVERROR_EOF; if (avio_seek(s->pb, ape->frames[ape->currentframe].pos, SEEK_SET) < 0) return AVERROR(EIO); /* Calculate how many blocks there are in this frame */ if (ape->currentframe == (ape->totalframes - 1)) nblocks = ape->finalframeblocks; else nblocks = ape->blocksperframe; if (ape->frames[ape->currentframe].size <= 0 || ape->frames[ape->currentframe].size > INT_MAX - extra_size) { av_log(s, AV_LOG_ERROR, "invalid packet size: %d\n", ape->frames[ape->currentframe].size); ape->currentframe++; return AVERROR(EIO); } if (av_new_packet(pkt, ape->frames[ape->currentframe].size + extra_size) < 0) return AVERROR(ENOMEM); AV_WL32(pkt->data , nblocks); AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip); ret = avio_read(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size); pkt->pts = ape->frames[ape->currentframe].pts; pkt->stream_index = 0; /* note: we need to modify the packet size here to handle the last packet */ pkt->size = ret + extra_size; ape->currentframe++; return 0; }


static GSList *nvdimm_get_plugged_device_list(void) { GSList *list = NULL; object_child_foreach(qdev_get_machine(), nvdimm_plugged_device_list, &list); return list; }


void ide_dma_cancel(BMDMAState *bm) { if (bm->status & BM_STATUS_DMAING) { bm->status &= ~BM_STATUS_DMAING; /* cancel DMA request */ bm->unit = -1; bm->dma_cb = NULL; if (bm->aiocb) { #ifdef DEBUG_AIO printf("aio_cancel\n"); #endif bdrv_aio_cancel(bm->aiocb); bm->aiocb = NULL; } } }


uint64_t helper_fre(CPUPPCState *env, uint64_t arg) { CPU_DoubleU farg; farg.ll = arg; if (unlikely(float64_is_signaling_nan(farg.d))) { /* sNaN reciprocal */ fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN); } farg.d = float64_div(float64_one, farg.d, &env->fp_status); return farg.d; }


PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, ISABus **isa_bus, qemu_irq *pic, MemoryRegion *address_space_mem, MemoryRegion *address_space_io, ram_addr_t ram_size, hwaddr pci_hole_start, hwaddr pci_hole_size, hwaddr pci_hole64_start, hwaddr pci_hole64_size, MemoryRegion *pci_address_space, MemoryRegion *ram_memory) { DeviceState *dev; PCIBus *b; PCIDevice *d; PCIHostState *s; PIIX3State *piix3; PCII440FXState *f; unsigned i; dev = qdev_create(NULL, TYPE_I440FX_PCI_HOST_BRIDGE); s = PCI_HOST_BRIDGE(dev); b = pci_bus_new(dev, NULL, pci_address_space, address_space_io, 0, TYPE_PCI_BUS); s->bus = b; object_property_add_child(qdev_get_machine(), "i440fx", OBJECT(dev), NULL); qdev_init_nofail(dev); d = pci_create_simple(b, 0, TYPE_I440FX_PCI_DEVICE); *pi440fx_state = I440FX_PCI_DEVICE(d); f = *pi440fx_state; f->system_memory = address_space_mem; f->pci_address_space = pci_address_space; f->ram_memory = ram_memory; memory_region_init_alias(&f->pci_hole, OBJECT(d), "pci-hole", f->pci_address_space, pci_hole_start, pci_hole_size); memory_region_add_subregion(f->system_memory, pci_hole_start, &f->pci_hole); memory_region_init_alias(&f->pci_hole_64bit, OBJECT(d), "pci-hole64", f->pci_address_space, pci_hole64_start, pci_hole64_size); if (pci_hole64_size) { memory_region_add_subregion(f->system_memory, pci_hole64_start, &f->pci_hole_64bit); } memory_region_init_alias(&f->smram_region, OBJECT(d), "smram-region", f->pci_address_space, 0xa0000, 0x20000); memory_region_add_subregion_overlap(f->system_memory, 0xa0000, &f->smram_region, 1); memory_region_set_enabled(&f->smram_region, false); init_pam(dev, f->ram_memory, f->system_memory, f->pci_address_space, &f->pam_regions[0], PAM_BIOS_BASE, PAM_BIOS_SIZE); for (i = 0; i < 12; ++i) { init_pam(dev, f->ram_memory, f->system_memory, f->pci_address_space, &f->pam_regions[i+1], PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE); } /* Xen supports additional interrupt routes from the PCI devices to * the IOAPIC: the four pins of each PCI device on the bus are also * connected to the IOAPIC directly. * These additional routes can be discovered through ACPI. */ if (xen_enabled()) { piix3 = DO_UPCAST(PIIX3State, dev, pci_create_simple_multifunction(b, -1, true, "PIIX3-xen")); pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq, piix3, XEN_PIIX_NUM_PIRQS); } else { piix3 = DO_UPCAST(PIIX3State, dev, pci_create_simple_multifunction(b, -1, true, "PIIX3")); pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3, PIIX_NUM_PIRQS); pci_bus_set_route_irq_fn(b, piix3_route_intx_pin_to_irq); } piix3->pic = pic; *isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0")); *piix3_devfn = piix3->dev.devfn; ram_size = ram_size / 8 / 1024 / 1024; if (ram_size > 255) { ram_size = 255; } d->config[0x57] = ram_size; i440fx_update_memory_mappings(f); return b; }


static int virtio_rng_device_exit(DeviceState *qdev) { VirtIORNG *vrng = VIRTIO_RNG(qdev); VirtIODevice *vdev = VIRTIO_DEVICE(qdev); timer_del(vrng->rate_limit_timer); timer_free(vrng->rate_limit_timer); unregister_savevm(qdev, "virtio-rng", vrng); virtio_cleanup(vdev); return 0; }


static int svq1_decode_frame_header(AVCodecContext *avctx, AVFrame *frame) { SVQ1Context *s = avctx->priv_data; GetBitContext *bitbuf = &s->gb; int frame_size_code; int width = s->width; int height = s->height; skip_bits(bitbuf, 8); /* temporal_reference */ /* frame type */ s->nonref = 0; switch (get_bits(bitbuf, 2)) { case 0: frame->pict_type = AV_PICTURE_TYPE_I; break; case 2: s->nonref = 1; case 1: frame->pict_type = AV_PICTURE_TYPE_P; break; default: av_log(avctx, AV_LOG_ERROR, "Invalid frame type.\n"); return AVERROR_INVALIDDATA; } if (frame->pict_type == AV_PICTURE_TYPE_I) { /* unknown fields */ if (s->frame_code == 0x50 || s->frame_code == 0x60) { int csum = get_bits(bitbuf, 16); csum = ff_svq1_packet_checksum(bitbuf->buffer, bitbuf->size_in_bits >> 3, csum); av_dlog(avctx, "%s checksum (%02x) for packet data\n", (csum == 0) ? "correct" : "incorrect", csum); } if ((s->frame_code ^ 0x10) >= 0x50) { uint8_t msg[256]; svq1_parse_string(bitbuf, msg); av_log(avctx, AV_LOG_INFO, "embedded message:\n%s\n", (char *)msg); } skip_bits(bitbuf, 2); skip_bits(bitbuf, 2); skip_bits1(bitbuf); /* load frame size */ frame_size_code = get_bits(bitbuf, 3); if (frame_size_code == 7) { /* load width, height (12 bits each) */ width = get_bits(bitbuf, 12); height = get_bits(bitbuf, 12); if (!width || !height) return AVERROR_INVALIDDATA; } else { /* get width, height from table */ width = ff_svq1_frame_size_table[frame_size_code][0]; height = ff_svq1_frame_size_table[frame_size_code][1]; } } /* unknown fields */ if (get_bits1(bitbuf)) { skip_bits1(bitbuf); /* use packet checksum if (1) */ skip_bits1(bitbuf); /* component checksums after image data if (1) */ if (get_bits(bitbuf, 2) != 0) return AVERROR_INVALIDDATA; } if (get_bits1(bitbuf)) { skip_bits1(bitbuf); skip_bits(bitbuf, 4); skip_bits1(bitbuf); skip_bits(bitbuf, 2); if (skip_1stop_8data_bits(bitbuf) < 0) return AVERROR_INVALIDDATA; } s->width = width; s->height = height; return 0; }


static struct pathelem *add_entry(struct pathelem *root, const char *name, unsigned type) { struct pathelem **e; root->num_entries++; root = realloc(root, sizeof(*root) + sizeof(root->entries[0])*root->num_entries); e = &root->entries[root->num_entries-1]; *e = new_entry(root->pathname, root, name); if (is_dir_maybe(type)) { *e = add_dir_maybe(*e); } return root; }


static void virtio_balloon_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); dc->exit = virtio_balloon_device_exit; dc->props = virtio_balloon_properties; set_bit(DEVICE_CATEGORY_MISC, dc->categories); vdc->init = virtio_balloon_device_init; vdc->get_config = virtio_balloon_get_config; vdc->set_config = virtio_balloon_set_config; vdc->get_features = virtio_balloon_get_features; }


static KeyValue *copy_key_value(KeyValue *src) { KeyValue *dst = g_new(KeyValue, 1); memcpy(dst, src, sizeof(*src)); return dst;


target_ulong helper_sub_suov(CPUTriCoreState *env, target_ulong r1, target_ulong r2) { int64_t t1 = extract64(r1, 0, 32); int64_t t2 = extract64(r2, 0, 32); int64_t result = t1 - t2; return suov32(env, result); }


static uint64_t icp_pit_read(void *opaque, target_phys_addr_t offset, unsigned size) { icp_pit_state *s = (icp_pit_state *)opaque; int n; /* ??? Don't know the PrimeCell ID for this device. */ n = offset >> 8; if (n > 2) { hw_error("%s: Bad timer %d\n", __func__, n); } return arm_timer_read(s->timer[n], offset & 0xff); }


static void v9fs_synth_direntry(V9fsSynthNode *node, struct dirent *entry, off_t off) { strcpy(entry->d_name, node->name); entry->d_ino = node->attr->inode; entry->d_off = off + 1; }


static void gen_nop_hint(DisasContext *s, int val) { switch (val) { case 1: /* yield */ if (!parallel_cpus) { gen_set_pc_im(s, s->pc); s->base.is_jmp = DISAS_YIELD; } break; case 3: /* wfi */ gen_set_pc_im(s, s->pc); s->base.is_jmp = DISAS_WFI; break; case 2: /* wfe */ if (!parallel_cpus) { gen_set_pc_im(s, s->pc); s->base.is_jmp = DISAS_WFE; } break; case 4: /* sev */ case 5: /* sevl */ /* TODO: Implement SEV, SEVL and WFE. May help SMP performance. */ default: /* nop */ break; } }


static void vnc_dpy_setdata(DisplayState *ds) { /* We don't have to do anything */ }


static int64_t ftp_seek(URLContext *h, int64_t pos, int whence) { FTPContext *s = h->priv_data; int err; int64_t new_pos, fake_pos; av_dlog(h, "ftp protocol seek %"PRId64" %d\n", pos, whence); switch(whence) { case AVSEEK_SIZE: return s->filesize; case SEEK_SET: new_pos = pos; break; case SEEK_CUR: new_pos = s->position + pos; break; case SEEK_END: if (s->filesize < 0) return AVERROR(EIO); new_pos = s->filesize + pos; break; default: return AVERROR(EINVAL); } if (h->is_streamed) return AVERROR(EIO); if (new_pos < 0) { av_log(h, AV_LOG_ERROR, "Seeking to nagative position.\n"); return AVERROR(EINVAL); } fake_pos = s->filesize != -1 ? FFMIN(new_pos, s->filesize) : new_pos; if (fake_pos != s->position) { if ((err = ftp_abort(h)) < 0) return err; s->position = fake_pos; } return new_pos; }


struct vhost_net *vhost_net_init(NetClientState *backend, int devfd, bool force) { int r; struct vhost_net *net = g_malloc(sizeof *net); if (!backend) { fprintf(stderr, "vhost-net requires backend to be setup\n"); goto fail; } r = vhost_net_get_fd(backend); if (r < 0) { goto fail; } net->nc = backend; net->dev.backend_features = tap_has_vnet_hdr(backend) ? 0 : (1 << VHOST_NET_F_VIRTIO_NET_HDR); net->backend = r; net->dev.nvqs = 2; net->dev.vqs = net->vqs; r = vhost_dev_init(&net->dev, devfd, "/dev/vhost-net", force); if (r < 0) { goto fail; } if (!tap_has_vnet_hdr_len(backend, sizeof(struct virtio_net_hdr_mrg_rxbuf))) { net->dev.features &= ~(1 << VIRTIO_NET_F_MRG_RXBUF); } if (~net->dev.features & net->dev.backend_features) { fprintf(stderr, "vhost lacks feature mask %" PRIu64 " for backend\n", (uint64_t)(~net->dev.features & net->dev.backend_features)); vhost_dev_cleanup(&net->dev); goto fail; } /* Set sane init value. Override when guest acks. */ vhost_net_ack_features(net, 0); return net; fail: g_free(net); return NULL; }


static int encode_superframe(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { WMACodecContext *s = avctx->priv_data; int i, total_gain, ret, error; s->block_len_bits= s->frame_len_bits; //required by non variable block len s->block_len = 1 << s->block_len_bits; apply_window_and_mdct(avctx, frame); if (s->ms_stereo) { float a, b; int i; for(i = 0; i < s->block_len; i++) { a = s->coefs[0][i]*0.5; b = s->coefs[1][i]*0.5; s->coefs[0][i] = a + b; s->coefs[1][i] = a - b; } } if ((ret = ff_alloc_packet2(avctx, avpkt, 2 * MAX_CODED_SUPERFRAME_SIZE))) return ret; total_gain= 128; for(i=64; i; i>>=1){ error = encode_frame(s, s->coefs, avpkt->data, avpkt->size, total_gain - i); if(error<=0) total_gain-= i; } while(total_gain <= 128 && error > 0) error = encode_frame(s, s->coefs, avpkt->data, avpkt->size, total_gain++); av_assert0((put_bits_count(&s->pb) & 7) == 0); i= avctx->block_align - (put_bits_count(&s->pb)+7)/8; av_assert0(i>=0); while(i--) put_bits(&s->pb, 8, 'N'); flush_put_bits(&s->pb); av_assert0(put_bits_ptr(&s->pb) - s->pb.buf == avctx->block_align); if (frame->pts != AV_NOPTS_VALUE) avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->delay); avpkt->size = avctx->block_align; *got_packet_ptr = 1; return 0; }


static int qcow_create(const char *filename, int64_t total_size, const char *backing_file, int flags) { int fd, header_size, backing_filename_len, l1_size, i, shift, l2_bits; QCowHeader header; uint64_t tmp, offset; QCowCreateState s1, *s = &s1; memset(s, 0, sizeof(*s)); fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); if (fd < 0) return -1; memset(&header, 0, sizeof(header)); header.magic = cpu_to_be32(QCOW_MAGIC); header.version = cpu_to_be32(QCOW_VERSION); header.size = cpu_to_be64(total_size * 512); header_size = sizeof(header); backing_filename_len = 0; if (backing_file) { header.backing_file_offset = cpu_to_be64(header_size); backing_filename_len = strlen(backing_file); header.backing_file_size = cpu_to_be32(backing_filename_len); header_size += backing_filename_len; } s->cluster_bits = 12; /* 4 KB clusters */ s->cluster_size = 1 << s->cluster_bits; header.cluster_bits = cpu_to_be32(s->cluster_bits); header_size = (header_size + 7) & ~7; if (flags & BLOCK_FLAG_ENCRYPT) { header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES); } else { header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE); } l2_bits = s->cluster_bits - 3; shift = s->cluster_bits + l2_bits; l1_size = (((total_size * 512) + (1LL << shift) - 1) >> shift); offset = align_offset(header_size, s->cluster_size); s->l1_table_offset = offset; header.l1_table_offset = cpu_to_be64(s->l1_table_offset); header.l1_size = cpu_to_be32(l1_size); offset += align_offset(l1_size * sizeof(uint64_t), s->cluster_size); s->refcount_table = qemu_mallocz(s->cluster_size); s->refcount_block = qemu_mallocz(s->cluster_size); s->refcount_table_offset = offset; header.refcount_table_offset = cpu_to_be64(offset); header.refcount_table_clusters = cpu_to_be32(1); offset += s->cluster_size; s->refcount_table[0] = cpu_to_be64(offset); s->refcount_block_offset = offset; offset += s->cluster_size; /* update refcounts */ create_refcount_update(s, 0, header_size); create_refcount_update(s, s->l1_table_offset, l1_size * sizeof(uint64_t)); create_refcount_update(s, s->refcount_table_offset, s->cluster_size); create_refcount_update(s, s->refcount_block_offset, s->cluster_size); /* write all the data */ write(fd, &header, sizeof(header)); if (backing_file) { write(fd, backing_file, backing_filename_len); } lseek(fd, s->l1_table_offset, SEEK_SET); tmp = 0; for(i = 0;i < l1_size; i++) { write(fd, &tmp, sizeof(tmp)); } lseek(fd, s->refcount_table_offset, SEEK_SET); write(fd, s->refcount_table, s->cluster_size); lseek(fd, s->refcount_block_offset, SEEK_SET); write(fd, s->refcount_block, s->cluster_size); qemu_free(s->refcount_table); qemu_free(s->refcount_block); close(fd); return 0; }


static void scsi_read_data(SCSIRequest *req) { SCSIDiskReq *r = DO_UPCAST(SCSIDiskReq, req, req); SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); uint32_t n; if (r->sector_count == (uint32_t)-1) { DPRINTF("Read buf_len=%zd\n", r->iov.iov_len); r->sector_count = 0; scsi_req_data(&r->req, r->iov.iov_len); return; } DPRINTF("Read sector_count=%d\n", r->sector_count); if (r->sector_count == 0) { scsi_command_complete(r, GOOD, NO_SENSE); return; } /* No data transfer may already be in progress */ assert(r->req.aiocb == NULL); n = r->sector_count; if (n > SCSI_DMA_BUF_SIZE / 512) n = SCSI_DMA_BUF_SIZE / 512; r->iov.iov_len = n * 512; qemu_iovec_init_external(&r->qiov, &r->iov, 1); r->req.aiocb = bdrv_aio_readv(s->bs, r->sector, &r->qiov, n, scsi_read_complete, r); if (r->req.aiocb == NULL) { scsi_read_complete(r, -EIO); } }


static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target, const char *replaces, int64_t speed, uint32_t granularity, int64_t buf_size, BlockdevOnError on_source_error, BlockdevOnError on_target_error, bool unmap, BlockCompletionFunc *cb, void *opaque, Error **errp, const BlockJobDriver *driver, bool is_none_mode, BlockDriverState *base) { MirrorBlockJob *s; BlockDriverState *replaced_bs; if (granularity == 0) { granularity = bdrv_get_default_bitmap_granularity(target); assert ((granularity & (granularity - 1)) == 0); if ((on_source_error == BLOCKDEV_ON_ERROR_STOP || on_source_error == BLOCKDEV_ON_ERROR_ENOSPC) && (!bs->blk || !blk_iostatus_is_enabled(bs->blk))) { error_setg(errp, QERR_INVALID_PARAMETER, "on-source-error"); if (buf_size < 0) { error_setg(errp, "Invalid parameter 'buf-size'"); if (buf_size == 0) { buf_size = DEFAULT_MIRROR_BUF_SIZE; s = block_job_create(driver, bs, speed, cb, opaque, errp); if (!s) { s->replaces = g_strdup(replaces); s->on_source_error = on_source_error; s->on_target_error = on_target_error; s->target = target; s->is_none_mode = is_none_mode; s->base = base; s->granularity = granularity; s->buf_size = ROUND_UP(buf_size, granularity); s->unmap = unmap; s->dirty_bitmap = bdrv_create_dirty_bitmap(bs, granularity, NULL, errp); if (!s->dirty_bitmap) { g_free(s->replaces); block_job_unref(&s->common); bdrv_op_block_all(s->target, s->common.blocker); bdrv_set_enable_write_cache(s->target, true); if (s->target->blk) { blk_set_on_error(s->target->blk, on_target_error, on_target_error); blk_iostatus_enable(s->target->blk); s->common.co = qemu_coroutine_create(mirror_run); trace_mirror_start(bs, s, s->common.co, opaque); qemu_coroutine_enter(s->common.co, s);


static void qemu_kvm_start_vcpu(CPUState *env) { env->thread = g_malloc0(sizeof(QemuThread)); env->halt_cond = g_malloc0(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); qemu_thread_create(env->thread, qemu_kvm_cpu_thread_fn, env, QEMU_THREAD_DETACHED); while (env->created == 0) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); } }


static MemTxResult address_space_write_continue(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, const uint8_t *buf, int len, hwaddr addr1, hwaddr l, MemoryRegion *mr) { uint8_t *ptr; uint64_t val; MemTxResult result = MEMTX_OK; bool release_lock = false; for (;;) { if (!memory_access_is_direct(mr, true)) { release_lock |= prepare_mmio_access(mr); l = memory_access_size(mr, l, addr1); /* XXX: could force current_cpu to NULL to avoid potential bugs */ switch (l) { case 8: /* 64 bit write access */ val = ldq_p(buf); result |= memory_region_dispatch_write(mr, addr1, val, 8, attrs); break; case 4: /* 32 bit write access */ val = (uint32_t)ldl_p(buf); result |= memory_region_dispatch_write(mr, addr1, val, 4, attrs); break; case 2: /* 16 bit write access */ val = lduw_p(buf); result |= memory_region_dispatch_write(mr, addr1, val, 2, attrs); break; case 1: /* 8 bit write access */ val = ldub_p(buf); result |= memory_region_dispatch_write(mr, addr1, val, 1, attrs); break; default: abort(); } } else { /* RAM case */ ptr = qemu_map_ram_ptr(mr->ram_block, addr1); memcpy(ptr, buf, l); invalidate_and_set_dirty(mr, addr1, l); } if (release_lock) { qemu_mutex_unlock_iothread(); release_lock = false; } len -= l; buf += l; addr += l; if (!len) { break; } l = len; mr = address_space_translate(as, addr, &addr1, &l, true); } return result; }


static int g729_parse(AVCodecParserContext *s1, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size) { G729ParseContext *s = s1->priv_data; ParseContext *pc = &s->pc; int next; if (!s->block_size) { switch (avctx->codec_id) { case AV_CODEC_ID_G729: /* FIXME: replace this heuristic block_size with more precise estimate */ s->block_size = (avctx->bit_rate < 8000) ? G729D_6K4_BLOCK_SIZE : G729_8K_BLOCK_SIZE; s->duration = avctx->frame_size; break; default: *poutbuf = buf; *poutbuf_size = buf_size; av_log(avctx, AV_LOG_ERROR, "Invalid codec_id\n"); return buf_size; } } if (!s->remaining) s->remaining = s->block_size; if (s->remaining <= buf_size) { next = s->remaining; s->remaining = 0; } else { next = END_NOT_FOUND; s->remaining -= buf_size; } if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) { *poutbuf = NULL; *poutbuf_size = 0; return buf_size; } s1->duration = s->duration; *poutbuf = buf; *poutbuf_size = buf_size; return next; }


static uint64_t timerblock_read(void *opaque, target_phys_addr_t addr, unsigned size) { timerblock *tb = (timerblock *)opaque; int64_t val; switch (addr) { case 0: /* Load */ return tb->load; case 4: /* Counter. */ if (((tb->control & 1) == 0) || (tb->count == 0)) { return 0; } /* Slow and ugly, but hopefully won't happen too often. */ val = tb->tick - qemu_get_clock_ns(vm_clock); val /= timerblock_scale(tb); if (val < 0) { val = 0; } return val; case 8: /* Control. */ return tb->control; case 12: /* Interrupt status. */ return tb->status; default: return 0; } }


static int decode_audio_block(AC3DecodeContext *s, int blk) { int fbw_channels = s->fbw_channels; int channel_mode = s->channel_mode; int i, bnd, seg, ch; int different_transforms; int downmix_output; int cpl_in_use; GetBitContext *gbc = &s->gbc; uint8_t bit_alloc_stages[AC3_MAX_CHANNELS]; memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); /* block switch flags */ different_transforms = 0; if (s->block_switch_syntax) { for (ch = 1; ch <= fbw_channels; ch++) { s->block_switch[ch] = get_bits1(gbc); if(ch > 1 && s->block_switch[ch] != s->block_switch[1]) different_transforms = 1; } } /* dithering flags */ if (s->dither_flag_syntax) { for (ch = 1; ch <= fbw_channels; ch++) { s->dither_flag[ch] = get_bits1(gbc); } } /* dynamic range */ i = !(s->channel_mode); do { if(get_bits1(gbc)) { s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)]-1.0) * s->avctx->drc_scale)+1.0; } else if(blk == 0) { s->dynamic_range[i] = 1.0f; } } while(i--); /* spectral extension strategy */ if (s->eac3 && (!blk || get_bits1(gbc))) { if (get_bits1(gbc)) { av_log_missing_feature(s->avctx, "Spectral extension", 1); return -1; } /* TODO: parse spectral extension strategy info */ } /* TODO: spectral extension coordinates */ /* coupling strategy */ if (s->eac3 ? s->cpl_strategy_exists[blk] : get_bits1(gbc)) { memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); if (!s->eac3) s->cpl_in_use[blk] = get_bits1(gbc); if (s->cpl_in_use[blk]) { /* coupling in use */ int cpl_start_subband, cpl_end_subband; if (channel_mode < AC3_CHMODE_STEREO) { av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n"); return -1; } /* check for enhanced coupling */ if (s->eac3 && get_bits1(gbc)) { /* TODO: parse enhanced coupling strategy info */ av_log_missing_feature(s->avctx, "Enhanced coupling", 1); return -1; } /* determine which channels are coupled */ if (s->eac3 && s->channel_mode == AC3_CHMODE_STEREO) { s->channel_in_cpl[1] = 1; s->channel_in_cpl[2] = 1; } else { for (ch = 1; ch <= fbw_channels; ch++) s->channel_in_cpl[ch] = get_bits1(gbc); } /* phase flags in use */ if (channel_mode == AC3_CHMODE_STEREO) s->phase_flags_in_use = get_bits1(gbc); /* coupling frequency range */ /* TODO: modify coupling end freq if spectral extension is used */ cpl_start_subband = get_bits(gbc, 4); cpl_end_subband = get_bits(gbc, 4) + 3; s->num_cpl_subbands = cpl_end_subband - cpl_start_subband; if (s->num_cpl_subbands < 0) { av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d > %d)\n", cpl_start_subband, cpl_end_subband); return -1; } s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37; s->end_freq[CPL_CH] = cpl_end_subband * 12 + 37; decode_band_structure(gbc, blk, s->eac3, 0, cpl_start_subband, cpl_end_subband, ff_eac3_default_cpl_band_struct, s->cpl_band_struct, &s->num_cpl_subbands, &s->num_cpl_bands, NULL); } else { /* coupling not in use */ for (ch = 1; ch <= fbw_channels; ch++) { s->channel_in_cpl[ch] = 0; s->first_cpl_coords[ch] = 1; } s->first_cpl_leak = s->eac3; s->phase_flags_in_use = 0; } } else if (!s->eac3) { if(!blk) { av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must be present in block 0\n"); return -1; } else { s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; } } cpl_in_use = s->cpl_in_use[blk]; /* coupling coordinates */ if (cpl_in_use) { int cpl_coords_exist = 0; for (ch = 1; ch <= fbw_channels; ch++) { if (s->channel_in_cpl[ch]) { if ((s->eac3 && s->first_cpl_coords[ch]) || get_bits1(gbc)) { int master_cpl_coord, cpl_coord_exp, cpl_coord_mant; s->first_cpl_coords[ch] = 0; cpl_coords_exist = 1; master_cpl_coord = 3 * get_bits(gbc, 2); for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { cpl_coord_exp = get_bits(gbc, 4); cpl_coord_mant = get_bits(gbc, 4); if (cpl_coord_exp == 15) s->cpl_coords[ch][bnd] = cpl_coord_mant << 22; else s->cpl_coords[ch][bnd] = (cpl_coord_mant + 16) << 21; s->cpl_coords[ch][bnd] >>= (cpl_coord_exp + master_cpl_coord); } } else if (!blk) { av_log(s->avctx, AV_LOG_ERROR, "new coupling coordinates must be present in block 0\n"); return -1; } } else { /* channel not in coupling */ s->first_cpl_coords[ch] = 1; } } /* phase flags */ if (channel_mode == AC3_CHMODE_STEREO && cpl_coords_exist) { for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { s->phase_flags[bnd] = s->phase_flags_in_use? get_bits1(gbc) : 0; } } } /* stereo rematrixing strategy and band structure */ if (channel_mode == AC3_CHMODE_STEREO) { if ((s->eac3 && !blk) || get_bits1(gbc)) { s->num_rematrixing_bands = 4; if(cpl_in_use && s->start_freq[CPL_CH] <= 61) s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); for(bnd=0; bnd<s->num_rematrixing_bands; bnd++) s->rematrixing_flags[bnd] = get_bits1(gbc); } else if (!blk) { av_log(s->avctx, AV_LOG_ERROR, "new rematrixing strategy must be present in block 0\n"); return -1; } } /* exponent strategies for each channel */ for (ch = !cpl_in_use; ch <= s->channels; ch++) { if (!s->eac3) s->exp_strategy[blk][ch] = get_bits(gbc, 2 - (ch == s->lfe_ch)); if(s->exp_strategy[blk][ch] != EXP_REUSE) bit_alloc_stages[ch] = 3; } /* channel bandwidth */ for (ch = 1; ch <= fbw_channels; ch++) { s->start_freq[ch] = 0; if (s->exp_strategy[blk][ch] != EXP_REUSE) { int group_size; int prev = s->end_freq[ch]; if (s->channel_in_cpl[ch]) s->end_freq[ch] = s->start_freq[CPL_CH]; else { int bandwidth_code = get_bits(gbc, 6); if (bandwidth_code > 60) { av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60\n", bandwidth_code); return -1; } s->end_freq[ch] = bandwidth_code * 3 + 73; } group_size = 3 << (s->exp_strategy[blk][ch] - 1); s->num_exp_groups[ch] = (s->end_freq[ch]+group_size-4) / group_size; if(blk > 0 && s->end_freq[ch] != prev) memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); } } if (cpl_in_use && s->exp_strategy[blk][CPL_CH] != EXP_REUSE) { s->num_exp_groups[CPL_CH] = (s->end_freq[CPL_CH] - s->start_freq[CPL_CH]) / (3 << (s->exp_strategy[blk][CPL_CH] - 1)); } /* decode exponents for each channel */ for (ch = !cpl_in_use; ch <= s->channels; ch++) { if (s->exp_strategy[blk][ch] != EXP_REUSE) { s->dexps[ch][0] = get_bits(gbc, 4) << !ch; if (decode_exponents(gbc, s->exp_strategy[blk][ch], s->num_exp_groups[ch], s->dexps[ch][0], &s->dexps[ch][s->start_freq[ch]+!!ch])) { av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range\n"); return -1; } if(ch != CPL_CH && ch != s->lfe_ch) skip_bits(gbc, 2); /* skip gainrng */ } } /* bit allocation information */ if (s->bit_allocation_syntax) { if (get_bits1(gbc)) { s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; s->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)]; for(ch=!cpl_in_use; ch<=s->channels; ch++) bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); } else if (!blk) { av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must be present in block 0\n"); return -1; } } /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ if(!s->eac3 || !blk){ if(s->snr_offset_strategy && get_bits1(gbc)) { int snr = 0; int csnr; csnr = (get_bits(gbc, 6) - 15) << 4; for (i = ch = !cpl_in_use; ch <= s->channels; ch++) { /* snr offset */ if (ch == i || s->snr_offset_strategy == 2) snr = (csnr + get_bits(gbc, 4)) << 2; /* run at least last bit allocation stage if snr offset changes */ if(blk && s->snr_offset[ch] != snr) { bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 1); } s->snr_offset[ch] = snr; /* fast gain (normal AC-3 only) */ if (!s->eac3) { int prev = s->fast_gain[ch]; s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; /* run last 2 bit allocation stages if fast gain changes */ if(blk && prev != s->fast_gain[ch]) bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); } } } else if (!s->eac3 && !blk) { av_log(s->avctx, AV_LOG_ERROR, "new snr offsets must be present in block 0\n"); return -1; } } /* fast gain (E-AC-3 only) */ if (s->fast_gain_syntax && get_bits1(gbc)) { for (ch = !cpl_in_use; ch <= s->channels; ch++) { int prev = s->fast_gain[ch]; s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; /* run last 2 bit allocation stages if fast gain changes */ if(blk && prev != s->fast_gain[ch]) bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); } } else if (s->eac3 && !blk) { for (ch = !cpl_in_use; ch <= s->channels; ch++) s->fast_gain[ch] = ff_ac3_fast_gain_tab[4]; } /* E-AC-3 to AC-3 converter SNR offset */ if (s->frame_type == EAC3_FRAME_TYPE_INDEPENDENT && get_bits1(gbc)) { skip_bits(gbc, 10); // skip converter snr offset } /* coupling leak information */ if (cpl_in_use) { if (s->first_cpl_leak || get_bits1(gbc)) { int fl = get_bits(gbc, 3); int sl = get_bits(gbc, 3); /* run last 2 bit allocation stages for coupling channel if coupling leak changes */ if(blk && (fl != s->bit_alloc_params.cpl_fast_leak || sl != s->bit_alloc_params.cpl_slow_leak)) { bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); } s->bit_alloc_params.cpl_fast_leak = fl; s->bit_alloc_params.cpl_slow_leak = sl; } else if (!s->eac3 && !blk) { av_log(s->avctx, AV_LOG_ERROR, "new coupling leak info must be present in block 0\n"); return -1; } s->first_cpl_leak = 0; } /* delta bit allocation information */ if (s->dba_syntax && get_bits1(gbc)) { /* delta bit allocation exists (strategy) */ for (ch = !cpl_in_use; ch <= fbw_channels; ch++) { s->dba_mode[ch] = get_bits(gbc, 2); if (s->dba_mode[ch] == DBA_RESERVED) { av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); return -1; } bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); } /* channel delta offset, len and bit allocation */ for (ch = !cpl_in_use; ch <= fbw_channels; ch++) { if (s->dba_mode[ch] == DBA_NEW) { s->dba_nsegs[ch] = get_bits(gbc, 3); for (seg = 0; seg <= s->dba_nsegs[ch]; seg++) { s->dba_offsets[ch][seg] = get_bits(gbc, 5); s->dba_lengths[ch][seg] = get_bits(gbc, 4); s->dba_values[ch][seg] = get_bits(gbc, 3); } /* run last 2 bit allocation stages if new dba values */ bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); } } } else if(blk == 0) { for(ch=0; ch<=s->channels; ch++) { s->dba_mode[ch] = DBA_NONE; } } /* Bit allocation */ for(ch=!cpl_in_use; ch<=s->channels; ch++) { if(bit_alloc_stages[ch] > 2) { /* Exponent mapping into PSD and PSD integration */ ff_ac3_bit_alloc_calc_psd(s->dexps[ch], s->start_freq[ch], s->end_freq[ch], s->psd[ch], s->band_psd[ch]); } if(bit_alloc_stages[ch] > 1) { /* Compute excitation function, Compute masking curve, and Apply delta bit allocation */ ff_ac3_bit_alloc_calc_mask(&s->bit_alloc_params, s->band_psd[ch], s->start_freq[ch], s->end_freq[ch], s->fast_gain[ch], (ch == s->lfe_ch), s->dba_mode[ch], s->dba_nsegs[ch], s->dba_offsets[ch], s->dba_lengths[ch], s->dba_values[ch], s->mask[ch]); } if(bit_alloc_stages[ch] > 0) { /* Compute bit allocation */ const uint8_t *bap_tab = s->channel_uses_aht[ch] ? ff_eac3_hebap_tab : ff_ac3_bap_tab; ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], s->start_freq[ch], s->end_freq[ch], s->snr_offset[ch], s->bit_alloc_params.floor, bap_tab, s->bap[ch]); } } /* unused dummy data */ if (s->skip_syntax && get_bits1(gbc)) { int skipl = get_bits(gbc, 9); while(skipl--) skip_bits(gbc, 8); } /* unpack the transform coefficients this also uncouples channels if coupling is in use. */ decode_transform_coeffs(s, blk); /* TODO: generate enhanced coupling coordinates and uncouple */ /* TODO: apply spectral extension */ /* recover coefficients if rematrixing is in use */ if(s->channel_mode == AC3_CHMODE_STEREO) do_rematrixing(s); /* apply scaling to coefficients (headroom, dynrng) */ for(ch=1; ch<=s->channels; ch++) { float gain = s->mul_bias / 4194304.0f; if(s->channel_mode == AC3_CHMODE_DUALMONO) { gain *= s->dynamic_range[ch-1]; } else { gain *= s->dynamic_range[0]; } s->dsp.int32_to_float_fmul_scalar(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256); } /* downmix and MDCT. order depends on whether block switching is used for any channel in this block. this is because coefficients for the long and short transforms cannot be mixed. */ downmix_output = s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) && s->fbw_channels == s->out_channels); if(different_transforms) { /* the delay samples have already been downmixed, so we upmix the delay samples in order to reconstruct all channels before downmixing. */ if(s->downmixed) { s->downmixed = 0; ac3_upmix_delay(s); } do_imdct(s, s->channels); if(downmix_output) { s->dsp.ac3_downmix(s->output, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256); } } else { if(downmix_output) { s->dsp.ac3_downmix(s->transform_coeffs+1, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256); } if(downmix_output && !s->downmixed) { s->downmixed = 1; s->dsp.ac3_downmix(s->delay, s->downmix_coeffs, s->out_channels, s->fbw_channels, 128); } do_imdct(s, s->out_channels); } return 0; }


setup_return(CPUARMState *env, struct target_sigaction *ka, abi_ulong *rc, abi_ulong frame_addr, int usig, abi_ulong rc_addr) { abi_ulong handler = ka->_sa_handler; abi_ulong retcode; int thumb = handler & 1; uint32_t cpsr = cpsr_read(env); cpsr &= ~CPSR_IT; if (thumb) { cpsr |= CPSR_T; } else { cpsr &= ~CPSR_T; } if (ka->sa_flags & TARGET_SA_RESTORER) { retcode = ka->sa_restorer; } else { unsigned int idx = thumb; if (ka->sa_flags & TARGET_SA_SIGINFO) idx += 2; __put_user(retcodes[idx], rc); retcode = rc_addr + thumb; } env->regs[0] = usig; env->regs[13] = frame_addr; env->regs[14] = retcode; env->regs[15] = handler & (thumb ? ~1 : ~3); cpsr_write(env, cpsr, 0xffffffff, CPSRWriteByInstr); }


static void tcg_exec_all(void) { int r; /* Account partial waits to QEMU_CLOCK_VIRTUAL. */ qemu_clock_warp(QEMU_CLOCK_VIRTUAL); if (next_cpu == NULL) { next_cpu = first_cpu; } for (; next_cpu != NULL && !exit_request; next_cpu = CPU_NEXT(next_cpu)) { CPUState *cpu = next_cpu; qemu_clock_enable(QEMU_CLOCK_VIRTUAL, (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0); if (cpu_can_run(cpu)) { r = tcg_cpu_exec(cpu); if (r == EXCP_DEBUG) { cpu_handle_guest_debug(cpu); break; } } else if (cpu->stop || cpu->stopped) { break; } } /* Pairs with smp_wmb in qemu_cpu_kick. */ atomic_mb_set(&exit_request, 0); }


static int get_keycode(const char *key) { const KeyDef *p; char *endp; int ret; for(p = key_defs; p->name != NULL; p++) { if (!strcmp(key, p->name)) return p->keycode; } if (strstart(key, "0x", NULL)) { ret = strtoul(key, &endp, 0); if (*endp == '\0' && ret >= 0x01 && ret <= 0xff) return ret; } return -1; }


static void tricore_testboard_init(MachineState *machine, int board_id) { TriCoreCPU *cpu; CPUTriCoreState *env; MemoryRegion *sysmem = get_system_memory(); MemoryRegion *ext_cram = g_new(MemoryRegion, 1); MemoryRegion *ext_dram = g_new(MemoryRegion, 1); MemoryRegion *int_cram = g_new(MemoryRegion, 1); MemoryRegion *int_dram = g_new(MemoryRegion, 1); MemoryRegion *pcp_data = g_new(MemoryRegion, 1); MemoryRegion *pcp_text = g_new(MemoryRegion, 1); if (!machine->cpu_model) { machine->cpu_model = "tc1796"; } cpu = cpu_tricore_init(machine->cpu_model); env = &cpu->env; if (!cpu) { error_report("Unable to find CPU definition"); exit(1); } memory_region_init_ram(ext_cram, NULL, "powerlink_ext_c.ram", 2*1024*1024, &error_abort); vmstate_register_ram_global(ext_cram); memory_region_init_ram(ext_dram, NULL, "powerlink_ext_d.ram", 4*1024*1024, &error_abort); vmstate_register_ram_global(ext_dram); memory_region_init_ram(int_cram, NULL, "powerlink_int_c.ram", 48*1024, &error_abort); vmstate_register_ram_global(int_cram); memory_region_init_ram(int_dram, NULL, "powerlink_int_d.ram", 48*1024, &error_abort); vmstate_register_ram_global(int_dram); memory_region_init_ram(pcp_data, NULL, "powerlink_pcp_data.ram", 16*1024, &error_abort); vmstate_register_ram_global(pcp_data); memory_region_init_ram(pcp_text, NULL, "powerlink_pcp_text.ram", 32*1024, &error_abort); vmstate_register_ram_global(pcp_text); memory_region_add_subregion(sysmem, 0x80000000, ext_cram); memory_region_add_subregion(sysmem, 0xa1000000, ext_dram); memory_region_add_subregion(sysmem, 0xd4000000, int_cram); memory_region_add_subregion(sysmem, 0xd0000000, int_dram); memory_region_add_subregion(sysmem, 0xf0050000, pcp_data); memory_region_add_subregion(sysmem, 0xf0060000, pcp_text); tricoretb_binfo.ram_size = machine->ram_size; tricoretb_binfo.kernel_filename = machine->kernel_filename; if (machine->kernel_filename) { tricore_load_kernel(env); } }


static uint64_t pxa2xx_cm_read(void *opaque, hwaddr addr, unsigned size) { PXA2xxState *s = (PXA2xxState *) opaque; switch (addr) { case CCCR: case CKEN: case OSCC: return s->cm_regs[addr >> 2]; case CCSR: return s->cm_regs[CCCR >> 2] | (3 << 28); default: printf("%s: Bad register " REG_FMT "\n", __FUNCTION__, addr); break; } return 0; }


static int mxf_write_header_metadata_sets(AVFormatContext *s) { AVStream *st; MXFStreamContext *sc = NULL; int i; mxf_write_preface(s); mxf_write_identification(s); mxf_write_content_storage(s); for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; sc = av_mallocz(sizeof(MXFStreamContext)); if (!sc) return AVERROR(ENOMEM); st->priv_data = sc; // set pts information if (st->codec->codec_type == CODEC_TYPE_VIDEO) av_set_pts_info(st, 64, 1, st->codec->time_base.den); else if (st->codec->codec_type == CODEC_TYPE_AUDIO) av_set_pts_info(st, 64, 1, st->codec->sample_rate); } mxf_build_structural_metadata(s, MaterialPackage); mxf_build_structural_metadata(s, SourcePackage); return 0; }


int av_opencl_buffer_write_image(cl_mem dst_cl_buf, size_t cl_buffer_size, int dst_cl_offset, uint8_t **src_data, int *plane_size, int plane_num) { int i, buffer_size = 0; uint8_t *temp; cl_int status; void *mapped; if ((unsigned int)plane_num > 8) { return AVERROR(EINVAL); } for (i = 0;i < plane_num;i++) { buffer_size += plane_size[i]; } if (buffer_size > cl_buffer_size) { av_log(&openclutils, AV_LOG_ERROR, "Cannot write image to OpenCL buffer: buffer too small\n"); return AVERROR(EINVAL); } mapped = clEnqueueMapBuffer(gpu_env.command_queue, dst_cl_buf, CL_TRUE,CL_MAP_WRITE, 0, buffer_size + dst_cl_offset, 0, NULL, NULL, &status); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not map OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } temp = mapped; temp += dst_cl_offset; for (i = 0; i < plane_num; i++) { memcpy(temp, src_data[i], plane_size[i]); temp += plane_size[i]; } status = clEnqueueUnmapMemObject(gpu_env.command_queue, dst_cl_buf, mapped, 0, NULL, NULL); if (status != CL_SUCCESS) { av_log(&openclutils, AV_LOG_ERROR, "Could not unmap OpenCL buffer: %s\n", opencl_errstr(status)); return AVERROR_EXTERNAL; } return 0; }


int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size) { int id; id = avio_rl16(pb); codec->codec_type = AVMEDIA_TYPE_AUDIO; codec->channels = avio_rl16(pb); codec->sample_rate = avio_rl32(pb); codec->bit_rate = avio_rl32(pb) * 8; codec->block_align = avio_rl16(pb); if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */ codec->bits_per_coded_sample = 8; }else codec->bits_per_coded_sample = avio_rl16(pb); if (id == 0xFFFE) { codec->codec_tag = 0; } else { codec->codec_tag = id; codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample); } if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */ int cbSize = avio_rl16(pb); /* cbSize */ size -= 18; cbSize = FFMIN(size, cbSize); if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */ ff_asf_guid subformat; codec->bits_per_coded_sample = avio_rl16(pb); codec->channel_layout = avio_rl32(pb); /* dwChannelMask */ ff_get_guid(pb, &subformat); if (!memcmp(subformat + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) { codec->codec_tag = AV_RL32(subformat); codec->codec_id = ff_wav_codec_get_id(codec->codec_tag, codec->bits_per_coded_sample); } else { codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subformat); if (!codec->codec_id) av_log(codec, AV_LOG_WARNING, "unknown subformat:"FF_PRI_GUID"\n", FF_ARG_GUID(subformat)); } cbSize -= 22; size -= 22; } codec->extradata_size = cbSize; if (cbSize > 0) { av_free(codec->extradata); codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); if (!codec->extradata) return AVERROR(ENOMEM); avio_read(pb, codec->extradata, codec->extradata_size); size -= cbSize; } /* It is possible for the chunk to contain garbage at the end */ if (size > 0) avio_skip(pb, size); } if (codec->codec_id == CODEC_ID_AAC_LATM) { /* channels and sample_rate values are those prior to applying SBR and/or PS */ codec->channels = 0; codec->sample_rate = 0; } /* override bits_per_coded_sample for G.726 */ if (codec->codec_id == CODEC_ID_ADPCM_G726) codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate; return 0; }


static int r3d_read_packet(AVFormatContext *s, AVPacket *pkt) { R3DContext *r3d = s->priv_data; Atom atom; int err = 0; while (!err) { if (read_atom(s, &atom) < 0) { err = -1; break; } switch (atom.tag) { case MKTAG('R','E','D','V'): if (s->streams[0]->discard == AVDISCARD_ALL) goto skip; if (!(err = r3d_read_redv(s, pkt, &atom))) return 0; break; case MKTAG('R','E','D','A'): if (!r3d->audio_channels) return -1; if (s->streams[1]->discard == AVDISCARD_ALL) goto skip; if (!(err = r3d_read_reda(s, pkt, &atom))) return 0; break; default: skip: avio_skip(s->pb, atom.size-8); } } return err; }


PPC_OP(test_ctrz_true) { T0 = (regs->ctr == 0 && (T0 & PARAM(1)) != 0); RETURN(); }


static void monitor_control_event(void *opaque, int event) { if (event == CHR_EVENT_OPENED) { QObject *data; Monitor *mon = opaque; mon->mc->command_mode = 0; json_message_parser_init(&mon->mc->parser, handle_qmp_command); data = get_qmp_greeting(); monitor_json_emitter(mon, data); qobject_decref(data); } }


void cpu_ppc_reset (void *opaque) { CPUPPCState *env; target_ulong msr; env = opaque; msr = (target_ulong)0; #if defined(TARGET_PPC64) msr |= (target_ulong)0 << MSR_HV; /* Should be 1... */ #endif msr |= (target_ulong)0 << MSR_AP; /* TO BE CHECKED */ msr |= (target_ulong)0 << MSR_SA; /* TO BE CHECKED */ msr |= (target_ulong)1 << MSR_EP; #if defined (DO_SINGLE_STEP) && 0 /* Single step trace mode */ msr |= (target_ulong)1 << MSR_SE; msr |= (target_ulong)1 << MSR_BE; #endif #if defined(CONFIG_USER_ONLY) msr |= (target_ulong)1 << MSR_FP; /* Allow floating point usage */ msr |= (target_ulong)1 << MSR_PR; #else env->nip = env->hreset_vector | env->excp_prefix; if (env->mmu_model != POWERPC_MMU_REAL_4xx) ppc_tlb_invalidate_all(env); #endif env->msr = msr; hreg_compute_hflags(env); env->reserve = -1; /* Be sure no exception or interrupt is pending */ env->pending_interrupts = 0; env->exception_index = POWERPC_EXCP_NONE; env->error_code = 0; /* Flush all TLBs */ tlb_flush(env, 1); }


static int mov_create_timecode_track(AVFormatContext *s, int index, int src_index, const char *tcstr) { int ret; MOVMuxContext *mov = s->priv_data; MOVTrack *track = &mov->tracks[index]; AVStream *src_st = s->streams[src_index]; AVTimecode tc; AVPacket pkt = {.stream_index = index, .flags = AV_PKT_FLAG_KEY, .size = 4}; AVRational rate = find_fps(s, src_st); /* compute the frame number */ ret = av_timecode_init_from_string(&tc, rate, tcstr, s); if (ret < 0) return ret; /* tmcd track based on video stream */ track->mode = mov->mode; track->tag = MKTAG('t','m','c','d'); track->src_track = src_index; track->timescale = mov->tracks[src_index].timescale; if (tc.flags & AV_TIMECODE_FLAG_DROPFRAME) track->timecode_flags |= MOV_TIMECODE_FLAG_DROPFRAME; /* set st to src_st for metadata access*/ track->st = src_st; /* encode context: tmcd data stream */ track->enc = avcodec_alloc_context3(NULL); track->enc->codec_type = AVMEDIA_TYPE_DATA; track->enc->codec_tag = track->tag; track->enc->time_base = av_inv_q(rate); /* the tmcd track just contains one packet with the frame number */ pkt.data = av_malloc(pkt.size); AV_WB32(pkt.data, tc.start); ret = ff_mov_write_packet(s, &pkt); av_free(pkt.data); return ret; }


static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t *dst) { MpegEncContext *s = &r->s; int i, j, k, v; int A, B, C; int pattern; int8_t *ptr; for(i = 0; i < 4; i++, dst += r->intra_types_stride){ if(!i && s->first_slice_line){ pattern = get_vlc2(gb, aic_top_vlc.table, AIC_TOP_BITS, 1); dst[0] = (pattern >> 2) & 2; dst[1] = (pattern >> 1) & 2; dst[2] = pattern & 2; dst[3] = (pattern << 1) & 2; continue; } ptr = dst; for(j = 0; j < 4; j++){ /* Coefficients are read using VLC chosen by the prediction pattern * The first one (used for retrieving a pair of coefficients) is * constructed from the top, top right and left coefficients * The second one (used for retrieving only one coefficient) is * top + 10 * left. */ A = ptr[-r->intra_types_stride + 1]; // it won't be used for the last coefficient in a row B = ptr[-r->intra_types_stride]; C = ptr[-1]; pattern = A + (B << 4) + (C << 8); for(k = 0; k < MODE2_PATTERNS_NUM; k++) if(pattern == rv40_aic_table_index[k]) break; if(j < 3 && k < MODE2_PATTERNS_NUM){ //pattern is found, decoding 2 coefficients v = get_vlc2(gb, aic_mode2_vlc[k].table, AIC_MODE2_BITS, 2); *ptr++ = v/9; *ptr++ = v%9; j++; }else{ if(B != -1 && C != -1) v = get_vlc2(gb, aic_mode1_vlc[B + C*10].table, AIC_MODE1_BITS, 1); else{ // tricky decoding v = 0; switch(C){ case -1: // code 0 -> 1, 1 -> 0 if(B < 2) v = get_bits1(gb) ^ 1; break; case 0: case 2: // code 0 -> 2, 1 -> 0 v = (get_bits1(gb) ^ 1) << 1; break; } } *ptr++ = v; } } } return 0; }


void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) { BusState *qbus = qdev_get_parent_bus(DEVICE(vdev)); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus); /* virtio-1 compliant devices cannot change the alignment */ if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) { error_report("tried to modify queue alignment for virtio-1 device"); return; } /* Check that the transport told us it was going to do this * (so a buggy transport will immediately assert rather than * silently failing to migrate this state) */ assert(k->has_variable_vring_alignment); vdev->vq[n].vring.align = align; virtio_queue_update_rings(vdev, n); }


static int update_wrap_reference(AVFormatContext *s, AVStream *st, int stream_index, AVPacket *pkt) { int64_t ref = pkt->dts; if (ref == AV_NOPTS_VALUE) ref = pkt->pts; if (ref == AV_NOPTS_VALUE) return 0; ref &= (1LL<<st->pts_wrap_bits)-1; if (s->correct_ts_overflow && st->pts_wrap_bits < 63 && st->pts_wrap_reference == AV_NOPTS_VALUE) { int i; // reference time stamp should be 60 s before first time stamp int64_t pts_wrap_reference = ref - av_rescale(60, st->time_base.den, st->time_base.num); // if first time stamp is not more than 1/8 and 60s before the wrap point, subtract rather than add wrap offset int pts_wrap_behavior = (ref < (1LL<<st->pts_wrap_bits) - (1LL<<st->pts_wrap_bits-3)) || (ref < (1LL<<st->pts_wrap_bits) - av_rescale(60, st->time_base.den, st->time_base.num)) ? AV_PTS_WRAP_ADD_OFFSET : AV_PTS_WRAP_SUB_OFFSET; AVProgram *first_program = av_find_program_from_stream(s, NULL, stream_index); if (!first_program) { int default_stream_index = av_find_default_stream_index(s); if (s->streams[default_stream_index]->pts_wrap_reference == AV_NOPTS_VALUE) { for (i=0; i<s->nb_streams; i++) { s->streams[i]->pts_wrap_reference = pts_wrap_reference; s->streams[i]->pts_wrap_behavior = pts_wrap_behavior; } } else { st->pts_wrap_reference = s->streams[default_stream_index]->pts_wrap_reference; st->pts_wrap_behavior = s->streams[default_stream_index]->pts_wrap_behavior; } } else { AVProgram *program = first_program; while (program) { if (program->pts_wrap_reference != AV_NOPTS_VALUE) { pts_wrap_reference = program->pts_wrap_reference; pts_wrap_behavior = program->pts_wrap_behavior; break; } program = av_find_program_from_stream(s, program, stream_index); } // update every program with differing pts_wrap_reference program = first_program; while(program) { if (program->pts_wrap_reference != pts_wrap_reference) { for (i=0; i<program->nb_stream_indexes; i++) { s->streams[program->stream_index[i]]->pts_wrap_reference = pts_wrap_reference; s->streams[program->stream_index[i]]->pts_wrap_behavior = pts_wrap_behavior; } program->pts_wrap_reference = pts_wrap_reference; program->pts_wrap_behavior = pts_wrap_behavior; } program = av_find_program_from_stream(s, program, stream_index); } } return 1; } return 0; }


static void action_command(EEPRO100State *s) { for (;;) { bool bit_el; bool bit_s; bool bit_i; bool bit_nc; uint16_t ok_status = STATUS_OK; s->cb_address = s->cu_base + s->cu_offset; read_cb(s); bit_el = ((s->tx.command & COMMAND_EL) != 0); bit_s = ((s->tx.command & COMMAND_S) != 0); bit_i = ((s->tx.command & COMMAND_I) != 0); bit_nc = ((s->tx.command & COMMAND_NC) != 0); #if 0 bool bit_sf = ((s->tx.command & COMMAND_SF) != 0); #endif s->cu_offset = s->tx.link; TRACE(OTHER, logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n", s->tx.status, s->tx.command, s->tx.link)); switch (s->tx.command & COMMAND_CMD) { case CmdNOp: /* Do nothing. */ break; case CmdIASetup: cpu_physical_memory_read(s->cb_address + 8, &s->conf.macaddr.a[0], 6); TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->conf.macaddr.a[0], 6))); break; case CmdConfigure: cpu_physical_memory_read(s->cb_address + 8, &s->configuration[0], sizeof(s->configuration)); TRACE(OTHER, logout("configuration: %s\n", nic_dump(&s->configuration[0], 16))); break; case CmdMulticastList: set_multicast_list(s); break; case CmdTx: if (bit_nc) { missing("CmdTx: NC = 0"); ok_status = 0; break; } tx_command(s); break; case CmdTDR: TRACE(OTHER, logout("load microcode\n")); /* Starting with offset 8, the command contains * 64 dwords microcode which we just ignore here. */ break; case CmdDiagnose: TRACE(OTHER, logout("diagnose\n")); /* Make sure error flag is not set. */ s->tx.status = 0; break; default: missing("undefined command"); ok_status = 0; break; } /* Write new status. */ stw_phys(s->cb_address, s->tx.status | ok_status | STATUS_C); if (bit_i) { /* CU completed action. */ eepro100_cx_interrupt(s); } if (bit_el) { /* CU becomes idle. Terminate command loop. */ set_cu_state(s, cu_idle); eepro100_cna_interrupt(s); break; } else if (bit_s) { /* CU becomes suspended. Terminate command loop. */ set_cu_state(s, cu_suspended); eepro100_cna_interrupt(s); break; } else { /* More entries in list. */ TRACE(OTHER, logout("CU list with at least one more entry\n")); } } TRACE(OTHER, logout("CU list empty\n")); /* List is empty. Now CU is idle or suspended. */ }


void SwScale_YV12slice(unsigned char* srcptr[],int stride[], int srcSliceY , int srcSliceH, uint8_t* dstptr[], int dststride, int dstbpp, int srcW, int srcH, int dstW, int dstH){ #ifdef RUNTIME_CPUDETECT #ifdef CAN_COMPILE_X86_ASM // ordered per speed fasterst first if(gCpuCaps.hasMMX2) SwScale_YV12slice_MMX2(srcptr, stride, srcSliceY, srcSliceH, dstptr, dststride, dstbpp, srcW, srcH, dstW, dstH); else if(gCpuCaps.has3DNow) SwScale_YV12slice_3DNow(srcptr, stride, srcSliceY, srcSliceH, dstptr, dststride, dstbpp, srcW, srcH, dstW, dstH); else if(gCpuCaps.hasMMX) SwScale_YV12slice_MMX(srcptr, stride, srcSliceY, srcSliceH, dstptr, dststride, dstbpp, srcW, srcH, dstW, dstH); else SwScale_YV12slice_C(srcptr, stride, srcSliceY, srcSliceH, dstptr, dststride, dstbpp, srcW, srcH, dstW, dstH); #else SwScale_YV12slice_C(srcptr, stride, srcSliceY, srcSliceH, dstptr, dststride, dstbpp, srcW, srcH, dstW, dstH); #endif #else //RUNTIME_CPUDETECT #ifdef HAVE_MMX2 SwScale_YV12slice_MMX2(srcptr, stride, srcSliceY, srcSliceH, dstptr, dststride, dstbpp, srcW, srcH, dstW, dstH); #elif defined (HAVE_3DNOW) SwScale_YV12slice_3DNow(srcptr, stride, srcSliceY, srcSliceH, dstptr, dststride, dstbpp, srcW, srcH, dstW, dstH); #elif defined (HAVE_MMX) SwScale_YV12slice_MMX(srcptr, stride, srcSliceY, srcSliceH, dstptr, dststride, dstbpp, srcW, srcH, dstW, dstH); #else SwScale_YV12slice_C(srcptr, stride, srcSliceY, srcSliceH, dstptr, dststride, dstbpp, srcW, srcH, dstW, dstH); #endif #endif //!RUNTIME_CPUDETECT }


int ppc_hash64_handle_mmu_fault(CPUPPCState *env, target_ulong address, int rw, int mmu_idx) { struct mmu_ctx_hash64 ctx; int access_type; int ret = 0; if (rw == 2) { /* code access */ rw = 0; access_type = ACCESS_CODE; } else { /* data access */ access_type = env->access_type; } ret = ppc_hash64_get_physical_address(env, &ctx, address, rw, access_type); if (ret == 0) { tlb_set_page(env, address & TARGET_PAGE_MASK, ctx.raddr & TARGET_PAGE_MASK, ctx.prot, mmu_idx, TARGET_PAGE_SIZE); ret = 0; } else if (ret < 0) { LOG_MMU_STATE(env); if (access_type == ACCESS_CODE) { switch (ret) { case -1: env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x40000000; break; case -2: /* Access rights violation */ env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x08000000; break; case -3: /* No execute protection violation */ env->exception_index = POWERPC_EXCP_ISI; env->error_code = 0x10000000; break; case -5: /* No match in segment table */ env->exception_index = POWERPC_EXCP_ISEG; env->error_code = 0; break; } } else { switch (ret) { case -1: /* No matches in page tables or TLB */ env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) { env->spr[SPR_DSISR] = 0x42000000; } else { env->spr[SPR_DSISR] = 0x40000000; } break; case -2: /* Access rights violation */ env->exception_index = POWERPC_EXCP_DSI; env->error_code = 0; env->spr[SPR_DAR] = address; if (rw == 1) { env->spr[SPR_DSISR] = 0x0A000000; } else { env->spr[SPR_DSISR] = 0x08000000; } break; case -5: /* No match in segment table */ env->exception_index = POWERPC_EXCP_DSEG; env->error_code = 0; env->spr[SPR_DAR] = address; break; } } #if 0 printf("%s: set exception to %d %02x\n", __func__, env->exception, env->error_code); #endif ret = 1; } return ret; }


static void isa_mmio_writew(void *opaque, target_phys_addr_t addr, uint32_t val) { cpu_outw(addr & IOPORTS_MASK, val); }


static int flic_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) { FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data; int stream_ptr = 0; int stream_ptr_after_color_chunk; int pixel_ptr; int palette_ptr; unsigned char palette_idx1; unsigned char palette_idx2; unsigned int frame_size; int num_chunks; unsigned int chunk_size; int chunk_type; int i, j; int color_packets; int color_changes; int color_shift; unsigned char r, g, b; int lines; int compressed_lines; int starting_line; signed short line_packets; int y_ptr; signed char byte_run; int pixel_skip; int pixel_countdown; unsigned char *pixels; int pixel_limit; s->frame.reference = 1; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; if (avctx->reget_buffer(avctx, &s->frame) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; } pixels = s->frame.data[0]; pixel_limit = s->avctx->height * s->frame.linesize[0]; frame_size = LE_32(&buf[stream_ptr]); stream_ptr += 6; /* skip the magic number */ num_chunks = LE_16(&buf[stream_ptr]); stream_ptr += 10; /* skip padding */ frame_size -= 16; /* iterate through the chunks */ while ((frame_size > 0) && (num_chunks > 0)) { chunk_size = LE_32(&buf[stream_ptr]); stream_ptr += 4; chunk_type = LE_16(&buf[stream_ptr]); stream_ptr += 2; switch (chunk_type) { case FLI_256_COLOR: case FLI_COLOR: stream_ptr_after_color_chunk = stream_ptr + chunk_size - 6; s->new_palette = 1; /* check special case: If this file is from the Magic Carpet * game and uses 6-bit colors even though it reports 256-color * chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during * initialization) */ if ((chunk_type == FLI_256_COLOR) && (s->fli_type != 0xAF13)) color_shift = 0; else color_shift = 2; /* set up the palette */ color_packets = LE_16(&buf[stream_ptr]); stream_ptr += 2; palette_ptr = 0; for (i = 0; i < color_packets; i++) { /* first byte is how many colors to skip */ palette_ptr += buf[stream_ptr++]; /* next byte indicates how many entries to change */ color_changes = buf[stream_ptr++]; /* if there are 0 color changes, there are actually 256 */ if (color_changes == 0) color_changes = 256; for (j = 0; j < color_changes; j++) { /* wrap around, for good measure */ if ((unsigned)palette_ptr >= 256) palette_ptr = 0; r = buf[stream_ptr++] << color_shift; g = buf[stream_ptr++] << color_shift; b = buf[stream_ptr++] << color_shift; s->palette[palette_ptr++] = (r << 16) | (g << 8) | b; } } /* color chunks sometimes have weird 16-bit alignment issues; * therefore, take the hardline approach and set the stream_ptr * to the value calculated w.r.t. the size specified by the color * chunk header */ stream_ptr = stream_ptr_after_color_chunk; break; case FLI_DELTA: y_ptr = 0; compressed_lines = LE_16(&buf[stream_ptr]); stream_ptr += 2; while (compressed_lines > 0) { line_packets = LE_16(&buf[stream_ptr]); stream_ptr += 2; if (line_packets < 0) { line_packets = -line_packets; y_ptr += line_packets * s->frame.linesize[0]; } else { compressed_lines--; pixel_ptr = y_ptr; pixel_countdown = s->avctx->width; for (i = 0; i < line_packets; i++) { /* account for the skip bytes */ pixel_skip = buf[stream_ptr++]; pixel_ptr += pixel_skip; pixel_countdown -= pixel_skip; byte_run = buf[stream_ptr++]; if (byte_run < 0) { byte_run = -byte_run; palette_idx1 = buf[stream_ptr++]; palette_idx2 = buf[stream_ptr++]; for (j = 0; j < byte_run; j++, pixel_countdown -= 2) { pixels[pixel_ptr++] = palette_idx1; pixels[pixel_ptr++] = palette_idx2; } } else { for (j = 0; j < byte_run * 2; j++, pixel_countdown--) { palette_idx1 = buf[stream_ptr++]; pixels[pixel_ptr++] = palette_idx1; } } } y_ptr += s->frame.linesize[0]; } } break; case FLI_LC: /* line compressed */ starting_line = LE_16(&buf[stream_ptr]); stream_ptr += 2; y_ptr = 0; y_ptr += starting_line * s->frame.linesize[0]; compressed_lines = LE_16(&buf[stream_ptr]); stream_ptr += 2; while (compressed_lines > 0) { pixel_ptr = y_ptr; pixel_countdown = s->avctx->width; line_packets = buf[stream_ptr++]; if (line_packets > 0) { for (i = 0; i < line_packets; i++) { /* account for the skip bytes */ pixel_skip = buf[stream_ptr++]; pixel_ptr += pixel_skip; pixel_countdown -= pixel_skip; byte_run = buf[stream_ptr++]; if (byte_run > 0) { for (j = 0; j < byte_run; j++, pixel_countdown--) { palette_idx1 = buf[stream_ptr++]; pixels[pixel_ptr++] = palette_idx1; } } else { byte_run = -byte_run; palette_idx1 = buf[stream_ptr++]; for (j = 0; j < byte_run; j++, pixel_countdown--) { pixels[pixel_ptr++] = palette_idx1; } } } } y_ptr += s->frame.linesize[0]; compressed_lines--; } break; case FLI_BLACK: /* set the whole frame to color 0 (which is usually black) */ memset(pixels, 0, s->frame.linesize[0] * s->avctx->height); break; case FLI_BRUN: /* Byte run compression: This chunk type only occurs in the first * FLI frame and it will update the entire frame. */ y_ptr = 0; for (lines = 0; lines < s->avctx->height; lines++) { pixel_ptr = y_ptr; /* disregard the line packets; instead, iterate through all * pixels on a row */ stream_ptr++; pixel_countdown = s->avctx->width; while (pixel_countdown > 0) { byte_run = buf[stream_ptr++]; if (byte_run > 0) { palette_idx1 = buf[stream_ptr++]; for (j = 0; j < byte_run; j++) { pixels[pixel_ptr++] = palette_idx1; pixel_countdown--; if (pixel_countdown < 0) av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n", pixel_countdown); } } else { /* copy bytes if byte_run < 0 */ byte_run = -byte_run; for (j = 0; j < byte_run; j++) { palette_idx1 = buf[stream_ptr++]; pixels[pixel_ptr++] = palette_idx1; pixel_countdown--; if (pixel_countdown < 0) av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d)\n", pixel_countdown); } } } y_ptr += s->frame.linesize[0]; } break; case FLI_COPY: /* copy the chunk (uncompressed frame) */ if (chunk_size - 6 > s->avctx->width * s->avctx->height) { av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \ "bigger than image, skipping chunk\n", chunk_size - 6); stream_ptr += chunk_size - 6; } else { for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height; y_ptr += s->frame.linesize[0]) { memcpy(&pixels[y_ptr], &buf[stream_ptr], s->avctx->width); stream_ptr += s->avctx->width; } } break; case FLI_MINI: /* some sort of a thumbnail? disregard this chunk... */ stream_ptr += chunk_size - 6; break; default: av_log(avctx, AV_LOG_ERROR, "Unrecognized chunk type: %d\n", chunk_type); break; } frame_size -= chunk_size; num_chunks--; } /* by the end of the chunk, the stream ptr should equal the frame * size (minus 1, possibly); if it doesn't, issue a warning */ if ((stream_ptr != buf_size) && (stream_ptr != buf_size - 1)) av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \ "and final chunk ptr = %d\n", buf_size, stream_ptr); /* make the palette available on the way out */ // if (s->new_palette) { if (1) { memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); s->frame.palette_has_changed = 1; s->new_palette = 0; } *data_size=sizeof(AVFrame); *(AVFrame*)data = s->frame; return buf_size; }


static int encode_superframe(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ WMACodecContext *s = avctx->priv_data; const short *samples = data; int i, total_gain; s->block_len_bits= s->frame_len_bits; //required by non variable block len s->block_len = 1 << s->block_len_bits; apply_window_and_mdct(avctx, samples, avctx->frame_size); if (s->ms_stereo) { float a, b; int i; for(i = 0; i < s->block_len; i++) { a = s->coefs[0][i]*0.5; b = s->coefs[1][i]*0.5; s->coefs[0][i] = a + b; s->coefs[1][i] = a - b; #if 1 total_gain= 128; for(i=64; i; i>>=1){ int error= encode_frame(s, s->coefs, buf, buf_size, total_gain-i); if(error<0) total_gain-= i; #else total_gain= 90; best= encode_frame(s, s->coefs, buf, buf_size, total_gain); for(i=32; i; i>>=1){ int scoreL= encode_frame(s, s->coefs, buf, buf_size, total_gain-i); int scoreR= encode_frame(s, s->coefs, buf, buf_size, total_gain+i); av_log(NULL, AV_LOG_ERROR, "%d %d %d (%d)\n", scoreL, best, scoreR, total_gain); if(scoreL < FFMIN(best, scoreR)){ best = scoreL; total_gain -= i; }else if(scoreR < best){ best = scoreR; total_gain += i; #endif encode_frame(s, s->coefs, buf, buf_size, total_gain); assert((put_bits_count(&s->pb) & 7) == 0); i= s->block_align - (put_bits_count(&s->pb)+7)/8; assert(i>=0); while(i--) put_bits(&s->pb, 8, 'N'); flush_put_bits(&s->pb); return put_bits_ptr(&s->pb) - s->pb.buf;


int kvm_on_sigbus(int code, void *addr) { #if defined(KVM_CAP_MCE) if ((first_cpu->mcg_cap & MCG_SER_P) && addr && code == BUS_MCEERR_AO) { uint64_t status; void *vaddr; ram_addr_t ram_addr; target_phys_addr_t paddr; /* Hope we are lucky for AO MCE */ vaddr = addr; if (qemu_ram_addr_from_host(vaddr, &ram_addr) || !kvm_physical_memory_addr_from_ram(first_cpu->kvm_state, ram_addr, &paddr)) { fprintf(stderr, "Hardware memory error for memory used by " "QEMU itself instead of guest system!: %p\n", addr); return 0; } status = MCI_STATUS_VAL | MCI_STATUS_UC | MCI_STATUS_EN | MCI_STATUS_MISCV | MCI_STATUS_ADDRV | MCI_STATUS_S | 0xc0; kvm_inject_x86_mce(first_cpu, 9, status, MCG_STATUS_MCIP | MCG_STATUS_RIPV, paddr, (MCM_ADDR_PHYS << 6) | 0xc, 1); kvm_mce_broadcast_rest(first_cpu); } else #endif { if (code == BUS_MCEERR_AO) { return 0; } else if (code == BUS_MCEERR_AR) { hardware_memory_error(); } else { return 1; } } return 0; }


static int ogg_save(AVFormatContext *s) { struct ogg *ogg = s->priv_data; struct ogg_state *ost = av_malloc(sizeof (*ost) + (ogg->nstreams-1) * sizeof (*ogg->streams)); int i; ost->pos = avio_tell (s->pb); ost->curidx = ogg->curidx; ost->next = ogg->state; ost->nstreams = ogg->nstreams; memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams)); for (i = 0; i < ogg->nstreams; i++){ struct ogg_stream *os = ogg->streams + i; os->buf = av_malloc (os->bufsize); memset (os->buf, 0, os->bufsize); memcpy (os->buf, ost->streams[i].buf, os->bufpos); } ogg->state = ost; return 0; }


static int dxtory_decode_v1_444(AVCodecContext *avctx, AVFrame *pic, const uint8_t *src, int src_size) { int h, w; uint8_t *Y, *U, *V; int ret; if (src_size < avctx->width * avctx->height * 3) { av_log(avctx, AV_LOG_ERROR, "packet too small\n"); return AVERROR_INVALIDDATA; } avctx->pix_fmt = AV_PIX_FMT_YUV444P; if ((ret = ff_get_buffer(avctx, pic, 0)) < 0) return ret; Y = pic->data[0]; U = pic->data[1]; V = pic->data[2]; for (h = 0; h < avctx->height; h++) { for (w = 0; w < avctx->width; w++) { Y[w] = *src++; U[w] = *src++ ^ 0x80; V[w] = *src++ ^ 0x80; } Y += pic->linesize[0]; U += pic->linesize[1]; V += pic->linesize[2]; } return 0; }


static size_t buffered_set_rate_limit(void *opaque, size_t new_rate) { QEMUFileBuffered *s = opaque; if (s->has_error) goto out; s->xfer_limit = new_rate / 10; out: return s->xfer_limit; }


static void ccw_init(MachineState *machine) { int ret; VirtualCssBus *css_bus; DeviceState *dev; s390_sclp_init(); s390_memory_init(machine->ram_size); /* get a BUS */ css_bus = virtual_css_bus_init(); s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline, machine->initrd_filename, "s390-ccw.img", true); s390_flic_init(); dev = qdev_create(NULL, TYPE_S390_PCI_HOST_BRIDGE); object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE, OBJECT(dev), NULL); qdev_init_nofail(dev); /* register hypercalls */ virtio_ccw_register_hcalls(); /* init CPUs */ s390_init_cpus(machine->cpu_model); if (kvm_enabled()) { kvm_s390_enable_css_support(s390_cpu_addr2state(0)); } /* * Create virtual css and set it as default so that non mcss-e * enabled guests only see virtio devices. */ ret = css_create_css_image(VIRTUAL_CSSID, true); assert(ret == 0); /* Create VirtIO network adapters */ s390_create_virtio_net(BUS(css_bus), "virtio-net-ccw"); /* Register savevm handler for guest TOD clock */ register_savevm(NULL, "todclock", 0, 1, gtod_save, gtod_load, kvm_state); }


int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, int64_t pos, int size) { BlockDriver *drv = bs->drv; if (!drv) return -ENOMEDIUM; if (drv->bdrv_load_vmstate) return drv->bdrv_load_vmstate(bs, buf, pos, size); if (bs->file) return bdrv_load_vmstate(bs->file, buf, pos, size); return -ENOTSUP; }


static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx) { return ff_vaapi_encode_init(avctx, &vaapi_encode_type_h265); }


static void versatile_init(ram_addr_t ram_size, int vga_ram_size, const char *boot_device, DisplayState *ds, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model, int board_id) { CPUState *env; qemu_irq *pic; qemu_irq *sic; void *scsi_hba; PCIBus *pci_bus; NICInfo *nd; int n; int done_smc = 0; int index; if (!cpu_model) cpu_model = "arm926"; env = cpu_init(cpu_model); if (!env) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } /* ??? RAM should repeat to fill physical memory space. */ /* SDRAM at address zero. */ cpu_register_physical_memory(0, ram_size, IO_MEM_RAM); arm_sysctl_init(0x10000000, 0x41007004); pic = arm_pic_init_cpu(env); pic = pl190_init(0x10140000, pic[0], pic[1]); sic = vpb_sic_init(0x10003000, pic, 31); pl050_init(0x10006000, sic[3], 0); pl050_init(0x10007000, sic[4], 1); pci_bus = pci_vpb_init(sic, 27, 0); /* The Versatile PCI bridge does not provide access to PCI IO space, so many of the qemu PCI devices are not useable. */ for(n = 0; n < nb_nics; n++) { nd = &nd_table[n]; if (!nd->model) nd->model = done_smc ? "rtl8139" : "smc91c111"; if (strcmp(nd->model, "smc91c111") == 0) { smc91c111_init(nd, 0x10010000, sic[25]); } else { pci_nic_init(pci_bus, nd, -1); } } if (usb_enabled) { usb_ohci_init_pci(pci_bus, 3, -1); } if (drive_get_max_bus(IF_SCSI) > 0) { fprintf(stderr, "qemu: too many SCSI bus\n"); exit(1); } scsi_hba = lsi_scsi_init(pci_bus, -1); for (n = 0; n < LSI_MAX_DEVS; n++) { index = drive_get_index(IF_SCSI, 0, n); if (index == -1) continue; lsi_scsi_attach(scsi_hba, drives_table[index].bdrv, n); } pl011_init(0x101f1000, pic[12], serial_hds[0], PL011_ARM); pl011_init(0x101f2000, pic[13], serial_hds[1], PL011_ARM); pl011_init(0x101f3000, pic[14], serial_hds[2], PL011_ARM); pl011_init(0x10009000, sic[6], serial_hds[3], PL011_ARM); pl080_init(0x10130000, pic[17], 8); sp804_init(0x101e2000, pic[4]); sp804_init(0x101e3000, pic[5]); /* The versatile/PB actually has a modified Color LCD controller that includes hardware cursor support from the PL111. */ pl110_init(ds, 0x10120000, pic[16], 1); index = drive_get_index(IF_SD, 0, 0); if (index == -1) { fprintf(stderr, "qemu: missing SecureDigital card\n"); exit(1); } pl181_init(0x10005000, drives_table[index].bdrv, sic[22], sic[1]); #if 0 /* Disabled because there's no way of specifying a block device. */ pl181_init(0x1000b000, NULL, sic, 23, 2); #endif /* Add PL031 Real Time Clock. */ pl031_init(0x101e8000,pic[10]); /* Memory map for Versatile/PB: */ /* 0x10000000 System registers. */ /* 0x10001000 PCI controller config registers. */ /* 0x10002000 Serial bus interface. */ /* 0x10003000 Secondary interrupt controller. */ /* 0x10004000 AACI (audio). */ /* 0x10005000 MMCI0. */ /* 0x10006000 KMI0 (keyboard). */ /* 0x10007000 KMI1 (mouse). */ /* 0x10008000 Character LCD Interface. */ /* 0x10009000 UART3. */ /* 0x1000a000 Smart card 1. */ /* 0x1000b000 MMCI1. */ /* 0x10010000 Ethernet. */ /* 0x10020000 USB. */ /* 0x10100000 SSMC. */ /* 0x10110000 MPMC. */ /* 0x10120000 CLCD Controller. */ /* 0x10130000 DMA Controller. */ /* 0x10140000 Vectored interrupt controller. */ /* 0x101d0000 AHB Monitor Interface. */ /* 0x101e0000 System Controller. */ /* 0x101e1000 Watchdog Interface. */ /* 0x101e2000 Timer 0/1. */ /* 0x101e3000 Timer 2/3. */ /* 0x101e4000 GPIO port 0. */ /* 0x101e5000 GPIO port 1. */ /* 0x101e6000 GPIO port 2. */ /* 0x101e7000 GPIO port 3. */ /* 0x101e8000 RTC. */ /* 0x101f0000 Smart card 0. */ /* 0x101f1000 UART0. */ /* 0x101f2000 UART1. */ /* 0x101f3000 UART2. */ /* 0x101f4000 SSPI. */ versatile_binfo.ram_size = ram_size; versatile_binfo.kernel_filename = kernel_filename; versatile_binfo.kernel_cmdline = kernel_cmdline; versatile_binfo.initrd_filename = initrd_filename; versatile_binfo.board_id = board_id; arm_load_kernel(env, &versatile_binfo); }


static void detach(sPAPRDRConnector *drc, DeviceState *d, spapr_drc_detach_cb *detach_cb, void *detach_cb_opaque, Error **errp) { trace_spapr_drc_detach(get_index(drc)); drc->detach_cb = detach_cb; drc->detach_cb_opaque = detach_cb_opaque; /* if we've signalled device presence to the guest, or if the guest * has gone ahead and configured the device (via manually-executed * device add via drmgr in guest, namely), we need to wait * for the guest to quiesce the device before completing detach. * Otherwise, we can assume the guest hasn't seen it and complete the * detach immediately. Note that there is a small race window * just before, or during, configuration, which is this context * refers mainly to fetching the device tree via RTAS. * During this window the device access will be arbitrated by * associated DRC, which will simply fail the RTAS calls as invalid. * This is recoverable within guest and current implementations of * drmgr should be able to cope. */ if (!drc->signalled && !drc->configured) { /* if the guest hasn't seen the device we can't rely on it to * set it back to an isolated state via RTAS, so do it here manually */ drc->isolation_state = SPAPR_DR_ISOLATION_STATE_ISOLATED; } if (drc->isolation_state != SPAPR_DR_ISOLATION_STATE_ISOLATED) { trace_spapr_drc_awaiting_isolated(get_index(drc)); drc->awaiting_release = true; return; } if (drc->type != SPAPR_DR_CONNECTOR_TYPE_PCI && drc->allocation_state != SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { trace_spapr_drc_awaiting_unusable(get_index(drc)); drc->awaiting_release = true; return; } if (drc->awaiting_allocation) { if (!drc->awaiting_allocation_skippable) { drc->awaiting_release = true; trace_spapr_drc_awaiting_allocation(get_index(drc)); return; } } drc->indicator_state = SPAPR_DR_INDICATOR_STATE_INACTIVE; if (drc->detach_cb) { drc->detach_cb(drc->dev, drc->detach_cb_opaque); } drc->awaiting_release = false; drc->awaiting_allocation_skippable = false; g_free(drc->fdt); drc->fdt = NULL; drc->fdt_start_offset = 0; object_property_del(OBJECT(drc), "device", NULL); drc->dev = NULL; drc->detach_cb = NULL; drc->detach_cb_opaque = NULL; }


char **breakline(char *input, int *count) { int c = 0; char *p; char **rval = calloc(sizeof(char *), 1); while (rval && (p = qemu_strsep(&input, " ")) != NULL) { if (!*p) { continue; } c++; rval = realloc(rval, sizeof(*rval) * (c + 1)); if (!rval) { c = 0; break; } rval[c - 1] = p; rval[c] = NULL; } *count = c; return rval; }