perm filename BAILDD.FAI[X,AIL]1 blob sn#245394 filedate 1976-11-04 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002		title SDDT - makes BAIL your DDT
C00006 ENDMK
C⊗;
	title SDDT - makes BAIL your DDT
	.load sys:bail
	t1←←1
	t2←←2
	t3←←3
	p←←17
	.jbddt←74
	external .jbsa,.jbopc,sailor,bail,.uinit,b.
	internal sddt
	loc .jbddt	;make this program DDT
	,sddt		;our starting address
	reloc

sddt:	movem t1,savacs
	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
nothi:	hrli t1,-100	;limit for search
next:	move t2,(t1)	;look at program
	camn t2,[pushj p,.uinit]	;find coordinate 0
	jrst found
	aobjn t1,next	;try again
	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)
	trne t1,400000	;if in high segment
	setuwp t3,	;set hi seg write prot back the way it was
	 jfcl

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,
	 jfcl
	jrst bail	;now make bail think it was called
			;from coordinate 0

break:	movei t1,b.	;here if program already started
	setddt t1,	;we arent needed, make BAIL DDT
	 jfcl
	move t1,savacs
	jrst b.		;and let BAIL handle it
savacs:	block 3
	end