Misc patches for qemu
Hello, Fabrice,
Here's a set of patches that fix some target emulation portability problems in qemu:
- The most important: Fix target-cpu option display in configure script
- Protect dyngen_exec.h against multiple inclusions. I'm not sure that it's still needed, but that cannot be bad...
- Add INTxx_MIN & MAX definitions.
- Remove the empty code test in PPC case: there are some various way to get a nop on PPC, and I feel good to let gcc produce no code for them rather than checking those cases during code generation phase.
- Fix a bug in PPC disassembly, assuming that the PPC memory is always big-endian...
- Protect some undefined syscalls for PPC. That may not be the best patch, but it makes things compile.
- Protect static inline functions in thunk.h:
those function have references on struct_entries
which isn't defined when compilng dyngen.c
It seems that native powerpc-gcc V 3.2 always tries to generate non inlined versions of thoses functions, which make the link process fail...
- #ifdef some #include "cpu-i386.h" things
So, nothing really corosive, for now !
More to come (soon), for PPC emulation...
Signature · 1 line
Jocelyn Mayer <[email protected]>
Index: configure
===================================================================
RCS file: /cvsroot/qemu/qemu/configure,v
retrieving revision 1.14
configure +1 -1
@@ -190,7 +192,7 @@ echo "Standard options:" echo " --help print this message" echo " --prefix=PREFIX install in PREFIX [$prefix]" echo " --interp-prefix=PREFIX where to find shared libraries, etc. [$interp_prefix]" -echo " --target_cpu=CPU set target cpu (x86 or arm) [$target_cpu]" +echo " --target-cpu=CPU set target cpu (x86 ppc or arm) [$target_cpu]" echo "" echo "Advanced options (experts only):" echo " --source-path=PATH path of source code [$source_path]"
Index: dyngen-exec.h
===================================================================
RCS file: /cvsroot/qemu/qemu/dyngen-exec.h,v
retrieving revision 1.1
dyngen-exec.h +18 -0
@@ -17,6 +17,9 @@* License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if !defined (__DYNGEN_EXEC_H__) +#define __DYNGEN_EXEC_H__ +typedef unsigned char uint8_t ;typedef unsigned short uint16_t ;typedef unsigned int uint32_t ;
@@ -27,6 +30,19 @@ typedef signed short int16_t;typedef signed int int32_t ;typedef signed long long int64_t ; +# define INT8_MIN (-128) +# define INT16_MIN (-32767-1) +# define INT32_MIN (-2147483647-1) +# define INT64_MIN (-(int64_t)(9223372036854775807)-1) +# define INT8_MAX (127) +# define INT16_MAX (32767) +# define INT32_MAX (2147483647) +# define INT64_MAX ((int64_t)(9223372036854775807)) +# define UINT8_MAX (255) +# define UINT16_MAX (65535) +# define UINT32_MAX (4294967295U) +# define UINT64_MAX ((uint64_t)(18446744073709551615)) +#define bswap32 (x) \ ({ \ uint32_t __x = (x); \
@@ -153,3 +169,5 @@ extern int __op_param1, __op_param2, __o#endif extern int __op_jmp0, __op_jmp1; + +#endif /* !defined (__DYNGEN_EXEC_H__) */
Index: dyngen.c
===================================================================
RCS file: /cvsroot/qemu/qemu/dyngen.c,v
retrieving revision 1.22
dyngen.c +3 -0
@@ -25,6 +25,7 @@#include <unistd.h> #include <fcntl.h> +#define NO_STATIC_THUNK_FUNC #include "config.h" /* elf format definitions. We use these macros to test the CPU to
@@ -456,8 +457,10 @@ void gen_code(const char *name, host_ulo {uint8_t *p; p = (void *)(p_end -4 ); +#if 0 if (p == p_start)error ("empty code for %s" , name); +#endif if (get32 ((uint32_t *)p) !=0x4e800020 )error ("blr expected at the end of %s" , name); copy_size = p - p_start;
Index: exec.c
===================================================================
RCS file: /cvsroot/qemu/qemu/exec.c,v
retrieving revision 1.9
exec.c +7 -0
@@ -26,7 +26,14 @@#include <inttypes.h> #include <sys/mman.h> +#include "config.h" +#if defined (TARGET_I386 )#include "cpu-i386.h" +#elif defined (TARGET_ARM ) +#include "cpu-arm.h" +#elif defined (TARGET_PPC ) +#include "cpu-ppc.h" +#endif #include "exec.h" //#define DEBUG_TB_INVALIDATE
Index: main.c
===================================================================
RCS file: /cvsroot/qemu/qemu/main.c,v
retrieving revision 1.32
main.c +6 -0
@@ -26,7 +26,13 @@#include "qemu.h" +#if defined (TARGET_I386 )#include "cpu-i386.h" +#elif defined (TARGET_ARM ) +#include "cpu-arm.h" +#elif defined (TARGET_PPC ) +#include "cpu-ppc.h" +#endif #define DEBUG_LOGFILE "/tmp/qemu.log"
Index: ppc-dis.c
===================================================================
RCS file: /cvsroot/qemu/qemu/ppc-dis.c,v
retrieving revision 1.1
ppc-dis.c +2 -1
@@ -3074,7 +3074,8 @@ static int print_insn_powerpc(FILE *, unint print_insn_ppc (bfd_vma pc,disassemble_info *info) { -return print_insn_powerpc (info->stream, *(unsigned *)(long )pc, pc, +return print_insn_powerpc (info->stream, + (int )bfd_getb32 ((bfd_byte *)pc), pc,PPC_OPCODE_PPC |PPC_OPCODE_601 ); }
Index: syscall.c
===================================================================
RCS file: /cvsroot/qemu/qemu/syscall.c,v
retrieving revision 1.34
syscall.c +8 -0
@@ -2116,6 +2125,7 @@ long do_syscall(void *cpu_env, int num, }#endif break ; +#ifdef TARGET_NR_getdents64case TARGET_NR_getdents64: {struct dirent64 *dirp = (void *)arg2;
@@ -2139,6 +2149,7 @@ long do_syscall(void *cpu_env, int num, } }break ; +#endif case TARGET_NR__newselect: ret =do_select (arg1, (void *)arg2, (void *)arg3, (void *)arg4, (void *)arg5);
@@ -2456,12 +2467,18 @@ long do_syscall(void *cpu_env, int num,case TARGET_NR_setfsgid32: ret =get_errno (setfsgid (arg1));break ; +#ifdef TARGET_NR_pivot_rootcase TARGET_NR_pivot_root: goto unimplemented; +#endif +#ifdef TARGET_NR_mincorecase TARGET_NR_mincore: goto unimplemented; +#endif +#ifdef TARGET_NR_madvisecase TARGET_NR_madvise: goto unimplemented; +#endif #if TARGET_LONG_BITS ==32 case TARGET_NR_fcntl64: {
Index: thunk.h
===================================================================
RCS file: /cvsroot/qemu/qemu/thunk.h,v
retrieving revision 1.9
thunk.h +2 -0
@@ -239,6 +239,7 @@ const argtype *thunk_convert(void *dst,extern StructEntry struct_entries[]; +#if !defined(NO_STATIC_THUNK_FUNC )static inline int thunk_type_size (const argtype *type_ptr,int is_host) {int type, size;
@@ -311,6 +312,7 @@ static inline int thunk_type_align(const return -1; } } +#endif /* !defined(NO_STATIC_THUNK_FUNC) */ unsigned int target_to_host_bitmask (unsigned int x86_mask,bitmask_transtbl * trans_tbl);
Jocelyn Mayer <[email protected]> wrote:
: Here's a set of patches that fix some target emulation portability : problems in qemu:
When can we expect the PPC target?
Signature · 4 lines
Johan Rydberg, Free Software Developer, Sweden http://rtmk.sf.net | http://www.nongnu.org/guss/ Playing The Supermen Lovers - Superflight
Quoted 6 lines · Johan Rydberg
Jocelyn Mayer <[email protected]> wrote:
: Here's a set of patches that fix some target emulation portability : problems in qemu:
When can we expect the PPC target?
Well I hope in a few days, maybe next week:
I got all basic arithmetic and logical opcodes OK, getting no differences between a real PPC and qemu. But "real" programs like bash still crash after a few thousands of instructions...
I need to do more tests on instructions using immediate values, load/store (especially multiple and strings ones) and it should be quite usable for simple programs using no floats or special stuffs like time synchronisation using tbl/tbu registers.
For now, I'm just trying to emulate a PPC purely based on the 32 bits PPC specification but I will extend it after to emulate real ones. I would also like to emulate 64 bits PPC, for fun...
Signature · 1 line
Jocelyn Mayer <[email protected]>
Quoted 10 lines
Quoted 2 lines
When can we expect the PPC target?
Well I hope in a few days, maybe next week:
I got all basic arithmetic and logical opcodes OK, getting no differences between a real PPC and qemu. But "real" programs like bash still crash after a few thousands of instructions....../...
It would be interesting to work out a way to use the PPC emulation to get the MacOnLinux virtual machine to run on non-PPC hardware :)
That would allow basically to run MacOS 9 and X on any machine...
I know Samuel already did some endian-fixing work for this and is currently mostly lacking the actual CPU emulation.
Ben.
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 9 lines
Quoted 1 line
When can we expect the PPC target?
Well I hope in a few days, maybe next week:
I got all basic arithmetic and logical opcodes OK, getting no differences between a real PPC and qemu. But "real" programs like bash still crash after a few thousands of instructions....../...
It would be interesting to work out a way to use the PPC emulation to get the MacOnLinux virtual machine to run on non-PPC hardware :)
Quoted 7 lines
That would allow basically to run MacOS 9 and X on any machine...
I know Samuel already did some endian-fixing work for this and is currently mostly lacking the actual CPU emulation.
Ben.
Well, that's quite what I'm trying to do.
For now, the only program I can launch is a program I do
that executes a lot of different instructions and dump the processor state before and after the execution, doing this with a lot of different operands. I can do this natively on PPC, in a emulated PPC on my Ibook and also on my PC.
The goal for me is to be able to launch PPC programs including MacOS/MOL on a PC. I would also like to launch OS-X processes under ix86 Linux, without the need of the X kernel... A little help from inside the Linux kernel is needed, but it seems that it can be done (I didn't say easily !).
I already have a few (native) BSD processes running under Linux using 2.4.20/21 kernels.
I'm curious to see the patches you talk about and try them to see if I can execute more programs...
But I noticed that the stack prepared by the Elf loader is really far from the one from a regular Linux kernel. I saw strange issues in this code,
and I'll try to fix some things during the next week-end...
Signature · 1 line
Jocelyn Mayer <[email protected]>
Quoted 6 lines
The goal for me is to be able to launch PPC programs including MacOS/MOL on a PC. I would also like to launch OS-X processes under ix86 Linux, without the need of the X kernel... A little help from inside the Linux kernel is needed, but it seems that it can be done (I didn't say easily !).
I already have a few (native) BSD processes running under Linux using 2.4.20/21 kernels.
As far as MOL is concerned, you don't want to "run it" within qemu/ppc, but rather intergrate the CPU emulation inside of MOL. You can't just "run" MOL like a normal program on PPC, it relies on a kernel module doing the MMU virtualization among others, and you probably want to avoid that when hosted on non-x86. But you'd have to talk to Samuel about that
Launching OS-X processes is another matter. (I mean just launching processes and not the whole operating system within MOL). You have to provide a syscall translation layer, of course, for the BSD-ish, but a _lot_ of OS X apps also rely on some Mach kernel semantics, and a few things like the Windows Server etc... will want to talk to the IOKit via Mach messages. So there is significant work to do to be able to run GUI OS X apps in linux (even on PPC)
Ben.
Quoted 6 lines · Benjamin Herrenschmidt
As far as MOL is concerned, you don't want to "run it" within qemu/ppc, but rather intergrate the CPU emulation inside of MOL. You can't just "run" MOL like a normal program on PPC, it relies on a kernel module doing the MMU virtualization among others, and you probably want to avoid that when hosted on non-x86. But you'd have to talk to Samuel about that
Of course, I meant "when hosted on non-PPC"
Ben.
Hi,
sorry for the long delay...
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines
The goal for me is to be able to launch PPC programs including MacOS/MOL on a PC. I would also like to launch OS-X processes under ix86 Linux, without the need of the X kernel... A little help from inside the Linux kernel is needed, but it seems that it can be done (I didn't say easily !).
I already have a few (native) BSD processes running under Linux using 2.4.20/21 kernels.
Quoted 6 lines
As far as MOL is concerned, you don't want to "run it" within qemu/ppc, but rather intergrate the CPU emulation inside of MOL. You can't just "run" MOL like a normal program on PPC, it relies on a kernel module doing the MMU virtualization among others, and you probably want to avoid that when hosted on non-x86. But you'd have to talk to Samuel about that
You're absolutely right, concerning the fact that the emulation should better be in MOL, but I think that it would be a great thing to be able to run it without patching the host kernel.
Quoted 9 lines
Launching OS-X processes is another matter. (I mean just launching processes and not the whole operating system within MOL). You have to provide a syscall translation layer, of course, for the BSD-ish, but a _lot_ of OS X apps also rely on some Mach kernel semantics, and a few things like the Windows Server etc... will want to talk to the IOKit via Mach messages. So there is significant work to do to be able to run GUI OS X apps in linux (even on PPC)
Ben.
Once again, you're right. I started with BSD things to try to figure out the patches needed in the standard kernel to use personality in standard syscall paths. It's really simpler to do this than trying to emulate Mach and Apple PPC syscalls. I made some tries with a Mach-O loader I wrote and it appeared clearly that all OS-X apps need at least some basics Mach syscall to make dyld able to link the app. So the work to be done seems far to be simple and easy.
For now, I have the syscall diverter, all syscall tables for FreeBSD, NetBSD OpenBSD and Darwin (including Mach syscalls, PPC ones and Darwin "private" ones) and a few BSD syscalls really implemented.
I'll come back with this beautiful idea when I'll get Darwin ls or echo running on my PC :=)
For now, I'm trying to find bugs in my PPC emulation for qemu until I can launch "real" processes and make it available as soon as possible...
Regards.
--
Jocelyn Mayer <[email protected]>