Skip to contentSkip to conversation

qemu Makefile.target cpu-all.h cpu-exec.c dynge...

Qemu-devel New Thiemo Seufer 3 participants 7 messages May 5, 2007 – Jul 31, 2007 Kbuild

lore
Share & tools
lore
#0 lore raw
#1 lore raw

Hello Thiemo,

here is a (partially crude) patch which mixes your code with my own MIPS host extension and code parts from a MIPS host made by Johannes E. Schindelin 2 years ago.

Using this new code I was able to start a Linux kernel using qemu-system-mipsel running in an emulated MALTA machine.

I could also start a simple i386 application (/bin/echo) with qemu-i386 (until it failed with the usual libc / tls problems).

When I started to write MIPS host, I found it difficult to get all locations which needed new code. To make it easier for new ports, I changed sequences of #if ... #endif, #if ... #endif into #if ... #elif ... #elif ... #else #error #endif.

Other changes include some smaller spelling corrections.

Most important was Johannes code for testandset and PARAMn.

The patch still includes your relocation code, but it is disabled and uses my own code. I had no time to check or try the differences.

Fabrice, could you please update the status web page and add "experimental MIPS host support" (otherwise still more people might start to re-invent the code) :-).

Stefan

Quoted 10 lines · Thiemo Seufer

CVSROOT: /sources/qemu
Module name: qemu
Changes by: Thiemo Seufer <ths> 07/05/05 19:23:11

Modified files:
. : Makefile.target cpu-all.h cpu-exec.c
dyngen-exec.h dyngen.c dyngen.h exec-all.h

Log message:
Some bits of Linux/MIPS host support, still segfaulty.

cpu-all.h +2 -1
diff --rec -u -x .svn -x CVS head/cpu-all.h mipshost/cpu-all.h
@@ -1045,8 +1045,9 @@
 
 #else
 /* The host CPU doesn't have an easily accessible cycle counter.
-   Just return a monotonically increasing vlue.  This will be totally wrong,
+   Just return a monotonically increasing value.  This will be totally wrong,
    but hopefully better than nothing.  */
