
; Public Domain

; test install command: install; ldmem; ldmem uninstall
; test run command: ; .; .

%include "lmacros3.mac"
%include "eld.mac"
%include "eldcall.mac"
%include "elddata.mac"

	cpu 8086

	addsection RELOCATEDDATA, nobits vstart=_ELD_RELOC_VSTART
relocateddata:

	addsection HEADER, start=0

	istruc ELD_HEADERX
at eldhxHeader
		; ELD executable header
	istruc ELD_HEADER
at eldhSignature,	db "ELD1"
			db 0,0,0
			db 26
at eldhCodeOffset,	dd CODEOFFSET
at eldhCodeImageLength,	dw code_size
at eldhCodeAllocLength,	dw 0
at eldhDataOffset,	dd DATAOFFSET
at eldhDataImageLength,	dw data_size
at eldhDataAllocLength,	dw total_data_size - data_size
at eldhCodeEntrypoint,	dw linker - code
at eldhReserved
at eldhExtensionSize,	dw header_extension_end - $$
	iend
at eldhxDescriptionOffset,	dd description
header_extension_end:
	iend

description:		asciz "Dump lDebug memory use."


	align 16, db 0

CODEOFFSET equ $ - $$
	addsection CODE, follows=HEADER vstart=_ELD_CODE_VSTART
%define CODEFIXUP - code + 0
code:
		; ELD instance header
	istruc ELD_INSTANCE
at eldiStartCode
at eldiEndCode
at eldiStartData
at eldiEndData
at eldiIdentifier,	fill 8, 32, db "LDMEM"
	iend


	numdef ELD_BUG, 0
	numdef ELD_BUG_RELOC, _ELD_BUG
	numdef ELD_BUG_LINK, _ELD_BUG
	numdef ELD_BUG_LENGTH, _ELD_BUG


%rep _ELD_BUG_LINK
	dw relocateddata		; missing linkdatarelocation
%endrep

%rep _ELD_BUG_RELOC
	dw msg.ldmem			; missing internaldatarelocation
%endrep

%if _ELD_BUG_LENGTH && _ELD_CODE_VSTART
times 64 db 0
%endif

command:
	jmp strict short .entry
.chain:
	extcall cmd3_not_ext, required	; must NOT be extcallcall
	times 10 - ($ - command) nop
.entry:
	push si
	cmp al, '-'
	jne @F
	extcallcall skipcomma
@@:
	dec si

	mov dx, msg.ldmem
internaldatarelocation
	extcallcall isstring?
	je .ours
	pop si
	dec si
	lodsb
	jmp .chain

.ours:
	pop ax
	extcallcall skipcomma
	dec si
	mov dx, relocateddata
linkdatarelocation msg.uninstall
	extcallcall isstring?
	je uninstall
	lodsb
	extcallcall chkeol
	call run
	extcallcall cmd3

uninstall:
	lodsb
	extcallcall chkeol

	mov es, word [relocateddata]
linkdatarelocation extdssel
	extcallcall ispm
	jz @F
	mov es, word [relocateddata]
linkdatarelocation extseg
@@:
	push es
	pop ds
	xor bx, bx		; = 0 (no prior, modify ext_command_handler)
	mov di, command		; di -> us
internalcoderelocation
	mov si, word [ss:relocateddata]
linkdatarelocation ext_command_handler
				; si -> first
	test si, si		; none installed ?
	jz .error		; error -->

.loop:
	cmp di, si		; found ?
	je .bx			; yes, use bx -->
	mov bx, si		; bx -> prior handler
	lodsw			; skip entrypoint jmp strict short
	lodsb			; get first byte of chainer
	cmp al, 0E9h		; expecting jmp near ?
	jne .error		; no, error -->
	lodsw			; get rel16 displacement
	add si, ax		; -> next handler
	jmp .loop

.bx:
	test bx, bx		; any prior ?
	jnz .bxnz		; yes -->
	scasw			; skip entrypoint jmp strict short
	cmp byte [di], 0E8h	; is it a call to cmd3_not_ext ?
	jne @F			; no -->
				; yes, reset ext_command_handler to zero
