Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2952 | svoboda | 1 | |
2 | #include <stdio.h> |
||
3 | #include <stdlib.h> |
||
4 | #include <ipc/ipc.h> |
||
5 | #include <syscall.h> |
||
6 | #include <libc.h> |
||
7 | #include <console.h> |
||
8 | #include <ipc/services.h> |
||
9 | |||
10 | static void kputint(unsigned i) |
||
11 | { |
||
12 | unsigned dummy; |
||
13 | asm volatile ( |
||
14 | "movl $30, %%eax;" |
||
15 | "int $0x30" |
||
16 | : "=d" (dummy) /* output - %edx clobbered */ |
||
17 | : "d" (i) /* input */ |
||
18 | : "%eax","%ecx" /* all scratch registers clobbered */ |
||
19 | ); |
||
20 | } |
||
21 | |||
22 | int |
||
23 | ipc_call_sync_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2, |
||
24 | ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3, |
||
25 | ipcarg_t *result4, ipcarg_t *result5) |
||
26 | { |
||
27 | ipc_call_t resdata; |
||
28 | int callres; |
||
29 | |||
30 | callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1, |
||
31 | arg2, arg3, (sysarg_t) &resdata); |
||
32 | if (callres) |
||
33 | return callres; |
||
34 | if (result1) |
||
35 | *result1 = IPC_GET_ARG1(resdata); |
||
36 | if (result2) |
||
37 | *result2 = IPC_GET_ARG2(resdata); |
||
38 | if (result3) |
||
39 | *result3 = IPC_GET_ARG3(resdata); |
||
40 | if (result4) |
||
41 | *result4 = IPC_GET_ARG4(resdata); |
||
42 | if (result5) |
||
43 | *result5 = IPC_GET_ARG5(resdata); |
||
44 | |||
45 | return IPC_GET_RETVAL(resdata); |
||
46 | } |
||
47 | |||
48 | int ipc_connect_me_to(int phoneid, int arg1, int arg2, int arg3) |
||
49 | { |
||
50 | ipcarg_t newphid; |
||
51 | int res; |
||
52 | |||
53 | res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, |
||
54 | NULL, NULL, NULL, NULL, &newphid); |
||
55 | if (res) |
||
56 | return res; |
||
57 | return newphid; |
||
58 | } |
||
59 | |||
60 | static int console_phone = -1; |
||
61 | |||
62 | ssize_t write_stderr(const void *buf, size_t count) |
||
63 | { |
||
64 | return count; |
||
65 | } |
||
66 | |||
67 | ssize_t read_stdin(void *buf, size_t count) |
||
68 | { |
||
69 | ipcarg_t r0, r1; |
||
70 | size_t i = 0; |
||
71 | |||
72 | while (i < count) { |
||
73 | if (ipc_call_sync_0_2(console_phone, CONSOLE_GETCHAR, &r0, |
||
74 | &r1) < 0) { |
||
75 | return -1; |
||
76 | } |
||
77 | ((char *) buf)[i++] = r0; |
||
78 | } |
||
79 | return i; |
||
80 | } |
||
81 | |||
82 | ssize_t write_stdout(const void *buf, size_t count) |
||
83 | { |
||
84 | int i; |
||
85 | |||
86 | for (i = 0; i < count; i++) |
||
87 | ipc_call_sync_1_0(console_phone, CONSOLE_PUTCHAR, |
||
88 | ((const char *) buf)[i]); |
||
89 | |||
90 | return count; |
||
91 | } |
||
92 | |||
93 | void open_stdin(void) |
||
94 | { |
||
95 | kputint(0x1234); |
||
96 | if (console_phone < 0) { |
||
97 | while ((console_phone = ipc_connect_me_to(PHONE_NS, |
||
98 | SERVICE_CONSOLE, 0, 0)) < 0) { |
||
99 | //usleep(10000); |
||
100 | } |
||
101 | kputint(console_phone); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | void open_stdout(void) |
||
106 | { |
||
107 | kputint(0x1235); |
||
108 | if (console_phone < 0) { |
||
109 | while ((console_phone = ipc_connect_me_to(PHONE_NS, |
||
110 | SERVICE_CONSOLE, 0, 0)) < 0) { |
||
111 | //usleep(10000); |
||
112 | } |
||
113 | kputint(console_phone); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | int get_cons_phone(void) |
||
118 | { |
||
119 | return console_phone; |
||
120 | } |
||
121 | |||
122 | |||
123 | void __main(void) |
||
124 | { |
||
125 | kputint(0x110); |
||
126 | } |
||
127 | |||
128 | void __io_init(void) |
||
129 | { |
||
130 | open_stdin(); |
||
131 | open_stdout(); |
||
132 | } |
||
133 | |||
134 | void __exit(void) |
||
135 | { |
||
136 | kputint(0x112); |
||
137 | } |
||
138 | |||
139 | int putchar(int c) |
||
140 | { |
||
141 | unsigned char ch = c; |
||
142 | if (write_stdout((void *) &ch, 1) == 1) |
||
143 | return c; |
||
144 | |||
145 | return EOF; |
||
146 | } |
||
147 | |||
148 | int getchar(void) |
||
149 | { |
||
150 | unsigned char c; |
||
151 | if (read_stdin((void *) &c, 1) == 1) |
||
152 | return c; |
||
153 | |||
154 | return EOF; |
||
155 | } |
||
156 | |||
157 | int printf(const char *fmt, ...) |
||
158 | { |
||
159 | while (*fmt) { |
||
160 | putchar(*fmt++); |
||
161 | } |
||
162 | return 0; |
||
163 | } |