Page 1 of 1

werid problem gcc?

Posted: Fri Mar 26, 2010 3:41 pm
by Sam111
I am compiling this sound file sound.c
with

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -c sound.c
but I am getting this

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -c sound.c
In file included from <command line>:1:
c:/djgpp/lib/gcc-lib/djgpp/3.1/djgpp.ver:1:25: no include path in which to find
sys/version.h
sound.c: In function `play_sound':
sound.c:25: warning: implicit declaration of function `outb'
sound.c:30: warning: implicit declaration of function `inb'
sound.c:50:1: warning: no newline at end of file
when I don't include this -nostdinc It works fine an generates the .o file.

What I don't get is what this sys/version.h is and why I need it
This is for a kernel so I don't want to include any libraries that depend on anything just me own.

The sound file is this

Code: Select all


void sound();
static void play_sound(long int) ;
static void nosound();
void beep() ;

void sound()
{
int i = 1 ;
while( i == 1 )
{
beep() ;
}

}


 //Play sound using built in speaker
 static void play_sound(long int nFrequence) {
 	long int Div;
 	unsigned char tmp;
 
        //Set the PIT to the desired frequency
 	Div = 1193180 / nFrequence;
 	outb(0x43, 0xb6);
 	outb(0x42, (unsigned char) (Div) );
 	outb(0x42, (unsigned char) (Div >> 8));
 
        //And play the sound using the PC speaker
 	tmp = inb(0x61);
  	if (tmp != (tmp | 3)) {
 		outb(0x61, tmp | 3);
 	}
 }
 
 //make it shutup
 static void nosound() {
 	unsigned char tmp = (inb(0x61) & 0xFC);
 
 	outb(0x61, tmp);
 }
 
 //Make a beep
 void beep() {
 	 play_sound(1000);
 	 //timer_wait(10);
 	 nosound();
          //set_PIT_2(old_frequency);
 }
 

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 4:09 pm
by KotuxGuy

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -c sound.c
Well, first of all, you did not give an #include for GCC to search for the outb and inb function prototypes.
Secondly, I think you should add the -nostartfiles option, as that should eliminate the sys/version.h stuff.

Thirdly, I don't mean to be mean ( :D ) or anything, but if you don't know what those options are, you need to study GCC's options, not copy-paste wiki code.

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 4:26 pm
by Sam111
Well the nostartfiles option didn't work?

And My problem is I don't know why I need to include this file it is not one of my includes?
And I don't know why the compiler would even complain about this.

Second I know how to include libraries and files using gcc ,...etc that is not my problem....

third of all I cleared up the inb, outb implicity stuff that wasn't my problem
This is
no include path in which to find
sys/version.h
I am sure I can include it but I really don't want to if I don't have to because if it depends on something else I am screwed.

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 4:58 pm
by Sam111
This doesn't seem to work either

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -I C:\djgpp\include\sys\version.h -c sound.c
it gives me this

Code: Select all

The system cannot execute the specified program.
So I must be typing something in wrong but the path is C:\djgpp\include\sys\version.h
but I am in C:\KERNEL~1 if I have to use ..\ before or something #-o

I mean I can get rid of all this be using gcc -c sound.c
however I would like to use the switches -nostdlib ,...etc if possible and just include that one include if I even need it.

Or maybe their is a way to tell djpgg not to need the sys/version

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 5:24 pm
by KotuxGuy
you wrote: I don't know why the compiler would even complain about this.
Because it cannot find the function prototypes. Honestly, you should know this..
you also wrote:This doesn't seem to work either

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -I C:\djgpp\include\sys\version.h -c sound.c
That's because the -I option adds a directory, not a file. Look at the GCC manual!
Plus, look at that version.h file and see what it has in it.

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 5:27 pm
by Combuster
djgpp/3.1
Seriously, get rid of that. That's meant for DOS and that version is nearly a decade old. Use a GCC Cross-Compiler instead.

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 5:38 pm
by KotuxGuy
Well, maybe he's using DOSBox, or something. Why would he do that, I dunno.
But we'll never know if he doesn't tell us, will we? :lol:

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 5:41 pm
by Sam111
C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -I C:\djgpp\include\sys\version.h -c sound.c
I changed it to -I C:\djgpp\include\sys\ not working anyway I have even tried the -L switch that didn't work.

version.h has this in it

Code: Select all

/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */

#undef DJGPP
#undef __DJGPP
#undef __DJGPP__

#define DJGPP 2
#define __DJGPP 2
#define __DJGPP__ 2

#undef DJGPP_MINOR
#undef __DJGPP_MINOR
#undef __DJGPP_MINOR__

#define DJGPP_MINOR 3
#define __DJGPP_MINOR 3
#define __DJGPP_MINOR__ 3

That is all their is in it
when I temporary copy the version.h to my folder it works.

But then when I link
ld -T link.ld sound.o load2.o
I get this error

Code: Select all

load2.o(.text+0x48): relocation truncated to fit: 16 .text
my link.ld is this

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(main)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
I just don't see where this error is occuring and why it is exceeding the space .....

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 5:53 pm
by Brynet-Inc
As you've been told repeatedly, you're using the functions inb/outb() without providing your own implementation.. djgpp generously provides inline versions in that header file.

This is quite obvious, clearly you do not have the required knowledge.. or the ability to apply some common sense.

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 6:02 pm
by Sam111
no that is not my problem in my sound.c
I have

Code: Select all

unsigned char inb (unsigned short _port)
{
    unsigned char rv;
    __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
    return rv;
}

void outb (unsigned short _port, unsigned char _data)
{
    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
}

My problem is I cann't get rid of the requirement of sys\version.h
And if I compile with gcc -c sound.c => when I try to link with my linker script I get this truncation error.
So I don't understand 2 thing where in the linker script it is doing truncation and why.
And how to get rid of this header file thing?
Also I don't want to do just gcc -c filename.c because I know it will probably include stuff I cann't use in the kernel.

I am sorry but I am learning and need a little help

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 6:19 pm
by Sam111
Ok , this did it

Code: Select all

C:\KERNEL~1>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functio
ns -nostdinc -fno-builtin -c sound.c -I../djgpp/include
turns out I didn't know the correct way to do up a directory
your not supposed to have ../C: just ../djgpp

but I am still getting
this

Code: Select all

C:\KERNEL~1>ld -T link.ld sound.o load2.o
load2.o(.text+0x48): relocation truncated to fit: 16 .text

Re: werid problem gcc?

Posted: Fri Mar 26, 2010 7:20 pm
by Sam111
Never mind I cleared that up as well.
thanks for the help