linux buildfix

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6673 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Shawn Hoffman 2010-12-27 22:51:20 +00:00
parent 722b7db8f9
commit 9553aa0100
2 changed files with 61 additions and 47 deletions

View File

@ -18,37 +18,41 @@
#include "../Memmap.h" #include "../Memmap.h"
#include "../EXI_Device.h" #include "../EXI_Device.h"
#include "../EXI_DeviceEthernet.h" #include "../EXI_DeviceEthernet.h"
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <net/if.h> #include <net/if.h>
#ifdef __linux__ #ifdef __linux__
#include <linux/if_tun.h> #include <linux/if_tun.h>
#else #else
#include <net/if_tun.h> #include <net/if_tun.h>
#endif #endif
#include <assert.h> #include <assert.h>
int fd = -1;
int fd = -1;
bool CEXIETHERNET::deactivate() bool CEXIETHERNET::deactivate()
{ {
close(fd); close(fd);
fd = -1; fd = -1;
return true; return true;
} }
bool CEXIETHERNET::isActivated() bool CEXIETHERNET::isActivated()
{ {
return fd != -1 ? true : false; return fd != -1 ? true : false;
} }
bool CEXIETHERNET::activate() { bool CEXIETHERNET::activate()
{
#ifdef __linux__ #ifdef __linux__
if(isActivated()) if(isActivated())
return true; return true;
if( (fd = open("/dev/net/tun", O_RDWR)) < 0) if( (fd = open("/dev/net/tun", O_RDWR)) < 0)
{ {
DEBUGPRINT("Couldn't Open device\n"); INFO_LOG(SP1, "Couldn't Open device\n");
return false; return false;
} }
struct ifreq ifr; struct ifreq ifr;
@ -63,22 +67,22 @@ bool CEXIETHERNET::activate() {
{ {
close(fd); close(fd);
fd = -1; fd = -1;
DEBUGPRINT(" Error with IOCTL: 0x%X\n", err); INFO_LOG(SP1, " Error with IOCTL: 0x%X\n", err);
return false; return false;
} }
ioctl( fd, TUNSETNOCSUM, 1 ); ioctl( fd, TUNSETNOCSUM, 1 );
/*int flags; /*int flags;
if ((flags = fcntl( fd, F_GETFL)) < 0) if ((flags = fcntl( fd, F_GETFL)) < 0)
{ {
DEBUGPRINT("getflags on tun device: %s", strerror (errno)); INFO_LOG(SP1, "getflags on tun device: %s", strerror (errno));
} }
flags |= O_NONBLOCK; flags |= O_NONBLOCK;
if (fcntl( fd, F_SETFL, flags ) < 0) if (fcntl( fd, F_SETFL, flags ) < 0)
{ {
DEBUGPRINT("set tun device flags: %s", strerror (errno)); INFO_LOG(SP1, "set tun device flags: %s", strerror (errno));
}*/ }*/
DEBUGPRINT("Returned Socket name is: %s\n", ifr.ifr_name); INFO_LOG(SP1, "Returned Socket name is: %s\n", ifr.ifr_name);
system("brctl addif pan0 Dolphin"); system("brctl addif pan0 Dolphin");
system("ifconfig Dolphin 0.0.0.0 promisc up"); system("ifconfig Dolphin 0.0.0.0 promisc up");
resume(); resume();
@ -87,6 +91,7 @@ bool CEXIETHERNET::activate() {
return false; return false;
#endif #endif
} }
bool CEXIETHERNET::CheckRecieved() bool CEXIETHERNET::CheckRecieved()
{ {
if(!isActivated()) if(!isActivated())
@ -119,22 +124,25 @@ bool CEXIETHERNET::CheckRecieved()
if ( retval > 0 ) { if ( retval > 0 ) {
if ( FD_ISSET(fd, &mask) ) if ( FD_ISSET(fd, &mask) )
{ {
DEBUGPRINT("\t\t\t\tWe have data!\n"); INFO_LOG(SP1, "\t\t\t\tWe have data!\n");
return true; return true;
} }
} }
return false; return false;
} }
bool CEXIETHERNET::resume() {
bool CEXIETHERNET::resume()
{
if(!isActivated()) if(!isActivated())
return true; return true;
DEBUGPRINT("BBA resume\n"); INFO_LOG(SP1, "BBA resume\n");
if(mBbaMem[BBA_NCRA] & BBA_NCRA_SR) { if(mBbaMem[BBA_NCRA] & NCRA_SR) {
startRecv(); startRecv();
} }
DEBUGPRINT("BBA resume complete\n"); INFO_LOG(SP1, "BBA resume complete\n");
return true; return true;
} }
THREAD_RETURN CpuThread(void *pArg) THREAD_RETURN CpuThread(void *pArg)
{ {
CEXIETHERNET* self = (CEXIETHERNET*)pArg; CEXIETHERNET* self = (CEXIETHERNET*)pArg;
@ -144,7 +152,7 @@ THREAD_RETURN CpuThread(void *pArg)
{ {
u8 B[1514]; u8 B[1514];
self->mRecvBufferLength = read(fd, B, 1500); self->mRecvBufferLength = read(fd, B, 1500);
//DEBUGPRINT("read return of 0x%x\n", self->mRecvBufferLength); //INFO_LOG(SP1, "read return of 0x%x\n", self->mRecvBufferLength);
if (self->mRecvBufferLength == 0xffffffff) if (self->mRecvBufferLength == 0xffffffff)
{ {
//Fail Boat //Fail Boat
@ -162,10 +170,10 @@ THREAD_RETURN CpuThread(void *pArg)
} }
else else
{ {
DEBUGPRINT("Unknown read return of 0x%x\n", self->mRecvBufferLength); INFO_LOG(SP1, "Unknown read return of 0x%x\n", self->mRecvBufferLength);
exit(0); exit(0);
} }
DEBUGPRINT("Received %d bytes of data\n", self->mRecvBufferLength); INFO_LOG(SP1, "Received %d bytes of data\n", self->mRecvBufferLength);
self->mWaiting = false; self->mWaiting = false;
self->handleRecvdPacket(); self->handleRecvdPacket();
return 0; return 0;
@ -174,12 +182,14 @@ THREAD_RETURN CpuThread(void *pArg)
} }
return 0; return 0;
} }
bool CEXIETHERNET::startRecv() {
DEBUGPRINT("Start Receive!\n"); bool CEXIETHERNET::startRecv()
{
INFO_LOG(SP1, "Start Receive!\n");
//exit(0); //exit(0);
DEBUGPRINT("startRecv... "); INFO_LOG(SP1, "startRecv... ");
if(mWaiting) { if(mWaiting) {
DEBUGPRINT("already waiting\n"); INFO_LOG(SP1, "already waiting\n");
return true; return true;
} }
Common::Thread *cpuThread = new Common::Thread(CpuThread, (void*)this); Common::Thread *cpuThread = new Common::Thread(CpuThread, (void*)this);
@ -188,28 +198,29 @@ bool CEXIETHERNET::startRecv() {
return true; return true;
} }
bool CEXIETHERNET::sendPacket(u8 *etherpckt, int size) bool CEXIETHERNET::sendPacket(u8 *etherpckt, int size)
{ {
if(!isActivated()) if(!isActivated())
return false; return false;
DEBUGPRINT( "Packet: 0x"); INFO_LOG(SP1, "Packet: 0x");
for(int a = 0; a < size; ++a) for(int a = 0; a < size; ++a)
{ {
DEBUGPRINT( "%02X ", etherpckt[a]); INFO_LOG(SP1, "%02X ", etherpckt[a]);
} }
DEBUGPRINT( " : Size: %d\n", size); INFO_LOG(SP1, " : Size: %d\n", size);
int numBytesWrit = write(fd, etherpckt, size); int numBytesWrit = write(fd, etherpckt, size);
if(numBytesWrit != size) if(numBytesWrit != size)
{ {
DEBUGPRINT("BBA sendPacket %i only got %i bytes sent!errno: %d\n", size, numBytesWrit, errno); INFO_LOG(SP1, "BBA sendPacket %i only got %i bytes sent!errno: %d\n", size, numBytesWrit, errno);
return false; return false;
} }
recordSendComplete(); recordSendComplete();
return true; return true;
} }
bool CEXIETHERNET::handleRecvdPacket() bool CEXIETHERNET::handleRecvdPacket()
{ {
int rbwpp = mCbw.p_write() + CB_OFFSET; //read buffer write page pointer int rbwpp = mCbw.p_write() + CB_OFFSET; //read buffer write page pointer
u32 available_bytes_in_cb; u32 available_bytes_in_cb;
if(rbwpp < mRBRPP) if(rbwpp < mRBRPP)
@ -235,31 +246,34 @@ bool CEXIETHERNET::handleRecvdPacket()
//mPacketsRcvd++; //mPacketsRcvd++;
mRecvBufferLength = 0; mRecvBufferLength = 0;
if(mBbaMem[BBA_IMR] & BBA_INTERRUPT_RECV) if(mBbaMem[BBA_IMR] & INT_R)
{ {
if(!(mBbaMem[BBA_IR] & BBA_INTERRUPT_RECV)) if(!(mBbaMem[BBA_IR] & INT_R))
{ {
mBbaMem[BBA_IR] |= BBA_INTERRUPT_RECV; mBbaMem[BBA_IR] |= INT_R;
DEBUGPRINT("BBA Recv interrupt raised\n"); INFO_LOG(SP1, "BBA Recv interrupt raised\n");
m_bInterruptSet = true; m_bInterruptSet = true;
} }
} }
if(mBbaMem[BBA_NCRA] & BBA_NCRA_SR) if(mBbaMem[BBA_NCRA] & NCRA_SR)
{ {
startRecv(); startRecv();
} }
return true; return true;
} }
union bba_descr { union bba_descr {
struct { u32 next_packet_ptr:12, packet_len:12, status:8; }; struct { u32 next_packet_ptr:12, packet_len:12, status:8; };
u32 word; u32 word;
}; };
bool CEXIETHERNET::cbwriteDescriptor(u32 size) {
bool CEXIETHERNET::cbwriteDescriptor(u32 size)
{
if(size < SIZEOF_ETH_HEADER) if(size < SIZEOF_ETH_HEADER)
{ {
DEBUGPRINT("Packet too small: %i bytes\n", size); INFO_LOG(SP1, "Packet too small: %i bytes\n", size);
return false; return false;
} }
@ -269,12 +283,12 @@ bool CEXIETHERNET::cbwriteDescriptor(u32 size) {
//since neither tmbinc, riptool.dol, or libogc does... //since neither tmbinc, riptool.dol, or libogc does...
if(mCbw.p_write() + SIZEOF_RECV_DESCRIPTOR >= CB_SIZE) if(mCbw.p_write() + SIZEOF_RECV_DESCRIPTOR >= CB_SIZE)
{ {
DEBUGPRINT("The descriptor won't fit\n"); INFO_LOG(SP1, "The descriptor won't fit\n");
return false; return false;
} }
if(size >= CB_SIZE) if(size >= CB_SIZE)
{ {
DEBUGPRINT("Packet too big: %i bytes\n", size); INFO_LOG(SP1, "Packet too big: %i bytes\n", size);
return false; return false;
} }
@ -297,7 +311,7 @@ bool CEXIETHERNET::cbwriteDescriptor(u32 size) {
descr.next_packet_ptr = npp >> 8; descr.next_packet_ptr = npp >> 8;
//DWORD swapped = swapw(descr.word); //DWORD swapped = swapw(descr.word);
//next_packet_ptr:12, packet_len:12, status:8; //next_packet_ptr:12, packet_len:12, status:8;
DEBUGPRINT("Writing descriptor 0x%08X @ 0x%04X: next 0x%03X len 0x%03X status 0x%02X\n", INFO_LOG(SP1, "Writing descriptor 0x%08X @ 0x%04lX: next 0x%03X len 0x%03X status 0x%02X\n",
descr.word, mCbw.p_write() + CB_OFFSET, descr.next_packet_ptr, descr.word, mCbw.p_write() + CB_OFFSET, descr.next_packet_ptr,
descr.packet_len, descr.status); descr.packet_len, descr.status);
mCbw.write(&descr.word, SIZEOF_RECV_DESCRIPTOR); mCbw.write(&descr.word, SIZEOF_RECV_DESCRIPTOR);

View File

@ -34,7 +34,7 @@ CEXIETHERNET::CEXIETHERNET(const std::string& mac_addr) :
int x = 0; int x = 0;
u8 new_addr[6] = { 0 }; u8 new_addr[6] = { 0 };
for (int i = 0; i < mac_addr.size() && x < 12; i++) for (int i = 0; i < (int)mac_addr.size() && x < 12; i++)
{ {
char c = mac_addr.at(i); char c = mac_addr.at(i);
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
@ -214,7 +214,7 @@ void CEXIETHERNET::ImmWrite(u32 data, u32 size)
//_dbg_assert_(SP1, data == (u32)((u16)mCbw.p_write() + CB_OFFSET) >> 8); //_dbg_assert_(SP1, data == (u32)((u16)mCbw.p_write() + CB_OFFSET) >> 8);
if (data != (u32)((u16)mCbw.p_write() + CB_OFFSET) >> 8) if (data != (u32)((u16)mCbw.p_write() + CB_OFFSET) >> 8)
{ {
ERROR_LOG(SP1, "BBA RWP ASSERT data %x p_write %x", data, mCbw.p_write()); ERROR_LOG(SP1, "BBA RWP ASSERT data %x p_write %lx", data, mCbw.p_write());
} }
break; break;
case BBA_RRP: // RRP - Receive Buffer Read Page Pointer case BBA_RRP: // RRP - Receive Buffer Read Page Pointer
@ -298,7 +298,7 @@ void CEXIETHERNET::ImmWrite(u32 data, u32 size)
break; break;
case 0x03: // status TODO more fields case 0x03: // status TODO more fields
mBbaMem[mReadP] = m_bInterruptSet ? 0x80 : 0; mBbaMem[mReadP] = m_bInterruptSet ? 0x80 : 0;
INFO_LOG(SP1, "\tStatus", mBbaMem[mReadP]); INFO_LOG(SP1, "\tStatus %x", mBbaMem[mReadP]);
break; break;
case BBA_LTPS: case BBA_LTPS:
INFO_LOG(SP1, "\tLPTS"); INFO_LOG(SP1, "\tLPTS");
@ -414,4 +414,4 @@ void CEXIETHERNET::DMARead(u32 addr, u32 size)
ERROR_LOG(SP1, "Unhandled BBA DMA read: %i, %08x", size, addr); ERROR_LOG(SP1, "Unhandled BBA DMA read: %i, %08x", size, addr);
} }
//#pragma optimize("",on) //#pragma optimize("",on)