static int flush_packet(AVFormatContext *ctx, int stream_index, int64_t pts, int64_t dts, int64_t scr, int trailer_size) { MpegMuxContext *s = ctx->priv_data; StreamInfo *stream = ctx->streams[stream_index]->priv_data; uint8_t *buf_ptr; int size, payload_size, startcode, id, stuffing_size, i, header_len; int packet_size; uint8_t buffer[128]; int zero_trail_bytes = 0; int pad_packet_bytes = 0; int pes_flags; int general_pack = 0; /*"general" pack without data specific to one stream?*/ int nb_frames; id = stream->id; #if 0 printf("packet ID=%2x PTS=%0.3f\n", id, pts / 90000.0); #endif buf_ptr = buffer; if ((s->packet_number % s->pack_header_freq) == 0 || s->last_scr != scr) { /* output pack and systems header if needed */ size = put_pack_header(ctx, buf_ptr, scr); buf_ptr += size; s->last_scr= scr; if (s->is_vcd) { /* there is exactly one system header for each stream in a VCD MPEG, One in the very first video packet and one in the very first audio packet (see VCD standard p. IV-7 and IV-8).*/ if (stream->packet_number==0) { size = put_system_header(ctx, buf_ptr, id); buf_ptr += size; } } else if (s->is_dvd) { if (stream->align_iframe || s->packet_number == 0){ int PES_bytes_to_fill = s->packet_size - size - 10; if (pts != AV_NOPTS_VALUE) { if (dts != pts) PES_bytes_to_fill -= 5 + 5; else PES_bytes_to_fill -= 5; } if (stream->bytes_to_iframe == 0 || s->packet_number == 0) { size = put_system_header(ctx, buf_ptr, 0); buf_ptr += size; size = buf_ptr - buffer; put_buffer(ctx->pb, buffer, size); put_be32(ctx->pb, PRIVATE_STREAM_2); put_be16(ctx->pb, 0x03d4); // length put_byte(ctx->pb, 0x00); // substream ID, 00=PCI for (i = 0; i < 979; i++) put_byte(ctx->pb, 0x00); put_be32(ctx->pb, PRIVATE_STREAM_2); put_be16(ctx->pb, 0x03fa); // length put_byte(ctx->pb, 0x01); // substream ID, 01=DSI for (i = 0; i < 1017; i++) put_byte(ctx->pb, 0x00); memset(buffer, 0, 128); buf_ptr = buffer; s->packet_number++; stream->align_iframe = 0; scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet size = put_pack_header(ctx, buf_ptr, scr); s->last_scr= scr; buf_ptr += size; /* GOP Start */ } else if (stream->bytes_to_iframe < PES_bytes_to_fill) { pad_packet_bytes = PES_bytes_to_fill - stream->bytes_to_iframe; } } } else { if ((s->packet_number % s->system_header_freq) == 0) { size = put_system_header(ctx, buf_ptr, 0); buf_ptr += size; } } } size = buf_ptr - buffer; put_buffer(ctx->pb, buffer, size); packet_size = s->packet_size - size; if (s->is_vcd && id == AUDIO_ID) /* The VCD standard demands that 20 zero bytes follow each audio pack (see standard p. IV-8).*/ zero_trail_bytes += 20; if ((s->is_vcd && stream->packet_number==0) || (s->is_svcd && s->packet_number==0)) { /* for VCD the first pack of each stream contains only the pack header, the system header and lots of padding (see VCD standard p. IV-6). In the case of an audio pack, 20 zero bytes are also added at the end.*/ /* For SVCD we fill the very first pack to increase compatibility with some DVD players. Not mandated by the standard.*/ if (s->is_svcd) general_pack = 1; /* the system header refers to both streams and no stream data*/ pad_packet_bytes = packet_size - zero_trail_bytes; } packet_size -= pad_packet_bytes + zero_trail_bytes; if (packet_size > 0) { /* packet header size */ packet_size -= 6; /* packet header */ if (s->is_mpeg2) { header_len = 3; if (stream->packet_number==0) header_len += 3; /* PES extension */ header_len += 1; /* obligatory stuffing byte */ } else { header_len = 0; } if (pts != AV_NOPTS_VALUE) { if (dts != pts) header_len += 5 + 5; else header_len += 5; } else { if (!s->is_mpeg2) header_len++; } payload_size = packet_size - header_len; if (id < 0xc0) { startcode = PRIVATE_STREAM_1; payload_size -= 1; if (id >= 0x40) { payload_size -= 3; if (id >= 0xa0) payload_size -= 3; } } else { startcode = 0x100 + id; } stuffing_size = payload_size - av_fifo_size(&stream->fifo); // first byte does not fit -> reset pts/dts + stuffing if(payload_size <= trailer_size && pts != AV_NOPTS_VALUE){ int timestamp_len=0; if(dts != pts) timestamp_len += 5; if(pts != AV_NOPTS_VALUE) timestamp_len += s->is_mpeg2 ? 5 : 4; pts=dts= AV_NOPTS_VALUE; header_len -= timestamp_len; if (s->is_dvd && stream->align_iframe) { pad_packet_bytes += timestamp_len; packet_size -= timestamp_len; } else { payload_size += timestamp_len; } stuffing_size += timestamp_len; if(payload_size > trailer_size) stuffing_size += payload_size - trailer_size; } if (pad_packet_bytes > 0 && pad_packet_bytes <= 7) { // can't use padding, so use stuffing packet_size += pad_packet_bytes; payload_size += pad_packet_bytes; // undo the previous adjustment if (stuffing_size < 0) { stuffing_size = pad_packet_bytes; } else { stuffing_size += pad_packet_bytes; } pad_packet_bytes = 0; } if (stuffing_size < 0) stuffing_size = 0; if (stuffing_size > 16) { /*<=16 for MPEG-1, <=32 for MPEG-2*/ pad_packet_bytes += stuffing_size; packet_size -= stuffing_size; payload_size -= stuffing_size; stuffing_size = 0; } nb_frames= get_nb_frames(ctx, stream, payload_size - stuffing_size); put_be32(ctx->pb, startcode); put_be16(ctx->pb, packet_size); if (!s->is_mpeg2) for(i=0;i<stuffing_size;i++) put_byte(ctx->pb, 0xff); if (s->is_mpeg2) { put_byte(ctx->pb, 0x80); /* mpeg2 id */ pes_flags=0; if (pts != AV_NOPTS_VALUE) { pes_flags |= 0x80; if (dts != pts) pes_flags |= 0x40; } /* Both the MPEG-2 and the SVCD standards demand that the P-STD_buffer_size field be included in the first packet of every stream. (see SVCD standard p. 26 V.2.3.1 and V.2.3.2 and MPEG-2 standard 2.7.7) */ if (stream->packet_number == 0) pes_flags |= 0x01; put_byte(ctx->pb, pes_flags); /* flags */ put_byte(ctx->pb, header_len - 3 + stuffing_size); if (pes_flags & 0x80) /*write pts*/ put_timestamp(ctx->pb, (pes_flags & 0x40) ? 0x03 : 0x02, pts); if (pes_flags & 0x40) /*write dts*/ put_timestamp(ctx->pb, 0x01, dts); if (pes_flags & 0x01) { /*write pes extension*/ put_byte(ctx->pb, 0x10); /* flags */ /* P-STD buffer info */ if (id == AUDIO_ID) put_be16(ctx->pb, 0x4000 | stream->max_buffer_size/128); else put_be16(ctx->pb, 0x6000 | stream->max_buffer_size/1024); } } else { if (pts != AV_NOPTS_VALUE) { if (dts != pts) { put_timestamp(ctx->pb, 0x03, pts); put_timestamp(ctx->pb, 0x01, dts); } else { put_timestamp(ctx->pb, 0x02, pts); } } else { put_byte(ctx->pb, 0x0f); } } if (s->is_mpeg2) { /* special stuffing byte that is always written to prevent accidental generation of start codes. */ put_byte(ctx->pb, 0xff); for(i=0;i<stuffing_size;i++) put_byte(ctx->pb, 0xff); } if (startcode == PRIVATE_STREAM_1) { put_byte(ctx->pb, id); if (id >= 0xa0) { /* LPCM (XXX: check nb_frames) */ put_byte(ctx->pb, 7); put_be16(ctx->pb, 4); /* skip 3 header bytes */ put_byte(ctx->pb, stream->lpcm_header[0]); put_byte(ctx->pb, stream->lpcm_header[1]); put_byte(ctx->pb, stream->lpcm_header[2]); } else if (id >= 0x40) { /* AC3 */ put_byte(ctx->pb, nb_frames); put_be16(ctx->pb, trailer_size+1); } } /* output data */ if(av_fifo_generic_read(&stream->fifo, payload_size - stuffing_size, &put_buffer, ctx->pb) < 0) return -1; stream->bytes_to_iframe -= payload_size - stuffing_size; }else{ payload_size= stuffing_size= 0; } if (pad_packet_bytes > 0) put_padding_packet(ctx,ctx->pb, pad_packet_bytes); for(i=0;i<zero_trail_bytes;i++) put_byte(ctx->pb, 0x00); put_flush_packet(ctx->pb); s->packet_number++; /* only increase the stream packet number if this pack actually contains something that is specific to this stream! I.e. a dedicated header or some data.*/ if (!general_pack) stream->packet_number++; return payload_size - stuffing_size; }


static void mux_chr_update_read_handler(CharDriverState *chr, GMainContext *context) { MuxDriver *d = chr->opaque; int idx; if (d->mux_cnt >= MAX_MUX) { fprintf(stderr, "Cannot add I/O handlers, MUX array is full\n"); return; } if (chr->mux_idx == -1) { chr->mux_idx = d->mux_cnt++; } idx = chr->mux_idx; d->ext_opaque[idx] = chr->handler_opaque; d->chr_can_read[idx] = chr->chr_can_read; d->chr_read[idx] = chr->chr_read; d->chr_event[idx] = chr->chr_event; /* Fix up the real driver with mux routines */ if (d->mux_cnt == 1) { qemu_chr_add_handlers_full(d->drv, mux_chr_can_read, mux_chr_read, mux_chr_event, chr, context); } if (d->focus != -1) { mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_OUT); } d->focus = idx; mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_IN); }


