ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ia64 / sn / fakeprom / runsim
1 #!/bin/sh
2
3 # Script for running PROMs and LINUX kernwls on medusa. 
4 # Type "sim -H" for instructions.
5
6 MEDUSA=${MEDUSA:-/home/rickc/official_medusa/medusa}
7
8 # ------------------ err -----------------------
9 err() {
10         echo "ERROR - $1"
11         exit 1
12 }
13
14 # ----------------  help ----------------------
15 help() {
16 cat <<END
17 Script for running a PROM or LINUX kernel under medusa.
18 This script creates a control file, creates links to the appropriate
19 linux/prom files, and/or calls medusa to make simulation runs.
20
21 Usage:  
22    Initial setup:
23         sim [-c <config_file>] <-p> | <-k>  [<work_dir>]
24                 -p      Create PROM control file & links
25                 -k      Create LINUX control file & links
26                 -c<cf>  Control file name                               [Default: cf]
27                 <work_dir> Path to directory that contains the linux or PROM files.
28                     The directory can be any of the following:
29                        (linux simulations)
30                                 worktree
31                                 worktree/linux
32                                 any directory with vmlinux, vmlinux.sym & fprom files
33                         (prom simulations)
34                                 worktree
35                                 worktree/stand/arcs/IP37prom/dev
36                                 any directory with fw.bin & fw.sim files
37
38     Simulations:
39         sim  [-X <n>] [-o <output>] [-M] [<config_file>]
40                 -c<cf>  Control file name                               [Default: cf]
41                 -M      Pipe output thru fmtmedusa
42                 -o      Output filename (copy of all commands/output)   [Default: simout]
43                 -X      Specifies number of instructions to execute     [Default: 0]
44                         (Used only in auto test mode - not described here)
45
46 Examples:
47         sim -p <promtree>       # create control file (cf) & links for prom simulations
48         sim -k <linuxtree>      # create control file (cf) & links for linux simulations
49         sim -p -c cfprom        # create a prom control file (cfprom) only. No links are made.
50
51         sim                     # run medusa using previously created links &
52                                 #   control file (cf).
53 END
54 exit 1
55 }
56
57 # ----------------------- create control file header --------------------
58 create_cf_header() {
59 cat <<END >>$CF
60 #
61 # Template for a control file for running linux kernels under medusa. 
62 # You probably want to make mods here but this is a good starting point.
63 #
64
65 # Preferences
66 setenv cpu_stepping A
67 setenv exceptionPrint off
68 setenv interrupt_messages off
69 setenv lastPCsize 100000
70 setenv low_power_mode on
71 setenv partialIntelChipSet on
72 setenv printIntelMessages off
73 setenv prom_write_action halt
74 setenv prom_write_messages on
75 setenv step_quantum 100
76 setenv swizzling on
77 setenv tsconsole on
78 setenv uart_echo on
79 symbols on
80
81 # IDE disk params
82 setenv diskCylinders 611
83 setenv bootDrive C
84 setenv diskHeads 16
85 setenv diskPath idedisk
86 setenv diskPresent 1
87 setenv diskSpt 63
88
89 # Hardware config
90 setenv coherency_type nasid
91 setenv cpu_cache_type default
92 setenv synergy_cache_type syn_cac_64m_8w
93 setenv l4_uc_snoop off
94
95 # Numalink config
96 setenv route_enable on
97 setenv network_type router              # Select [xbar|router]
98 setenv network_warning 0xff
99
100 END
101 }
102
103
104 # ------------------ create control file entries for linux simulations -------------
105 create_cf_linux() {
106 cat <<END >>$CF
107 # Kernel specific options
108 setenv calias_size 0
109 setenv mca_on_memory_failure off
110 setenv LOADPC 0x00100000                # FPROM load address/entry point (8 digits!)
111 setenv symbol_table vmlinux.sym
112 load fprom
113 load vmlinux
114
115 # Useful breakpoints to always have set. Add more if desired.
116 break 0xe000000000505e00        all     # dispatch_to_fault_handler
117 break panic                     all     # stop on panic
118 break die_if_kernel             all     # may as well stop
119
120 END
121 }
122
123 # ------------------ create control file entries for prom simulations ---------------
124 create_cf_prom() {
125         SYM2=""
126         ADDR="0x80000000ff800000"
127         [ "$EMBEDDED_LINUX" != "0" ] || SYM2="setenv symbol_table2 vmlinux.sym"
128         [ "$SIZE" = "8MB" ] || ADDR="0x80000000ffc00000"
129         cat <<END >>$CF
130 # PROM specific options
131 setenv mca_on_memory_failure on
132 setenv LOADPC 0x80000000ffffffb0
133 setenv promFile fw.bin
134 setenv promAddr $ADDR
135 setenv symbol_table fw.sym
136 $SYM2
137
138 # Useful breakpoints to always have set. Add more if desired.
139 break ivt_gexx          all
140 break ivt_brk           all
141 break PROM_Panic_Spin   all
142 break PROM_Panic        all
143 break PROM_C_Panic      all
144 break fled_die          all
145 break ResetNow          all
146 break zzzbkpt           all
147
148 END
149 }
150
151
152 # ------------------ create control file entries for memory configuration -------------
153 create_cf_memory() {
154 cat <<END >>$CF
155 # CPU/Memory map format:
156 #       setenv nodeN_memory_config 0xBSBSBSBS
157 #               B=banksize (0=unused, 1=64M, 2=128M, .., 5-1G, c=8M, d=16M, e=32M)
158 #               S=bank enable (0=both disable, 3=both enable, 2=bank1 enable, 1=bank0 enable)
159 #                 rightmost digits are for bank 0, the lowest address.
160 #       setenv nodeN_nasid <nasid>
161 #               specifies the NASID for the node. This is used ONLY if booting the kernel.
162 #               On PROM configurations, set to 0 - PROM will change it later.
163 #       setenv nodeN_cpu_config <cpu_mask>
164 #               Set bit number N to 1 to enable cpu N. Ex., a value of 5 enables cpu 0 & 2.
165 #
166 # Repeat the above 3 commands for each node.
167 #
168 # For kernel, default to 32MB. Although this is not a valid hardware configuration,
169 # it runs faster on medusa. For PROM, 64MB is smallest allowed value.
170
171 setenv node0_cpu_config         0x1     # Enable only cpu 0 on the node
172 END
173
174 if [ $LINUX -eq 1 ] ; then
175 cat <<END >>$CF
176 setenv node0_nasid              0       # cnode 0 has NASID 0
177 setenv node0_memory_config      0xe1    # 32MB
178 END
179 else
180 cat <<END >>$CF
181 setenv node0_memory_config      0x31    # 256MB
182 END
183 fi
184 }
185
186 # -------------------- set links to linux files -------------------------
187 set_linux_links() {
188         if [ -d $D/linux/arch ] ; then
189                 D=$D/linux
190         elif [ -d $D/arch -o -e vmlinux.sym -o -e $D/vmlinux ] ; then
191                 D=$D
192         else
193                 err "cant determine directory for linux binaries"
194         fi
195         rm -rf vmlinux vmlinux.sym fprom
196         ln -s $D/vmlinux vmlinux
197         if [ -f $D/vmlinux.sym ] ; then
198                 ln -s $D/vmlinux.sym vmlinux.sym
199         elif  [ -f $D/System.map ] ; then
200                 ln -s $D/System.map vmlinux.sym
201         fi
202         if [ -d $D/arch ] ; then
203                 ln -s $D/arch/ia64/sn/fprom/fprom fprom
204         else
205                 ln -s $D/fprom fprom
206         fi
207         echo "  .. Created links to linux files"        
208 }
209
210 # -------------------- set links to prom files -------------------------
211 set_prom_links() {
212         if [ -d $D/stand ] ; then
213                 D=$D/stand/arcs/IP37prom/dev
214         elif [ -d $D/sal ] ; then
215                 D=$D
216         else
217                 err "cant determine directory for PROM binaries"
218         fi
219         SETUP="/tmp/tmp.$$"
220         rm -r -f $SETUP
221         sed 's/export/setenv/' < $D/../../../../.setup | sed 's/=/ /' >$SETUP
222         egrep -q '^ *setenv *PROMSIZE *8MB|^ *export' $SETUP
223         if [ $? -eq 0 ] ; then
224                 SIZE="8MB"
225         else
226                 SIZE="4MB"
227         fi
228         grep -q '^ *setenv *LAUNCH_VMLINUX' $SETUP
229         EMBEDDED_LINUX=$?
230         PRODUCT=`grep '^ *setenv *PRODUCT' $SETUP | cut -d" " -f3`
231         rm -f fw.bin fw.map fw.sym vmlinux vmlinux.sym fprom $SETUP
232         SDIR="${PRODUCT}${SIZE}.O"
233         BIN="${PRODUCT}ip37prom${SIZE}"
234         ln -s $D/$SDIR/$BIN.bin fw.bin
235         ln -s $D/$SDIR/$BIN.map fw.map
236         ln -s $D/$SDIR/$BIN.sym fw.sym
237         echo "  .. Created links to $SIZE prom files"
238         if [ $EMBEDDED_LINUX -eq 0 ] ; then
239                 ln -s $D/linux/vmlinux vmlinux
240                 ln -s $D/linux/vmlinux.sym vmlinux.sym
241                 if [ -d linux/arch ] ; then
242                         ln -s $D/linux/arch/ia64/sn/fprom/fprom fprom
243                 else
244                         ln -s $D/linux/fprom fprom
245                 fi
246                 echo "  .. Created links to embedded linux files in prom tree"
247         fi
248 }
249
250 # --------------- start of shell script --------------------------------
251 OUT="simout"
252 FMTMED=0
253 STEPCNT=0
254 PROM=0
255 LINUX=0
256 NCF="cf"
257 while getopts "HMX:c:o:pk" c ; do
258         case ${c} in
259                 H) help;;
260                 M) FMTMED=1;;
261                 X) STEPCNT=${OPTARG};;
262                 c) NCF=${OPTARG};;
263                 k) PROM=0;LINUX=1;;
264                 p) PROM=1;LINUX=0;;
265                 o) OUT=${OPTARG};;
266                 \?) exit 1;;
267         esac
268 done
269 shift `expr ${OPTIND} - 1`
270
271 # Check if command is for creating control file and/or links to images.
272 if [ $PROM -eq 1 -o $LINUX -eq 1 ] ; then
273         CF=$NCF
274         [ ! -f $CF ] || err "wont overwrite an existing control file ($CF)"
275         if [ $# -gt 0 ] ; then
276                 D=$1
277                 [ -d $D ] || err "cannot find directory $D"
278                 [ $PROM -eq 0 ]  || set_prom_links
279                 [ $LINUX -eq 0 ] || set_linux_links
280         fi
281         create_cf_header
282         [ $PROM -eq 0 ]  || create_cf_prom
283         [ $LINUX -eq 0 ] || create_cf_linux
284         [ ! -f ../idedisk ] || ln -s ../idedisk .
285         create_cf_memory
286         echo "  .. Basic control file created (in $CF). You might want to edit"
287         echo "     this file (at least, look at it)."
288         exit 0
289 fi
290
291 # Verify that the control file exists
292 CF=${1:-$NCF}
293 [ -f $CF ] || err "No control file exists. For help, type: $0 -H"
294
295 # Build the .cf files from the user control file. The .cf file is
296 # identical except that the actual start & load addresses are inserted
297 # into the file. In addition, the FPROM commands for configuring memory
298 # and LIDs are generated. 
299
300 rm -f .cf .cf1 .cf2
301 awk '
302 function strtonum(n) {
303          if (substr(n,1,2) != "0x")
304                 return int(n)
305          n = substr(n,3)
306          r=0
307          while (length(n) > 0) {
308                 r = r*16+(index("0123456789abcdef", substr(n,1,1))-1)
309                 n = substr(n,2)
310          }
311          return r
312         }
313 /^#/    {next}
314 /^$/    {next}
315 /^setenv *LOADPC/               {loadpc = $3; next}
316 /^setenv *node.._cpu_config/    {n=int(substr($2,5,2)); cpuconf[n] = strtonum($3); print; next}
317 /^setenv *node.._memory_config/ {n=int(substr($2,5,2)); memconf[n] = strtonum($3); print; next}
318 /^setenv *node.._nasid/         {n=int(substr($2,5,2)); nasid[n] = strtonum($3); print; next}
319 /^setenv *node._cpu_config/     {n=int(substr($2,5,1)); cpuconf[n] = strtonum($3); print; next}
320 /^setenv *node._memory_config/  {n=int(substr($2,5,1)); memconf[n] = strtonum($3); print; next}
321 /^setenv *node._nasid/          {n=int(substr($2,5,1)); nasid[n] = strtonum($3); print; next}
322                 {print}
323 END     {
324          # Generate the memmap info that starts at the beginning of
325          # the node the kernel was loaded on.
326          loadnasid = nasid[0]
327          cnode = 0
328          for (i=0; i<128; i++) {
329                 if (memconf[i] != "") {
330                         printf "sm 0x%x%08x 0x%x%04x%04x\n", 
331                                 2*loadnasid, 8*cnodes+8, memconf[i], cpuconf[i], nasid[i]
332                         cnodes++
333                         cpus += substr("0112122312232334", cpuconf[i]+1,1)
334                 }
335          }
336          printf "sm 0x%x00000000 0x%x%08x\n", 2*loadnasid, cnodes, cpus
337          printf "setenv number_of_nodes %d\n", cnodes
338
339          # Now set the starting PC for each cpu.
340          cnode = 0
341          lowcpu=-1
342          for (i=0; i<128; i++) {
343                 if (memconf[i] != "") {
344                         printf "setnode %d\n", cnode
345                         conf = cpuconf[i]
346                         for (j=0; j<4; j++) {
347                                 if (conf != int(conf/2)*2) {
348                                         printf "setcpu %d\n", j
349                                         if (length(loadpc) == 18)
350                                                 printf "sr pc %s\n", loadpc
351                                         else
352                                                 printf "sr pc 0x%x%s\n", 2*loadnasid, substr(loadpc,3)
353                                         if (lowcpu == -1)
354                                                 lowcpu = j
355                                 }
356                                 conf = int(conf/2)
357                         }
358                         cnode++
359                 }
360          }
361          printf "setnode 0\n"
362          printf "setcpu %d\n", lowcpu
363         }
364 ' <$CF >.cf
365
366 # Now build the .cf1 & .cf2 control files.
367 CF2_LINES="^sm |^break |^run |^si |^quit |^symbols "
368 egrep  "$CF2_LINES" .cf >.cf2
369 egrep -v "$CF2_LINES" .cf >.cf1
370 if [ $STEPCNT -ne 0 ] ; then
371         echo "s $STEPCNT" >>.cf2
372         echo "lastpc 1000" >>.cf2
373         echo "q" >>.cf2
374 fi
375 if [ -f vmlinux.sym ] ; then
376         awk '/ _start$/ {print "sr g 9 0x" $3}' < vmlinux.sym >> .cf2
377 fi
378 echo "script-on $OUT" >>.cf2
379
380 # Now start medusa....
381 if [ $FMTMED -ne 0 ] ; then
382         $MEDUSA -system mpsn1 -c .cf1 -i .cf2 |  fmtmedusa
383 elif [ $STEPCNT -eq 0 ] ; then
384         $MEDUSA -system mpsn1 -c .cf1 -i .cf2 
385 else
386         $MEDUSA -system mpsn1 -c .cf1 -i .cf2 2>&1 
387 fi