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 | |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 8 | #include <command.h> |
| 9 | |
Heinrich Schuchardt | 9d5163b | 2023-09-21 10:42:18 +0200 | [diff] [blame] | 10 | static int do_compressed(struct cmd_tbl *cmdtp, int flag, int argc, |
| 11 | char *const argv[]) |
| 12 | { |
| 13 | /* c.li a0, 0; c.li a0, 0 */ |
| 14 | asm volatile (".long 0x45014501\n"); |
| 15 | printf("The system supports compressed instructions.\n"); |
| 16 | return CMD_RET_SUCCESS; |
| 17 | } |
| 18 | |
Heinrich Schuchardt | ba0cfad | 2021-04-09 10:48:14 +0000 | [diff] [blame] | 19 | static int do_ebreak(struct cmd_tbl *cmdtp, int flag, int argc, |
| 20 | char *const argv[]) |
| 21 | { |
| 22 | asm volatile ("ebreak\n"); |
| 23 | return CMD_RET_FAILURE; |
| 24 | } |
| 25 | |
Heinrich Schuchardt | 42fb8e2 | 2023-09-21 12:39:29 +0200 | [diff] [blame] | 26 | static int do_ialign16(struct cmd_tbl *cmdtp, int flag, int argc, |
| 27 | char *const argv[]) |
| 28 | { |
| 29 | asm volatile ( |
| 30 | /* jump skipping 2 bytes */ |
| 31 | ".long 0x0060006f\n" |
| 32 | ".long 0x006f0000\n" |
| 33 | ".long 0x00000060\n" |
| 34 | ); |
| 35 | printf("The system supports 16 bit aligned instructions.\n"); |
| 36 | return CMD_RET_SUCCESS; |
| 37 | } |
| 38 | |
Heinrich Schuchardt | 5dfa883 | 2020-08-06 12:34:59 +0200 | [diff] [blame] | 39 | static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc, |
| 40 | char *const argv[]) |
| 41 | { |
| 42 | asm volatile ( |
| 43 | "auipc a1, 0\n" |
| 44 | "ori a1, a1, 3\n" |
| 45 | "lw a2, (0)(a1)\n" |
| 46 | ); |
| 47 | printf("The system supports unaligned access.\n"); |
| 48 | return CMD_RET_SUCCESS; |
| 49 | } |
| 50 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 51 | static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc, |
| 52 | char *const argv[]) |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 53 | { |
| 54 | asm volatile (".word 0xffffffff\n"); |
| 55 | return CMD_RET_FAILURE; |
| 56 | } |
| 57 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 58 | static struct cmd_tbl cmd_sub[] = { |
Heinrich Schuchardt | 9d5163b | 2023-09-21 10:42:18 +0200 | [diff] [blame] | 59 | U_BOOT_CMD_MKENT(compressed, CONFIG_SYS_MAXARGS, 1, do_compressed, |
| 60 | "", ""), |
Heinrich Schuchardt | ba0cfad | 2021-04-09 10:48:14 +0000 | [diff] [blame] | 61 | U_BOOT_CMD_MKENT(ebreak, CONFIG_SYS_MAXARGS, 1, do_ebreak, |
| 62 | "", ""), |
Heinrich Schuchardt | 42fb8e2 | 2023-09-21 12:39:29 +0200 | [diff] [blame] | 63 | U_BOOT_CMD_MKENT(ialign16, CONFIG_SYS_MAXARGS, 1, do_ialign16, |
| 64 | "", ""), |
Heinrich Schuchardt | 5dfa883 | 2020-08-06 12:34:59 +0200 | [diff] [blame] | 65 | U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned, |
| 66 | "", ""), |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 67 | U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, |
| 68 | "", ""), |
| 69 | }; |
| 70 | |
Tom Rini | 4c1ca0d | 2024-06-19 10:09:44 -0600 | [diff] [blame] | 71 | U_BOOT_LONGHELP(exception, |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 72 | "<ex>\n" |
| 73 | " The following exceptions are available:\n" |
Heinrich Schuchardt | 9d5163b | 2023-09-21 10:42:18 +0200 | [diff] [blame] | 74 | " compressed - compressed instruction\n" |
| 75 | " ebreak - breakpoint\n" |
Heinrich Schuchardt | 42fb8e2 | 2023-09-21 12:39:29 +0200 | [diff] [blame] | 76 | " ialign16 - 16 bit aligned instruction\n" |
Heinrich Schuchardt | 9d5163b | 2023-09-21 10:42:18 +0200 | [diff] [blame] | 77 | " undefined - illegal instruction\n" |
Tom Rini | 4c1ca0d | 2024-06-19 10:09:44 -0600 | [diff] [blame] | 78 | " unaligned - load address misaligned\n"); |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 79 | |
| 80 | #include <exception.h> |