[alt.msdos.programmer] Propagating Device Driver error status into C runtime errno variable.

venkat@matrix.UUCP (D Venkatrangan) (08/21/90)

Greetings MS-DOS programmers:

I am writing an installable device driver for DOS 3.0.  It is a character
device which will support read, write and close calls.  I.e., INT 21h functions
AH=3Eh, AH=3Fh and AH=40h.  In the case where there are no errors, I have it
working correctly.

The strategy routine saves ES and BX in current code segment.  Then the
interrpt routine gets this saved address and calls the appropriate function.
When it is done, es:[bx].status is set to the DONE (0x100h) value.

If there are errors however, I would like to make sure that one out of a large
number of error numbers is set.  Basically, I want to make sure that the
code that did the INT 21h gets a Carry Flag that is set and an error code
that is set in AX to a particular error.  But setting the Carry Flag before
returning from the interrupt strategy routine does not seem to help.  It looks
like a lot of processing happens after the return from the driver's
interrupt routine up to the IRET from the int 21h.  During this processing the
carry flag gets cleared.  Also, the C runtime
library functions read(), write() and close() which originally issued the
INT 21h appear to expect the Carry Flag to be set, with an error number only
in AH with AL set to zero.  If this is the case, the C runtime implementation
of read() etc. transfers the error value from AH into the errno variable.

Who sets the Carry Flag for the return from int21h and what should the driver's
interrupt routine do for that flag to be set?

Setting es:[bx].status to 8000h OR'ed with a byte of error code in the range
0 to 0Fh causes a message such as "Write Fault Error on Device XXX" to be
displayed.  Instead, I would like to quietly return to the caller of write(),
a value of -1 with errno set to the value.  Or, alternatively, I should be
able to return quetly from the INT 21h with Carry Set and AX = an error code.

Any help in this will be greatly appreciated.

mlord@bwdls58.bnr.ca (Mark Lord) (08/21/90)

In article <163@matrix.UUCP> venkat@matrix.UUCP (D Venkatrangan) writes:
>
>Who sets the Carry Flag for the return from int21h and what should the driver's
>interrupt routine do for that flag to be set?
>
The IRET instruction does an implicit POPF, which restores the carry flag
and all other flags to the values they had before the interrupt.  Instead
of doing an IRET, do a POPF, set the carry flag manually, and then do
the appropriate type of RET   (FAR ?).  Or twiddle the saved carry bit
on the stack before doing an IRET.

Have Fun.
-- 
 ___Mark S. Lord__________________________________________
| ..uunet!bnrgate!bmerh724!mlord | Climb Free Or Die (NH) |
| Ottawa, Ontario.  613-763-7482 | Personal views only.   |
|________________________________|________________________|