OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 9:52 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Issues with loading ACPI tables with LAI
PostPosted: Thu May 05, 2022 3:41 pm 
Offline
Member
Member

Joined: Tue Aug 31, 2021 7:25 am
Posts: 67
I have integrated the LAI core AML interpreter (https://github.com/managarm/lai) into my OS but I am having a few problems.
I have tried to create a namespace with:
Code:
lai_set_acpi_revision(rsdp->Revision);
lai_create_namespace();

These are the logs that have occurred when trying to create a namespace:
Quote:
[ACPI] Discovered table with signature FACP
[ACPI] Discovered table with signature APIC
[ACPI] Discovered table with signature HPET
[ACPI LAI] loaded AML table 'DSDT', total 1634628864 bytes of AML code.
[ACPI LAI WARN] undefined reference PSDT in object mode, aborting
[ACPI LAI WARN] lai_exec_run() failed in lai_populate()
[ACPI LAI] loaded AML table 'SSDT', total 1146310656 bytes of AML code.
[ACPI LAI PANIC] assertion failed: parse_mode == LAI_OBJECT_MODE at src/c/lai/exec.c:3083

I don't know too much about LAI so I don't know how to interpret them, hoping someone with more experience can help here.
But the fact the "total bytes for the DSDT table" is about 1.6GB points to a serious problem.

Details:
qemu i386 emulator
32-bit kernel booted with GRUB
Using cross-compiler with libgcc
C++ kernel with C compiled with i686 gcc and C++ compiled with i686 g++
No paging enabled or handled

laihost_scan implementation (all structs such as RSDT are from the forum page):
Code:
void* locate_rsdp() {
    // Start address of EBDA.
    uint8_t* ebda = (uint8_t*)0x9FC00;
   
    // Look for RSDP in the bios extended area.
    for (uint32_t i = 0; i < 64; i++) {
        uint8_t* segment = (ebda + (i * 16));
       
        // Verify signature.
        if (verify_signature(segment, 8, "RSD PTR ") == true) {
           
            // RSDP found, return address.
            return segment;
        }
    }
   
    // Address of possible RSDP area.
    uint8_t* mba = (uint8_t*)0x000E0000;
   
    for (uint32_t i = 0; i < 8192; i++) {
        uint8_t* segment = mba + (i * 16);
       
        // Verify signature.
        if (verify_signature(segment, 8, "RSD PTR ") == true) {
           
            // RSDP found, return address.
            return segment;
        }
    }

    return NULL;
}

void* laihost_scan(const char* signature, size_t index) {
    struct RSDT* rsdp = locate_rsdp();

    uint32_t entries = (rsdp->h.Length - sizeof(rsdp->h)) / 4;
    uint32_t current_index = 0;

    for (uint32_t i = 0; i < entries; i++) {
        // Get table of header.
        struct SDTHeader* header = rsdp->table_pointers[i];

        // Check if signature matches requested table.
        if (verify_signature(header, 4, (char*)signature) == true) {
            if (index == current_index) return header;
            else current_index++;
        }
    }

    return NULL;
}


I should also mention the code which finds the tables works fine as I have tried running them on their own and they locate the relevant tables without a problem.

Thanks!


Top
 Profile  
 
 Post subject: Re: Issues with loading ACPI tables with LAI
PostPosted: Thu May 05, 2022 10:42 pm 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
Quote:
Code:
[ACPI LAI] loaded AML table 'DSDT', total 1634628864 bytes of AML code.

I don't much about LAI, but that seems like way too much AML code to be right.

Is it possible the ACPI tables aren't all mapped in correctly or that LAI isn't aware of the proper physical-to-virtual mapping?


Top
 Profile  
 
 Post subject: Re: Issues with loading ACPI tables with LAI
PostPosted: Fri May 06, 2022 2:13 am 
Offline
Member
Member

Joined: Tue Aug 31, 2021 7:25 am
Posts: 67
davmac314 wrote:
Quote:
Code:
[ACPI LAI] loaded AML table 'DSDT', total 1634628864 bytes of AML code.

I don't much about LAI, but that seems like way too much AML code to be right.

Is it possible the ACPI tables aren't all mapped in correctly or that LAI isn't aware of the proper physical-to-virtual mapping?

Are you talking about paging? If so I don't have it enabled.

I also tried another emulator like virtualbox and the same occurred, it appears to be reading more memory than it should - long shot of a theory but maybe my kernel is positioned too low or too high? Or something else in my code such as the heap is positioned where the ACPI tables are?


Top
 Profile  
 
 Post subject: Re: Issues with loading ACPI tables with LAI
PostPosted: Fri May 06, 2022 2:52 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
YDeeps1 wrote:
Are you talking about paging? If so I don't have it enabled.

I was; ok, that's ruled out.

Quote:
But the fact the "total bytes for the DSDT table" is about 1.6GB points to a serious problem

I somehow missed that when I read it the first time. Yeah, it's not right.

Quote:
I also tried another emulator like virtualbox and the same occurred, it appears to be reading more memory than it should - long shot of a theory but maybe my kernel is positioned too low or too high? Or something else in my code such as the heap is positioned where the ACPI tables are?

There's only really two possible causes that I can think of: the table pointer you're returning is incorrect (your code looks fine, is perhaps the table structure definition not right?) or the data has been corrupted somehow (overwritten).


Top
 Profile  
 
 Post subject: Re: Issues with loading ACPI tables with LAI
PostPosted: Fri May 06, 2022 2:55 am 
Offline
Member
Member

Joined: Tue Aug 31, 2021 7:25 am
Posts: 67
I did check and everything should be positioned correctly so I don't know what the issue may be.
I have included a brief AML dump in case anyone would want to see it:
Image


Top
 Profile  
 
 Post subject: Re: Issues with loading ACPI tables with LAI
PostPosted: Fri May 06, 2022 3:06 am 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
What does the DSDT header look like? Is the signature correct? What does the length field contain?


Top
 Profile  
 
 Post subject: Re: Issues with loading ACPI tables with LAI
PostPosted: Fri May 06, 2022 3:29 am 
Offline
Member
Member

Joined: Tue Aug 31, 2021 7:25 am
Posts: 67
davmac314 wrote:
What does the DSDT header look like? Is the signature correct? What does the length field contain?

Sure.
Image
The header seems completely correct. The issue may perhaps be pointing to my malloc/free implementation? But I have tested it many times so I don't think it's that.


Top
 Profile  
 
 Post subject: Re: Issues with loading ACPI tables with LAI
PostPosted: Fri May 06, 2022 10:39 am 
Offline
Member
Member

Joined: Tue Aug 31, 2021 7:25 am
Posts: 67
I found the problem and it's a proper facepalm moment.
I was digging around the LAI source code trying to figure out the possible issue and then looked at some old code I wrote to retrieve the tables and went "hold on since when does the RSDP have a pointer to the RSDT?".
I took a long break from osdev and completely forget the structure you search for initially is the RSDP which points to the RSDT and not the RSDT itself.

=D>


Top
 Profile  
 
 Post subject: Re: Issues with loading ACPI tables with LAI
PostPosted: Fri May 06, 2022 3:14 pm 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
Ahh. I should have noticed that. Easy mistake to make, though.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: DotBot [Bot], Google [Bot], Majestic-12 [Bot] and 66 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group