Reboot, and the machine device that makes it possible

Until now the only way to restart was to stop the emulator and run it
again, which meant the one thing the machine could not do was the thing
Once was written for. The loop now closes without leaving it:

  > Once /System/Boot/bare.bin
  next start: /System/Boot/bare.bin, once
  > Reboot
  starting again
  stage two
  just this once: /System/Boot/bare.bin
  bare metal: no system, just this

Writing 1 to port 0x13 asks the machine to start over. A PORT RATHER THAN A
SERVICE, because a reset has to work when the system does not: something
only askable through SWI would be unavailable in exactly the case that
wants it most, and a program that owns the whole machine has no system to
ask. It is device class 0x04, in the range kept for the machine rather than
among the peripherals, because it is not one - it is not attached to
anything and cannot be unplugged.

WHAT A RESET REPEATS IS HOW THE MACHINE STARTED. Named an image, the
emulator places it again; named none, the ROM is shadowed again and reads
the disk. Anything else would mean a reset changed what the machine IS,
which is the one thing a reset must not do. Both are tested.

Taken between instructions, because a device cannot restart the machine
from inside the instruction that asked: the CPU is part way through a step
and its state is not yet anything a reset could leave behind consistently.

The disk stays attached and keeps everything written to it - that is what
warm means. The vector table is cleared, which is the one deliberate
departure from leaving memory alone: a vector points into whatever
installed it, and after a reset that program is not running, so a handler
left behind would aim an interrupt at an address belonging to something
gone. It is the argument CosmOS already makes at exit, applied to the
machine.

Reboot is 45 bytes, most of them the word it prints.
This commit is contained in:
Anachronaut
2026-08-27 20:56:46 -04:00
parent 7b28f48f52
commit 79727044b7
13 changed files with 199 additions and 1 deletions
+6
View File
@@ -0,0 +1,6 @@
CosmOS
> starting again
CosmOS
> halted
Execution halted.
[exit 0]
+10
View File
@@ -0,0 +1,10 @@
stage two
CosmOS
> next start: /System/Boot/bare.bin, once
finished
> starting again
stage two
just this once: /System/Boot/bare.bin
bare metal: no system, just this
Execution halted.
[exit 0]
+2
View File
@@ -0,0 +1,2 @@
Once /System/Boot/bare.bin
Reboot
+2
View File
@@ -0,0 +1,2 @@
Reboot
exit
+10
View File
@@ -550,3 +550,13 @@ cp "$DISKS/onceasked.img" "$DISKS/oncedue.img"
"$TOOL" put "$DISKS/oncedue.img" "$WORK/once.cfg" /System/Boot/once.cfg >/dev/null
# And after it has been taken: the request is gone, and nothing else changed.
cp "$DISKS/onceasked.img" "$DISKS/onceafter.img"
# ---- Starting again without leaving the machine ----
#
# The whole loop in one session: ask for a one shot, restart, watch it own the machine.
# Before Reboot the only way to restart was to stop the emulator and run it again, which
# meant the one thing the machine could not do was the thing Once was written for.
"$ROOT/Assembler" -I "$ROOT/Programs/CosmOS/Source" \
"$ROOT/Programs/CosmOS/Apps/Reboot.asm" -o "$WORK/Reboot.sbx" >/dev/null
cp "$DISKS/onceasked.img" "$DISKS/reboot.img"
"$TOOL" put "$DISKS/reboot.img" "$WORK/Reboot.sbx" /Apps/Reboot.sbx >/dev/null
+15
View File
@@ -483,6 +483,21 @@ onceDue | Boot/stage1.asm | rom | -
onceAfter | Boot/stage1.asm | rom | - | 200000000 | disks/onceafter.img
onceApp | CosmOS/Apps/Once.asm | assemble | - | -
# ---- Starting again ----
#
# The loop end to end and inside one session: ask for a one shot, restart, and watch an
# image with no operating system in it take the machine. Before this the only way to
# restart was to stop the emulator, which meant the one thing the machine could not do was
# the thing Once exists for.
#
# A reset repeats HOW THIS MACHINE STARTED. Here no image is named, so the ROM is shadowed
# again and reads the disk.
rebootOnce | Boot/stage1.asm | rom | reboot.in | 300000000 | disks/reboot.img
# And here one IS named, so the reset places it again rather than reading the disk - a
# reset that changed what the machine is would be the one thing a reset must not do.
rebootDirect | CosmOS/Source/cosmos.asm | run | rebootDirect.in | 200000000 | disks/reboot.img
rebootApp | CosmOS/Apps/Reboot.asm | assemble | - | -
# A failed start with NOTHING to fall back to. The mark must not become a reason to refuse
# to start at all - a failure that was passing recovers here, and one that is not leaves
# the machine exactly where it would have been without any of this.