macro.h 1.8 KB

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