comp.lang.ada
 help / color / mirror / Atom feed
* inb/outb for GNAT (Linux) ??
@ 1998-01-27  0:00 Nicolas NAVET
  1998-01-27  0:00 ` David Bacon
  1998-01-28  0:00 ` Markus Kuhn
  0 siblings, 2 replies; 4+ messages in thread
From: Nicolas NAVET @ 1998-01-27  0:00 UTC (permalink / raw)



Hello,

 I'am using GNAT for Linux. I need to write
 data to a serial port. Is it possible to do that with ADA
 without using a device driver ?
 I' have searched through the packages for functions like 
 inb()/outb() but without result.
       

Thanks,

Nicolas Navet




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: inb/outb for GNAT (Linux) ??
  1998-01-27  0:00 inb/outb for GNAT (Linux) ?? Nicolas NAVET
@ 1998-01-27  0:00 ` David Bacon
  1998-01-28  0:00 ` Markus Kuhn
  1 sibling, 0 replies; 4+ messages in thread
From: David Bacon @ 1998-01-27  0:00 UTC (permalink / raw)



Nicolas NAVET wrote:
> 
> Hello,
> 
>  I'am using GNAT for Linux. I need to write
>  data to a serial port. Is it possible to do that with ADA
>  without using a device driver ?
>  I' have searched through the packages for functions like
>  inb()/outb() but without result.
> 
> 
> Thanks,
> 
> Nicolas Navet

You are looking in the wrong place, and my answer is necessarily
not Ada-specific:

In Linux, the serial ports can be opened and written to in much
the same way as regular files.  They are usually named /dev/cua0,
/dev/cua1, etc.  For low-level operations (such as manipulating
the DTR bit), you may find direct-access operations on /dev/port
useful also (try "man port" on Slackware or RedHat Linux).

     dB




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: inb/outb for GNAT (Linux) ??
  1998-01-27  0:00 inb/outb for GNAT (Linux) ?? Nicolas NAVET
  1998-01-27  0:00 ` David Bacon
@ 1998-01-28  0:00 ` Markus Kuhn
  1998-01-28  0:00   ` Corey Minyard
  1 sibling, 1 reply; 4+ messages in thread
From: Markus Kuhn @ 1998-01-28  0:00 UTC (permalink / raw)



Nicolas NAVET wrote:
>  I'am using GNAT for Linux. I need to write
>  data to a serial port. Is it possible to do that with ADA
>  without using a device driver ?

This has nothing to do with Ada or GNAT:

No Linux process can directly access the peripherial hardware
directly with in/out assembler instructions. Linux is not DOS.
The same applies for WinNT, btw.

If you are running as root, you can access ports indirectly via the
/dev/port device (read "man 4 port" on this) using the open(),
lseek(), read(), and write() system calls or their Ada equivalents.
For everything more sophisticated, you'll have to write a
loadable kernel module (either in Ada or in C, as you wish) to
do the job as a device driver.

>  I' have searched through the packages for functions like
>  inb()/outb() but without result.

Not surprising, because these functions would be useless except
for kernel developers. You can always directly include these
assembler instructions, but it will cause a Bus Error and abort
your process unless you are inside the kernel. This has nothing
to do with Ada, it happens under C exactly the same way.

What you probably really want to do instead is to access the
serial port via the existing Linux kernel driver as the
devices /dev/ttyS0 and /dev/ttyS1 just as any other Unix process
is doing it.

Hope this helped ...

Markus

-- 
Markus G. Kuhn, Security Group, Computer Lab, Cambridge University, UK
email: mkuhn at acm.org,  home page: <http://www.cl.cam.ac.uk/~mgk25/>




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: inb/outb for GNAT (Linux) ??
  1998-01-28  0:00 ` Markus Kuhn
@ 1998-01-28  0:00   ` Corey Minyard
  0 siblings, 0 replies; 4+ messages in thread
From: Corey Minyard @ 1998-01-28  0:00 UTC (permalink / raw)



Markus Kuhn <Markus.Kuhn@cl.cam.ac.uk> writes:

> Nicolas NAVET wrote:
> >  I'am using GNAT for Linux. I need to write
> >  data to a serial port. Is it possible to do that with ADA
> >  without using a device driver ?
> 
> This has nothing to do with Ada or GNAT:
> 
> No Linux process can directly access the peripherial hardware
> directly with in/out assembler instructions. Linux is not DOS.
> The same applies for WinNT, btw.

Wrong.  On an ix86 under linux, you can call ioperm() or iopl() with
the proper parameters then do inb and outb instructions to your
heart's content (you have to be root to do this, obviously).  Most X
servers require this to set things up properly, dosemu allows it for
direct port acess, and I have done it for writing some test drivers.

To do this , you will have to create bindings to all the functions
that you need.  I doubt any standard binding exist to do this since it
is very non-portable and non-standard.  Also note that you cannot
get interrupts from the serial port.

> What you probably really want to do instead is to access the
> serial port via the existing Linux kernel driver as the
> devices /dev/ttyS0 and /dev/ttyS1 just as any other Unix process
> is doing it.

This I agree with.  Learning the semantics of termios is kind of a
pain, but your program will be MUCH more portable between *nix system,
it will be able to use any type of serial port on Linux, etc.  Richard
Steven's book "Advanced Programming in the Unix Environment" is my
favorite book on the subject, well worth having if you do any serious
programming under Unix.  With the Posix Ada bindings, you don't even
have to write any C code.  If you are interested, I have a program to
page alphanumeric pagers on a modem on my web page written in Ada95
that uses the Posix bindings.  I also have a copy of the forest Posix
binding there that will compile on Linux with gnat-3.10p.

-- 
Corey Minyard               Internet:  minyard@acm.org
  Work: minyard@nortel.ca       UUCP:  minyard@wf-rch.cirr.com




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-01-28  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-27  0:00 inb/outb for GNAT (Linux) ?? Nicolas NAVET
1998-01-27  0:00 ` David Bacon
1998-01-28  0:00 ` Markus Kuhn
1998-01-28  0:00   ` Corey Minyard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox