I have successfully accessed the RSDT and retrieved it's address. Now I am trying to pass that to the MADT in order to find the address of the IOAPIC. I had taken the function from the MADT article on the Wiki and modified it a bit so that it only retrieved the IOAPIC.
madt.c
Code:
#include "madt.h"
uint64_t detect_ioapic(RSDT *rsdt) {
uint8_t *ptr, *ptr2;
uint32_t len;
uint64_t ioapic_ptr = 0;
for(len = *((uint32_t*)(rsdt + 4)), ptr2 = rsdt + 36; ptr2 < rsdt + rsdt->h.Length; ptr2 += rsdt->h.Signature[0]=='X' ? 8 : 4) {
ptr = (uint8_t*)(uintptr_t)(rsdt->h.Signature[0]=='X' ? *((uint64_t*)ptr2) : *((uint32_t*)ptr2));
if(!memcmp(ptr, "APIC", 4)) {
ptr2 = ptr + *((uint32_t*)(ptr + 4));
for(ptr += 44; ptr < ptr2; ptr += ptr[1]) {
if (ptr[0] == 1) {
ioapic_ptr = (uint64_t)*((uint32_t*)(ptr+4));
return ioapic_ptr;
}
}
break;
}
}
}
However, any of the code within the first if statement triggers a triple fault (even only having the 'break;'). I am a little confused as to why this is happening. I know it may be a stupid mistake or error I am missing but help would be much appreciated.