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 | |
Heinrich Schuchardt | 91e4b75 | 2021-04-09 10:48:14 +0000 | [diff] [blame^] | 11 | static int do_ebreak(struct cmd_tbl *cmdtp, int flag, int argc, |
| 12 | char *const argv[]) |
| 13 | { |
| 14 | asm volatile ("ebreak\n"); |
| 15 | return CMD_RET_FAILURE; |
| 16 | } |
| 17 | |
Heinrich Schuchardt | db3585d | 2020-08-06 12:34:59 +0200 | [diff] [blame] | 18 | static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc, |
| 19 | char *const argv[]) |
| 20 | { |
| 21 | asm volatile ( |
| 22 | "auipc a1, 0\n" |
| 23 | "ori a1, a1, 3\n" |
| 24 | "lw a2, (0)(a1)\n" |
| 25 | ); |
| 26 | printf("The system supports unaligned access.\n"); |
| 27 | return CMD_RET_SUCCESS; |
| 28 | } |
| 29 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 30 | static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc, |
| 31 | char *const argv[]) |
Heinrich Schuchardt | dab8788 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 32 | { |
| 33 | asm volatile (".word 0xffffffff\n"); |
| 34 | return CMD_RET_FAILURE; |
| 35 | } |
| 36 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 37 | static struct cmd_tbl cmd_sub[] = { |
Heinrich Schuchardt | 91e4b75 | 2021-04-09 10:48:14 +0000 | [diff] [blame^] | 38 | U_BOOT_CMD_MKENT(ebreak, CONFIG_SYS_MAXARGS, 1, do_ebreak, |
| 39 | "", ""), |
Heinrich Schuchardt | db3585d | 2020-08-06 12:34:59 +0200 | [diff] [blame] | 40 | U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned, |
| 41 | "", ""), |
Heinrich Schuchardt | dab8788 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 42 | U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, |
| 43 | "", ""), |
| 44 | }; |
| 45 | |
| 46 | static char exception_help_text[] = |
| 47 | "<ex>\n" |
| 48 | " The following exceptions are available:\n" |
Heinrich Schuchardt | 91e4b75 | 2021-04-09 10:48:14 +0000 | [diff] [blame^] | 49 | " ebreak - breakpoint\n" |
Heinrich Schuchardt | db3585d | 2020-08-06 12:34:59 +0200 | [diff] [blame] | 50 | " undefined - illegal instruction\n" |
| 51 | " unaligned - load address misaligned\n" |
Heinrich Schuchardt | dab8788 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 52 | ; |
| 53 | |
| 54 | #include <exception.h> |