4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qemu/help-texts.h"
22 #include "qemu/units.h"
23 #include "qemu/accel.h"
24 #include "qemu-version.h"
25 #include <sys/syscall.h>
26 #include <sys/resource.h>
28 #include <linux/binfmts.h>
30 #include "qapi/error.h"
32 #include "user-internals.h"
33 #include "qemu/path.h"
34 #include "qemu/queue.h"
35 #include "qemu/config-file.h"
36 #include "qemu/cutils.h"
37 #include "qemu/error-report.h"
38 #include "qemu/help_option.h"
39 #include "qemu/module.h"
40 #include "qemu/plugin.h"
41 #include "exec/exec-all.h"
42 #include "exec/gdbstub.h"
44 #include "qemu/timer.h"
45 #include "qemu/envlist.h"
46 #include "qemu/guest-random.h"
48 #include "trace/control.h"
49 #include "target_elf.h"
50 #include "cpu_loop-common.h"
51 #include "crypto/init.h"
53 #include "signal-common.h"
55 #include "user-mmap.h"
56 #include "accel/tcg/perf.h"
58 #ifdef CONFIG_SEMIHOSTING
59 #include "semihosting/semihost.h"
62 #ifndef AT_FLAGS_PRESERVE_ARGV0
63 #define AT_FLAGS_PRESERVE_ARGV0_BIT 0
64 #define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT)
68 char real_exec_path
[PATH_MAX
];
71 static const char *argv0
;
72 static const char *gdbstub
;
73 static envlist_t
*envlist
;
74 static const char *cpu_model
;
75 static const char *cpu_type
;
76 static const char *seed_optarg
;
77 unsigned long mmap_min_addr
;
82 * Used to implement backwards-compatibility for the `-strace`, and
83 * QEMU_STRACE options. Without this, the QEMU_LOG can be overwritten by
84 * -strace, or vice versa.
86 static bool enable_strace
;
89 * The last log mask given by the user in an environment variable or argument.
90 * Used to support command line arguments overriding environment variables.
92 static int last_log_mask
;
93 static const char *last_log_filename
;
96 * When running 32-on-64 we should make sure we can fit all of the possible
97 * guest address space into a contiguous chunk of virtual host memory.
99 * This way we will never overlap with our own libraries or binaries or stack
100 * or anything else that QEMU maps.
102 * Many cpus reserve the high bit (or more than one for some 64-bit cpus)
103 * of the address for the kernel. Some cpus rely on this and user space
104 * uses the high bit(s) for pointer tagging and the like. For them, we
105 * must preserve the expected address space.
107 #ifndef MAX_RESERVED_VA
108 # if HOST_LONG_BITS > TARGET_VIRT_ADDR_SPACE_BITS
109 # if TARGET_VIRT_ADDR_SPACE_BITS == 32 && \
110 (TARGET_LONG_BITS == 32 || defined(TARGET_ABI32))
111 /* There are a number of places where we assign reserved_va to a variable
112 of type abi_ulong and expect it to fit. Avoid the last page. */
113 # define MAX_RESERVED_VA(CPU) (0xfffffffful & TARGET_PAGE_MASK)
115 # define MAX_RESERVED_VA(CPU) (1ul << TARGET_VIRT_ADDR_SPACE_BITS)
118 # define MAX_RESERVED_VA(CPU) 0
122 unsigned long reserved_va
;
124 static void usage(int exitcode
);
126 static const char *interp_prefix
= CONFIG_QEMU_INTERP_PREFIX
;
127 const char *qemu_uname_release
;
129 #if !defined(TARGET_DEFAULT_STACK_SIZE)
130 /* XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
131 we allocate a bigger stack. Need a better solution, for example
132 by remapping the process stack directly at the right place */
133 #define TARGET_DEFAULT_STACK_SIZE 8 * 1024 * 1024UL
136 unsigned long guest_stack_size
= TARGET_DEFAULT_STACK_SIZE
;
138 /***********************************************************/
139 /* Helper routines for implementing atomic operations. */
141 /* Make sure everything is in a consistent state for calling fork(). */
142 void fork_start(void)
147 qemu_plugin_user_prefork_lock();
150 void fork_end(int child
)
152 qemu_plugin_user_postfork(child
);
153 mmap_fork_end(child
);
155 CPUState
*cpu
, *next_cpu
;
156 /* Child processes created by fork() only have a single thread.
157 Discard information about the parent threads. */
158 CPU_FOREACH_SAFE(cpu
, next_cpu
) {
159 if (cpu
!= thread_cpu
) {
160 QTAILQ_REMOVE_RCU(&cpus
, cpu
, node
);
163 qemu_init_cpu_list();
164 gdbserver_fork(thread_cpu
);
169 * qemu_init_cpu_list() reinitialized the child exclusive state, but we
170 * also need to keep current_cpu consistent, so call end_exclusive() for
171 * both child and parent.
176 __thread CPUState
*thread_cpu
;
178 bool qemu_cpu_is_self(CPUState
*cpu
)
180 return thread_cpu
== cpu
;
183 void qemu_cpu_kick(CPUState
*cpu
)
188 void task_settid(TaskState
*ts
)
190 if (ts
->ts_tid
== 0) {
191 ts
->ts_tid
= (pid_t
)syscall(SYS_gettid
);
195 void stop_all_tasks(void)
198 * We trust that when using NPTL, start_exclusive()
199 * handles thread stopping correctly.
204 /* Assumes contents are already zeroed. */
205 void init_task_state(TaskState
*ts
)
211 ts
->sigaltstack_used
= (struct target_sigaltstack
) {
214 .ss_flags
= TARGET_SS_DISABLE
,
217 /* Capture task start time relative to system boot */
219 ticks_per_sec
= sysconf(_SC_CLK_TCK
);
221 if ((ticks_per_sec
> 0) && !clock_gettime(CLOCK_BOOTTIME
, &bt
)) {
222 /* start_boottime is expressed in clock ticks */
223 ts
->start_boottime
= bt
.tv_sec
* (uint64_t) ticks_per_sec
;
224 ts
->start_boottime
+= bt
.tv_nsec
* (uint64_t) ticks_per_sec
/
225 NANOSECONDS_PER_SECOND
;
229 CPUArchState
*cpu_copy(CPUArchState
*env
)
231 CPUState
*cpu
= env_cpu(env
);
232 CPUState
*new_cpu
= cpu_create(cpu_type
);
233 CPUArchState
*new_env
= new_cpu
->env_ptr
;
236 /* Reset non arch specific state */
239 new_cpu
->tcg_cflags
= cpu
->tcg_cflags
;
240 memcpy(new_env
, env
, sizeof(CPUArchState
));
241 #if defined(TARGET_I386) || defined(TARGET_X86_64)
242 new_env
->gdt
.base
= target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES
,
243 PROT_READ
| PROT_WRITE
,
244 MAP_ANONYMOUS
| MAP_PRIVATE
, -1, 0);
245 memcpy(g2h_untagged(new_env
->gdt
.base
), g2h_untagged(env
->gdt
.base
),
246 sizeof(uint64_t) * TARGET_GDT_ENTRIES
);
247 OBJECT(new_cpu
)->free
= OBJECT(cpu
)->free
;
250 /* Clone all break/watchpoints.
251 Note: Once we support ptrace with hw-debug register access, make sure
252 BP_CPU break/watchpoints are handled correctly on clone. */
253 QTAILQ_INIT(&new_cpu
->breakpoints
);
254 QTAILQ_FOREACH(bp
, &cpu
->breakpoints
, entry
) {
255 cpu_breakpoint_insert(new_cpu
, bp
->pc
, bp
->flags
, NULL
);
261 static void handle_arg_help(const char *arg
)
266 static void handle_arg_log(const char *arg
)
268 last_log_mask
= qemu_str_to_log_mask(arg
);
269 if (!last_log_mask
) {
270 qemu_print_log_usage(stdout
);
275 static void handle_arg_dfilter(const char *arg
)
277 qemu_set_dfilter_ranges(arg
, &error_fatal
);
280 static void handle_arg_log_filename(const char *arg
)
282 last_log_filename
= arg
;
285 static void handle_arg_set_env(const char *arg
)
289 while ((token
= strsep(&p
, ",")) != NULL
) {
290 if (envlist_setenv(envlist
, token
) != 0) {
297 static void handle_arg_unset_env(const char *arg
)
301 while ((token
= strsep(&p
, ",")) != NULL
) {
302 if (envlist_unsetenv(envlist
, token
) != 0) {
309 static void handle_arg_argv0(const char *arg
)
314 static void handle_arg_stack_size(const char *arg
)
317 guest_stack_size
= strtoul(arg
, &p
, 0);
318 if (guest_stack_size
== 0) {
323 guest_stack_size
*= MiB
;
324 } else if (*p
== 'k' || *p
== 'K') {
325 guest_stack_size
*= KiB
;
329 static void handle_arg_ld_prefix(const char *arg
)
331 interp_prefix
= strdup(arg
);
334 static void handle_arg_pagesize(const char *arg
)
336 qemu_host_page_size
= atoi(arg
);
337 if (qemu_host_page_size
== 0 ||
338 (qemu_host_page_size
& (qemu_host_page_size
- 1)) != 0) {
339 fprintf(stderr
, "page size must be a power of two\n");
344 static void handle_arg_seed(const char *arg
)
349 static void handle_arg_gdb(const char *arg
)
351 gdbstub
= g_strdup(arg
);
354 static void handle_arg_uname(const char *arg
)
356 qemu_uname_release
= strdup(arg
);
359 static void handle_arg_cpu(const char *arg
)
361 cpu_model
= strdup(arg
);
362 if (cpu_model
== NULL
|| is_help_option(cpu_model
)) {
363 /* XXX: implement xxx_cpu_list for targets that still miss it */
364 #if defined(cpu_list)
371 static void handle_arg_guest_base(const char *arg
)
373 guest_base
= strtol(arg
, NULL
, 0);
374 have_guest_base
= true;
377 static void handle_arg_reserved_va(const char *arg
)
381 reserved_va
= strtoul(arg
, &p
, 0);
395 unsigned long unshifted
= reserved_va
;
397 reserved_va
<<= shift
;
398 if (reserved_va
>> shift
!= unshifted
) {
399 fprintf(stderr
, "Reserved virtual address too big\n");
404 fprintf(stderr
, "Unrecognised -R size suffix '%s'\n", p
);
409 static void handle_arg_singlestep(const char *arg
)
414 static void handle_arg_strace(const char *arg
)
416 enable_strace
= true;
419 static void handle_arg_version(const char *arg
)
421 printf("qemu-" TARGET_NAME
" version " QEMU_FULL_VERSION
422 "\n" QEMU_COPYRIGHT
"\n");
426 static void handle_arg_trace(const char *arg
)
428 trace_opt_parse(arg
);
431 #if defined(TARGET_XTENSA)
432 static void handle_arg_abi_call0(const char *arg
)
434 xtensa_set_abi_call0();
438 static void handle_arg_perfmap(const char *arg
)
440 perf_enable_perfmap();
443 static void handle_arg_jitdump(const char *arg
)
445 perf_enable_jitdump();
448 static QemuPluginList plugins
= QTAILQ_HEAD_INITIALIZER(plugins
);
451 static void handle_arg_plugin(const char *arg
)
453 qemu_plugin_opt_parse(arg
, &plugins
);
457 struct qemu_argument
{
461 void (*handle_opt
)(const char *arg
);
466 static const struct qemu_argument arg_table
[] = {
467 {"h", "", false, handle_arg_help
,
468 "", "print this help"},
469 {"help", "", false, handle_arg_help
,
471 {"g", "QEMU_GDB", true, handle_arg_gdb
,
472 "port", "wait gdb connection to 'port'"},
473 {"L", "QEMU_LD_PREFIX", true, handle_arg_ld_prefix
,
474 "path", "set the elf interpreter prefix to 'path'"},
475 {"s", "QEMU_STACK_SIZE", true, handle_arg_stack_size
,
476 "size", "set the stack size to 'size' bytes"},
477 {"cpu", "QEMU_CPU", true, handle_arg_cpu
,
478 "model", "select CPU (-cpu help for list)"},
479 {"E", "QEMU_SET_ENV", true, handle_arg_set_env
,
480 "var=value", "sets targets environment variable (see below)"},
481 {"U", "QEMU_UNSET_ENV", true, handle_arg_unset_env
,
482 "var", "unsets targets environment variable (see below)"},
483 {"0", "QEMU_ARGV0", true, handle_arg_argv0
,
484 "argv0", "forces target process argv[0] to be 'argv0'"},
485 {"r", "QEMU_UNAME", true, handle_arg_uname
,
486 "uname", "set qemu uname release string to 'uname'"},
487 {"B", "QEMU_GUEST_BASE", true, handle_arg_guest_base
,
488 "address", "set guest_base address to 'address'"},
489 {"R", "QEMU_RESERVED_VA", true, handle_arg_reserved_va
,
490 "size", "reserve 'size' bytes for guest virtual address space"},
491 {"d", "QEMU_LOG", true, handle_arg_log
,
492 "item[,...]", "enable logging of specified items "
493 "(use '-d help' for a list of items)"},
494 {"dfilter", "QEMU_DFILTER", true, handle_arg_dfilter
,
495 "range[,...]","filter logging based on address range"},
496 {"D", "QEMU_LOG_FILENAME", true, handle_arg_log_filename
,
497 "logfile", "write logs to 'logfile' (default stderr)"},
498 {"p", "QEMU_PAGESIZE", true, handle_arg_pagesize
,
499 "pagesize", "set the host page size to 'pagesize'"},
500 {"singlestep", "QEMU_SINGLESTEP", false, handle_arg_singlestep
,
501 "", "run in singlestep mode"},
502 {"strace", "QEMU_STRACE", false, handle_arg_strace
,
503 "", "log system calls"},
504 {"seed", "QEMU_RAND_SEED", true, handle_arg_seed
,
505 "", "Seed for pseudo-random number generator"},
506 {"trace", "QEMU_TRACE", true, handle_arg_trace
,
507 "", "[[enable=]<pattern>][,events=<file>][,file=<file>]"},
509 {"plugin", "QEMU_PLUGIN", true, handle_arg_plugin
,
510 "", "[file=]<file>[,<argname>=<argvalue>]"},
512 {"version", "QEMU_VERSION", false, handle_arg_version
,
513 "", "display version information and exit"},
514 #if defined(TARGET_XTENSA)
515 {"xtensa-abi-call0", "QEMU_XTENSA_ABI_CALL0", false, handle_arg_abi_call0
,
516 "", "assume CALL0 Xtensa ABI"},
518 {"perfmap", "QEMU_PERFMAP", false, handle_arg_perfmap
,
519 "", "Generate a /tmp/perf-${pid}.map file for perf"},
520 {"jitdump", "QEMU_JITDUMP", false, handle_arg_jitdump
,
521 "", "Generate a jit-${pid}.dump file for perf"},
522 {NULL
, NULL
, false, NULL
, NULL
, NULL
}
525 static void usage(int exitcode
)
527 const struct qemu_argument
*arginfo
;
531 printf("usage: qemu-" TARGET_NAME
" [options] program [arguments...]\n"
532 "Linux CPU emulator (compiled for " TARGET_NAME
" emulation)\n"
534 "Options and associated environment variables:\n"
537 /* Calculate column widths. We must always have at least enough space
538 * for the column header.
540 maxarglen
= strlen("Argument");
541 maxenvlen
= strlen("Env-variable");
543 for (arginfo
= arg_table
; arginfo
->handle_opt
!= NULL
; arginfo
++) {
544 int arglen
= strlen(arginfo
->argv
);
545 if (arginfo
->has_arg
) {
546 arglen
+= strlen(arginfo
->example
) + 1;
548 if (strlen(arginfo
->env
) > maxenvlen
) {
549 maxenvlen
= strlen(arginfo
->env
);
551 if (arglen
> maxarglen
) {
556 printf("%-*s %-*s Description\n", maxarglen
+1, "Argument",
557 maxenvlen
, "Env-variable");
559 for (arginfo
= arg_table
; arginfo
->handle_opt
!= NULL
; arginfo
++) {
560 if (arginfo
->has_arg
) {
561 printf("-%s %-*s %-*s %s\n", arginfo
->argv
,
562 (int)(maxarglen
- strlen(arginfo
->argv
) - 1),
563 arginfo
->example
, maxenvlen
, arginfo
->env
, arginfo
->help
);
565 printf("-%-*s %-*s %s\n", maxarglen
, arginfo
->argv
,
566 maxenvlen
, arginfo
->env
,
573 "QEMU_LD_PREFIX = %s\n"
574 "QEMU_STACK_SIZE = %ld byte\n",
579 "You can use -E and -U options or the QEMU_SET_ENV and\n"
580 "QEMU_UNSET_ENV environment variables to set and unset\n"
581 "environment variables for the target process.\n"
582 "It is possible to provide several variables by separating them\n"
583 "by commas in getsubopt(3) style. Additionally it is possible to\n"
584 "provide the -E and -U options multiple times.\n"
585 "The following lines are equivalent:\n"
586 " -E var1=val2 -E var2=val2 -U LD_PRELOAD -U LD_DEBUG\n"
587 " -E var1=val2,var2=val2 -U LD_PRELOAD,LD_DEBUG\n"
588 " QEMU_SET_ENV=var1=val2,var2=val2 QEMU_UNSET_ENV=LD_PRELOAD,LD_DEBUG\n"
589 "Note that if you provide several changes to a single variable\n"
590 "the last change will stay in effect.\n"
592 QEMU_HELP_BOTTOM
"\n");
597 static int parse_args(int argc
, char **argv
)
601 const struct qemu_argument
*arginfo
;
603 for (arginfo
= arg_table
; arginfo
->handle_opt
!= NULL
; arginfo
++) {
604 if (arginfo
->env
== NULL
) {
608 r
= getenv(arginfo
->env
);
610 arginfo
->handle_opt(r
);
616 if (optind
>= argc
) {
625 if (!strcmp(r
, "-")) {
628 /* Treat --foo the same as -foo. */
633 for (arginfo
= arg_table
; arginfo
->handle_opt
!= NULL
; arginfo
++) {
634 if (!strcmp(r
, arginfo
->argv
)) {
635 if (arginfo
->has_arg
) {
636 if (optind
>= argc
) {
637 (void) fprintf(stderr
,
638 "qemu: missing argument for option '%s'\n", r
);
641 arginfo
->handle_opt(argv
[optind
]);
644 arginfo
->handle_opt(NULL
);
650 /* no option matched the current argv */
651 if (arginfo
->handle_opt
== NULL
) {
652 (void) fprintf(stderr
, "qemu: unknown option '%s'\n", r
);
657 if (optind
>= argc
) {
658 (void) fprintf(stderr
, "qemu: no user program specified\n");
662 exec_path
= argv
[optind
];
667 int main(int argc
, char **argv
, char **envp
)
669 struct target_pt_regs regs1
, *regs
= ®s1
;
670 struct image_info info1
, *info
= &info1
;
671 struct linux_binprm bprm
;
676 char **target_environ
, **wrk
;
682 unsigned long max_reserved_va
;
686 module_call_init(MODULE_INIT_TRACE
);
687 qemu_init_cpu_list();
688 module_call_init(MODULE_INIT_QOM
);
690 envlist
= envlist_create();
692 /* add current environment into the list */
693 for (wrk
= environ
; *wrk
!= NULL
; wrk
++) {
694 (void) envlist_setenv(envlist
, *wrk
);
697 /* Read the stack limit from the kernel. If it's "unlimited",
698 then we can do little else besides use the default. */
701 if (getrlimit(RLIMIT_STACK
, &lim
) == 0
702 && lim
.rlim_cur
!= RLIM_INFINITY
703 && lim
.rlim_cur
== (target_long
)lim
.rlim_cur
704 && lim
.rlim_cur
> guest_stack_size
) {
705 guest_stack_size
= lim
.rlim_cur
;
711 qemu_add_opts(&qemu_trace_opts
);
712 qemu_plugin_add_opts();
714 optind
= parse_args(argc
, argv
);
716 qemu_set_log_filename_flags(last_log_filename
,
717 last_log_mask
| (enable_strace
* LOG_STRACE
),
720 if (!trace_init_backends()) {
724 qemu_plugin_load_list(&plugins
, &error_fatal
);
727 memset(regs
, 0, sizeof(struct target_pt_regs
));
729 /* Zero out image_info */
730 memset(info
, 0, sizeof(struct image_info
));
732 memset(&bprm
, 0, sizeof (bprm
));
734 /* Scan interp_prefix dir for replacement files. */
735 init_paths(interp_prefix
);
737 init_qemu_uname_release();
740 * Manage binfmt-misc open-binary flag
742 execfd
= qemu_getauxval(AT_EXECFD
);
744 execfd
= open(exec_path
, O_RDONLY
);
746 printf("Error while loading %s: %s\n", exec_path
, strerror(errno
));
751 /* Resolve executable file name to full path name */
752 if (realpath(exec_path
, real_exec_path
)) {
753 exec_path
= real_exec_path
;
757 * get binfmt_misc flags
759 preserve_argv0
= !!(qemu_getauxval(AT_FLAGS
) & AT_FLAGS_PRESERVE_ARGV0
);
762 * Manage binfmt-misc preserve-arg[0] flag
763 * argv[optind] full path to the binary
764 * argv[optind + 1] original argv[0]
766 if (optind
+ 1 < argc
&& preserve_argv0
) {
770 if (cpu_model
== NULL
) {
771 cpu_model
= cpu_get_model(get_elf_eflags(execfd
));
773 cpu_type
= parse_cpu_option(cpu_model
);
775 /* init tcg before creating CPUs and to get qemu_host_page_size */
777 AccelClass
*ac
= ACCEL_GET_CLASS(current_accel());
779 accel_init_interfaces(ac
);
780 ac
->init_machine(NULL
);
782 cpu
= cpu_create(cpu_type
);
788 * Reserving too much vm space via mmap can run into problems
789 * with rlimits, oom due to page table creation, etc. We will
790 * still try it, if directed by the command-line option, but
793 max_reserved_va
= MAX_RESERVED_VA(cpu
);
794 if (reserved_va
!= 0) {
795 if (max_reserved_va
&& reserved_va
> max_reserved_va
) {
796 fprintf(stderr
, "Reserved virtual address too big\n");
799 } else if (HOST_LONG_BITS
== 64 && TARGET_VIRT_ADDR_SPACE_BITS
<= 32) {
801 * reserved_va must be aligned with the host page size
802 * as it is used with mmap()
804 reserved_va
= max_reserved_va
& qemu_host_page_mask
;
809 if (seed_optarg
!= NULL
) {
810 qemu_guest_random_seed_main(seed_optarg
, &err
);
815 error_reportf_err(err
, "cannot initialize crypto: ");
820 target_environ
= envlist_to_environ(envlist
, NULL
);
821 envlist_free(envlist
);
824 * Read in mmap_min_addr kernel parameter. This value is used
825 * When loading the ELF image to determine whether guest_base
826 * is needed. It is also used in mmap_find_vma.
831 if ((fp
= fopen("/proc/sys/vm/mmap_min_addr", "r")) != NULL
) {
833 if (fscanf(fp
, "%lu", &tmp
) == 1 && tmp
!= 0) {
835 qemu_log_mask(CPU_LOG_PAGE
, "host mmap_min_addr=0x%lx\n",
843 * We prefer to not make NULL pointers accessible to QEMU.
844 * If we're in a chroot with no /proc, fall back to 1 page.
846 if (mmap_min_addr
== 0) {
847 mmap_min_addr
= qemu_host_page_size
;
848 qemu_log_mask(CPU_LOG_PAGE
,
849 "host mmap_min_addr=0x%lx (fallback)\n",
854 * Prepare copy of argv vector for target.
856 target_argc
= argc
- optind
;
857 target_argv
= calloc(target_argc
+ 1, sizeof (char *));
858 if (target_argv
== NULL
) {
859 (void) fprintf(stderr
, "Unable to allocate memory for target_argv\n");
864 * If argv0 is specified (using '-0' switch) we replace
865 * argv[0] pointer with the given one.
869 target_argv
[i
++] = strdup(argv0
);
871 for (; i
< target_argc
; i
++) {
872 target_argv
[i
] = strdup(argv
[optind
+ i
]);
874 target_argv
[target_argc
] = NULL
;
876 ts
= g_new0(TaskState
, 1);
878 /* build Task State */
886 ret
= loader_exec(execfd
, exec_path
, target_argv
, target_environ
, regs
,
889 printf("Error while loading %s: %s\n", exec_path
, strerror(-ret
));
893 for (wrk
= target_environ
; *wrk
; wrk
++) {
897 g_free(target_environ
);
899 if (qemu_loglevel_mask(CPU_LOG_PAGE
)) {
900 FILE *f
= qemu_log_trylock();
902 fprintf(f
, "guest_base %p\n", (void *)guest_base
);
903 fprintf(f
, "page layout changed following binary load\n");
906 fprintf(f
, "start_brk 0x" TARGET_ABI_FMT_lx
"\n",
908 fprintf(f
, "end_code 0x" TARGET_ABI_FMT_lx
"\n",
910 fprintf(f
, "start_code 0x" TARGET_ABI_FMT_lx
"\n",
912 fprintf(f
, "start_data 0x" TARGET_ABI_FMT_lx
"\n",
914 fprintf(f
, "end_data 0x" TARGET_ABI_FMT_lx
"\n",
916 fprintf(f
, "start_stack 0x" TARGET_ABI_FMT_lx
"\n",
918 fprintf(f
, "brk 0x" TARGET_ABI_FMT_lx
"\n",
920 fprintf(f
, "entry 0x" TARGET_ABI_FMT_lx
"\n",
922 fprintf(f
, "argv_start 0x" TARGET_ABI_FMT_lx
"\n",
924 fprintf(f
, "env_start 0x" TARGET_ABI_FMT_lx
"\n",
926 fprintf(f
, "auxv_start 0x" TARGET_ABI_FMT_lx
"\n",
932 target_set_brk(info
->brk
);
936 /* Now that we've loaded the binary, GUEST_BASE is fixed. Delay
937 generating the prologue until now so that the prologue can take
938 the real value of GUEST_BASE into account. */
939 tcg_prologue_init(tcg_ctx
);
941 target_cpu_copy_regs(env
, regs
);
944 if (gdbserver_start(gdbstub
) < 0) {
945 fprintf(stderr
, "qemu: could not open gdbserver on %s\n",
949 gdb_handlesig(cpu
, 0);
952 #ifdef CONFIG_SEMIHOSTING
953 qemu_semihosting_guestfd_init();