GCC optimizing my code away
Posted: Tue Nov 11, 2008 11:35 am
I compile all my source files with the -O2 flag.
I want to switch on the A20 gate and have the following code:
I use gcc 4.3.1 for compiling and if I compile this code gcc only makes assembly code so that I write 0 at 0x500 and 1 at 0x100500 and because for it the if statement is always true it doesn´t compile the rest of the function. How can I say to gcc (w/o creating an extra entry in my makefile for this source file) that it has not to optimize this code away?
I want to switch on the A20 gate and have the following code:
Code: Select all
uint32t enableA20Gate() {
struct x86Regs_t regs= { 0x2401, 0, 0, 0, 0, 0, 0, 0 };
uint32t flags, tmp;
uint16t *test1= (uint16t *)0x500, *test2= (uint16t *)0x100500;
*test1= 0;
*test2= 1;
if(*test1 != *test2)
return 1;
flags= callBIOS(0x15,®s);
if(flags & FLAG_CF) {
tmp= inb(0x92);
tmp|= 2;
outb(0x92,tmp);
}
*test2= 1;
if(*test1 != *test2)
return 1;
waitKbd();
outb(0x64,0xad);
waitKbd();
outb(0x64,0xd0);
waitKbdData();
tmp= inb(0x60);
waitKbd();
outb(0x64,0xd1);
waitKbd();
outb(0x60,tmp | 2);
waitKbd();
outb(0x64,0xae);
waitKbd();
*test2= 1;
if(*test1 != *test2)
return 1;
return 0;
}