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
do_unaligned(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])11 static int do_unaligned(struct cmd_tbl *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
do_breakpoint(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])26 static int do_breakpoint(struct cmd_tbl *cmdtp, int flag, int argc,
27 char *const argv[])
28 {
29 asm volatile ("BKPT #123\n");
30 return CMD_RET_FAILURE;
31 }
32
do_undefined(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])33 static int do_undefined(struct cmd_tbl *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 struct cmd_tbl 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>
62