qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Misc patches for qemu
@ 2003-06-24 20:18 Jocelyn Mayer
  2003-06-26 13:58 ` Johan Rydberg
  0 siblings, 1 reply; 8+ messages in thread
From: Jocelyn Mayer @ 2003-06-24 20:18 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1189 bytes --]

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...


-- 
Jocelyn Mayer <jma@netgem.com>

[-- Attachment #2: qemu1.diff --]
[-- Type: text/x-patch, Size: 6790 bytes --]

Index: configure
===================================================================
RCS file: /cvsroot/qemu/qemu/configure,v
retrieving revision 1.14
diff -u -d -w -B -b -d -p -r1.14 configure
--- configure	15 Jun 2003 20:25:43 -0000	1.14
+++ configure	24 Jun 2003 19:19:23 -0000
@@ -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
diff -u -d -w -B -b -d -p -r1.1 dyngen-exec.h
--- dyngen-exec.h	15 Jun 2003 19:46:57 -0000	1.1
+++ dyngen-exec.h	24 Jun 2003 19:19:23 -0000
@@ -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
diff -u -d -w -B -b -d -p -r1.22 dyngen.c
--- dyngen.c	15 Jun 2003 22:50:44 -0000	1.22
+++ dyngen.c	24 Jun 2003 19:19:24 -0000
@@ -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
diff -u -d -w -B -b -d -p -r1.9 exec.c
--- exec.c	24 Jun 2003 13:28:12 -0000	1.9
+++ exec.c	24 Jun 2003 19:19:25 -0000
@@ -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
diff -u -d -w -B -b -d -p -r1.32 main.c
--- main.c	24 Jun 2003 13:30:31 -0000	1.32
+++ main.c	24 Jun 2003 19:19:25 -0000
@@ -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
diff -u -d -w -B -b -d -p -r1.1 ppc-dis.c
--- ppc-dis.c	29 Apr 2003 20:38:27 -0000	1.1
+++ ppc-dis.c	24 Jun 2003 19:19:28 -0000
@@ -3074,7 +3074,8 @@ static int print_insn_powerpc(FILE *, un
 
 int 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
diff -u -d -w -B -b -d -p -r1.34 syscall.c
--- syscall.c	15 Jun 2003 19:56:46 -0000	1.34
+++ syscall.c	24 Jun 2003 19:19:31 -0000
@@ -2116,6 +2125,7 @@ long do_syscall(void *cpu_env, int num, 
         }
 #endif
         break;
+#ifdef TARGET_NR_getdents64
     case 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_root
     case TARGET_NR_pivot_root:
         goto unimplemented;
+#endif
+#ifdef TARGET_NR_mincore
     case TARGET_NR_mincore:
         goto unimplemented;
+#endif
+#ifdef TARGET_NR_madvise
     case 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
diff -u -d -w -B -b -d -p -r1.9 thunk.h
--- thunk.h	15 Jun 2003 19:52:54 -0000	1.9
+++ thunk.h	24 Jun 2003 19:19:32 -0000
@@ -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);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] Misc patches for qemu
  2003-06-24 20:18 [Qemu-devel] Misc patches for qemu Jocelyn Mayer
@ 2003-06-26 13:58 ` Johan Rydberg
  2003-06-26 20:38   ` Jocelyn Mayer
  0 siblings, 1 reply; 8+ messages in thread
From: Johan Rydberg @ 2003-06-26 13:58 UTC (permalink / raw)
  To: qemu-devel

Jocelyn Mayer <jma@netgem.com> wrote:

: Here's a set of patches that fix some target emulation portability
: problems in qemu:

When can we expect the PPC target? 

-- 
Johan Rydberg, Free Software Developer, Sweden
http://rtmk.sf.net | http://www.nongnu.org/guss/

Playing The Supermen Lovers - Superflight

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] Misc patches for qemu
  2003-06-26 13:58 ` Johan Rydberg
@ 2003-06-26 20:38   ` Jocelyn Mayer
  2003-06-27  8:18     ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 8+ messages in thread
From: Jocelyn Mayer @ 2003-06-26 20:38 UTC (permalink / raw)
  To: qemu mailing list

On Thu, 2003-06-26 at 15:58, Johan Rydberg wrote:
> Jocelyn Mayer <jma@netgem.com> 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...

-- 
Jocelyn Mayer <jma@netgem.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] Misc patches for qemu
  2003-06-26 20:38   ` Jocelyn Mayer
@ 2003-06-27  8:18     ` Benjamin Herrenschmidt
  2003-06-27 13:55       ` Jocelyn Mayer
  0 siblings, 1 reply; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2003-06-27  8:18 UTC (permalink / raw)
  To: qemu-devel


> > 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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] Misc patches for qemu
  2003-06-27  8:18     ` Benjamin Herrenschmidt
@ 2003-06-27 13:55       ` Jocelyn Mayer
  2003-06-27 15:29         ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 8+ messages in thread
From: Jocelyn Mayer @ 2003-06-27 13:55 UTC (permalink / raw)
  To: qemu mailing list

On Fri, 2003-06-27 at 10:18, Benjamin Herrenschmidt wrote:
> > > 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.
> 

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...


-- 
Jocelyn Mayer <jma@netgem.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] Misc patches for qemu
  2003-06-27 13:55       ` Jocelyn Mayer
@ 2003-06-27 15:29         ` Benjamin Herrenschmidt
  2003-06-27 15:49           ` Benjamin Herrenschmidt
  2003-06-30 22:41           ` Jocelyn Mayer
  0 siblings, 2 replies; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2003-06-27 15:29 UTC (permalink / raw)
  To: qemu-devel


> 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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] Misc patches for qemu
  2003-06-27 15:29         ` Benjamin Herrenschmidt
@ 2003-06-27 15:49           ` Benjamin Herrenschmidt
  2003-06-30 22:41           ` Jocelyn Mayer
  1 sibling, 0 replies; 8+ messages in thread
From: Benjamin Herrenschmidt @ 2003-06-27 15:49 UTC (permalink / raw)
  To: qemu-devel

On Fri, 2003-06-27 at 17:29, Benjamin Herrenschmidt wrote:
> 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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] Misc patches for qemu
  2003-06-27 15:29         ` Benjamin Herrenschmidt
  2003-06-27 15:49           ` Benjamin Herrenschmidt
@ 2003-06-30 22:41           ` Jocelyn Mayer
  1 sibling, 0 replies; 8+ messages in thread
From: Jocelyn Mayer @ 2003-06-30 22:41 UTC (permalink / raw)
  To: qemu mailing list

Hi,

sorry for the long delay...

On Fri, 2003-06-27 at 17:29, Benjamin Herrenschmidt wrote: 
> > 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

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.


> 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 <jma@netgem.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-06-30 22:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-24 20:18 [Qemu-devel] Misc patches for qemu Jocelyn Mayer
2003-06-26 13:58 ` Johan Rydberg
2003-06-26 20:38   ` Jocelyn Mayer
2003-06-27  8:18     ` Benjamin Herrenschmidt
2003-06-27 13:55       ` Jocelyn Mayer
2003-06-27 15:29         ` Benjamin Herrenschmidt
2003-06-27 15:49           ` Benjamin Herrenschmidt
2003-06-30 22:41           ` Jocelyn Mayer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).