comp.lang.ada
 help / color / mirror / Atom feed
* R/W hardware registers ?
@ 2017-06-29 22:38 patrick
  2017-06-30  7:48 ` Jacob Sparre Andersen
  0 siblings, 1 reply; 5+ messages in thread
From: patrick @ 2017-06-29 22:38 UTC (permalink / raw)


Hi Everyone

This post is partly a a continuation of this one:

https://groups.google.com/forum/#!searchin/comp.lang.ada/ada$20hardware|sort:relevance/comp.lang.ada/ZhB27DtPb9I/y7dxjrhZCAAJ

There are some really great applications written in C but I try to avoid C whenever I can. I haven't been able to avoid it over the past few months.

There are lots of ways to interact with hardware from a desktop PC but a lot of them involve C. Microprocesor, SBCs(like RPI) and microcontroller based solutions are probably easier than ever before. There is great work being done with AVR-Ada but really all I want to do is use a desktop computer with some circuits.

I have been fooling around with parallel ports on and off the past few months. I am thinking about getting an ISA breadboard card and fooling around a little more. I have other plans but right now it's just some hobby silliness.

I have been reading about writing Linux device drivers but I just don't need interupts and so on and I am losing interest in reading about this further.

Assuming these:
1)It's just hobby fun
2)I am the only user
3)it's on Posix, normally linux
4)I am interacting with CPU-less, passive circuitry

Then do you see any major problems with just reading and writing to a device's registers though root access and without a kernel API?

Please see this program, it's cut down to keep it simple:


  #include <stdio.h>
  #include <unistd.h>   
  #include <sys/io.h>   

  /* Address of the first parallel port. found in BIOS settings. */
  #define kDATA_REG (0xec00)          /* Base address = data register. */
  #define kSTAT_REG (kDATA_REG + 1)    /* Status register. */
  #define kCONT_REG (kDATA_REG + 2)    /* Control register. */

  int main()
  {
      int i;

      if (ioperm(kDATA_REG, 1, 1))    /* Get permission to access this port. */
          {
          printf("ioperm(%x) failed.\nYou must be root to execute!\n", kDATA_REG);
          return 1;
          }

      if (ioperm(kCONT_REG, 1, 1))    /* Get permission to access this port. */
          {
          printf("ioperm(%x) failed.\nYou must be root to execute!\n", kDATA_REG);
          return 1;
          }



      /* Assume port is already in output mode (bit 5 in control register). */
      for (i = 0; i <= 9; i++)        /* Let the LED(s) blink. */
          {
          outb(i, kDATA_REG);       /* All 8 datalines high. */
          printf("value sent is %d \n", i) ;
          sleep(5);

          }
      return 0;
  }





The above program does this.

If it's just me, do I really need a call to ioperm ?

Could I not access registers through access/pointers ?

I bet I could have lots of fun with parallel ports, ISA cards and then after that maybe I could write to the registers of a PIC-E cards and have parallel to serial conversion done by the OS and I could dump ISA later and control circuits in a serial manner(I am not sure about this last part at all)

Does anyone see a pitfall I am about to fall into ?

Thanks for reading-Patrick





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

* Re: R/W hardware registers ?
  2017-06-29 22:38 R/W hardware registers ? patrick
@ 2017-06-30  7:48 ` Jacob Sparre Andersen
  2017-06-30 13:11   ` patrick
  0 siblings, 1 reply; 5+ messages in thread
From: Jacob Sparre Andersen @ 2017-06-30  7:48 UTC (permalink / raw)


patrick@spellingbeewinnars.org writes:

> Assuming these:
> 1)It's just hobby fun
> 2)I am the only user
> 3)it's on Posix, normally linux
> 4)I am interacting with CPU-less, passive circuitry
>
> Then do you see any major problems with just reading and writing to a
> device's registers though root access and without a kernel API?

Yes.  I'm pretty sure even processes running with UID = 0 have to go
through the kernel for accessing the hardware.

If you switch to DOS or some other "operating system" without memory
management, it is a different story, but POSIX operating systems are
supposed to provide memory management, and that blocks direct hardware
access outside the kernel.

But what's wrong with binding ioperm() and outb() to Ada?

Greetings,

Jacob
-- 
"Human beings just can't not communicate."


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

* Re: R/W hardware registers ?
  2017-06-30  7:48 ` Jacob Sparre Andersen
