
PROC system_deadstart_prolog, sysdp ()

  TASK ring=11

    create_variable cmv$ask_for_first_intervention k=boolean
    create_variable cmv$ask_for_second_intervention k=boolean
    create_variable cmv$choice k=string
    create_variable cmv$configuration_activated k=boolean scope=xref
    create_variable cmv$copy_status k=status
    create_variable cmv$device_file_copy_status k=status scope=xref
    create_variable cmv$include_status k=status
    create_variable cmv$installation k=(string $max_name) value='INSTALL'
    create_variable cmv$intervene k=boolean
    create_variable cmv$lcu_status k=status
    create_variable cmv$pcu_intervention_occurred k=boolean value=false
    create_variable cmv$pcu_status k=status
    create_variable cmv$prolog_installed k=status ..
          value=$status(false, 'CM', 9999, 'Prolog Found')
    create_variable cmv$prolog_path k=(string 256) ..
          value='$user.configuration_prologs' scope=job
    create_variable cmv$prompt k=(string 80) scope=xdcl
    create_variable cmv$sdp_ignore_status k=status
    create_variable cmv$status k=status
    create_variable osv$configuration_prolog_name k=(string $max_name) ..
          scope=xref
    create_variable osv$deadstart_phase k=(string $max_name) scope=xref
    create_variable osv$operator_intervention k=boolean scope=xref
    create_variable osv$reinitialize_system_device k=boolean scope=xref

    prolog_lfn = $unique

    cmf$prompt_for_answer = '$local.' // $unique

COLLECT_TEXT $fname(cmf$prompt_for_answer)
*copy raf$prompt_for_answer
**

COLLECT_TEXT $local.create_prolog_file
*copy rai$create_prolog_file
**

    WHEN any_fault interrupt DO
COLLECT_TEXT $output sm='?'

 The following error was detected in command: ?osv$command_name?
**
      display_value osv$status o=$output
      CONTINUE
    WHENEND

"
" BEGIN: System Deadstart Prolog
"

"---------------------------------------------------------------------------
"NOTE ON STYLE:

" It is not possible to have an SCL conditional statement span two SCL
"blocks."
" For example:
"    execute_task sp=lcu
"    IF TRUE THEN
"      quit
"    IFEND
"----------------------------------------------------------------------
    IF osv$deadstart_phase = cmv$installation THEN

"
"   EXECUTE INSTALLATION DEADSTART COMMANDS
"

      IF $file($local.installation_deadstart_commands, opened) THEN

        display_value ' Executing installation deadstart commands.' ..
              o=$output status=cmv$sdp_ignore_status

        include_file $local.installation_deadstart_commands ..
              status=cmv$include_status
        IF NOT cmv$include_status.normal THEN
COLLECT_TEXT $output
 The following error was detected when including the commands from
 the file: $local.installation_deadstart_commands:

**
          display_value cmv$include_status o=$output
          wait 4000 "delay so status may be read"
        IFEND
      IFEND

"
"   INSTALL CONFIGURATION PROLOG SUBCATALOG
"
      IF $file($local.prolog_file, opened) THEN

        create_catalog $fname(cmv$prolog_path) status=cmv$sdp_ignore_status

        include_file $local.prolog_file status=cmv$include_status
        IF NOT cmv$include_status.normal AND ..
              NOT ..
              (cmv$include_status.condition = cmv$prolog_installed.condition..
              ) THEN
COLLECT_TEXT $output
 The following error was detected when including the commands from
 the file: $local.prolog_file:

**
          display_value cmv$include_status o=$output
          wait 4000 "delay so status may be read"
        IFEND
      IFEND
      IF osv$configuration_prolog_name <> '' THEN
        cmv$pcu_prolog_name = cmv$prolog_path // '.' // ..
              osv$configuration_prolog_name // '.PCU_SUBCOMMANDS'
        cmv$lcu_prolog_name = cmv$prolog_path // '.' // ..
              osv$configuration_prolog_name // '.LCU_MAINFRAME_SUBCOMMANDS'
      ELSE "Use mainframe name as default prolog subcatalog"
        cmv$pcu_prolog_name = cmv$prolog_path // '.' // $mainframe(..
              identifier) // '.PCU_SUBCOMMANDS'
        cmv$lcu_prolog_name = cmv$prolog_path // '.' // $mainframe(..
              identifier) // '.LCU_MAINFRAME_SUBCOMMANDS'
      IFEND
    IFEND

