/* Initialisation routine */ void *ds1225y_init(target_phys_addr_t mem_base, const char *filename) { ds1225y_t *s; int mem_indexRW, mem_indexRP; QEMUFile *file; s = qemu_mallocz(sizeof(ds1225y_t)); s->chip_size = 0x2000; /* Fixed for ds1225y chip: 8 KiB */ s->contents = qemu_mallocz(s->chip_size); s->protection = 7; /* Read current file */ file = qemu_fopen(filename, "rb"); if (file) { /* Read nvram contents */ qemu_get_buffer(file, s->contents, s->chip_size); qemu_fclose(file); } s->file = qemu_fopen(filename, "wb"); if (s->file) { /* Write back contents, as 'wb' mode cleaned the file */ qemu_put_buffer(s->file, s->contents, s->chip_size); qemu_fflush(s->file); } /* Read/write memory */ mem_indexRW = cpu_register_io_memory(nvram_read, nvram_write, s); cpu_register_physical_memory(mem_base, s->chip_size, mem_indexRW); /* Read/write protected memory */ mem_indexRP = cpu_register_io_memory(nvram_read, nvram_write_protected, s); cpu_register_physical_memory(mem_base + s->chip_size, s->chip_size, mem_indexRP); return s; }
void do_savevm(const char *name) { QEMUFile *f; int saved_vm_running, ret; f = qemu_fopen(name, "wb"); /* ??? Should this occur after vm_stop? */ qemu_aio_flush(); saved_vm_running = vm_running; vm_stop(0); if (!f) { fprintf(logfile, "Failed to open savevm file '%s'\n", name); goto the_end; } ret = qemu_savevm_state(f); qemu_fclose(f); if (ret < 0) fprintf(logfile, "Error %d while writing VM to savevm file '%s'\n", ret, name); the_end: if (saved_vm_running) vm_start(); return; }
void qmp_dump_skeys(const char *filename, Error **errp) { S390SKeysState *ss = s390_get_skeys_device(); S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss); const uint64_t total_count = ram_size / TARGET_PAGE_SIZE; uint64_t handled_count = 0, cur_count; Error *lerr = NULL; vaddr cur_gfn = 0; uint8_t *buf; int ret; QEMUFile *f; /* Quick check to see if guest is using storage keys*/ if (!skeyclass->skeys_enabled(ss)) { error_setg(errp, "This guest is not using storage keys - " "nothing to dump"); return; } f = qemu_fopen(filename, "wb"); if (!f) { error_setg_file_open(errp, errno, filename); return; } buf = g_try_malloc(S390_SKEYS_BUFFER_SIZE); if (!buf) { error_setg(errp, "Could not allocate memory"); goto out; } /* we'll only dump initial memory for now */ while (handled_count < total_count) { /* Calculate how many keys to ask for & handle overflow case */ cur_count = MIN(total_count - handled_count, S390_SKEYS_BUFFER_SIZE); ret = skeyclass->get_skeys(ss, cur_gfn, cur_count, buf); if (ret < 0) { error_setg(errp, "get_keys error %d", ret); goto out_free; } /* write keys to stream */ write_keys(f, buf, cur_gfn, cur_count, &lerr); if (lerr) { goto out_free; } cur_gfn += cur_count; handled_count += cur_count; } out_free: error_propagate(errp, lerr); g_free(buf); out: qemu_fclose(f); }
static int ds1225y_set_to_mode(ds1225y_t *NVRAM, nvram_open_mode mode, const char *filemode) { if (NVRAM->open_mode != mode) { if (NVRAM->file) qemu_fclose(NVRAM->file); NVRAM->file = qemu_fopen(NVRAM->filename, filemode); NVRAM->open_mode = mode; } return (NVRAM->file != NULL); }
void do_loadvm(const char *name) { QEMUFile *f; int saved_vm_running, ret; /* Flush all IO requests so they don't interfere with the new state. */ qemu_aio_flush(); saved_vm_running = vm_running; vm_stop(0); /* restore the VM state */ f = qemu_fopen(name, "rb"); if (!f) { fprintf(logfile, "Could not open VM state file\n"); goto the_end; } ret = qemu_loadvm_state(f); qemu_fclose(f); if (ret < 0) { fprintf(logfile, "Error %d while loading savevm file '%s'\n", ret, name); goto the_end; } #if 0 /* del tmp file */ if (unlink(name) == -1) fprintf(stderr, "delete tmp qemu state file failed.\n"); #endif the_end: if (saved_vm_running) vm_start(); }
int wav_start_capture (CaptureState *s, const char *path, int freq, int bits, int nchannels) { Monitor *mon = cur_mon; WAVState *wav; uint8_t hdr[] = { 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x44, 0xac, 0x00, 0x00, 0x10, 0xb1, 0x02, 0x00, 0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00 }; struct audsettings as; struct audio_capture_ops ops; int stereo, bits16, shift; CaptureVoiceOut *cap; if (bits != 8 && bits != 16) { monitor_printf(mon, "incorrect bit count %d, must be 8 or 16\n", bits); return -1; } if (nchannels != 1 && nchannels != 2) { monitor_printf(mon, "incorrect channel count %d, must be 1 or 2\n", nchannels); return -1; } stereo = nchannels == 2; bits16 = bits == 16; as.freq = freq; as.nchannels = 1 << stereo; as.fmt = bits16 ? AUD_FMT_S16 : AUD_FMT_U8; as.endianness = 0; ops.notify = wav_notify; ops.capture = wav_capture; ops.destroy = wav_destroy; wav = g_malloc0 (sizeof (*wav)); shift = bits16 + stereo; hdr[34] = bits16 ? 0x10 : 0x08; le_store (hdr + 22, as.nchannels, 2); le_store (hdr + 24, freq, 4); le_store (hdr + 28, freq << shift, 4); le_store (hdr + 32, 1 << shift, 2); wav->f = qemu_fopen (path, "wb"); if (!wav->f) { monitor_printf(mon, "Failed to open wave file `%s'\nReason: %s\n", path, strerror (errno)); g_free (wav); return -1; } wav->path = g_strdup (path); wav->bits = bits; wav->nchannels = nchannels; wav->freq = freq; qemu_put_buffer (wav->f, hdr, sizeof (hdr)); cap = AUD_add_capture (&as, &ops, wav); if (!cap) { monitor_printf(mon, "Failed to add audio capture\n"); g_free (wav->path); qemu_fclose (wav->f); g_free (wav); return -1; } wav->cap = cap; s->opaque = wav; s->ops = wav_capture_ops; return 0; }