setjmp.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2016 Andes Technology, Inc.
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. /*
  6. setjmp/longjmp for nds32.
  7. r0 - r5 are for paramter passing - no need to save
  8. r6 - r14 are callee saved - needs to save
  9. r15 is temp register for assembler - no need to save
  10. r16 - r25 are caller saved - no need to save
  11. r26 - r27 are temp registers for OS - no need to save
  12. r28 is fp - need to save
  13. r29 is gp - need to save
  14. r30 is ra - need to save
  15. r31 is sp - need to save
  16. so we need to save r6 - r14 and r28 - r31
  17. The jmpbuf looks like this:
  18. r6
  19. r7
  20. r8
  21. r9
  22. r10
  23. r11
  24. r12
  25. r13
  26. r14
  27. fp
  28. gp
  29. ra
  30. sp
  31. #ifdef NDS32_ABI_2FP_PLUS
  32. ($fpcfg.freg)
  33. (callee-saved FPU regs)
  34. #endif
  35. reserved(for 8-byte align if needed)
  36. */
  37. #include <sysdep.h>
  38. #define _SETJMP_H
  39. #define _ASM
  40. #include <bits/setjmp.h>
  41. .section .text
  42. ENTRY(__sigsetjmp)
  43. move $r2, $r0
  44. .off_16bit
  45. ! save registers into buffer
  46. smw.bim $r6, [$r2], $r14, #0xf
  47. .restore_16bit
  48. #ifdef NDS32_ABI_2FP_PLUS
  49. /* Process for FPU registers. */
  50. fmfcfg $r20 /* Keep $fpcfg in $r20. */
  51. slli $r20, $r20, #28
  52. srli $r20, $r20, #30 /* Set $r20 as $fpcfg.freg. */
  53. swi.bi $r20, [$r2], #4
  54. /* Case switch for $r20 as $fpcfg.freg. */
  55. beqz $r20, .LCFG0 /* Branch if $fpcfg.freg = 0b00. */
  56. xori $r15, $r20, #0b10
  57. beqz $r15, .LCFG2 /* Branch if $fpcfg.freg = 0b10. */
  58. srli $r20, $r20, #0b01
  59. beqz $r20, .LCFG1 /* Branch if $fpcfg.freg = 0b01. */
  60. /* Fall-through if $fpcfg.freg = 0b11. */
  61. .LCFG3:
  62. fsdi.bi $fd31, [$r2], #8
  63. fsdi.bi $fd30, [$r2], #8
  64. fsdi.bi $fd29, [$r2], #8
  65. fsdi.bi $fd28, [$r2], #8
  66. fsdi.bi $fd27, [$r2], #8
  67. fsdi.bi $fd26, [$r2], #8
  68. fsdi.bi $fd25, [$r2], #8
  69. fsdi.bi $fd24, [$r2], #8
  70. .LCFG2:
  71. fsdi.bi $fd10, [$r2], #8
  72. fsdi.bi $fd9, [$r2], #8
  73. fsdi.bi $fd8, [$r2], #8
  74. .LCFG1:
  75. fsdi.bi $fd7, [$r2], #8
  76. fsdi.bi $fd6, [$r2], #8
  77. fsdi.bi $fd5, [$r2], #8
  78. fsdi.bi $fd4, [$r2], #8
  79. .LCFG0:
  80. fsdi.bi $fd3, [$r2], #8
  81. #endif /* NDS32_ABI_2FP_PLUS */
  82. /* Make a tail call to __sigjmp_save. */
  83. #ifdef PIC
  84. /* Initialize $r2 as $gp value. */
  85. sethi $r2, hi20(_GLOBAL_OFFSET_TABLE_-8)
  86. ori $r2, $r2, lo12(_GLOBAL_OFFSET_TABLE_-4)
  87. mfusr $r15, $pc
  88. add $r2, $r15, $r2
  89. ! la $r3, __sigjmp_save@PLT
  90. sethi $r3, hi20(__sigjmp_save@PLT)
  91. ori $r3, $r3, lo12(__sigjmp_save@PLT)
  92. add $r3, $r3, $r2
  93. jr $r3
  94. #else /* NOT PIC */
  95. la $r15, C_SYMBOL_NAME(__sigjmp_save)
  96. jr $r15
  97. #endif
  98. END(__sigsetjmp)
  99. libc_hidden_def(__sigsetjmp)