+#warning host without cycle counter
 static inline int64_t cpu_get_real_ticks (void)
 {
     static int64_t ticks = 0;
dyngen.c +92 -29

164 lines not on this page · raw message

dyngen-exec.h +40 -40

166 lines not on this page · raw message

dyngen.h +25 -29

139 lines not on this page · raw message

exec-all.h +23 -42

130 lines not on this page · raw message

#2 lore raw

For Linux usermode emulation, this patch was missing.

Stefan

cpu-exec.c (Arbeitskopie) renamed from cpu-exec.c (Revision 656) +2 -1
Index: cpu-exec.c
===================================================================
@@ -1545,9 +1545,10 @@
 
 #elif defined(__mips__)
 
-int cpu_signal_handler(int host_signum, struct siginfo *info,
+int cpu_signal_handler(int host_signum, void *pinfo,
                        void *puc)
 {
+    struct siginfo *info = (struct siginfo *)pinfo;
     struct ucontext *uc = puc;
     greg_t pc = uc->uc_mcontext.pc;
     int is_write;
#3 lore raw
In reply to Stefan Weil

Hi Stefan,

Quoted 3 lines · Stefan Weil

here is a (partially crude) patch which mixes your code with my own MIPS host extension and code parts from a MIPS host made by Johannes E. Schindelin 2 years ago.

Hey, that's cool! I did not have the motivation/time/machines to pick up on that port...

Ciao,
Dscho

#4 lore raw
In reply to Stefan Weil

Stefan Weil wrote:
[snip]

I cherrypicked the easy bits, and will look at the rest when I have more time.

Quoted 4 lines

When I started to write MIPS host, I found it difficult to get all locations which needed new code. To make it easier for new ports, I changed sequences of #if ... #endif, #if ... #endif into #if ... #elif ... #elif ... #else #error #endif.

Some of those folded unrelated things together, I committed a different patch based on yours.

Quoted 1 line

Other changes include some smaller spelling corrections.

Also committed.

Quoted 1 line

Most important was Johannes code for testandset and PARAMn.

AFAICS that testandset implementation is broken, and I think mine is correct, maybe except for the +R vs. +m bit in the asm constraints.

Did my implementation fail for you?

Quoted 2 lines

The patch still includes your relocation code, but it is disabled and uses my own code. I had no time to check or try the differences.

Then I gather there's no particular reason why my _PC16 reloc code is deleted in the patch.

Thiemo

#5 lore raw

PATCH 1/1 QEMU Mips Host

Some parts for a working mips host are still missing in QEMU CVS HEAD.

Here is a new patch which makes mips host work for system emulation.

I tested it with i386-softmmu/qemu, mips-softmmu/qemu-system-mips and mipsel-softmmu/qemu-system-mipsel running on
an emulated malta (big and little endian, 32 bit) machine.

I could not test it with 64 bit mips host.

User mode emulation does not work (it does not work with i386 host, too).

These parts of my patch are essential to get a working emulation:

Makefile.target:
compiler flags for mips op.o

dyngen-exec.h:
declarations for PARAM1, PARAM2 and PARAM3
declaration for GOTO_LABEL_PARAM

dyngen.c:
fixes for gen_code() and relocation code

dyngen.h:
exec-all.h:
I'm not sure whether these changes are needed. At least it works with the changes...

Stefan

Quoted 17 lines · Thiemo Seufer

Stefan Weil wrote:
[snip]

I cherrypicked the easy bits, and will look at the rest when I have more time.

Quoted 4 lines

When I started to write MIPS host, I found it difficult to get all locations which needed new code. To make it easier for new ports, I changed sequences of #if ... #endif, #if ... #endif into #if ... #elif ... #elif ... #else #error #endif.

Some of those folded unrelated things together, I committed a different patch based on yours.

Quoted 1 line

Most important was Johannes code for testandset and PARAMn.

AFAICS that testandset implementation is broken, and I think mine is correct, maybe except for the +R vs. +m bit in the asm constraints.

Quoted 8 lines

Did my implementation fail for you?

Quoted 2 lines

The patch still includes your relocation code, but it is disabled and uses my own code. I had no time to check or try the differences.

Then I gather there's no particular reason why my _PC16 reloc code is deleted in the patch.

Thiemo

Index: Makefile.target
===================================================================
RCS file: /sources/qemu/qemu/Makefile.target,v
retrieving revision 1.189

Makefile.target +1 -1
diff -u -b -B -r1.189 Makefile.target
@@ -181,7 +185,7 @@
 endif
 
 ifeq ($(ARCH),mips)
-OP_CFLAGS+=-mabi=32 -G0 -fno-PIC -mno-abicalls -fomit-frame-pointer -fno-delayed-branch -Wa,-O0
+OP_CFLAGS += -G 0 -fomit-frame-pointer -fno-delayed-branch
 ifeq ($(WORDS_BIGENDIAN),yes)
 BASE_LDFLAGS+=-Wl,-T,$(SRC_PATH)/$(ARCH).ld
 else

Index: dyngen-exec.h
===================================================================
RCS file: /sources/qemu/qemu/dyngen-exec.h,v
retrieving revision 1.36

dyngen-exec.h +14 -1
diff -u -b -B -r1.36 dyngen-exec.h
@@ -224,6 +224,16 @@
 #define PARAM1 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param1)); _r; })
 #define PARAM2 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param2)); _r; })
 #define PARAM3 ({ int _r; asm("" : "=r"(_r) : "0" (&__op_param3)); _r; })
+#elif defined(__mips__)
+/* On MIPS, parameters to a c expression are passed via the global pointer.
+ * We don't want that. */
+#define PARAMN(index) ({ register int _r; \
+                asm("lui %0,%%hi(__op_param" #index ")\n\t" \
+                        "ori %0,%0,%%lo(__op_param" #index ")" \
+                        : "=r"(_r)); _r; })
+#define PARAM1 PARAMN(1)
+#define PARAM2 PARAMN(2)
+#define PARAM3 PARAMN(3)
 #else
 #if defined(__APPLE__)
 static int __op_param1, __op_param2, __op_param3;
@@ -271,7 +281,10 @@
 #define EXIT_TB() asm volatile ("rts")
 #elif defined(__mips__)
 #define EXIT_TB() asm volatile ("jr $ra")
-#define GOTO_LABEL_PARAM(n) asm volatile (".set noat; la $1, " ASM_NAME(__op_gen_label) #n "; jr $1; .set at")
+#define GOTO_LABEL_PARAM(n) asm volatile (\
+    "lui $2,%hi(" ASM_NAME(__op_gen_label) #n ")\n\t" \
+    "ori $2,$2,%lo(" ASM_NAME(__op_gen_label)#n ")\n\t" \
+    "jr $2")
 #else
 #error unsupported CPU
 #endif

