From patchwork Thu Jul 17 11:04:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Dovgalyuk X-Patchwork-Id: 371172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C72AF14017A for ; Thu, 17 Jul 2014 23:59:55 +1000 (EST) Received: from localhost ([::1]:44493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7mDx-00028n-Qi for incoming@patchwork.ozlabs.org; Thu, 17 Jul 2014 09:59:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7jjx-0008P5-Fs for qemu-devel@nongnu.org; Thu, 17 Jul 2014 07:20:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X7jjq-0002Bk-Mj for qemu-devel@nongnu.org; Thu, 17 Jul 2014 07:20:45 -0400 Received: from mail.ispras.ru ([83.149.199.45]:47471) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X7jTk-00054Q-4Z for qemu-devel@nongnu.org; Thu, 17 Jul 2014 07:04:00 -0400 Received: from [10.10.150.172] (unknown [80.250.189.177]) by mail.ispras.ru (Postfix) with ESMTPSA id 541B8540151; Thu, 17 Jul 2014 15:03:59 +0400 (MSK) To: qemu-devel@nongnu.org From: Pavel Dovgalyuk Date: Thu, 17 Jul 2014 15:04:02 +0400 Message-ID: <20140717110402.8352.88354.stgit@PASHA-ISP> In-Reply-To: <20140717110153.8352.80175.stgit@PASHA-ISP> References: <20140717110153.8352.80175.stgit@PASHA-ISP> User-Agent: StGit/0.16 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 83.149.199.45 X-Mailman-Approved-At: Thu, 17 Jul 2014 09:36:33 -0400 Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, mark.burton@greensocs.com, real@ispras.ru, batuzovk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, fred.konrad@greensocs.com Subject: [Qemu-devel] [RFC PATCH v2 22/49] replay: internal functions for replay log X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds functions to perform read and write operations with replay log. Signed-off-by: Pavel Dovgalyuk --- replay/Makefile.objs | 1 replay/replay-internal.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++ replay/replay-internal.h | 50 ++++++++++++++++ replay/replay.c | 6 ++ 4 files changed, 198 insertions(+), 0 deletions(-) create mode 100755 replay/replay-internal.c create mode 100755 replay/replay-internal.h diff --git a/replay/Makefile.objs b/replay/Makefile.objs index 7ea860f..1148f45 100755 --- a/replay/Makefile.objs +++ b/replay/Makefile.objs @@ -1 +1,2 @@ obj-y += replay.o +obj-y += replay-internal.o diff --git a/replay/replay-internal.c b/replay/replay-internal.c new file mode 100755 index 0000000..706b46b --- /dev/null +++ b/replay/replay-internal.c @@ -0,0 +1,141 @@ +/* + * replay-internal.c + * + * Copyright (c) 2010-2014 Institute for System Programming + * of the Russian Academy of Sciences. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu-common.h" +#include "replay-internal.h" + +volatile unsigned int replay_data_kind = -1; +volatile unsigned int replay_has_unread_data; + +/* File for replay writing */ +FILE *replay_file; + +void replay_put_byte(unsigned char byte) +{ + if (replay_file) { + fwrite(&byte, sizeof(byte), 1, replay_file); + } +} + +void replay_put_event(unsigned char event) +{ + replay_put_byte(event); +} + + +void replay_put_word(uint16_t word) +{ + if (replay_file) { + fwrite(&word, sizeof(word), 1, replay_file); + } +} + +void replay_put_dword(unsigned int dword) +{ + if (replay_file) { + fwrite(&dword, sizeof(dword), 1, replay_file); + } +} + +void replay_put_qword(int64_t qword) +{ + if (replay_file) { + fwrite(&qword, sizeof(qword), 1, replay_file); + } +} + +void replay_put_array(const uint8_t *buf, size_t size) +{ + if (replay_file) { + fwrite(&size, sizeof(size), 1, replay_file); + fwrite(buf, 1, size, replay_file); + } +} + +unsigned char replay_get_byte(void) +{ + unsigned char byte; + if (replay_file) { + fread(&byte, sizeof(byte), 1, replay_file); + } + return byte; +} + +uint16_t replay_get_word(void) +{ + uint16_t word; + if (replay_file) { + fread(&word, sizeof(word), 1, replay_file); + } + + return word; +} + +unsigned int replay_get_dword(void) +{ + unsigned int dword; + if (replay_file) { + fread(&dword, sizeof(dword), 1, replay_file); + } + + return dword; +} + +int64_t replay_get_qword(void) +{ + int64_t qword; + if (replay_file) { + fread(&qword, sizeof(qword), 1, replay_file); + } + + return qword; +} + +void replay_get_array(uint8_t *buf, size_t *size) +{ + if (replay_file) { + fread(size, sizeof(*size), 1, replay_file); + fread(buf, 1, *size, replay_file); + } +} + +void replay_get_array_alloc(uint8_t **buf, size_t *size) +{ + if (replay_file) { + fread(size, sizeof(*size), 1, replay_file); + *buf = g_malloc(*size); + fread(*buf, 1, *size, replay_file); + } +} + +void replay_check_error(void) +{ + if (replay_file) { + if (feof(replay_file)) { + fprintf(stderr, "replay file is over\n"); + exit(1); + } else if (ferror(replay_file)) { + fprintf(stderr, "replay file is over or something goes wrong\n"); + exit(1); + } + } +} + +void replay_fetch_data_kind(void) +{ + if (replay_file) { + if (!replay_has_unread_data) { + replay_data_kind = replay_get_byte(); + replay_check_error(); + replay_has_unread_data = 1; + } + } +} diff --git a/replay/replay-internal.h b/replay/replay-internal.h new file mode 100755 index 0000000..b959bca --- /dev/null +++ b/replay/replay-internal.h @@ -0,0 +1,50 @@ +#ifndef REPLAY_INTERNAL_H +#define REPLAY_INTERNAL_H + +/* + * replay-internal.h + * + * Copyright (c) 2010-2014 Institute for System Programming + * of the Russian Academy of Sciences. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include + +extern volatile unsigned int replay_data_kind; +extern volatile unsigned int replay_has_unread_data; + +/* File for replay writing */ +extern FILE *replay_file; + +void replay_put_byte(unsigned char byte); +void replay_put_event(unsigned char event); +void replay_put_word(uint16_t word); +void replay_put_dword(unsigned int dword); +void replay_put_qword(int64_t qword); +void replay_put_array(const uint8_t *buf, size_t size); + +unsigned char replay_get_byte(void); +uint16_t replay_get_word(void); +unsigned int replay_get_dword(void); +int64_t replay_get_qword(void); +void replay_get_array(uint8_t *buf, size_t *size); +void replay_get_array_alloc(uint8_t **buf, size_t *size); + +/*! Checks error status of the file. */ +void replay_check_error(void); + +/*! Reads data type from the file and stores it in the + replay_data_kind variable. */ +void replay_fetch_data_kind(void); + +/*! Saves queued events (like instructions and sound). */ +void replay_save_instructions(void); +/*! Checks that the next data is corresponding to the desired kind. + Terminates the program in case of error. */ +void validate_data_kind(int kind); + +#endif diff --git a/replay/replay.c b/replay/replay.c index 5a69465..2961e17 100755 --- a/replay/replay.c +++ b/replay/replay.c @@ -17,3 +17,9 @@ int play_submode = REPLAY_PLAY_UNKNOWN; /* Suffix for the disk images filenames */ char *replay_image_suffix; + + +int replay_get_play_submode(void) +{ + return play_submode; +}