1e4630047Sths /* 2e4630047Sths * MIPS o32 Linux syscall example 3e4630047Sths * 4e4630047Sths * http://www.linux-mips.org/wiki/RISC/os 5e4630047Sths * http://www.linux-mips.org/wiki/MIPSABIHistory 6e4630047Sths * http://www.linux.com/howtos/Assembly-HOWTO/mips.shtml 7e4630047Sths * 8e4630047Sths * mipsel-linux-gcc -nostdlib -mno-abicalls -fno-PIC -mabi=32 \ 9e4630047Sths * -O2 -static -o hello-mips hello-mips.c 10e4630047Sths * 11e4630047Sths */ 12e4630047Sths #define __NR_SYSCALL_BASE 4000 13e4630047Sths #define __NR_exit (__NR_SYSCALL_BASE+ 1) 14e4630047Sths #define __NR_write (__NR_SYSCALL_BASE+ 4) 15e4630047Sths 16e4630047Sths static inline void exit1(int status) 17e4630047Sths { 18e4630047Sths register unsigned long __a0 asm("$4") = (unsigned long) status; 19e4630047Sths 20e4630047Sths __asm__ __volatile__ ( 21e4630047Sths " .set push \n" 22e4630047Sths " .set noreorder \n" 23e4630047Sths " li $2, %0 \n" 24e4630047Sths " syscall \n" 25e4630047Sths " .set pop " 26e4630047Sths : 27e4630047Sths : "i" (__NR_exit), "r" (__a0) 28e4630047Sths : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", 29e4630047Sths "memory"); 30e4630047Sths } 31e4630047Sths 32e4630047Sths static inline int write(int fd, const char *buf, int len) 33e4630047Sths { 34e4630047Sths register unsigned long __a0 asm("$4") = (unsigned long) fd; 35e4630047Sths register unsigned long __a1 asm("$5") = (unsigned long) buf; 36e4630047Sths register unsigned long __a2 asm("$6") = (unsigned long) len; 37e4630047Sths register unsigned long __a3 asm("$7"); 38e4630047Sths unsigned long __v0; 39e4630047Sths 40e4630047Sths __asm__ __volatile__ ( 41e4630047Sths " .set push \n" 42e4630047Sths " .set noreorder \n" 43e4630047Sths " li $2, %2 \n" 44e4630047Sths " syscall \n" 45e4630047Sths " move %0, $2 \n" 46e4630047Sths " .set pop " 47e4630047Sths : "=r" (__v0), "=r" (__a3) 48e4630047Sths : "i" (__NR_write), "r" (__a0), "r" (__a1), "r" (__a2) 49e4630047Sths : "$2", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", 50e4630047Sths "memory"); 51e4630047Sths 52e4630047Sths /* if (__a3 == 0) */ 53e4630047Sths return (int) __v0; 54e4630047Sths /* 55e4630047Sths errno = __v0; 56e4630047Sths return -1; 57e4630047Sths */ 58e4630047Sths } 59e4630047Sths 60e4630047Sths void __start(void) 61e4630047Sths { 62e4630047Sths write (1, "Hello, World!\n", 14); 63*b4f39615SAlex Bennée exit1(0); 64e4630047Sths } 65