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:
@@ -324,6 +324,15 @@ static uint8_t consoleStatus(void) {
|
||||
|
||||
static uint8_t pendingInterrupts[INTERRUPT_LINE_BYTES];
|
||||
|
||||
// Whether somebody has asked the machine to start over, and taking that request away.
|
||||
static int resetWanted = 0;
|
||||
|
||||
int takeResetRequest(void) {
|
||||
int wanted = resetWanted;
|
||||
resetWanted = 0;
|
||||
return wanted;
|
||||
}
|
||||
|
||||
void raiseInterrupt(uint8_t port) {
|
||||
pendingInterrupts[port >> 3] |= (uint8_t)(1u << (port & 7));
|
||||
}
|
||||
@@ -570,6 +579,7 @@ static const DeviceRecord deviceTable[] = {
|
||||
{ PORT_CONSOLE, DEVICE_CONSOLE, 0 },
|
||||
{ PORT_TEST, DEVICE_TEST, 0 },
|
||||
{ PORT_REFUSE, DEVICE_REFUSE, 0 },
|
||||
{ PORT_MACHINE, DEVICE_MACHINE, 0 },
|
||||
{ PORT_MEMORY, DEVICE_MEMORY, DEVICE_FLAG_HAS_MEMORY },
|
||||
{ PORT_DISK, DEVICE_DISK, DEVICE_FLAG_HAS_MEMORY },
|
||||
{ PORT_REGISTRY, DEVICE_REGISTRY, 0 },
|
||||
@@ -645,6 +655,15 @@ uint8_t OutputHandler(uint8_t DataByte, uint8_t Address) {
|
||||
case DISK_BLOCK_HIGH: diskBlock = (uint16_t)(DataByte << 8) | (diskBlock & 0x00FF); break;
|
||||
case DISK_BLOCK_LOW: diskBlock = (diskBlock & 0xFF00) | DataByte; break;
|
||||
case DISK_COMMAND: diskCommand(DataByte); break;
|
||||
case PORT_MACHINE:
|
||||
// Asked for here and acted on 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
|
||||
// consistently behind.
|
||||
if (DataByte == MACHINE_RESET) {
|
||||
resetWanted = 1;
|
||||
}
|
||||
break;
|
||||
case PORT_MEMORY:
|
||||
// Fills the memory this device owns with the byte written. Nothing is
|
||||
// reachable from here: to get at it, register it as a bank and go through
|
||||
|
||||
Reference in New Issue
Block a user