CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4];
static int io_mem_nb;
+/* log support */
+char *logfilename = "/tmp/qemu.log";
+FILE *logfile;
+int loglevel;
+
static void page_init(void)
{
/* NOTE: we can always suppose that host_page_size >=
#endif
}
+/* enable or disable low levels log */
+void cpu_set_log(int log_flags)
+{
+ loglevel = log_flags;
+ if (loglevel && !logfile) {
+ logfile = fopen(logfilename, "w");
+ if (!logfile) {
+ perror(logfilename);
+ _exit(1);
+ }
+ setvbuf(logfile, NULL, _IOLBF, 0);
+ }
+}
+
+void cpu_set_log_filename(const char *filename)
+{
+ logfilename = strdup(filename);
+}
/* mask must never be zero */
void cpu_interrupt(CPUState *env, int mask)
int cpl;
int iopl;
int tf; /* TF cpu flag */
+ int singlestep_enabled; /* "hardware" single step enabled */
int jmp_opt; /* use direct block chaining for direct jumps */
int mem_index; /* select memory access functions */
struct TranslationBlock *tb;
{
if (s->cc_op != CC_OP_DYNAMIC)
gen_op_set_cc_op(s->cc_op);
- if (s->tf) {
+ if (s->singlestep_enabled) {
+ gen_op_debug();
+ } else if (s->tf) {
gen_op_raise_exception(EXCP01_SSTP);
} else {
gen_op_movl_T0_0();
dc->cpl = (flags >> HF_CPL_SHIFT) & 3;
dc->iopl = (flags >> IOPL_SHIFT) & 3;
dc->tf = (flags >> TF_SHIFT) & 1;
+ dc->singlestep_enabled = env->singlestep_enabled;
dc->cc_op = CC_OP_DYNAMIC;
dc->cs_base = cs_base;
dc->tb = tb;
break;
/* if single step mode, we generate only one instruction and
generate an exception */
- if (dc->tf) {
+ if (dc->tf || dc->singlestep_enabled) {
gen_op_jmp_im(pc_ptr - dc->cs_base);
gen_eob(dc);
break;
#include "vl.h"
-#define DEBUG_LOGFILE "/tmp/vl.log"
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
#define BIOS_FILENAME "bios.bin"
#define VGABIOS_FILENAME "vgabios.bin"
char phys_ram_file[1024];
CPUX86State *global_env;
CPUX86State *cpu_single_env;
-FILE *logfile = NULL;
-int loglevel;
IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
BlockDriverState *bs_table[MAX_DISKS];
int dummy_refresh_clock;
int pit_min_timer_count = 0;
-int64_t get_clock(void)
+
+#if defined(__powerpc__)
+
+static inline uint32_t get_tbl(void)
{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return tv.tv_sec * 1000000LL + tv.tv_usec;
+ uint32_t tbl;
+ asm volatile("mftb %0" : "=r" (tbl));
+ return tbl;
}
-int64_t cpu_get_ticks(void)
+static inline uint32_t get_tbu(void)
+{
+ uint32_t tbl;
+ asm volatile("mftbu %0" : "=r" (tbl));
+ return tbl;
+}
+
+int64_t cpu_get_real_ticks(void)
+{
+ uint32_t l, h, h1;
+ /* NOTE: we test if wrapping has occurred */
+ do {
+ h = get_tbu();
+ l = get_tbl();
+ h1 = get_tbu();
+ } while (h != h1);
+ return ((int64_t)h << 32) | l;
+}
+
+#elif defined(__i386__)
+
+int64_t cpu_get_real_ticks(void)
{
int64_t val;
asm("rdtsc" : "=A" (val));
return val;
}
+#else
+#error unsupported CPU
+#endif
+
+static int64_t cpu_ticks_offset;
+static int64_t cpu_ticks_last;
+
+int64_t cpu_get_ticks(void)
+{
+ return cpu_get_real_ticks() + cpu_ticks_offset;
+}
+
+/* enable cpu_get_ticks() */
+void cpu_enable_ticks(void)
+{
+ cpu_ticks_offset = cpu_ticks_last - cpu_get_real_ticks();
+}
+
+/* disable cpu_get_ticks() : the clock is stopped. You must not call
+ cpu_get_ticks() after that. */
+void cpu_disable_ticks(void)
+{
+ cpu_ticks_last = cpu_get_ticks();
+}
+
+int64_t get_clock(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec * 1000000LL + tv.tv_usec;
+}
+
void cpu_calibrate_ticks(void)
{
int64_t usec, ticks;
}
serial_ok = 1;
+ cpu_enable_ticks();
for(;;) {
ret = cpu_x86_exec(env);
- if (reset_requested)
+ if (reset_requested) {
+ ret = EXCP_INTERRUPT;
break;
- if (ret == EXCP_DEBUG)
- return EXCP_DEBUG;
+ }
+ if (ret == EXCP_DEBUG) {
+ ret = EXCP_DEBUG;
+ break;
+ }
/* if hlt instruction, we wait until the next IRQ */
if (ret == EXCP_HLT)
timeout = 10;
uint8_t buf[1];
/* stop emulation if requested by gdb */
n = read(gdbstub_fd, buf, 1);
- if (n == 1)
+ if (n == 1) {
+ ret = EXCP_INTERRUPT;
break;
+ }
}
}
gui_refresh_pending = 0;
}
}
- return EXCP_INTERRUPT;
+ cpu_disable_ticks();
+ return ret;
}
void help(void)
}
break;
case 'd':
- loglevel = 1;
+ cpu_set_log(CPU_LOG_ALL);
break;
case 'n':
pstrcpy(network_script, sizeof(network_script), optarg);
/* init debug */
setvbuf(stdout, NULL, _IOLBF, 0);
- if (loglevel) {
- logfile = fopen(DEBUG_LOGFILE, "w");
- if (!logfile) {
- perror(DEBUG_LOGFILE);
- _exit(1);
- }
- setvbuf(logfile, NULL, _IOLBF, 0);
- }
/* init network tun interface */
if (net_fd < 0)