int ff_hevc_decode_nal_pps(HEVCContext *s) { GetBitContext *gb = &s->HEVClc->gb; HEVCSPS *sps = NULL; int pic_area_in_ctbs; int log2_diff_ctb_min_tb_size; int i, j, x, y, ctb_addr_rs, tile_id; int ret = 0; unsigned int pps_id = 0; AVBufferRef *pps_buf; HEVCPPS *pps = av_mallocz(sizeof(*pps)); if (!pps) return AVERROR(ENOMEM); pps_buf = av_buffer_create((uint8_t *)pps, sizeof(*pps), hevc_pps_free, NULL, 0); if (!pps_buf) { av_freep(&pps); return AVERROR(ENOMEM); } av_log(s->avctx, AV_LOG_DEBUG, "Decoding PPS\n"); // Default values pps->loop_filter_across_tiles_enabled_flag = 1; pps->num_tile_columns = 1; pps->num_tile_rows = 1; pps->uniform_spacing_flag = 1; pps->disable_dbf = 0; pps->beta_offset = 0; pps->tc_offset = 0; pps->log2_max_transform_skip_block_size = 2; // Coded parameters pps_id = get_ue_golomb_long(gb); if (pps_id >= MAX_PPS_COUNT) { av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); ret = AVERROR_INVALIDDATA; goto err; } pps->sps_id = get_ue_golomb_long(gb); if (pps->sps_id >= MAX_SPS_COUNT) { av_log(s->avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", pps->sps_id); ret = AVERROR_INVALIDDATA; goto err; } if (!s->sps_list[pps->sps_id]) { av_log(s->avctx, AV_LOG_ERROR, "SPS %u does not exist.\n", pps->sps_id); ret = AVERROR_INVALIDDATA; goto err; } sps = (HEVCSPS *)s->sps_list[pps->sps_id]->data; pps->dependent_slice_segments_enabled_flag = get_bits1(gb); pps->output_flag_present_flag = get_bits1(gb); pps->num_extra_slice_header_bits = get_bits(gb, 3); pps->sign_data_hiding_flag = get_bits1(gb); pps->cabac_init_present_flag = get_bits1(gb); pps->num_ref_idx_l0_default_active = get_ue_golomb_long(gb) + 1; pps->num_ref_idx_l1_default_active = get_ue_golomb_long(gb) + 1; pps->pic_init_qp_minus26 = get_se_golomb(gb); pps->constrained_intra_pred_flag = get_bits1(gb); pps->transform_skip_enabled_flag = get_bits1(gb); pps->cu_qp_delta_enabled_flag = get_bits1(gb); pps->diff_cu_qp_delta_depth = 0; if (pps->cu_qp_delta_enabled_flag) pps->diff_cu_qp_delta_depth = get_ue_golomb_long(gb); pps->cb_qp_offset = get_se_golomb(gb); if (pps->cb_qp_offset < -12 || pps->cb_qp_offset > 12) { av_log(s->avctx, AV_LOG_ERROR, "pps_cb_qp_offset out of range: %d\n", pps->cb_qp_offset); ret = AVERROR_INVALIDDATA; goto err; } pps->cr_qp_offset = get_se_golomb(gb); if (pps->cr_qp_offset < -12 || pps->cr_qp_offset > 12) { av_log(s->avctx, AV_LOG_ERROR, "pps_cr_qp_offset out of range: %d\n", pps->cr_qp_offset); ret = AVERROR_INVALIDDATA; goto err; } pps->pic_slice_level_chroma_qp_offsets_present_flag = get_bits1(gb); pps->weighted_pred_flag = get_bits1(gb); pps->weighted_bipred_flag = get_bits1(gb); pps->transquant_bypass_enable_flag = get_bits1(gb); pps->tiles_enabled_flag = get_bits1(gb); pps->entropy_coding_sync_enabled_flag = get_bits1(gb); if (pps->tiles_enabled_flag) { pps->num_tile_columns = get_ue_golomb_long(gb) + 1; pps->num_tile_rows = get_ue_golomb_long(gb) + 1; if (pps->num_tile_columns == 0 || pps->num_tile_columns >= sps->width) { av_log(s->avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n", pps->num_tile_columns - 1); ret = AVERROR_INVALIDDATA; goto err; } if (pps->num_tile_rows == 0 || pps->num_tile_rows >= sps->height) { av_log(s->avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n", pps->num_tile_rows - 1); ret = AVERROR_INVALIDDATA; goto err; } pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width)); pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height)); if (!pps->column_width || !pps->row_height) { ret = AVERROR(ENOMEM); goto err; } pps->uniform_spacing_flag = get_bits1(gb); if (!pps->uniform_spacing_flag) { uint64_t sum = 0; for (i = 0; i < pps->num_tile_columns - 1; i++) { pps->column_width[i] = get_ue_golomb_long(gb) + 1; sum += pps->column_width[i]; } if (sum >= sps->ctb_width) { av_log(s->avctx, AV_LOG_ERROR, "Invalid tile widths.\n"); ret = AVERROR_INVALIDDATA; goto err; } pps->column_width[pps->num_tile_columns - 1] = sps->ctb_width - sum; sum = 0; for (i = 0; i < pps->num_tile_rows - 1; i++) { pps->row_height[i] = get_ue_golomb_long(gb) + 1; sum += pps->row_height[i]; } if (sum >= sps->ctb_height) { av_log(s->avctx, AV_LOG_ERROR, "Invalid tile heights.\n"); ret = AVERROR_INVALIDDATA; goto err; } pps->row_height[pps->num_tile_rows - 1] = sps->ctb_height - sum; } pps->loop_filter_across_tiles_enabled_flag = get_bits1(gb); } pps->seq_loop_filter_across_slices_enabled_flag = get_bits1(gb); pps->deblocking_filter_control_present_flag = get_bits1(gb); if (pps->deblocking_filter_control_present_flag) { pps->deblocking_filter_override_enabled_flag = get_bits1(gb); pps->disable_dbf = get_bits1(gb); if (!pps->disable_dbf) { pps->beta_offset = get_se_golomb(gb) * 2; pps->tc_offset = get_se_golomb(gb) * 2; if (pps->beta_offset/2 < -6 || pps->beta_offset/2 > 6) { av_log(s->avctx, AV_LOG_ERROR, "pps_beta_offset_div2 out of range: %d\n", pps->beta_offset/2); ret = AVERROR_INVALIDDATA; goto err; } if (pps->tc_offset/2 < -6 || pps->tc_offset/2 > 6) { av_log(s->avctx, AV_LOG_ERROR, "pps_tc_offset_div2 out of range: %d\n", pps->tc_offset/2); ret = AVERROR_INVALIDDATA; goto err; } } } pps->scaling_list_data_present_flag = get_bits1(gb); if (pps->scaling_list_data_present_flag) { set_default_scaling_list_data(&pps->scaling_list); ret = scaling_list_data(s, &pps->scaling_list, sps); if (ret < 0) goto err; } pps->lists_modification_present_flag = get_bits1(gb); pps->log2_parallel_merge_level = get_ue_golomb_long(gb) + 2; if (pps->log2_parallel_merge_level > sps->log2_ctb_size) { av_log(s->avctx, AV_LOG_ERROR, "log2_parallel_merge_level_minus2 out of range: %d\n", pps->log2_parallel_merge_level - 2); ret = AVERROR_INVALIDDATA; goto err; } pps->slice_header_extension_present_flag = get_bits1(gb); if (get_bits1(gb)) { // pps_extension_present_flag int pps_range_extensions_flag = get_bits1(gb); /* int pps_extension_7bits = */ get_bits(gb, 7); if (sps->ptl.general_ptl.profile_idc == FF_PROFILE_HEVC_REXT && pps_range_extensions_flag) { pps_range_extensions(s, pps, sps); } } // Inferred parameters pps->col_bd = av_malloc_array(pps->num_tile_columns + 1, sizeof(*pps->col_bd)); pps->row_bd = av_malloc_array(pps->num_tile_rows + 1, sizeof(*pps->row_bd)); pps->col_idxX = av_malloc_array(sps->ctb_width, sizeof(*pps->col_idxX)); if (!pps->col_bd || !pps->row_bd || !pps->col_idxX) { ret = AVERROR(ENOMEM); goto err; } if (pps->uniform_spacing_flag) { if (!pps->column_width) { pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width)); pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height)); } if (!pps->column_width || !pps->row_height) { ret = AVERROR(ENOMEM); goto err; } for (i = 0; i < pps->num_tile_columns; i++) { pps->column_width[i] = ((i + 1) * sps->ctb_width) / pps->num_tile_columns - (i * sps->ctb_width) / pps->num_tile_columns; } for (i = 0; i < pps->num_tile_rows; i++) { pps->row_height[i] = ((i + 1) * sps->ctb_height) / pps->num_tile_rows - (i * sps->ctb_height) / pps->num_tile_rows; } } pps->col_bd[0] = 0; for (i = 0; i < pps->num_tile_columns; i++) pps->col_bd[i + 1] = pps->col_bd[i] + pps->column_width[i]; pps->row_bd[0] = 0; for (i = 0; i < pps->num_tile_rows; i++) pps->row_bd[i + 1] = pps->row_bd[i] + pps->row_height[i]; for (i = 0, j = 0; i < sps->ctb_width; i++) { if (i > pps->col_bd[j]) j++; pps->col_idxX[i] = j; } /** * 6.5 */ pic_area_in_ctbs = sps->ctb_width * sps->ctb_height; pps->ctb_addr_rs_to_ts = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_rs_to_ts)); pps->ctb_addr_ts_to_rs = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->ctb_addr_ts_to_rs)); pps->tile_id = av_malloc_array(pic_area_in_ctbs, sizeof(*pps->tile_id)); pps->min_tb_addr_zs_tab = av_malloc_array((sps->tb_mask+2) * (sps->tb_mask+2), sizeof(*pps->min_tb_addr_zs_tab)); if (!pps->ctb_addr_rs_to_ts || !pps->ctb_addr_ts_to_rs || !pps->tile_id || !pps->min_tb_addr_zs_tab) { ret = AVERROR(ENOMEM); goto err; } for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) { int tb_x = ctb_addr_rs % sps->ctb_width; int tb_y = ctb_addr_rs / sps->ctb_width; int tile_x = 0; int tile_y = 0; int val = 0; for (i = 0; i < pps->num_tile_columns; i++) { if (tb_x < pps->col_bd[i + 1]) { tile_x = i; break; } } for (i = 0; i < pps->num_tile_rows; i++) { if (tb_y < pps->row_bd[i + 1]) { tile_y = i; break; } } for (i = 0; i < tile_x; i++) val += pps->row_height[tile_y] * pps->column_width[i]; for (i = 0; i < tile_y; i++) val += sps->ctb_width * pps->row_height[i]; val += (tb_y - pps->row_bd[tile_y]) * pps->column_width[tile_x] + tb_x - pps->col_bd[tile_x]; pps->ctb_addr_rs_to_ts[ctb_addr_rs] = val; pps->ctb_addr_ts_to_rs[val] = ctb_addr_rs; } for (j = 0, tile_id = 0; j < pps->num_tile_rows; j++) for (i = 0; i < pps->num_tile_columns; i++, tile_id++) for (y = pps->row_bd[j]; y < pps->row_bd[j + 1]; y++) for (x = pps->col_bd[i]; x < pps->col_bd[i + 1]; x++) pps->tile_id[pps->ctb_addr_rs_to_ts[y * sps->ctb_width + x]] = tile_id; pps->tile_pos_rs = av_malloc_array(tile_id, sizeof(*pps->tile_pos_rs)); if (!pps->tile_pos_rs) { ret = AVERROR(ENOMEM); goto err; } for (j = 0; j < pps->num_tile_rows; j++) for (i = 0; i < pps->num_tile_columns; i++) pps->tile_pos_rs[j * pps->num_tile_columns + i] = pps->row_bd[j] * sps->ctb_width + pps->col_bd[i]; log2_diff_ctb_min_tb_size = sps->log2_ctb_size - sps->log2_min_tb_size; pps->min_tb_addr_zs = &pps->min_tb_addr_zs_tab[1*(sps->tb_mask+2)+1]; for (y = 0; y < sps->tb_mask+2; y++) { pps->min_tb_addr_zs_tab[y*(sps->tb_mask+2)] = -1; pps->min_tb_addr_zs_tab[y] = -1; } for (y = 0; y < sps->tb_mask+1; y++) { for (x = 0; x < sps->tb_mask+1; x++) { int tb_x = x >> log2_diff_ctb_min_tb_size; int tb_y = y >> log2_diff_ctb_min_tb_size; int ctb_addr_rs = sps->ctb_width * tb_y + tb_x; int val = pps->ctb_addr_rs_to_ts[ctb_addr_rs] << (log2_diff_ctb_min_tb_size * 2); for (i = 0; i < log2_diff_ctb_min_tb_size; i++) { int m = 1 << i; val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0); } pps->min_tb_addr_zs[y * (sps->tb_mask+2) + x] = val; } } if (get_bits_left(gb) < 0) { av_log(s->avctx, AV_LOG_ERROR, "Overread PPS by %d bits\n", -get_bits_left(gb)); goto err; } av_buffer_unref(&s->pps_list[pps_id]); s->pps_list[pps_id] = pps_buf; return 0; err: av_buffer_unref(&pps_buf); return ret; }


static void ide_drive_pre_save(void *opaque) { IDEState *s = opaque; s->cur_io_buffer_len = 0; if (!(s->status & DRQ_STAT)) return; s->cur_io_buffer_offset = s->data_ptr - s->io_buffer; s->cur_io_buffer_len = s->data_end - s->data_ptr; s->end_transfer_fn_idx = transfer_end_table_idx(s->end_transfer_func); if (s->end_transfer_fn_idx == -1) { fprintf(stderr, "%s: invalid end_transfer_func for DRQ_STAT\n", __func__); s->end_transfer_fn_idx = 2; } }


static int gdb_breakpoint_remove(CPUState *env, target_ulong addr, target_ulong len, int type) { switch (type) { case GDB_BREAKPOINT_SW: case GDB_BREAKPOINT_HW: return cpu_breakpoint_remove(env, addr, BP_GDB); #ifndef CONFIG_USER_ONLY case GDB_WATCHPOINT_WRITE: case GDB_WATCHPOINT_READ: case GDB_WATCHPOINT_ACCESS: return cpu_watchpoint_remove(env, addr, len, xlat_gdb_type[type]); #endif default: return -ENOSYS; } }


static int unin_main_pci_host_init(PCIDevice *d) { pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_APPLE); pci_config_set_device_id(d->config, PCI_DEVICE_ID_APPLE_UNI_N_PCI); d->config[0x08] = 0x00; // revision pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST); d->config[0x0C] = 0x08; // cache_line_size d->config[0x0D] = 0x10; // latency_timer d->config[0x34] = 0x00; // capabilities_pointer return 0; }


VirtIODevice *virtio_serial_init(DeviceState *dev, uint32_t max_nr_ports) { VirtIOSerial *vser; VirtIODevice *vdev; uint32_t i; if (!max_nr_ports) return NULL; vdev = virtio_common_init("virtio-serial", VIRTIO_ID_CONSOLE, sizeof(struct virtio_console_config), sizeof(VirtIOSerial)); vser = DO_UPCAST(VirtIOSerial, vdev, vdev); /* Spawn a new virtio-serial bus on which the ports will ride as devices */ vser->bus = virtser_bus_new(dev); vser->bus->vser = vser; QTAILQ_INIT(&vser->ports); vser->bus->max_nr_ports = max_nr_ports; vser->ivqs = qemu_malloc(max_nr_ports * sizeof(VirtQueue *)); vser->ovqs = qemu_malloc(max_nr_ports * sizeof(VirtQueue *)); /* Add a queue for host to guest transfers for port 0 (backward compat) */ vser->ivqs[0] = virtio_add_queue(vdev, 128, handle_input); /* Add a queue for guest to host transfers for port 0 (backward compat) */ vser->ovqs[0] = virtio_add_queue(vdev, 128, handle_output); /* control queue: host to guest */ vser->c_ivq = virtio_add_queue(vdev, 16, control_in); /* control queue: guest to host */ vser->c_ovq = virtio_add_queue(vdev, 16, control_out); for (i = 1; i < vser->bus->max_nr_ports; i++) { /* Add a per-port queue for host to guest transfers */ vser->ivqs[i] = virtio_add_queue(vdev, 128, handle_input); /* Add a per-per queue for guest to host transfers */ vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output); } vser->config.max_nr_ports = max_nr_ports; vser->ports_map = qemu_mallocz(((max_nr_ports + 31) / 32) * sizeof(vser->ports_map[0])); /* * Reserve location 0 for a console port for backward compat * (old kernel, new qemu) */ mark_port_added(vser, 0); vser->vdev.get_features = get_features; vser->vdev.get_config = get_config; vser->vdev.set_config = set_config; /* * Register for the savevm section with the virtio-console name * to preserve backward compat */ register_savevm(dev, "virtio-console", -1, 2, virtio_serial_save, virtio_serial_load, vser); return vdev; }


static void pci_vpb_map(SysBusDevice *dev, target_phys_addr_t base) { PCIVPBState *s = (PCIVPBState *)dev; /* Selfconfig area. */ memory_region_add_subregion(get_system_memory(), base + 0x01000000, &s->mem_config); /* Normal config area. */ memory_region_add_subregion(get_system_memory(), base + 0x02000000, &s->mem_config2); if (s->realview) { /* IO memory area. */ memory_region_add_subregion(get_system_memory(), base + 0x03000000, &s->isa); } }


static void qmp_input_start_struct(Visitor *v, const char *name, void **obj, size_t size, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); QObject *qobj = qmp_input_get_object(qiv, name, true, errp); Error *err = NULL; if (obj) { *obj = NULL; } if (!qobj) { return; } if (qobject_type(qobj) != QTYPE_QDICT) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "QDict"); return; } qmp_input_push(qiv, qobj, obj, &err); if (err) { error_propagate(errp, err); return; } if (obj) { *obj = g_malloc0(size); } }


