blob: f38f454a0b1fb7b9641b133461b5f5cb7d752c42 [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
8#include <common.h>
9#include <command.h>
10
Heinrich Schuchardt9d5163b2023-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 Schuchardtba0cfad2021-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 Schuchardt42fb8e22023-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 Schuchardt5dfa8832020-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 Glassed38aef2020-05-10 11:40:03 -060052static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
53 char *const argv[])
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010054{
55 asm volatile (".word 0xffffffff\n");
56 return CMD_RET_FAILURE;
57}
58
Simon Glassed38aef2020-05-10 11:40:03 -060059static struct cmd_tbl cmd_sub[] = {
Heinrich Schuchardt9d5163b2023-09-21 10:42:18 +020060 U_BOOT_CMD_MKENT(compressed, CONFIG_SYS_MAXARGS, 1, do_compressed,
61 "", ""),
Heinrich Schuchardtba0cfad2021-04-09 10:48:14 +000062 U_BOOT_CMD_MKENT(ebreak, CONFIG_SYS_MAXARGS, 1, do_ebreak,
63 "", ""),
Heinrich Schuchardt42fb8e22023-09-21 12:39:29 +020064 U_BOOT_CMD_MKENT(ialign16, CONFIG_SYS_MAXARGS, 1, do_ialign16,
65 "", ""),
Heinrich Schuchardt5dfa8832020-08-06 12:34:59 +020066 U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
67 "", ""),
Heinrich Schuchardtf7d6b072018-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 Schuchardt9d5163b2023-09-21 10:42:18 +020075 " compressed - compressed instruction\n"
76 " ebreak - breakpoint\n"
Heinrich Schuchardt42fb8e22023-09-21 12:39:29 +020077 " ialign16 - 16 bit aligned instruction\n"
Heinrich Schuchardt9d5163b2023-09-21 10:42:18 +020078 " undefined - illegal instruction\n"
79 " unaligned - load address misaligned\n"
Heinrich Schuchardtf7d6b072018-12-26 17:20:35 +010080 ;
81
82#include <exception.h>