blob: fff1a16e3fe2933d4b997c3870d135083e6d63ba [file] [log] [blame]
Eric Biederman90089602004-05-28 14:11:54 +00001struct syscall_result {
2 long val;
3 int errno;
4};
5
6static struct syscall_result syscall_return(long result)
7{
8 struct syscall_result res;
9 if (((unsigned long)result) >= ((unsigned long)-125)) {
10 res.errno = - result;
11 res.val = -1;
12 } else {
13 res.errno = 0;
14 res.val = result;
15 }
16 return res;
17}
18
19static struct syscall_result syscall1(unsigned long nr, unsigned long arg1)
20{
21 long res;
22 asm volatile(
23 "int $0x80"
24 : "=a" (res)
25 : "a" (nr), "b" (arg1));
26 return syscall_return(res);
Stefan Reinauer14e22772010-04-27 06:56:47 +000027
Eric Biederman90089602004-05-28 14:11:54 +000028}
29
30
31static struct syscall_result syscall3(unsigned long nr, unsigned long arg1, unsigned long arg2,
32 unsigned long arg3)
33{
34 long res;
35 asm volatile(
36 "int $0x80"
37 : "=a" (res)
38 : "a" (nr), "b" (arg1), "c" (arg2), "d" (arg3));
39 return syscall_return(res);
Stefan Reinauer14e22772010-04-27 06:56:47 +000040
Eric Biederman90089602004-05-28 14:11:54 +000041}
42
43#define NR_exit 1
44#define NR_write 4
45
46/* Standard file descriptors */
47#define STDIN_FILENO 0 /* Standard input */
48#define STDOUT_FILENO 1 /* Standard output */
49#define STDERR_FILENO 2 /* Standard error output */
50
51typedef long ssize_t;
52typedef unsigned long size_t;
53
54static ssize_t write(int fd, const void *buf, size_t count)
55{
56 struct syscall_result res;
57 res = syscall3(NR_write, fd, (unsigned long)buf, count);
58 return res.val;
59}
60
61static void _exit(int status)
62{
63 struct syscall_result res;
64 res = syscall1(NR_exit, status);
65}
66
67static void console_tx_string(const char *str)
68{
69 unsigned char ch;
70 while(1) {
71
72 }
73 for(;1;) {
74 }
75 do {
76 } while(1);
77 if (1) {
78 }else {
79 }
80}
81
82
83static void main(void)
84{
85 static const char msg[] = "hello world\r\n";
86 write(STDOUT_FILENO, msg, sizeof(msg));
87 _exit(0);
88}