;/*static char *SCCSID = "@(#)dosext.asm        6.7 92/03/18";*/
PAGE    ,132
NAME    DOSEXT
TITLE   DOSEXT.ASM - External debugger commands for OS/2
.386p
.286p

;***    DOSEXT.ASM
;
;       IBM/Microsoft Confidential
;
;       Copyright (c) IBM Corporation 1987, 1989
;       Copyright (c) Microsoft Corporation 1987, 1989
;
;       All Rights Reserved
;
;
;       Routines to perform commands that are external to
;       the debugger and are environment dependent. These
;       are commands that are specific to OS/2 and uses
;       OS/2 data structures.
;
; Modification:
;********************************************************************
;82818 ChangeTeam 02/07/95                                    ;82818
;82818     Moving r206 debug .mk command to R207              ;82818
;RJM       Fix .LMP
;154740 15 May 1996 RJM Add .LMI and .SYSDUMP
;155843 13 Jun 1996 RJM Add .ML to Help            
;158783 27 Jun 1996 RJM fix trap d in GetMTEName
;                       Add .MK to help
;                       remove .D DT from help


INCL_MI =       1

.xlist
        include fnodeb.inc
        include dosseg.inc
        include basemaca.inc
        include osmaca.inc
        include mi.inc
        include vpb.inc
        include dpb.inc
        include bpb.inc
        include sft.inc
        include tkexport.inc
        include mft.inc
        include buffer.inc
        include devsym.inc
        include debseg.inc
        include debmac.inc
        include debequ.inc
        include debprt.inc
        include curdir.inc
        include ldrvars.inc
        include attrace.inc
.list
        ModName dosext,FNO_DOSEXT_ASM

EXTRNFAR       Find_DPB
EXTRN32        TMR32SubTime
; Start of change DGE
EXTRN32        TMR32AddTime
; End of change DGE
extrn          _PGSwitchContext:far
extrn          pgSwitchRet:far
extrn          _tkSchedNext:far
extrn          SchedNextRet:far
extrn          SchedNextRet2:far
extrn          _DebugLoadSymMTE:far
extrn          EndDebugLoadSymMTE:far
extrn          _Debug_CtrlC32:far
extrn          _EndCtrlC32:far

ReferFlat      ulTmrFreq, DWORD
; Start of change DGE
ReferFlat       pTSBuff, DWORD
; End of change DGE

.386p
_DATA   SEGMENT

public  GoTimeL, GoTimeH
        GoTimeL         dd      0       ; Low half of GoTime
        GoTimeH         dd      0       ; High half of GoTime

; Start of code change DGE
        cTSEntries              dd      -1      ; # entries in TS buff (less 1)
; End of code change DGE

_DATA   ENDS
.286p



?ASSUMECS macro
        assumeCODE <cs>         ;; Hack for CALL32 macro
endm

MAX_PATH_LEN    equ     64      ;; BUGBUG was defined in segmngr.inc!!
CACHEPATHLEN    equ     PMPATHLEN
MAXMODNAME      equ     20

        EXTRN32         _DbgDRAlloc
        EXTRN32         _DbgDRFree

        Extern  DosLinAddr, BYTE

        ReferFlat       _mte_h,DWORD
        ReferFlat       _pTCBCur,DWORD

LINES_PER_PAGE          equ     23

;       BUGBUG - h2inc chokes on h/newexe.h:
new_seg struc
        db      8 dup (?)
new_seg ends

DataSegmentStart

;
; Bad trace address table
;

.386p
ASSUME FS:FLAT                  ; To enable keyword

GenPub btatab, PUBLIC
_btatab LABEL BYTE

        ; First Start AddrS Structure

        dd      offset FLAT:_PGSwitchContext    ; Offset
        dw      0                               ; Segment
        db      EXPR_TYPE_LIN                   ; Type
        db      0                               ; Address Size
        dw      0                               ; Address Task

        ; First End AddrS Structure

        dd      offset FLAT:pgSwitchRet         ; Offset
        dw      0                               ; Segment
        db      EXPR_TYPE_LIN                   ; Type
        db      0                               ; Address Size
        dw      0                               ; Address Task

        ; Second Start AddrS Structure

        dd      offset FLAT:_DebugLoadSymMTE    ; Offset
        dw      0                               ; Segment
        db      EXPR_TYPE_LIN                   ; Type
        db      0                               ; Address Size
        dw      0                               ; Address Task

        ; Second End AddrS Structure

        dd      offset FLAT:EndDebugLoadSymMTE  ; Offset
        dw      0                               ; Segment
        db      EXPR_TYPE_LIN                   ; Type
        db      0                               ; Address Size
        dw      0                               ; Address Task

        ; Third Start AddrS Structure

        dd      offset DBGCODE:_Debug_CtrlC32   ; Offset
        dw      seg DBGCODE                     ; Segment
        db      EXPR_TYPE_SEL                   ; Type
        db      0                               ; Address Size
        dw      0                               ; Address Task

        ; Third End AddrS Structure

        dd      offset DBGCODE:_EndCtrlC32      ; Offset
        dw      seg DBGCODE                     ; Segment
        db      EXPR_TYPE_SEL                   ; Type
        db      0                               ; Address Size
        dw      0                               ; Address Task

;
; Start and end(s) of a reschedule
;

GenPub ContextStartAddr, PUBLIC
_ContextStartAddr LABEL BYTE
        dd      offset FLAT:_tkSchedNext        ; Offset
        dw      0                               ; Segment
        db      EXPR_TYPE_LIN                   ; Type
        db      0                               ; Address Size
        dw      0                               ; Address Task

GenPub ContextEndAddr, PUBLIC
_ContextEndAddr LABEL BYTE
        dd      offset FLAT:SchedNextRet        ; Offset
        dw      0                               ; Segment
        db      EXPR_TYPE_LIN                   ; Type
        db      0                               ; Address Size
        dw      0                               ; Address Task

GenPub ContextEndAddr2, PUBLIC
_ContextEndAddr2 LABEL BYTE
        dd      offset FLAT:SchedNextRet2       ; Offset
        dw      0                               ; Segment
        db      EXPR_TYPE_LIN                   ; Type
        db      0                               ; Address Size
        dw      0                               ; Address Task

.286p

Extern  pTXT,      WORD
Extern  RegSA,     WORD
Static  Context,   DWORD,       0       ; Last context for TraceSpecial

Static  HelpMsg, LABEL, BYTE

        db      "B <baud rate> [<port addr>] - set COM baud rate/port addr (1 = COM1, 2 = COM2)"
        db      CR,LF

        db      "C - dump ABIOS common data area"
        db      CR,LF

        db      "D <name> [<addr>] - dump a DOS data struc: "
        db      "SFT,DPB,BPB,VPB,DEV,REQ,MFT,BUF,CDS,"
        db      CR,LF
        db      "                                           "
        db      "SEM32,OPENQ,MUXQ,KSEM"        ; 158783
        db      CR,LF

        db      "IT[D | B] <slot> - make TSD present"
        db      CR,LF

        db      "I[D | B] <addr> - make address present"
        db      CR,LF

        db      "K [<slot> | # | *] - dump user stack"
        db      CR,LF

;154740 RJM add .LMI
        db      "LM[O][L|P|V|I|X] [<hobmte> | <pmte> | <'modulename'>] - print MTEs"
        db      CR,LF

        db      "MA[B|C|F|H|L|M|R] [<har|laddr>] | [<range>] - dump arena records"
        db      CR,LF

        db      "MC[B|C|F] [<hco|laddr>] | [<range>] - dump context records"
        db      CR,LF
;158783 moved to be in alphabetical order
;** 82818 ***
        db      "MK[L] [hob] - dump vm lock info record"
        db      CR,LF
;** end 82818 ***

        db      "ML[B|C|F] [<hal|laddr>] | [<range>] - dump alias records" ;155843
        db      CR,LF                                                      ;155843

        db      "MO[B|C|F|M|N|P|S|V] [<hob|laddr>] | [<range>] - dump object records"
        db      CR,LF

;154740 RJM .MP fix syntax
        db      "MP[B|F|I|L|R] [<frame|laddr>] | [<range>] - dump page frame"
        db      CR,LF

;154740 RJM .MS -> .MV and correct description
        db      "MV[B|F|L|R] [<swapid|laddr>] | [<range>] - dump virtual page"
        db      CR,LF


;154740 RJM add .PG
        db      "P[B|U|Q] [<slot> | # | *] - prints process status"
        db      CR,LF

        db      "R [<slot> | # | *] - registers of another context"
        db      CR,LF

        db      "S[S] [<slot> | *] - change to an other task context"
        db      CR,LF

        db      "REBOOT - reboots machine"
        db      CR,LF

;154740 RJM
        db      "SYSDUMP - forces a system dump"
        db      CR,LF

        db      "T [<count>] [maj=<xx> [min=<xx>]] - dump trace buffer records"
        db      CR,LF

        db      "? - prints help message"
        db      CR,LF

        db      0

Static  ExtCmdTable, LABEL, BYTE
        CmdTable_s <"B", codeOFFSET SetBaudCmd>
        CmdTable_s <"C", codeOFFSET DumpCDA>
        CmdTable_s <"D", codeOFFSET DumpData>
        CmdTable_s <"I", codeOFFSET MakePresentCmd>
        CmdTable_s <"K", codeOFFSET DumpUserStack>
        CmdTable_s <"L", codeOFFSET DumpLoader>
        CmdTable_s <"M", codeOFFSET DumpMem>
        CmdTable_s <"P", codeOFFSET ProcessStatus>
        CmdTable_s <"R", codeOFFSET RCheck>
;RJM    CmdTable_s <"S", codeOFFSET ChangeCurrTask> ;RJM 154740
        CmdTable_s <"S", codeOFFSET SCheck>         ;RJM 154740
        CmdTable_s <"T", codeOFFSET DumpTraceBuffer>
        CmdTable_s <"?", codeOFFSET Help>
        CmdTable_s <0,   codeOFFSET perr>


;*      DOS data structure printer data

Static  SFTmsg, STRING, "SFT"
Static  VPBmsg, STRING, "VPB"
Static  DPBmsg, STRING, "DPB"
Static  DEVmsg, STRING, "DEV"
Static  REQmsg, STRING, "REQ"
Static  BPBmsg, STRING, "BPB"
Static  MFTmsg, STRING, "MFT"
Static  BUFmsg, STRING, "BUF"
Static  CDSmsg, STRING, "CDS"
Static  SEMmsg, STRING, "SEM32"
Static  OpQmsg, STRING, "OPENQ"
Static  MQmsg,  STRING, "MUXQ"
Static  DTmsg,  STRING, "DT"
Static  KSmsg,  STRING, "KSEM"

DumpDataCmds    label   word
        InSwitchStr                             ; switch on register name
        SwitchEntry     SFTmsg, DumpSFT
        SwitchEntry     VPBmsg, DumpVPB
        SwitchEntry     DPBmsg, DumpDPB
        SwitchEntry     DEVmsg, DumpDEV
        SwitchEntry     REQmsg, DumpREQ
        SwitchEntry     BPBmsg, DumpBPB
        SwitchEntry     MFTmsg, DumpMFT
        SwitchEntry     BUFmsg, DumpBUF
        SwitchEntry     CDSmsg, DumpCDS
        SwitchEntry     SEMmsg, DumpSEM
        SwitchEntry     OpQmsg, DumpOpQ
        SwitchEntry     MQmsg,  DumpMQ
        SwitchEntry     DTmsg,  DumpDT          ; Dump Disk Trace
        SwitchEntry     KSmsg,  DumpKSEM
        SwitchEnd       DumpErr

;*      Prints a SFT structure

