head.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Copyright 2005 Oleg I. Vdovikin (oleg@cs.msu.su) */
  2. /* cache manipulation adapted from Broadcom code */
  3. /* idea taken from original bunzip2 decompressor code */
  4. /* Copyright 2004 Manuel Novoa III (mjn3@codepoet.org) */
  5. /* Licensed under the linux kernel's version of the GPL.*/
  6. #include <asm/asm.h>
  7. #include <asm/regdef.h>
  8. #define KSEG0 0x80000000
  9. #define C0_CONFIG $16
  10. #define C0_TAGLO $28
  11. #define C0_TAGHI $29
  12. #define CONF1_DA_SHIFT 7 /* D$ associativity */
  13. #define CONF1_DA_MASK 0x00000380
  14. #define CONF1_DA_BASE 1
  15. #define CONF1_DL_SHIFT 10 /* D$ line size */
  16. #define CONF1_DL_MASK 0x00001c00
  17. #define CONF1_DL_BASE 2
  18. #define CONF1_DS_SHIFT 13 /* D$ sets/way */
  19. #define CONF1_DS_MASK 0x0000e000
  20. #define CONF1_DS_BASE 64
  21. #define CONF1_IA_SHIFT 16 /* I$ associativity */
  22. #define CONF1_IA_MASK 0x00070000
  23. #define CONF1_IA_BASE 1
  24. #define CONF1_IL_SHIFT 19 /* I$ line size */
  25. #define CONF1_IL_MASK 0x00380000
  26. #define CONF1_IL_BASE 2
  27. #define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */
  28. #define CONF1_IS_MASK 0x01c00000
  29. #define CONF1_IS_BASE 64
  30. #define Index_Invalidate_I 0x00
  31. #define Index_Writeback_Inv_D 0x01
  32. .text
  33. LEAF(startup)
  34. .set noreorder
  35. addi sp, -48
  36. sw a0, 16(sp)
  37. sw a1, 20(sp)
  38. sw a2, 24(sp)
  39. sw a3, 28(sp)
  40. /* Copy decompressor code to the right place */
  41. li t2, BZ_TEXT_START
  42. add a0, t2, 0
  43. la a1, code_start
  44. la a2, code_stop
  45. $L1:
  46. lw t0, 0(a1)
  47. sw t0, 0(a0)
  48. add a1, 4
  49. add a0, 4
  50. blt a1, a2, $L1
  51. nop
  52. /* At this point we need to invalidate dcache and */
  53. /* icache before jumping to new code */
  54. 1: /* Get cache sizes */
  55. .set mips32
  56. mfc0 s0,C0_CONFIG,1
  57. .set mips0
  58. li s1,CONF1_DL_MASK
  59. and s1,s0
  60. beq s1,zero,nodc
  61. nop
  62. srl s1,CONF1_DL_SHIFT
  63. li t0,CONF1_DL_BASE
  64. sll s1,t0,s1 /* s1 has D$ cache line size */
  65. li s2,CONF1_DA_MASK
  66. and s2,s0
  67. srl s2,CONF1_DA_SHIFT
  68. addiu s2,CONF1_DA_BASE /* s2 now has D$ associativity */
  69. li t0,CONF1_DS_MASK
  70. and t0,s0
  71. srl t0,CONF1_DS_SHIFT
  72. li s3,CONF1_DS_BASE
  73. sll s3,s3,t0 /* s3 has D$ sets per way */
  74. multu s2,s3 /* sets/way * associativity */
  75. mflo t0 /* total cache lines */
  76. multu s1,t0 /* D$ linesize * lines */
  77. mflo s2 /* s2 is now D$ size in bytes */
  78. /* Initilize the D$: */
  79. mtc0 zero,C0_TAGLO
  80. mtc0 zero,C0_TAGHI
  81. li t0,KSEG0 /* Just an address for the first $ line */
  82. addu t1,t0,s2 /* + size of cache == end */
  83. .set mips3
  84. 1: cache Index_Writeback_Inv_D,0(t0)
  85. .set mips0
  86. bne t0,t1,1b
  87. addu t0,s1
  88. nodc:
  89. /* Now we get to do it all again for the I$ */
  90. move s3,zero /* just in case there is no icache */
  91. move s4,zero
  92. li t0,CONF1_IL_MASK
  93. and t0,s0
  94. beq t0,zero,noic
  95. nop
  96. srl t0,CONF1_IL_SHIFT
  97. li s3,CONF1_IL_BASE
  98. sll s3,t0 /* s3 has I$ cache line size */
  99. li t0,CONF1_IA_MASK
  100. and t0,s0
  101. srl t0,CONF1_IA_SHIFT
  102. addiu s4,t0,CONF1_IA_BASE /* s4 now has I$ associativity */
  103. li t0,CONF1_IS_MASK
  104. and t0,s0
  105. srl t0,CONF1_IS_SHIFT
  106. li s5,CONF1_IS_BASE
  107. sll s5,t0 /* s5 has I$ sets per way */
  108. multu s4,s5 /* sets/way * associativity */
  109. mflo t0 /* s4 is now total cache lines */
  110. multu s3,t0 /* I$ linesize * lines */
  111. mflo s4 /* s4 is cache size in bytes */
  112. /* Initilize the I$: */
  113. mtc0 zero,C0_TAGLO
  114. mtc0 zero,C0_TAGHI
  115. li t0,KSEG0 /* Just an address for the first $ line */
  116. addu t1,t0,s4 /* + size of cache == end */
  117. .set mips3
  118. 1: cache Index_Invalidate_I,0(t0)
  119. .set mips0
  120. bne t0,t1,1b
  121. addu t0,s3
  122. noic:
  123. move a0,s3 /* icache line size */
  124. move a1,s4 /* icache size */
  125. move a2,s1 /* dcache line size */
  126. jal t2
  127. move a3,s2 /* dcache size */
  128. .set reorder
  129. END(startup)