static inline void RENAME(yuv2packed2)(SwsContext *c, uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { int yalpha1=yalpha^4095; int uvalpha1=uvalpha^4095; int i; #if 0 //isn't used if (flags&SWS_FULL_CHR_H_INT) { switch(dstFormat) { #ifdef HAVE_MMX case PIX_FMT_RGB32: asm volatile( FULL_YSCALEYUV2RGB "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 "movq %%mm3, %%mm1 \n\t" "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 MOVNTQ(%%mm3, (%4, %%REGa, 4)) MOVNTQ(%%mm1, 8(%4, %%REGa, 4)) "add $4, %%"REG_a" \n\t" "cmp %5, %%"REG_a" \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" ((long)dstW), "m" (yalpha1), "m" (uvalpha1) : "%"REG_a ); break; case PIX_FMT_BGR24: asm volatile( FULL_YSCALEYUV2RGB // lsb ... msb "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 "movq %%mm3, %%mm1 \n\t" "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 "movq %%mm3, %%mm2 \n\t" // BGR0BGR0 "psrlq $8, %%mm3 \n\t" // GR0BGR00 "pand "MANGLE(bm00000111)", %%mm2 \n\t" // BGR00000 "pand "MANGLE(bm11111000)", %%mm3 \n\t" // 000BGR00 "por %%mm2, %%mm3 \n\t" // BGRBGR00 "movq %%mm1, %%mm2 \n\t" "psllq $48, %%mm1 \n\t" // 000000BG "por %%mm1, %%mm3 \n\t" // BGRBGRBG "movq %%mm2, %%mm1 \n\t" // BGR0BGR0 "psrld $16, %%mm2 \n\t" // R000R000 "psrlq $24, %%mm1 \n\t" // 0BGR0000 "por %%mm2, %%mm1 \n\t" // RBGRR000 "mov %4, %%"REG_b" \n\t" "add %%"REG_a", %%"REG_b" \n\t" #ifdef HAVE_MMX2 //FIXME Alignment "movntq %%mm3, (%%"REG_b", %%"REG_a", 2) \n\t" "movntq %%mm1, 8(%%"REG_b", %%"REG_a", 2) \n\t" #else "movd %%mm3, (%%"REG_b", %%"REG_a", 2) \n\t" "psrlq $32, %%mm3 \n\t" "movd %%mm3, 4(%%"REG_b", %%"REG_a", 2) \n\t" "movd %%mm1, 8(%%"REG_b", %%"REG_a", 2) \n\t" #endif "add $4, %%"REG_a" \n\t" "cmp %5, %%"REG_a" \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%"REG_a, "%"REG_b ); break; case PIX_FMT_BGR555: asm volatile( FULL_YSCALEYUV2RGB #ifdef DITHER1XBPP "paddusb "MANGLE(g5Dither)", %%mm1 \n\t" "paddusb "MANGLE(r5Dither)", %%mm0 \n\t" "paddusb "MANGLE(b5Dither)", %%mm3 \n\t" #endif "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R "psrlw $3, %%mm3 \n\t" "psllw $2, %%mm1 \n\t" "psllw $7, %%mm0 \n\t" "pand "MANGLE(g15Mask)", %%mm1 \n\t" "pand "MANGLE(r15Mask)", %%mm0 \n\t" "por %%mm3, %%mm1 \n\t" "por %%mm1, %%mm0 \n\t" MOVNTQ(%%mm0, (%4, %%REGa, 2)) "add $4, %%"REG_a" \n\t" "cmp %5, %%"REG_a" \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%"REG_a ); break; case PIX_FMT_BGR565: asm volatile( FULL_YSCALEYUV2RGB #ifdef DITHER1XBPP "paddusb "MANGLE(g6Dither)", %%mm1 \n\t" "paddusb "MANGLE(r5Dither)", %%mm0 \n\t" "paddusb "MANGLE(b5Dither)", %%mm3 \n\t" #endif "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R "psrlw $3, %%mm3 \n\t" "psllw $3, %%mm1 \n\t" "psllw $8, %%mm0 \n\t" "pand "MANGLE(g16Mask)", %%mm1 \n\t" "pand "MANGLE(r16Mask)", %%mm0 \n\t" "por %%mm3, %%mm1 \n\t" "por %%mm1, %%mm0 \n\t" MOVNTQ(%%mm0, (%4, %%REGa, 2)) "add $4, %%"REG_a" \n\t" "cmp %5, %%"REG_a" \n\t" " jb 1b \n\t" :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), "m" (yalpha1), "m" (uvalpha1) : "%"REG_a ); break; #endif /* HAVE_MMX */ case PIX_FMT_BGR32: #ifndef HAVE_MMX case PIX_FMT_RGB32: #endif if (dstFormat==PIX_FMT_RGB32) { int i; #ifdef WORDS_BIGENDIAN dest++; #endif for (i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)]; dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)]; dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)]; dest+= 4; } } else if (dstFormat==PIX_FMT_BGR24) { int i; for (i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)]; dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)]; dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)]; dest+= 3; } } else if (dstFormat==PIX_FMT_BGR565) { int i; for (i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); ((uint16_t*)dest)[i] = clip_table16b[(Y + yuvtab_40cf[U]) >>13] | clip_table16g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | clip_table16r[(Y + yuvtab_3343[V]) >>13]; } } else if (dstFormat==PIX_FMT_BGR555) { int i; for (i=0;i<dstW;i++){ // vertical linear interpolation && yuv2rgb in a single step: int Y=yuvtab_2568[((buf0[i]*yalpha1+buf1[i]*yalpha)>>19)]; int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); ((uint16_t*)dest)[i] = clip_table15b[(Y + yuvtab_40cf[U]) >>13] | clip_table15g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | clip_table15r[(Y + yuvtab_3343[V]) >>13]; } } }//FULL_UV_IPOL else { #endif // if 0 #ifdef HAVE_MMX switch(c->dstFormat) { //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( case PIX_FMT_RGB32: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB(%%REGBP, %5) WRITEBGR32(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; case PIX_FMT_BGR24: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB(%%REGBP, %5) WRITEBGR24(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; case PIX_FMT_BGR555: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB(%%REGBP, %5) /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" "paddusb "MANGLE(g5Dither)", %%mm4 \n\t" "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" #endif WRITEBGR15(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; case PIX_FMT_BGR565: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2RGB(%%REGBP, %5) /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" "paddusb "MANGLE(g6Dither)", %%mm4 \n\t" "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" #endif WRITEBGR16(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; case PIX_FMT_YUYV422: asm volatile( "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" "mov %4, %%"REG_b" \n\t" "push %%"REG_BP" \n\t" YSCALEYUV2PACKED(%%REGBP, %5) WRITEYUY2(%%REGb, 8280(%5), %%REGBP) "pop %%"REG_BP" \n\t" "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), "a" (&c->redDither) ); return; default: break; } #endif //HAVE_MMX YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C) }


static void apply_delogo(uint8_t *dst, int dst_linesize, uint8_t *src, int src_linesize, int w, int h, AVRational sar, int logo_x, int logo_y, int logo_w, int logo_h, unsigned int band, int show, int direct) { int x, y; uint64_t interp, weightl, weightr, weightt, weightb; uint8_t *xdst, *xsrc; uint8_t *topleft, *botleft, *topright; unsigned int left_sample, right_sample; int xclipl, xclipr, yclipt, yclipb; int logo_x1, logo_x2, logo_y1, logo_y2; xclipl = FFMAX(-logo_x, 0); xclipr = FFMAX(logo_x+logo_w-w, 0); yclipt = FFMAX(-logo_y, 0); yclipb = FFMAX(logo_y+logo_h-h, 0); logo_x1 = logo_x + xclipl; logo_x2 = logo_x + logo_w - xclipr; logo_y1 = logo_y + yclipt; logo_y2 = logo_y + logo_h - yclipb; topleft = src+logo_y1 * src_linesize+logo_x1; topright = src+logo_y1 * src_linesize+logo_x2-1; botleft = src+(logo_y2-1) * src_linesize+logo_x1; if (!direct) av_image_copy_plane(dst, dst_linesize, src, src_linesize, w, h); dst += (logo_y1 + 1) * dst_linesize; src += (logo_y1 + 1) * src_linesize; for (y = logo_y1+1; y < logo_y2-1; y++) { left_sample = topleft[src_linesize*(y-logo_y1)] + topleft[src_linesize*(y-logo_y1-1)] + topleft[src_linesize*(y-logo_y1+1)]; right_sample = topright[src_linesize*(y-logo_y1)] + topright[src_linesize*(y-logo_y1-1)] + topright[src_linesize*(y-logo_y1+1)]; for (x = logo_x1+1, xdst = dst+logo_x1+1, xsrc = src+logo_x1+1; x < logo_x2-1; x++, xdst++, xsrc++) { /* Weighted interpolation based on relative distances, taking SAR into account */ weightl = (uint64_t) (logo_x2-1-x) * (y-logo_y1) * (logo_y2-1-y) * sar.den; weightr = (uint64_t)(x-logo_x1) * (y-logo_y1) * (logo_y2-1-y) * sar.den; weightt = (uint64_t)(x-logo_x1) * (logo_x2-1-x) * (logo_y2-1-y) * sar.num; weightb = (uint64_t)(x-logo_x1) * (logo_x2-1-x) * (y-logo_y1) * sar.num; interp = left_sample * weightl + right_sample * weightr + (topleft[x-logo_x1] + topleft[x-logo_x1-1] + topleft[x-logo_x1+1]) * weightt + (botleft[x-logo_x1] + botleft[x-logo_x1-1] + botleft[x-logo_x1+1]) * weightb; interp /= (weightl + weightr + weightt + weightb) * 3U; if (y >= logo_y+band && y < logo_y+logo_h-band && x >= logo_x+band && x < logo_x+logo_w-band) { *xdst = interp; } else { unsigned dist = 0; if (x < logo_x+band) dist = FFMAX(dist, logo_x-x+band); else if (x >= logo_x+logo_w-band) dist = FFMAX(dist, x-(logo_x+logo_w-1-band)); if (y < logo_y+band) dist = FFMAX(dist, logo_y-y+band); else if (y >= logo_y+logo_h-band) dist = FFMAX(dist, y-(logo_y+logo_h-1-band)); *xdst = (*xsrc*dist + interp*(band-dist))/band; if (show && (dist == band-1)) *xdst = 0; } } dst += dst_linesize; src += src_linesize; } }


static long getrampagesize(void) { long hpsize = LONG_MAX; Object *memdev_root; if (mem_path) { return gethugepagesize(mem_path); } /* it's possible we have memory-backend objects with * hugepage-backed RAM. these may get mapped into system * address space via -numa parameters or memory hotplug * hooks. we want to take these into account, but we * also want to make sure these supported hugepage * sizes are applicable across the entire range of memory * we may boot from, so we take the min across all * backends, and assume normal pages in cases where a * backend isn't backed by hugepages. */ memdev_root = object_resolve_path("/objects", NULL); if (!memdev_root) { return getpagesize(); } object_child_foreach(memdev_root, find_max_supported_pagesize, &hpsize); if (hpsize == LONG_MAX) { return getpagesize(); } if (nb_numa_nodes == 0 && hpsize > getpagesize()) { /* No NUMA nodes and normal RAM without -mem-path ==> no huge pages! */ static bool warned; if (!warned) { error_report("Huge page support disabled (n/a for main memory)."); warned = true; } return getpagesize(); } return hpsize; }


static int kvm_put_xsave(CPUState *env) { #ifdef KVM_CAP_XSAVE int i; struct kvm_xsave* xsave; uint16_t cwd, swd, twd, fop; if (!kvm_has_xsave()) return kvm_put_fpu(env); xsave = qemu_memalign(4096, sizeof(struct kvm_xsave)); memset(xsave, 0, sizeof(struct kvm_xsave)); cwd = swd = twd = fop = 0; swd = env->fpus & ~(7 << 11); swd |= (env->fpstt & 7) << 11; cwd = env->fpuc; for (i = 0; i < 8; ++i) twd |= (!env->fptags[i]) << i; xsave->region[0] = (uint32_t)(swd << 16) + cwd; xsave->region[1] = (uint32_t)(fop << 16) + twd; memcpy(&xsave->region[XSAVE_ST_SPACE], env->fpregs, sizeof env->fpregs); memcpy(&xsave->region[XSAVE_XMM_SPACE], env->xmm_regs, sizeof env->xmm_regs); xsave->region[XSAVE_MXCSR] = env->mxcsr; *(uint64_t *)&xsave->region[XSAVE_XSTATE_BV] = env->xstate_bv; memcpy(&xsave->region[XSAVE_YMMH_SPACE], env->ymmh_regs, sizeof env->ymmh_regs); return kvm_vcpu_ioctl(env, KVM_SET_XSAVE, xsave); #else return kvm_put_fpu(env); #endif }


static int decode_rle(AVCodecContext *avctx, AVFrame *p, GetByteContext *gbc, int step) { int i, j; int offset = avctx->width * step; uint8_t *outdata = p->data[0]; for (i = 0; i < avctx->height; i++) { int size, left, code, pix; uint8_t *out = outdata; int pos = 0; /* size of packed line */ size = left = bytestream2_get_be16(gbc); if (bytestream2_get_bytes_left(gbc) < size) /* decode line */ while (left > 0) { code = bytestream2_get_byte(gbc); if (code & 0x80 ) { /* run */ pix = bytestream2_get_byte(gbc); for (j = 0; j < 257 - code; j++) { out[pos] = pix; pos += step; if (pos >= offset) { pos -= offset; pos++; } } left -= 2; } else { /* copy */ for (j = 0; j < code + 1; j++) { out[pos] = bytestream2_get_byte(gbc); pos += step; if (pos >= offset) { pos -= offset; pos++; } } left -= 2 + code; } } outdata += p->linesize[0]; } return 0; }


uint64_t helper_msub64_q_ssov(CPUTriCoreState *env, uint64_t r1, uint32_t r2, uint32_t r3, uint32_t n) { int64_t t1 = (int64_t)r1; int64_t t2 = sextract64(r2, 0, 32); int64_t t3 = sextract64(r3, 0, 32); int64_t result, mul; int64_t ovf; mul = (t2 * t3) << n; result = t1 - mul; env->PSW_USB_AV = (result ^ result * 2u) >> 32; env->PSW_USB_SAV |= env->PSW_USB_AV; ovf = (result ^ t1) & (t1 ^ mul); /* we do the saturation by hand, since we produce an overflow on the host if the mul before was (0x80000000 * 0x80000000) << 1). If this is the case, we flip the saturated value. */ if (mul == 0x8000000000000000LL) { if (ovf >= 0) { env->PSW_USB_V = (1 << 31); env->PSW_USB_SV = (1 << 31); /* ext_ret > MAX_INT */ if (mul >= 0) { result = INT64_MAX; /* ext_ret < MIN_INT */ result = INT64_MIN; } } if (ovf < 0) { env->PSW_USB_V = (1 << 31); env->PSW_USB_SV = (1 << 31); /* ext_ret > MAX_INT */ if (mul < 0) { result = INT64_MAX; /* ext_ret < MIN_INT */ result = INT64_MIN; } } } return (uint64_t)result; }


static void mtree_print_mr(fprintf_function mon_printf, void *f, const MemoryRegion *mr, unsigned int level, hwaddr base, MemoryRegionListHead *alias_print_queue) { MemoryRegionList *new_ml, *ml, *next_ml; MemoryRegionListHead submr_print_queue; const MemoryRegion *submr; unsigned int i; if (!mr) { return; } for (i = 0; i < level; i++) { mon_printf(f, MTREE_INDENT); } if (mr->alias) { MemoryRegionList *ml; bool found = false; /* check if the alias is already in the queue */ QTAILQ_FOREACH(ml, alias_print_queue, queue) { if (ml->mr == mr->alias) { found = true; } } if (!found) { ml = g_new(MemoryRegionList, 1); ml->mr = mr->alias; QTAILQ_INSERT_TAIL(alias_print_queue, ml, queue); } mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %s): alias %s @%s " TARGET_FMT_plx "-" TARGET_FMT_plx "%s\n", base + mr->addr, base + mr->addr + MR_SIZE(mr->size), mr->priority, memory_region_type((MemoryRegion *)mr), memory_region_name(mr), memory_region_name(mr->alias), mr->alias_offset, mr->alias_offset + MR_SIZE(mr->size), mr->enabled ? "" : " [disabled]"); } else { mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %s): %s%s\n", base + mr->addr, base + mr->addr + MR_SIZE(mr->size), mr->priority, memory_region_type((MemoryRegion *)mr), memory_region_name(mr), mr->enabled ? "" : " [disabled]"); } QTAILQ_INIT(&submr_print_queue); QTAILQ_FOREACH(submr, &mr->subregions, subregions_link) { new_ml = g_new(MemoryRegionList, 1); new_ml->mr = submr; QTAILQ_FOREACH(ml, &submr_print_queue, queue) { if (new_ml->mr->addr < ml->mr->addr || (new_ml->mr->addr == ml->mr->addr && new_ml->mr->priority > ml->mr->priority)) { QTAILQ_INSERT_BEFORE(ml, new_ml, queue); new_ml = NULL; break; } } if (new_ml) { QTAILQ_INSERT_TAIL(&submr_print_queue, new_ml, queue); } } QTAILQ_FOREACH(ml, &submr_print_queue, queue) { mtree_print_mr(mon_printf, f, ml->mr, level + 1, base + mr->addr, alias_print_queue); } QTAILQ_FOREACH_SAFE(ml, &submr_print_queue, queue, next_ml) { g_free(ml); } }


static uint64_t bonito_cop_readl(void *opaque, hwaddr addr, unsigned size) { uint32_t val; PCIBonitoState *s = opaque; val = ((uint32_t *)(&s->boncop))[addr/sizeof(uint32_t)]; return val;


static int vmdk_snapshot_create(const char *filename, const char *backing_file) { int snp_fd, p_fd; int ret; uint32_t p_cid; char *p_name, *gd_buf, *rgd_buf; const char *real_filename, *temp_str; VMDK4Header header; uint32_t gde_entries, gd_size; int64_t gd_offset, rgd_offset, capacity, gt_size; char p_desc[DESC_SIZE], s_desc[DESC_SIZE], hdr[HEADER_SIZE]; static const char desc_template[] = "# Disk DescriptorFile\n" "version=1\n" "CID=%x\n" "parentCID=%x\n" "createType=\"monolithicSparse\"\n" "parentFileNameHint=\"%s\"\n" "\n" "# Extent description\n" "RW %u SPARSE \"%s\"\n" "\n" "# The Disk Data Base \n" "#DDB\n" "\n"; snp_fd = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 0644); if (snp_fd < 0) return -errno; p_fd = open(backing_file, O_RDONLY | O_BINARY | O_LARGEFILE); if (p_fd < 0) { close(snp_fd); return -errno; } /* read the header */ if (lseek(p_fd, 0x0, SEEK_SET) == -1) { ret = -errno; goto fail; } if (read(p_fd, hdr, HEADER_SIZE) != HEADER_SIZE) { ret = -errno; goto fail; } /* write the header */ if (lseek(snp_fd, 0x0, SEEK_SET) == -1) { ret = -errno; goto fail; } if (write(snp_fd, hdr, HEADER_SIZE) == -1) { ret = -errno; goto fail; } memset(&header, 0, sizeof(header)); memcpy(&header,&hdr[4], sizeof(header)); // skip the VMDK4_MAGIC if (ftruncate(snp_fd, header.grain_offset << 9)) { ret = -errno; goto fail; } /* the descriptor offset = 0x200 */ if (lseek(p_fd, 0x200, SEEK_SET) == -1) { ret = -errno; goto fail; } if (read(p_fd, p_desc, DESC_SIZE) != DESC_SIZE) { ret = -errno; goto fail; } if ((p_name = strstr(p_desc,"CID")) != NULL) { p_name += sizeof("CID"); sscanf(p_name,"%x",&p_cid); } real_filename = filename; if ((temp_str = strrchr(real_filename, '\\')) != NULL) real_filename = temp_str + 1; if ((temp_str = strrchr(real_filename, '/')) != NULL) real_filename = temp_str + 1; if ((temp_str = strrchr(real_filename, ':')) != NULL) real_filename = temp_str + 1; snprintf(s_desc, sizeof(s_desc), desc_template, p_cid, p_cid, backing_file, (uint32_t)header.capacity, real_filename); /* write the descriptor */ if (lseek(snp_fd, 0x200, SEEK_SET) == -1) { ret = -errno; goto fail; } if (write(snp_fd, s_desc, strlen(s_desc)) == -1) { ret = -errno; goto fail; } gd_offset = header.gd_offset * SECTOR_SIZE; // offset of GD table rgd_offset = header.rgd_offset * SECTOR_SIZE; // offset of RGD table capacity = header.capacity * SECTOR_SIZE; // Extent size /* * Each GDE span 32M disk, means: * 512 GTE per GT, each GTE points to grain */ gt_size = (int64_t)header.num_gtes_per_gte * header.granularity * SECTOR_SIZE; if (!gt_size) { ret = -EINVAL; goto fail; } gde_entries = (uint32_t)(capacity / gt_size); // number of gde/rgde gd_size = gde_entries * sizeof(uint32_t); /* write RGD */ rgd_buf = qemu_malloc(gd_size); if (lseek(p_fd, rgd_offset, SEEK_SET) == -1) { ret = -errno; goto fail_rgd; } if (read(p_fd, rgd_buf, gd_size) != gd_size) { ret = -errno; goto fail_rgd; } if (lseek(snp_fd, rgd_offset, SEEK_SET) == -1) { ret = -errno; goto fail_rgd; } if (write(snp_fd, rgd_buf, gd_size) == -1) { ret = -errno; goto fail_rgd; } qemu_free(rgd_buf); /* write GD */ gd_buf = qemu_malloc(gd_size); if (lseek(p_fd, gd_offset, SEEK_SET) == -1) { ret = -errno; goto fail_gd; } if (read(p_fd, gd_buf, gd_size) != gd_size) { ret = -errno; goto fail_gd; } if (lseek(snp_fd, gd_offset, SEEK_SET) == -1) { ret = -errno; goto fail_gd; } if (write(snp_fd, gd_buf, gd_size) == -1) { ret = -errno; goto fail_gd; } qemu_free(gd_buf); close(p_fd); close(snp_fd); return 0; fail_gd: qemu_free(gd_buf); fail_rgd: qemu_free(rgd_buf); fail: close(p_fd); close(snp_fd); return ret; }


static void piix3_ide_xen_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->init = pci_piix_ide_initfn; k->vendor_id = PCI_VENDOR_ID_INTEL; k->device_id = PCI_DEVICE_ID_INTEL_82371SB_1; k->class_id = PCI_CLASS_STORAGE_IDE; set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); dc->no_user = 1; dc->unplug = pci_piix3_xen_ide_unplug; }


