From 4ac24d75f49eb168514fb13d8121b65a959d1027 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 12 Aug 2018 15:08:26 -0500 Subject: [PATCH] Keep our driver installed on switch back from P8. --- driver.c | 22 +++++++++++++++++----- netdiskinit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/driver.c b/driver.c index 8dd5186..6ee63e8 100644 --- a/driver.c +++ b/driver.c @@ -258,7 +258,9 @@ static Word DoMountURL(struct GSOSDP *dp) { err = CheckTwoImg(sess); if (err != OPERATION_SUCCESSFUL) { EndNetDiskSession(sess); - // TODO error + // TODO better error + dp->transferCount = 0; + return drvrIOError; } dp->dibPointer->extendedDIBPtr = sess; @@ -328,8 +330,18 @@ static Word DoEject(struct GSOSDP *dp) { } static Word DoShutdown(struct GSOSDP *dp) { - EndNetDiskSession(dp->dibPointer->extendedDIBPtr); - dp->dibPointer->extendedDIBPtr = NULL; - //TODO should return error unless all of our other DIBs are already shut down? - return 0; + /* + * We don't actually end the session here, because this may just be + * a switch to P8. If so, this driver won't work within P8, but if we + * leave things in place it should work again once we're back in GS/OS. + * Do end the current TCP connection, since it would probably time out. + */ + EndTCPConnection(dp->dibPointer->extendedDIBPtr); + + /* + * Return error to indicate we shouldn't be purged. + * (I don't think we would be anyhow, since this isn't an + * actual device driver file, but let's do this to be safe.) + */ + return drvrIOError; } \ No newline at end of file diff --git a/netdiskinit.c b/netdiskinit.c index 55cc78a..13d1729 100644 --- a/netdiskinit.c +++ b/netdiskinit.c @@ -5,25 +5,41 @@ #include #include #include +#include #include #include "driver.h" #include "installdriver.h" +#include "asmglue.h" #include "version.h" const char bootInfoString[] = "NetDisk " BOOT_INFO_VERSION; Word *unloadFlagPtr; +static struct NotificationProcRec { + Long reserved1; + Word reserved2; + Word Signature; + Long Event_flags; + Long Event_code; + Byte jml; + void (*proc)(void); +} notificationProcRec; + +#define NOTIFY_SHUTDOWN 0x20 +#define NOTIFY_GSOS_SWITCH 0x04 + +static void notificationProc(void); + +#define JML 0x5C + + static void setUnloadFlag(void) { if (unloadFlagPtr != NULL && *unloadFlagPtr == 0) *unloadFlagPtr = 1; } int main(void) { - for (int i = 1; i < 256; i++) { - UnloadOneTool(i); // event mgr - } - /* * Load Marinetti. * We may get an error if the TCPIP init isn't loaded yet, but we ignore it. @@ -45,6 +61,14 @@ int main(void) { /* We're not going to error out, so show boot info. */ ShowBootInfo(bootInfoString, NULL); + /* Add notification proc to be called on shutdown and switches to GS/OS */ + notificationProcRec.Signature = 0xA55A; + notificationProcRec.Event_flags = NOTIFY_SHUTDOWN | NOTIFY_GSOS_SWITCH; + notificationProcRec.jml = JML; + notificationProcRec.proc = notificationProc; + NotifyProcRecGS addNotifyProcRec = {1, (ProcPtr)¬ificationProcRec}; + AddNotifyProcGS(&addNotifyProcRec); + /* * Put Marinetti in the default TPT so its tool stub won't be unloaded, * even if UnloadOneTool is called on it. Programs may still call @@ -61,3 +85,22 @@ error: setUnloadFlag(); return; } + +/* + * Notification procedure called at shutdown time or when switching to GS/OS. + */ +#pragma databank 1 +static void notificationProc(void) { + Word stateReg = ForceRomIn(); + + if (notificationProcRec.Event_code & NOTIFY_GSOS_SWITCH) { + /* Reinstall our driver on switch back to GS/OS from P8 */ + InstallDriver(); + } else if (notificationProcRec.Event_code & NOTIFY_SHUTDOWN) { + //TODO eject disks + } + + RestoreStateReg(stateReg); +} +#pragma databank 0 +