home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / os2 / programm / 6295 < prev    next >
Encoding:
Text File  |  1992-11-09  |  3.4 KB  |  98 lines

  1. Path: sparky!uunet!vnet.ibm.com
  2. From: joe2@vnet.ibm.com
  3. Message-ID: <19921109.104506.901@almaden.ibm.com>
  4. Date: Mon, 9 Nov 92 19:45:32 FWT
  5. Newsgroups: comp.os.os2.programmer
  6. Subject: Re: CSet/2 and port access.
  7. Reply-To: <joe2@vnet.ibm.com>
  8. Disclaimer: This posting represents the poster's views, not those of IBM
  9. News-Software: UReply 3.0
  10. References: <1dij4sINNmek@flop.ENGR.ORST.EDU>
  11. Lines: 85
  12.  
  13. In <1dij4sINNmek@flop.ENGR.ORST.EDU> the Dodger writes:
  14. >Alright, I'm starting to get frustrated here. I've been using CSet/2 for a
  15. >couple of days now and I love it. However, there are no hardware port access
  16. >functions such as outp and inp. I really need these functions to do what I
  17. >am trying to do. So I thought that I would just write the port functions in
  18. >assembler, assemble them with TASM 3.0, and then link it all together. Well,
  19. >it all goes fine until I run the program. The program just exits. I have no
  20. >idea what the exit codes are (it is a full screen graphics program) and I
  21. >get no access violations or anything like that.
  22. >
  23. >Someone hinted at the fact that the hardware ports cannot be accessed from
  24. >32bit protected mode. Is this true? Am I going to have to try to write a
  25. >ring 0 dll to get this done? And if so, what will be the performance benefits
  26. >of this. My program will eventually be doing a LOT of port access, and if it
  27. >has to call a dll a few million times, then won't that slow things down a lot?
  28. >
  29. >Thanks for any help.
  30. >
  31.  
  32.    Several solutions:
  33.  
  34. 1) Write a device driver. Ok, I know, you don't want to... but it is not
  35.    that difficult, and from a device driver you can control CPU
  36.    scheduling, etc.
  37.  
  38. 2) Use the services of the TESTCFG$ driver, through DosDevIOCtl.
  39.    I am not sure if this is really documented/supported though!
  40.  
  41. 3) Include a RING2 segment in your code, and check that IOPL=YES in your
  42.    config.sys. This RING2 segment has to be 16bit (32bit segments
  43.    are RING3 only). The easiest way to write such a code is to use
  44.    MASM.
  45.  
  46. 4) Use C Set/2 version 2.0 (beta version included in the PDK CDROM).
  47.    It does include _inp and _outp. *BUT* beware: I understand it is
  48.    implemented using a 16bit RING2 segment, so each time you
  49.    call inp or outp, a ring transition will occur. So it's not going
  50.    to be fast. With method 3, you can put more than just one I/O
  51.    in the RING2 code.
  52.  
  53.   Now some more details about method 3. Let me show you how to
  54. implement inp with a MASM RING2 segment. First the .ASM file:
  55.  
  56. ------------------------------------
  57.         PUBLIC  MYINP                   ; UPPERCASE (Pascal calling convention)
  58.  
  59.  
  60. R2SEG   SEGMENT BYTE PUBLIC 'CODE'
  61.         ASSUME  CS:R2SEG, DS:NOTHING
  62.  
  63. MYINP   PROC    FAR
  64.  
  65.         push    bp
  66.         mov     bp, sp
  67.  
  68.         mov     dx, 
  69. bp+6Y              ; One arg: port
  70.         in      al, dx                  ; Get value
  71.         sub     ah, ah                  ; Return value in ax
  72.  
  73.         pop     bp
  74.         ret     2                       ; Remove one word from stack
  75. MYINP   ENDP
  76.  
  77.   Now, very important, things to include in the .DEF file:
  78.  
  79. --------------------------------------------
  80.  
  81.  
  82.  
  83.  
  84. SEGMENTS
  85.         R2SEG   CLASS 'CODE' IOPL
  86.  
  87. EXPORTS
  88.         MYINP   1                -> To tell the CPU how many word to
  89.                                     copy from the RING3 stack to the
  90.                                     RING2 stack...
  91.  
  92.  
  93.  That's it! Now you can call MYINP with the followin C Set/2 prototype:
  94.  
  95. extern USHORT _Far16 _Pascal MyInp  (USHORT port) ;
  96.  
  97.  
  98. Hope this helps!     -Joel Armengaud
  99.