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