sys_unix_loong64.s 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: Apache-2.0
  2. // SPDX-FileCopyrightText: 2025 The Ebitengine Authors
  3. //go:build linux
  4. #include "textflag.h"
  5. #include "go_asm.h"
  6. #include "funcdata.h"
  7. #include "abi_loong64.h"
  8. TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0
  9. NO_LOCAL_POINTERS
  10. SUBV $(16*8), R3, R14
  11. MOVD F0, 0(R14)
  12. MOVD F1, 8(R14)
  13. MOVD F2, 16(R14)
  14. MOVD F3, 24(R14)
  15. MOVD F4, 32(R14)
  16. MOVD F5, 40(R14)
  17. MOVD F6, 48(R14)
  18. MOVD F7, 56(R14)
  19. MOVV R4, 64(R14)
  20. MOVV R5, 72(R14)
  21. MOVV R6, 80(R14)
  22. MOVV R7, 88(R14)
  23. MOVV R8, 96(R14)
  24. MOVV R9, 104(R14)
  25. MOVV R10, 112(R14)
  26. MOVV R11, 120(R14)
  27. // Adjust SP by frame size.
  28. SUBV $(22*8), R3
  29. // It is important to save R30 because the go assembler
  30. // uses it for move instructions for a variable.
  31. // This line:
  32. // MOVV ·callbackWrap_call(SB), R4
  33. // Creates the instructions:
  34. // PCALAU12I off1(PC), R30
  35. // MOVV off2(R30), R4
  36. // R30 is a callee saved register so we are responsible
  37. // for ensuring its value doesn't change. So save it and
  38. // restore it at the end of this function.
  39. // R1 is the link register. crosscall2 doesn't save it
  40. // so it's saved here.
  41. MOVV R1, 0(R3)
  42. MOVV R30, 8(R3)
  43. // Create a struct callbackArgs on our stack.
  44. MOVV $(callbackArgs__size)(R3), R13
  45. MOVV R12, callbackArgs_index(R13) // callback index
  46. MOVV R14, callbackArgs_args(R13) // address of args vector
  47. MOVV $0, callbackArgs_result(R13) // result
  48. // Move parameters into registers
  49. // Get the ABIInternal function pointer
  50. // without <ABIInternal> by using a closure.
  51. MOVV ·callbackWrap_call(SB), R4
  52. MOVV (R4), R4 // fn unsafe.Pointer
  53. MOVV R13, R5 // frame (&callbackArgs{...})
  54. MOVV $0, R7 // ctxt uintptr
  55. JAL crosscall2(SB)
  56. // Get callback result.
  57. MOVV $(callbackArgs__size)(R3), R13
  58. MOVV callbackArgs_result(R13), R4
  59. // Restore LR and R30
  60. MOVV 0(R3), R1
  61. MOVV 8(R3), R30
  62. ADDV $(22*8), R3
  63. RET