home *** CD-ROM | disk | FTP | other *** search
- /*-----------------------------------------------------------------------*
- * filename - harderr.cas
- *
- * function(s)
- * harderr - establishes a hardware error handler
- * hardresume - hardware error handler function
- * hardreturn - hardware error handler function
- * hentry - calls user error handler
- *-----------------------------------------------------------------------*/
-
- /*[]------------------------------------------------------------[]*/
- /*| |*/
- /*| Turbo C Run Time Library - Version 3.0 |*/
- /*| |*/
- /*| |*/
- /*| Copyright (c) 1987,1988,1990 by Borland International |*/
- /*| All Rights Reserved. |*/
- /*| |*/
- /*[]------------------------------------------------------------[]*/
-
-
- #pragma inline
- #include <dos.h>
-
- static int Hsav;
- static int (*Hfunc)(unsigned di, unsigned ax, unsigned bp, unsigned si);
-
- /*-----------------------------------------------------------------------*
-
- Name hentry - calls user error handler
-
- Usage static void interrupt far hentry(bp, di, si, ds, es,
- dx, cx, bx, ax);
-
- Description calls the user hardware error handler
-
- Return value nothing
-
- *------------------------------------------------------------------------*/
- #pragma argsused
- static void interrupt far hentry(bp, di, si, ds, es, dx, cx, bx, ax)
- {
- Hsav = _SP; /* save the stack pointer */
- ax = (*Hfunc)(di & 0xff, ax, bp, si);
- }
-
-
- /*-----------------------------------------------------------------------*
-
- Name harderr - establishes a hardware error handler
-
- Usage void harderr(int (*fptr)());
-
- Related
- functions usage void hardresume(int rescode);
- void hardretn(int errcode);
-
- Prototype in dos.h
-
- Description harderr establishes a hardware error handler for the
- current program. This handler is invoked whenever an interrupt
- 0x24 occurs. (See the MS-DOS Programmer's Reference Manual for a
- discussion of the interrupt.)
-
- The function pointed to by fptr will be called when such an
- interrupt occurs. The handler function will be called with the
- following arguments:
-
- handler(int errval, int ax, int bp, int si);
-
- errval is the error code set in the DI register by MS-DOS.
- ax, bp, and si are the values MS-DOS sets for the AX,
- BP, and SI registers, respectively.
-
- ax indicates whether a disk error or other device error was
- encountered. If ax is non-negative, a disk error was
- encountered; otherwise, the error was a device error. For a
- disk error, ax ANDed with 0x00FF will give the failing drive
- number (1 = A, 2 = B, etc.).
-
- bp and si together point to the device driver header of
- the failing driver.
-
- The named function is not called directly. harderr establishes
- a DOS interrupt handler that calls the function.
-
- peek and peekb can be used to retrieve device information from
- this driver header. bp is the segment address, and si is
- the offset.
-
- The handler may issue bdos calls 1 through 0xC, but any other
- bdos call will corrupt MS-DOS. In particular, any of the C
- standard I/O or UNIX-emulation I/O calls may not be used.
-
- The driver header may not be altered via poke or pokeb.
-
- The error handler may return or call hardresume to return to
- MS-DOS. The return value of the handler or rescode (result code)
- of hardresume contains an abort (2), retry (1), or ignore (0)
- indicator. The abort is accomplished by invoking DOS interrupt
- 0x23, the control-break interrupt.
-
- The error handler may return directly to the application
- program by calling hardretn.
-
- Return value The handler must return 0 for ignore, 1 for retry,
- and 2 for abort.
-
- Portability Unique to MS-DOS.
-
- See also peek, poke, setjmp
-
- *------------------------------------------------------------------------*/
- void harderr(int (*fptr)())
- {
- Hfunc = fptr;
- setvect(0x24, hentry);
- }
-
-
- /*-----------------------------------------------------------------------*
-
- Name hardresume - hardware error handler function
-
- Usage void hardresume(int rescode);
-
- Prototype in dos.h
-
- Description see harderr
-
- *------------------------------------------------------------------------*/
- void hardresume(int axret)
- {
- _AX = axret;
- _SP = Hsav;
- asm pop bp
- asm pop di
- asm pop si
- asm pop ds
- asm pop es
- asm pop dx
- asm pop cx
- asm pop bx
- asm inc sp; /* Don't restore ax */
- asm inc sp;
- asm iret
- }
-
-
- /*-----------------------------------------------------------------------*
-
- Name hardretn - hardware error handler function
-
- Usage void hardretn(int errcode);
-
- Prototype in dos.h
-
- Description see harderr
-
- *------------------------------------------------------------------------*/
- void hardretn(int retn)
- {
- bdos(0x54,0,0); /* Clean up DOS */
- _AX = retn;
- _BP = _SP = Hsav + 26; /* Restore stack and make it addressable */
- asm or byte ptr 20[bp], 1 /* Set carry flag */
- asm pop bx
- asm pop cx
- asm pop dx
- asm pop si
- asm pop di
- asm pop bp
- asm pop ds
- asm pop es
- asm iret /* Hop back to user */
- }
-
-