[comp.sources.amiga] v90i278: GDosTool - test/set memory location 0, Part01/01

amiga-request@abcfd20.larc.nasa.gov (Amiga Sources/Binaries Moderator) (10/15/90)

Submitted-by: "John Davis,chem dept, UoC NZ" <CHEM194@canterbury.ac.nz>
Posting-number: Volume 90, Issue 278
Archive-name: util/gdostool/part01

[ uuencoded executable and icons enclosed  ...tad ]

A tiny utility that will tell you (via a requester) whether memory
location 0 is set to a non-zero value, and give you an option to
either clear it, or set it to a 'problem' value. The first option
is handy for people with 2091s and A590s, which have been known
to set $0="GDOS", the facility to set $0='GDOS' is handy for 
software authors wishing to make sure their programs aren't
accidentally (either thru nil pointers or dropped #'s in assembler)
using $0 as a pointer.

#!/bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 1)."
# Contents:  gdostool.doc gdostool.s gdostool.s.uu gdostool.uu
#   gdostool0.uu gdostool1.uu
# Wrapped by tadguy@abcfd20 on Sun Oct 14 14:19:23 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'gdostool.doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gdostool.doc'\"
else
echo shar: Extracting \"'gdostool.doc'\" \(1285 characters\)
sed "s/^X//" >'gdostool.doc' <<'END_OF_FILE'
XGdosTool - By J Davis 08/1990
X
XWhy
X---
X
XAn  easy  mistake  to make when progrmming in assembler is to accidentally
Xuse  $0 (the value in memory location $0) where you mean #$0 (the constant
Xvalue  zero).   A  subtle  mistake - one not aided by the fact that memory
Xloaction  0  often holds 0, so it will yield the right results.  
X
XThe first you notice of this problem is when your code is run on some a590
Xequipped  500's  ,  or  2000s with 2091 controllers, where $0 may actually
Xhold  the  string  'GDOS'.  The same situation can also occur in most high
Xlevel languages, by de-referencing a NIL pointer.
X
XThe  result  can  be anything from small errors upto a full blown GURU (if
Xthe  code  tries  to  de-ref  $0  as a pointer to a word - it will yield a
Xnon-word aligned word access)
X 
XThis is a common problem (other programs that have trouble with a non zero
Xlocation  0  are  virusx4,  lharc1.20,  execellence  1.11,  Jrcomm 1.0 and
Xseveral others).
X 
XBy  using  this tool you can set location zero to a 'problem' value before
Xtesting  your code - this will hopefully make the release of programs with
Xsuch 'mistakes' less common.
X 
XYou  can  also  set  it  back  to  $0000000 - useful after you've finished
Xtesting, and also potentially useful for people with a590s or 2091s.
X
END_OF_FILE
if test 1285 -ne `wc -c <'gdostool.doc'`; then
    echo shar: \"'gdostool.doc'\" unpacked with wrong size!
