home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #2 / Amiga Plus CD - 1995 - No. 2.iso / internet / faq / englisch / comp.os.ms-windows.programmer < prev    next >
Encoding:
Text File  |  1995-04-11  |  15.8 KB  |  408 lines

  1. Archive-name: windows/programming/device-drivers
  2. Posting-Frequency: bimonthly
  3. Last-modified: February 9, 1995
  4.  
  5.  
  6.            Frequently Asked Questions (FAQ)
  7.                  for
  8.         comp.os.ms-windows.programmer.drivers
  9.  
  10. Summary:
  11.     This is a working document.  Suggestions, questions, answers,
  12.     are welcome.  I will post this document near the beginning of
  13.     each month.  This FAQ is particularly thin on Windows NT driver
  14.     information (that's a hint for you NT driver wizards out there
  15.     to send in some info...).
  16.  
  17.     Thanks for help, comments, and answers from Lee Fisher, Michael Geary, 
  18.     Chris Marriott, Dan Norton, and especially Don Matthews.
  19.  
  20.     Edited by Steve Lewin-Berlin (Berlin@vireo.com)
  21.  
  22. Questions:
  23.  
  24.  1.  Help, I need a driver for...
  25.  2.  How do I access physical memory at <addr> from a Windows 3.1 application?
  26.  3.  What are the differences between embedded, installable, and conventional
  27.      device drivers?
  28.  4.  I need to write a Windows device driver.  Should it be a DLL or a VxD?
  29.  5.  How do I handle interrupts in my VxD?
  30.  6.  How do I access physical memory in my VxD?
  31.  7.  How do I access memory from my application or DLL in my VxD?
  32.  8.  Can I write device drivers in C/C++, or must I use assembly language?
  33.  9.  What commercial products are available to help write drivers?
  34. 10.  What books are available?
  35. 11.  What on-line resources are available?
  36. 12.  What other information is available?
  37.  
  38. Answers:
  39.  
  40.  1.  Help, I need a driver for ...
  41.  
  42.      I'm afraid you've asked on the wrong group. This is a newsgroup for
  43.      discussions of device driver programming, not for requesting drivers for
  44.      particular devices. I'm sure you'll get help if you ask on the correct
  45.      newsgroup, which is "comp.os.ms-windows.setup".
  46.  
  47.  2.  How do I access physical memory at <e.g. D000:0000> from a
  48.      Windows 3.1 application?
  49.  
  50.      This is very easy to do.  Here is a sample program that  references the
  51.      VGA display buffer at A000:0000.  You can use the same technique, except
  52.      use _D000h instead of _A000h.  KERNEL defines a whole set of these
  53.      selectors for you covering the A000 through F000 range.
  54.  
  55.          #include "nojunk.h"
  56.      #define STRICT
  57.      #include <windows.h>
  58.  
  59.      typedef WORD SELECTOR;
  60.  
  61.      // __A000h is an absolute value; by declaring it as a NEAR variable
  62.      // in our data segment we can take its "address" and get the
  63.      // 16-bit absolute value.
  64.  
  65.      extern BYTE NEAR CDECL _A000h;
  66.  
  67.      SELECTOR selVGA = (SELECTOR)&_A000h;
  68.  
  69.      int PASCAL WinMain (HINSTANCE   hinst,
  70.                  HINSTANCE   hinstPrev,
  71.                  LPSTR       lpszCmdLine,
  72.                  int         cmdShow
  73.                  )
  74.     {
  75.     WORD FAR * lpVGA = MAKELP( selVGA, 0 );
  76.  
  77.     // Should put garbage pixels on top left of screen
  78.     lpVGA[0] = 0x1234;
  79.     lpVGA[1] = 0x5678;
  80.  
  81.     return 0;
  82.     }
  83.  
  84.  
  85.  3.  What are the differences between embedded, installable, and conventional
  86.      device drivers?
  87.  
  88.      All of these terms can be used to describe 16-bit protected-mode DLLs.
  89.      
  90.    o An embedded device driver is a DLL that basically acts as an extension
  91.      of a particular Windows application.  It usually contains an interrupt
  92.      handler, and it exports any set of services the author might choose to
  93.      implement.
  94.  
  95.    o An installable device driver must conform to more rigid guidelines.
  96.      This type of driver can be opened, closed, enabled, disabled, etc. by
  97.      other applications or DLLs.  It contains a DriverProc, which is like
  98.      the WindowProc in a Windows application.  The DriverProc responds to
  99.      a standard set of messages sent by Windows and to custom messages sent
  100.      by applications.  This is the type of driver that can be installed
  101.      using the Control Panel applet.
  102.  
  103.    o A conventional device driver (also sometimes called a "standard"
  104.      device driver) interacts with a hardware device supported by the
  105.      Windows API.  For example, the display, keyboard, and printer are
  106.      considered to be "standard" devices.  These drivers are sometimes
  107.      given a file extension of .DRV, and are usually installable drivers.
  108.      They work with certain pre-defined data structures and provide certain
  109.      pre-defined services.
  110.  
  111.  4.  I need to write a Windows device driver.  Should it be a DLL or a VxD?
  112.  
  113.      This is the kind of question whose answer really depends on your
  114.      application and your objectives.  In general, a VxD is more difficult
  115.      to develop, but yields higher performance when processing interrupts
  116.      and accessing I/O ports.  A VxD can also do things that aren't
  117.      otherwise possible with a DLL.
  118.      
  119.      The first step is to determine what it is that your driver must do.
  120.      If it must support a hardware device, then which of the following
  121.      system resources are required by your hardware?
  122.  
  123.      a.)  I/O ports
  124.      b.)  IRQ lines
  125.      c.)  Memory ranges
  126.      d.)  DMA channels
  127.  
  128.      If I/O ports are involved, then be aware that there are performance
  129.      issues related to accessing I/O ports from ring 3, as you would in a 
  130.      DLL, as compared to accessing them from ring 0 in a VxD.  There is
  131.      overhead associated with accessing I/O ports from ring 3, perhaps as
  132.      much as 100% or more (i.e. ring 3 accesses take twice as much time as
  133.      ring 0 accesses).
  134.  
  135.      If IRQ lines are involved, then be aware that there is significantly
  136.      more interrupt latency associated with an ISR running in ring 3 than
  137.      in a DLL.
  138.  
  139.      Access to physical memory can be accomplished with DPMI services in
  140.      a DLL, or VMM services in a VxD.
  141.  
  142.      Access to DMA channels should go through VDS (Virtual DMA Services).
  143.  
  144.      If you need to make your hardware appear to be shared by Windows
  145.      applications and DOS applications running in separate DOS boxes,
  146.      then you need to "virtualize" your hardware with a VxD.  You also
  147.      need to "virtualize" your hardware if you need to mediate access, or
  148.      resolve contention for your device.
  149.  
  150.  5.  How do I handle interrupts in my VxD?
  151.  
  152.      You should use the services provided by the Virtual PIC Device (VPICD)
  153.      to install an ISR for your hardware device.  This involves creating
  154.      a data structure in the locked data segment of your VxD of type
  155.      VPICD_IRQ_Descriptor.  In it, you specify the IRQ number and the
  156.      address of your ISR, among other things.  You then register your
  157.      ISR by calling VPICD_Virtualize_IRQ.  This returns an IRQ Handle,
  158.      which you should save for future reference.
  159.      
  160.      Later, when an interrupt occurs, your ISR will be entered with minimal
  161.      latency.  The ISR should be in a locked code segment.  The IRQ Handle
  162.      that uniquely identifies this interrupt will be in EAX upon entry.
  163.      You should call VPICD_Phys_EOI at the end of your ISR.  Just before
  164.      returning from your ISR, clear the carry flag if you successfully
  165.      processed the interrupt.  If the IRQ is sharable, you can pass the
  166.      IRQ on to the next handler in the chain by setting the carry flag.
  167.      Return from the ISR with a RET instruction, not IRET.
  168.      
  169.      Upon entry to the VID_Hw_Int_Proc (your ISR), interrupts are masked
  170.      at the PIC for that particular interrupt, and an EOI has already been
  171.      sent to the PIC for that same interrupt.  The call to VPICD_Phys_EOI
  172.      at the end of the ISR doesn't actually send an EOI to the physical
  173.      PIC, as the name implies, but rather simply unmasks the interrupt at
  174.      the PIC. The EOI was actually sent to the PIC before entering
  175.      VID_Hw_Int_Proc.  The name of the VPICD_Phys_EOI service is misleading.
  176.  
  177.      Check out the useful services provided by VPICD.
  178.  
  179.  6.  How do I access physical memory in my VxD?
  180.  
  181.      You should first convert the physical address to a linear address
  182.      with the _MapPhysToLinear service.  Then convert the linear address
  183.      to either a protected-mode address in <selector>:<offset> form or a
  184.      V86-mode address in <segment>:<offset> form with the Map_Lin_To_VM_Addr
  185.      service.
  186.  
  187.  7.  How do I access memory from my application or DLL in my VxD?
  188.  
  189.      You should convert the protected-mode address to a linear address
  190.      with the Map_Flat service.  
  191.  
  192.  8.  Can I write device drivers in C/C++, or must I use assembly language?
  193.  
  194.      VxDs are 32-bit programs.  You may use a 32-bit C/C++ compiler, but
  195.      you must be careful about segmentation, calling conventions, and
  196.      run time library routines that require initialization.  Many of the
  197.      interfaces provided by the Virtual Machine Manager have register-based
  198.      calling conventions.
  199.  
  200.      Vireo Software sells a toolkit that allows you to use C or C++ to
  201.      write VxDs.  See below.
  202.  
  203.  9.  What commercial products are available to help write device drivers?
  204.  
  205.         MSDN level 1   (Microsoft)
  206.         MSDN level 2   (Microsoft)
  207.         Soft-ICE/W     (Nu-Mega Technologies)
  208.         VtoolsD        (Vireo Software)
  209.  
  210.     MSDN level 1
  211.         Summary:  Membership in level 1 of the Microsoft Developer Network
  212.               gets you a CD 4 times per year. The CD is packed with
  213.               documentation and on-line books, including articles about
  214.               VxD development.
  215.         Price:    $195/ year
  216.         Contact:  Microsoft Developer Network
  217.               mail:  PO Box 10296, Des Moines, IA  50336
  218.               voice: (800) 759-5474
  219.               voice: (206) 936-8661
  220.               CIS:  go MSDS
  221.  
  222.     MSDN level 2
  223.         Summary:  Membership in level 2 of the Microsoft Developer Network
  224.               gets you a set of CDs 4 times per year.  The CDs include
  225.               the level-1 CD (see above) plus operating systems, SDKs,
  226.               and DDKs for a number of MS products.  This includes the
  227.               Windows Device Driver Kit (DDK), which includes
  228.               utilities required to build device drivers, along with
  229.               numerous examples.
  230.         Price:    $495/ year
  231.         Contact:  MSDN (see above)
  232.  
  233.     VtoolsD for Windows 3.1
  234.         Summary:  VtoolsD is a toolkit that allows developers to build VxDs
  235.               in C or C++ using the Microsoft 32-bit C/C++ compiler.
  236.               VtoolsD includes a visual-programming VxD code generator,
  237.               ANSI C run-time libraries, VMM/VxD service libraries, 
  238.               and a VxD Class Library.  Compatible with Microsoft and
  239.               Borland C/C++ compilers.
  240.         Price:    $495
  241.         Contact:  Vireo Software
  242.               mail:  385 Long Hill Road, Bolton, MA  01740
  243.               voice: (508) 779-8352
  244.               fax:   (508) 779-8351
  245.               Email: Vireo@vireo.com
  246.  
  247.     VtoolsD for Windows 95 (Pre-release)
  248.         Summary:  The Windows 95 Pre-release allows developers to build
  249.               VxDs that call new services available in Windows 95.
  250.               Requires Windows 95 DDK.
  251.         Price:    $495
  252.         Contact:  Vireo Software (see above)
  253.  
  254.     Soft-ICE/W
  255.         Summary:  Soft-ICE/W is a full-screen character-mode debugger that
  256.               can be used to debug VxDs and applications. Soft-ICE/W
  257.               can debug VxDs at the instruction level, or display
  258.               ASM, C, or C++ source code.
  259.         Price:    $386
  260.         Contact:  Nu-Mega Technologies, Inc.
  261.               mail:  PO Box 7780, Nashua, NH  03060
  262.               voice: (603) 889-2386
  263.               fax:   (603) 889-1135
  264.  
  265. 10.  What books are available?
  266.  
  267.         Writing Windows Device Drivers           (Daniel Norton)
  268.         Writing Windows Virtual Device Drivers   (Thielen and Woodruff)
  269.  
  270.         Title:    Writing Windows Virtual Device Drivers
  271.         Author:    David Thielen and Bryan Woodruff
  272.         Publisher:    Addison Wesley
  273.         ISBN:    0-201-62706-X
  274.         Price:    $39.95
  275.  
  276.         Title:    Writing Windows Device Drivers
  277.         Author:    Daniel Norton
  278.         Publisher:    Addison Wesley
  279.         ISBN:    0-201-57795-X
  280.         Price:    $29.95
  281.  
  282. 11.  What on-line resources are available?
  283.  
  284.         CompuServe
  285.         Internet
  286.  
  287.         Internet news groups
  288.         comp.os.ms-windows.programmer.drivers
  289.  
  290.         Internet FTP site
  291.         ftp.microsoft.com
  292.             Developr/drg/developer-info/devinfo.zip
  293.                 This file contains a list of developer resources
  294.             available from Microsoft; it is not driver specific.
  295.             Developr/MSDN/
  296.             Developr/DRG/MSDN-Info/
  297.                 These directories contain additional information
  298.             about Microsoft Developer Network.
  299.  
  300.         CompuServe
  301.             Microsoft operates several forums on CompuServe that may
  302.         be of interest to device driver developers:
  303.  
  304.         Microsoft Developer Knowledge Base      Service: MDKB  
  305.  
  306.             The Microsoft Developer Knowledge Base is a reference tool
  307.             containing technical information and articles about the
  308.             Microsoft developer-specific products.  This database is
  309.             compiled and maintained by Microsoft Product Support and is
  310.             full-text, keyword searchable. You will find Microsoft
  311.             press releases and technical articles about product bugs,
  312.             trouble-shooting and updates.      
  313.  
  314.         Microsoft Developer Network Forum       Service: MSDNLIB
  315.  
  316.             The Microsoft Developer Network (MSDN) Technical Library
  317.             Forum offers software developers a quick and efficient way
  318.             of obtaining technical information.  The libraries contain
  319.             a collection of technical articles in the Windows Help file
  320.             format and sample code, which are available for
  321.             downloading. Message sections enable you to discuss any of
  322.             the files or codes with other users, as well as with
  323.             Microsoft Representatives.
  324.  
  325.         Microsoft Knowledge Base        Service: MSKB
  326.  
  327.             Microsoft Knowledge Base is a database which provides
  328.             access to information about Microsoft products previously
  329.             available only to the Microsoft support engineers. Search
  330.             the database by product name, version or category. Or for
  331.             immediate responses to your questions, perform a full-text
  332.             search of all documents contained within database that
  333.             contain the subject of your question. Also communicate
  334.             directly with Microsoft by sending an electronic message to
  335.             its Help Desk.
  336.  
  337.         Microsoft Service Request       Service: MSR
  338.  
  339.             Microsoft offers the Service Request System as an optional,
  340.             private (fee-based per incident) technical support service
  341.             that offers to help solve complex development problems.
  342.             Other avenues, such as the Microsoft Developer Support
  343.             Forums and Microsoft Developer Knowlede Base, should be
  344.             consulted prior to using the Service Request System.
  345.  
  346.         Microsoft Software Library      Service: MSL
  347.  
  348.             The Microsoft Software Library is a collection of uploaded
  349.             binary files, samples, technical notes and utilities about
  350.             various Microsoft programs.  The entire library is keyword
  351.             searchable and the files can easily be downloaded to your
  352.             computer.
  353.  
  354.         Microsoft Windows SDK Forum     Service: WINSDK 
  355.  
  356.             Developers using the Windows Software Development Kit [and
  357.             DDK] will want to take advantage of the community of
  358.             assistance and support available in the Windows SDK Forum.
  359.             Help is available for subjects such as tools, accelerators,
  360.             controls, dialogue boxes, memory management, fonts,
  361.             palettes and color [and device drivers].
  362.  
  363. 12.  What other information is available?
  364.  
  365.     The October 1992 Microsoft Windows NT Device Driver Developer's 
  366.     Conference video/audio tapes are still available. Contact:
  367.  
  368.           MobileTape Co. Inc.
  369.           address: 25061 W. Stanford, Suite 70; Valencia, CA 91355, USA
  370.           phone (orders): 800.369.5718
  371.           phone (info): 805.295.0504
  372.           fax: 805.295.8474
  373.  
  374.         ask for the order form for the event:
  375.  
  376.           Microsoft Windows NT Device Driver Developer's Conference
  377.           October 26-28, 1992
  378.           Anaheim, CA
  379.  
  380.     Solomon Software Technologies
  381.     20 Hunters Lante
  382.     Nashua, NH 03063-2245
  383.     USA
  384.     Phone: 1.800.492.4898
  385.     Phone: 1.603.595.9059
  386.     FAX: 1.603.595.9005
  387.     Email: 71561.3603@CompuServe.COM
  388.  
  389.         They offer various technical seminars by folks such as Richard Hale
  390.         Shaw, Jamie Hanrahan, Jeffrey Richter, and David Solomon. Topics
  391.         include Visual C++, OLE, MFC, Windows '95 ("Chicago"), Win32
  392.         programming, and Windows NT device drivers. One relevant seminar
  393.         is "Windows NT Kernel-Mode Device Driver Programming".
  394.  
  395.  
  396. 99.  Conflict of interest?
  397.  
  398.     The editor works for Vireo Software, Inc. and is one
  399.     of the authors of the VtoolsD VxD toolkit mentioned
  400.     in this document.  I hope you find the information listed
  401.     here to be useful.  Please send comments, suggestions,
  402.     questions, etc.
  403.  
  404.     -- Steve Lewin-Berlin
  405.        Vireo Software
  406.        Berlin@vireo.com
  407.  
  408.