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