Commit e4630047e161ac1b23bfd37b2c52785fce49400a

Authored by ths
1 parent 73e14b62

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
tests/Makefile
... ... @@ -82,6 +82,13 @@ hello-arm: hello-arm.o
82 82 hello-arm.o: hello-arm.c
83 83 arm-linux-gcc -Wall -g -O2 -c -o $@ $<
84 84  
  85 +# MIPS test
  86 +hello-mips: hello-mips.c
  87 + mips-linux-gnu-gcc -nostdlib -static -mno-abicalls -fno-PIC -mabi=32 -Wall -Wextra -g -O2 -o $@ $<
  88 +
  89 +hello-mipsel: hello-mips.c
  90 + mipsel-linux-gnu-gcc -nostdlib -static -mno-abicalls -fno-PIC -mabi=32 -Wall -Wextra -g -O2 -o $@ $<
  91 +
85 92 # XXX: find a way to compile easily a test for each arch
86 93 test2:
87 94 @for arch in i386 arm armeb sparc ppc mips mipsel; do \
... ...
tests/hello-mips.c 0 → 100644
  1 +/*
  2 +* MIPS o32 Linux syscall example
  3 +*
  4 +* http://www.linux-mips.org/wiki/RISC/os
  5 +* http://www.linux-mips.org/wiki/MIPSABIHistory
  6 +* http://www.linux.com/howtos/Assembly-HOWTO/mips.shtml
  7 +*
  8 +* mipsel-linux-gcc -nostdlib -mno-abicalls -fno-PIC -mabi=32 \
  9 +* -O2 -static -o hello-mips hello-mips.c
  10 +*
  11 +*/
  12 +#define __NR_SYSCALL_BASE 4000
  13 +#define __NR_exit (__NR_SYSCALL_BASE+ 1)
  14 +#define __NR_write (__NR_SYSCALL_BASE+ 4)
  15 +
  16 +static inline void exit1(int status)
  17 +{
  18 + register unsigned long __a0 asm("$4") = (unsigned long) status;
  19 +
  20 + __asm__ __volatile__ (
  21 + " .set push \n"
  22 + " .set noreorder \n"
  23 + " li $2, %0 \n"
  24 + " syscall \n"
  25 + " .set pop "
  26 + :
  27 + : "i" (__NR_exit), "r" (__a0)
  28 + : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
  29 + "memory");
  30 +}
  31 +
  32 +static inline int write(int fd, const char *buf, int len)
  33 +{
  34 + register unsigned long __a0 asm("$4") = (unsigned long) fd;
  35 + register unsigned long __a1 asm("$5") = (unsigned long) buf;
  36 + register unsigned long __a2 asm("$6") = (unsigned long) len;
  37 + register unsigned long __a3 asm("$7");
  38 + unsigned long __v0;
  39 +
  40 + __asm__ __volatile__ (
  41 + " .set push \n"
  42 + " .set noreorder \n"
  43 + " li $2, %2 \n"
  44 + " syscall \n"
  45 + " move %0, $2 \n"
  46 + " .set pop "
  47 + : "=r" (__v0), "=r" (__a3)
  48 + : "i" (__NR_write), "r" (__a0), "r" (__a1), "r" (__a2)
  49 + : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24",
  50 + "memory");
  51 +
  52 +/* if (__a3 == 0) */
  53 + return (int) __v0;
  54 +/*
  55 + errno = __v0;
  56 + return -1;
  57 + */
  58 +}
  59 +
  60 +void __start(void)
  61 +{
  62 + write (1, "Hello, World!\n", 14);
  63 + exit1 (42);
  64 +}
... ...