exception.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_unaligned(struct cmd_tbl *cmdtp, int flag, int argc,
  10. char *const argv[])
  11. {
  12. /*
  13. * The LDRD instruction requires the data source to be four byte aligned
  14. * even if strict alignment fault checking is disabled in the system
  15. * control register.
  16. */
  17. asm volatile (
  18. "MOV r5, sp\n"
  19. "ADD r5, #1\n"
  20. "LDRD r6, r7, [r5]\n");
  21. return CMD_RET_FAILURE;
  22. }
  23. static int do_breakpoint(struct cmd_tbl *cmdtp, int flag, int argc,
  24. char *const argv[])
  25. {
  26. asm volatile ("BKPT #123\n");
  27. return CMD_RET_FAILURE;
  28. }
  29. static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
  30. char *const argv[])
  31. {
  32. /*
  33. * 0xe7f...f. is undefined in ARM mode
  34. * 0xde.. is undefined in Thumb mode
  35. */
  36. asm volatile (".word 0xe7f7defb\n");
  37. return CMD_RET_FAILURE;
  38. }
  39. static struct cmd_tbl cmd_sub[] = {
  40. U_BOOT_CMD_MKENT(breakpoint, CONFIG_SYS_MAXARGS, 1, do_breakpoint,
  41. "", ""),
  42. U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
  43. "", ""),
  44. U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined,
  45. "", ""),
  46. };
  47. static char exception_help_text[] =
  48. "<ex>\n"
  49. " The following exceptions are available:\n"
  50. " breakpoint - prefetch abort\n"
  51. " unaligned - data abort\n"
  52. " undefined - undefined instruction\n"
  53. ;
  54. #include <exception.h>