Blob


1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <sys/mman.h>
4 #include <stdbool.h>
5 #include <unistd.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <fcntl.h>
9 #include <stdio.h>
10 #include <err.h>
12 __attribute__((always_inline))
13 inline static void ebreak (void)
14 {
15 __asm __volatile__ ("ebreak");
16 }
18 __attribute__((always_inline))
19 inline static void *sys_brk (void *ptr)
20 {
21 register void *a0 asm ("a0") = ptr;
22 register int a7 asm ("a7") = 214;
23 __asm __volatile__ ("ecall" : "=r"(a0) : "r"(a0), "r"(a7));
24 return a0;
25 }
27 unsigned mul(unsigned a, unsigned b)
28 {
29 return a / b;
30 }
32 int main (int argc, char *argv[]) {
33 FILE *in, *out;
34 int ch, *ptr;
36 ptr = malloc (4);
37 *ptr = 1;
38 free (ptr);
40 in = fopen ("/test.txt", "r");
41 if (in == NULL)
42 err (1, "open('test.txt')");
44 out = fopen ("/output.txt", "w");
45 if (out == NULL)
46 err (1, "open('output.txt')");
48 while ((ch = fgetc (in)) != EOF)
49 fputc (ch, out);
51 fclose (out);
52 fclose (in);
54 in = fopen ("/output.txt", "r");
55 if (in == NULL)
56 err (1, "reopen('output.txt')");
58 while ((ch = fgetc (in)) != EOF)
59 putchar (ch);
61 fclose (in);
63 printf ("Result: %u\n", mul (3, 2));
65 execlp ("ksh", "ksh", NULL);
67 return 0;
68 }