DumpSFT         label   byte

        OutBlanks 6
        OutStr  "sf_ref_count: "
        OutWordHexPtr sf_ref_count

        OutBlanks 24
        OutStr  "sfi_mode: "
        OutWordHexPtr sf_fsi.sfi_mode
        OutCrLf

        OutBlanks 8
        OutStr  "sf_usercnt: "
        OutWordHexPtr sf_fsi.sf_usercnt

        OutBlanks 24
        OutStr  "sfi_hVPB: "
        OutWordHexPtr sf_fsi.sfi_hVPB
        OutCrLf

        OutBlanks 10
        OutStr  "reserved: "
        OutByteHexPtr reserved

        OutBlanks 25
        OutStr  "sfi_ctime: "
        OutWordHexPtr sf_fsi.sfi_ctime
        OutCrLf

        OutBlanks 7
        OutStr  "sf_flags(2): "
        OutWordHexPtr sf_flags
        OutStr  ":"
        OutWordHexPtr sf_flags2

        OutBlanks 18
        OutStr  "sfi_cdate: "
        OutWordHexPtr sf_fsi.sfi_cdate
        OutCrLf

        OutBlanks 9
        OutStr  "sf_devptr: #"
        OutWordHexPtr sf_devptr.Segmt16
        OutChar ":"
        OutWordHexPtr sf_devptr.Offst16

        OutBlanks 17
        OutStr  "sfi_atime: "
        OutWordHexPtr sf_fsi.sfi_atime
        OutCrLf

        OutBlanks 12
        OutStr  "sf_FSC: #"
        OutWordHexPtr sf_FSC.Segmt16
        OutChar ":"
        OutWordHexPtr sf_FSC.Offst16

        OutBlanks 17
        OutStr  "sfi_adate: "
        OutWordHexPtr sf_fsi.sfi_adate
        OutCrLf

        OutBlanks 10
        OutStr  "sf_chain: #"
        OutWordHexPtr sf_chain.Segmt16
        OutChar ":"
        OutWordHexPtr sf_chain.Offst16

        OutBlanks 17
        OutStr  "sfi_mtime: "
        OutWordHexPtr sf_fsi.sfi_mtime
        OutCrLf

        OutBlanks 12
        OutStr  "sf_MFT: "
        OutDwordHexPtr sf_MFT

        OutBlanks 19
        OutStr  "sfi_mdate: "
        OutWordHexPtr sf_fsi.sfi_mdate
        OutCrLf

;       OutBlanks 0
        OutStr  "sfdFAT_firFILEclus: "
        OutWordHexPtr sf_fsd.sfdFAT_firFILEclus

        OutBlanks 24
        OutStr  "sfi_size: "
        OutDwordHexPtr sf_fsi.sfi_size
        OutCrLf

        OutBlanks 4
        OutStr  "sfdFAT_cluspos: "
        OutWordHexPtr sf_fsd.sfdFAT_cluspos

        OutBlanks 20
        OutStr  "sfi_position: "
        OutDwordHexPtr sf_fsi.sfi_position
        OutCrLf

        OutBlanks 4
        OutStr  "sfdFAT_lstclus: "
        OutWordHexPtr sf_fsd.sfdFAT_lstclus

        OutBlanks 25
        OutStr  "sfi_UID: "
        OutWordHexPtr sf_fsi.sfi_UID
        OutCrLf

        OutBlanks 5
        OutStr  "sfdFAT_dirsec: "
        OutDwordHexPtr sf_fsd.sfdFAT_dirsec

        OutBlanks 21
        OutStr  "sfi_PID: "
        OutWordHexPtr sf_fsi.sfi_PID
        OutCrLf

        OutBlanks 5
        OutStr  "sfdFAT_dirpos: "
        OutByteHexPtr sf_fsd.sfdFAT_dirpos

        OutBlanks 27
        OutStr  "sfi_PDB: "
        OutWordHexPtr sf_fsi.sfi_PDB
        OutCrLf

        OutBlanks 7
        OutStr  "sfdFAT_name: "
        OutStrPtr sf_fsd.sfdFAT_name, SFNAMELEN

        OutBlanks 22
        OutStr  "sfi_selfsfn: "
        OutWordHexPtr sf_fsi.sfi_selfsfn
        OutCrLf

        OutBlanks 3
        OutStr  "sfdFAT_EAHandle: "
        OutWordHexPtr sf_fsd.sfdFAT_EAHandle

        OutBlanks 22
        OutStr  "sfi_tstamp: "
        OutByteHexPtr sf_fsi.sfi_tstamp
        OutCrLf

        OutBlanks 10
        OutStr "sf_plock: "
        OutWordHexPtr sf_plock

        OutBlanks 21
        OutStr  "sfi_DOSattr: "
        OutByteHexPtr sf_fsi.sfi_DOSattr
        OutCrLf

        OutBlanks 6
        OutStr "sf_NmPipeSfn: "
        OutWordHexPtr sf_NmPipeSfn
        OutCrLf

        OutBlanks 7
        OutStr "sf_codepage: "
        OutWordHexPtr sf_codepage
        OutCrLf

        EndOp

;*      Prints a VPB structure

DumpVPB         label   byte

        OutBlanks 8
        OutStr  "vpb_flink: "
        OutWordHexPtr vpb_flink

        OutBlanks 18
        OutStr  "vpdFAT_cluster_mask: "
        OutByteHexPtr vpb_fsd.vpdFAT_cluster_mask
        OutCrLf

        OutBlanks 8
        OutStr  "vpb_blink: "
        OutWordHexPtr vpb_blink

        OutBlanks 17
        OutStr  "vpdFAT_cluster_shift: "
        OutByteHexPtr vpb_fsd.vpdFAT_cluster_shift
        OutCrLf

        OutBlanks 4
        OutStr  "vpb_ref_count: "
        OutWordHexPtr vpb_ref_count

        OutBlanks 21
        OutStr  "vpdFAT_first_FAT: "
        OutWordHexPtr vpb_fsd.vpdFAT_first_FAT
        OutCrLf

        OutBlank
        OutStr  "vpb_search_count: "
        OutWordHexPtr vpb_search_count

        OutBlanks 21
        OutStr  "vpdFAT_FAT_count: "
        OutByteHexPtr vpb_fsd.vpdFAT_FAT_count
        OutCrLf

        OutBlank
        OutStr  "vpb_first_access: "
        OutByteHexPtr vpb_first_access

        OutBlanks 20
        OutStr  "vpdFAT_root_entries: "
        OutWordHexPtr vpb_fsd.vpdFAT_root_entries
        OutCrLf

        OutBlanks 4
        OutStr  "vpb_signature: "
        OutWordHexPtr vpb_signature

        OutBlanks 18
        OutStr  "vpdFAT_first_sector: "
        OutDwordHexPtr vpb_fsd.vpdFAT_first_sector
        OutCrLf

        OutBlanks 5
        OutStr  "vpb_flags(2): "
        OutByteHexPtr vpb_flags
        OutStr  ":"
        OutByteHexPtr vpb_fMisc

        OutBlanks 18
        OutStr  "vpdFAT_max_cluster: "
        OutWordHexPtr vpb_fsd.vpdFAT_max_cluster
        OutCrLf

        OutBlanks 10
        OutStr  "vpb_FSC: #"
        OutWordHexPtr vpb_FSC.Segmt16
        OutChar ":"
        OutWordHexPtr vpb_FSC.Offst16

        OutBlanks 16
        OutStr  "vpdFAT_FAT_size: "
        OutWordHexPtr vpb_fsd.vpdFAT_FAT_size
        OutCrLf

        OutBlanks 11
        OutStr  "vpi_ID: "
        OutDwordHexPtr vpb_fsi.vpi_ID

        OutBlanks 16
        OutStr  "vpdFAT_dir_sector: "
        OutDwordHexPtr vpb_fsd.vpdFAT_dir_sector
        OutCrLf

        OutBlanks 9
        OutStr  "vpi_pDPB: #"
        OutWordHexPtr vpb_fsi.vpi_pDPB.Segmt16
        OutChar ":"
        OutWordHexPtr vpb_fsi.vpi_pDPB.Offst16

        OutBlanks 19
        OutStr  "vpdFAT_media: "
        OutByteHexPtr vpb_fsd.vpdFAT_media
        OutCrLf

        OutBlanks 5
        OutStr  "vpi_cbSector: "
        OutWordHexPtr vpb_fsi.vpi_cbSector

        OutBlanks 21
        OutStr  "vpdFAT_next_free: "
        OutWordHexPtr vpb_fsd.vpdFAT_next_free
        OutCrLf

        OutBlanks 7
        OutStr  "vpi_totsec: "
        OutDwordHexPtr vpb_fsi.vpi_totsec

        OutBlanks 18
        OutStr  "vpdFAT_free_cnt: "
        OutWordHexPtr vpb_fsd.vpdFAT_free_cnt
        OutCrLf

        OutBlanks 7
        OutStr  "vpi_trksec: "
        OutWordHexPtr vpb_fsi.vpi_trksec

        OutBlanks 18
        OutStr  "vpdFAT_FATentrysize: "
        OutByteHexPtr vpb_fsd.vpdFAT_FATentrysize
        OutCrLf

        OutBlanks 8
        OutStr  "vpi_nhead: "
        OutWordHexPtr vpb_fsi.vpi_nhead

        OutBlanks 22
        OutStr  "vpdFAT_IDsector: "
        OutDwordHexPtr vpb_fsd.vpdFAT_IDsector
        OutCrLf

        OutBlanks 9
        OutStr  "vpi_pDCS: #"
        OutWordHexPtr vpb_fsi.vpi_pDCS.Segmt16
        OutChar ":"
        OutWordHexPtr vpb_fsi.vpi_pDCS.Offst16

        OutBlanks 18
        OutStr  "vpdFAT_access: "
        OutWordHexPtr vpb_fsd.vpdFAT_access
        OutCrLf

        OutBlanks 9
        OutStr  "vpi_pVCS: #"
        OutWordHexPtr vpb_fsi.vpi_pVCS.Segmt16
        OutChar ":"
        OutWordHexPtr vpb_fsi.vpi_pVCS.Offst16

        OutBlanks 17
        OutStr  "vpdFAT_accwait: "
        OutWordHexPtr vpb_fsd.vpdFAT_accwait
        OutCrLf

        OutBlanks 8
        OutStr  "vpi_drive: "
        OutByteHexPtr vpb_fsi.vpi_drive

        OutBlanks 26
        OutStr  "vpdFAT_pEASFT: #"
        OutWordHexPtr vpb_fsd.vpdFAT_pEASFT.Segmt16
        OutChar ":"
        OutWordHexPtr vpb_fsd.vpdFAT_pEASFT.Offst16
        OutCrLf

        OutBlanks 9
        OutStr  "vpi_unit: "
        OutByteHexPtr vpb_fsi.vpi_unit
        OutCrLf

        OutBlanks 9
        OutStr  "vpi_text: "
        OutStrPtr vpb_fsi.vpi_text, VPBTEXTLEN
        OutCrLf

        OutBlanks 9
        OutStr  "vpi_flags: "
        OutWordHexPtr vpb_fsi.vpi_flags
        OutCrLf
        EndOp

;*      Prints a DPB structure

DumpDPB         label   byte

        OutBlanks 8
        OutStr  "dpb_drive: "
        OutByteHexPtr dpb_drive
        OutCrLf

        OutBlanks 9
        OutStr  "dpb_unit: "
        OutByteHexPtr dpb_unit
        OutCrLf

        OutBlanks 2
        OutStr  "dpb_driver_addr: #"
        OutWordHexPtr dpb_driver_addr.Segmt16
        OutChar ":"
        OutWordHexPtr dpb_driver_addr.Offst16
        OutCrLf

        OutBlanks 5
        OutStr  "dpb_next_dpb: #"
        OutWordHexPtr dpb_next_dpb.Segmt16
        OutChar ":"
        OutWordHexPtr dpb_next_dpb.Offst16
        OutCrLf

        OutBlanks 5
        OutStr  "dpb_cbSector: "
        OutWordHexPtr dpb_cbSector
        OutCrLf

        OutBlanks 4
        OutStr  "dpb_first_FAT: "
        OutWordHexPtr dpb_first_FAT
        OutCrLf

        OutBlanks 2
        OutStr  "dpb_toggle_time: "
        OutDwordHexPtr dpb_toggle_time
        OutCrLf

        OutBlanks 9
        OutStr  "dpb_hVPB: "
        OutWordHexPtr dpb_hVPB
        OutCrLf

        OutBlanks 8
        OutStr  "dpb_media: "
        OutByteHexPtr dpb_media
        OutCrLf

        OutBlanks 8
        OutStr  "dpb_flags: "
        OutByteHexPtr dpb_flags
        OutCrLf

        OutBlanks 3
        OutStr  "dpb_drive_lock: "
        OutWordHexPtr dpb_drive_lock
        OutCrLf

        OutBlanks 4
        OutStr  "dpb_strategy2: #"
        OutWordHexPtr dpb_strategy2.Segmt16
        OutChar ":"
        OutWordHexPtr dpb_strategy2.Offst16
        OutCrLf
        EndOp

