call_o32.S 2.4 KB

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