static int sami_paragraph_to_ass(AVCodecContext *avctx, const char *src) { SAMIContext *sami = avctx->priv_data; int ret = 0; char *tag = NULL; char *dupsrc = av_strdup(src); char *p = dupsrc; AVBPrint *dst_content = &sami->encoded_content; AVBPrint *dst_source = &sami->encoded_source; av_bprint_clear(&sami->encoded_content); av_bprint_clear(&sami->content); av_bprint_clear(&sami->encoded_source); for (;;) { char *saveptr = NULL; int prev_chr_is_space = 0; AVBPrint *dst = &sami->content; /* parse & extract paragraph tag */ p = av_stristr(p, "<P"); if (!p) break; if (p[2] != '>' && !av_isspace(p[2])) { // avoid confusion with tags such as <PRE> p++; continue; } if (dst->len) // add a separator with the previous paragraph if there was one av_bprintf(dst, "\\N"); tag = av_strtok(p, ">", &saveptr); if (!tag || !saveptr) break; p = saveptr; /* check if the current paragraph is the "source" (speaker name) */ if (av_stristr(tag, "ID=Source") || av_stristr(tag, "ID=\"Source\"")) { dst = &sami->source; av_bprint_clear(dst); } /* if empty event -> skip subtitle */ while (av_isspace(*p)) p++; if (!strncmp(p, " ", 6)) { ret = -1; goto end; } /* extract the text, stripping most of the tags */ while (*p) { if (*p == '<') { if (!av_strncasecmp(p, "<P", 2) && (p[2] == '>' || av_isspace(p[2]))) break; } if (!av_strncasecmp(p, "<BR", 3)) { av_bprintf(dst, "\\N"); p++; while (*p && *p != '>') p++; if (!*p) break; if (*p == '>') p++; continue; } if (!av_isspace(*p)) av_bprint_chars(dst, *p, 1); else if (!prev_chr_is_space) av_bprint_chars(dst, ' ', 1); prev_chr_is_space = av_isspace(*p); p++; } } av_bprint_clear(&sami->full); if (sami->source.len) { ret = ff_htmlmarkup_to_ass(avctx, dst_source, sami->source.str); if (ret < 0) goto end; av_bprintf(&sami->full, "{\\i1}%s{\\i0}\\N", sami->encoded_source.str); } ret = ff_htmlmarkup_to_ass(avctx, dst_content, sami->content.str); if (ret < 0) goto end; av_bprintf(&sami->full, "%s", sami->encoded_content.str); end: av_free(dupsrc); return ret; }


static void reset_codec(WmallDecodeCtx *s) { int ich, ilms; s->mclms_recent = s->mclms_order * s->num_channels; for (ich = 0; ich < s->num_channels; ich++) { for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++) s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order; /* first sample of a seekable subframe is considered as the starting of a transient area which is samples_per_frame samples long */ s->channel[ich].transient_counter = s->samples_per_frame; s->transient[ich] = 1; } }


static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid, int read) { AVCodecContext *vcodec = vstream->codec; switch(flv_codecid) { case FLV_CODECID_H263 : vcodec->codec_id = AV_CODEC_ID_FLV1 ; break; case FLV_CODECID_SCREEN: vcodec->codec_id = AV_CODEC_ID_FLASHSV; break; case FLV_CODECID_SCREEN2: vcodec->codec_id = AV_CODEC_ID_FLASHSV2; break; case FLV_CODECID_VP6 : vcodec->codec_id = AV_CODEC_ID_VP6F ; case FLV_CODECID_VP6A : if(flv_codecid == FLV_CODECID_VP6A) vcodec->codec_id = AV_CODEC_ID_VP6A; if (read) { if (vcodec->extradata_size != 1) { vcodec->extradata_size = 1; vcodec->extradata = av_malloc(1); } vcodec->extradata[0] = avio_r8(s->pb); } return 1; // 1 byte body size adjustment for flv_read_packet() case FLV_CODECID_H264: vcodec->codec_id = AV_CODEC_ID_H264; return 3; // not 4, reading packet type will consume one byte default: av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid); vcodec->codec_tag = flv_codecid; } return 0; }


float64 float64_scalbn( float64 a, int n STATUS_PARAM ) { flag aSign; int16 aExp; uint64_t aSig; a = float64_squash_input_denormal(a STATUS_VAR); aSig = extractFloat64Frac( a ); aExp = extractFloat64Exp( a ); aSign = extractFloat64Sign( a ); if ( aExp == 0x7FF ) { return a; } if ( aExp != 0 ) aSig |= LIT64( 0x0010000000000000 ); else if ( aSig == 0 ) return a; aExp += n - 1; aSig <<= 10; return normalizeRoundAndPackFloat64( aSign, aExp, aSig STATUS_VAR ); }


static int postcopy_start(MigrationState *ms, bool *old_vm_running) { int ret; QIOChannelBuffer *bioc; QEMUFile *fb; int64_t time_at_stop = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); bool restart_block = false; int cur_state = MIGRATION_STATUS_ACTIVE; if (!migrate_pause_before_switchover()) { migrate_set_state(&ms->state, MIGRATION_STATUS_ACTIVE, MIGRATION_STATUS_POSTCOPY_ACTIVE); } trace_postcopy_start(); qemu_mutex_lock_iothread(); trace_postcopy_start_set_run(); qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); *old_vm_running = runstate_is_running(); global_state_store(); ret = vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); if (ret < 0) { goto fail; } ret = migration_maybe_pause(ms, &cur_state, MIGRATION_STATUS_POSTCOPY_ACTIVE); if (ret < 0) { goto fail; } ret = bdrv_inactivate_all(); if (ret < 0) { goto fail; } restart_block = true; /* * Cause any non-postcopiable, but iterative devices to * send out their final data. */ qemu_savevm_state_complete_precopy(ms->to_dst_file, true, false); /* * in Finish migrate and with the io-lock held everything should * be quiet, but we've potentially still got dirty pages and we * need to tell the destination to throw any pages it's already received * that are dirty */ if (migrate_postcopy_ram()) { if (ram_postcopy_send_discard_bitmap(ms)) { error_report("postcopy send discard bitmap failed"); goto fail; } } /* * send rest of state - note things that are doing postcopy * will notice we're in POSTCOPY_ACTIVE and not actually * wrap their state up here */ qemu_file_set_rate_limit(ms->to_dst_file, INT64_MAX); if (migrate_postcopy_ram()) { /* Ping just for debugging, helps line traces up */ qemu_savevm_send_ping(ms->to_dst_file, 2); } /* * While loading the device state we may trigger page transfer * requests and the fd must be free to process those, and thus * the destination must read the whole device state off the fd before * it starts processing it. Unfortunately the ad-hoc migration format * doesn't allow the destination to know the size to read without fully * parsing it through each devices load-state code (especially the open * coded devices that use get/put). * So we wrap the device state up in a package with a length at the start; * to do this we use a qemu_buf to hold the whole of the device state. */ bioc = qio_channel_buffer_new(4096); qio_channel_set_name(QIO_CHANNEL(bioc), "migration-postcopy-buffer"); fb = qemu_fopen_channel_output(QIO_CHANNEL(bioc)); object_unref(OBJECT(bioc)); /* * Make sure the receiver can get incoming pages before we send the rest * of the state */ qemu_savevm_send_postcopy_listen(fb); qemu_savevm_state_complete_precopy(fb, false, false); if (migrate_postcopy_ram()) { qemu_savevm_send_ping(fb, 3); } qemu_savevm_send_postcopy_run(fb); /* <><> end of stuff going into the package */ /* Last point of recovery; as soon as we send the package the destination * can open devices and potentially start running. * Lets just check again we've not got any errors. */ ret = qemu_file_get_error(ms->to_dst_file); if (ret) { error_report("postcopy_start: Migration stream errored (pre package)"); goto fail_closefb; } restart_block = false; /* Now send that blob */ if (qemu_savevm_send_packaged(ms->to_dst_file, bioc->data, bioc->usage)) { goto fail_closefb; } qemu_fclose(fb); /* Send a notify to give a chance for anything that needs to happen * at the transition to postcopy and after the device state; in particular * spice needs to trigger a transition now */ ms->postcopy_after_devices = true; notifier_list_notify(&migration_state_notifiers, ms); ms->downtime = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - time_at_stop; qemu_mutex_unlock_iothread(); if (migrate_postcopy_ram()) { /* * Although this ping is just for debug, it could potentially be * used for getting a better measurement of downtime at the source. */ qemu_savevm_send_ping(ms->to_dst_file, 4); } if (migrate_release_ram()) { ram_postcopy_migrated_memory_release(ms); } ret = qemu_file_get_error(ms->to_dst_file); if (ret) { error_report("postcopy_start: Migration stream errored"); migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, MIGRATION_STATUS_FAILED); } return ret; fail_closefb: qemu_fclose(fb); fail: migrate_set_state(&ms->state, MIGRATION_STATUS_POSTCOPY_ACTIVE, MIGRATION_STATUS_FAILED); if (restart_block) { /* A failure happened early enough that we know the destination hasn't * accessed block devices, so we're safe to recover. */ Error *local_err = NULL; bdrv_invalidate_cache_all(&local_err); if (local_err) { error_report_err(local_err); } } qemu_mutex_unlock_iothread(); return -1; }


