39 virtual void write_bytes(
void* data,
int num_bytes) = 0;
57 size(size),data(
new char[size]){}
58 void* get_data() {
return (
void*)data; }
59 int get_size() {
return size; }
60 void reset_size(
int size) { this->size = size; }
69 virtual void initialize_io_structures() = 0;
76 pthread_t read_thread;
77 pthread_mutex_t read_lock;
78 std::list<io_buffer*> read_q;
82 pthread_attr_t io_sched_attr;
83 struct sched_param fifo_param;
95 QemuNic(std::string mac_addr =
"");
101 void initialize_io_structures(){}
104 std::string mac_addr;
122 void initialize_io_structures();
124 char socket_file[100];
125 struct sockaddr_un address;
127 static const int buf_size;
145 void initialize_io_structures();
148 char write_file[100];
149 int read_fd, write_fd;
150 volatile bool exit_read;
151 static const int buf_size;
164 virtual unsigned read_mem(
unsigned addr) = 0;
165 virtual void write_mem(
unsigned addr,
unsigned dat) = 0;
179 virtual int elapsed() = 0;
181 static CompSysEmulator* launch_qemu(
const char* exec_file, std::vector<std::string>& args);
188 virtual bool is_alive() = 0;
190 virtual void run(
unsigned us) = 0;
192 virtual void join() = 0;
195 template <
typename X>
202 void delta_ext(
double e,
const Bag<X>& xb);
203 void delta_conf(
const Bag<X>& xb);
205 void output_func(
Bag<X>& yb);
208 double get_timing_error()
const {
return qemu_time-sim_time; }
209 double get_qemu_time()
const {
return qemu_time; }
210 double get_quantum_seconds()
const {
return quantum; }
211 double get_mean_timing_error()
const {
return acc_error/(double)(error_samples+1); }
212 double get_max_timing_error()
const {
return max_error; }
223 std::vector<std::string>& qemu_args,
224 std::string disk_img,
226 EmulatorMode emulator_mode = PRECISE);
228 std::vector<std::string>& qemu_args,
229 std::vector<std::string>& disks,
230 std::vector<std::string>& disk_formats,
234 EmulatorMode emulator_mode);
236 std::vector<std::string>& ucsim_args,
237 std::string flash_img,
241 const double quantum;
243 double ttg, qemu_time, sim_time, acc_error, max_error;
244 unsigned error_samples;
245 void inject_input(
void* buf,
unsigned size);
246 enum { CATCHUP, THREAD_RUNNING, IDLE } mode;
248 void internal_and_confluent();
251 template <
typename X>
254 quantum(quantum_seconds),
266 template <
typename X>
269 if (emulator != NULL)
271 if (mode == THREAD_RUNNING)
277 template <
typename X>
282 if (mode == THREAD_RUNNING)
287 qemu_time += (emulator->elapsed()/1E6);
291 template <
typename X>
301 if (mode != CATCHUP && qemu_time > sim_time)
305 acc_error += get_timing_error();
306 max_error = (max_error > get_timing_error()) ? max_error : get_timing_error();
307 ttg = qemu_time - sim_time;
310 else if (emulator->is_alive())
312 assert(mode != THREAD_RUNNING);
313 emulator->run(quantum*1E6);
314 mode = THREAD_RUNNING;
320 template <
typename X>
323 internal_and_confluent();
326 template <
typename X>
333 template <
typename X>
336 internal_and_confluent();
339 template <
typename X>
342 if (emulator->is_alive())
344 return adevs_inf<double>();
347 template <
typename X>
349 std::vector<std::string>& args,
350 std::vector<std::string>& disks,
351 std::vector<std::string>& disk_formats,
355 EmulatorMode emulator_mode)
358 args.push_back(
"-vga");
359 args.push_back(
"std");
360 args.push_back(
"-m");
361 sprintf(arg_buf,
"%d",mb_ram);
362 args.push_back(arg_buf);
364 args.push_back(
"-monitor");
365 args.push_back(
"none");
368 args.push_back(
"-rtc");
369 args.push_back(
"clock=vm");
371 if (emulator_mode == PRECISE)
373 sprintf(arg_buf,
"1,sleep=off");
374 args.push_back(
"-icount");
375 args.push_back(arg_buf);
377 else if (emulator_mode == FAST)
379 args.push_back(
"-cpu");
380 args.push_back(
"kvm64,-kvmclock,-tsc");
381 args.push_back(
"-machine");
382 args.push_back(
"smm=off");
383 args.push_back(
"-enable-kvm");
386 for (
unsigned idx = 0; idx < disks.size(); idx++)
388 sprintf(arg_buf,
"file=%s,index=%u,media=disk,format=%s",
389 disks[idx].c_str(),idx,disk_formats[idx].c_str());
390 args.push_back(
"-drive");
391 args.push_back(arg_buf);
395 args.push_back(
"-cdrom");
396 args.push_back(cdrom);
399 args.push_back(
"-boot");
404 emulator = CompSysEmulator::launch_qemu(
"qemu-system-i386",args);
405 assert(emulator->is_alive());
408 template <
typename X>
410 std::vector<std::string>& args,
411 std::string disk_image,
413 QemuComputer<X>::EmulatorMode emulator_mode)
415 std::string cdrom =
"";
416 std::vector<std::string> disks, disk_formats;
417 disks.push_back(disk_image);
418 disk_formats.push_back(
"raw");
419 create_x86(args,disks,disk_formats,cdrom,
false,mb_ram,emulator_mode);
422 template <
typename X>
424 std::vector<std::string>& args,
425 std::string flash_image,
428 args.push_back(
"-t");
429 args.push_back(
"8052");
430 args.push_back(flash_image);
431 emulator = CompSysEmulator::launch_ucsim(
"s51",args,obj);
432 assert(emulator->is_alive());
double ta()
Definition: adevs_qemu.h:340
Definition: adevs_qemu.h:21
void output_func(Bag< X > &yb)
Definition: adevs_qemu.h:278
Definition: adevs_qemu.h:135
Definition: adevs_qemu.h:196
void read_bytes(void *buf)
Definition: adevs_qemu.h:172
Definition: adevs_qemu.h:91
virtual void write_bytes(void *data, int num_bytes)=0
Definition: adevs_fmi.h:57
void delta_conf(const Bag< X > &xb)
Definition: adevs_qemu.h:334
Definition: adevs_qemu.h:53
Definition: adevs_qemu.h:160
void delta_int()
Internal transition function.
Definition: adevs_qemu.h:321
virtual void append_qemu_arguments(std::vector< std::string > &args)=0
void delta_ext(double e, const Bag< X > &xb)
Definition: adevs_qemu.h:327
Definition: adevs_qemu.h:112
Definition: adevs_models.h:47