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