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> |
Andre Przywara | ddda5d8 | 2022-02-11 11:29:34 +0000 | [diff] [blame] | 9 | #include <linux/bitops.h> |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 10 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 11 | static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc, |
| 12 | char *const argv[]) |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 13 | { |
| 14 | /* |
Andre Przywara | ddda5d8 | 2022-02-11 11:29:34 +0000 | [diff] [blame] | 15 | * Instructions starting with the upper 16 bits all 0 are permanently |
| 16 | * undefined. The lower 16 bits can be used for some kind of immediate. |
| 17 | * --- ARMv8 ARM (ARM DDI 0487G.a C6.2.339: "UDF") |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 18 | */ |
Andre Przywara | ddda5d8 | 2022-02-11 11:29:34 +0000 | [diff] [blame] | 19 | asm volatile (".word 0x00001234\n"); |
| 20 | |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 21 | return CMD_RET_FAILURE; |
| 22 | } |
| 23 | |
Andre Przywara | ddda5d8 | 2022-02-11 11:29:34 +0000 | [diff] [blame] | 24 | /* |
| 25 | * The ID_AA64MMFR2_EL1 register name is only know to binutils for ARMv8.2 |
| 26 | * and later architecture revisions. However the register is valid regardless |
| 27 | * of binutils architecture support or the core the code is running on, so |
| 28 | * just use the generic encoding. |
| 29 | */ |
| 30 | #define ID_AA64MMFR2_EL1 "S3_0_C0_C7_2" |
| 31 | |
| 32 | static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc, |
| 33 | char *const argv[]) |
| 34 | { |
| 35 | uint64_t reg; |
| 36 | |
| 37 | /* |
| 38 | * The unaligned LDAR access below is only guaranteed to generate an |
| 39 | * alignment fault on cores not implementing FEAT_LSE2. To avoid false |
| 40 | * negatives, check this condition before we exectute LDAR. |
| 41 | */ |
| 42 | asm ("mrs %0, "ID_AA64MMFR2_EL1"\n" : "=r" (reg)); |
| 43 | if (reg & GENMASK(35, 32)) { |
| 44 | printf("unaligned access check only supported on pre-v8.4 cores\n"); |
| 45 | return CMD_RET_FAILURE; |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * The load acquire instruction requires the data source to be |
| 50 | * naturally aligned, and will fault even if strict alignment fault |
| 51 | * checking is disabled (but only without FEAT_LSE2). |
| 52 | * --- ARMv8 ARM (ARM DDI 0487G.a B2.5.2: "Alignment of data accesses") |
| 53 | */ |
| 54 | asm volatile ( |
| 55 | "mov x1, sp\n\t" |
| 56 | "orr x1, x1, #3\n\t" |
| 57 | "ldar x0, [x1]\n" |
| 58 | ::: "x0", "x1" ); |
| 59 | |
| 60 | return CMD_RET_FAILURE; |
| 61 | } |
| 62 | |
| 63 | static int do_breakpoint(struct cmd_tbl *cmdtp, int flag, int argc, |
| 64 | char *const argv[]) |
| 65 | { |
| 66 | asm volatile ("brk #123\n"); |
| 67 | |
| 68 | return CMD_RET_FAILURE; |
| 69 | } |
| 70 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 71 | static struct cmd_tbl cmd_sub[] = { |
Andre Przywara | ddda5d8 | 2022-02-11 11:29:34 +0000 | [diff] [blame] | 72 | U_BOOT_CMD_MKENT(breakpoint, CONFIG_SYS_MAXARGS, 1, do_breakpoint, |
| 73 | "", ""), |
| 74 | U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned, |
| 75 | "", ""), |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 76 | U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined, |
| 77 | "", ""), |
| 78 | }; |
| 79 | |
Tom Rini | 4c1ca0d | 2024-06-19 10:09:44 -0600 | [diff] [blame] | 80 | U_BOOT_LONGHELP(exception, |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 81 | "<ex>\n" |
| 82 | " The following exceptions are available:\n" |
Andre Przywara | ddda5d8 | 2022-02-11 11:29:34 +0000 | [diff] [blame] | 83 | " breakpoint - breakpoint instruction exception\n" |
| 84 | " unaligned - unaligned LDAR data abort\n" |
Tom Rini | 4c1ca0d | 2024-06-19 10:09:44 -0600 | [diff] [blame] | 85 | " undefined - undefined instruction exception\n"); |
Heinrich Schuchardt | f7d6b07 | 2018-12-26 17:20:35 +0100 | [diff] [blame] | 86 | |
| 87 | #include <exception.h> |