Dec 092017
 
Aid to writting Device Drivers in C.
File DEV_C.ZIP from The Programmer’s Corner in
Category C Source Code
Aid to writting Device Drivers in C.
File Name File Size Zip Size Zip Type
AT&TCLOK.C 2950 1216 deflated
AT&TCLOK.SYS 2048 1111 deflated
DEV.DOC 8064 2610 deflated
DEV.H 2878 1261 deflated
DEV.O 526 383 deflated
EXE2SYS.C 4862 1757 deflated
EXE2SYS.EXE 12288 6247 deflated
MAKECLOK.BAT 107 70 deflated

Download File DEV_C.ZIP Here

Contents of the DEV.DOC file





Device Driver Interface for Desmet C Page 1














DEV

John Birchfield

March 18th, 1986




DEV is a small program and Binder Module which allows you to
create MS DOS (tm) Device Drivers coded in Desmet C. All you
need to do to create a device driver is to write your collection
of device handling routines and bind them into an exe file. You
must have one routine called dev_interrupt () which translates
the DEVICE INTERRUPT call.



BINDING TO DEV.O

Bind the module as follows...

BIND dev , ..., -a -o -Sstackval

where:
, , ... are the names of your .O and
.S files

is the desired name of the .EXE file

Binding with DEV.O as the first module in the bind command
line and using the -a and -s options.
-a tells Bind88 not to hook in to _CSETUP
-s tells Bind88 how much stack to give the program.

You must tell Bind how much stack you want as _CSETUP isn't
invoked. A good figure is -S400 (1k)














Device Driver Interface for Desmet C Page 2




RUNNING EXE2SYS


Run EXE2SYS against the program to create a .SYS file which is
acceptable to MS-DOS/PC-DOS for use as a device driver.

The purpose of DEV.O is to initialize data areas and translate
DOS DEV_INT calls into a function call to dev_interrupt (). At
this time the programmer can use any of the high level constructs
of C except Malloc Realloc type stuff.

Default Initialization is performed to the extent that All memory
past the default Stack Pointer is returned to DOS and the number
of devices the Device Driver will control is set to 1. The
Programmer can override this in his init code if he wishes. To
this end two variables c_s_seg and c_sp are provided for
explicit manipulation of the memory area. the memory map looks
like

CS -> base of C code
DS|SS -> base of data
SP -> top of stack

The amount of stack can be controlled (more or less) by the -S
option of Bind - I would say that a -S400 giving about 1k of
stack should be a good beginning.


Then run EXE2SYS to create the .SYS file

Exe2sys expects input of the following type

Exe2sys [options]

Options char block ioctl
stdin stdout open-rm
clock non-fat till-busy

Use lower case input

filename: the name of your .EXE file

device_title: the name DOS will know your device by - for
example if you were creating a clock device you would use
CLOCK$.

options: tells exe2sys what attributes to set in the device
driver header attribute word - If left off - defaults to
CHARACTER.












Device Driver Interface for Desmet C Page 3




DEV_INTERRUPT ()


Dev_interrupt () is the routine called when the DEV_INTERRUPT
entry of your device driver is invoked. It receives two
parameters, a pointer to the request header and the device
request command number. You may interpret the request header
pointer as either an Offset and Segment or a Long. The command
is an integer. Thus your dev_interrupt function could look
like...

dev_interrupt (rh_off, rh_seg, command)
unsigned rh_offset, rh_segment;
int command;
{
switch (command) {
case INIT: dev_init (rh_off, rh_seg);
case IN: dev_input (rh_off, rh_seg); break;
caee IN_NO_WAIT: dev_input_nw (rh_off, rh_seg); break;
case IN_STATUS: dev_instatus (rh_off, rh_seg); break;
case IN_FLUSH: dev_inflush (rh_off, rh_seg); break;
case OUT: dev_output (rh_off, rh_seg); break;
default: set_error (rh_off, rh_seg); break;
}
}

OR

dev_interupt (rheader, command)
long rheader;
int command;
{
switch (command) {
case INIT: dev_init (rheader);
case MEDIA_CHECK: dev_media_check (rheader); break;
case BUILD_BPB: dev_build_bpb (rheader); break;
case IOCTL_IN: dev_ioctl_in (rheader); break;
case IN: dev_input (rheader); break;
case IN_NO_WAIT: dev_input_nw (rheader); break;
case IN_STATUS: dev_instatus (rheader); break;
case IN_FLUSH: dev_inflush (rheader); break;
case OUT: dev_output (rheader); break;
default: set_error (rheader); break;
}
}

The case values are defined in DEV.H - you supply the commands to
be performed by the action requested.













Device Driver Interface for Desmet C Page 4




DEV.H




*** IF YOU ARE USING A VERSION EARLIER THAN 2.5 ***
*** YOU MAY HAVE TO MODIFY THE DEFINES SOMEWHAT ***

Dev.h provides defines and typedefs which ease access to the
Static Request Header Structure and to more easily manipulate
references to data outside of the Device Driver's current Data
Segment. Two structures are typedefed as follows:


/*
* These defines make it considerably easier to manipulate
* data not in your current data segment
*/

typedef struct {
unsigned offset, seg;
} Far_Ptr;

# define Long_to_Far_Ptr(l, fp) _move (4, &(l), &(fp))
# define Far_Ptr_to_Long(fp, l) _move (4, (fp), (l))


/*
* Pertinent Request Header data...
*/


typedef struct {
char length,
sub_unit,
command_code;
int device_status;
char reserved [8];
} SRH;






















Device Driver Interface for Desmet C Page 5




AT&TCLOK.SYS

A very simple Clock Device Driver called, appropriately
enough, AT&TCLOK.SYS is provided as a simple example. This
Device Driver is also useful if you wish to have access to the
Real Time Clock of the AT&T 6300 and run PC DOS 3.x.

To create AT&TCLOK.SYS, enter the following commands...

C88 AT&TCLOK

BIND DEV AT&TCLOK -a -oAT&TCLOK -S400

EXE2SYS AT&TCLOK CLOCK$ char clock

You will then have a working copy of AT&TCLOK.SYS.



Desmet is a trademark of C-Ware Corp.
PC-DOS is a trademark of International Business Machines Corp.
AT&T is a trademark of American Telephone & Telegraph Corp.
MS-DOS is a trademark of MicroSoft Corp.




































orp.
MS-DOS is a trademark of MicroSoft Corp.
































 December 9, 2017  Add comments

Leave a Reply