;*      Print BPB (bios parameter block)

DumpBPB         label   byte

        OutBlanks 3
        OutStr  "BytesPerSector: "
        OutWordHexPtr BPB_BytesPerSector
        OutCrLf

        OutStr  "SectorsPerCluster: "
        OutByteHexPtr BPB_SectorsPerCluster
        OutCrLf

        OutBlanks 2
        OutStr  "ReservedSectors: "
        OutWordHexPtr BPB_ReservedSectors
        OutCrLf

        OutBlanks 5
        OutStr  "NumberOfFATs: "
        OutByteHexPtr BPB_NumberOfFATs
        OutCrLf

        OutBlanks 6
        OutStr  "RootEntries: "
        OutWordHexPtr BPB_RootEntries
        OutCrLf

        OutBlanks 5
        OutStr  "TotalSectors: "
        OutWordHexPtr BPB_TotalSectors
        OutCrLf

        OutBlanks 2
        OutStr  "MediaDescriptor: "
        OutByteHexPtr BPB_MediaDescriptor
        OutCrLf

        OutBlanks 4
        OutStr  "SectorsPerFAT: "
        OutWordHexPtr BPB_SectorsPerFAT
        OutCrLf

        OutBlanks 2
        OutStr  "SectorsPerTrack: "
        OutWordHexPtr BPB_SectorsPerTrack
        OutCrLf

        OutBlanks 12
        OutStr  "Heads: "
        OutWordHexPtr BPB_Heads
        OutCrLf

        OutBlanks 4
        OutStr  "HiddenSectors: "
        OutDwordHexPtr BPB_HiddenSectors
        OutCrLf

        OutBlanks 2
        OutStr  "BigTotalSectors: "
        OutDwordHexPtr BPB_BigTotalSectors
        OutCrLf
        EndOp


;*      Dump Disk Trace (DDT)
DumpDT          label   byte                    ; Dump Disk Trace (DDT)

        CaseJump  trace_type, 0, 8
        CaseEntry trace_strat1_type,        PrintStrat1Pkt      ; entry to strat1.
        CaseEntry trace_strat2_good_type,   PrintStrat2GTPkt    ; strat2 - RLH is good.
        CaseEntry trace_strat2_rh_type,     PrintStrat2RHPkt    ; strat2 - starting RH processing.
        CaseEntry trace_rlh_err_out_p_type, PrintStrat2GTPkt    ; pbsubr - RLH callout with error.
        CaseEntry trace_rlh_callout_p_type, PrintStrat2GTPkt    ; pbsubr - RLH callout without error.
        CaseEntry trace_rlh_err_out_s_type, PrintStrat2GTPkt    ; strat2 - RLH callout with error.
        CaseEntry trace_rh_callout_p_type,  PrintStrat2GTPkt    ; pbsubr - RH callout.
        CaseEntry trace_rh_err_out_s_type,  PrintStrat2GTPkt    ; strat2 - RH callout with error.
        CaseEnd
        CallOp  DumpErr

        EndOp



PrintStrat1Pkt          label   byte
        OutByteHexPtr trace_type
        OutStr "= Strat1 packet    "
        OutByteHexPtr trace_unit
        OutBlanks 3
        OutWordHexPtr trace_w_1
        OutBlanks 7

        OutWordHexPtr trace_w_2
        OutBlanks 2

        OutWordHexPtr trace_w_3
        OutBlanks 18
        OutWordHexPtr trace_w_6
        OutBlanks 2
        OutWordHexPtr trace_w_7
        OutCrLf
        EndOp


PrintStrat2GTPkt        label   byte
        OutByteHexPtr trace_type
        OutStr "=good RLH (STRAT2) "
        OutByteHexPtr trace_unit
        OutBlanks 1
        OutWordHexPtr trace_w_1
        OutBlanks 7

        OutWordHexPtr trace_w_2
        OutBlanks 1

        OutWordHexPtr trace_w_3
        OutBlanks 1
        OutWordHexPtr trace_w_4
        OutStr  ":"
        OutWordHexPtr trace_w_5
        OutBlanks 13
        OutWordHexPtr trace_w_6
        OutStr  ":"
        OutWordHexPtr trace_w_7
        OutCrLf
        EndOp


PrintStrat2RHPkt        label   byte
        OutByteHexPtr trace_type
        OutStr "=extract RH        "
        OutByteHexPtr trace_unit
        OutBlanks 7
        OutWordHexPtr trace_w_1
        OutBlanks 1
        OutWordHexPtr trace_w_2
        OutBlanks 1

        OutWordHexPtr trace_w_3
        OutBlanks 1
        OutWordHexPtr trace_w_4
        OutStr  ":"
        OutWordHexPtr trace_w_5
        OutBlanks 13

        OutWordHexPtr trace_w_6
        OutStr  ":"
        OutWordHexPtr trace_w_7
        OutCrLf
        EndOp


;*      Print KSEM (internal kernel semaphore)

DumpKSEM        label   byte

        OutStr  "Signature     : "
ifdef   MISCSTRICT
        OutStrPtr ks_Signature, 4
else
        OutStr  "KSEM"
endif

        JumpIfBitF ks_bType,0,2,0,ksem10; If not Share or Mutex Sem
        OutBlanks 24
        OutStr  "Nest: "
        OutWordHexPtr ks_cusNest

ksem10  label   byte
        OutCrLf

        OutStr  "Type          : "
        JumpIfBitSet ks_bType,1,ksem30  ; Share Sem
        JumpIfBitSet ks_bType,0,ksem20  ; Mutex Sem

        OutStr  "EVENT"
        JumpIfBitClr ks_bType,2,ksem40  ; Jump

ksem20  label   byte
        OutStr  "MUTEX"
        JumpIfBitClr ks_bType,2,ksem40  ; Jump

ksem30  label   byte
        OutStr  "SHARE"

ksem40  label   byte
        JumpIfBitClr ks_bType,1,ksem50  ; If not ShareSem
        OutBlanks 20
        OutStr  "Readers: "
        OutWordHexPtr ks_cusReaders

ksem50  label   byte
        OutCrLf

        OutStr  "Flags         : "
        OutByteHexPtr ks_bFlags

        JumpIfBitClr ks_bType,1,ksem60  ; If not ShareSem
        OutBlanks 16
        OutStr  "PendingReaders: "
        OutWordHexPtr ks_cusPendingReaders

ksem60  label   byte
        OutCrLf

        OutStr  "Owner         : "
        OutWordHexPtr ks_Owner

        OutBlanks 14
        OutStr  "PendingWriters: "
        OutWordHexPtr ks_cusPendingWriters

        OutCrLf
        EndOp


;*      Print MFT (Master File Table)

DumpMFT         label   byte

        OutBlanks 5
        OutStr  "mft_ksem:"
        OutCrLf
        CallOp  DumpKSEM

        OutBlanks 5
        OutStr  "mft_lptr: "
        OutWordHexPtr mft_lptr

        OutBlanks 20
        OutStr  "mft_sptr: "
        OutWordHexPtr mft_sptr.Segmt16
        OutChar ":"
        OutWordHexPtr mft_sptr.Offst16

        OutCrLf

        OutBlanks 4
        OutStr  "mft_pCMap: "
        OutDwordHexPtr mft_pCMap

        OutBlanks 16
        OutStr  "mft_serl: "
        OutWordHexPtr mft_serl

ifdef FSSTRICT
        OutBlanks 7
        OutStr  "mft_signature: "
        OutWordHexPtr mft_signature
endif

        OutCrLf

        OutStr  " mft_CMapKSem:"
        OutCrLf
;       CallOp  DumpKSEM, mft_CMapKSem  ; BUGBUG

        OutBlanks 5
        OutStr  "mft_hvpb: "
        OutWordHexPtr mft_hvpb

        OutBlanks 17
        OutStr  "mft_opflags: "
        OutWordHexPtr mft_opflags

        OutBlanks 11
        OutStr  "mft_flags: "
        OutWordHexPtr mft_flags

        OutCrLf

        OutBlanks 5
        OutStr  "mft_name: "
        OutStrPtr mft_name, DBG_MAX_PATH_LEN
        OutCrLf
        EndOp


;*      Print BUF (Disk buffer)

DumpBUF         label   byte

        OutBlanks 3
        OutStr  "buf_next: "
        OutWordHexPtr buf_next

        OutBlanks 12
        OutStr  "buf_prev: "
        OutWordHexPtr buf_prev

        OutBlanks 11
        OutStr  "buf_freeLink: "
        OutWordHexPtr buf_freeLink

        OutCrLf

        OutBlanks 2
        OutStr  "buf_flags: "
        OutByteHexPtr buf_flags

        OutBlanks 14
        OutStr  "buf_hVPB: "
        OutWordHexPtr buf_hVPB

        OutBlanks 11
        OutStr  "buf_sector: "
        OutDwordHexPtr buf_sector

        OutCrLf

        OutBlanks 4
        OutStr  "buf_tid: "
        OutByteHexPtr buf_tid

        OutBlanks 14
        OutStr  "buf_wrtcnt: "
        OutByteHexPtr buf_wrtcnt

        OutBlanks 11
        OutStr  "buf_wrtcntinc: "
        OutWordHexPtr buf_wrtcntinc

        OutCrLf

        OutBlanks 3
        OutStr  "buf_fill: "
        OutWordHexPtr buf_fill

        OutCrLf

        EndOp

;*      Print CDS (Current Directory Structure)

DumpCDS         label   byte

        OutBlanks 3
        OutStr  "cd_handle: "
        OutWordHexPtr cd_handle

        OutBlanks 26
        OutStr  "cddFAT_id: "
        OutWordHexPtr cd_fsd.cddFAT_id
        OutCrLf

        OutBlanks 3
        OutStr  "cd_refcnt: "
        OutWordHexPtr cd_refcnt
        OutCrLf

        OutBlanks 4
        OutStr  "cd_flags: "
        OutByteHexPtr cd_flags
        OutCrLf

        OutBlanks 3
        OutStr  "cd_devptr: "
        OutWordHexPtr cd_devptr.Segmt16
        OutStr  ":"
        OutWordHexPtr cd_devptr.Offst16
        OutCrLf

        OutBlanks 1
        OutStr  "cd_OwnerFSC: "
        OutWordHexPtr cd_OwnerFSC.Offst16
        OutCrLf

        OutCrLf

        OutBlanks 4
        OutStr  "cdi_hVPB: "
        OutWordHexPtr cd_fsi.cdi_hVPB
        OutCrLf

        OutBlanks 5
        OutStr  "cdi_end: "
        OutWordHexPtr cd_fsi.cdi_end
        OutCrLf

        OutBlanks 3
        OutStr  "cdi_flags: "
        OutByteHexPtr cd_fsi.cdi_flags
        OutCrLf

        OutBlanks 4
        OutStr  "cdi_text: "
        OutStrPtr cd_fsi.cdi_text, 255          ; handles only 1-byte length
        OutCrLf

        EndOp

;*      Print Device Driver Headers

DumpDEV         label   byte

        OutBlanks 10
        OutStr  "DevNext: "
        OutWordHexPtr SDevNext.Segmt16
        OutChar ":"
        OutWordHexPtr SDevNext.Offst16
        OutCrLf

        OutBlanks 10
        OutStr  "DevAttr: "
        OutWordHexPtr SDevAtt
        OutCrLf

        OutBlanks 9
        OutStr  "DevStrat: "
        OutWordHexPtr SDevStrat
        OutCrLf

        OutBlanks 11
        OutStr  "DevInt: "
        OutWordHexPtr SDevInt
        OutCrLf

        JumpIfBitSet SDevAtt,15,PrintCharHdr

        OutBlanks 9
        OutStr  "NumUnits: "
        OutByteHexPtr SDevName
        OutCrLf
        JumpOp  PrintRestHdr

