cpuport.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-10-25 Shell Move ffs to cpuport, add general implementation
  9. * by inline assembly
  10. * 2024-01-18 Shell support rt_hw_thread_self to improve overall performance
  11. */
  12. #ifndef CPUPORT_H__
  13. #define CPUPORT_H__
  14. #include <armv8.h>
  15. #include <rtcompiler.h>
  16. #include <rttypes.h>
  17. #ifdef RT_USING_SMP
  18. /**
  19. * Spinlock
  20. */
  21. typedef struct
  22. {
  23. rt_uint32_t value;
  24. } rt_hw_spinlock_t;
  25. #endif /* RT_USING_SMP */
  26. #define rt_hw_barrier(cmd, ...) \
  27. __asm__ volatile (RT_STRINGIFY(cmd) " "RT_STRINGIFY(__VA_ARGS__):::"memory")
  28. #define rt_hw_isb() rt_hw_barrier(isb)
  29. #define rt_hw_dmb() rt_hw_barrier(dmb, ish)
  30. #define rt_hw_wmb() rt_hw_barrier(dmb, ishst)
  31. #define rt_hw_rmb() rt_hw_barrier(dmb, ishld)
  32. #define rt_hw_dsb() rt_hw_barrier(dsb, ish)
  33. #define rt_hw_wfi() rt_hw_barrier(wfi)
  34. #define rt_hw_wfe() rt_hw_barrier(wfe)
  35. #define rt_hw_sev() rt_hw_barrier(sev)
  36. #define rt_hw_cpu_relax() rt_hw_barrier(yield)
  37. #define rt_hw_sysreg_write(sysreg, val) \
  38. __asm__ volatile ("msr "RT_STRINGIFY(sysreg)", %0"::"r"((rt_uint64_t)(val)))
  39. #define rt_hw_sysreg_read(sysreg, val) \
  40. __asm__ volatile ("mrs %0, "RT_STRINGIFY(sysreg)"":"=r"((val)))
  41. void _thread_start(void);
  42. #ifdef ARCH_USING_HW_THREAD_SELF
  43. rt_inline struct rt_thread *rt_hw_thread_self(void)
  44. {
  45. struct rt_thread *thread;
  46. __asm__ volatile ("mrs %0, " RT_STRINGIFY(ARM64_THREAD_REG) :"=r"(thread));
  47. return thread;
  48. }
  49. rt_inline void rt_hw_thread_set_self(struct rt_thread *thread)
  50. {
  51. __asm__ volatile ("msr " RT_STRINGIFY(ARM64_THREAD_REG) ", %0"::"r"(thread));
  52. }
  53. #endif /* ARCH_USING_HW_THREAD_SELF */
  54. #endif /*CPUPORT_H__*/