home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / linux / 25591 < prev    next >
Encoding:
Text File  |  1993-01-27  |  2.3 KB  |  76 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!pizol!heeb
  3. From: heeb@watson.ibm.com (Hansruedi Heeb)
  4. Subject: Re: ?? Why no out/in in assembler ?? (CODE to do out/in from C)
  5. Sender: news@watson.ibm.com (NNTP News Poster)
  6. Message-ID: <1993Jan26.033933.12233@watson.ibm.com>
  7. Date: Tue, 26 Jan 1993 03:39:33 GMT
  8. Disclaimer: This posting represents the poster's views, not necessarily those of IBM
  9. References: <C1DpM9.H6L@helios.physics.utoronto.ca> <C1E98M.4JE@ichaos.nullnet.fi> <C1Fno4.IBI@helios.physics.utoronto.ca>
  10. Nntp-Posting-Host: pizol.watson.ibm.com
  11. Organization: IBM T.J. Watson Research Center
  12. Lines: 62
  13.  
  14. In article <C1Fno4.IBI@helios.physics.utoronto.ca> grindley@helios.physics.utoronto.ca (Robin Grindley) writes:
  15. >
  16. >Sorry, i should have been a little clearer. I realize that user tasks will
  17. >run at different privileges and IOPL's. Any normal code should not be allowed
  18. >to do what i want. But if one wants to debug a system one has to have access
  19. >to tools that can bypass normal security. My question is, IF i do setup
  20. >a task to run as root and i make sure i have the correct IOPL, the assembler
  21. >does not even have the capability to generate these instructions (they are
  22. >not in its "dictionary"). 
  23. >
  24.  
  25. I think what you want can be done directly from C.
  26.  
  27. Sample code (mostly stolen from the kernel):
  28.  
  29. #define SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
  30.  
  31. ...
  32.  
  33. if (iopl(3)) {
  34.     fprintf(stderr,"%s: iopl failed (must be root!)\n",argv[0]);
  35.     exit(1);
  36. }
  37.  
  38. ...
  39.  
  40. void inline outb_p(char value, unsigned short port)
  41. {
  42. __asm__ __volatile__ ("outb %%al,%%dx"
  43.                 ::"a" ((char) value),"d" ((unsigned short) port));
  44.         SLOW_DOWN_IO;
  45. }
  46.  
  47. void inline outw_p(char value, unsigned short port)
  48. {
  49. __asm__ __volatile__ ("outw %%ax,%%dx"
  50.                 ::"a" (value),"d" ((unsigned short) port));
  51.         SLOW_DOWN_IO;
  52. }
  53.  
  54. unsigned int inline inb_p(unsigned short port)
  55. {
  56.         unsigned int _v;
  57. __asm__ __volatile__ ("inb %%dx,%%al"
  58.                 :"=a" (_v):"d" ((unsigned short) port),"0" (0));
  59.         SLOW_DOWN_IO;
  60.         return _v;
  61. }
  62.  
  63. unsigned int inline inw_p(unsigned short port)
  64. {
  65.         unsigned int _v;
  66. __asm__ __volatile__ ("inw %%dx,%%ax"
  67.                 :"=a" (_v):"d" ((unsigned short) port),"0" (0));
  68.         SLOW_DOWN_IO;
  69.         return _v;
  70. }
  71.  
  72. Works fine for me!
  73.  
  74. -- Hansruedi
  75.  
  76.