1 // 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
do_unaligned(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])11 static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc,
12 char *const argv[])
13 {
14 asm volatile (
15 "auipc a1, 0\n"
16 "ori a1, a1, 3\n"
17 "lw a2, (0)(a1)\n"
18 );
19 printf("The system supports unaligned access.\n");
20 return CMD_RET_SUCCESS;
21 }
22
do_undefined(struct cmd_tbl * cmdtp,int flag,int argc,char * const argv[])23 static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
24 char *const argv[])
25 {
26 asm volatile (".word 0xffffffff\n");
27 return CMD_RET_FAILURE;
28 }
29
30 static struct cmd_tbl cmd_sub[] = {
31 U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
32 "", ""),
33 U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined,
34 "", ""),
35 };
36
37 static char exception_help_text[] =
38 "<ex>\n"
39 " The following exceptions are available:\n"
40 " undefined - illegal instruction\n"
41 " unaligned - load address misaligned\n"
42 ;
43
44 #include <exception.h>
45