4 * Copyright (c) 2010-2015 Institute for System Programming
5 * of the Russian Academy of Sciences.
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
12 #include "qemu-common.h"
13 #include "sysemu/replay.h"
14 #include "replay-internal.h"
15 #include "qemu/timer.h"
16 #include "qemu/main-loop.h"
18 ReplayMode replay_mode = REPLAY_MODE_NONE;
20 ReplayState replay_state;
22 bool replay_next_event_is(int event)
26 /* nothing to skip - not all instructions used */
27 if (replay_state.instructions_count != 0) {
28 assert(replay_data_kind == EVENT_INSTRUCTION);
29 return event == EVENT_INSTRUCTION;
33 if (event == replay_data_kind) {
36 switch (replay_data_kind) {
38 /* clock, time_t, checkpoint and other events */
45 uint64_t replay_get_current_step(void)
47 return cpu_get_icount_raw();
50 int replay_get_instructions(void)
54 if (replay_next_event_is(EVENT_INSTRUCTION)) {
55 res = replay_state.instructions_count;
57 replay_mutex_unlock();
61 void replay_account_executed_instructions(void)
63 if (replay_mode == REPLAY_MODE_PLAY) {
65 if (replay_state.instructions_count > 0) {
66 int count = (int)(replay_get_current_step()
67 - replay_state.current_step);
68 replay_state.instructions_count -= count;
69 replay_state.current_step += count;
70 if (replay_state.instructions_count == 0) {
71 assert(replay_data_kind == EVENT_INSTRUCTION);
72 replay_finish_event();
73 /* Wake up iothread. This is required because
74 timers will not expire until clock counters
75 will be read from the log. */
79 replay_mutex_unlock();
83 bool replay_exception(void)
85 if (replay_mode == REPLAY_MODE_RECORD) {
86 replay_save_instructions();
88 replay_put_event(EVENT_EXCEPTION);
89 replay_mutex_unlock();
91 } else if (replay_mode == REPLAY_MODE_PLAY) {
92 bool res = replay_has_exception();
95 replay_finish_event();
96 replay_mutex_unlock();
104 bool replay_has_exception(void)
107 if (replay_mode == REPLAY_MODE_PLAY) {
108 replay_account_executed_instructions();
110 res = replay_next_event_is(EVENT_EXCEPTION);
111 replay_mutex_unlock();
117 bool replay_interrupt(void)
119 if (replay_mode == REPLAY_MODE_RECORD) {
120 replay_save_instructions();
122 replay_put_event(EVENT_INTERRUPT);
123 replay_mutex_unlock();
125 } else if (replay_mode == REPLAY_MODE_PLAY) {
126 bool res = replay_has_interrupt();
129 replay_finish_event();
130 replay_mutex_unlock();
138 bool replay_has_interrupt(void)
141 if (replay_mode == REPLAY_MODE_PLAY) {
142 replay_account_executed_instructions();
144 res = replay_next_event_is(EVENT_INTERRUPT);
145 replay_mutex_unlock();