.setbx:
	mov word [ss:relocateddata], bx
linkdatarelocation ext_command_handler
	jmp .done

@@:
	cmp byte [di], 0E9h	; validate
	jne .error		; failure -->
	inc di			; -> rel16 displacement
	mov bx, word [di]	; get displacement
	scasw			; -> after jmp near
	add bx, di		; -> next handler
	jmp .setbx		; set ext_command_handler to next

.bxnz:
	mov si, bx		; -> prior handler with us as downlink
	xchg di, si		; si -> ours, di -> prior
	cmpsw			; skip entrypoint jmp strict short
	movsb			; copy 0E8h/0E9h
	lodsw			; ax = near rel16 displacement
	add ax, si		; add in our base (= absolute offset)
	sub ax, di
	dec ax
	dec ax			; subtract new base (= relative displacement)
	stosw			; store new rel16 displacement
	movsw			; jmp strict short
	movsw			; linkcall target
	movsb			; trailer
.done:
	clropt [code + eldiFlags], eldifResident
internalcoderelocation -3	; mark block as free
	mov dx, msg.uninstall_done
internaldatarelocation
@@:
	push ss
	pop ds
	extcallcall putsz
	extcallcall cmd3	; return

.error:
	mov dx, msg.uninstall_error
internaldatarelocation
	jmp @B


run:
	push ss
	pop es
	mov si, table
internaldatarelocation
	mov dx, table_sorted
internaldatarelocation

loopprepare:
	lodsw
	test ax, ax
	jz .done
	lodsw
	test ax, ax
	jnz @F
.segzero:
	add si, 4
	jmp .next

@@:
	xchg bx, ax
	mov ax, [bx]
	test ax, ax
	jz .segzero
	mov di, table_sorted + 4
internaldatarelocation
@@:
	cmp di, dx
	jae .insert_at_di_minus_4
	scasw
	jb .insert_at_di_minus_6
	add di, 6
	jmp @B

.insert_at_di_minus_4:
	scasw
.insert_at_di_minus_6:
	sub di, 6
.insert_at_di:
	mov cx, dx
	sub cx, di
	push si
	push di
	mov di, dx		; -> end
	add di, 8		; -> after destination
	mov dx, di		; update -> end
	std			; AMD erratum 109 workaround
	scasw			; -> last word destination
	lea si, [di - 8]	; -> last word source (dx - 2)
	shr cx, 1		; = amount of words
	jcxz @FF
	cmp cx, 20
	ja @FF
@@:
	movsw
	loop @B
@@:
	rep movsw		; move up all following entries
	cld
	pop di
	pop si
	sub si, 4
	movsw			; copy message offset
	movsw			; copy seg offset
	stosw			; store seg value
	lodsw			; skip this field
	movsw			; copy size offset
.next:
	jmp loopprepare

.done:
	xchg dx, di
	xor ax, ax
	stosw			; terminator

	mov bx, relocateddata
linkdatarelocation alloc_seg, -2, optional
	mov dx, bx
	test bx, bx
	jz @F
	mov dx, [bx]
@@:

	mov si, table_sorted
internaldatarelocation
loop:
	mov di, relocateddata
linkdatarelocation line_out
	lodsw
	test ax, ax
	jz .done
	push si
	push ax
	lodsw
	test dx, dx
	jz .nogap
	test ax, ax
	jz .nogap
	xchg bx, ax
	mov ax, [bx]
	cmp dx, ax
	jae .nogap
	call gap
.nogap:
	pop si
	extcallcall copy_single_counted_string
	pop si
	lodsw
	test ax, ax
	jnz @F
	add si, 4
	push si
	mov si, msg.none
internaldatarelocation
.next_string:
	extcallcall copy_single_counted_string
	xor dx, dx
	pop si
	jmp .next

@@:
	xchg bx, ax
	mov cx, relocateddata + 26
linkdatarelocation line_out
	sub cx, di
	jbe @F
	mov al, 32
	rep stosb
@@:
	mov ax, [bx]
	mov dx, ax
	extcallcall hexword
	push si
	mov si, msg.address.1
