Page 1 of 1

gcc optimization

Posted: Thu Jul 30, 2009 9:21 pm
by mcheung63
void setGDTR(char *gdt, unsigned short numberOfGDTDescriptor) {
char gdtr[6];
memset(gdtr, 0, 6);
if (numberOfGDTDescriptor < 8192) {
if (numberOfGDTDescriptor == 0) {
*(unsigned short *)gdtr = (unsigned short) 0; //gdtr's limit is 8N-1
} else {
*(unsigned short *)gdtr = (unsigned short) (8 * numberOfGDTDescriptor)
- 1; //gdtr's limit is 8N-1
}
*(unsigned int *) (gdtr + 2) = gdt;
__asm__ __volatile__("lgdt (%%eax)"::"a"(gdtr));
}
}

GCC thinks I haven't used the gdtr variable, so all the line with gdtr will be be compiled into instruction code. May I know how to fix it?

thanks
from Peter ([email protected])

Re: gcc optimization

Posted: Thu Jul 30, 2009 9:46 pm
by frank
Maybe try

Code: Select all

-O0

Re: gcc optimization

Posted: Thu Jul 30, 2009 10:25 pm
by 01000101
this may give GCC the hint:

Code: Select all

*(volatile unsigned short *)gdtr =

Re: gcc optimization

Posted: Fri Jul 31, 2009 10:17 am
by gravaera
Yup. 01000101 beat me to it. Whenever GCC engages in folly, I just volatile that ho (Ohhhh). ;)

Re: gcc optimization

Posted: Fri Jul 31, 2009 12:10 pm
by mcheung63
thanks gentlemen