static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size) { int skip, len; for(;;) { len = get_buffer(pb, buf, TS_PACKET_SIZE); if (len != TS_PACKET_SIZE) return AVERROR(EIO); /* check paquet sync byte */ if (buf[0] != 0x47) { /* find a new packet start */ url_fseek(pb, -TS_PACKET_SIZE, SEEK_CUR); if (mpegts_resync(pb) < 0) return AVERROR_INVALIDDATA; else continue; } else { skip = raw_packet_size - TS_PACKET_SIZE; if (skip > 0) url_fskip(pb, skip); break; } } return 0; }


av_cold void ff_fft_init_arm(FFTContext *s) { if (HAVE_NEON) { s->fft_permute = ff_fft_permute_neon; s->fft_calc = ff_fft_calc_neon; s->imdct_calc = ff_imdct_calc_neon; s->imdct_half = ff_imdct_half_neon; s->mdct_calc = ff_mdct_calc_neon; s->permutation = FF_MDCT_PERM_INTERLEAVE; } }


static int coroutine_fn bdrv_co_io_em(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *iov, bool is_write) { CoroutineIOCompletion co = { .coroutine = qemu_coroutine_self(), }; BlockDriverAIOCB *acb; if (is_write) { acb = bdrv_aio_writev(bs, sector_num, iov, nb_sectors, bdrv_co_io_em_complete, &co); } else { acb = bdrv_aio_readv(bs, sector_num, iov, nb_sectors, bdrv_co_io_em_complete, &co); } trace_bdrv_co_io_em(bs, sector_num, nb_sectors, is_write, acb); if (!acb) { return -EIO; } qemu_coroutine_yield(); return co.ret; }


static void v9fs_getlock(void *opaque) { size_t offset = 7; struct stat stbuf; V9fsFidState *fidp; V9fsGetlock *glock; int32_t fid, err = 0; V9fsPDU *pdu = opaque; V9fsState *s = pdu->s; glock = g_malloc(sizeof(*glock)); pdu_unmarshal(pdu, offset, "dbqqds", &fid, &glock->type, &glock->start, &glock->length, &glock->proc_id, &glock->client_id); trace_v9fs_getlock(pdu->tag, pdu->id, fid, glock->type, glock->start, glock->length); fidp = get_fid(pdu, fid); if (fidp == NULL) { err = -ENOENT; goto out_nofid; } err = v9fs_co_fstat(pdu, fidp, &stbuf); if (err < 0) { goto out; } glock->type = P9_LOCK_TYPE_UNLCK; offset += pdu_marshal(pdu, offset, "bqqds", glock->type, glock->start, glock->length, glock->proc_id, &glock->client_id); err = offset; trace_v9fs_getlock_return(pdu->tag, pdu->id, glock->type, glock->start, glock->length, glock->proc_id); out: put_fid(pdu, fidp); out_nofid: complete_pdu(s, pdu, err); v9fs_string_free(&glock->client_id); g_free(glock); }


void stb_phys(target_phys_addr_t addr, uint32_t val) { uint8_t v = val; cpu_physical_memory_write(addr, &v, 1); }


void error_set(Error **errp, const char *fmt, ...) { Error *err; va_list ap; if (errp == NULL) { return; } assert(*errp == NULL); err = g_malloc0(sizeof(*err)); va_start(ap, fmt); err->obj = qobject_to_qdict(qobject_from_jsonv(fmt, &ap)); va_end(ap); err->msg = qerror_format(fmt, err->obj); *errp = err; }


static void term_handle_command(const char *cmdline) { const char *p, *pstart, *typestr; char *q; int c, nb_args, len, i, has_arg; term_cmd_t *cmd; char cmdname[256]; char buf[1024]; void *str_allocated[MAX_ARGS]; void *args[MAX_ARGS]; #ifdef DEBUG term_printf("command='%s'\n", cmdline); #endif /* extract the command name */ p = cmdline; q = cmdname; while (isspace(*p)) p++; if (*p == '\0') return; pstart = p; while (*p != '\0' && *p != '/' && !isspace(*p)) p++; len = p - pstart; if (len > sizeof(cmdname) - 1) len = sizeof(cmdname) - 1; memcpy(cmdname, pstart, len); cmdname[len] = '\0'; /* find the command */ for(cmd = term_cmds; cmd->name != NULL; cmd++) { if (compare_cmd(cmdname, cmd->name)) goto found; } term_printf("unknown command: '%s'\n", cmdname); return; found: for(i = 0; i < MAX_ARGS; i++) str_allocated[i] = NULL; /* parse the parameters */ typestr = cmd->args_type; nb_args = 0; for(;;) { c = *typestr; if (c == '\0') break; typestr++; switch(c) { case 'F': case 'B': case 's': { int ret; char *str; while (isspace(*p)) p++; if (*typestr == '?') { typestr++; if (*p == '\0') { /* no optional string: NULL argument */ str = NULL; goto add_str; } } ret = get_str(buf, sizeof(buf), &p); if (ret < 0) { switch(c) { case 'F': term_printf("%s: filename expected\n", cmdname); break; case 'B': term_printf("%s: block device name expected\n", cmdname); break; default: term_printf("%s: string expected\n", cmdname); break; } goto fail; } str = qemu_malloc(strlen(buf) + 1); strcpy(str, buf); str_allocated[nb_args] = str; add_str: if (nb_args >= MAX_ARGS) { error_args: term_printf("%s: too many arguments\n", cmdname); goto fail; } args[nb_args++] = str; } break; case '/': { int count, format, size; while (isspace(*p)) p++; if (*p == '/') { /* format found */ p++; count = 1; if (isdigit(*p)) { count = 0; while (isdigit(*p)) { count = count * 10 + (*p - '0'); p++; } } size = -1; format = -1; for(;;) { switch(*p) { case 'o': case 'd': case 'u': case 'x': case 'i': case 'c': format = *p++; break; case 'b': size = 1; p++; break; case 'h': size = 2; p++; break; case 'w': size = 4; p++; break; case 'g': case 'L': size = 8; p++; break; default: goto next; } } next: if (*p != '\0' && !isspace(*p)) { term_printf("invalid char in format: '%c'\n", *p); goto fail; } if (format < 0) format = default_fmt_format; if (format != 'i') { /* for 'i', not specifying a size gives -1 as size */ if (size < 0) size = default_fmt_size; } default_fmt_size = size; default_fmt_format = format; } else { count = 1; format = default_fmt_format; if (format != 'i') { size = default_fmt_size; } else { size = -1; } } if (nb_args + 3 > MAX_ARGS) goto error_args; args[nb_args++] = (void*)count; args[nb_args++] = (void*)format; args[nb_args++] = (void*)size; } break; case 'i': { int val; while (isspace(*p)) p++; if (*typestr == '?' || *typestr == '.') { typestr++; if (*typestr == '?') { if (*p == '\0') has_arg = 0; else has_arg = 1; } else { if (*p == '.') { p++; while (isspace(*p)) p++; has_arg = 1; } else { has_arg = 0; } } if (nb_args >= MAX_ARGS) goto error_args; args[nb_args++] = (void *)has_arg; if (!has_arg) { if (nb_args >= MAX_ARGS) goto error_args; val = -1; goto add_num; } } if (get_expr(&val, &p)) goto fail; add_num: if (nb_args >= MAX_ARGS) goto error_args; args[nb_args++] = (void *)val; } break; case '-': { int has_option; /* option */ c = *typestr++; if (c == '\0') goto bad_type; while (isspace(*p)) p++; has_option = 0; if (*p == '-') { p++; if (*p != c) { term_printf("%s: unsupported option -%c\n", cmdname, *p); goto fail; } p++; has_option = 1; } if (nb_args >= MAX_ARGS) goto error_args; args[nb_args++] = (void *)has_option; } break; default: bad_type: term_printf("%s: unknown type '%c'\n", cmdname, c); goto fail; } } /* check that all arguments were parsed */ while (isspace(*p)) p++; if (*p != '\0') { term_printf("%s: extraneous characters at the end of line\n", cmdname); goto fail; } switch(nb_args) { case 0: cmd->handler(); break; case 1: cmd->handler(args[0]); break; case 2: cmd->handler(args[0], args[1]); break; case 3: cmd->handler(args[0], args[1], args[2]); break; case 4: cmd->handler(args[0], args[1], args[2], args[3]); break; case 5: cmd->handler(args[0], args[1], args[2], args[3], args[4]); break; case 6: cmd->handler(args[0], args[1], args[2], args[3], args[4], args[5]); break; default: term_printf("unsupported number of arguments: %d\n", nb_args); goto fail; } fail: for(i = 0; i < MAX_ARGS; i++) qemu_free(str_allocated[i]); return; }


static inline void gen_op_eval_bleu(TCGv dst, TCGv_i32 src) { gen_mov_reg_Z(cpu_tmp0, src); gen_mov_reg_C(dst, src); tcg_gen_or_tl(dst, dst, cpu_tmp0); }


static void usb_host_auto_check(void *unused) { struct USBHostDevice *s; int unconnected = 0; usb_host_scan(NULL, usb_host_auto_scan); QTAILQ_FOREACH(s, &hostdevs, next) { if (s->fd == -1) { unconnected++; } } if (unconnected == 0) { /* nothing to watch */ if (usb_auto_timer) { qemu_del_timer(usb_auto_timer); } return; } if (!usb_auto_timer) { usb_auto_timer = qemu_new_timer(rt_clock, usb_host_auto_check, NULL); if (!usb_auto_timer) { return; } } qemu_mod_timer(usb_auto_timer, qemu_get_clock(rt_clock) + 2000); }


int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv){ int i, t = 0; uint8_t *zero, *last, *cur; JLSState *state; int off = 0, stride = 1, width, shift; zero = av_mallocz(s->picture.linesize[0]); last = zero; cur = s->picture.data[0]; state = av_mallocz(sizeof(JLSState)); /* initialize JPEG-LS state from JPEG parameters */ state->near = near; state->bpp = (s->bits < 2) ? 2 : s->bits; state->maxval = s->maxval; state->T1 = s->t1; state->T2 = s->t2; state->T3 = s->t3; state->reset = s->reset; ff_jpegls_reset_coding_parameters(state, 0); ff_jpegls_init_state(state); if(s->bits <= 8) shift = point_transform + (8 - s->bits); else shift = point_transform + (16 - s->bits); if (s->avctx->debug & FF_DEBUG_PICT_INFO) { av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n", s->width, s->height, state->near, state->maxval, state->T1, state->T2, state->T3, state->reset, state->limit, state->qbpp, state->range); av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan); } if(ilv == 0) { /* separate planes */ stride = (s->nb_components > 1) ? 3 : 1; off = av_clip(s->cur_scan - 1, 0, stride); width = s->width * stride; cur += off; for(i = 0; i < s->height; i++) { if(s->bits <= 8){ ls_decode_line(state, s, last, cur, t, width, stride, off, 8); t = last[0]; }else{ ls_decode_line(state, s, last, cur, t, width, stride, off, 16); t = *((uint16_t*)last); } last = cur; cur += s->picture.linesize[0]; if (s->restart_interval && !--s->restart_count) { align_get_bits(&s->gb); skip_bits(&s->gb, 16); /* skip RSTn */ } } } else if(ilv == 1) { /* line interleaving */ int j; int Rc[3] = {0, 0, 0}; stride = (s->nb_components > 1) ? 3 : 1; memset(cur, 0, s->picture.linesize[0]); width = s->width * stride; for(i = 0; i < s->height; i++) { for(j = 0; j < stride; j++) { ls_decode_line(state, s, last + j, cur + j, Rc[j], width, stride, j, 8); Rc[j] = last[j]; if (s->restart_interval && !--s->restart_count) { align_get_bits(&s->gb); skip_bits(&s->gb, 16); /* skip RSTn */ } } last = cur; cur += s->picture.linesize[0]; } } else if(ilv == 2) { /* sample interleaving */ av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n"); av_free(state); av_free(zero); return -1; } if(shift){ /* we need to do point transform or normalize samples */ int x, w; w = s->width * s->nb_components; if(s->bits <= 8){ uint8_t *src = s->picture.data[0]; for(i = 0; i < s->height; i++){ for(x = off; x < w; x+= stride){ src[x] <<= shift; } src += s->picture.linesize[0]; } }else{ uint16_t *src = (uint16_t*) s->picture.data[0]; for(i = 0; i < s->height; i++){ for(x = 0; x < w; x++){ src[x] <<= shift; } src += s->picture.linesize[0]/2; } } } av_free(state); av_free(zero); return 0; }