@ 2017-06-30 13:11   ` patrick
  2017-06-30 14:40     ` patrick
  2017-06-30 15:17     ` Dennis Lee Bieber
  0 siblings, 2 replies; 5+ messages in thread
From: patrick @ 2017-06-30 13:11 UTC (permalink / raw)


Hi Jacob

Thanks for answering my post. I am pretty sure you are right. I knew that DOS pretty much only has a root user and that user can access parallel ports and such and I knew that regular Posix users could not access hardware like this but I thought it could be by-passed with root access.

However, if that was the case, people could still set pointers to hardware addresses in C and skip the use of outb(and similar calls).

I can bind to ioperm and outb but at this point C is just pestering me. I want to use C when I choose to use it but it just seems to be everywhere and it won't leave me alone.

I just want a break from C, it's more about fun then it is about getting stuff done.

If I find a solution, I will post back to leave a trail of breadcrumbs for others.

Thanks again-Patrick

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

* Re: R/W hardware registers ?
  2017-06-30 13:11   ` patrick
@ 2017-06-30 14:40     ` patrick
  2017-06-30 15:17     ` Dennis Lee Bieber
  1 sibling, 0 replies; 5+ messages in thread
From: patrick @ 2017-06-30 14:40 UTC (permalink / raw)


I've spent an hour and a half on this, it's all old information. It looks like FreeDOS is the only or at least best option to do this but as GCC is completely incompatible with it, Ada will never fly there.

I will have to make a skeleton driver that uses ioperm and outb and friends. What a pain in the ass...

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

* Re: R/W hardware registers ?
  2017-06-30 13:11   ` patrick
  2017-06-30 14:40     ` patrick
@ 2017-06-30 15:17     ` Dennis Lee Bieber
  1 sibling, 0 replies; 5+ messages in thread
From: Dennis Lee Bieber @ 2017-06-30 15:17 UTC (permalink / raw)


On Fri, 30 Jun 2017 06:11:09 -0700 (PDT), patrick@spellingbeewinnars.org
declaimed the following:

>Thanks for answering my post. I am pretty sure you are right. I knew that DOS pretty much only has a root user and that user can access parallel ports and such and I knew that regular Posix users could not access hardware like this but I thought it could be by-passed with root access.
>
>However, if that was the case, people could still set pointers to hardware addresses in C and skip the use of outb(and similar calls).
>

	And you will find such restrictions in /any/ modern general purpose
multi-tasking OS* as they are designed to isolate the hardware from the
user.

	You have to descend to the realm of embedded RTOS to get direct
hardware access (and at that level, you likely have to write your own
device drivers anyway -- so getting close to creating a Linux kernel
module/driver to allow access from user-space).




* AmigaOS was a mixed blessing/bane -- it did not use memory protection,
all processes shared a flat memory space. This made it easy for a
mis-behaving process to kill the system, but it also made the IPC (message
ports => linked lists often carrying pointers to the data being passed)
very efficient -- and it needed to be as practically everything in the OS
went through message ports (opening a file sent IPC to file-handler process
[which new the filesystem]  which sent IPC to device handler [low-level
device access], etc.). Upgrading AmigaOS to use memory protection/virtual
memory would have required lots of overhead in copying/remapping IPC data
between the various processes.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/


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

end of thread, other threads:[~2017-06-30 15:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-29 22:38 R/W hardware registers ? patrick
2017-06-30  7:48 ` Jacob Sparre Andersen
2017-06-30 13:11   ` patrick
2017-06-30 14:40     ` patrick
2017-06-30 15:17     ` Dennis Lee Bieber

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