?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Operating System : Job Template Initialization' ??
MODULE osm$job_template_initialization;


?? NEWTITLE := 'Global Declarations Referenced by this module' ??
?? PUSH (LISTEXT := ON) ??
*copyc dsc$previous_recovery_type
*copyc jmc$system_family
*copyc jmt$executing_task_entry
*copyc jmt$task_to_execute_entry
*copyc oss$job_paged_literal
*copyc oss$task_shared
*copyc ost$string
*copyc pfe$internal_error_conditions
*copyc pmt$spy_identifier
*copyc tmt$system_task_id
?? POP ??
*copyc avp$initialize
*copyc avp$validate_job
*copyc clp$create_variable
*copyc clp$log_comment
*copyc clp$operator_intervention
*copyc clp$put_job_output
*copyc clp$scan_command_line
*copyc clp$write_variable
*copyc cme$manage_interface_tables
*copyc cmp$configure_peripheral
*copyc cmp$get_mass_storage_info
*copyc cmp$initialize_dft
*copyc cmp$process_deadstart_signals
*copyc cmp$save_mf_configuration
*copyc cmp$set_post_ds_flag
*copyc dmp$build_sorted_dfl
*copyc dmp$recover_mainframe
*copyc dmp$save_recovery_info
*copyc dfp$recover_client_mainframes
*copyc dfp$recover_server_mainframes
*copyc dsp$advance_deadstart_sequence
*copyc dsp$allow_sys_msg_logging
*copyc dsp$enlarge_sys_msg_buffer
*copyc dsp$exit_deadstart
*copyc dsp$get_data_from_rdf
*copyc dsp$process_deadstart_files
*copyc dsp$recover_mf_wired
*copyc dsp$start_all_cpus
*copyc dsp$store_data_in_rdf
*copyc jmp$define_and_permit_catalogs
*copyc jmp$initialize_job_tables
*copyc jmp$initialize_scheduler_tables
*copyc jmp$initialize_ssn
*copyc jmp$recover_queues
*copyc lgp$install_global_logs
*copyc lgp$recover_global_logs
*copyc lgp$install_engineering_log
*copyc lgp$setup_recovery_logging
*copyc mlp$initialize
*copyc mmp$write_all_segments_to_disk
*copyc nlp$cl_recover_cid_seed
*copyc ocp$define_linker_debug_table
*copyc osp$enable_pico_statistics
*copyc osp$activate_system_task
*copyc osp$complete_job_recovery
*copyc osp$define_system_task
*copyc osp$generate_message
*copyc osp$recover_executing_jobs
*copyc osp$reset_ptl
*copyc osp$verify_system_privilege
*copyc pfp$overhaul_set
*copyc pfp$recreate_system_catalog
*copyc pmp$delay
*copyc pmp$execute
*copyc pmp$get_date
*copyc pmp$set_spy_identifier
*copyc pmp$zero_out_table
*copyc sfp$init_system_routing_control
*copyc stp$activate_deadstart_sets
*copyc stp$build_family_list_for_set
*copyc stp$change_access_to_set
*copyc stp$initialize_sets
*copyc syp$disable_job_recovery
*copyc syp$display_deadstart_message
*copyc syp$initialize_jt_ptr_array
*copyc syp$initialize_syscore_template
*copyc syp$process_deadstart_status
*copyc syp$recover_executing_ajl_ord
*copyc syp$save_system_constants
*copyc syp$trace_deadstart_message
*copyc tmp$save_system_task_id
?? EJECT ??
*copyc cmv$logical_unit_table
*copyc dmv$reconcile_locator
*copyc fmv$initial_pdu_pointer
*copyc lgv$global_log_ctl
*copyc lgv$local_log_ctl
*copyc osv$deadstart_phase
*copyc osv$delete_unreconciled_files
*copyc osv$emergency_intervention
*copyc osv$operator_intervention
*copyc osv$reconcile_permanent_files
*copyc osv$recover_system_set_phase
*copyc osv$reorganize_permanent_files
*copyc osv$task_private_heap
*copyc osv$validate_active_sets
*copyc osv$validate_permanent_files
*copyc osv$170_os_type
*copyc rav$deadstart_intervention
*copyc stv$system_set_name
*copyc syv$job_recovery_option
*copyc syv$job_template_name
?? TITLE := 'Global Declarations Declared by this module', EJECT ??

  TYPE
    ost$system_task_id = (job_terminator, mli_helper, zdis, job_sched, job_sched_async,
          administer_device_logs, administer_allocation_logs, volume_space_management);

  VAR
    lgv$modify_log_segments: [XREF] boolean;

  VAR
    dsv$scl_enabled: [XDCL] boolean := FALSE,
    osv$debug_table: [XDCL, #GATE] ^SEQ ( * ) := NIL,
    osv$hang_task: [XDCL, STATIC] boolean := FALSE,
    osv$system_catalog_recreated: [STATIC, oss$task_shared] boolean := FALSE,
    osv$ignore_operator: [XDCL] boolean := FALSE,

    global_statistic_log_keywords: [READ, oss$job_paged_literal] array [1 .. 3] of ost$name := ['ACCOUNT',
          'STATISTIC', 'ENGINEERING'];

?? TITLE := 'phase1_installation', EJECT ??

  PROCEDURE phase1_installation
    (VAR status: ost$status);

    VAR
      date: ost$date,
      date_entry: string (60),
      date_entry_length: integer;

    syp$trace_deadstart_message ('initialize sets');
    stp$initialize_sets (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('initialize sets', TRUE, status);
    IFEND;

    syp$trace_deadstart_message ('pf initialization');
    pfp$overhaul_set (stv$system_set_name, $pft$set_overhaul_choices [], status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('pf initialization', TRUE, status);
    IFEND;

    syp$trace_deadstart_message ('accounting / validation initialize');
    avp$initialize (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('avp initialize', TRUE, status);
    IFEND;

    syp$trace_deadstart_message ('install global logs');
    lgp$install_global_logs (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('install global logs', TRUE, status);
    IFEND;

    dmp$save_recovery_info;

    dsp$advance_deadstart_sequence (dsc$dss_ssr_committed);

    syp$trace_deadstart_message ('initialize global stats');
    sfp$init_system_routing_control (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('initialize global stats', TRUE, status);
    IFEND;

    pmp$get_date (osc$month_date, date, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('initialize global stats', TRUE, status);
    IFEND;
    STRINGREP (date_entry, date_entry_length, '**********  INSTALLATION DEADSTART ON  ', date.month);
    clp$log_comment (date_entry (1, date_entry_length), global_statistic_log_keywords, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('initialize global stats', TRUE, status);
    IFEND;

    syp$trace_deadstart_message ('define and permit catalogs');
    jmp$define_and_permit_catalogs (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('define and permit catalogs', TRUE, status);
    IFEND;

  PROCEND phase1_installation;
?? TITLE := 'phase1_normal', EJECT ??

  PROCEDURE phase1_normal
    (VAR status: ost$status);

    syp$trace_deadstart_message ('setup recovery logging');
    lgp$setup_recovery_logging (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('setup rec logging', TRUE, status);
    IFEND;


    dmp$save_recovery_info;

    dsp$advance_deadstart_sequence (dsc$dss_ssr_committed);

{ ***WARNING*** Dont even think about using perm files here.

  PROCEND phase1_normal;
?? TITLE := 'phase2_installation', EJECT ??

  PROCEDURE phase2_installation
    (VAR status: ost$status);

    VAR
      set_overhaul_choices: pft$set_overhaul_choices;

    syp$trace_deadstart_message ('start multiple processors');
    dsp$start_all_cpus;

    syp$trace_deadstart_message ('configure peripheral environment');
    dsp$advance_deadstart_sequence (dsc$dss_idle_system_core);
    cmp$configure_peripheral (status);
    IF NOT status.normal THEN
      clp$operator_intervention (status);
    IFEND;

{ At this point the number of channels on the system is known so the system message buffer
{ can be enlarged.

    dsp$enlarge_sys_msg_buffer;

    recover_mainframe ({Installation } TRUE);

    dsp$advance_deadstart_sequence (dsc$dss_system_committed);
    syp$trace_deadstart_message ('system committed (installation)');
    cmp$process_deadstart_signals;

{ ********** System committed - installation deadstart *********

{ Build the sorted dfl and activate sets so that a recover system set deadstart
{ with multiple sets present works correctly!  Assume sets require recovery.

    dmp$build_sorted_dfl (stv$system_set_name, dmv$reconcile_locator, status);

    set_overhaul_choices := $pft$set_overhaul_choices [pfc$all_catalogs, pfc$validate_files,
          pfc$reorganize_catalogs, pfc$reconcile_fmds, pfc$recover_purged_files];
    stp$activate_deadstart_sets (set_overhaul_choices, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('activate sets', TRUE, status);
    IFEND;

{ Build the KJL, KOL - minimum sizes are one entry each.  This request must take place after the
{ volume space management task is started

    syp$trace_deadstart_message ('initialize job tables');
    jmp$initialize_job_tables (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('jmp initialize job tables', TRUE, status);
    IFEND;

    syp$trace_deadstart_message ('initialize scheduler tables');
    jmp$initialize_scheduler_tables (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('jmp initialize scheduler tables', TRUE, status);
    IFEND;

  PROCEND phase2_installation;
?? TITLE := 'phase2_normal', EJECT ??

  PROCEDURE phase2_normal
    (VAR status: ost$status);

    VAR
      date: ost$date,
      local_status: ost$status,
      reconcile_permanent_files: boolean,
      recovery_type: string (8),
      recovery_type_seq_p: ^SEQ ( * ),
      set_overhaul_choices: pft$set_overhaul_choices,
      swap_file_recovery_list_p: ^jmt$swap_file_recovery_list,
      swap_file_recovery_list_count: jmt$job_count_range,
      text: string (78),
      text_length: integer,
      validate_active_sets: boolean;

    syp$trace_deadstart_message ('start multiple processors');
    dsp$start_all_cpus;

    syp$trace_deadstart_message ('configure peripheral environment');
    dsp$advance_deadstart_sequence (dsc$dss_idle_system_core);
    cmp$configure_peripheral (status);
    IF NOT status.normal THEN
      clp$operator_intervention (status);
    IFEND;

{ At this point the number of channels on the system is known so the system message buffer
{ can be enlarged.

    dsp$enlarge_sys_msg_buffer;

    syp$trace_deadstart_message ('change access to set');
    stp$change_access_to_set (stv$system_set_name, stc$allow_access, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('change access to set', TRUE, status);
    IFEND;

    recover_mainframe ({Installation } FALSE);

    IF osv$emergency_intervention THEN
      clp$put_job_output (' Emergency Intervention', status);
      clp$operator_intervention (status);
    IFEND;

{ The next NLP$ call must be made before system commit.
    nlp$cl_recover_cid_seed;

{ Go recover the ajls of job/jobs executing at time of failure.
    syp$recover_executing_ajl_ord;

    pfp$recreate_system_catalog (status);
    IF NOT status.normal THEN
      IF status.condition = pfe$system_catalog_recreated THEN
        syp$trace_deadstart_message ('$SYSTEM master catalog recreated.');
        status.normal := TRUE;
        osv$system_catalog_recreated := TRUE;
      ELSE
        syp$process_deadstart_status ('Recreate system master catalog', TRUE, status);
      IFEND;
    IFEND;

    syp$trace_deadstart_message ('build dm/pf reconciliation list');
    dmp$build_sorted_dfl (stv$system_set_name, dmv$reconcile_locator, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Build dm/pf reconciliation list.', TRUE, status);
    IFEND;

{ Build the KJL, KOL.  This request must take place after the volume space management task is started.

    syp$trace_deadstart_message ('initialize job tables');
    jmp$initialize_job_tables (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('jmp initialize job tables', TRUE, status);
    IFEND;

{ Build the scheduler tables.  This request must take place before active jobs are recovered.

    syp$trace_deadstart_message ('initialize scheduler tables');
    jmp$initialize_scheduler_tables (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('jmp initialize scheduler tables', TRUE, status);
    IFEND;

{ NOTE: This call must always be made before system commit and job sched start.

    syp$trace_deadstart_message ('reconcile active jobs');
    osp$recover_executing_jobs (swap_file_recovery_list_p, swap_file_recovery_list_count, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('WARNING -- Job recovery not possible', FALSE, status);
      syp$disable_job_recovery;
      status.normal := TRUE;
    IFEND;
    cmp$set_post_ds_flag;
    dsp$advance_deadstart_sequence (dsc$dss_system_committed);
    syp$trace_deadstart_message ('system committed (normal)');

{ ********** System committed - normal (continuation) deadstart **********

    recovery_type_seq_p := #SEQ (recovery_type);
    dsp$get_data_from_rdf (dsc$rdf_previous_recovery_type, dsc$rdf_production, recovery_type_seq_p);
    IF (recovery_type = dsc$recovery_without_image) AND NOT osv$validate_active_sets THEN
      syp$trace_deadstart_message ('pf recovery is required due to missing image');
      validate_active_sets := TRUE;
    ELSE
      validate_active_sets := osv$validate_active_sets;
    IFEND;

    reconcile_permanent_files := osv$reconcile_permanent_files OR osv$reorganize_permanent_files OR
          osv$delete_unreconciled_files;

    set_overhaul_choices := $pft$set_overhaul_choices [];
    IF osv$validate_permanent_files OR reconcile_permanent_files OR validate_active_sets THEN
      syp$trace_deadstart_message ('pf recovery');

      set_overhaul_choices := $pft$set_overhaul_choices [pfc$all_catalogs];
      IF syv$job_recovery_option = syc$jre_enabled THEN
        syp$trace_deadstart_message ('- job recovery');
        set_overhaul_choices := set_overhaul_choices + $pft$set_overhaul_choices [pfc$recover_purged_files];
      IFEND;

      IF osv$validate_permanent_files OR validate_active_sets THEN
        syp$trace_deadstart_message ('- validate_permanent_files');
        set_overhaul_choices := set_overhaul_choices + $pft$set_overhaul_choices [pfc$validate_files];
      IFEND;

      IF osv$reorganize_permanent_files OR validate_active_sets THEN
        syp$trace_deadstart_message ('- reorganize_permanent_files');
        set_overhaul_choices := set_overhaul_choices + $pft$set_overhaul_choices [pfc$reorganize_catalogs];
      IFEND;

      IF reconcile_permanent_files OR validate_active_sets THEN
        syp$trace_deadstart_message ('- reconcile_permanent_files');
        set_overhaul_choices := set_overhaul_choices + $pft$set_overhaul_choices [pfc$reconcile_fmds];
      IFEND;

      IF osv$delete_unreconciled_files THEN
        syp$trace_deadstart_message ('- delete_unreconciled_files');
        set_overhaul_choices := set_overhaul_choices + $pft$set_overhaul_choices
              [pfc$delete_unreconciled_objects];
      IFEND;

      pfp$overhaul_set (stv$system_set_name, set_overhaul_choices, status);
      IF NOT status.normal THEN
        IF status.condition = pfe$recovery_summary THEN
          status.normal := TRUE;
        ELSE
          syp$process_deadstart_status ('pf recovery', TRUE, status);
        IFEND;
      IFEND;
    IFEND;

    recovery_type := dsc$recovery_completed_normally;
    dsp$store_data_in_rdf (dsc$rdf_previous_recovery_type, dsc$rdf_production, #SEQ (recovery_type));

    stp$build_family_list_for_set (stv$system_set_name,
          {activating_during_deadstart=} TRUE, {defer_input_queue} FALSE, status);

    stp$activate_deadstart_sets (set_overhaul_choices, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('activate sets', TRUE, status);
    IFEND;

    IF osv$emergency_intervention THEN
      clp$put_job_output (' Emergency Intervention', status);
      clp$operator_intervention (status);
    IFEND;

    syp$trace_deadstart_message ('accounting / validation initialize');
    avp$initialize (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('avp initialize', TRUE, status);
    IFEND;

    syp$trace_deadstart_message ('recover global logs');
    lgp$recover_global_logs (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('rec global logs', TRUE, status);
    IFEND;
    IF lgv$modify_log_segments THEN
     syp$trace_deadstart_message ('modifying log segments');
      lgp$install_eng_log (status);
    IFEND;

    syp$trace_deadstart_message ('initialize global stats');
    sfp$init_system_routing_control (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('initialize global stats', TRUE, status);
    IFEND;
    pmp$get_date (osc$month_date, date, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('initializ global stats', TRUE, status);
    IFEND;
    STRINGREP (text, text_length, '**********  RECOVERY DEADSTART ON  ', date.month);
    clp$log_comment (text (1, text_length), global_statistic_log_keywords, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('initializ global stats', TRUE, status);
    IFEND;

{ This request verifies that the input/output/swap queues exist and have the current permits.
{ PF recovery may, potentially, delete the queues.

    jmp$define_and_permit_catalogs (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('define and permit catalogs', FALSE, status);
    IFEND;

{ Recover the input and output queues.

    syp$trace_deadstart_message ('recover queues');
    jmp$recover_queues (swap_file_recovery_list_p, swap_file_recovery_list_count, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('error in queue recovery', FALSE, status);
    IFEND;

    dfp$recover_client_mainframes (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('error in file server client recovery', FALSE, status);
      status.normal := TRUE;
    IFEND;

    cmp$process_deadstart_signals;

    osp$enable_pico_statistics;

  PROCEND phase2_normal;

?? TITLE := 'recover_mainfame', EJECT ??

  PROCEDURE recover_mainframe (installation: boolean);

    VAR
      status: ost$status;

{ All system tasks that run and terminate must be completed by now.  Re-initialize
{ the PTL and DCT free queue pointers. This is in case we need to perform job
{ recovery later.  Since there can be any number of tasks that run and terminate
{ before this point (in particular PCU/LCU) there is no way to know what taskid (PTL
{ ordinal) the following tasks will receive.  If they get different taskids then
{ what they had on the previous deadstart, it is possible that a recovering task
{ would have the same taskid as the new one assigned.

    osp$reset_ptl;

    syp$trace_deadstart_message ('start volume space management task');
    start_system_task (volume_space_management);

    dsp$recover_mf_wired;

    dsp$advance_deadstart_sequence (dsc$dss_recover_mainframe);

    dmp$recover_mainframe (status);

    IF status.normal THEN
      IF NOT installation THEN
        dfp$recover_server_mainframes (status);
        IF NOT status.normal THEN
          syp$process_deadstart_status ('error in file server server recovery', FALSE, status);
        IFEND;
      IFEND;

      dsp$advance_deadstart_sequence (dsc$dss_mainframe_recovered);
      dsp$advance_deadstart_sequence (dsc$dss_recovery_completed);
    ELSE
      syp$process_deadstart_status ('recover mainframe', TRUE, status);
    IFEND;

    syp$trace_deadstart_message ('start admin device log task');
    start_system_task (administer_device_logs);

    syp$trace_deadstart_message ('start admin allocation log task');
    start_system_task (administer_allocation_logs);

  PROCEND recover_mainframe;
?? TITLE := 'start_system_task', EJECT ??

  PROCEDURE start_system_task
    (    task: ost$system_task_id);

    VAR
      execute_status: ost$status,
      executing_task_p: ^jmt$executing_task_entry,
      ignore_status: ost$status,
      program_attributes: pmt$program_attributes,
      program_attributes_seq_p: ^SEQ ( * ),
      spy_id: [STATIC, READ, oss$job_paged_literal] array [ost$system_task_id] of pmt$spy_identifier :=
            [0, 53, 0, 54, 0, 55, 56, 57],
      task_param: SEQ (boolean),
      task_to_execute: [STATIC, READ, oss$job_paged_literal] array [ost$system_task_id] of
            jmt$task_to_execute_entry := [['JMP$JOB_TERMINATOR_ENTRY_POINT', TRUE, TRUE, FALSE],
            ['MLP$INVOKE_MLI_HELPER', TRUE, FALSE, FALSE], ['JMP$ZDIS_ENTRY_POINT', TRUE, FALSE, TRUE],
            ['JMP$JOB_SCHEDULER_ENTRY_POINT', TRUE, FALSE, FALSE],
            ['JMP$JOB_SCHED_ASYNC_ENTRY_PT', TRUE, FALSE, FALSE],
            ['DMP$ADMINISTER_DEVICE_LOG', TRUE, TRUE, TRUE], ['DMP$ADMINISTER_ALLOCATION_LOG', TRUE, TRUE,
            TRUE], ['DMP$VOLUME_SPACE_MANAGEMENT', TRUE, TRUE, TRUE]];

    ALLOCATE executing_task_p IN osv$task_private_heap^;
    pmp$zero_out_table (#LOC (executing_task_p^), #SIZE (executing_task_p^));

    executing_task_p^.task_name := task_to_execute [task].task_name;

    program_attributes.contents := $pmt$prog_description_contents
          [pmc$starting_proc_specified, pmc$load_map_options_specified, pmc$term_error_level_specified];
    program_attributes.load_map_options := $pmt$load_map_options [pmc$no_load_map];
    program_attributes.termination_error_level := pmc$warning_load_errors;
    program_attributes.starting_procedure := executing_task_p^.task_name;

    pmp$set_spy_identifier (spy_id [task], 0, ignore_status);

    program_attributes_seq_p := #SEQ (program_attributes);
    pmp$execute (program_attributes_seq_p^, task_param, osc$nowait, executing_task_p^.task_id,
          executing_task_p^.task_status, execute_status);

    IF NOT execute_status.normal THEN
      syp$process_deadstart_status ('Execute system task.', TRUE, execute_status);
    IFEND;

    pmp$set_spy_identifier (0, 0, ignore_status);

  PROCEND start_system_task;
?? TITLE := 'osp$get_job_template_name', EJECT ??

{ PURPOSE:
{   This procedure provides access to the "job template name" for the current job for code
{   running above ring 3.

  PROCEDURE [XDCL, #GATE] osp$get_job_template_name
    (VAR job_template_name: ost$name);

    job_template_name := syv$job_template_name;

  PROCEND osp$get_job_template_name;
?? TITLE := 'osp$initialize_sc_debugger', EJECT ??

{ PURPOSE:
{   The purpose of this routine is to initialize the system core debugger environment for this job.
{   It is called once for the NOS/VE job template during deadstart and once per job for other job templates.

  PROCEDURE [XDCL] osp$initialize_sc_debugger;

    VAR
      jt_debug_pointers_p: ^array [1 .. * ] of ^cell,
      local_status: ost$status;

    PUSH jt_debug_pointers_p: [1 .. 4];
    jt_debug_pointers_p^ [1] := #LOC (lgv$local_log_ctl);
    jt_debug_pointers_p^ [2] := #LOC (lgv$global_log_ctl);
    jt_debug_pointers_p^ [3] := #LOC (osv$hang_task);
    jt_debug_pointers_p^ [4] := #LOC (fmv$initial_pdu_pointer);
    syp$initialize_jt_ptr_array (jt_debug_pointers_p);
    ocp$define_linker_debug_table (osv$debug_table, local_status);

  PROCEND osp$initialize_sc_debugger;
?? TITLE := 'osp$job_template_init_ph1', EJECT ??

  PROCEDURE [XDCL, #GATE] osp$job_template_init_ph1;

    VAR
      intervention_array: array [1 .. 1] of clt$boolean,
      intervention_scope: clt$variable_scope,
      intervention_variable: clt$variable_reference,
      phase_array: array [1 .. 2 {#SIZE(ost$string_size)} + osc$max_name_size] of cell,
      phase_scope: clt$variable_scope,
      phase_string: record
        size: ost$string_size,
        value: ost$name,
      recend,
      phase_variable: clt$variable_reference,
      reinitialize_array: array [1 .. 1] of clt$boolean,
      reinitialize_scope: clt$variable_scope,
      reinitialize_variable: clt$variable_reference,
      status: ost$status;

    tmp$save_system_task_id (tmc$stid_job_monitor, TRUE, status);

    osp$verify_system_privilege;

    dsp$advance_deadstart_sequence (dsc$dss_job_template_started);

    osp$initialize_sc_debugger;
    syp$initialize_syscore_template;

    CASE osv$deadstart_phase OF
    = osc$installation_deadstart =
      phase_string.size := 7;
      phase_string.value := 'INSTALL';
    = osc$recovery_deadstart, osc$normal_deadstart =
      phase_string.size := 6;
      phase_string.value := 'NORMAL';
    ELSE
      phase_string.size := 0;
      phase_string.value := '';
    CASEND;

{ Create the SCL variable for deadstart phase.

    #UNCHECKED_CONVERSION (phase_string, phase_array);
    phase_scope.kind := clc$job_variable;
    clp$create_variable ('OSV$DEADSTART_PHASE', clc$string_value, osc$max_name_size, 1, 1, phase_scope,
          phase_variable, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Create osv$deadstart_phase cl variable.', TRUE, status);
    IFEND;
    phase_variable.value.string_value := ^phase_array;
    clp$write_variable ('OSV$DEADSTART_PHASE', phase_variable.value, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Initialize osv$deadstart_phase cl variable.', TRUE, status);
    IFEND;

{ Create the SCL variable for operator intervention.

    intervention_scope.kind := clc$job_variable;
    clp$create_variable ('OSV$OPERATOR_INTERVENTION', clc$boolean_value, 0, 1, 1, intervention_scope,
          intervention_variable, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Create osv$operator_intervention cl variable.', TRUE, status);
    IFEND;
    intervention_array [1].kind := clc$true_false_boolean;
    intervention_array [1].value := osv$operator_intervention;
    intervention_variable.value.boolean_value := ^intervention_array;
    clp$write_variable ('OSV$OPERATOR_INTERVENTION', intervention_variable.value, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Initialize osv$operator_intervention cl variable.', TRUE, status);
    IFEND;

{ Create the SCL variable for system_deadstart_prolog to determine if this is an installation deadstart
{ where the system device is reinitialized.

    reinitialize_scope.kind := clc$job_variable;
    clp$create_variable ('OSV$REINITIALIZE_SYSTEM_DEVICE', clc$boolean_value, 0, 1, 1, reinitialize_scope,
          reinitialize_variable, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Create osv$reinitialize_system_device cl variable.', TRUE, status);
    IFEND;
    reinitialize_array [1].kind := clc$true_false_boolean;
    reinitialize_array [1].value := (osv$recover_system_set_phase = osc$reinitialize_system_device);
    reinitialize_variable.value.boolean_value := ^reinitialize_array;
    clp$write_variable ('OSV$REINITIALIZE_SYSTEM_DEVICE', reinitialize_variable.value, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Initialize osv$reinitiaize_system_device cl variable>', TRUE, status);
    IFEND;

    syp$trace_deadstart_message ('initializing cm device file table');
    cmp$initialize_dft (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Initialize cm device file table failed.', TRUE, status);
    IFEND;

    CASE osv$deadstart_phase OF
    = osc$installation_deadstart =
      phase1_installation (status);
    = osc$recovery_deadstart, osc$normal_deadstart =
      phase1_normal (status);
    ELSE
      syp$process_deadstart_status ('Bad deadstart phase.', TRUE, status);
    CASEND;

    dsp$advance_deadstart_sequence (dsc$dss_load_sitecp);
    dsp$process_deadstart_files ('MF_CONFIG_EPILOG ', FALSE);
    dsp$advance_deadstart_sequence (dsc$dss_sitecp_loaded);

    syp$trace_deadstart_message ('writing all segments to disk');
    mmp$write_all_segments_to_disk (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Write all segments failed.', TRUE, status);
    IFEND;

    dsv$scl_enabled := TRUE;
    pmp$delay (1000, status);

  PROCEND osp$job_template_init_ph1;
?? TITLE := 'osp$job_template_init_ph2', EJECT ??

  PROCEDURE [XDCL, #GATE] osp$job_template_init_ph2
    (VAR deadstart_intervention: boolean;
     VAR deadstart_phase: ost$deadstart_phase);

    VAR
      count: integer,
      define_status: ost$status,
      index: integer,
      msi: cmt$mass_storage_information,
      parameters_p: ^pmt$program_parameters,
      program_attributes: llt$program_attributes,
      status: ost$status,
      task_name: ost$name;

    osp$verify_system_privilege;

    status.normal := TRUE;

    CASE osv$deadstart_phase OF
    = osc$installation_deadstart =
      phase2_installation (status);
      IF NOT status.normal THEN
        syp$process_deadstart_status ('Phase 2 installation', true, status);
      IFEND;
    = osc$recovery_deadstart, osc$normal_deadstart =
      phase2_normal (status);
      IF NOT status.normal THEN
        syp$process_deadstart_status ('Phase 2 normal', true, status);
      IFEND;
    ELSE
      syp$process_deadstart_status ('Bad ds phase in jti.', TRUE, status);
    CASEND;

    jmp$initialize_ssn (osv$deadstart_phase, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('initialize ssn', TRUE, status);
    IFEND;

{ Turn on the ability to log system messages into the engineering log.  This procedure MUST not be called
{ until the global statistics are initialized.

    dsp$allow_sys_msg_logging;

{ Activate the system display manager task.

    program_attributes.contents := $pmt$prog_description_contents
          [pmc$starting_proc_specified, pmc$load_map_options_specified, pmc$term_error_level_specified];
    program_attributes.starting_procedure := 'OFP$SYSTEM_DISPLAY_MANAGER';
    program_attributes.load_map_options := $pmt$load_map_options [pmc$no_load_map];
    program_attributes.termination_error_level := pmc$warning_load_errors;
    task_name := 'OPERATOR_DISPLAY_MANAGER';
    PUSH parameters_p: [[REP 1 OF cell]];
    osp$define_system_task (task_name, TRUE {auto restart} , osc$tt_ignore_or_prohibited
          {deactivate option} , osc$tt_ignore_or_prohibited {idle option} , FALSE {restart after idle} ,
          0 {spy_identifier} , osc$user_ring {execution_ring} , #SEQ (program_attributes), parameters_p,
          define_status);
    osp$activate_system_task (task_name, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Activate system display manager task.', TRUE, status);
    IFEND;

{ Activate the critical window manager task.

    program_attributes.starting_procedure := 'OFP$CRITICAL_WINDOW_MANAGER';
    task_name := 'CRITICAL_WINDOW_MANAGER';
    osp$define_system_task (task_name, TRUE {auto restart} , osc$tt_ignore_or_prohibited
          {deactivate option} , osc$tt_ignore_or_prohibited {idle option} , TRUE {restart after idle} ,
          0 {spy_identifier} , osc$user_ring {execution_ring} , #SEQ (program_attributes), parameters_p,
          define_status);
    osp$activate_system_task (task_name, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Activate critical window manager task.', TRUE, status);
    IFEND;

{ Activate the sweep disk units task.

    count := 0;

  /count_sweep_candidates/
    FOR index := LOWERBOUND (cmv$logical_unit_table^) TO UPPERBOUND (cmv$logical_unit_table^) DO
      IF cmv$logical_unit_table^ [index].configured THEN
        cmp$get_mass_storage_info (cmv$logical_unit_table^ [index].logical_unit_number, msi, status);
        IF NOT status.normal THEN
          CYCLE /count_sweep_candidates/;
        IFEND;
        CASE msi.unit_type OF
        = cmc$ms885_1x, cmc$ms885_4x, cmc$ms834_2, cmc$msfsd_2 =
          count := count + 1;
        ELSE
        CASEND;
      IFEND;
    FOREND /count_sweep_candidates/;

    IF count <> 0 THEN
      program_attributes.starting_procedure := 'IOP$SWEEP_DISK_UNITS';
      task_name := 'SWEEP_DISK_UNITS';
      osp$define_system_task (task_name, TRUE {auto restart} , osc$tt_ignore_or_prohibited
            {deactivate option} , osc$tt_terminate {idle option} , TRUE {restart after idle} , 0
            {spy_identifier} , osc$user_ring {execution_ring} , #SEQ (program_attributes), parameters_p,
            define_status);
      osp$activate_system_task (task_name, status);
      IF NOT status.normal THEN
        syp$process_deadstart_status ('Activate the sweep disk units task.', TRUE, status);
      IFEND;
    IFEND;

{ Activate the DAS head shift testing task.

    count := 0;

  /count_test_candidates/
    FOR index := LOWERBOUND (cmv$logical_unit_table^) TO UPPERBOUND (cmv$logical_unit_table^) DO
      IF cmv$logical_unit_table^ [index].configured THEN
        cmp$get_mass_storage_info (cmv$logical_unit_table^ [index].logical_unit_number, msi, status);
        IF NOT status.normal THEN
          IF (status.condition = cme$it_not_cip_device) OR
                (status.condition = cme$it_no_cip_access) OR
                (status.condition = cme$it_unusable_cip_access) THEN
            ;
          ELSE
            CYCLE /count_test_candidates/;
          IFEND;
        IFEND;
        CASE msi.unit_type OF
        = cmc$ms5833_1 .. cmc$ms5833_4 =
          count := count + 1;
        ELSE
        CASEND;
      IFEND;
    FOREND /count_test_candidates/;

    IF count <> 0 THEN
      program_attributes.starting_procedure := 'IOP$DAS_HEAD_SHIFT_TEST';
      task_name := 'DAS_HEAD_SHIFT_TEST';
      osp$define_system_task (task_name, TRUE {auto restart} , osc$tt_ignore_or_prohibited
            {deactivate option} , osc$tt_terminate {idle option} , TRUE {restart after idle} , 0
            {spy_identifier} , osc$user_ring {execution_ring} , #SEQ (program_attributes), parameters_p,
            define_status);
      osp$activate_system_task (task_name, status);
      IF NOT status.normal THEN
        syp$process_deadstart_status ('Activate the DAS head shift testing task.', TRUE, status);
      IFEND;
    IFEND;

    syp$trace_deadstart_message ('av validate job');
    avp$validate_job (jmc$system_user, jmc$system_family, osc$null_name, osc$null_name, NIL, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('avp validate job', TRUE, status);
    IFEND;

    IF osv$170_os_type <> osc$ot7_none THEN
      syp$trace_deadstart_message ('mli init');
      mlp$initialize (status);
      IF NOT status.normal THEN
        syp$process_deadstart_status ('mlp init', TRUE, status);
      IFEND;
    IFEND;

    syp$trace_deadstart_message ('start job sched task');
    start_system_task (job_sched);

    deadstart_phase := osv$deadstart_phase;
    deadstart_intervention := rav$deadstart_intervention;

    dsp$advance_deadstart_sequence (dsc$dss_load_dstape_libraries);
    dsp$process_deadstart_files ('PRODUCT_EPILOG   ', TRUE);
    dsp$advance_deadstart_sequence (dsc$dss_dstape_libraries_loaded);

  PROCEND osp$job_template_init_ph2;
?? TITLE := 'osp$job_template_init_ph3', EJECT ??

  PROCEDURE [XDCL, #GATE] osp$job_template_init_ph3;

    VAR
      define_status: ost$status,
      parameters_p: ^pmt$program_parameters,
      program_attributes: llt$program_attributes,
      local_status: ost$status,
      recovery_type: string (8),
      rss_command: string (85),
      status: ost$status,
      task_name: ost$name;

    osp$verify_system_privilege;

    status.normal := TRUE;

{ Activate the Tape Scanner task.

    program_attributes.contents := $pmt$prog_description_contents
          [pmc$starting_proc_specified, pmc$load_map_options_specified, pmc$term_error_level_specified];
    program_attributes.starting_procedure := 'IOP$TAPE_SCANNER_EP';
    program_attributes.load_map_options := $pmt$load_map_options [pmc$no_load_map];
    program_attributes.termination_error_level := pmc$warning_load_errors;
    task_name := 'TAPE_SCANNER';
    PUSH parameters_p: [[REP 1 OF cell]];
    osp$define_system_task (task_name, TRUE {auto restart} , osc$tt_ignore_or_prohibited
          {deactivate option} , osc$tt_ignore_or_prohibited {idle option} , FALSE {restart after idle} , 0
          {spy_identifier} , osc$user_ring {execution_ring} , #SEQ (program_attributes), parameters_p,
          define_status);
    osp$activate_system_task (task_name, status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('Activate the tape scanner task.', TRUE, status);
    IFEND;

    IF (osv$deadstart_phase <> osc$installation_deadstart) THEN
      syp$display_deadstart_message ('Begin job reconciliation ...');
      osp$complete_job_recovery (status);
      IF NOT status.normal THEN
        syp$process_deadstart_status ('WARNING -- Job recovery not possible', FALSE, status);
        syp$disable_job_recovery;
        status.normal := TRUE;
      IFEND;
    IFEND;

    cmp$save_mf_configuration (status);
    IF NOT status.normal THEN
      syp$process_deadstart_status ('WARNING -- Update of $system.mainframe.configuration failed', FALSE,
            status);
      status.normal := TRUE;
    IFEND;

    IF osv$170_os_type <> osc$ot7_none THEN
      syp$trace_deadstart_message ('start mli helper task');
      start_system_task (mli_helper);
    IFEND;

    cmp$set_post_ds_flag;
    dsp$exit_deadstart (dsc$run_ve);
    dsp$advance_deadstart_sequence (dsc$dss_deadstart_completed);

    IF (osv$recover_system_set_phase = osc$reinitialize_system_device) OR osv$system_catalog_recreated THEN
      clp$scan_command_line ('change_file_attributes $local.osf$ds_library ra=(3 13 13)', status);
      IF NOT status.normal THEN
        osp$generate_message (status, local_status);
      IFEND;
      rss_command (1, 54) := '$local.osf$ds_library.pfp$recover_system_set set_name=';
      rss_command (55, 31) := stv$system_set_name;
      clp$scan_command_line (rss_command (1, 85), status);
      IF NOT status.normal THEN
        osp$generate_message (status, local_status);
      IFEND;
      recovery_type := dsc$recovery_without_image;
      dsp$store_data_in_rdf (dsc$rdf_previous_recovery_type, dsc$rdf_production, #SEQ (recovery_type));
    IFEND;

  PROCEND osp$job_template_init_ph3;
MODEND osm$job_template_initialization;

