LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-17-2009, 01:22 AM   #16
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231

see here
 
Old 10-17-2009, 01:29 AM   #17
Danteleo
LQ Newbie
 
Registered: Oct 2006
Posts: 28

Original Poster
Rep: Reputation: 16
Isn't that why it uses this command to run the script?

sudo gcc -O2 -o rccar rccar.c


I don't know C/C++ so it's just a guess.
 
Old 10-17-2009, 01:31 AM   #18
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
u got me there this time
 
Old 10-17-2009, 01:34 AM   #19
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
"man outb" for me...

Hm,
According to the man page for my distribution ("man outb")

Quote:
The value argument is passed first and the port argument is passed second
And from what I can tell, that's exactly what rccar.c is doing;

Code:
sysop$ nl rccar.c|grep outb
    34   * *  outb(8, x)   = pin 5      UNUSED
    35   * *  outb(16, x)  = pin 6      Forward
    36   * *  outb(32, x)  = pin 7      Reverse
    37   * *  outb(64, x)  = pin 8      Left
    38   * *  outb(128, x) = pin 9      Right
    39   * *  outb(80, x)  = pin 6 & 8  FORWARDLEFT
    40   * *  outb(144, x) = pin 6 & 9  FORWARDRIGHT
    41   * *  outb(96, x)  = pin 7 & 8  REVERSELEFT
    42   * *  outb(160, x) = pin 7 & 9  REVERSERIGHT
    64   outb(16, LPT1PORT);     /* Set pin 9 to high */
    69   outb(32, LPT1PORT);
    74   outb(64, LPT1PORT);
    79   outb(128, LPT1PORT);
    84   outb(80, LPT1PORT);
    89   outb(144, LPT1PORT);
    94   outb(96, LPT1PORT);
    99   outb(160, LPT1PORT);
   105   outb(0, LPT1PORT);      /* Set the data signals (D0-7) of the port to all low (0) */
   110   outb(0, LPT1PORT);
However we have 9 "outb(#, x)" where I'm thinking we should be defining the port (LPT1PORT), rather than just "x"

I'm thinking that maybe one of the "outb" friends might help....

As for the optimization flags ("-O" versus "-O2" versus nothing), I think we're safe. The "outb" doesn't appear to be affected by those flags....

Last edited by xeleema; 10-17-2009 at 01:36 AM.
 
Old 10-17-2009, 01:39 AM   #20
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by xeleema View Post
Hm,
As for the optimization flags ("-O" versus "-O2" versus nothing), I think we're safe. The "outb" doesn't appear to be affected by those flags....
did you read my link?
@Original poster
try putting this on the top of the file
#define outb(n, port) outportb(port, n)
#define inpb inportb
 
Old 10-17-2009, 01:39 AM   #21
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Found more "outb" information....

Found an interesting chunk over here;

Quote:
Obsolete IO macros

Back in a time when AVR-GCC and avr-libc could not handle IO port access in the direct assignment form as they are handled now, all IO port access had to be done through specific macros that eventually resulted in inline assembly instructions performing the desired action.

These macros became obsolete, as reading and writing IO ports can be done by simply using the IO port name in an expression, and all bit manipulation (including those on IO ports) can be done using generic C bit manipulation operators.

The macros in this group simulate the historical behaviour. While they are supposed to be applied to IO ports, the emulation actually uses standard C methods, so they could be applied to arbitrary memory locations as well.
#define inp(port) (port)
#define outp(val, port) (port) = (val)
#define inb(port) (port)
#define outb(port, val) (port) = (val)
#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))
 
Old 10-17-2009, 01:43 AM   #22
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by xeleema View Post
Found an interesting chunk over here;
that obviously will not work
 
Old 10-17-2009, 01:45 AM   #23
Danteleo
LQ Newbie
 
Registered: Oct 2006
Posts: 28

Original Poster
Rep: Reputation: 16
Got this after adding
#define outb(n, port) outportb(port, n)
#define inpb inport



