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