macro.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #ifndef __ASM_NDS_MACRO_H
  27. #define __ASM_NDS_MACRO_H
  28. #ifdef __ASSEMBLY__
  29. /*
  30. * These macros provide a convenient way to write 8, 16 and 32 bit data
  31. * to an "immediate address (address used by periphal)" only.
  32. * Registers r4 and r5 are used, any data in these registers are
  33. * overwritten by the macros.
  34. * The macros are valid for any NDS32 architecture, they do not implement
  35. * any memory barriers so caution is recommended when using these when the
  36. * caches are enabled or on a multi-core system.
  37. */
  38. .macro write32, addr, data
  39. li $r4, addr
  40. li $r5, data
  41. swi $r5, [$r4]
  42. .endm
  43. .macro write16, addr, data
  44. li $r4, addr
  45. li $r5, data
  46. shi $r5, [$r4]
  47. .endm
  48. .macro write8, addr, data
  49. li $r4, addr
  50. li $r5, data
  51. sbi $r5, [$r4]
  52. .endm
  53. /*
  54. * This macro read a value from a register, then do OR operation
  55. * (set bit fields) to the value, and then store it back to the register.
  56. * Note: Instruction 'ori' supports immediate value up to 15 bits.
  57. */
  58. .macro setbf32, addr, data
  59. li $r4, addr
  60. lwi $r5, [$r4]
  61. li $r6, data
  62. or $r5, $r5, $r6
  63. swi $r5, [$r4]
  64. .endm
  65. .macro setbf15, addr, data
  66. li $r4, addr
  67. lwi $r5, [$r4]
  68. ori $r5, $r5, data
  69. swi $r5, [$r4]
  70. .endm
  71. /*
  72. * This macro generates a loop that can be used for delays in the code.
  73. * Register r4 is used, any data in this register is overwritten by the
  74. * macro.
  75. * The macro is valid for any NDS32 architeture. The actual time spent in the
  76. * loop will vary from CPU to CPU though.
  77. */
  78. .macro wait_timer, time
  79. li $r4, time
  80. 1:
  81. nop
  82. addi $r4, $r4, -1
  83. bnez $r4, 1b
  84. .endm
  85. #endif /* __ASSEMBLY__ */
  86. #endif /* __ASM_ARM_MACRO_H */