PrintCharHdr    label   byte

        OutBlanks 10
        OutStr  "DevName: "
        OutStrPtr SDevName, 8
        OutCrLf

PrintRestHdr    label   byte

        OutBlanks 8
        OutStr  "DevProtCS: "
        OutWordHexPtr SDevProtCS
        OutCrLf

        OutBlanks 8
        OutStr  "DevProtDS: "
        OutWordHexPtr SDevProtDS
        OutCrLf

        OutBlanks 8
        OutStr  "DevRealCS: "
        OutWordHexPtr SDevRealCS
        OutCrLf

        OutBlanks 8
        OutStr  "DevRealDS: "
        OutWordHexPtr SDevRealDS
        OutCrLf
        EndOp


;*      Dump device driver request packet

DumpREQ label   byte

        OutBlanks 11
        OutStr  "PktLen: "
        OutByteHexPtr PktLen
        OutCrLf

        OutBlanks 10
        OutStr  "PktUnit: "
        OutByteHexPtr PktUnit
        OutCrLf

        OutBlanks 11
        OutStr  "PktCmd: "
        OutByteHexPtr PktCmd
        OutCrLf

        OutBlanks 8
        OutStr  "PktStatus: "
        OutWordHexPtr PktStatus
        OutCrLf

        OutBlanks 7
        OutStr  "PktDOSLink: "
        OutDwordHexPtr PktDOSLink
        OutCrLf

        OutBlanks 7
        OutStr  "PktDevLink: "
        OutDwordHexPtr PktDevLink
        OutCrLf

        CaseJump  PktCmd, 0, 8
        CaseEntry CMDInit, PrintCMDInit
        CaseEntry CMDMedChk, PrintCMDMedChk
        CaseEntry CMDBldBPB, PrintCMDBldBPB
        CaseEntry CMDIOCTLR, PrintCMDIO
        CaseEntry CMDINPUT, PrintCMDIO
        CaseEntry CMDOUTPUT, PrintCMDIO
        CaseEntry CMDOUTPUTV, PrintCMDIO
        CaseEntry CMDInputBypass, PrintCMDIO
        CaseEntry CMDOutputBypass, PrintCMDIO
        CaseEntry CMDOutputBypassV, PrintCMDIO
        CaseEntry CMDIOCTLW, PrintCMDIO
        CaseEntry CMDGenIOCTL, PrintCMDGenIOCTL
        CaseEntry CMDGetLogMap, PrintCMDLogMap
        CaseEntry CMDSetLogMap, PrintCMDLogMap
        CaseEnd
        EndOp

PrintCMDInit    label   byte

        OutBlanks 8
        OutStr  "InitcUnit: "
        OutByteHexPtr InitcUnit
        OutCrLf

        OutBlanks 7
        OutStr  "InitDevHlp: "
        OutWordHexPtr (InitDevHlp).Segmt16
        OutChar ":"
        OutWordHexPtr (InitDevHlp).Offst16
        OutCrLf

        OutBlanks 8
        OutStr  "InitParms: "
        OutWordHexPtr (InitParms).Segmt16
        OutChar ":"
        OutWordHexPtr (InitParms).Offst16
        OutCrLf

        OutBlanks 10
        OutStr  "InitDrv: "
        OutByteHexPtr Initdrv
        OutCrLf

        OutBlanks 5
        OutStr  "InitSysiData: "
        OutWordHexPtr InitSysiData
        OutCrLf
        EndOp

PrintCMDMedChk  label   byte

        OutBlanks 6
        OutStr  "MedChkMedia: "
        OutByteHexPtr MedChkmedia
        OutCrLf

        OutBlanks 7
        OutStr  "MedChkFlag: "
        OutByteHexPtr MedChkflag
        OutCrLf

        OutBlanks 7
        OutStr  "MedChkpVID: "
        OutDwordHexPtr MedChkpVID
        OutCrLf
        EndOp

PrintCMDBldBPB  label   byte

        OutBlanks 6
        OutStr  "BldBPBmedia: "
        OutByteHexPtr BldBPBmedia
        OutCrLf

        OutBlanks 5
        OutStr  "BldBPBbuffer: "
        OutWordHexPtr (BldBPBbuffer).Segmt16
        OutChar ":"
        OutWordHexPtr (BldBPBbuffer).Offst16
        OutCrLf

        OutBlanks 7
        OutStr  "BldBPBpBPB: "
        OutWordHexPtr (BldBPBpBPB).Segmt16
        OutChar ":"
        OutWordHexPtr (BldBPBpBPB).Offst16
        OutCrLf
        EndOp

PrintCMDIO      label   byte

        OutBlanks 10
        OutStr  "IOmedia: "
        OutByteHexPtr IOmedia
        OutCrLf

        OutBlanks 10
        OutStr  "IOpData: "
        OutDwordHexPtr IOpData
        OutCrLf

        OutBlanks 10
        OutStr  "IOcount: "
        OutWordHexPtr IOcount
        OutCrLf

        OutBlanks 10
        OutStr  "IOstart: "
        OutDwordHexPtr IOstart
        OutCrLf
        EndOp

PrintCMDGenIOCTL        label   byte

        OutBlanks 6
        OutStr  "GIOCategory: "
        OutByteHexPtr GIOCategory
        OutCrLf

        OutBlanks 6
        OutStr  "GIOFunction: "
        OutByteHexPtr GIOFunction
        OutCrLf

        OutBlanks 6
        OutStr  "GIOParaPack: "
        OutWordHexPtr (GIOParaPack).Segmt16
        OutChar ":"
        OutWordHexPtr (GIOParaPack).Offst16
        OutCrLf

        OutBlanks 6
        OutStr  "GIODataPack: "
        OutWordHexPtr (GIODataPack).Segmt16
        OutChar ":"
        OutWordHexPtr (GIODataPack).Offst16
        OutCrLf
        EndOp

PrintCMDLogMap  label   byte

        OutBlanks 4
        OutStr  "Logical_Drive: "
        OutByteHexPtr Logical_Drive
        OutCrLf
        EndOp

DumpSEM label   byte
        JumpIfBitSet    0, 3H, ds2
        JumpIfBitSet    0, 4H, ds1
        JumpIfBitSet    0, 5H, ds3
        OutBlanks 6
        OutStr  "Invalid Semaphore Type"
        OutCrLf
        JumpOp          dsx

ds1     label   byte
        OutBlanks 8
        OutStr  "Type: "
        OutMsgIfBitSet 0, 0, Shmsg
        OutMsgIfBitClr 0, 0, Prmsg
        OutStr  "Event"
        OutCrLf
        OutBlanks 7
        OutStr  "Flags: "
        OutMsgIfBitSet 0, 6, Postmsg
        OutMsgIfBitClr 0, 6, Resetmsg
        OutMsgIfBitSet 0, 9, DHOmsg
        OutCrLf
        OutBlanks 7
        OutStr  "pMuxQ: "
        OutDwordHexPtr  2
        OutCrLf
        OutBlanks 2
        OutStr  "Post Count: "
        OutWordHexPtr   6
        OutCrLf
        JumpIfBitSet    0, 0, dse1
        OutBlanks 2
        OutStr  "Open Count: "
        OutWordHexPtr   8
        OutCrLf
        OutBlanks 1
        OutStr  "Create Addr: "
        OutDwordHexPtr  0AH
        OutCrLf
        JumpOp  dsx
dse1    label   byte
        OutBlanks 6
        OutStr  "pOpenQ: "
        OutDwordHexPtr  8
        OutCrLf
        OutBlanks 7
        OutStr  "pName: "
        JumpIfDwordNull 0CH, dse2
        OutDwordHexPtr  0CH
        OutCrLf
        OutBlanks 1
        OutStr  "Create Addr: "
        OutDwordHexPtr  10H
        OutCrLf
        JumpOp  dsx
dse2    label   byte
        OutStr  "NULL (anonymous)"
        OutCrLf
        OutBlanks 1
        OutStr  "Create Addr: "
        OutDwordHexPtr  10H
        OutCrLf
        JumpOp  dsx

ds2     label   byte
        OutBlanks 8
        OutStr  "Type: "
        OutMsgIfBitSet 0, 0, Shmsg
        OutMsgIfBitClr 0, 0, Prmsg
        OutStr  "Mutex"
        OutCrLf
        OutBlanks 7
        OutStr  "Flags: "
        OutMsgIfBitSet 0, 7, Owndmsg
        OutCrLf
        OutBlanks 7
        OutStr  "pMuxQ: "
        OutDwordHexPtr  2
        OutCrLf
        OutBlanks 2
        OutStr  "Request Ct: "
        OutWordHexPtr   6
        OutCrLf
        OutBlanks 7
        OutStr  "Owner: "
        OutWordHexPtr   8
        OutCrLf
        OutStr  "Requester Ct: "
        OutWordHexPtr   0AH
        OutCrLf
        JumpIfBitSet    0, 0, dsm1
        OutBlanks 2
        OutStr  "Open Count: "
        OutWordHexPtr   0CH
        OutCrLf
        OutBlanks 1
        OutStr  "Create Addr: "
        OutDwordHexPtr  0EH
        OutCrLf
        JumpOp  dsx
dsm1    label   byte
        OutBlanks 6
        OutStr  "pOpenQ: "
        OutDwordHexPtr  0CH
        OutCrLf
        OutBlanks 7
        OutStr  "pName: "
        JumpIfDwordNull 10H, dsm2
        OutDwordHexPtr  10H
        OutCrLf
dsm1a   label byte
        OutBlanks 1
        OutStr  "Create Addr: "
        OutDwordHexPtr  14H
        OutCrLf
        JumpOp  dsx
dsm2    label   byte
        OutStr  "NULL (anonymous)"
        OutCrLf
        JumpOp  dsm1a

ds3     label   byte
        OutBlanks 8
        OutStr  "Type: "
        OutMsgIfBitSet 0, 0, Shmsg
        OutMsgIfBitClr 0, 0, Prmsg
        OutStr  "MuxWait"
        OutCrLf
        OutBlanks 7
        OutStr  "Flags: "
        OutMsgIfBitSet 0, 8, MtxMuxmsg
        OutMsgIfBitClr 0, 8, EvtMuxmsg
        OutCrLf
        OutBlanks 4
        OutStr  "SR Count: "
        OutWordHexPtr   2
        OutCrLf
        OutBlanks 2
        OutStr  "SR Pointer: "
        OutDwordHexPtr  4
        OutCrLf
        OutBlanks 2
        OutStr  "Wait Count: "
        OutWordHexPtr   8
        OutCrLf
        JumpIfBitSet    0, 0, dsmw1
        OutBlanks 2
        OutStr  "Open Count: "
        OutWordHexPtr   0AH
        OutCrLf
        OutBlanks 1
        OutStr  "Create Addr: "
        OutDwordHexPtr  0CH
        OutCrLf
        JumpOp  dsx
dsmw1   label   byte
        OutBlanks 6
        OutStr  "pOpenQ: "
        OutDwordHexPtr  0AH
        OutCrLf
        OutBlanks 7
        OutStr  "pName: "
        JumpIfDwordNull 0EH, dsmw2
        OutDwordHexPtr  0EH
        OutCrLf
        OutBlanks 1
        OutStr  "Create Addr: "
        OutDwordHexPtr  12H
        OutCrLf
        JumpOp  dsx
dsmw2   label   byte
        OutStr  "NULL (anonymous)"
        OutBlanks 1
        OutStr  "Create Addr: "
        OutDwordHexPtr  12H
        OutCrLf
        OutCrLf

dsx     label   byte
        OutCrLf
        EndOp

DumpOpQ label   byte
        OutCrLf
        OutBlanks 2
        OutStr  "PID   Open Count"
        OutCrLf
        OutBlanks 2
        OutStr  "----------------"
        OutCrLf
doq2    label   byte
        OutBlanks 2
        OutWordHexPtr   0
        OutBlanks 5
        OutWordHexPtr   2
        OutCrLf
        JumpIfDwordNull 4, doq1
        LoadCache 4
        JumpOp  doq2
