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