]> git.proxmox.com Git - mirror_qemu.git/blame - replay/replay-internal.h
i386/cpu: Store LAPIC bus frequency in CPU structure
[mirror_qemu.git] / replay / replay-internal.h
CommitLineData
c92079f4
PD
1#ifndef REPLAY_INTERNAL_H
2#define REPLAY_INTERNAL_H
3
4/*
5 * replay-internal.h
6 *
7 * Copyright (c) 2010-2015 Institute for System Programming
8 * of the Russian Academy of Sciences.
9 *
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.
12 *
13 */
14
80be169c 15/* Any changes to order/number of events will need to bump REPLAY_VERSION */
26bc60ac
PD
16enum ReplayEvents {
17 /* for instruction event */
18 EVENT_INSTRUCTION,
6f060969
PD
19 /* for software interrupt */
20 EVENT_INTERRUPT,
21 /* for emulated exceptions */
22 EVENT_EXCEPTION,
c0c071d0
PD
23 /* for async events */
24 EVENT_ASYNC,
802f045a 25 /* for shutdown requests, range allows recovery of ShutdownCause */
b60c48a7 26 EVENT_SHUTDOWN,
802f045a 27 EVENT_SHUTDOWN_LAST = EVENT_SHUTDOWN + SHUTDOWN_CAUSE__MAX,
33577b47
PD
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,
3d4d16f4
PD
33 /* for audio out event */
34 EVENT_AUDIO_OUT,
35 /* for audio in event */
36 EVENT_AUDIO_IN,
878ec29b
PD
37 /* for random number generator */
38 EVENT_RANDOM,
8eda206e
PD
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,
8bd7f71d
PD
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,
7615936e
PD
47 /* end of log event */
48 EVENT_END,
26bc60ac
PD
49 EVENT_COUNT
50};
51
c0c071d0
PD
52/* Asynchronous events IDs */
53
54enum ReplayAsyncEventKind {
8a354bd9 55 REPLAY_ASYNC_EVENT_BH,
e4ec5ad4 56 REPLAY_ASYNC_EVENT_BH_ONESHOT,
ee312992
PD
57 REPLAY_ASYNC_EVENT_INPUT,
58 REPLAY_ASYNC_EVENT_INPUT_SYNC,
33577b47 59 REPLAY_ASYNC_EVENT_CHAR_READ,
63785678 60 REPLAY_ASYNC_EVENT_BLOCK,
646c5478 61 REPLAY_ASYNC_EVENT_NET,
c0c071d0
PD
62 REPLAY_ASYNC_COUNT
63};
64
65typedef enum ReplayAsyncEventKind ReplayAsyncEventKind;
66
26bc60ac 67typedef struct ReplayState {
8eda206e
PD
68 /*! Cached clock values. */
69 int64_t cached_clock[REPLAY_CLOCK_COUNT];
13f26713
PD
70 /*! Current icount - number of processed instructions. */
71 uint64_t current_icount;
26bc60ac 72 /*! Number of instructions to be executed before other events happen. */
13f26713 73 int instruction_count;
f186d64d
PD
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;
306e196f
PD
78 /*! Temporary variable for saving current log offset. */
79 uint64_t file_offset;
6d0ceb80
PD
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;
4b930d26
PD
84 /*! Prior value of the host clock */
85 uint64_t host_clock_last;
0b30dc01
PD
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;
26bc60ac
PD
92} ReplayState;
93extern ReplayState replay_state;
94
c92079f4
PD
95/* File for replay writing */
96extern FILE *replay_file;
97
98void replay_put_byte(uint8_t byte);
99void replay_put_event(uint8_t event);
100void replay_put_word(uint16_t word);
101void replay_put_dword(uint32_t dword);
102void replay_put_qword(int64_t qword);
103void replay_put_array(const uint8_t *buf, size_t size);
104
105uint8_t replay_get_byte(void);
106uint16_t replay_get_word(void);
107uint32_t replay_get_dword(void);
108int64_t replay_get_qword(void);
109void replay_get_array(uint8_t *buf, size_t *size);
110void replay_get_array_alloc(uint8_t **buf, size_t *size);
111
a36544d3
AB
112/* Mutex functions for protecting replay log file and ensuring
113 * synchronisation between vCPU and main-loop threads. */
c16861ef
PD
114
115void replay_mutex_init(void);
a36544d3 116bool replay_mutex_locked(void);
c16861ef 117
c92079f4
PD
118/*! Checks error status of the file. */
119void replay_check_error(void);
120
121/*! Finishes processing of the replayed event and fetches
122 the next event from the log. */
123void replay_finish_event(void);
124/*! Reads data type from the file and stores it in the
f186d64d 125 data_kind variable. */
c92079f4
PD
126void replay_fetch_data_kind(void);
127
13f26713
PD
128/*! Advance replay_state.current_icount to the specified value. */
129void replay_advance_current_icount(uint64_t current_icount);
26bc60ac
PD
130/*! Saves queued events (like instructions and sound). */
131void replay_save_instructions(void);
132
133/*! Skips async events until some sync event will be found.
134 \return true, if event was found */
135bool replay_next_event_is(int event);
136
8eda206e
PD
137/*! Reads next clock value from the file.
138 If clock kind read from the file is different from the parameter,
139 the value is not used. */
140void replay_read_next_clock(unsigned int kind);
141
c0c071d0
PD
142/* Asynchronous events queue */
143
144/*! Initializes events' processing internals */
145void replay_init_events(void);
146/*! Clears internal data structures for events handling */
147void replay_finish_events(void);
c0c071d0
PD
148/*! Flushes events queue */
149void replay_flush_events(void);
c0c071d0
PD
150/*! Returns true if there are any unsaved events in the queue */
151bool replay_has_events(void);
152/*! Saves events from queue into the file */
153void replay_save_events(int checkpoint);
154/*! Read events from the file into the input queue */
155void replay_read_events(int checkpoint);
33577b47
PD
156/*! Adds specified async event to the queue */
157void replay_add_event(ReplayAsyncEventKind event_kind, void *opaque,
158 void *opaque2, uint64_t id);
c0c071d0 159
ee312992
PD
160/* Input events */
161
162/*! Saves input event to the log */
163void replay_save_input_event(InputEvent *evt);
164/*! Reads input event from the log */
165InputEvent *replay_read_input_event(void);
166/*! Adds input event to the queue */
167void replay_add_input_event(struct InputEvent *event);
168/*! Adds input sync event to the queue */
169void replay_add_input_sync_event(void);
170
33577b47
PD
171/* Character devices */
172
173/*! Called to run char device read event. */
174void replay_event_char_read_run(void *opaque);
175/*! Writes char read event to the file. */
176void replay_event_char_read_save(void *opaque);
177/*! Reads char event read from the file. */
178void *replay_event_char_read_load(void);
179
646c5478
PD
180/* Network devices */
181
182/*! Called to run network event. */
183void replay_event_net_run(void *opaque);
184/*! Writes network event to the file. */
185void replay_event_net_save(void *opaque);
186/*! Reads network from the file. */
187void *replay_event_net_load(void);
188
306e196f
PD
189/* VMState-related functions */
190
191/* Registers replay VMState.
192 Should be called before virtual devices initialization
193 to make cached timers available for post_load functions. */
194void replay_vmstate_register(void);
195
c92079f4 196#endif