diff --git a/include/drivers/amd_am79c973.h b/include/drivers/amd_am79c973.h index a886d50..4b554db 100644 --- a/include/drivers/amd_am79c973.h +++ b/include/drivers/amd_am79c973.h @@ -71,7 +71,8 @@ namespace myos int Reset(); common::uint32_t HandleInterrupt(common::uint32_t esp); - + void Send(common::uint8_t* buffer, int count); + void Receive(); }; diff --git a/include/drivers/driver.h b/include/drivers/driver.h index 33b5dbb..ab96dbd 100644 --- a/include/drivers/driver.h +++ b/include/drivers/driver.h @@ -20,7 +20,7 @@ namespace myos class DriverManager { - private: + public: Driver* drivers[265]; int numDrivers; diff --git a/src/drivers/amd_am79c973.cpp b/src/drivers/amd_am79c973.cpp index 6ad5816..3d1f4e1 100644 --- a/src/drivers/amd_am79c973.cpp +++ b/src/drivers/amd_am79c973.cpp @@ -108,6 +108,7 @@ int amd_am79c973::Reset() void printf(char*); +void printfHex(uint8_t); uint32_t amd_am79c973::HandleInterrupt(common::uint32_t esp) { @@ -120,15 +121,66 @@ uint32_t amd_am79c973::HandleInterrupt(common::uint32_t esp) if((temp & 0x2000) == 0x2000) printf("AMD am79c973 COLLISION ERROR\n"); if((temp & 0x1000) == 0x1000) printf("AMD am79c973 MISSED FRAME\n"); if((temp & 0x0800) == 0x0800) printf("AMD am79c973 MEMORY ERROR\n"); - if((temp & 0x0400) == 0x0400) printf("AMD am79c973 DATA RECEVED\n"); + if((temp & 0x0400) == 0x0400) Receive(); if((temp & 0x0200) == 0x0200) printf("AMD am79c973 DATA SENT\n"); // acknoledge registerAddressPort.Write(0); registerDataPort.Write(temp); - if((temp & 0x0200) == 0x0200) printf("AMD am79c973 INIT DONE\n"); + if((temp & 0x0100) == 0x0100) printf("AMD am79c973 INIT DONE\n"); return esp; } - \ No newline at end of file + + +void amd_am79c973::Send(uint8_t* buffer, int size) +{ + int sendDescriptor = currentSendBuffer; + currentSendBuffer = (currentSendBuffer + 1) % 8; + + if(size > 1518) + size = 1518; + + for(uint8_t *src = buffer + size -1, + *dst = (uint8_t*)(sendBufferDescr[sendDescriptor].address + size -1); + src >= buffer; src--, dst--) + *dst = *src; + + sendBufferDescr[sendDescriptor].avail = 0; + sendBufferDescr[sendDescriptor].flags2 = 0; + sendBufferDescr[sendDescriptor].flags = 0x8300F000 + | ((uint16_t)((-size) & 0xFFF)); + registerAddressPort.Write(0); + registerDataPort.Write(0x48); +} + +void amd_am79c973::Receive() +{ + printf("AMD am79c973 DATA RECEIVED\n"); + + for(; (recvBufferDescr[currentRecvBuffer].flags & 0x80000000) == 0; + currentRecvBuffer = (currentRecvBuffer + 1) % 8) + { + if(!(recvBufferDescr[currentRecvBuffer].flags & 0x40000000) + && (recvBufferDescr[currentRecvBuffer].flags & 0x03000000) == 0x03000000) + + { + uint32_t size = recvBufferDescr[currentRecvBuffer].flags & 0xFFF; + if(size > 64) // remove checksum + size -= 4; + + uint8_t* buffer = (uint8_t*)(recvBufferDescr[currentRecvBuffer].address); + + for(int i = 0; i < size; i++) + { + printfHex(buffer[i]); + printf(" "); + } + } + + recvBufferDescr[currentRecvBuffer].flags2 = 0; + recvBufferDescr[currentRecvBuffer].flags = 0x8000F7FF; + } +} + diff --git a/src/kernel.cpp b/src/kernel.cpp index f264ef0..e783ed9 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -12,6 +12,8 @@ #include #include +#include + // #define GRAPHICSMODE @@ -188,7 +190,7 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot printfHex(((size_t)allocated >> 8 ) & 0xFF); printfHex(((size_t)allocated ) & 0xFF); printf("\n"); - + TaskManager taskManager; /* Task task1(&gdt, taskA); @@ -242,6 +244,11 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot desktop.AddChild(&win2); #endif + + + amd_am79c973* eth0 = (amd_am79c973*)(drvManager.drivers[2]); + eth0->Send((uint8_t*)"Hello Network", 13); + interrupts.Activate();