test_main.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #include <sbi/sbi_ecall_interface.h>
  10. #define SBI_ECALL(__num, __a0, __a1, __a2) \
  11. ({ \
  12. register unsigned long a0 asm("a0") = (unsigned long)(__a0); \
  13. register unsigned long a1 asm("a1") = (unsigned long)(__a1); \
  14. register unsigned long a2 asm("a2") = (unsigned long)(__a2); \
  15. register unsigned long a7 asm("a7") = (unsigned long)(__num); \
  16. asm volatile("ecall" \
  17. : "+r"(a0) \
  18. : "r"(a1), "r"(a2), "r"(a7) \
  19. : "memory"); \
  20. a0; \
  21. })
  22. #define SBI_ECALL_0(__num) SBI_ECALL(__num, 0, 0, 0)
  23. #define SBI_ECALL_1(__num, __a0) SBI_ECALL(__num, __a0, 0, 0)
  24. #define SBI_ECALL_2(__num, __a0, __a1) SBI_ECALL(__num, __a0, __a1, 0)
  25. #define sbi_ecall_console_putc(c) SBI_ECALL_1(SBI_EXT_0_1_CONSOLE_PUTCHAR, (c))
  26. static inline void sbi_ecall_console_puts(const char *str)
  27. {
  28. while (str && *str)
  29. sbi_ecall_console_putc(*str++);
  30. }
  31. #define wfi() \
  32. do { \
  33. __asm__ __volatile__("wfi" ::: "memory"); \
  34. } while (0)
  35. void test_main(unsigned long a0, unsigned long a1)
  36. {
  37. sbi_ecall_console_puts("\nTest payload running\n");
  38. while (1)
  39. wfi();
  40. }