internaldatarelocation
	extcallcall copy_single_counted_string
	pop si
	lodsw
	lodsw
	test ax, ax
	jnz @F
	push si
	mov si, msg.nonesize
internaldatarelocation
	jmp .next_string

@@:
	push dx
	push si
	mov si, msg.size.1
internaldatarelocation
	extcallcall copy_single_counted_string
	xchg bx, ax
	mov ax, [bx]
	extcallcall hexword
	mov si, msg.size.2
internaldatarelocation
	extcallcall copy_single_counted_string
	xor dx, dx
	mov cx, 1
	mov bx, 9
	extcallcall disp_dxax_times_cx_width_bx_size.store
	pop si
	pop dx
	add ax, 15
	shr ax, 1
	shr ax, 1
	shr ax, 1
	shr ax, 1
	add dx, ax
.next:
	push dx
	extcallcall putsline_crlf
	pop dx
	jmp loop

.done:
loop_done:

	mov bx, relocateddata
linkdatarelocation alloc_seg, -2, optional
	test bx, bx
	jz .nogap
	mov ax, [bx]
	mov bx, relocateddata
linkdatarelocation alloc_size, -2, optional
	test bx, bx
	jz .nogap
	add ax, [bx]
	test dx, dx
	jz .nogap
	cmp dx, ax
	jae .nogap
	call gap
.nogap:


display_alloc:
	mov dx, msg.alloc
internaldatarelocation
	extcallcall putsz

	mov bx, relocateddata
linkdatarelocation alloc_seg, -2, optional
	test bx, bx
	jnz @F
	mov si, msg.none
.eol_string:
internaldatarelocation
	extcallcall copy_single_counted_string
	jmp .eol

@@:
	mov ax, [bx]
	extcallcall hexword
	mov si, msg.address.1
internaldatarelocation
	extcallcall copy_single_counted_string

	mov bx, relocateddata
linkdatarelocation alloc_size, -2, optional
	test bx, bx
	jnz @F
	mov si, msg.nonesize
internaldatarelocation
	jmp .eol_string

@@:
	mov ax, [bx]
	call parasize
.eol:
	extcallcall putsline_crlf


historysize:
	lframe none
	lenter
	mov byte [history_data_entry], 0
internaldatarelocation -3
	mov ax, relocateddata
linkdatarelocation historyformat, -2, optional
	test ax, ax
	jnz @F
	mov dx, msg.history_none
internaldatarelocation
.putsz_end:
	extcallcall putsz
	jmp .end

@@:
	mov dx, msg.history_data_entry
internaldatarelocation
	cmp ax, 2
	jb .in_data_entry
	mov dx, msg.history_separate
internaldatarelocation
	je .in_separate

	mov dx, msg.history_unknown
internaldatarelocation
	jmp .putsz_end

.in_data_entry:
	not byte [history_data_entry]
internaldatarelocation
.in_separate:
	extcallcall putsz
	mov bx, relocateddata
linkdatarelocation history.last, -2, optional
	mov dx, relocateddata
linkdatarelocation history.first, -2, optional
	test bx, bx
	jz @F
	test dx, dx
	jnz @FF

@@:
.missing:
	mov dx, msg.history_missing
internaldatarelocation
	jmp .putsz_end

@@:
	mov di, relocateddata
linkdatarelocation line_out
	mov si, msg.history.1
internaldatarelocation
	extcallcall copy_single_counted_string
	xchg dx, bx
	mov ax, [bx]
	xchg dx, bx
	sub ax, [bx]
	shr ax, 1
	extcallcall decword
	push ax
	mov si, msg.history.2
internaldatarelocation
	extcallcall copy_single_counted_string
	mov bx, [bx]
	rol byte [history_data_entry], 1
internaldatarelocation
	jc .not_seg
	push bx
	mov bx, relocateddata
linkdatarelocation history.segorsel, -2, optional
	test bx, bx
	jz .missing
	mov ds, word [bx]
	pop bx
.not_seg:
	mov ax, [bx]
	 push ss
	 pop ds
	pop cx
	add ax, cx
	add ax, cx
	push cx
	inc ax
	inc ax
	extcallcall decword
	push ax
	mov si, msg.history.3
