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