"
" INSTALL and ACTIVATE the PHYSICAL CONFIGURATION."
"

"
" DETERMINE NEED FOR OPERATOR INTERVENTION
"
"     Installation Deadstart:
"        a. Unconfigured deadstart file, if desired.
"        b. Error in configuration prolog.
"     Continuation Deadstart:
"        a. The installed physical configuration
"           could not be copied from its device file.
"     Any Deadstart:
"        a. Operator intervention requested.
"
    cmv$intervene = false
    IF osv$deadstart_phase = cmv$installation THEN
      change_file_attribute $local.physical_configuration ra=(11, 11, 11) ..
            status=cmv$sdp_ignore_status
      IF $file($local.physical_configuration, opened) AND ..
            ($file($local.physical_configuration, size) = 0) THEN
        copy_file $local.cmf$default_configuration ..
              $local.physical_configuration status=cmv$sdp_ignore_status
COLLECT_TEXT $output

 This is an unconfigured, installation deadstart.
 If you answer 'NO' to the question below you will
 only have one disk and one tape storage device.

 Do you want to change the mainframe's physical configuration?
**
        cmv$prompt = ''
        include_file $fname(cmf$prompt_for_answer)
        IF cmv$intervene THEN
COLLECT_TEXT $output
 ENTERING THE PHYSICAL CONFIGURATION UTILITY ...

 The file $local.physical_configuration has been created for you.
 This file contains the DEFINE_ELEMENT subcommands for the system
 disk subsystem and the tape subsystem used for system installation.
 The element names and serial numbers of these peripherals have been
 invented by NOS/VE; please correct this information now.  The
 following commands are used to correct and install the physical
 configuration:

   EDIT_PHYSICAL_CONFIGURATION
     ADD_ELEMENT_DEFINITION    (for each new peripheral)
     CHANGE_ELEMENT_DEFINITION (to correct serial number)
     CHANGE_ELEMENT_NAME       (to correct element name)
   QUIT
   INSTALL_PHYSICAL_CONFIGURATION
   QUIT
**
        IFEND
      IFEND

      attach_file $fname(cmv$pcu_prolog_name) ..
            local_file_name=$name(prolog_lfn) status=cmv$status
      IF cmv$status.normal AND ($file($fname(prolog_lfn), size) > 0) THEN
        display_value ' Executing '//cmv$pcu_prolog_name o=$output ..
              status=cmv$sdp_ignore_status
        EXECUTE_TASK sp=physical_configuration_utility
          WHEN any_fault interrupt DO
COLLECT_TEXT $output sm='?'

 The following error was detected in command: ?osv$command_name?

**
            display_value osv$status o=$output
            CONTINUE
          WHENEND
          include_file $fname(prolog_lfn) status=cmv$include_status
        QUIT
        IF NOT cmv$include_status.normal THEN
COLLECT_TEXT $output sm='?'

 The following error was detected when executing the prolog file:

 ?cmv$pcu_prolog_name?.

**
          IF NOT cmv$intervene THEN
COLLECT_TEXT $output

 ENTERING THE PHYSICAL CONFIGURATION UTILITY ...

 Use these subcommands to correct and install the physical configuration:

   EDIT_PHYSICAL_CONFIGURATION
     CHANGE_ELEMENT_DEFINITION
   QUIT
   INSTALL_PHYSICAL_CONFIGURATION
   QUIT

 The following error was reported:

**
          IFEND
          display_value (cmv$include_status, ' ') o=$output
          cmv$intervene = true
        IFEND
      ELSE
        IF osv$configuration_prolog_name <> '' THEN
COLLECT_TEXT $output sm='?'

 Prolog file:
     ?cmv$pcu_prolog_name?
 is missing or empty.
**
        IFEND
      IFEND
      detach_file $fname(prolog_lfn) status=cmv$sdp_ignore_status
    ELSEIF (NOT cmv$device_file_copy_status.normal) THEN
      cmv$intervene = true
