aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2006-12-14 14:48:11 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2006-12-14 14:48:11 +0000
commite4630047e161ac1b23bfd37b2c52785fce49400a (patch)
tree9a9ced3ffc77a7149a4c4565b3217609ab4b1b1f /tests
parent73e14b623fc960385f60f3eed06583c27fb5d9df (diff)
downloadqemu-e4630047e161ac1b23bfd37b2c52785fce49400a.zip
qemu-e4630047e161ac1b23bfd37b2c52785fce49400a.tar.gz
qemu-e4630047e161ac1b23bfd37b2c52785fce49400a.tar.bz2
Simple test for mips/mipsel, based on a test by Alexander Voropay.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2246 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile7
-rw-r--r--tests/hello-mips.c64
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/Makefile b/tests/Makefile
index d7abae6..f803f6a 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -82,6 +82,13 @@ hello-arm: hello-arm.o
hello-arm.o: hello-arm.c
arm-linux-gcc -Wall -g -O2 -c -o $@ $<
+# MIPS test
+hello-mips: hello-mips.c
+ mips-linux-gnu-gcc -nostdlib -static -mno-abicalls -fno-PIC -mabi=32 -Wall -Wextra -g -O2 -o $@ $<
+
+hello-mipsel: hello-mips.c
+ mipsel-linux-gnu-gcc -nostdlib -static -mno-abicalls -fno-PIC -mabi=32 -Wall -Wextra -g -O2 -o $@ $<
+
# XXX: find a way to compile easily a test for each arch
test2:
@for arch in i386 arm armeb sparc ppc mips mipsel; do \
diff --git a/tests/hello-mips.c b/tests/hello-mips.c
new file mode 100644
index 0000000..f825673
--- /dev/null
+++ b/tests/hello-mips.c
@@ -0,0 +1,64 @@
+/*
+* MIPS o32 Linux syscall example
+*
+* http://www.linux-mips.org/wiki/RISC/os
+* http://www.linux-mips.org/wiki/MIPSABIHistory
+* http://www.linux.com/howtos/Assembly-HOWTO/mips.shtml
+*
+* mipsel-linux-gcc -nostdlib -mno-abicalls -fno-PIC -mabi=32 \
+* -O2 -static -o hello-mips hello-mips.c
+*
+*/
+#define __NR_SYSCALL_BASE 4000
+#define __NR_exit (__NR_SYSCALL_BASE+ 1)
+#define __NR_write (__NR_SYSCALL_BASE+ 4)
+
+static inline void exit1(int status)
+{
+ register unsigned long __a0 asm("$4") = (unsigned long) status;
+
+ __asm__ __volatile__ (
+ " .set push \n"
+ " .set noreorder \n"
+ " li $2, %0 \n"
+ " syscall \n"
+ " .set pop "
+ :
+ : "i" (__NR_exit), "r" (__a0)
+ : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
+ "memory");
+}
+
+static inline int write(int fd, const char *buf, int len)
+{
+ register unsigned long __a0 asm("$4") = (unsigned long) fd;
+ register unsigned long __a1 asm("$5") = (unsigned long) buf;
+ register unsigned long __a2 asm("$6") = (unsigned long) len;
+ register unsigned long __a3 asm("$7");
+ unsigned long __v0;
+
+ __asm__ __volatile__ (
+ " .set push \n"
+ " .set noreorder \n"
+ " li $2, %2 \n"
+ " syscall \n"
+ " move %0, $2 \n"
+ " .set pop "
+ : "=r" (__v0), "=r" (__a3)
+ : "i" (__NR_write), "r" (__a0), "r" (__a1), "r" (__a2)
+ : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
+ "memory");
+
+/* if (__a3 == 0) */
+ return (int) __v0;
+/*
+ errno = __v0;
+ return -1;
+ */
+}
+
+void __start(void)
+{
+ write (1, "Hello, World!\n", 14);
+ exit1 (42);
+}