I have tried to find the SATA controller using the BIOS.
Code: Select all
get_ahci_bus_dev_fun:
mov word [interface], 0
.get_ahci_address:
mov si, 0 ; get pci address of first ahci ctrller
mov ax, 0xB103
mov ecx, 0x00010600
mov cl, byte [interface]
int 0x1A
.check_ahci:
cmp ah, 0x86 ; if ah returned 0x86, we failed
jne .copy_bus ; set_protected_mode
.go_to_next_interface:
inc word [interface]
cmp word [interface], 256
jne .get_ahci_address
jmp .save_null
.copy_bus:
movzx eax, bh ; bus is in bh
.copy_dev:
movzx ecx, bl ; dev is in 5 higher bits of bl
shr ecx, 3
.copy_fun:
movzx edx, bl ; fun is in 3 lower bits of bl
and edx, 7
.save_vars:
mov si, 0x1280 ; variables are saved
mov ds, si
mov si, 0
mov dword [ds:si], eax
mov dword [ds:si + 4], ecx
mov dword [ds:si + 8], edx
jmp set_protected_mode
.save_null:
mov si, 0x1280
mov ds, si
mov si, 0
mov dword [ds:si], 0xFFFFFFFF
mov dword [ds:si + 4], 0xFFFFFFFF
mov dword [ds:si + 8], 0xFFFFFFFF
set_protected_mode:
Code: Select all
ahci_find_ctrller:
.setup:
mov dword [pci_bus], 0
mov dword [pci_dev], 0
mov dword [pci_fun], 0
mov dword [pci_offset], 8
.probe_next_fun:
call pci_set_config_address
call pci_read_dword
mov eax, dword [pci_data] ; dword [pci_data] contains the pci register value
shr eax, 16
cmp ax, 0x0106
je .return
inc dword [pci_fun]
cmp dword [pci_fun], 8
jb .probe_next_fun
.probe_next_dev:
mov dword [pci_fun], 0
inc dword [pci_dev]
cmp dword [pci_dev], 32
jb .probe_next_fun
.probe_next_bus:
mov dword [pci_dev], 0
inc dword [pci_bus]
cmp dword [pci_bus], 256
jb .probe_next_fun
.return_invalid:
mov dword [ahci_bus], 0xFFFFFFFF
mov dword [ahci_dev], 0xFFFFFFFF
mov dword [ahci_fun], 0xFFFFFFFF
ret
.return:
mov eax, dword [pci_bus]
mov dword [ahci_bus], eax
mov eax, dword [pci_dev]
mov dword [ahci_dev], eax
mov eax, dword [pci_fun]
mov dword [ahci_fun], eax
ret
From that I have read, SATA's class code equals 0x01, subclass equals 0x06, and interface equals 0x01 for AHCI. BareMetal OS doesn't even mention the interface, but again, the controller should be found. I don't exclude the error is assembly code specific, though.
Regards,
glauxosdev
Edit: Before you ask, the PCI calls that I didn't post work, as they are usable for reading/writing the EHCI configuration space.