target/ppc: Moved vector multiply high and low to decodetree
[qemu/rayw.git] / replay / replay-internal.h
blob97649ed8d77b0d8785f498c5ae4a26596764e402
1 #ifndef REPLAY_INTERNAL_H
2 #define REPLAY_INTERNAL_H
4 /*
5 * replay-internal.h
7 * Copyright (c) 2010-2015 Institute for System Programming
8 * of the Russian Academy of Sciences.
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
15 /* Any changes to order/number of events will need to bump REPLAY_VERSION */
16 enum ReplayEvents {
17 /* for instruction event */
18 EVENT_INSTRUCTION,
19 /* for software interrupt */
20 EVENT_INTERRUPT,
21 /* for emulated exceptions */
22 EVENT_EXCEPTION,
23 /* for async events */
24 EVENT_ASYNC,
25 /* for shutdown requests, range allows recovery of ShutdownCause */
26 EVENT_SHUTDOWN,
27 EVENT_SHUTDOWN_LAST = EVENT_SHUTDOWN + SHUTDOWN_CAUSE__MAX,
28 /* for character device write event */
29 EVENT_CHAR_WRITE,
30 /* for character device read all event */
31 EVENT_CHAR_READ_ALL,
32 EVENT_CHAR_READ_ALL_ERROR,
33 /* for audio out event */
34 EVENT_AUDIO_OUT,
35 /* for audio in event */
36 EVENT_AUDIO_IN,
37 /* for random number generator */
38 EVENT_RANDOM,
39 /* for clock read/writes */
40 /* some of greater codes are reserved for clocks */
41 EVENT_CLOCK,
42 EVENT_CLOCK_LAST = EVENT_CLOCK + REPLAY_CLOCK_COUNT - 1,
43 /* for checkpoint event */
44 /* some of greater codes are reserved for checkpoints */
45 EVENT_CHECKPOINT,
46 EVENT_CHECKPOINT_LAST = EVENT_CHECKPOINT + CHECKPOINT_COUNT - 1,
47 /* end of log event */
48 EVENT_END,
49 EVENT_COUNT
52 /* Asynchronous events IDs */
54 enum ReplayAsyncEventKind {
55 REPLAY_ASYNC_EVENT_BH,
56 REPLAY_ASYNC_EVENT_BH_ONESHOT,
57 REPLAY_ASYNC_EVENT_INPUT,
58 REPLAY_ASYNC_EVENT_INPUT_SYNC,
59 REPLAY_ASYNC_EVENT_CHAR_READ,
60 REPLAY_ASYNC_EVENT_BLOCK,
61 REPLAY_ASYNC_EVENT_NET,
62 REPLAY_ASYNC_COUNT
65 typedef enum ReplayAsyncEventKind ReplayAsyncEventKind;
67 typedef struct ReplayState {
68 /*! Cached clock values. */
69 int64_t cached_clock[REPLAY_CLOCK_COUNT];
70 /*! Current icount - number of processed instructions. */
71 uint64_t current_icount;
72 /*! Number of instructions to be executed before other events happen. */
73 int instruction_count;
74 /*! Type of the currently executed event. */
75 unsigned int data_kind;
76 /*! Flag which indicates that event is not processed yet. */
77 unsigned int has_unread_data;
78 /*! Temporary variable for saving current log offset. */
79 uint64_t file_offset;
80 /*! Next block operation id.
81 This counter is global, because requests from different
82 block devices should not get overlapping ids. */
83 uint64_t block_request_id;
84 /*! Prior value of the host clock */
85 uint64_t host_clock_last;
86 /*! Asynchronous event type read from the log */
87 int32_t read_event_kind;
88 /*! Asynchronous event id read from the log */
89 uint64_t read_event_id;
90 /*! Asynchronous event checkpoint id read from the log */
91 int32_t read_event_checkpoint;
92 } ReplayState;
93 extern ReplayState replay_state;
95 /* File for replay writing */
96 extern FILE *replay_file;
97 /* Instruction count of the replay breakpoint */
98 extern uint64_t replay_break_icount;
99 /* Timer for the replay breakpoint callback */
100 extern QEMUTimer *replay_break_timer;
102 void replay_put_byte(uint8_t byte);
103 void replay_put_event(uint8_t event);
104 void replay_put_word(uint16_t word);
105 void replay_put_dword(uint32_t dword);
106 void replay_put_qword(int64_t qword);
107 void replay_put_array(const uint8_t *buf, size_t size);
109 uint8_t replay_get_byte(void);
110 uint16_t replay_get_word(void);
111 uint32_t replay_get_dword(void);
112 int64_t replay_get_qword(void);
113 void replay_get_array(uint8_t *buf, size_t *size);
114 void replay_get_array_alloc(uint8_t **buf, size_t *size);
116 /* Mutex functions for protecting replay log file and ensuring
117 * synchronisation between vCPU and main-loop threads. */
119 void replay_mutex_init(void);
120 bool replay_mutex_locked(void);
122 /*! Checks error status of the file. */
123 void replay_check_error(void);
125 /*! Finishes processing of the replayed event and fetches
126 the next event from the log. */
127 void replay_finish_event(void);
128 /*! Reads data type from the file and stores it in the
129 data_kind variable. */
130 void replay_fetch_data_kind(void);
132 /*! Advance replay_state.current_icount to the specified value. */
133 void replay_advance_current_icount(uint64_t current_icount);
134 /*! Saves queued events (like instructions and sound). */
135 void replay_save_instructions(void);
137 /*! Skips async events until some sync event will be found.
138 \return true, if event was found */
139 bool replay_next_event_is(int event);
141 /*! Reads next clock value from the file.
142 If clock kind read from the file is different from the parameter,
143 the value is not used. */
144 void replay_read_next_clock(unsigned int kind);
146 /* Asynchronous events queue */
148 /*! Initializes events' processing internals */
149 void replay_init_events(void);
150 /*! Clears internal data structures for events handling */
151 void replay_finish_events(void);
152 /*! Returns true if there are any unsaved events in the queue */
153 bool replay_has_events(void);
154 /*! Saves events from queue into the file */
155 void replay_save_events(int checkpoint);
156 /*! Read events from the file into the input queue */
157 void replay_read_events(int checkpoint);
158 /*! Adds specified async event to the queue */
159 void replay_add_event(ReplayAsyncEventKind event_kind, void *opaque,
160 void *opaque2, uint64_t id);
162 /* Input events */
164 /*! Saves input event to the log */
165 void replay_save_input_event(InputEvent *evt);
166 /*! Reads input event from the log */
167 InputEvent *replay_read_input_event(void);
168 /*! Adds input event to the queue */
169 void replay_add_input_event(struct InputEvent *event);
170 /*! Adds input sync event to the queue */
171 void replay_add_input_sync_event(void);
173 /* Character devices */
175 /*! Called to run char device read event. */
176 void replay_event_char_read_run(void *opaque);
177 /*! Writes char read event to the file. */
178 void replay_event_char_read_save(void *opaque);
179 /*! Reads char event read from the file. */
180 void *replay_event_char_read_load(void);
182 /* Network devices */
184 /*! Called to run network event. */
185 void replay_event_net_run(void *opaque);
186 /*! Writes network event to the file. */
187 void replay_event_net_save(void *opaque);
188 /*! Reads network from the file. */
189 void *replay_event_net_load(void);
191 /* VMState-related functions */
193 /* Registers replay VMState.
194 Should be called before virtual devices initialization
195 to make cached timers available for post_load functions. */
196 void replay_vmstate_register(void);
198 #endif