sh4 linux user emulation on an x86_64 system
Hi all,
I have some trouble using the qemu emulator on the x86_64 host system. The system emulate an qemu-sh4 machine. I try to fix it without success:
if I run:
qemu-sh4-32 I don't have problems. I have the log and the program run ok.
If I recompile for the qemu-sh4-64 the system crash. I find the reason of the crash, but the problem appears early in the generated code. The effect is the env variabile env->pr is filled with an an invalid value
then the pr is taken by the delayed_pc and finally by the pc.
The %r14 register point to the CPUState structure
OUT: [size=242]
0x6018c9e0: mov 0x28(%r14),%edi 0x6018c9e4: mov 0x40(%r14),%esi 0x6018c9e8: add $0x60,%esi 0x6018c9eb: mov %rsi,%rdx 0x6018c9ee: mov %edx,0x44(%r14) 0x6018c9f2: mov %esi,0x40(%r14) 0x6018c9f6: mov %edi,0x8(%r14) 0x6018c9fa: movslq (%rdx),%rdi 0x6018c9fd: mov 0x44(%r14),%esi 0x6018ca01: add $0x4,%esi 0x6018ca04: mov %rsi,%rdx 0x6018ca07: mov %esi,0x44(%r14) 0x6018ca0b: mov %edi,0x114(%r14) <--- the %edi is invalid and here I set the env->pr
the pr is then copied to the delayed_pc and then in the pc. variabile
Then the system crash with an access violation. I set a break condition and a watch point to trace down the problem and try to compare the i386 code with the x86_64 code. It appears that the problem is before.
It is a problem if the regs_to_env and env_to_regs are not implemented during a longjmp and setjmp.
Regards Michael
Hello
Quoted 4 lines · michael
qemu-sh4-32 I don't have problems. I have the log and the program run ok.
If I recompile for the qemu-sh4-64 the system crash. I find the reason of the
I have nothing useful to add, except that I have been trying to track down a very similar problem with qemu-cris. It works fine on x86, but gets stuck in x86-64 due to the PC getting mis-set. The problem seems possibly related to the exception handling code which uses longjmp. Maybe the problems are related.
Vince
Quoted 11 lines · Vince Weaver
Hello
Quoted 4 lines · michael
qemu-sh4-32 I don't have problems. I have the log and the program run ok.
If I recompile for the qemu-sh4-64 the system crash. I find the reason of the
I have nothing useful to add, except that I have been trying to track down a very similar problem with qemu-cris. It works fine on x86, but gets stuck in x86-64 due to the PC getting mis-set. The problem seems possibly related to the exception handling code which uses longjmp. Maybe the problems are related.
Vince
In the user-mode I see that the expection handling just set the expeciont reason to -1. I will try to track down the problem. I don't find how the tcg avoid the use of low part of a register that is used used for special purpose. The x86_64 has the notion only of the 64bit register but a 64bit register can be used only in the low part. Another thing is the define:
#define CODE_GEN_ALIGN 16 /* must be >= of the size of a icache line */
In the x86_64 is not 64?
Regards Michael
Quoted 2 lines
PATCH 1/1 SH: Fix struct target_stat64 for 64bit host
In reply to michaelHi,
Quoted 3 lines
I have some trouble using the qemu emulator on the
x86_64host system. The system emulate
an qemu-sh4 machine. I try to fix it without success:
I found stat64 has damaged return address on stack because of bloated
struct stat64.
On sh4 target, struct target_stat64 has "unsigned int" as its member. It may results unwanted struct layout on 64bit host. Switched to abi_ulong. We also have to use packed attribute for sh4, because the struct has unaligned 64bit member st_size.
--- linux-user/syscall_defs.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
linux-user/syscall_defs.h +3 -3
@@ -1475,15 +1475,15 @@ struct target_stat {/* This matches struct stat64 in glibc2.1, hence the absolutely * insane amounts of padding around dev_t's. */ -struct target_stat64 { +struct __attribute__((__packed__ ))target_stat64 {unsigned long long st_dev;unsigned char __pad0[4 ];#define TARGET_STAT64_HAS_BROKEN_ST_INO 1abi_ulong __st_ino; -unsigned int st_mode; -unsigned int st_nlink; +abi_ulong st_mode; +abi_ulong st_nlink;abi_ulong st_uid;abi_ulong st_gid;
Signature · 1 line
1.5.4.3
[Qemu-devel] Re: [PATCH] SH: Fix struct target_stat64 for 64bit host
Hi,
Quoted 35 lines · [email protected] wrote:
Hi,
Quoted 3 lines
I have some trouble using the qemu emulator on the
x86_64host system. The system emulate an qemu-sh4 machine. I try to fix it without success:I found stat64 has damaged return address on stack because of bloated
struct stat64.On sh4 target, struct
target_stat64has "unsigned int" as its member. It may results unwanted struct layout on 64bit host. Switched toabi_ulong. We also have to use packed attribute for sh4, because the struct has unaligned 64bit memberst_size.Signed-off-by Takashi YOSHII <[email protected]>--- linux-user/syscall_defs.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)linux-user/syscall_defs.h +1
-1@@ -1475,15 +1475,15 @@ struct target_stat {/* This matches struct stat64 in glibc2.1, hence the absolutely * insane amounts of padding around dev_t's. */ -struct target_stat64 { +struct __attribute__((__packed__ ))target_stat64 {unsigned long long st_dev;unsigned char __pad0[4 ];
linux-user/syscall_defs.h struct target_stat { · line 1489
Quoted 10 lines
linux-user/syscall_defs.h +2
-2#define TARGET_STAT64_HAS_BROKEN_ST_INO 1abi_ulong __st_ino; -unsigned int st_mode; -unsigned int st_nlink; +abi_ulong st_mode; +abi_ulong st_nlink;abi_ulong st_uid;abi_ulong st_gid;
The patch fix the problem for me.
Regards Michael
Re: [Qemu-devel] [PATCH] SH: Fix struct target_stat64 for 64bit host
In reply to [email protected]Quoted 26 lines · [email protected] wrote:
Hi,
Quoted 3 lines
I have some trouble using the qemu emulator on the
x86_64host system. The system emulate an qemu-sh4 machine. I try to fix it without success:I found stat64 has damaged return address on stack because of bloated
struct stat64.On sh4 target, struct
target_stat64has "unsigned int" as its member. It may results unwanted struct layout on 64bit host. Switched toabi_ulong. We also have to use packed attribute for sh4, because the struct has unaligned 64bit memberst_size.Signed-off-by Takashi YOSHII <[email protected]>--- linux-user/syscall_defs.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)linux-user/syscall_defs.h +0
-0
linux-user/syscall_defs.h struct target_stat { · line 1480
Quoted 7 lines
linux-user/syscall_defs.h +1
-1@@ -1475,15 +1475,15 @@ struct target_stat {/* This matches struct stat64 in glibc2.1, hence the absolutely * insane amounts of padding around dev_t's. */ -struct target_stat64 { +struct __attribute__((__packed__ ))target_stat64 {unsigned long long st_dev;
Define it packets assecure me that each type occopies the exact dimension
linux-user/syscall_defs.h struct target_stat { · line 1487
Quoted 10 lines
linux-user/syscall_defs.h +2
-2unsigned char __pad0[4 ];#define TARGET_STAT64_HAS_BROKEN_ST_INO 1abi_ulong __st_ino; -unsigned int st_mode; -unsigned int st_nlink; +abi_ulong st_mode; +abi_ulong st_nlink;
The size of an unsigned int is 4 byte and is ok? Why this change?
Quoted 4 lines
linux-user/syscall_defs.h +0
-0abi_ulong st_uid;
abi_ulongst_gid;
Regards Michael
Re: [Qemu-devel] [PATCH] SH: Fix struct target_stat64 for 64bit host
In reply to [email protected]hi,
Quoted 35 lines · [email protected] wrote:
Hi,
Quoted 3 lines
I have some trouble using the qemu emulator on the
x86_64host system. The system emulate an qemu-sh4 machine. I try to fix it without success:I found stat64 has damaged return address on stack because of bloated
struct stat64.On sh4 target, struct
target_stat64has "unsigned int" as its member. It may results unwanted struct layout on 64bit host. Switched toabi_ulong. We also have to use packed attribute for sh4, because the struct has unaligned 64bit memberst_size.Signed-off-by Takashi YOSHII <[email protected]>--- linux-user/syscall_defs.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)linux-user/syscall_defs.h +1
-1@@ -1475,15 +1475,15 @@ struct target_stat {/* This matches struct stat64 in glibc2.1, hence the absolutely * insane amounts of padding around dev_t's. */ -struct target_stat64 { +struct __attribute__((__packed__ ))target_stat64 {unsigned long long st_dev;unsigned char __pad0[4 ];
linux-user/syscall_defs.h struct target_stat { · line 1489
Quoted 10 lines
linux-user/syscall_defs.h +2
-2#define TARGET_STAT64_HAS_BROKEN_ST_INO 1abi_ulong __st_ino; -unsigned int st_mode; -unsigned int st_nlink; +abi_ulong st_mode; +abi_ulong st_nlink;abi_ulong st_uid;abi_ulong st_gid;
What would you think about this one?
syscall_defs.h +1 -1
@@ -1506,7 +1506,7 @@abi_ulong target_st_ctime_nsec;unsigned long long st_ino; -}; +} __attribute__((packed));#elif defined(TARGET_I386 ) && !defined(TARGET_ABI32 ) struct target_stat {
[Qemu-devel] Re: [PATCH] SH: Fix struct target_stat64 for 64bit host
Hi,
Quoted 1 line
The size of an unsigned int is 4 byte and is ok? Why this change?
Oh, you are right. I seems to be confused during debugging. So, one line modification adding "packed" attribute like your patch is the answer. I confirmed the issue fixed with your patch.
Thank you, Michael.
/yoshii @ lunch break at office :)
PATCH 1/1 take2. SH: Fix struct target_stat64 for 64bit host
In reply to [email protected]I send fixed one, because I found (perhaps) I should send fixed patch with
signed-off line to be committed to the repository....
This one simply add packed attribute to the struct, as michael pointed out.
--- linux-user/syscall_defs.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
linux-user/syscall_defs.h +1 -1
@@ -1475,7 +1475,7 @@ struct target_stat {/* This matches struct stat64 in glibc2.1, hence the absolutely * insane amounts of padding around dev_t's. */ -struct target_stat64 { +struct __attribute__((__packed__ ))target_stat64 {unsigned long long st_dev;unsigned char __pad0[4 ];
Signature · 1 line
1.5.4.3
Aurelien Jarno
AppliedRe: [Qemu-devel] [PATCH] take2. SH: Fix struct target_stat64 for 64bit host
Quoted 6 lines · On Mon, Oct 27, 2008 at 12:37:39AM +0900, [email protected] wrote:
I send fixed one, because I found (perhaps) I should send fixed patch with
signed-off line to be committed to the repository....This one simply add packed attribute to the struct, as michael pointed out.
Signed-off-by Takashi YOSHII <[email protected]>
Thanks, applied.
Quoted 23 lines
--- linux-user/syscall_defs.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)linux-user/syscall_defs.h +1
-1@@ -1475,7 +1475,7 @@ struct target_stat {/* This matches struct stat64 in glibc2.1, hence the absolutely * insane amounts of padding around dev_t's. */ -struct target_stat64 { +struct __attribute__((__packed__ ))target_stat64 {unsigned long long st_dev;unsigned char __pad0[4 ];Signature · 1 line
1.5.4.3
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net