nlrmips.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2013-2017 Damien P. George
  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_MIPS
  28. __attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr);
  29. __asm(
  30. ".globl nlr_push \n"
  31. "nlr_push: \n"
  32. ".ent nlr_push \n"
  33. ".frame $29, 0, $31 \n"
  34. ".set noreorder \n"
  35. ".cpload $25 \n"
  36. ".set reorder \n"
  37. "sw $31, 8($4) \n" /* is the offset of regs in nlr_buf_t */
  38. "sw $30, 12($4) \n"
  39. "sw $29, 16($4) \n"
  40. "sw $28, 20($4) \n"
  41. "sw $23, 24($4) \n"
  42. "sw $22, 28($4) \n"
  43. "sw $21, 32($4) \n"
  44. "sw $20, 36($4) \n"
  45. "sw $19, 40($4) \n"
  46. "sw $18, 44($4) \n"
  47. "sw $17, 48($4) \n"
  48. "sw $16, 52($4) \n"
  49. #ifdef __pic__
  50. "la $25, nlr_push_tail \n"
  51. #endif
  52. "j nlr_push_tail \n"
  53. ".end nlr_push \n"
  54. );
  55. NORETURN void nlr_jump(void *val) {
  56. MP_NLR_JUMP_HEAD(val, top)
  57. __asm(
  58. "move $4, %0 \n"
  59. "lw $31, 8($4) \n"
  60. "lw $30, 12($4) \n"
  61. "lw $29, 16($4) \n"
  62. "lw $28, 20($4) \n"
  63. "lw $23, 24($4) \n"
  64. "lw $22, 28($4) \n"
  65. "lw $21, 32($4) \n"
  66. "lw $20, 36($4) \n"
  67. "lw $19, 40($4) \n"
  68. "lw $18, 44($4) \n"
  69. "lw $17, 48($4) \n"
  70. "lw $16, 52($4) \n"
  71. "lui $2,1 \n" // set return value 1
  72. "j $31 \n"
  73. "nop \n"
  74. :
  75. : "r" (top)
  76. : "memory"
  77. );
  78. MP_UNREACHABLE
  79. }
  80. #endif // MICROPY_NLR_MIPS