blob: 7a08061d12037554e98d45f1d179d887bab18411 [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 Schuchardt91e4b752021-04-09 10:48:14 +000011static int do_ebreak(struct cmd_tbl *cmdtp, int flag, int argc,
12 char *const argv[])
13{
14 asm volatile ("ebreak\n");
15 return CMD_RET_FAILURE;
16}
17
Heinrich Schuchardtdb3585d2020-08-06 12:34:59 +020018static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc,
19 char *const argv[])
20{
21 asm volatile (
22 "auipc a1, 0\n"
23 "ori a1, a1, 3\n"
24 "lw a2, (0)(a1)\n"
25 );
26 printf("The system supports unaligned access.\n");
27 return CMD_RET_SUCCESS;
28}
29
Simon Glass09140112020-05-10 11:40:03 -060030static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
31 char *const argv[])
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010032{
33 asm volatile (".word 0xffffffff\n");
34 return CMD_RET_FAILURE;
35}
36
Simon Glass09140112020-05-10 11:40:03 -060037static struct cmd_tbl cmd_sub[] = {
Heinrich Schuchardt91e4b752021-04-09 10:48:14 +000038 U_BOOT_CMD_MKENT(ebreak, CONFIG_SYS_MAXARGS, 1, do_ebreak,
39 "", ""),
Heinrich Schuchardtdb3585d2020-08-06 12:34:59 +020040 U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
41 "", ""),
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010042 U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined,
43 "", ""),
44};
45
46static char exception_help_text[] =
47 "<ex>\n"
48 " The following exceptions are available:\n"
Heinrich Schuchardt91e4b752021-04-09 10:48:14 +000049 " ebreak - breakpoint\n"
Heinrich Schuchardtdb3585d2020-08-06 12:34:59 +020050 " undefined - illegal instruction\n"
51 " unaligned - load address misaligned\n"
Heinrich Schuchardtdab87882018-12-26 17:20:35 +010052 ;
53
54#include <exception.h>