internaldatarelocation
	extcallcall copy_single_counted_string
	mov bx, dx
	mov ax, [bx]
	rol byte [history_data_entry], 1
internaldatarelocation
	jnc .not_entry
	push bx
	mov bx, relocateddata
linkdatarelocation historybuffer, -2, optional
	test bx, bx
	jz .missing
	sub ax, bx
	pop bx
.not_entry:
	inc ax
	inc ax
	extcallcall decword
	pop ax
	pop dx
	test dx, dx
	jnz @F

	mov si, msg.history.average.none
internaldatarelocation
	jmp .string_end

@@:
	mov si, msg.history.average.1
internaldatarelocation
	extcallcall copy_single_counted_string

	xor cx, cx
	xchg cx, dx
	div cx
	test dx, dx
	jz @F
	inc ax
@@:
	extcallcall decword
	mov si, msg.history.average.2
internaldatarelocation
.string_end:
	extcallcall copy_single_counted_string
	extcallcall putsline_crlf
.end:
	lleave , forcerestoresp


stacksize:
	mov di, relocateddata
linkdatarelocation line_out
	mov bx, relocateddata
linkdatarelocation stack, -2, optional
	mov dx, relocateddata
linkdatarelocation stack_end, -2, optional
	test bx, bx
	jz @F
	test dx, dx
	jnz @FF
@@:
	mov si, msg.stack.none
internaldatarelocation
	jmp .string_end

@@:
	mov si, msg.stack.1
internaldatarelocation
	extcallcall copy_single_counted_string
	mov ax, dx
	sub ax, bx
	extcallcall decword
	mov si, msg.stack.2
internaldatarelocation
	extcallcall copy_single_counted_string
	mov al, [bx]
	extcallcall hexbyte
	mov si, msg.stack.3
internaldatarelocation
	extcallcall copy_single_counted_string
	xchg di, bx
	mov cx, -1
	repe scasb
	not cx
	dec cx
	xchg ax, cx
	xchg di, bx
	extcallcall decword
	mov si, msg.stack.4
internaldatarelocation

.string_end:
	extcallcall copy_single_counted_string
	extcallcall putsline_crlf


display_eld_memory:
	mov dx, msg.eld.1
internaldatarelocation
	extcallcall putsz

	xor ax, ax
.loop:
	mov di, relocateddata
linkdatarelocation line_out
	cmp word [relocateddata], ax
linkdatarelocation extseg_used
	ja @F

	xor bp, bp
	mov dx, word [relocateddata]
linkdatarelocation extseg_size
	sub dx, ax
	xor bx, bx
	xor cx, cx
.free:
	 push ss
	 pop ds
	push cx
	mov si, msg.eld.free
internaldatarelocation
	extcallcall copy_single_counted_string
	pop cx
	jmp .have

@@:
	mov bx, relocateddata
linkdatarelocation extdssel, -2, optional
	extcallcall ispm
	jz @F
	mov bx, relocateddata
linkdatarelocation extseg, -2, optional
@@:
	test bx, bx
	jnz @F
.error:
	mov dx, msg.eld.error
internaldatarelocation
	extcallcall putsz
	jmp .end

@@:
	mov es, word [bx]
	mov bx, ax
	cmp word [es:bx + eldiStartCode], ax
	jne .error
	mov dx, ax
	add dx, ELD_INSTANCE_size
	jc .error
	cmp word [es:bx + eldiEndCode], dx
	jb .error
	mov dx, word [relocateddata]
linkdatarelocation extseg_used
	cmp word [es:bx + eldiEndCode], dx
	ja .error
	je @F
	sub dx, ELD_INSTANCE_size
	jc .error
	cmp word [es:bx + eldiEndCode], dx
	ja .error
@@:
	mov dx, word [es:bx + eldiEndCode]
	mov bp, dx
	sub dx, ax
	jc .error
	push word [es:bx + eldiStartData]
	push bx
	mov bx, word [es:bx + eldiEndData]
	pop si
	testopt [es:si + eldiFlags], eldifResident
	lea si, [si + eldiIdentifier]
	push es
	pop ds
	 push ss
	 pop es
	pop cx
	jz .free
	push cx
	push ax
	mov al, '"'
	stosb
	mov cx, 4
	rep movsw
	stosb
	pop ax
	 push ss
	 pop ds
	pop cx
