> load Asm.sbx
> run cosmos.asm
wrote cosmos.bin: program 7036, data 2448, labels 475
> run Asm.asm
wrote Asm.sbx: program 7533, data 4099, labels 555
Both byte for byte identical to what the host assembler builds from the
same source. The machine now builds the operating system it is running on,
and builds the thing that built it.
THE CHECK THAT MATTERS MOST IS THE THIRD ONE. A binary that matches could
still have come from an assembler wrong in some way this particular source
happens not to exercise. So Tests/native.sh boots the CosmOS that CosmOS
built and has THAT assemble CosmOS again - and the second generation is
identical to the first, down to the cycle count. It is a fixed point: the
machinery has been through itself. After this the host is a convenience
rather than a necessity.
WHAT STOOD IN THE WAY was not the assembler. It loaded, faulted at 7,780
cycles, and the fault was in CosmOS: a loaded program is staged at 0x8000
before being blitted into place, so the whole FILE has to fit in the 32,768
bytes above it. The assembler's file was 33,983, and 22K of that was
zeroed scratch buffers - because #Reserve emits what it reserves.
None of that is initialised data. It is scratch, wanted only while the
assembler runs, and while it runs everything above its own data is free.
So the buffers are a MAP now rather than declarations - Assembler/scratch.asm
writes down six addresses and the file carries none of it. 33,983 bytes
became 11,648, and the assembler could load itself.
The map has a file of its own because the reader and the label table both
need addresses out of it while neither includes the other.
The sizes are cut to the largest thing it is asked to build, and that turns
out not to be the operating system: the assembler is 555 labels and 11,648
bytes of output against CosmOS's 475 and 9,564. The hardest thing this
assembles is itself.
Also: sizing it for CosmOS meant raising the label table, and raising the
label table is what pushed the file over the staging limit. The two facts
only met because the first one was tried.
Speed, measured rather than guessed: CosmOS takes 80,168,646 cycles, which
is eighty seconds of emulated time and under a second under --fast. Most of
it is a straight walk of 475 label names, several thousand times. Sorting
or bucketing that is easy and was deliberately not written before there was
something to measure.
make run-cosmos now puts every source file on the disk, so the whole thing
can be done rather than read about.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
143 lines
5.5 KiB
Makefile
143 lines
5.5 KiB
Makefile
# SplitBit Programs Makefile
|
|
# Anachronaut
|
|
#
|
|
# Builds every SplitBit program into build/, and keeps track of which libraries
|
|
# each one includes so that editing a library reassembles whatever depends on it.
|
|
#
|
|
# make Assemble everything.
|
|
# make clean Throw away build/.
|
|
# make run-hello Assemble and run one program.
|
|
|
|
ASM ?= ../Assembler
|
|
EMU ?= ../SplitBit
|
|
BUILD ?= build
|
|
|
|
# Libraries are included by bare name, so the assembler is told where to find them.
|
|
# CosmOS owns the filesystem library and the service names, so it is a place to look too.
|
|
INCLUDES = -I Libraries -I CosmOS/Source
|
|
|
|
# The programs worth building. Files in Libraries/ are left out because they have no
|
|
# entry point of their own, and the ones in testPrograms/ are covered by 'make test'
|
|
# in the parent directory.
|
|
PROGRAMS = \
|
|
CosmOS/Source/cosmos.asm \
|
|
hello.asm \
|
|
printHello.asm \
|
|
inputTest.asm \
|
|
replCalculator.asm \
|
|
Fibonacci/8bitFibonacci.asm \
|
|
Fibonacci/16bitFibonacci.asm \
|
|
Fibonacci/32bitFibonacci.asm \
|
|
primeSieve/8bitSieve.asm \
|
|
primeSieve/16bitSegmentedSieve.asm \
|
|
primeSieve/16bitSegmentedSieveModern.asm \
|
|
gameOfLife/16x16Life.asm \
|
|
gameOfLife/16x16LifeModern.asm
|
|
|
|
BINARIES = $(PROGRAMS:%.asm=$(BUILD)/%.bin)
|
|
DEPENDENCIES = $(BINARIES:.bin=.d)
|
|
|
|
all: $(BINARIES)
|
|
|
|
# -M writes out which source files went into the binary, in the form of a make rule.
|
|
$(BUILD)/%.bin: %.asm
|
|
@mkdir -p $(@D)
|
|
$(ASM) $(INCLUDES) -M $(@:.bin=.d) -o $@ $<
|
|
|
|
# Assemble and run a single program, as in 'make run-hello'.
|
|
run-%: $(BUILD)/%.bin
|
|
$(EMU) $<
|
|
|
|
# ---- CosmOS ----
|
|
#
|
|
# make cosmos Assemble the system and everything it can load.
|
|
# make cosmos-disk ... and put the loadable programs on a disk image.
|
|
# make run-cosmos ... and boot the machine with that disk in the drive.
|
|
#
|
|
# Programs in Apps/ say where they live with #Base, so the assembler writes them out as
|
|
# loadable programs rather than as boot images. They are named .sbx to keep that
|
|
# difference visible: a .bin is something the machine boots, a .sbx is something a
|
|
# running system loads.
|
|
|
|
DISKTOOL ?= ../SplitDisk
|
|
COSMOS = $(BUILD)/CosmOS/Source/cosmos.bin
|
|
APPS = $(patsubst CosmOS/Apps/%.asm,$(BUILD)/CosmOS/Apps/%.sbx,$(wildcard CosmOS/Apps/*.asm))
|
|
COSMOS_DISK = $(BUILD)/cosmos.img
|
|
DEPENDENCIES += $(APPS:.sbx=.d)
|
|
|
|
$(BUILD)/CosmOS/Apps/%.sbx: CosmOS/Apps/%.asm
|
|
@mkdir -p $(@D)
|
|
$(ASM) $(INCLUDES) -M $(@:.sbx=.d) -o $@ $<
|
|
|
|
# The assembler that runs on the machine. It is not in Apps/ because it is not one file:
|
|
# it has a directory of its own, the way the C assembler does. Its own pieces are found
|
|
# beside it without being told, since an include is looked for next to the file that asked
|
|
# for it before anywhere else; only services.asm needs the include path.
|
|
NATIVE_ASM = $(BUILD)/CosmOS/Assembler/Asm.sbx
|
|
DEPENDENCIES += $(NATIVE_ASM:.sbx=.d)
|
|
|
|
$(NATIVE_ASM): CosmOS/Assembler/Asm.asm
|
|
@mkdir -p $(@D)
|
|
$(ASM) $(INCLUDES) -M $(@:.sbx=.d) -o $@ $<
|
|
|
|
cosmos: $(COSMOS) $(APPS) $(NATIVE_ASM)
|
|
|
|
# Made from scratch every time, so that what is on it is what is in Apps/ now and not
|
|
# also whatever used to be.
|
|
$(COSMOS_DISK): $(APPS) $(NATIVE_ASM) testPrograms/stringKeyword.asm \
|
|
CosmOS/Apps/hello.asm CosmOS/Apps/Say.asm CosmOS/Apps/Keys.asm \
|
|
CosmOS/Source/services.asm CosmOS/Source/console.asm \
|
|
$(wildcard CosmOS/Source/*.asm) $(wildcard CosmOS/Assembler/*.asm)
|
|
@mkdir -p $(@D)
|
|
rm -f $@
|
|
$(DISKTOOL) format $@ 4096 8
|
|
@for app in $(APPS); do $(DISKTOOL) put $@ $$app; done
|
|
$(DISKTOOL) put $@ $(NATIVE_ASM)
|
|
@# SOURCE goes on as well, because an assembler with nothing to assemble is a
|
|
@# demonstration of nothing.
|
|
@#
|
|
@# hello.asm and Say.asm are the APPLICATION versions, so each assembles to a .sbx
|
|
@# written straight over the one the host tool put there - which means the next
|
|
@# thing loaded is a program the machine built itself, in the same breath.
|
|
@#
|
|
@# Keys.asm is the one that brings a vector of its own, so assembling it exercises the
|
|
@# version two header and the Vector Segment: the loader installs its handler, the
|
|
@# console interrupts into it, and the shell takes the vector back at exit.
|
|
@#
|
|
@# strings.asm is the odd one out on purpose: it has no #Include and no #Base, so it
|
|
@# comes out as a boot image rather than a loadable program, and the difference
|
|
@# between the two is visible on one disk.
|
|
$(DISKTOOL) put $@ CosmOS/Apps/hello.asm
|
|
$(DISKTOOL) put $@ CosmOS/Apps/Say.asm
|
|
$(DISKTOOL) put $@ CosmOS/Apps/Keys.asm
|
|
$(DISKTOOL) put $@ CosmOS/Source/services.asm
|
|
$(DISKTOOL) put $@ CosmOS/Source/console.asm
|
|
$(DISKTOOL) put $@ testPrograms/stringKeyword.asm strings.asm
|
|
@# And the whole of CosmOS, and the whole of the assembler, so that the machine can
|
|
@# build the system it is running on and then build the thing that built it:
|
|
@#
|
|
@# > load Asm.sbx
|
|
@# > run cosmos.asm
|
|
@# > run Asm.asm
|
|
@#
|
|
@# Both come out byte for byte what the host tool makes from the same source.
|
|
@for f in CosmOS/Source/*.asm CosmOS/Assembler/*.asm; do \
|
|
$(DISKTOOL) put $@ $$f >/dev/null; done
|
|
|
|
# The system as well as the disk. Building only the image leaves whatever cosmos.bin was
|
|
# there before, or none at all, and then the disk is booted with a system that does not
|
|
# match the programs on it.
|
|
cosmos-disk: $(COSMOS) $(COSMOS_DISK)
|
|
|
|
run-cosmos: $(COSMOS) $(COSMOS_DISK)
|
|
$(EMU) --disk $(COSMOS_DISK) $(COSMOS)
|
|
|
|
clean:
|
|
rm -rf $(BUILD)
|
|
|
|
# Pull in the dependency rules written by -M above, so that touching a library
|
|
# reassembles every program that includes it.
|
|
-include $(DEPENDENCIES)
|
|
|
|
.PHONY: all clean cosmos cosmos-disk run-cosmos
|