
PROC dum$analyze_active_segment_tab, analyze_active_segment_table, anaast (
  output, o: file = $output
  status)

  crev s kind=status
  crev field_offset integer
  crev field_length integer
  crev asti integer
  delf out status=s
  setfa out fc=list

  pft_entry_size = $mem($sa(mmv$pft_p)+14 4)
  pftlb = $mem($sa(mmv$pft_p)+10 4)
  pftub = ($mem($sa(mmv$pft_p)+6 4) / pft_entry_size) + pftlb - 1
  pft   = $mem($sa(mmv$pft_p) 6)-pftlb*pft_entry_size

  ast   = $mem($sa(mmv$ast_p) 6)
  ast_entry_size = $mem($sa(mmv$ast_p)+14 4)
  astub = $mem($sa(mmv$ast_p)+6 4) / ast_entry_size - 1

  mmt$page_frame_table_entry field=sva offset=field_offset length=field_length
  asid_offset = field_offset / 8
  mmt$page_frame_table_entry field=aste_p offset=field_offset length=field_length
  aste_p_offset = field_offset / 8
  mmt$active_segment_table_entry field=pages_in_memory offset=field_offset length=field_length
  pim_offset = field_offset / 8
  mmt$active_segment_table_entry field=in_use offset=field_offset length=field_length
  in_use_offset = field_offset / 8

  crev asidcnt integer d=0..65535 v=0
  crev astp integer d=0..65535 v=0ffff80000000(16)
  putl ' ANALYZE ACTIVE SEGMENT TABLE ' o=out.$eoi
  FOR pfti = pftlb to pftub do
    pftp = pft+pft_entry_size*pfti
    asid = $mem(pftp+asid_offset 2)
    asidcnt(asid) = asidcnt(asid) + 1
    if astp(asid) =  0ffff80000000(16) then
      astp(asid) = $mem(pftp+aste_p_offset 6)
      dum$asti asid ,, asti
      if (asid <> 0) AND ((asti*ast_entry_size + ast) <> astp(asid)) THEN
        putl ' PFT.ASTE_P does not point to the entry that corresponds to PFT.SVA.ASID, PFTI = '//$strrep(pfti 16) o=out.$eoi
      ifend
    elseif (astp(asid) <> $mem(pftp+aste_p_offset 6)) and (asid > 0) then
      putl ' Inconsistent PFT.ASTE_P. PFTI = '//$strrep(pfti 16) o=out.$eoi
      putl '     Found '//$strrep($mem(pftp+aste_p_offset 6) 16)//', and '//$strrep(astp(asid) 16) o=out.$eoi
    ifend
  FOREND


  crev asteok boolean d=0..65535 v=false
  for asid = 1 to 65535
    astep = astp(asid)
    if astep <> 0ffff80000000(16)
      if $mem(astep+pim_offset 2) <> asidcnt(asid) then
        putl ' AST.PIM <> number PFT entries found. ASID = '//$strrep(asid 16)//'. ASTE_P = '//$strrep(astep 16) o=out.$eoi
        putl '        AST.PIM = '//$strrep($mem(astep+pim_offset 2))//', found = '//$strrep(asidcnt(asid)) o=out.$eoi
      ifend
      asti = (astep - ast) / ast_entry_size
      asteok(asti) = TRUE
    ifend
  forend

  astfree = 0
  astfreepim = 0
  for asti = 1 to astub
    astep = ast+asti*ast_entry_size
    if NOT asteok(asti)
      if $mem(astep+pim_offset 2) > 0 then
        putl ' AST.PIM > 0 but no PFT entries found. ASTEP = '//$strrep(astep 16) o=out.$eoi
        putl '        AST.PIM = '//$strrep($mem(astep+pim_offset 2)) o=out.$eoi
      ifend
    ifend
    if $mem(astep+in_use_offset 1) = 0 then
      if $mem(astep+pim_offset 2) = 0 then
        astfree = astfree + 1
      else
        astfreepim = astfreepim + 1
        putl ' ASTE free but PIM>0, ASTI = '//$strrep(asti 16)
      ifend
    ifend
  forend
  if astfree <> $mem($sa(mmv$number_free_astes) 8) then
    putl ' Bad NUMBER_FREE_ASTES. Found = '//$strrep(astfree)//', should be '//$strrep($mem($sa(mmv$number_free_astes) 8))..
          o=out.$eoi
  ifend
  if astfreepim <> $mem($sa(mmv$number_free_astes_with_pim) 8) then
    putl ' Bad NUMBER_FREE_ASTES_WITH_PIM. Found = '//$strrep(astfreepim)//', should be '//..
          $strrep($mem($sa(mmv$number_free_astes_with_pim) 8)) o=out.$eoi
  ifend
  copf out $value(output)
PROCEND dum$analyze_active_segment_tab

