xref: /qemu/replay/replay-internal.h (revision 8eda206e)
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 
15 #include <stdio.h>
16 
17 enum ReplayEvents {
18     /* for instruction event */
19     EVENT_INSTRUCTION,
20     /* for software interrupt */
21     EVENT_INTERRUPT,
22     /* for emulated exceptions */
23     EVENT_EXCEPTION,
24     /* for async events */
25     EVENT_ASYNC,
26     /* for clock read/writes */
27     /* some of greater codes are reserved for clocks */
28     EVENT_CLOCK,
29     EVENT_CLOCK_LAST = EVENT_CLOCK + REPLAY_CLOCK_COUNT - 1,
30     EVENT_COUNT
31 };
32 
33 /* Asynchronous events IDs */
34 
35 enum ReplayAsyncEventKind {
36     REPLAY_ASYNC_COUNT
37 };
38 
39 typedef enum ReplayAsyncEventKind ReplayAsyncEventKind;
40 
41 typedef struct ReplayState {
42     /*! Cached clock values. */
43     int64_t cached_clock[REPLAY_CLOCK_COUNT];
44     /*! Current step - number of processed instructions and timer events. */
45     uint64_t current_step;
46     /*! Number of instructions to be executed before other events happen. */
47     int instructions_count;
48 } ReplayState;
49 extern ReplayState replay_state;
50 
51 extern unsigned int replay_data_kind;
52 
53 /* File for replay writing */
54 extern FILE *replay_file;
55 
56 void replay_put_byte(uint8_t byte);
57 void replay_put_event(uint8_t event);
58 void replay_put_word(uint16_t word);
59 void replay_put_dword(uint32_t dword);
60 void replay_put_qword(int64_t qword);
61 void replay_put_array(const uint8_t *buf, size_t size);
62 
63 uint8_t replay_get_byte(void);
64 uint16_t replay_get_word(void);
65 uint32_t replay_get_dword(void);
66 int64_t replay_get_qword(void);
67 void replay_get_array(uint8_t *buf, size_t *size);
68 void replay_get_array_alloc(uint8_t **buf, size_t *size);
69 
70 /* Mutex functions for protecting replay log file */
71 
72 void replay_mutex_init(void);
73 void replay_mutex_destroy(void);
74 void replay_mutex_lock(void);
75 void replay_mutex_unlock(void);
76 
77 /*! Checks error status of the file. */
78 void replay_check_error(void);
79 
80 /*! Finishes processing of the replayed event and fetches
81     the next event from the log. */
82 void replay_finish_event(void);
83 /*! Reads data type from the file and stores it in the
84     replay_data_kind variable. */
85 void replay_fetch_data_kind(void);
86 
87 /*! Saves queued events (like instructions and sound). */
88 void replay_save_instructions(void);
89 
90 /*! Skips async events until some sync event will be found.
91     \return true, if event was found */
92 bool replay_next_event_is(int event);
93 
94 /*! Reads next clock value from the file.
95     If clock kind read from the file is different from the parameter,
96     the value is not used. */
97 void replay_read_next_clock(unsigned int kind);
98 
99 /* Asynchronous events queue */
100 
101 /*! Initializes events' processing internals */
102 void replay_init_events(void);
103 /*! Clears internal data structures for events handling */
104 void replay_finish_events(void);
105 /*! Enables storing events in the queue */
106 void replay_enable_events(void);
107 /*! Flushes events queue */
108 void replay_flush_events(void);
109 /*! Clears events list before loading new VM state */
110 void replay_clear_events(void);
111 /*! Returns true if there are any unsaved events in the queue */
112 bool replay_has_events(void);
113 /*! Saves events from queue into the file */
114 void replay_save_events(int checkpoint);
115 /*! Read events from the file into the input queue */
116 void replay_read_events(int checkpoint);
117 
118 #endif
119