.have:
	mov si, msg.eld.2
internaldatarelocation
	push bx
	call display_eld_size
	pop bx

	mov ax, bx
	sub ax, cx
	jz .next
	xchg dx, ax
	mov ax, cx
	mov si, msg.eld.5
internaldatarelocation
	call display_eld_size

.next:
	extcallcall putsline_crlf
	test bp, bp
	mov ax, bp
	jnz .loop
.end:

	mov di, relocateddata
linkdatarelocation line_out
	mov ax, word [relocateddata]
linkdatarelocation extdata_used
	mov dx, word [relocateddata]
linkdatarelocation extdata_size
	sub dx, ax
	jz @F
	add ax, [relocateddata]
linkdatarelocation extdata
	mov si, msg.eld.6
internaldatarelocation
	call display_eld_size
	extcallcall putsline_crlf
@@:


display_eld_variables:
	mov di, relocateddata
linkdatarelocation line_out

	mov si, msg.var.format
internaldatarelocation
	extcallcall copy_single_counted_string

	mov ax, relocateddata
linkdatarelocation ext_var_format
	cmp ax, 1
	je .known

.unknown:
	mov di, msg.varunknown.format
internaldatarelocation
	extcallcall hexword

	mov dx, msg.varunknown
internaldatarelocation
	extcallcall putsz
	jmp .end

.known:
	extcallcall hexword

	mov si, msg.var.size
internaldatarelocation
	extcallcall copy_single_counted_string

	mov ax, relocateddata
linkdatarelocation ext_var_size

	extcallcall hexword
	xchg dx, ax

	mov si, msg.var.amount
internaldatarelocation
	extcallcall copy_single_counted_string

	xor bx, bx
	mov cx, relocateddata
linkdatarelocation ext_var_amount
	push cx
	jcxz .done

	push di
	mov di, relocateddata
linkdatarelocation ext_var
	mov si, relocateddata
linkdatarelocation isvariable_morebyte_nameheaders.ext
.loop:
	cmp word [di], 0
	je .next
	inc bx
.next:
	add di, dx
	lodsw
	loop .loop
	pop di
.done:

	xchg ax, bx
	extcallcall decword

	mov si, msg.var.amountbetween
internaldatarelocation
	extcallcall copy_single_counted_string

	pop ax
	extcallcall decword

	mov si, msg.var.amountafter
internaldatarelocation
	extcallcall copy_single_counted_string
	extcallcall putsline_crlf
.end:


end:
	retn


		; INP:	si -> first string
		;	ax = start
		;	dx = length
display_eld_size:
	push cx
	extcallcall copy_single_counted_string
	call hexword
	mov si, msg.eld.3
internaldatarelocation
	extcallcall copy_single_counted_string
	add ax, dx
	call hexword
	mov si, msg.eld.4
internaldatarelocation
	extcallcall copy_single_counted_string
	mov ax, dx
	call hexword
	mov si, msg.size.2
internaldatarelocation
	extcallcall copy_single_counted_string
	xor dx, dx
	mov cx, 1
	mov bx, 9
	extcallcall disp_dxax_times_cx_width_bx_size.store
	pop cx
	retn


parasize:
	mov si, msg.size.1
internaldatarelocation
	extcallcall copy_single_counted_string
	mov cl, 4
	push ax
	mov dx, ax
	rol ax, cl
	test al, 15
	jz @F
	dec di
	extcallcall hexnyb
@@:
	xchg ax, dx
	shl ax, cl
	extcallcall hexword
	mov si, msg.size.2
internaldatarelocation
	extcallcall copy_single_counted_string
	pop ax
	xor dx, dx
	mov cx, 16
	mov bx, 9
	extcallcall disp_dxax_times_cx_width_bx_size.store
	retn


		; INP:	dx => end of prior
		;	ax => start of next
