ia64 support
This patch series adds host Itanium support to QEMU.
System mode works correctly except a few unaligned access in the slirp code (fixed by the kernel). It has been tested by booting debian installer on arm, i386, mips, mipsel, ppc, sparc, and x86_64. A full installation has been done on sparc.
User mode works correctly for static binaries, but fails for some dynamic binaries, due to mmap emulation not working correctly when host page size is bigger than the target one.
PATCH 1/5 linux-user/ia64: workaround ia64 strangenesses
ia64 has some strangenesses that need to be workaround:
- it has a __clone2() syscall instead of the using clone() one, with different arguments, and which is not declared in the usual headers.
- ucontext.uc_sigmask is declared with type long int, while it is actually of type sigset_t.
- uc_mcontext, uc_sigmask, uc_stack, uc_link are declared using #define, which clashes with the target_ucontext fields. Change their names to tuc_*, as already done for some target architectures.
--- cpu-exec.c | 6 +- linux-user/signal.c | 208 +++++++++++++++++++++++++------------------------- linux-user/syscall.c | 6 +- 3 files changed, 114 insertions(+), 106 deletions(-)
cpu-exec.c +5 -1
@@ -81,7 +81,11 @@ void cpu_resume_from_signal(CPUState *env1, void *puc)if (puc) {/* XXX: use siglongjmp ? */ #ifdef __linux__ +#ifdef __ia64 +sigprocmask (SIG_SETMASK , (sigset_t *)&uc->uc_sigmask,NULL ); +#else sigprocmask (SIG_SETMASK , &uc->uc_sigmask,NULL ); +#endif #elif defined(__OpenBSD__)sigprocmask (SIG_SETMASK , &uc->sc_mask,NULL );#endif
@@ -1150,7 +1154,7 @@ int cpu_signal_handler(int host_signum, void *pinfo, void *puc) }return handle_cpu_signal (ip, (unsigned long )info->si_addr, is_write, - &uc->uc_sigmask, puc); + (sigset_t *)&uc->uc_sigmask, puc); }#elif defined(__s390__)
linux-user/signal.c +104 -104
438 lines not on this page · raw message
linux-user/syscall.c +5 -1
@@ -41,6 +41,10 @@#include <sys/swap.h> #include <signal.h> #include <sched.h> +#ifdef __ia64__ +int __clone2 (int (*fn)(void *),void *child_stack_base, +size_t stack_size,int flags,void *arg, ...); +#endif #include <sys/socket.h> #include <sys/un.h> #include <sys/uio.h>
@@ -3628,7 +3632,7 @@ static int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp,return -EINVAL ;/* This is probably going to die very quickly, but do it anyway. */ #ifdef __ia64__ - ret =__clone2 (clone_func, new_stack +NEW_STACK_SIZE , flags, new_env); + ret =__clone2 (clone_func, new_stack,NEW_STACK_SIZE , flags, new_env);#else ret =clone (clone_func, new_stack +NEW_STACK_SIZE , flags, new_env);#endif
Signature · 1 line
1.7.0.2
[Qemu-devel] Re: [PATCH 1/5] linux-user/ia64: workaround ia64 strangenesses
cpu-exec.c void cpu_resume_from_signal(CPUState *env1, void *puc) · line 88
Quoted 6 lines
cpu-exec.c +4
-0+#ifdef __ia64 +sigprocmask (SIG_SETMASK , (sigset_t *)&uc->uc_sigmask,NULL ); +#else sigprocmask (SIG_SETMASK ,&uc->uc_sigmask,NULL ); +#endif
Any reason for the ifdef?
Paolo
Re: [Qemu-devel] Re: [PATCH 1/5] linux-user/ia64: workaround ia64 strangenesses
Quoted 9 lines · Paolo Bonzini
cpu-exec.c void cpu_resume_from_signal(CPUState *env1, void *puc) · line 88
Quoted 6 lines
cpu-exec.c +4
-0+#ifdef __ia64 +sigprocmask (SIG_SETMASK , (sigset_t *)&uc->uc_sigmask,NULL ); +#else sigprocmask (SIG_SETMASK ,&uc->uc_sigmask,NULL ); +#endif Any reason for the ifdef?
It is not strictly needed, as all architectures can cope with the ia64 version. I have added it to make sure that a new architecture triggers a warning if uc->uc_sigmask is not of type sigset_t, so that a human can verify the cast is correct.
That said, I am fine removing the #ifdef if we consider this is unlikely to happen.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Re: [Qemu-devel] Re: [PATCH 1/5] linux-user/ia64: workaround ia64 strangenesses
Quoted 11 lines · Aurelien Jarno
Quoted 9 lines · Paolo Bonzini
cpu-exec.c void cpu_resume_from_signal(CPUState *env1, void *puc) · line 88
Quoted 6 lines
cpu-exec.c +4
-0+#ifdef __ia64 +sigprocmask (SIG_SETMASK , (sigset_t *)&uc->uc_sigmask,NULL ); +#else sigprocmask (SIG_SETMASK ,&uc->uc_sigmask,NULL ); +#endif Any reason for the ifdef?
Quoted 4 lines
It is not strictly needed, as all architectures can cope with the ia64 version. I have added it to make sure that a new architecture triggers a warning if
uc->uc_sigmaskis not of typesigset_t, so that a human can verify the cast is correct.
What type is the ia64 uc_sigmask, if not sigset_t? A git grep of the kernel found only:
arch/ia64/include/asm/ucontext.h:#define uc_sigmask uc_mcontext.sc_sigmask
with sc_sigmask not defined anywhere. The uc_mcontext.sc_mask field, though, is a sigset_t.
-- Jamie
Re: [Qemu-devel] Re: [PATCH 1/5] linux-user/ia64: workaround ia64 strangenesses
Quoted 12 lines · Jamie Lokier
Quoted 11 lines · Aurelien Jarno
Quoted 9 lines · Paolo Bonzini
cpu-exec.c void cpu_resume_from_signal(CPUState *env1, void *puc) · line 88
Quoted 6 lines
cpu-exec.c +4
-0+#ifdef __ia64 +sigprocmask (SIG_SETMASK , (sigset_t *)&uc->uc_sigmask,NULL ); +#else sigprocmask (SIG_SETMASK ,&uc->uc_sigmask,NULL ); +#endif Any reason for the ifdef?
Quoted 6 lines
Quoted 4 lines
It is not strictly needed, as all architectures can cope with the ia64 version. I have added it to make sure that a new architecture triggers a warning if
uc->uc_sigmaskis not of typesigset_t, so that a human can verify the cast is correct.What type is the ia64
uc_sigmask, if notsigset_t?
It is defined as a unsigned long int. From <bits/sigcontext.h>:
| /* sc_mask is actually an sigset_t but we don't want to | * include the kernel headers here. */ | unsigned long int sc_mask; /* signal mask to restore after handler returns */
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
PATCH 2/5 linux-user: fix page_unprotect when host page size > target page size
In reply to Aurelien JarnoWhen the host page size is bigger that the target one, unprotecting a page should:
- mark all the target pages corresponding to the host page as writable
- invalidate all tb corresponding to the host page (and not the target page)
--- exec.c | 45 ++++++++++++++++++++++----------------------- 1 files changed, 22 insertions(+), 23 deletions(-)
exec.c +22 -23
@@ -2447,8 +2447,8 @@ int page_check_range(target_ulong start, target_ulong len, int flags)page. Return TRUE if the fault was successfully handled. */ int page_unprotect (target_ulong address,unsigned long pc,void *puc) { -unsigned int page_index, prot, pindex; -PageDesc *p, *p1; +unsigned int prot; +PageDesc *p;target_ulong host_start, host_end, addr;/* Technically this isn't safe inside a signal handler. However we
@@ -2456,37 +2456,36 @@ int page_unprotect(target_ulong address, unsigned long pc, void *puc)practice it seems to be ok. */ mmap_lock (); - host_start = address & qemu_host_page_mask; - page_index = host_start >>TARGET_PAGE_BITS ; - p1 =page_find (page_index); -if (!p1) { + p =page_find (address >>TARGET_PAGE_BITS ); +if (!p) {mmap_unlock ();return 0 ; } - host_end = host_start + qemu_host_page_size; - p = p1; - prot =0 ; -for (addr = host_start;addr < host_end; addr +=TARGET_PAGE_SIZE ) { - prot |= p->flags; - p++; - } +/* if the page was really writable, then we change its protection back to writable */ -if (prot &PAGE_WRITE_ORG ) { - pindex = (address - host_start) >>TARGET_PAGE_BITS ; -if (!(p1[pindex].flags &PAGE_WRITE )) { -mprotect ((void *)g2h (host_start), qemu_host_page_size, - (prot &PAGE_BITS ) |PAGE_WRITE ); - p1[pindex].flags |=PAGE_WRITE ; +if ((p->flags &PAGE_WRITE_ORG ) && !(p->flags &PAGE_WRITE )) { + host_start = address & qemu_host_page_mask; + host_end = host_start + qemu_host_page_size; + + prot =0 ; +for (addr = host_start ; addr < host_end ; addr +=TARGET_PAGE_SIZE ) { + p =page_find (addr >>TARGET_PAGE_BITS ); + p->flags |=PAGE_WRITE ; + prot |= p->flags; +/* and since the content will be modified, we must invalidate the corresponding translated code. */ -tb_invalidate_phys_page (address, pc, puc); +tb_invalidate_phys_page (addr, pc, puc);#ifdef DEBUG_TB_CHECK -tb_invalidate_check (address); +tb_invalidate_check (addr);#endif -mmap_unlock (); -return 1 ; } +mprotect ((void *)g2h (host_start), qemu_host_page_size, + prot &PAGE_BITS ); + +mmap_unlock (); +return 1 ; }mmap_unlock ();return 0 ;
Signature · 1 line
1.7.0.2
PATCH 3/5 ia64 disas support
In reply to Aurelien JarnoTaken from binutils SVN, using last GPLv2 version.
--- Makefile.objs | 1 + configure | 4 + dis-asm.h | 5 + disas.c | 17 + ia64-dis.c |10598 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 10625 insertions(+), 0 deletions(-) create mode 100644 ia64-dis.c
See attached gzipped file. Sorry for the inconvenience, but the message size on the mailing list is limited.
PATCH 4/5 tcg: align static_code_gen_buffer to CODE_GEN_ALIGN
In reply to Aurelien JarnoOn ia64, the default memory alignement is not enough for a code alignement. To fix that, force static_code_gen_buffer alignment to CODE_GEN_ALIGN.
--- exec.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
exec.c +2 -1
@@ -447,7 +447,8 @@ static void tlb_unprotect_code_phys(CPUState *env, ram_addr_t ram_addr,#endif #ifdef USE_STATIC_CODE_GEN_BUFFER -static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE ]; +static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] + __attribute__((aligned (CODE_GEN_ALIGN)));#endif static void code_gen_alloc (unsigned long tb_size)
Signature · 1 line
1.7.0.2
PATCH 5/5 tcg: initial ia64 support
In reply to Aurelien JarnoA few words about design choices:
* On IA64, instructions should be grouped by bundle, and dependencies between instructions declared. A first version of this code tried to schedule instructions automatically, but was very complex and too invasive for the current common TCG code (ops not ending at instruction boundaries, code retranslation breaking already generated code, etc.) It was also not very efficient, as dependencies between TCG ops is not available.
Instead the option taken by the current implementation does not try to fill the bundle by scheduling instructions, but by providing ops not available as an ia64 instruction, and by offering 22-bit constant loading for most of the instructions. With both options the bundle are filled are approximately the same level.
* Up to 128 registers can be affected to a function on IA64, but TCG limits this number to 64, which is actually more than enough. The register affectation is the following:
- r0: used to map a constant argument with value 0
- r1: global pointer
- r2, r3: internal use
- r4 to r6: not used to avoid saving them
- r7: env structure
- r8 to r11: free for TCG (call clobbered)
- r12: stack pointer
- r13: thread pointer
- r14 to r31: free for TCG (call clobbered)
- r32: reserved (return address)
- r33: reserved (PFS)
- r33 to r63: free for TCG
* The IA64 architecture has only 64-bit registers and no 32-bit instructions (the only exception being cmp4). Therefore 64-bit registers and instructions are used for 32-bit ops. The adopted strategy is the same as the ABI, that is the higher 32 bits are undefined. Most ops (and, or, add, shl, etc.) can directly use the 64-bit registers, while some others have to sign-extend (sar, div, etc.) or zero-extend (shr, divu, etc.) the register first.
--- configure | 20 +- cpu-common.h | 2 +- tcg/ia64/tcg-target.c | 2325 +++++++++++++++++++++++++++++++++++++++++++++++++ tcg/ia64/tcg-target.h | 156 ++++ 4 files changed, 2488 insertions(+), 15 deletions(-) create mode 100644 tcg/ia64/tcg-target.c create mode 100644 tcg/ia64/tcg-target.h
configure +6 -14
@@ -193,6 +193,8 @@ elif check_define _ARCH_PPC ; then fi elif check_define __mips__ ; then cpu="mips" +elif check_define __ia64__ ; then + cpu="ia64" else cpu=`uname -m` fi
@@ -710,6 +712,9 @@ case "$cpu" in mips*) host_guest_base="yes" ;; + ia64*) + host_guest_base="yes" + ;; esac [ -z "$guest_base" ] && guest_base="$host_guest_base"
@@ -2659,9 +2664,6 @@ alpha) # Ensure there's only a single GP cflags="-msmall-data $cflags" ;; -ia64) - cflags="-mno-sdata $cflags" -;; esac if test "$target_softmmu" = "yes" ; then
@@ -2706,21 +2708,11 @@ if test "$target_linux_user" = "yes" -o "$target_bsd_user" = "yes" ; then # -static is used to avoid g1/g3 usage by the dynamic linker ldflags="$linker_script -static $ldflags" ;; - ia64) - ldflags="-Wl,-G0 $linker_script -static $ldflags" - ;; - i386|x86_64|ppc|ppc64|s390|sparc64|alpha|arm|m68k|mips|mips64) + i386|x86_64|ppc|ppc64|s390|sparc64|alpha|arm|m68k|mips|mips64|ia64) ldflags="$linker_script $ldflags" ;; esac fi -if test "$target_softmmu" = "yes" ; then - case "$ARCH" in - ia64) - ldflags="-Wl,-G0 $linker_script -static $ldflags" - ;; - esac -fi echo "LDFLAGS+=$ldflags" >> $config_target_mak echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
cpu-common.h +1 -1
@@ -3,7 +3,7 @@/* 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(__ia64__)#define WORDS_ALIGNED #endif
tcg/ia64/tcg-target.c new file +2325 -0
2,325 lines not on this page · raw message
tcg/ia64/tcg-target.h new file +156 -0
156 lines not on this page · raw message
Signature · 1 line
1.7.0.2