void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1, int32_t arg2, int label) { TCGv_i32 t0 = tcg_const_i32(arg2); tcg_gen_brcond_i32(cond, arg1, t0, label); tcg_temp_free_i32(t0); }


void s390x_cpu_do_unaligned_access(CPUState *cs, vaddr addr, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { S390CPU *cpu = S390_CPU(cs); CPUS390XState *env = &cpu->env; if (retaddr) { cpu_restore_state(cs, retaddr); } program_interrupt(env, PGM_SPECIFICATION, ILEN_LATER); }


static void q35_host_get_pci_hole_start(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { Q35PCIHost *s = Q35_HOST_DEVICE(obj); uint32_t value = s->mch.pci_hole.begin; visit_type_uint32(v, name, &value, errp); }


static int kvm_max_vcpus(KVMState *s) { int ret; /* Find number of supported CPUs using the recommended * procedure from the kernel API documentation to cope with * older kernels that may be missing capabilities. */ ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS); if (ret) { return ret; } ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS); if (ret) { return ret; } return 4; }


static int cpu_load_old(QEMUFile *f, void *opaque, int version_id) { PowerPCCPU *cpu = opaque; CPUPPCState *env = &cpu->env; unsigned int i, j; target_ulong sdr1; uint32_t fpscr; target_ulong xer; for (i = 0; i < 32; i++) qemu_get_betls(f, &env->gpr[i]); #if !defined(TARGET_PPC64) for (i = 0; i < 32; i++) qemu_get_betls(f, &env->gprh[i]); #endif qemu_get_betls(f, &env->lr); qemu_get_betls(f, &env->ctr); for (i = 0; i < 8; i++) qemu_get_be32s(f, &env->crf[i]); qemu_get_betls(f, &xer); cpu_write_xer(env, xer); qemu_get_betls(f, &env->reserve_addr); qemu_get_betls(f, &env->msr); for (i = 0; i < 4; i++) qemu_get_betls(f, &env->tgpr[i]); for (i = 0; i < 32; i++) { union { float64 d; uint64_t l; } u; u.l = qemu_get_be64(f); env->fpr[i] = u.d; } qemu_get_be32s(f, &fpscr); env->fpscr = fpscr; qemu_get_sbe32s(f, &env->access_type); #if defined(TARGET_PPC64) qemu_get_betls(f, &env->spr[SPR_ASR]); qemu_get_sbe32s(f, &env->slb_nr); #endif qemu_get_betls(f, &sdr1); for (i = 0; i < 32; i++) qemu_get_betls(f, &env->sr[i]); for (i = 0; i < 2; i++) for (j = 0; j < 8; j++) qemu_get_betls(f, &env->DBAT[i][j]); for (i = 0; i < 2; i++) for (j = 0; j < 8; j++) qemu_get_betls(f, &env->IBAT[i][j]); qemu_get_sbe32s(f, &env->nb_tlb); qemu_get_sbe32s(f, &env->tlb_per_way); qemu_get_sbe32s(f, &env->nb_ways); qemu_get_sbe32s(f, &env->last_way); qemu_get_sbe32s(f, &env->id_tlbs); qemu_get_sbe32s(f, &env->nb_pids); if (env->tlb.tlb6) { // XXX assumes 6xx for (i = 0; i < env->nb_tlb; i++) { qemu_get_betls(f, &env->tlb.tlb6[i].pte0); qemu_get_betls(f, &env->tlb.tlb6[i].pte1); qemu_get_betls(f, &env->tlb.tlb6[i].EPN); } } for (i = 0; i < 4; i++) qemu_get_betls(f, &env->pb[i]); for (i = 0; i < 1024; i++) qemu_get_betls(f, &env->spr[i]); if (!env->external_htab) { ppc_store_sdr1(env, sdr1); } qemu_get_be32s(f, &env->vscr); qemu_get_be64s(f, &env->spe_acc); qemu_get_be32s(f, &env->spe_fscr); qemu_get_betls(f, &env->msr_mask); qemu_get_be32s(f, &env->flags); qemu_get_sbe32s(f, &env->error_code); qemu_get_be32s(f, &env->pending_interrupts); qemu_get_be32s(f, &env->irq_input_state); for (i = 0; i < POWERPC_EXCP_NB; i++) qemu_get_betls(f, &env->excp_vectors[i]); qemu_get_betls(f, &env->excp_prefix); qemu_get_betls(f, &env->ivor_mask); qemu_get_betls(f, &env->ivpr_mask); qemu_get_betls(f, &env->hreset_vector); qemu_get_betls(f, &env->nip); qemu_get_betls(f, &env->hflags); qemu_get_betls(f, &env->hflags_nmsr); qemu_get_sbe32(f); /* Discard unused mmu_idx */ qemu_get_sbe32(f); /* Discard unused power_mode */ /* Recompute mmu indices */ hreg_compute_mem_idx(env); return 0; }


static inline uint32_t get_hwc_address(SM501State *state, int crt) { uint32_t addr = crt ? state->dc_crt_hwc_addr : state->dc_panel_hwc_addr; return (addr & 0x03FFFFF0)/* >> 4*/; }


int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data) { MigrationState *s = current_migration; if (s) s->cancel(s); return 0; }


int cpu_is_bsp(CPUX86State *env) { /* We hard-wire the BSP to the first CPU. */ return env->cpu_index == 0; }


void qerror_report(const char *fmt, ...) { va_list va; QError *qerror; va_start(va, fmt); qerror = qerror_from_info(fmt, &va); va_end(va); if (monitor_cur_is_qmp()) { monitor_set_error(cur_mon, qerror); } else { qerror_print(qerror); QDECREF(qerror); } }


static void change_qscale(MpegEncContext * s, int dquant) { s->qscale += dquant; if (s->qscale < 1) s->qscale = 1; else if (s->qscale > 31) s->qscale = 31; s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; }


void add_boot_device_path(int32_t bootindex, DeviceState *dev, const char *suffix) { FWBootEntry *node, *i; if (bootindex < 0) { return; } assert(dev != NULL || suffix != NULL); node = g_malloc0(sizeof(FWBootEntry)); node->bootindex = bootindex; node->suffix = suffix ? g_strdup(suffix) : NULL; node->dev = dev; QTAILQ_FOREACH(i, &fw_boot_order, link) { if (i->bootindex == bootindex) { fprintf(stderr, "Two devices with same boot index %d\n", bootindex); exit(1); } else if (i->bootindex < bootindex) { continue; } QTAILQ_INSERT_BEFORE(i, node, link); return; } QTAILQ_INSERT_TAIL(&fw_boot_order, node, link); }


QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap) { char *cmdline; struct QOSState *qs = g_malloc(sizeof(QOSState)); cmdline = g_strdup_vprintf(cmdline_fmt, ap); qs->qts = qtest_start(cmdline); qs->ops = ops; qtest_irq_intercept_in(global_qtest, "ioapic"); if (ops && ops->init_allocator) { qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS); } g_free(cmdline); return qs; }


static void gen_dozo(DisasContext *ctx) { int l1 = gen_new_label(); int l2 = gen_new_label(); TCGv t0 = tcg_temp_new(); TCGv t1 = tcg_temp_new(); TCGv t2 = tcg_temp_new(); /* Start with XER OV disabled, the most likely case */ tcg_gen_movi_tl(cpu_ov, 0); tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0); tcg_gen_andc_tl(t1, t1, t2); tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); tcg_gen_movi_tl(cpu_ov, 1); tcg_gen_movi_tl(cpu_so, 1); tcg_gen_br(l2); gen_set_label(l1); tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); gen_set_label(l2); tcg_temp_free(t0); tcg_temp_free(t1); tcg_temp_free(t2); if (unlikely(Rc(ctx->opcode) != 0)) gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); }


static void qdev_prop_cpy(DeviceState *dev, Property *props, void *src) { if (props->info->type == PROP_TYPE_BIT) { bool *defval = src; bit_prop_set(dev, props, *defval); } else { char *dst = qdev_get_prop_ptr(dev, props); memcpy(dst, src, props->info->size); } }


int qemu_cpu_self(void *_env) { CPUState *env = _env; QemuThread this; qemu_thread_self(&this); return qemu_thread_equal(&this, env->thread); }


void pstrcpy_targphys(const char *name, target_phys_addr_t dest, int buf_size, const char *source) { const char *nulp; char *ptr; if (buf_size <= 0) return; nulp = memchr(source, 0, buf_size); if (nulp) { rom_add_blob_fixed(name, source, (nulp - source) + 1, dest); } else { rom_add_blob_fixed(name, source, buf_size, dest); ptr = rom_ptr(dest + buf_size - 1); *ptr = 0; } }