doq1    label   byte
        OutCrLf
        EndOp

DumpMQ  label   byte
        OutCrLf
        OutBlanks 2
        OutStr  "pMux"
        OutCrLf
        OutBlanks 2
        OutStr  "--------"
        OutCrLf
dmq2    label   byte
        OutBlanks 2
        OutDwordHexPtr  0
        OutCrLf
        JumpIfDwordNull 4, dmq1
        LoadCache 4
        JumpOp  dmq2
dmq1    label   byte
        OutCrLf
        EndOp

DumpErr         label   byte

        OutStr  "Invalid structure name"
        OutCrLf
        EndOp


Static  Rmsg,       STRING, "r"
Static  Wmsg,       STRING, "w"
Static  Xmsg,       STRING, "x"
Static  Minusmsg,   STRING, "-"
Static  Aliasmsg,   STRING, " alias"
Static  Bigmsg,     STRING, " big"
Static  Codemsg,    STRING, " code"
Static  Confmsg,    STRING, " conf"
Static  Datamsg,    STRING, " data"
Static  Discmsg,    STRING, " disc"
Static  Eomsg,      STRING, " EO"
Static  Romsg,      STRING, " RO"
Static  Invmsg,     STRING, " inv"
Static  Itermsg,    STRING, " iter"
Static  Ioplmsg,    STRING, " iopl"
Static  Movmsg,     STRING, " move"
Static  Premsg,     STRING, " prel"
Static  Relmsg,     STRING, " rel"
Static  Rsrcmsg,    STRING, " rsrc"
Static  Shrmsg,     STRING, " shr"
Static  Zfilmsg,    STRING, " zfill"
Static  Shmsg,      STRING, "Shared "
Static  Prmsg,      STRING, "Private "
Static  Postmsg,    STRING, "Posted "
Static  Resetmsg,   STRING, "Reset "
Static  Owndmsg,    STRING, "Owner_Died "
Static  MtxMuxmsg   STRING, "Mutex_Mux "
Static  EvtMuxmsg   STRING, "Event_MUX "
Static  DHOmsg      STRING, "DH_Open "

Static  BadNamemsg, STRING, "???"

ShiftDef macro  name, nameshift, count
    nameshift equ count
    .errnz ((1 shl nameshift) - name)
endm

SEGNOIOPL       equ     (RING_3 - RING_2)       ; low dpl bit

ShiftDef  DATA_TYPE,  DATA_TYPESHIFT,  0
ShiftDef  ITERATED,   ITERATEDSHIFT,   3
ShiftDef  MOVABLE,    MOVABLESHIFT,    4
ShiftDef  SHARED,     SHAREDSHIFT,     5
ShiftDef  PRELOAD,    PRELOADSHIFT,    6
ShiftDef  ERONLY,     ERONLYSHIFT,     7
ShiftDef  RELOCINFO,  RELOCINFOSHIFT,  8
ShiftDef  CONFORMING, CONFORMINGSHIFT, 9
ShiftDef  SEGNOIOPL,  SEGNOIOPLSHIFT,  10
ShiftDef  DISCARD,    DISCARDSHIFT,    12


ShiftDef  OBJREAD,    OBJREADSHIFT,    0
ShiftDef  OBJWRITE,   OBJWRITESHIFT,   1
ShiftDef  OBJEXEC,    OBJEXECSHIFT,    2
ShiftDef  OBJRSRC,    OBJRSRCSHIFT,    3
ShiftDef  OBJDISCARD, OBJDISCARDSHIFT, 4
ShiftDef  OBJSHARED,  OBJSHAREDSHIFT,  5
ShiftDef  OBJPRELOAD, OBJPRELOADSHIFT, 6
ShiftDef  OBJINVALID, OBJINVALIDSHIFT, 7
ShiftDef  OBJZEROFIL, OBJZEROFILSHIFT, 8

ShiftDef  OBJALIAS16, OBJALIAS16SHIFT, 12
ShiftDef  OBJBIGDEF,  OBJBIGDEFSHIFT,  13
ShiftDef  OBJCONFORM, OBJCONFORMSHIFT, 14
ShiftDef  OBJIOPL,    OBJIOPLSHIFT,    15

;*      Prints an STE

PrintSTE label  byte
        OutBlank
        OutWordHexPtr   ste_offset
        OutBlank
        OutWordHexPtr   ste_size
        OutBlank
        OutWordHexPtr   ste_minsiz
        OutBlank
        OutWordHexPtr   ste_seghdl
        OutBlank
        OutWordHexPtr   ste_selector
        OutBlank
        OutWordHexPtr   ste_flags
        OutMsgIfBitSet  ste_flags, DATA_TYPESHIFT,  Datamsg     ; Data
        OutMsgIfBitClr  ste_flags, DATA_TYPESHIFT,  Codemsg     ; Code
        OutMsgIfBitSet  ste_flags, ITERATEDSHIFT,   Itermsg
        OutMsgIfBitSet  ste_flags, MOVABLESHIFT,    Movmsg
        OutMsgIfBitSet  ste_flags, SHAREDSHIFT,     Shrmsg
        OutMsgIfBitSet  ste_flags, PRELOADSHIFT,    Premsg
        JumpIfBitClr    ste_flags, ERONLYSHIFT, pst50
        OutMsgIfBitSet  ste_flags, DATA_TYPESHIFT,  Romsg       ; Data
        OutMsgIfBitClr  ste_flags, DATA_TYPESHIFT,  Eomsg       ; Code
pst50 label byte
        OutMsgIfBitSet  ste_flags, RELOCINFOSHIFT,  Relmsg
        OutMsgIfBitSet  ste_flags, CONFORMINGSHIFT, Confmsg
        OutMsgIfBitClr  ste_flags, SEGNOIOPLSHIFT,  Ioplmsg
        OutMsgIfBitSet  ste_flags, DISCARDSHIFT,    Discmsg
        EndOp


;*      Prints an OTE

PrintOTE label  byte
        OutBlank
        OutDwordHexPtr  ote_size
        OutBlank
        OutDwordHexPtr  ote_base
        OutBlank
        OutDwordHexPtr  ote_flags
        OutBlank
        OutDwordHexPtr  ote_pagemap
        OutBlank
        OutDwordHexPtr  ote_mapsize
        OutBlank
        EndOp

PrintOTESel label       byte
        OutWordHexPtr   ote_handle                      ; handle
        OutBlank
        OutWordHexPtr   ote_selector                    ; sel
        EndOp

PrintOTEVdd label       byte
        OutDwordHexPtr  ote_vddaddr                     ; fixup linear address
        OutBlank
        EndOp

PrintOTEFlags label     byte
        OutBlank
        OutMsgIfBitSet  ote_flags, OBJREADSHIFT,    Rmsg
        OutMsgIfBitClr  ote_flags, OBJREADSHIFT,    Minusmsg
        OutMsgIfBitSet  ote_flags, OBJWRITESHIFT,   Wmsg
        OutMsgIfBitClr  ote_flags, OBJWRITESHIFT,   Minusmsg
        OutMsgIfBitSet  ote_flags, OBJEXECSHIFT,    Xmsg
        OutMsgIfBitClr  ote_flags, OBJEXECSHIFT,    Minusmsg
        OutMsgIfBitSet  ote_flags, OBJRSRCSHIFT,    Rsrcmsg
        OutMsgIfBitSet  ote_flags, OBJDISCARDSHIFT, Discmsg
        OutMsgIfBitSet  ote_flags, OBJSHAREDSHIFT,  Shrmsg
        OutMsgIfBitSet  ote_flags, OBJPRELOADSHIFT, Premsg
        OutMsgIfBitSet  ote_flags, OBJINVALIDSHIFT, Invmsg
        OutMsgIfBitSet  ote_flags, OBJZEROFILSHIFT, Zfilmsg
        OutMsgIfBitSet  ote_flags, OBJALIAS16SHIFT, Aliasmsg
        OutMsgIfBitSet  ote_flags, OBJBIGDEFSHIFT,  Bigmsg
        OutMsgIfBitSet  ote_flags, OBJCONFORMSHIFT, Confmsg
        OutMsgIfBitSet  ote_flags, OBJIOPLSHIFT,    Ioplmsg
        EndOp

DataSegmentEnd

CodeSegmentStart

Extern  perr, NEAR
Extern  DumpMem, NEAR
Extern  DumpTraceBuffer, NEAR
Extern  DumpUserStack, NEAR
Extern  DumpCDA, NEAR
Extern  MakePresentCmd, NEAR
Extern  SetBaudCmd, NEAR
Extern  ProcessStatus, NEAR
Extern  ChangeCurrTask, NEAR
Extern  OEMInitCom, NEAR
Extern  OEMOutputChar, NEAR
Extern  OEMBreakChk, NEAR
Extern  OEMScanChar, NEAR
Extern  OEMEnableNMI, NEAR
Extern  OEMEnableA20, NEAR
Extern  OEMRestoreA20, NEAR
Extern  OEMBeep, NEAR
Extern  RebootCmd, NEAR
Extern  SysdumpCmd, NEAR
Extern  DebGetCurrTask, NEAR
Extern  DebGetDescInfo, NEAR
Extern  DebEntryRoutine, NEAR
Extern  DebExitRoutine, NEAR
Extern  DebGetPDE, NEAR
Extern  DebGetFrame, NEAR

CallOutTable    label   word
        .errnz  DEB_CALLOUT_INIT_COM-0
        dw      codeOFFSET OEMInitCom

        .errnz  DEB_CALLOUT_OUTPUT_CHAR-1
        dw      codeOFFSET OEMOutputChar

        .errnz  DEB_CALLOUT_SCAN_CHAR-2
        dw      codeOFFSET OEMScanChar

        .errnz  DEB_CALLOUT_ENABLE_NMI-3
        dw      codeOFFSET OEMEnableNMI

        .errnz  DEB_CALLOUT_ENABLE_A20-4
        dw      codeOFFSET OEMEnableA20

        .errnz  DEB_CALLOUT_RESTORE_A20-5
        dw      codeOFFSET OEMRestoreA20

        .errnz  DEB_CALLOUT_EXTCMD-6
        dw      codeOFFSET ExtCmdRoutine

        .errnz  DEB_CALLOUT_DEBENTRY-7
        dw      codeOFFSET DebEntryRoutine

        .errnz  DEB_CALLOUT_DEBEXIT-8
        dw      codeOFFSET DebExitRoutine

        .errnz  DEB_CALLOUT_DEBINIT-9
        dw      codeOFFSET DebInitRoutine

        .errnz  DEB_CALLOUT_DEBEND-10
        dw      codeOFFSET DebEndRoutine

        .errnz  DEB_CALLOUT_GETCURRTASK-11
        dw      codeOFFSET DebGetCurrTask

        .errnz  DEB_CALLOUT_GETDESCINFO-12
        dw      codeOFFSET DebGetDescInfo

        .errnz  DEB_CALLOUT_BREAK-13
        dw      codeOFFSET OEMBreakChk

        .errnz  DEB_CALLOUT_BEEP-14
        dw      codeOFFSET OEMBeep

        .errnz  DEB_CALLOUT_DRALLOC-15
        dw      codeOFFSET DebDRAlloc

        .errnz  DEB_CALLOUT_DRFREE-16
        dw      codeOFFSET DebDRFree

        .errnz  DEB_CALLOUT_GETPDE-17
        dw      codeOFFSET DebGetPDE

        .errnz  DEB_CALLOUT_GETFRAME-18
        dw      codeOFFSET DebGetFrame

        .errnz  DEB_CALLOUT_MAX + 1 - (($ - CallOutTable)/2)


;***    RCheck
;
;       This routine calls RebootCmd, which will reboot the machine if
;       the user typed .REBOOT.  Otherwise, it will return and we assume
;       that the user typed some variation of the .R command, so we call
;       RegisterSlot.
;
;       ENTRY:  NONE
;
;       EXIT:   NONE
;
;       USES:   ALL
;
        assumeDATA <ds, es, ss>

DefProc RCheck, NEAR, LOCAL
        push    pTXT                    ;save; RebootCmd alters
        Pcall   RebootCmd
        pop     pTXT                    ;we returned; must be .R command
        Pcall   RegisterSlot
