home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / os2 / misc / 37268 < prev    next >
Encoding:
Text File  |  1992-11-24  |  4.8 KB  |  164 lines

  1. Xref: sparky comp.os.os2.misc:37268 comp.os.os2.programmer:6595
  2. Newsgroups: comp.os.os2.misc,comp.os.os2.programmer
  3. Path: sparky!uunet!spool.mu.edu!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!ee.ualberta.ca!jpenne
  4. From: jpenne@ee.ualberta.ca (Jerry Penner)
  5. Subject: Re: Port I/O for 32 Bit Apps
  6. Message-ID: <jpenne.722340849@ee.ualberta.ca>
  7. Sender: news@kakwa.ucs.ualberta.ca
  8. Nntp-Posting-Host: eigen.ee.ualberta.ca
  9. Organization: University Of Alberta, Edmonton Canada
  10. References: <722157399.F00004@tdkt.kksys.com> <1992Nov19.231947.16673@netcom.com>
  11. Date: Sat, 21 Nov 1992 10:14:09 GMT
  12. Lines: 150
  13.  
  14. feustel@netcom.com (David Feustel) writes:
  15.  
  16. >Bertram.Moshier@f115.n282.z1.tdkt.kksys.com (Bertram Moshier) writes:
  17.  
  18. >>Actually, this question is best put on comp.os.os2.programmer.  To
  19. >>answer your question, though, what you say is true.  A 32 bit OS/2
  20. >>application can get to I/O devices.  You should look at IOPL.  This
  21. >>interface allows a ring three application to perform selected ring two
  22. >>operations (namely I/O).
  23.  
  24. >Could you give a simple example? My impression is that IBM doesn't
  25. >currently use this hardware feature to permit ring 3 i/o for os2
  26. >applications.
  27.  
  28. All port I/O must be done at ring 2 or less and from 16-bit code.
  29.  
  30. The rules to follow when doing this are:
  31.  
  32. - Declare IOPL 16-bit routines as _pascal (I'm assuming you are
  33.   writing 16-bit code with Microsoft C v6) to the 16-bit compiler.
  34. - Declare IOPL 16-bit routines as _Far16 _Pascal to the 32-bit
  35.   compiler.  (These first two points can be taken care of easily with
  36.   an include file that #defines _Far16 and _Pascal to different things
  37.   depending on which compiler you are using.  See the \ibmc\samples\
  38.   sample04 directory for examples on this or look at your C Set/2
  39.   User's guide around page 270 (I think, my book is at work).
  40. - Ensure that your parameter declarations and return values are the
  41.   same size.  Ie.  Microsoft C 'int' is 16-bits, C Set/2 'int' is
  42.   32-bits.  Use 'short' for 16-bits and 'long' for 32-bits.
  43. - In your .DEF file (for creating the 16-bit DLL) do NOT prefix IOPL
  44.   routines in your EXPORTS section with '_'.  And make sure you add a
  45.   number after the function name to inform the system how many WORDS
  46.   (not bytes) of parameters are defined.
  47. - Make sure each function name that runs under IOPL is in all
  48.   CAPITALS.  Other non-IOPL functions should have their case settings
  49.   the same as in the source code.
  50. - Also in the DEF file, the SEGMENTS line should read:
  51.     SEGMENTS your_seg_name CLASS 'CODE' IOPL
  52.   'your_seg_name' is usually the filename of your 16-bit code minus
  53.   the extension.
  54.  
  55. Here's a little example which I'm making up from memory since I am not
  56. at work.  If you can't get this to work with Microsoft C v6 and IBM C
  57. Set/2 email me and I will check this over.
  58.  
  59. -------------------------------
  60. test16.c
  61. -------------------------------
  62.  
  63. #include "common.h"
  64.  
  65. short _Far16 _Pascal InPort( short ioport )
  66. {
  67.     short rc;
  68.  
  69.     _asm    MOV    DX,ioport
  70.     _asm    IN    AX,DX
  71.     _asm    SUB    AH,AH
  72.     _asm    MOV    rc,AX
  73.  
  74.     return rc;    /* you probably don't need the MOV rc,AX */
  75.             /* or the return rc since AX is the return */
  76.             /* value but I did it this way and it works */
  77.             /* but I didn't try it with it removed.  :)
  78.             */
  79. } /* end InPort() */
  80.  
  81.  
  82.  
  83. -------------------------------
  84. common.h
  85. -------------------------------
  86.  
  87. #ifndef __32BIT__
  88.     #define    _Far16
  89.     #define _Pascal _pascal
  90.     #define _Seg16 /* something may go here, I can't remember */
  91.  
  92.     #define extern
  93. #endif
  94.  
  95. extern _Far16 _Pascal InPort( short ioaddr );
  96.  
  97. -------------------------------
  98. test16.def
  99. -------------------------------
  100.  
  101. LIBRARY
  102. DESCRIPTION '16-bit IOPL code DLL'
  103. PROTMODE
  104. EXPORTS
  105.     INPORT    1
  106. SEGMENTS
  107.     'TEST16' CLASS 'CODE' IOPL
  108.  
  109.  
  110. -------------------------------
  111. test32.c
  112. -------------------------------
  113.  
  114. #include <stdio.h>
  115. #include "common.h"
  116.  
  117. main()
  118. {
  119.     int  in;
  120.  
  121.  
  122.     in = InPort( 0x300 );
  123.     printf( "port value = %d\n", in );
  124. }
  125.  
  126.  
  127. -------------------------------
  128. test32.def
  129. -------------------------------
  130.  
  131. NAME
  132. DESCRIPTION '32-bit part of 32/16 bit example w/ IOPL code'
  133. PROTMODE
  134.  
  135.  
  136. -------------------------------
  137. compiling commands (normally in a makefile)
  138. -------------------------------
  139.  
  140. test16.obj: test16.c common.h
  141.     cl -c -Alfu -G2s test16.c
  142.  
  143. test16.dll: test16.obj test16.def
  144.     link /NOL /NOI /MAP /NOD test16,test16.dll,test16,os2286,test16.def
  145.  
  146. test16.lib: test16.def
  147.     implib test16.lib test16.def
  148.  
  149. test32.obj: test32.c common.h
  150.     icc -c -Gd- test32.c
  151.  
  152. test32.exe: test32.obj test16.dll
  153.     link386 /NOL test32,test32.exe,test32,test16.lib,test32.def
  154.  
  155.  
  156. I think that should do it.  I spent a lot of time figuring most of
  157. this out so hopefully you won't have to do the same.  Some of this
  158. info is in the manuals (C Set/2 User's and Migration Guides) but some
  159. of it isn't but is the result of trial and error testing...
  160.  
  161. Good luck.
  162. -- 
  163. Jerry Penner   jpenne@ee.ualberta.ca   Try a 1-line .sig today.
  164.