call_o32.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * O32 interface for the 64 (or N32) ABI.
  4. *
  5. * Copyright (C) 2002, 2014 Maciej W. Rozycki
  6. */
  7. #include <asm/asm.h>
  8. #include <asm/regdef.h>
  9. /* O32 register size. */
  10. #define O32_SZREG 4
  11. /* Maximum number of arguments supported. Must be even! */
  12. #define O32_ARGC 32
  13. /* Number of static registers we save. */
  14. #define O32_STATC 11
  15. /* Argument area frame size. */
  16. #define O32_ARGSZ (O32_SZREG * O32_ARGC)
  17. /* Static register save area frame size. */
  18. #define O32_STATSZ (SZREG * O32_STATC)
  19. /* Stack pointer register save area frame size. */
  20. #define O32_SPSZ SZREG
  21. /* Combined area frame size. */
  22. #define O32_FRAMESZ (O32_ARGSZ + O32_SPSZ + O32_STATSZ)
  23. /* Switched stack frame size. */
  24. #define O32_NFRAMESZ (O32_ARGSZ + O32_SPSZ)
  25. .text
  26. /*
  27. * O32 function call dispatcher, for interfacing 32-bit ROM routines.
  28. *
  29. * The standard 64 (N32) calling sequence is supported, with a0 holding
  30. * a function pointer, a1 a pointer to the new stack to call the
  31. * function with or 0 if no stack switching is requested, a2-a7 -- the
  32. * function call's first six arguments, and the stack -- the remaining
  33. * arguments (up to O32_ARGC, including a2-a7). Static registers, gp
  34. * and fp are preserved, v0 holds the result. This code relies on the
  35. * called o32 function for sp and ra restoration and this dispatcher has
  36. * to be placed in a KSEGx (or KUSEG) address space. Any pointers
  37. * passed have to point to addresses within one of these spaces as well.
  38. */
  39. NESTED(call_o32, O32_FRAMESZ, ra)
  40. REG_SUBU sp,O32_FRAMESZ
  41. REG_S ra,O32_FRAMESZ-1*SZREG(sp)
  42. REG_S fp,O32_FRAMESZ-2*SZREG(sp)
  43. REG_S gp,O32_FRAMESZ-3*SZREG(sp)
  44. REG_S s7,O32_FRAMESZ-4*SZREG(sp)
  45. REG_S s6,O32_FRAMESZ-5*SZREG(sp)
  46. REG_S s5,O32_FRAMESZ-6*SZREG(sp)
  47. REG_S s4,O32_FRAMESZ-7*SZREG(sp)
  48. REG_S s3,O32_FRAMESZ-8*SZREG(sp)
  49. REG_S s2,O32_FRAMESZ-9*SZREG(sp)
  50. REG_S s1,O32_FRAMESZ-10*SZREG(sp)
  51. REG_S s0,O32_FRAMESZ-11*SZREG(sp)
  52. move jp,a0
  53. move fp,sp
  54. beqz a1,0f
  55. REG_SUBU fp,a1,O32_NFRAMESZ
  56. 0:
  57. REG_S sp,O32_NFRAMESZ-1*SZREG(fp)
  58. sll a0,a2,zero
  59. sll a1,a3,zero
  60. sll a2,a4,zero
  61. sll a3,a5,zero
  62. sw a6,4*O32_SZREG(fp)
  63. sw a7,5*O32_SZREG(fp)
  64. PTR_LA t0,O32_FRAMESZ(sp)
  65. PTR_LA t1,6*O32_SZREG(fp)
  66. li t2,O32_ARGC-6
  67. 1:
  68. lw t3,(t0)
  69. REG_ADDU t0,SZREG
  70. sw t3,(t1)
  71. REG_SUBU t2,1
  72. REG_ADDU t1,O32_SZREG
  73. bnez t2,1b
  74. move sp,fp
  75. jalr jp
  76. REG_L sp,O32_NFRAMESZ-1*SZREG(sp)
  77. REG_L s0,O32_FRAMESZ-11*SZREG(sp)
  78. REG_L s1,O32_FRAMESZ-10*SZREG(sp)
  79. REG_L s2,O32_FRAMESZ-9*SZREG(sp)
  80. REG_L s3,O32_FRAMESZ-8*SZREG(sp)
  81. REG_L s4,O32_FRAMESZ-7*SZREG(sp)
  82. REG_L s5,O32_FRAMESZ-6*SZREG(sp)
  83. REG_L s6,O32_FRAMESZ-5*SZREG(sp)
  84. REG_L s7,O32_FRAMESZ-4*SZREG(sp)
  85. REG_L gp,O32_FRAMESZ-3*SZREG(sp)
  86. REG_L fp,O32_FRAMESZ-2*SZREG(sp)
  87. REG_L ra,O32_FRAMESZ-1*SZREG(sp)
  88. REG_ADDU sp,O32_FRAMESZ
  89. jr ra
  90. END(call_o32)