public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Assembler in C under Linux
@ 1999-12-02 11:37 Marshall Perrin
  1999-12-04 22:51 ` Martin Kahlert
  1999-12-31 22:24 ` Marshall Perrin
  0 siblings, 2 replies; 4+ messages in thread
From: Marshall Perrin @ 1999-12-02 11:37 UTC (permalink / raw)
  To: help-gcc

I'm trying to port a driver for a digital signal processor card from
DOS to Linux. The DOS driver, developed by someone not me ;-), is
mostly C but has a fair amount of inline assembler.  For Borland C for 
DOS, this was pretty easy to do. Just
  asm {
      mov dx, DSP_BaseIO
      add dx, reg_offset
 }
etc etc.

Gcc of course chokes on the above. I've attempted to read through the gcc
documentation and figure out how to do this, but no luck. That led me 
towards something like

    asm("mov dx, %0" : : "d" (DSP32C_BaseIo));
    asm("add dx, %0" : : "d" (reg_offset));
    asm("in ax,dx");
    asm("mov %0,ax"  :"=d" (value) : );

And yet I get the error message "/tmp/ccAimSJo.s:818: Error: 
operands given don't match any known 386 instruction" over and over again
with that approach.

Poking through the kernel source leads me to try something like

    asm("mov %%edx, %0" : : "b" (DSP_BaseIo));
    asm("add %%edx, %0" : : "b" (reg_offset));
    asm("in %%eax,%%edx");
    asm("mov %0,%%eax"  :"=b" (value) : );

But that's no luck either - If I comment out the third line, that compiles, 
but if the 3rd line is there I get "/tmp/ccGjg9uV.s:26: Error: bad 
register name ('%%eax')", which makes little sense as I use %%eax just fine
in the other three instructions.

So, what am I doing wrong? Any help here would be greatly appreciated, whether it be 
pointer to a web page, book, or some other source of information. Thanks much!

 - Marshall Perrin
   Harvard/Smithsonian Center for Astrophysics


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

* Re: Assembler in C under Linux
  1999-12-02 11:37 Assembler in C under Linux Marshall Perrin
@ 1999-12-04 22:51 ` Martin Kahlert
  1999-12-31 22:24   ` Martin Kahlert
  1999-12-31 22:24 ` Marshall Perrin
  1 sibling, 1 reply; 4+ messages in thread
From: Martin Kahlert @ 1999-12-04 22:51 UTC (permalink / raw)
  To: help-gcc

[Posted and mailed]

In article < slrn84dhpn.ihf.mperrin@hcs.harvard.edu >,
	mperrin@hcs.harvard.edu (Marshall Perrin) writes:
> I'm trying to port a driver for a digital signal processor card from
> DOS to Linux. The DOS driver, developed by someone not me ;-), is
> mostly C but has a fair amount of inline assembler.  For Borland C for 
> DOS, this was pretty easy to do. Just
>   asm {
>       mov dx, DSP_BaseIO
>       add dx, reg_offset
>  }
> etc etc.
> 
> Gcc of course chokes on the above. I've attempted to read through the gcc
> documentation and figure out how to do this, but no luck. That led me 
> towards something like
> 
>     asm("mov dx, %0" : : "d" (DSP32C_BaseIo));
>     asm("add dx, %0" : : "d" (reg_offset));
>     asm("in ax,dx");
>     asm("mov %0,ax"  :"=d" (value) : );

The (hopefully) correct syntax for these lines would be
something like:

#include <stdio.h>

int main(int argc,const char *argv[])
{
 short int DSP32C_BaseIo=18,reg_offset=15,value;
 asm("inw %1, %0" : "=r" (value) : "r" (DSP32C_BaseIo+reg_offset));

 printf("value=%d\n",value);
 return 0;
}

Then gcc -O -o prog prog.c
         ^^^ important!
This prog doesn't work!

In LINUX you can't directly access the hardware.
Write a driver, or write a setuid root program.

All the stuff the asm does could be done easily
and much more portable in C.
For that read 
http://www.linuxdoc.org/HOWTO/mini/IO-Port-Programming.html
first.

Hope that helps,
Martin.

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

* Re: Assembler in C under Linux
  1999-12-04 22:51 ` Martin Kahlert