COLLECT_TEXT $output

 The installed physical configuration cannot be read without error from
 the system device.  You must either manually reinstall the physical
 configuration or you must redeadstart from a deadstart tape containing the
 desired physical configuration.  To do the latter you need to specify the
 following System Core command:

       USE_INSTALLED_CONFIGURATION false.

 It is assumed that you will manually reinstall the physical configuration;
 therefore, you will be entering the Physical Configuration Utility in a
 moment for this purpose.  However, if you have a deadstart tape matching the
 system you have installed, it may well be faster for you to use it as
 indicated above.
**

      wait 10000 "allow operator enough time to read the message"

COLLECT_TEXT $output

 ENTERING THE PHYSICAL CONFIGURATION UTILITY ...

**
    IFEND

    IF (NOT cmv$intervene) AND osv$operator_intervention THEN
COLLECT_TEXT $output

 Do you want to change the mainframe's physical configuration?
**
      cmv$prompt = ''
      include_file $fname(cmf$prompt_for_answer)
      IF cmv$intervene THEN
COLLECT_TEXT $output

 ENTERING THE PHYSICAL CONFIGURATION UTILITY ...

**
      IFEND
    IFEND

"
" ATTEMPT TO INSTALL THE PHYSICAL CONFIGURATION
"
    IF cmv$intervene THEN
      IF osv$deadstart_phase <> cmv$installation THEN
COLLECT_TEXT $output
 This is a continuation deadstart.
 YOU CANNOT REFERENCE PERMANENT FILES.
 YOU ARE RESTRICTED TO USING ONLY PCU SUBCOMMANDS

**
        IF cmv$device_file_copy_status.normal THEN
COLLECT_TEXT $output
 The most recently installed configuration has been copied to
 the file $local.physical_configuration for you.

**
        IFEND
      IFEND
      cmv$pcu_intervention_occurred = true
      EXECUTE_TASK sp=physical_configuration_utility
        WHEN any_fault interrupt DO
COLLECT_TEXT $output sm='?'

 The following error was detected in command: ?osv$command_name?

**
          display_value osv$status o=$output
          CONTINUE
        WHENEND

        include_file command prompt='PCU'
      "$QUIT
    IFEND
"
" ENSURE PHYSICAL CONFIGURATION IS INSTALLED
"
  pcu: ..
    WHILE NOT cmv$configuration_activated DO

      "Automatically install the physical configuration in case the operator"
      "did not ask for intervention or forgot to do it.                     "
      EXECUTE_TASK sp=physical_configuration_utility
        install_physical_configuration status=cmv$status
      QUIT
      IF NOT cmv$status.normal THEN
COLLECT_TEXT $output

 ENTERING THE PHYSICAL CONFIGURATION UTILITY ...

 Use these subcommands to correct and install the physical configuration:

   EDIT_PHYSICAL_CONFIGURATION
     CHANGE_ELEMENT_DEFINITION
   QUIT
   INSTALL_PHYSICAL_CONFIGURATION
   QUIT

 The following error was reported:

**
        display_value (cmv$status, ' ') o=$output

        EXECUTE_TASK sp=physical_configuration_utility
          WHEN any_fault interrupt DO
COLLECT_TEXT $output sm='?'

 The following error was detected in command: ?osv$command_name?

**
            display_value osv$status o=$output
            CONTINUE
          WHENEND
          cmv$pcu_intervention_occurred = true
          include_file command prompt='PCU'
        "$QUIT
      IFEND
    WHILEND pcu