[CODE]shawn@shawn-desktop:~/Desktop$ sudo gcc -O2 -o rccar rccar.c
[sudo] password for shawn:
rccar.c: In function ‘main’:
rccar.c:131: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result
/tmp/ccuSNFAn.o: In function `main':
rccar.c.text+0x11e): undefined reference to `outportb'
rccar.c.text+0x150): undefined reference to `outportb'
rccar.c.text+0x180): undefined reference to `outportb'
rccar.c.text+0x1b0): undefined reference to `outportb'
rccar.c.text+0x1e0): undefined reference to `outportb'
/tmp/ccuSNFAn.o:rccar.c.text+0x210): more undefined references to `outportb' follow
collect2: ld returned 1 exit status
/CODE]
 
Old 10-17-2009, 01:46 AM   #24
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
dang it!
this is one of those few reasons dos/windows is better then linux
 
Old 10-17-2009, 01:47 AM   #25
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
FYI: swapping the port and value for all the "outb" statements didn't work.

Code:
sysop$ diff rccar.c rccar.c.new
64c64
< outb(LPT1PORT, 16);     /* Set pin 9 to high */
---
> outb(16, LPT1PORT);     /* Set pin 9 to high */
69c69
< outb(LPT1PORT, 32);
---
> outb(32, LPT1PORT);
74c74
< outb(LPT1PORT, 64);
---
> outb(64, LPT1PORT);
79c79
< outb(LPT1PORT, 128);
---
> outb(128, LPT1PORT);
84c84
< outb(LPT1PORT, 80);
---
> outb(80, LPT1PORT);
89c89
< outb(1LPT1PORT, 44);
---
> outb(144, LPT1PORT);
94c94
< outb(LPT1PORT, 96);
---
> outb(96, LPT1PORT);
99c99
< outb(LPT1PORT, 160);
---
> outb(160, LPT1PORT);
105c105
< outb(LPT1PORT, 0);      /* Set the data signals (D0-7) of the port to all low (0) */
---
> outb(0, LPT1PORT);      /* Set the data signals (D0-7) of the port to all low (0) */
 
Old 10-17-2009, 01:54 AM   #26
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
"Teh Win" or "Fail" ?

Okay, get this, I added "#include <sys/io.h>

Code:
sysop$ gcc -O2 -o rccar rccar.c
sysop$ ldd rccar
        linux-gate.so.1 =>  (0xffffe000)
        libc.so.6 => /lib/libc.so.6 (0xb7f0a000)
        /lib/ld-linux.so.2 (0xb806b000)
sysop$ ./rccar
ioperm: Operation not permitted
*SO* close! I think we need to call i386_set_ioperm instead of just ioperm....
 
Old 10-17-2009, 01:56 AM   #27
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
try compiling with gcc -O2 rccar rccar.c

Last edited by smeezekitty; 10-17-2009 at 01:57 AM. Reason: urine and tree + cat hair under the dogs foot
 
Old 10-17-2009, 01:59 AM   #28
Danteleo
LQ Newbie
 
Registered: Oct 2006
Posts: 28

Original Poster
Rep: Reputation: 16
When I added #include <sys/io.h>

I got this

Code:
shawn@shawn-desktop:~/Desktop$ sudo gcc -O2 -o rccar rccar.c
[sudo] password for shawn:
rccar.c:46:1: warning: "inpb" redefined
rccar.c:45:1: warning: this is the location of the previous definition
rccar.c: In function ?main?:
rccar.c:134: warning: ignoring return value of ?read?, declared with attribute warn_unused_result
 
Old 10-17-2009, 02:02 AM   #29
Danteleo
LQ Newbie
 
Registered: Oct 2006
Posts: 28

Original Poster
Rep: Reputation: 16
I get this when I compile using


sudo gcc -O2 rccar rccar.c

as opposed to

sudo gcc -O2 -o rccar rccar.c


Code:
shawn@shawn-desktop:~/Desktop$ sudo gcc -O2 rccar rccar.c                                     
rccar.c:46:1: warning: "inpb" redefined                                                       
rccar.c:45:1: warning: this is the location of the previous definition
rccar.c: In function ‘main’:
rccar.c:134: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result
rccar: In function `_start':
/build/buildd/glibc-2.9/csu/../sysdeps/i386/elf/start.S:65: multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o:/build/buildd/glibc-2.9/csu/../sysdeps/i386/elf/start.S:65: first defined here
rccar:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here
rccar: In function `_fini':
/build/buildd/glibc-2.9/csu/../sysdeps/generic/initfini.c:109: multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crti.o:/build/buildd/glibc-2.9/csu/../sysdeps/generic/initfini.c:109: first defined here
rccar:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
rccar: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o:(.data+0x0): first defined here
rccar: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.3.3/crtbegin.o:(.data+0x0): first defined here
rccar: In function `_init':
/build/buildd/glibc-2.9/build-tree/i386-libc/csu/crti.S:15: multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crti.o:/build/buildd/glibc-2.9/build-tree/i386-libc/csu/crti.S:15: first defined here
/tmp/cciBw3vh.o: In function `main':
rccar.c:(.text+0x0): multiple definition of `main'
rccar:(.text+0xc0): first defined here
/usr/lib/gcc/i486-linux-gnu/4.3.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
rccar:(.dtors+0x4): first defined here
collect2: ld returned 1 exit status
 
Old 10-17-2009, 02:07 AM   #30
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Quote:
try compiling with gcc -O2 rccar rccar.c
Dropping the "-o" doesn't even work for me, I get

Quote:
root# gcc -O2 rccar rccar.c
gcc: rccar: No such file or directory
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make: *** [all] Error 2 ? Need Help compiling DOSBOX source code! d3vi4nt Linux - Software 7 01-08-2010 12:41 AM
Getting cannot find symbol error compiling java code using NetBeans 6.5 IDE rstewart Programming 1 02-13-2009 04:43 PM
c++ code compiling error k1ll3r_x Programming 4 10-03-2006 02:41 AM
error in compiling simple code Tinku Programming 6 09-17-2004 01:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration