home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!pizol!heeb
- From: heeb@watson.ibm.com (Hansruedi Heeb)
- Subject: Re: ?? Why no out/in in assembler ?? (CODE to do out/in from C)
- Sender: news@watson.ibm.com (NNTP News Poster)
- Message-ID: <1993Jan26.033933.12233@watson.ibm.com>
- Date: Tue, 26 Jan 1993 03:39:33 GMT
- Disclaimer: This posting represents the poster's views, not necessarily those of IBM
- References: <C1DpM9.H6L@helios.physics.utoronto.ca> <C1E98M.4JE@ichaos.nullnet.fi> <C1Fno4.IBI@helios.physics.utoronto.ca>
- Nntp-Posting-Host: pizol.watson.ibm.com
- Organization: IBM T.J. Watson Research Center
- Lines: 62
-
- In article <C1Fno4.IBI@helios.physics.utoronto.ca> grindley@helios.physics.utoronto.ca (Robin Grindley) writes:
- >
- >Sorry, i should have been a little clearer. I realize that user tasks will
- >run at different privileges and IOPL's. Any normal code should not be allowed
- >to do what i want. But if one wants to debug a system one has to have access
- >to tools that can bypass normal security. My question is, IF i do setup
- >a task to run as root and i make sure i have the correct IOPL, the assembler
- >does not even have the capability to generate these instructions (they are
- >not in its "dictionary").
- >
-
- I think what you want can be done directly from C.
-
- Sample code (mostly stolen from the kernel):
-
- #define SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
-
- ...
-
- if (iopl(3)) {
- fprintf(stderr,"%s: iopl failed (must be root!)\n",argv[0]);
- exit(1);
- }
-
- ...
-
- void inline outb_p(char value, unsigned short port)
- {
- __asm__ __volatile__ ("outb %%al,%%dx"
- ::"a" ((char) value),"d" ((unsigned short) port));
- SLOW_DOWN_IO;
- }
-
- void inline outw_p(char value, unsigned short port)
- {
- __asm__ __volatile__ ("outw %%ax,%%dx"
- ::"a" (value),"d" ((unsigned short) port));
- SLOW_DOWN_IO;
- }
-
- unsigned int inline inb_p(unsigned short port)
- {
- unsigned int _v;
- __asm__ __volatile__ ("inb %%dx,%%al"
- :"=a" (_v):"d" ((unsigned short) port),"0" (0));
- SLOW_DOWN_IO;
- return _v;
- }
-
- unsigned int inline inw_p(unsigned short port)
- {
- unsigned int _v;
- __asm__ __volatile__ ("inw %%dx,%%ax"
- :"=a" (_v):"d" ((unsigned short) port),"0" (0));
- SLOW_DOWN_IO;
- return _v;
- }
-
- Works fine for me!
-
- -- Hansruedi
-
-