"  BEGIN LCU INTERVENTION PROCESS
"
" Optional operator intervention allowed. Operator is asked if he/she desires
" intervention, if intervention is not forced and either the operator asked
" for operator pause or a PCU intervention occurred.
" IF installation deadstart THEN
"   IF recover system set in effect THEN
"       Suppress prolog execution
"       Activate all available system set members
"   ELSE
"       Execute the LCU_MAINFRAME_SUBCOMMANDS prolog file
"       Volumes are activated as each is initialized and added to a set
"       Operator intervention is forced if there is an error in the prolog
"       The LCU does not activate any volumes implicitly during this phase of
"         deadstart.
"   IFEND
" ELSE {continuation deadstart}
"   Allow first optional intervention before any volumes are activated.
"     This allows a window where existing set members may be reinitialized.
"   The QUIT from the first LCU execution during a continuation deadstart
"     will activate all available volumes in the system set.
"   If the operator requests intervention to initialize volumes, he/she will
"     be prompted again after all volumes are activated to determine whether
"     another intervention is desired.
"   Thus the operator will have zero, one, or two intervention opportunities;
"     The LCU will be executed at least once regardless of whether or not the
"     intervention is requested.
" IFEND

    cmv$intervene = false
    cmv$ask_for_first_intervention = (osv$operator_intervention OR ..
          cmv$pcu_intervention_occurred)
    cmv$ask_for_second_intervention = false

    IF osv$deadstart_phase = cmv$installation AND ..
          NOT osv$reinitialize_system_device THEN

      attach_file $fname(cmv$lcu_prolog_name) ..
            local_file_name=$name(prolog_lfn) status=cmv$status

      IF cmv$status.normal AND ($file($fname(prolog_lfn), size) > 0) THEN
        display_value ' Executing '//cmv$lcu_prolog_name o=$output ..
              status=cmv$sdp_ignore_status
        EXECUTE_TASK sp=logical_configuration_utility status=cmv$lcu_status
          include_line prolog_lfn//' status=cmv$include_status'
        QUIT
        IF NOT cmv$include_status.normal THEN
COLLECT_TEXT $output sm='?'

 The following error was detected when executing the prolog file:

 ?cmv$lcu_prolog_name?.

**
          display_value cmv$include_status o=$output
COLLECT_TEXT $output sm='?'

 You may now correct the problem(s) in the logical configuration
 OR enter QUIT.
**
          cmv$ask_for_first_intervention = false
          cmv$intervene = true
        IFEND "end of prolog execution"
      ELSEIF osv$configuration_prolog_name <> '' THEN
COLLECT_TEXT $output sm='?'

 Prolog file:
     ?cmv$lcu_prolog_name?
 is missing or empty.
**
      IFEND
      detach_file $fname(prolog_lfn) status=cmv$sdp_ignore_status

      IF cmv$ask_for_first_intervention THEN
COLLECT_TEXT $output

 Do you want to change the mainframe's logical configuration?
**
        cmv$prompt = ''
        include_file $fname(cmf$prompt_for_answer)
      IFEND

      IF cmv$intervene THEN
COLLECT_TEXT $output

 ENTERING THE LOGICAL CONFIGURATION UTILITY ...

**
        EXECUTE_TASK sp=logical_configuration_utility status=cmv$lcu_status
          WHEN any_fault interrupt DO
COLLECT_TEXT $output sm='?'

 The following error was detected in command: ?osv$command_name?

**
            display_value osv$status o=$output
            CONTINUE
          WHENEND
          include_file command prompt='LCU'
        "$quit
      IFEND
      WHILE NOT cmv$lcu_status.normal DO
COLLECT_TEXT $output

 ENTERING THE LOGICAL CONFIGURATION UTILITY ...

 The following error was reported by the Logical Configuration Utility;
 you must correct this problem now:

**
        display_value (cmv$lcu_status, ' ') o=$output

        EXECUTE_TASK sp=logical_configuration_utility status=cmv$lcu_status
          WHEN any_fault interrupt DO
COLLECT_TEXT $output sm='?'

 The following error was detected in command: ?osv$command_name?

**
            display_value osv$status o=$output
            CONTINUE
          WHENEND
          include_file command prompt='LCU'
        "$quit

      WHILEND

    ELSE "Continuation Deadstart or Reinitialization of the System Device"
      IF osv$reinitialize_system_device THEN
COLLECT_TEXT $output sm='?'

 Execution of the prolog:
     ?cmv$lcu_prolog_name?
 is suppressed because a system set recovery is in progress.

**
      IFEND

      IF cmv$ask_for_first_intervention THEN

