spu_restore_crt0.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * crt0_r.S: Entry function for SPU-side context restore.
  3. *
  4. * Copyright (C) 2005 IBM
  5. *
  6. * Entry and exit function for SPU-side of the context restore
  7. * sequence. Sets up an initial stack frame, then branches to
  8. * 'main'. On return, restores all 128 registers from the LSCSA
  9. * and exits.
  10. *
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2, or (at your option)
  15. * any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  25. */
  26. #include <asm/spu_csa.h>
  27. .data
  28. .align 7
  29. .globl regs_spill
  30. regs_spill:
  31. .space SIZEOF_SPU_SPILL_REGS, 0x0
  32. .text
  33. .global _start
  34. _start:
  35. /* Initialize the stack pointer to point to 16368
  36. * (16kb-16). The back chain pointer is initialized
  37. * to NULL.
  38. */
  39. il $0, 0
  40. il $SP, 16368
  41. stqd $0, 0($SP)
  42. /* Allocate a minimum stack frame for the called main.
  43. * This is needed so that main has a place to save the
  44. * link register when it calls another function.
  45. */
  46. stqd $SP, -160($SP)
  47. ai $SP, $SP, -160
  48. /* Call the program's main function. */
  49. brsl $0, main
  50. .global exit
  51. .global _exit
  52. exit:
  53. _exit:
  54. /* SPU Context Restore, Step 5: Restore the remaining 112 GPRs. */
  55. ila $3, regs_spill + 256
  56. restore_regs:
  57. lqr $4, restore_reg_insts
  58. restore_reg_loop:
  59. ai $4, $4, 4
  60. .balignl 16, 0x40200000
  61. restore_reg_insts: /* must be quad-word aligned. */
  62. lqd $16, 0($3)
  63. lqd $17, 16($3)
  64. lqd $18, 32($3)
  65. lqd $19, 48($3)
  66. andi $5, $4, 0x7F
  67. stqr $4, restore_reg_insts
  68. ai $3, $3, 64
  69. brnz $5, restore_reg_loop
  70. /* SPU Context Restore Step 17: Restore the first 16 GPRs. */
  71. lqa $0, regs_spill + 0
  72. lqa $1, regs_spill + 16
  73. lqa $2, regs_spill + 32
  74. lqa $3, regs_spill + 48
  75. lqa $4, regs_spill + 64
  76. lqa $5, regs_spill + 80
  77. lqa $6, regs_spill + 96
  78. lqa $7, regs_spill + 112
  79. lqa $8, regs_spill + 128
  80. lqa $9, regs_spill + 144
  81. lqa $10, regs_spill + 160
  82. lqa $11, regs_spill + 176
  83. lqa $12, regs_spill + 192
  84. lqa $13, regs_spill + 208
  85. lqa $14, regs_spill + 224
  86. lqa $15, regs_spill + 240
  87. /* Under normal circumstances, the 'exit' function
  88. * terminates with 'stop SPU_RESTORE_COMPLETE',
  89. * indicating that the SPU-side restore code has
  90. * completed.
  91. *
  92. * However it is possible that instructions immediately
  93. * following the 'stop 0x3ffc' have been modified at run
  94. * time so as to recreate the exact SPU_Status settings
  95. * from the application, e.g. illegal instruciton, halt,
  96. * etc.
  97. */
  98. .global exit_fini
  99. .global _exit_fini
  100. exit_fini:
  101. _exit_fini:
  102. stop SPU_RESTORE_COMPLETE
  103. stop 0
  104. stop 0
  105. stop 0
  106. /* Pad the size of this crt0.o to be multiple of 16 bytes. */
  107. .balignl 16, 0x0