fix other mandelbrot variants
[mu.git] / tools / translate_minified
blob27cd5473bd9f88d9b850143ea51dca57d1ea9a21
1 #!/bin/sh
2 # Translate a Mu program to a _minified_ bootable disk image.
4 # Hacky; only intended for some stats at the moment, even though all programs
5 # I've run through it seem to continue to work. If there are no power-on unit
6 # tests, I don't trust it.
8 set -ev
10 # Map of the Mu code disk
11 export DISK=20160 # 20*16*63 512-byte sectors = almost 10MB
12 dd if=/dev/zero of=code.img count=$DISK status=none
13 # code: sectors 0-8999
14 # font: sectors 9000-10079 (1080 sectors = space enough for 16k glyphs (1080 * 512 / 34 bytes per glyph))
15 export FONT=9000 # keep this sync'd with boot.subx
16 # debug: sector 10080 onwards
17 export DEBUG=10080
19 ## Code
21 cat $* [0-9]*.mu |linux/mu > a.subx
23 cat boot.subx |grep -vh '^\s*$\|^\s*#' > a.boot.strip
24 cat tools/mu-init-minify.subx [0-9]*.subx a.subx|grep -vh '^\s*$\|^\s*#' > a.strip
26 # treeshake everything but boot.subx, which isn't quite standard SubX and
27 # doesn't get parsed correctly by treeshake for some reason.
28 cat a.strip |tools/treeshake > a.treeshake
30 cat a.boot.strip a.treeshake |linux/braces > a.braces
32 cat a.braces |linux/calls > a.calls
34 cat a.calls |linux/sigils > a.sigils
36 cat a.sigils |linux/tests > a.tests
38 # no assort since baremetal SubX doesn't have segments yet
40 cat a.tests |linux/dquotes > a.dquotes
42 cat a.dquotes |linux/pack > a.pack
44 cat a.pack |linux/survey_baremetal > labels
45 cat a.pack |linux/labels_baremetal labels > a.survey
47 cat a.survey |linux/hex > a.bin
49 dd if=a.bin of=code.img conv=notrunc status=none
51 if [ `stat --printf="%s" a.bin` -ge 492544 ] # 15 tracks * 63 sectors per track * 512 bytes per sector (keep this sync'd with boot.subx)
52 then
53 echo "a.bin won't all be loaded on boot"
54 exit 1
57 if [ `stat --printf="%s" a.bin` -ge 492544 ] # 15 tracks * 63 sectors per track * 512 bytes per sector
58 then
59 echo "a.bin will overwrite BIOS/Video memory; you'll need to adjust boot.subx to load code to some other non-contiguous area of memory"
60 exit 1
63 if [ `stat --printf="%s" a.bin` -ge $(($FONT*512)) ]
64 then
65 echo "a.bin will overwrite font in disk"
66 exit 1
69 ## Latter half of disk is for debug info
71 if [ `stat --printf="%s" labels` -ge 1048576 ] # 8 reads * 256 sectors * 512 bytes per sector
72 then
73 echo "labels won't all be loaded on abort"
74 exit 1
77 if [ `wc -l < labels` -gt 20480 ] # 0x5000 stream capacity in abort.subx
78 then
79 echo "abort will go into infinite regress"
80 exit 1
83 dd if=labels of=code.img seek=$DEBUG conv=notrunc status=none # keep this sync'd with abort.subx
85 ## Font data at another well-defined location
86 cat font.subx |sed 's,/[^ ]*,,' |linux/hex > a.font
88 if [ `stat --printf="%s" a.font` -ge 262144 ] # 0x200 sectors * 512 bytes per sector (keep this sync'd with boot.subx)
89 then
90 echo "font won't all be loaded on boot"
91 exit 1
94 if [ `stat --printf="%s" a.font` -ge 14680064 ] # 0x00e00000 = 0x00f00000 - 0x00100000
95 then
96 echo "font is so large it overlaps the ISA memory hole; see https://wiki.osdev.org/Memory_Map_(x86)"
97 exit 1
100 if [ `stat --printf="%s" a.font` -ge $(( ($DEBUG - $FONT) * 512 )) ]
101 then
102 echo "font will overwrite debug info in disk"
103 exit 1
106 dd if=a.font of=code.img seek=$FONT conv=notrunc status=none