mung
Posts: 506
Joined: Fri Nov 18, 2011 10:49 am

iopl(3) calls in linux

Sat Aug 25, 2012 11:33 am

I am wanting access to bare metal using the iopl(3) call, does not seem to work???

the code probably looks something like this:

Code: Select all

e=iopl(3);
if(e) { fprintf(stderr,"iopl failed %i",e); exit(1); }

I compile and run with: sudo a.out and it fails

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: iopl(3) calls in linux

Sat Aug 25, 2012 12:00 pm

"sudo apt-get install manpages-dev && man 2 iopl" says: This call is mostly for the i386 architecture. On many other architectures it does not exist or will always return an error.

dwelch67
Posts: 955
Joined: Sat May 26, 2012 5:32 pm

Re: iopl(3) calls in linux

Sat Aug 25, 2012 1:47 pm

If you are running linux you are not really doing much bare metal. If you want to get direct access to hardware from linux, try mmap().

David

mung
Posts: 506
Joined: Fri Nov 18, 2011 10:49 am

Re: iopl(3) calls in linux

Sat Aug 25, 2012 2:14 pm

dwelch67 wrote:If you are running linux you are not really doing much bare metal. If you want to get direct access to hardware from linux, try mmap().

David

I really don't know anything much about the low level kernel stuff that is why I am asking here, but as I have got some attention I will further elaborate on my full situation.

1) I have already written a driver for my hardware using /dev/mem memmap it seems to work when tested under sudo.
2) I have a codebase that I want to integrate the driver into and it seems to use iopl(3), I dont want to start hacking it to pieces unless absolutely necessary
3) I have no real idea about how everything works at present so am hoping someone can give me a brief idiots guide type reply.
4) http://www.makelinux.net/ldd3/chp-9-sect-2 seems to suggest that iopl(3) is fully supported by ARM???


I think the iopl(3) call give full SUID root access to the hardware and avoids running the entire program as root privilege, the driver will not run unless it has root access.

I wonder how X handles this problem?

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: iopl(3) calls in linux

Sat Aug 25, 2012 3:36 pm

mung wrote:4) http://www.makelinux.net/ldd3/chp-9-sect-2 seems to suggest that iopl(3) is fully supported by ARM???

I think the iopl(3) call give full SUID root access to the hardware and avoids running the entire program as root privilege, the driver will not run unless it has root access.

I wonder how X handles this problem?
X starts as root. You also need to be root to call iopl(), even on platforms where it exists. You should be able to drop root privileges after running the necessary setup calls, such as mmap(). setuid(getuid()) will attempt to drop root privileges in a suid program (but not under sudo).

That page only mentions iopl() in the context of x86. In fact it says that ARM does not have separate I/O ports, only memory mapping. So the thing that iopl() does is not even applicable.

If the code that you are trying to port calls iopl() then it probably goes on to use instructions like INB and OUTB, when the ARM equivalent is to use memory references instead. And the port numbers are sure to be specific to PC hardware.

Return to “Bare metal, Assembly language”