blob: 8857f1216049823df4724f4616c8511ed8f9851b [file] [log] [blame]
Heinrich Schuchardtf7d6b072018-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 Schuchardtf7d6b072018-12-26 17:20:35 +01008#include <command.h>
9
Simon Glassed38aef2020-05-10 11:40:03 -060010static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc,
11 char *const argv[])
Heinrich Schuchardtf7d6b072018-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 Glassed38aef2020-05-10 11:40:03 -060025static int do_breakpoint(struct cmd_tbl *cmdtp, int flag, int argc,
26 char *const argv[])
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010027{
28 asm volatile ("BKPT #123\n");
29 return CMD_RET_FAILURE;
30}
31
Simon Glassed38aef2020-05-10 11:40:03 -060032static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
33 char *const argv[])
Heinrich Schuchardtf7d6b072018-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 Glassed38aef2020-05-10 11:40:03 -060043static struct cmd_tbl cmd_sub[] = {
Heinrich Schuchardtf7d6b072018-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
Tom Rini4c1ca0d2024-06-19 10:09:44 -060052U_BOOT_LONGHELP(exception,
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010053 "<ex>\n"
54 " The following exceptions are available:\n"
55 " breakpoint - prefetch abort\n"
56 " unaligned - data abort\n"
Tom Rini4c1ca0d2024-06-19 10:09:44 -060057 " undefined - undefined instruction\n");
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010058
59#include <exception.h>