__longjmp.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /* __longjmp (env[0].__jmpbuf, val ?: 1); */
  43. ENTRY(__longjmp)
  44. ! restore registers
  45. lmw.bim $r6, [$r0], $r14, #0xf
  46. #ifdef NDS32_ABI_2FP_PLUS
  47. lwi.bi $r20, [$r0], #4 /* Load $fpcfg.freg to $r20. */
  48. /* Case switch for $r20 as $fpcfg.freg. */
  49. beqz $r20, .LCFG0 /* Branch if $fpcfg.freg = 0b00. */
  50. xori $r15, $r20, #0b10
  51. beqz $r15, .LCFG2 /* Branch if $fpcfg.freg = 0b10. */
  52. srli $r20, $r20, #0b01
  53. beqz $r20, .LCFG1 /* Branch if $fpcfg.freg = 0b01. */
  54. /* Fall-through if $fpcfg.freg = 0b11. */
  55. .LCFG3:
  56. fldi.bi $fd31, [$r0], #8
  57. fldi.bi $fd30, [$r0], #8
  58. fldi.bi $fd29, [$r0], #8
  59. fldi.bi $fd28, [$r0], #8
  60. fldi.bi $fd27, [$r0], #8
  61. fldi.bi $fd26, [$r0], #8
  62. fldi.bi $fd25, [$r0], #8
  63. fldi.bi $fd24, [$r0], #8
  64. .LCFG2:
  65. fldi.bi $fd10, [$r0], #8
  66. fldi.bi $fd9, [$r0], #8
  67. fldi.bi $fd8, [$r0], #8
  68. .LCFG1:
  69. fldi.bi $fd7, [$r0], #8
  70. fldi.bi $fd6, [$r0], #8
  71. fldi.bi $fd5, [$r0], #8
  72. fldi.bi $fd4, [$r0], #8
  73. .LCFG0:
  74. fldi.bi $fd3, [$r0], #8
  75. #endif /* NDS32_ABI_2FP_PLUS */
  76. ! return error code; make sure error code is not 0
  77. bnez $r1, .Ldone
  78. movi $r1, #1
  79. .Ldone:
  80. addi $r0, $r1, #0
  81. ret
  82. END(__longjmp)
  83. libc_hidden_def(__longjmp)