hw/cpu/a15mpcore: If CPU has EL2, enable it on the GIC and wire it up
[qemu.git] / replay / replay-char.c
blob736cc8c2e61de0ec03a94cad8a9b127332549869
1 /*
2 * replay-char.c
4 * Copyright (c) 2010-2016 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/osdep.h"
13 #include "qemu/error-report.h"
14 #include "sysemu/replay.h"
15 #include "replay-internal.h"
16 #include "sysemu/sysemu.h"
17 #include "chardev/char.h"
19 /* Char drivers that generate qemu_chr_be_write events
20 that should be saved into the log. */
21 static Chardev **char_drivers;
22 static int drivers_count;
24 /* Char event attributes. */
25 typedef struct CharEvent {
26 int id;
27 uint8_t *buf;
28 size_t len;
29 } CharEvent;
31 static int find_char_driver(Chardev *chr)
33 int i = 0;
34 for ( ; i < drivers_count ; ++i) {
35 if (char_drivers[i] == chr) {
36 return i;
39 return -1;
42 void replay_register_char_driver(Chardev *chr)
44 if (replay_mode == REPLAY_MODE_NONE) {
45 return;
47 char_drivers = g_realloc(char_drivers,
48 sizeof(*char_drivers) * (drivers_count + 1));
49 char_drivers[drivers_count++] = chr;
52 void replay_chr_be_write(Chardev *s, uint8_t *buf, int len)
54 CharEvent *event = g_malloc0(sizeof(CharEvent));
56 event->id = find_char_driver(s);
57 if (event->id < 0) {
58 fprintf(stderr, "Replay: cannot find char driver\n");
59 exit(1);
61 event->buf = g_malloc(len);
62 memcpy(event->buf, buf, len);
63 event->len = len;
65 replay_add_event(REPLAY_ASYNC_EVENT_CHAR_READ, event, NULL, 0);
68 void replay_event_char_read_run(void *opaque)
70 CharEvent *event = (CharEvent *)opaque;
72 qemu_chr_be_write_impl(char_drivers[event->id], event->buf,
73 (int)event->len);
75 g_free(event->buf);
76 g_free(event);
79 void replay_event_char_read_save(void *opaque)
81 CharEvent *event = (CharEvent *)opaque;
83 replay_put_byte(event->id);
84 replay_put_array(event->buf, event->len);
87 void *replay_event_char_read_load(void)
89 CharEvent *event = g_malloc0(sizeof(CharEvent));
91 event->id = replay_get_byte();
92 replay_get_array_alloc(&event->buf, &event->len);
94 return event;
97 void replay_char_write_event_save(int res, int offset)
99 g_assert(replay_mutex_locked());
101 replay_save_instructions();
102 replay_put_event(EVENT_CHAR_WRITE);
103 replay_put_dword(res);
104 replay_put_dword(offset);
107 void replay_char_write_event_load(int *res, int *offset)
109 g_assert(replay_mutex_locked());
111 replay_account_executed_instructions();
112 if (replay_next_event_is(EVENT_CHAR_WRITE)) {
113 *res = replay_get_dword();
114 *offset = replay_get_dword();
115 replay_finish_event();
116 } else {
117 error_report("Missing character write event in the replay log");
118 exit(1);
122 int replay_char_read_all_load(uint8_t *buf)
124 g_assert(replay_mutex_locked());
126 if (replay_next_event_is(EVENT_CHAR_READ_ALL)) {
127 size_t size;
128 int res;
129 replay_get_array(buf, &size);
130 replay_finish_event();
131 res = (int)size;
132 assert(res >= 0);
133 return res;
134 } else if (replay_next_event_is(EVENT_CHAR_READ_ALL_ERROR)) {
135 int res = replay_get_dword();
136 replay_finish_event();
137 return res;
138 } else {
139 error_report("Missing character read all event in the replay log");
140 exit(1);
144 void replay_char_read_all_save_error(int res)
146 g_assert(replay_mutex_locked());
147 assert(res < 0);
148 replay_save_instructions();
149 replay_put_event(EVENT_CHAR_READ_ALL_ERROR);
150 replay_put_dword(res);
153 void replay_char_read_all_save_buf(uint8_t *buf, int offset)
155 g_assert(replay_mutex_locked());
156 replay_save_instructions();
157 replay_put_event(EVENT_CHAR_READ_ALL);
158 replay_put_array(buf, offset);