tcg-hppa get it working, v2.1
cover tcg-hppa get it working, v2.1
Gah. Left out --thread and -s options to format-patch. Sorry about that.
r~
Richard Henderson (4):
tcg-hppa: Fix const errors in hppa-dis.c.
tcg-hppa: Fix 64-bit argument ordering.
tcg-hppa: Finish the port.
tcg-hppa: Compute is_write in cpu_signal_handler.
configure | 5 +- cpu-exec.c | 38 +- hppa-dis.c | 4 +- tcg/hppa/tcg-target.c | 1846 +++++++++++++++++++++++++++++++++++-------------- tcg/hppa/tcg-target.h | 142 +--- tcg/tcg.c | 12 +- 6 files changed, 1387 insertions(+), 660 deletions(-)
PATCH 1/4 tcg-hppa: Fix const errors in hppa-dis.c.
--- hppa-dis.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
hppa-dis.c +2 -2
@@ -576,7 +576,7 @@ struct pa_opcodeconst char *name;unsigned long int match;/* Bits that must be set... */ unsigned long int mask;/* ... in these bits. */ -char *args; +const char *args;enum pa_arch arch;char flags; };
@@ -2753,7 +2753,7 @@ print_insn_hppa (bfd_vma memaddr, disassemble_info *info)int sf =GET_FIELD (insn,19 ,20 );const char *const * source = float_format_names;const char *const * dest = float_format_names; -char *t ="" ; +const char *t ="" ;if (sub ==4 ) {
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [PATCH 1/4] tcg-hppa: Fix const errors in hppa-dis.c.
Quoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
Quoted 30 lines
--- hppa-dis.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hppa-dis.c +2
-2@@ -576,7 +576,7 @@ struct pa_opcodeconst char *name;unsigned long int match;/* Bits that must be set... */ unsigned long int mask;/* ... in these bits. */ -char *args; +const char *args;enum pa_arch arch;char flags; };@@ -2753,7 +2753,7 @@ print_insn_hppa (bfd_vma memaddr, disassemble_info *info)int sf =GET_FIELD (insn,19 ,20 );const char *const * source = float_format_names;const char *const * dest = float_format_names; -char *t ="" ; +const char *t ="" ;if (sub ==4 ) {Signature · 1 line
1.6.6.1
Aurelien Jarno
AppliedRe: [Qemu-devel] [PATCH 1/4] tcg-hppa: Fix const errors in hppa-dis.c.
In reply to Richard HendersonQuoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
Thanks, applied.
Quoted 32 lines
--- hppa-dis.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)hppa-dis.c +2
-2@@ -576,7 +576,7 @@ struct pa_opcodeconst char *name;unsigned long int match;/* Bits that must be set... */ unsigned long int mask;/* ... in these bits. */ -char *args; +const char *args;enum pa_arch arch;char flags; };@@ -2753,7 +2753,7 @@ print_insn_hppa (bfd_vma memaddr, disassemble_info *info)int sf =GET_FIELD (insn,19 ,20 );const char *const * source = float_format_names;const char *const * dest = float_format_names; -char *t ="" ; +const char *t ="" ;if (sub ==4 ) {Signature · 1 line
1.6.6.1
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
PATCH 2/4 tcg-hppa: Fix 64-bit argument ordering.
In reply to Richard Henderson--- tcg/tcg.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)
tcg/tcg.c +11 -1
@@ -596,7 +596,17 @@ void tcg_gen_callN(TCGContext *s, TCGv_ptr func, unsigned int flags, real_args++; }#endif -#ifdef TCG_TARGET_WORDS_BIGENDIAN +/* If stack grows up, then we will be placing successive +arguments at lower addresses, which means we need to +reverse the order compared to how we would normally +treat either big or little-endian. For those arguments +that will wind up in registers, this still works for +HPPA (the only current STACK_GROWSUP target) since the +argument registers are *also* allocated in decreasing +order. If another such target is added, this logic may +have to get more complicated to differentiate between +stack arguments and register arguments. */ +#if defined(TCG_TARGET_WORDS_BIGENDIAN ) != defined(TCG_TARGET_STACK_GROWSUP ) *gen_opparam_ptr++ = args[i] +1 ; *gen_opparam_ptr++ = args[i];#else
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [PATCH 2/4] tcg-hppa: Fix 64-bit argument ordering.
Quoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
Quoted 31 lines
--- tcg/tcg.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)tcg/tcg.c +11
-1@@ -596,7 +596,17 @@ void tcg_gen_callN(TCGContext *s, TCGv_ptr func, unsigned int flags, real_args++; }#endif -#ifdef TCG_TARGET_WORDS_BIGENDIAN +/* If stack grows up, then we will be placing successive +arguments at lower addresses, which means we need to +reverse the order compared to how we would normally +treat either big or little-endian. For those arguments +that will wind up in registers, this still works for +HPPA (the only current STACK_GROWSUP target) since the +argument registers are *also* allocated in decreasing +order. If another such target is added, this logic may +have to get more complicated to differentiate between +stack arguments and register arguments. */ +#if defined(TCG_TARGET_WORDS_BIGENDIAN ) != defined(TCG_TARGET_STACK_GROWSUP ) *gen_opparam_ptr++ = args[i] +1 ; *gen_opparam_ptr++ = args[i];#else Signature · 1 line
1.6.6.1
Aurelien Jarno
AppliedRe: [Qemu-devel] [PATCH 2/4] tcg-hppa: Fix 64-bit argument ordering.
In reply to Richard HendersonQuoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
Thanks, applied.
Quoted 33 lines
--- tcg/tcg.c | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-)tcg/tcg.c +11
-1@@ -596,7 +596,17 @@ void tcg_gen_callN(TCGContext *s, TCGv_ptr func, unsigned int flags, real_args++; }#endif -#ifdef TCG_TARGET_WORDS_BIGENDIAN +/* If stack grows up, then we will be placing successive +arguments at lower addresses, which means we need to +reverse the order compared to how we would normally +treat either big or little-endian. For those arguments +that will wind up in registers, this still works for +HPPA (the only current STACK_GROWSUP target) since the +argument registers are *also* allocated in decreasing +order. If another such target is added, this logic may +have to get more complicated to differentiate between +stack arguments and register arguments. */ +#if defined(TCG_TARGET_WORDS_BIGENDIAN ) != defined(TCG_TARGET_STACK_GROWSUP ) *gen_opparam_ptr++ = args[i] +1 ; *gen_opparam_ptr++ = args[i];#else Signature · 1 line
1.6.6.1
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
PATCH 3/4 tcg-hppa: Finish the port.
In reply to Richard HendersonDelete inline functions from tcg-target.h that don't need to be there, move the others to tcg-target.c. Add 'Z', 'I', 'J' constraints for 0, signed 11-bit, and signed 5-bit respectively. Add 'c' constraint for RET1 register. Add GUEST_BASE support similar to ppc64, with the value stored in a register. Add missing registers to reg_alloc_order. Add support for 12-bit branch relocations. Add functions for synthetic
operations: addi, mtctl, dep, shd, vshd, ori, andi, shifts, rotates, multiply, millicode calls, branches, setcond. Split out TLB reads from qemu_ld and qemu_st; fix argument loading for tlb external calls. Generate the prologue.
--- configure | 5 +- tcg/hppa/tcg-target.c | 1846 +++++++++++++++++++++++++++++++++++-------------- tcg/hppa/tcg-target.h | 142 +--- 3 files changed, 1343 insertions(+), 650 deletions(-)
configure +4 -1
@@ -707,6 +707,9 @@ case "$cpu" in ppc*) host_guest_base="yes" ;; + hppa*) + host_guest_base="yes" + ;; esac [ -z "$guest_base" ] && guest_base="$host_guest_base"
@@ -2659,7 +2662,7 @@ if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then ia64) ldflags="-Wl,-G0 $linker_script -static $ldflags" ;; - i386|x86_64|ppc|ppc64|s390|sparc64|alpha|arm|m68k|mips|mips64) + *) ldflags="$linker_script $ldflags" ;; esac
tcg/hppa/tcg-target.c +1312 -534
2,174 lines not on this page · raw message
tcg/hppa/tcg-target.h +27 -115
160 lines not on this page · raw message
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [PATCH 3/4] tcg-hppa: Finish the port.
Quoted 11 lines · Richard Henderson
Delete inline functions from
tcg-target.hthat don't need to be there, move the others totcg-target.c. Add 'Z', 'I', 'J' constraints for 0, signed 11-bit, and signed 5-bit respectively. Add 'c' constraint for RET1 register. AddGUEST_BASEsupport similar to ppc64, with the value stored in a register. Add missing registers toreg_alloc_order. Add support for 12-bit branch relocations. Add functions for synthetic
operations: addi, mtctl, dep, shd, vshd, ori, andi, shifts, rotates, multiply, millicode calls, branches, setcond. Split out TLB reads fromqemu_ldandqemu_st; fix argument loading for tlb external calls. Generate the prologue.
Quoted 1 line
Signed-off-by Richard Henderson <[email protected]>
I suppose you'd normally have split this into smaller patches, which would make reviewing easier, but there's hardly any risk of regressions, here. I'm away from my HPPA box for a few weeks, so can't really test, but I can't see anything obviously wrong.
I'll try to read through this a little more thoroughly at a later date, but this patch certainly can't make matters any worse than they are... (Bearing in mind that the half-finished HPPA support was written fairly soon after the move to TCG and wasn't substantially updated since!)
The tcg_reg_free() calls worry me slightly, but I assume they're safe...
Signature · 1 line
Stuart Brady
Re: [Qemu-devel] [PATCH 3/4] tcg-hppa: Finish the port.
Quoted 1 line · Stuart Brady
The
tcg_reg_free()calls worry me slightly, but I assume they're safe...
Yeah, that one's rather gross.
Since Aurelien's generic div/rem patch I could simply remove all that millicode stuff, including that tcg_reg_free, and let the generic code handle this instead. Which would get to the same millicode routine via one or two extra levels of indirection.
Thoughts?
r~
Re: [Qemu-devel] [PATCH 3/4] tcg-hppa: Finish the port.
Quoted 4 lines · Richard Henderson
Since Aurelien's generic div/rem patch I could simply remove all that millicode stuff, including that
tcg_reg_free, and let the generic code handle this instead. Which would get to the same millicode routine via one or two extra levels of indirection.
The following patch implements this, and does indeed work.
r~
----
tcg/hppa/tcg-target.c +0 -82
@@ -193,11 +193,6 @@ static int target_parse_constraint(TCGArgConstraint *ct, const char **pct_str) ct->ct |=TCG_CT_REG ;tcg_regset_set32 (ct->u.regs,0 ,0xffffffff );break ; -case 'c' : -/* millicode division return register. */ - ct->ct |TCG_CT_REG ; -tcg_regset_set32 (ct->u.regs,0 ,1u <<TCG_REG_RET1 ); -break ;case 'L' :/* qemu_ld/st constraint */ ct->ct |=TCG_CT_REG ;tcg_regset_set32 (ct->u.regs,0 ,0xffffffff );
@@ -680,65 +675,6 @@ static void tcg_out_xmpyu(TCGContext *s, int retl, int reth, } } -/* We define the following table directly in assembly so that we -can avoid getting PLABEL addresses. */ - -extern tcg_target_long qemu_milli[4 ]; -asm(".section .rodata\n\ -.import $$divI,millicode\n\ -.import $$remI,millicode\n\ -.import $$divU,millicode\n\ -.import $$remU,millicode\n\ -.type qemu_milli,@object\n\ -.size qemu_milli,16\n\ -qemu_milli:\n\ -.word $$divI\n\ -.word $$remI\n\ -.word $$divU\n\ -.word $$remU\n\ -.previous" ); - -#define MILLI_DIVI 0 -#define MILLI_REMI 1 -#define MILLI_DIVU 2 -#define MILLI_REMU 3 - -/* ??? Move this up in tcg.c. */ -static void tcg_reg_free (TCGContext *,int ); - -/* Note that the return is constrained to be r29, and the inputs are -constrained to not be in the first two parameter registers. Otherwise, -we clobber r1 and r31, which are already marked as reserved. */ -static void tcg_out_milli (TCGContext *s,int arg1,int arg2,int which) -{ -tcg_target_long routine, disp; - -/* The parameter registers are clobbered. Store them back to their -stack slots before we lose the contents. */ -tcg_reg_free (s,TCG_REG_R26 ); -tcg_reg_free (s,TCG_REG_R25 ); -tcg_out_mov (s,TCG_REG_R26 , arg1); - - routine = qemu_milli[which]; - disp = (routine - ((tcg_target_long )s->code_ptr +8 )) >>2 ; - -if (check_fit_tl (disp,17 )) { -tcg_out32 (s,INSN_BL |INSN_R2 (TCG_REG_R31 ) |reassemble_17 (disp)); - }else { -uint32_t hi, lo; - - hi = routine >>11 ; - lo = routine &0x7ff ; - -tcg_out32 (s,INSN_LDIL |INSN_R2 (TCG_REG_R1 ) |reassemble_21 (hi)); -tcg_out32 (s,INSN_BLE_SR4 |INSN_R2 (TCG_REG_R1 ) - |reassemble_17 (lo >>2 )); - } - -/* Second input copy in call delay slot. */ -tcg_out_mov (s,TCG_REG_R25 , arg2); -} -static void tcg_out_branch (TCGContext *s,int label_index,int nul) {TCGLabel *l = &s->labels[label_index];
@@ -1443,19 +1379,6 @@ static inline void tcg_out_op(TCGContext *s, int opc, const TCGArg *args,tcg_out_xmpyu (s, args[0 ], args[1 ], args[2 ], args[3 ]);break ; -case INDEX_op_div_i32: -tcg_out_milli (s, args[1 ], args[2 ],MILLI_DIVI ); -break ; -case INDEX_op_divu_i32: -tcg_out_milli (s, args[1 ], args[2 ],MILLI_DIVU ); -break ; -case INDEX_op_rem_i32: -tcg_out_milli (s, args[1 ], args[2 ],MILLI_REMI ); -break ; -case INDEX_op_remu_i32: -tcg_out_milli (s, args[1 ], args[2 ],MILLI_REMU ); -break ; -case INDEX_op_bswap16_i32:tcg_out_bswap16 (s, args[0 ], args[1 ],0 );break ;
@@ -1590,11 +1513,6 @@ static const TCGTargetOpDef hppa_op_defs[] = { { INDEX_op_mul_i32, { "r", "r", "r" } }, { INDEX_op_mulu2_i32, { "r", "r", "r", "r" } }, - { INDEX_op_div_i32, { "c", "L", "L" } }, - { INDEX_op_divu_i32, { "c", "L", "L" } }, - { INDEX_op_rem_i32, { "c", "L", "L" } }, - { INDEX_op_remu_i32, { "c", "L", "L" } }, - { INDEX_op_shl_i32, { "r", "r", "ri" } }, { INDEX_op_shr_i32, { "r", "r", "ri" } }, { INDEX_op_sar_i32, { "r", "r", "ri" } },
tcg/hppa/tcg-target.h +1 -1
@@ -82,7 +82,7 @@ enum {#define TCG_TARGET_STACK_GROWSUP /* optional instructions */ -#define TCG_TARGET_HAS_div_i32 +// #define TCG_TARGET_HAS_div_i32 #define TCG_TARGET_HAS_rot_i32#define TCG_TARGET_HAS_ext8s_i32#define TCG_TARGET_HAS_ext16s_i32
Re: [Qemu-devel] [PATCH 3/4] tcg-hppa: Finish the port.
In reply to Richard HendersonQuoted 11 lines · Richard Henderson
Quoted 1 line · Stuart Brady
The
tcg_reg_free()calls worry me slightly, but I assume they're safe...Yeah, that one's rather gross.
Since Aurelien's generic div/rem patch I could simply remove all that millicode stuff, including that
tcg_reg_free, and let the generic code handle this instead. Which would get to the same millicode routine via one or two extra levels of indirection.Thoughts?
Well, assuming that the millicode stuff does indeed work, I wouldn't worry too much about it... I only imagine that this is something that other archs might need to do too, so it'd be worth doing as cleanly as possible.
Likewise, the qemu_ld/qemu_st refactoring should really be done for other archs at some later stage, too, as it's quite a significant improvement in readability of the code.
Cheers,
Signature · 1 line
Stuart Brady
Re: [Qemu-devel] [PATCH 3/4] tcg-hppa: Finish the port.
In reply to Richard HendersonQuoted 12 lines · Richard Henderson
Quoted 1 line · Stuart Brady
The
tcg_reg_free()calls worry me slightly, but I assume they're safe...Yeah, that one's rather gross.
Since Aurelien's generic div/rem patch I could simply remove all that millicode stuff, including that
tcg_reg_free, and let the generic code handle this instead. Which would get to the same millicode routine via one or two extra levels of indirection.Thoughts?
I think that's the way to go. Can you please send a new patch doing that?
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
PATCH 4/4 tcg-hppa: Compute is_write in cpu_signal_handler.
In reply to Richard Henderson--- cpu-exec.c | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-)
cpu-exec.c +31 -7
@@ -1193,15 +1193,39 @@ int cpu_signal_handler(int host_signum, void *pinfo, {struct siginfo *info = pinfo;struct ucontext *uc = puc; -unsigned long pc; -int is_write; +unsigned long pc = uc->uc_mcontext.sc_iaoq[0 ]; +uint32_t insn = *(uint32_t *)pc; +int is_write =0 ; + +/* XXX: need kernel patch to get write flag faster. */ +switch (insn >>26 ) { +case 0x1a :/* STW */ +case 0x19 :/* STH */ +case 0x18 :/* STB */ +case 0x1b :/* STWM */ + is_write =1 ; +break ; + +case 0x09 :/* CSTWX, FSTWX, FSTWS */ +case 0x0b :/* CSTDX, FSTDX, FSTDS */ +/* Distinguish from coprocessor load ... */ + is_write = (insn >>9 ) &1 ; +break ; + +case 0x03 : +switch ((insn >>6 ) &15 ) { +case 0xa :/* STWS */ +case 0x9 :/* STHS */ +case 0x8 :/* STBS */ +case 0xe :/* STWAS */ +case 0xc :/* STBYS */ + is_write =1 ; + } +break ; + } - pc = uc->uc_mcontext.sc_iaoq[0 ]; -/* FIXME: compute is_write */ - is_write =0 ;return handle_cpu_signal (pc, (unsigned long )info->si_addr, - is_write, - &uc->uc_sigmask, puc); + is_write, &uc->uc_sigmask, puc); }#else
Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [PATCH 4/4] tcg-hppa: Compute is_write in cpu_signal_handler.
Quoted 1 line · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>
Argh. It just seems mind bogglingly silly that is_write doesn't seem to be included in the siginfo on archs where doing so would make sense...
It's at least something I'd have hoped libc could take care of in the case where the hardware doesn't indicate whether the fault was due to a read or a write...
(Right up there with the use of our own caching flushing code instead of calls to mprotect(), etc. and the rather dubious use of qemu-lock.h...)
Quoted 59 lines
--- cpu-exec.c | 38 +++++++++++++++++++++++++++++++------- 1 files changed, 31 insertions(+), 7 deletions(-)cpu-exec.c +31
-7@@ -1193,15 +1193,39 @@ int cpu_signal_handler(int host_signum, void *pinfo, {struct siginfo *info = pinfo;struct ucontext *uc = puc; -unsigned long pc; -int is_write; +unsigned long pc = uc->uc_mcontext.sc_iaoq[0 ]; +uint32_t insn = *(uint32_t *)pc; +int is_write =0 ; + +/* XXX: need kernel patch to get write flag faster. */ +switch (insn >>26 ) { +case 0x1a :/* STW */ +case 0x19 :/* STH */ +case 0x18 :/* STB */ +case 0x1b :/* STWM */ + is_write =1 ; +break ; + +case 0x09 :/* CSTWX, FSTWX, FSTWS */ +case 0x0b :/* CSTDX, FSTDX, FSTDS */ +/* Distinguish from coprocessor load ... */ + is_write = (insn >>9 ) &1 ; +break ; + +case 0x03 : +switch ((insn >>6 ) &15 ) { +case 0xa :/* STWS */ +case 0x9 :/* STHS */ +case 0x8 :/* STBS */ +case 0xe :/* STWAS */ +case 0xc :/* STBYS */ + is_write =1 ; + } +break ; + } - pc = uc->uc_mcontext.sc_iaoq[0 ]; -/* FIXME: compute is_write */ - is_write =0 ;return handle_cpu_signal (pc, (unsigned long )info->si_addr, - is_write, - &uc->uc_sigmask, puc); + is_write, &uc->uc_sigmask, puc); }#else Signature · 1 line
1.6.6.1
Re: [Qemu-devel] [PATCH 4/4] tcg-hppa: Compute is_write in cpu_signal_handler.
Quoted 6 lines · Stuart Brady
Argh. It just seems mind bogglingly silly that
is_writedoesn't seem to be included in the siginfo on archs where doing so would make sense...It's at least something I'd have hoped libc could take care of in the case where the hardware doesn't indicate whether the fault was due to a read or a write...
Oh, actually, I guess you'd just test the equivalent of '(info->si_isr >> 33) & 1' or 'DSISR_sig(uc) & 0x00800000)' on such an arch, but it still seems a shame that this isn't done for us on archs without that ability...
Cheers,
Signature · 1 line
Stuart Brady
Re: [Qemu-devel] [PATCH 4/4] tcg-hppa: Compute is_write in cpu_signal_handler.
Quoted 4 lines · Stuart Brady
Quoted 2 lines · Stuart Brady
Argh. It just seems mind bogglingly silly that
is_writedoesn't seem to be included in the siginfo on archs where doing so would make sense...
Quoted 8 lines
Quoted 3 lines
It's at least something I'd have hoped libc could take care of in the case where the hardware doesn't indicate whether the fault was due to a read or a write...
Oh, actually, I guess you'd just test the equivalent of '(
info->si_isr>> 33) & 1' or 'DSISR_sig(uc)&0x00800000)' on such an arch, but it still seems a shame that this isn't done for us on archs without that ability...
Unfortunately there's no reserved space in the hppa sigcontext, which is what would need to be expanded in order to store the additional info from the kernel. So in addition to a kernel patch, userland would need to change its abi. All kinda nasty, that.
r~