static void ioport_write(void *opaque, target_phys_addr_t addr, uint64_t val, unsigned size) { PCIQXLDevice *d = opaque; uint32_t io_port = addr; qxl_async_io async = QXL_SYNC; #if SPICE_INTERFACE_QXL_MINOR >= 1 uint32_t orig_io_port = io_port; #endif switch (io_port) { case QXL_IO_RESET: case QXL_IO_SET_MODE: case QXL_IO_MEMSLOT_ADD: case QXL_IO_MEMSLOT_DEL: case QXL_IO_CREATE_PRIMARY: case QXL_IO_UPDATE_IRQ: case QXL_IO_LOG: #if SPICE_INTERFACE_QXL_MINOR >= 1 case QXL_IO_MEMSLOT_ADD_ASYNC: case QXL_IO_CREATE_PRIMARY_ASYNC: #endif break; default: if (d->mode != QXL_MODE_VGA) { break; } dprint(d, 1, "%s: unexpected port 0x%x (%s) in vga mode\n", __func__, io_port, io_port_to_string(io_port)); #if SPICE_INTERFACE_QXL_MINOR >= 1 /* be nice to buggy guest drivers */ if (io_port >= QXL_IO_UPDATE_AREA_ASYNC && io_port <= QXL_IO_DESTROY_ALL_SURFACES_ASYNC) { qxl_send_events(d, QXL_INTERRUPT_IO_CMD); } #endif return; } #if SPICE_INTERFACE_QXL_MINOR >= 1 /* we change the io_port to avoid ifdeffery in the main switch */ orig_io_port = io_port; switch (io_port) { case QXL_IO_UPDATE_AREA_ASYNC: io_port = QXL_IO_UPDATE_AREA; goto async_common; case QXL_IO_MEMSLOT_ADD_ASYNC: io_port = QXL_IO_MEMSLOT_ADD; goto async_common; case QXL_IO_CREATE_PRIMARY_ASYNC: io_port = QXL_IO_CREATE_PRIMARY; goto async_common; case QXL_IO_DESTROY_PRIMARY_ASYNC: io_port = QXL_IO_DESTROY_PRIMARY; goto async_common; case QXL_IO_DESTROY_SURFACE_ASYNC: io_port = QXL_IO_DESTROY_SURFACE_WAIT; goto async_common; case QXL_IO_DESTROY_ALL_SURFACES_ASYNC: io_port = QXL_IO_DESTROY_ALL_SURFACES; goto async_common; case QXL_IO_FLUSH_SURFACES_ASYNC: async_common: async = QXL_ASYNC; qemu_mutex_lock(&d->async_lock); if (d->current_async != QXL_UNDEFINED_IO) { qxl_guest_bug(d, "%d async started before last (%d) complete", io_port, d->current_async); qemu_mutex_unlock(&d->async_lock); return; } d->current_async = orig_io_port; qemu_mutex_unlock(&d->async_lock); dprint(d, 2, "start async %d (%"PRId64")\n", io_port, val); break; default: break; } #endif switch (io_port) { case QXL_IO_UPDATE_AREA: { QXLRect update = d->ram->update_area; qxl_spice_update_area(d, d->ram->update_surface, &update, NULL, 0, 0, async); break; } case QXL_IO_NOTIFY_CMD: qemu_spice_wakeup(&d->ssd); break; case QXL_IO_NOTIFY_CURSOR: qemu_spice_wakeup(&d->ssd); break; case QXL_IO_UPDATE_IRQ: qxl_update_irq(d); break; case QXL_IO_NOTIFY_OOM: if (!SPICE_RING_IS_EMPTY(&d->ram->release_ring)) { break; } d->oom_running = 1; qxl_spice_oom(d); d->oom_running = 0; break; case QXL_IO_SET_MODE: dprint(d, 1, "QXL_SET_MODE %d\n", (int)val); qxl_set_mode(d, val, 0); break; case QXL_IO_LOG: if (d->guestdebug) { fprintf(stderr, "qxl/guest-%d: %" PRId64 ": %s", d->id, qemu_get_clock_ns(vm_clock), d->ram->log_buf); } break; case QXL_IO_RESET: dprint(d, 1, "QXL_IO_RESET\n"); qxl_hard_reset(d, 0); break; case QXL_IO_MEMSLOT_ADD: if (val >= NUM_MEMSLOTS) { qxl_guest_bug(d, "QXL_IO_MEMSLOT_ADD: val out of range"); break; } if (d->guest_slots[val].active) { qxl_guest_bug(d, "QXL_IO_MEMSLOT_ADD: memory slot already active"); break; } d->guest_slots[val].slot = d->ram->mem_slot; qxl_add_memslot(d, val, 0, async); break; case QXL_IO_MEMSLOT_DEL: if (val >= NUM_MEMSLOTS) { qxl_guest_bug(d, "QXL_IO_MEMSLOT_DEL: val out of range"); break; } qxl_del_memslot(d, val); break; case QXL_IO_CREATE_PRIMARY: if (val != 0) { qxl_guest_bug(d, "QXL_IO_CREATE_PRIMARY (async=%d): val != 0", async); goto cancel_async; } dprint(d, 1, "QXL_IO_CREATE_PRIMARY async=%d\n", async); d->guest_primary.surface = d->ram->create_surface; qxl_create_guest_primary(d, 0, async); break; case QXL_IO_DESTROY_PRIMARY: if (val != 0) { qxl_guest_bug(d, "QXL_IO_DESTROY_PRIMARY (async=%d): val != 0", async); goto cancel_async; } dprint(d, 1, "QXL_IO_DESTROY_PRIMARY (async=%d) (%s)\n", async, qxl_mode_to_string(d->mode)); if (!qxl_destroy_primary(d, async)) { dprint(d, 1, "QXL_IO_DESTROY_PRIMARY_ASYNC in %s, ignored\n", qxl_mode_to_string(d->mode)); goto cancel_async; } break; case QXL_IO_DESTROY_SURFACE_WAIT: if (val >= NUM_SURFACES) { qxl_guest_bug(d, "QXL_IO_DESTROY_SURFACE (async=%d):" "%d >= NUM_SURFACES", async, val); goto cancel_async; } qxl_spice_destroy_surface_wait(d, val, async); break; #if SPICE_INTERFACE_QXL_MINOR >= 1 case QXL_IO_FLUSH_RELEASE: { QXLReleaseRing *ring = &d->ram->release_ring; if (ring->prod - ring->cons + 1 == ring->num_items) { fprintf(stderr, "ERROR: no flush, full release ring [p%d,%dc]\n", ring->prod, ring->cons); } qxl_push_free_res(d, 1 /* flush */); dprint(d, 1, "QXL_IO_FLUSH_RELEASE exit (%s, s#=%d, res#=%d,%p)\n", qxl_mode_to_string(d->mode), d->guest_surfaces.count, d->num_free_res, d->last_release); break; } case QXL_IO_FLUSH_SURFACES_ASYNC: dprint(d, 1, "QXL_IO_FLUSH_SURFACES_ASYNC" " (%"PRId64") (%s, s#=%d, res#=%d)\n", val, qxl_mode_to_string(d->mode), d->guest_surfaces.count, d->num_free_res); qxl_spice_flush_surfaces_async(d); break; #endif case QXL_IO_DESTROY_ALL_SURFACES: d->mode = QXL_MODE_UNDEFINED; qxl_spice_destroy_surfaces(d, async); break; default: fprintf(stderr, "%s: ioport=0x%x, abort()\n", __FUNCTION__, io_port); abort(); } return; cancel_async: #if SPICE_INTERFACE_QXL_MINOR >= 1 if (async) { qxl_send_events(d, QXL_INTERRUPT_IO_CMD); qemu_mutex_lock(&d->async_lock); d->current_async = QXL_UNDEFINED_IO; qemu_mutex_unlock(&d->async_lock); } #else return; #endif }


void timer_mod_anticipate(QEMUTimer *ts, int64_t expire_time) { timer_mod_anticipate_ns(ts, expire_time * ts->scale); }


static void musicpal_init(ram_addr_t ram_size, const char *boot_device, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { CPUState *env; qemu_irq *cpu_pic; qemu_irq pic[32]; DeviceState *dev; DeviceState *i2c_dev; DeviceState *lcd_dev; DeviceState *key_dev; #ifdef HAS_AUDIO DeviceState *wm8750_dev; SysBusDevice *s; #endif i2c_bus *i2c; int i; unsigned long flash_size; DriveInfo *dinfo; ram_addr_t sram_off; if (!cpu_model) { cpu_model = "arm926"; } env = cpu_init(cpu_model); if (!env) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } cpu_pic = arm_pic_init_cpu(env); /* For now we use a fixed - the original - RAM size */ cpu_register_physical_memory(0, MP_RAM_DEFAULT_SIZE, qemu_ram_alloc(MP_RAM_DEFAULT_SIZE)); sram_off = qemu_ram_alloc(MP_SRAM_SIZE); cpu_register_physical_memory(MP_SRAM_BASE, MP_SRAM_SIZE, sram_off); dev = sysbus_create_simple("mv88w8618_pic", MP_PIC_BASE, cpu_pic[ARM_PIC_CPU_IRQ]); for (i = 0; i < 32; i++) { pic[i] = qdev_get_gpio_in(dev, i); } sysbus_create_varargs("mv88w8618_pit", MP_PIT_BASE, pic[MP_TIMER1_IRQ], pic[MP_TIMER2_IRQ], pic[MP_TIMER3_IRQ], pic[MP_TIMER4_IRQ], NULL); if (serial_hds[0]) { #ifdef TARGET_WORDS_BIGENDIAN serial_mm_init(MP_UART1_BASE, 2, pic[MP_UART1_IRQ], 1825000, serial_hds[0], 1, 1); #else serial_mm_init(MP_UART1_BASE, 2, pic[MP_UART1_IRQ], 1825000, serial_hds[0], 1, 0); #endif } if (serial_hds[1]) { #ifdef TARGET_WORDS_BIGENDIAN serial_mm_init(MP_UART2_BASE, 2, pic[MP_UART2_IRQ], 1825000, serial_hds[1], 1, 1); #else serial_mm_init(MP_UART2_BASE, 2, pic[MP_UART2_IRQ], 1825000, serial_hds[1], 1, 0); #endif } /* Register flash */ dinfo = drive_get(IF_PFLASH, 0, 0); if (dinfo) { flash_size = bdrv_getlength(dinfo->bdrv); if (flash_size != 8*1024*1024 && flash_size != 16*1024*1024 && flash_size != 32*1024*1024) { fprintf(stderr, "Invalid flash image size\n"); exit(1); } /* * The original U-Boot accesses the flash at 0xFE000000 instead of * 0xFF800000 (if there is 8 MB flash). So remap flash access if the * image is smaller than 32 MB. */ #ifdef TARGET_WORDS_BIGENDIAN pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(flash_size), dinfo->bdrv, 0x10000, (flash_size + 0xffff) >> 16, MP_FLASH_SIZE_MAX / flash_size, 2, 0x00BF, 0x236D, 0x0000, 0x0000, 0x5555, 0x2AAA, 1); #else pflash_cfi02_register(0-MP_FLASH_SIZE_MAX, qemu_ram_alloc(flash_size), dinfo->bdrv, 0x10000, (flash_size + 0xffff) >> 16, MP_FLASH_SIZE_MAX / flash_size, 2, 0x00BF, 0x236D, 0x0000, 0x0000, 0x5555, 0x2AAA, 0); #endif } sysbus_create_simple("mv88w8618_flashcfg", MP_FLASHCFG_BASE, NULL); qemu_check_nic_model(&nd_table[0], "mv88w8618"); dev = qdev_create(NULL, "mv88w8618_eth"); qdev_set_nic_properties(dev, &nd_table[0]); qdev_init_nofail(dev); sysbus_mmio_map(sysbus_from_qdev(dev), 0, MP_ETH_BASE); sysbus_connect_irq(sysbus_from_qdev(dev), 0, pic[MP_ETH_IRQ]); sysbus_create_simple("mv88w8618_wlan", MP_WLAN_BASE, NULL); musicpal_misc_init(); dev = sysbus_create_simple("musicpal_gpio", MP_GPIO_BASE, pic[MP_GPIO_IRQ]); i2c_dev = sysbus_create_simple("gpio_i2c", 0, NULL); i2c = (i2c_bus *)qdev_get_child_bus(i2c_dev, "i2c"); lcd_dev = sysbus_create_simple("musicpal_lcd", MP_LCD_BASE, NULL); key_dev = sysbus_create_simple("musicpal_key", 0, NULL); /* I2C read data */ qdev_connect_gpio_out(i2c_dev, 0, qdev_get_gpio_in(dev, MP_GPIO_I2C_DATA_BIT)); /* I2C data */ qdev_connect_gpio_out(dev, 3, qdev_get_gpio_in(i2c_dev, 0)); /* I2C clock */ qdev_connect_gpio_out(dev, 4, qdev_get_gpio_in(i2c_dev, 1)); for (i = 0; i < 3; i++) { qdev_connect_gpio_out(dev, i, qdev_get_gpio_in(lcd_dev, i)); } for (i = 0; i < 4; i++) { qdev_connect_gpio_out(key_dev, i, qdev_get_gpio_in(dev, i + 8)); } for (i = 4; i < 8; i++) { qdev_connect_gpio_out(key_dev, i, qdev_get_gpio_in(dev, i + 15)); } #ifdef HAS_AUDIO wm8750_dev = i2c_create_slave(i2c, "wm8750", MP_WM_ADDR); dev = qdev_create(NULL, "mv88w8618_audio"); s = sysbus_from_qdev(dev); qdev_prop_set_ptr(dev, "wm8750", wm8750_dev); qdev_init_nofail(dev); sysbus_mmio_map(s, 0, MP_AUDIO_BASE); sysbus_connect_irq(s, 0, pic[MP_AUDIO_IRQ]); #endif musicpal_binfo.ram_size = MP_RAM_DEFAULT_SIZE; musicpal_binfo.kernel_filename = kernel_filename; musicpal_binfo.kernel_cmdline = kernel_cmdline; musicpal_binfo.initrd_filename = initrd_filename; arm_load_kernel(env, &musicpal_binfo); }


static void vscsi_inquiry_no_target(VSCSIState *s, vscsi_req *req) { uint8_t *cdb = req->iu.srp.cmd.cdb; uint8_t resp_data[36]; int rc, len, alen; /* We dont do EVPD. Also check that page_code is 0 */ if ((cdb[1] & 0x01) || (cdb[1] & 0x01) || cdb[2] != 0) { /* Send INVALID FIELD IN CDB */ vscsi_makeup_sense(s, req, ILLEGAL_REQUEST, 0x24, 0); vscsi_send_rsp(s, req, CHECK_CONDITION, 0, 0); return; } alen = cdb[3]; alen = (alen << 8) | cdb[4]; len = MIN(alen, 36); /* Fake up inquiry using PQ=3 */ memset(resp_data, 0, 36); resp_data[0] = 0x7f; /* Not capable of supporting a device here */ resp_data[2] = 0x06; /* SPS-4 */ resp_data[3] = 0x02; /* Resp data format */ resp_data[4] = 36 - 5; /* Additional length */ resp_data[7] = 0x10; /* Sync transfers */ memcpy(&resp_data[16], "QEMU EMPTY ", 16); memcpy(&resp_data[8], "QEMU ", 8); req->writing = 0; vscsi_preprocess_desc(req); rc = vscsi_srp_transfer_data(s, req, 0, resp_data, len); if (rc < 0) { vscsi_makeup_sense(s, req, HARDWARE_ERROR, 0, 0); vscsi_send_rsp(s, req, CHECK_CONDITION, 0, 0); } else { vscsi_send_rsp(s, req, 0, 36 - rc, 0); } }


static SocketAddress *unix_build_address(const char *path) { SocketAddress *saddr; saddr = g_new0(SocketAddress, 1); saddr->type = SOCKET_ADDRESS_KIND_UNIX; saddr->u.q_unix.data = g_new0(UnixSocketAddress, 1); saddr->u.q_unix.data->path = g_strdup(path); return saddr; }


void net_cleanup(void) { #if !defined(_WIN32) VLANState *vlan; /* close network clients */ for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { VLANClientState *vc; for(vc = vlan->first_client; vc != NULL; vc = vc->next) { if (vc->fd_read == tap_receive) { TAPState *s = vc->opaque; if (s->down_script[0]) launch_script(s->down_script, s->down_script_arg, s->fd); } #if defined(CONFIG_VDE) if (vc->fd_read == vde_from_qemu) { VDEState *s = vc->opaque; vde_close(s->vde); } #endif } } #endif }


void qmp_transaction(TransactionActionList *dev_list, Error **errp) { TransactionActionList *dev_entry = dev_list; BlkTransactionState *state, *next; Error *local_err = NULL; QSIMPLEQ_HEAD(snap_bdrv_states, BlkTransactionState) snap_bdrv_states; QSIMPLEQ_INIT(&snap_bdrv_states); /* drain all i/o before any snapshots */ bdrv_drain_all(); /* We don't do anything in this loop that commits us to the snapshot */ while (NULL != dev_entry) { TransactionAction *dev_info = NULL; const BdrvActionOps *ops; dev_info = dev_entry->value; dev_entry = dev_entry->next; assert(dev_info->kind < ARRAY_SIZE(actions)); ops = &actions[dev_info->kind]; state = g_malloc0(ops->instance_size); state->ops = ops; state->action = dev_info; QSIMPLEQ_INSERT_TAIL(&snap_bdrv_states, state, entry); state->ops->prepare(state, &local_err); if (error_is_set(&local_err)) { error_propagate(errp, local_err); goto delete_and_fail; } } QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) { if (state->ops->commit) { state->ops->commit(state); } } /* success */ goto exit; delete_and_fail: /* * failure, and it is all-or-none; abandon each new bs, and keep using * the original bs for all images */ QSIMPLEQ_FOREACH(state, &snap_bdrv_states, entry) { if (state->ops->abort) { state->ops->abort(state); } } exit: QSIMPLEQ_FOREACH_SAFE(state, &snap_bdrv_states, entry, next) { if (state->ops->clean) { state->ops->clean(state); } g_free(state); } }


BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque) { BlockDriver *drv = bs->drv; BlockDriverAIOCB *ret; if (!drv) return NULL; if (bdrv_rd_badreq_sectors(bs, sector_num, nb_sectors)) return NULL; /* XXX: we assume that nb_sectors == 0 is suppored by the async read */ if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) { memcpy(buf, bs->boot_sector_data, 512); sector_num++; nb_sectors--; buf += 512; } ret = drv->bdrv_aio_read(bs, sector_num, buf, nb_sectors, cb, opaque); if (ret) { /* Update stats even though technically transfer has not happened. */ bs->rd_bytes += (unsigned) nb_sectors * SECTOR_SIZE; bs->rd_ops ++; } return ret; }


GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count, int64_t count, Error **errp) { GuestFileRead *read_data = NULL; guchar *buf; HANDLE fh; bool is_ok; DWORD read_count; GuestFileHandle *gfh = guest_file_handle_find(handle, errp); if (!gfh) { return NULL; } if (!has_count) { count = QGA_READ_COUNT_DEFAULT; } else if (count < 0) { error_setg(errp, "value '%" PRId64 "' is invalid for argument count", count); return NULL; } fh = gfh->fh; buf = g_malloc0(count+1); is_ok = ReadFile(fh, buf, count, &read_count, NULL); if (!is_ok) { error_setg_win32(errp, GetLastError(), "failed to read file"); slog("guest-file-read failed, handle %" PRId64, handle); } else { buf[read_count] = 0; read_data = g_malloc0(sizeof(GuestFileRead)); read_data->count = (size_t)read_count; read_data->eof = read_count == 0; if (read_count != 0) { read_data->buf_b64 = g_base64_encode(buf, read_count); } } g_free(buf); return read_data; }


