AHCI driver error on qemu

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
MikyBart
Posts: 16
Joined: Tue Sep 03, 2024 9:21 am
Libera.chat IRC: MikyBart

AHCI driver error on qemu

Post by MikyBart »

Hi all, I wrote an ahci driver for my kernel in assembly (nasm).
when I run qemu, the kernel in the initialization of the ahci driver does not hang but in exit qemu gives me the following error:

Code: Select all

qemu: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
so that the buffer must be in physical memory and not virtual.

What can I do to overcome this problem?

thanks to all.
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: AHCI driver error on qemu

Post by Octocontrabass »

Put a valid physical address in the PxFB and PxFBU registers.
MikyBart
Posts: 16
Joined: Tue Sep 03, 2024 9:21 am
Libera.chat IRC: MikyBart

Re: AHCI driver error on qemu

Post by MikyBart »

Thanks for the reply, how can I get a physical address with limine?
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: AHCI driver error on qemu

Post by MichaelPetch »

I assume you allocated the space for the buffers in virtual memory somewhere?
miky
Posts: 9
Joined: Wed Feb 11, 2009 3:39 am

Re: AHCI driver error on qemu

Post by miky »

Yes, I use Limine as a bootloader.
So I have to assign a physical address to a buffer, but I don't know where to assign it, in which area of ​​memory.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: AHCI driver error on qemu

Post by MichaelPetch »

Q1: Might be easier to ask it this way - have you implemented a physical memory manager yet?
Q2: As I recall you are writing this all in NASM? Is that still the case?
Q3: Have you at this stage setup any Limine requests? Do you know how to? There is probably quick and dirty way where you have to do a Limine request

I ask this because there is a way you could probably do it by putting the buffer in the .bss section and using the LIMINE_KERNEL_ADDRESS_REQUEST (see: https://github.com/limine-bootloader/li ... ss-feature ) . If you make that request and compute the difference between virtual_base and physical_base (ie kernel_offset = virtual_base-physical_base) you can subtract kernel_offset from any address in the kernel address space (which would include the .bss section) to get the corresponding physical address. That physical address can then be used as the physical address for AHCI (ie: the physical addresses for PxFB and PxFBU registers).

I recently helped someone on Stackoverflow regarding computing a physical address from a virtual kernel address in Limine. The "C" code was here: https://github.com/baponkar/KeblaOS/blo ... nel.c#L105 . kernel_offset is computed and stored as a global variable that can then be subtracted from any kernel virtual address to yield a physical address.
MikyBart
Posts: 16
Joined: Tue Sep 03, 2024 9:21 am
Libera.chat IRC: MikyBart

Re: AHCI driver error on qemu

Post by MikyBart »

Thanks for your reply.

A1: No
A2: Yes
A3: My kernel currently sets up a GDT, IDT and interrupt handling including system calls (int 128).
I know the limine protocol but the manual is very limited on memory management.

I don't have a memory manager yet, neither physical nor virtual, these are things I'm currently studying.
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: AHCI driver error on qemu

Post by MichaelPetch »

This assumes you are using Limine Boot Protocol.

Although you have no VMM, you do have virtual memory mappings provided by Limine. Without a physical memory manager at this point the easiest way is I suggested already. You will have to make a Limine request (LIMINE_KERNEL_ADDRESS_REQUEST) to retrieve the address of the kernel in virtual memory and the physical address (both part of the response). As I pointed out if you compute the difference (call it kernel_phys_virt_offset) between them (virtual_base-physical_base from the Limine response) you can then take any kernel virtual address and subtract that computed offset to obtain the physical address.

If you place the buffers in .bss, that becomes part of the kernel virtual address space. You would just take the virtual address of the buffers in the .bss section and subtract kernel_phys_virt_offset from them. Those will be the physical addresses in memory of the buffers. Those physical addresses can then be used for AHCI for the PxFB and PxFBU registers. This works because Limine has a guarantee that wherever it places the kernel in physical memory it is contiguous physical memory. It then maps that contiguous physical memory into the higher half.

If you had a physical memory manager you would request free physical page(s) and use addresses in those page(s) to use for the AHCI buffers.
Post Reply