static BusState *qbus_find(const char *path) { DeviceState *dev; BusState *bus; char elem[128]; int pos, len; /* find start element */ if (path[0] == '/') { bus = sysbus_get_default(); pos = 0; } else { if (sscanf(path, "%127[^/]%n", elem, &len) != 1) { assert(!path[0]); elem[0] = len = 0; } bus = qbus_find_recursive(sysbus_get_default(), elem, NULL); if (!bus) { qerror_report(QERR_BUS_NOT_FOUND, elem); return NULL; } else if (qbus_is_full(bus)) { qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full", elem); return NULL; } pos = len; } for (;;) { assert(path[pos] == '/' || !path[pos]); while (path[pos] == '/') { pos++; } if (path[pos] == '\0') { return bus; } /* find device */ if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) { g_assert_not_reached(); elem[0] = len = 0; } pos += len; dev = qbus_find_dev(bus, elem); if (!dev) { qerror_report(QERR_DEVICE_NOT_FOUND, elem); if (!monitor_cur_is_qmp()) { qbus_list_dev(bus); } return NULL; } assert(path[pos] == '/' || !path[pos]); while (path[pos] == '/') { pos++; } if (path[pos] == '\0') { /* last specified element is a device. If it has exactly * one child bus accept it nevertheless */ switch (dev->num_child_bus) { case 0: qerror_report(ERROR_CLASS_GENERIC_ERROR, "Device '%s' has no child bus", elem); return NULL; case 1: return QLIST_FIRST(&dev->child_bus); default: qerror_report(ERROR_CLASS_GENERIC_ERROR, "Device '%s' has multiple child busses", elem); if (!monitor_cur_is_qmp()) { qbus_list_bus(dev); } return NULL; } } /* find bus */ if (sscanf(path+pos, "%127[^/]%n", elem, &len) != 1) { g_assert_not_reached(); elem[0] = len = 0; } pos += len; bus = qbus_find_bus(dev, elem); if (!bus) { qerror_report(QERR_BUS_NOT_FOUND, elem); if (!monitor_cur_is_qmp()) { qbus_list_bus(dev); } return NULL; } } }


void bdrv_init(void) { bdrv_register(&bdrv_raw); bdrv_register(&bdrv_host_device); bdrv_register(&bdrv_cow); bdrv_register(&bdrv_qcow); bdrv_register(&bdrv_vmdk); bdrv_register(&bdrv_cloop); bdrv_register(&bdrv_dmg); bdrv_register(&bdrv_bochs); bdrv_register(&bdrv_vpc); bdrv_register(&bdrv_vvfat); bdrv_register(&bdrv_qcow2); bdrv_register(&bdrv_parallels); bdrv_register(&bdrv_nbd); }


void ff_h264_direct_dist_scale_factor(H264Context * const h){ const int poc = h->cur_pic_ptr->field_poc[h->picture_structure == PICT_BOTTOM_FIELD]; const int poc1 = h->ref_list[1][0].poc; int i, field; if (FRAME_MBAFF(h)) for (field = 0; field < 2; field++){ const int poc = h->cur_pic_ptr->field_poc[field]; const int poc1 = h->ref_list[1][0].field_poc[field]; for (i = 0; i < 2 * h->ref_count[0]; i++) h->dist_scale_factor_field[field][i^field] = get_scale_factor(h, poc, poc1, i+16); } for (i = 0; i < h->ref_count[0]; i++){ h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i); } }


static void virtio_net_handle_tx_bh(VirtIODevice *vdev, VirtQueue *vq) { VirtIONet *n = to_virtio_net(vdev); if (unlikely(n->tx_waiting)) { return; } virtio_queue_set_notification(vq, 0); qemu_bh_schedule(n->tx_bh); n->tx_waiting = 1; }


static int net_dump_init(NetClientState *peer, const char *device, const char *name, const char *filename, int len) { struct pcap_file_hdr hdr; NetClientState *nc; DumpState *s; struct tm tm; int fd; fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0644); if (fd < 0) { error_report("-net dump: can't open %s", filename); return -1; } hdr.magic = PCAP_MAGIC; hdr.version_major = 2; hdr.version_minor = 4; hdr.thiszone = 0; hdr.sigfigs = 0; hdr.snaplen = len; hdr.linktype = 1; if (write(fd, &hdr, sizeof(hdr)) < sizeof(hdr)) { error_report("-net dump write error: %s", strerror(errno)); close(fd); return -1; } nc = qemu_new_net_client(&net_dump_info, peer, device, name); snprintf(nc->info_str, sizeof(nc->info_str), "dump to %s (len=%d)", filename, len); s = DO_UPCAST(DumpState, nc, nc); s->fd = fd; s->pcap_caplen = len; qemu_get_timedate(&tm, 0); s->start_ts = mktime(&tm); return 0; }


AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms, enum AVSampleFormat sample_fmt, int size, int64_t channel_layout, int planar) { AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); AVFilterBufferRef *ref = NULL; int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0; char *buf; if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef)))) goto fail; ref->buf = samples; ref->format = sample_fmt; ref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps)); if (!ref->audio) goto fail; ref->audio->channel_layout = channel_layout; ref->audio->size = size; ref->audio->planar = planar; /* make sure the buffer gets read permission or it's useless for output */ ref->perms = perms | AV_PERM_READ; samples->refcount = 1; samples->free = ff_avfilter_default_free_buffer; sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3; chans_nb = av_get_channel_layout_nb_channels(channel_layout); per_channel_size = size/chans_nb; ref->audio->nb_samples = per_channel_size/sample_size; /* Set the number of bytes to traverse to reach next sample of a particular channel: * For planar, this is simply the sample size. * For packed, this is the number of samples * sample_size. */ for (i = 0; i < chans_nb; i++) samples->linesize[i] = planar > 0 ? per_channel_size : sample_size; memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0])); /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */ bufsize = (size + 15)&~15; buf = av_malloc(bufsize); if (!buf) goto fail; /* For planar, set the start point of each channel's data within the buffer * For packed, set the start point of the entire buffer only */ samples->data[0] = buf; if (buf && planar) { for (i = 1; i < chans_nb; i++) { step_size += per_channel_size; samples->data[i] = buf + step_size; } } else { for (i = 1; i < chans_nb; i++) samples->data[i] = buf; } memset(&samples->data[chans_nb], 0, (8-chans_nb) * sizeof(samples->data[0])); memcpy(ref->data, samples->data, sizeof(ref->data)); memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize)); return ref; fail: av_free(buf); if (ref && ref->audio) av_free(ref->audio); av_free(ref); av_free(samples); return NULL; }


static void test_keyval_visit_any(void) { Visitor *v; QDict *qdict; QObject *any; QList *qlist; QString *qstr; qdict = keyval_parse("a.0=null,a.1=1", NULL, &error_abort); v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); QDECREF(qdict); visit_start_struct(v, NULL, NULL, 0, &error_abort); visit_type_any(v, "a", &any, &error_abort); qlist = qobject_to_qlist(any); g_assert(qlist); qstr = qobject_to_qstring(qlist_pop(qlist)); g_assert_cmpstr(qstring_get_str(qstr), ==, "null"); qstr = qobject_to_qstring(qlist_pop(qlist)); g_assert_cmpstr(qstring_get_str(qstr), ==, "1"); g_assert(qlist_empty(qlist)); visit_check_struct(v, &error_abort); visit_end_struct(v, NULL); visit_free(v); }


static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n, int coded, int codingset, int mquant) { GetBitContext *gb = &v->s.gb; MpegEncContext *s = &v->s; int dc_pred_dir = 0; /* Direction of the DC prediction used */ int i; int16_t *dc_val; int16_t *ac_val, *ac_val2; int dcdiff; int a_avail = v->a_avail, c_avail = v->c_avail; int use_pred = s->ac_pred; int scale; int q1, q2 = 0; int mb_pos = s->mb_x + s->mb_y * s->mb_stride; /* Get DC differential */ if (n < 4) { dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); } else { dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); } if (dcdiff < 0) { av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n"); return -1; } if (dcdiff) { if (dcdiff == 119 /* ESC index value */) { /* TODO: Optimize */ if (mquant == 1) dcdiff = get_bits(gb, 10); else if (mquant == 2) dcdiff = get_bits(gb, 9); else dcdiff = get_bits(gb, 8); } else { if (mquant == 1) dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3; else if (mquant == 2) dcdiff = (dcdiff << 1) + get_bits1(gb) - 1; } if (get_bits1(gb)) dcdiff = -dcdiff; } /* Prediction */ dcdiff += vc1_pred_dc(&v->s, v->overlap, mquant, n, v->a_avail, v->c_avail, &dc_val, &dc_pred_dir); *dc_val = dcdiff; /* Store the quantized DC coeff, used for prediction */ if (n < 4) { block[0] = dcdiff * s->y_dc_scale; } else { block[0] = dcdiff * s->c_dc_scale; } //AC Decoding i = 1; /* check if AC is needed at all */ if (!a_avail && !c_avail) use_pred = 0; ac_val = s->ac_val[0][0] + s->block_index[n] * 16; ac_val2 = ac_val; scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0); if (dc_pred_dir) // left ac_val -= 16; else // top ac_val -= 16 * s->block_wrap[n]; q1 = s->current_picture.f.qscale_table[mb_pos]; if ( dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.f.qscale_table[mb_pos - 1]; if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride]; if ( dc_pred_dir && n == 1) q2 = q1; if (!dc_pred_dir && n == 2) q2 = q1; if (n == 3) q2 = q1; if (coded) { int last = 0, skip, value; const uint8_t *zz_table; int k; if (v->s.ac_pred) { if (!use_pred && v->fcm == ILACE_FRAME) { zz_table = v->zzi_8x8; } else { if (!dc_pred_dir) // top zz_table = v->zz_8x8[2]; else // left zz_table = v->zz_8x8[3]; } } else { if (v->fcm != ILACE_FRAME) zz_table = v->zz_8x8[1]; else zz_table = v->zzi_8x8; } while (!last) { vc1_decode_ac_coeff(v, &last, &skip, &value, codingset); i += skip; if (i > 63) break; block[zz_table[i++]] = value; } /* apply AC prediction if needed */ if (use_pred) { /* scale predictors if needed*/ if (q2 && q1 != q2) { q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; if (q1 < 1) return AVERROR_INVALIDDATA; if (dc_pred_dir) { // left for (k = 1; k < 8; k++) block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } else { // top for (k = 1; k < 8; k++) block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } else { if (dc_pred_dir) { //left for (k = 1; k < 8; k++) block[k << v->left_blk_sh] += ac_val[k]; } else { //top for (k = 1; k < 8; k++) block[k << v->top_blk_sh] += ac_val[k + 8]; } } } /* save AC coeffs for further prediction */ for (k = 1; k < 8; k++) { ac_val2[k ] = block[k << v->left_blk_sh]; ac_val2[k + 8] = block[k << v->top_blk_sh]; } /* scale AC coeffs */ for (k = 1; k < 64; k++) if (block[k]) { block[k] *= scale; if (!v->pquantizer) block[k] += (block[k] < 0) ? -mquant : mquant; } if (use_pred) i = 63; } else { // no AC coeffs int k; memset(ac_val2, 0, 16 * 2); if (dc_pred_dir) { // left if (use_pred) { memcpy(ac_val2, ac_val, 8 * 2); if (q2 && q1 != q2) { q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; if (q1 < 1) return AVERROR_INVALIDDATA; for (k = 1; k < 8; k++) ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } } else { // top if (use_pred) { memcpy(ac_val2 + 8, ac_val + 8, 8 * 2); if (q2 && q1 != q2) { q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; if (q1 < 1) return AVERROR_INVALIDDATA; for (k = 1; k < 8; k++) ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } } /* apply AC prediction if needed */ if (use_pred) { if (dc_pred_dir) { // left for (k = 1; k < 8; k++) { block[k << v->left_blk_sh] = ac_val2[k] * scale; if (!v->pquantizer && block[k << v->left_blk_sh]) block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant; } } else { // top for (k = 1; k < 8; k++) { block[k << v->top_blk_sh] = ac_val2[k + 8] * scale; if (!v->pquantizer && block[k << v->top_blk_sh]) block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant; } } i = 63; } } s->block_last_index[n] = i; return 0; }


static int crc_write_packet(struct AVFormatContext *s, int stream_index, const uint8_t *buf, int size, int64_t pts) { CRCState *crc = s->priv_data; crc->crcval = adler32(crc->crcval, buf, size); return 0; }


void kvm_arch_update_guest_debug(CPUState *cpu, struct kvm_guest_debug *dbg) { }


static void do_subtitle_out(AVFormatContext *s, OutputStream *ost, InputStream *ist, AVSubtitle *sub) { int subtitle_out_max_size = 1024 * 1024; int subtitle_out_size, nb, i; AVCodecContext *enc; AVPacket pkt; int64_t pts; if (sub->pts == AV_NOPTS_VALUE) { av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n"); if (exit_on_error) exit_program(1); return; } enc = ost->enc_ctx; if (!subtitle_out) { subtitle_out = av_malloc(subtitle_out_max_size); } /* Note: DVB subtitle need one packet to draw them and one other packet to clear them */ /* XXX: signal it in the codec context ? */ if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) nb = 2; else nb = 1; /* shift timestamp to honor -ss and make check_recording_time() work with -t */ pts = sub->pts; if (output_files[ost->file_index]->start_time != AV_NOPTS_VALUE) pts -= output_files[ost->file_index]->start_time; for (i = 0; i < nb; i++) { ost->sync_opts = av_rescale_q(pts, AV_TIME_BASE_Q, enc->time_base); if (!check_recording_time(ost)) return; sub->pts = pts; // start_display_time is required to be 0 sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q); sub->end_display_time -= sub->start_display_time; sub->start_display_time = 0; if (i == 1) sub->num_rects = 0; ost->frames_encoded++; subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, subtitle_out_max_size, sub); if (i == 1) sub->num_rects = save_num_rects; if (subtitle_out_size < 0) { av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n"); exit_program(1); } av_init_packet(&pkt); pkt.data = subtitle_out; pkt.size = subtitle_out_size; pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base); pkt.duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, ost->st->time_base); if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { /* XXX: the pts correction is handled here. Maybe handling it in the codec would be better */ if (i == 0) pkt.pts += 90 * sub->start_display_time; else pkt.pts += 90 * sub->end_display_time; } pkt.dts = pkt.pts; write_frame(s, &pkt, ost); } }


