blob: f38f454a0b1fb7b9641b133461b5f5cb7d752c42 [file] [log] [blame]
Heinrich Schuchardtdab87882018-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
8#include <common.h>
9#include <command.h>
10
Heinrich Schuchardtf2e4b9d2023-09-21 10:42:18 +020011static 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 Schuchardt91e4b752021-04-09 10:48:14 +000020static 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 Schuchardtef5ccaa2023-09-21 12:39:29 +020027static 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 Schuchardtdb3585d2020-08-06 12:34:59 +020040static 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 Glass09140112020-05-10 11:40:03 -060052static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
53 char *const argv[])
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010054{
55 asm volatile (".word 0xffffffff\n");
56 return CMD_RET_FAILURE;
57}
58
Simon Glass09140112020-05-10 11:40:03 -060059static struct cmd_tbl cmd_sub[] = {
Heinrich Schuchardtf2e4b9d2023-09-21 10:42:18 +020060 U_BOOT_CMD_MKENT(compressed, CONFIG_SYS_MAXARGS, 1, do_compressed,
61 "", ""),
Heinrich Schuchardt91e4b752021-04-09 10:48:14 +000062 U_BOOT_CMD_MKENT(ebreak, CONFIG_SYS_MAXARGS, 1, do_ebreak,
63 "", ""),
Heinrich Schuchardtef5ccaa2023-09-21 12:39:29 +020064 U_BOOT_CMD_MKENT(ialign16, CONFIG_SYS_MAXARGS, 1, do_ialign16,
65 "", ""),
Heinrich Schuchardtdb3585d2020-08-06 12:34:59 +020066 U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
67 "", ""),
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010068 U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined,
69 "", ""),
70};
71
72static char exception_help_text[] =
73 "<ex>\n"
74 " The following exceptions are available:\n"
Heinrich Schuchardtf2e4b9d2023-09-21 10:42:18 +020075 " compressed - compressed instruction\n"
76 " ebreak - breakpoint\n"
Heinrich Schuchardtef5ccaa2023-09-21 12:39:29 +020077 " ialign16 - 16 bit aligned instruction\n"
Heinrich Schuchardtf2e4b9d2023-09-21 10:42:18 +020078 " undefined - illegal instruction\n"
79 " unaligned - load address misaligned\n"
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010080 ;
81
82#include <exception.h>