-O0:

-03:

If needed, I can also post my source code.
Code: Select all
------------------------------------------
FASTCALL void init_apic(u_addr io_apic_addr){
/* Initialize the page table for APICs */
u32* apic_ptes=ALLOC_PAGE();
memset(apic_ptes, 0, PAGE_SIZE);
/* Map I/O APIC */
assert(io_apic_addr>0xFC000000,":-( I/O APIC Address Out of Range.");
apic_ptes[va2pte(IO_APIC_ADDR)]=io_apic_addr+0b11011;
/* Map Local APIC */
u64 msr=asm_rdmsr(IA32_APIC_BASE); /* Read IA32_APIC_BASE MSR */
asm_wrmsr(IA32_APIC_BASE, BIT_SET(BIT_SET(APIC_REG_ADDR,8),11));
/* Enable APIC if not */
apic_ptes[va2pte(APIC_REG_ADDR)]=APIC_REG_ADDR+0b11011;
/* Map the page table */
kernel_pde[va2pde(APIC_REG_ADDR)]=va2pa(apic_ptes)+0b11011;
asm_setCR3(va2pa(kernel_pde));
u8 apic_id=apic_read(APIC_ID_REG)>>24;
u32 id;
for(id=0;id<16;id++){
io_apic_write(IO_APIC_RED(id)+1,apic_id<<(56-32));
io_apic_write(IO_APIC_RED(id),0x10000+0x20+id);
}
for(;id<24;id++){
io_apic_write(IO_APIC_RED(id)+1,apic_id<<(56-32));
io_apic_write(IO_APIC_RED(id),0x10000);
}
for(id=0;id<16;id++){
if(IRQOverride[id]!=id)
io_apic_write(IO_APIC_RED(IRQOverride[id]),0x10000+0x20+id);
}
/* Display Info */
puts("Local APIC ID:");
dispByte(apic_id);
puts("\r\n");
puts("I / O APIC ID:");
dispByte(io_apic_read(0)>>24);
puts("\r\n");
}
----------------------------------------
Code: Select all
u32* apic_ptes=ALLOC_PAGE();
memset(apic_ptes, 0, PAGE_SIZE);
Nope, nope, nope.I read somewhere that O3 does optimizations that aren't always suitable for a kernel. However, O0, O1 and O2 should always give the same result
Now you just chopped out part of what I said out of context, making it appear wrong. O0, O1 and O2 should always give the same result, provided the input code is correct, including statements such as volatile. That's why I write, "If these give different results you have a bug somewhere in your code".Combuster wrote:Nope, nope, nope.I read somewhere that O3 does optimizations that aren't always suitable for a kernel. However, O0, O1 and O2 should always give the same result
Thank you, I will change my macros to inline functions.Owen wrote:Your code was wrong. The constant "11" is of type int. the "A" specifier has very well defined behavior: it allocates EAX:EDX as appropriate for the passed data type. Being as int is 32-bit, it only allocated EAX.
Perhaps declare the type involved correctly. Say, use an inline function rather than a mess of macros...