2 * Copyright (c) 2005 Martin Decky
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
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
15 * derived from this software without specific prior written permission.
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
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @addtogroup generic
35 * @brief Syscall table and syscall wrappers.
38 #include <syscall/syscall.h>
39 #include <proc/thread.h>
40 #include <proc/task.h>
47 #include <ipc/sysipc.h>
48 #include <synch/futex.h>
50 #include <security/cap.h>
51 #include <syscall/copy.h>
52 #include <sysinfo/sysinfo.h>
53 #include <console/console.h>
54 #include <console/klog.h>
56 /** Print using kernel facility
58 * Some simulators can print only through kernel. Userspace can use
59 * this syscall to facilitate it.
61 static unative_t
sys_io(int fd
, const void * buf
, size_t count
)
67 if (count
> PAGE_SIZE
)
70 data
= malloc(count
, 0);
74 rc
= copy_from_uspace(data
, buf
, count
);
80 for (i
= 0; i
< count
; i
++)
87 /** Tell kernel to get keyboard/console access again */
88 static unative_t
sys_debug_enable_console(void)
94 /** Dispatch system call */
95 unative_t
syscall_handler(unative_t a1
, unative_t a2
, unative_t a3
,
96 unative_t a4
, unative_t id
)
100 if (id
< SYSCALL_END
)
101 rc
= syscall_table
[id
](a1
,a2
,a3
,a4
);
103 klog_printf("TASK %lld: Unknown syscall id %d",TASK
->taskid
,id
);
104 task_kill(TASK
->taskid
);
108 if (THREAD
->interrupted
)
114 syshandler_t syscall_table
[SYSCALL_END
] = {
118 /* Thread and task related syscalls. */
123 /* Synchronization related syscalls. */
124 sys_futex_sleep_timeout
,
127 /* Address space related syscalls. */
132 /* IPC related syscalls. */
133 sys_ipc_call_sync_fast
,
135 sys_ipc_call_async_fast
,
139 sys_ipc_forward_fast
,
140 sys_ipc_wait_for_call
,
142 sys_ipc_register_irq
,
143 sys_ipc_unregister_irq
,
145 /* Capabilities related syscalls. */
149 /* DDI related syscalls. */
154 /* Sysinfo syscalls */
159 sys_debug_enable_console