fi
# end of 'gdostool.doc'
fi
if test -f 'gdostool.s' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gdostool.s'\"
else
echo shar: Extracting \"'gdostool.s'\" \(3694 characters\)
sed "s/^X//" >'gdostool.s' <<'END_OF_FILE'
X; program to allow user examination and setting of ($0)
X; 
X; allows both simulation of the $0='GDOS' phenomena on some a590s and
X; 2091s ( useful for testing code for nil pointer de-references and
X; incorrect use of $0 when it should be #$0
X;
X; also allows clearing of $0, either to remove settings from previous
X; use, or due to the a590/2091 itself
X
Xforbid		equ	-$084	; offsets for various exec and int calls
Xgetmsg		equ	-$174	; saves long includes and compile times
Xreplymsg	equ	-$17a
Xwaitport	equ	-$180
Xfindtask	equ	-$126
Xautoreq		equ	-$15c
Xopenlib		equ	-$228
Xcloselib	equ	-$19e
X
Xpr_cli		equ	$0Ac	; process cli flag offset
Xpr_msgport	equ	$05c	; process msgport offset
X
Xstartup:	move.l	$4,a6
X		move.l	#0,a1
X		jsr	findtask(a6)		; find ourselves
X
X		move.l	d0,a4			; save our process pointer
X
X		move.l	pr_cli(a4),d0
X		bne	fromdos			; was a DOS startup
X
X		; was started from WB
X
X		lea	pr_msgport(a4),a0
X		jsr	waitport(a6)		; wait for startup msg
X		lea	pr_msgport(a4),a0
X		jsr	getmsg(a6)		; get the wb msg
X
X		move.l	d0,wbmsg		; save pointer to our startup msg
X		move.l	#1,wb			; flag we started from wb
X
Xfromdos:	move.l	$0,d0
X		cmp.l	#$0,d0
X		beq	is_zero			; if $0=0 then req already setup
X
X		lea	nzbodytext,a0
X		move.l	a0,ctext		; set so req displays non-zero msg
X		bra	_xx
X
Xis_zero:	lea	zbodytext,a0
X		move.l	a0,ctext
X
X_xx:		lea	intuiname,a1
X		move.l	#0,d0
X		move.l	$4,a6
X		jsr	openlib(a6) 		; open intuition lib
X
X		move.l	d0,a6			; save ibase
X		
X		move.l	#0,a0			; window to display in
X		move.l	#bodyitext,a1		; body text
X		move.l	#yesitext,a2 		; postive text
X		move.l	#noitext,a3  		; negative text
X		move.l	#0,d0			; pflags
X		move.l	#0,d1			; nflags
X		move.l	#640,d2			; width
X		move.l	#50,d3			; height
X		jsr	autoreq(a6)		; request user confirmation
X
X		cmp.l	#0,d0
X		beq	cleargdos		; user selected clear
X
Xsetgdos:	move.l	#"GDOS",$0		; set $0="GDOS"		
X		bra	_n1
X
Xcleargdos:	move.l	#$0,$0
X
X_n1:		move.l	a6,a1			; close intuition lib
X		move.l	$4,a6
X		jsr	closelib(A6)
X		
Xexit:		move.l	wb,d0
X		cmp.l	#$0,d0			; was this a CLI invocation
X		beq	exit_dos
X
X		; workbench exit
X
X		move.l	$4,a6
X		jsr	forbid(a6)		; lock out everyone else
X
X		move.l	wbmsg,a1
X		jsr	replymsg(a6)		; reply to Wbstartup msg
X
Xexit_dos:	move.l	#0,d0			; return with return code 0
X		rts			
X
X;=============================================================
X		
Xwb:		dc.l	0			; run mode flag 0=dos process 1=wbprocess
Xwbmsg:		dc.l	0			; where we save our workbench msg
X
Xintuiname:	dc.b	"intuition.library",0
X
X; stuff for our autorequester
X
Xbodyitext:	dc.b	0	   	; front pen
X		dc.b	1	   	; back pen
X		dc.b	0	   	; draw mode
X		dc.w	0	   	; leftedge
X		dc.w	6	   	; topedge
X		dc.l	0	   	; textattr = default
X		dc.l	bodytext1  	; actual text
X		dc.l	nbodyitext 	; next
X
Xnbodyitext:	dc.b	0	   	; front pen
X		dc.b	1	   	; back pen
X		dc.b	0	   	; draw mode
X		dc.w	0	   	; leftedge
X		dc.w	20	   	; topedge
X		dc.l	0	   	; textattr = default
Xctext:		dc.l	0	  	; actual text
X		dc.l	0	 	; next
X
X
Xyesitext:	dc.b	2		; front pen
X		dc.b	1		; back pen
X		dc.b	0		; draw mode
X		dc.w	4		; leftedge
X		dc.w	4		; topedge
X		dc.l	0		; textattr = default
X		dc.l	yestext		; actual text
X		dc.l	0		; next
X		
Xnoitext:	dc.b	2		; front pen
X		dc.b	1		; back pen
X		dc.b	0		; draw mode
X		dc.w	4		; leftedge
X		dc.w	4		; topedge
X		dc.l	0		; textattr = default
X		dc.l	notext		; actual text
X		dc.l	0		; next		
X
X		; actual text for our requester
X
Xbodytext1:	dc.b	"   SetGDOS by J Davis, 08-1990 v1.0 - an aid to hunting nil pointer de-refs",0
Xzbodytext:	dc.b	"                  Location $0 currently holds a NULL (0) value",0
Xnzbodytext:	dc.b	"                     Location $0 is currently NON-ZERO",0
X
Xyestext:	dc.b	"Set $0='GDOS'",0
Xnotext:		dc.b	"Set $0=NULL",0
X
X		END
END_OF_FILE
if test 3694 -ne `wc -c <'gdostool.s'`; then
    echo shar: \"'gdostool.s'\" unpacked with wrong size!
fi
# end of 'gdostool.s'
fi
if test -f 'gdostool.s.uu' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gdostool.s.uu'\"
else
echo shar: Extracting \"'gdostool.s.uu'\" \(538 characters\)
sed "s/^X//" >'gdostool.s.uu' <<'END_OF_FILE'
Xbegin 666 gdostool.s.info
XMXQ```0```````````"``'``%``,``0#%\-@`````````````````````````&
XM````!```QA]Z`,7OXH````"````````````````````````````@`!P``@#%\
XM[_@#````````````!___^`?___@&$)(8!S.3.`<PQS@',Y,X!S"3.`?___@$G
XM```(!___^`?_?[@'_O-X!_S-.`?Z,M@'_W^X!][S>`<DS3@/FC+8#WO]^`[WY
XMF_@9)FGX'-&6^#____A____X#___^````````````````````````````>]MZ
XMY@#,;,8`SSC&`,QLQ@#/;,8````&`___]@````8``(!&``$,A@`#,L8`!<TF_
XM``"`1@`A#(8`VS+&`&7-+@"$`@X!"&0.!MF6'@,N:1X````^````_@____X#0
XG___^``````````9C.F-E9``````(````#D9)3$5465!%/51E>'0`E
X``
Xend
Xsize 354
END_OF_FILE
if test 538 -ne `wc -c <'gdostool.s.uu'`; then
    echo shar: \"'gdostool.s.uu'\" unpacked with wrong size!
fi
# end of 'gdostool.s.uu'
fi
if test -f 'gdostool.uu' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gdostool.uu'\"
else
echo shar: Extracting \"'gdostool.uu'\" \(1559 characters\)
sed "s/^X//" >'gdostool.uu' <<'END_OF_FILE'
Xbegin 666 gdostool
XM```#\P`````````!``````````````"5```#Z0```)4L>0````0B?`````!.B
XMKO[:*$`@+`"L9@``(D'L`%Q.KOZ`0>P`7$ZN_HPCP````1`C_`````$```$,A
XM(#D`````L+P`````9P``$D'Y```"`2/(```!1F````Y!^0```<(CR````49#-
XM^0```10@/``````L>0````1.KOW8+$`@?``````B?````28D?````4XF?```"
XM`6(@/``````B/``````D/````H`F/````#).KOZDL+P`````9P``$"/\1T1/-
XM4P````!@```,(_P``````````").+'D````$3J[^8B`Y```!#+"\`````&<`,
XM`!8L>0````1.KO]\(GD```$03J[^AB`\`````$YU``````````!I;G1U:71I'
XM;VXN;&EB<F%R>0```0``````!@````````%V```!.@`!```````4````````.
XM`````````@$````$``0````````".``````"`0````0`!`````````)&````8
XM`"`@(%-E=$=$3U,@8GD@2B!$879I<RP@,#@M,3DY,"!V,2XP("T@86X@86ED8
XM('1O(&AU;G1I;F<@;FEL('!O:6YT97(@9&4M<F5F<P`@("`@("`@("`@("`@*
XM("`@("!,;V-A=&EO;B`D,"!C=7)R96YT;'D@:&]L9',@82!.54Q,("@P*2!VB
XM86QU90`@("`@("`@("`@("`@("`@("`@("!,;V-A=&EO;B`D,"!I<R!C=7)R,
XM96YT;'D@3D].+5I%4D\`4V5T("0P/2='1$]3)P!3970@)#`]3E5,3```````4
XM`^P````0`````````"P````V````3````%(```!<````8@```&@```"&````K
XMC````)(```#B````_````3(```$V```!6@```6X````````#\`````%W8@``]
XM```!#`````%?;C$`````U`````%?>'@`````9@````%E>&ET````X`````)C6
XM=&5X=````````48````"=V)M<V<```````$0`````FYO=&5X=``````"1@``K
XM``)F<F]M9&]S`````#H````":7-?>F5R;P````!:`````FYO:71E>'0````!;
XM8@````)S971G9&]S`````+P````"<W1A<G1U<````````````GEE<W1E>'0`&
XM```".`````)E>&ET7V1O<P```00````">65S:71E>'0```%.`````V)O9'EI*
XM=&5X=````````28````#8F]D>71E>'0Q```````!=@````-C;&5A<F=D;W,`!
XM``````#*`````VEN='5I;F%M90```````10````#>F)O9'ET97AT```````!=
XMP@````-N8F]D>6ET97AT``````$Z`````VYZ8F]D>71E>'0``````@$`````K
X$```#\@-NF
X``
Xend
Xsize 1084
END_OF_FILE
if test 1559 -ne `wc -c <'gdostool.uu'`; then
    echo shar: \"'gdostool.uu'\" unpacked with wrong size!
fi
# end of 'gdostool.uu'
fi
if test -f 'gdostool0.uu' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gdostool0.uu'\"
else
echo shar: Extracting \"'gdostool0.uu'\" \(540 characters\)
sed "s/^X//" >'gdostool0.uu' <<'END_OF_FILE'
Xbegin 666 gdostool.doc.info
XMXQ```0```````````"``'``%``,``0#%\-@`````````````````````````&
XM````!```QA]Z`,7OXH````"````````````````````````````@`!P``@#%\
XM[_@#````````````!___^`?___@&$)(8!S.3.`<PQS@',Y,X!S"3.`?___@$G
XM```(!___^`?_?[@'_O-X!_S-.`?Z,M@'_W^X!][S>`<DS3@/FC+8#WO]^`[WY
XMF_@9)FGX'-&6^#____A____X#___^````````````````````````````>]MZ
XMY@#,;,8`SSC&`,QLQ@#/;,8````&`___]@````8``(!&``$,A@`#,L8`!<TF_
XM``"`1@`A#(8`VS+&`&7-+@"$`@X!"&0.!MF6'@,N:1X````^````_@____X#0
XG___^``````````9C.F-E9``````(````#D9)3$5465!%/51E>'0`E
X``
Xend
Xsize 354
END_OF_FILE
if test 540 -ne `wc -c <'gdostool0.uu'`; then
    echo shar: \"'gdostool0.uu'\" unpacked with wrong size!
fi
# end of 'gdostool0.uu'
fi
if test -f 'gdostool1.uu' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gdostool1.uu'\"
else
echo shar: Extracting \"'gdostool1.uu'\" \(532 characters\)
sed "s/^X//" >'gdostool1.uu' <<'END_OF_FILE'
Xbegin 666 gdostool.info
XMXQ```0`````!7@"9`",`$0`%``,``0#"W<``````````````````````````(
XM`````\,`P%-P`````````4X```".``%ZX`````````^@````+@%R`)?__P``F
XM```"0`)_``%=!```````P!*`````````````6@`H_____P`!____Z0``````<
XM`````",`$``"``%\H`,```````!__\````!_X<````!_X<````!_X<````!_R
XM_\````````````````````/ZJ/````/U1'@```/JHC@```/5<1@```.J__@`4
XM``-5__@```*K__@```/___@``````````/____^``/_____``/_____@`/__^
XM___@`/_____@`/_____@`/_____@`/P']0_@`/P.ZH?@`/P=U4?@`/P[BJ?@1
XD`/QW``?@`/SN``?@`,W<``?@`/P```?@``````````````$`?
X``
Xend
Xsize 351
END_OF_FILE
if test 532 -ne `wc -c <'gdostool1.uu'`; then
    echo shar: \"'gdostool1.uu'\" unpacked with wrong size!
fi
# end of 'gdostool1.uu'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have the archive.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
Mail comments to the moderator at <amiga-request@uunet.uu.net>.
Post requests for sources, and general discussion to comp.sys.amiga.