1 /* 2 * Helper functions for CRIS system tests 3 * 4 * There is no libc and only a limited set of headers. 5 */ 6 7 #include <stddef.h> 8 9 void exit(int status) 10 { 11 register unsigned int callno asm ("r9") = 1; /* NR_exit */ 12 13 asm volatile ("break 13\n" 14 : /* no outputs */ 15 : "r" (callno) 16 : "memory"); 17 while (1) { 18 /* do nothing */ 19 }; 20 } 21 22 size_t write(int fd, const void *buf, size_t count) 23 { 24 register unsigned int callno asm ("r9") = 4; /* NR_write */ 25 register unsigned int r10 asm ("r10") = fd; 26 register const void *r11 asm ("r11") = buf; 27 register size_t r12 asm ("r12") = count; 28 register unsigned int r asm ("r10"); 29 30 asm volatile ("break 13\n" 31 : "=r" (r) 32 : "r" (callno), "0" (r10), "r" (r11), "r" (r12) 33 : "memory"); 34 35 return r; 36 } 37 38 static inline int mystrlen(char *s) 39 { 40 int i = 0; 41 while (s[i]) { 42 i++; 43 } 44 return i; 45 } 46 47 48 void pass(void) 49 { 50 char s[] = "passed.\n"; 51 write(1, s, sizeof(s) - 1); 52 exit(0); 53 } 54 55 void _fail(char *reason) 56 { 57 char s[] = "\nfailed: "; 58 int len = mystrlen(reason); 59 write(1, s, sizeof(s) - 1); 60 write(1, reason, len); 61 write(1, "\n", 1); 62 exit(1); 63 } 64