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