void av_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den) { unsigned int gcd= av_gcd(pts_num, pts_den); s->pts_wrap_bits = pts_wrap_bits; s->time_base.num = pts_num/gcd; s->time_base.den = pts_den/gcd; if(gcd>1) av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from timebase\n", s->index, gcd); }


static int msvideo1_decode_init(AVCodecContext *avctx) { Msvideo1Context *s = avctx->priv_data; s->avctx = avctx; /* figure out the colorspace based on the presence of a palette */ if (s->avctx->palctrl) { s->mode_8bit = 1; avctx->pix_fmt = PIX_FMT_PAL8; } else { s->mode_8bit = 0; avctx->pix_fmt = PIX_FMT_RGB555; } dsputil_init(&s->dsp, avctx); s->frame.data[0] = NULL; return 0; }


static void convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], const uint16_t *quant_matrix, int bias, int qmin, int qmax) { int qscale; for(qscale=qmin; qscale<=qmax; qscale++){ int i; if (dsp->fdct == ff_jpeg_fdct_islow #ifdef FAAN_POSTSCALE || dsp->fdct == ff_faandct #endif ) { for(i=0;i<64;i++) { const int j= dsp->idct_permutation[i]; /* 16 <= qscale * quant_matrix[i] <= 7905 */ /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); } } else if (dsp->fdct == fdct_ifast #ifndef FAAN_POSTSCALE || dsp->fdct == ff_faandct #endif ) { for(i=0;i<64;i++) { const int j= dsp->idct_permutation[i]; /* 16 <= qscale * quant_matrix[i] <= 7905 */ /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ qmat[qscale][i] = (int)((uint64_t_C(1) << (QMAT_SHIFT + 14)) / (aanscales[i] * qscale * quant_matrix[j])); } } else { for(i=0;i<64;i++) { const int j= dsp->idct_permutation[i]; /* We can safely suppose that 16 <= quant_matrix[i] <= 255 So 16 <= qscale * quant_matrix[i] <= 7905 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 */ qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); // qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); } } } }


static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size, const AVSubtitle *h) { uint8_t *q, *qq; int object_id; int offset1[20], offset2[20]; int i, imax, color, alpha, rects = h->num_rects; unsigned long hmax; unsigned long hist[256]; int cmap[256]; if (rects == 0 || h->rects == NULL) return -1; if (rects > 20) rects = 20; // analyze bitmaps, compress to 4 colors for (i=0; i<256; ++i) { hist[i] = 0; cmap[i] = 0; } for (object_id = 0; object_id < rects; object_id++) for (i=0; i<h->rects[object_id]->w*h->rects[object_id]->h; ++i) { color = h->rects[object_id]->pict.data[0][i]; // only count non-transparent pixels alpha = ((uint32_t*)h->rects[object_id]->pict.data[1])[color] >> 24; hist[color] += alpha; } for (color=3;; --color) { hmax = 0; imax = 0; for (i=0; i<256; ++i) if (hist[i] > hmax) { imax = i; hmax = hist[i]; } if (hmax == 0) break; if (color == 0) color = 3; av_log(NULL, AV_LOG_DEBUG, "dvd_subtitle hist[%d]=%ld -> col %d\n", imax, hist[imax], color); cmap[imax] = color; hist[imax] = 0; } // encode data block q = outbuf + 4; for (object_id = 0; object_id < rects; object_id++) { offset1[object_id] = q - outbuf; // worst case memory requirement: 1 nibble per pixel.. if ((q - outbuf) + h->rects[object_id]->w*h->rects[object_id]->h/2 + 17*rects + 21 > outbuf_size) { av_log(NULL, AV_LOG_ERROR, "dvd_subtitle too big\n"); return -1; } dvd_encode_rle(&q, h->rects[object_id]->pict.data[0], h->rects[object_id]->w*2, h->rects[object_id]->w, h->rects[object_id]->h >> 1, cmap); offset2[object_id] = q - outbuf; dvd_encode_rle(&q, h->rects[object_id]->pict.data[0] + h->rects[object_id]->w, h->rects[object_id]->w*2, h->rects[object_id]->w, h->rects[object_id]->h >> 1, cmap); } // set data packet size qq = outbuf + 2; bytestream_put_be16(&qq, q - outbuf); // send start display command bytestream_put_be16(&q, (h->start_display_time*90) >> 10); bytestream_put_be16(&q, (q - outbuf) /*- 2 */ + 8 + 12*rects + 2); *q++ = 0x03; // palette - 4 nibbles *q++ = 0x03; *q++ = 0x7f; *q++ = 0x04; // alpha - 4 nibbles *q++ = 0xf0; *q++ = 0x00; //*q++ = 0x0f; *q++ = 0xff; // XXX not sure if more than one rect can really be encoded.. // 12 bytes per rect for (object_id = 0; object_id < rects; object_id++) { int x2 = h->rects[object_id]->x + h->rects[object_id]->w - 1; int y2 = h->rects[object_id]->y + h->rects[object_id]->h - 1; *q++ = 0x05; // x1 x2 -> 6 nibbles *q++ = h->rects[object_id]->x >> 4; *q++ = (h->rects[object_id]->x << 4) | ((x2 >> 8) & 0xf); *q++ = x2; // y1 y2 -> 6 nibbles *q++ = h->rects[object_id]->y >> 4; *q++ = (h->rects[object_id]->y << 4) | ((y2 >> 8) & 0xf); *q++ = y2; *q++ = 0x06; // offset1, offset2 bytestream_put_be16(&q, offset1[object_id]); bytestream_put_be16(&q, offset2[object_id]); } *q++ = 0x01; // start command *q++ = 0xff; // terminating command // send stop display command last bytestream_put_be16(&q, (h->end_display_time*90) >> 10); bytestream_put_be16(&q, (q - outbuf) - 2 /*+ 4*/); *q++ = 0x02; // set end *q++ = 0xff; // terminating command qq = outbuf; bytestream_put_be16(&qq, q - outbuf); av_log(NULL, AV_LOG_DEBUG, "subtitle_packet size=%td\n", q - outbuf); return q - outbuf; }


bool io_mem_write(MemoryRegion *mr, hwaddr addr, uint64_t val, unsigned size) { return memory_region_dispatch_write(mr, addr, val, size); }


static int bit_allocation(IMCContext *q, IMCChannel *chctx, int stream_format_code, int freebits, int flag) { int i, j; const float limit = -1.e20; float highest = 0.0; int indx; int t1 = 0; int t2 = 1; float summa = 0.0; int iacc = 0; int summer = 0; int rres, cwlen; float lowest = 1.e10; int low_indx = 0; float workT[32]; int flg; int found_indx = 0; for (i = 0; i < BANDS; i++) highest = FFMAX(highest, chctx->flcoeffs1[i]); for (i = 0; i < BANDS - 1; i++) chctx->flcoeffs4[i] = chctx->flcoeffs3[i] - log2f(chctx->flcoeffs5[i]); chctx->flcoeffs4[BANDS - 1] = limit; highest = highest * 0.25; for (i = 0; i < BANDS; i++) { indx = -1; if ((band_tab[i + 1] - band_tab[i]) == chctx->bandWidthT[i]) indx = 0; if ((band_tab[i + 1] - band_tab[i]) > chctx->bandWidthT[i]) indx = 1; if (((band_tab[i + 1] - band_tab[i]) / 2) >= chctx->bandWidthT[i]) indx = 2; if (indx == -1) chctx->flcoeffs4[i] += xTab[(indx * 2 + (chctx->flcoeffs1[i] < highest)) * 2 + flag]; } if (stream_format_code & 0x2) { chctx->flcoeffs4[0] = limit; chctx->flcoeffs4[1] = limit; chctx->flcoeffs4[2] = limit; chctx->flcoeffs4[3] = limit; } for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS - 1; i++) { iacc += chctx->bandWidthT[i]; summa += chctx->bandWidthT[i] * chctx->flcoeffs4[i]; } chctx->bandWidthT[BANDS - 1] = 0; summa = (summa * 0.5 - freebits) / iacc; for (i = 0; i < BANDS / 2; i++) { rres = summer - freebits; if ((rres >= -8) && (rres <= 8)) break; summer = 0; iacc = 0; for (j = (stream_format_code & 0x2) ? 4 : 0; j < BANDS; j++) { cwlen = av_clipf(((chctx->flcoeffs4[j] * 0.5) - summa + 0.5), 0, 6); chctx->bitsBandT[j] = cwlen; summer += chctx->bandWidthT[j] * cwlen; if (cwlen > 0) iacc += chctx->bandWidthT[j]; } flg = t2; t2 = 1; if (freebits < summer) t2 = -1; if (i == 0) flg = t2; if (flg != t2) t1++; summa = (float)(summer - freebits) / ((t1 + 1) * iacc) + summa; } for (i = (stream_format_code & 0x2) ? 4 : 0; i < BANDS; i++) { for (j = band_tab[i]; j < band_tab[i + 1]; j++) chctx->CWlengthT[j] = chctx->bitsBandT[i]; } if (freebits > summer) { for (i = 0; i < BANDS; i++) { workT[i] = (chctx->bitsBandT[i] == 6) ? -1.e20 : (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] - 0.415); } highest = 0.0; do { if (highest <= -1.e20) break; found_indx = 0; highest = -1.e20; for (i = 0; i < BANDS; i++) { if (workT[i] > highest) { highest = workT[i]; found_indx = i; } } if (highest > -1.e20) { workT[found_indx] -= 2.0; if (++chctx->bitsBandT[found_indx] == 6) workT[found_indx] = -1.e20; for (j = band_tab[found_indx]; j < band_tab[found_indx + 1] && (freebits > summer); j++) { chctx->CWlengthT[j]++; summer++; } } } while (freebits > summer); } if (freebits < summer) { for (i = 0; i < BANDS; i++) { workT[i] = chctx->bitsBandT[i] ? (chctx->bitsBandT[i] * -2 + chctx->flcoeffs4[i] + 1.585) : 1.e20; } if (stream_format_code & 0x2) { workT[0] = 1.e20; workT[1] = 1.e20; workT[2] = 1.e20; workT[3] = 1.e20; } while (freebits < summer) { lowest = 1.e10; low_indx = 0; for (i = 0; i < BANDS; i++) { if (workT[i] < lowest) { lowest = workT[i]; low_indx = i; } } // if (lowest >= 1.e10) // break; workT[low_indx] = lowest + 2.0; if (!--chctx->bitsBandT[low_indx]) workT[low_indx] = 1.e20; for (j = band_tab[low_indx]; j < band_tab[low_indx+1] && (freebits < summer); j++) { if (chctx->CWlengthT[j] > 0) { chctx->CWlengthT[j]--; summer--; } } } } return 0; }


static int sox_read_header(AVFormatContext *s) { AVIOContext *pb = s->pb; unsigned header_size, comment_size; double sample_rate, sample_rate_frac; AVStream *st; st = avformat_new_stream(s, NULL); if (!st) return AVERROR(ENOMEM); st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; if (avio_rl32(pb) == SOX_TAG) { st->codecpar->codec_id = AV_CODEC_ID_PCM_S32LE; header_size = avio_rl32(pb); avio_skip(pb, 8); /* sample count */ sample_rate = av_int2double(avio_rl64(pb)); st->codecpar->channels = avio_rl32(pb); comment_size = avio_rl32(pb); } else { st->codecpar->codec_id = AV_CODEC_ID_PCM_S32BE; header_size = avio_rb32(pb); avio_skip(pb, 8); /* sample count */ sample_rate = av_int2double(avio_rb64(pb)); st->codecpar->channels = avio_rb32(pb); comment_size = avio_rb32(pb); } if (comment_size > 0xFFFFFFFFU - SOX_FIXED_HDR - 4U) { av_log(s, AV_LOG_ERROR, "invalid comment size (%u)\n", comment_size); return AVERROR_INVALIDDATA; } if (sample_rate <= 0 || sample_rate > INT_MAX) { av_log(s, AV_LOG_ERROR, "invalid sample rate (%f)\n", sample_rate); return AVERROR_INVALIDDATA; } sample_rate_frac = sample_rate - floor(sample_rate); if (sample_rate_frac) av_log(s, AV_LOG_WARNING, "truncating fractional part of sample rate (%f)\n", sample_rate_frac); if ((header_size + 4) & 7 || header_size < SOX_FIXED_HDR + comment_size || st->codecpar->channels > 65535) /* Reserve top 16 bits */ { av_log(s, AV_LOG_ERROR, "invalid header\n"); return AVERROR_INVALIDDATA; } if (comment_size && comment_size < UINT_MAX) { char *comment = av_malloc(comment_size+1); if(!comment) return AVERROR(ENOMEM); if (avio_read(pb, comment, comment_size) != comment_size) { av_freep(&comment); return AVERROR(EIO); } comment[comment_size] = 0; av_dict_set(&s->metadata, "comment", comment, AV_DICT_DONT_STRDUP_VAL); } avio_skip(pb, header_size - SOX_FIXED_HDR - comment_size); st->codecpar->sample_rate = sample_rate; st->codecpar->bits_per_coded_sample = 32; st->codecpar->bit_rate = st->codecpar->sample_rate * st->codecpar->bits_per_coded_sample * st->codecpar->channels; st->codecpar->block_align = st->codecpar->bits_per_coded_sample * st->codecpar->channels / 8; avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); return 0; }


static void gen_swa(DisasContext *dc, TCGv rb, TCGv ra, int32_t ofs) { TCGv ea, val; TCGLabel *lab_fail, *lab_done; ea = tcg_temp_new(); tcg_gen_addi_tl(ea, ra, ofs); lab_fail = gen_new_label(); lab_done = gen_new_label(); tcg_gen_brcond_tl(TCG_COND_NE, ea, cpu_lock_addr, lab_fail); tcg_temp_free(ea); val = tcg_temp_new(); tcg_gen_atomic_cmpxchg_tl(val, cpu_lock_addr, cpu_lock_value, rb, dc->mem_idx, MO_TEUL); tcg_gen_setcond_tl(TCG_COND_EQ, cpu_sr_f, val, cpu_lock_value); tcg_temp_free(val); tcg_gen_br(lab_done); gen_set_label(lab_fail); tcg_gen_movi_tl(cpu_sr_f, 0); gen_set_label(lab_done); tcg_gen_movi_tl(cpu_lock_addr, -1); }


static uint32_t get_cmd(ESPState *s, uint8_t *buf, uint8_t buflen) { uint32_t dmalen; int target; target = s->wregs[ESP_WBUSID] & BUSID_DID; if (s->dma) { dmalen = s->rregs[ESP_TCLO]; dmalen |= s->rregs[ESP_TCMID] << 8; dmalen |= s->rregs[ESP_TCHI] << 16; if (dmalen > buflen) { s->dma_memory_read(s->dma_opaque, buf, dmalen); } else { dmalen = s->ti_size; memcpy(buf, s->ti_buf, dmalen); buf[0] = buf[2] >> 5; trace_esp_get_cmd(dmalen, target); s->ti_size = 0; s->ti_rptr = 0; s->ti_wptr = 0; if (s->current_req) { /* Started a new command before the old one finished. Cancel it. */ scsi_req_cancel(s->current_req); s->async_len = 0; s->current_dev = scsi_device_find(&s->bus, 0, target, 0); if (!s->current_dev) { // No such drive s->rregs[ESP_RSTAT] = 0; s->rregs[ESP_RINTR] = INTR_DC; s->rregs[ESP_RSEQ] = SEQ_0; esp_raise_irq(s); return dmalen;


static void migration_bitmap_sync_range(ram_addr_t start, ram_addr_t length) { unsigned long *bitmap; bitmap = atomic_rcu_read(&migration_bitmap); migration_dirty_pages += cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length); }


static int decode_frame_png(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { PNGDecContext *const s = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AVFrame *p; int64_t sig; int ret; ff_thread_release_buffer(avctx, &s->last_picture); FFSWAP(ThreadFrame, s->picture, s->last_picture); p = s->picture.f; bytestream2_init(&s->gb, buf, buf_size); /* check signature */ sig = bytestream2_get_be64(&s->gb); if (sig != PNGSIG && sig != MNGSIG) { av_log(avctx, AV_LOG_ERROR, "Invalid PNG signature 0x%08"PRIX64".\n", sig); return AVERROR_INVALIDDATA; } s->y = s->has_trns = 0; s->hdr_state = 0; s->pic_state = 0; /* init the zlib */ s->zstream.zalloc = ff_png_zalloc; s->zstream.zfree = ff_png_zfree; s->zstream.opaque = NULL; ret = inflateInit(&s->zstream); if (ret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "inflateInit returned error %d\n", ret); return AVERROR_EXTERNAL; } if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0) goto the_end; if (avctx->skip_frame == AVDISCARD_ALL) { *got_frame = 0; ret = bytestream2_tell(&s->gb); goto the_end; } if ((ret = av_frame_ref(data, s->picture.f)) < 0) return ret; *got_frame = 1; ret = bytestream2_tell(&s->gb); the_end: inflateEnd(&s->zstream); s->crow_buf = NULL; return ret; }


static int ass_decode_frame(AVCodecContext *avctx, void *data, int *got_sub_ptr, AVPacket *avpkt) { const char *ptr = avpkt->data; int len, size = avpkt->size; ff_ass_init(data); while (size > 0) { len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1); if (len < 0) return len; ptr += len; size -= len; } *got_sub_ptr = avpkt->size > 0; return avpkt->size; }


int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt) { AVCodecInternal *avci = avctx->internal; int ret = 0; *got_frame_ptr = 0; if (!avpkt->data && avpkt->size) { av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n"); return AVERROR(EINVAL); } if (!avctx->codec) return AVERROR(EINVAL); if (avctx->codec->type != AVMEDIA_TYPE_AUDIO) { av_log(avctx, AV_LOG_ERROR, "Invalid media type for audio\n"); return AVERROR(EINVAL); } av_frame_unref(frame); if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) { uint8_t *side; int side_size; uint32_t discard_padding = 0; // copy to ensure we do not change avpkt AVPacket tmp = *avpkt; int did_split = av_packet_split_side_data(&tmp); ret = apply_param_change(avctx, &tmp); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error applying parameter changes.\n"); if (avctx->err_recognition & AV_EF_EXPLODE) goto fail; } avctx->internal->pkt = &tmp; if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) ret = ff_thread_decode_frame(avctx, frame, got_frame_ptr, &tmp); else { ret = avctx->codec->decode(avctx, frame, got_frame_ptr, &tmp); frame->pkt_dts = avpkt->dts; } if (ret >= 0 && *got_frame_ptr) { add_metadata_from_side_data(avctx, frame); avctx->frame_number++; av_frame_set_best_effort_timestamp(frame, guess_correct_pts(avctx, frame->pkt_pts, frame->pkt_dts)); if (frame->format == AV_SAMPLE_FMT_NONE) frame->format = avctx->sample_fmt; if (!frame->channel_layout) frame->channel_layout = avctx->channel_layout; if (!av_frame_get_channels(frame)) av_frame_set_channels(frame, avctx->channels); if (!frame->sample_rate) frame->sample_rate = avctx->sample_rate; } side= av_packet_get_side_data(avctx->internal->pkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size); if(side && side_size>=10) { avctx->internal->skip_samples = AV_RL32(side); av_log(avctx, AV_LOG_DEBUG, "skip %d samples due to side data\n", avctx->internal->skip_samples); discard_padding = AV_RL32(side + 4); } if (avctx->internal->skip_samples && *got_frame_ptr) { if(frame->nb_samples <= avctx->internal->skip_samples){ *got_frame_ptr = 0; avctx->internal->skip_samples -= frame->nb_samples; av_log(avctx, AV_LOG_DEBUG, "skip whole frame, skip left: %d\n", avctx->internal->skip_samples); } else { av_samples_copy(frame->extended_data, frame->extended_data, 0, avctx->internal->skip_samples, frame->nb_samples - avctx->internal->skip_samples, avctx->channels, frame->format); if(avctx->pkt_timebase.num && avctx->sample_rate) { int64_t diff_ts = av_rescale_q(avctx->internal->skip_samples, (AVRational){1, avctx->sample_rate}, avctx->pkt_timebase); if(frame->pkt_pts!=AV_NOPTS_VALUE) frame->pkt_pts += diff_ts; if(frame->pkt_dts!=AV_NOPTS_VALUE) frame->pkt_dts += diff_ts; if (av_frame_get_pkt_duration(frame) >= diff_ts) av_frame_set_pkt_duration(frame, av_frame_get_pkt_duration(frame) - diff_ts); } else { av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for skipped samples.\n"); } av_log(avctx, AV_LOG_DEBUG, "skip %d/%d samples\n", avctx->internal->skip_samples, frame->nb_samples); frame->nb_samples -= avctx->internal->skip_samples; avctx->internal->skip_samples = 0; } } if (discard_padding > 0 && discard_padding <= frame->nb_samples && *got_frame_ptr) { if (discard_padding == frame->nb_samples) { *got_frame_ptr = 0; } else { if(avctx->pkt_timebase.num && avctx->sample_rate) { int64_t diff_ts = av_rescale_q(frame->nb_samples - discard_padding, (AVRational){1, avctx->sample_rate}, avctx->pkt_timebase); if (av_frame_get_pkt_duration(frame) >= diff_ts) av_frame_set_pkt_duration(frame, av_frame_get_pkt_duration(frame) - diff_ts); } else { av_log(avctx, AV_LOG_WARNING, "Could not update timestamps for discarded samples.\n"); } av_log(avctx, AV_LOG_DEBUG, "discard %d/%d samples\n", discard_padding, frame->nb_samples); frame->nb_samples -= discard_padding; } } fail: avctx->internal->pkt = NULL; if (did_split) { av_packet_free_side_data(&tmp); if(ret == tmp.size) ret = avpkt->size; } if (ret >= 0 && *got_frame_ptr) { if (!avctx->refcounted_frames) { int err = unrefcount_frame(avci, frame); if (err < 0) return err; } } else av_frame_unref(frame); } return ret; }


static int parse_dsd_diin(AVFormatContext *s, AVStream *st, uint64_t eof) { AVIOContext *pb = s->pb; while (avio_tell(pb) + 12 <= eof) { uint32_t tag = avio_rl32(pb); uint64_t size = avio_rb64(pb); uint64_t orig_pos = avio_tell(pb); const char * metadata_tag = NULL; switch(tag) { case MKTAG('D','I','A','R'): metadata_tag = "artist"; break; case MKTAG('D','I','T','I'): metadata_tag = "title"; break; } if (metadata_tag && size > 4) { unsigned int tag_size = avio_rb32(pb); int ret = get_metadata(s, metadata_tag, FFMIN(tag_size, size - 4)); if (ret < 0) { av_log(s, AV_LOG_ERROR, "cannot allocate metadata tag %s!\n", metadata_tag); return ret; } } avio_skip(pb, size - (avio_tell(pb) - orig_pos) + (size & 1)); } return 0; }


static unsigned tget_short(const uint8_t **p, int le) { unsigned v = le ? AV_RL16(*p) : AV_RB16(*p); *p += 2; return v; }


void checkasm_check_vf_interlace(void) { check_lowpass_line(8); report("lowpass_line_8"); check_lowpass_line(16); report("lowpass_line_16"); }


static int blk_mig_save_dirty_block(QEMUFile *f, int is_async) { BlkMigDevState *bmds; int ret = 1; QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { ret = mig_save_device_dirty(f, bmds, is_async); if (ret <= 0) { break; } } return ret; }


static void qtrle_decode_32bpp(QtrleContext *s) { int stream_ptr; int header; int start_line; int lines_to_change; signed char rle_code; int row_ptr, pixel_ptr; int row_inc = s->frame.linesize[0]; unsigned char r, g, b; unsigned int argb; unsigned char *rgb = s->frame.data[0]; int pixel_limit = s->frame.linesize[0] * s->avctx->height; /* check if this frame is even supposed to change */ if (s->size < 8) return; /* start after the chunk size */ stream_ptr = 4; /* fetch the header */ CHECK_STREAM_PTR(2); header = BE_16(&s->buf[stream_ptr]); stream_ptr += 2; /* if a header is present, fetch additional decoding parameters */ if (header & 0x0008) { CHECK_STREAM_PTR(8); start_line = BE_16(&s->buf[stream_ptr]); stream_ptr += 4; lines_to_change = BE_16(&s->buf[stream_ptr]); stream_ptr += 4; } else { start_line = 0; lines_to_change = s->avctx->height; } row_ptr = row_inc * start_line; while (lines_to_change--) { CHECK_STREAM_PTR(2); pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 4; while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { if (rle_code == 0) { /* there's another skip code in the stream */ CHECK_STREAM_PTR(1); pixel_ptr += (s->buf[stream_ptr++] - 1) * 4; CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ } else if (rle_code < 0) { /* decode the run length code */ rle_code = -rle_code; CHECK_STREAM_PTR(4); stream_ptr++; /* skip the alpha (?) byte */ r = s->buf[stream_ptr++]; g = s->buf[stream_ptr++]; b = s->buf[stream_ptr++]; argb = (r << 16) | (g << 8) | (b << 0); CHECK_PIXEL_PTR(rle_code * 4); while (rle_code--) { *(unsigned int *)(&rgb[pixel_ptr]) = argb; pixel_ptr += 4; } } else { CHECK_STREAM_PTR(rle_code * 4); CHECK_PIXEL_PTR(rle_code * 4); /* copy pixels directly to output */ while (rle_code--) { stream_ptr++; /* skip the alpha (?) byte */ r = s->buf[stream_ptr++]; g = s->buf[stream_ptr++]; b = s->buf[stream_ptr++]; argb = (r << 16) | (g << 8) | (b << 0); *(unsigned int *)(&rgb[pixel_ptr]) = argb; pixel_ptr += 4; } } } row_ptr += row_inc; } }


static void scsi_command_complete(SCSIDiskReq *r, int status, int sense) { DPRINTF("Command complete tag=0x%x status=%d sense=%d\n", r->req.tag, status, sense); scsi_req_set_status(r, status, sense); scsi_req_complete(&r->req); scsi_remove_request(r); }


static int vio_make_devnode(VIOsPAPRDevice *dev, void *fdt) { VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev); int vdevice_off, node_off, ret; char *dt_name; vdevice_off = fdt_path_offset(fdt, "/vdevice"); if (vdevice_off < 0) { return vdevice_off; } dt_name = vio_format_dev_name(dev); if (!dt_name) { return -ENOMEM; } node_off = fdt_add_subnode(fdt, vdevice_off, dt_name); free(dt_name); if (node_off < 0) { return node_off; } ret = fdt_setprop_cell(fdt, node_off, "reg", dev->reg); if (ret < 0) { return ret; } if (pc->dt_type) { ret = fdt_setprop_string(fdt, node_off, "device_type", pc->dt_type); if (ret < 0) { return ret; } } if (pc->dt_compatible) { ret = fdt_setprop_string(fdt, node_off, "compatible", pc->dt_compatible); if (ret < 0) { return ret; } } if (dev->qirq) { uint32_t ints_prop[] = {cpu_to_be32(dev->vio_irq_num), 0}; ret = fdt_setprop(fdt, node_off, "interrupts", ints_prop, sizeof(ints_prop)); if (ret < 0) { return ret; } } if (dev->rtce_window_size) { uint32_t dma_prop[] = {cpu_to_be32(dev->reg), 0, 0, 0, cpu_to_be32(dev->rtce_window_size)}; ret = fdt_setprop_cell(fdt, node_off, "ibm,#dma-address-cells", 2); if (ret < 0) { return ret; } ret = fdt_setprop_cell(fdt, node_off, "ibm,#dma-size-cells", 2); if (ret < 0) { return ret; } ret = fdt_setprop(fdt, node_off, "ibm,my-dma-window", dma_prop, sizeof(dma_prop)); if (ret < 0) { return ret; } } if (pc->devnode) { ret = (pc->devnode)(dev, fdt, node_off); if (ret < 0) { return ret; } } return node_off; }


static void uc32_cpu_class_init(ObjectClass *oc, void *data) { DeviceClass *dc = DEVICE_CLASS(oc); CPUClass *cc = CPU_CLASS(oc); UniCore32CPUClass *ucc = UNICORE32_CPU_CLASS(oc); ucc->parent_realize = dc->realize; dc->realize = uc32_cpu_realizefn; cc->class_by_name = uc32_cpu_class_by_name; cc->has_work = uc32_cpu_has_work; cc->do_interrupt = uc32_cpu_do_interrupt; cc->cpu_exec_interrupt = uc32_cpu_exec_interrupt; cc->dump_state = uc32_cpu_dump_state; cc->set_pc = uc32_cpu_set_pc; #ifdef CONFIG_USER_ONLY cc->handle_mmu_fault = uc32_cpu_handle_mmu_fault; #else cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug; #endif dc->vmsd = &vmstate_uc32_cpu; }


static int eval_refl(int *refl, const int16_t *coefs, RA144Context *ractx) { int b, i, j; int buffer1[10]; int buffer2[10]; int *bp1 = buffer1; int *bp2 = buffer2; for (i=0; i < 10; i++) buffer2[i] = coefs[i]; refl[9] = bp2[9]; if ((unsigned) bp2[9] + 0x1000 > 0x1fff) { av_log(ractx, AV_LOG_ERROR, "Overflow. Broken sample?\n"); return 1; } for (i=8; i >= 0; i--) { b = 0x1000-((bp2[i+1] * bp2[i+1]) >> 12); if (!b) b = -2; for (j=0; j <= i; j++) bp1[j] = ((bp2[j] - ((refl[i+1] * bp2[i-j]) >> 12)) * (0x1000000 / b)) >> 12; refl[i] = bp1[i]; if ((unsigned) bp1[i] + 0x1000 > 0x1fff) return 1; FFSWAP(int *, bp1, bp2); } return 0; }


static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner, const char *name, uint64_t ram_size) { if (mem_path) { #ifdef __linux__ Error *err = NULL; memory_region_init_ram_from_file(mr, owner, name, ram_size, false, mem_path, &err); /* Legacy behavior: if allocation failed, fall back to * regular RAM allocation. */ if (err) { error_report_err(err); memory_region_init_ram(mr, owner, name, ram_size, &error_abort); } #else fprintf(stderr, "-mem-path not supported on this host\n"); exit(1); #endif } else { memory_region_init_ram(mr, owner, name, ram_size, &error_abort); } vmstate_register_ram_global(mr); }


static void cmd646_cmd_write(void *opaque, target_phys_addr_t addr, uint64_t data, unsigned size) { CMD646BAR *cmd646bar = opaque; if (addr != 2 || size != 1) { return; } ide_cmd_write(cmd646bar->bus, addr + 2, data); }


static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg ret, tcg_target_long arg) { tcg_target_long hi, lo; /* A 13-bit constant sign-extended to 64-bits. */ if (check_fit_tl(arg, 13)) { tcg_out_movi_imm13(s, ret, arg); return; } /* A 32-bit constant, or 32-bit zero-extended to 64-bits. */ if (type == TCG_TYPE_I32 || arg == (uint32_t)arg) { tcg_out_sethi(s, ret, arg); if (arg & 0x3ff) { tcg_out_arithi(s, ret, ret, arg & 0x3ff, ARITH_OR); } return; } /* A 32-bit constant sign-extended to 64-bits. */ if (check_fit_tl(arg, 32)) { tcg_out_sethi(s, ret, ~arg); tcg_out_arithi(s, ret, ret, (arg & 0x3ff) | -0x400, ARITH_XOR); return; } /* A 64-bit constant decomposed into 2 32-bit pieces. */ lo = (int32_t)arg; if (check_fit_tl(lo, 13)) { hi = (arg - lo) >> 32; tcg_out_movi(s, TCG_TYPE_I32, ret, hi); tcg_out_arithi(s, ret, ret, 32, SHIFT_SLLX); tcg_out_arithi(s, ret, ret, lo, ARITH_ADD); } else { hi = arg >> 32; tcg_out_movi(s, TCG_TYPE_I32, ret, hi); tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_T2, lo); tcg_out_arithi(s, ret, ret, 32, SHIFT_SLLX); tcg_out_arith(s, ret, ret, TCG_REG_T2, ARITH_OR); } }


int vnc_display_open(DisplayState *ds, const char *arg) { struct sockaddr *addr; struct sockaddr_in iaddr; #ifndef _WIN32 struct sockaddr_un uaddr; #endif int reuse_addr, ret; socklen_t addrlen; const char *p; VncState *vs = ds ? (VncState *)ds->opaque : vnc_state; vnc_display_close(ds); if (strcmp(arg, "none") == 0) return 0; if (!(vs->display = strdup(arg))) return -1; #ifndef _WIN32 if (strstart(arg, "unix:", &p)) { addr = (struct sockaddr *)&uaddr; addrlen = sizeof(uaddr); vs->lsock = socket(PF_UNIX, SOCK_STREAM, 0); if (vs->lsock == -1) { fprintf(stderr, "Could not create socket\n"); free(vs->display); vs->display = NULL; return -1; } uaddr.sun_family = AF_UNIX; memset(uaddr.sun_path, 0, 108); snprintf(uaddr.sun_path, 108, "%s", p); unlink(uaddr.sun_path); } else #endif { addr = (struct sockaddr *)&iaddr; addrlen = sizeof(iaddr); if (parse_host_port(&iaddr, arg) < 0) { fprintf(stderr, "Could not parse VNC address\n"); free(vs->display); vs->display = NULL; return -1; } iaddr.sin_port = htons(ntohs(iaddr.sin_port) + 5900); vs->lsock = socket(PF_INET, SOCK_STREAM, 0); if (vs->lsock == -1) { fprintf(stderr, "Could not create socket\n"); free(vs->display); vs->display = NULL; return -1; } reuse_addr = 1; ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuse_addr, sizeof(reuse_addr)); if (ret == -1) { fprintf(stderr, "setsockopt() failed\n"); close(vs->lsock); vs->lsock = -1; free(vs->display); vs->display = NULL; return -1; } } if (bind(vs->lsock, addr, addrlen) == -1) { fprintf(stderr, "bind() failed\n"); close(vs->lsock); vs->lsock = -1; free(vs->display); vs->display = NULL; return -1; } if (listen(vs->lsock, 1) == -1) { fprintf(stderr, "listen() failed\n"); close(vs->lsock); vs->lsock = -1; free(vs->display); vs->display = NULL; return -1; } return qemu_set_fd_handler2(vs->lsock, vnc_listen_poll, vnc_listen_read, NULL, vs); }


static uint64_t msix_table_mmio_read(void *opaque, target_phys_addr_t addr, unsigned size) { PCIDevice *dev = opaque; return pci_get_long(dev->msix_table + addr); }


PCIBus *pci_device_root_bus(const PCIDevice *d) { PCIBus *bus = d->bus; while (!pci_bus_is_root(bus)) { d = bus->parent_dev; assert(d != NULL); bus = d->bus; } return bus; }


static int ftp_connect_data_connection(URLContext *h) { int err; char buf[CONTROL_BUFFER_SIZE], opts_format[20]; AVDictionary *opts = NULL; FTPContext *s = h->priv_data; if (!s->conn_data) { /* Enter passive mode */ if ((err = ftp_passive_mode(s)) < 0) { av_dlog(h, "Set passive mode failed\n"); return err; } /* Open data connection */ ff_url_join(buf, sizeof(buf), "tcp", NULL, s->hostname, s->server_data_port, NULL); if (s->rw_timeout != -1) { snprintf(opts_format, sizeof(opts_format), "%d", s->rw_timeout); av_dict_set(&opts, "timeout", opts_format, 0); } /* if option is not given, don't pass it and let tcp use its own default */ err = ffurl_open(&s->conn_data, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback, &opts); av_dict_free(&opts); if (err < 0) return err; if (s->position) if ((err = ftp_restart(s, s->position)) < 0) return err; } s->state = READY; return 0; }


static BlockDriver *find_protocol(const char *filename) { BlockDriver *drv1; char protocol[128]; int len; const char *p; #ifdef _WIN32 if (is_windows_drive(filename) || is_windows_drive_prefix(filename)) return bdrv_find_format("raw"); #endif p = strchr(filename, ':'); if (!p) return bdrv_find_format("raw"); len = p - filename; if (len > sizeof(protocol) - 1) len = sizeof(protocol) - 1; memcpy(protocol, filename, len); protocol[len] = '\0'; QLIST_FOREACH(drv1, &bdrv_drivers, list) { if (drv1->protocol_name && !strcmp(drv1->protocol_name, protocol)) { return drv1; } } return NULL; }


static void virtio_net_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIONet *n = VIRTIO_NET(dev); NetClientState *nc; int i; virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size); n->max_queues = MAX(n->nic_conf.queues, 1); n->vqs = g_malloc0(sizeof(VirtIONetQueue) * n->max_queues); n->vqs[0].rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx); n->curr_queues = 1; n->vqs[0].n = n; n->tx_timeout = n->net_conf.txtimer; if (n->net_conf.tx && strcmp(n->net_conf.tx, "timer") && strcmp(n->net_conf.tx, "bh")) { error_report("virtio-net: " "Unknown option tx=%s, valid options: \"timer\" \"bh\"", n->net_conf.tx); error_report("Defaulting to \"bh\""); } if (n->net_conf.tx && !strcmp(n->net_conf.tx, "timer")) { n->vqs[0].tx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_tx_timer); n->vqs[0].tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, virtio_net_tx_timer, &n->vqs[0]); } else { n->vqs[0].tx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_tx_bh); n->vqs[0].tx_bh = qemu_bh_new(virtio_net_tx_bh, &n->vqs[0]); } n->ctrl_vq = virtio_add_queue(vdev, 64, virtio_net_handle_ctrl); qemu_macaddr_default_if_unset(&n->nic_conf.macaddr); memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac)); n->status = VIRTIO_NET_S_LINK_UP; if (n->netclient_type) { /* * Happen when virtio_net_set_netclient_name has been called. */ n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf, n->netclient_type, n->netclient_name, n); } else { n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf, object_get_typename(OBJECT(dev)), dev->id, n); } peer_test_vnet_hdr(n); if (peer_has_vnet_hdr(n)) { for (i = 0; i < n->max_queues; i++) { qemu_peer_using_vnet_hdr(qemu_get_subqueue(n->nic, i), true); } n->host_hdr_len = sizeof(struct virtio_net_hdr); } else { n->host_hdr_len = 0; } qemu_format_nic_info_str(qemu_get_queue(n->nic), n->nic_conf.macaddr.a); n->vqs[0].tx_waiting = 0; n->tx_burst = n->net_conf.txburst; virtio_net_set_mrg_rx_bufs(n, 0); n->promisc = 1; /* for compatibility */ n->mac_table.macs = g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN); n->vlans = g_malloc0(MAX_VLAN >> 3); nc = qemu_get_queue(n->nic); nc->rxfilter_notify_enabled = 1; n->qdev = dev; register_savevm(dev, "virtio-net", -1, VIRTIO_NET_VM_VERSION, virtio_net_save, virtio_net_load, n); add_boot_device_path(n->nic_conf.bootindex, dev, "/ethernet-phy@0"); }


