invokeNative_mips.s 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. .text
  17. .align 2
  18. .globl invokeNative
  19. .ent invokeNative
  20. .type invokeNative, @function
  21. /**
  22. * On function entry parameters:
  23. * $4 = func_ptr
  24. * $5 = args
  25. * $6 = arg_num
  26. */
  27. invokeNative:
  28. .frame $fp, 8, $0
  29. .mask 0x00000000, 0
  30. .fmask 0x00000000, 0
  31. /* Fixed part of frame */
  32. subu $sp, 8
  33. /* save registers */
  34. sw $31, 4($sp)
  35. sw $fp, 0($sp)
  36. /* set frame pointer to bottom of fixed frame */
  37. move $fp, $sp
  38. /* allocate enough stack space */
  39. sll $11, $6, 2 /* $11 == arg_num * 4 */
  40. subu $sp, $11
  41. /* make 8-byte aligned */
  42. and $sp, ~7
  43. move $9, $sp
  44. move $25, $4 /* $25 = func_ptr */
  45. push_args:
  46. beq $6, 0, done /* arg_num == 0 ? */
  47. lw $8, 0($5) /* $8 = *args */
  48. sw $8, 0($9) /* store $8 to stack */
  49. addu $5, 4 /* args++ */
  50. addu $9, 4 /* sp++ */
  51. subu $6, 1 /* arg_num-- */
  52. j push_args
  53. done:
  54. lw $4, 0($sp) /* Load $4..$7 from stack */
  55. lw $5, 4($sp)
  56. lw $6, 8($sp)
  57. lw $7, 12($sp)
  58. ldc1 $f12, 0($sp) /* Load $f12, $f13, $f14, $f15 */
  59. ldc1 $f14, 8($sp)
  60. jalr $25 /* call function */
  61. nop
  62. /* restore saved registers */
  63. move $sp, $fp
  64. lw $31, 4($sp)
  65. lw $fp, 0($sp)
  66. /* pop frame */
  67. addu $sp, $sp, 8
  68. j $31
  69. .end invokeNative