call_o32.S 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * arch/mips/dec/prom/call_o32.S
  3. *
  4. * O32 interface for the 64 (or N32) ABI.
  5. *
  6. * Copyright (C) 2002 Maciej W. Rozycki
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #include <asm/asm.h>
  14. #include <asm/regdef.h>
  15. /* Maximum number of arguments supported. Must be even! */
  16. #define O32_ARGC 32
  17. /* Number of static registers we save. */
  18. #define O32_STATC 11
  19. /* Frame size for static register */
  20. #define O32_FRAMESZ (SZREG * O32_STATC)
  21. /* Frame size on new stack */
  22. #define O32_FRAMESZ_NEW (SZREG + 4 * O32_ARGC)
  23. .text
  24. /*
  25. * O32 function call dispatcher, for interfacing 32-bit ROM routines.
  26. *
  27. * The standard 64 (N32) calling sequence is supported, with a0
  28. * holding a function pointer, a1 a new stack pointer, a2-a7 -- its
  29. * first six arguments and the stack -- remaining ones (up to O32_ARGC,
  30. * including a2-a7). Static registers, gp and fp are preserved, v0 holds
  31. * a result. This code relies on the called o32 function for sp and ra
  32. * restoration and this dispatcher has to be placed in a KSEGx (or KUSEG)
  33. * address space. Any pointers passed have to point to addresses within
  34. * one of these spaces as well.
  35. */
  36. NESTED(call_o32, O32_FRAMESZ, ra)
  37. REG_SUBU sp,O32_FRAMESZ
  38. REG_S ra,O32_FRAMESZ-1*SZREG(sp)
  39. REG_S fp,O32_FRAMESZ-2*SZREG(sp)
  40. REG_S gp,O32_FRAMESZ-3*SZREG(sp)
  41. REG_S s7,O32_FRAMESZ-4*SZREG(sp)
  42. REG_S s6,O32_FRAMESZ-5*SZREG(sp)
  43. REG_S s5,O32_FRAMESZ-6*SZREG(sp)
  44. REG_S s4,O32_FRAMESZ-7*SZREG(sp)
  45. REG_S s3,O32_FRAMESZ-8*SZREG(sp)
  46. REG_S s2,O32_FRAMESZ-9*SZREG(sp)
  47. REG_S s1,O32_FRAMESZ-10*SZREG(sp)
  48. REG_S s0,O32_FRAMESZ-11*SZREG(sp)
  49. move jp,a0
  50. REG_SUBU s0,a1,O32_FRAMESZ_NEW
  51. REG_S sp,O32_FRAMESZ_NEW-1*SZREG(s0)
  52. sll a0,a2,zero
  53. sll a1,a3,zero
  54. sll a2,a4,zero
  55. sll a3,a5,zero
  56. sw a6,0x10(s0)
  57. sw a7,0x14(s0)
  58. PTR_LA t0,O32_FRAMESZ(sp)
  59. PTR_LA t1,0x18(s0)
  60. li t2,O32_ARGC-6
  61. 1:
  62. lw t3,(t0)
  63. REG_ADDU t0,SZREG
  64. sw t3,(t1)
  65. REG_SUBU t2,1
  66. REG_ADDU t1,4
  67. bnez t2,1b
  68. move sp,s0
  69. jalr jp
  70. REG_L sp,O32_FRAMESZ_NEW-1*SZREG(sp)
  71. REG_L s0,O32_FRAMESZ-11*SZREG(sp)
  72. REG_L s1,O32_FRAMESZ-10*SZREG(sp)
  73. REG_L s2,O32_FRAMESZ-9*SZREG(sp)
  74. REG_L s3,O32_FRAMESZ-8*SZREG(sp)
  75. REG_L s4,O32_FRAMESZ-7*SZREG(sp)
  76. REG_L s5,O32_FRAMESZ-6*SZREG(sp)
  77. REG_L s6,O32_FRAMESZ-5*SZREG(sp)
  78. REG_L s7,O32_FRAMESZ-4*SZREG(sp)
  79. REG_L gp,O32_FRAMESZ-3*SZREG(sp)
  80. REG_L fp,O32_FRAMESZ-2*SZREG(sp)
  81. REG_L ra,O32_FRAMESZ-1*SZREG(sp)
  82. REG_ADDU sp,O32_FRAMESZ
  83. jr ra
  84. END(call_o32)