static int usbredir_handle_control(USBDevice *udev, USBPacket *p, int request, int value, int index, int length, uint8_t *data) { USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev); struct usb_redir_control_packet_header control_packet; AsyncURB *aurb; /* Special cases for certain standard device requests */ switch (request) { case DeviceOutRequest | USB_REQ_SET_ADDRESS: DPRINTF("set address %d\n", value); dev->dev.addr = value; return 0; case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: return usbredir_set_config(dev, p, value & 0xff); case DeviceRequest | USB_REQ_GET_CONFIGURATION: return usbredir_get_config(dev, p); case InterfaceOutRequest | USB_REQ_SET_INTERFACE: return usbredir_set_interface(dev, p, index, value); case InterfaceRequest | USB_REQ_GET_INTERFACE: return usbredir_get_interface(dev, p, index); } /* "Normal" ctrl requests */ aurb = async_alloc(dev, p); /* Note request is (bRequestType << 8) | bRequest */ DPRINTF("ctrl-out type 0x%x req 0x%x val 0x%x index %d len %d id %u\n", request >> 8, request & 0xff, value, index, length, aurb->packet_id); control_packet.request = request & 0xFF; control_packet.requesttype = request >> 8; control_packet.endpoint = control_packet.requesttype & USB_DIR_IN; control_packet.value = value; control_packet.index = index; control_packet.length = length; aurb->control_packet = control_packet; if (control_packet.requesttype & USB_DIR_IN) { usbredirparser_send_control_packet(dev->parser, aurb->packet_id, &control_packet, NULL, 0); } else { usbredir_log_data(dev, "ctrl data out:", data, length); usbredirparser_send_control_packet(dev->parser, aurb->packet_id, &control_packet, data, length); } usbredirparser_do_write(dev->parser); return USB_RET_ASYNC; }


