diff --git a/kernel/arch/x86_64/architecture/cpu.d b/kernel/arch/x86_64/architecture/cpu.d index 9d90a47..fdf56a2 100644 --- a/kernel/arch/x86_64/architecture/cpu.d +++ b/kernel/arch/x86_64/architecture/cpu.d @@ -109,6 +109,32 @@ public: }`; } + void ioOut(T)(int port, int data) { + asm { + mov EAX, data; + mov EDX, port; + } + + static if (is(T == ubyte) || is(T == byte)) { + asm { + out DX, AL; + } + } + else static if (is(T == ushort) || is(T == short)) { + asm { + out DX, AX; + } + } + else static if (is(T == uint) || is(T == int)) { + asm { + out DX, EAX; + } + } + else { + static assert (false, "Cannot determine data type."); + } + } + void ioOut(T, char[] port)(int data) { //static assert (port[$-1] == 'h', "Cannot reduce port number"); diff --git a/kernel/arch/x86_64/architecture/pci.d b/kernel/arch/x86_64/architecture/pci.d index c604092..7941535 100644 --- a/kernel/arch/x86_64/architecture/pci.d +++ b/kernel/arch/x86_64/architecture/pci.d @@ -13,6 +13,7 @@ class PCIImplementation { static: // Description: Will read a uint from PCI. + synchronized uint read32(uint address) { _setAddress(address); @@ -24,6 +25,7 @@ static: } // Description: Will read a ushort from PCI. + synchronized ushort read16(uint address) { _setAddress(address); @@ -35,6 +37,7 @@ static: } // Description: Will read a ubyte from PCI. + synchronized ubyte read8(uint address) { _setAddress(address); @@ -46,18 +49,43 @@ static: } // Description: Will write to PCI. - void write8(uint address, ubyte value) { + synchronized + void write32(uint address, uint value) { + _setAddress(address); + + // get offset + ushort offset = cast(ushort)(address & 0xff); + + // write in data + Cpu.ioOut!(uint)(0xcfc + offset, value); } // Description: Will write to PCI. + synchronized void write16(uint address, ushort value) { + _setAddress(address); + + // get offset + ushort offset = cast(ushort)(address & 0xff); + + // write in data + Cpu.ioOut!(ushort)(0xcfc + offset, value); } // Description: Will write to PCI. - void write32(uint address, uint value) { + synchronized + void write8(uint address, ubyte value) { + _setAddress(address); + + // get offset + ushort offset = cast(ushort)(address & 0xff); + + // write in data + Cpu.ioOut!(ubyte)(0xcfc + offset, value); } private: + void _setAddress(uint address) { // write out address Cpu.ioOut!(uint, "0xcf8")(address);