Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / cris / bare / sys.c
blob1644eecc3346300ed81938d0492fffad059f3611
1 /*
2 * Helper functions for CRIS system tests
4 * There is no libc and only a limited set of headers.
5 */
7 #include <stddef.h>
9 void exit(int status)
11 register unsigned int callno asm ("r9") = 1; /* NR_exit */
13 asm volatile ("break 13\n"
14 : /* no outputs */
15 : "r" (callno)
16 : "memory");
17 while (1) {
18 /* do nothing */
22 size_t write(int fd, const void *buf, size_t count)
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");
30 asm volatile ("break 13\n"
31 : "=r" (r)
32 : "r" (callno), "0" (r10), "r" (r11), "r" (r12)
33 : "memory");
35 return r;
38 static inline int mystrlen(char *s)
40 int i = 0;
41 while (s[i]) {
42 i++;
44 return i;
48 void pass(void)
50 char s[] = "passed.\n";
51 write(1, s, sizeof(s) - 1);
52 exit(0);
55 void _fail(char *reason)
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);