static uint32_t uhci_ioport_readw(void *opaque, uint32_t addr) { UHCIState *s = opaque; uint32_t val; addr &= 0x1f; switch(addr) { case 0x00: val = s->cmd; break; case 0x02: val = s->status; break; case 0x04: val = s->intr; break; case 0x06: val = s->frnum; break; case 0x10 ... 0x1f: { UHCIPort *port; int n; n = (addr >> 1) & 7; if (n >= NB_PORTS) goto read_default; port = &s->ports[n]; val = port->ctrl; } break; default: read_default: val = 0xff7f; /* disabled port */ break; } #ifdef DEBUG printf("uhci readw port=0x%04x val=0x%04x\n", addr, val); #endif return val; }


cac_delete_pki_applet_private(VCardAppletPrivate *applet_private) { CACPKIAppletData *pki_applet_data = NULL; if (applet_private == NULL) { return; } pki_applet_data = &(applet_private->u.pki_data); if (pki_applet_data->cert != NULL) { g_free(pki_applet_data->cert); } if (pki_applet_data->sign_buffer != NULL) { g_free(pki_applet_data->sign_buffer); } if (pki_applet_data->key != NULL) { vcard_emul_delete_key(pki_applet_data->key); } g_free(applet_private); }


static void cpu_handle_debug_exception(CPUState *env) { CPUWatchpoint *wp; if (!env->watchpoint_hit) TAILQ_FOREACH(wp, &env->watchpoints, entry) wp->flags &= ~BP_WATCHPOINT_HIT; if (debug_excp_handler) debug_excp_handler(env); }


static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t count, int flags, int64_t *total) { Coroutine *co; CoWriteZeroes data = { .blk = blk, .offset = offset, .count = count, .total = total, .flags = flags, .done = false, }; if (count >> BDRV_SECTOR_BITS > INT_MAX) { return -ERANGE; } co = qemu_coroutine_create(co_pwrite_zeroes_entry, &data); qemu_coroutine_enter(co); while (!data.done) { aio_poll(blk_get_aio_context(blk), true); } if (data.ret < 0) { return data.ret; } else { return 1; } }


static inline void cow_set_bits(uint8_t *bitmap, int start, int64_t nb_sectors) { int64_t bitnum = start, last = start + nb_sectors; while (bitnum < last) { if ((bitnum & 7) == 0 && bitnum + 8 <= last) { bitmap[bitnum / 8] = 0xFF; bitnum += 8; continue; } bitmap[bitnum/8] |= (1 << (bitnum % 8)); bitnum++; } }


int bdrv_open2(BlockDriverState *bs, const char *filename, int flags, BlockDriver *drv) { int ret, open_flags; char tmp_filename[PATH_MAX]; char backing_filename[PATH_MAX]; bs->is_temporary = 0; bs->encrypted = 0; bs->valid_key = 0; /* buffer_alignment defaulted to 512, drivers can change this value */ bs->buffer_alignment = 512; if (flags & BDRV_O_SNAPSHOT) { BlockDriverState *bs1; int64_t total_size; int is_protocol = 0; BlockDriver *bdrv_qcow2; QEMUOptionParameter *options; /* if snapshot, we create a temporary backing file and open it instead of opening 'filename' directly */ /* if there is a backing file, use it */ bs1 = bdrv_new(""); ret = bdrv_open2(bs1, filename, 0, drv); if (ret < 0) { bdrv_delete(bs1); return ret; } total_size = bdrv_getlength(bs1) >> BDRV_SECTOR_BITS; if (bs1->drv && bs1->drv->protocol_name) is_protocol = 1; bdrv_delete(bs1); get_tmp_filename(tmp_filename, sizeof(tmp_filename)); /* Real path is meaningless for protocols */ if (is_protocol) snprintf(backing_filename, sizeof(backing_filename), "%s", filename); else if (!realpath(filename, backing_filename)) return -errno; bdrv_qcow2 = bdrv_find_format("qcow2"); options = parse_option_parameters("", bdrv_qcow2->create_options, NULL); set_option_parameter_int(options, BLOCK_OPT_SIZE, total_size * 512); set_option_parameter(options, BLOCK_OPT_BACKING_FILE, backing_filename); if (drv) { set_option_parameter(options, BLOCK_OPT_BACKING_FMT, drv->format_name); } ret = bdrv_create(bdrv_qcow2, tmp_filename, options); if (ret < 0) { return ret; } filename = tmp_filename; drv = bdrv_qcow2; bs->is_temporary = 1; } pstrcpy(bs->filename, sizeof(bs->filename), filename); if (flags & BDRV_O_FILE) { drv = find_protocol(filename); } else if (!drv) { drv = find_hdev_driver(filename); if (!drv) { drv = find_image_format(filename); } } if (!drv) { ret = -ENOENT; goto unlink_and_fail; } bs->drv = drv; bs->opaque = qemu_mallocz(drv->instance_size); /* * Yes, BDRV_O_NOCACHE aka O_DIRECT means we have to present a * write cache to the guest. We do need the fdatasync to flush * out transactions for block allocations, and we maybe have a * volatile write cache in our backing device to deal with. */ if (flags & (BDRV_O_CACHE_WB|BDRV_O_NOCACHE)) bs->enable_write_cache = 1; bs->read_only = (flags & BDRV_O_RDWR) == 0; if (!(flags & BDRV_O_FILE)) { open_flags = (flags & (BDRV_O_RDWR | BDRV_O_CACHE_MASK|BDRV_O_NATIVE_AIO)); if (bs->is_temporary) { /* snapshot should be writeable */ open_flags |= BDRV_O_RDWR; } } else { open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT); } if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) { ret = -ENOTSUP; } else { ret = drv->bdrv_open(bs, filename, open_flags); } if (ret < 0) { qemu_free(bs->opaque); bs->opaque = NULL; bs->drv = NULL; unlink_and_fail: if (bs->is_temporary) unlink(filename); return ret; } if (drv->bdrv_getlength) { bs->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS; } #ifndef _WIN32 if (bs->is_temporary) { unlink(filename); } #endif if ((flags & BDRV_O_NO_BACKING) == 0 && bs->backing_file[0] != '\0') { /* if there is a backing file, use it */ BlockDriver *back_drv = NULL; bs->backing_hd = bdrv_new(""); path_combine(backing_filename, sizeof(backing_filename), filename, bs->backing_file); if (bs->backing_format[0] != '\0') back_drv = bdrv_find_format(bs->backing_format); ret = bdrv_open2(bs->backing_hd, backing_filename, open_flags, back_drv); bs->backing_hd->read_only = (open_flags & BDRV_O_RDWR) == 0; if (ret < 0) { bdrv_close(bs); return ret; } } if (!bdrv_key_required(bs)) { /* call the change callback */ bs->media_changed = 1; if (bs->change_cb) bs->change_cb(bs->change_opaque); } return 0; }


milkymist_init(QEMUMachineInitArgs *args) { const char *cpu_model = args->cpu_model; const char *kernel_filename = args->kernel_filename; const char *kernel_cmdline = args->kernel_cmdline; const char *initrd_filename = args->initrd_filename; LM32CPU *cpu; CPULM32State *env; int kernel_size; DriveInfo *dinfo; MemoryRegion *address_space_mem = get_system_memory(); MemoryRegion *phys_sdram = g_new(MemoryRegion, 1); qemu_irq irq[32], *cpu_irq; int i; char *bios_filename; ResetInfo *reset_info; /* memory map */ target_phys_addr_t flash_base = 0x00000000; size_t flash_sector_size = 128 * 1024; size_t flash_size = 32 * 1024 * 1024; target_phys_addr_t sdram_base = 0x40000000; size_t sdram_size = 128 * 1024 * 1024; target_phys_addr_t initrd_base = sdram_base + 0x1002000; target_phys_addr_t cmdline_base = sdram_base + 0x1000000; size_t initrd_max = sdram_size - 0x1002000; reset_info = g_malloc0(sizeof(ResetInfo)); if (cpu_model == NULL) { cpu_model = "lm32-full"; } cpu = cpu_lm32_init(cpu_model); env = &cpu->env; reset_info->cpu = cpu; cpu_lm32_set_phys_msb_ignore(env, 1); memory_region_init_ram(phys_sdram, "milkymist.sdram", sdram_size); vmstate_register_ram_global(phys_sdram); memory_region_add_subregion(address_space_mem, sdram_base, phys_sdram); dinfo = drive_get(IF_PFLASH, 0, 0); /* Numonyx JS28F256J3F105 */ pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size, dinfo ? dinfo->bdrv : NULL, flash_sector_size, flash_size / flash_sector_size, 2, 0x00, 0x89, 0x00, 0x1d, 1); /* create irq lines */ cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1); env->pic_state = lm32_pic_init(*cpu_irq); for (i = 0; i < 32; i++) { irq[i] = qdev_get_gpio_in(env->pic_state, i); } /* load bios rom */ if (bios_name == NULL) { bios_name = BIOS_FILENAME; } bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); if (bios_filename) { load_image_targphys(bios_filename, BIOS_OFFSET, BIOS_SIZE); } reset_info->bootstrap_pc = BIOS_OFFSET; /* if no kernel is given no valid bios rom is a fatal error */ if (!kernel_filename && !dinfo && !bios_filename) { fprintf(stderr, "qemu: could not load Milkymist One bios '%s'\n", bios_name); exit(1); } milkymist_uart_create(0x60000000, irq[0]); milkymist_sysctl_create(0x60001000, irq[1], irq[2], irq[3], 80000000, 0x10014d31, 0x0000041f, 0x00000001); milkymist_hpdmc_create(0x60002000); milkymist_vgafb_create(0x60003000, 0x40000000, 0x0fffffff); milkymist_memcard_create(0x60004000); milkymist_ac97_create(0x60005000, irq[4], irq[5], irq[6], irq[7]); milkymist_pfpu_create(0x60006000, irq[8]); milkymist_tmu2_create(0x60007000, irq[9]); milkymist_minimac2_create(0x60008000, 0x30000000, irq[10], irq[11]); milkymist_softusb_create(0x6000f000, irq[15], 0x20000000, 0x1000, 0x20020000, 0x2000); /* make sure juart isn't the first chardev */ env->juart_state = lm32_juart_init(); if (kernel_filename) { uint64_t entry; /* Boots a kernel elf binary. */ kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL, 1, ELF_MACHINE, 0); reset_info->bootstrap_pc = entry; if (kernel_size < 0) { kernel_size = load_image_targphys(kernel_filename, sdram_base, sdram_size); reset_info->bootstrap_pc = sdram_base; } if (kernel_size < 0) { fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename); exit(1); } } if (kernel_cmdline && strlen(kernel_cmdline)) { pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline); reset_info->cmdline_base = (uint32_t)cmdline_base; } if (initrd_filename) { size_t initrd_size; initrd_size = load_image_targphys(initrd_filename, initrd_base, initrd_max); reset_info->initrd_base = (uint32_t)initrd_base; reset_info->initrd_size = (uint32_t)initrd_size; } qemu_register_reset(main_cpu_reset, reset_info); }


