home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / thnk11.zip / THUNKER.DOC < prev    next >
Text File  |  1995-03-24  |  10KB  |  214 lines

  1. 4/30/94 
  2.  
  3. While OS/2 2.X has many wonderful features it has one source of irritation 
  4. to programmers used to almost any other system. That source of irritation is 
  5. the fact that somebody at IBM made a poor decision and eliminated the KBD 
  6. MOU and VIO system calls from the 32 bit version of the operating system. 
  7. Whatever the reasoning behind this choice, it left the system crippled. 
  8. I would guess that one of the excuses given for deleting these calls was 
  9. that command line programs are "obsolete". In addition it was probably also 
  10. argued that programmers could always create thunks to the existing 16 bit 
  11. API's if they needed to.
  12.     Trust me on this; the source code necessary to create the thunks to 
  13. the almost 100 missing API functions is so ugly that in a controlled test 
  14. mere exposure to it resulted in the sterilization of frogs at a distance of 
  15. more than 100 paces. 
  16.     Fortunately I was able to hide all of this ugliness inside of nice 
  17. clean little .DLL file so that the rest of you won't have to see it. 
  18.  
  19. The files in THUNKER.ZIP are:
  20.  
  21. * (Changed, see below)
  22.  
  23. THUNKER.DLL --- This converts 32 bit calls to 16 bit for you.
  24. THUNKER.LIB --- This allows 32 bit C & asm to call MOU KBD and VIO functions.
  25. THUNKER.H   --- This allows C to pretend there are 32 bit MOU KBD & VIO API's.
  26. THUNKER.DOC --- Obviously this document.
  27. THNKTEST.C  --- Sample for use of the 32 bit MOU KBD and VIO API's
  28. THNKTEST.MAK -- Sample make file showing the linking.
  29. THNKTEST.DEF -- Def file for sample.
  30.  
  31. * (Changed, see below)
  32.     Maybe the fact that this DLL exists will encourage IBM to correct 
  33. their horrendous blunder and make real 32 bit versions of these functions. 
  34. In any case, as long as the 16 bit calls exist in the system this .DLL makes 
  35. them accessible for your use.
  36.     The only 32 bit C which I have is GNU C. While the header functions 
  37. correctly with it,I have not tested it to work with commercial C compilers. 
  38. About the only source of potential trouble would be if some items in 
  39. THUNKER.H were already defined in your other headers. It is very plain 
  40. vanilla C - nothing compiler specific about it.
  41.     There is no reason not to call the functions from assembly code, but
  42. be aware of the following: 
  43.  
  44. * (Changed, see below)
  45.  
  46.     1. The function names are preceded by an '_'. EX: _VioWrtTTY
  47.     2. The stack is left dirty with the calling parms.
  48.     3. Parms are pushed in reverse order from the 1.x calls
  49. * (Changed, see below)
  50.  
  51. All 3 of the above are for C's benefit.
  52.  
  53. THIS CODE IS RELEASED INTO THE PUBLIC DOMAIN AND MAY BE USED FOR COMMERCIAL 
  54. PURPOSES. UNDER NO CIRCUMSTANCES WILL THE AUTHOR BE LIABLE FOR ANY DAMAGES 
  55. RESULTING FROM THE USE OF THIS CODE.
  56.  
  57. ABOUT:
  58.     The code: THUNKER.DLL was written in 32 bit assembly and assembled 
  59. with MASM 6.0 under OS/2.
  60.  
  61.     The author: Robert E. Canup II has been involved in the micro 
  62. computer revolution since the pre-IBM S-100 days as an engineer and 
  63. programmer. He has held the world record for the fastest micro computer 
  64. design. 
  65.  
  66.  
  67. I am interested in any comments about this code including bug reports. 
  68. My CompuServe number is 73513,216
  69.  
  70.                         Bob
  71. Rev 1.1 Notes 3/20/95
  72.  
  73. As I said above, when I originally wrote the DLL the only 32 bit development 
  74. tools that I had were 2.1 and 2.2 versions of GNU C which I downloaded from 
  75. CompuServe. The original DLL ran fine with them. The DLL was made by linking 
  76. my asm code with the DOSCALLS.LIB that came with OS/2. Two problems occurred 
  77. with this procedure.
  78.  
  79. 1.) DOSCALLS.LIB has no linkages to the PM versions of the VIO calls.
  80. 2.) Despite the fact that all of the documentation has the API calls in 
  81. mixed case DOSCALLS.LIB has them in uppercase (VIOWRTTTY etc.).
  82.  
  83. When I linked the original DLL I forgot to use the /NOI switch on Link386. 
  84. This was ok with both masm and GNU C 2.1 and 2.2 but it blew up in my face
  85. when I tried to use it with GNU C 2.5.4 from the Hobbes CD Rom. In addition I
  86. have since obtained IBM's C-Set First Step and the OS/2 developers toolkit. 
  87. The new version has the case problem taken care of. The rev 1.1 DLL is linked
  88. to the toolkit's OS2286.lib which has the PM versions of the VIO calls in it.
  89.  
  90. The differences between GNU C and IBM C require that there be two versions of
  91. the DLL's.  In GNU, as I said above, function names are proceeded by _ as 
  92. in _VioWrtTTY while in IBM C (at least in the C-Set first step) the name is 
  93. simply VioWrtTTY. In addition it is necessary to change the header file 
  94. to use the APIRET APIENTRY pair before the functions. C-Set uses registers 
  95. to pass variables unless the APIENTRY keyword is used.
  96.  
  97. The C-Set variable passing method is as follows:
  98.  
  99.     Left most parm in EAX
  100.     Second parm in EDX
  101.     Third parm in ECX
  102.     Fourth through N parms pushed on stack.
  103. Remember parms are pushed from right to left in C.
  104.  
  105. Shortly after I posted the zip file to CompuServe I discovered a typo in the
  106. header file. The new Rev fixes that problem. 
  107.  
  108. About a month ago Morton Kaplon 73457,437 pointed out a problem with the high
  109. 16 bits of the values returned by the thunked functions. Checking my code I 
  110. realized that I had neglected to mask the high 16 bits of the eax register 
  111. off before I returned the values. That is also fixed in the current release.
  112.  
  113. There are some things about using this DLL with C that need to be pointed out.
  114. On both GNU C 2.5.4 and IBM's C-set it is necessary to lightly modify some 
  115. of the header files that come with the compilers. Specifically there is a 
  116. conflict between Thunker.h and BSESUB.h. The headers have some #defines like
  117. this: 
  118.  
  119. #define VioWrtTTY Vio16WrtTTY
  120.  
  121. these #defines need to be commented out as they conflict with the prototypes 
  122. in the Thunker.h file. The #defines are controlled by an opening control
  123. statement that reads something like this:
  124.  
  125. #ifdef INCL_SUB
  126.     #define INCL_KBD
  127.     #define INCL_VIO
  128.     #define INCL_MOU
  129. #endif /* INCL_SUB */
  130.  
  131. The easiest thing to do is simply move the comment earlier as follows :
  132.  
  133. /* This is the mod to allow THUNKER.h to work.
  134. #ifdef INCL_SUB
  135.     #define INCL_KBD
  136.     #define INCL_VIO
  137.     #define INCL_MOU
  138. #endif  INCL_SUB */
  139.  
  140. Now the INCL_SUB won't do anything.
  141.  
  142. The second .h file that needs changing is the PMAVIO.H file. This is a some-
  143. what more difficult case but is still easy to fix.
  144.  
  145. Simply locate the offending code (most of the header) and surround it with
  146.  
  147. #ifdef NO_THUNK
  148. .
  149. .
  150. .
  151. #endif
  152.  
  153. Since NO_THUNK is not defined anywhere the troublesome part of the header
  154. in effect disappears.
  155.  
  156. There is only one THUNKER.H file supplied as this works for both IBM C and 
  157. GNU C.
  158.  
  159. The new files in this zip file are as follows:
  160.  
  161. THUNKGCC.DLL --- This converts 32 bit calls to 16 bit for you. For use with
  162.          GNU C.
  163. THUNKGCC.LIB --- This allows 32 bit GNU C & asm to call MOU KBD and VIO 
  164.          functions.
  165. THUNKICC.DLL --- This converts 32 bit calls to 16 bit for you. For use with
  166.          IBM C-SET compiler.
  167. THUNKICC.LIB --- This allows 32 bit IBM C & asm to call MOU KBD and VIO 
  168.          functions.
  169. THUNKER.H   --- This allows C to pretend there are 32 bit MOU KBD & VIO API's.
  170. THUNKER.DOC --- Obviously this document.
  171. THNKTEST.C  --- Sample for use of the 32 bit MOU KBD and VIO API's
  172. THNKTEST.MAK -- Sample make file showing the linking.
  173. THNKTEST.DEF -- Def file for sample.
  174. THNKTEST.EXE -- Executable compiled with C-Set.
  175. THNKTEST.ASM -- Asm file produced by C-Set compiler (/Fa switch) showing how
  176.         to call the code from assembly programs (without a macro).
  177.  
  178. The only difference between THUNKGCC.DLL and THUNKICC.DLL is that the 
  179. function names have a '_' in front of them in the GCC version and don't in the
  180. ICC version. This allows the same C source code to be used with both of them.
  181. The ICC version is probably preferable for use with MASM since you don't have
  182. to include a '_' on the front of the names.
  183.  
  184. Hopefully one of the two will work with Borland and Watcom C. If not then I 
  185. can create versions that will if someone will give me the register passing 
  186. and naming protocols for these C's.
  187.  
  188. Part of the reason that it would be nice to have real 32 bit versions of the
  189. API's as opposed to thunked versions involves the problems inherent in the
  190. mapping of flat 32 bit addresses to the tiled 16-16 segments used by the 16
  191. bit version of the API's. Two restrictions occur from this difference:
  192.  
  193.     1. Passing an array which overlaps a 64K boundary will cause the
  194.        code to crater. In the tiled system the probability that this will
  195.        happen in a given piece of code is (size of array-1/65536). This
  196.        means that adding variables to your code can cause it to fail. 
  197.        This problem won't show up until we have enough variables or 
  198.        stack usage (local variables use the stack) to exceed 64K. 
  199.     2. OS/2 reserves the first 16 bit selector for its own use. Under
  200.        GNU C I find it necessary to sometimes include a dummy char array
  201.        to take up the first 65537 bytes. Why the value is 65537 and not
  202.        65536 I have not a clue.
  203.  
  204. As I said in the original documentation for these files leaving the KBD MOU 
  205. and VIO calls out of the 32 bit version of OS/2 cripples programmers. With 
  206. the standard version of the API's all one can do is crawl around helplessly 
  207. trying to do I/O using DosRead and DosWrite (Arrrrgh). With these files I am
  208. providing programmers with a wheel chair. Now that is a huge advance over 
  209. crawling but it doesn't compare with being able to walk. 
  210.  
  211.             GIVE US OUR LEGS BACK IBM!!!
  212.  
  213.                         Bob Canup
  214.                         73513,216