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