static int aac_decode_frame_int(AVCodecContext *avctx, void *data, int *got_frame_ptr, GetBitContext *gb, AVPacket *avpkt) { AACContext *ac = avctx->priv_data; ChannelElement *che = NULL, *che_prev = NULL; enum RawDataBlockType elem_type, elem_type_prev = TYPE_END; int err, elem_id; int samples = 0, multiplier, audio_found = 0, pce_found = 0; int is_dmono, sce_count = 0; ac->frame = data; if (show_bits(gb, 12) == 0xfff) { if (parse_adts_frame_header(ac, gb) < 0) { av_log(avctx, AV_LOG_ERROR, "Error decoding AAC frame header.\n"); err = -1; goto fail; } if (ac->oc[1].m4ac.sampling_index > 12) { av_log(ac->avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", ac->oc[1].m4ac.sampling_index); err = -1; goto fail; } } if (frame_configure_elements(avctx) < 0) { err = -1; goto fail; } ac->tags_mapped = 0; // parse while ((elem_type = get_bits(gb, 3)) != TYPE_END) { elem_id = get_bits(gb, 4); if (elem_type < TYPE_DSE) { if (!(che=get_che(ac, elem_type, elem_id))) { av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id); err = -1; goto fail; } samples = 1024; } switch (elem_type) { case TYPE_SCE: err = decode_ics(ac, &che->ch[0], gb, 0, 0); audio_found = 1; sce_count++; break; case TYPE_CPE: err = decode_cpe(ac, gb, che); audio_found = 1; break; case TYPE_CCE: err = decode_cce(ac, gb, che); break; case TYPE_LFE: err = decode_ics(ac, &che->ch[0], gb, 0, 0); audio_found = 1; break; case TYPE_DSE: err = skip_data_stream_element(ac, gb); break; case TYPE_PCE: { uint8_t layout_map[MAX_ELEM_ID*4][3]; int tags; push_output_configuration(ac); tags = decode_pce(avctx, &ac->oc[1].m4ac, layout_map, gb); if (tags < 0) { err = tags; break; } if (pce_found) { av_log(avctx, AV_LOG_ERROR, "Not evaluating a further program_config_element as this construct is dubious at best.\n"); pop_output_configuration(ac); } else { err = output_configure(ac, layout_map, tags, OC_TRIAL_PCE, 1); if (!err) ac->oc[1].m4ac.chan_config = 0; pce_found = 1; } break; } case TYPE_FIL: if (elem_id == 15) elem_id += get_bits(gb, 8) - 1; if (get_bits_left(gb) < 8 * elem_id) { av_log(avctx, AV_LOG_ERROR, "TYPE_FIL: "overread_err); err = -1; goto fail; } while (elem_id > 0) elem_id -= decode_extension_payload(ac, gb, elem_id, che_prev, elem_type_prev); err = 0; /* FIXME */ break; default: err = -1; /* should not happen, but keeps compiler happy */ break; } che_prev = che; elem_type_prev = elem_type; if (err) goto fail; if (get_bits_left(gb) < 3) { av_log(avctx, AV_LOG_ERROR, overread_err); err = -1; goto fail; } } spectral_to_sample(ac); multiplier = (ac->oc[1].m4ac.sbr == 1) ? ac->oc[1].m4ac.ext_sample_rate > ac->oc[1].m4ac.sample_rate : 0; samples <<= multiplier; /* for dual-mono audio (SCE + SCE) */ is_dmono = ac->dmono_mode && sce_count == 2 && ac->oc[1].channel_layout == (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT); if (samples) ac->frame->nb_samples = samples; *got_frame_ptr = !!samples; if (is_dmono) { if (ac->dmono_mode == 1) ((AVFrame *)data)->data[1] =((AVFrame *)data)->data[0]; else if (ac->dmono_mode == 2) ((AVFrame *)data)->data[0] =((AVFrame *)data)->data[1]; } if (ac->oc[1].status && audio_found) { avctx->sample_rate = ac->oc[1].m4ac.sample_rate << multiplier; avctx->frame_size = samples; ac->oc[1].status = OC_LOCKED; } if (multiplier) { int side_size; uint32_t *side = av_packet_get_side_data(avpkt, AV_PKT_DATA_SKIP_SAMPLES, &side_size); if (side && side_size>=4) AV_WL32(side, 2*AV_RL32(side)); } return 0; fail: pop_output_configuration(ac); return err; }


void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, const char *boot_device, BusState *idebus0, BusState *idebus1, FDCtrl *floppy_controller, ISADevice *s) { int val, nb; FDriveType fd0, fd1; static pc_cmos_init_late_arg arg; /* various important CMOS locations needed by PC/Bochs bios */ /* memory size */ val = 640; /* base memory in K */ rtc_set_memory(s, 0x15, val); rtc_set_memory(s, 0x16, val >> 8); val = (ram_size / 1024) - 1024; if (val > 65535) val = 65535; rtc_set_memory(s, 0x17, val); rtc_set_memory(s, 0x18, val >> 8); rtc_set_memory(s, 0x30, val); rtc_set_memory(s, 0x31, val >> 8); if (above_4g_mem_size) { rtc_set_memory(s, 0x5b, (unsigned int)above_4g_mem_size >> 16); rtc_set_memory(s, 0x5c, (unsigned int)above_4g_mem_size >> 24); rtc_set_memory(s, 0x5d, (uint64_t)above_4g_mem_size >> 32); } if (ram_size > (16 * 1024 * 1024)) val = (ram_size / 65536) - ((16 * 1024 * 1024) / 65536); else val = 0; if (val > 65535) val = 65535; rtc_set_memory(s, 0x34, val); rtc_set_memory(s, 0x35, val >> 8); /* set the number of CPU */ rtc_set_memory(s, 0x5f, smp_cpus - 1); /* set boot devices, and disable floppy signature check if requested */ if (set_boot_dev(s, boot_device, fd_bootchk)) { exit(1); } /* floppy type */ fd0 = fdctrl_get_drive_type(floppy_controller, 0); fd1 = fdctrl_get_drive_type(floppy_controller, 1); val = (cmos_get_fd_drive_type(fd0) << 4) | cmos_get_fd_drive_type(fd1); rtc_set_memory(s, 0x10, val); val = 0; nb = 0; if (fd0 < FDRIVE_DRV_NONE) { nb++; } if (fd1 < FDRIVE_DRV_NONE) { nb++; } switch (nb) { case 0: break; case 1: val |= 0x01; /* 1 drive, ready for boot */ break; case 2: val |= 0x41; /* 2 drives, ready for boot */ break; } val |= 0x02; /* FPU is there */ val |= 0x04; /* PS/2 mouse installed */ rtc_set_memory(s, REG_EQUIPMENT_BYTE, val); /* hard drives */ arg.rtc_state = s; arg.idebus0 = idebus0; arg.idebus1 = idebus1; qemu_register_reset(pc_cmos_init_late, &arg); }


START_TEST(unterminated_dict_comma) { QObject *obj = qobject_from_json("{'abc':32,"); fail_unless(obj == NULL); }


void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t soffset, size_t sbytes) { int i; size_t done; struct iovec *siov = src->iov; assert(dst->nalloc != -1); assert(src->size >= soffset); for (i = 0, done = 0; done < sbytes && i < src->niov; i++) { if (soffset < siov[i].iov_len) { size_t len = MIN(siov[i].iov_len - soffset, sbytes - done); qemu_iovec_add(dst, siov[i].iov_base + soffset, len); done += len; soffset = 0; } else { soffset -= siov[i].iov_len; } } /* return done; */ }


void net_host_device_add(Monitor *mon, const char *device, const char *opts) { if (!net_host_check_device(device)) { monitor_printf(mon, "invalid host network device %s\n", device); return; } if (net_client_init(device, opts ? : "") < 0) { monitor_printf(mon, "adding host network device %s failed\n", device); } }


static void musicpal_register_devices(void) { sysbus_register_dev("mv88w8618_pic", sizeof(mv88w8618_pic_state), mv88w8618_pic_init); sysbus_register_dev("mv88w8618_pit", sizeof(mv88w8618_pit_state), mv88w8618_pit_init); sysbus_register_dev("mv88w8618_flashcfg", sizeof(mv88w8618_flashcfg_state), mv88w8618_flashcfg_init); sysbus_register_dev("mv88w8618_eth", sizeof(mv88w8618_eth_state), mv88w8618_eth_init); sysbus_register_dev("mv88w8618_wlan", sizeof(SysBusDevice), mv88w8618_wlan_init); sysbus_register_dev("musicpal_lcd", sizeof(musicpal_lcd_state), musicpal_lcd_init); sysbus_register_withprop(&musicpal_gpio_info); sysbus_register_dev("musicpal_key", sizeof(musicpal_key_state), musicpal_key_init); }


static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVQcowState *s = bs->opaque; int len, i, ret = 0; QCowHeader header; QemuOpts *opts; Error *local_err = NULL; uint64_t ext_end; uint64_t l1_vm_state_index; const char *opt_overlap_check; int overlap_check_template = 0; ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read qcow2 header"); goto fail; } be32_to_cpus(&header.magic); be32_to_cpus(&header.version); be64_to_cpus(&header.backing_file_offset); be32_to_cpus(&header.backing_file_size); be64_to_cpus(&header.size); be32_to_cpus(&header.cluster_bits); be32_to_cpus(&header.crypt_method); be64_to_cpus(&header.l1_table_offset); be32_to_cpus(&header.l1_size); be64_to_cpus(&header.refcount_table_offset); be32_to_cpus(&header.refcount_table_clusters); be64_to_cpus(&header.snapshots_offset); be32_to_cpus(&header.nb_snapshots); if (header.magic != QCOW_MAGIC) { error_setg(errp, "Image is not in qcow2 format"); ret = -EMEDIUMTYPE; goto fail; } if (header.version < 2 || header.version > 3) { report_unsupported(bs, errp, "QCOW version %d", header.version); ret = -ENOTSUP; goto fail; } s->qcow_version = header.version; /* Initialise version 3 header fields */ if (header.version == 2) { header.incompatible_features = 0; header.compatible_features = 0; header.autoclear_features = 0; header.refcount_order = 4; header.header_length = 72; } else { be64_to_cpus(&header.incompatible_features); be64_to_cpus(&header.compatible_features); be64_to_cpus(&header.autoclear_features); be32_to_cpus(&header.refcount_order); be32_to_cpus(&header.header_length); } if (header.header_length > sizeof(header)) { s->unknown_header_fields_size = header.header_length - sizeof(header); s->unknown_header_fields = g_malloc(s->unknown_header_fields_size); ret = bdrv_pread(bs->file, sizeof(header), s->unknown_header_fields, s->unknown_header_fields_size); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read unknown qcow2 header " "fields"); goto fail; } } if (header.backing_file_offset) { ext_end = header.backing_file_offset; } else { ext_end = 1 << header.cluster_bits; } /* Handle feature bits */ s->incompatible_features = header.incompatible_features; s->compatible_features = header.compatible_features; s->autoclear_features = header.autoclear_features; if (s->incompatible_features & ~QCOW2_INCOMPAT_MASK) { void *feature_table = NULL; qcow2_read_extensions(bs, header.header_length, ext_end, &feature_table, NULL); report_unsupported_feature(bs, errp, feature_table, s->incompatible_features & ~QCOW2_INCOMPAT_MASK); ret = -ENOTSUP; goto fail; } if (s->incompatible_features & QCOW2_INCOMPAT_CORRUPT) { /* Corrupt images may not be written to unless they are being repaired */ if ((flags & BDRV_O_RDWR) && !(flags & BDRV_O_CHECK)) { error_setg(errp, "qcow2: Image is corrupt; cannot be opened " "read/write"); ret = -EACCES; goto fail; } } /* Check support for various header values */ if (header.refcount_order != 4) { report_unsupported(bs, errp, "%d bit reference counts", 1 << header.refcount_order); ret = -ENOTSUP; goto fail; } s->refcount_order = header.refcount_order; if (header.cluster_bits < MIN_CLUSTER_BITS || header.cluster_bits > MAX_CLUSTER_BITS) { error_setg(errp, "Unsupported cluster size: 2^%i", header.cluster_bits); ret = -EINVAL; goto fail; } if (header.crypt_method > QCOW_CRYPT_AES) { error_setg(errp, "Unsupported encryption method: %i", header.crypt_method); ret = -EINVAL; goto fail; } s->crypt_method_header = header.crypt_method; if (s->crypt_method_header) { bs->encrypted = 1; } s->cluster_bits = header.cluster_bits; s->cluster_size = 1 << s->cluster_bits; s->cluster_sectors = 1 << (s->cluster_bits - 9); s->l2_bits = s->cluster_bits - 3; /* L2 is always one cluster */ s->l2_size = 1 << s->l2_bits; bs->total_sectors = header.size / 512; s->csize_shift = (62 - (s->cluster_bits - 8)); s->csize_mask = (1 << (s->cluster_bits - 8)) - 1; s->cluster_offset_mask = (1LL << s->csize_shift) - 1; s->refcount_table_offset = header.refcount_table_offset; s->refcount_table_size = header.refcount_table_clusters << (s->cluster_bits - 3); s->snapshots_offset = header.snapshots_offset; s->nb_snapshots = header.nb_snapshots; /* read the level 1 table */ s->l1_size = header.l1_size; l1_vm_state_index = size_to_l1(s, header.size); if (l1_vm_state_index > INT_MAX) { error_setg(errp, "Image is too big"); ret = -EFBIG; goto fail; } s->l1_vm_state_index = l1_vm_state_index; /* the L1 table must contain at least enough entries to put header.size bytes */ if (s->l1_size < s->l1_vm_state_index) { error_setg(errp, "L1 table is too small"); ret = -EINVAL; goto fail; } s->l1_table_offset = header.l1_table_offset; if (s->l1_size > 0) { s->l1_table = g_malloc0( align_offset(s->l1_size * sizeof(uint64_t), 512)); ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read L1 table"); goto fail; } for(i = 0;i < s->l1_size; i++) { be64_to_cpus(&s->l1_table[i]); } } /* alloc L2 table/refcount block cache */ s->l2_table_cache = qcow2_cache_create(bs, L2_CACHE_SIZE); s->refcount_block_cache = qcow2_cache_create(bs, REFCOUNT_CACHE_SIZE); s->cluster_cache = g_malloc(s->cluster_size); /* one more sector for decompressed data alignment */ s->cluster_data = qemu_blockalign(bs, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512); s->cluster_cache_offset = -1; s->flags = flags; ret = qcow2_refcount_init(bs); if (ret != 0) { error_setg_errno(errp, -ret, "Could not initialize refcount handling"); goto fail; } QLIST_INIT(&s->cluster_allocs); QTAILQ_INIT(&s->discards); /* read qcow2 extensions */ if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL, &local_err)) { error_propagate(errp, local_err); ret = -EINVAL; goto fail; } /* read the backing file name */ if (header.backing_file_offset != 0) { len = header.backing_file_size; if (len > 1023) { len = 1023; } ret = bdrv_pread(bs->file, header.backing_file_offset, bs->backing_file, len); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read backing file name"); goto fail; } bs->backing_file[len] = '\0'; } ret = qcow2_read_snapshots(bs); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read snapshots"); goto fail; } /* Clear unknown autoclear feature bits */ if (!bs->read_only && s->autoclear_features != 0) { s->autoclear_features = 0; ret = qcow2_update_header(bs); if (ret < 0) { error_setg_errno(errp, -ret, "Could not update qcow2 header"); goto fail; } } /* Initialise locks */ qemu_co_mutex_init(&s->lock); /* Repair image if dirty */ if (!(flags & BDRV_O_CHECK) && !bs->read_only && (s->incompatible_features & QCOW2_INCOMPAT_DIRTY)) { BdrvCheckResult result = {0}; ret = qcow2_check(bs, &result, BDRV_FIX_ERRORS); if (ret < 0) { error_setg_errno(errp, -ret, "Could not repair dirty image"); goto fail; } } /* Enable lazy_refcounts according to image and command line options */ opts = qemu_opts_create(&qcow2_runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); if (local_err) { error_propagate(errp, local_err); ret = -EINVAL; goto fail; } s->use_lazy_refcounts = qemu_opt_get_bool(opts, QCOW2_OPT_LAZY_REFCOUNTS, (s->compatible_features & QCOW2_COMPAT_LAZY_REFCOUNTS)); s->discard_passthrough[QCOW2_DISCARD_NEVER] = false; s->discard_passthrough[QCOW2_DISCARD_ALWAYS] = true; s->discard_passthrough[QCOW2_DISCARD_REQUEST] = qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_REQUEST, flags & BDRV_O_UNMAP); s->discard_passthrough[QCOW2_DISCARD_SNAPSHOT] = qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_SNAPSHOT, true); s->discard_passthrough[QCOW2_DISCARD_OTHER] = qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_OTHER, false); opt_overlap_check = qemu_opt_get(opts, "overlap-check") ?: "cached"; if (!strcmp(opt_overlap_check, "none")) { overlap_check_template = 0; } else if (!strcmp(opt_overlap_check, "constant")) { overlap_check_template = QCOW2_OL_CONSTANT; } else if (!strcmp(opt_overlap_check, "cached")) { overlap_check_template = QCOW2_OL_CACHED; } else if (!strcmp(opt_overlap_check, "all")) { overlap_check_template = QCOW2_OL_ALL; } else { error_setg(errp, "Unsupported value '%s' for qcow2 option " "'overlap-check'. Allowed are either of the following: " "none, constant, cached, all", opt_overlap_check); qemu_opts_del(opts); ret = -EINVAL; goto fail; } s->overlap_check = 0; for (i = 0; i < QCOW2_OL_MAX_BITNR; i++) { /* overlap-check defines a template bitmask, but every flag may be * overwritten through the associated boolean option */ s->overlap_check |= qemu_opt_get_bool(opts, overlap_bool_option_names[i], overlap_check_template & (1 << i)) << i; } qemu_opts_del(opts); if (s->use_lazy_refcounts && s->qcow_version < 3) { error_setg(errp, "Lazy refcounts require a qcow2 image with at least " "qemu 1.1 compatibility level"); ret = -EINVAL; goto fail; } #ifdef DEBUG_ALLOC { BdrvCheckResult result = {0}; qcow2_check_refcounts(bs, &result, 0); } #endif return ret; fail: g_free(s->unknown_header_fields); cleanup_unknown_header_ext(bs); qcow2_free_snapshots(bs); qcow2_refcount_close(bs); g_free(s->l1_table); /* else pre-write overlap checks in cache_destroy may crash */ s->l1_table = NULL; if (s->l2_table_cache) { qcow2_cache_destroy(bs, s->l2_table_cache); } g_free(s->cluster_cache); qemu_vfree(s->cluster_data); return ret; }


