exception.c 1.0 KB

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