test_main.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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(__eid, __fid, __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 a6 asm("a6") = (unsigned long)(__fid); \
  16. register unsigned long a7 asm("a7") = (unsigned long)(__eid); \
  17. asm volatile("ecall" \
  18. : "+r"(a0) \
  19. : "r"(a1), "r"(a2), "r"(a6), "r"(a7) \
  20. : "memory"); \
  21. a0; \
  22. })
  23. #define SBI_ECALL_0(__eid, __fid) SBI_ECALL(__eid, __fid, 0, 0, 0)
  24. #define SBI_ECALL_1(__eid, __fid, __a0) SBI_ECALL(__eid, __fid, __a0, 0, 0)
  25. #define SBI_ECALL_2(__eid, __fid, __a0, __a1) SBI_ECALL(__eid, __fid, __a0, __a1, 0)
  26. #define sbi_ecall_console_putc(c) SBI_ECALL_1(SBI_EXT_0_1_CONSOLE_PUTCHAR, 0, (c))
  27. static inline void sbi_ecall_console_puts(const char *str)
  28. {
  29. while (str && *str)
  30. sbi_ecall_console_putc(*str++);
  31. }
  32. #define wfi() \
  33. do { \
  34. __asm__ __volatile__("wfi" ::: "memory"); \
  35. } while (0)
  36. void test_main(unsigned long a0, unsigned long a1)
  37. {
  38. sbi_ecall_console_puts("\nTest payload running\n");
  39. while (1)
  40. wfi();
  41. }