?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE System Initialization: Main Routine' ??
MODULE osm$initialize_virtual_system;

{ PURPOSE:
{   This module contains the procedures to complete the initialization of the system to the point where
{   deadstart completes and the System Loop is entered.
{
{ NOTES:
{   This module is located on the OSF$JOB_TEMPLATE_2DD library.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc ost$deadstart_phase
*copyc ost$status
?? POP ??
*copyc clp$convert_string_to_file
*copyc clp$include_line
*copyc clp$log_comment
*copyc loc$task_services_library_name
*copyc osp$activate_system_task
*copyc osp$define_system_task
*copyc osp$generate_message
*copyc osp$scan_ijl_for_recovered_jobs
?? TITLE := '[XDCL] osp$initialize_virtual_system', EJECT ??

{ PURPOSE:
{   This interface initializes the system to the point where deadstart completes.  The system task Dump Broken
{   Job is defined and activated.  Then job classes are established and jobs recovered.  Finally, the system
{   task Console Interaction is defined (not activated).
{
{ NOTES:
{   Console Interaction is activated within the interface OSP$RUN_VIRTUAL_SYSTEM.

  PROCEDURE [XDCL] osp$initialize_virtual_system
    (    deadstart_phase: ost$deadstart_phase);

    VAR
      console_interaction_descriptor: ^llt$program_description,
      dump_broken_job_descriptor: ^llt$program_description,
      ignore_status: ost$status,
      libraries: ^llt$object_library_list,
      log_name_selections: array [1 .. 1] of ost$name,
      parameters: ^pmt$program_parameters,
      program_attributes: ^llt$program_attributes,
      status: ost$status,
      task_name: ost$name;

    status.normal := TRUE;

{ Define and activate the system task Dump Broken Job.

    PUSH dump_broken_job_descriptor: [[REP (#SIZE (llt$program_attributes) + #SIZE (clt$path_name)) OF
          cell]];
    RESET dump_broken_job_descriptor;
    PUSH parameters: [[REP 1 OF cell]];
    NEXT program_attributes IN dump_broken_job_descriptor;
    program_attributes^.contents := $pmt$prog_description_contents
          [pmc$starting_proc_specified, pmc$library_list_specified, pmc$load_map_options_specified,
          pmc$term_error_level_specified];
    program_attributes^.starting_procedure := 'OSP$BROKEN_JOB_DUMP_TASK';
    program_attributes^.number_of_libraries := 1;
    NEXT libraries: [1 .. 1] IN dump_broken_job_descriptor;
    libraries^ [1] := loc$task_services_library_name;
    program_attributes^.load_map_options := $pmt$load_map_options [pmc$no_load_map];
    program_attributes^.termination_error_level := pmc$warning_load_errors;
    task_name := 'DUMP_BROKEN_JOB';

    osp$define_system_task (task_name, TRUE {auto restart} , osc$tt_terminate {deactivate option} ,
          osc$tt_terminate {idle option} , TRUE {restart after idle} , 0 {spy_identifier} ,
          osc$user_ring {execution_ring} , dump_broken_job_descriptor, parameters, status);
    IF NOT status.normal THEN
      osp$generate_message (status, ignore_status);
    IFEND;

    osp$activate_system_task (task_name, status);
    IF NOT status.normal THEN
      osp$generate_message (status, ignore_status);
    IFEND;

{ Establish job classes on a continuation deadstart.

    IF deadstart_phase = osc$normal_deadstart THEN
      clp$include_line ('$system.osf$builtin_library.rap$establish_job_classes initiate_jobs=FALSE',
            TRUE, osc$null_name, status);
      IF NOT status.normal THEN
        osp$generate_message (status, ignore_status);
      IFEND;
    IFEND;

{ Allow recoverable jobs to swap in or get rid of any jobs for which the job class of the job is not defined;
{ if this is not a recovery deadstart no jobs will be found, so nothing will happen.

    osp$scan_ijl_for_recovered_jobs;

{ Define the system task Console Interaction.

    PUSH console_interaction_descriptor: [[REP (#SIZE (llt$program_attributes) +
          2 * #SIZE (clt$path_name)) OF cell]];
    RESET console_interaction_descriptor;
    PUSH parameters: [[REP 1 OF cell]];
    NEXT program_attributes IN console_interaction_descriptor;
    program_attributes^.contents := $pmt$prog_description_contents
          [pmc$starting_proc_specified, pmc$library_list_specified, pmc$load_map_options_specified,
          pmc$term_error_level_specified];
    program_attributes^.starting_procedure := 'OSP$CONSOLE_INTERACTION_TASK';
    program_attributes^.number_of_libraries := 2;
    NEXT libraries: [1 .. 2] IN console_interaction_descriptor;
    libraries^ [1] := loc$task_services_library_name;
    libraries^ [2] := '$SYSTEM.OSF$OPERATOR_LIBRARY';
    program_attributes^.load_map_options := $pmt$load_map_options [pmc$no_load_map];
    program_attributes^.termination_error_level := pmc$warning_load_errors;
    task_name := 'CONSOLE_INTERACTION';

    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} , console_interaction_descriptor, parameters,
          status);
    IF NOT status.normal THEN
      osp$generate_message (status, ignore_status);
    IFEND;

    log_name_selections [1] := 'SYSTEM';
    clp$log_comment ('----  System Deadstart Completed ----', log_name_selections, status);
    IF NOT status.normal THEN
      osp$generate_message (status, ignore_status);
    IFEND;

  PROCEND osp$initialize_virtual_system;

MODEND osm$initialize_virtual_system;
