blob: 2b58b1c449c08d02bef2c0cba477d574258f6505 [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 Schuchardt5dfa8832020-08-06 12:34:59 +020039static 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 Glassed38aef2020-05-10 11:40:03 -060051static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
52 char *const argv[])
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010053{
54 asm volatile (".word 0xffffffff\n");
55 return CMD_RET_FAILURE;
56}
57
Simon Glassed38aef2020-05-10 11:40:03 -060058static struct cmd_tbl cmd_sub[] = {
Heinrich Schuchardt9d5163b2023-09-21 10:42:18 +020059 U_BOOT_CMD_MKENT(compressed, CONFIG_SYS_MAXARGS, 1, do_compressed,
60 "", ""),
Heinrich Schuchardtba0cfad2021-04-09 10:48:14 +000061 U_BOOT_CMD_MKENT(ebreak, CONFIG_SYS_MAXARGS, 1, do_ebreak,
62 "", ""),
Heinrich Schuchardt42fb8e22023-09-21 12:39:29 +020063 U_BOOT_CMD_MKENT(ialign16, CONFIG_SYS_MAXARGS, 1, do_ialign16,
64 "", ""),
Heinrich Schuchardt5dfa8832020-08-06 12:34:59 +020065 U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
66 "", ""),
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010067 U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined,
68 "", ""),
69};
70
Tom Rini4c1ca0d2024-06-19 10:09:44 -060071U_BOOT_LONGHELP(exception,
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010072 "<ex>\n"
73 " The following exceptions are available:\n"
Heinrich Schuchardt9d5163b2023-09-21 10:42:18 +020074 " compressed - compressed instruction\n"
75 " ebreak - breakpoint\n"
Heinrich Schuchardt42fb8e22023-09-21 12:39:29 +020076 " ialign16 - 16 bit aligned instruction\n"
Heinrich Schuchardt9d5163b2023-09-21 10:42:18 +020077 " undefined - illegal instruction\n"
Tom Rini4c1ca0d2024-06-19 10:09:44 -060078 " unaligned - load address misaligned\n");
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010079
80#include <exception.h>