static void vexpress_a9_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 = NULL; MemoryRegion *sysmem = get_system_memory(); MemoryRegion *ram = g_new(MemoryRegion, 1); MemoryRegion *lowram = g_new(MemoryRegion, 1); MemoryRegion *vram = g_new(MemoryRegion, 1); MemoryRegion *sram = g_new(MemoryRegion, 1); MemoryRegion *hackram = g_new(MemoryRegion, 1); DeviceState *dev, *sysctl, *pl041; SysBusDevice *busdev; qemu_irq *irqp; qemu_irq pic[64]; int n; qemu_irq cpu_irq[4]; uint32_t proc_id; uint32_t sys_id; ram_addr_t low_ram_size, vram_size, sram_size; target_phys_addr_t *map = motherboard_legacy_map; if (!cpu_model) { cpu_model = "cortex-a9"; } for (n = 0; n < smp_cpus; n++) { env = cpu_init(cpu_model); if (!env) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } irqp = arm_pic_init_cpu(env); cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ]; } if (ram_size > 0x40000000) { /* 1GB is the maximum the address space permits */ fprintf(stderr, "vexpress: cannot model more than 1GB RAM\n"); exit(1); } memory_region_init_ram(ram, "vexpress.highmem", ram_size); vmstate_register_ram_global(ram); low_ram_size = ram_size; if (low_ram_size > 0x4000000) { low_ram_size = 0x4000000; } /* RAM is from 0x60000000 upwards. The bottom 64MB of the * address space should in theory be remappable to various * things including ROM or RAM; we always map the RAM there. */ memory_region_init_alias(lowram, "vexpress.lowmem", ram, 0, low_ram_size); memory_region_add_subregion(sysmem, 0x0, lowram); memory_region_add_subregion(sysmem, 0x60000000, ram); /* 0x1e000000 A9MPCore (SCU) private memory region */ dev = qdev_create(NULL, "a9mpcore_priv"); qdev_prop_set_uint32(dev, "num-cpu", smp_cpus); qdev_init_nofail(dev); busdev = sysbus_from_qdev(dev); vexpress_binfo.smp_priv_base = 0x1e000000; sysbus_mmio_map(busdev, 0, vexpress_binfo.smp_priv_base); for (n = 0; n < smp_cpus; n++) { sysbus_connect_irq(busdev, n, cpu_irq[n]); } /* Interrupts [42:0] are from the motherboard; * [47:43] are reserved; [63:48] are daughterboard * peripherals. Note that some documentation numbers * external interrupts starting from 32 (because the * A9MP has internal interrupts 0..31). */ for (n = 0; n < 64; n++) { pic[n] = qdev_get_gpio_in(dev, n); } /* Motherboard peripherals: the wiring is the same but the * addresses vary between the legacy and A-Series memory maps. */ sys_id = 0x1190f500; proc_id = 0x0c000191; sysctl = qdev_create(NULL, "realview_sysctl"); qdev_prop_set_uint32(sysctl, "sys_id", sys_id); qdev_prop_set_uint32(sysctl, "proc_id", proc_id); qdev_init_nofail(sysctl); sysbus_mmio_map(sysbus_from_qdev(sysctl), 0, map[VE_SYSREGS]); /* VE_SP810: not modelled */ /* VE_SERIALPCI: not modelled */ pl041 = qdev_create(NULL, "pl041"); qdev_prop_set_uint32(pl041, "nc_fifo_depth", 512); qdev_init_nofail(pl041); sysbus_mmio_map(sysbus_from_qdev(pl041), 0, map[VE_PL041]); sysbus_connect_irq(sysbus_from_qdev(pl041), 0, pic[11]); dev = sysbus_create_varargs("pl181", map[VE_MMCI], pic[9], pic[10], NULL); /* Wire up MMC card detect and read-only signals */ qdev_connect_gpio_out(dev, 0, qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_WPROT)); qdev_connect_gpio_out(dev, 1, qdev_get_gpio_in(sysctl, ARM_SYSCTL_GPIO_MMC_CARDIN)); sysbus_create_simple("pl050_keyboard", map[VE_KMI0], pic[12]); sysbus_create_simple("pl050_mouse", map[VE_KMI1], pic[13]); sysbus_create_simple("pl011", map[VE_UART0], pic[5]); sysbus_create_simple("pl011", map[VE_UART1], pic[6]); sysbus_create_simple("pl011", map[VE_UART2], pic[7]); sysbus_create_simple("pl011", map[VE_UART3], pic[8]); sysbus_create_simple("sp804", map[VE_TIMER01], pic[2]); sysbus_create_simple("sp804", map[VE_TIMER23], pic[3]); /* VE_SERIALDVI: not modelled */ sysbus_create_simple("pl031", map[VE_RTC], pic[4]); /* RTC */ /* VE_COMPACTFLASH: not modelled */ /* VE_CLCD: not modelled (we use the daughterboard CLCD only) */ /* Daughterboard peripherals : 0x10020000 .. 0x20000000 */ /* 0x10020000 PL111 CLCD (daughterboard) */ sysbus_create_simple("pl111", 0x10020000, pic[44]); /* 0x10060000 AXI RAM */ /* 0x100e0000 PL341 Dynamic Memory Controller */ /* 0x100e1000 PL354 Static Memory Controller */ /* 0x100e2000 System Configuration Controller */ sysbus_create_simple("sp804", 0x100e4000, pic[48]); /* 0x100e5000 SP805 Watchdog module */ /* 0x100e6000 BP147 TrustZone Protection Controller */ /* 0x100e9000 PL301 'Fast' AXI matrix */ /* 0x100ea000 PL301 'Slow' AXI matrix */ /* 0x100ec000 TrustZone Address Space Controller */ /* 0x10200000 CoreSight debug APB */ /* 0x1e00a000 PL310 L2 Cache Controller */ sysbus_create_varargs("l2x0", 0x1e00a000, NULL); /* VE_NORFLASH0: not modelled */ /* VE_NORFLASH0ALIAS: not modelled */ /* VE_NORFLASH1: not modelled */ sram_size = 0x2000000; memory_region_init_ram(sram, "vexpress.sram", sram_size); vmstate_register_ram_global(sram); memory_region_add_subregion(sysmem, map[VE_SRAM], sram); vram_size = 0x800000; memory_region_init_ram(vram, "vexpress.vram", vram_size); vmstate_register_ram_global(vram); memory_region_add_subregion(sysmem, map[VE_VIDEORAM], vram); /* 0x4e000000 LAN9118 Ethernet */ if (nd_table[0].vlan) { lan9118_init(&nd_table[0], map[VE_ETHERNET], pic[15]); } /* VE_USB: not modelled */ /* VE_DAPROM: not modelled */ /* ??? Hack to map an additional page of ram for the secondary CPU startup code. I guess this works on real hardware because the BootROM happens to be in ROM/flash or in memory that isn't clobbered until after Linux boots the secondary CPUs. */ memory_region_init_ram(hackram, "vexpress.hack", 0x1000); vmstate_register_ram_global(hackram); memory_region_add_subregion(sysmem, SMP_BOOT_ADDR, hackram); vexpress_binfo.ram_size = ram_size; vexpress_binfo.kernel_filename = kernel_filename; vexpress_binfo.kernel_cmdline = kernel_cmdline; vexpress_binfo.initrd_filename = initrd_filename; vexpress_binfo.nb_cpus = smp_cpus; vexpress_binfo.board_id = VEXPRESS_BOARD_ID; vexpress_binfo.loader_start = 0x60000000; vexpress_binfo.smp_bootreg_addr = map[VE_SYSREGS] + 0x30; arm_load_kernel(first_cpu, &vexpress_binfo); }


static void gpollfds_to_select(int ret) { int i; FD_ZERO(&rfds); FD_ZERO(&wfds); FD_ZERO(&xfds); if (ret <= 0) { return; } for (i = 0; i < gpollfds->len; i++) { int fd = g_array_index(gpollfds, GPollFD, i).fd; int revents = g_array_index(gpollfds, GPollFD, i).revents; if (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) { FD_SET(fd, &rfds); } if (revents & (G_IO_OUT | G_IO_ERR)) { FD_SET(fd, &wfds); } if (revents & G_IO_PRI) { FD_SET(fd, &xfds); } } }


