Rev 3022 | Rev 4201 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3022 | Rev 4055 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <syscall/syscall.h> |
38 | #include <syscall/syscall.h> |
39 | #include <proc/thread.h> |
39 | #include <proc/thread.h> |
40 | #include <proc/task.h> |
40 | #include <proc/task.h> |
- | 41 | #include <proc/program.h> |
|
41 | #include <mm/as.h> |
42 | #include <mm/as.h> |
42 | #include <print.h> |
43 | #include <print.h> |
43 | #include <putchar.h> |
44 | #include <putchar.h> |
44 | #include <errno.h> |
45 | #include <errno.h> |
45 | #include <arch.h> |
46 | #include <arch.h> |
46 | #include <debug.h> |
47 | #include <debug.h> |
47 | #include <ipc/sysipc.h> |
48 | #include <ipc/sysipc.h> |
48 | #include <synch/futex.h> |
49 | #include <synch/futex.h> |
- | 50 | #include <synch/smc.h> |
|
49 | #include <ddi/ddi.h> |
51 | #include <ddi/ddi.h> |
50 | #include <security/cap.h> |
52 | #include <security/cap.h> |
51 | #include <syscall/copy.h> |
53 | #include <syscall/copy.h> |
52 | #include <sysinfo/sysinfo.h> |
54 | #include <sysinfo/sysinfo.h> |
53 | #include <console/console.h> |
55 | #include <console/console.h> |
54 | #include <console/klog.h> |
56 | #include <udebug/udebug.h> |
55 | 57 | ||
56 | /** Print using kernel facility |
58 | /** Print using kernel facility |
57 | * |
59 | * |
58 | * Some simulators can print only through kernel. Userspace can use |
- | |
59 | * this syscall to facilitate it. |
60 | * Print to kernel log. |
- | 61 | * |
|
60 | */ |
62 | */ |
61 | static unative_t sys_io(int fd, const void * buf, size_t count) |
63 | static unative_t sys_klog(int fd, const void * buf, size_t count) |
62 | { |
64 | { |
63 | size_t i; |
- | |
64 | char *data; |
65 | char *data; |
65 | int rc; |
66 | int rc; |
66 | 67 | ||
67 | if (count > PAGE_SIZE) |
68 | if (count > PAGE_SIZE) |
68 | return ELIMIT; |
69 | return ELIMIT; |
69 | - | ||
70 | data = (char *) malloc(count, 0); |
- | |
71 | if (!data) |
- | |
72 | return ENOMEM; |
- | |
73 | 70 | ||
- | 71 | if (count > 0) { |
|
- | 72 | data = (char *) malloc(count + 1, 0); |
|
- | 73 | if (!data) |
|
- | 74 | return ENOMEM; |
|
- | 75 | ||
74 | rc = copy_from_uspace(data, buf, count); |
76 | rc = copy_from_uspace(data, buf, count); |
75 | if (rc) { |
77 | if (rc) { |
- | 78 | free(data); |
|
- | 79 | return rc; |
|
- | 80 | } |
|
- | 81 | data[count] = 0; |
|
- | 82 | ||
- | 83 | printf("%s", data); |
|
76 | free(data); |
84 | free(data); |
77 | return rc; |
- | |
78 | } |
85 | } else |
79 | - | ||
80 | for (i = 0; i < count; i++) |
- | |
81 | putchar(data[i]); |
86 | klog_update(); |
82 | free(data); |
- | |
83 | 87 | ||
84 | return count; |
88 | return count; |
85 | } |
89 | } |
86 | 90 | ||
87 | /** Tell kernel to get keyboard/console access again */ |
91 | /** Tell kernel to get keyboard/console access again */ |
88 | static unative_t sys_debug_enable_console(void) |
92 | static unative_t sys_debug_enable_console(void) |
89 | { |
93 | { |
- | 94 | #ifdef CONFIG_KCONSOLE |
|
90 | arch_grab_console(); |
95 | grab_console(); |
- | 96 | return true; |
|
- | 97 | #else |
|
- | 98 | return false; |
|
- | 99 | #endif |
|
- | 100 | } |
|
- | 101 | ||
- | 102 | /** Tell kernel to relinquish keyboard/console access */ |
|
- | 103 | static unative_t sys_debug_disable_console(void) |
|
- | 104 | { |
|
- | 105 | release_console(); |
|
91 | return 0; |
106 | return true; |
92 | } |
107 | } |
93 | 108 | ||
94 | /** Dispatch system call */ |
109 | /** Dispatch system call */ |
95 | unative_t syscall_handler(unative_t a1, unative_t a2, unative_t a3, |
110 | unative_t syscall_handler(unative_t a1, unative_t a2, unative_t a3, |
96 | unative_t a4, unative_t a5, unative_t a6, unative_t id) |
111 | unative_t a4, unative_t a5, unative_t a6, unative_t id) |
97 | { |
112 | { |
98 | unative_t rc; |
113 | unative_t rc; |
99 | 114 | ||
- | 115 | #ifdef CONFIG_UDEBUG |
|
- | 116 | udebug_syscall_event(a1, a2, a3, a4, a5, a6, id, 0, false); |
|
- | 117 | #endif |
|
100 | if (id < SYSCALL_END) |
118 | if (id < SYSCALL_END) { |
101 | rc = syscall_table[id](a1, a2, a3, a4, a5, a6); |
119 | rc = syscall_table[id](a1, a2, a3, a4, a5, a6); |
102 | else { |
120 | } else { |
103 | klog_printf("TASK %llu: Unknown syscall id %llx", TASK->taskid, |
121 | printf("Task %" PRIu64": Unknown syscall %#" PRIxn, TASK->taskid, id); |
104 | id); |
- | |
105 | task_kill(TASK->taskid); |
122 | task_kill(TASK->taskid); |
106 | thread_exit(); |
123 | thread_exit(); |
107 | } |
124 | } |
108 | 125 | ||
109 | if (THREAD->interrupted) |
126 | if (THREAD->interrupted) |
110 | thread_exit(); |
127 | thread_exit(); |
- | 128 | ||
- | 129 | #ifdef CONFIG_UDEBUG |
|
- | 130 | udebug_syscall_event(a1, a2, a3, a4, a5, a6, id, rc, true); |
|
111 | 131 | ||
- | 132 | /* |
|
- | 133 | * Stopping point needed for tasks that only invoke non-blocking |
|
- | 134 | * system calls. |
|
- | 135 | */ |
|
- | 136 | udebug_stoppable_begin(); |
|
- | 137 | udebug_stoppable_end(); |
|
- | 138 | #endif |
|
112 | return rc; |
139 | return rc; |
113 | } |
140 | } |
114 | 141 | ||
115 | syshandler_t syscall_table[SYSCALL_END] = { |
142 | syshandler_t syscall_table[SYSCALL_END] = { |
116 | (syshandler_t) sys_io, |
143 | (syshandler_t) sys_klog, |
117 | (syshandler_t) sys_tls_set, |
144 | (syshandler_t) sys_tls_set, |
118 | 145 | ||
119 | /* Thread and task related syscalls. */ |
146 | /* Thread and task related syscalls. */ |
120 | (syshandler_t) sys_thread_create, |
147 | (syshandler_t) sys_thread_create, |
121 | (syshandler_t) sys_thread_exit, |
148 | (syshandler_t) sys_thread_exit, |
122 | (syshandler_t) sys_thread_get_id, |
149 | (syshandler_t) sys_thread_get_id, |
- | 150 | ||
123 | (syshandler_t) sys_task_get_id, |
151 | (syshandler_t) sys_task_get_id, |
- | 152 | (syshandler_t) sys_task_set_name, |
|
- | 153 | (syshandler_t) sys_program_spawn_loader, |
|
124 | 154 | ||
125 | /* Synchronization related syscalls. */ |
155 | /* Synchronization related syscalls. */ |
126 | (syshandler_t) sys_futex_sleep_timeout, |
156 | (syshandler_t) sys_futex_sleep_timeout, |
127 | (syshandler_t) sys_futex_wakeup, |
157 | (syshandler_t) sys_futex_wakeup, |
- | 158 | (syshandler_t) sys_smc_coherence, |
|
128 | 159 | ||
129 | /* Address space related syscalls. */ |
160 | /* Address space related syscalls. */ |
130 | (syshandler_t) sys_as_area_create, |
161 | (syshandler_t) sys_as_area_create, |
131 | (syshandler_t) sys_as_area_resize, |
162 | (syshandler_t) sys_as_area_resize, |
- | 163 | (syshandler_t) sys_as_area_change_flags, |
|
132 | (syshandler_t) sys_as_area_destroy, |
164 | (syshandler_t) sys_as_area_destroy, |
133 | 165 | ||
134 | /* IPC related syscalls. */ |
166 | /* IPC related syscalls. */ |
135 | (syshandler_t) sys_ipc_call_sync_fast, |
167 | (syshandler_t) sys_ipc_call_sync_fast, |
136 | (syshandler_t) sys_ipc_call_sync_slow, |
168 | (syshandler_t) sys_ipc_call_sync_slow, |
137 | (syshandler_t) sys_ipc_call_async_fast, |
169 | (syshandler_t) sys_ipc_call_async_fast, |
138 | (syshandler_t) sys_ipc_call_async_slow, |
170 | (syshandler_t) sys_ipc_call_async_slow, |
139 | (syshandler_t) sys_ipc_answer_fast, |
171 | (syshandler_t) sys_ipc_answer_fast, |
140 | (syshandler_t) sys_ipc_answer_slow, |
172 | (syshandler_t) sys_ipc_answer_slow, |
141 | (syshandler_t) sys_ipc_forward_fast, |
173 | (syshandler_t) sys_ipc_forward_fast, |
- | 174 | (syshandler_t) sys_ipc_forward_slow, |
|
142 | (syshandler_t) sys_ipc_wait_for_call, |
175 | (syshandler_t) sys_ipc_wait_for_call, |
143 | (syshandler_t) sys_ipc_hangup, |
176 | (syshandler_t) sys_ipc_hangup, |
144 | (syshandler_t) sys_ipc_register_irq, |
177 | (syshandler_t) sys_ipc_register_irq, |
145 | (syshandler_t) sys_ipc_unregister_irq, |
178 | (syshandler_t) sys_ipc_unregister_irq, |
146 | 179 | ||
Line 156... | Line 189... | ||
156 | /* Sysinfo syscalls */ |
189 | /* Sysinfo syscalls */ |
157 | (syshandler_t) sys_sysinfo_valid, |
190 | (syshandler_t) sys_sysinfo_valid, |
158 | (syshandler_t) sys_sysinfo_value, |
191 | (syshandler_t) sys_sysinfo_value, |
159 | 192 | ||
160 | /* Debug calls */ |
193 | /* Debug calls */ |
161 | (syshandler_t) sys_debug_enable_console |
194 | (syshandler_t) sys_debug_enable_console, |
- | 195 | (syshandler_t) sys_debug_disable_console, |
|
- | 196 | ||
- | 197 | (syshandler_t) sys_ipc_connect_kbox |
|
162 | }; |
198 | }; |
163 | 199 | ||
164 | /** @} |
200 | /** @} |
165 | */ |
201 | */ |