Rev 2275 | Rev 3065 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2275 | Rev 2319 | ||
---|---|---|---|
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 'tlb' command. */ |
337 | /* Data and methods for 'tlb' command. */ |
338 | static int cmd_tlb(cmd_arg_t *argv); |
338 | static int cmd_tlb(cmd_arg_t *argv); |
339 | cmd_info_t tlb_info = { |
339 | cmd_info_t tlb_info = { |
340 | .name = "tlb", |
340 | .name = "tlb", |
341 | .description = "Print TLB of current processor.", |
341 | .description = "Print TLB of current processor.", |
342 | .help = NULL, |
342 | .help = NULL, |
343 | .func = cmd_tlb, |
343 | .func = cmd_tlb, |
344 | .argc = 0, |
344 | .argc = 0, |
345 | .argv = NULL |
345 | .argv = NULL |
346 | }; |
346 | }; |
347 | 347 | ||
348 | static int cmd_threads(cmd_arg_t *argv); |
348 | static int cmd_threads(cmd_arg_t *argv); |
349 | static cmd_info_t threads_info = { |
349 | static cmd_info_t threads_info = { |
350 | .name = "threads", |
350 | .name = "threads", |
351 | .description = "List all threads.", |
351 | .description = "List all threads.", |
352 | .func = cmd_threads, |
352 | .func = cmd_threads, |
353 | .argc = 0 |
353 | .argc = 0 |
354 | }; |
354 | }; |
355 | 355 | ||
356 | static int cmd_tasks(cmd_arg_t *argv); |
356 | static int cmd_tasks(cmd_arg_t *argv); |
357 | static cmd_info_t tasks_info = { |
357 | static cmd_info_t tasks_info = { |
358 | .name = "tasks", |
358 | .name = "tasks", |
359 | .description = "List all tasks.", |
359 | .description = "List all tasks.", |
360 | .func = cmd_tasks, |
360 | .func = cmd_tasks, |
361 | .argc = 0 |
361 | .argc = 0 |
362 | }; |
362 | }; |
363 | 363 | ||
364 | 364 | ||
365 | static int cmd_sched(cmd_arg_t *argv); |
365 | static int cmd_sched(cmd_arg_t *argv); |
366 | static cmd_info_t sched_info = { |
366 | static cmd_info_t sched_info = { |
367 | .name = "scheduler", |
367 | .name = "scheduler", |
368 | .description = "List all scheduler information.", |
368 | .description = "List all scheduler information.", |
369 | .func = cmd_sched, |
369 | .func = cmd_sched, |
370 | .argc = 0 |
370 | .argc = 0 |
371 | }; |
371 | }; |
372 | 372 | ||
373 | static int cmd_slabs(cmd_arg_t *argv); |
373 | static int cmd_slabs(cmd_arg_t *argv); |
374 | static cmd_info_t slabs_info = { |
374 | static cmd_info_t slabs_info = { |
375 | .name = "slabs", |
375 | .name = "slabs", |
376 | .description = "List slab caches.", |
376 | .description = "List slab caches.", |
377 | .func = cmd_slabs, |
377 | .func = cmd_slabs, |
378 | .argc = 0 |
378 | .argc = 0 |
379 | }; |
379 | }; |
380 | 380 | ||
381 | /* Data and methods for 'zones' command */ |
381 | /* Data and methods for 'zones' command */ |
382 | static int cmd_zones(cmd_arg_t *argv); |
382 | static int cmd_zones(cmd_arg_t *argv); |
383 | static cmd_info_t zones_info = { |
383 | static cmd_info_t zones_info = { |
384 | .name = "zones", |
384 | .name = "zones", |
385 | .description = "List of memory zones.", |
385 | .description = "List of memory zones.", |
386 | .func = cmd_zones, |
386 | .func = cmd_zones, |
387 | .argc = 0 |
387 | .argc = 0 |
388 | }; |
388 | }; |
389 | 389 | ||
390 | /* Data and methods for 'ipc_task' command */ |
390 | /* Data and methods for 'ipc_task' command */ |
391 | static int cmd_ipc_task(cmd_arg_t *argv); |
391 | static int cmd_ipc_task(cmd_arg_t *argv); |
392 | static cmd_arg_t ipc_task_argv = { |
392 | static cmd_arg_t ipc_task_argv = { |
393 | .type = ARG_TYPE_INT, |
393 | .type = ARG_TYPE_INT, |
394 | }; |
394 | }; |
395 | static cmd_info_t ipc_task_info = { |
395 | static cmd_info_t ipc_task_info = { |
396 | .name = "ipc_task", |
396 | .name = "ipc_task", |
397 | .description = "ipc_task <taskid> Show IPC information of given task.", |
397 | .description = "ipc_task <taskid> Show IPC information of given task.", |
398 | .func = cmd_ipc_task, |
398 | .func = cmd_ipc_task, |
399 | .argc = 1, |
399 | .argc = 1, |
400 | .argv = &ipc_task_argv |
400 | .argv = &ipc_task_argv |
401 | }; |
401 | }; |
402 | 402 | ||
403 | /* Data and methods for 'zone' command */ |
403 | /* Data and methods for 'zone' command */ |
404 | static int cmd_zone(cmd_arg_t *argv); |
404 | static int cmd_zone(cmd_arg_t *argv); |
405 | static cmd_arg_t zone_argv = { |
405 | static cmd_arg_t zone_argv = { |
406 | .type = ARG_TYPE_INT, |
406 | .type = ARG_TYPE_INT, |
407 | }; |
407 | }; |
408 | 408 | ||
409 | static cmd_info_t zone_info = { |
409 | static cmd_info_t zone_info = { |
410 | .name = "zone", |
410 | .name = "zone", |
411 | .description = "Show memory zone structure.", |
411 | .description = "Show memory zone structure.", |
412 | .func = cmd_zone, |
412 | .func = cmd_zone, |
413 | .argc = 1, |
413 | .argc = 1, |
414 | .argv = &zone_argv |
414 | .argv = &zone_argv |
415 | }; |
415 | }; |
416 | 416 | ||
417 | /* Data and methods for 'cpus' command. */ |
417 | /* Data and methods for 'cpus' command. */ |
418 | static int cmd_cpus(cmd_arg_t *argv); |
418 | static int cmd_cpus(cmd_arg_t *argv); |
419 | cmd_info_t cpus_info = { |
419 | cmd_info_t cpus_info = { |
420 | .name = "cpus", |
420 | .name = "cpus", |
421 | .description = "List all processors.", |
421 | .description = "List all processors.", |
422 | .help = NULL, |
422 | .help = NULL, |
423 | .func = cmd_cpus, |
423 | .func = cmd_cpus, |
424 | .argc = 0, |
424 | .argc = 0, |
425 | .argv = NULL |
425 | .argv = NULL |
426 | }; |
426 | }; |
427 | 427 | ||
428 | /* Data and methods for 'version' command. */ |
428 | /* Data and methods for 'version' command. */ |
429 | static int cmd_version(cmd_arg_t *argv); |
429 | static int cmd_version(cmd_arg_t *argv); |
430 | cmd_info_t version_info = { |
430 | cmd_info_t version_info = { |
431 | .name = "version", |
431 | .name = "version", |
432 | .description = "Print version information.", |
432 | .description = "Print version information.", |
433 | .help = NULL, |
433 | .help = NULL, |
434 | .func = cmd_version, |
434 | .func = cmd_version, |
435 | .argc = 0, |
435 | .argc = 0, |
436 | .argv = NULL |
436 | .argv = NULL |
437 | }; |
437 | }; |
438 | 438 | ||
439 | static cmd_info_t *basic_commands[] = { |
439 | static cmd_info_t *basic_commands[] = { |
440 | &call0_info, |
440 | &call0_info, |
441 | &mcall0_info, |
441 | &mcall0_info, |
442 | &call1_info, |
442 | &call1_info, |
443 | &call2_info, |
443 | &call2_info, |
444 | &call3_info, |
444 | &call3_info, |
445 | &continue_info, |
445 | &continue_info, |
446 | &cpus_info, |
446 | &cpus_info, |
447 | &desc_info, |
447 | &desc_info, |
448 | &exit_info, |
448 | &exit_info, |
449 | &reboot_info, |
449 | &reboot_info, |
450 | &uptime_info, |
450 | &uptime_info, |
451 | &halt_info, |
451 | &halt_info, |
452 | &help_info, |
452 | &help_info, |
453 | &ipc_task_info, |
453 | &ipc_task_info, |
454 | &set4_info, |
454 | &set4_info, |
455 | &slabs_info, |
455 | &slabs_info, |
456 | &symaddr_info, |
456 | &symaddr_info, |
457 | &sched_info, |
457 | &sched_info, |
458 | &threads_info, |
458 | &threads_info, |
459 | &tasks_info, |
459 | &tasks_info, |
460 | &tlb_info, |
460 | &tlb_info, |
461 | &version_info, |
461 | &version_info, |
462 | &zones_info, |
462 | &zones_info, |
463 | &zone_info, |
463 | &zone_info, |
464 | #ifdef CONFIG_TEST |
464 | #ifdef CONFIG_TEST |
465 | &tests_info, |
465 | &tests_info, |
466 | &test_info, |
466 | &test_info, |
467 | &bench_info, |
467 | &bench_info, |
468 | #endif |
468 | #endif |
469 | NULL |
469 | NULL |
470 | }; |
470 | }; |
471 | 471 | ||
472 | 472 | ||
473 | /** Initialize command info structure. |
473 | /** Initialize command info structure. |
474 | * |
474 | * |
475 | * @param cmd Command info structure. |
475 | * @param cmd Command info structure. |
476 | * |
476 | * |
477 | */ |
477 | */ |
478 | void cmd_initialize(cmd_info_t *cmd) |
478 | void cmd_initialize(cmd_info_t *cmd) |
479 | { |
479 | { |
480 | spinlock_initialize(&cmd->lock, "cmd"); |
480 | spinlock_initialize(&cmd->lock, "cmd"); |
481 | link_initialize(&cmd->link); |
481 | link_initialize(&cmd->link); |
482 | } |
482 | } |
483 | 483 | ||
484 | /** Initialize and register commands. */ |
484 | /** Initialize and register commands. */ |
485 | void cmd_init(void) |
485 | void cmd_init(void) |
486 | { |
486 | { |
487 | int i; |
487 | int i; |
488 | 488 | ||
489 | for (i=0;basic_commands[i]; i++) { |
489 | for (i=0;basic_commands[i]; i++) { |
490 | cmd_initialize(basic_commands[i]); |
490 | cmd_initialize(basic_commands[i]); |
491 | if (!cmd_register(basic_commands[i])) |
491 | if (!cmd_register(basic_commands[i])) |
492 | panic("could not register command %s\n", |
492 | panic("could not register command %s\n", |
493 | basic_commands[i]->name); |
493 | basic_commands[i]->name); |
494 | } |
494 | } |
495 | } |
495 | } |
496 | 496 | ||
497 | 497 | ||
498 | /** List supported commands. |
498 | /** List supported commands. |
499 | * |
499 | * |
500 | * @param argv Argument vector. |
500 | * @param argv Argument vector. |
501 | * |
501 | * |
502 | * @return 0 on failure, 1 on success. |
502 | * @return 0 on failure, 1 on success. |
503 | */ |
503 | */ |
504 | int cmd_help(cmd_arg_t *argv) |
504 | int cmd_help(cmd_arg_t *argv) |
505 | { |
505 | { |
506 | link_t *cur; |
506 | link_t *cur; |
507 | 507 | ||
508 | spinlock_lock(&cmd_lock); |
508 | spinlock_lock(&cmd_lock); |
509 | 509 | ||
510 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
510 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
511 | cmd_info_t *hlp; |
511 | cmd_info_t *hlp; |
512 | 512 | ||
513 | hlp = list_get_instance(cur, cmd_info_t, link); |
513 | hlp = list_get_instance(cur, cmd_info_t, link); |
514 | spinlock_lock(&hlp->lock); |
514 | spinlock_lock(&hlp->lock); |
515 | 515 | ||
516 | printf("%s - %s\n", hlp->name, hlp->description); |
516 | printf("%s - %s\n", hlp->name, hlp->description); |
517 | 517 | ||
518 | spinlock_unlock(&hlp->lock); |
518 | spinlock_unlock(&hlp->lock); |
519 | } |
519 | } |
520 | 520 | ||
521 | spinlock_unlock(&cmd_lock); |
521 | spinlock_unlock(&cmd_lock); |
522 | 522 | ||
523 | return 1; |
523 | return 1; |
524 | } |
524 | } |
525 | 525 | ||
526 | 526 | ||
527 | /** Reboot the system. |
527 | /** Reboot the system. |
528 | * |
528 | * |
529 | * @param argv Argument vector. |
529 | * @param argv Argument vector. |
530 | * |
530 | * |
531 | * @return 0 on failure, 1 on success. |
531 | * @return 0 on failure, 1 on success. |
532 | */ |
532 | */ |
533 | int cmd_reboot(cmd_arg_t *argv) |
533 | int cmd_reboot(cmd_arg_t *argv) |
534 | { |
534 | { |
535 | reboot(); |
535 | reboot(); |
536 | 536 | ||
537 | /* Not reached */ |
537 | /* Not reached */ |
538 | return 1; |
538 | return 1; |
539 | } |
539 | } |
540 | 540 | ||
541 | 541 | ||
542 | /** Print system uptime information. |
542 | /** Print system uptime information. |
543 | * |
543 | * |
544 | * @param argv Argument vector. |
544 | * @param argv Argument vector. |
545 | * |
545 | * |
546 | * @return 0 on failure, 1 on success. |
546 | * @return 0 on failure, 1 on success. |
547 | */ |
547 | */ |
548 | int cmd_uptime(cmd_arg_t *argv) |
548 | int cmd_uptime(cmd_arg_t *argv) |
549 | { |
549 | { |
550 | ASSERT(uptime); |
550 | ASSERT(uptime); |
551 | 551 | ||
552 | /* This doesn't have to be very accurate */ |
552 | /* This doesn't have to be very accurate */ |
553 | unative_t sec = uptime->seconds1; |
553 | unative_t sec = uptime->seconds1; |
554 | 554 | ||
555 | printf("Up %u days, %u hours, %u minutes, %u seconds\n", |
555 | printf("Up %u days, %u hours, %u minutes, %u seconds\n", |
556 | sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); |
556 | sec / 86400, (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); |
557 | 557 | ||
558 | return 1; |
558 | return 1; |
559 | } |
559 | } |
560 | 560 | ||
561 | /** Describe specified command. |
561 | /** Describe specified command. |
562 | * |
562 | * |
563 | * @param argv Argument vector. |
563 | * @param argv Argument vector. |
564 | * |
564 | * |
565 | * @return 0 on failure, 1 on success. |
565 | * @return 0 on failure, 1 on success. |
566 | */ |
566 | */ |
567 | int cmd_desc(cmd_arg_t *argv) |
567 | int cmd_desc(cmd_arg_t *argv) |
568 | { |
568 | { |
569 | link_t *cur; |
569 | link_t *cur; |
570 | 570 | ||
571 | spinlock_lock(&cmd_lock); |
571 | spinlock_lock(&cmd_lock); |
572 | 572 | ||
573 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
573 | for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
574 | cmd_info_t *hlp; |
574 | cmd_info_t *hlp; |
575 | 575 | ||
576 | hlp = list_get_instance(cur, cmd_info_t, link); |
576 | hlp = list_get_instance(cur, cmd_info_t, link); |
577 | spinlock_lock(&hlp->lock); |
577 | spinlock_lock(&hlp->lock); |
578 | 578 | ||
579 | if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) { |
579 | if (strncmp(hlp->name, (const char *) argv->buffer, strlen(hlp->name)) == 0) { |
580 | printf("%s - %s\n", hlp->name, hlp->description); |
580 | printf("%s - %s\n", hlp->name, hlp->description); |
581 | if (hlp->help) |
581 | if (hlp->help) |
582 | hlp->help(); |
582 | hlp->help(); |
583 | spinlock_unlock(&hlp->lock); |
583 | spinlock_unlock(&hlp->lock); |
584 | break; |
584 | break; |
585 | } |
585 | } |
586 | 586 | ||
587 | spinlock_unlock(&hlp->lock); |
587 | spinlock_unlock(&hlp->lock); |
588 | } |
588 | } |
589 | 589 | ||
590 | spinlock_unlock(&cmd_lock); |
590 | spinlock_unlock(&cmd_lock); |
591 | 591 | ||
592 | return 1; |
592 | return 1; |
593 | } |
593 | } |
594 | 594 | ||
595 | /** Search symbol table */ |
595 | /** Search symbol table */ |
596 | int cmd_symaddr(cmd_arg_t *argv) |
596 | int cmd_symaddr(cmd_arg_t *argv) |
597 | { |
597 | { |
598 | symtab_print_search((char *) argv->buffer); |
598 | symtab_print_search((char *) argv->buffer); |
599 | 599 | ||
600 | return 1; |
600 | return 1; |
601 | } |
601 | } |
602 | 602 | ||
603 | /** Call function with zero parameters */ |
603 | /** Call function with zero parameters */ |
604 | int cmd_call0(cmd_arg_t *argv) |
604 | int cmd_call0(cmd_arg_t *argv) |
605 | { |
605 | { |
606 | uintptr_t symaddr; |
606 | uintptr_t symaddr; |
607 | char *symbol; |
607 | char *symbol; |
608 | unative_t (*f)(void); |
608 | unative_t (*f)(void); |
609 | #ifdef ia64 |
609 | #ifdef ia64 |
610 | struct { |
610 | struct { |
611 | unative_t f; |
611 | unative_t f; |
612 | unative_t gp; |
612 | unative_t gp; |
613 | } fptr; |
613 | } fptr; |
614 | #endif |
614 | #endif |
615 | 615 | ||
616 | symaddr = get_symbol_addr((char *) argv->buffer); |
616 | symaddr = get_symbol_addr((char *) argv->buffer); |
617 | if (!symaddr) |
617 | if (!symaddr) |
618 | printf("Symbol %s not found.\n", argv->buffer); |
618 | printf("Symbol %s not found.\n", argv->buffer); |
619 | else if (symaddr == (uintptr_t) -1) { |
619 | else if (symaddr == (uintptr_t) -1) { |
620 | symtab_print_search((char *) argv->buffer); |
620 | symtab_print_search((char *) argv->buffer); |
621 | printf("Duplicate symbol, be more specific.\n"); |
621 | printf("Duplicate symbol, be more specific.\n"); |
622 | } else { |
622 | } else { |
623 | symbol = get_symtab_entry(symaddr); |
623 | symbol = get_symtab_entry(symaddr); |
624 | printf("Calling %s() (%.*p)\n", symbol, sizeof(uintptr_t) * 2, symaddr); |
624 | printf("Calling %s() (%.*p)\n", symbol, sizeof(uintptr_t) * 2, symaddr); |
625 | #ifdef ia64 |
625 | #ifdef ia64 |
626 | fptr.f = symaddr; |
626 | fptr.f = symaddr; |
627 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
627 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
628 | f = (unative_t (*)(void)) &fptr; |
628 | f = (unative_t (*)(void)) &fptr; |
629 | #else |
629 | #else |
630 | f = (unative_t (*)(void)) symaddr; |
630 | f = (unative_t (*)(void)) symaddr; |
631 | #endif |
631 | #endif |
632 | printf("Result: %#zx\n", f()); |
632 | printf("Result: %#zx\n", f()); |
633 | } |
633 | } |
634 | 634 | ||
635 | return 1; |
635 | return 1; |
636 | } |
636 | } |
637 | 637 | ||
638 | /** Call function with zero parameters on each CPU */ |
638 | /** Call function with zero parameters on each CPU */ |
639 | int cmd_mcall0(cmd_arg_t *argv) |
639 | int cmd_mcall0(cmd_arg_t *argv) |
640 | { |
640 | { |
641 | /* |
641 | /* |
642 | * For each CPU, create a thread which will |
642 | * For each CPU, create a thread which will |
643 | * call the function. |
643 | * call the function. |
644 | */ |
644 | */ |
645 | 645 | ||
646 | count_t i; |
646 | count_t i; |
647 | for (i = 0; i < config.cpu_count; i++) { |
647 | for (i = 0; i < config.cpu_count; i++) { |
- | 648 | if (!cpus[i].active) |
|
- | 649 | continue; |
|
- | 650 | ||
648 | thread_t *t; |
651 | thread_t *t; |
649 | if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) { |
652 | if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) { |
650 | spinlock_lock(&t->lock); |
653 | spinlock_lock(&t->lock); |
651 | t->cpu = &cpus[i]; |
654 | t->cpu = &cpus[i]; |
652 | spinlock_unlock(&t->lock); |
655 | spinlock_unlock(&t->lock); |
653 | printf("cpu%u: ", i); |
656 | printf("cpu%u: ", i); |
654 | thread_ready(t); |
657 | thread_ready(t); |
655 | thread_join(t); |
658 | thread_join(t); |
656 | thread_detach(t); |
659 | thread_detach(t); |
657 | } else |
660 | } else |
658 | printf("Unable to create thread for cpu%u\n", i); |
661 | printf("Unable to create thread for cpu%u\n", i); |
659 | } |
662 | } |
660 | 663 | ||
661 | return 1; |
664 | return 1; |
662 | } |
665 | } |
663 | 666 | ||
664 | /** Call function with one parameter */ |
667 | /** Call function with one parameter */ |
665 | int cmd_call1(cmd_arg_t *argv) |
668 | int cmd_call1(cmd_arg_t *argv) |
666 | { |
669 | { |
667 | uintptr_t symaddr; |
670 | uintptr_t symaddr; |
668 | char *symbol; |
671 | char *symbol; |
669 | unative_t (*f)(unative_t,...); |
672 | unative_t (*f)(unative_t,...); |
670 | unative_t arg1 = argv[1].intval; |
673 | unative_t arg1 = argv[1].intval; |
671 | #ifdef ia64 |
674 | #ifdef ia64 |
672 | struct { |
675 | struct { |
673 | unative_t f; |
676 | unative_t f; |
674 | unative_t gp; |
677 | unative_t gp; |
675 | }fptr; |
678 | }fptr; |
676 | #endif |
679 | #endif |
677 | 680 | ||
678 | symaddr = get_symbol_addr((char *) argv->buffer); |
681 | symaddr = get_symbol_addr((char *) argv->buffer); |
679 | if (!symaddr) |
682 | if (!symaddr) |
680 | printf("Symbol %s not found.\n", argv->buffer); |
683 | printf("Symbol %s not found.\n", argv->buffer); |
681 | else if (symaddr == (uintptr_t) -1) { |
684 | else if (symaddr == (uintptr_t) -1) { |
682 | symtab_print_search((char *) argv->buffer); |
685 | symtab_print_search((char *) argv->buffer); |
683 | printf("Duplicate symbol, be more specific.\n"); |
686 | printf("Duplicate symbol, be more specific.\n"); |
684 | } else { |
687 | } else { |
685 | symbol = get_symtab_entry(symaddr); |
688 | symbol = get_symtab_entry(symaddr); |
686 | 689 | ||
687 | printf("Calling f(%#zx): %.*p: %s\n", arg1, sizeof(uintptr_t) * 2, symaddr, symbol); |
690 | printf("Calling f(%#zx): %.*p: %s\n", arg1, sizeof(uintptr_t) * 2, symaddr, symbol); |
688 | #ifdef ia64 |
691 | #ifdef ia64 |
689 | fptr.f = symaddr; |
692 | fptr.f = symaddr; |
690 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
693 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
691 | f = (unative_t (*)(unative_t,...)) &fptr; |
694 | f = (unative_t (*)(unative_t,...)) &fptr; |
692 | #else |
695 | #else |
693 | f = (unative_t (*)(unative_t,...)) symaddr; |
696 | f = (unative_t (*)(unative_t,...)) symaddr; |
694 | #endif |
697 | #endif |
695 | printf("Result: %#zx\n", f(arg1)); |
698 | printf("Result: %#zx\n", f(arg1)); |
696 | } |
699 | } |
697 | 700 | ||
698 | return 1; |
701 | return 1; |
699 | } |
702 | } |
700 | 703 | ||
701 | /** Call function with two parameters */ |
704 | /** Call function with two parameters */ |
702 | int cmd_call2(cmd_arg_t *argv) |
705 | int cmd_call2(cmd_arg_t *argv) |
703 | { |
706 | { |
704 | uintptr_t symaddr; |
707 | uintptr_t symaddr; |
705 | char *symbol; |
708 | char *symbol; |
706 | unative_t (*f)(unative_t,unative_t,...); |
709 | unative_t (*f)(unative_t,unative_t,...); |
707 | unative_t arg1 = argv[1].intval; |
710 | unative_t arg1 = argv[1].intval; |
708 | unative_t arg2 = argv[2].intval; |
711 | unative_t arg2 = argv[2].intval; |
709 | #ifdef ia64 |
712 | #ifdef ia64 |
710 | struct { |
713 | struct { |
711 | unative_t f; |
714 | unative_t f; |
712 | unative_t gp; |
715 | unative_t gp; |
713 | }fptr; |
716 | }fptr; |
714 | #endif |
717 | #endif |
715 | 718 | ||
716 | symaddr = get_symbol_addr((char *) argv->buffer); |
719 | symaddr = get_symbol_addr((char *) argv->buffer); |
717 | if (!symaddr) |
720 | if (!symaddr) |
718 | printf("Symbol %s not found.\n", argv->buffer); |
721 | printf("Symbol %s not found.\n", argv->buffer); |
719 | else if (symaddr == (uintptr_t) -1) { |
722 | else if (symaddr == (uintptr_t) -1) { |
720 | symtab_print_search((char *) argv->buffer); |
723 | symtab_print_search((char *) argv->buffer); |
721 | printf("Duplicate symbol, be more specific.\n"); |
724 | printf("Duplicate symbol, be more specific.\n"); |
722 | } else { |
725 | } else { |
723 | symbol = get_symtab_entry(symaddr); |
726 | symbol = get_symtab_entry(symaddr); |
724 | printf("Calling f(0x%zx,0x%zx): %.*p: %s\n", |
727 | printf("Calling f(0x%zx,0x%zx): %.*p: %s\n", |
725 | arg1, arg2, sizeof(uintptr_t) * 2, symaddr, symbol); |
728 | arg1, arg2, sizeof(uintptr_t) * 2, symaddr, symbol); |
726 | #ifdef ia64 |
729 | #ifdef ia64 |
727 | fptr.f = symaddr; |
730 | fptr.f = symaddr; |
728 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
731 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
729 | f = (unative_t (*)(unative_t,unative_t,...)) &fptr; |
732 | f = (unative_t (*)(unative_t,unative_t,...)) &fptr; |
730 | #else |
733 | #else |
731 | f = (unative_t (*)(unative_t,unative_t,...)) symaddr; |
734 | f = (unative_t (*)(unative_t,unative_t,...)) symaddr; |
732 | #endif |
735 | #endif |
733 | printf("Result: %#zx\n", f(arg1, arg2)); |
736 | printf("Result: %#zx\n", f(arg1, arg2)); |
734 | } |
737 | } |
735 | 738 | ||
736 | return 1; |
739 | return 1; |
737 | } |
740 | } |
738 | 741 | ||
739 | /** Call function with three parameters */ |
742 | /** Call function with three parameters */ |
740 | int cmd_call3(cmd_arg_t *argv) |
743 | int cmd_call3(cmd_arg_t *argv) |
741 | { |
744 | { |
742 | uintptr_t symaddr; |
745 | uintptr_t symaddr; |
743 | char *symbol; |
746 | char *symbol; |
744 | unative_t (*f)(unative_t,unative_t,unative_t,...); |
747 | unative_t (*f)(unative_t,unative_t,unative_t,...); |
745 | unative_t arg1 = argv[1].intval; |
748 | unative_t arg1 = argv[1].intval; |
746 | unative_t arg2 = argv[2].intval; |
749 | unative_t arg2 = argv[2].intval; |
747 | unative_t arg3 = argv[3].intval; |
750 | unative_t arg3 = argv[3].intval; |
748 | #ifdef ia64 |
751 | #ifdef ia64 |
749 | struct { |
752 | struct { |
750 | unative_t f; |
753 | unative_t f; |
751 | unative_t gp; |
754 | unative_t gp; |
752 | }fptr; |
755 | }fptr; |
753 | #endif |
756 | #endif |
754 | 757 | ||
755 | symaddr = get_symbol_addr((char *) argv->buffer); |
758 | symaddr = get_symbol_addr((char *) argv->buffer); |
756 | if (!symaddr) |
759 | if (!symaddr) |
757 | printf("Symbol %s not found.\n", argv->buffer); |
760 | printf("Symbol %s not found.\n", argv->buffer); |
758 | else if (symaddr == (uintptr_t) -1) { |
761 | else if (symaddr == (uintptr_t) -1) { |
759 | symtab_print_search((char *) argv->buffer); |
762 | symtab_print_search((char *) argv->buffer); |
760 | printf("Duplicate symbol, be more specific.\n"); |
763 | printf("Duplicate symbol, be more specific.\n"); |
761 | } else { |
764 | } else { |
762 | symbol = get_symtab_entry(symaddr); |
765 | symbol = get_symtab_entry(symaddr); |
763 | printf("Calling f(0x%zx,0x%zx, 0x%zx): %.*p: %s\n", |
766 | printf("Calling f(0x%zx,0x%zx, 0x%zx): %.*p: %s\n", |
764 | arg1, arg2, arg3, sizeof(uintptr_t) * 2, symaddr, symbol); |
767 | arg1, arg2, arg3, sizeof(uintptr_t) * 2, symaddr, symbol); |
765 | #ifdef ia64 |
768 | #ifdef ia64 |
766 | fptr.f = symaddr; |
769 | fptr.f = symaddr; |
767 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
770 | fptr.gp = ((unative_t *)cmd_call2)[1]; |
768 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr; |
771 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr; |
769 | #else |
772 | #else |
770 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr; |
773 | f = (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr; |
771 | #endif |
774 | #endif |
772 | printf("Result: %#zx\n", f(arg1, arg2, arg3)); |
775 | printf("Result: %#zx\n", f(arg1, arg2, arg3)); |
773 | } |
776 | } |
774 | 777 | ||
775 | return 1; |
778 | return 1; |
776 | } |
779 | } |
777 | 780 | ||
778 | 781 | ||
779 | /** Print detailed description of 'describe' command. */ |
782 | /** Print detailed description of 'describe' command. */ |
780 | void desc_help(void) |
783 | void desc_help(void) |
781 | { |
784 | { |
782 | printf("Syntax: describe command_name\n"); |
785 | printf("Syntax: describe command_name\n"); |
783 | } |
786 | } |
784 | 787 | ||
785 | /** Halt the kernel. |
788 | /** Halt the kernel. |
786 | * |
789 | * |
787 | * @param argv Argument vector (ignored). |
790 | * @param argv Argument vector (ignored). |
788 | * |
791 | * |
789 | * @return 0 on failure, 1 on success (never returns). |
792 | * @return 0 on failure, 1 on success (never returns). |
790 | */ |
793 | */ |
791 | int cmd_halt(cmd_arg_t *argv) |
794 | int cmd_halt(cmd_arg_t *argv) |
792 | { |
795 | { |
793 | halt(); |
796 | halt(); |
794 | return 1; |
797 | return 1; |
795 | } |
798 | } |
796 | 799 | ||
797 | /** Command for printing TLB contents. |
800 | /** Command for printing TLB contents. |
798 | * |
801 | * |
799 | * @param argv Not used. |
802 | * @param argv Not used. |
800 | * |
803 | * |
801 | * @return Always returns 1. |
804 | * @return Always returns 1. |
802 | */ |
805 | */ |
803 | int cmd_tlb(cmd_arg_t *argv) |
806 | int cmd_tlb(cmd_arg_t *argv) |
804 | { |
807 | { |
805 | tlb_print(); |
808 | tlb_print(); |
806 | return 1; |
809 | return 1; |
807 | } |
810 | } |
808 | 811 | ||
809 | /** Write 4 byte value to address */ |
812 | /** Write 4 byte value to address */ |
810 | int cmd_set4(cmd_arg_t *argv) |
813 | int cmd_set4(cmd_arg_t *argv) |
811 | { |
814 | { |
812 | uint32_t *addr; |
815 | uint32_t *addr; |
813 | uint32_t arg1 = argv[1].intval; |
816 | uint32_t arg1 = argv[1].intval; |
814 | bool pointer = false; |
817 | bool pointer = false; |
815 | 818 | ||
816 | if (((char *)argv->buffer)[0] == '*') { |
819 | if (((char *)argv->buffer)[0] == '*') { |
817 | addr = (uint32_t *) get_symbol_addr((char *) argv->buffer + 1); |
820 | addr = (uint32_t *) get_symbol_addr((char *) argv->buffer + 1); |
818 | pointer = true; |
821 | pointer = true; |
819 | } else if (((char *) argv->buffer)[0] >= '0' && |
822 | } else if (((char *) argv->buffer)[0] >= '0' && |
820 | ((char *)argv->buffer)[0] <= '9') |
823 | ((char *)argv->buffer)[0] <= '9') |
821 | addr = (uint32_t *)atoi((char *)argv->buffer); |
824 | addr = (uint32_t *)atoi((char *)argv->buffer); |
822 | else |
825 | else |
823 | addr = (uint32_t *)get_symbol_addr((char *) argv->buffer); |
826 | addr = (uint32_t *)get_symbol_addr((char *) argv->buffer); |
824 | 827 | ||
825 | if (!addr) |
828 | if (!addr) |
826 | printf("Symbol %s not found.\n", argv->buffer); |
829 | printf("Symbol %s not found.\n", argv->buffer); |
827 | else if (addr == (uint32_t *) -1) { |
830 | else if (addr == (uint32_t *) -1) { |
828 | symtab_print_search((char *) argv->buffer); |
831 | symtab_print_search((char *) argv->buffer); |
829 | printf("Duplicate symbol, be more specific.\n"); |
832 | printf("Duplicate symbol, be more specific.\n"); |
830 | } else { |
833 | } else { |
831 | if (pointer) |
834 | if (pointer) |
832 | addr = (uint32_t *)(*(unative_t *)addr); |
835 | addr = (uint32_t *)(*(unative_t *)addr); |
833 | printf("Writing 0x%x -> %.*p\n", arg1, sizeof(uintptr_t) * 2, addr); |
836 | printf("Writing 0x%x -> %.*p\n", arg1, sizeof(uintptr_t) * 2, addr); |
834 | *addr = arg1; |
837 | *addr = arg1; |
835 | 838 | ||
836 | } |
839 | } |
837 | 840 | ||
838 | return 1; |
841 | return 1; |
839 | } |
842 | } |
840 | 843 | ||
841 | /** Command for listings SLAB caches |
844 | /** Command for listings SLAB caches |
842 | * |
845 | * |
843 | * @param argv Ignores |
846 | * @param argv Ignores |
844 | * |
847 | * |
845 | * @return Always 1 |
848 | * @return Always 1 |
846 | */ |
849 | */ |
847 | int cmd_slabs(cmd_arg_t * argv) { |
850 | int cmd_slabs(cmd_arg_t * argv) { |
848 | slab_print_list(); |
851 | slab_print_list(); |
849 | return 1; |
852 | return 1; |
850 | } |
853 | } |
851 | 854 | ||
852 | 855 | ||
853 | /** Command for listings Thread information |
856 | /** Command for listings Thread information |
854 | * |
857 | * |
855 | * @param argv Ignores |
858 | * @param argv Ignores |
856 | * |
859 | * |
857 | * @return Always 1 |
860 | * @return Always 1 |
858 | */ |
861 | */ |
859 | int cmd_threads(cmd_arg_t * argv) { |
862 | int cmd_threads(cmd_arg_t * argv) { |
860 | thread_print_list(); |
863 | thread_print_list(); |
861 | return 1; |
864 | return 1; |
862 | } |
865 | } |
863 | 866 | ||
864 | /** Command for listings Task information |
867 | /** Command for listings Task information |
865 | * |
868 | * |
866 | * @param argv Ignores |
869 | * @param argv Ignores |
867 | * |
870 | * |
868 | * @return Always 1 |
871 | * @return Always 1 |
869 | */ |
872 | */ |
870 | int cmd_tasks(cmd_arg_t * argv) { |
873 | int cmd_tasks(cmd_arg_t * argv) { |
871 | task_print_list(); |
874 | task_print_list(); |
872 | return 1; |
875 | return 1; |
873 | } |
876 | } |
874 | 877 | ||
875 | /** Command for listings Thread information |
878 | /** Command for listings Thread information |
876 | * |
879 | * |
877 | * @param argv Ignores |
880 | * @param argv Ignores |
878 | * |
881 | * |
879 | * @return Always 1 |
882 | * @return Always 1 |
880 | */ |
883 | */ |
881 | int cmd_sched(cmd_arg_t * argv) { |
884 | int cmd_sched(cmd_arg_t * argv) { |
882 | sched_print_list(); |
885 | sched_print_list(); |
883 | return 1; |
886 | return 1; |
884 | } |
887 | } |
885 | 888 | ||
886 | /** Command for listing memory zones |
889 | /** Command for listing memory zones |
887 | * |
890 | * |
888 | * @param argv Ignored |
891 | * @param argv Ignored |
889 | * |
892 | * |
890 | * return Always 1 |
893 | * return Always 1 |
891 | */ |
894 | */ |
892 | int cmd_zones(cmd_arg_t * argv) { |
895 | int cmd_zones(cmd_arg_t * argv) { |
893 | zone_print_list(); |
896 | zone_print_list(); |
894 | return 1; |
897 | return 1; |
895 | } |
898 | } |
896 | 899 | ||
897 | /** Command for memory zone details |
900 | /** Command for memory zone details |
898 | * |
901 | * |
899 | * @param argv Integer argument from cmdline expected |
902 | * @param argv Integer argument from cmdline expected |
900 | * |
903 | * |
901 | * return Always 1 |
904 | * return Always 1 |
902 | */ |
905 | */ |
903 | int cmd_zone(cmd_arg_t * argv) { |
906 | int cmd_zone(cmd_arg_t * argv) { |
904 | zone_print_one(argv[0].intval); |
907 | zone_print_one(argv[0].intval); |
905 | return 1; |
908 | return 1; |
906 | } |
909 | } |
907 | 910 | ||
908 | /** Command for printing task ipc details |
911 | /** Command for printing task ipc details |
909 | * |
912 | * |
910 | * @param argv Integer argument from cmdline expected |
913 | * @param argv Integer argument from cmdline expected |
911 | * |
914 | * |
912 | * return Always 1 |
915 | * return Always 1 |
913 | */ |
916 | */ |
914 | int cmd_ipc_task(cmd_arg_t * argv) { |
917 | int cmd_ipc_task(cmd_arg_t * argv) { |
915 | ipc_print_task(argv[0].intval); |
918 | ipc_print_task(argv[0].intval); |
916 | return 1; |
919 | return 1; |
917 | } |
920 | } |
918 | 921 | ||
919 | 922 | ||
920 | /** Command for listing processors. |
923 | /** Command for listing processors. |
921 | * |
924 | * |
922 | * @param argv Ignored. |
925 | * @param argv Ignored. |
923 | * |
926 | * |
924 | * return Always 1. |
927 | * return Always 1. |
925 | */ |
928 | */ |
926 | int cmd_cpus(cmd_arg_t *argv) |
929 | int cmd_cpus(cmd_arg_t *argv) |
927 | { |
930 | { |
928 | cpu_list(); |
931 | cpu_list(); |
929 | return 1; |
932 | return 1; |
930 | } |
933 | } |
931 | 934 | ||
932 | /** Command for printing kernel version. |
935 | /** Command for printing kernel version. |
933 | * |
936 | * |
934 | * @param argv Ignored. |
937 | * @param argv Ignored. |
935 | * |
938 | * |
936 | * return Always 1. |
939 | * return Always 1. |
937 | */ |
940 | */ |
938 | int cmd_version(cmd_arg_t *argv) |
941 | int cmd_version(cmd_arg_t *argv) |
939 | { |
942 | { |
940 | version_print(); |
943 | version_print(); |
941 | return 1; |
944 | return 1; |
942 | } |
945 | } |
943 | 946 | ||
944 | /** Command for returning console back to userspace. |
947 | /** Command for returning console back to userspace. |
945 | * |
948 | * |
946 | * @param argv Ignored. |
949 | * @param argv Ignored. |
947 | * |
950 | * |
948 | * return Always 1. |
951 | * return Always 1. |
949 | */ |
952 | */ |
950 | int cmd_continue(cmd_arg_t *argv) |
953 | int cmd_continue(cmd_arg_t *argv) |
951 | { |
954 | { |
952 | printf("The kernel will now relinquish the console.\n"); |
955 | printf("The kernel will now relinquish the console.\n"); |
953 | printf("Use userspace controls to redraw the screen.\n"); |
956 | printf("Use userspace controls to redraw the screen.\n"); |
954 | arch_release_console(); |
957 | arch_release_console(); |
955 | return 1; |
958 | return 1; |
956 | } |
959 | } |
957 | 960 | ||
958 | #ifdef CONFIG_TEST |
961 | #ifdef CONFIG_TEST |
959 | /** Command for printing kernel tests list. |
962 | /** Command for printing kernel tests list. |
960 | * |
963 | * |
961 | * @param argv Ignored. |
964 | * @param argv Ignored. |
962 | * |
965 | * |
963 | * return Always 1. |
966 | * return Always 1. |
964 | */ |
967 | */ |
965 | int cmd_tests(cmd_arg_t *argv) |
968 | int cmd_tests(cmd_arg_t *argv) |
966 | { |
969 | { |
967 | test_t *test; |
970 | test_t *test; |
968 | 971 | ||
969 | for (test = tests; test->name != NULL; test++) |
972 | for (test = tests; test->name != NULL; test++) |
970 | printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
973 | printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
971 | 974 | ||
972 | printf("*\t\tRun all safe tests\n"); |
975 | printf("*\t\tRun all safe tests\n"); |
973 | return 1; |
976 | return 1; |
974 | } |
977 | } |
975 | 978 | ||
976 | static bool run_test(const test_t *test) |
979 | static bool run_test(const test_t *test) |
977 | { |
980 | { |
978 | printf("%s\t\t%s\n", test->name, test->desc); |
981 | printf("%s\t\t%s\n", test->name, test->desc); |
979 | 982 | ||
980 | /* Update and read thread accounting |
983 | /* Update and read thread accounting |
981 | for benchmarking */ |
984 | for benchmarking */ |
982 | ipl_t ipl = interrupts_disable(); |
985 | ipl_t ipl = interrupts_disable(); |
983 | spinlock_lock(&TASK->lock); |
986 | spinlock_lock(&TASK->lock); |
984 | uint64_t t0 = task_get_accounting(TASK); |
987 | uint64_t t0 = task_get_accounting(TASK); |
985 | spinlock_unlock(&TASK->lock); |
988 | spinlock_unlock(&TASK->lock); |
986 | interrupts_restore(ipl); |
989 | interrupts_restore(ipl); |
987 | 990 | ||
988 | /* Execute the test */ |
991 | /* Execute the test */ |
989 | char * ret = test->entry(false); |
992 | char * ret = test->entry(false); |
990 | 993 | ||
991 | /* Update and read thread accounting */ |
994 | /* Update and read thread accounting */ |
992 | ipl = interrupts_disable(); |
995 | ipl = interrupts_disable(); |
993 | spinlock_lock(&TASK->lock); |
996 | spinlock_lock(&TASK->lock); |
994 | uint64_t dt = task_get_accounting(TASK) - t0; |
997 | uint64_t dt = task_get_accounting(TASK) - t0; |
995 | spinlock_unlock(&TASK->lock); |
998 | spinlock_unlock(&TASK->lock); |
996 | interrupts_restore(ipl); |
999 | interrupts_restore(ipl); |
997 | 1000 | ||
998 | uint64_t cycles; |
1001 | uint64_t cycles; |
999 | char suffix; |
1002 | char suffix; |
1000 | order(dt, &cycles, &suffix); |
1003 | order(dt, &cycles, &suffix); |
1001 | 1004 | ||
1002 | printf("Time: %llu%c cycles\n", cycles, suffix); |
1005 | printf("Time: %llu%c cycles\n", cycles, suffix); |
1003 | 1006 | ||
1004 | if (ret == NULL) { |
1007 | if (ret == NULL) { |
1005 | printf("Test passed\n"); |
1008 | printf("Test passed\n"); |
1006 | return true; |
1009 | return true; |
1007 | } |
1010 | } |
1008 | 1011 | ||
1009 | printf("%s\n", ret); |
1012 | printf("%s\n", ret); |
1010 | return false; |
1013 | return false; |
1011 | } |
1014 | } |
1012 | 1015 | ||
1013 | static bool run_bench(const test_t *test, const uint32_t cnt) |
1016 | static bool run_bench(const test_t *test, const uint32_t cnt) |
1014 | { |
1017 | { |
1015 | uint32_t i; |
1018 | uint32_t i; |
1016 | bool ret = true; |
1019 | bool ret = true; |
1017 | uint64_t cycles; |
1020 | uint64_t cycles; |
1018 | char suffix; |
1021 | char suffix; |
1019 | 1022 | ||
1020 | if (cnt < 1) |
1023 | if (cnt < 1) |
1021 | return true; |
1024 | return true; |
1022 | 1025 | ||
1023 | uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0); |
1026 | uint64_t *data = (uint64_t *) malloc(sizeof(uint64_t) * cnt, 0); |
1024 | if (data == NULL) { |
1027 | if (data == NULL) { |
1025 | printf("Error allocating memory for statistics\n"); |
1028 | printf("Error allocating memory for statistics\n"); |
1026 | return false; |
1029 | return false; |
1027 | } |
1030 | } |
1028 | 1031 | ||
1029 | for (i = 0; i < cnt; i++) { |
1032 | for (i = 0; i < cnt; i++) { |
1030 | printf("%s (%d/%d) ... ", test->name, i + 1, cnt); |
1033 | printf("%s (%d/%d) ... ", test->name, i + 1, cnt); |
1031 | 1034 | ||
1032 | /* Update and read thread accounting |
1035 | /* Update and read thread accounting |
1033 | for benchmarking */ |
1036 | for benchmarking */ |
1034 | ipl_t ipl = interrupts_disable(); |
1037 | ipl_t ipl = interrupts_disable(); |
1035 | spinlock_lock(&TASK->lock); |
1038 | spinlock_lock(&TASK->lock); |
1036 | uint64_t t0 = task_get_accounting(TASK); |
1039 | uint64_t t0 = task_get_accounting(TASK); |
1037 | spinlock_unlock(&TASK->lock); |
1040 | spinlock_unlock(&TASK->lock); |
1038 | interrupts_restore(ipl); |
1041 | interrupts_restore(ipl); |
1039 | 1042 | ||
1040 | /* Execute the test */ |
1043 | /* Execute the test */ |
1041 | char * ret = test->entry(true); |
1044 | char * ret = test->entry(true); |
1042 | 1045 | ||
1043 | /* Update and read thread accounting */ |
1046 | /* Update and read thread accounting */ |
1044 | ipl = interrupts_disable(); |
1047 | ipl = interrupts_disable(); |
1045 | spinlock_lock(&TASK->lock); |
1048 | spinlock_lock(&TASK->lock); |
1046 | uint64_t dt = task_get_accounting(TASK) - t0; |
1049 | uint64_t dt = task_get_accounting(TASK) - t0; |
1047 | spinlock_unlock(&TASK->lock); |
1050 | spinlock_unlock(&TASK->lock); |
1048 | interrupts_restore(ipl); |
1051 | interrupts_restore(ipl); |
1049 | 1052 | ||
1050 | if (ret != NULL) { |
1053 | if (ret != NULL) { |
1051 | printf("%s\n", ret); |
1054 | printf("%s\n", ret); |
1052 | ret = false; |
1055 | ret = false; |
1053 | break; |
1056 | break; |
1054 | } |
1057 | } |
1055 | 1058 | ||
1056 | data[i] = dt; |
1059 | data[i] = dt; |
1057 | order(dt, &cycles, &suffix); |
1060 | order(dt, &cycles, &suffix); |
1058 | printf("OK (%llu%c cycles)\n", cycles, suffix); |
1061 | printf("OK (%llu%c cycles)\n", cycles, suffix); |
1059 | } |
1062 | } |
1060 | 1063 | ||
1061 | if (ret) { |
1064 | if (ret) { |
1062 | printf("\n"); |
1065 | printf("\n"); |
1063 | 1066 | ||
1064 | uint64_t sum = 0; |
1067 | uint64_t sum = 0; |
1065 | 1068 | ||
1066 | for (i = 0; i < cnt; i++) { |
1069 | for (i = 0; i < cnt; i++) { |
1067 | sum += data[i]; |
1070 | sum += data[i]; |
1068 | } |
1071 | } |
1069 | 1072 | ||
1070 | order(sum / (uint64_t) cnt, &cycles, &suffix); |
1073 | order(sum / (uint64_t) cnt, &cycles, &suffix); |
1071 | printf("Average\t\t%llu%c\n", cycles, suffix); |
1074 | printf("Average\t\t%llu%c\n", cycles, suffix); |
1072 | } |
1075 | } |
1073 | 1076 | ||
1074 | free(data); |
1077 | free(data); |
1075 | 1078 | ||
1076 | return ret; |
1079 | return ret; |
1077 | } |
1080 | } |
1078 | 1081 | ||
1079 | /** Command for returning kernel tests |
1082 | /** Command for returning kernel tests |
1080 | * |
1083 | * |
1081 | * @param argv Argument vector. |
1084 | * @param argv Argument vector. |
1082 | * |
1085 | * |
1083 | * return Always 1. |
1086 | * return Always 1. |
1084 | */ |
1087 | */ |
1085 | int cmd_test(cmd_arg_t *argv) |
1088 | int cmd_test(cmd_arg_t *argv) |
1086 | { |
1089 | { |
1087 | test_t *test; |
1090 | test_t *test; |
1088 | 1091 | ||
1089 | if (strcmp((char *) argv->buffer, "*") == 0) { |
1092 | if (strcmp((char *) argv->buffer, "*") == 0) { |
1090 | for (test = tests; test->name != NULL; test++) { |
1093 | for (test = tests; test->name != NULL; test++) { |
1091 | if (test->safe) { |
1094 | if (test->safe) { |
1092 | printf("\n"); |
1095 | printf("\n"); |
1093 | if (!run_test(test)) |
1096 | if (!run_test(test)) |
1094 | break; |
1097 | break; |
1095 | } |
1098 | } |
1096 | } |
1099 | } |
1097 | } else { |
1100 | } else { |
1098 | bool fnd = false; |
1101 | bool fnd = false; |
1099 | 1102 | ||
1100 | for (test = tests; test->name != NULL; test++) { |
1103 | for (test = tests; test->name != NULL; test++) { |
1101 | if (strcmp(test->name, (char *) argv->buffer) == 0) { |
1104 | if (strcmp(test->name, (char *) argv->buffer) == 0) { |
1102 | fnd = true; |
1105 | fnd = true; |
1103 | run_test(test); |
1106 | run_test(test); |
1104 | break; |
1107 | break; |
1105 | } |
1108 | } |
1106 | } |
1109 | } |
1107 | 1110 | ||
1108 | if (!fnd) |
1111 | if (!fnd) |
1109 | printf("Unknown test\n"); |
1112 | printf("Unknown test\n"); |
1110 | } |
1113 | } |
1111 | 1114 | ||
1112 | return 1; |
1115 | return 1; |
1113 | } |
1116 | } |
1114 | 1117 | ||
1115 | /** Command for returning kernel tests as benchmarks |
1118 | /** Command for returning kernel tests as benchmarks |
1116 | * |
1119 | * |
1117 | * @param argv Argument vector. |
1120 | * @param argv Argument vector. |
1118 | * |
1121 | * |
1119 | * return Always 1. |
1122 | * return Always 1. |
1120 | */ |
1123 | */ |
1121 | int cmd_bench(cmd_arg_t *argv) |
1124 | int cmd_bench(cmd_arg_t *argv) |
1122 | { |
1125 | { |
1123 | test_t *test; |
1126 | test_t *test; |
1124 | uint32_t cnt = argv[1].intval; |
1127 | uint32_t cnt = argv[1].intval; |
1125 | 1128 | ||
1126 | bool fnd = false; |
1129 | bool fnd = false; |
1127 | 1130 | ||
1128 | for (test = tests; test->name != NULL; test++) { |
1131 | for (test = tests; test->name != NULL; test++) { |
1129 | if (strcmp(test->name, (char *) argv->buffer) == 0) { |
1132 | if (strcmp(test->name, (char *) argv->buffer) == 0) { |
1130 | fnd = true; |
1133 | fnd = true; |
1131 | 1134 | ||
1132 | if (test->safe) |
1135 | if (test->safe) |
1133 | run_bench(test, cnt); |
1136 | run_bench(test, cnt); |
1134 | else |
1137 | else |
1135 | printf("Unsafe test\n"); |
1138 | printf("Unsafe test\n"); |
1136 | 1139 | ||
1137 | break; |
1140 | break; |
1138 | } |
1141 | } |
1139 | } |
1142 | } |
1140 | 1143 | ||
1141 | if (!fnd) |
1144 | if (!fnd) |
1142 | printf("Unknown test\n"); |
1145 | printf("Unknown test\n"); |
1143 | 1146 | ||
1144 | return 1; |
1147 | return 1; |
1145 | } |
1148 | } |
1146 | 1149 | ||
1147 | #endif |
1150 | #endif |
1148 | 1151 | ||
1149 | /** @} |
1152 | /** @} |
1150 | */ |
1153 | */ |
1151 | 1154 |