Rev 955 | Rev 965 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 955 | Rev 959 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2005 Martin Decky |
2 | * Copyright (C) 2005 Martin Decky |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include <syscall/syscall.h> |
29 | #include <syscall/syscall.h> |
30 | #include <proc/thread.h> |
30 | #include <proc/thread.h> |
31 | #include <print.h> |
31 | #include <print.h> |
32 | #include <putchar.h> |
32 | #include <putchar.h> |
33 | #include <ipc/ipc.h> |
33 | #include <ipc/ipc.h> |
34 | #include <errno.h> |
34 | #include <errno.h> |
35 | #include <proc/task.h> |
35 | #include <proc/task.h> |
36 | #include <arch.h> |
36 | #include <arch.h> |
37 | #include <debug.h> |
37 | #include <debug.h> |
38 | 38 | ||
39 | static __native sys_ctl(void) { |
39 | static __native sys_ctl(void) { |
40 | printf("Thread finished\n"); |
40 | printf("Thread finished\n"); |
41 | thread_exit(); |
41 | thread_exit(); |
42 | /* Unreachable */ |
42 | /* Unreachable */ |
43 | return 0; |
43 | return 0; |
44 | } |
44 | } |
45 | 45 | ||
46 | static __native sys_io(int fd, const void * buf, size_t count) { |
46 | static __native sys_io(int fd, const void * buf, size_t count) { |
47 | 47 | ||
48 | // TODO: buf sanity checks and a lot of other stuff ... |
48 | // TODO: buf sanity checks and a lot of other stuff ... |
49 | 49 | ||
50 | size_t i; |
50 | size_t i; |
51 | 51 | ||
52 | for (i = 0; i < count; i++) |
52 | for (i = 0; i < count; i++) |
53 | putchar(((char *) buf)[i]); |
53 | putchar(((char *) buf)[i]); |
54 | 54 | ||
55 | return count; |
55 | return count; |
56 | } |
56 | } |
57 | 57 | ||
58 | /** Send a call over syscall |
58 | /** Send a call over IPC, wait for reply, return to user |
59 | * |
59 | * |
60 | * @return Call identification, returns -1 on fatal error, |
60 | * @return Call identification, returns -1 on fatal error, |
61 | -2 on 'Too many async request, handle answers first |
61 | -2 on 'Too many async request, handle answers first |
62 | */ |
62 | */ |
63 | static __native sys_ipc_call(__native phoneid, __native arg1, __native arg2) |
63 | static __native sys_ipc_call_sync(__native phoneid, __native arg1, |
- | 64 | __native arg2, __native *respdata) |
|
- | 65 | { |
|
- | 66 | call_t *call; |
|
- | 67 | phone_t *phone; |
|
- | 68 | /* Special answerbox for synchronous messages */ |
|
- | 69 | ||
- | 70 | if (phoneid >= IPC_MAX_PHONES) |
|
- | 71 | return -ENOENT; |
|
- | 72 | ||
- | 73 | phone = &TASK->phones[phoneid]; |
|
- | 74 | if (!phone->callee) |
|
- | 75 | return -ENOENT; |
|
- | 76 | ||
- | 77 | call = ipc_call_alloc(); |
|
- | 78 | call->data[0] = arg1; |
|
- | 79 | call->data[1] = arg2; |
|
- | 80 | ||
- | 81 | ipc_call_sync(phone, call); |
|
- | 82 | ||
- | 83 | copy_to_uspace(respdata, &call->data, sizeof(__native) * IPC_CALL_LEN); |
|
- | 84 | ||
- | 85 | return 0; |
|
- | 86 | } |
|
- | 87 | ||
- | 88 | /** Send an asynchronous call over ipc |
|
- | 89 | * |
|
- | 90 | * @return Call identification, returns -1 on fatal error, |
|
- | 91 | -2 on 'Too many async request, handle answers first |
|
- | 92 | */ |
|
- | 93 | static __native sys_ipc_call_async(__native phoneid, __native arg1, |
|
- | 94 | __native arg2) |
|
64 | { |
95 | { |
65 | call_t *call; |
96 | call_t *call; |
66 | phone_t *phone; |
97 | phone_t *phone; |
67 | 98 | ||
68 | if (phoneid >= IPC_MAX_PHONES) |
99 | if (phoneid >= IPC_MAX_PHONES) |
69 | return -ENOENT; |
100 | return -ENOENT; |
70 | 101 | ||
71 | phone = &TASK->phones[phoneid]; |
102 | phone = &TASK->phones[phoneid]; |
72 | if (!phone->callee) |
103 | if (!phone->callee) |
73 | return -ENOENT; |
104 | return -ENOENT; |
74 | 105 | ||
75 | 106 | ||
76 | /* TODO: Check that we did not exceed system imposed maximum |
107 | /* TODO: Check that we did not exceed system imposed maximum |
77 | * of asynchrnously sent messages |
108 | * of asynchrnously sent messages |
78 | * - the userspace should be able to handle it correctly |
109 | * - the userspace should be able to handle it correctly |
79 | */ |
110 | */ |
80 | call = ipc_call_alloc(); |
111 | call = ipc_call_alloc(); |
81 | call->data[0] = arg1; |
112 | call->data[0] = arg1; |
82 | call->data[1] = arg2; |
113 | call->data[1] = arg2; |
83 | ipc_call(phone, call); |
114 | ipc_call(phone, call); |
84 | 115 | ||
85 | return (__native) call; |
116 | return (__native) call; |
86 | } |
117 | } |
87 | 118 | ||
88 | /** Send IPC answer */ |
119 | /** Send IPC answer */ |
89 | static __native sys_ipc_answer(__native callid, __native arg1, __native arg2) |
120 | static __native sys_ipc_answer(__native callid, __native arg1, __native arg2) |
90 | { |
121 | { |
91 | call_t *call; |
122 | call_t *call; |
92 | 123 | ||
93 | /* Check that the user is not sending us answer callid */ |
124 | /* Check that the user is not sending us answer callid */ |
94 | ASSERT(! (callid & 1)); |
125 | ASSERT(! (callid & 1)); |
95 | /* TODO: Check that the callid is in the dispatch table */ |
126 | /* TODO: Check that the callid is in the dispatch table */ |
96 | call = (call_t *) callid; |
127 | call = (call_t *) callid; |
97 | 128 | ||
98 | call->data[0] = arg1; |
129 | call->data[0] = arg1; |
99 | call->data[1] = arg2; |
130 | call->data[1] = arg2; |
100 | 131 | ||
101 | ipc_answer(&TASK->answerbox, call); |
132 | ipc_answer(&TASK->answerbox, call); |
102 | return 0; |
133 | return 0; |
103 | } |
134 | } |
104 | 135 | ||
105 | /** Wait for incoming ipc call or answer |
136 | /** Wait for incoming ipc call or answer |
106 | * |
137 | * |
107 | * @param result |
138 | * @param result |
108 | * @param flags |
139 | * @param flags |
109 | * @return Callid, if callid & 1, then the call is answer |
140 | * @return Callid, if callid & 1, then the call is answer |
110 | */ |
141 | */ |
111 | static __native sys_ipc_wait_for_call(__native *calldata, __native flags) |
142 | static __native sys_ipc_wait_for_call(__native *calldata, __native flags) |
112 | { |
143 | { |
113 | call_t *call; |
144 | call_t *call; |
114 | 145 | ||
115 | call = ipc_wait_for_call(&TASK->answerbox, flags); |
146 | call = ipc_wait_for_call(&TASK->answerbox, flags); |
116 | copy_to_uspace(calldata, &call->data, sizeof(__native) * IPC_CALL_LEN); |
147 | copy_to_uspace(calldata, &call->data, sizeof(__native) * IPC_CALL_LEN); |
117 | 148 | ||
118 | if (call->flags & IPC_CALL_ANSWERED) |
149 | if (call->flags & IPC_CALL_ANSWERED) |
119 | return ((__native)call) | 1; |
150 | return ((__native)call) | 1; |
120 | return (__native)call; |
151 | return (__native)call; |
121 | } |
152 | } |
122 | 153 | ||
123 | 154 | ||
124 | syshandler_t syscall_table[SYSCALL_END] = { |
155 | syshandler_t syscall_table[SYSCALL_END] = { |
125 | sys_ctl, |
156 | sys_ctl, |
126 | sys_io, |
157 | sys_io, |
127 | sys_ipc_call, |
158 | sys_ipc_call_sync, |
- | 159 | sys_ipc_call_async, |
|
128 | sys_ipc_answer, |
160 | sys_ipc_answer, |
129 | sys_ipc_wait_for_call |
161 | sys_ipc_wait_for_call |
130 | }; |
162 | }; |
131 | 163 |