Skip to contentSkip to conversation

arm return

Qemu-devel Davide Ferraretto 2 participants 8 messages Jun 1, 2012 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

In arm user mode, where does qemu exit? Where is last qemu's instruction?

I.E.
int main (){return 0;}
in what file does qemu run "return 0"??

#1 lore raw
Quoted 5 lines · Davide Ferraretto

In arm user mode, where does qemu exit? Where is last qemu's instruction?

I.E.
int main (){return 0;}
in what file does qemu run "return 0"??

Simulated code reaches the point where libc calls 'exit' or 'exit_group' syscall and then QEMU goes to the do_syscall in the linux-user/syscall.c to terminate the process.

Signature · 2 lines
Thanks.
-- Max
#2 lore raw

I tried to insert " printf("exit\n"); ", but qemu dosen't write to monitor.

Quoted 11 lines · Max Filippov
Quoted 5 lines · Davide Ferraretto

In arm user mode, where does qemu exit? Where is last qemu's instruction?

I.E.
int main (){return 0;}
in what file does qemu run "return 0"??

Simulated code reaches the point where libc calls 'exit' or 'exit_group' syscall and then QEMU goes to the do_syscall in the linux-user/syscall.c to terminate the process.

#3 lore raw
Quoted 1 line · Davide Ferraretto

I tried to insert " printf("exit\n"); ", but qemu dosen't write to monitor.

printf should not write to monitor (if you mean QEMU monitor), it should go to stdout.
I don't have ARM compiler set up ATM, but x86_64 with the following patch does what I describe:

$ git diff
linux-user/syscall.c +2 -0
index 20d2a74..ccb71dc 100644
@@ -5052,6 +5052,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 
     switch(num) {
     case TARGET_NR_exit:
+        fprintf(stderr, "TARGET_NR_exit\n");
 #ifdef CONFIG_USE_NPTL
       /* In old applications this may be used to implement _exit(2).
          However in threaded applictions it is used for thread termination,
@@ -6833,6 +6834,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 #ifdef __NR_exit_group
         /* new thread calls */
     case TARGET_NR_exit_group:
+        fprintf(stderr, "TARGET_NR_exit_group\n");
 #ifdef TARGET_GPROF
         _mcleanup();
 #endif
$ cat a.c
#include <stdio.h>
int main()
{
    printf("Hello, world\n");
    return 0;
}
$ gcc -static a.c -o a
$ qemu-all/root/bin/qemu-x86_64 ./a
Hello, world
TARGET_NR_exit_group
Quoted 18 lines · Max Filippov
Quoted 16 lines
Quoted 6 lines · Davide Ferraretto

In arm user mode, where does qemu exit? Where is last qemu's instruction?

I.E.
int main (){return 0;}
in what file does qemu run "return 0"??

Simulated code reaches the point where libc calls 'exit' or 'exit_group' syscall
and then QEMU goes to the do_syscall in the linux-user/syscall.c to terminate
the process.

Signature · 2 lines
Thanks.
-- Max
#4 lore raw

I'm in "arm user space" with "sigle step mode". I want write "exit\n" in linux shell (no QEMU monitor) when emulate code arrives to "return 0"

Quoted 57 lines · Max Filippov
Quoted 1 line · Davide Ferraretto

I tried to insert " printf("exit\n"); ", but qemu dosen't write to monitor.

printf should not write to monitor (if you mean QEMU monitor), it should go to stdout.
I don't have ARM compiler set up ATM, but x86_64 with the following patch does what I describe:

$ git diff
linux-user/syscall.c +2 -0
index 20d2a74..ccb71dc 100644
@@ -5052,6 +5052,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 
      switch(num) {
      case TARGET_NR_exit:
+        fprintf(stderr, "TARGET_NR_exit\n");
  #ifdef CONFIG_USE_NPTL
        /* In old applications this may be used to implement _exit(2).
           However in threaded applictions it is used for thread termination,
@@ -6833,6 +6834,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
  #ifdef __NR_exit_group
          /* new thread calls */
      case TARGET_NR_exit_group:
+        fprintf(stderr, "TARGET_NR_exit_group\n");
  #ifdef TARGET_GPROF
          _mcleanup();
  #endif
$ cat a.c
#include<stdio.h>
int main()
{
     printf("Hello, world\n");
     return 0;
}
$ gcc -static a.c -o a
$ qemu-all/root/bin/qemu-x86_64 ./a
Hello, world
TARGET_NR_exit_group
Quoted 14 lines · Max Filippov
Quoted 13 lines
Quoted 5 lines · Davide Ferraretto

In arm user mode, where does qemu exit? Where is last qemu's instruction?

I.E.
int main (){return 0;}
in what file does qemu run "return 0"??

Simulated code reaches the point where libc calls 'exit' or 'exit_group' syscall
and then QEMU goes to the do_syscall in the linux-user/syscall.c to terminate
the process.

#5 lore raw
Quoted 2 lines · Davide Ferraretto

I'm in "arm user space" with "sigle step mode". I want write "exit\n" in linux shell (no QEMU monitor) when emulate code arrives to "return 0"

Ok, what do you execute and where? Is it qemu-arm or qemu-system-arm? In the latter case do you use -semihosting?

What is "ARM user space"?
How is it all related to single step mode?
Which linux shell do you mean, guest or host?

Please, don't top-post.

Signature · 2 lines
Thanks.
-- Max

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 3 lines · Davide Ferraretto

I run qemu-arm -singlestep prog

Linux shell --> host.

Ok, and you build 'prog' as a static linux ELF for ARM? What does

qemu-arm -strace prog

print?

Signature · 2 lines
Thanks.
-- Max

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw
Quoted 2 lines · Davide Ferraretto

I compile so:
arm-elf-gcc-4.0.2 prog -o prog

As its name suggests, arm-elf-gcc builds bare-metal ELF that wouldn't run on linux, doesn't it?
And what about the other question, what does qemu-arm -strace prog print?

Signature · 2 lines
Thanks.
-- Max