[fpc-pascal] accessing hardware ports in FPC

Daniël Mantione daniel.mantione at freepascal.org
Tue May 22 14:08:45 CEST 2007



Op Tue, 22 May 2007, schreef Tomas Hajny:

> I don't know Linux, but: If ioperm needs to be called just once (without
> specifying a particular port number), this call could be added to unit
> initialization. If it needs to be called for particular port number or
> port range, we could add a function doing this to interface of unit ports
> (and document it as appropriate, of course), because it's better to
> provide common approach than to require users to fiddle with IFDEFs and
> platform specific API for this (such a function probably exists for most
> platforms and platforms not requiring such a thing may simply ignore it).

It would be a good idea to make even this platform independend, but only =

if you can provide similar semantics on all platforms. However, at least =

in the case of Linux, it such not entirely clear what this initialization =

should do.

There are two calls:
* ioperm, allows you to ports $0..$3ff, for each port individually.
* iopl, which moves the program into cpu ring 2. It can then access ports
  $0..$ffff and execute the cli/sti instructions.

A program can inherite port access, if the parent process has io port =

access, so has the child. So, perhaps the intention of the user could even =

be that no io permission is asked.
 =

> Potentially, we could even add a boolean array to implementation part of
> unit ports maintaining the permission status for all the ports. Calling
> the "IOPerm" function would mark access to that port as permitted. Call to
> getter/setter would check the status first and call IOPerm if needed,
> otherwise skip the IOPerm call (that would allow both fast access and "no
> hassle" approach for our users).

This could be an elegant way to abstract the ioperm style functionality =

into a platform independend interface.

Dani=EBl


More information about the fpc-pascal mailing list