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