Rev 4207 | Rev 4227 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4207 | Rev 4216 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2005 Jakub Jermar |
2 | * Copyright (c) 2005 Jakub Jermar |
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 | /** @addtogroup genericconsole |
29 | /** @addtogroup genericconsole |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * @file cmd.c |
34 | * @file cmd.c |
35 | * @brief Kernel console command wrappers. |
35 | * @brief Kernel console command wrappers. |
36 | * |
36 | * |
37 | * This file is meant to contain all wrapper functions for |
37 | * This file is meant to contain all wrapper functions for |
38 | * all kconsole commands. The point is in separating |
38 | * all kconsole commands. The point is in separating |
39 | * kconsole specific wrappers from kconsole-unaware functions |
39 | * kconsole specific wrappers from kconsole-unaware functions |
40 | * from other subsystems. |
40 | * from other subsystems. |
41 | */ |
41 | */ |
42 | 42 | ||
43 | #include <console/cmd.h> |
43 | #include <console/cmd.h> |
44 | #include <console/console.h> |
44 | #include <console/console.h> |
45 | #include <console/kconsole.h> |
45 | #include <console/kconsole.h> |
46 | #include <print.h> |
46 | #include <print.h> |
47 | #include <panic.h> |
47 | #include <panic.h> |
48 | #include <arch/types.h> |
48 | #include <arch/types.h> |
49 | #include <adt/list.h> |
49 | #include <adt/list.h> |
50 | #include <arch.h> |
50 | #include <arch.h> |
51 | #include <config.h> |
51 | #include <config.h> |
52 | #include <func.h> |
52 | #include <func.h> |
53 | #include <string.h> |
53 | #include <string.h> |
54 | #include <macros.h> |
54 | #include <macros.h> |
55 | #include <debug.h> |
55 | #include <debug.h> |
56 | #include <cpu.h> |
56 | #include <cpu.h> |
57 | #include <mm/tlb.h> |
57 | #include <mm/tlb.h> |
58 | #include <arch/mm/tlb.h> |
58 | #include <arch/mm/tlb.h> |
59 | #include <mm/frame.h> |
59 | #include <mm/frame.h> |
60 | #include <main/version.h> |
60 | #include <main/version.h> |
61 | #include <mm/slab.h> |
61 | #include <mm/slab.h> |
62 | #include <proc/scheduler.h> |
62 | #include <proc/scheduler.h> |
63 | #include <proc/thread.h> |
63 | #include <proc/thread.h> |
64 | #include <proc/task.h> |
64 | #include <proc/task.h> |
65 | #include <ipc/ipc.h> |
65 | #include <ipc/ipc.h> |
66 | #include <ipc/irq.h> |
66 | #include <ipc/irq.h> |
67 | #include <event/event.h> |
67 | #include <event/event.h> |
68 | #include <symtab.h> |
68 | #include <symtab.h> |
69 | #include <errno.h> |
69 | #include <errno.h> |
70 | 70 | ||
71 | #ifdef CONFIG_TEST |
71 | #ifdef CONFIG_TEST |
72 | #include <test.h> |
72 | #include <test.h> |
73 | #endif |
73 | #endif |
74 | 74 | ||
75 | /* Data and methods for 'help' command. */ |
75 | /* Data and methods for 'help' command. */ |
76 | static int cmd_help(cmd_arg_t *argv); |
76 | static int cmd_help(cmd_arg_t *argv); |
77 | static cmd_info_t help_info = { |
77 | static cmd_info_t help_info = { |
78 | .name = "help", |
78 | .name = "help", |
79 | .description = "List of supported commands.", |
79 | .description = "List of supported commands.", |
80 | .func = cmd_help, |
80 | .func = cmd_help, |
81 | .argc = 0 |
81 | .argc = 0 |
82 | }; |
82 | }; |
83 | 83 | ||
84 | static int cmd_reboot(cmd_arg_t *argv); |
84 | static int cmd_reboot(cmd_arg_t *argv); |
85 | static cmd_info_t reboot_info = { |
85 | static cmd_info_t reboot_info = { |
86 | .name = "reboot", |
86 | .name = "reboot", |
87 | .description = "Reboot.", |
87 | .description = "Reboot.", |
88 | .func = cmd_reboot, |
88 | .func = cmd_reboot, |
89 | .argc = 0 |
89 | .argc = 0 |
90 | }; |
90 | }; |
91 | 91 | ||
92 | static int cmd_uptime(cmd_arg_t *argv); |
92 | static int cmd_uptime(cmd_arg_t *argv); |
93 | static cmd_info_t uptime_info = { |
93 | static cmd_info_t uptime_info = { |
94 | .name = "uptime", |
94 | .name = "uptime", |
95 | .description = "Print uptime information.", |
95 | .description = "Print uptime information.", |
96 | .func = cmd_uptime, |
96 | .func = cmd_uptime, |
97 | .argc = 0 |
97 | .argc = 0 |
98 | }; |
98 | }; |
99 | 99 | ||
100 | static int cmd_continue(cmd_arg_t *argv); |
100 | static int cmd_continue(cmd_arg_t *argv); |
101 | static cmd_info_t continue_info = { |
101 | static cmd_info_t continue_info = { |
102 | .name = "continue", |
102 | .name = "continue", |
103 | .description = "Return console back to userspace.", |
103 | .description = "Return console back to userspace.", |
104 | .func = cmd_continue, |
104 | .func = cmd_continue, |
105 | .argc = 0 |
105 | .argc = 0 |
106 | }; |
106 | }; |
107 | 107 | ||
108 | #ifdef CONFIG_TEST |
108 | #ifdef CONFIG_TEST |
109 | static int cmd_tests(cmd_arg_t *argv); |
109 | static int cmd_tests(cmd_arg_t *argv); |
110 | static cmd_info_t tests_info = { |
110 | static cmd_info_t tests_info = { |
111 | .name = "tests", |
111 | .name = "tests", |
112 | .description = "Print available kernel tests.", |
112 | .description = "Print available kernel tests.", |
113 | .func = cmd_tests, |
113 | .func = cmd_tests, |
114 | .argc = 0 |
114 | .argc = 0 |
115 | }; |
115 | }; |
116 | 116 | ||
117 | static char test_buf[MAX_CMDLINE + 1]; |
117 | static char test_buf[MAX_CMDLINE + 1]; |
118 | static int cmd_test(cmd_arg_t *argv); |
118 | static int cmd_test(cmd_arg_t *argv); |
119 | static cmd_arg_t test_argv[] = { |
119 | static cmd_arg_t test_argv[] = { |
120 | { |
120 | { |
121 | .type = ARG_TYPE_STRING, |
121 | .type = ARG_TYPE_STRING, |
122 | .buffer = test_buf, |
122 | .buffer = test_buf, |
123 | .len = sizeof(test_buf) |
123 | .len = sizeof(test_buf) |
124 | } |
124 | } |
125 | }; |
125 | }; |
126 | static cmd_info_t test_info = { |
126 | static cmd_info_t test_info = { |
127 | .name = "test", |
127 | .name = "test", |
128 | .description = "Run kernel test.", |
128 | .description = "Run kernel test.", |
129 | .func = cmd_test, |
129 | .func = cmd_test, |
130 | .argc = 1, |
130 | .argc = 1, |
131 | .argv = test_argv |
131 | .argv = test_argv |
132 | }; |
132 | }; |
133 | 133 | ||
134 | static int cmd_bench(cmd_arg_t *argv); |
134 | static int cmd_bench(cmd_arg_t *argv); |
135 | static cmd_arg_t bench_argv[] = { |
135 | static cmd_arg_t bench_argv[] = { |
136 | { |
136 | { |
137 | .type = ARG_TYPE_STRING, |
137 | .type = ARG_TYPE_STRING, |
138 | .buffer = test_buf, |
138 | .buffer = test_buf, |
139 | .len = sizeof(test_buf) |
139 | .len = sizeof(test_buf) |
140 | }, |
140 | }, |
141 | { |
141 | { |
142 | .type = ARG_TYPE_INT, |
142 | .type = ARG_TYPE_INT, |
143 | } |
143 | } |
144 | }; |
144 | }; |
145 | static cmd_info_t bench_info = { |
145 | static cmd_info_t bench_info = { |
146 | .name = "bench", |
146 | .name = "bench", |
147 | .description = "Run kernel test as benchmark.", |
147 | .description = "Run kernel test as benchmark.", |
148 | .func = cmd_bench, |
148 | .func = cmd_bench, |
149 | .argc = 2, |
149 | .argc = 2, |
150 | .argv = bench_argv |
150 | .argv = bench_argv |
151 | }; |
151 | }; |
152 | #endif |
152 | #endif |
153 | 153 | ||
154 | /* Data and methods for 'description' command. */ |
154 | /* Data and methods for 'description' command. */ |
155 | static int cmd_desc(cmd_arg_t *argv); |
155 | static int cmd_desc(cmd_arg_t *argv); |
156 | static void desc_help(void); |
156 | static void desc_help(void); |
157 | static char desc_buf[MAX_CMDLINE+1]; |
157 | static char desc_buf[MAX_CMDLINE+1]; |
158 | static cmd_arg_t desc_argv = { |
158 | static cmd_arg_t desc_argv = { |
159 | .type = ARG_TYPE_STRING, |
159 | .type = ARG_TYPE_STRING, |
160 | .buffer = desc_buf, |
160 | .buffer = desc_buf, |
161 | .len = sizeof(desc_buf) |
161 | .len = sizeof(desc_buf) |
162 | }; |
162 | }; |
163 | static cmd_info_t desc_info = { |
163 | static cmd_info_t desc_info = { |
164 | .name = "describe", |
164 | .name = "describe", |
165 | .description = "Describe specified command.", |
165 | .description = "Describe specified command.", |
166 | .help = desc_help, |
166 | .help = desc_help, |
167 | .func = cmd_desc, |
167 | .func = cmd_desc, |
168 | .argc = 1, |
168 | .argc = 1, |
169 | .argv = &desc_argv |
169 | .argv = &desc_argv |
170 | }; |
170 | }; |
171 | 171 | ||
172 | /* Data and methods for 'symaddr' command. */ |
172 | /* Data and methods for 'symaddr' command. */ |
173 | static int cmd_symaddr(cmd_arg_t *argv); |
173 | static int cmd_symaddr(cmd_arg_t *argv); |
174 | static char symaddr_buf[MAX_CMDLINE+1]; |
174 | static char symaddr_buf[MAX_CMDLINE+1]; |
175 | static cmd_arg_t symaddr_argv = { |
175 | static cmd_arg_t symaddr_argv = { |
176 | .type = ARG_TYPE_STRING, |
176 | .type = ARG_TYPE_STRING, |
177 | .buffer = symaddr_buf, |
177 | .buffer = symaddr_buf, |
178 | .len = sizeof(symaddr_buf) |
178 | .len = sizeof(symaddr_buf) |
179 | }; |
179 | }; |
180 | static cmd_info_t symaddr_info = { |
180 | static cmd_info_t symaddr_info = { |
181 | .name = "symaddr", |
181 | .name = "symaddr", |
182 | .description = "Return symbol address.", |
182 | .description = "Return symbol address.", |
183 | .func = cmd_symaddr, |
183 | .func = cmd_symaddr, |
184 | .argc = 1, |
184 | .argc = 1, |
185 | .argv = &symaddr_argv |
185 | .argv = &symaddr_argv |
186 | }; |
186 | }; |
187 | 187 | ||
188 | static char set_buf[MAX_CMDLINE+1]; |
188 | static char set_buf[MAX_CMDLINE+1]; |
189 | static int cmd_set4(cmd_arg_t *argv); |
189 | static int cmd_set4(cmd_arg_t *argv); |
190 | static cmd_arg_t set4_argv[] = { |
190 | static cmd_arg_t set4_argv[] = { |
191 | { |
191 | { |
192 | .type = ARG_TYPE_STRING, |
192 | .type = ARG_TYPE_STRING, |
193 | .buffer = set_buf, |
193 | .buffer = set_buf, |
194 | .len = sizeof(set_buf) |
194 | .len = sizeof(set_buf) |
195 | }, |
195 | }, |
196 | { |
196 | { |
197 | .type = ARG_TYPE_INT |
197 | .type = ARG_TYPE_INT |
198 | } |
198 | } |
199 | }; |
199 | }; |
200 | static cmd_info_t set4_info = { |
200 | static cmd_info_t set4_info = { |
201 | .name = "set4", |
201 | .name = "set4", |
202 | .description = "set <dest_addr> <value> - 4byte version", |
202 | .description = "set <dest_addr> <value> - 4byte version", |
203 | .func = cmd_set4, |
203 | .func = cmd_set4, |
204 | .argc = 2, |
204 | .argc = 2, |
205 | .argv = set4_argv |
205 | .argv = set4_argv |
206 | }; |
206 | }; |
207 | 207 | ||
208 | /* Data and methods for 'call0' command. */ |
208 | /* Data and methods for 'call0' command. */ |
209 | static char call0_buf[MAX_CMDLINE + 1]; |
209 | static char call0_buf[MAX_CMDLINE + 1]; |
210 | static char carg1_buf[MAX_CMDLINE + 1]; |
210 | static char carg1_buf[MAX_CMDLINE + 1]; |
211 | static char carg2_buf[MAX_CMDLINE + 1]; |
211 | static char carg2_buf[MAX_CMDLINE + 1]; |
212 | static char carg3_buf[MAX_CMDLINE + 1]; |
212 | static char carg3_buf[MAX_CMDLINE + 1]; |
213 | 213 | ||
214 | static int cmd_call0(cmd_arg_t *argv); |
214 | static int cmd_call0(cmd_arg_t *argv); |
215 | static cmd_arg_t call0_argv = { |
215 | static cmd_arg_t call0_argv = { |
216 | .type = ARG_TYPE_STRING, |
216 | .type = ARG_TYPE_STRING, |
217 | .buffer = call0_buf, |
217 | .buffer = call0_buf, |
218 | .len = sizeof(call0_buf) |
218 | .len = sizeof(call0_buf) |
219 | }; |
219 | }; |
220 | static cmd_info_t call0_info = { |
220 | static cmd_info_t call0_info = { |
221 | .name = "call0", |
221 | .name = "call0", |
222 | .description = "call0 <function> -> call function().", |
222 | .description = "call0 <function> -> call function().", |
223 | .func = cmd_call0, |
223 | .func = cmd_call0, |
224 | .argc = 1, |
224 | .argc = 1, |
225 | .argv = &call0_argv |
225 | .argv = &call0_argv |
226 | }; |
226 | }; |
227 | 227 | ||
228 | /* Data and methods for 'mcall0' command. */ |
228 | /* Data and methods for 'mcall0' command. */ |
229 | static int cmd_mcall0(cmd_arg_t *argv); |
229 | static int cmd_mcall0(cmd_arg_t *argv); |
230 | static cmd_arg_t mcall0_argv = { |
230 | static cmd_arg_t mcall0_argv = { |
231 | .type = ARG_TYPE_STRING, |
231 | .type = ARG_TYPE_STRING, |
232 | .buffer = call0_buf, |
232 | .buffer = call0_buf, |
233 | .len = sizeof(call0_buf) |
233 | .len = sizeof(call0_buf) |
234 | }; |
234 | }; |
235 | static cmd_info_t mcall0_info = { |
235 | static cmd_info_t mcall0_info = { |
236 | .name = "mcall0", |
236 | .name = "mcall0", |
237 | .description = "mcall0 <function> -> call function() on each CPU.", |
237 | .description = "mcall0 <function> -> call function() on each CPU.", |
238 | .func = cmd_mcall0, |
238 | .func = cmd_mcall0, |
239 | .argc = 1, |
239 | .argc = 1, |
240 | .argv = &mcall0_argv |
240 | .argv = &mcall0_argv |
241 | }; |
241 | }; |
242 | 242 | ||
243 | /* Data and methods for 'call1' command. */ |
243 | /* Data and methods for 'call1' command. */ |
244 | static int cmd_call1(cmd_arg_t *argv); |
244 | static int cmd_call1(cmd_arg_t *argv); |
245 | static cmd_arg_t call1_argv[] = { |
245 | static cmd_arg_t call1_argv[] = { |
246 | { |
246 | { |
247 | .type = ARG_TYPE_STRING, |
247 | .type = ARG_TYPE_STRING, |
248 | .buffer = call0_buf, |
248 | .buffer = call0_buf, |
249 | .len = sizeof(call0_buf) |
249 | .len = sizeof(call0_buf) |
250 | }, |
250 | }, |
251 | { |
251 | { |
252 | .type = ARG_TYPE_VAR, |
252 | .type = ARG_TYPE_VAR, |
253 | .buffer = carg1_buf, |
253 | .buffer = carg1_buf, |
254 | .len = sizeof(carg1_buf) |
254 | .len = sizeof(carg1_buf) |
255 | } |
255 | } |
256 | }; |
256 | }; |
257 | static cmd_info_t call1_info = { |
257 | static cmd_info_t call1_info = { |
258 | .name = "call1", |
258 | .name = "call1", |
259 | .description = "call1 <function> <arg1> -> call function(arg1).", |
259 | .description = "call1 <function> <arg1> -> call function(arg1).", |
260 | .func = cmd_call1, |
260 | .func = cmd_call1, |
261 | .argc = 2, |
261 | .argc = 2, |
262 | .argv = call1_argv |
262 | .argv = call1_argv |
263 | }; |
263 | }; |
264 | 264 | ||
265 | /* Data and methods for 'call2' command. */ |
265 | /* Data and methods for 'call2' command. */ |
266 | static int cmd_call2(cmd_arg_t *argv); |
266 | static int cmd_call2(cmd_arg_t *argv); |
267 | static cmd_arg_t call2_argv[] = { |
267 | static cmd_arg_t call2_argv[] = { |
268 | { |
268 | { |
269 | .type = ARG_TYPE_STRING, |
269 | .type = ARG_TYPE_STRING, |
270 | .buffer = call0_buf, |
270 | .buffer = call0_buf, |
271 | .len = sizeof(call0_buf) |
271 | .len = sizeof(call0_buf) |
272 | }, |
272 | }, |
273 | { |
273 | { |
274 | .type = ARG_TYPE_VAR, |
274 | .type = ARG_TYPE_VAR, |
275 | .buffer = carg1_buf, |
275 | .buffer = carg1_buf, |
276 | .len = sizeof(carg1_buf) |
276 | .len = sizeof(carg1_buf) |
277 | }, |
277 | }, |
278 | { |
278 | { |
279 | .type = ARG_TYPE_VAR, |
279 | .type = ARG_TYPE_VAR, |
280 | .buffer = carg2_buf, |
280 | .buffer = carg2_buf, |
281 | .len = sizeof(carg2_buf) |
281 | .len = sizeof(carg2_buf) |
282 | } |
282 | } |
283 | }; |
283 | }; |
284 | static cmd_info_t call2_info = { |
284 | static cmd_info_t call2_info = { |
285 | .name = "call2", |
285 | .name = "call2", |
286 | .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).", |
286 | .description = "call2 <function> <arg1> <arg2> -> call function(arg1,arg2).", |
287 | .func = cmd_call2, |
287 | .func = cmd_call2, |
288 | .argc = 3, |
288 | .argc = 3, |
289 | .argv = call2_argv |
289 | .argv = call2_argv |
290 | }; |
290 | }; |
291 | 291 | ||
292 | /* Data and methods for 'call3' command. */ |
292 | /* Data and methods for 'call3' command. */ |
293 | static int cmd_call3(cmd_arg_t *argv); |
293 | static int cmd_call3(cmd_arg_t *argv); |
294 | static cmd_arg_t call3_argv[] = { |
294 | static cmd_arg_t call3_argv[] = { |
295 | { |
295 | { |
296 | .type = ARG_TYPE_STRING, |
296 | .type = ARG_TYPE_STRING, |
297 | .buffer = call0_buf, |
297 | .buffer = call0_buf, |
298 | .len = sizeof(call0_buf) |
298 | .len = sizeof(call0_buf) |
299 | }, |
299 | }, |
300 | { |
300 | { |
301 | .type = ARG_TYPE_VAR, |
301 | .type = ARG_TYPE_VAR, |
302 | .buffer = carg1_buf, |
302 | .buffer = carg1_buf, |
303 | .len = sizeof(carg1_buf) |
303 | .len = sizeof(carg1_buf) |
304 | }, |
304 | }, |
305 | { |
305 | { |
306 | .type = ARG_TYPE_VAR, |
306 | .type = ARG_TYPE_VAR, |
307 | .buffer = carg2_buf, |
307 | .buffer = carg2_buf, |
308 | .len = sizeof(carg2_buf) |
308 | .len = sizeof(carg2_buf) |
309 | }, |
309 | }, |
310 | { |
310 | { |
311 | .type = ARG_TYPE_VAR, |
311 | .type = ARG_TYPE_VAR, |
312 | .buffer = carg3_buf, |
312 | .buffer = carg3_buf, |
313 | .len = sizeof(carg3_buf) |
313 | .len = sizeof(carg3_buf) |
314 | } |
314 | } |
315 | 315 | ||
316 | }; |
316 | }; |
317 | static cmd_info_t call3_info = { |
317 | static cmd_info_t call3_info = { |
318 | .name = "call3", |
318 | .name = "call3", |
319 | .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).", |
319 | .description = "call3 <function> <arg1> <arg2> <arg3> -> call function(arg1,arg2,arg3).", |
320 | .func = cmd_call3, |
320 | .func = cmd_call3, |
321 | .argc = 4, |
321 | .argc = 4, |
322 | .argv = call3_argv |
322 | .argv = call3_argv |
323 | }; |
323 | }; |
324 | 324 | ||
325 | /* Data and methods for 'halt' command. */ |
325 | /* Data and methods for 'halt' command. */ |
326 | static int cmd_halt(cmd_arg_t *argv); |
326 | static int cmd_halt(cmd_arg_t *argv); |
327 | static cmd_info_t halt_info = { |
327 | static cmd_info_t halt_info = { |
328 | .name = "halt", |
328 | .name = "halt", |
329 | .description = "Halt the kernel.", |
329 | .description = "Halt the kernel.", |
330 | .func = cmd_halt, |
330 | .func = cmd_halt, |
331 | .argc = 0 |
331 | .argc = 0 |
332 | }; |
332 | }; |
333 | 333 | ||
334 | /* Data and methods for 'physmem' command. */ |
334 | /* Data and methods for 'physmem' command. */ |
335 | static int cmd_physmem(cmd_arg_t *argv); |
335 | static int cmd_physmem(cmd_arg_t *argv); |
336 | cmd_info_t physmem_info = { |
336 | cmd_info_t physmem_info = { |
337 | .name = "physmem", |
337 | .name = "physmem", |
338 | .description = "Print physical memory configuration.", |
338 | .description = "Print physical memory configuration.", |
339 | .help = NULL, |
339 | .help = NULL, |
340 | .func = cmd_physmem, |
340 | .func = cmd_physmem, |
341 | .argc = 0, |
341 | .argc = 0, |
342 | .argv = NULL |
342 | .argv = NULL |
343 | }; |
343 | }; |
344 | 344 | ||
345 | /* Data and methods for 'tlb' command. */ |
345 | /* Data and methods for 'tlb' command. */ |
346 | static int cmd_tlb(cmd_arg_t *argv); |
346 | static int cmd_tlb(cmd_arg_t *argv); |
347 | cmd_info_t tlb_info = { |
347 | cmd_info_t tlb_info = { |
348 | .name = "tlb", |
348 | .name = "tlb", |
349 | .description = "Print TLB of current processor.", |
349 | .description = "Print TLB of current processor.", |
350 | .help = NULL, |
350 | .help = NULL, |
351 | .func = cmd_tlb, |
351 | .func = cmd_tlb, |
352 | .argc = 0, |
352 | .argc = 0, |
353 | .argv = NULL |
353 | .argv = NULL |
354 | }; |
354 | }; |
355 | 355 | ||
356 | static int cmd_threads(cmd_arg_t *argv); |
356 | static int cmd_threads(cmd_arg_t *argv); |
357 | static cmd_info_t threads_info = { |
357 | static cmd_info_t threads_info = { |
358 | .name = "threads", |
358 | .name = "threads", |
359 | .description = "List all threads.", |
359 | .description = "List all threads.", |
360 | .func = cmd_threads, |
360 | .func = cmd_threads, |
361 | .argc = 0 |
361 | .argc = 0 |
362 | }; |
362 | }; |
363 | 363 | ||
364 | static int cmd_tasks(cmd_arg_t *argv); |
364 | static int cmd_tasks(cmd_arg_t *argv); |
365 | static cmd_info_t tasks_info = { |
365 | static cmd_info_t tasks_info = { |
366 | .name = "tasks", |
366 | .name = "tasks", |
367 | .description = "List all tasks.", |
367 | .description = "List all tasks.", |
368 | .func = cmd_tasks, |
368 | .func = cmd_tasks, |
369 | .argc = 0 |
369 | .argc = 0 |
370 | }; |
370 | }; |
371 | 371 | ||
372 | 372 | ||
373 | static int cmd_sched(cmd_arg_t *argv); |
373 | static int cmd_sched(cmd_arg_t *argv); |
374 | static cmd_info_t sched_info = { |
374 | static cmd_info_t sched_info = { |
375 | .name = "scheduler", |
375 | .name = "scheduler", |
376 | .description = "List all scheduler information.", |
376 | .description = "List all scheduler information.", |
377 | .func = cmd_sched, |
377 | .func = cmd_sched, |
378 | .argc = 0 |
378 | .argc = 0 |
379 | }; |
379 | }; |
380 | 380 | ||
381 | static int cmd_slabs(cmd_arg_t *argv); |
381 | static int cmd_slabs(cmd_arg_t *argv); |
382 | static cmd_info_t slabs_info = { |
382 | static cmd_info_t slabs_info = { |
383 | .name = "slabs", |
383 | .name = "slabs", |
384 | .description = "List slab caches.", |
384 | .description = "List slab caches.", |
385 | .func = cmd_slabs, |
385 | .func = cmd_slabs, |
386 | .argc = 0 |
386 | .argc = 0 |
387 | }; |
387 | }; |
388 | 388 | ||
389 | /* Data and methods for 'zones' command */ |
389 | /* Data and methods for 'zones' command */ |
390 | static int cmd_zones(cmd_arg_t *argv); |
390 | static int cmd_zones(cmd_arg_t *argv); |
391 | static cmd_info_t zones_info = { |
391 | static cmd_info_t zones_info = { |
392 | .name = "zones", |
392 | .name = "zones", |
393 | .description = "List of memory zones.", |
393 | .description = "List of memory zones.", |
394 | .func = cmd_zones, |
394 | .func = cmd_zones, |
395 | .argc = 0 |
395 | .argc = 0 |
396 | }; |
396 | }; |
397 | 397 | ||
398 | /* Data and methods for 'ipc' command */ |
398 | /* Data and methods for 'ipc' command */ |
399 | static int cmd_ipc(cmd_arg_t *argv); |
399 | static int cmd_ipc(cmd_arg_t *argv); |
400 | static cmd_arg_t ipc_argv = { |
400 | static cmd_arg_t ipc_argv = { |
401 | .type = ARG_TYPE_INT, |
401 | .type = ARG_TYPE_INT, |
402 | }; |
402 | }; |
403 | static cmd_info_t ipc_info = { |
403 | static cmd_info_t ipc_info = { |
404 | .name = "ipc", |
404 | .name = "ipc", |
405 | .description = "ipc <taskid> Show IPC information of given task.", |
405 | .description = "ipc <taskid> Show IPC information of given task.", |
406 | .func = cmd_ipc, |
406 | .func = cmd_ipc, |
407 | .argc = 1, |
407 | .argc = 1, |
408 | .argv = &ipc_argv |
408 | .argv = &ipc_argv |
409 | }; |
409 | }; |
410 | 410 | ||
411 | /* Data and methods for 'zone' command */ |
411 | /* Data and methods for 'zone' command */ |
412 | static int cmd_zone(cmd_arg_t *argv); |
412 | static int cmd_zone(cmd_arg_t *argv); |
413 | static cmd_arg_t zone_argv = { |
413 | static cmd_arg_t zone_argv = { |
414 | .type = ARG_TYPE_INT, |
414 | .type = ARG_TYPE_INT, |
415 | }; |
415 | }; |
416 | 416 | ||
417 | static cmd_info_t zone_info = { |
417 | static cmd_info_t zone_info = { |
418 | .name = "zone", |
418 | .name = "zone", |
419 | .description = "Show memory zone structure.", |
419 | .description = "Show memory zone structure.", |
420 | .func = cmd_zone, |
420 | .func = cmd_zone, |
421 | .argc = 1, |
421 | .argc = 1, |
422 | .argv = &zone_argv |
422 | .argv = &zone_argv |
423 | }; |
423 | }; |
424 | 424 | ||
425 | /* Data and methods for 'cpus' command. */ |
425 | /* Data and methods for 'cpus' command. */ |
426 | static int cmd_cpus(cmd_arg_t *argv); |
426 | static int cmd_cpus(cmd_arg_t *argv); |
427 | cmd_info_t cpus_info = { |
427 | cmd_info_t cpus_info = { |
428 | .name = "cpus", |
428 | .name = "cpus", |
429 | .description = "List all processors.", |
429 | .description = "List all processors.", |
430 | .help = NULL, |
430 | .help = NULL, |
431 | .func = cmd_cpus, |
431 | .func = cmd_cpus, |
432 | .argc = 0, |
432 | .argc = 0, |
433 | .argv = NULL |
433 | .argv = NULL |
434 | }; |
434 | }; |
435 | 435 | ||
436 | /* Data and methods for 'version' command. */ |
436 | /* Data and methods for 'version' command. */ |
437 | static int cmd_version(cmd_arg_t *argv); |
437 | static int cmd_version(cmd_arg_t *argv); |
438 | cmd_info_t version_info = { |
438 | cmd_info_t version_info = { |
439 | .name = "version", |
439 | .name = "version", |
440 | .description = "Print version information.", |
440 | .description = "Print version information.", |
441 | .help = NULL, |
441 | .help = NULL, |
442 | .func = cmd_version, |
442 | .func = cmd_version, |
443 | .argc = 0, |
443 | .argc = 0, |
444 | .argv = NULL |
444 | .argv = NULL |
445 | }; |
445 | }; |
446 | 446 | ||
447 | static cmd_info_t *basic_commands[] = { |
447 | static cmd_info_t *basic_commands[] = { |
448 | &call0_info, |
448 | &call0_info, |
449 | &mcall0_info, |
449 | &mcall0_info, |
450 | &call1_info, |
450 | &call1_info, |
451 | &call2_info, |
451 | &call2_info, |
452 | &call3_info, |
452 | &call3_info, |
453 | &continue_info, |
453 | &continue_info, |
454 | &cpus_info, |
454 | &cpus_info, |
455 | &desc_info, |
455 | &desc_info, |
456 | &reboot_info, |
456 | &reboot_info, |
457 | &uptime_info, |
457 | &uptime_info, |
458 | &halt_info, |
458 | &halt_info, |
459 | &help_info, |
459 | &help_info, |
460 | &ipc_info, |
460 | &ipc_info, |
461 | &set4_info, |
461 | &set4_info, |
462 | &slabs_info, |
462 | &slabs_info, |
463 | &symaddr_info, |
463 | &symaddr_info, |
464 | &sched_info, |
464 | &sched_info, |
465 | &threads_info, |
465 | &threads_info, |
466 | &tasks_info, |
466 | &tasks_info, |
467 | &physmem_info, |
467 | &physmem_info, |
468 | &tlb_info, |
468 | &tlb_info, |
469 | &version_info, |
469 | &version_info, |
470 | &zones_info, |
470 | &zones_info, |
471 | &zone_info, |
471 | &zone_info, |
472 | #ifdef CONFIG_TEST |
472 | #ifdef CONFIG_TEST |
473 | &tests_info, |
473 | &tests_info, |
474 | &test_info, |
474 | &test_info, |
475 | &bench_info, |
475 | &bench_info, |
476 | #endif |
476 | #endif |
477 | NULL |
477 | NULL |
478 | }; |
478 | }; |
479 | 479 | ||
480 | 480 | ||
481 | /** Initialize command info structure. |
481 | /** Initialize command info structure. |
482 | * |
482 | * |
483 | * @param cmd Command info structure. |
483 | * @param cmd Command info structure. |
484 | * |
484 | * |
485 | */ |
485 | */ |
486 | void cmd_initialize(cmd_info_t *cmd) |
486 | void cmd_initialize(cmd_info_t *cmd) |
487 | { |
487 | { |
488 | spinlock_initialize(&cmd->lock, "cmd"); |
488 | spinlock_initialize(&cmd->lock, "cmd"); |
489 | link_initialize(&cmd->link); |
489 | link_initialize(&cmd->link); |
490 | } |
490 | } |
491 | 491 | ||
492 | /** Initialize and register commands. */ |
492 | /** Initialize and register commands. */ |
493 | void cmd_init(void) |
493 | void cmd_init(void) |
494 | { |
494 | { |
495 | unsigned int i; |
495 | unsigned int i; |
496 | 496 | ||
497 | for (i = 0; basic_commands[i]; i++) { |
497 | for (i = 0; basic_commands[i]; i++) { |
498 | cmd_initialize(basic_commands[i]); |
498 | cmd_initialize(basic_commands[i]); |
499 | if (!cmd_register(basic_commands[i])) |
499 | if (!cmd_register(basic_commands[i])) |
500 | printf("Cannot register command %s\n", basic_commands[i]->name); |
500 | printf("Cannot register command %s\n", basic_commands[i]->name); |
501 | } |
501 | } |
502 | } |
502 | } |
503 | 503 | ||
504 | 504 | ||
505 | /** List supported commands. |
505 | /** List supported commands. |
506 | * |
506 | * |
507 | * @param argv Argument vector. |
507 | * @param argv Argument vector. |
508 | * |
508 | * |
509 | * @return 0 on failure, 1 on success. |
509 | * @return 0 on failure, 1 on success. |
510 | */ |
510 | */ |
511 | int cmd_help(cmd_arg_t *argv) |
511 | int cmd_help(cmd_arg_t *argv) |
512 | { |
512 | { |
513 | spinlock_lock(&cmd_lock); |
513 | spinlock_lock(&cmd_lock); |
514 | 514 | ||
515 | link_t *cur; |
515 | link_t *cur; |
516 | size_t len = 0; |
516 | count_t len = 0; |
517 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
517 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
518 | cmd_info_t *hlp; |
518 | cmd_info_t *hlp; |
519 | hlp = list_get_instance(cur, cmd_info_t, link); |
519 | hlp = list_get_instance(cur, cmd_info_t, link); |
520 | 520 | ||
521 | spinlock_lock(&hlp->lock); |
521 | spinlock_lock(&hlp->lock); |
522 | if (str_size(hlp->name) > len) |
522 | if (str_length(hlp->name) > len) |
523 | len = str_size(hlp->name); |
523 | len = str_length(hlp->name); |
524 | spinlock_unlock(&hlp->lock); |
524 | spinlock_unlock(&hlp->lock); |
525 | } |
525 | } |
526 | 526 | ||
527 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
527 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
528 | cmd_info_t *hlp; |
528 | cmd_info_t *hlp; |
529 | hlp = list_get_instance(cur, cmd_info_t, link); |
529 | hlp = list_get_instance(cur, cmd_info_t, link); |
530 | 530 | ||
531 | spinlock_lock(&hlp->lock); |
531 | spinlock_lock(&hlp->lock); |
532 | printf("%-*s %s\n", len, hlp->name, hlp->description); |
532 | printf("%-*s %s\n", len, hlp->name, hlp->description); |
533 | spinlock_unlock(&hlp->lock); |
533 | spinlock_unlock(&hlp->lock); |
534 | } |
534 | } |
535 | 535 | ||
536 | spinlock_unlock(&cmd_lock); |
536 | spinlock_unlock(&cmd_lock); |
537 | 537 | ||
538 | return 1; |
538 | return 1; |
539 | } |
539 | } |
540 | 540 | ||
541 | 541 | ||
542 | /** Reboot the system. |
542 | /** Reboot the system. |
543 | * |
543 | * |
544 | * @param argv Argument vector. |
544 | * @param argv Argument vector. |
545 | * |
545 | * |
546 | * @return 0 on failure, 1 on success. |
546 | * @return 0 on failure, 1 on success. |
547 | */ |
547 | */ |
548 | int cmd_reboot(cmd_arg_t *argv) |
548 | int cmd_reboot(cmd_arg_t *argv) |
549 | { |
549 | { |
550 | reboot(); |
550 | reboot(); |
551 | 551 | ||
552 | /* Not reached */ |
552 | /* Not reached */ |
553 | return 1; |
553 | return 1; |
554 | } |
554 | } |
555 | 555 | ||
556 | 556 | ||
557 | /** Print system uptime information. |
557 | /** Print system uptime information. |
558 | * |
558 | * |
559 | * @param argv Argument vector. |
559 | * @param argv Argument vector. |
560 | * |
560 | * |
561 | * @return 0 on failure, 1 on success. |
561 | * @return 0 on failure, 1 on success. |
562 | */ |
562 | */ |
563 | int cmd_uptime(cmd_arg_t *argv) |
563 | int cmd_uptime(cmd_arg_t *argv) |
564 | { |
564 | { |
565 | ASSERT(uptime); |
565 | ASSERT(uptime); |
566 | 566 | ||
567 | /* This doesn't have to be very accurate */ |
567 | /* This doesn't have to be very accurate */ |
568 | unative_t sec = uptime->seconds1; |
568 | unative_t sec = uptime->seconds1; |
569 | 569 | ||
570 | printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n", |
570 | printf("Up %" PRIun " days, %" PRIun " hours, %" PRIun " minutes, %" PRIun " seconds\n", |
571 | sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); |
571 | sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); |
572 | 572 | ||
573 | return 1; |
573 | return 1; |
574 | } |
574 | } |
575 | 575 | ||
576 | /** Describe specified command. |
576 | /** Describe specified command. |
577 | * |
577 | * |
578 | * @param argv Argument vector. |
578 | * @param argv Argument vector. |
579 | * |
579 | * |
580 | * @return 0 on failure, 1 on success. |
580 | * @return 0 on failure, 1 on success. |
581 | */ |
581 | */ |
582 | int cmd_desc(cmd_arg_t *argv) |
582 | int cmd_desc(cmd_arg_t *argv) |
583 | { |
583 | { |
584 | link_t *cur; |
584 | link_t *cur; |
585 | 585 | ||
586 | spinlock_lock(&cmd_lock); |
586 | spinlock_lock(&cmd_lock); |
587 | 587 | ||
588 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
588 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
589 | cmd_info_t *hlp; |
589 | cmd_info_t *hlp; |
590 | 590 | ||
591 | hlp = list_get_instance(cur, cmd_info_t, link); |
591 | hlp = list_get_instance(cur, cmd_info_t, link); |
592 | spinlock_lock(&hlp->lock); |
592 | spinlock_lock(&hlp->lock); |
593 | 593 | ||
594 | if (strncmp(hlp->name, (const char *) argv->buffer, str_size(hlp->name)) == 0) { |
594 | if (str_lcmp(hlp->name, (const char *) argv->buffer, str_length(hlp->name)) == 0) { |
595 | printf("%s - %s\n", hlp->name, hlp->description); |
595 | printf("%s - %s\n", hlp->name, hlp->description); |
596 | if (hlp->help) |
596 | if (hlp->help) |
597 | hlp->help(); |
597 | hlp->help(); |
598 | spinlock_unlock(&hlp->lock); |
598 | spinlock_unlock(&hlp->lock); |
599 | break; |
599 | break; |
600 | } |
600 | } |
601 | 601 | ||
602 | spinlock_unlock(&hlp->lock); |
602 | spinlock_unlock(&hlp->lock); |
603 | } |
603 | } |
604 | 604 | ||
605 | spinlock_unlock(&cmd_lock); |
605 | spinlock_unlock(&cmd_lock); |
606 | 606 | ||
607 | return 1; |
607 | return 1; |
608 | } |
608 | } |
609 | 609 | ||
610 | /** Search symbol table */ |
610 | /** Search symbol table */ |
611 | int cmd_symaddr(cmd_arg_t *argv) |
611 | int cmd_symaddr(cmd_arg_t *argv) |
612 | { |
612 | { |
613 | symtab_print_search((char *) argv->buffer); |
613 | symtab_print_search((char *) argv->buffer); |
614 | 614 | ||
615 | return 1; |
615 | return 1; |
616 | } |
616 | } |
617 | 617 | ||
618 | /** Call function with zero parameters */ |
618 | /** Call function with zero parameters */ |
619 | int cmd_call0(cmd_arg_t *argv) |
619 | int cmd_call0(cmd_arg_t *argv) |
620 | { |
620 | { |
621 | uintptr_t symaddr; |
621 | uintptr_t symaddr; |
622 | char *symbol; |
622 | char *symbol; |
623 | unative_t (*fnc)(void); |
623 | unative_t (*fnc)(void); |
624 | fncptr_t fptr; |
624 | fncptr_t fptr; |
625 | int rc; |
625 | int rc; |
626 | 626 | ||
627 | symbol = (char *) argv->buffer; |
627 | symbol = (char *) argv->buffer; |
628 | rc = symtab_addr_lookup(symbol, &symaddr); |
628 | rc = symtab_addr_lookup(symbol, &symaddr); |
629 | 629 | ||
630 | if (rc == ENOENT) |
630 | if (rc == ENOENT) |
631 | printf("Symbol %s not found.\n", symbol); |
631 | printf("Symbol %s not found.\n", symbol); |
632 | else if (rc == EOVERFLOW) { |
632 | else if (rc == EOVERFLOW) { |
633 | symtab_print_search(symbol); |
633 | symtab_print_search(symbol); |
634 | printf("Duplicate symbol, be more specific.\n"); |
634 | printf("Duplicate symbol, be more specific.\n"); |
635 | } else if (rc == EOK) { |
635 | } else if (rc == EOK) { |
636 | fnc = (unative_t (*)(void)) arch_construct_function(&fptr, |
636 | fnc = (unative_t (*)(void)) arch_construct_function(&fptr, |
637 | (void *) symaddr, (void *) cmd_call0); |
637 | (void *) symaddr, (void *) cmd_call0); |
638 | printf("Calling %s() (%p)\n", symbol, symaddr); |
638 | printf("Calling %s() (%p)\n", symbol, symaddr); |
639 | printf("Result: %#" PRIxn "\n", fnc()); |
639 | printf("Result: %#" PRIxn "\n", fnc()); |
640 | } else { |
640 | } else { |
641 | printf("No symbol information available.\n"); |
641 | printf("No symbol information available.\n"); |
642 | } |
642 | } |
643 | return 1; |
643 | return 1; |
644 | } |
644 | } |
645 | 645 | ||
646 | /** Call function with zero parameters on each CPU */ |
646 | /** Call function with zero parameters on each CPU */ |
647 | int cmd_mcall0(cmd_arg_t *argv) |
647 | int cmd_mcall0(cmd_arg_t *argv) |
648 | { |
648 | { |
649 | /* |
649 | /* |
650 | * For each CPU, create a thread which will |
650 | * For each CPU, create a thread which will |
651 | * call the function. |
651 | * call the function. |
652 | */ |
652 | */ |
653 | 653 | ||
654 | count_t i; |
654 | count_t i; |
655 | for (i = 0; i < config.cpu_count; i++) { |
655 | for (i = 0; i < config.cpu_count; i++) { |
656 | if (!cpus[i].active) |
656 | if (!cpus[i].active) |
657 | continue; |
657 | continue; |
658 | 658 | ||
659 | thread_t *t; |
659 | thread_t *t; |
660 | if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) { |
660 | if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) { |
661 | spinlock_lock(&t->lock); |
661 | spinlock_lock(&t->lock); |
662 | t->cpu = &cpus[i]; |
662 | t->cpu = &cpus[i]; |
663 | spinlock_unlock(&t->lock); |
663 | spinlock_unlock(&t->lock); |
664 | printf("cpu%u: ", i); |
664 | printf("cpu%u: ", i); |
665 | thread_ready(t); |
665 | thread_ready(t); |
666 | thread_join(t); |
666 | thread_join(t); |
667 | thread_detach(t); |
667 | thread_detach(t); |
668 | } else |
668 | } else |
669 | printf("Unable to create thread for cpu%u\n", i); |
669 | printf("Unable to create thread for cpu%u\n", i); |
670 | } |
670 | } |
671 | 671 | ||
672 | return 1; |
672 | return 1; |
673 | } |
673 | } |
674 | 674 | ||
675 | /** Call function with one parameter */ |
675 | /** Call function with one parameter */ |
676 | int cmd_call1(cmd_arg_t *argv) |
676 | int cmd_call1(cmd_arg_t *argv) |
677 | { |
677 | { |
678 | uintptr_t symaddr; |
678 | uintptr_t symaddr; |
679 | char *symbol; |
679 | char *symbol; |
680 | unative_t (*fnc)(unative_t, ...); |
680 | unative_t (*fnc)(unative_t, ...); |
681 | unative_t arg1 = argv[1].intval; |
681 | unative_t arg1 = argv[1].intval; |
682 | fncptr_t fptr; |
682 | fncptr_t fptr; |
683 | int rc; |
683 | int rc; |
684 | 684 | ||
685 | symbol = (char *) argv->buffer; |
685 | symbol = (char *) argv->buffer; |
686 | rc = symtab_addr_lookup(symbol, &symaddr); |
686 | rc = symtab_addr_lookup(symbol, &symaddr); |
687 | 687 | ||
688 | if (rc == ENOENT) { |
688 | if (rc == ENOENT) { |
689 | printf("Symbol %s not found.\n", symbol); |
689 | printf("Symbol %s not found.\n", symbol); |
690 | } else if (rc == EOVERFLOW) { |
690 | } else if (rc == EOVERFLOW) { |
691 | symtab_print_search(symbol); |
691 | symtab_print_search(symbol); |
692 | printf("Duplicate symbol, be more specific.\n"); |
692 | printf("Duplicate symbol, be more specific.\n"); |
693 | } else if (rc == EOK) { |
693 | } else if (rc == EOK) { |
694 | fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1); |
694 | fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1); |
695 | printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol); |
695 | printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol); |
696 | printf("Result: %#" PRIxn "\n", fnc(arg1)); |
696 | printf("Result: %#" PRIxn "\n", fnc(arg1)); |
697 | } else { |
697 | } else { |
698 | printf("No symbol information available.\n"); |
698 | printf("No symbol information available.\n"); |
699 | } |
699 | } |
700 | 700 | ||
701 | return 1; |
701 | return 1; |
702 | } |
702 | } |
703 | 703 | ||
704 | /** Call function with two parameters */ |
704 | /** Call function with two parameters */ |
705 | int cmd_call2(cmd_arg_t *argv) |
705 | int cmd_call2(cmd_arg_t *argv) |
706 | { |
706 | { |
707 | uintptr_t symaddr; |
707 | uintptr_t symaddr; |
708 | char *symbol; |
708 | char *symbol; |
709 | unative_t (*fnc)(unative_t, unative_t, ...); |
709 | unative_t (*fnc)(unative_t, unative_t, ...); |
710 | unative_t arg1 = argv[1].intval; |
710 | unative_t arg1 = argv[1].intval; |
711 | unative_t arg2 = argv[2].intval; |
711 | unative_t arg2 = argv[2].intval; |
712 | fncptr_t fptr; |
712 | fncptr_t fptr; |
713 | int rc; |
713 | int rc; |
714 | 714 | ||
715 | symbol = (char *) argv->buffer; |
715 | symbol = (char *) argv->buffer; |
716 | rc = symtab_addr_lookup(symbol, &symaddr); |
716 | rc = symtab_addr_lookup(symbol, &symaddr); |
717 | 717 | ||
718 | if (rc == ENOENT) { |
718 | if (rc == ENOENT) { |
719 | printf("Symbol %s not found.\n", symbol); |
719 | printf("Symbol %s not found.\n", symbol); |
720 | } else if (rc == EOVERFLOW) { |
720 | } else if (rc == EOVERFLOW) { |
721 | symtab_print_search(symbol); |
721 | symtab_print_search(symbol); |
722 | printf("Duplicate symbol, be more specific.\n"); |
722 | printf("Duplicate symbol, be more specific.\n"); |
723 | } else if (rc == EOK) { |
723 | } else if (rc == EOK) { |
724 | fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2); |
724 | fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2); |
725 | printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
725 | printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
726 | arg1, arg2, symaddr, symbol); |
726 | arg1, arg2, symaddr, symbol); |
727 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2)); |
727 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2)); |
728 | } else { |
728 | } else { |
729 | printf("No symbol information available.\n"); |
729 | printf("No symbol information available.\n"); |
730 | } |
730 | } |
731 | return 1; |
731 | return 1; |
732 | } |
732 | } |
733 | 733 | ||
734 | /** Call function with three parameters */ |
734 | /** Call function with three parameters */ |
735 | int cmd_call3(cmd_arg_t *argv) |
735 | int cmd_call3(cmd_arg_t *argv) |
736 | { |
736 | { |
737 | uintptr_t symaddr; |
737 | uintptr_t symaddr; |
738 | char *symbol; |
738 | char *symbol; |
739 | unative_t (*fnc)(unative_t, unative_t, unative_t, ...); |
739 | unative_t (*fnc)(unative_t, unative_t, unative_t, ...); |
740 | unative_t arg1 = argv[1].intval; |
740 | unative_t arg1 = argv[1].intval; |
741 | unative_t arg2 = argv[2].intval; |
741 | unative_t arg2 = argv[2].intval; |
742 | unative_t arg3 = argv[3].intval; |
742 | unative_t arg3 = argv[3].intval; |
743 | fncptr_t fptr; |
743 | fncptr_t fptr; |
744 | int rc; |
744 | int rc; |
745 | 745 | ||
746 | symbol = (char *) argv->buffer; |
746 | symbol = (char *) argv->buffer; |
747 | rc = symtab_addr_lookup(symbol, &symaddr); |
747 | rc = symtab_addr_lookup(symbol, &symaddr); |
748 | 748 | ||
749 | if (rc == ENOENT) { |
749 | if (rc == ENOENT) { |
750 | printf("Symbol %s not found.\n", symbol); |
750 | printf("Symbol %s not found.\n", symbol); |
751 | } else if (rc == EOVERFLOW) { |
751 | } else if (rc == EOVERFLOW) { |
752 | symtab_print_search(symbol); |
752 | symtab_print_search(symbol); |
753 | printf("Duplicate symbol, be more specific.\n"); |
753 | printf("Duplicate symbol, be more specific.\n"); |
754 | } else if (rc == EOK) { |
754 | } else if (rc == EOK) { |
755 | fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3); |
755 | fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3); |
756 | printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
756 | printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
757 | arg1, arg2, arg3, symaddr, symbol); |
757 | arg1, arg2, arg3, symaddr, symbol); |
758 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3)); |
758 | printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3)); |
759 | } else { |
759 | } else { |
760 | printf("No symbol information available.\n"); |
760 | printf("No symbol information available.\n"); |
761 | } |
761 | } |
762 | return 1; |
762 | return 1; |
763 | } |
763 | } |
764 | 764 | ||
765 | 765 | ||
766 | /** Print detailed description of 'describe' command. */ |
766 | /** Print detailed description of 'describe' command. */ |
767 | void desc_help(void) |
767 | void desc_help(void) |
768 | { |
768 | { |
769 | printf("Syntax: describe command_name\n"); |
769 | printf("Syntax: describe command_name\n"); |
770 | } |
770 | } |
771 | 771 | ||
772 | /** Halt the kernel. |
772 | /** Halt the kernel. |
773 | * |
773 | * |
774 | * @param argv Argument vector (ignored). |
774 | * @param argv Argument vector (ignored). |
775 | * |
775 | * |
776 | * @return 0 on failure, 1 on success (never returns). |
776 | * @return 0 on failure, 1 on success (never returns). |
777 | */ |
777 | */ |
778 | int cmd_halt(cmd_arg_t *argv) |
778 | int cmd_halt(cmd_arg_t *argv) |
779 | { |
779 | { |
780 | halt(); |
780 | halt(); |
781 | return 1; |
781 | return 1; |
782 | } |
782 | } |
783 | 783 | ||
784 | /** Command for printing TLB contents. |
784 | /** Command for printing TLB contents. |
785 | * |
785 | * |
786 | * @param argv Not used. |
786 | * @param argv Not used. |
787 | * |
787 | * |
788 | * @return Always returns 1. |
788 | * @return Always returns 1. |
789 | */ |
789 | */ |
790 | int cmd_tlb(cmd_arg_t *argv) |
790 | int cmd_tlb(cmd_arg_t *argv) |
791 | { |
791 | { |
792 | tlb_print(); |
792 | tlb_print(); |
793 | return 1; |
793 | return 1; |
794 | } |
794 | } |
795 | 795 | ||
796 | /** Command for printing physical memory configuration. |
796 | /** Command for printing physical memory configuration. |
797 | * |
797 | * |
798 | * @param argv Not used. |
798 | * @param argv Not used. |
799 | * |
799 | * |
800 | * @return Always returns 1. |
800 | * @return Always returns 1. |
801 | */ |
801 | */ |
802 | int cmd_physmem(cmd_arg_t *argv) |
802 | int cmd_physmem(cmd_arg_t *argv) |
803 | { |
803 | { |
804 | physmem_print(); |
804 | physmem_print(); |
805 | return 1; |
805 | return 1; |
806 | } |
806 | } |
807 | 807 | ||
808 | /** Write 4 byte value to address */ |
808 | /** Write 4 byte value to address */ |
809 | int cmd_set4(cmd_arg_t *argv) |
809 | int cmd_set4(cmd_arg_t *argv) |
810 | { |
810 | { |
811 | uintptr_t addr; |
811 | uintptr_t addr; |
812 | uint32_t arg1 = argv[1].intval; |
812 | uint32_t arg1 = argv[1].intval; |
813 | bool pointer = false; |
813 | bool pointer = false; |
814 | int rc; |
814 | int rc; |
815 | 815 | ||
816 | if (((char *)argv->buffer)[0] == '*') { |
816 | if (((char *)argv->buffer)[0] == '*') { |
817 | rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr); |
817 | rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr); |
818 | pointer = true; |
818 | pointer = true; |
819 | } else if (((char *) argv->buffer)[0] >= '0' && |
819 | } else if (((char *) argv->buffer)[0] >= '0' && |
820 | ((char *)argv->buffer)[0] <= '9') { |
820 | ((char *)argv->buffer)[0] <= '9') { |
821 | rc = EOK; |
821 | rc = EOK; |
822 | addr = atoi((char *)argv->buffer); |
822 | addr = atoi((char *)argv->buffer); |
823 | } else { |
823 | } else { |
824 | rc = symtab_addr_lookup((char *) argv->buffer, &addr); |
824 | rc = symtab_addr_lookup((char *) argv->buffer, &addr); |
825 | } |
825 | } |
826 | 826 | ||
827 | if (rc == ENOENT) |
827 | if (rc == ENOENT) |
828 | printf("Symbol %s not found.\n", argv->buffer); |
828 | printf("Symbol %s not found.\n", argv->buffer); |
829 | else if (rc == EOVERFLOW) { |
829 | else if (rc == EOVERFLOW) { |
830 | symtab_print_search((char *) argv->buffer); |
830 | symtab_print_search((char *) argv->buffer); |
831 | printf("Duplicate symbol, be more specific.\n"); |
831 | printf("Duplicate symbol, be more specific.\n"); |
832 | } else if (rc == EOK) { |
832 | } else if (rc == EOK) { |
833 | if (pointer) |
833 | if (pointer) |
834 | addr = *(uintptr_t *) addr; |
834 | addr = *(uintptr_t *) addr; |
835 | printf("Writing %#" PRIx64 " -> %p\n", arg1, addr); |
835 | printf("Writing %#" PRIx64 " -> %p\n", arg1, addr); |
836 | *(uint32_t *) addr = arg1; |
836 | *(uint32_t *) addr = arg1; |
837 | } else { |
837 | } else { |
838 | printf("No symbol information available.\n"); |
838 | printf("No symbol information available.\n"); |
839 | } |
839 | } |
840 | 840 | ||
841 | return 1; |
841 | return 1; |
842 | } |
842 | } |
843 | 843 | ||
844 | /** Command for listings SLAB caches |
844 | /** Command for listings SLAB caches |
845 | * |
845 | * |
846 | * @param argv Ignores |
846 | * @param argv Ignores |
847 | * |
847 | * |
848 | * @return Always 1 |
848 | * @return Always 1 |
849 | */ |
849 | */ |
850 | int cmd_slabs(cmd_arg_t * argv) { |
850 | int cmd_slabs(cmd_arg_t * argv) { |
851 | slab_print_list(); |
851 | slab_print_list(); |
852 | return 1; |
852 | return 1; |
853 | } |
853 | } |
854 | 854 | ||
855 | 855 | ||
856 | /** Command for listings Thread information |
856 | /** Command for listings Thread information |
857 | * |
857 | * |
858 | * @param argv Ignores |
858 | * @param argv Ignores |
859 | * |
859 | * |
860 | * @return Always 1 |
860 | * @return Always 1 |
861 | */ |
861 | */ |
862 | int cmd_threads(cmd_arg_t * argv) { |
862 | int cmd_threads(cmd_arg_t * argv) { |
863 | thread_print_list(); |
863 | thread_print_list(); |
864 | return 1; |
864 | return 1; |
865 | } |
865 | } |
866 | 866 | ||
867 | /** Command for listings Task information |
867 | /** Command for listings Task information |
868 | * |
868 | * |
869 | * @param argv Ignores |
869 | * @param argv Ignores |
870 | * |
870 | * |
871 | * @return Always 1 |
871 | * @return Always 1 |
872 | */ |
872 | */ |
873 | int cmd_tasks(cmd_arg_t * argv) { |
873 | int cmd_tasks(cmd_arg_t * argv) { |
874 | task_print_list(); |
874 | task_print_list(); |
875 | return 1; |
875 | return 1; |
876 | } |
876 | } |
877 | 877 | ||
878 | /** Command for listings Thread information |
878 | /** Command for listings Thread information |
879 | * |
879 | * |
880 | * @param argv Ignores |
880 | * @param argv Ignores |
881 | * |
881 | * |
882 | * @return Always 1 |
882 | * @return Always 1 |
883 | */ |
883 | */ |
884 | int cmd_sched(cmd_arg_t * argv) { |
884 | int cmd_sched(cmd_arg_t * argv) { |
885 | sched_print_list(); |
885 | sched_print_list(); |
886 | return 1; |
886 | return 1; |
887 | } |
887 | } |
888 | 888 | ||
889 | /** Command for listing memory zones |
889 | /** Command for listing memory zones |
890 | * |
890 | * |
891 | * @param argv Ignored |
891 | * @param argv Ignored |
892 | * |
892 | * |
893 | * return Always 1 |
893 | * return Always 1 |
894 | */ |
894 | */ |
895 | int cmd_zones(cmd_arg_t * argv) { |
895 | int cmd_zones(cmd_arg_t * argv) { |
896 | zone_print_list(); |
896 | zone_print_list(); |
897 | return 1; |
897 | return 1; |
898 | } |
898 | } |
899 | 899 | ||
900 | /** Command for memory zone details |
900 | /** Command for memory zone details |
901 | * |
901 | * |
902 | * @param argv Integer argument from cmdline expected |
902 | * @param argv Integer argument from cmdline expected |
903 | * |
903 | * |
904 | * return Always 1 |
904 | * return Always 1 |
905 | */ |
905 | */ |
906 | int cmd_zone(cmd_arg_t * argv) { |
906 | int cmd_zone(cmd_arg_t * argv) { |
907 | zone_print_one(argv[0].intval); |
907 | zone_print_one(argv[0].intval); |
908 | return 1; |
908 | return 1; |
909 | } |
909 | } |
910 | 910 | ||
911 | /** Command for printing task ipc details |
911 | /** Command for printing task ipc details |
912 | * |
912 | * |
913 | * @param argv Integer argument from cmdline expected |
913 | * @param argv Integer argument from cmdline expected |
914 | * |
914 | * |
915 | * return Always 1 |
915 | * return Always 1 |
916 | */ |
916 | */ |
917 | int cmd_ipc(cmd_arg_t * argv) { |
917 | int cmd_ipc(cmd_arg_t * argv) { |
918 | ipc_print_task(argv[0].intval); |
918 | ipc_print_task(argv[0].intval); |
919 | return 1; |
919 | return 1; |
920 | } |
920 | } |
921 | 921 | ||
922 | 922 | ||
923 | /** Command for listing processors. |
923 | /** Command for listing processors. |
924 | * |
924 | * |
925 | * @param argv Ignored. |
925 | * @param argv Ignored. |
926 | * |
926 | * |
927 | * return Always 1. |
927 | * return Always 1. |
928 | */ |
928 | */ |
929 | int cmd_cpus(cmd_arg_t *argv) |
929 | int cmd_cpus(cmd_arg_t *argv) |
930 | { |
930 | { |
931 | cpu_list(); |
931 | cpu_list(); |
932 | return 1; |
932 | return 1; |
933 | } |
933 | } |
934 | 934 | ||
935 | /** Command for printing kernel version. |
935 | /** Command for printing kernel version. |
936 | * |
936 | * |
937 | * @param argv Ignored. |
937 | * @param argv Ignored. |
938 | * |
938 | * |
939 | * return Always 1. |
939 | * return Always 1. |
940 | */ |
940 | */ |
941 | int cmd_version(cmd_arg_t *argv) |
941 | int cmd_version(cmd_arg_t *argv) |
942 | { |
942 | { |
943 | version_print(); |
943 | version_print(); |
944 | return 1; |
944 | return 1; |
945 | } |
945 | } |
946 | 946 | ||
947 | /** Command for returning console back to userspace. |
947 | /** Command for returning console back to userspace. |
948 | * |
948 | * |
949 | * @param argv Ignored. |
949 | * @param argv Ignored. |
950 | * |
950 | * |
951 | * return Always 1. |
951 | * return Always 1. |
952 | */ |
952 | */ |
953 | int cmd_continue(cmd_arg_t *argv) |
953 | int cmd_continue(cmd_arg_t *argv) |
954 | { |
954 | { |
955 | printf("The kernel will now relinquish the console.\n"); |
955 | printf("The kernel will now relinquish the console.\n"); |
956 | release_console(); |
956 | release_console(); |
957 | 957 | ||
958 | event_notify_0(EVENT_KCONSOLE); |
958 | event_notify_0(EVENT_KCONSOLE); |
959 | 959 | ||
960 | return 1; |
960 | return 1; |
961 | } |
961 | } |
962 | 962 | ||
963 | #ifdef CONFIG_TEST |
963 | #ifdef CONFIG_TEST |
964 | /** Command for printing kernel tests list. |
964 | /** Command for printing kernel tests list. |
965 | * |
965 | * |
966 | * @param argv Ignored. |
966 | * @param argv Ignored. |
967 | * |
967 | * |
968 | * return Always 1. |
968 | * return Always 1. |
969 | */ |
969 | */ |
970 | int cmd_tests(cmd_arg_t *argv) |
970 | int cmd_tests(cmd_arg_t *argv) |
971 | { |
971 | { |
972 | size_t len = 0; |
972 | count_t len = 0; |
973 | test_t *test; |
973 | test_t *test; |
974 | for (test = tests; test->name != NULL; test++) { |
974 | for (test = tests; test->name != NULL; test++) { |
975 | if (str_size(test->name) > len) |
975 | if (str_length(test->name) > len) |
976 | len = str_size(test->name); |
976 | len = str_length(test->name); |
977 | } |
977 | } |
978 | 978 | ||
979 | for (test = tests; test->name != NULL; test++) |
979 | for (test = tests; test->name != NULL; test++) |
980 | printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
980 | printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
981 | 981 | ||
982 | printf("%-*s Run all safe tests\n", len, "*"); |
982 | printf("%-*s Run all safe tests\n", len, "*"); |
983 | return 1; |
983 | return 1; |
984 | } |
984 | } |
985 | 985 | ||
986 | static bool run_test(const test_t *test) |
986 | static bool run_test(const test_t *test) |
987 | { |
987 | { |
988 | printf("%s (%s)\n", test->name, test->desc); |
988 | printf("%s (%s)\n", test->name, test->desc); |
989 | 989 | ||
990 | /* Update and read thread accounting |
990 | /* Update and read thread accounting |
991 | for benchmarking */ |
991 | for benchmarking */ |
992 | ipl_t ipl = interrupts_disable(); |
992 | ipl_t ipl = interrupts_disable(); |
993 | spinlock_lock(&TASK->lock); |
993 | spinlock_lock(&TASK->lock); |
994 | uint64_t t0 = task_get_accounting(TASK); |
994 | uint64_t t0 = task_get_accounting(TASK); |
995 | spinlock_unlock(&TASK->lock); |
995 | spinlock_unlock(&TASK->lock); |
996 | interrupts_restore(ipl); |
996 | interrupts_restore(ipl); |
997 | 997 | ||
998 | /* Execute the test */ |
998 | /* Execute the test */ |
999 | char * ret = test->entry(false); |
999 | char * ret = test->entry(false); |
1000 | 1000 | ||
1001 | /* Update and read thread accounting */ |
1001 | /* Update and read thread accounting */ |
1002 | ipl = interrupts_disable(); |
1002 | ipl = interrupts_disable(); |
1003 | spinlock_lock(&TASK->lock); |
1003 | spinlock_lock(&TASK->lock); |
1004 | uint64_t dt = task_get_accounting(TASK) - t0; |
1004 | uint64_t dt = task_get_accounting(TASK) - t0; |
1005 | spinlock_unlock(&TASK->lock); |
1005 | spinlock_unlock(&TASK->lock); |
1006 | interrupts_restore(ipl); |
1006 | interrupts_restore(ipl); |
1007 | 1007 | ||
1008 | uint64_t cycles; |
1008 | uint64_t cycles; |
1009 | char suffix; |
1009 | char suffix; |
1010 | order(dt, &cycles, &suffix); |
1010 | order(dt, &cycles, &suffix); |
1011 | 1011 | ||
1012 | printf("Time: %" PRIu64 "%c cycles\n", cycles, suffix); |
1012 | printf("Time: %" PRIu64 "%c cycles\n", cycles, suffix); |
1013 | 1013 | ||
1014 | if (ret == NULL) { |
1014 | if (ret == NULL) { |
1015 | printf("Test passed\n"); |
1015 | printf("Test passed\n"); |
1016 | return true; |
1016 | return true; |
1017 | } |
1017 | } |
1018 | 1018 | ||
1019 | printf("%s\n", ret); |
1019 | printf("%s\n", ret); |
1020 | return false; |
1020 | return false; |
1021 | } |
1021 | } |
1022 | 1022 | ||
1023 | static bool run_bench(const test_t *test, const uint32_t cnt) |
1023 | static bool run_bench(const test_t *test, const uint32_t cnt) |
1024 | { |
1024 | { |
1025 | uint32_t i; |
1025 | uint32_t i; |
1026 | bool ret = true; |
1026 | bool ret = true; |
1027 | uint64_t cycles; |
1027 | uint64_t cycles; |
1028 | char suffix; |
1028 | char suffix; |
1029 | 1029 | ||
1030 | if (cnt < 1) |
1030 | if (cnt < 1) |
1031 | return true; |
1031 | return true; |
1032 | 1032 | ||
1033 | uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0); |
1033 | uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0); |
1034 | if (data == NULL) { |
1034 | if (data == NULL) { |
1035 | printf("Error allocating memory for statistics\n"); |
1035 | printf("Error allocating memory for statistics\n"); |
1036 | return false; |
1036 | return false; |
1037 | } |
1037 | } |
1038 | 1038 | ||
1039 | for (i = 0; i < cnt; i++) { |
1039 | for (i = 0; i < cnt; i++) { |
1040 | printf("%s (%u/%u) ... ", test->name, i + 1, cnt); |
1040 | printf("%s (%u/%u) ... ", test->name, i + 1, cnt); |
1041 | 1041 | ||
1042 | /* Update and read thread accounting |
1042 | /* Update and read thread accounting |
1043 | for benchmarking */ |
1043 | for benchmarking */ |
1044 | ipl_t ipl = interrupts_disable(); |
1044 | ipl_t ipl = interrupts_disable(); |
1045 | spinlock_lock(&TASK->lock); |
1045 | spinlock_lock(&TASK->lock); |
1046 | uint64_t t0 = task_get_accounting(TASK); |
1046 | uint64_t t0 = task_get_accounting(TASK); |
1047 | spinlock_unlock(&TASK->lock); |
1047 | spinlock_unlock(&TASK->lock); |
1048 | interrupts_restore(ipl); |
1048 | interrupts_restore(ipl); |
1049 | 1049 | ||
1050 | /* Execute the test */ |
1050 | /* Execute the test */ |
1051 | char * ret = test->entry(true); |
1051 | char * ret = test->entry(true); |
1052 | 1052 | ||
1053 | /* Update and read thread accounting */ |
1053 | /* Update and read thread accounting */ |
1054 | ipl = interrupts_disable(); |
1054 | ipl = interrupts_disable(); |
1055 | spinlock_lock(&TASK->lock); |
1055 | spinlock_lock(&TASK->lock); |
1056 | uint64_t dt = task_get_accounting(TASK) - t0; |
1056 | uint64_t dt = task_get_accounting(TASK) - t0; |
1057 | spinlock_unlock(&TASK->lock); |
1057 | spinlock_unlock(&TASK->lock); |
1058 | interrupts_restore(ipl); |
1058 | interrupts_restore(ipl); |
1059 | 1059 | ||
1060 | if (ret != NULL) { |
1060 | if (ret != NULL) { |
1061 | printf("%s\n", ret); |
1061 | printf("%s\n", ret); |
1062 | ret = false; |
1062 | ret = false; |
1063 | break; |
1063 | break; |
1064 | } |
1064 | } |
1065 | 1065 | ||
1066 | data[i] = dt; |
1066 | data[i] = dt; |
1067 | order(dt, &cycles, &suffix); |
1067 | order(dt, &cycles, &suffix); |
1068 | printf("OK (%" PRIu64 "%c cycles)\n", cycles, suffix); |
1068 | printf("OK (%" PRIu64 "%c cycles)\n", cycles, suffix); |
1069 | } |
1069 | } |
1070 | 1070 | ||
1071 | if (ret) { |
1071 | if (ret) { |
1072 | printf("\n"); |
1072 | printf("\n"); |
1073 | 1073 | ||
1074 | uint64_t sum = 0; |
1074 | uint64_t sum = 0; |
1075 | 1075 | ||
1076 | for (i = 0; i < cnt; i++) { |
1076 | for (i = 0; i < cnt; i++) { |
1077 | sum += data[i]; |
1077 | sum += data[i]; |
1078 | } |
1078 | } |
1079 | 1079 | ||
1080 | order(sum / (uint64_t) cnt, &cycles, &suffix); |
1080 | order(sum / (uint64_t) cnt, &cycles, &suffix); |
1081 | printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix); |
1081 | printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix); |
1082 | } |
1082 | } |
1083 | 1083 | ||
1084 | free(data); |
1084 | free(data); |
1085 | 1085 | ||
1086 | return ret; |
1086 | return ret; |
1087 | } |
1087 | } |
1088 | 1088 | ||
1089 | /** Command for returning kernel tests |
1089 | /** Command for returning kernel tests |
1090 | * |
1090 | * |
1091 | * @param argv Argument vector. |
1091 | * @param argv Argument vector. |
1092 | * |
1092 | * |
1093 | * return Always 1. |
1093 | * return Always 1. |
1094 | */ |
1094 | */ |
1095 | int cmd_test(cmd_arg_t *argv) |
1095 | int cmd_test(cmd_arg_t *argv) |
1096 | { |
1096 | { |
1097 | test_t *test; |
1097 | test_t *test; |
1098 | 1098 | ||
1099 | if (strcmp((char *) argv->buffer, "*") == 0) { |
1099 | if (str_cmp((char *) argv->buffer, "*") == 0) { |
1100 | for (test = tests; test->name != NULL; test++) { |
1100 | for (test = tests; test->name != NULL; test++) { |
1101 | if (test->safe) { |
1101 | if (test->safe) { |
1102 | printf("\n"); |
1102 | printf("\n"); |
1103 | if (!run_test(test)) |
1103 | if (!run_test(test)) |
1104 | break; |
1104 | break; |
1105 | } |
1105 | } |
1106 | } |
1106 | } |
1107 | } else { |
1107 | } else { |
1108 | bool fnd = false; |
1108 | bool fnd = false; |
1109 | 1109 | ||
1110 | for (test = tests; test->name != NULL; test++) { |
1110 | for (test = tests; test->name != NULL; test++) { |
1111 | if (strcmp(test->name, (char *) argv->buffer) == 0) { |
1111 | if (str_cmp(test->name, (char *) argv->buffer) == 0) { |
1112 | fnd = true; |
1112 | fnd = true; |
1113 | run_test(test); |
1113 | run_test(test); |
1114 | break; |
1114 | break; |
1115 | } |
1115 | } |
1116 | } |
1116 | } |
1117 | 1117 | ||
1118 | if (!fnd) |
1118 | if (!fnd) |
1119 | printf("Unknown test\n"); |
1119 | printf("Unknown test\n"); |
1120 | } |
1120 | } |
1121 | 1121 | ||
1122 | return 1; |
1122 | return 1; |
1123 | } |
1123 | } |
1124 | 1124 | ||
1125 | /** Command for returning kernel tests as benchmarks |
1125 | /** Command for returning kernel tests as benchmarks |
1126 | * |
1126 | * |
1127 | * @param argv Argument vector. |
1127 | * @param argv Argument vector. |
1128 | * |
1128 | * |
1129 | * return Always 1. |
1129 | * return Always 1. |
1130 | */ |
1130 | */ |
1131 | int cmd_bench(cmd_arg_t *argv) |
1131 | int cmd_bench(cmd_arg_t *argv) |
1132 | { |
1132 | { |
1133 | test_t *test; |
1133 | test_t *test; |
1134 | uint32_t cnt = argv[1].intval; |
1134 | uint32_t cnt = argv[1].intval; |
1135 | 1135 | ||
1136 | bool fnd = false; |
1136 | bool fnd = false; |
1137 | 1137 | ||
1138 | for (test = tests; test->name != NULL; test++) { |
1138 | for (test = tests; test->name != NULL; test++) { |
1139 | if (strcmp(test->name, (char *) argv->buffer) == 0) { |
1139 | if (str_cmp(test->name, (char *) argv->buffer) == 0) { |
1140 | fnd = true; |
1140 | fnd = true; |
1141 | 1141 | ||
1142 | if (test->safe) |
1142 | if (test->safe) |
1143 | run_bench(test, cnt); |
1143 | run_bench(test, cnt); |
1144 | else |
1144 | else |
1145 | printf("Unsafe test\n"); |
1145 | printf("Unsafe test\n"); |
1146 | 1146 | ||
1147 | break; |
1147 | break; |
1148 | } |
1148 | } |
1149 | } |
1149 | } |
1150 | 1150 | ||
1151 | if (!fnd) |
1151 | if (!fnd) |
1152 | printf("Unknown test\n"); |
1152 | printf("Unknown test\n"); |
1153 | 1153 | ||
1154 | return 1; |
1154 | return 1; |
1155 | } |
1155 | } |
1156 | 1156 | ||
1157 | #endif |
1157 | #endif |
1158 | 1158 | ||
1159 | /** @} |
1159 | /** @} |
1160 | */ |
1160 | */ |
1161 | 1161 |