home *** CD-ROM | disk | FTP | other *** search
- Date: Fri 18 May 90 19:14:41
- From: tweten@prandtl.nas.nasa.gov
- Subject: overwriting the psp
-
- From: djb@wjh12.harvard.edu (David J. Birnbaum)
-
- >... if it isn't too much trouble, I'd be interested in taking a look
- >at the source for the tsrs you mention.
-
- I've enclosed the source code for my simplest TSR for illustration of the
- following points:
-
- 1. By using the undocumented MS-DOS INT 21 function 52H, you can
- find the beginning of the chain of MS-DOS memory blocks. Run that
- chain and you will find all environment and code blocks in the machine
- (see the code after "blkscn" and the data structure at
- "BLK_HDR_SEGMENT").
-
- This is a better way to find a previously installed copy of a TSR
- than is use of any MS-DOS interrupt such as the MicroSoft-recommended
- "multiplex interrupt", 25H. Even if you use an interrupt MicroSoft has
- "reserved for user programs" all that means is that the inevitable
- collision will be with some third party's program rather than with
- MicroSoft's.
-
- If you run the list of memory blocks, you can string compare some
- portion of the block's contents with your own code. If the string is
- long enough and if it matches, you can bet it is another copy of your
- TSR. The most important considerations in selecting a "signature" to
- compare are to make sure that it is long enough and is unchanging. The
- machine instructions in the resident portion of your program will do
- nicely. Just be sure not to embed any variable data in the comparison
- range, or you'll never find it.
-
- The technique can be used for simple duplicate detection, or can be
- used to pass new parameters to the existing TSR without having to use
- interrupts and risk collisions (see all references to "sibling").
-
- 2. In a TSR, the non-resident code and data should be positioned
- at the end of the program, so their space can be surrendered at initial
- termination (see the code at "START" and "go").
-
- 3. You can deal with the changed addresses of code relocated into
- the tail end of the PSP by modifying CS (see all references to
- "res_offs") before entry to the code, so it compensates for the move.
- That requires that the code be originally assembled at a location an
- even multiple of 16 bytes away from its final destination in the PSP.
- The result may be the "waste" of a few bytes in the initial .COM image
- (range between "START" and "beg_pr"), but you don't care because no
- space is wasted after termination.
-
- Some care must be devoted to the segment registers. In the included
- program, I simply told the assembler not to use any segment registers
- but CS (see assume directive after "_TEXT"). This works well if you
- have few instructions which use another segment register by default;
- MASM will automatically prefix any such instructions with a CS segment
- override.
-
- If there would otherwise be a lot of prefixes, it may be worthwhile
- to save and restore initial contents of some other segment registers,
- and give them new values derived from CS. If you do so, be sure to
- reflect that fact in your "assume" directive.
-
- I hope all this helps. Good luck.
-
- ----------------------------8<--- CUT HERE ---8<--------------------------
- page 58,132
- TITLE Go -- Control (and measure) speed for Heath/Zenith PC
-
- ; (c) Copyright 1987 David E. Tweten
-
- ; All rights reserved. Permission for distribution is granted
- ; provided that no direct commercial advantage is gained, and
- ; provided that this copyright notice appears on all copies.
-
- ; --------------------------------------------------------------------
- ;
- ; Go serves three purposes relating to Dante Bencivengo's "TurboPlus
- ; V2.0" modification to 4.77 MHz Heath/Zenith PCs. It permits FORMAT
- ; and VERIFY ON to work. It also permits the user to speed or slow
- ; the processor. Finally, it measures the processor's speed setting
- ; (primarily for batch file use). "TurboPlus", the predecessor
- ; version of "TurboPlus V2.0", was described in the June, 1986 issue
- ; of REMark, the journal of the Heath/Zenith Users' Group.
- ;
- ; Due to a quirk in the diskette BIOS, errors will occur when a track
- ; format or verify operation is requested at any high speed, or when
- ; any diskette operation is attempted at 8 MHz. The terminate-and-
- ; stay-resident portion of this code will prevent the errors from
- ; occuring by slowing the processor for the duration of the
- ; operation, unless it is already operating at the slow (4.77 MHz)
- ; speed.
- ;
- ; The optional switch for Go can specify the speed to use when not
- ; formatting or verifying a floppy disk. It can be "f", which will
- ; set the clock speed to fast, or it can be "s", which will set the
- ; clock speed to slow. In any but its initial (TSR installing) call,
- ; if no switch is given, Go does not change the speed setting. On
- ; the initial call, if no argument is given, Go assumes "f". Go uses
- ; whatever switch character is current.
- ;
- ; The termination code for Go is set according to the processor speed
- ; at call, and by whether or not it has previously been called. The
- ; meaning of its termination code is as follows:
- ;
- ; 0 - Go has been called before so the TSR portion is already
- ; resident. Before the call the clock was set to run at
- ; 4.77 MHz.
- ;
- ; 1 - Go has been called before so the TSR portion is already
- ; resident. Before the call the clock was set to run at
- ; its fast speed.
- ;
- ; 2 - Go has not been called before. This call installed the TSR
- ; code and set the clock speed to the specified value (either
- ; Fast or Slow). If no speed was specified on the call, the
- ; default of Fast was used.
- ;
- ; 3 - Go has been called in error. It did nothing.
- ;
- ; NOTE that the actual processor speed is the slower of the speed
- ; specified and detected by Go, and the speed specified by the
- ; hardware switch included in the "TurboPlus V2.0". The actual speed
- ; is indicated by the LED included with the "TurboPlus V2.0" package.
- ;
- ; Written by: David E. Tweten <tweten@prandtl.nas.nasa.gov>
- ;
- ; 12141 Atrium Drive
- ; Saratoga, CA 95070
- ;
- ; (408) 446-4131
- ;
- ; Inspiration: FV.COM, a program of unstated authorship, included on
- ; the "TurboPlus" software disk.
- ;
- ; Modification History:
- ;
- ; 1.0 5-10-87 Initial version.
- ;
- ; --------------------------------------------------------------------