macro.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * include/asm-nds32/macro.h
  4. *
  5. * Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  6. * Copyright (C) 2011 Andes Technology Corporation
  7. * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
  8. */
  9. #ifndef __ASM_NDS_MACRO_H
  10. #define __ASM_NDS_MACRO_H
  11. #ifdef __ASSEMBLY__
  12. /*
  13. * These macros provide a convenient way to write 8, 16 and 32 bit data
  14. * to an "immediate address (address used by periphal)" only.
  15. * Registers r4 and r5 are used, any data in these registers are
  16. * overwritten by the macros.
  17. * The macros are valid for any NDS32 architecture, they do not implement
  18. * any memory barriers so caution is recommended when using these when the
  19. * caches are enabled or on a multi-core system.
  20. */
  21. .macro write32, addr, data
  22. li $r4, \addr
  23. li $r5, \data
  24. swi $r5, [$r4]
  25. .endm
  26. .macro write16, addr, data
  27. li $r4, \addr
  28. li $r5, \data
  29. shi $r5, [$r4]
  30. .endm
  31. .macro write8, addr, data
  32. li $r4, \addr
  33. li $r5, \data
  34. sbi $r5, [$r4]
  35. .endm
  36. /*
  37. * This macro read a value from a register, then do OR operation
  38. * (set bit fields) to the value, and then store it back to the register.
  39. * Note: Instruction 'ori' supports immediate value up to 15 bits.
  40. */
  41. .macro setbf32, addr, data
  42. li $r4, \addr
  43. lwi $r5, [$r4]
  44. li $r6, \data
  45. or $r5, $r5, $r6
  46. swi $r5, [$r4]
  47. .endm
  48. .macro setbf15, addr, data
  49. li $r4, \addr
  50. lwi $r5, [$r4]
  51. ori $r5, $r5, \data
  52. swi $r5, [$r4]
  53. .endm
  54. /*
  55. * This macro generates a loop that can be used for delays in the code.
  56. * Register r4 is used, any data in this register is overwritten by the
  57. * macro.
  58. * The macro is valid for any NDS32 architeture. The actual time spent in the
  59. * loop will vary from CPU to CPU though.
  60. */
  61. .macro wait_timer, time
  62. li $r4, \time
  63. 1:
  64. nop
  65. addi $r4, $r4, -1
  66. bnez $r4, 1b
  67. .endm
  68. #endif /* __ASSEMBLY__ */
  69. #endif /* __ASM_ARM_MACRO_H */