ppc64 host support
PATCH 1/1 ppc64 host support
In case someone else has interest in this, a preliminary patch for 64-bit powerpc host _with_ 64-bit userland, eg. gentoo/ppc64. A bit unclean, because some functions needed one argument to be appended. Compiles at least i386-user+softmmu and powerpc-softmmu. i386-softmmu boots sarge i386 netinst, but has some trouble after keyboard selection, i386-user runs 'ls'. The configure changes rudely destroy building on ppc 64-bit kernel + 32-bit userland.
-- Heikki Lindholm
configure +9 -3
@@ -41,9 +41,12 @@ alpha) cpu="alpha" ;; - "Power Macintosh"|ppc|ppc64) + "Power Macintosh"|ppc) cpu="powerpc" ;; + ppc64) + cpu="powerpc64" + ;; mips) cpu="mips" ;;
@@ -262,7 +265,7 @@ else # if cross compiling, cannot launch a program, so make a static guess -if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" -o "$cpu" = "sparc" -o "$cpu" = "sparc64" -o "$cpu" = "m68k" -o "$cpu" = "armv4b"; then +if test "$cpu" = "powerpc" -o "$cpu" = "powerpc64" -o "$cpu" = "mips" -o "$cpu" = "s390" -o "$cpu" = "sparc" -o "$cpu" = "sparc64" -o "$cpu" = "m68k" -o "$cpu" = "armv4b"; then bigendian="yes" fi
@@ -270,7 +273,7 @@ # host long bits test hostlongbits="32" -if test "$cpu" = "sparc64" -o "$cpu" = "ia64" -o "$cpu" = "x86_64" -o "$cpu" = "alpha"; then +if test "$cpu" = "sparc64" -o "$cpu" = "ia64" -o "$cpu" = "x86_64" -o "$cpu" = "alpha" -o "$cpu" = "powerpc64"; then hostlongbits="64" fi
@@ -501,6 +504,9 @@ elif test "$cpu" = "powerpc" ; then echo "ARCH=ppc" >> $config_mak echo "#define HOST_PPC 1" >> $config_h +elif test "$cpu" = "powerpc64" ; then + echo "ARCH=ppc64" >> $config_mak + echo "#define HOST_PPC64 1" >> $config_h elif test "$cpu" = "mips" ; then echo "ARCH=mips" >> $config_mak echo "#define HOST_MIPS 1" >> $config_h
cpu-exec.c +28 -2
@@ -83,6 +83,9 @@unsigned int h;target_ulong phys_pc, phys_page1, phys_page2, virt_page2;uint8_t *tc_ptr; +#ifdef __powerpc64__ +long toc_addr; +#endif spin_lock (&tb_lock);
@@ -132,9 +135,16 @@ tb->tc_ptr = tc_ptr; tb->cs_base = cs_base; tb->flags = flags; -cpu_gen_code (env, tb,CODE_GEN_MAX_SIZE , &code_gen_size); +cpu_gen_code (env, tb,CODE_GEN_MAX_SIZE , +#ifdef __powerpc64__ + &toc_addr, +#endif + &code_gen_size); code_gen_ptr = (void *)(((unsigned long )code_gen_ptr + code_gen_size +CODE_GEN_ALIGN -1 ) & ~(CODE_GEN_ALIGN -1 )); - +#ifdef __powerpc64__ + tb->toc_addr = toc_addr; +#endif +/* check next page if needed */ virt_page2 = (pc + tb->size -1 ) &TARGET_PAGE_MASK ; phys_page2 =-1 ;
@@ -253,6 +263,9 @@int saved_i7, tmp_T0;#endif int ret, interrupt_request; +#ifdef __powerpc64__ +unsigned long toc_addr; +#endif void (*gen_func)(void );TranslationBlock *tb;uint8_t *tc_ptr;
@@ -649,6 +662,9 @@ } } tc_ptr = tb->tc_ptr; +#ifdef __powerpc64__ + toc_addr = tb->toc_addr; +#endif env->current_tb = tb;/* execute the generated code */ gen_func = (void *)tc_ptr;
@@ -739,6 +755,16 @@ ); } } +#elif defined(__powerpc64__) +struct fdesc { +uint64_t entry; +uint64_t toc_base; +uint64_t env_ptr; + } fp; + fp.entry = (uint64_t )tc_ptr; + fp.toc_base = toc_addr; + fp.env_ptr =0 ; + (*(void (*)(void ))&fp)();#elif defined(__ia64)struct fptr { void *ip;
dyngen.c +171 -8
340 lines not on this page · raw message
dyngen-exec.h +2 -2
@@ -29,7 +29,7 @@typedef unsigned short uint16_t ;typedef unsigned int uint32_t ;/* XXX may be done for all 64 bits targets ? */ -#if defined (__x86_64__) || defined(__ia64) +#if defined (__x86_64__) || defined(__ia64) || defined(__powerpc64__)typedef unsigned long uint64_t ;#else typedef unsigned long long uint64_t ;
@@ -38,7 +38,7 @@typedef signed char int8_t ;typedef signed short int16_t ;typedef signed int int32_t ; -#if defined (__x86_64__) || defined(__ia64) +#if defined (__x86_64__) || defined(__ia64) || defined(__powerpc64__)typedef signed long int64_t ;#else typedef signed long long int64_t ;
dyngen.h +138 -18
169 lines not on this page · raw message
elf.h +121 -0
127 lines not on this page · raw message
exec-all.h +81 -7
145 lines not on this page · raw message
exec.c +10 -2
@@ -439,7 +439,11 @@another TB */ static inline void tb_reset_jump (TranslationBlock *tb,int n) { -tb_set_jmp_target (tb, n, (unsigned long )(tb->tc_ptr + tb->tb_next_offset[n])); +tb_set_jmp_target (tb, n, +#ifdef __powerpc64__ + tb->toc_addr, +#endif + (unsigned long )(tb->tc_ptr + tb->tb_next_offset[n])); }static inline void tb_phys_invalidate (TranslationBlock *tb,unsigned int page_addr)
@@ -580,7 +584,11 @@ tb->cs_base = cs_base; tb->flags = flags; tb->cflags = cflags; -cpu_gen_code (env, tb,CODE_GEN_MAX_SIZE , &code_gen_size); +cpu_gen_code (env, tb,CODE_GEN_MAX_SIZE , +#ifdef __powerpc64__ + &tb->toc_addr, +#endif + &code_gen_size); code_gen_ptr = (void *)(((unsigned long )code_gen_ptr + code_gen_size +CODE_GEN_ALIGN -1 ) & ~(CODE_GEN_ALIGN -1 ));/* check next page if needed */
linux-user/elfload.c +12 -0
@@ -13,6 +13,18 @@#include "qemu.h" #include "disas.h" +#ifdef __powerpc64__ +#undef elf_check_arch +#undef ELF_CLASS +#undef ELF_DATA +#undef ELF_ARCH +#undef ELF_PLAT_INIT +#undef ELF_PLATFORM +#undef ELF_HWCAP +#undef R_PPC_NUM +#undef ARCH_DLINFO +#endif +/* this flag is uneffective under linux too, should be deleted */ #ifndef MAP_DENYWRITE #define MAP_DENYWRITE 0
linux-user/mmap.c +2 -2
@@ -153,7 +153,7 @@ {unsigned long ret, end, host_start, host_end, retaddr, host_offset, host_len;#if defined(__alpha__) || defined(__sparc__) || defined(__x86_64__) || \ - defined(__ia64) + defined(__ia64) || defined(__powerpc64__)static unsigned long last_start =0x40000000 ;#endif
@@ -195,7 +195,7 @@if (!(flags &MAP_FIXED )) {#if defined(__alpha__) || defined(__sparc__) || defined(__x86_64__) || \ - defined(__ia64) + defined(__ia64) || defined(__powerpc64__)/* tell the kenel to search at the same place as i386 */ if (host_start ==0 ) { host_start = last_start;
linux-user/syscall.c +15 -2
@@ -87,18 +87,21 @@#undef __sc_loadargs_3#undef __sc_loadargs_4#undef __sc_loadargs_5 +#undef __sc_loadargs_6#undef __sc_asm_input_0#undef __sc_asm_input_1#undef __sc_asm_input_2#undef __sc_asm_input_3#undef __sc_asm_input_4#undef __sc_asm_input_5 +#undef __sc_asm_input_6#undef _syscall0#undef _syscall1#undef _syscall2#undef _syscall3#undef _syscall4#undef _syscall5 +#undef _syscall6/* need to redefine syscalls as Linux kernel defines are incorrect for the clobber list */
@@ -117,6 +120,7 @@ registerunsigned long __sc_5 __asm__ ("r5" ); \ registerunsigned long __sc_6 __asm__ ("r6" ); \ registerunsigned long __sc_7 __asm__ ("r7" ); \ + registerunsigned long __sc_8 __asm__ ("r8" ); \ \ __sc_loadargs_##nr(name, args); \ __asm__ __volatile__ \
@@ -125,10 +129,10 @@ : "=&r" (__sc_0), \ "=&r" (__sc_3), "=&r" (__sc_4), \ "=&r" (__sc_5), "=&r" (__sc_6), \ - "=&r" (__sc_7) \ + "=&r" (__sc_7), "=&r" (__sc_8) \ : __sc_asm_input_##nr \ : "cr0", "ctr", "memory", \ - "r8", "r9", "r10","r11", "r12"); \ + "r9", "r10","r11", "r12"); \ __sc_ret = __sc_3; \ __sc_err = __sc_0; \ } \
@@ -156,6 +160,9 @@#define __sc_loadargs_5 (name, arg1, arg2, arg3, arg4, arg5) \ __sc_loadargs_4(name, arg1, arg2, arg3, arg4); \ __sc_7 = (unsigned long) (arg5) +#define __sc_loadargs_6 (name, arg1, arg2, arg3, arg4, arg5, arg6) \ + __sc_loadargs_5(name, arg1, arg2, arg3, arg4, arg5); \ + __sc_8 = (unsigned long) (arg6)#define __sc_asm_input_0 "0" (__sc_0)#define __sc_asm_input_1 __sc_asm_input_0, "1" (__sc_3)
@@ -163,6 +170,7 @@#define __sc_asm_input_3 __sc_asm_input_2, "3" (__sc_5)#define __sc_asm_input_4 __sc_asm_input_3, "4" (__sc_6)#define __sc_asm_input_5 __sc_asm_input_4, "5" (__sc_7) +#define __sc_asm_input_6 __sc_asm_input_5, "6" (__sc_8)#define _syscall0 (type,name) \ type name(void) \
@@ -199,6 +207,11 @@ { \__syscall_nr (5 , type, name, arg1, arg2, arg3, arg4, arg5); \ } +#define _syscall6 (type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,type5,arg5,type6,arg6) \ +type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) \ +{ \ + __syscall_nr(6, type, name, arg1, arg2, arg3, arg4, arg5, arg6); \ +}#endif #define __NR_sys_uname __NR_uname
Makefile.target +6 -0
@@ -101,6 +101,12 @@ LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc.ld endif +ifeq ($(ARCH),ppc64) +CFLAGS+= -D__powerpc__ -D__powerpc64__ +OP_CFLAGS=$(CFLAGS) +LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc64.ld +endif + ifeq ($(ARCH),s390) OP_CFLAGS=$(CFLAGS) LDFLAGS+=-Wl,-T,$(SRC_PATH)/s390.ld
ppc_icache.h +26 -0
@@ -0,0 +1,26 @@ +#ifdef __powerpc64__ +#define MIN_CACHE_LINE_SIZE 0x80 +#else +#define MIN_CACHE_LINE_SIZE 8/* conservative value */ +#endif + +static void inline flush_icache_range (unsigned long start,unsigned long stop) +{ +unsigned long p; + + p = start & ~(MIN_CACHE_LINE_SIZE -1 ); + stop = (stop +MIN_CACHE_LINE_SIZE -1 ) & ~(MIN_CACHE_LINE_SIZE -1 ); + +for (p = start; p < stop; p +=MIN_CACHE_LINE_SIZE ) { + asmvolatile ("dcbst 0,%0" : :"r" (p) :"memory" ); + } + asmvolatile ("sync" : : :"memory" ); +for (p = start; p < stop; p +=MIN_CACHE_LINE_SIZE ) { + asmvolatile ("icbi 0,%0" : :"r" (p) :"memory" ); + } +#ifndef __powerpc64__ + asmvolatile ("sync" : : :"memory" ); +#endif + asmvolatile ("isync" : : :"memory" ); +} +
ppc64.ld +222 -0
222 lines not on this page · raw message
translate-all.c +13 -2
@@ -31,6 +31,9 @@#include "disas.h" extern int dyngen_code (uint8_t *gen_code_buf, +#ifdef __powerpc64__ + uint64_t *toc_addr_ptr, +#endifuint16_t *label_offsets,uint16_t *jmp_offsets,const uint16_t *opc_buf,const uint32_t *opparam_buf,const long *gen_labels);
@@ -139,7 +142,11 @@code). */ int cpu_gen_code (CPUState *env,TranslationBlock *tb, -int max_code_size,int *gen_code_size_ptr) +int max_code_size, +#ifdef __powerpc64__ + uint64_t *toc_addr_ptr, +#endif +int *gen_code_size_ptr) {uint8_t *gen_code_buf;int gen_code_size;
@@ -165,7 +172,11 @@#endif dyngen_labels (gen_labels, nb_gen_labels, gen_code_buf, gen_opc_buf); - gen_code_size = dyngen_code(gen_code_buf, tb->tb_next_offset, + gen_code_size = dyngen_code(gen_code_buf, +#ifdef __powerpc64__ + toc_addr_ptr, +#endif + tb->tb_next_offset, #ifdef USE_DIRECT_JUMP tb->tb_jmp_offset, #else
vl.c +10 -1
@@ -506,7 +506,16 @@/***********************************************************/ /* timers */ -#if defined(__powerpc__) +#if defined(__powerpc64__) + +int64_t cpu_get_real_ticks (void ) +{ +int64_t t; + asmvolatile ("mftb %0\n" :"=r" (t)); +return t; +} + +#elif defined(__powerpc__)static inline uint32_t get_tbl (void ) {