?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Dump Analyzer : Copy Control Store Command' ??
MODULE dum$copy_control_store;

{ PURPOSE:
{   This module contains the code for the copy_control_store command.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc due$exception_condition_codes
?? POP ??
*copyc amp$get_segment_pointer
*copyc amp$set_segment_eoi
*copyc dup$evaluate_parameters
*copyc fsp$close_file
*copyc fsp$open_file
*copyc osp$append_status_integer
*copyc osp$append_status_parameter
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
*copyc osp$set_status_abnormal
?? EJECT ??
*copyc duv$dump_environment_p
*copyc duv$execution_environment
?? OLDTITLE ??
?? NEWTITLE := 'dup$copy_control_store' ??

{ PURPOSE:
{   This procedure copies the control store data from the restart file to the output file.

  PROCEDURE [XDCL] dup$copy_control_store
    (    parameter_list: clt$parameter_list;
     VAR status: ost$status);

{ PROCEDURE copy_control_store, copcs (
{   file, f: file = $required
{   processor, p: integer 0..3 = 0
{   shadow, s: boolean = FALSE
{   status)

?? PUSH (LISTEXT := ON) ??
?? FMT (FORMAT := OFF) ??
  VAR
    pdt: [STATIC, READ, cls$declaration_section] record
      header: clt$pdt_header,
      names: array [1 .. 7] of clt$pdt_parameter_name,
      parameters: array [1 .. 4] of clt$pdt_parameter,
      type1: record
        header: clt$type_specification_header,
      recend,
      type2: record
        header: clt$type_specification_header,
        qualifier: clt$integer_type_qualifier,
        default_value: string (1),
      recend,
      type3: record
        header: clt$type_specification_header,
        default_value: string (5),
      recend,
      type4: record
        header: clt$type_specification_header,
      recend,
    recend := [
    [1,
    [90, 9, 19, 8, 0, 0, 344],
    clc$command, 7, 4, 1, 0, 0, 0, 4, ''], [
    ['F                              ',clc$abbreviation_entry, 1],
    ['FILE                           ',clc$nominal_entry, 1],
    ['P                              ',clc$abbreviation_entry, 2],
    ['PROCESSOR                      ',clc$nominal_entry, 2],
    ['S                              ',clc$abbreviation_entry, 3],
    ['SHADOW                         ',clc$nominal_entry, 3],
    ['STATUS                         ',clc$nominal_entry, 4]],
    [
{ PARAMETER 1
    [2, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 3, clc$required_parameter, 0
  , 0],
{ PARAMETER 2
    [4, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 20,
  clc$optional_default_parameter, 0, 1],
{ PARAMETER 3
    [6, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name, clc$specify_positionally],
    clc$pass_by_value, clc$immediate_evaluation, clc$standard_parameter_checking, 3,
  clc$optional_default_parameter, 0, 5],
{ PARAMETER 4
    [7, clc$normal_usage_entry, clc$non_secure_parameter,
    $clt$parameter_spec_methods[clc$specify_by_name],
    clc$pass_by_reference, clc$immediate_evaluation, clc$standard_parameter_checking, 3,
  clc$optional_parameter, 0, 0]],
{ PARAMETER 1
    [[1, 0, clc$file_type]],
{ PARAMETER 2
    [[1, 0, clc$integer_type], [0, 3, 10],
    '0'],
{ PARAMETER 3
    [[1, 0, clc$boolean_type],
    'FALSE'],
{ PARAMETER 4
    [[1, 0, clc$status_type]]];
?? FMT (FORMAT := ON) ??
?? POP ??

    CONST
      p$file = 1,
      p$processor = 2,
      p$shadow = 3,
      p$status = 4;

    VAR
      pvt: array [1 .. 4] of clt$parameter_value;

    VAR
      cell_p: ^cell,
      control_store_entry: dut$de_control_store_entry,
      default_list: ARRAY [1 .. 1] OF dut$default_change_list_entry,
      fa_p: ^fst$attachment_options,
      file_buffer_p: ^SEQ ( * ),
      file_identifier: amt$file_identifier,
      file_pointer: amt$segment_pointer,
      ignore_status: ost$status,
      mca_p: ^fst$file_cycle_attributes,
      processor: 0 .. 3,
      restart_file_buffer_p: ^SEQ ( * ),
      restart_file_seq_p: ^SEQ ( * );

*copy dup$abort_handler
?? NEWTITLE := 'clean_up', EJECT ??

{ PURPOSE:
{   This procedure is called from the abort hander to close the file.

    PROCEDURE [INLINE] clean_up;

      VAR
        ignore_status: ost$status;

      fsp$close_file (file_identifier, ignore_status);

    PROCEND clean_up;
?? OLDTITLE, EJECT ??

    status.normal := TRUE;

    { Change the default value for the PROCESSOR parameter.

    default_list [1].default_name := duc$dp_processor;
    default_list [1].number := p$processor;
    dup$evaluate_parameters (parameter_list, default_list, #SEQ (pdt), ^pvt, status);
    IF NOT status.normal THEN
      RETURN;  {---->
    IFEND;

    IF duv$dump_environment_p = NIL THEN
      osp$set_status_abnormal (duc$dump_analyzer_id, due$no_restart_file, '', status);
      RETURN;  {---->
    IFEND;

    processor := pvt [p$processor].value^.integer_value.value;
    IF pvt [p$shadow].value^.boolean_value.value THEN
      control_store_entry := duv$dump_environment_p^.control_store.shadow [processor];
    ELSE
      control_store_entry := duv$dump_environment_p^.control_store.main [processor];
    IFEND;
    IF NOT control_store_entry.available THEN
      IF pvt [p$shadow].value^.boolean_value.value THEN
        osp$set_status_abnormal (duc$dump_analyzer_id, due$data_not_on_dump,
              'The shadow control store for processor', status);
      ELSE
        osp$set_status_abnormal (duc$dump_analyzer_id, due$data_not_on_dump,
              'The main control store for processor', status);
      IFEND;
      osp$append_status_integer (osc$status_parameter_delimiter, processor, 10, FALSE, status);
      osp$append_status_parameter (osc$status_parameter_delimiter, 'is', status);
      RETURN;  {---->
    IFEND;

    osp$establish_block_exit_hndlr (^abort_handler);

    { Open the output file.

    PUSH fa_p: [1 .. 1];
    fa_p^ [1].selector := fsc$access_and_share_modes;
    fa_p^ [1].access_modes.selector := fsc$specific_access_modes;
    fa_p^ [1].access_modes.value := $fst$file_access_options [fsc$read, fsc$shorten, fsc$append, fsc$modify];
    fa_p^ [1].share_modes.selector := fsc$specific_share_modes;
    fa_p^ [1].share_modes.value := $fst$file_access_options [fsc$read, fsc$shorten, fsc$append, fsc$modify];

    PUSH mca_p: [1 .. 2];
    mca_p^ [1].selector := fsc$record_type;
    mca_p^ [1].record_type := amc$undefined;
    mca_p^ [2].selector := fsc$preset_value;
    mca_p^ [2].preset_value := -1;

    fsp$open_file (pvt [p$file].value^.file_value^, amc$segment, fa_p, NIL, mca_p, NIL, NIL, file_identifier,
          status);
    IF NOT status.normal THEN
      RETURN;  {---->
    IFEND;

   /file_opened/
    BEGIN
      amp$get_segment_pointer (file_identifier, amc$sequence_pointer, file_pointer, status);
      IF NOT status.normal THEN
        EXIT /file_opened/;  {---->
      IFEND;
      IF file_pointer.sequence_pointer = NIL THEN
        osp$set_status_abnormal (duc$dump_analyzer_id, due$nil_pointer, '', status);
        EXIT /file_opened/;  {---->
      IFEND;
      RESET file_pointer.sequence_pointer;

      { Retrieve a pointer to the control store data on the restart file.

      restart_file_seq_p := duv$execution_environment.data_file_p^.segment_pointer.sequence_pointer;
      cell_p := #ADDRESS (#RING (restart_file_seq_p), #SEGMENT (restart_file_seq_p),
            control_store_entry.first_byte);
      RESET restart_file_seq_p TO cell_p;
      NEXT restart_file_buffer_p: [[REP control_store_entry.size OF dut$de_control_store_word]] IN
            restart_file_seq_p;
      IF restart_file_buffer_p = NIL THEN
        osp$set_status_abnormal (duc$dump_analyzer_id, due$nil_pointer, '', status);
        EXIT /file_opened/;  {---->
      IFEND;

      { Retrieve a pointer to the output file for the control store data.

      NEXT file_buffer_p: [[REP control_store_entry.size OF dut$de_control_store_word]] IN
            file_pointer.sequence_pointer;
      IF file_buffer_p = NIL THEN
        osp$set_status_abnormal (duc$dump_analyzer_id, due$nil_pointer, '', status);
        EXIT /file_opened/;  {---->
      IFEND;

      { Copy the control store data from the restart file to the output file.

      file_buffer_p^ := restart_file_buffer_p^;
      amp$set_segment_eoi (file_identifier, file_pointer, status);
    END /file_opened/;

    fsp$close_file (file_identifier, ignore_status);
    osp$disestablish_cond_handler;

  PROCEND dup$copy_control_store;
MODEND dum$copy_control_store;
