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 | d46dc18 | 2024-08-11 16:41:23 +0200 | [diff] [blame] | 39 | static int do_rdcycle(struct cmd_tbl *cmdtp, int flag, int argc, |
| 40 | char *const argv[]) |
| 41 | { |
| 42 | printf("cycle = 0x%lx\n", csr_read(CSR_CYCLE)); |
| 43 | |
| 44 | return CMD_RET_SUCCESS; |
| 45 | } |
| 46 | |
Heinrich Schuchardt | 5dfa883 | 2020-08-06 12:34:59 +0200 | [diff] [blame] | 47 | static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc, |
| 48 | char *const argv[]) |
| 49 | { |
| 50 | asm volatile ( |
| 51 | "auipc a1, 0\n" |
| 52 | "ori a1, a1, 3\n" |
| 53 | "lw a2, (0)(a1)\n" |
| 54 | ); |
| 55 | printf("The system supports unaligned access.\n"); |
| 56 | return CMD_RET_SUCCESS; |
| 57 | } |
| 58 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 59 | static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc, |
| 60 | char *const argv[]) |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 61 | { |
| 62 | asm volatile (".word 0xffffffff\n"); |
| 63 | return CMD_RET_FAILURE; |
| 64 | } |
| 65 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 66 | static struct cmd_tbl cmd_sub[] = { |
Heinrich Schuchardt | 9d5163b | 2023-09-21 10:42:18 +0200 | [diff] [blame] | 67 | U_BOOT_CMD_MKENT(compressed, CONFIG_SYS_MAXARGS, 1, do_compressed, |
| 68 | "", ""), |
Heinrich Schuchardt | ba0cfad | 2021-04-09 10:48:14 +0000 | [diff] [blame] | 69 | U_BOOT_CMD_MKENT(ebreak, CONFIG_SYS_MAXARGS, 1, do_ebreak, |
| 70 | "", ""), |
Heinrich Schuchardt | 42fb8e2 | 2023-09-21 12:39:29 +0200 | [diff] [blame] | 71 | U_BOOT_CMD_MKENT(ialign16, CONFIG_SYS_MAXARGS, 1, do_ialign16, |
| 72 | "", ""), |
Heinrich Schuchardt | d46dc18 | 2024-08-11 16:41:23 +0200 | [diff] [blame] | 73 | U_BOOT_CMD_MKENT(rdcycle, CONFIG_SYS_MAXARGS, 1, do_rdcycle, |
| 74 | "", ""), |
Heinrich Schuchardt | 5dfa883 | 2020-08-06 12:34:59 +0200 | [diff] [blame] | 75 | U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned, |
| 76 | "", ""), |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 77 | U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, |
| 78 | "", ""), |
| 79 | }; |
| 80 | |
Tom Rini | 4c1ca0d | 2024-06-19 10:09:44 -0600 | [diff] [blame] | 81 | U_BOOT_LONGHELP(exception, |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 82 | "<ex>\n" |
| 83 | " The following exceptions are available:\n" |
Heinrich Schuchardt | 9d5163b | 2023-09-21 10:42:18 +0200 | [diff] [blame] | 84 | " compressed - compressed instruction\n" |
| 85 | " ebreak - breakpoint\n" |
Heinrich Schuchardt | 42fb8e2 | 2023-09-21 12:39:29 +0200 | [diff] [blame] | 86 | " ialign16 - 16 bit aligned instruction\n" |
Heinrich Schuchardt | d46dc18 | 2024-08-11 16:41:23 +0200 | [diff] [blame] | 87 | " rdcycle - read cycle CSR\n" |
| 88 | " unaligned - load address misaligned\n" |
| 89 | " undefined - illegal instruction\n"); |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 90 | |
| 91 | #include <exception.h> |