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