arc_asm_common.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /* ------------------------------------------
  2. * Copyright (c) 2016, Synopsys, Inc. All rights reserved.
  3. * Redistribution and use in source and binary forms, with or without modification,
  4. * are permitted provided that the following conditions are met:
  5. * 1) Redistributions of source code must retain the above copyright notice, this
  6. * list of conditions and the following disclaimer.
  7. * 2) Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation and/or
  9. * other materials provided with the distribution.
  10. * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
  11. * be used to endorse or promote products derived from this software without
  12. * specific prior written permission.
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * \version 2016.05
  25. * \date 2014-07-15
  26. * \author Wayne Ren(Wei.Ren@synopsys.com)
  27. --------------------------------------------- */
  28. /**
  29. * \file
  30. * \ingroup ARC_HAL_MISC
  31. * \brief common macro definitions for assembly file
  32. */
  33. /** @cond ARC_HAL_ASM_COMMON */
  34. #ifndef _ARC_HAL_ASM_COMMON_H_
  35. #define _ARC_HAL_ASM_COMMON_H_
  36. #include "embARC_BSP_config.h"
  37. #include "arc_feature_config.h"
  38. /* Note on the LD/ST addr modes with addr reg wback
  39. *
  40. * LD.a same as LD.aw
  41. *
  42. * LD.a reg1, [reg2, x] => Pre Incr
  43. * Eff Addr for load = [reg2 + x]
  44. *
  45. * LD.ab reg1, [reg2, x] => Post Incr
  46. * Eff Addr for load = [reg2]
  47. */
  48. #if defined(__GNU__)
  49. .macro PUSH reg
  50. st.a \reg, [sp, -4]
  51. .endm
  52. .macro PUSHAX aux
  53. lr r10, [\aux]
  54. PUSH r10
  55. .endm
  56. .macro POP reg
  57. ld.ab \reg, [sp, 4]
  58. .endm
  59. .macro POPAX aux
  60. POP r10
  61. sr r10, [\aux]
  62. .endm
  63. #else
  64. .macro PUSH, reg
  65. st.a reg, [sp, -4]
  66. .endm
  67. .macro PUSHAX, aux
  68. lr r10, [aux]
  69. PUSH r10
  70. .endm
  71. .macro POP, reg
  72. ld.ab reg, [sp, 4]
  73. .endm
  74. .macro POPAX, aux
  75. POP r10
  76. sr r10, [aux]
  77. .endm
  78. #endif
  79. /*--------------------------------------------------------------
  80. * Helpers to save/restore callee-saved regs:
  81. * used by several macros below
  82. *-------------------------------------------------------------*/
  83. .macro SAVE_CALLEE_REGS
  84. PUSH r13
  85. PUSH r14
  86. PUSH r15
  87. #ifndef ARC_FEATURE_RF16
  88. PUSH r16
  89. PUSH r17
  90. PUSH r18
  91. PUSH r19
  92. PUSH r20
  93. PUSH r21
  94. PUSH r22
  95. PUSH r23
  96. PUSH r24
  97. PUSH r25
  98. #endif
  99. .endm
  100. .macro RESTORE_CALLEE_REGS
  101. #ifndef ARC_FEATURE_RF16
  102. POP r25
  103. POP r24
  104. POP r23
  105. POP r22
  106. POP r21
  107. POP r20
  108. POP r19
  109. POP r18
  110. POP r17
  111. POP r16
  112. #endif
  113. POP r15
  114. POP r14
  115. POP r13
  116. .endm
  117. .macro CLEAR_CALLEE_REGS
  118. #ifndef ARC_FEATURE_RF16
  119. mov r25, 0
  120. mov r24, 0
  121. mov r23, 0
  122. mov r22, 0
  123. mov r21, 0
  124. mov r20, 0
  125. mov r19, 0
  126. mov r18, 0
  127. mov r17, 0
  128. mov r16, 0
  129. #endif
  130. mov r15, 0
  131. mov r14, 0
  132. mov r13, 0
  133. .endm
  134. .macro CLEAR_SCRATCH_REGS
  135. mov r1, 0
  136. mov r2, 0
  137. mov r3, 0
  138. mov r4, 0
  139. mov r5, 0
  140. mov r6, 0
  141. mov r7, 0
  142. mov r8, 0
  143. mov r9, 0
  144. mov r10, 0
  145. mov r11, 0
  146. mov r12, 0
  147. mov fp, 0
  148. mov r29, 0
  149. mov r30, 0
  150. .endm
  151. .macro SAVE_LP_REGS
  152. PUSH r60
  153. PUSHAX AUX_LP_START
  154. PUSHAX AUX_LP_END
  155. .endm
  156. .macro RESTORE_LP_REGS
  157. POPAX AUX_LP_END
  158. POPAX AUX_LP_START
  159. POP r10
  160. /* must not use the LP_COUNT register(r60) as the destination of multi-cycle instruction */
  161. mov r60, r10
  162. .endm
  163. .macro SAVE_R0_TO_R12
  164. PUSH r0
  165. PUSH r1
  166. PUSH r2
  167. PUSH r3
  168. #ifndef ARC_FEATURE_RF16
  169. PUSH r4
  170. PUSH r5
  171. PUSH r6
  172. PUSH r7
  173. PUSH r8
  174. PUSH r9
  175. #endif
  176. PUSH r10
  177. PUSH r11
  178. PUSH r12
  179. .endm
  180. .macro RESTORE_R0_TO_R12
  181. POP r12
  182. POP r11
  183. POP r10
  184. #ifndef ARC_FEATURE_RF16
  185. POP r9
  186. POP r8
  187. POP r7
  188. POP r6
  189. POP r5
  190. POP r4
  191. #endif
  192. POP r3
  193. POP r2
  194. POP r1
  195. POP r0
  196. .endm
  197. .macro SAVE_CODE_DENSITY
  198. PUSHAX AUX_JLI_BASE
  199. PUSHAX AUX_LDI_BASE
  200. PUSHAX AUX_EI_BASE
  201. .endm
  202. .macro RESTORE_CODE_DENSITY
  203. POPAX AUX_EI_BASE
  204. POPAX AUX_LDI_BASE
  205. POPAX AUX_JLI_BASE
  206. .endm
  207. /* todo: check the contents of NON_SCRATCH_REGS in debug */
  208. .macro SAVE_NONSCRATCH_REGS
  209. /* r0-r12 are saved by caller function */
  210. PUSH gp
  211. PUSH fp
  212. PUSH blink
  213. SAVE_CALLEE_REGS
  214. .endm
  215. .macro RESTORE_NONSCRATCH_REGS
  216. RESTORE_CALLEE_REGS
  217. POP blink
  218. POP fp
  219. POP gp
  220. .endm
  221. .macro SAVE_FIQ_EXC_REGS
  222. #ifndef ARC_FEATURE_RGF_BANKED_REGS
  223. SAVE_R0_TO_R12
  224. PUSH gp
  225. PUSH fp
  226. PUSH r30 /* general purpose */
  227. PUSH blink
  228. #else
  229. #if ARC_FEATURE_RGF_BANKED_REGS != 4 && ARC_FEATURE_RGF_BANKED_REGS != 8 && \
  230. ARC_FEATURE_RGF_BANKED_REGS != 16 && ARC_FEATURE_RGF_BANKED_REGS != 32
  231. #error "unsupported ARC_FEATURE_RGF_BANKED_REGS"
  232. #endif
  233. #if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8 || \
  234. ARC_FEATURE_RGF_BANKED_REGS == 16
  235. PUSH r4
  236. PUSH r5
  237. PUSH r6
  238. PUSH r7
  239. PUSH r8
  240. PUSH r9
  241. #endif
  242. #if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8
  243. PUSH r10
  244. PUSH r11
  245. #endif
  246. #if ARC_FEATURE_RGF_BANKED_REGS == 4
  247. PUSH r12
  248. #endif
  249. #if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8
  250. PUSH gp
  251. PUSH fp
  252. PUSH r30 /* general purpose */
  253. PUSH blink
  254. #endif
  255. #endif /* #ifndef ARC_FEATURE_RGF_BANKED_REGS */
  256. #ifdef ARC_FEATURE_CODE_DENSITY
  257. SAVE_CODE_DENSITY
  258. #endif
  259. SAVE_LP_REGS
  260. .endm
  261. .macro RESTORE_FIQ_EXC_REGS
  262. RESTORE_LP_REGS
  263. #ifdef ARC_FEATURE_CODE_DENSITY
  264. RESTORE_CODE_DENSITY
  265. #endif
  266. #ifndef ARC_FEATURE_RGF_BANKED_REGS
  267. POP blink
  268. POP r30
  269. POP fp
  270. POP gp
  271. RESTORE_R0_TO_R12
  272. #else
  273. #if ARC_FEATURE_RGF_BANKED_REGS != 4 && ARC_FEATURE_RGF_BANKED_REGS != 8 && \
  274. ARC_FEATURE_RGF_BANKED_REGS != 16 && ARC_FEATURE_RGF_BANKED_REGS != 32
  275. #error "unsupported ARC_FEATURE_RGF_BANKED_REGS"
  276. #endif
  277. #if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8
  278. POP blink
  279. POP r30
  280. POP fp
  281. POP gp
  282. #endif
  283. #if ARC_FEATURE_RGF_BANKED_REGS == 4
  284. POP r12
  285. #endif
  286. #if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8
  287. POP r11
  288. POP r10
  289. #endif
  290. #if ARC_FEATURE_RGF_BANKED_REGS == 4 || ARC_FEATURE_BANKED_REGS == 8 || \
  291. ARC_FEATURE_RGF_BANKED_REGS == 16
  292. POP r9
  293. POP r8
  294. POP r7
  295. POP r6
  296. POP r5
  297. POP r4
  298. #endif
  299. #endif /* #ifndef ARC_FEATURE_RGF_BANKED_REGS */
  300. .endm
  301. /* normal interrupt prologue, pc, status and r0-r11 are saved by hardware */
  302. .macro INTERRUPT_PROLOGUE
  303. PUSH r12
  304. PUSH gp
  305. PUSH fp
  306. PUSH ilink
  307. PUSH r30
  308. sub sp, sp, 4 /* skip bta */
  309. .endm
  310. /* normal interrupt epilogue, pc, status and r0-r11 are restored by hardware */
  311. .macro INTERRUPT_EPILOGUE
  312. add sp, sp, 4 /* skip bta */
  313. POP r30
  314. POP ilink
  315. POP fp
  316. POP gp
  317. POP r12
  318. .endm
  319. #if SECURESHIELD_VERSION == 2
  320. /* exception prologue, create the same frame of interrupt manually */
  321. .macro EXCEPTION_PROLOGUE
  322. st.as r10, [sp, -6] /* save r10 first, free up a register*/
  323. PUSHAX AUX_ERSTATUS
  324. sub sp, sp, 4 /* slot for SEC_STAT */
  325. PUSHAX AUX_ERRET
  326. PUSH blink
  327. PUSH r11
  328. sub sp, sp, 4 /* r10 is pushed before */
  329. #ifndef ARC_FEATURE_RF16
  330. PUSH r9
  331. PUSH r8
  332. PUSH r7
  333. PUSH r6
  334. PUSH r5
  335. PUSH r4
  336. #endif
  337. PUSH r3
  338. PUSH r2
  339. PUSH r1
  340. PUSH r0
  341. #ifdef ARC_FEATURE_CODE_DENSITY
  342. SAVE_CODE_DENSITY
  343. #endif
  344. SAVE_LP_REGS
  345. PUSH r12
  346. PUSH gp
  347. PUSH fp
  348. PUSH ilink
  349. PUSH r30
  350. PUSHAX AUX_ERBTA
  351. .endm
  352. /* exception epilogue, restore the same frame of interrupt manually */
  353. .macro EXCEPTION_EPILOGUE
  354. POPAX AUX_ERBTA
  355. POP r30
  356. POP ilink
  357. POP fp
  358. POP gp
  359. POP r12
  360. RESTORE_LP_REGS
  361. #ifdef ARC_FEATURE_CODE_DENSITY
  362. RESTORE_CODE_DENSITY
  363. #endif
  364. POP r0
  365. POP r1
  366. POP r2
  367. POP r3
  368. #ifndef ARC_FEATURE_RF16
  369. POP r4
  370. POP r5
  371. POP r6
  372. POP r7
  373. POP r8
  374. POP r9
  375. #endif
  376. add sp, sp, 4 /* r10 will be popped finally */
  377. POP r11
  378. POP blink
  379. POPAX AUX_ERRET
  380. add sp, sp, 4 /* slot for SEC_STAT */
  381. POPAX AUX_ERSTATUS
  382. ld.as r10, [sp, -6] /* restore r10 */
  383. .endm
  384. #else /* normal version */
  385. /* exception prologue, create the same frame of interrupt manually */
  386. .macro EXCEPTION_PROLOGUE
  387. #ifdef ARC_FEATURE_CODE_DENSITY
  388. st.as r10, [sp, -11] /* save r10 first, free up a register*/
  389. #else
  390. st.as r10, [sp, -8]
  391. #endif
  392. PUSHAX AUX_ERSTATUS
  393. PUSHAX AUX_ERRET
  394. #ifdef ARC_FEATURE_CODE_DENSITY
  395. SAVE_CODE_DENSITY
  396. #endif
  397. SAVE_LP_REGS
  398. PUSH blink
  399. PUSH r11
  400. sub sp, sp, 4 /* r10 is pushed before */
  401. #ifndef ARC_FEATURE_RF16
  402. PUSH r9
  403. PUSH r8
  404. PUSH r7
  405. PUSH r6
  406. PUSH r5
  407. PUSH r4
  408. #endif
  409. PUSH r3
  410. PUSH r2
  411. PUSH r1
  412. PUSH r0
  413. PUSH r12
  414. PUSH gp
  415. PUSH fp
  416. PUSH ilink
  417. PUSH r30
  418. PUSHAX AUX_ERBTA
  419. .endm
  420. /* exception epilogue, restore the same frame of interrupt manually */
  421. .macro EXCEPTION_EPILOGUE
  422. POPAX AUX_ERBTA
  423. POP r30
  424. POP ilink
  425. POP fp
  426. POP gp
  427. POP r12
  428. POP r0
  429. POP r1
  430. POP r2
  431. POP r3
  432. #ifndef ARC_FEATURE_RF16
  433. POP r4
  434. POP r5
  435. POP r6
  436. POP r7
  437. POP r8
  438. POP r9
  439. #endif
  440. add sp, sp, 4 /* r10 will be popped finally */
  441. POP r11
  442. POP blink
  443. RESTORE_LP_REGS
  444. #ifdef ARC_FEATURE_CODE_DENSITY
  445. RESTORE_CODE_DENSITY
  446. #endif
  447. POPAX AUX_ERRET
  448. POPAX AUX_ERSTATUS
  449. #ifdef ARC_FEATURE_CODE_DENSITY
  450. ld.as r10, [sp, -11] /* restore r10 */
  451. #else
  452. ld.as r10, [sp, -8]
  453. #endif
  454. .endm
  455. #endif /* SECURESHIELD_VERSION == 2 */
  456. #endif /* _ARC_HAL_ASM_COMMON_H */
  457. /** @endcond */