Commit dab8788a8cadaa18a44001f98fa959fc672fff4f
Committed by
Tom Rini
1 parent
c986aa624b
Exists in
smarc_8mq_lf_v2020.04
and in
9 other branches
cmd: add exception command
The 'exception' command allows to test exception handling. This implementation supports ARM, x86, RISC-V and the following exceptions: * 'breakpoint' - prefetch abort exception (ARM 32bit only) * 'unaligned' - data abort exception (ARM only) * 'undefined' - undefined instruction exception Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Showing 11 changed files with 232 additions and 0 deletions Side-by-side Diff
MAINTAINERS
... | ... | @@ -86,6 +86,7 @@ |
86 | 86 | S: Maintained |
87 | 87 | T: git git://git.denx.de/u-boot-arm.git |
88 | 88 | F: arch/arm/ |
89 | +F: cmd/arm/ | |
89 | 90 | |
90 | 91 | ARM ALTERA SOCFPGA |
91 | 92 | M: Marek Vasut <marex@denx.de> |
... | ... | @@ -677,6 +678,7 @@ |
677 | 678 | S: Maintained |
678 | 679 | T: git git://git.denx.de/u-boot-riscv.git |
679 | 680 | F: arch/riscv/ |
681 | +F: cmd/riscv/ | |
680 | 682 | F: tools/prelink-riscv.c |
681 | 683 | |
682 | 684 | ROCKUSB |
... | ... | @@ -788,6 +790,7 @@ |
788 | 790 | S: Maintained |
789 | 791 | T: git git://git.denx.de/u-boot-x86.git |
790 | 792 | F: arch/x86/ |
793 | +F: cmd/x86/ | |
791 | 794 | |
792 | 795 | XTENSA |
793 | 796 | M: Max Filippov <jcmvbkbc@gmail.com> |
cmd/Kconfig
... | ... | @@ -1433,6 +1433,12 @@ |
1433 | 1433 | particularly for managing boot parameters as well as examining |
1434 | 1434 | various EFI status for debugging. |
1435 | 1435 | |
1436 | +config CMD_EXCEPTION | |
1437 | + bool "exception - raise exception" | |
1438 | + depends on ARM || RISCV || X86 | |
1439 | + help | |
1440 | + Enable the 'exception' command which allows to raise an exception. | |
1441 | + | |
1436 | 1442 | config CMD_LED |
1437 | 1443 | bool "led" |
1438 | 1444 | depends on LED |
cmd/Makefile
cmd/arm/Makefile
cmd/arm/exception.c
1 | +// SPDX-License-Identifier: GPL-2.0+ | |
2 | +/* | |
3 | + * The 'exception' command can be used for testing exception handling. | |
4 | + * | |
5 | + * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de> | |
6 | + */ | |
7 | + | |
8 | +#include <common.h> | |
9 | +#include <command.h> | |
10 | + | |
11 | +static int do_unaligned(cmd_tbl_t *cmdtp, int flag, int argc, | |
12 | + char * const argv[]) | |
13 | +{ | |
14 | + /* | |
15 | + * The LDRD instruction requires the data source to be four byte aligned | |
16 | + * even if strict alignment fault checking is disabled in the system | |
17 | + * control register. | |
18 | + */ | |
19 | + asm volatile ( | |
20 | + "MOV r5, sp\n" | |
21 | + "ADD r5, #1\n" | |
22 | + "LDRD r6, r7, [r5]\n"); | |
23 | + return CMD_RET_FAILURE; | |
24 | +} | |
25 | + | |
26 | +static int do_breakpoint(cmd_tbl_t *cmdtp, int flag, int argc, | |
27 | + char * const argv[]) | |
28 | +{ | |
29 | + asm volatile ("BKPT #123\n"); | |
30 | + return CMD_RET_FAILURE; | |
31 | +} | |
32 | + | |
33 | +static int do_undefined(cmd_tbl_t *cmdtp, int flag, int argc, | |
34 | + char * const argv[]) | |
35 | +{ | |
36 | + /* | |
37 | + * 0xe7f...f. is undefined in ARM mode | |
38 | + * 0xde.. is undefined in Thumb mode | |
39 | + */ | |
40 | + asm volatile (".word 0xe7f7defb\n"); | |
41 | + return CMD_RET_FAILURE; | |
42 | +} | |
43 | + | |
44 | +static cmd_tbl_t cmd_sub[] = { | |
45 | + U_BOOT_CMD_MKENT(breakpoint, CONFIG_SYS_MAXARGS, 1, do_breakpoint, | |
46 | + "", ""), | |
47 | + U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned, | |
48 | + "", ""), | |
49 | + U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, | |
50 | + "", ""), | |
51 | +}; | |
52 | + | |
53 | +static char exception_help_text[] = | |
54 | + "<ex>\n" | |
55 | + " The following exceptions are available:\n" | |
56 | + " breakpoint - prefetch abort\n" | |
57 | + " unaligned - data abort\n" | |
58 | + " undefined - undefined instruction\n" | |
59 | + ; | |
60 | + | |
61 | +#include <exception.h> |
cmd/arm/exception64.c
1 | +// SPDX-License-Identifier: GPL-2.0+ | |
2 | +/* | |
3 | + * The 'exception' command can be used for testing exception handling. | |
4 | + * | |
5 | + * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de> | |
6 | + */ | |
7 | + | |
8 | +#include <common.h> | |
9 | +#include <command.h> | |
10 | + | |
11 | +static int do_undefined(cmd_tbl_t *cmdtp, int flag, int argc, | |
12 | + char * const argv[]) | |
13 | +{ | |
14 | + /* | |
15 | + * 0xe7f...f. is undefined in ARM mode | |
16 | + * 0xde.. is undefined in Thumb mode | |
17 | + */ | |
18 | + asm volatile (".word 0xe7f7defb\n"); | |
19 | + return CMD_RET_FAILURE; | |
20 | +} | |
21 | + | |
22 | +static cmd_tbl_t cmd_sub[] = { | |
23 | + U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, | |
24 | + "", ""), | |
25 | +}; | |
26 | + | |
27 | +static char exception_help_text[] = | |
28 | + "<ex>\n" | |
29 | + " The following exceptions are available:\n" | |
30 | + " undefined - undefined instruction\n" | |
31 | + ; | |
32 | + | |
33 | +#include <exception.h> |
cmd/riscv/Makefile
cmd/riscv/exception.c
1 | +// SPDX-License-Identifier: GPL-2.0+ | |
2 | +/* | |
3 | + * The 'exception' command can be used for testing exception handling. | |
4 | + * | |
5 | + * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de> | |
6 | + */ | |
7 | + | |
8 | +#include <common.h> | |
9 | +#include <command.h> | |
10 | + | |
11 | +static int do_undefined(cmd_tbl_t *cmdtp, int flag, int argc, | |
12 | + char * const argv[]) | |
13 | +{ | |
14 | + asm volatile (".word 0xffffffff\n"); | |
15 | + return CMD_RET_FAILURE; | |
16 | +} | |
17 | + | |
18 | +static cmd_tbl_t cmd_sub[] = { | |
19 | + U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, | |
20 | + "", ""), | |
21 | +}; | |
22 | + | |
23 | +static char exception_help_text[] = | |
24 | + "<ex>\n" | |
25 | + " The following exceptions are available:\n" | |
26 | + " undefined - undefined instruction\n" | |
27 | + ; | |
28 | + | |
29 | +#include <exception.h> |
cmd/x86/Makefile
cmd/x86/exception.c
1 | +// SPDX-License-Identifier: GPL-2.0+ | |
2 | +/* | |
3 | + * The 'exception' command can be used for testing exception handling. | |
4 | + * | |
5 | + * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de> | |
6 | + */ | |
7 | + | |
8 | +#include <common.h> | |
9 | +#include <command.h> | |
10 | + | |
11 | +static int do_undefined(cmd_tbl_t *cmdtp, int flag, int argc, | |
12 | + char * const argv[]) | |
13 | +{ | |
14 | + asm volatile (".word 0xffff\n"); | |
15 | + return CMD_RET_FAILURE; | |
16 | +} | |
17 | + | |
18 | +static cmd_tbl_t cmd_sub[] = { | |
19 | + U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, | |
20 | + "", ""), | |
21 | +}; | |
22 | + | |
23 | +static char exception_help_text[] = | |
24 | + "<ex>\n" | |
25 | + " The following exceptions are available:\n" | |
26 | + " undefined - undefined instruction\n" | |
27 | + ; | |
28 | + | |
29 | +#include <exception.h> |
include/exception.h
1 | +/* SPDX-License-Identifier: GPL-2.0+ */ | |
2 | +/* | |
3 | + * The 'exception' command can be used for testing exception handling. | |
4 | + * | |
5 | + * Copyright (c) 2018, Heinrich Schuchardt <xypron.glpk@gmx.de> | |
6 | + */ | |
7 | + | |
8 | +static int do_exception(cmd_tbl_t *cmdtp, int flag, int argc, | |
9 | + char * const argv[]) | |
10 | +{ | |
11 | + cmd_tbl_t *cp; | |
12 | + | |
13 | + if (argc != 2) | |
14 | + return CMD_RET_USAGE; | |
15 | + | |
16 | + /* drop sub-command parameter */ | |
17 | + argc--; | |
18 | + argv++; | |
19 | + | |
20 | + cp = find_cmd_tbl(argv[0], cmd_sub, ARRAY_SIZE(cmd_sub)); | |
21 | + | |
22 | + if (cp) | |
23 | + return cp->cmd(cmdtp, flag, argc, argv); | |
24 | + | |
25 | + return CMD_RET_USAGE; | |
26 | +} | |
27 | + | |
28 | +static int exception_complete(int argc, char * const argv[], char last_char, | |
29 | + int maxv, char *cmdv[]) | |
30 | +{ | |
31 | + int len = 0; | |
32 | + int i = 0; | |
33 | + cmd_tbl_t *cmdtp; | |
34 | + | |
35 | + switch (argc) { | |
36 | + case 1: | |
37 | + break; | |
38 | + case 2: | |
39 | + len = strlen(argv[1]); | |
40 | + break; | |
41 | + default: | |
42 | + return 0; | |
43 | + } | |
44 | + for (cmdtp = cmd_sub; cmdtp != cmd_sub + ARRAY_SIZE(cmd_sub); cmdtp++) { | |
45 | + if (i >= maxv - 1) | |
46 | + return i; | |
47 | + if (!strncmp(argv[1], cmdtp->name, len)) | |
48 | + cmdv[i++] = cmdtp->name; | |
49 | + } | |
50 | + cmdv[i] = NULL; | |
51 | + return i; | |
52 | +} | |
53 | + | |
54 | +U_BOOT_CMD_COMPLETE( | |
55 | + exception, 2, 0, do_exception, | |
56 | + "Forces an exception to occur", | |
57 | + exception_help_text, exception_complete | |
58 | +); |