[comp.os.msdos.programmer] Writing a device driver in TP

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (05/29/91)

I've heard (and said!) repeatedly that it's impossible to write a DOS device
driver in Turbo Pascal.  Not true - I've written a simple one entirely in
TP 6, and uploaded it to garbo.uwasa.fi (TPDEV.ZIP).  It would be harder,
but probably possible, to do the same thing in earlier versions of TP.
I imagine it would require careful byte counting, external assembler code,
patching, or some other trick I can't think of.  TP 6 has the inline
assembler, assembler procedures, and allows constants to be initialized with
the address of code, so it was relatively easy there.

Take a look at it.   It makes prototyping a device driver much easier than
writing it from scratch in assembler.

One limitation:  it produces .EXE format drivers.  I asked the other day about
limitations on these, and got two responses:

 - They work in MSDOS, but not PCDOS, because the .EXE loader is part of
   COMMAND.COM in PCDOS.
 - They only work in version 3 or higher.

Thanks to those who responded!  I can confirm that the .EXE format is
fine in MSDOS 3.2, but haven't tested it anywhere else.

Duncan Murdoch
dmurdoch@watstat.waterloo.edu

valley@gsbsun.uchicago.edu (Doug Dougherty) (05/30/91)

This has nothing to do with the original post, but...

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:

> - They [.EXE format device drivers] work in MSDOS, but not PCDOS,
	because the .EXE loader is part of COMMAND.COM in PCDOS.
really??? ---------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> - They only work in version 3 or higher.

That's interesting.  Does this mean that you can't exec() a .EXE file
directly (from another program) in PC/DOS?  (I.e., that you would have
to run it via system() ?)
--

	(Another fine mess brought to you by valley@gsbsun.uchicago.edu)

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (05/30/91)

In article <1991May30.002543.13967@midway.uchicago.edu> valley@gsbsun.uchicago.edu (Doug Dougherty) writes:
>This has nothing to do with the original post, but...
>
>dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:
>
>> - They [.EXE format device drivers] work in MSDOS, but not PCDOS,
>	because the .EXE loader is part of COMMAND.COM in PCDOS.
>really??? ---------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>> - They only work in version 3 or higher.
>
>That's interesting.  Does this mean that you can't exec() a .EXE file
>directly (from another program) in PC/DOS?  (I.e., that you would have
>to run it via system() ?)

I haven't tested either claim, but the first one is kind of hard to believe.
In fact, my PC DOS 3.1 tech ref manual specifically mentions that .EXE format
device drivers are allowed, though it doesn't say much about them.  However,
I have heard it before, so the tech ref could be wrong.

As to the exec() question:  the version I heard was that the loader was part
of the resident part of COMMAND.COM, so it'll handle the EXEC service.
I'd love to here from someone who uses PC DOS whether this limitation is real
or just folklore.

Duncan Murdoch
dmurdoch@watstat.waterloo.edu

valley@gsbsun.uchicago.edu (Doug Dougherty) (05/30/91)

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:

(Question as to which chunk of PCDOS handles EXE file conversion)

>As to the exec() question:  the version I heard was that the loader was part
>of the resident part of COMMAND.COM, so it'll handle the EXEC service.
>I'd love to here from someone who uses PC DOS whether this limitation is real
>or just folklore.

Yes.  That would explain it.  But what about people who load an
alternate shell via SHELL= (e.g., MKS Korn shell, 4DOS, etc) ? How do they
run .EXE's under PCDOS?
--

	(Another fine mess brought to you by valley@gsbsun.uchicago.edu)

luns@spocom.guild.org (Luns Tee) (06/05/91)

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:

> In article <1991May30.002543.13967@midway.uchicago.edu> valley@gsbsun.uchicag
> >dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:
> >
> >> - They [.EXE format device drivers] work in MSDOS, but not PCDOS,
> >	because the .EXE loader is part of COMMAND.COM in PCDOS.
> >really??? ---------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> >> - They only work in version 3 or higher.
> >
> >That's interesting.  Does this mean that you can't exec() a .EXE file
> >directly (from another program) in PC/DOS?  (I.e., that you would have
> >to run it via system() ?)
> 
> I haven't tested either claim, but the first one is kind of hard to believe.
> In fact, my PC DOS 3.1 tech ref manual specifically mentions that .EXE format
> device drivers are allowed, though it doesn't say much about them.  However,
> I have heard it before, so the tech ref could be wrong.

    The distinction isn't quite that clear. .EXE format drivers will work 
in all generic versions of MSDOS. And most versions of PCDOS. There are 
certain versions of PCDOS where the .EXE loader was part of COMMAND.COM, 
but I have yet to hear a list of version numbers. I don't think it was 
very clear-cut, but I'd imagine it was only in certain 1.x and 2.x 
versions.
    As for the second claim, the .EXE loader in COMMAND.COM stays in 
memory when outside of COMMAND.COM, so as far as any program you write is 
concerned, it's part of the Kernal. I think.

terra@diku.dk (Morten Welinder) (06/06/91)

valley@gsbsun.uchicago.edu (Doug Dougherty) writes:

>This has nothing to do with the original post, but...

>dmurdoch@watstat.waterloo.edu (Duncan Murdoch) writes:

>> - They [.EXE format device drivers] work in MSDOS, but not PCDOS,
>	because the .EXE loader is part of COMMAND.COM in PCDOS.
>really??? ---------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

My manual says so too! (MSDOS 3.1 technical ref.)


>> - They only work in version 3 or higher.

>That's interesting.  Does this mean that you can't exec() a .EXE file
>directly (from another program) in PC/DOS?  (I.e., that you would have
>to run it via system() ?)
>--

No. It is only a problem when writing device drivers, since they are loaded
before the first instance of command.com.

Morten 'Sally' Welinder
terra@rimfaxe.diku.dk

Ralf.Brown@B.GP.CS.CMU.EDU (06/09/91)

In article <7e3131w164w@spocom.guild.org>, luns@spocom.guild.org (Luns Tee) wrote:
}but I have yet to hear a list of version numbers. I don't think it was 
}very clear-cut, but I'd imagine it was only in certain 1.x and 2.x 
}versions.

The program loader in in COMMAND.COM for all versions 1.x (both PC- and MS-
DOS), since there is no EXEC function call.  PC-DOS 2.x puts the EXEC code
into COMMAND.COM, but not PC-DOS 3.x or any MS-DOS 2.x or higher.  The
PC-DOS code consists of a short stub in the resident portion of COMMAND.COM,
with the actual loader in a *second* transient portion of COMMAND.COM.	As
a result, COMMAND.COM needs to be available, as the EXEC program loader
must first load itself from disk each time it is called.

-- 
{backbone}!cs.cmu.edu!ralf  ARPA: RALF@CS.CMU.EDU   FIDO: Ralf Brown 1:129/53
BITnet: RALF%CS.CMU.EDU@CARNEGIE   AT&Tnet: (412)268-3053 (school)   FAX: ask
DISCLAIMER?  Did  | It isn't what we don't know that gives us trouble, it's
I claim something?| what we know that ain't so.  --Will Rogers