blob: 522f6dff53f266d31ee267b3af1b0dc042718b5a [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
8#include <common.h>
9#include <command.h>
10
Simon Glass09140112020-05-10 11:40:03 -060011static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc,
12 char *const argv[])
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010013{
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
Simon Glass09140112020-05-10 11:40:03 -060026static int do_breakpoint(struct cmd_tbl *cmdtp, int flag, int argc,
27 char *const argv[])
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010028{
29 asm volatile ("BKPT #123\n");
30 return CMD_RET_FAILURE;
31}
32
Simon Glass09140112020-05-10 11:40:03 -060033static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
34 char *const argv[])
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010035{
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
Simon Glass09140112020-05-10 11:40:03 -060044static struct cmd_tbl cmd_sub[] = {
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010045 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
53static 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>