EndProc

;RJM 154740
;***    SCheck
;
;       This routine calls SysdumpCmd, which will dump the machine if
;       the user typed .SYSDUMP.  Otherwise, it will return and we assume
;       that the user typed some variation of the .S command, so we call
;       ChageCurrTask.
;
;       ENTRY:  NONE
;
;       EXIT:   NONE
;
;       USES:   ALL
;
        assumeDATA <ds, es, ss>

DefProc SCheck, NEAR, LOCAL
        push    pTXT                    ;save; SysdumpCmd alters
        Pcall   SysdumpCmd
        pop     pTXT                    ;we returned; must be .S command
        Pcall   ChangeCurrTask
EndProc
;RJM 154740


;***    DebCallOutRoutine
;
;       ENTRY:  (FuncCode)
;
;       EXIT:   Depends on function code
;
;       USES:   Depends on function code
;
        ASSUME  DS:NOTHING, ES:NOTHING, SS:NOTHING

DefProc DebCallOutRoutine,FAR,PUBLIC

ArgVar  FuncCode,WORD

BeginProc
        push    bx
        mov     bx,FuncCode
        shl     bx,1
        mov     bx,CallOutTable[bx]
        mov     FuncCode,bx
        pop     bx
        call    FuncCode
EndProc


;***    DebInitRoutine
;
;       Called when the debugger is initialized via Debug_Entry.
;
;       ENTRY:  NONE
;
;       EXIT:   NONE
;
;       USES:   Flags
;
        assumeDATA <ss,ds,es>

DefProc DebInitRoutine,NEAR,LOCAL
EndProc


;***    DebEndRoutine
;
;       Called when the debugger is terminated via Debug_Exit.
;
;       ENTRY:  NONE
;
;       EXIT:   NONE
;
;       USES:   Flags
;
        assumeDATA <ss,ds,es>

DefProc DebEndRoutine,NEAR,LOCAL
EndProc


;***    ExtCmdRoutine
;
;       This routine executes the external debugger commands.
;
;       ENTRY:  NONE
;
;       EXIT:   NONE
;
;       USES:   ALL
;
        assumeDATA <ss,ds,es>

DefProc ExtCmdRoutine, NEAR, PUBLIC
        Pcall   GetChrI                         ; (AL) = command letter
        jnz     ecr1
        jmp     perr

ecr1:   mov     si,dataOFFSET ExtCmdTable       ; (SI) = address of cmd table
        Pcall   ExecSubr                        ; execute command
EndProc


;***    Help
;
;       This prints the help menu.
;
;       ENTRY:  NONE
;
;       EXIT:   NONE
;
;       USES:   ALL
;
        assumeDATA <ds, es, ss>

DefProc Help, NEAR, LOCAL
        mov     dx,dataOFFSET HelpMsg
        Pcall   rprbuf
EndProc


;***    DumpData
;
;       The routine prints a number of DOS data structures like
;       DPB's, VPB's, etc.
;
;       ENTRY:  NONE
;
;       EXIT:   NONE
;
;       USES:   ALL
;
        assumeDATA <ds, es, ss>

DefProc DumpData, NEAR, LOCAL

LocVar  TmpAddr, <size AddrS>

BeginProc
        push    pTXT
        Pcall   ScanP           ; skip leading blanks
        jz      dda3
        mov     si,pTXT

dda1:   lodsb                   ; skip up to the next blank or comma
        or      al,al
        je      dda2
        cmp     al,','
        je      dda2
        cmp     al,' '
        jne     dda1
dda2:   mov     pTXT,si         ; point command line to address start

        lea     bx,TmpAddr
        Pcall   GetDSaddr
        Pcall   EvalAddr, <bx,bx>
        Pcall   CheckAddr, <bx>

        pop     si
        xchg    si,pTXT         ; point command line back to structure name
        push    si

        mov     dx,MEMCACHESIZE
        Pcall   GetCache        ; (DI) = cache buffer
        jc      ddae

        mov     si,dataOFFSET DumpDataCmds
        Pcall   OpInterpret
dda3:   pop     pTXT            ; point command line to end of command
EndProc
ddae:   Jump    ErrBreak





;***    DumpLoader
;
;       This routine dumps MTEs.
;
;       ENTRY   NONE
;       EXIT    NONE
;       USES    ALL

DefProc DumpLoader, NEAR, LOCAL
    assumeDATA <ds, es, ss>
        Pcall   PeekChr                 ; (AL) = character
        jz      short dmt00
        cmp     al,"M"
        jz      short dmt10
dmt00:  putstr  <"Invalid option">
        Jump    CmdBreak

dmt10:  Pcall   SkipB                   ; eat the character in the input buffer
        call    DumpMTE
dmtx:
EndProc


.386p
;***    DumpMTE
;
;       The routine dumps all MTEs.
;
;       ENTRY   NONE
;       EXIT    NONE
;       USES    ALL

DefProc DumpMTE, NEAR, LOCAL
    assumeDATA <ds, es, ss>
    LocVar dle_cline, WORD
    LocVar dle_next, DWORD
    LocVar dle_pmte, DWORD
    LocVar dle_size, DWORD
    LocVar dle_cote, DWORD
    LocVar dle_pote, DWORD
    LocVar dle_hobmte, DWORD
    LocVar dle_cprint, WORD
    LocVar dle_cnonrsrc, DWORD
    LocVar dle_mflags, DWORD
    LocVar dle_fmodmatch, BYTE
    LocVar dle_fobjdump, BYTE
    LocVar dle_fcrlf, BYTE
;   LocVar dle_modnamecnt, BYTE      ; Don't need this anymore, see LDRVARS.H
    LocVar dle_mflagsmatch, DWORD
    LocVar dle_fpagetab, DWORD
    LocVar dle_fixupsize, DWORD
;   LocVar dle_modname, DWORD        ; Don't need this anymore, see LDRVARS.H
    LocVar dle_impmodcnt, DWORD
    LocVar dle_swapmte, DWORD
    LocVar dle_hobmtematch, DWORD
    LocVar dle_pmtematch, DWORD
    LocVar dle_addr, <size AddrS>
    LocVar dle_saddr, <size AddrS>
    LocVar dle_modaddr, <size AddrS>
    LocVar dle_namebuf, <CMDLINELEN>

BeginProc
        xor     eax,eax
        mov     [dle_hobmtematch],eax
        mov     [dle_pmtematch],eax
        mov     [dle_namebuf],al
        mov     [dle_fmodmatch],al
        mov     [dle_fobjdump],al
        mov     [dle_fcrlf],al

dle00:  Pcall   PeekChr                 ; (AL) = character
        jz      short dle04
        mov     ebx,LIBRARYMOD
        cmp     al,"L"
        jz      short dle01
        mov     ebx,DEVDRVMOD+LIBRARYMOD       ;RJM
        cmp     al,"P"
        jz      short dle01
        mov     ebx,VDDMOD+LIBRARYMOD
        cmp     al,"V"
        jz      short dle01
        mov     ebx,FSDMOD+LIBRARYMOD          ;RJM 154740
        cmp     al,"I"                         ;RJM 154740
        jz      short dle01                    ;RJM 154740
        xor     ebx,ebx
        cmp     al,"X"
        jz      short dle01
        cmp     al,"O"
        jnz     short dle04
        mov     al,1
        xchg    [dle_fobjdump],al
        jmp     short dle02

dle01:  mov     [dle_mflagsmatch],ebx
        mov     al,1
        xchg    [dle_fmodmatch],al
dle02:  or      al,al
        jnz     short dle03
        Pcall   SkipB                   ; eat the character in the input buffer
        jmp     short dle00

dle03:  putstr  <"Redundant option">
        Jump    CmdBreak

dle04:  Pcall   ScanP
        jz      short dle16             ; jmp if no more command line input

        Pcall   CheckString
        jnz     short dle08             ; jmp if command line has quoted string
        lea     di,[dle_namebuf]
        mov     dx,di
        Pcall   ParseString
        jc      dlee
        sub     di,dx
        Ccall   lowercase,<dx>
        jmp     short dle16

dle08:  lea     si,[dle_addr]
        Pcall   EvalExpr

        mov     al,[si].AddrType        ; (AL) = address type
        lea     bx,[dle_hobmtematch]
        cmp     al,EXPR_TYPE_DATA
        jz      short dle12
        lea     bx,[dle_pmtematch]
        cmp     al,EXPR_TYPE_LIN
        jz      short dle12
        putstr  <"Invalid expression">
        Jump    CmdBreak

dle12:  mov     edx,[si].AddrOff        ; (EDX) = start address/object number
        mov     [bx],edx

dle16:  push    ds
        FlatContext ds
        mov     edx,[_mte_h]
        mov     [dle_next],edx
        pop     ds
    assumeDATA  ds

dle20:  mov     edx,[dle_next]          ; (EDX) = mte laddr
        or      edx,edx
        jz      dlex
        mov     [dle_pmte],edx          ; set current mte laddr

        lea     bx,[dle_addr]
        Pcall   FillLinAddr, <bx, edx>

        Pcall   GetWord                 ; fetch the signature
        jc      dlee
        mov     eax,size ldrote_s
        and     dx,MTEFORMATMASK
        cmp     dx,MTEFORMATLX
        jz      short dle24
        mov     eax,size ldrste_s
        cmp     dx,MTEFORMATNE
        jz      short dle24
        putstr  <"not an MTE">
        Jump    CmdBreak

dle24:  mov     [dle_size],eax
        mov     cx,4
        lea     di,[dle_swapmte]        ; get pointer to swappable mte
        Pcall   GetBuffOff, <mte_swapmte, 0>
        mov     edx,[dle_swapmte]
        lea     bx,[dle_saddr]          ; fill in addr buffer with swap ptr
        Pcall   FillLinAddr, <bx, edx>
        mov     cx,4                    ; get pointer to next mte
        lea     di,[dle_next]
        lea     bx,[dle_addr]           ; address of resident mte addr
        Pcall   GetBuffOff, <mte_link, 0>
        jc      dlee

        lea     di,[dle_hobmte]
        mov     [di].HighWord,0
        mov     cx,2
        lea     bx,[dle_addr]           ; address of resident mte addr
        Pcall   GetBuffOff, <mte_handle, 0>
        jc      dlee
        mov     eax,[dle_hobmtematch]   ; if non-zero, hobmte must match
        or      eax,eax
        jz      short dle28
        cmp     [dle_hobmte],eax
        jnz     dle20                   ; jmp if no match

dle28:  mov     eax,[dle_pmtematch]     ; if non-zero, pmte must match
        or      eax,eax
        jz      dle44

;       Display the mte only if the match pointer points into the resident
;       or swappable section of the mte.

        mov     edi,[dle_pmte]
        cmp     edi,eax
        ja      dle37                   ; jmp if below resident mte section
        add     edi,size ldrmte_s
        push    edi                     ; (EDI) - size od resident mte
   ; Changed MTE structure so that mte_modname is 8 bytes,
   ; not a pointer to a length prefixed string.
   ; See LDRVARS.H
   ;    lea     di,[dle_modname]
   ;    lea     bx,[dle_addr]           ; address of resident mte addr
   ;    mov     cx,4
   ;    Pcall   GetBuffOff, <mte_modname, 0>
   ;    mov     edx,[dle_modname]
   ;    lea     bx,[dle_modaddr]        ; fill in addr buffer with modname
   ;    Pcall   FillLinAddr, <bx, edx>
   ;    lea     di,[dle_modnamecnt]
   ;    lea     bx,[dle_modaddr]        ; address of resident mte addr
   ;    mov     cx,1
   ;    Pcall   GetBuffOff, <0, 0>      ; bugbug ? offset 0 ??
   ;    xor     ecx,ecx
   ;    mov     cl,[dle_modnamecnt]
   ;    pop     edi                     ; (EDI) - size of resident mte
   ;    add     edi,ecx
   ;    push    edi
        lea     di,[dle_impmodcnt]
        lea     bx,[dle_addr]           ; address of resident mte addr
        mov     cx,4
        Pcall   GetBuffOff, <mte_impmodcnt, 0>
        mov     ecx,[dle_impmodcnt]
        shl     ecx,2
        pop     edi                     ; (EDI) - size of resident mte
        add     edi,ecx                 ; add 4*impmodcnt (for pMTE of imports)
        cmp     edi,[dle_pmtematch]
        ja      short dle44             ; jmp if within resident mte section

