blob: 16e335327f17c6961f62158e030feca0a2fcc5ab [file] [log] [blame]
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +01001// 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 Schuchardtf7d6b072018-12-26 17:20:35 +01008#include <command.h>
9
Heinrich Schuchardt9d5163b2023-09-21 10:42:18 +020010static 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 Schuchardtba0cfad2021-04-09 10:48:14 +000019static 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 Schuchardt42fb8e22023-09-21 12:39:29 +020026static 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 Schuchardtd46dc182024-08-11 16:41:23 +020039static 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 Schuchardt5dfa8832020-08-06 12:34:59 +020047static 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 Glassed38aef2020-05-10 11:40:03 -060059static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
60 char *const argv[])
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010061{
62 asm volatile (".word 0xffffffff\n");
63 return CMD_RET_FAILURE;
64}
65
Simon Glassed38aef2020-05-10 11:40:03 -060066static struct cmd_tbl cmd_sub[] = {
Heinrich Schuchardt9d5163b2023-09-21 10:42:18 +020067 U_BOOT_CMD_MKENT(compressed, CONFIG_SYS_MAXARGS, 1, do_compressed,
68 "", ""),
Heinrich Schuchardtba0cfad2021-04-09 10:48:14 +000069 U_BOOT_CMD_MKENT(ebreak, CONFIG_SYS_MAXARGS, 1, do_ebreak,
70 "", ""),
Heinrich Schuchardt42fb8e22023-09-21 12:39:29 +020071 U_BOOT_CMD_MKENT(ialign16, CONFIG_SYS_MAXARGS, 1, do_ialign16,
72 "", ""),
Heinrich Schuchardtd46dc182024-08-11 16:41:23 +020073 U_BOOT_CMD_MKENT(rdcycle, CONFIG_SYS_MAXARGS, 1, do_rdcycle,
74 "", ""),
Heinrich Schuchardt5dfa8832020-08-06 12:34:59 +020075 U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
76 "", ""),
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010077 U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined,
78 "", ""),
79};
80
Tom Rini4c1ca0d2024-06-19 10:09:44 -060081U_BOOT_LONGHELP(exception,
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010082 "<ex>\n"
83 " The following exceptions are available:\n"
Heinrich Schuchardt9d5163b2023-09-21 10:42:18 +020084 " compressed - compressed instruction\n"
85 " ebreak - breakpoint\n"
Heinrich Schuchardt42fb8e22023-09-21 12:39:29 +020086 " ialign16 - 16 bit aligned instruction\n"
Heinrich Schuchardtd46dc182024-08-11 16:41:23 +020087 " rdcycle - read cycle CSR\n"
88 " unaligned - load address misaligned\n"
89 " undefined - illegal instruction\n");
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010090
91#include <exception.h>