blob: 98a9795b68c82cf0dfb6d416c68a1cb7826814a2 [file] [log] [blame]
Heinrich Schuchardtdab87882018-12-26 17:20:35 +01001// 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
Heinrich Schuchardtdab87882018-12-26 17:20:35 +01008#include <command.h>
9
Simon Glass09140112020-05-10 11:40:03 -060010static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc,
11 char *const argv[])
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010012{
13 /*
14 * The LDRD instruction requires the data source to be four byte aligned
15 * even if strict alignment fault checking is disabled in the system
16 * control register.
17 */
18 asm volatile (
19 "MOV r5, sp\n"
20 "ADD r5, #1\n"
21 "LDRD r6, r7, [r5]\n");
22 return CMD_RET_FAILURE;
23}
24
Simon Glass09140112020-05-10 11:40:03 -060025static int do_breakpoint(struct cmd_tbl *cmdtp, int flag, int argc,
26 char *const argv[])
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010027{
28 asm volatile ("BKPT #123\n");
29 return CMD_RET_FAILURE;
30}
31
Simon Glass09140112020-05-10 11:40:03 -060032static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
33 char *const argv[])
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010034{
35 /*
36 * 0xe7f...f. is undefined in ARM mode
37 * 0xde.. is undefined in Thumb mode
38 */
39 asm volatile (".word 0xe7f7defb\n");
40 return CMD_RET_FAILURE;
41}
42
Simon Glass09140112020-05-10 11:40:03 -060043static struct cmd_tbl cmd_sub[] = {
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010044 U_BOOT_CMD_MKENT(breakpoint, CONFIG_SYS_MAXARGS, 1, do_breakpoint,
45 "", ""),
46 U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
47 "", ""),
48 U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined,
49 "", ""),
50};
51
52static char exception_help_text[] =
53 "<ex>\n"
54 " The following exceptions are available:\n"
55 " breakpoint - prefetch abort\n"
56 " unaligned - data abort\n"
57 " undefined - undefined instruction\n"
58 ;
59
60#include <exception.h>