Index: dyngen.c
===================================================================
RCS file: /sources/qemu/qemu/dyngen.c,v
retrieving revision 1.54

dyngen.c +40 -27

109 lines not on this page · raw message

Index: dyngen.h
===================================================================
RCS file: /sources/qemu/qemu/dyngen.h,v
retrieving revision 1.15

dyngen.h +1 -1
diff -u -b -B -r1.15 dyngen.h
@@ -19,7 +19,7 @@
  */
 
 int __op_param1, __op_param2, __op_param3;
-#if defined(__sparc__) || defined(__arm__)
+#if defined(__sparc__) || defined(__arm__) || defined(__mips__)
   void __op_gen_label1(){}
   void __op_gen_label2(){}
   void __op_gen_label3(){}

Index: exec-all.h
===================================================================
RCS file: /sources/qemu/qemu/exec-all.h,v
retrieving revision 1.58

exec-all.h +15 -0
diff -u -b -B -r1.58 exec-all.h
@@ -472,6 +472,20 @@
 {
     int ret;
 
+#if 1
+    __asm__ __volatile__(
+            ".set push\n"
+            ".set mips2\n"
+            "ll %0,%1\n"
+            ".set noreorder\n"
+            "bnez %0,1f\n"
+            "li %0,0\n" /* branch delay slot */
+            "li %0,1\n"
+            "sc %0,%1\n"
+            "1:\n"
+            ".set pop\n"
+            : "=r" (ret), "=m" (*p));
+#else
     __asm__ __volatile__ (
 	"	.set push		\n"
 	"	.set noat		\n"
@@ -484,6 +498,7 @@
 	: "=r" (ret), "+R" (*p)
 	:
 	: "memory");
+#endif
 
     return ret;
 }
#6 lore raw
In reply to Stefan Weil
Quoted 8 lines · Stefan Weil

Hello Thiemo,

here is a (partially crude) patch which mixes your code with my own MIPS host extension and code parts from a MIPS host made by Johannes E. Schindelin 2 years ago.

Using this new code I was able to start a Linux kernel using qemu-system-mipsel running in an emulated MALTA machine.

I fails to build for me (on a Broadcom SWARM running Debian unstable):

[...]
gcc-3.4 -Wall -O2 -g -fno-strict-aliasing -fno-reorder-blocks -fno-gcse -fno-optimize-sibling-calls -fno-crossjumping -fno-align-labels -fno-align-jumps -fno-align-functions -mabi=32 -G0 -fno-PIC -mno-abicalls -fomit-frame-pointer -fno-delayed-branch -Wa,-O0 -I. -I.. -I/srv/ths/qemu/qemu-upstream/target-mips -I/srv/ths/qemu/qemu-upstream -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I/srv/ths/qemu/qemu-upstream/fpu -DHAS_AUDIO -I/srv/ths/qemu/qemu-upstream/slirp -c -o op.o /srv/ths/qemu/qemu-upstream/target-mips/op.c
../dyngen -o op.h op.o
dyngen: empty code for op_store_T0_gpr_gpr1
make[1]: *** [op.h] Error 1
make[1]: Leaving directory `/srv/ths/qemu/qemu-upstream/mips-softmmu'
make: *** [subdir-mips-softmmu] Error 2

Thiemo