[Lazarus-es] Utilizando asm

José Mejuto joshyfun en gmail.com
Vie Feb 25 09:39:26 CET 2011


Hello José,

Friday, February 25, 2011, 8:08:04 AM, you wrote:

JMJ>    Perdona, pero puede ser que no indicara el SO,
JMJ>     Estoy utilizando Ubuntu(linux)
JMJ>    Y me gustaria escribir un carácter en un puerto, utilizando ASM u otra cosa

Necesitas que tu Linux tenga un driver de modo kernel que te provea
del acceso a los puertos ya que sólo el kernel puede hacerlo.

La mayoría de Linux vienen con este driver de serie, el ioperm. En fpc
accedes a esa función incluyendo en el uses la unit "libc".

Un poco más de información, es para "C" pero la idea es la misma.

-------------------------
Before you access any ports, you must give your program permission to
do so. This is done by calling the ioperm() function (declared in
unistd.h, and defined in the kernel) somewhere near the start of your
program (before any I/O port accesses). The syntax is ioperm(from,
num, turn_on), where from is the first port number to give access to,
and num the number of consecutive ports to give access to. For
example, ioperm(0x300, 5, 1) would give access to ports 0x300 through
0x304 (a total of 5 ports). The last argument is a Boolean value
specifying whether to give access to the program to the ports (true
(1)) or to remove access (false (0)). You can call ioperm() multiple
times to enable multiple non-consecutive ports. See the ioperm(2)
manual page for details on the syntax.

The ioperm() call requires your program to have root privileges; thus
you need to either run it as the root user, or make it setuid root.
You can drop the root privileges after you have called ioperm() to
enable the ports you want to use. You are not required to explicitly
drop your port access privileges with ioperm(..., 0) at the end of
your program; this is done automatically as the process exits.

A setuid() to a non-root user does not disable the port access granted
by ioperm(), but a fork() does (the child process does not get access,
but the parent retains it).

ioperm() can only give access to ports 0x000 through 0x3ff; for higher
ports, you need to use iopl() (which gives you access to all ports at
once). Use the level argument 3 (i.e., iopl(3)) to give your program
access to all I/O ports (so be careful --- accessing the wrong ports
can do all sorts of nasty things to your computer). Again, you need
root privileges to call iopl(). See the iopl(2) manual page for
details.
-------------------------

http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html#s2

-- 
Best regards,
 José





More information about the Lazarus-es mailing list