added VDE functionality

This commit is contained in:
MSharq 2018-09-28 16:14:14 +02:00
parent 2e302d60a3
commit 90b65715ae
4 changed files with 91 additions and 5 deletions

View File

@ -323,6 +323,8 @@ else
SDL_SUPPORT="none"
fi
LIBS="$CFLAGS -lvdeplug"
dnl We need X11, if not using SDL or Mac GUI.
if [[ "x$WANT_SDL_VIDEO" = "xno" -a "x$WANT_MACOSX_GUI" = "xno" ]]; then
AC_PATH_XTRA

View File

@ -20,6 +20,9 @@
#include "sysdeps.h"
extern "C" {
#include <libvdeplug.h>
}
/*
* NOTES concerning MacOS X issues:
* - poll() does not exist in 10.2.8, but is available in 10.4.4
@ -93,7 +96,8 @@ enum {
NET_IF_SHEEPNET,
NET_IF_ETHERTAP,
NET_IF_TUNTAP,
NET_IF_SLIRP
NET_IF_SLIRP,
NET_IF_VDE
};
// Constants
@ -115,6 +119,7 @@ static pthread_t slirp_thread; // Slirp reception thread
static bool slirp_thread_active = false; // Flag: Slirp reception threadinstalled
static int slirp_output_fd = -1; // fd of slirp output pipe
static int slirp_input_fds[2] = { -1, -1 }; // fds of slirp input pipe
VDECONN *vde_conn;
#ifdef SHEEPSHAVER
static bool net_open = false; // Flag: initialization succeeded, network device open
static uint8 ether_addr[6]; // Our Ethernet address
@ -250,6 +255,10 @@ bool ether_init(void)
else if (strcmp(name, "slirp") == 0)
net_if_type = NET_IF_SLIRP;
#endif
else if (strcmp(name, "vde") == 0){
printf("selected Ethernet device type VDE\n");
net_if_type = NET_IF_VDE;
}
else
net_if_type = NET_IF_SHEEPNET;
@ -301,7 +310,33 @@ bool ether_init(void)
strcpy(dev_name, "/dev/sheep_net");
break;
}
if (net_if_type != NET_IF_SLIRP) {
//vde switch information
int port = 0;
char *init_group = NULL;
mode_t mode = 0700;
struct vde_open_args args = {
.port = port,
.group = init_group,
.mode = mode,
};
if (net_if_type == NET_IF_VDE) {
/* calling vde open to open the vde connection to the vde switch */
vde_conn = vde_open(vde_sock, (char *)"macemu", &args);
if (!vde_conn) {
D(bug("VDE open failed\n"));
return -1;
} else {
/* for select/poll when this fd receive data, there are
* packets to recv(call vde_recv) */
fd = vde_datafd(vde_conn);
}
}
if (net_if_type != NET_IF_SLIRP && net_if_type != NET_IF_VDE) {
fd = open(dev_name, O_RDWR);
if (fd < 0) {
sprintf(str, GetString(STR_NO_SHEEP_NET_DRIVER_WARN), dev_name, strerror(errno));
@ -388,6 +423,13 @@ bool ether_init(void)
ether_addr[4] = 0x34;
ether_addr[5] = 0x56;
#endif
} else if (net_if_type == NET_IF_VDE) {
ether_addr[0] = 0x52;
ether_addr[1] = 0x54;
ether_addr[2] = 0x00;
ether_addr[3] = 0x12;
ether_addr[4] = 0x34;
ether_addr[5] = 0x56;
} else
ioctl(fd, SIOCGIFADDR, ether_addr);
D(bug("Ethernet address %02x %02x %02x %02x %02x %02x\n", ether_addr[0], ether_addr[1], ether_addr[2], ether_addr[3], ether_addr[4], ether_addr[5]));
@ -453,6 +495,9 @@ void ether_exit(void)
if (slirp_output_fd > 0)
close(slirp_output_fd);
// Close vde_connection
if (net_if_type == NET_IF_VDE)
vde_close(vde_conn);
#if STATISTICS
// Show statistics
printf("%ld messages put on write queue\n", num_wput);
@ -749,9 +794,27 @@ static int16 ether_do_write(uint32 arg)
write(slirp_input_fd, &len, sizeof(len));
write(slirp_input_fd, packet, len);
return noErr;
} else
}
#endif
if (write(fd, packet, len) < 0) {
if (net_if_type == NET_IF_VDE) {
if (fd == -1) { // which means vde service is not running
D(bug("WARNING: Couldn't transmit VDE packet\n"));
return excessCollsns;
}
if (vde_conn == NULL)
{
D(bug("WARNING: vde_conn is NULL\n"));
return -1;
}
do {
len = vde_send(vde_conn,packet,sizeof(packet),0);
} while (len < 0);
return noErr;
}
else if (write(fd, packet, len) < 0) {
D(bug("WARNING: Couldn't transmit packet\n"));
return excessCollsns;
} else
@ -925,6 +988,9 @@ void ether_do_interrupt(void)
} else
#endif
{
if (net_if_type == NET_IF_VDE) {
length = vde_recv(vde_conn, Mac2HostAddr(packet), 1514, 0);
} else {
// Read packet from sheep_net device
#if defined(__linux__)
@ -932,6 +998,7 @@ void ether_do_interrupt(void)
#else
length = read(fd, Mac2HostAddr(packet), 1514);
#endif
}
if (length < 14)
break;

View File

@ -207,6 +207,8 @@ static void sigill_handler(int sig, int code, struct sigcontext *scp);
extern "C" void EmulOpTrampoline(void);
#endif
// vde switch variable
char* vde_sock;
/*
* Ersatz functions
@ -374,7 +376,8 @@ static void usage(const char *prg_name)
" --display STRING\n X display to use\n"
" --break ADDRESS\n set ROM breakpoint in hexadecimal\n"
" --loadbreak FILE\n load breakpoint from FILE\n"
" --rominfo\n dump ROM information\n", prg_name
" --rominfo\n dump ROM information\n"
" --switch SWITCH_PATH\n vde switch address\n", prg_name
);
LoadPrefs(NULL); // read the prefs file so PrefsPrintUsage() will print the correct default values
PrefsPrintUsage();
@ -436,6 +439,17 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "--rominfo") == 0) {
argv[i] = NULL;
PrintROMInfo = true;
} else if (strcmp(argv[i], "--switch") == 0) {
argv[i] = NULL;
if (argv[++i] == NULL) {
printf("switch address not defined\n");
usage(argv[0]);
}
int vde_str_len = strlen(argv[i]);
vde_sock = (char*)malloc(vde_str_len);
memset(vde_sock,NULL,vde_str_len);
strncpy(vde_sock,argv[i],vde_str_len);
argv[i] = NULL; //don't know why it works
}
}

View File

@ -74,6 +74,9 @@ extern uint32 InterruptFlags; // Currently pending interrupts
extern void SetInterruptFlag(uint32 flag); // Set/clear interrupt flags
extern void ClearInterruptFlag(uint32 flag);
// vde switch variable
extern char* vde_sock;
// Array length
#if __cplusplus >= 201103L || (_MSC_VER >= 1900 && defined __cplusplus)
template <typename T, size_t size>