/* Code to provide a restart block (RPB) for the VAX.  This will try
 * to restart the gateway instead of just rebooting it.
 */

#include <types.h>

ext int _start();
ext byte cpmbx;			/* Console Program Mailbox */

ext struct _RPB {
    struct _RPB *rpb_self;
    int (*rpb_addr)();
    int rpb_cksum;
    int rpb_flags;
} RPB;

int restarts = 0;

/* Initialization sets up the Parameter Block.  The flags are not
 * cleared immediately.  A timer is set up to do this later if the
 * gateway stays up that long.  If the gateway crashes before the
 * flags are cleared, then next time the VAX will reboot instead of
 * restart.
 */
restart_init()
{
    reg int cksum;
    reg int *ptr;
    reg int i;
    int restart_clr_flgs(), restart_stat();

    RPB.rpb_self = &RPB;
    RPB.rpb_addr = (int (*)())((int)_start + 2);
    cksum = 0;
    ptr = (int *)RPB.rpb_addr;
    for (i = 31; i; i--)
      cksum += *ptr++;
    RPB.rpb_cksum = cksum;
    restarts++;
    stime(restart_clr_flgs, 0, 120, 100);
}

restart_clr_flgs()
{
    RPB.rpb_flags = 0;
    cpmbx = 0x20;
}
