diff --git a/TODO.md b/TODO.md index d230739..e4fa403 100644 --- a/TODO.md +++ b/TODO.md @@ -4,7 +4,8 @@ PS/2 controller --> need to setup some timing device, probably PIT +-> need to setup some timing device, probably PIT DONE! +-> might need to do a PCI controller first, so that i can discover the controllers, to be enabled -> need to setup the USB controller first, so i can disable Legacy USB bios shit -> need to configure ACPI so i can actually detect for the PS/2 controller -> then we can start configuring the PS/2 diff --git a/kernel/arch/io/io.s b/kernel/arch/io/io.s index 567288e..7e2ae7b 100644 --- a/kernel/arch/io/io.s +++ b/kernel/arch/io/io.s @@ -9,8 +9,25 @@ outb: out dx, al ; send the data to the I/O port ret ; return to the calling function + +global outb_16 +outb_16: + mov ax, [esp + 8] + mov dx, [esp + 4] + out dx, ax + ret + + + +global outb_32 +outb_32: + mov eax, [esp + 8] + mov dx, [esp + 4] + out dx, eax + ret + global inb -; inb - returns a byte from the given I/O port +; inb - returns a byte from the given I/O porot ; stack: [esp + 4] The address of the I/O port ; [esp ] The return address inb: @@ -18,9 +35,24 @@ inb: in al, dx ; read a byte from the I/O port and store it in the al register ret ; return the read byte +global inb_16 +inb_16: + mov dx, [esp + 4] + in ax, dx + ret + +global inb_32 +inb_32: + mov dx, [esp + 4] + in eax, dx + ret + global io_wait io_wait: mov al, 0x0 out 0x80, al ret + + + diff --git a/kernel/arch/pic/pci.c b/kernel/arch/pic/pci.c new file mode 100644 index 0000000..7c2d0a3 --- /dev/null +++ b/kernel/arch/pic/pci.c @@ -0,0 +1,34 @@ +#include +#include + +#include + +uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset) +{ + uint32_t address; + uint32_t lbus = (uint32_t) bus; + uint32_t lslot = (uint32_t) slot; + uint32_t lfunc = (uint32_t) func; + uint16_t tmp = 0; + + + address = (uint32_t) ((lbus << 16) | (lslot << 11) | + (lfunc << 8) | (offset & 0xFC) | ((uint32_t) 0x80000000)); + + outb_32(PCI_CONFIG_ADDRESS, address); + + tmp = (uint16_t)((inb(PCI_CONFIG_DATA) >> ((offset & 2) * 8)) * 0xFFFF); + return tmp; +} + +uint16_t pci_check_vendor(uint8_t bus, uint8_t slot) +{ + uint16_t vendor, device; + + if ((vendor = pci_config_read_word(bus, slot, 0, 0)) != 0xFFFF) { + device = pci_config_read_word(bus, slot, 0, 2); + printf("Device: %d, Vendor: %d\n", device, vendor); + } + return vendor; +} + diff --git a/kernel/include/kernel/x86/io.h b/kernel/include/kernel/x86/io.h index 9579303..a8f7fd2 100644 --- a/kernel/include/kernel/x86/io.h +++ b/kernel/include/kernel/x86/io.h @@ -1,3 +1,5 @@ +#include + #ifndef ARCH_IO_H #define ARCH_IO_H @@ -8,7 +10,9 @@ * @param port The I/O port to send the data to * @param data The data to send to the I/O port */ -void outb(unsigned short port, unsigned char data); +void outb(unsigned short port, uint8_t data); +void outb_16(unsigned short port, uint16_t data); +void outb_32(unsigned short port, uint32_t data); /** * inb: @@ -17,7 +21,9 @@ void outb(unsigned short port, unsigned char data); * @param port The address of the I/O port * @return The read byte */ -unsigned char inb(unsigned short port); +uint8_t inb(unsigned short port); +uint16_t inb_16(unsigned short port); +uint32_t inb_32(unsigned short port); /** * io_wait: diff --git a/kernel/include/kernel/x86/pci.h b/kernel/include/kernel/x86/pci.h new file mode 100644 index 0000000..9f41c03 --- /dev/null +++ b/kernel/include/kernel/x86/pci.h @@ -0,0 +1,13 @@ +#include + +#ifndef ARCH_PCI_H +#define ARCH_PCI_H + +#define PCI_CONFIG_ADDRESS (0xCF8) +#define PCI_CONFIG_DATA (0xCFC) + +uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset); + +uint16_t pci_check_vendor(uint8_t bus, uint8_t slot); + +#endif