void helper_ldl_kernel(uint64_t t0, uint64_t t1) { ldl_kernel(t1, t0); }


static void test_visitor_out_any(TestOutputVisitorData *data, const void *unused) { QObject *qobj; QInt *qint; QBool *qbool; QString *qstring; QDict *qdict; QObject *obj; qobj = QOBJECT(qint_from_int(-42)); visit_type_any(data->ov, NULL, &qobj, &error_abort); obj = visitor_get(data); g_assert(qobject_type(obj) == QTYPE_QINT); g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), ==, -42); qobject_decref(qobj); visitor_reset(data); qdict = qdict_new(); qdict_put(qdict, "integer", qint_from_int(-42)); qdict_put(qdict, "boolean", qbool_from_bool(true)); qdict_put(qdict, "string", qstring_from_str("foo")); qobj = QOBJECT(qdict); visit_type_any(data->ov, NULL, &qobj, &error_abort); qobject_decref(qobj); qdict = qobject_to_qdict(visitor_get(data)); g_assert(qdict); qobj = qdict_get(qdict, "integer"); g_assert(qobj); qint = qobject_to_qint(qobj); g_assert(qint); g_assert_cmpint(qint_get_int(qint), ==, -42); qobj = qdict_get(qdict, "boolean"); g_assert(qobj); qbool = qobject_to_qbool(qobj); g_assert(qbool); g_assert(qbool_get_bool(qbool) == true); qstring = qobject_to_qstring(qdict_get(qdict, "string")); g_assert(qstring); g_assert_cmpstr(qstring_get_str(qstring), ==, "foo"); }


static void handle_user_command(Monitor *mon, const char *cmdline) { QDict *qdict; const mon_cmd_t *cmd; qdict = qdict_new(); cmd = monitor_parse_command(mon, cmdline, qdict); if (!cmd) goto out; if (monitor_handler_is_async(cmd)) { user_async_cmd_handler(mon, cmd, qdict); } else if (monitor_handler_ported(cmd)) { monitor_call_handler(mon, cmd, qdict); } else { cmd->mhandler.cmd(mon, qdict); } if (monitor_has_error(mon)) monitor_print_error(mon); out: QDECREF(qdict); }


