Heinrich Schuchardt | dab8788 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 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 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 11 | static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc, |
| 12 | char *const argv[]) |
Heinrich Schuchardt | dab8788 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 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 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 26 | static int do_breakpoint(struct cmd_tbl *cmdtp, int flag, int argc, |
| 27 | char *const argv[]) |
Heinrich Schuchardt | dab8788 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 28 | { |
| 29 | asm volatile ("BKPT #123\n"); |
| 30 | return CMD_RET_FAILURE; |
| 31 | } |
| 32 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 33 | static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc, |
| 34 | char *const argv[]) |
Heinrich Schuchardt | dab8788 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 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 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 44 | static struct cmd_tbl cmd_sub[] = { |
Heinrich Schuchardt | dab8788 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 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> |