dle37:  lea     di,[dle_swapmte]
        lea     bx,[dle_addr]           ; address of resident mte addr
        mov     cx,4
        Pcall   GetBuffOff, <mte_swapmte, 0>
        mov     edi,[dle_swapmte]
        or      edi,edi
        jz      dle20                   ; jmp if no swappable section exists
        cmp     edi,[dle_pmtematch]
        ja      dle20                   ; jmp if below swappable section
        lea     di,[dle_fixupsize]
        lea     bx,[dle_saddr]          ; address of swappable mte addr
        mov     cx,4
        Pcall   GetBuffOff, <smte_fixupsize, 0>
        jc      dle20
        lea     di,[dle_fpagetab]
        lea     bx,[dle_saddr]          ; address of swappable mte addr
        mov     cx,4
        Pcall   GetBuffOff, <smte_fpagetab, 0>
        jc      dle20
        mov     edi,[dle_fpagetab]
        add     edi,[dle_fixupsize]
        cmp     edi,[dle_pmtematch]
        jbe     dle20                   ; jmp if above swappable section

dle44:  lea     di,[dle_mflags]
        lea     bx,[dle_addr]           ; address of resident mte addr
        mov     cx,4
        Pcall   GetBuffOff, <mte_flags1, 0>
        jc      dlee
        cmp     [dle_fmodmatch],0
        jz      short dle56
        mov     eax,[dle_mflags]
        and     eax,LIBRARYMOD+DEVDRVMOD+VDDMOD+FSDMOD ;RJM 154740
        cmp     [dle_mflagsmatch],eax
        jnz     dle20
        jmp     dle56

dle56:  xor     ax,ax
        mov     [dle_cprint],ax
        mov     [dle_cline],ax

        cmp     [dle_namebuf],0
        jz      short dle58             ; jmp if no name given, print all

        mov     bx,7                    ; (BX) = flag: 7=no drive, path, ext
        mov     edx,[dle_hobmte]
        xor     di,di                   ; (DI) = buffer: use cache
        Pcall   GetMTEName
        jc      dle20                   ; jmp if no name, no match

        lea     si,[dle_namebuf]
dle57:  lodsb
        cmp     [di],al
        jnz     dle20                   ; jmp if name doesn't match
        inc     di
        or      al,al
        jnz     short dle57             ; examine next byte

dle58:  xor     bx,bx                   ; (BX) = flag: 0=full path
        mov     edx,[dle_hobmte]
        xor     di,di                   ; (DI) = buffer: use cache
        Pcall   GetMTEName
        jnc     short dle60

        mov     di,dataOFFSET BadNamemsg
dle60:  cmp     [dle_fcrlf],0
        jz      short dle62
        Pcall   crlf
dle62:  mov     edx,[dle_hobmte]
        mov     ecx,[dle_pmte]
        mov     ebx,[dle_mflags]
        printf  <"hmte=%04lx pmte=%%%08lx mflags=%08lx %s",CR,LF>, \
                                                            <edx,ecx,ebx,di>
        cmp     [dle_fobjdump],0
        jz      dle20

        lea     di,[dle_cote]
        mov     cx,4
        lea     bx,[dle_saddr]          ; address of swappable mte addr
        Pcall   GetBuffOff, <smte_objcnt, 0>
        jnc     short dle63
        printf  <" swappable mte - swapped">
        Pcall   crlf
        jmp     dle20

dle63:  lea     di,[dle_pote]
        lea     bx,[dle_saddr]          ; address of swappable mte addr
        mov     cx,4
        Pcall   GetBuffOff, <smte_objtab, 0>
        jc      dlee

        lea     di,[dle_cnonrsrc]       ; fetch resource count
        lea     bx,[dle_saddr]          ; address of swappable mte addr
        mov     cx,4
        Pcall   GetBuffOff, <smte_rsrccnt, 0>
        jc      dlee
        mov     eax,[dle_cote]          ; convert to # of non-resource segs
        sub     eax,[dle_cnonrsrc]
        mov     [dle_cnonrsrc],eax

        mov     [dle_fcrlf],1
        cmp     [dle_cote],0
        jz      dle20

dle64:  cmp     [dle_cline],0
        jne     short dle80
        cmp     [dle_size],size ldrote_s
        jz      short dle68
        putstr  <"seg  sect psiz vsiz hob  sel  flags">
        jmp     short dle76

dle68:  putstr  <"obj   vsize    vbase    flags   ipagemap cpagemap ">
        test    [dle_mflags],VDDMOD
        jnz     short dle72
        putstr  <"hob  sel">
        jmp     short dle76

dle72:  putstr  <" vaddr">
dle76:  Pcall   crlf
        mov     [dle_cline],LINES_PER_PAGE

dle80:  inc     [dle_cprint]
        mov     dx,[dle_cprint]
        Pcall   out16
        lea     bx,[dle_addr]
        mov     edx,[dle_pote]
        Pcall   FillLinAddr, <bx, edx>
        mov     edx,[dle_size]
        Pcall   GetCache
        jnc     short dle84
        mov     edx,[dle_pote]
        printf  <" %%%08lx - swapped">,<edx>
        jmp     short dle96

dle84:  cmp     [dle_size],size ldrste_s
        jz      short dle92
        mov     si,dataOFFSET PrintOTE  ; else dump ote in three parts
        Pcall   OpInterpret
        mov     si,dataOFFSET PrintOTEVdd
        test    [dle_mflags],VDDMOD
        jnz     short dle88
        mov     si,dataOFFSET PrintOTESel
dle88:  Pcall   OpInterpret
        mov     si,dataOFFSET PrintOTEFlags
        Pcall   OpInterpret
        jmp     short dle96

dle92:  mov     si,dataOFFSET PrintSTE  ; (SI) = ldrste_s op table
        Pcall   OpInterpret
        movzx   eax,[dle_cprint]
        cmp     eax,[dle_cnonrsrc]
        jbe     short dle96
        mov     dx,dataOFFSET Rsrcmsg   ; flag the resource
        Pcall   rprbuf
dle96:  Pcall   crlf
        dec     [dle_cline]
        mov     eax,[dle_size]
        add     [dle_pote],eax
        dec     [dle_cote]
        jnz     dle64
        jmp     dle20

dlee:   Jump    ErrBreak
dlex:
EndProc


;***    GetMTEName
;
;       Obtain an MTE name
;
;       Pcall   GetMTEName
;
;       ENTRY   (AL) = fill character           (if DI non-zero)
;               (BX) = flags:
;                            1=skip drive
;                            2=skip path
;                            4=skip extension
;               (CX) = buffer length            (if DI non-zero)
;               (DX) = MTE handle
;               (DI) = name buffer, 0 means use the cache
;       EXIT    Carry set on failure
;                       (AX) = error code
;               Carry clear on success
;                       (DI) = name buffer
;       USES    AX, BX, CX, DX, SI, DI, Flags

DefProc GetMTEName, NEAR
    assumeDATA <ds, es, ss>
    LocVar gmn_addr, <size AddrS>
    LocVar gmn_saddr, <size AddrS>
    LocVar gmn_pname, DWORD
    LocVar gmn_swapmte, DWORD
;   LocVar gmn_modname, DWORD        ; Don't need this anymore, see LDRVARS.H
    LocVar gmn_buffer, WORD
    LocVar gmn_length, WORD
    LocVar gmn_flags, WORD
    LocVar gmn_fill, BYTE
BeginProc
        or      di,di
        jnz     short gmn00
        xor     al,al
        mov     cx,CACHEPATHLEN
gmn00:  mov     [gmn_buffer],di
        mov     [gmn_length],cx
        mov     [gmn_flags],bx
        mov     [gmn_fill],al

        lea     bx,[gmn_addr]
        Pcall   GetObjectAddr
        jnc     short gmn05
        Pcall   GetPseudoObjectAddr
        jc      gmnx
gmn05:  Pcall   GetWordOff, <mte_flags2, 0>
        jc      gmnx
        and     dx,MTEFORMATMASK
        cmp     dx,MTEFORMATLX
        jz      short gmn10
        mov     ax,DEBERR_INVALID_ADDR_TYPE
        cmp     dx,MTEFORMATNE
        stc
        jnz     gmnx
gmn10:
        mov     cx,4
        lea     di,[gmn_swapmte]        ; get pointer to swappable mte
        lea     bx,[gmn_addr]
        Pcall   GetBuffOff, <mte_swapmte, 0>
        mov     edx,[gmn_swapmte]
        lea     bx,[gmn_saddr]          ; fill in addr buffer with swap ptr
        Pcall   FillLinAddr, <bx, edx>
        mov     cx,4                    ; (CX) = 4 bytes
        lea     di,[gmn_pname]
        lea     bx,[gmn_saddr]
        Pcall   GetBuffOff, <smte_path, 0> ; fetch linear pathname pointer
        jc      gmn12		 	; rjm 158783 fix trap d in KDB
        mov     edx,[gmn_pname]
        lea     bx,[gmn_saddr]
        Pcall   FillLinAddr, <bx, edx>
        mov     dx,CACHEPATHLEN         ; (DX) = number of bytes
        Pcall   GetCache                ; (DI) = cache buffer address
        jnc     short gmn15
gmn12:					; rjm 158783

    ; Changed MTE structure so that mte_modname is 8 bytes,
    ; not a pointer to a length prefixed string.
    ; See LDRVARS.H
    ;   mov     cx,4                    ; path swapped out use modname
    ;   lea     di,[gmn_modname]        ; get pointer to modname
    ;   lea     bx,[gmn_addr]
    ;   Pcall   GetBuffOff, <mte_modname, 0>
    ;   mov     edx,[gmn_modname]
        lea     bx,[gmn_addr]           ; fill in addr buffer with modname
    ;   Pcall   FillLinAddr, <bx, edx>
        mov     dx,MAXMODNAME+mte_modname; (DX) = number of bytes
        Pcall   GetCache                ; (DI) = cache buffer address
        jc      gmnx

        add     di,mte_modname
        mov     byte ptr [di+8],0       ;Null terminate (if it was full 8 char)

        push    di
        xor     ax,ax                   ;look for null
        mov     cx,-1                   ;look forever (we just put one, though)
        repne scasb
        not     cx                      ; How may did we skip?
        dec     cx                      ; don't count null
        pop     di

        dec     di                      ; make room for length prefix
        mov     byte ptr [di],cl        ; set length of name
    ; End of changes for new MTE structure

        add     cl,2                    ; add two; one for length, one for \0
        mov     [gmn_length],cx
        mov     byte ptr [di+gmn_length+1],0; zero terminate string
        mov     byte ptr [di],'!'       ; indicate that modname returned
        jmp     gmn16

gmn15:  mov     byte ptr [di+CACHEPATHLEN+1],0 ; ensure nul termination

gmn16:  mov     si,di
        mov     di,[gmn_buffer]
        or      di,di
        jnz     short gmn20
        mov     di,si

gmn20:  mov     cx,[gmn_length]
        mov     bx,[gmn_flags]
        mov     [gmn_buffer],di
        cmp     byte ptr [si+1],':'
        jnz     short gmn30
        lodsw
        test    bl,1
        jnz     short gmn30             ; jmp to skip driver letter and colon
        stosw
        dec     cx                      ; count buffer length
        dec     cx
gmn30:  test    bl,2
        jz      short gmn40             ; jmp to include full path

;       Skip all but the last component of the pathname.

gmn32:  mov     bx,si                   ; save pointer to rest of name
gmn33:  lodsb
        or      al,al
        jz      short gmn35             ; jmp if at end of name
        cmp     al,'\'
        jz      short gmn32             ; jmp if path separator, save pointer
        jmp     short gmn33             ; normal character, loop again

gmn35:  mov     si,bx
        mov     bx,[gmn_flags]          ; (bx) = flags