static inline void RENAME(uyvytoyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, long width, long height, long lumStride, long chromStride, long srcStride) { long y; const long chromWidth= width>>1; for(y=0; y<height; y+=2) { #ifdef HAVE_MMX asm volatile( "xorl %%eax, %%eax \n\t" "pcmpeqw %%mm7, %%mm7 \n\t" "psrlw $8, %%mm7 \n\t" // FF,00,FF,00... ASMALIGN16 "1: \n\t" PREFETCH" 64(%0, %%eax, 4) \n\t" "movq (%0, %%eax, 4), %%mm0 \n\t" // UYVY UYVY(0) "movq 8(%0, %%eax, 4), %%mm1 \n\t" // UYVY UYVY(4) "movq %%mm0, %%mm2 \n\t" // UYVY UYVY(0) "movq %%mm1, %%mm3 \n\t" // UYVY UYVY(4) "pand %%mm7, %%mm0 \n\t" // U0V0 U0V0(0) "pand %%mm7, %%mm1 \n\t" // U0V0 U0V0(4) "psrlw $8, %%mm2 \n\t" // Y0Y0 Y0Y0(0) "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(4) "packuswb %%mm1, %%mm0 \n\t" // UVUV UVUV(0) "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(0) MOVNTQ" %%mm2, (%1, %%eax, 2) \n\t" "movq 16(%0, %%eax, 4), %%mm1 \n\t" // UYVY UYVY(8) "movq 24(%0, %%eax, 4), %%mm2 \n\t" // UYVY UYVY(12) "movq %%mm1, %%mm3 \n\t" // UYVY UYVY(8) "movq %%mm2, %%mm4 \n\t" // UYVY UYVY(12) "pand %%mm7, %%mm1 \n\t" // U0V0 U0V0(8) "pand %%mm7, %%mm2 \n\t" // U0V0 U0V0(12) "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(8) "psrlw $8, %%mm4 \n\t" // Y0Y0 Y0Y0(12) "packuswb %%mm2, %%mm1 \n\t" // UVUV UVUV(8) "packuswb %%mm4, %%mm3 \n\t" // YYYY YYYY(8) MOVNTQ" %%mm3, 8(%1, %%eax, 2) \n\t" "movq %%mm0, %%mm2 \n\t" // UVUV UVUV(0) "movq %%mm1, %%mm3 \n\t" // UVUV UVUV(8) "psrlw $8, %%mm0 \n\t" // V0V0 V0V0(0) "psrlw $8, %%mm1 \n\t" // V0V0 V0V0(8) "pand %%mm7, %%mm2 \n\t" // U0U0 U0U0(0) "pand %%mm7, %%mm3 \n\t" // U0U0 U0U0(8) "packuswb %%mm1, %%mm0 \n\t" // VVVV VVVV(0) "packuswb %%mm3, %%mm2 \n\t" // UUUU UUUU(0) MOVNTQ" %%mm0, (%3, %%eax) \n\t" MOVNTQ" %%mm2, (%2, %%eax) \n\t" "addl $8, %%eax \n\t" "cmpl %4, %%eax \n\t" " jb 1b \n\t" ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth) : "memory", "%eax" ); ydst += lumStride; src += srcStride; asm volatile( "xorl %%eax, %%eax \n\t" ASMALIGN16 "1: \n\t" PREFETCH" 64(%0, %%eax, 4) \n\t" "movq (%0, %%eax, 4), %%mm0 \n\t" // YUYV YUYV(0) "movq 8(%0, %%eax, 4), %%mm1 \n\t" // YUYV YUYV(4) "movq 16(%0, %%eax, 4), %%mm2 \n\t" // YUYV YUYV(8) "movq 24(%0, %%eax, 4), %%mm3 \n\t" // YUYV YUYV(12) "psrlw $8, %%mm0 \n\t" // Y0Y0 Y0Y0(0) "psrlw $8, %%mm1 \n\t" // Y0Y0 Y0Y0(4) "psrlw $8, %%mm2 \n\t" // Y0Y0 Y0Y0(8) "psrlw $8, %%mm3 \n\t" // Y0Y0 Y0Y0(12) "packuswb %%mm1, %%mm0 \n\t" // YYYY YYYY(0) "packuswb %%mm3, %%mm2 \n\t" // YYYY YYYY(8) MOVNTQ" %%mm0, (%1, %%eax, 2) \n\t" MOVNTQ" %%mm2, 8(%1, %%eax, 2) \n\t" "addl $8, %%eax \n\t" "cmpl %4, %%eax \n\t" " jb 1b \n\t" ::"r"(src), "r"(ydst), "r"(udst), "r"(vdst), "g" (chromWidth) : "memory", "%eax" ); #else long i; for(i=0; i<chromWidth; i++) { udst[i] = src[4*i+0]; ydst[2*i+0] = src[4*i+1]; vdst[i] = src[4*i+2]; ydst[2*i+1] = src[4*i+3]; } ydst += lumStride; src += srcStride; for(i=0; i<chromWidth; i++) { ydst[2*i+0] = src[4*i+1]; ydst[2*i+1] = src[4*i+3]; } #endif udst += chromStride; vdst += chromStride; ydst += lumStride; src += srcStride; } #ifdef HAVE_MMX asm volatile( EMMS" \n\t" SFENCE" \n\t" :::"memory"); #endif }


static int do_create(struct iovec *iovec) { int ret; V9fsString path; int flags, mode, uid, gid, cur_uid, cur_gid; v9fs_string_init(&path); ret = proxy_unmarshal(iovec, PROXY_HDR_SZ, "sdddd", &path, &flags, &mode, &uid, &gid); if (ret < 0) { goto unmarshal_err_out; } cur_uid = geteuid(); cur_gid = getegid(); ret = setfsugid(uid, gid); if (ret < 0) { /* * On failure reset back to the * old uid/gid */ ret = -errno; goto err_out; } ret = open(path.data, flags, mode); if (ret < 0) { ret = -errno; } err_out: setfsugid(cur_uid, cur_gid); unmarshal_err_out: v9fs_string_free(&path); return ret; }


static unsigned int dec_movem_rm(DisasContext *dc) { TCGv tmp; TCGv addr; int i; DIS(fprintf (logfile, "movem $r%u, [$r%u%s\n", dc->op2, dc->op1, dc->postinc ? "+]" : "]")); cris_flush_cc_state(dc); tmp = tcg_temp_new(TCG_TYPE_TL); addr = tcg_temp_new(TCG_TYPE_TL); tcg_gen_movi_tl(tmp, 4); tcg_gen_mov_tl(addr, cpu_R[dc->op1]); for (i = 0; i <= dc->op2; i++) { /* Displace addr. */ /* Perform the store. */ gen_store(dc, addr, cpu_R[i], 4); tcg_gen_add_tl(addr, addr, tmp); } if (dc->postinc) tcg_gen_mov_tl(cpu_R[dc->op1], addr); cris_cc_mask(dc, 0); tcg_temp_free(tmp); tcg_temp_free(addr); return 2; }


void event_notifier_init_fd(EventNotifier *e, int fd) { e->fd = fd; }


static int raw_probe(const uint8_t *buf, int buf_size, const char *filename) { /* smallest possible positive score so that raw is used if and only if no * other block driver works */ return 1; }


void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp) { int64_t value; if (v->type_uint64) { v->type_uint64(v, obj, name, errp); } else { value = *obj; v->type_int64(v, &value, name, errp); *obj = value; } }


void helper_fcmpu(CPUPPCState *env, uint64_t arg1, uint64_t arg2, uint32_t crfD) { CPU_DoubleU farg1, farg2; uint32_t ret = 0; farg1.ll = arg1; farg2.ll = arg2; if (unlikely(float64_is_any_nan(farg1.d) || float64_is_any_nan(farg2.d))) { ret = 0x01UL; } else if (float64_lt(farg1.d, farg2.d, &env->fp_status)) { ret = 0x08UL; } else if (!float64_le(farg1.d, farg2.d, &env->fp_status)) { ret = 0x04UL; } else { ret = 0x02UL; } env->fpscr &= ~(0x0F << FPSCR_FPRF); env->fpscr |= ret << FPSCR_FPRF; env->crf[crfD] = ret; if (unlikely(ret == 0x01UL && (float64_is_signaling_nan(farg1.d) || float64_is_signaling_nan(farg2.d)))) { /* sNaN comparison */ fload_invalid_op_excp(env, POWERPC_EXCP_FP_VXSNAN); } }


static void gen_dmtc0 (CPUState *env, DisasContext *ctx, int reg, int sel) { const char *rn = "invalid"; if (sel != 0) check_insn(env, ctx, ISA_MIPS64); switch (reg) { case 0: switch (sel) { case 0: gen_op_mtc0_index(); rn = "Index"; break; case 1: check_mips_mt(env, ctx); gen_op_mtc0_mvpcontrol(); rn = "MVPControl"; break; case 2: check_mips_mt(env, ctx); /* ignored */ rn = "MVPConf0"; break; case 3: check_mips_mt(env, ctx); /* ignored */ rn = "MVPConf1"; break; default: goto die; } break; case 1: switch (sel) { case 0: /* ignored */ rn = "Random"; break; case 1: check_mips_mt(env, ctx); gen_op_mtc0_vpecontrol(); rn = "VPEControl"; break; case 2: check_mips_mt(env, ctx); gen_op_mtc0_vpeconf0(); rn = "VPEConf0"; break; case 3: check_mips_mt(env, ctx); gen_op_mtc0_vpeconf1(); rn = "VPEConf1"; break; case 4: check_mips_mt(env, ctx); gen_op_mtc0_yqmask(); rn = "YQMask"; break; case 5: check_mips_mt(env, ctx); gen_op_mtc0_vpeschedule(); rn = "VPESchedule"; break; case 6: check_mips_mt(env, ctx); gen_op_mtc0_vpeschefback(); rn = "VPEScheFBack"; break; case 7: check_mips_mt(env, ctx); gen_op_mtc0_vpeopt(); rn = "VPEOpt"; break; default: goto die; } break; case 2: switch (sel) { case 0: gen_op_mtc0_entrylo0(); rn = "EntryLo0"; break; case 1: check_mips_mt(env, ctx); gen_op_mtc0_tcstatus(); rn = "TCStatus"; break; case 2: check_mips_mt(env, ctx); gen_op_mtc0_tcbind(); rn = "TCBind"; break; case 3: check_mips_mt(env, ctx); gen_op_mtc0_tcrestart(); rn = "TCRestart"; break; case 4: check_mips_mt(env, ctx); gen_op_mtc0_tchalt(); rn = "TCHalt"; break; case 5: check_mips_mt(env, ctx); gen_op_mtc0_tccontext(); rn = "TCContext"; break; case 6: check_mips_mt(env, ctx); gen_op_mtc0_tcschedule(); rn = "TCSchedule"; break; case 7: check_mips_mt(env, ctx); gen_op_mtc0_tcschefback(); rn = "TCScheFBack"; break; default: goto die; } break; case 3: switch (sel) { case 0: gen_op_mtc0_entrylo1(); rn = "EntryLo1"; break; default: goto die; } break; case 4: switch (sel) { case 0: gen_op_mtc0_context(); rn = "Context"; break; case 1: // gen_op_mtc0_contextconfig(); /* SmartMIPS ASE */ rn = "ContextConfig"; // break; default: goto die; } break; case 5: switch (sel) { case 0: gen_op_mtc0_pagemask(); rn = "PageMask"; break; case 1: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_pagegrain(); rn = "PageGrain"; break; default: goto die; } break; case 6: switch (sel) { case 0: gen_op_mtc0_wired(); rn = "Wired"; break; case 1: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_srsconf0(); rn = "SRSConf0"; break; case 2: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_srsconf1(); rn = "SRSConf1"; break; case 3: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_srsconf2(); rn = "SRSConf2"; break; case 4: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_srsconf3(); rn = "SRSConf3"; break; case 5: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_srsconf4(); rn = "SRSConf4"; break; default: goto die; } break; case 7: switch (sel) { case 0: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_hwrena(); rn = "HWREna"; break; default: goto die; } break; case 8: /* ignored */ rn = "BadVaddr"; break; case 9: switch (sel) { case 0: gen_op_mtc0_count(); rn = "Count"; break; /* 6,7 are implementation dependent */ default: goto die; } /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; break; case 10: switch (sel) { case 0: gen_op_mtc0_entryhi(); rn = "EntryHi"; break; default: goto die; } break; case 11: switch (sel) { case 0: gen_op_mtc0_compare(); rn = "Compare"; break; /* 6,7 are implementation dependent */ default: goto die; } /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; break; case 12: switch (sel) { case 0: gen_op_mtc0_status(); /* BS_STOP isn't good enough here, hflags may have changed. */ gen_save_pc(ctx->pc + 4); ctx->bstate = BS_EXCP; rn = "Status"; break; case 1: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_intctl(); /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; rn = "IntCtl"; break; case 2: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_srsctl(); /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; rn = "SRSCtl"; break; case 3: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_srsmap(); /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; rn = "SRSMap"; break; default: goto die; } break; case 13: switch (sel) { case 0: gen_op_mtc0_cause(); rn = "Cause"; break; default: goto die; } /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; break; case 14: switch (sel) { case 0: gen_op_mtc0_epc(); rn = "EPC"; break; default: goto die; } break; case 15: switch (sel) { case 0: /* ignored */ rn = "PRid"; break; case 1: check_insn(env, ctx, ISA_MIPS32R2); gen_op_mtc0_ebase(); rn = "EBase"; break; default: goto die; } break; case 16: switch (sel) { case 0: gen_op_mtc0_config0(); rn = "Config"; /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; break; case 1: /* ignored */ rn = "Config1"; break; case 2: gen_op_mtc0_config2(); rn = "Config2"; /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; break; case 3: /* ignored */ rn = "Config3"; break; /* 6,7 are implementation dependent */ default: rn = "Invalid config selector"; goto die; } break; case 17: switch (sel) { case 0: /* ignored */ rn = "LLAddr"; break; default: goto die; } break; case 18: switch (sel) { case 0 ... 7: gen_op_mtc0_watchlo(sel); rn = "WatchLo"; break; default: goto die; } break; case 19: switch (sel) { case 0 ... 7: gen_op_mtc0_watchhi(sel); rn = "WatchHi"; break; default: goto die; } break; case 20: switch (sel) { case 0: check_insn(env, ctx, ISA_MIPS3); gen_op_mtc0_xcontext(); rn = "XContext"; break; default: goto die; } break; case 21: /* Officially reserved, but sel 0 is used for R1x000 framemask */ switch (sel) { case 0: gen_op_mtc0_framemask(); rn = "Framemask"; break; default: goto die; } break; case 22: /* ignored */ rn = "Diagnostic"; /* implementation dependent */ break; case 23: switch (sel) { case 0: gen_op_mtc0_debug(); /* EJTAG support */ /* BS_STOP isn't good enough here, hflags may have changed. */ gen_save_pc(ctx->pc + 4); ctx->bstate = BS_EXCP; rn = "Debug"; break; case 1: // gen_op_mtc0_tracecontrol(); /* PDtrace support */ /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; rn = "TraceControl"; // break; case 2: // gen_op_mtc0_tracecontrol2(); /* PDtrace support */ /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; rn = "TraceControl2"; // break; case 3: // gen_op_mtc0_usertracedata(); /* PDtrace support */ /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; rn = "UserTraceData"; // break; case 4: // gen_op_mtc0_debug(); /* PDtrace support */ /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; rn = "TraceBPC"; // break; default: goto die; } break; case 24: switch (sel) { case 0: gen_op_mtc0_depc(); /* EJTAG support */ rn = "DEPC"; break; default: goto die; } break; case 25: switch (sel) { case 0: gen_op_mtc0_performance0(); rn = "Performance0"; break; case 1: // gen_op_mtc0_performance1(); rn = "Performance1"; // break; case 2: // gen_op_mtc0_performance2(); rn = "Performance2"; // break; case 3: // gen_op_mtc0_performance3(); rn = "Performance3"; // break; case 4: // gen_op_mtc0_performance4(); rn = "Performance4"; // break; case 5: // gen_op_mtc0_performance5(); rn = "Performance5"; // break; case 6: // gen_op_mtc0_performance6(); rn = "Performance6"; // break; case 7: // gen_op_mtc0_performance7(); rn = "Performance7"; // break; default: goto die; } break; case 26: /* ignored */ rn = "ECC"; break; case 27: switch (sel) { case 0 ... 3: /* ignored */ rn = "CacheErr"; break; default: goto die; } break; case 28: switch (sel) { case 0: case 2: case 4: case 6: gen_op_mtc0_taglo(); rn = "TagLo"; break; case 1: case 3: case 5: case 7: gen_op_mtc0_datalo(); rn = "DataLo"; break; default: goto die; } break; case 29: switch (sel) { case 0: case 2: case 4: case 6: gen_op_mtc0_taghi(); rn = "TagHi"; break; case 1: case 3: case 5: case 7: gen_op_mtc0_datahi(); rn = "DataHi"; break; default: rn = "invalid sel"; goto die; } break; case 30: switch (sel) { case 0: gen_op_mtc0_errorepc(); rn = "ErrorEPC"; break; default: goto die; } break; case 31: switch (sel) { case 0: gen_op_mtc0_desave(); /* EJTAG support */ rn = "DESAVE"; break; default: goto die; } /* Stop translation as we may have switched the execution mode */ ctx->bstate = BS_STOP; break; default: goto die; } #if defined MIPS_DEBUG_DISAS if (loglevel & CPU_LOG_TB_IN_ASM) { fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n", rn, reg, sel); } #endif return; die: #if defined MIPS_DEBUG_DISAS if (loglevel & CPU_LOG_TB_IN_ASM) { fprintf(logfile, "dmtc0 %s (reg %d sel %d)\n", rn, reg, sel); } #endif generate_exception(ctx, EXCP_RI); }