Porting TCG to alpha platform
Hi, Richard.
I almost re-write the whole code under your help and now it seems somehow elegant. Unfortunately, it still can't run MS windows, I wonder whether there are some other special places in QEMU to be modifed for alpha case, beside the 3 files (cpu-all.h/tcg-target.c/tcg-target.h) I write or modified.
Is there any good method to find the bug except "guess and try"? And it seems that few people is interested in porting QEMU/TCG to alpha platform, why? just because alpha machine is disappearing? And may the patch in current stage be accepted by QEMU, i just want to attract more eye-balls and to get things done.
Anyhow, I'll continue to work on it and any help from you will be appreciated. I append the newest patch in attachment, please take a look if it doesn't waste too much your time.
Thanks.
Dong Weiyu
___________________________________________________________
好玩贺卡等你发,邮箱贺卡全新上线!
http://card.mail.cn.yahoo.com/
From d51491a60ccf9ab91eb963ba07be2e590afda71d Mon Sep 17 00:00:00 2001
From: Dong Weiyu <[email protected]>
Date: Fri, 22 Jan 2010 23:10:43 +0800
Subject: [PATCH] Porting TCG to alpha platform
--- cpu-all.h | 2 +- tcg/alpha/tcg-target.c | 1081 ++++++++++++++++++++++++++++++++++++++++++++++++ tcg/alpha/tcg-target.h | 68 +++ 3 files changed, 1150 insertions(+), 1 deletions(-) create mode 100644 tcg/alpha/tcg-target.c create mode 100644 tcg/alpha/tcg-target.h
cpu-all.h +1 -1
@@ -22,7 +22,7 @@#include "qemu-common.h" -#if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) +#if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) || defined(__alpha__)#define WORDS_ALIGNED #endif
tcg/alpha/tcg-target.c new file +1081 -0
1,081 lines not on this page · raw message
tcg/alpha/tcg-target.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
1.6.3.3
Quoted 1 line · identifier scorpio
Is there any good method to find the bug except "guess and try"?
-singlestep -d in_asm,cpu,exec
Use these options on both Alpha host and x86_64 host and diff the resulting output files. That will show you which target instruction is emulated differently.
Quoted 2 lines
And it seems that few people is interested in porting QEMU/TCG to alpha platform, why? just because alpha machine is disappearing?
Probably. I no longer have functioning alpha hardware, which is why I've become interested in qemu with alpha as a target.
Quoted 1 line
+
tcg_out32(s, (opc)|INSN_RA(ra)|INSN_DISP21(disp));
Coding style: spaces around operators, no useless parens around opc.
tcg/alpha/tcg-target.c line 139
Quoted 2 lines
tcg/alpha/tcg-target.c new file +2
-0+static inline int tcg_target_const_match ( \ +tcg_target_long val,const TCGArgConstraint *arg_ct)
Coding style: no trailing \; there's no need for line continuation anywhere except in preprocessor directives. Merge the first argument into the first line, assuming that can happen without exceeding 80 columns. Arguments that do get split to subsequent lines should be properly indented below the first argument on the previous line.
tcg/alpha/tcg-target.c line 193
Quoted 2 lines
tcg/alpha/tcg-target.c new file +2
-0+if ( type ==TCG_TYPE_I32 ) + val = (int32_t )val;
Coding style: use braces, even for a single statement. Yes, there's plenty of code in the project that doesn't, but the coding style is being enforced on all new code.
Also, extra space after open paren.
tcg/alpha/tcg-target.c line 246
Quoted 7 lines
tcg/alpha/tcg-target.c new file +7
-0+if (disp != (int16_t )disp) { +tcg_out_movi (s,TCG_TYPE_I64 ,TMP_REG1 , disp); +tcg_out_fmt_opr (s,INSN_ADDQ , rb,TMP_REG1 ,TMP_REG1 ); +tcg_out_fmt_mem (s, opc, ra,TMP_REG1 ,0 ); + }else { +tcg_out_fmt_mem (s, opc, ra, rb, disp); + }
The reason I suggested writing the tcg_out_opc_long as I did was so that for a 32-bit displacement like 0x12345678 instead of
ldah $28,0x1234($31)
lda $28,0x5678($28)
addq $16,$28,$28
ldq $17,0($28)we can generate
ldah $28,0x1234($16)
ldq $17,0x5678($28)For larger 64-bit constants obviously we have no choice but to use an ADDQ, but even then one can stuff the final 16-bit addition into the memory insn itself.
Given the size of the CPUState, offsets > 32k are very common, so it would be good to handle this case well.
tcg/alpha/tcg-target.c line 417
Quoted 8 lines
tcg/alpha/tcg-target.c new file +8
-0+static void tcg_out_mov_addr (TCGContext *s,int ret,int addr) +{ +tcg_out_mov (s, ret, addr); +#if TARGET_LONG_BITS ==32 +/* if VM is of 32-bit arch, clear higher 32-bit of addr */ +tcg_out_fmt_opi (s,INSN_ZAPNOT , ret,0x0f , ret); +#endif +}
It's a bit wasteful to emit the move *and* the zap; give "addr" to the first operand of the zapnot directly.
tcg/alpha/tcg-target.c line 453
Quoted 8 lines
tcg/alpha/tcg-target.c new file +8
-0+ tgen_arithi(s, INSN_ADDQ, r1, offsetof(CPUState, tlb_table[mem_index][0].addr_read)); +tcg_out_fmt_opr (s,INSN_ADDQ , r1,TCG_REG_15 , r1); +#if TARGET_LONG_BITS ==32 +tcg_out_fmt_mem (s,INSN_LDL ,TMP_REG1 , r1,0 ); +tcg_out_fmt_opi (s,INSN_ZAPNOT ,TMP_REG1 ,0x0f ,TMP_REG1 ); +#else +tcg_out_fmt_mem (s,INSN_LDQ ,TMP_REG1 , r1,0 ); +#endif
Better as
tcg_out_fmt_opr(s, INSN_ADDQ, r1, TCG_REG_15, r1);
tcg_out_ldst(s, TARGET_LONG_BITS == 32 ? INSN_LDL : INSN_LDQ,
TMP_REG1, r1, offsetof(CPUState, ...), 0);to fold part of the offset into the memory displacement, and reuse your existing code emitting the zapnot.
You might also consider copying the ppc64 port and split out a tcg_out_tlb_read function from both qemu_ld and qemu_st.
Review
Quoted 2 lines
(quoted diff) +2
-0+ *(uint32_t *)label1_ptr = (uint32_t) \ + ( INSN_BNE | ( TMP_REG1 << 21 ) | ( val & 0x1fffff));
If you're not going to use the gen_new_label method, at least use your INSN_RA and INSN_DISP21 macros.
tcg/alpha/tcg-target.c line 533
Quoted 4 lines
tcg/alpha/tcg-target.c new file +4
-0+tcg_out_movi (s,TCG_TYPE_I64 ,TMP_REG1 , \ + offsetof(CPUTLBEntry , addend) - offsetof(CPUTLBEntry , addr_read)); +tcg_out_fmt_opr (s,INSN_ADDQ , r1,TMP_REG1 , r1); +tcg_out_fmt_mem (s,INSN_LDQ ,TMP_REG1 , r1,0 );
As above, better to use tcg_out_ldst.
Quoted 1 line
+ {
INDEX_op_add_i32, { "r", "0", "r" } },
All of these matching constraints are wrong -- alpha is a 3 address machine; should be { "r", "r", "r" }, at least until you support constant arguments properly.
I still haven't seen anything that looks actively wrong to explain why windows isn't working for you...
r~
I've rearranged the code a tad, along the lines I had in mind.
I *think* I may have found cause of some of your problems running Windows. Mainly, tcg_target_long was used places that could be holding HOST values, which means that the host values would have been truncated to 32 bits.
Anyway, give this a try and let me know what happens. All I could actually try was a cross-compile of the code...
r~
cpu-common.h +2 -1
@@ -3,7 +3,8 @@/* CPU interfaces that are target indpendent. */ -#if defined(__arm__) || defined(__sparc__) || defined(__mips__) || defined(__hppa__) +#if defined(__arm__) || defined(__sparc__) || defined(__mips__) \ + || defined(__hppa__) || defined(__alpha__)#define WORDS_ALIGNED #endif
exec-all.h +5 -1
@@ -114,7 +114,8 @@ static inline int tlb_set_page(CPUState *env1, target_ulong vaddr,#define CODE_GEN_AVG_BLOCK_SIZE 64#endif -#if defined(_ARCH_PPC) || defined(__x86_64__) || defined(__arm__) || defined(__i386__) +#if defined(_ARCH_PPC) || defined(__x86_64__) || defined(__arm__) \ + || defined(__i386__) || defined(__alpha__)#define USE_DIRECT_JUMP #endif
@@ -189,6 +190,9 @@ extern int code_gen_max_blocks;#if defined(_ARCH_PPC)extern void ppc_tb_set_jmp_target (unsigned long jmp_addr,unsigned long addr);#define tb_set_jmp_target1 ppc_tb_set_jmp_target +#elif defined(__alpha__) +extern void alpha_tb_set_jmp_target(unsigned long, unsigned long) +#define tb_set_jmp_target1 alpha_tb_set_jmp_target#elif defined(__i386__) || defined(__x86_64__)static inline void tb_set_jmp_target1 (unsigned long jmp_addr,unsigned long addr) {
tcg/alpha/tcg-target.c new file +1398 -0
1,398 lines not on this page · raw message
tcg/alpha/tcg-target.h new file +89 -0
89 lines not on this page · raw message
I'v reviewed your code and applied the patch to 0.12.0.rc1. After fixing some small bugs I run it on my debian/alpha platform, and it hung after running abort 3 TBs. I'll continue to trace your code.
The bugs that are fixed are listed as follow:
1. adding constraints for operation mov_i32/movi_i32/mov_i64/movi_i64
2. replacing "goto do_arith" with "break" for INDEX_op_not_i32/i64 case handling in tcg_out_op
3. removing the redundant declaration for "alpha_tb_set_jmp_target()" at tail of tcg-target.c, it has been declared in exec-all.h
I just find that a suspect bug in tcg_out_brcond() and have not tried yet.
if ( opc == 0) {
opc = cmp_opc[cond];
if ( const_arg2) { /* should be if (const_arg2 && arg2 & ~0xff == 0) ? tcg_out_fmt_opi(s, opc, ...)
...
Your code is more skilled and I learn a lot from it, but I haven't yet recognized the key difference between your version and mine. In last mail, you've said that "Mainly, tcg_target_long was used places that could be holding HOST values, which means that the host values would have been truncated to 32 bits.", and I can't fully understand it, may you put it more clearly.
BTW, there is no internet access in my daily working environment, so forgive me for not being able to check my mail regularly.
Dong Weiyu.
___________________________________________________________
好玩贺卡等你发,邮箱贺卡全新上线!
http://card.mail.cn.yahoo.com/
Quoted 3 lines · identifier scorpio
1. adding constraints for operation mov_i32/movi_i32/mov_i64/movi_i64
2. replacing "gotodo_arith" with "break" for INDEX_op_not_i32/i64 case handling intcg_out_op
Oops.
Quoted 2 lines
3. removing the redundant declaration for "
alpha_tb_set_jmp_target()" at tail oftcg-target.c, it has been declared inexec-all.h
Ah, yes, a line I had to add temporarily for the x86 compiler; I meant to take it out again.
Quoted 6 lines
I just find that a suspect bug in
tcg_out_brcond()and have not tried yet.if ( opc == 0) {
opc = cmp_opc[cond];
if (const_arg2) { /* should be if (const_arg2&& arg2 & ~0xff == 0) ?tcg_out_fmt_opi(s, opc, ...)
{ INDEX_op_brcond_i32, { "rJ", "rI" } },
{ INDEX_op_brcond_i64, { "rJ", "rI" } },The "I" constraint is supposed to have already limited the constant to 0 .. 0xff. You could put an assert there if you like, to make sure everything is going as it should.
Quoted 6 lines
Your code is more skilled and I learn a lot from it, but I haven't yet recognized the key difference between your version and mine. In last mail, you've said that "Mainly,
tcg_target_longwas used places that could be holding HOST values, which means that the host values would have been truncated to 32 bits.", and I can't fully understand it, may you put it more clearly.
It was a mis-statement made while tired. Of course tcg_target_long is defined to int64_t when TCG_TARGET_REG_BITS == 64, so there was no truncation to 32 bits.
Have you tested of any of the other embedded targets? You may be able to find the error with one of those easier than finding it emulating full-scale Windows. See the images at the bottom of the QEMU download page.
r~
Review
Quoted 2 lines · Richard Henderson
(quoted diff) +2
-0+ } else if (~val == (uint8_t)~val) { + tcg_out_fmt_opi(s, INSN_BIC, ra, ~val, rc);
Bug here. I've applied the following to my local tree.
r~
commit 2ecce92da6eee4b3496c7655da45259308abb536
Author: Richard Henderson <[email protected]> Date: Fri Jan 29 09:36:28 2010 -0800
tcg-alpha: Fix cast error with immediate op to BIC.
The cast was in the wrong place. A change to ~(uint8_t)val would technically produce the correct result, but via a string of implicit conversions that are more difficult to follow than simply using the 0xff mask with the original type.
Adjust the AND test to match, lexically, for cleanliness.
tcg/alpha/tcg-target.c +2 -2
@@ -344,9 +344,9 @@ static inline void tcg_out_addi(TCGContext *s, int reg, long val)static void tcg_out_andi (TCGContext *s,int ra,long val,int rc) { -if (val == (uint8_t )val) { +if (val == (val &0xff )) {tcg_out_fmt_opi (s,INSN_AND , ra, val, rc); - }else if (~val == (uint8_t )~val) { + }else if (~val == ~(val &0xff )) {tcg_out_fmt_opi (s,INSN_BIC , ra, ~val, rc); }else {long mask0, maskff;
Review
Quoted 3 lines
(quoted diff) +3
-0+ } else if (cond == TCG_COND_EQ || cond == TCG_COND_NE) { + tcg_out_mem_long(s, INSN_LDA, TMP_REG1, arg1, -arg2); + opc = (cond == TCG_COND_EQ ? INSN_BEQ : INSN_BNE);
Bug here. What was intended was to add "arg1 = TMP_REG1". But since the constraints use "I" for uint8_t input constants, we might as well remove this hunk entirely.
Also, let's future-proof this routine against changes to the layout of the TCGCond enumeration.
r~
commit 9d787576342c193f13e2531953fc81442458de7e
Author: Richard Henderson <[email protected]> Date: Fri Jan 29 11:14:20 2010 -0800
tcg-alpha: Fix EQ/NE with a constant.
There was start of code to handle EQ and NE with arbitrary constants, but it wasn't completed. Remove the half-done code and add a comment for future enhancements.
Also, don't rely on the current layout of TCGCond; instead encode the need for inversion of the compare insn result by means of a low bit set in the cmp_opc table. Reduce the element size of cmp_opc.
tcg/alpha/tcg-target.c +36 -16
@@ -540,9 +540,11 @@ static void tcg_out_br(TCGContext *s, int opc, int ra, int label_index)tcg_out_fmt_br (s, opc, ra, value); } -static void tcg_out_brcond (TCGContext *s,int cond,TCGArg arg1, +static void tcg_out_brcond (TCGContext *s,TCGCond cond,TCGArg arg1,TCGArg arg2,int const_arg2,int label_index) { +/* Note that unsigned comparisons are not present here, which means +that their entries will contain zeros. */ static const int br_opc[10 ] = { [TCG_COND_EQ ] =INSN_BEQ , [TCG_COND_NE ] =INSN_BNE ,
@@ -552,38 +554,56 @@ static void tcg_out_brcond(TCGContext *s, int cond, TCGArg arg1, [TCG_COND_GT ] =INSN_BGT }; -static const uint64_t cmp_opc[10 ] = { +/* The low bit of these entries indicates that the result of +the comparison must be inverted. This bit should not be +output with the rest of the instruction. */ +static const int cmp_opc[10 ] = { [TCG_COND_EQ ] =INSN_CMPEQ , - [TCG_COND_NE ] =INSN_CMPEQ , + [TCG_COND_NE ] =INSN_CMPEQ |1 , [TCG_COND_LT ] =INSN_CMPLT , - [TCG_COND_GE ] =INSN_CMPLT , + [TCG_COND_GE ] =INSN_CMPLT |1 , [TCG_COND_LE ] =INSN_CMPLE , - [TCG_COND_GT ] =INSN_CMPLE , + [TCG_COND_GT ] =INSN_CMPLE |1 , [TCG_COND_LTU ] =INSN_CMPULT , - [TCG_COND_GEU ] =INSN_CMPULT , + [TCG_COND_GEU ] =INSN_CMPULT |1 , [TCG_COND_LEU ] =INSN_CMPULE , - [TCG_COND_GTU ] =INSN_CMPULE + [TCG_COND_GTU ] =INSN_CMPULE |1 };int opc =0 ; -if (const_arg2) { -if (arg2 ==0 ) { - opc = br_opc[cond]; - }else if (cond ==TCG_COND_EQ || cond ==TCG_COND_NE ) { -tcg_out_mem_long (s,INSN_LDA ,TMP_REG1 , arg1, -arg2); - opc = (cond ==TCG_COND_EQ ?INSN_BEQ :INSN_BNE ); - } +/* Possible improvements: +(1) Notice arg1 == $31 and !const_arg2. In this case, swap the +two operands and swap the sense of the comparison to allow the +use of the direct branches. + +(2) Allow arbitrary constants. We can, on occasion, generate one +less instruction if we compute +TMP = ARG1 - CONST +instead of +TMP = ARG1 cmp TMP2 +where TMP2 is the constant loaded into a register by generic code. +Note that for 64-bit operands this works only for EQ and NE. For +32-bit operands, we would need to either limit this to signed +comparisons or properly zero-extend unsigned inputs. The payoff +here isn't great though; much less than(1). */ + +/* Notice signed comparisons vs zero. These are handled by the +branch instructions directly. */ +if (const_arg2 && arg2 ==0 ) { + opc = br_opc[cond]; } +/* Otherwise, generate a comparison into a temporary. */ if (opc ==0 ) { - opc = cmp_opc[cond]; + opc = cmp_opc[cond] & ~1 ;if (const_arg2) {tcg_out_fmt_opi (s, opc, arg1, arg2,TMP_REG1 ); }else {tcg_out_fmt_opr (s, opc, arg1, arg2,TMP_REG1 ); } - opc = (cond &1 ) ?INSN_BEQ :INSN_BNE ; + + opc = (cmp_opc[cond] &1 ?INSN_BEQ :INSN_BNE ); arg1 =TMP_REG1 ; }
Quoted 8 lines · Richard Henderson
Quoted 6 lines · identifier scorpio
Your code is more skilled and I learn a lot from it, but I haven't yet recognized the key difference between your version and mine. In last mail, you've said that "Mainly,
tcg_target_longwas used places that could be holding HOST values, which means that the host values would have been truncated to 32 bits.", and I can't fully understand it, may you put it more clearly.
Quoted 7 lines
It was a mis-statement made while tired. Of course
tcg_target_longis defined toint64_twhenTCG_TARGET_REG_BITS== 64, so there was no truncation to 32 bits.Have you tested of any of the other embedded targets? You may be able to find the error with one of those easier than finding it emulating full-scale Windows. See the images at the bottom of the QEMU download page.
Hi,
Although I've never hacked on a TCG backend I'd still like to give some advice.
Quoted 1 line
From experience when developing both the CRIS and the MicroBlaze ISA
translators I very much suggest getting something very stable to work in linux-user before going further.
I used GCC's C torture tests and OpenSSL's bignum tests to verify the ports. In particular, OpenSSL's bignum tests seem to excersice lot's of cornercases.
If you pass those, you've come a long way. In general it's much easier to debug a guest testcase (bntest, etc) that fails compared to huge propretiary blob that fails (windows).
Just a suggestion, hope it helps.
Cheers,
Edgar
Quoted 30 lines · Edgar E. Iglesias
Quoted 7 lines · Richard Henderson
Quoted 6 lines · identifier scorpio
Your code is more skilled and I learn a lot from it, but I haven't yet recognized the key difference between your version and mine. In last mail, you've said that "Mainly,
tcg_target_longwas used places that could be holding HOST values, which means that the host values would have been truncated to 32 bits.", and I can't fully understand it, may you put it more clearly.Quoted 8 lines
It was a mis-statement made while tired. Of course
tcg_target_longis defined toint64_twhenTCG_TARGET_REG_BITS== 64, so there was no truncation to 32 bits.Have you tested of any of the other embedded targets? You may be able to find the error with one of those easier than finding it emulating full-scale Windows. See the images at the bottom of the QEMU download page.
Hi,
Although I've never hacked on a TCG backend I'd still like to give some advice.
Quoted 1 line
From experience when developing both the CRIS and the MicroBlaze ISA
translators I very much suggest getting something very stable to work in linux-user before going further.
I used GCC's C torture tests and OpenSSL's bignum tests to verify the ports. In particular, OpenSSL's bignum tests seem to excersice lot's of cornercases.
Quoted 8 lines
If you pass those, you've come a long way. In general it's much easier to debug a guest testcase (bntest, etc) that fails compared to huge propretiary blob that fails (windows).
Just a suggestion, hope it helps.
Cheers,
Edgar
Hi Edgar,
that was a good suggestion. bntest raises a segmentation fault (NULL pointer, p == 0, see below) with qemu-x86_64 on a x86_64 host.
Regards,
Stefan
obase=16
ibase=16
test BN_add
print "test BN_add\n"
Program received signal SIGSEGV, Segmentation fault. tb_alloc_page (tb=0x7ffff3423290, phys_pc=<value optimized out>, phys_page2=18446744073709551615) at /home/stefan/src/qemu/repo.or.cz/qemu/ar7/exec.c:1124
1124 tb->page_next[n] = p->first_tb;
(gdb) i s
#0 tb_alloc_page (tb=0x7ffff3423290, phys_pc=<value optimized out>, phys_page2=18446744073709551615) at /home/stefan/src/qemu/repo.or.cz/qemu/ar7/exec.c:1124
#1 tb_link_phys (tb=0x7ffff3423290, phys_pc=<value optimized out>, phys_page2=18446744073709551615) at /home/stefan/src/qemu/repo.or.cz/qemu/ar7/exec.c:1214
#2 0x000000006001fd5c in tb_gen_code (env=0x7ffff7f97010, pc=18446744073699066880, cs_base=<value optimized out>, flags=<value optimized out>, cflags=<value optimized out>) at /home/stefan/src/qemu/repo.or.cz/qemu/ar7/exec.c:912
#3 0x000000006002241b in tb_find_slow (env1=<value optimized out>) at /home/stefan/src/qemu/repo.or.cz/qemu/ar7/cpu-exec.c:161
#4 tb_find_fast (env1=<value optimized out>) at /home/stefan/src/qemu/repo.or.cz/qemu/ar7/cpu-exec.c:182
#5 cpu_x86_exec (env1=<value optimized out>) at /home/stefan/src/qemu/repo.or.cz/qemu/ar7/cpu-exec.c:574
#6 0x00000000600064c0 in cpu_loop (env=0x7ffff7f97010) at /home/stefan/src/qemu/repo.or.cz/qemu/ar7/linux-user/main.c:309 #7 0x00000000600076d2 in main (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>) at /home/stefan/src/qemu/repo.or.cz/qemu/ar7/linux-user/main.c:3101
Quoted 46 lines · Stefan Weil
Quoted 30 lines · Edgar E. Iglesias
Quoted 7 lines · Richard Henderson
Quoted 6 lines · identifier scorpio
Your code is more skilled and I learn a lot from it, but I haven't yet recognized the key difference between your version and mine. In last mail, you've said that "Mainly,
tcg_target_longwas used places that could be holding HOST values, which means that the host values would have been truncated to 32 bits.", and I can't fully understand it, may you put it more clearly.Quoted 8 lines
It was a mis-statement made while tired. Of course
tcg_target_longis defined toint64_twhenTCG_TARGET_REG_BITS== 64, so there was no truncation to 32 bits.Have you tested of any of the other embedded targets? You may be able to find the error with one of those easier than finding it emulating full-scale Windows. See the images at the bottom of the QEMU download page.
Hi,
Although I've never hacked on a TCG backend I'd still like to give some advice.
Quoted 1 line
From experience when developing both the CRIS and the MicroBlaze ISA
translators I very much suggest getting something very stable to work in linux-user before going further.
I used GCC's C torture tests and OpenSSL's bignum tests to verify the ports. In particular, OpenSSL's bignum tests seem to excersice lot's of cornercases.
Quoted 8 lines
If you pass those, you've come a long way. In general it's much easier to debug a guest testcase (bntest, etc) that fails compared to huge propretiary blob that fails (windows).
Just a suggestion, hope it helps.
Cheers,
EdgarHi Edgar,
that was a good suggestion. bntest raises a segmentation fault (NULL pointer, p == 0, see below) with qemu-x86_64 on a
x86_64host.
Quoted 7 lines
Regards,
Stefanobase=16
ibase=16
testBN_add
print "test BN_add\n"
Hi Stefan,
I didn't expect x86_64 to bug out so fast. But, like I said. The bignum tests are not a game. That testsuite is a serious thing to pass. Both CRIS and MicroBlaze pass them both in linux-user and in system emul. If not let me know.
Cheers,
Edgar
On Sat, Jan 30, 2010 at 12:04 AM, Stefan Weil <[email protected]> wrote:
[...]
Quoted 3 lines
that was a good suggestion. bntest raises a segmentation fault (NULL pointer, p == 0, see below) with qemu-x86_64 on a
x86_64host.
Compile bntest statically and it should work.
x86_64 user mode is completely broken for dynamically linked programs.
Laurent
BUG?
In tcg_out_qemu_ld
tcg_out_ld(s, TCG_TYPE_I64, r1, r1, offsetof(CPUTLBEntry, addend)
- offsetof(CPUTLBEntry, addr_read));
should be modified to
tcg_out_ld(s, TCG_TYPE_I64, r1, r1,
offsetof(CPUTLBEntry, addend));
since the when calling tcg_out_ld, the R1's value is (cpu_env + TLB_entry_offset), which was computed in tcg_out_tlb_cmp()
And the save problem in tcg_out_qemu_ld()
another BUG?
At the end of tcg_out_tlb_cmp(), R0's value is (page# | low bit of VA), if the branch is taken, i.e., TLB miss, R0 will be passed as an argument to helper functions, is it currently holding the correct value? I think at this time R0 should equal to addr_reg.
I'm currently testing your code in my free time.
Dong Weiyu.
___________________________________________________________
好玩贺卡等你发,邮箱贺卡全新上线!
http://card.mail.cn.yahoo.com/
[Qemu-devel] [BUG] qemu-x86_64 crash when running bntest (was: [PATCH] Porting TCG to alpha platform)
In reply to Laurent DesnoguesQuoted 6 lines · Laurent Desnogues
On Sat, Jan 30, 2010 at 12:04 AM, Stefan Weil <[email protected]> wrote:
[...]Quoted 2 lines
that was a good suggestion. bntest raises a segmentation fault (NULL pointer, p == 0, see below) with qemu-x86_64 on a
x86_64host.
Quoted 8 lines
Compile bntest statically and it should work.
x86_64user mode is completely broken for dynamically linked programs.Laurent
A statically linked bntest results in a crash, too.
Stefan
$ ldd bntest
not a dynamic executable
$ x86/x86_64-linux-user/qemu-x86_64 ./bntest
ERROR: ioctl(SNDCTL_DSP_MAPINBUF): target=0x80085013 host=0x80105013
ERROR: ioctl(SNDCTL_DSP_MAPOUTBUF): target=0x80085014 host=0x80105014
obase=16
ibase=16
test BN_add
print "test BN_add\n"
qemu: uncaught target signal 11 (Segmentation fault) - core dumpedRe: [Qemu-devel] [BUG] qemu-x86_64 crash when running bntest (was: [PATCH] Porting TCG to alpha platform)
Quoted 21 lines · Stefan Weil
Quoted 6 lines · Laurent Desnogues
On Sat, Jan 30, 2010 at 12:04 AM, Stefan Weil <[email protected]> wrote:
[...]Quoted 2 lines
that was a good suggestion. bntest raises a segmentation fault (NULL pointer, p == 0, see below) with qemu-x86_64 on a
x86_64host.Quoted 8 lines
Compile bntest statically and it should work.
x86_64user mode is completely broken for dynamically linked programs.Laurent
A statically linked bntest results in a crash, too.
Stefan
Quoted 10 lines
$ ldd bntest not a dynamic executable $ x86/x86_64-linux-user/qemu-x86_64 ./bntest ERROR: ioctl(SNDCTL_DSP_MAPINBUF): target=0x80085013 host=0x80105013 ERROR: ioctl(SNDCTL_DSP_MAPOUTBUF): target=0x80085014 host=0x80105014 obase=16 ibase=16 test BN_add print "test BN_add\n" qemu: uncaught target signal 11 (Segmentation fault) - core dumped
That worked for me. Could show us the last translated TB?
Laurent
Re: [Qemu-devel] [BUG] qemu-x86_64 crash when running bntest (was: [PATCH] Porting TCG to alpha platform)
In reply to Stefan WeilQuoted 9 lines · Stefan Weil
Quoted 8 lines · Laurent Desnogues
On Sat, Jan 30, 2010 at 12:04 AM, Stefan Weil <[email protected]> wrote:
[...]Quoted 2 lines
that was a good suggestion. bntest raises a segmentation fault (NULL pointer, p == 0, see below) with qemu-x86_64 on a
x86_64host.Compile bntest statically and it should work.
Quoted 8 lines
Quoted 6 lines
x86_64user mode is completely broken for dynamically linked programs.Laurent
A statically linked bntest results in a crash, too.
OK, I found the issue. It's vsyscall. You should use the patch I sent to this list a few months ago.
Laurent
Quoted 6 lines
tcg_out_ld(s, TCG_TYPE_I64, r1, r1, offsetof(CPUTLBEntry, addend) - offsetof(CPUTLBEntry, addr_read));should be modified to
tcg_out_ld(s, TCG_TYPE_I64, r1, r1, offsetof(CPUTLBEntry, addend));
Actually, it should be the entire offset from CPUState. The ADDR_WRITE offset before was entirely stuffed into the LD offset.
Quoted 4 lines
At the end of
tcg_out_tlb_cmp(), R0's value is (page# | low bit of VA), if the branch is taken, i.e., TLB miss, R0 will be passed as an argument to helper functions, is it currently holding the correct value? I think at this time R0 should equal toaddr_reg.
You're absolutely right here.
Here's the kind of patch I think will fix it.
r~
commit 04e0dc252203bfbc5b02c2d3d8757a005e304a39
Author: Richard Henderson <[email protected]> Date: Sun Jan 31 15:06:35 2010 -0800
tcg-alpha: Fix problems in qemu_ld/st.
Copy address to R0 in tcg_out_tlb_cmp, for use in helper path. Use entire TLB constant offset performing the ADDEND read.
tcg/alpha/tcg-target.c +18 -30
@@ -709,9 +709,10 @@ static void *qemu_st_helpers[4] = {static void tcg_out_tlb_cmp (TCGContext *s,int sizeop,int r0,int r1,int addr_reg,int label1,long tlb_offset) { +int addrsizeop =TARGET_LONG_BITS ==32 ?2 :3 ;long val; -/* Mask the page, plus the low bits of the access, into R0. Note +/* Mask the page, plus the low bits of the access, into TMP3. Note that the low bits are added in order to catch unaligned accesses, as those bits won't be set in the TLB entry. For 32-bit targets, force the high bits of the mask to be zero, as the high bits of
@@ -720,7 +721,7 @@ static void tcg_out_tlb_cmp(TCGContext *s, int sizeop, int r0, int r1,if (TARGET_LONG_BITS ==32 ) { val &=0xffffffffu ; } -tcg_out_andi (s, addr_reg, val, r0); +tcg_out_andi (s, addr_reg, val,TMP_REG3 );/* Compute the index into the TLB into R1. Again, note that the high bits of a 32-bit address must be cleared. */
@@ -736,11 +737,14 @@ static void tcg_out_tlb_cmp(TCGContext *s, int sizeop, int r0, int r1,/* Load the word at (R1 + CPU_ENV + TLB_OFFSET). Note that we arrange for a 32-bit load to be zero-extended. */ tcg_out_fmt_opr (s,INSN_ADDQ , r1,TCG_AREG0 , r1); -tcg_out_ld_sz (s,TARGET_LONG_BITS ==32 ?2 :3 , -TMP_REG2 , r1, tlb_offset); +tcg_out_ld_sz (s, addrsizeop,TMP_REG2 , r1, tlb_offset); -/* Compare R0 with the value loaded from the TLB. */ - tcg_out_brcond(s, TCG_COND_NE, TMP_REG2, r0, 0, label1); +/* Copy the original address into R0. This is needed on the +slow path through the helper function. */ +tcg_out_extend (s, addrsizeop, addr_reg, r0); + +/* Compare TMP3 with the value loaded from the TLB. */ + tcg_out_brcond(s, TCG_COND_NE, TMP_REG2, TMP_REG3, 0, label1); }#endif /* SOFTMMU */
@@ -769,20 +773,12 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, int sizeop)/* TLB Hit. Note that Alpha statically predicts forward branch as not taken, so arrange the fallthru as the common case. -ADDR_REG contains the guest address, and R1 contains the pointer -to TLB_ENTRY.ADDR_READ. We need to load TLB_ENTRY.ADDEND and -add it to ADDR_REG to get the host address. */ +R0 contains the guest address, and R1 contains the pointer +to CPU_ENV plus the TLB entry offset. */ tcg_out_ld (s,TCG_TYPE_I64 , r1, r1, - offsetof(CPUTLBEntry , addend) - - offsetof(CPUTLBEntry , addr_read)); - -if (TARGET_LONG_BITS ==32 ) { -tcg_out_extend (s,2 , addr_reg, r0); - addr_reg = r0; - } - -tcg_out_fmt_opr (s,INSN_ADDQ , addr_reg, r1, r0); + offsetof(CPUState, tlb_table[mem_index][0].addend)); +tcg_out_fmt_opr (s,INSN_ADDQ , r0, r1, r0); val =0 ;#else r0 = addr_reg;
@@ -841,20 +837,12 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, int sizeop)/* TLB Hit. Note that Alpha statically predicts forward branch as not taken, so arrange the fallthru as the common case. -ADDR_REG contains the guest address, and R1 contains the pointer -to TLB_ENTRY.ADDR_READ. We need to load TLB_ENTRY.ADDEND and -add it to ADDR_REG to get the host address. */ +R0 contains the guest address, and R1 contains the pointer +to CPU_ENV plus the TLB entry offset. */ tcg_out_ld (s,TCG_TYPE_I64 , r1, r1, - offsetof(CPUTLBEntry , addend) - - offsetof(CPUTLBEntry , addr_write)); - -if (TARGET_LONG_BITS ==32 ) { -tcg_out_extend (s,2 , addr_reg, r0); - addr_reg = r0; - } - -tcg_out_fmt_opr (s,INSN_ADDQ , addr_reg, r1, r0); + offsetof(CPUState, tlb_table[mem_index][0].addend)); +tcg_out_fmt_opr (s,INSN_ADDQ , r0, r1, r0); val =0 ;#else r0 = addr_reg;