X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/986563b173ca2d4bd47b10455b19c86e5cd5bba2..1fba509527beb74bdcf50bc07ad3cd8244ad9c61:/bsd-user/main.c diff --git a/bsd-user/main.c b/bsd-user/main.c index cc7d4a37ad..de74d17cde 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -31,20 +31,19 @@ /* For tb_lock */ #include "cpu.h" #include "tcg.h" -#include "qemu-timer.h" -#include "envlist.h" - -#define DEBUG_LOGFILE "/tmp/qemu.log" +#include "qemu/timer.h" +#include "qemu/envlist.h" int singlestep; #if defined(CONFIG_USE_GUEST_BASE) unsigned long mmap_min_addr; unsigned long guest_base; int have_guest_base; +unsigned long reserved_va; #endif static const char *interp_prefix = CONFIG_QEMU_INTERP_PREFIX; -const char *qemu_uname_release = CONFIG_UNAME_RELEASE; +const char *qemu_uname_release; extern char **environ; enum BSDType bsd_type; @@ -63,18 +62,18 @@ void gemu_log(const char *fmt, ...) } #if defined(TARGET_I386) -int cpu_get_pic_interrupt(CPUState *env) +int cpu_get_pic_interrupt(CPUX86State *env) { return -1; } #endif /* These are no-ops because we are not threadsafe. */ -static inline void cpu_exec_start(CPUState *env) +static inline void cpu_exec_start(CPUArchState *env) { } -static inline void cpu_exec_end(CPUState *env) +static inline void cpu_exec_end(CPUArchState *env) { } @@ -93,7 +92,7 @@ void fork_start(void) void fork_end(int child) { if (child) { - gdbserver_fork(thread_env); + gdbserver_fork((CPUArchState *)thread_cpu->env_ptr); } } @@ -109,7 +108,7 @@ void cpu_list_unlock(void) /***********************************************************/ /* CPUX86 core interface */ -void cpu_smm_update(CPUState *env) +void cpu_smm_update(CPUX86State *env) { } @@ -379,8 +378,8 @@ void cpu_loop(CPUX86State *env) #endif default: pc = env->segs[R_CS].base + env->eip; - fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - aborting\n", - (long)pc, trapnr); + error_report("qemu: 0x%08lx: unhandled CPU exception 0x%x" + " - aborting", (long)pc, trapnr); abort(); } process_pending_signals(env); @@ -512,6 +511,7 @@ static void flush_windows(CPUSPARCState *env) void cpu_loop(CPUSPARCState *env) { + CPUState *cs = CPU(sparc_env_get_cpu(env)); int trapnr, ret, syscall_nr; //target_siginfo_t info; @@ -643,7 +643,7 @@ void cpu_loop(CPUSPARCState *env) { int sig; - sig = gdb_handlesig (env, TARGET_SIGTRAP); + sig = gdb_handlesig(cs, TARGET_SIGTRAP); #if 0 if (sig) { @@ -660,7 +660,7 @@ void cpu_loop(CPUSPARCState *env) badtrap: #endif printf ("Unhandled trap: 0x%x\n", trapnr); - cpu_dump_state(env, stderr, fprintf, 0); + cpu_dump_state(cs, stderr, fprintf, 0); exit (1); } process_pending_signals (env); @@ -671,8 +671,8 @@ void cpu_loop(CPUSPARCState *env) static void usage(void) { - printf("qemu-" TARGET_ARCH " version " QEMU_VERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n" - "usage: qemu-" TARGET_ARCH " [options] program [arguments...]\n" + printf("qemu-" TARGET_NAME " version " QEMU_VERSION ", Copyright (c) 2003-2008 Fabrice Bellard\n" + "usage: qemu-" TARGET_NAME " [options] program [arguments...]\n" "BSD CPU emulator (compiled for %s emulation)\n" "\n" "Standard options:\n" @@ -680,7 +680,7 @@ static void usage(void) "-g port wait gdb connection to port\n" "-L path set the elf interpreter prefix (default=%s)\n" "-s size set the stack size in bytes (default=%ld)\n" - "-cpu model select CPU (-cpu ? for list)\n" + "-cpu model select CPU (-cpu help for list)\n" "-drop-ld-preload drop LD_PRELOAD for target process\n" "-E var=value sets/modifies targets environment variable(s)\n" "-U var unsets targets environment variable(s)\n" @@ -690,11 +690,12 @@ static void usage(void) "-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n" "\n" "Debug options:\n" - "-d options activate log (default logfile=%s)\n" - "-D logfile override default logfile location\n" - "-p pagesize set the host page size to 'pagesize'\n" - "-singlestep always run in singlestep mode\n" - "-strace log system calls\n" + "-d item1[,...] enable logging of specified items\n" + " (use '-d help' for a list of log items)\n" + "-D logfile write logs to 'logfile' (default stderr)\n" + "-p pagesize set the host page size to 'pagesize'\n" + "-singlestep always run in singlestep mode\n" + "-strace log system calls\n" "\n" "Environment variables:\n" "QEMU_STRACE Print system calls and arguments similar to the\n" @@ -706,14 +707,13 @@ static void usage(void) "Note that if you provide several changes to single variable\n" "last change will stay in effect.\n" , - TARGET_ARCH, + TARGET_NAME, interp_prefix, - x86_stack_size, - DEBUG_LOGFILE); + x86_stack_size); exit(1); } -THREAD CPUState *thread_env; +THREAD CPUState *thread_cpu; /* Assumes contents are already zeroed. */ void init_task_state(TaskState *ts) @@ -732,12 +732,13 @@ int main(int argc, char **argv) { const char *filename; const char *cpu_model; - const char *log_file = DEBUG_LOGFILE; + const char *log_file = NULL; const char *log_mask = NULL; struct target_pt_regs regs1, *regs = ®s1; struct image_info info1, *info = &info1; TaskState ts1, *ts = &ts1; - CPUState *env; + CPUArchState *env; + CPUState *cpu; int optind; const char *r; int gdbstub_port = 0; @@ -748,8 +749,10 @@ int main(int argc, char **argv) if (argc <= 1) usage(); + module_call_init(MODULE_INIT_QOM); + if ((envlist = envlist_create()) == NULL) { - (void) fprintf(stderr, "Unable to allocate envlist\n"); + error_report("Unable to allocate envlist"); exit(1); } @@ -791,7 +794,7 @@ int main(int argc, char **argv) } else if (!strcmp(r, "ignore-environment")) { envlist_free(envlist); if ((envlist = envlist_create()) == NULL) { - (void) fprintf(stderr, "Unable to allocate envlist\n"); + error_report("Unable to allocate envlist"); exit(1); } } else if (!strcmp(r, "U")) { @@ -813,7 +816,7 @@ int main(int argc, char **argv) qemu_host_page_size = atoi(argv[optind++]); if (qemu_host_page_size == 0 || (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { - fprintf(stderr, "page size must be a power of two\n"); + error_report("page size must be a power of two"); exit(1); } } else if (!strcmp(r, "g")) { @@ -822,7 +825,7 @@ int main(int argc, char **argv) qemu_uname_release = argv[optind++]; } else if (!strcmp(r, "cpu")) { cpu_model = argv[optind++]; - if (strcmp(cpu_model, "?") == 0) { + if (is_help_option(cpu_model)) { /* XXX: implement xxx_cpu_list for targets that still miss it */ #if defined(cpu_list) cpu_list(stdout, &fprintf); @@ -858,20 +861,16 @@ int main(int argc, char **argv) } /* init debug */ - cpu_set_log_filename(log_file); + qemu_set_log_filename(log_file); if (log_mask) { int mask; - const CPULogItem *item; - mask = cpu_str_to_log_mask(log_mask); + mask = qemu_str_to_log_mask(log_mask); if (!mask) { - printf("Log items (comma separated):\n"); - for (item = cpu_log_items; item->mask != 0; item++) { - printf("%-10s %s\n", item->name, item->help); - } + qemu_print_log_usage(stdout); exit(1); } - cpu_set_log(mask); + qemu_set_log(mask); } if (optind >= argc) { @@ -911,13 +910,14 @@ int main(int argc, char **argv) qemu_host_page_size */ env = cpu_init(cpu_model); if (!env) { - fprintf(stderr, "Unable to find CPU definition\n"); + error_report("Unable to find CPU definition"); exit(1); } -#if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC) - cpu_reset(env); + cpu = ENV_GET_CPU(env); +#if defined(TARGET_SPARC) || defined(TARGET_PPC) + cpu_reset(cpu); #endif - thread_env = env; + thread_cpu = cpu; if (getenv("QEMU_STRACE")) { do_strace = 1; @@ -1000,21 +1000,19 @@ int main(int argc, char **argv) memset(ts, 0, sizeof(TaskState)); init_task_state(ts); ts->info = info; - env->opaque = ts; + cpu->opaque = ts; #if defined(TARGET_I386) - cpu_x86_set_cpl(env, 3); - env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; env->hflags |= HF_PE_MASK; - if (env->cpuid_features & CPUID_SSE) { + if (env->features[FEAT_1_EDX] & CPUID_SSE) { env->cr[4] |= CR4_OSFXSR_MASK; env->hflags |= HF_OSFXSR_MASK; } #ifndef TARGET_ABI32 /* enable 64 bit mode if possible */ - if (!(env->cpuid_ext2_features & CPUID_EXT2_LM)) { - fprintf(stderr, "The selected x86 CPU does not support 64 bit mode\n"); + if (!(env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM)) { + error_report("The selected x86 CPU does not support 64 bit mode"); exit(1); } env->cr[4] |= CR4_PAE_MASK; @@ -1136,7 +1134,7 @@ int main(int argc, char **argv) if (gdbstub_port) { gdbserver_start (gdbstub_port); - gdb_handlesig(env, 0); + gdb_handlesig(cpu, 0); } cpu_loop(env); /* never exits */