gap:
	push dx
	neg dx
	add dx, ax
	mov si, msg.gap
internaldatarelocation
	extcallcall copy_single_counted_string
	pop ax
	extcallcall hexword
	mov si, msg.address.1
internaldatarelocation
	extcallcall copy_single_counted_string
	xchg ax, dx
	call parasize
	extcallcall putsline_crlf
	mov di, relocateddata
linkdatarelocation line_out
	retn


	eldcall_dump_callcall ELDCALL_CALLCALL_LIST

endinstalled equ ($ + CODEFIXUP + 15) & ~15


start:
	mov bx, es
	 push ss
	 pop es
	call skipcomma
	dec si
	mov dx, relocateddata
linkdatarelocation msg.install
	call isstring?
	je install
; linkdatarelocation msg.run
;	call isstring?

	call run
	call uninstall_oneshot
	xor ax, ax
	retf


uninstall_oneshot:
	testopt [ss:relocateddata], 1
linkdatarelocation options7, -3
	jnz @F

	mov ax, word [cs:code + eldiEndCode]
internalcoderelocation
	sub ax, word [cs:code + eldiStartCode]
internalcoderelocation
	sub word [relocateddata], ax
linkdatarelocation extseg_used

	mov ax, word [cs:code + eldiEndData]
internalcoderelocation
	sub ax, word [cs:code + eldiStartData]
internalcoderelocation
	sub word [relocateddata], ax
linkdatarelocation extdata_used
@@:
	retn


install:
	lodsb
	extcall chkeol

	houdini
	mov es, bx		; => ext seg (writable)
	mov ax, endresident - endinstalled
	sub word [es:code + eldiEndCode], ax
internalcoderelocation		; adjust size
	sub word [relocateddata], ax
linkdatarelocation extseg_used	; adjust size
	mov bx, word [relocateddata]
linkdatarelocation ext_command_handler
				; -> prior
	mov di, command		; -> our handler
internalcoderelocation
	test bx, bx		; installing as first ?
	jz .only_first		; yes, simple --> (leave as extcall cmd3_not_ext)
	scasw			; skip entrypoint jmp strict short
	mov al, 0E9h		; = jmp near opcode
	stosb			; store
	xchg ax, bx		; ax -> next handler
	sub ax, di
	dec ax
	dec ax			; ax = ax - (di + 2)
	stosw			; store our downlink as rel16 displacement

.only_first:
	setopt [es:code + eldiFlags], eldifResident
internalcoderelocation -3	; mark block as resident
	mov word [relocateddata], command
linkdatarelocation ext_command_handler, -4
internalcoderelocation		; -> our entrypoint

	testopt [relocateddata], 4
linkdatarelocation options7, -3
	jnz @F
	mov dx, msg.installed
internaldatarelocation
	call putsz
@@:
	xor ax, ax
	retf


DATAOFFSET equ CODEOFFSET + code_size
	addsection DATA, follows=CODE vstart=_ELD_DATA_VSTART
%define DATAFIXUP - datastart + 0
datastart:

%rep _ELD_BUG
	dw msg.ldmem			; missing internaldatarelocation
%endrep

	align 8, db 0
table:
.:
	dw msg.entryseg
internaldatarelocation
	dw relocateddata
linkdatarelocation pspdbg, -2, optional
	dw 0
	dw relocateddata
linkdatarelocation entryseg_size, -2, optional

	dw msg.messageseg
internaldatarelocation
	dw relocateddata
linkdatarelocation messageseg, -2, optional
	dw 0
	dw relocateddata
linkdatarelocation messageseg_size, -2, optional

	dw msg.auxbuffseg
internaldatarelocation
	dw relocateddata
linkdatarelocation auxbuff_segment, -2, optional
	dw 0
	dw relocateddata
linkdatarelocation auxbuff_current_size, -2, optional

	dw msg.codeseg
internaldatarelocation
	dw relocateddata
linkdatarelocation code_seg, -2, optional
	dw 0
	dw relocateddata
linkdatarelocation code_size, -2, optional

	dw msg.code2seg
internaldatarelocation
	dw relocateddata
