1#!/usr/bin/env mksh
2# $MirOS: src/usr.sbin/installboot/bxinst.sparc,v 1.29 2013/09/15 11:01:30 tg Exp $
3# $miros: src/sys/arch/sparc/stand/bootxx/mkbxinst.sh,v 1.23 2010/01/16 23:25:53 tg Exp $
4#-
5# Copyright (c) 2007, 2008, 2009, 2010
6#	Thorsten Glaser <tg@mirbsd.org>
7#
8# Provided that these terms and disclaimer and all copyright notices
9# are retained or reproduced in an accompanying document, permission
10# is granted to deal in this work without restriction, including un‐
11# limited rights to use, publicly perform, distribute, sell, modify,
12# merge, give away, or sublicence.
13#
14# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
15# the utmost extent permitted by applicable law, neither express nor
16# implied; without malicious intent or gross negligence. In no event
17# may a licensor, author or contributor be held liable for indirect,
18# direct, other damage, loss, or other issues arising in any way out
19# of dealing in the work, even if advised of the possibility of such
20# damage or existence of a defect, except proven that it results out
21# of said person’s immediate fault when using the work as intended.
22#-
23# Self-installing 32-bit sun4m/sun4c boot blocks for MirOS BSD/sparc
24# Reads a list of extents (firstblock lastblock) from standard input
25# and writes bootxx to standard output, which can subsequentially be
26# stored past the SunOS disklabel directly on the disc.
27# Other mode creates ustarfs leader from self and /usr/mdec/boot.fd.
28
29# $miros: src/sys/arch/i386/stand/bootxx_ustarfs/tarcksum,v 1.2 2010/01/16 23:16:55 tg Exp $
30function tarcksum {
31	typeset buf i
32
33	buf=($(dd if="$1" count=1 2>/dev/null | hexdump -ve '1/1 "0x%02X "'))
34	buf[0x94]=0
35	buf[0x95]=0
36	buf[0x96]=0
37	buf[0x97]=0
38	buf[0x98]=0
39	buf[0x99]=0
40	buf[0x9A]=0
41	buf[0x9B]=0
42	i=0
43	typeset -Z9 -Uui8 chksum=256
44	while (( i < 512 )); do
45		(( chksum += buf[i++] ))
46	done
47	print ${chksum#8#}
48}
49
50typeset -i outsz=6500 ustar_keep=62
51
52set -A pbs_thecode 0x66 0x31 0xC0 0x66 0x50 0x66 0x9D 0x05 0xA0 0x07 0x8E 0xD0 0xBC 0xFC 0xFF 0xFB 0x50 0x68 0x24 0x00 0x8E 0xD8 0x8E 0xC0 0x31 0xFF 0xBE 0x00 0x02 0xB9 0x80 0x00 0xF3 0x66 0xA5 0xCB 0xB8 0x01 0x02 0xBB 0x00 0x02 0xB9 0x19 0x00 0xB6 0x00 0x60 0xCD 0x13 0x61 0x73 0x08 0x60 0x31 0xC0 0xCD 0x13 0x61 0xEB 0xF2 0xEA 0x00 0x7C 0x00 0x00
53typeset -Uui8 pbs_thecode
54typeset -i pbs_ofs_sector=43 pbs_curptr=66 ustarmode=0
55
56function pbs_output {
57	typeset ostr=
58	typeset -i psz cylno
59
60	# fill the block table
61	(( pbs_thecode[pbs_ofs_sector] = $1 + 1 ))
62	if (( ustarmode )); then
63		pbs_curptr=0
64		pbs_thecode[pbs_curptr++]=1#u
65		pbs_thecode[pbs_curptr++]=1#s
66		pbs_thecode[pbs_curptr++]=1#t
67		pbs_thecode[pbs_curptr++]=1#a
68		pbs_thecode[pbs_curptr++]=1#r
69		pbs_thecode[pbs_curptr++]=1#f
70		pbs_thecode[pbs_curptr++]=1#s
71		pbs_thecode[pbs_curptr++]=0
72	fi
73	while (( pbs_curptr < 126 )); do
74		(( pbs_thecode[pbs_curptr++] = RANDOM & 0xFF ))
75	done
76
77	# create the Sun disklabel
78	while (( pbs_curptr < 512 )); do
79		pbs_thecode[pbs_curptr++]=0
80	done
81
82	# rpm
83	pbs_thecode[420]=0x01
84	pbs_thecode[421]=0x2C
85	# pcyl
86	(( pbs_thecode[422] = (g_code[0] >> 8) & 0xFF ))
87	(( pbs_thecode[423] = g_code[0] & 0xFF ))
88	# interleave
89	pbs_thecode[431]=1
90	# ncyl
91	(( pbs_thecode[432] = (g_code[0] >> 8) & 0xFF ))
92	(( pbs_thecode[433] = g_code[0] & 0xFF ))
93	# ntrk
94	(( pbs_thecode[436] = (g_code[1] >> 8) & 0xFF ))
95	(( pbs_thecode[437] = g_code[1] & 0xFF ))
96	# nsec
97	(( pbs_thecode[438] = (g_code[2] >> 8) & 0xFF ))
98	(( pbs_thecode[439] = g_code[2] & 0xFF ))
99	# sectors per drive
100	(( psz = g_code[0] * g_code[1] * g_code[2] ))
101	# sparc partitions
102	print -u2 geometry is $psz sectors in ${g_code[0]} cylinders, \
103	    ${g_code[1]} heads, ${g_code[2]} sectors per track
104	(( pbs_thecode[448] = pbs_thecode[456] = pbs_thecode[464] = \
105	    pbs_thecode[472] = (psz >> 24) & 0xFF ))
106	(( pbs_thecode[449] = pbs_thecode[457] = pbs_thecode[465] = \
107	    pbs_thecode[473] = (psz >> 16) & 0xFF ))
108	(( pbs_thecode[450] = pbs_thecode[458] = pbs_thecode[466] = \
109	    pbs_thecode[474] = (psz >> 8) & 0xFF ))
110	(( pbs_thecode[451] = pbs_thecode[459] = pbs_thecode[467] = \
111	    pbs_thecode[475] = psz & 0xFF ))
112	# sparc partition h (for ustarfs)
113	let psz--
114	pbs_thecode[503]=1
115	(( pbs_thecode[504] = (psz >> 24) & 0xFF ))
116	(( pbs_thecode[505] = (psz >> 16) & 0xFF ))
117	(( pbs_thecode[506] = (psz >> 8) & 0xFF ))
118	(( pbs_thecode[507] = psz & 0xFF ))
119	let psz++
120	# i386 partition
121	pbs_thecode[478]=0x80
122	(( pbs_thecode[480] = ustarmode ? 2 : 1 ))
123	pbs_thecode[482]=0x96
124	(( pbs_thecode[483] = g_code[1] - 1 ))
125	(( cylno = g_code[0] > 1024 ? 1023 : g_code[0] - 1 ))
126	(( pbs_thecode[484] = g_code[2] | ((cylno & 0x0300) >> 2) ))
127	(( pbs_thecode[485] = cylno & 0x00FF ))
128	(( ustarmode )) && pbs_thecode[486]=1
129	(( ustarmode )) && let psz--
130	(( pbs_thecode[490] = psz & 0xFF ))
131	(( pbs_thecode[491] = (psz >> 8) & 0xFF ))
132	(( pbs_thecode[492] = (psz >> 16) & 0xFF ))
133	(( pbs_thecode[493] = (psz >> 24) & 0xFF ))
134	(( ustarmode )) && let psz++
135	# magic
136	pbs_thecode[508]=0xDA
137	pbs_thecode[509]=0xBE
138	pbs_thecode[510]=0x55
139	pbs_thecode[511]=0xAA
140
141	# fill in the hashes
142	pbs_curptr=0
143	while (( pbs_curptr < 126 )); do
144		(( pbs_thecode[126] ^= pbs_thecode[pbs_curptr++] ))
145		(( pbs_thecode[127] ^= pbs_thecode[pbs_curptr++] ))
146	done
147	pbs_curptr=128
148	while (( pbs_curptr < 512 )); do
149		(( pbs_thecode[126] ^= pbs_thecode[pbs_curptr++] ))
150		(( pbs_thecode[127] ^= pbs_thecode[pbs_curptr++] ))
151	done
152
153	# create the output string
154	pbs_curptr=0
155	while (( pbs_curptr < 512 )); do
156		ostr=$ostr\\0${pbs_thecode[pbs_curptr++]#8#}
157	done
158	print -n "$ostr"
159}
160
161function out_int32 {
162	typeset -Uui16 value=$1
163	typeset -Uui8 ba bb bc bd
164
165	(( ba = (value >> 24) & 0xFF ))
166	(( bb = (value >> 16) & 0xFF ))
167	(( bc = (value >> 8) & 0xFF ))
168	(( bd = value & 0xFF ))
169	print -n "\\0${ba#8#}\\0${bb#8#}\\0${bc#8#}\\0${bd#8#}"
170}
171
172function out_int8 {
173	typeset -Uui8 b
174
175	(( b = $1 & 0xFF ))
176	print -n "\\0${b#8#}"
177}
178
179# Output the following:
180# • 512 bytes: Sun disklabel
181# • outsz bytes: bootxx (where first 512 bytes is ustar header)
182# • pad until end of sector: random bytes
183# • variable number of bytes: second stage bootloader
184# • pad until end of sector: undefined
185# A real ustar archive containing the kernel can be appended.
186# Layout on disc (only 0‥k are written):
187# • 0: Sun disklabel
188# • 1: ustar header 1‥k
189# • 2‥i: first stage bootloader
190# • j‥k: second stage bootloader
191# • k+1: next ustar header or 1024 NUL-bytes
192# i = 1 + (outsz_padded / 512) - 1
193# j = i + 1
194# k = j + (stage2size_padded / 512) - 1
195function do_ustar {
196	typeset me=$1 mdecboot=$2
197
198	# round up to whole of 512 bytes
199	(( outsz = (outsz + 511) & ~511 ))
200
201	# we need this later
202	if ! T=$(mktemp -d /tmp/bootxx.XXXXXXXXXX); then
203		print -u2 Error: cannot create temporary directory
204		exit 1
205	fi
206	cd "$T"
207
208	# output modified Sun disklabel
209	pbs_output 0 >label
210
211	# copy over second stage bootloader
212	dd if="$mdecboot" of=stage2 2>/dev/null
213	stage2size=$(stat -f %z stage2)
214	(( stage2size = (stage2size + 511) & ~511 ))
215
216	(( i = 1 + (outsz / 512) - 1 ))
217	(( j = i + 1 ))
218	(( k = j + (stage2size / 512) - 1 ))
219
220	# create bootxx by using myself and calculated values
221	print $j $k | mksh "$me" >stage1
222
223	# copy tarball content (stage1 + stage2) together
224	dd if=stage1 of=content obs=512 conv=osync 2>/dev/null
225	if (( $(stat -f %z content) != outsz )); then
226		print -u2 Internal error
227		cd /
228		rm -rf "$T"
229		exit 255
230	fi
231	cat stage2 >>content
232
233	# split content into file (f) and ustar header (h)
234	dd if=content of=f bs=512 skip=1 2>/dev/null
235	x=0
236	while (( x++ < 100 )); do
237		out_int8 $RANDOM
238	done >h
239	dd if=content bs=$ustar_keep count=1 conv=notrunc of=h 2>/dev/null
240
241	# create an ustar archive
242	tarprog=$(whence -p mirtar || whence -p tar)
243	$tarprog -b 1 -M dist -cf a.tar f
244	tarsize=$(stat -f %z a.tar)
245	if (( tarsize != (outsz + stage2size + 1024) )); then
246		print -u2 Error: tar output size $tarsize wrong, want \
247		    $((outsz + stage2size + 1024))
248		cd /
249		rm -rf "$T"
250		exit 1
251	fi
252
253	# patch its header
254	dd if=h bs=100 count=1 conv=notrunc of=a.tar 2>/dev/null
255	print -n "$(tarcksum a.tar)\\0" | \
256	    dd of=a.tar bs=1 seek=148 conv=notrunc 2>/dev/null
257
258	# output the result
259	print -u2 created $((tarsize - 512)) bytes of ustarfs/sparc lead
260	dd if=a.tar bs=512 count=$(((tarsize - 1024)/512)) 2>/dev/null | \
261	    cat label -
262
263	# clean up
264	cd /
265	rm -rf "$T"
266}
267
268typeset -i blktblsz=256
269set -A blktblent
270typeset -i blktblent blktblnum=0 firstblock lastblock i=0 sscale=0 chainsec=-1
271set -A g_code 2048 1 640
272
273while getopts ":0:g:N:S:T:" ch; do
274	case $ch {
275	(0)	if (( (chainsec = OPTARG) < 0 || OPTARG > 62 )); then
276			print -u2 Error: invalid chain sector "'$OPTARG'"
277			exit 1
278		fi ;;
279	(g)	if [[ $OPTARG != +([0-9]):+([0-9]):+([0-9]) ]]; then
280			print -u2 Error: invalid geometry code "'$OPTARG'"
281			exit 1
282		fi
283		saveIFS=$IFS
284		IFS=:
285		set -A g_code -- $OPTARG
286		IFS=$saveIFS ;;
287	(N)	;;
288	(S)	if (( (sscale = OPTARG) < 0 || OPTARG > 24 )); then
289			print -u2 Error: invalid sector scale "'$OPTARG'"
290			exit 1
291		fi ;;
292	(T)	if [[ ! -s $OPTARG ]]; then
293			print -u2 Error: "'$OPTARG'" not found
294			exit 1
295		fi
296		ustarfile=$OPTARG
297		ustarmode=1 ;;
298	(*)	print -u2 'Syntax:
299	bxinst [-0 secno [-g C:H:S]] [-S scale] <blocklist >loader
300	(bxinst -g C:H:S -T .../boot; tar -b 1 -M dist -cf - bsd) >floppy.tar
301Default scale=0, geometry: 2048 cyls 1 head 640 secs, suggest secno=24'
302		exit 1 ;;
303	}
304done
305shift $((OPTIND - 1))
306
307if (( ustarmode )); then
308	if [[ ${g_code[*]} = "2048 1 640" ]]; then
309		print -u2 Error: Use option -g C:H:S as well
310		exit 1
311	fi
312	do_ustar "$(realpath "$0")" "$(realpath "$ustarfile")"
313	exit 0
314fi
315
316# if desired, output chain sector (MBR) including partition and Sun disklabel
317(( chainsec >= 0 )) && pbs_output $chainsec
318
319# zero-initialise the block array
320while (( i < blktblsz )); do
321	blktblent[i++]=0
322done
323
324# read in the extents
325while read firstblock lastblock junk; do
326	while (( firstblock <= lastblock )); do
327		(( blktblent[blktblnum++] = firstblock++ << sscale ))
328	done
329	if (( blktblnum > blktblsz )); then
330		print -u2 Error: too many blocks, maximum $blktblsz
331		exit 1
332	fi
333done
334
335# verbose output
336i=0
337print -nu2 "using $blktblnum blocks of size $((512 << sscale)):"
338while (( i < blktblnum )); do
339	print -nu2 " ${blktblent[i++]}"
340done
341print -u2 .
342
343# Part 1
344print -n '\01\03\01\07\060\0200\0\07\0\0\0\0\0\0\01\0234\0\0\0\0\0\070\0\0\0\0\0\0\0\0\0\0\023\0\016\0\0222\022\0140\0\0235\0342\0177\0240\0100\0\0\0165\01\0\0\0\01\0\0\0\0127\0105\0126\0202\0\0\0220\0220\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0165\0163\0164\0141\0162\0\060\060\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0220\0220\01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0336\0255\0276\0357\0\0\0312\0376\0125\0252\0240\03\0377\0364\043\0\016\0\0242\024\0140\0\021\0\016\06\0220\022\042\0340\0244\042\0\021\0320\04\0\0\0240\04\040\04\0320\044\0100\0\0244\0244\0240\04\024\0277\0377\0374\0242\04\0140\04\03\0\016\0\0202\020\0142\040\0201\0300\0100\0\01\0\0\0\021\0\016\06\0220\022\041\0104\023\0\016\06\0222\022\0142\0340\0100\0\02\0273\0222\042\0100\010\0221\0110\0\0\0220\052\057\0\0201\0212\053\0\01\0\0\0\01\0\0\0\01\0\0\0\021\0\016\05\017\0\0\020\0200\0246\0\07\02\0200\0\07\01\0\0\0\023\0\016\06\0360\042\0142\0324\0210\020\040\01\0212\020\040\014\060\0200\0\03\0210\020\040\0\0212\020\040\015\0310\042\040\0170\021\0\016\05\0312\042\040\0204\0220\020\040\01\0213\052\0\05\021\0\016\05\0312\042\040\0174\0212\041\0140\01\021\0\016\05\0312\042\040\0200\0100\0\0\0130\0220\020\0\030\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0220\051\0\016\05\0100\0\02\0146\0320\05\040\0214\0242\0222\040\0\062\0200\0\05\047\0\016\05\021\0\016\04\020\0200\0\051\0220\022\043\0\0302\04\0340\0210\0244\020\040\0\0200\0244\0200\01\026\0200\0\0105\01\0\0\0\0205\054\0240\02\011\0\016\05\0206\021\040\0220\0324\0\0300\02\0200\0242\0240\0\062\0200\0\05\0336\06\040\04\023\0\016\04\020\0200\0\032\0220\022\0143\030\0222\020\040\01\0326\05\040\0214\0230\020\0\021\0320\06\040\010\0232\07\0277\0364\0302\03\0340\04\0237\0300\0100\0\041\0\016\05\0222\020\0\021\0200\0242\040\0\02\0200\0\05\0220\020\0\031\025\0\016\04\020\0200\0\013\0220\022\0243\060\0100\0\03\0310\0324\04\040\0214\0326\04\040\0214\0324\07\0277\0364\0200\0242\0200\013\02\0200\0\07\0200\0244\0240\0\031\0\016\04\0220\023\043\0110\033\0\016\04\0100\0\02\0233\0222\023\0142\0370\022\0200\0\031\0320\04\0340\0210\0310\06\0100\0\041\077\0377\0300\0222\020\0\031\0200\0211\0\020\02\0200\0\05\0220\06\0177\0340\07\0\0\077\0204\020\0343\0377\0210\011\0\02\0230\031\041\013\0200\0240\0\014\0226\031\041\010\0236\0140\077\0377\0200\0240\0\013\0202\0140\077\0377\0200\0223\0300\01\022\0200\0\04\0200\0241\041\07\062\0200\0\05\0320\04\0340\0210\0100\0\03\0246\0262\020\0\010\0320\04\0340\0210\0244\04\0240\01\0310\07\0277\0364\0200\0244\0200\010\06\0277\0377\0277\0262\06\0100\04\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0220\0100\0\0\0163\043\0\0\020\05\0\016\06\0202\020\040\04\0240\020\0242\0170\0222\020\040\0\0220\020\0\020\0224\07\0277\0364\0100\0\01\0330\0302\040\0242\0170\0200\0242\040\0\02\0200\0\06\023\0\016\04\021\0\016\04\0220\022\043\0130\0100\0\02\0151\0222\022\0142\0370\0220\020\0\020\0177\0377\0377\0231\0222\020\0\021\0326\04\040\04\0324\02\0340\014\0237\0302\0200\0\0220\020\0\020\011\0\016\05\0306\01\040\0170\0200\0240\0340\0\02\0200\0\04\0220\020\0\021\031\0\016\06\0320\03\042\0324\0237\0304\0100\0\01\0\0\0\0100\0\01\024\01\0\0\0\01\0\0\0\0201\0303\0340\010\01\0\0\0\05\0\016\05\03\0\020\0177\0332\0\0240\0170\0230\020\0143\0377\07\077\0374\0\05\0\015\0\011\0\01\0\0200\0243\0140\01\022\0200\0\06\01\0\0\0\0302\0210\0200\0140\0302\0250\0300\0140\020\0200\0\05\0204\0\0200\04\0302\0220\0200\0140\0302\0260\0300\0140\0204\0\0200\04\0200\0240\0200\014\04\0277\0377\0365\0206\0\0300\04\0201\0303\0340\010\01\0\0\0\0235\0343\0277\0230\021\077\0363\0\011\0\03\0177\0204\06\0\010\0202\021\043\0377\0200\0240\0200\01\010\0200\0\05\0206\020\0\030\07\0\016\04\0100\0\02\063\0220\020\0343\0160\061\077\0357\0\0201\0307\0340\010\0221\0350\0300\030\0235\0343\0277\0230\021\0\04\0\011\0\03\0177\0204\06\0\010\0202\021\043\0377\0200\0240\0200\01\010\0200\0\05\0206\020\0\030\07\0\016\04\0100\0\02\045\0220\020\0343\0200\061\0\021\0\0201\0307\0340\010\0221\0350\0300\030\0235\0343\0277\0230\0220\020\0\030\0100\0\01\0271\0262\020\0\030\0200\0242\040\0\02\0200\0\04\01\0\0\0\0177\0377\0377\0335\0221\0350\0\010\0201\0307\0340\010\0221\0350\040\0\0235\0343\0277\0230\0220\020\0\030\0177\0377\0377\0345\0222\020\0\031\0200\0242\040\0\02\0200\0\04\01\0\0\0\0100\0\01\0324\0221\0350\0\010\01\0\0\0\0201\0307\0340\010\0201\0350\0\0\0201\0303\0340\010\0220\020\040\0\0201\0303\0340\010\0220\020\040\05\0235\0343\0277\0230\05\0\016\05\0302\0\0240\0170\0200\0240\0140\0\022\0200\0\046\061\0\016\06\07\0\016\06\0202\020\0341\0110\07\077\0372\04\0304\0\0340\0234\0310\0\0340\050\0360\0\0340\0140\0372\0\0340\054\0370\0\0340\030\0366\0\0340\0134\0364\0\0340\034\0362\0\0340\024\0336\0\0340\0230\0332\0\0340\0314\0330\0\0340\014\0326\0\0340\0304\0304\040\0140\0160\05\0\016\06\0302\040\0242\0324\0310\040\0140\0110\011\0\016\06\0372\040\0140\0114\0370\040\0140\0124\0366\040\0140\0140\0364\040\0140\0130\0362\040\0140\0120\0360\040\0140\0144\0336\040\0140\0154\0332\040\0141\04\0330\040\0140\0200\0326\040\0140\0164\0300\040\0140\04\0306\0\0340\044\0360\010\0300\0\0360\041\042\0140\0300\050\0300\0\061\0\016\06\0304\06\042\0324\0302\0\0240\04\0200\0240\0140\01\010\0200\0\06\07\0\016\06\0364\0\0240\0210\0362\06\0200\0\020\0200\0\026\0362\040\0342\0320\011\0\016\06\0272\021\042\0120\0372\040\0342\0320\0206\020\0\035\0370\0\0240\0200\0366\07\0\0\0304\06\0300\0\0302\0110\0200\0\0200\0240\0140\0\02\0200\0\012\0302\010\0200\0\0302\050\0300\0\0206\0\0340\01\0364\010\0200\0\0263\056\0240\030\0261\076\0140\030\0200\0246\040\051\022\0277\0377\0366\0204\0\0240\01\0300\050\0300\0\07\0\016\04\05\0\016\04\0260\020\0343\0240\0100\0\02\0274\0223\0350\0242\0370\01\0\0\0\0235\0343\0277\0230\043\0\016\06\0304\04\0142\0324\0302\0\0240\04\0224\020\0\032\0200\0240\0140\01\010\0200\0\027\0340\06\0\0\0306\06\040\010\0200\0240\0340\01\022\0200\0\010\0200\0246\0140\01\0310\0\0240\0274\0225\056\0240\011\0220\020\0\020\0237\0301\0\0\0222\020\040\0\0200\0246\0140\01\022\0200\0\04\0302\04\0142\0324\020\0200\0\03\0302\0\0140\0264\0302\0\0140\0270\0220\020\0\020\0222\020\0\034\0237\0300\0100\0\0224\020\0\033\020\0200\0\014\0320\047\0100\0\0200\0246\0140\01\062\0200\0\03\0302\0\0240\060\0302\0\0240\054\0220\020\0\020\0223\066\0340\011\0237\0300\0100\0\0226\020\0\034\0221\052\040\011\0320\047\0100\0\0201\0307\0340\010\0221\0350\040\0\0235\0343\0277\0230\0340\06\040\04\0222\020\0\033\0344\04\040\04\0177\0377\0377\0117\0220\020\0\034\0262\036\0140\01\0200\0240\0\031\0242\020\0\010\0320\044\040\044\0222\0100\040\0\0364\044\040\040\0220\020\0\020\0366\044\040\050\0222\02\0140\01\0302\04\0240\024\0237\0300\0100\0\0260\020\040\05\0222\020\0\033\0240\020\0\010\0177\0377\0377\0115\0220\020\0\021\0200\0244\040\0\02\0200\0\04\01\0\0\0\0340\047\0100\0\0260\020\040\0\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0230\011\0\016\06\0306\01\042\0324\0304\06\040\010\0302\0\0340\04\0200\0240\0140\01\010\0200\0\06\0320\0\0200\0\0322\0\0340\0260\0237\0302\0100\0\0260\020\040\0\060\0200\0\04\0324\0\0340\050\0237\0302\0200\0\0260\020\040\0\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0220\0360\057\0277\0367\07\0\016\06\0304\0\0342\0324\0220\020\0\030\0222\07\0277\0367\0302\0\0240\04\0200\0240\0140\02\010\0200\0\07\0224\020\040\01\0310\0\0240\0224\0304\0\0240\0270\0237\0300\0200\0\0320\01\0\0\060\0200\0\04\0322\0\0240\0124\0237\0302\0100\0\01\0\0\0\01\0\0\0\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0230\0200\0246\040\012\022\0200\0\04\01\0\0\0\0177\0377\0377\0347\0220\020\040\015\0177\0377\0377\0345\0201\0350\0\0\01\0\0\0\0235\0343\0277\0230\07\0\016\06\0304\0\0342\0324\0302\0\0240\0164\0237\0300\0100\0\01\0\0\0\01\0\0\0\0235\0343\0277\0230\043\0\016\06\0302\04\0142\0144\0200\0240\0140\0\02\0200\0\016\0220\020\0\030\0306\06\040\04\0304\0\0340\020\0237\0300\0200\0\0340\0\0340\034\0320\06\040\064\0200\0242\040\0\042\0200\0\06\0300\044\0142\0144\0177\0377\0377\031\0322\04\040\04\0300\046\040\064\0300\044\0142\0144\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0230\0340\06\040\010\0260\020\040\0\0177\0377\0377\0351\0320\04\040\04\011\077\0372\04\07\0\016\06\0300\044\040\04\0304\01\040\044\0302\0\0342\0140\0302\050\0200\0\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0230\051\0\016\06\0302\05\042\0144\0252\020\0\030\0200\0240\0140\0\022\0200\0\0174\0260\020\040\030\025\077\0372\04\0322\02\0240\014\0340\02\0100\0\0346\04\040\0230\0177\0377\0376\0276\0344\04\0340\034\011\0\016\06\0242\021\042\0230\0222\020\040\070\0100\0\0\0327\0220\020\0\021\0346\044\0140\04\0310\04\040\0210\0310\044\0140\014\0320\04\040\0214\0320\044\0140\020\0306\04\040\0220\0306\044\0140\024\0304\04\0240\014\0200\0241\0\02\050\0200\0\07\0322\04\0200\0\027\0\016\04\0100\0\01\0376\0220\022\0343\0270\020\0200\0\0141\0260\020\040\06\0200\0242\0140\0\042\0200\0\0100\0320\04\0240\04\021\0\016\05\0332\02\040\0174\0231\053\0140\02\0360\04\0240\020\0237\051\040\02\0200\0242\0100\014\0324\06\0\017\04\0200\0\05\0330\04\0240\024\043\0\016\04\020\0200\0\026\0220\024\0143\0330\03\0\016\06\0332\0\0141\064\0210\020\040\0\0200\0241\0\015\032\0200\0\015\05\0\016\06\0226\020\0240\0274\0204\020\040\0\0206\020\0\013\0340\0\0300\0\0200\0244\0\014\02\0200\0\013\0210\01\040\01\0204\0\0240\014\0200\0241\0\015\012\0277\0377\0372\0206\0\0340\014\045\0\016\04\0222\020\0\014\0220\024\0243\0360\0100\0\0\0326\01\0\0\0\0232\0\0200\013\027\0\016\05\0310\03\0140\010\03\074\0\0\0340\02\0340\0204\027\0\016\06\0360\03\0140\04\0210\01\0\012\0332\02\0340\0270\0207\071\0\020\0330\02\040\0174\0224\026\0\01\037\077\0376\0\0220\050\0300\017\0202\022\0200\010\0302\0243\0100\0200\0222\042\0100\014\0232\03\0100\014\0200\0242\0140\0\024\0277\0377\0374\0202\0\0140\01\0330\02\0340\0270\025\0\016\05\0320\02\0240\0200\0204\011\0\010\0222\023\0\02\0322\044\0140\060\0320\04\0240\04\0200\0242\040\0\042\0200\0\06\0320\04\0240\010\0177\0377\0376\0225\01\0\0\0\0320\044\0140\064\0320\04\0240\010\0200\0242\040\0\042\0200\0\06\0344\04\0340\014\0100\0\0\0111\01\0\0\0\0320\044\0140\010\0344\04\0340\014\0237\0304\0200\0\0220\020\0\021\0200\0242\040\0\042\0200\0\011\0342\045\0140\04\0322\04\0340\030\0224\020\0\010\047\0\016\05\0100\0\01\0243\0220\024\0340\020\020\0200\0\06\0260\020\040\06\0260\020\040\0\0342\05\042\0144\0252\04\0140\01\0352\045\042\0144\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0230\0220\020\040\024\0100\0\0\061\043\0\016\05\0302\04\0140\0170\0240\020\0\010\0200\0240\0140\0\02\0200\0\023\0244\020\0\030\07\0\016\06\0304\0\0342\0324\0310\0\0240\04\0200\0241\040\01\010\0200\0\04\07\0\016\06\020\0200\0\03\0302\0\0240\0254\0302\0\0240\044\0320\0\0342\0320\0237\0300\0100\0\0260\020\040\06\0200\0242\040\0\02\0200\0\012\05\0\016\06\020\0200\0\016\0320\044\0\0\0177\0377\0377\0143\01\0\0\0\0260\0222\040\0\02\0200\0\012\0226\020\040\01\05\0\016\06\021\0\016\05\0322\0\0242\0320\0100\0\01\0167\0220\022\040\060\020\0200\0\015\0220\020\0\030\0226\020\040\01\0326\044\040\010\025\0\016\06\0322\04\0140\0170\0200\0242\0140\0\02\0200\0\03\0204\022\0240\0220\0204\0\0240\024\0340\044\0240\010\0220\020\040\0\0304\044\0240\04\0201\0307\0340\010\0221\0350\0\010\05\0\016\06\0302\0\0241\070\0200\0240\0140\0\0206\020\0241\070\0232\020\040\0\0210\020\077\0377\02\0200\0\022\0200\0241\077\0377\0304\0\0300\0\0302\0\0200\0\0200\0240\0100\010\052\0200\0\012\0302\0\0240\04\0200\0240\0100\010\02\0200\0\030\0200\0240\0100\04\072\0200\0\05\0302\0\0240\04\0232\020\0\03\0210\020\0\01\0302\0\0240\04\0206\0\0240\04\020\0277\0377\0360\0200\0240\0140\0\022\0200\0\016\0206\020\0\015\011\0\016\06\0200\0242\040\07\030\0200\0\03\0306\01\041\074\0220\020\040\010\0204\02\040\07\0204\010\0277\0370\0232\0\0300\02\0220\03\0140\010\0320\041\041\074\020\0200\0\05\0220\0\0340\010\0310\0\0300\0\0304\01\040\04\0220\01\040\010\0201\0303\0340\010\0304\040\0300\0\0220\02\077\0370\05\0\016\06\0302\0\0241\070\0302\042\040\04\0201\0303\0340\010\0320\040\0241\070\0224\022\0\011\0200\0212\0240\07\022\0200\0\07\0202\020\0\0\0222\0242\0140\010\066\0277\0377\0377\0300\072\0\011\0201\0303\0340\010\01\0\0\0\0200\0242\0140\017\066\0200\0\07\0200\0212\040\01\0222\0242\0140\01\066\0277\0377\0377\0300\052\0\011\0201\0303\0340\010\01\0\0\0\042\0200\0\06\0200\0212\040\02\0300\052\0\0\0220\02\040\01\0222\042\0140\01\0200\0212\040\02\042\0200\0\06\0200\0212\040\04\0300\062\0\0\0220\02\040\02\0222\042\0140\02\0200\0212\040\04\02\0200\0\05\0222\042\0140\010\0300\042\0\0\0220\02\040\04\0222\042\0140\04\0300\072\0\0\0220\02\040\010\0222\0242\0140\010\066\0277\0377\0376\0300\072\0\0\0200\0212\0140\04\02\0200\0\04\0200\0212\0140\02\0300\042\0\0\0220\02\040\04\02\0200\0\04\0200\0212\0140\01\0300\062\0\0\0220\02\040\02\062\0200\0\02\0300\052\0\0\0201\0303\0340\010\01\0\0\0\0235\0343\0277\0230\05\0\016\06\0302\0\0242\0150\0362\047\0240\0110\0200\0240\0140\0\0364\047\0240\0114\0366\047\0240\0120\0370\047\0240\0124\022\0200\0\05\0372\047\0240\0130\0206\020\040\01\0177\0377\0375\0241\0306\040\0242\0150\0220\020\0\030\0100\0\0\0353\0222\07\0240\0110\021\0\016\05\0100\0\0\0360\0220\022\040\0110\0177\0377\0376\0252\01\0\0\0\01\0\0\0\0235\0343\0277\0230\021\0\016\05\0177\0377\0377\0350\0220\022\040\0120\01\0\0\0\0235\0343\0277\0210\0240\07\0277\0350\03\0\016\05\0242\020\0\020\0206\020\0140\0130\0201\0200\0\0\01\0\0\0\01\0\0\0\01\0\0\0\0210\0166\0100\032\0222\0131\0\032\0200\0241\040\0\0220\046\0100\011\0304\010\0300\010\0262\020\0\04\0304\054\0\0\022\0277\0377\0365\0240\04\040\01\0240\04\077\0377\0237\0306\0\0\0320\0114\0\0\0200\0244\0\021\030\0277\0377\0375\0240\04\077\0377\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0170\0242\020\0\032\0302\0116\0100\0\0262\06\0140\01\0200\0240\0140\045\02\0200\0\012\0220\0220\0140\0\02\0200\0\0273\01\0\0\0\0237\0306\0\0\01\0\0\0\0302\0116\0100\0\0200\0240\0140\045\020\0277\0377\0370\0262\06\0140\01\0264\020\040\0\0340\0116\0100\0\0200\0244\040\0154\02\0200\0\040\0262\06\0140\01\0200\0244\040\0154\024\0200\0\016\0200\0244\040\0163\0200\0244\040\0142\02\0200\0\034\0202\04\0140\04\064\0200\0\04\0200\0244\040\0143\020\0200\0\023\0200\0244\040\0130\02\0200\0\0106\0200\0244\040\0144\042\0200\0\0124\0364\04\0100\0\060\0200\0\0224\02\0200\0\0105\0200\0244\040\0163\024\0200\0\010\0200\0244\040\0165\0200\0244\040\0157\02\0200\0\0125\0200\0244\040\0160\02\0200\0\0137\0220\020\040\060\060\0200\0\0212\02\0200\0\0126\0200\0244\040\0170\02\0200\0\0137\0200\0246\0240\01\060\0200\0\0205\020\0277\0377\0336\0264\06\0240\01\0340\0\0100\0\0364\04\0100\0\0220\020\0\030\0324\0114\0\0\0177\0377\0377\0256\0222\020\0\032\0200\0246\0240\0\02\0277\0377\0307\0242\04\0140\010\0304\0114\040\01\0206\020\040\0\0200\0240\0240\0\02\0277\0377\0302\0240\04\040\02\0204\0\0277\0377\0220\020\040\01\0211\052\0\02\0200\0216\0200\04\042\0200\0\020\0324\0114\0\0\0200\0240\0\03\0222\0100\077\0377\0206\012\0140\020\0237\0306\0\0\0220\0\0340\054\0320\0114\0\0\0200\0242\040\040\04\0200\0\014\0206\020\040\01\0237\0306\0\0\0240\04\040\01\020\0277\0377\0373\0320\0114\0\0\0324\0114\0\0\0200\0242\0240\040\044\0200\0\05\0304\0114\0\0\020\0277\0377\0374\0240\04\040\01\0304\0114\0\0\0200\0240\0240\0\022\0277\0377\0345\0240\04\040\01\0200\0240\0340\0\022\0200\0\0136\0220\020\040\076\020\0277\0377\0241\0302\0116\0100\0\0326\04\0100\0\0242\04\0140\04\020\0200\0\0130\0220\012\0340\0177\0332\04\0100\0\0242\04\0140\04\0320\0113\0100\0\0240\03\0140\01\0200\0242\040\0\042\0277\0377\0226\0302\0116\0100\0\0237\0306\0\0\01\0\0\0\0320\0114\0\0\020\0277\0377\0372\0240\04\040\01\0240\04\0140\04\0200\0246\0240\0\026\0200\0\05\0242\020\0\020\0264\040\0\032\0237\0306\0\0\0220\020\040\055\020\0200\0\013\0222\020\0\032\0322\04\0100\0\0264\04\0140\04\0220\020\0\030\0242\020\0\032\020\0200\0\061\0224\020\040\010\0220\04\0140\04\0322\04\0100\0\0242\020\0\010\0220\020\0\030\020\0200\0\053\0224\020\040\012\0237\0306\0\0\0264\06\0240\01\0237\0306\0\0\0220\020\040\0170\0200\0246\0240\01\04\0200\0\040\0232\04\0140\04\0222\020\0\021\0220\07\0277\0330\0100\0\0\0134\0224\020\040\010\0320\032\0\0\0240\07\0277\0340\07\0\016\05\0242\04\0140\010\0232\020\0340\0130\0264\020\0\020\0202\012\0140\017\0336\013\0100\01\0227\062\0140\04\0223\062\040\04\0231\052\040\034\0220\020\0\011\0224\023\0\013\0222\020\0\012\0336\054\0\0\0200\0222\0\012\022\0277\0377\0366\0240\04\040\01\0240\04\077\0377\0237\0306\0\0\0320\0114\0\0\0200\0244\0\032\070\0277\0377\0375\0240\04\077\0377\020\0277\0377\0127\0302\0116\0100\0\0322\04\0100\0\0220\020\0\030\0242\020\0\015\0224\020\040\020\0177\0377\0377\064\01\0\0\0\020\0277\0377\0117\0302\0116\0100\0\0237\0306\0\0\0220\020\040\045\0200\0246\0240\0\02\0200\0\05\0220\020\0\020\0237\0306\0\0\0220\020\040\0154\0220\020\0\020\0237\0306\0\0\01\0\0\0\020\0277\0377\0103\0302\0116\0100\0\0201\0307\0340\010\0201\0350\0\0\0224\020\0\011\0222\020\0\010\021\0\016\02\0220\022\040\0274\0202\023\0300\0\0177\0377\0377\067\0236\020\0100\0\01\0\0\0\0235\0343\0277\0230\021\0\016\02\0362\047\0240\0110\0222\020\0\030\0364\047\0240\0114\0366\047\0240\0120\0220\022\040\0274\0370\047\0240\0124\0224\07\0240\0110\0177\0377\0377\053\0372\047\0240\0130\01\0\0\0\0201\0307\0340\010\0201\0350\0\0\0235\0343\0277\0230\05\0\016\06\0302\0\0241\0100\0200\0240\0140\0\022\0200\0\015\011\0\016\06\0322\01\042\0154\021\0\016\05\0224\012\0140\03\0226\022\040\0160\0320\0112\0300\012\0206\02\0140\01\0260\020\040\010\0177\0377\0375\0230\0306\041\042\0154\0177\0377\0375\0226\0201\0350\0\0\01\0\0\0\0201\0307\0340\010\0201\0350\0\0\0200\0242\0240\0\02\0200\0\034\0206\020\0\010\0200\0242\0100\010\032\0200\0\017\0202\02\0277\0377\0222\02\0100\012\0204\020\0\01\0200\0240\0177\0377\02\0200\0\024\0224\02\0\012\0222\02\0177\0377\0302\012\0100\0\0224\02\0277\0377\0204\0\0277\0377\0200\0240\0277\0377\022\0277\0377\0373\0302\052\0200\0\060\0200\0\013\0200\0240\0177\0377\02\0200\0\011\0204\020\0\01\0310\012\0100\0\0204\0\0277\0377\0222\02\0140\01\0200\0240\0277\0377\0310\050\0300\0\022\0277\0377\0373\0206\0\0340\01\0201\0303\0340\010\01\0\0\0\0\0\0\0\0142\0157\0157\0164\0170\0170\0\0\045\0163\072\040\0141\0154\0154\0157\0143\040\0146\0141\0151\0154\0145\0144\0\0\0\0\0\0\0\0\045\0163\072\040\0142\0154\0157\0143\0153\040\0164\0141\0142\0154\0145\040\0143\0157\0162\0162\0165\0160\0164\0\045\0163\072\040\0162\0145\0141\0144\040\0146\0141\0151\0154\0165\0162\0145\0\0\0\0\0\0\0\0\045\0163\072\040\0163\0150\0157\0162\0164\040\0162\0145\0141\0144\0\0\045\0163\072\040\0143\0141\0156\047\0164\040\0157\0160\0145\0156\040\0144\0145\0166\0151\0143\0145\0\0\0\0144\0166\0155\0141\0137\0155\0141\0160\0151\0156\0\0\0\0\0\0\0144\0166\0155\0141\0137\0155\0141\0160\0157\0165\0164\0\0\0\0\0\0160\0162\0157\0155\060\0\0\0\0160\0162\0157\0155\0\0\0\0\076\076\040\0115\0151\0162\0102\0123\0104\040\045\0163\040\060\0101\0102\064\012\0\0\0\0\0\0\0111\0156\0166\0141\0154\0151\0144\040\0143\0157\0156\0164\0162\0157\0154\0154\0145\0162\040\0156\0165\0155\0142\0145\0162\012\0\0\0\0\0\0\0160\0162\0157\0155\0137\0155\0141\0160\0151\0156\072\040\0154\0145\0156\0147\0164\0150\075\045\0144\0\0\0\0160\0162\0157\0155\0137\0155\0141\0160\0151\0156\072\040\0151\0156\0166\0141\0154\0151\0144\040\0155\0141\0160\0164\0171\0160\0145\040\045\0144\0\0\0160\0162\0157\0155\0137\0151\0157\0160\0145\0156\072\040\042\045\0163\042\040\0145\0162\0162\0157\0162\075\045\0144\012\0\0\0\0\0\0\0103\0141\0156\047\0164\040\0157\0160\0145\0156\040\0144\0145\0166\0151\0143\0145\040\0140\045\0163\047\012\0\012\0\0\0\0\0\0\0\0145\0170\0151\0164\0\0\0\0\060\061\062\063\064\065\066\067\070\071\0101\0102\0103\0104\0105\0106\0\0\0\0\0\0\0\0\0174\057\055\0134\0\0\0\0\0\0\0\01\0\0\0\01\0\0\0\01\0\0\0\01'
345
346# The Block Table
347out_int32 $blktblnum
348out_int32 $((512 << sscale))
349i=0
350while (( i < blktblsz )); do
351	out_int32 ${blktblent[i++]}
352done
353
354# Part 2
355print -n '\0\070\023\0220\0\070\07\0260\0\070\05\0310\0\070\011\0114\0\070\05\0320\0\070\023\0230\0\070\07\014\0\070\05\0310\0\070\010\044\0\070\05\0320\017\0376\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01\04\0\0\0\0\0\0\0\0\0\0\02\010\0\0\0\0377\0\0\0\0\0\0\03\010\0\0\0\0377\0377\0\0\0\0\0\04\010\0\0\0\0377\0377\0\0\0\0\0\05\014\0\0\0\0377\0377\0\0\0\0\0\06\010\0\0\0\0377\0\0\0\0\0\0\07\014\0\0\0\0377\0\0\0\0\0\0\010\010\0\0\0\0\0\0\0\0\0\0\011\014\0\0\0\0\0\0\0\0\0\0\012\0\0\0\0\0\070\032\0340\0\0\0\0'
356
357# Pad with random octets until end of sector
358while (( outsz++ & 511 )); do
359	out_int8 $RANDOM
360done
361#let outsz--
362
363exit 0
364