Permalink
Browse files

Added implementation of PCI config writes.

  • Loading branch information...
1 parent a8159b9 commit 80f7b2964aebd9f296c7c0e9baa9462fdb79ec04 @wilkie wilkie committed with The XOmB Overlord Feb 21, 2010
Showing with 56 additions and 2 deletions.
  1. +26 −0 kernel/arch/x86_64/architecture/cpu.d
  2. +30 −2 kernel/arch/x86_64/architecture/pci.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");
@@ -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);

0 comments on commit 80f7b29

Please sign in to comment.