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