@ 1999-12-31 22:24   ` Martin Kahlert
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Kahlert @ 1999-12-31 22:24 UTC (permalink / raw)
  To: help-gcc

[Posted and mailed]

In article < slrn84dhpn.ihf.mperrin@hcs.harvard.edu >,
	mperrin@hcs.harvard.edu (Marshall Perrin) writes:
> I'm trying to port a driver for a digital signal processor card from
> DOS to Linux. The DOS driver, developed by someone not me ;-), is
> mostly C but has a fair amount of inline assembler.  For Borland C for 
> DOS, this was pretty easy to do. Just
>   asm {
>       mov dx, DSP_BaseIO
>       add dx, reg_offset
>  }
> etc etc.
> 
> Gcc of course chokes on the above. I've attempted to read through the gcc
> documentation and figure out how to do this, but no luck. That led me 
> towards something like
> 
>     asm("mov dx, %0" : : "d" (DSP32C_BaseIo));
>     asm("add dx, %0" : : "d" (reg_offset));
>     asm("in ax,dx");
>     asm("mov %0,ax"  :"=d" (value) : );

The (hopefully) correct syntax for these lines would be
something like:

#include <stdio.h>

int main(int argc,const char *argv[])
{
 short int DSP32C_BaseIo=18,reg_offset=15,value;
 asm("inw %1, %0" : "=r" (value) : "r" (DSP32C_BaseIo+reg_offset));

 printf("value=%d\n",value);
 return 0;
}

Then gcc -O -o prog prog.c
         ^^^ important!
This prog doesn't work!

In LINUX you can't directly access the hardware.
Write a driver, or write a setuid root program.

All the stuff the asm does could be done easily
and much more portable in C.
For that read 
http://www.linuxdoc.org/HOWTO/mini/IO-Port-Programming.html
first.

Hope that helps,
Martin.

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

* Assembler in C under Linux
  1999-12-02 11:37 Assembler in C under Linux Marshall Perrin
  1999-12-04 22:51 ` Martin Kahlert
@ 1999-12-31 22:24 ` Marshall Perrin
  1 sibling, 0 replies; 4+ messages in thread
From: Marshall Perrin @ 1999-12-31 22:24 UTC (permalink / raw)
  To: help-gcc

I'm trying to port a driver for a digital signal processor card from
DOS to Linux. The DOS driver, developed by someone not me ;-), is
mostly C but has a fair amount of inline assembler.  For Borland C for 
DOS, this was pretty easy to do. Just
  asm {
      mov dx, DSP_BaseIO
      add dx, reg_offset
 }
etc etc.

Gcc of course chokes on the above. I've attempted to read through the gcc
documentation and figure out how to do this, but no luck. That led me 
towards something like

    asm("mov dx, %0" : : "d" (DSP32C_BaseIo));
    asm("add dx, %0" : : "d" (reg_offset));
    asm("in ax,dx");
    asm("mov %0,ax"  :"=d" (value) : );

And yet I get the error message "/tmp/ccAimSJo.s:818: Error: 
operands given don't match any known 386 instruction" over and over again
with that approach.

Poking through the kernel source leads me to try something like

    asm("mov %%edx, %0" : : "b" (DSP_BaseIo));
    asm("add %%edx, %0" : : "b" (reg_offset));
    asm("in %%eax,%%edx");
    asm("mov %0,%%eax"  :"=b" (value) : );

But that's no luck either - If I comment out the third line, that compiles, 
but if the 3rd line is there I get "/tmp/ccGjg9uV.s:26: Error: bad 
register name ('%%eax')", which makes little sense as I use %%eax just fine
in the other three instructions.

So, what am I doing wrong? Any help here would be greatly appreciated, whether it be 
pointer to a web page, book, or some other source of information. Thanks much!

 - Marshall Perrin
   Harvard/Smithsonian Center for Astrophysics


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

end of thread, other threads:[~1999-12-31 22:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-02 11:37 Assembler in C under Linux Marshall Perrin
1999-12-04 22:51 ` Martin Kahlert
1999-12-31 22:24   ` Martin Kahlert
1999-12-31 22:24 ` Marshall Perrin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).