Rev 714 | Rev 959 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 714 | Rev 955 | ||
|---|---|---|---|
| Line 28... | Line 28... | ||
| 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> |
|
| - | 34 | #include <errno.h> |
|
| - | 35 | #include <proc/task.h> |
|
| - | 36 | #include <arch.h> |
|
| - | 37 | #include <debug.h> |
|
| 33 | 38 | ||
| 34 | int sys_ctl(void) { |
39 | static __native sys_ctl(void) { |
| 35 | printf("Thread finished\n"); |
40 | printf("Thread finished\n"); |
| 36 | thread_exit(); |
41 | thread_exit(); |
| 37 | /* Unreachable */ |
42 | /* Unreachable */ |
| 38 | return 0; |
43 | return 0; |
| 39 | } |
44 | } |
| 40 | 45 | ||
| 41 | int sys_io(int fd, const void * buf, size_t count) { |
46 | static __native sys_io(int fd, const void * buf, size_t count) { |
| 42 | 47 | ||
| 43 | // TODO: buf sanity checks and a lot of other stuff ... |
48 | // TODO: buf sanity checks and a lot of other stuff ... |
| 44 | 49 | ||
| 45 | size_t i; |
50 | size_t i; |
| 46 | 51 | ||
| Line 48... | Line 53... | ||
| 48 | putchar(((char *) buf)[i]); |
53 | putchar(((char *) buf)[i]); |
| 49 | 54 | ||
| 50 | return count; |
55 | return count; |
| 51 | } |
56 | } |
| 52 | 57 | ||
| - | 58 | /** Send a call over syscall |
|
| - | 59 | * |
|
| - | 60 | * @return Call identification, returns -1 on fatal error, |
|
| - | 61 | -2 on 'Too many async request, handle answers first |
|
| - | 62 | */ |
|
| - | 63 | static __native sys_ipc_call(__native phoneid, __native arg1, __native arg2) |
|
| - | 64 | { |
|
| - | 65 | call_t *call; |
|
| - | 66 | phone_t *phone; |
|
| - | 67 | ||
| - | 68 | if (phoneid >= IPC_MAX_PHONES) |
|
| - | 69 | return -ENOENT; |
|
| - | 70 | ||
| - | 71 | phone = &TASK->phones[phoneid]; |
|
| - | 72 | if (!phone->callee) |
|
| - | 73 | return -ENOENT; |
|
| - | 74 | ||
| - | 75 | ||
| - | 76 | /* TODO: Check that we did not exceed system imposed maximum |
|
| - | 77 | * of asynchrnously sent messages |
|
| - | 78 | * - the userspace should be able to handle it correctly |
|
| - | 79 | */ |
|
| - | 80 | call = ipc_call_alloc(); |
|
| - | 81 | call->data[0] = arg1; |
|
| - | 82 | call->data[1] = arg2; |
|
| - | 83 | ipc_call(phone, call); |
|
| - | 84 | ||
| - | 85 | return (__native) call; |
|
| - | 86 | } |
|
| - | 87 | ||
| - | 88 | /** Send IPC answer */ |
|
| - | 89 | static __native sys_ipc_answer(__native callid, __native arg1, __native arg2) |
|
| - | 90 | { |
|
| - | 91 | call_t *call; |
|
| - | 92 | ||
| - | 93 | /* Check that the user is not sending us answer callid */ |
|
| - | 94 | ASSERT(! (callid & 1)); |
|
| - | 95 | /* TODO: Check that the callid is in the dispatch table */ |
|
| - | 96 | call = (call_t *) callid; |
|
| - | 97 | ||
| - | 98 | call->data[0] = arg1; |
|
| - | 99 | call->data[1] = arg2; |
|
| - | 100 | ||
| - | 101 | ipc_answer(&TASK->answerbox, call); |
|
| - | 102 | return 0; |
|
| - | 103 | } |
|
| - | 104 | ||
| - | 105 | /** Wait for incoming ipc call or answer |
|
| - | 106 | * |
|
| - | 107 | * @param result |
|
| - | 108 | * @param flags |
|
| - | 109 | * @return Callid, if callid & 1, then the call is answer |
|
| - | 110 | */ |
|
| - | 111 | static __native sys_ipc_wait_for_call(__native *calldata, __native flags) |
|
| - | 112 | { |
|
| - | 113 | call_t *call; |
|
| - | 114 | ||
| - | 115 | call = ipc_wait_for_call(&TASK->answerbox, flags); |
|
| - | 116 | copy_to_uspace(calldata, &call->data, sizeof(__native) * IPC_CALL_LEN); |
|
| - | 117 | ||
| - | 118 | if (call->flags & IPC_CALL_ANSWERED) |
|
| - | 119 | return ((__native)call) | 1; |
|
| - | 120 | return (__native)call; |
|
| - | 121 | } |
|
| - | 122 | ||
| - | 123 | ||
| 53 | syshandler_t syscall_table[SYSCALL_END] = { |
124 | syshandler_t syscall_table[SYSCALL_END] = { |
| 54 | sys_ctl, |
125 | sys_ctl, |
| 55 | sys_io |
126 | sys_io, |
| - | 127 | sys_ipc_call, |
|
| - | 128 | sys_ipc_answer, |
|
| - | 129 | sys_ipc_wait_for_call |
|
| 56 | }; |
130 | }; |