43 virtual void write_bytes(
void* data,
int num_bytes) = 0;
66 size(size),data(
new char[size]){}
67 void* get_data() {
return (
void*)data; }
68 int get_size() {
return size; }
69 void reset_size(
int size) { this->size = size; }
78 virtual void initialize_io_structures() = 0;
85 pthread_t read_thread;
86 pthread_mutex_t read_lock;
87 std::list<io_buffer*> read_q;
91 pthread_attr_t io_sched_attr;
92 struct sched_param fifo_param;
109 QemuNic(std::string mac_addr =
"");
120 void initialize_io_structures(){}
123 std::string mac_addr;
141 void initialize_io_structures();
143 char socket_file[100];
144 struct sockaddr_un address;
146 static const int buf_size;
164 void initialize_io_structures();
167 char write_file[100];
168 int read_fd, write_fd;
169 volatile bool exit_read;
170 static const int buf_size;
183 virtual unsigned read_mem(
unsigned addr) = 0;
184 virtual void write_mem(
unsigned addr,
unsigned dat) = 0;
198 virtual int elapsed() = 0;
200 static CompSysEmulator* launch_qemu(
const char* exec_file, std::vector<std::string>& args);
207 virtual bool is_alive() = 0;
209 virtual void run(
unsigned us) = 0;
211 virtual void join() = 0;
214 template <
typename X>
221 void delta_ext(
double e,
const Bag<X>& xb);
222 void delta_conf(
const Bag<X>& xb);
224 void output_func(
Bag<X>& yb);
227 double get_timing_error()
const {
return qemu_time-sim_time; }
228 double get_qemu_time()
const {
return qemu_time; }
229 double get_quantum_seconds()
const {
return quantum; }
230 double get_mean_timing_error()
const {
return acc_error/(double)(error_samples+1); }
231 double get_max_timing_error()
const {
return max_error; }
242 std::vector<std::string>& qemu_args,
243 std::string disk_img,
245 EmulatorMode emulator_mode = PRECISE);
247 std::vector<std::string>& qemu_args,
248 std::vector<std::string>& disks,
249 std::vector<std::string>& disk_formats,
253 EmulatorMode emulator_mode);
255 std::vector<std::string>& ucsim_args,
256 std::string flash_img,
260 const double quantum;
262 double ttg, qemu_time, sim_time, acc_error, max_error;
263 unsigned error_samples;
264 void inject_input(
void* buf,
unsigned size);
265 enum { CATCHUP, THREAD_RUNNING, IDLE } mode;
267 void internal_and_confluent();
270 template <
typename X>
273 quantum(quantum_seconds),
285 template <
typename X>
288 if (emulator != NULL)
290 if (mode == THREAD_RUNNING)
296 template <
typename X>
301 if (mode == THREAD_RUNNING)
306 qemu_time += (emulator->elapsed()/1E6);
310 template <
typename X>
320 if (mode != CATCHUP && qemu_time > sim_time)
324 acc_error += get_timing_error();
325 max_error = (max_error > get_timing_error()) ? max_error : get_timing_error();
326 ttg = qemu_time - sim_time;
329 else if (emulator->is_alive())
331 assert(mode != THREAD_RUNNING);
332 emulator->run(quantum*1E6);
333 mode = THREAD_RUNNING;
339 template <
typename X>
342 internal_and_confluent();
345 template <
typename X>
352 template <
typename X>
355 internal_and_confluent();
358 template <
typename X>
361 if (emulator->is_alive())
363 return adevs_inf<double>();
366 template <
typename X>
368 std::vector<std::string>& args,
369 std::vector<std::string>& disks,
370 std::vector<std::string>& disk_formats,
374 EmulatorMode emulator_mode)
377 args.push_back(
"-vga");
378 args.push_back(
"std");
379 args.push_back(
"-m");
380 sprintf(arg_buf,
"%d",mb_ram);
381 args.push_back(arg_buf);
383 args.push_back(
"-monitor");
384 args.push_back(
"none");
387 args.push_back(
"-rtc");
388 args.push_back(
"clock=vm");
390 if (emulator_mode == PRECISE)
392 sprintf(arg_buf,
"1,sleep=off");
393 args.push_back(
"-icount");
394 args.push_back(arg_buf);
396 else if (emulator_mode == FAST)
398 args.push_back(
"-cpu");
399 args.push_back(
"host,kvm=off,-kvmclock");
400 args.push_back(
"-enable-kvm");
403 for (
unsigned idx = 0; idx < disks.size(); idx++)
405 sprintf(arg_buf,
"file=%s,index=%u,media=disk,format=%s",
406 disks[idx].c_str(),idx,disk_formats[idx].c_str());
407 args.push_back(
"-drive");
408 args.push_back(arg_buf);
412 args.push_back(
"-cdrom");
413 args.push_back(cdrom);
416 args.push_back(
"-boot");
421 emulator = CompSysEmulator::launch_qemu(
"qemu-system-x86_64",args);
422 assert(emulator->is_alive());
425 template <
typename X>
427 std::vector<std::string>& args,
428 std::string disk_image,
430 QemuComputer<X>::EmulatorMode emulator_mode)
432 std::string cdrom =
"";
433 std::vector<std::string> disks, disk_formats;
434 disks.push_back(disk_image);
435 disk_formats.push_back(
"raw");
436 create_x86(args,disks,disk_formats,cdrom,
false,mb_ram,emulator_mode);
439 template <
typename X>
441 std::vector<std::string>& args,
442 std::string flash_image,
445 args.push_back(
"-t");
446 args.push_back(
"8052");
447 args.push_back(flash_image);
448 emulator = CompSysEmulator::launch_ucsim(
"s51",args,obj);
449 assert(emulator->is_alive());
double ta()
Definition: adevs_qemu.h:359
Definition: adevs_qemu.h:21
void output_func(Bag< X > &yb)
Definition: adevs_qemu.h:297
Definition: adevs_qemu.h:154
Definition: adevs_qemu.h:215
void read_bytes(void *buf)
Definition: adevs_qemu.h:191
Definition: adevs_qemu.h:100
void read_loop()
Called by the reading thread to execute the read loop.
virtual void write_bytes(void *data, int num_bytes)=0
virtual ~QemuDeviceModel()
Destructor.
Definition: adevs_fmi.h:57
void delta_conf(const Bag< X > &xb)
Definition: adevs_qemu.h:353
Definition: adevs_qemu.h:62
Definition: adevs_qemu.h:179
void delta_int()
Internal transition function.
Definition: adevs_qemu.h:340
virtual void append_qemu_arguments(std::vector< std::string > &args)=0
void delta_ext(double e, const Bag< X > &xb)
Definition: adevs_qemu.h:346
Definition: adevs_qemu.h:131
Definition: adevs_models.h:47
QemuDeviceModel()
Constructor.