From f4294119b4398a855d3d91870dc02854844d18a8 Mon Sep 17 00:00:00 2001 From: kotorifan Date: Fri, 3 Apr 2026 10:42:26 +0200 Subject: Added code to pci.asm --- src/kernel/pci.asm | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/kernel/pci.asm (limited to 'src/kernel/pci.asm') diff --git a/src/kernel/pci.asm b/src/kernel/pci.asm new file mode 100644 index 0000000..63ff3df --- /dev/null +++ b/src/kernel/pci.asm @@ -0,0 +1,89 @@ +;; pci.asm +;; PCI Bus + +%define PCI_ENABLE 0x80000000 +%define PCI_CONFIG_ADDR_1 0xcf8 +%define PCI_CONFIG_ADDR_2 0xcfc +%define PCI_SLOT_EMPTY 0xffff +%define PCI_SLOT_COUNT 32 + +pci_config_read_word: + enter + movzx ebx, word [ebp + 8] ; bus + movzx edx, word [ebp + 12] ; slot + movzx ecx, word [ebp + 16] ; func + movzx eax, word [ebp + 20] ; offset + + shl ebx, 16 + shl edx, 11 + shl ecx, 8 + and eax, 0xfc + + or eax, ecx + or eax, edx + or eax, ebx + or eax, 0x80000000 + + mov dx, PCI_CONFIG_ADDR_1 ; write address + out dx, eax + + mov dx, PCI_CONFIG_ADDR_2 ; read data + in dx, eax + + movzx ecx, word [ebp + 20] ; offset + and ecx, 2 + imul ecx, ecx, 8 + shr eax, cl + and ax, 0xffff + + leave + ret + +pci_config_get_vendor: + enter + movzx ebx, word [ebp + 8] ; bus + movzx edx, word [ebp + 12] ; device + movzx ecx, word [ebp + 16] ; func + + push 0 + push ecx + push edx + push ebx + call pci_config_read_word + + leave + ret + +pci_config_get_device: + enter + movzx ebx, word [ebp + 8] ; bus + movzx edx, word [ebp + 12] ; device + movzx ecx, word [ebp + 16] ; func + + push 2 + push ecx + push edx + push ebx + + call pci_config_read_word + leave + ret + +pci_config_get_class: + enter + movzx ebx, word [ebp + 8] ; bus + movzx edx, word [ebp + 12] ; device + movzx ecx, word [ebp + 16] ; func + + push 0xa + push ecx + push edx + push ebx + call pci_config_read_word + + xor esi, esi + not esi, 0xff00 + and eax, esi + + leave + ret -- cgit v1.3