linkdatarelocation code2_seg, -2, optional
	dw 0
	dw relocateddata
linkdatarelocation code2_size, -2, optional

	dw msg.historyseg
internaldatarelocation
	dw relocateddata
linkdatarelocation history_segment, -2, optional
	dw 0
	dw relocateddata
linkdatarelocation historyseg_size, -2, optional

	dw msg.extseg
internaldatarelocation
	dw relocateddata
linkdatarelocation extseg, -2, optional
	dw 0
	dw relocateddata
linkdatarelocation extseg_size, -2, optional

	dw msg.envseg
internaldatarelocation
	dw relocateddata
linkdatarelocation envseg, -2, optional
	dw 0
	dw relocateddata
linkdatarelocation env_size, -2, optional
.end:
.amount equ (.end - .) / 8

	dw 0

history_data_entry:
	db 0

msg:
.ldmem:			asciz "LDMEM"
.uninstall_done:	asciz "LDMEM uninstalled. (Don't forget to use reclaim.eld)",13,10
.uninstall_error:	asciz "LDMEM unable to uninstall!",13,10
.entryseg:	counted "Entry segment: "
.messageseg:	counted "Message segment: "
.codeseg:	counted "First code segment: "
.code2seg:	counted "Second code segment: "
.auxbuffseg:	counted "Auxiliary buffer segment: "
.historyseg:	counted "History segment: "
.extseg:	counted "ELD code segment: "
.envseg:	counted "Environment segment: "
.none:		counted "None (Segment data not available.)"
.nonesize:	counted "Size data not available."
.address.1:	counted "  "
.size.1:	counted "Size:  "
.size.2:	counted "  "
.alloc:		fill 26, 32, db "Total allocation: "
		asciz
.gap:		db .gap.end - ($ + 1)
		fill 26, 32, db "Gap: "
.gap.end:
.history_none:		asciz 13,10,"No history format link found.",13,10
.history_data_entry:	asciz 13,10,"History in data entry section.",13,10
.history_separate:	asciz 13,10,"History in a separate segment.",13,10
.history_unknown:	asciz 13,10,"Unknown history format.",13,10
.history_missing:	asciz "History last or first displacement or segment missing.",13,10
.history.1:		counted "History entries: "
.history.2:		counted 13,10,"History bytes: "
.history.3:		counted " used / "
.history.average.1:	counted " total",13,10,"Average history entry size is <= "
.history.average.2:	counted " bytes."
.history.average.none:	counted " total",13,10,"Cannot calculate average, no history entries."
.stack.none:		counted 13,10,"No stack link found.",13,10
.stack.1:		counted 13,10,"Stack size: "
.stack.2:		counted " bytes",13,10,"Heuristic match byte: "
.stack.3:		counted "h",13,10,"Heuristic unused stack: "
.stack.4:		counted " bytes",13,10
.eld.1:			asciz "Loaded ELDs:",13,10
.eld.error:		asciz "Error during ELD enumeration.",13,10
.eld.free:		counted "Free space"
.eld.2:			counted ", code start "
.eld.3:			counted ", stop "
.eld.4:			counted ", size "
.eld.5:			db .eld.5.end - ($ + 1)
			db 13,10
			times 8 + 2 + 2 db 32
			db "Data start "
.eld.5.end:
.eld.6:			counted "Free space, data start "
.var.format:		counted 13,10,"Ext variables format="
.var.size:		counted "h, structure size="
.var.amount:		counted "h",13,10,"Amount ext variables: "
.var.amountbetween:	counted " used / "
.var.amountafter:	counted " total"
.varunknown:		db 13,10,"Unknown ext variables format="
.varunknown.format:	asciz "----h",13,10

uinit_data: equ $
.installed:		asciz "LDMEM installed.",13,10

	align 16, db 0
data_size equ $ - datastart

	absolute uinit_data
	alignb 8
table_sorted:
	resb 8 * table.amount + 2

	alignb 16
uinit_data_end:

total_data_size equ $ - datastart
%assign _DATA_SIZE total_data_size

	usesection CODE

%include "eldlink.asm"

	align 16
code_size equ $ - code
