#include "exec.h"
//#define DEBUG_TB_INVALIDATE
-#define DEBUG_FLUSH
+//#define DEBUG_FLUSH
/* make various TB consistency checks */
//#define DEBUG_TB_CHECK
static PageDesc *l1_map[L1_SIZE];
-void page_init(void)
+static void page_init(void)
{
/* NOTE: we can always suppose that host_page_size >=
TARGET_PAGE_SIZE */
spin_unlock(&tb_lock);
}
-void cpu_x86_tblocks_init(void)
+void cpu_exec_init(void)
{
if (!code_gen_ptr) {
code_gen_ptr = code_gen_buffer;
+ page_init();
}
}
page_unprotect(addr);
}
}
+
+/* find the TB 'tb' such that tb[0].tc_ptr <= tc_ptr <
+ tb[1].tc_ptr. Return NULL if not found */
+TranslationBlock *tb_find_pc(unsigned long tc_ptr)
+{
+ int m_min, m_max, m;
+ unsigned long v;
+ TranslationBlock *tb;
+
+ if (nb_tbs <= 0)
+ return NULL;
+ if (tc_ptr < (unsigned long)code_gen_buffer ||
+ tc_ptr >= (unsigned long)code_gen_ptr)
+ return NULL;
+ /* binary search (cf Knuth) */
+ m_min = 0;
+ m_max = nb_tbs - 1;
+ while (m_min <= m_max) {
+ m = (m_min + m_max) >> 1;
+ tb = &tbs[m];
+ v = (unsigned long)tb->tc_ptr;
+ if (v == tc_ptr)
+ return tb;
+ else if (tc_ptr < v) {
+ m_max = m - 1;
+ } else {
+ m_min = m + 1;
+ }
+ }
+ return &tbs[m_max];
+}
+
+void cpu_abort(CPUState *env, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ fprintf(stderr, "qemu: fatal: ");
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+#ifdef TARGET_I386
+ cpu_x86_dump_state(env, stderr, X86_DUMP_FPU | X86_DUMP_CCOP);
+#endif
+ va_end(ap);
+ abort();
+}
+
+#ifdef TARGET_I386
+/* unmap all maped pages and flush all associated code */
+void page_unmap(void)
+{
+ PageDesc *p, *pmap;
+ unsigned long addr;
+ int i, j, ret, j1;
+
+ for(i = 0; i < L1_SIZE; i++) {
+ pmap = l1_map[i];
+ if (pmap) {
+ p = pmap;
+ for(j = 0;j < L2_SIZE;) {
+ if (p->flags & PAGE_VALID) {
+ addr = (i << (32 - L1_BITS)) | (j << TARGET_PAGE_BITS);
+ /* we try to find a range to make less syscalls */
+ j1 = j;
+ p++;
+ j++;
+ while (j < L2_SIZE && (p->flags & PAGE_VALID)) {
+ p++;
+ j++;
+ }
+ ret = munmap((void *)addr, (j - j1) << TARGET_PAGE_BITS);
+ if (ret != 0) {
+ fprintf(stderr, "Could not unmap page 0x%08lx\n", addr);
+ exit(1);
+ }
+ } else {
+ p++;
+ j++;
+ }
+ }
+ free(pmap);
+ l1_map[i] = NULL;
+ }
+ }
+ tb_flush();
+}
+#endif