COLLECT_TEXT $output

 Do you want to make any of the following kinds of changes to the
 mainframe's logical configuration?

   - Change the state of an element (CHANGE_ELEMENT_STATE)
   - Initialize a volume            (INITIALIZE_MS_VOLUME)
   - Add a volume to a set          (ADD_VOLUME_TO_SET)
   - Define a mass storage flaw     (DEFINE_MS_FLAW)

**
        cmv$prompt = ''
        include_file $fname(cmf$prompt_for_answer)

        cmv$ask_for_second_intervention = true

        IF cmv$intervene THEN
COLLECT_TEXT $output

 ENTERING THE LOGICAL CONFIGURATION UTILITY ...

 This is a continuation deadstart.
 YOU CANNOT REFERENCE PERMANENT FILES.
 YOU ARE RESTRICTED TO USING ONLY LCU SUBCOMMANDS.

 Only the mass storage classes of the System Device and any volume that
 you initialize or add to a set can be changed or displayed at this time.

**
          EXECUTE_TASK sp=logical_configuration_utility status=cmv$lcu_status
            WHEN any_fault interrupt DO
COLLECT_TEXT $output sm='?'

 The following error was detected in command: ?osv$command_name?

**
              display_value osv$status o=$output
              CONTINUE
            WHENEND
            include_file command prompt='LCU'
          "$quit
        IFEND "end of requested intervention"
      IFEND "end of first opportunity for manual intervention"

      IF NOT cmv$intervene OR NOT cmv$ask_for_first_intervention THEN
        " Ensure all available volumes are activated."
        EXECUTE_TASK sp=logical_configuration_utility status=cmv$lcu_status
        QUIT
      IFEND
      IF cmv$ask_for_second_intervention THEN
COLLECT_TEXT $output

 Do you want to make other changes to the mainframe's logical configuration?
**
        cmv$prompt = ''
        include_file $fname(cmf$prompt_for_answer)
        IF cmv$intervene THEN
COLLECT_TEXT $output

 ENTERING THE LOGICAL CONFIGURATION UTILITY ...

 This is a continuation deadstart.
 YOU CANNOT REFERENCE PERMANENT FILES.
 YOU ARE RESTRICTED TO USING ONLY LCU SUBCOMMANDS.

**
          EXECUTE_TASK sp=logical_configuration_utility status=cmv$lcu_status
            WHEN any_fault interrupt DO
COLLECT_TEXT $output sm='?'

 The following error was detected in command: ?osv$command_name?

**
              display_value osv$status o=$output
              CONTINUE
            WHENEND
            include_file command prompt='LCU'
          "$quit
        IFEND "end of second requested intervention"
      IFEND "end of second opportunity for LCU intervention"

    lcu: ..
      WHILE NOT cmv$lcu_status.normal DO
COLLECT_TEXT $output

 ENTERING THE LOGICAL CONFIGURATION UTILITY ...

 This is a continuation deadstart.
 YOU CANNOT REFERENCE PERMANENT FILES.
 YOU ARE RESTRICTED TO USING ONLY LCU SUBCOMMANDS.

 The following error was reported by the Logical Configuration Utility;
 you must correct this problem now:

**
        display_value (cmv$lcu_status, ' ') o=$output

        EXECUTE_TASK sp=logical_configuration_utility status=cmv$lcu_status
          WHEN any_fault interrupt DO
COLLECT_TEXT $output sm='?'

 The following error was detected in command: ?osv$command_name?

**
            display_value osv$status o=$output
            CONTINUE
          WHENEND
          include_file command prompt='LCU'
        "$quit

      WHILEND lcu
    IFEND "end of all operator intervention opportunities"


    IF osv$configuration_prolog_name = '' THEN
      osv$configuration_prolog_name = $mainframe(identifier)
    IFEND

    delete_file $fname(cmf$prompt_for_answer) status=cmv$sdp_ignore_status
    delete_file $local.cmf$default_configuration status=cmv$sdp_ignore_status
    delete_file $local.create_prolog_file status=cmv$sdp_ignore_status
    delete_file $local.installation_deadstart_commands ..
          status=cmv$sdp_ignore_status
    delete_file $local.physical_configuration status=cmv$sdp_ignore_status
    delete_file $local.prolog_file status=cmv$sdp_ignore_status
  TASKEND

PROCEND system_deadstart_prolog
