;       SCCSID = @(#)dosibm.asm	6.1 90/11/17
PAGE	,132
NAME	DOSIBM
TITLE	DOSIBM.ASM - IBM CODE FOR DEBUGGER
.286p

;***	DOSIBM.ASM
;
;	SCCSID = @(#)dosibm.asm	13.8 90/04/17
;

.xlist
	include dosseg.inc
	include basemaca.inc
	include osmaca.inc
	include debseg.inc
	include debmac.inc
	include debequ.inc
	include debprt.inc
	include struc.inc
	include abios.inc
.list


	ReferGlobal	ABIOS_CDA_anchor_p, WORD
	ReferGlobal	ABIOS_CDA_anchor_r, WORD
	ReferGlobal	ABIOS_present, BYTE



DataSegmentStart

;
;	ABIOS Device Type Strings
;

ABIOSMsgs	label	word

	dw	dataOFFSET ABIOSmsg		; 0
	dw	dataOFFSET DSKETTEmsg		; 1
	dw	dataOFFSET DISKmsg		; 2
	dw	dataOFFSET VIDEOmsg		; 3
	dw	dataOFFSET KEYBDmsg		; 4
	dw	dataOFFSET PRINTmsg		; 5
	dw	dataOFFSET ASYNCHmsg		; 6
	dw	dataOFFSET SYSTMRmsg		; 7
	dw	dataOFFSET RTCTMRmsg		; 8
	dw	dataOFFSET SYSSmsg		; 9
	dw	dataOFFSET NMImsg		; a
	dw	dataOFFSET POINTmsg		; b
	dw	dataOFFSET LPENmsg		; c
	dw	dataOFFSET JOYSmsg		; d
	dw	dataOFFSET CMOSRmsg		; e
	dw	dataOFFSET DMAmsg		; f
	dw	dataOFFSET POSmsg		; 10
	dw	dataOFFSET ELOGmsg		; 11
	dw	dataOFFSET SADmsg		; 12
	dw	dataOFFSET IOPmsg		; 13
	dw	dataOFFSET AUDIOmsg		; 14
	dw	dataOFFSET INTCmsg		; 15
	dw	dataOFFSET SECmsg		; 16


Static	ABIOSmsg,	STRING, "Internal   "
Static	DSKETTEmsg,	STRING, "Diskette   "
Static	DISKmsg,	STRING, "Disk       "
Static	VIDEOmsg,	STRING, "Video      "
Static	KEYBDmsg,	STRING, "Keyboard   "
Static	PRINTmsg,	STRING, "Printer    "
Static	ASYNCHmsg,	STRING	"Asynch     "
Static	SYSTMRmsg,	STRING, "SysTimer   "
Static	RTCTMRmsg,	STRING, "RTCTimer   "
Static	SYSSmsg,	STRING, "SysService "
Static	NMImsg,		STRING, "NMInterrupt"
Static	POINTmsg,	STRING, "PointDevice"
Static	LPENmsg,	STRING, "LightPen   "
Static	JOYSmsg,	STRING, "JoyStick   "
Static	CMOSRmsg,	STRING, "CMOSRam    "
Static	DMAmsg,		STRING, "DMA        "
Static	POSmsg,		STRING, "POS        "
Static	ELOGmsg,	STRING, "ErrorLog   "
Static	SADmsg,		STRING, "S/A Dump   "
Static	IOPmsg,		STRING, "IOPortAlloc"
Static	AUDIOmsg,	STRING, "AudioTone  "
Static	INTCmsg,	STRING, "Int/8259   "
Static	SECmsg,		STRING, "Security   "

;
;   Prints Device ID For a Logical ID
;

DumpDevID   label   word

	OutMsgBitF	0, 0, 16, ABIOSMsgs
	EndOp

DataSegmentEnd



CodeSegmentStart

;***	DumpCDA
;
;	This Dumps the ABIOS Common Data Area
;
;	ENTRY:	NONE
;
;	EXIT:	NONE
;
;	USES:	ALL
;
	assumeDATA <ds, es, ss>

DefProc DumpCDA, NEAR, PUBLIC

LocVar CDASeg,	  WORD			    ; Segment with ABIOS data
LocVar NumLids,	  WORD			    ; number of Logical IDs in ABIOS
LocVar ThisDevID, WORD			    ; device ID of this LID
LocVar ThisEntry, <size LIDEntry>	    ; LID currently being examined

BeginProc

    DosContext	<ds>
    .if <ds:ABIOS_present ne 0> and  near
    .if <ds:ABIOS_CDA_anchor_p ne 0> near

	Pcall	IsDebProtMode
	.if c
	    mov	    ds, ds:ABIOS_CDA_anchor_p
	.else
	    mov	    ds, ds:ABIOS_CDA_anchor_r
	.endif

	assume	ds:NOTHING		    ; (DS) = ABIOS segment

	mov	CDASeg, ds		    ; save ABIOS seg for later

	xor	dx, dx			    ; (DX) = 0th LID
	mov	cx, ds:[0].CDALids
	mov	NumLids, cx		    ; save number of LIDs

dc10:
	    mov	    ds, CDASeg		    ; (DS) = ABIOS segment
	    mov	    si, dx		    ; (SI) = current LID number
	    shl	    si, 3		    ; (DS:SI) -> nth LID
	    .errnz  (size LIDEntry - 8)

	    lea	    di, ThisEntry	    ; (ES:DI) -> current LID area
	    mov	    cx, (size LIDEntry) / 2 ; # of words per LID
	    rep	    movsw		    ; copy from ABIOS to ThisEntry

	    lea	    di, ThisEntry	    ; (ES:DI) -> current LID area

	    .if <es:[di].DBSegment ne 0> and
	    .if <dx ne 0>		    ; DBSegment holds #LIDS in LID 0
		mov	ds, es:[di].DBSegment
		mov	si, es:[di].DBOffset ;(DS:SI) -> current data block
		mov	ax, ds:[si].DevID
		mov	ThisDevID, ax	    ; ThisDevID = this LID's devid
	    .endif

	    push    es			    ; kernel debugger is small model,
	    pop	    ds			    ; so reset DS before calling
	    assumeDATA <ds>		    ; (DS) = debugger data

	    putstr  <"  LID(">		    ; Print LID #
	    Pcall   out16
	    putstr  <")  ">

	    SaveReg <dx>		    ; save current LID number

	    putstr  <"Type=">		    ; Print Device Type
	    .if <[di].DBSegment eq 0> and
	    .if <[di].FTTSegment eq 0>
		putstr	<"Null       ">
	    .elseif <dx eq 0>
		putstr	<"Reserved   ">
	    .elseif <[di].DBSegment ne 0>
		SaveReg <dx,si,di>
		lea	di, ThisDevID
		mov	si, dataOFFSET DumpDevID
		Pcall	OpInterpret
		RestReg <di,si,dx>
	    .endif

	    putstr  <"  DB=">
	    mov	    dx, [di].DBSegment
	    Pcall   out16
	    putstr  <":">
	    mov	    dx, [di].DBOffset
	    Pcall   out16
	    putstr  <"  FTT=">
	    mov	    dx, [di].FTTSegment
	    Pcall   out16
	    putstr  <":">
	    mov	    dx, [di].FTTOffset
	    Pcall   out16
	    Pcall   crlf		    ; NewLine

	    RestoreReg <dx>		    ; (DX) = current LID number
	    inc	    dx			    ; Next LID #

	 cmp  dx, NumLids		    ; have we printed all LIDs?
	 je   dcx			    ; yup, exit
	 jmp  dc10			    ; nope, do next one

    .else
	putstr	<"ABIOS Not Present or Not Initialized", CR, LF>
    .endif

dcx:

EndProc

CodeSegmentEnd

	end