gmn40:  lodsb                           ; copy to the target buffer
        test    bl,4                    ; Skip extension?
        jz      short gmn45             ;  no, skip this test
        cmp     al,'.'                  ; Dot?
        je      short gmn50             ;  yes, stop
gmn45:  or      al,al
        jz      short gmn50             ; until at end of name
        stosb
        loop    gmn40                   ; or until buffer is full
        inc     cx                      ; truncate name to leave room for nul
        dec     di

gmn50:  dec     cx                      ; fill all but nul byte
        mov     al,[gmn_fill]
        or      al,al
        jz      short gmn60
        rep stosb
gmn60:  xor     al,al                   ; fill nul byte
        stosb

gmn90:  mov     di,[gmn_buffer]
        Ccall   lowercase,<di>
gmnx:
EndProc
.286p

;***    DebDRAlloc
;
;       Allocate a debug register
;
;       ENTRY:  None
;
;       EXIT:   (SI) = -1       Out of debug registers
;               (SI) = 0,1,2,3  Debug register (SI) allocated
;
;       USES:   SI
;
    assumeDATA <ds, es, ss>
.386p
DefProc DebDRAlloc, NEAR
        movzx   esp,sp
        SaveReg <eax,ecx,edx,ds,es>
        FlatContext <ds,es>,ax
        CCALL32 _DbgDRAlloc,,nofar32
.386p
        mov     si,ax
        RestoreReg <es,ds,edx,ecx,eax>
    assumeDATA <ds, es>
EndProc
.286p

;***    DebDRFree
;
;       Free a debug register
;
;       ENTRY:  AX = debug register to free (0,1,2,3)
;
;       EXIT:   SI = 0, no error
;
;               SI != 0, error code in SI
;
;       USES:   SI
;
    assumeDATA <ds, es, ss>
.386p
DefProc DebDRFree, NEAR
        movzx   esp,sp
        SaveReg <eax,ecx,edx,ds,es>
        movzx   eax,ax
        FlatContext <ds,es>,cx
        CCALL32 _DbgDRFree,eax
.386p
        mov     si,ax
        RestoreReg <es,ds,edx,ecx,eax>
    assumeDATA <ds, es>
EndProc
.286p

;***    SaveContext
;
;       Save a unique reference to the current context
;
;       ENTRY:  DS = DataContext
;
;       EXIT:   None
;
;       USES:   EBX
;
    assumeDATA <ds>

DefProc SaveContext, NEAR

        FlatContext <ds>,bx
        .386p
        mov     ebx,[_pTCBCur]
        DataContext <ds>
        mov     Context,ebx
        .286p
EndProc

;***    CompareContext
;
;       Compares current context to context saved with SaveContext
;
;       ENTRY:  DS = DataContext
;
;       EXIT:   ZF = 1  => Same context
;               ZF = 0  => Different Context
;
;       USES:   EBX, FLAGS
;
    assumeDATA <ds>

DefProc CompareContext, NEAR

        FlatContext <ds>,bx
        .386p
        mov     ebx,[_pTCBCur]
        DataContext <ds>
        cmp     ebx,Context             ; Are we in same context?
        .286p

EndProc

;***    ZeroGoTime
;
;       Clears to GoTime counter
;
;       ENTRY:  DS = DataContext
;
;       EXIT:   GoTime Cleared
;
;       USES:   EAX, FLAGS
;
    assumeDATA <ds>

DefProc ZeroGoTime, NEAR
        .386p
        FlatContext <ds>,ax
        xor     eax,eax
        mov     GoTimeH,eax                     ; Zero var so -Time
        mov     GoTimeL,eax                     ;  can be placed in it.
        .286p
        DataContext <ds>,ax
EndProc

;***    CheckGoTime
;
;       Checks Go time to verify the counter = 0.
;
;       ENTRY:  DS = DataContext
;
;       EXIT:   none
;
;       USES:   EAX, EBX, ECX, EDX, FLAGS
;
    assumeDATA <ds>

DefProc CheckGoTime, NEAR
        .386p
        FlatContext <ds>,ax
        mov     eax,GoTimeH
        add     eax,GoTimeL                     ;  can be placed in it.
        .286p
        DataContext <ds>,ax
        jz      cgt10

        putstr  <"Warning: Debugger entered during GS timing from ">
        mov     bx,dataOFFSET RegSA.CSIPsav
        Pcall   OutAddrS, <bx>
        Pcall   crlf

cgt10:

EndProc

;***    MarkStartTime
;
;       Starts the PerfView timer.
;
;       ENTRY:  RegSA = User registers
;
;       EXIT:   None
;
;       USES:   FLAGS
;

    assumeDATA <ds>

DefProc MarkGoTime, NEAR

;
; We need to turn interrupts on *before* calling TMR32SubTime to avoid
; adding the time of the interrupt routines to the Go time. But it would
; be very bad to turn interrupts on in an unexpected context. If interrupts
; were not on in the saved flags, then we just won't time at all.
;
        test    [RegSA.Fsav],F_INTERRUPT        ; Were interrupts on?
        jz      mst10                           ;  No.
        Pcall   CheckCtrlC
        .386p
        SaveReg <ds,es,eax,edx>
        FlatContext <es,ds>,eax
        mov     eax, GoTimeL
        add     eax, GoTimeH
        or      eax,eax                         ; Zero time --> Mark
        jnz     short mst5

        lea     ecx,GoTimeL
        sti                                     ; Clear pending interrupts
        CCALL32 TMR32SubTime,,nofar32
        cli
        .386p
mst5:   RestoreReg <edx,eax,es,ds>
    assumeDATA  <ds>
        .286p

mst10:

EndProc

;***    DisplayGoTime
;
;       Prints out the time stored in GoTime
;
;       ENTRY:  DS = DataContext
;
;       EXIT:   GoTime Cleared
;
;       USES:   EAX, EBX, ECX, EDX, FLAGS
;
    assumeDATA <ds>

DefProc DisplayGoTime, NEAR

        .386p
        FlatContext <ds>,eax

        mov     edx,GoTimeH
        mov     eax,GoTimeL                     ; EDX:EAX = Time (tics)
        xor     ecx,ecx
        mov     GoTimeH,ecx
        mov     GoTimeL,ecx

        DataContext <ds>,ecx
    assumeDATA  <ds>

        SaveReg <eax,edx>
        printf  <"Go Time (tics) = %lx%lx (hex)">, <edx,eax>
        RestoreReg <edx,eax>

        xor     ecx,ecx
        xchg    ecx,edx                         ; ECX = High DWord of tics
        FlatContext <ds>

        mov     ebx, 1000000
        mul     ebx
        div     [ulTmrFreq]
        mov     ebx, eax                        ; EBX = uSecs from low word

        mov     edx,0F423Fh                     ; EDX:EAX = FFFFFFFF *
        mov     eax,0FFF0BDC0h                  ;           1000000
        div     [ulTmrFreq]                     ; EAX = uSecs from 1 tick
                                                ;       in high word
        DataContext <ds>
    assumeDATA  <ds>

        mul     ecx                             ; EDX:EAX = # uSecs from high
                                                ;           word
        add     eax,ebx

        adc     edx,0                           ; EDX:EAX = Total uSecs

        jz      short dgt20                     ; EDX expected to be 0

;
; For times greater than 2^32 uSec just print a hex time to make life
; easier. This is unlikely to happen.
;
        printf  <" = %lx%lx (hex uSec)">,<edx,eax>
        jmp     short dgt40

dgt20:  printf  <" = %ld (uSec)">,<eax>
        .286p

dgt40:  Pcall   crlf

EndProc

; Start of code change DGE
;***    ShowTimeStamps
;
;       Shows the time stamps stored in TSBuff
;
;       ENTRY:  RegSA = User registers
;
;       EXIT:
;
;       USES:   EAX, EBX, ECX, EDX, FLAGS
;
    assumeDATA <ds>

DefProc ShowTimeStamps, NEAR
        .386p
        SaveReg <ds,es,eax,edx>

        FlatContext <ds>,eax

        mov     ebx,cTSEntries
        inc     ebx

        DataContext <ds>,ecx
    assumeDATA  <ds>

        printf  <"Number of entries = %ld">, <ebx>
        Pcall   crlf

        FlatContext <ds>

; Compute eax = the number entries to print, ebx = index to 1st entry to show

        mov     eax,cTSEntries
        or      eax,eax
        js      dts40           ; jump if zero entries (count = -1)
        mov     ebx,eax
dts10:  cmp     ebx,TSBUFF_LEN  ; wraparound?
        jbe     dts20           ; jump if no
        mov     eax,TSBUFF_LEN  ; clamp number of entries to print
        sub     ebx,TSBUFF_LEN
        jmp     dts10
dts20:  sal     ebx,3           ; multiply entry index by 8
        mov     ecx,pTSBuff
        add     ecx,ebx         ; result is address of last entry used

dts30:  or      eax,eax
        js      dts40
        dec     eax
        SaveReg <eax>
        cmp     ecx,[pTSBuff]   ; Wrap?
        jae     dts35
        mov     ecx,pTSBuff
        add     ecx,TSBUFF_BUFF_SIZE
        sub     ecx,8
dts35:  add     ecx,4
        mov     eax,[ecx]
        sub     ecx,4
        mov     edx,[ecx]
        sub     ecx,8
        mov     ebx,eax
        and     eax,0ffffffh    ; mask of the breakpoint number
        shr     ebx,28          ; position the breakpoint number
        SaveReg <ecx>

        DataContext <ds>,ecx
    assumeDATA  <ds>

        SaveReg <eax,edx,ebx>
        printf  <"BP%lx %lx%lx (hex)">, <ebx,eax,edx>
        Pcall   crlf
        RestoreReg <ebx,edx,eax>

        FlatContext <ds>

        RestoreReg <ecx>
        RestoreReg <eax>
        jmp     dts30

dts40:
        RestoreReg <edx,eax,es,ds>
    assumeDATA  <ds>
        .286p

EndProc
;***    TimeStampBP
;
;       Time stamp the PerfView timer value into the time stamp circular buffer
;
;       ENTRY:  RegSA = User registers, cx = break point number
;
;       EXIT:   None
;
;       USES:   FLAGS
;
    assumeDATA <ds>

DefProc TimeStampBP, NEAR

;
        .386p
        SaveReg <ds,es,eax,edx>
        FlatContext <es,ds>,eax
        push    ecx             ; remember the break point number
        mov     ebx,cTSEntries
        inc     ebx
        mov     cTSEntries,ebx
tsbp10: cmp     ebx,TSBUFF_LEN  ; wraparound?
        jbe     tsbp20          ; jump if no
        sub     ebx,TSBUFF_LEN
        jmp     tsbp10
tsbp20: sal     ebx,3           ; multiply number of entries by 8
        mov     ecx,pTSBuff
        add     ecx,ebx
        xor     eax,eax         ; zero the QW entry 'cuz we add to it
        mov     [ecx+4],eax
        inc     eax
        mov     [ecx],eax

        CCALL32 TMR32AddTime,,nofar32
;       CCALL32 TMR32AddTime
        .386p
        sub     DWORD PTR [ecx],1
        sbb     DWORD PTR [ecx+4],0
        pop     eax             ; recall break point number
        sal     eax,28          ; put entry point number in hi-nibble
        add     ecx,4           ; point to hi-dword of time stamp entry
        mov     ebx,[ecx]       ; get time stamp hi-dword
        and     ebx,0ffffffh    ; strip hi-nibble of time stamp
        or      eax,ebx
        mov     [ecx],eax
        RestoreReg <edx,eax,es,ds>
    assumeDATA  <ds>
        .286p

EndProc
;***    ClearTimeStamps
;
;       Clear time stamps
;
;       ENTRY:  RegSA = User registers
;
;       EXIT:   None
;
;       USES:   FLAGS
;
    assumeDATA <ds>

DefProc ClearTimeStamps, NEAR

;
        .386p
        SaveReg <ds,eax>
        FlatContext <ds>,eax
        mov     eax,-1
        mov     cTSEntries,eax
        RestoreReg <eax,ds>
    assumeDATA  <ds>
        .286p

EndProc
;End of code change DGE

CodeSegmentEnd

        end
