perm filename BAILDD.FAI[NEW,AIL] blob sn#408274 filedate 1979-01-08 generic text, type C, neo UTF8
C00001 00001
C00002 00002		title SDDT - makes BAIL your DDT
C00007 ENDMK
	title SDDT - makes BAIL your DDT
comment \
.r maklib
               ↑        ↑ this file
               ↑ block structure ddt
The purpose of this is so that ↑C DDT will work in the case
DDT (POPJ 17,$X to return)
	.load sys:bail
	external .jbsa,.jbopc,sailor,bail,.uinit,ddbail,.jbrel,.jbhrl,ddt
	internal sddt
	loc .jbddt	;make this program DDT
	,sddt		;our starting address
	loc .jbcst	;and put loc of real ddt here for bail
	reloc 0

sddt:	movem t1,savacs
	movei t1,ddbail	;in future use bail, not us
	setddt t1,
	skipe sailor	;if sailor is set, program has started
	jrst break		;do regular bail break processing
	movem t2,savacs+1 ;otherwise break coord 0 and start
	movem t3,savacs+2
	movei t3,0	;code for setting hi seg write priv
	hrrz t1,.jbsa	;start searching for coordinate 0
	trnn t1,400000	;if in hi segment
	jrst nothi
	setuwp t3,	; then set hi seg write priv
	 jrst go	;  if we can't, forget all this
	movem t3,olduwp	;save for later since we need t3
nothi:	hrrz t3,.jbrel	;upper limit for seaach - highest legal addr
	trne t1,400000	;unless we are in high seg
	hrrz t3,.jbhrl	;then use high seg limit
next:	move t2,(t1)	;look at program
	camn t2,[pushj p,.uinit]	;find coordinate 0
	jrst found
	camge t1,t3	;reached upper limit?
	aoja t1,next	;no - go on
	jrst go		;can't find it, so forget all this

found:	move t2,[pushj p,bailst]	;replace coord 0 with a break
	movem t2,(t1)
	move t3,olduwp	;get back old high-seg protection
	trne t1,400000	;if in high segment
	setuwp t3,	;set hi seg write prot back the way it was

go:	move t3,savacs+2
	move t2,savacs+1
	hrrz t1,.jbsa	;have to strip off LH(.JBSA) for indirect jrst
	exch t1,savacs
	jrst @savacs	;now start main program

bailst:	pushj p,.uinit	;here at initial break - do what was there
	move t1,[pushj p,.uinit]	;then remove the break
	move t2,(p)	;this is return addr = addr of break+1
	movei t3,0	;clear hi seg prot if needed
	trnn t2,400000	;see if hi segment
	 jrst nothigh
	setuwp t3,	;now clear protection
	 jrst bail	;can't, forget all this
nothigh: movem t1,-1(t2) ;restore the broken location
	trne t2,400000	;and restore hi seg write protection
	setuwp t3,
	jrst bail	;now make bail think it was called
			;from coordinate 0

break:	movei t1,savacs	;here if program already started
	jrst ddbail	;and let bail handle it

ddlink:	movem t1,savacs	;here if bail trying to call ddt
	movei t1,ddt	;set so ddt command is in right context
	setddt t1,
	move t1,savacs
	pushj p,ddt	;now it is safe to goto ddt
	movem t1,savacs	;here on return from ddt
	movei t1,ddbail	;reset to sail context
	setddt t1,
	move t1,savacs
	popj p,		;return to bail

savacs:	block 3
olduwp:	block 1