nlrpowerpc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2019, Michael Neuling, IBM Corporation.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #include "py/mpstate.h"
  27. #if MICROPY_NLR_POWERPC
  28. #undef nlr_push
  29. // Saving all ABI non-vol registers here
  30. unsigned int nlr_push(nlr_buf_t *nlr) {
  31. __asm__ volatile (
  32. "li 4, 0x4eed ; " // Store canary
  33. "std 4, 0x00(%0) ;"
  34. "std 0, 0x08(%0) ;"
  35. "std 1, 0x10(%0) ;"
  36. "std 2, 0x18(%0) ;"
  37. "std 14, 0x20(%0) ;"
  38. "std 15, 0x28(%0) ;"
  39. "std 16, 0x30(%0) ;"
  40. "std 17, 0x38(%0) ;"
  41. "std 18, 0x40(%0) ;"
  42. "std 19, 0x48(%0) ;"
  43. "std 20, 0x50(%0) ;"
  44. "std 21, 0x58(%0) ;"
  45. "std 22, 0x60(%0) ;"
  46. "std 23, 0x68(%0) ;"
  47. "std 24, 0x70(%0) ;"
  48. "std 25, 0x78(%0) ;"
  49. "std 26, 0x80(%0) ;"
  50. "std 27, 0x88(%0) ;"
  51. "std 28, 0x90(%0) ;"
  52. "std 29, 0x98(%0) ;"
  53. "std 30, 0xA0(%0) ;"
  54. "std 31, 0xA8(%0) ;"
  55. "mfcr 4 ; "
  56. "std 4, 0xB0(%0) ;"
  57. "mflr 4 ;"
  58. "std 4, 0xB8(%0) ;"
  59. "li 4, nlr_push_tail@l ;"
  60. "oris 4, 4, nlr_push_tail@h ;"
  61. "mtctr 4 ;"
  62. "mr 3, %1 ; "
  63. "bctr ;"
  64. :
  65. : "r" (&nlr->regs), "r" (nlr)
  66. :
  67. );
  68. return 0;
  69. }
  70. NORETURN void nlr_jump(void *val) {
  71. MP_NLR_JUMP_HEAD(val, top)
  72. __asm__ volatile (
  73. "ld 3, 0x0(%0) ;"
  74. "cmpdi 3, 0x4eed ; " // Check canary
  75. "bne . ; "
  76. "ld 0, 0x08(%0) ;"
  77. "ld 1, 0x10(%0) ;"
  78. "ld 2, 0x18(%0) ;"
  79. "ld 14, 0x20(%0) ;"
  80. "ld 15, 0x28(%0) ;"
  81. "ld 16, 0x30(%0) ;"
  82. "ld 17, 0x38(%0) ;"
  83. "ld 18, 0x40(%0) ;"
  84. "ld 19, 0x48(%0) ;"
  85. "ld 20, 0x50(%0) ;"
  86. "ld 21, 0x58(%0) ;"
  87. "ld 22, 0x60(%0) ;"
  88. "ld 23, 0x68(%0) ;"
  89. "ld 24, 0x70(%0) ;"
  90. "ld 25, 0x78(%0) ;"
  91. "ld 26, 0x80(%0) ;"
  92. "ld 27, 0x88(%0) ;"
  93. "ld 28, 0x90(%0) ;"
  94. "ld 29, 0x98(%0) ;"
  95. "ld 30, 0xA0(%0) ;"
  96. "ld 31, 0xA8(%0) ;"
  97. "ld 3, 0xB0(%0) ;"
  98. "mtcr 3 ;"
  99. "ld 3, 0xB8(%0) ;"
  100. "mtlr 3 ; "
  101. "li 3, 1;"
  102. "blr ;"
  103. :
  104. : "r" (&top->regs)
  105. :
  106. );
  107. MP_UNREACHABLE;
  108. }
  109. #endif // MICROPY_NLR_POWERPC