Skip to content

Commit

Permalink
Added implementation of PCI config writes.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie authored and The XOmB Overlord committed Feb 27, 2010
1 parent a8159b9 commit 80f7b29
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
26 changes: 26 additions & 0 deletions kernel/arch/x86_64/architecture/cpu.d
Expand Up @@ -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");

Expand Down
32 changes: 30 additions & 2 deletions kernel/arch/x86_64/architecture/pci.d
Expand Up @@ -13,6 +13,7 @@ class PCIImplementation {
static:

// Description: Will read a uint from PCI.
synchronized
uint read32(uint address) {
_setAddress(address);

Expand All @@ -24,6 +25,7 @@ static:
}

// Description: Will read a ushort from PCI.
synchronized
ushort read16(uint address) {
_setAddress(address);

Expand All @@ -35,6 +37,7 @@ static:
}

// Description: Will read a ubyte from PCI.
synchronized
ubyte read8(uint address) {
_setAddress(address);

Expand All @@ -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);
Expand Down

0 comments on commit 80f7b29

Please sign in to comment.