static void cpu_4xx_pit_cb (void *opaque) { CPUState *env; ppc_tb_t *tb_env; ppcemb_timer_t *ppcemb_timer; env = opaque; tb_env = env->tb_env; ppcemb_timer = tb_env->opaque; env->spr[SPR_40x_TSR] |= 1 << 27; if ((env->spr[SPR_40x_TCR] >> 26) & 0x1) ppc_set_irq(env, PPC_INTERRUPT_PIT, 1); start_stop_pit(env, tb_env, 1); LOG_TB("%s: ar %d ir %d TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx " " "%016" PRIx64 "\n", __func__, (int)((env->spr[SPR_40x_TCR] >> 22) & 0x1), (int)((env->spr[SPR_40x_TCR] >> 26) & 0x1), env->spr[SPR_40x_TCR], env->spr[SPR_40x_TSR], ppcemb_timer->pit_reload); }


CPUArchState *cpu_copy(CPUArchState *env) { CPUState *cpu = ENV_GET_CPU(env); CPUArchState *new_env = cpu_init(cpu_model); CPUState *new_cpu = ENV_GET_CPU(new_env); #if defined(TARGET_HAS_ICE) CPUBreakpoint *bp; CPUWatchpoint *wp; #endif /* Reset non arch specific state */ cpu_reset(new_cpu); memcpy(new_env, env, sizeof(CPUArchState)); /* Clone all break/watchpoints. Note: Once we support ptrace with hw-debug register access, make sure BP_CPU break/watchpoints are handled correctly on clone. */ QTAILQ_INIT(&cpu->breakpoints); QTAILQ_INIT(&cpu->watchpoints); #if defined(TARGET_HAS_ICE) QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { cpu_breakpoint_insert(new_cpu, bp->pc, bp->flags, NULL); } QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { cpu_watchpoint_insert(new_cpu, wp->vaddr, wp->len, wp->flags, NULL); } #endif return new_env; }


static void mdct512(AC3MDCTContext *mdct, float *out, float *in) { mdct->fft.mdct_calc(&mdct->fft, out, in); }


static void av_noinline qpeg_decode_inter(QpegContext *qctx, uint8_t *dst, int stride, int width, int height, int delta, const uint8_t *ctable, uint8_t *refdata) { int i, j; int code; int filled = 0; int orig_height; if(!refdata) refdata= dst; /* copy prev frame */ for(i = 0; i < height; i++) memcpy(dst + (i * stride), refdata + (i * stride), width); orig_height = height; height--; dst = dst + height * stride; while ((bytestream2_get_bytes_left(&qctx->buffer) > 0) && (height >= 0)) { code = bytestream2_get_byte(&qctx->buffer); if(delta) { /* motion compensation */ while(bytestream2_get_bytes_left(&qctx->buffer) > 0 && (code & 0xF0) == 0xF0) { if(delta == 1) { int me_idx; int me_w, me_h, me_x, me_y; uint8_t *me_plane; int corr, val; /* get block size by index */ me_idx = code & 0xF; me_w = qpeg_table_w[me_idx]; me_h = qpeg_table_h[me_idx]; /* extract motion vector */ corr = bytestream2_get_byte(&qctx->buffer); val = corr >> 4; if(val > 7) val -= 16; me_x = val; val = corr & 0xF; if(val > 7) val -= 16; me_y = val; /* check motion vector */ if ((me_x + filled < 0) || (me_x + me_w + filled > width) || (height - me_y - me_h < 0) || (height - me_y >= orig_height) || (filled + me_w > width) || (height - me_h < 0)) av_log(NULL, AV_LOG_ERROR, "Bogus motion vector (%i,%i), block size %ix%i at %i,%i\n", me_x, me_y, me_w, me_h, filled, height); else { /* do motion compensation */ me_plane = refdata + (filled + me_x) + (height - me_y) * stride; for(j = 0; j < me_h; j++) { for(i = 0; i < me_w; i++) dst[filled + i - (j * stride)] = me_plane[i - (j * stride)]; } } } code = bytestream2_get_byte(&qctx->buffer); } } if(code == 0xE0) /* end-of-picture code */ break; if(code > 0xE0) { /* run code: 0xE1..0xFF */ int p; code &= 0x1F; p = bytestream2_get_byte(&qctx->buffer); for(i = 0; i <= code; i++) { dst[filled++] = p; if(filled >= width) { filled = 0; dst -= stride; height--; if (height < 0) break; } } } else if(code >= 0xC0) { /* copy code: 0xC0..0xDF */ code &= 0x1F; if(code + 1 > bytestream2_get_bytes_left(&qctx->buffer)) break; for(i = 0; i <= code; i++) { dst[filled++] = bytestream2_get_byte(&qctx->buffer); if(filled >= width) { filled = 0; dst -= stride; height--; if (height < 0) break; } } } else if(code >= 0x80) { /* skip code: 0x80..0xBF */ int skip; code &= 0x3F; /* codes 0x80 and 0x81 are actually escape codes, skip value minus constant is in the next byte */ if(!code) skip = bytestream2_get_byte(&qctx->buffer) + 64; else if(code == 1) skip = bytestream2_get_byte(&qctx->buffer) + 320; else skip = code; filled += skip; while( filled >= width) { filled -= width; dst -= stride; height--; if(height < 0) break; } } else { /* zero code treated as one-pixel skip */ if(code) { dst[filled++] = ctable[code & 0x7F]; } else filled++; if(filled >= width) { filled = 0; dst -= stride; height--; } } } }


static void block_job_detach_aio_context(void *opaque) { BlockJob *job = opaque; /* In case the job terminates during aio_poll()... */ block_job_ref(job); block_job_pause(job); if (!job->paused) { /* If job is !job->busy this kicks it into the next pause point. */ block_job_enter(job); } while (!job->paused && !job->completed) { aio_poll(block_job_get_aio_context(job), true); } block_job_unref(job); }


void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp) { int mapped_node_id; /* set by -numa option */ int node_id = object_property_get_int(OBJECT(dev), "node-id", &error_abort); /* by default CPUState::numa_node was 0 if it wasn't set explicitly * TODO: make it error when incomplete numa mapping support is removed */ mapped_node_id = slot->props.node_id; if (!slot->props.has_node_id) { mapped_node_id = 0; } if (node_id == CPU_UNSET_NUMA_NODE_ID) { /* due to bug in libvirt, it doesn't pass node-id from props on * device_add as expected, so we have to fix it up here */ object_property_set_int(OBJECT(dev), mapped_node_id, "node-id", errp); } else if (node_id != mapped_node_id) { error_setg(errp, "node-id=%d must match numa node specified " "with -numa option", node_id); } }


static void multiwrite_cb(void *opaque, int ret) { MultiwriteCB *mcb = opaque; trace_multiwrite_cb(mcb, ret); if (ret < 0 && !mcb->error) { mcb->error = ret; } mcb->num_requests--; if (mcb->num_requests == 0) { multiwrite_user_cb(mcb); g_free(mcb); } }


static void qdict_setup(void) { tests_dict = qdict_new(); fail_unless(tests_dict != NULL); }


static int parallels_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVParallelsState *s = bs->opaque; int i; ParallelsHeader ph; int ret; ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph)); if (ret < 0) { goto fail; } bs->total_sectors = le64_to_cpu(ph.nb_sectors); if (le32_to_cpu(ph.version) != HEADER_VERSION) { goto fail_format; } if (!memcmp(ph.magic, HEADER_MAGIC, 16)) { s->off_multiplier = 1; bs->total_sectors = 0xffffffff & bs->total_sectors; } else if (!memcmp(ph.magic, HEADER_MAGIC2, 16)) { s->off_multiplier = le32_to_cpu(ph.tracks); } else { goto fail_format; } s->tracks = le32_to_cpu(ph.tracks); if (s->tracks == 0) { error_setg(errp, "Invalid image: Zero sectors per track"); ret = -EINVAL; goto fail; } if (s->tracks > INT32_MAX/513) { error_setg(errp, "Invalid image: Too big cluster"); ret = -EFBIG; goto fail; } s->catalog_size = le32_to_cpu(ph.catalog_entries); if (s->catalog_size > INT_MAX / sizeof(uint32_t)) { error_setg(errp, "Catalog too large"); ret = -EFBIG; goto fail; } s->catalog_bitmap = g_try_new(uint32_t, s->catalog_size); if (s->catalog_size && s->catalog_bitmap == NULL) { ret = -ENOMEM; goto fail; } ret = bdrv_pread(bs->file, sizeof(ParallelsHeader), s->catalog_bitmap, s->catalog_size * sizeof(uint32_t)); if (ret < 0) { goto fail; } for (i = 0; i < s->catalog_size; i++) le32_to_cpus(&s->catalog_bitmap[i]); s->has_truncate = bdrv_has_zero_init(bs->file) && bdrv_truncate(bs->file, bdrv_getlength(bs->file)) == 0; qemu_co_mutex_init(&s->lock); return 0; fail_format: error_setg(errp, "Image not in Parallels format"); ret = -EINVAL; fail: g_free(s->catalog_bitmap); return ret; }


void imx_timerp_create(const target_phys_addr_t addr, qemu_irq irq, DeviceState *ccm) { IMXTimerPState *pp; DeviceState *dev; dev = sysbus_create_simple("imx_timerp", addr, irq); pp = container_of(dev, IMXTimerPState, busdev.qdev); pp->ccm = ccm; }


if_start(Slirp *slirp) { uint64_t now = qemu_get_clock_ns(rt_clock); int requeued = 0; bool from_batchq = false; struct mbuf *ifm, *ifqt; DEBUG_CALL("if_start"); if (slirp->if_queued == 0) return; /* Nothing to do */ again: /* check if we can really output */ if (!slirp_can_output(slirp->opaque)) return; /* * See which queue to get next packet from * If there's something in the fastq, select it immediately */ if (slirp->if_fastq.ifq_next != &slirp->if_fastq) { ifm = slirp->if_fastq.ifq_next; } else { /* Nothing on fastq, see if next_m is valid */ if (slirp->next_m != &slirp->if_batchq) ifm = slirp->next_m; else ifm = slirp->if_batchq.ifq_next; from_batchq = true; } slirp->if_queued--; /* Try to send packet unless it already expired */ if (ifm->expiration_date >= now && !if_encap(slirp, ifm)) { /* Packet is delayed due to pending ARP resolution */ requeued++; goto out; } if (from_batchq) { /* Set which packet to send on next iteration */ slirp->next_m = ifm->ifq_next; } /* Remove it from the queue */ ifqt = ifm->ifq_prev; remque(ifm); /* If there are more packets for this session, re-queue them */ if (ifm->ifs_next != /* ifm->ifs_prev != */ ifm) { insque(ifm->ifs_next, ifqt); ifs_remque(ifm); } /* Update so_queued */ if (ifm->ifq_so) { if (--ifm->ifq_so->so_queued == 0) /* If there's no more queued, reset nqueued */ ifm->ifq_so->so_nqueued = 0; } m_free(ifm); out: if (slirp->if_queued) goto again; slirp->if_queued = requeued; }


e1000_cleanup(NetClientState *nc) { E1000State *s = qemu_get_nic_opaque(nc); s->nic = NULL; }


static void sdram_set_bcr (uint32_t *bcrp, uint32_t bcr, int enabled) { if (*bcrp & 0x00000001) { /* Unmap RAM */ #ifdef DEBUG_SDRAM printf("%s: unmap RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n", __func__, sdram_base(*bcrp), sdram_size(*bcrp)); #endif cpu_register_physical_memory(sdram_base(*bcrp), sdram_size(*bcrp), IO_MEM_UNASSIGNED); } *bcrp = bcr & 0xFFDEE001; if (enabled && (bcr & 0x00000001)) { #ifdef DEBUG_SDRAM printf("%s: Map RAM area " TARGET_FMT_plx " " TARGET_FMT_lx "\n", __func__, sdram_base(bcr), sdram_size(bcr)); #endif cpu_register_physical_memory(sdram_base(bcr), sdram_size(bcr), sdram_base(bcr) | IO_MEM_RAM); } }


static Suite *qfloat_suite(void) { Suite *s; TCase *qfloat_public_tcase; s = suite_create("QFloat test-suite"); qfloat_public_tcase = tcase_create("Public Interface"); suite_add_tcase(s, qfloat_public_tcase); tcase_add_test(qfloat_public_tcase, qfloat_from_double_test); tcase_add_test(qfloat_public_tcase, qfloat_destroy_test); return s; }


void qemu_unregister_clock_reset_notifier(QEMUClock *clock, Notifier *notifier) { qemu_clock_unregister_reset_notifier(clock->type, notifier); }


target_ulong cpu_get_phys_page_debug(CPUState *env, target_ulong addr) { uint8_t *pde_ptr, *pte_ptr; uint32_t pde, pte, paddr, page_offset, page_size; if (!(env->cr[0] & CR0_PG_MASK)) { pte = addr; page_size = 4096; } else { /* page directory entry */ pde_ptr = phys_ram_base + (((env->cr[3] & ~0xfff) + ((addr >> 20) & ~3)) & a20_mask); pde = ldl_raw(pde_ptr); if (!(pde & PG_PRESENT_MASK)) return -1; if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) { pte = pde & ~0x003ff000; /* align to 4MB */ page_size = 4096 * 1024; } else { /* page directory entry */ pte_ptr = phys_ram_base + (((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & a20_mask); pte = ldl_raw(pte_ptr); if (!(pte & PG_PRESENT_MASK)) return -1; page_size = 4096; } } pte = pte & a20_mask; page_offset = (addr & TARGET_PAGE_MASK) & (page_size - 1); paddr = (pte & TARGET_PAGE_MASK) + page_offset; return paddr; }


static uint64_t imx_serial_read(void *opaque, target_phys_addr_t offset, unsigned size) { IMXSerialState *s = (IMXSerialState *)opaque; uint32_t c; DPRINTF("read(offset=%x)\n", offset >> 2); switch (offset >> 2) { case 0x0: /* URXD */ c = s->readbuff; if (!(s->uts1 & UTS1_RXEMPTY)) { /* Character is valid */ c |= URXD_CHARRDY; s->usr1 &= ~USR1_RRDY; s->usr2 &= ~USR2_RDR; s->uts1 |= UTS1_RXEMPTY; imx_update(s); qemu_chr_accept_input(s->chr); } return c; case 0x20: /* UCR1 */ return s->ucr1; case 0x21: /* UCR2 */ return s->ucr2; case 0x25: /* USR1 */ return s->usr1; case 0x26: /* USR2 */ return s->usr2; case 0x2A: /* BRM Modulator */ return s->ubmr; case 0x2B: /* Baud Rate Count */ return s->ubrc; case 0x2d: /* Test register */ return s->uts1; case 0x24: /* UFCR */ return s->ufcr; case 0x2c: return s->onems; case 0x22: /* UCR3 */ return s->ucr3; case 0x23: /* UCR4 */ case 0x29: /* BRM Incremental */ return 0x0; /* TODO */ default: IPRINTF("imx_serial_read: bad offset: 0x%x\n", (int)offset); return 0; } }


void qemu_del_net_client(NetClientState *nc) { NetClientState *ncs[MAX_QUEUE_NUM]; int queues, i; /* If the NetClientState belongs to a multiqueue backend, we will change all * other NetClientStates also. */ queues = qemu_find_net_clients_except(nc->name, ncs, NET_CLIENT_OPTIONS_KIND_NIC, MAX_QUEUE_NUM); assert(queues != 0); /* If there is a peer NIC, delete and cleanup client, but do not free. */ if (nc->peer && nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_NIC) { NICState *nic = qemu_get_nic(nc->peer); if (nic->peer_deleted) { return; } nic->peer_deleted = true; for (i = 0; i < queues; i++) { ncs[i]->peer->link_down = true; } if (nc->peer->info->link_status_changed) { nc->peer->info->link_status_changed(nc->peer); } for (i = 0; i < queues; i++) { qemu_cleanup_net_client(ncs[i]); } return; } assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC); for (i = 0; i < queues; i++) { qemu_cleanup_net_client(ncs[i]); qemu_free_net_client(ncs[i]); } }


static inline void omap_gp_timer_trigger(struct omap_gp_timer_s *timer) { if (timer->pt) /* TODO in overflow-and-match mode if the first event to * occurs is the match, don't toggle. */ omap_gp_timer_out(timer, !timer->out_val); else /* TODO inverted pulse on timer->out_val == 1? */ qemu_irq_pulse(timer->out); }


timer_write(void *opaque, target_phys_addr_t addr, uint64_t val64, unsigned int size) { struct etrax_timer *t = opaque; uint32_t value = val64; switch (addr) { case RW_TMR0_DIV: t->rw_tmr0_div = value; break; case RW_TMR0_CTRL: D(printf ("RW_TMR0_CTRL=%x\n", value)); t->rw_tmr0_ctrl = value; update_ctrl(t, 0); break; case RW_TMR1_DIV: t->rw_tmr1_div = value; break; case RW_TMR1_CTRL: D(printf ("RW_TMR1_CTRL=%x\n", value)); t->rw_tmr1_ctrl = value; update_ctrl(t, 1); break; case RW_INTR_MASK: D(printf ("RW_INTR_MASK=%x\n", value)); t->rw_intr_mask = value; timer_update_irq(t); break; case RW_WD_CTRL: timer_watchdog_update(t, value); break; case RW_ACK_INTR: t->rw_ack_intr = value; timer_update_irq(t); t->rw_ack_intr = 0; break; default: printf ("%s " TARGET_FMT_plx " %x\n", __func__, addr, value); break; } }