root / tests / tcg / cris / sys.c @ c09015dd
History | View | Annotate | Download (939 Bytes)
1 | dd43edf4 | ths | #include <stdio.h> |
---|---|---|---|
2 | dd43edf4 | ths | #include <stdlib.h> |
3 | dd43edf4 | ths | #include <unistd.h> |
4 | dd43edf4 | ths | |
5 | dd43edf4 | ths | static inline int mystrlen(char *s) { |
6 | dd43edf4 | ths | int i = 0; |
7 | dd43edf4 | ths | while (s[i])
|
8 | dd43edf4 | ths | i++; |
9 | dd43edf4 | ths | return i;
|
10 | dd43edf4 | ths | } |
11 | dd43edf4 | ths | |
12 | dd43edf4 | ths | void pass(void) { |
13 | dd43edf4 | ths | char s[] = "passed.\n"; |
14 | dd43edf4 | ths | write (1, s, sizeof (s) - 1); |
15 | dd43edf4 | ths | exit (0);
|
16 | dd43edf4 | ths | } |
17 | dd43edf4 | ths | |
18 | dd43edf4 | ths | void _fail(char *reason) { |
19 | 31328119 | edgar_igl | char s[] = "\nfailed: "; |
20 | dd43edf4 | ths | int len = mystrlen(reason);
|
21 | dd43edf4 | ths | write (1, s, sizeof (s) - 1); |
22 | dd43edf4 | ths | write (1, reason, len);
|
23 | dd43edf4 | ths | write (1, "\n", 1); |
24 | dd43edf4 | ths | // exit (1);
|
25 | dd43edf4 | ths | } |
26 | dd43edf4 | ths | |
27 | dd43edf4 | ths | void *memset (void *s, int c, size_t n) { |
28 | dd43edf4 | ths | char *p = s;
|
29 | dd43edf4 | ths | int i;
|
30 | dd43edf4 | ths | for (i = 0; i < n; i++) |
31 | dd43edf4 | ths | p[i] = c; |
32 | dd43edf4 | ths | return p;
|
33 | dd43edf4 | ths | } |
34 | dd43edf4 | ths | |
35 | dd43edf4 | ths | void exit (int status) { |
36 | dd43edf4 | ths | asm volatile ("moveq 1, $r9\n" /* NR_exit. */ |
37 | dd43edf4 | ths | "break 13\n");
|
38 | dd43edf4 | ths | while(1) |
39 | dd43edf4 | ths | ; |
40 | dd43edf4 | ths | } |
41 | dd43edf4 | ths | |
42 | dd43edf4 | ths | ssize_t write (int fd, const void *buf, size_t count) { |
43 | dd43edf4 | ths | int r;
|
44 | 31328119 | edgar_igl | asm ("move.d %0, $r10\n" |
45 | 31328119 | edgar_igl | "move.d %1, $r11\n"
|
46 | 31328119 | edgar_igl | "move.d %2, $r12\n"
|
47 | 31328119 | edgar_igl | "moveq 4, $r9\n" /* NR_write. */ |
48 | 31328119 | edgar_igl | "break 13\n" : : "r" (fd), "r" (buf), "r" (count) : "memory"); |
49 | 31328119 | edgar_igl | asm ("move.d $r10, %0\n" : "=r" (r)); |
50 | dd43edf4 | ths | return r;
|
51 | dd43edf4 | ths | } |