exception.c 1.3 KB

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