Clean up I$ and D$ initialization a bit
[yari.git] / shared / tools / makeconfig.sh
blobf01c3f5e1e0fc0f758354c34ba5b5619b2c5cd4e
1 #!/bin/sh
3 # This is the main configuration file. It just happens to be a Bash
4 # shell script that generates the instruction tag memory
5 # initialization files as well as config.h
7 source $1
9 # Cachable range
10 CACHEABLE_BITS=32
12 printf 'I$: %3d KiB (%d word lines)\n' $((1 << ($IC_LINE_INDEX_BITS + $IC_WORD_INDEX_BITS + 4 - 10))) $((1 << $IC_WORD_INDEX_BITS))
13 printf 'D$: %3d KiB (%d word lines)\n' $((1 << ($DC_LINE_INDEX_BITS + $DC_WORD_INDEX_BITS + 4 - 10))) $((1 << $DC_WORD_INDEX_BITS))
15 # Instruction cache (4-way associtative tag-sequential 8 KiB)
16 IC_SET_INDEX_BITS=2 # Caches has four sets
17 IC_LINE_INDEX_BITS=$IC_LINE_INDEX_BITS # Each set has 128 lines
18 IC_WORD_INDEX_BITS=$IC_WORD_INDEX_BITS # Each line has 4 32-bit words (128 bits)
20 # Data cache (4-way associtative tag-sequential 16 KiB)
21 DC_SET_INDEX_BITS=2 # Caches has four sets
22 DC_LINE_INDEX_BITS=$DC_LINE_INDEX_BITS # Each set has 256 lines
23 DC_WORD_INDEX_BITS=$DC_WORD_INDEX_BITS # Each line has 4 32-bit words (128 bits)
25 cat<<EOF > config.h
26 // Don't edit this! Edit config.sh
27 // This configuration file was autogenerated by config.sh on `date`
29 // Cachable range
30 parameter CACHEABLE_BITS=$CACHEABLE_BITS;
32 // Instruction cache (4-way associtative tag-sequential 8 KiB)
33 parameter IC_SET_INDEX_BITS=$IC_SET_INDEX_BITS; // Caches has four sets
34 parameter IC_LINE_INDEX_BITS=$IC_LINE_INDEX_BITS; // Each set has 128 lines
35 parameter IC_WORD_INDEX_BITS=$IC_WORD_INDEX_BITS; // Each line has 4 32-bit words (128 bits)
37 // Data cache (4-way associtative tag-sequential 16 KiB)
38 parameter DC_SET_INDEX_BITS=$DC_SET_INDEX_BITS; // Caches has four sets
39 parameter DC_LINE_INDEX_BITS=$DC_LINE_INDEX_BITS; // Each set has 256 lines
40 parameter DC_WORD_INDEX_BITS=$DC_WORD_INDEX_BITS; // Each line has 4 32-bit words (128 bits)
41 EOF
43 gen_tag() {
44 name=$1
45 size=$2
46 val=$3
47 width=$4
48 depth=$5
50 echo gen_tag $name $size $val $width $depth
52 cat<<EOF > $name.mif
53 -- Memory Initialization File (.mif) for tag$set
56 WIDTH=$width;
57 DEPTH=$depth;
59 ADDRESS_RADIX=HEX;
60 DATA_RADIX=HEX;
62 CONTENT BEGIN
63 EOF
65 rm -f $name.data
66 csi=0
67 while [ $csi -lt $size ]; do
68 printf "\t%08x : %x;\n" $csi $val >> $name.mif
69 printf "%x\n" $val >> $name.data
70 csi=$((csi + 1))
71 done
72 echo "END;" >> $name.mif
75 IC_SET_BITS=$((IC_LINE_INDEX_BITS + IC_WORD_INDEX_BITS + 2))
76 IC_TAG_BITS=$((CACHEABLE_BITS - IC_SET_BITS))
78 # Now generate tagX.mif
79 for set in 0 1 2 3; do
80 size=$((1 << IC_LINE_INDEX_BITS))
81 name=icache_tag$set
82 val=$(((0xBFC00000 >> IC_SET_BITS) + set))
83 gen_tag $name $size $val $IC_TAG_BITS $((1 << IC_LINE_INDEX_BITS))
84 done
86 DC_SET_BITS=$((IC_LINE_INDEX_BITS + IC_WORD_INDEX_BITS + 2))
87 DC_TAG_BITS=$((CACHEABLE_BITS - DC_SET_BITS))
89 # Now generate tagX.mif
90 for set in 0 1 2 3; do
91 size=$((1 << DC_LINE_INDEX_BITS))
92 name=dcache_tag$set
93 val=$(((0xFFFFFFFF >> DC_SET_BITS) - set))
94 gen_tag $name $size $val $DC_TAG_BITS $((1 << DC_LINE_INDEX_BITS))
95 done