Statistics
| Branch: | Revision:

root / tests / tcg / cris / sys.c @ c09015dd

History | View | Annotate | Download (939 Bytes)

1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <unistd.h>
4

    
5
static inline int mystrlen(char *s) {
6
        int i = 0;
7
        while (s[i])
8
                i++;
9
        return i;
10
}
11

    
12
void pass(void) {
13
        char s[] = "passed.\n";
14
        write (1, s, sizeof (s) - 1);
15
        exit (0);
16
}
17

    
18
void _fail(char *reason) {
19
        char s[] = "\nfailed: ";
20
        int len = mystrlen(reason);
21
        write (1, s, sizeof (s) - 1);
22
        write (1, reason, len);
23
        write (1, "\n", 1);
24
//        exit (1);
25
}
26

    
27
void *memset (void *s, int c, size_t n) {
28
        char *p = s;
29
        int i;
30
        for (i = 0; i < n; i++)
31
                p[i] = c;
32
        return p;
33
}
34

    
35
void exit (int status) {
36
        asm volatile ("moveq 1, $r9\n" /* NR_exit.  */
37
                      "break 13\n");
38
        while(1)
39
                ;
40
}
41

    
42
ssize_t write (int fd, const void *buf, size_t count) {
43
        int r;
44
        asm ("move.d %0, $r10\n"
45
             "move.d %1, $r11\n"
46
             "move.d %2, $r12\n"
47
             "moveq 4, $r9\n" /* NR_write.  */
48
             "break 13\n" : : "r" (fd), "r" (buf), "r" (count) : "memory");
49
        asm ("move.d $r10, %0\n" : "=r" (r));
50
        return r;
51
}