1 /* Copyright 2007 Gabor Juhos */
2 /* keep original values of the a0,a1,a2,a3 registers */
3 /* cache manipulation adapted from Broadcom code */
4 /* Copyright 2005 Oleg I. Vdovikin (oleg@cs.msu.su) */
5 /* cache manipulation adapted from Broadcom code */
6 /* idea taken from original bunzip2 decompressor code */
7 /* Copyright 2004 Manuel Novoa III (mjn3@codepoet.org) */
8 /* Licensed under the linux kernel's version of the GPL.*/
11 #include <asm/regdef.h>
13 #define KSEG0 0x80000000
19 #define CONF1_DA_SHIFT 7 /* D$ associativity */
20 #define CONF1_DA_MASK 0x00000380
21 #define CONF1_DA_BASE 1
22 #define CONF1_DL_SHIFT 10 /* D$ line size */
23 #define CONF1_DL_MASK 0x00001c00
24 #define CONF1_DL_BASE 2
25 #define CONF1_DS_SHIFT 13 /* D$ sets/way */
26 #define CONF1_DS_MASK 0x0000e000
27 #define CONF1_DS_BASE 64
28 #define CONF1_IA_SHIFT 16 /* I$ associativity */
29 #define CONF1_IA_MASK 0x00070000
30 #define CONF1_IA_BASE 1
31 #define CONF1_IL_SHIFT 19 /* I$ line size */
32 #define CONF1_IL_MASK 0x00380000
33 #define CONF1_IL_BASE 2
34 #define CONF1_IS_SHIFT 22 /* Instruction cache sets/way */
35 #define CONF1_IS_MASK 0x01c00000
36 #define CONF1_IS_BASE 64
38 #define Index_Invalidate_I 0x00
39 #define Index_Writeback_Inv_D 0x01
45 /* Copy decompressor code to the right place */
57 /* At this point we need to invalidate dcache and */
58 /* icache before jumping to new code */
60 1: /* Get cache sizes */
72 sll s1,t0,s1 /* s1 has D$ cache line size */
77 addiu s2,CONF1_DA_BASE /* s2 now has D$ associativity */
83 sll s3,s3,t0 /* s3 has D$ sets per way */
85 multu s2,s3 /* sets/way * associativity */
86 mflo t0 /* total cache lines */
88 multu s1,t0 /* D$ linesize * lines */
89 mflo s2 /* s2 is now D$ size in bytes */
91 /* Initilize the D$: */
95 li t0,KSEG0 /* Just an address for the first $ line */
96 addu t1,t0,s2 /* + size of cache == end */
99 1: cache Index_Writeback_Inv_D,0(t0)
105 /* Now we get to do it all again for the I$ */
107 move s3,zero /* just in case there is no icache */
115 srl t0,CONF1_IL_SHIFT
117 sll s3,t0 /* s3 has I$ cache line size */
121 srl t0,CONF1_IA_SHIFT
122 addiu s4,t0,CONF1_IA_BASE /* s4 now has I$ associativity */
126 srl t0,CONF1_IS_SHIFT
128 sll s5,t0 /* s5 has I$ sets per way */
130 multu s4,s5 /* sets/way * associativity */
131 mflo t0 /* s4 is now total cache lines */
133 multu s3,t0 /* I$ linesize * lines */
134 mflo s4 /* s4 is cache size in bytes */
136 /* Initilize the I$: */
140 li t0,KSEG0 /* Just an address for the first $ line */
141 addu t1,t0,s4 /* + size of cache == end */
144 1: cache Index_Invalidate_I,0(t0)
152 addiu sp, -32 /* reserve stack for parameters */
159 sw s3, 16(sp) /* icache line size */
160 sw s4, 20(sp) /* icache size */
161 sw s1, 24(sp) /* dcache line size */
163 sw s2, 28(sp) /* dcache size */