From 3eb09ff9fec8cff2dd3b1ca3da33414fda386e59 Mon Sep 17 00:00:00 2001 From: waltje Date: Mon, 22 May 2017 00:21:22 -0400 Subject: [PATCH 1/4] Updates for dynamic loading of DLLs, some cleanups. --- src/86box.cfg | Bin 7452 -> 0 bytes src/86box.h | 2 + src/Makefile.mingw | 21 ++--- src/WIN/86Box.rc | 1 + src/WIN/plat_dynld.h | 30 +++++++ src/WIN/win.h | 93 +++++++++++-------- src/WIN/win_dynld.c | 64 +++++++++++++ src/WIN/win_language.c | 2 +- src/net_ne2000.c | 55 +++--------- src/net_pcap.c | 197 ++++++++++++++++++++--------------------- src/network.c | 34 +++++-- src/network.h | 5 +- 12 files changed, 296 insertions(+), 208 deletions(-) delete mode 100644 src/86box.cfg create mode 100644 src/WIN/plat_dynld.h create mode 100644 src/WIN/win_dynld.c diff --git a/src/86box.cfg b/src/86box.cfg deleted file mode 100644 index ad83f0d3556b0b9f3477aa51f21bf2a4a3740c75..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7452 zcmezWFPg!fA(bJIA(f$sA(0`6A(nxcfs3JxA(J76A)cX#A(f$+A(NqsA(cUa!InXR z!2m-(k0AxD8)O1RO$viCLkfc>lFC$ue1>?2G=@@!9EKc*Vuoa}$sl{b94VTDYB!WGp7Q0V3| zq%!0(B!TUO=>@6GV<=-NVu)ubU;vq%0d+?JgB3#zLlA>2LkL3bgA+qO zLj^+&LowLrF$@sB`V1g*au^aB@)*(?N*NLv(vf1(guwtBLm*Yr489DB49N@`V85h7 zQ$a36J~(c3ptff+Br)VN6fh)%O-^PgU?^pXXUGNHP|A=7Hlc)}6dbojP(6^4hp0vN zA4DXcp`0O+A(Np59FHKMg3=qZI!O3{QVDV@gt*=e#T}&##o!oBVW?!tV@L$MA{mP- z;=$=15#woKe<0h5nj(t9=D|#Yq!~z$yz$nJsI=E;x;b}1;mgK`|mJWx6>Mv5(17?dzn zGJtG=n3Bs-3=W$jhD>lC2bq_}kk3#F4)siiWQJ^pcm`BGkaz>BjAjUC$Y&@8r+kP% zi@|JEf95gdgG&*Rj$ClKWHQ7vWH97|?T81bBbbXJu7cPA3LQ`!gYsV@SS_L)fvEub z3Rw@xH<=7Z3(pi&AJub`3$R0iWV zFM}ZkTv~%lq&$Wah9ZW1a5;+zNo3nWB|E5eG(ajHA>|Y#3=#4s@UTUe2jw!5TS0C# zWI)YLu=ETGZ)BB5cva>w6fl6oA35itnw7**%8(8&!9b-VHgyo!L&DYro(Dmtb1_3U z11vOQVFgM#kkS=Y?}1VvsQd=iC$N+T@iT%%4ntH^av9PXa=|r12DmH)r2tr&32_yw zdRPd9%3DzBOh`Q}1;jJtFyw>FmlB3daDIci)queYoEt#CN3|=B0ak~h%7NkoRJTy( zdypxl_#UL56yJl?6ZX9!R^Nm4;_^MHgrMB_AX7;3JxDz%z6Yr%?0X}uz6a^W<$Duw zNe8MS6B)=)`5;qB@jXaADZU4(C+vG;tiA{7#pQcbs`wsc3Msw^sVBwvAoYZOZ-UkL zAicPJZ$=g0gG?dC_aOD8_#UL5ui|-+Narqw9PNlTIH)H^rLW=J}>PhiENIfCn zgZzov)`PeWm+wI>AQW6EFz4qYR#8j!iDs!{Dll`CfejgWvw z6bitjF`zL!#OOIfEvVcg-d2!mT(*Mbh_w||)}Y#oJhp*w9Y`H6`#^HU+6T&^#MlQ? zhs!>Y9De(f8B)Mu4H}7o#3%CTBPc#VBm1xs6Ht6&>L8R`ki!X6H@;MF1RmkV)I%uc z8!#Z3`I!1M!Q=0sk$uQ$7HCWn;zvv$g3<_SVFJ=YewcuC;|mkWs5h#gKzay=335$< zsh^ZE0i|Qo!UUv){4fFO#up|gSkehd58*IDt{+gt1f-voFahN?(!vC!gZwZ7>Bbi( WrdYxRq=#^rAlDkGVFJ>RKTH6h>w5zL diff --git a/src/86box.h b/src/86box.h index ef0a45e15..d45b1bead 100644 --- a/src/86box.h +++ b/src/86box.h @@ -3,3 +3,5 @@ */ #define emulator_version "1.20" #define emulator_version_w L"1.20" + +#define CONFIG_FILE L"86box.cfg" diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 39caf693b..49f095965 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -8,7 +8,7 @@ # # Modified Makefile for Win32 MinGW 32-bit environment. # -# Version: @(#)Makefile.mingw 1.0.13 2017/05/17 +# Version: @(#)Makefile.mingw 1.0.14 2017/05/21 # # Authors: Kotori, # Fred N. van Kempen, @@ -29,13 +29,10 @@ STUFF = EXTRAS = # Do we want a debugging build? -DEBUG = y -OPTIM = n +DEBUG = n +OPTIM = y X64 = n -# Where is the WinPcap DLL ? -PCAPDLL = C:\\Windows\\System32\\wpcap.dll - ######################################################################### # Nothing should need changing from here on.. # @@ -46,7 +43,7 @@ CPP = g++.exe CC = gcc.exe WINDRES = windres.exe -OPTS = -DWIN32 -I$(PLAT) $(EXTRAS) $(STUFF) +OPTS = -DWIN32 -I$(PLAT) -I$(X64INC) $(EXTRAS) $(STUFF) ifeq ($(DEBUG), y) ifeq ($(VRAMDUMP), y) DFLAGS = -march=i686 -ggdb -DDEBUG -DENABLE_VRAM_DUMP @@ -179,7 +176,7 @@ VIDOBJ = video.o \ WINOBJ = win.o \ win_d3d.o win_d3d-fs.o \ win_ddraw.o win_ddraw-fs.o win_ddraw-screenshot.o \ - win_language.o win_status.o win_opendir.o \ + win_language.o win_status.o win_opendir.o win_dynld.o \ win_video.o win_serial.o win_mouse.o \ win_joystick.o win_midi.o \ win_settings.o win_deviceconfig.o win_joystickconfig.o \ @@ -200,7 +197,7 @@ LIBS = -mwindows -lcomctl32 -lwinmm -lopenal.dll -lopenal -lddraw \ # Build rules. %.o: %.c @echo $< - $(CC) $(CFLAGS) -c $< + @$(CC) $(CFLAGS) -c $< %.o: %.cc @echo $< @@ -217,7 +214,7 @@ $(PROG).exe: $(OBJ) $(LZFOBJ) $(SLIRPOBJ) @echo Linking $(PROG).exe .. @$(CC) -o $(PROG).exe \ $(OBJ) $(LZFOBJ) $(SLIRPOBJ) \ - $(LIBS) -static -Lpcap -lwpcapdelay + $(LIBS) #-static -Lpcap -lwpcapdelay ifneq ($(DEBUG), y) @strip $(PROG).exe endif @@ -241,10 +238,6 @@ clean: @echo Processing $< @$(WINDRES) $(RFLAGS) -i win/86Box.rc -o 86Box.res -libwpcapdelay.a: $(PCAPDLL) - @dlltool --export-all-symbols --output-def wpcap.def $(PCAPDLL) - @dlltool --def wpcap.def --output-delaylib libwpcapdelay.a - pcap_if.res: pcap_if.rc @echo Processing $< @$(WINDRES) $(RFLAGS) -i win/pcap_if.rc -o pcap_if.res diff --git a/src/WIN/86Box.rc b/src/WIN/86Box.rc index a593212e4..2da75e1ee 100644 --- a/src/WIN/86Box.rc +++ b/src/WIN/86Box.rc @@ -1004,6 +1004,7 @@ BEGIN 2199 "USB is not yet supported" 2200 "Invalid PCap device" 2201 "English (United States)" + 2202 "Pcap Library Not Available" END diff --git a/src/WIN/plat_dynld.h b/src/WIN/plat_dynld.h new file mode 100644 index 000000000..74af2e8f8 --- /dev/null +++ b/src/WIN/plat_dynld.h @@ -0,0 +1,30 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Define the Dynamic Module Loader interface. + * + * Version: @(#)plat_dynld.h 1.0.1 2017/05/21 + * + * Author: Fred N. van Kempen, + * Copyright 2017 Fred N. van Kempen + */ +#ifndef PLAT_DYNLD_H +# define PLAT_DYNLD_H + + +typedef struct { + const char *name; + void *func; +} dllimp_t; + + +extern void *dynld_module(const char *, dllimp_t *); +extern void dynld_close(void *); + + +#endif /*PLAT_DYNLD_H*/ diff --git a/src/WIN/win.h b/src/WIN/win.h index ffe8fea2f..255c15a6e 100644 --- a/src/WIN/win.h +++ b/src/WIN/win.h @@ -1,53 +1,72 @@ +/* + * This should be named 'plat.h' and then include any + * Windows-specific header files needed, to keep them + * out of the main code. + */ /* Copyright holders: Sarah Walker see COPYING for more details */ -extern HINSTANCE hinstance; -extern HWND ghwnd; -extern int mousecapture; +#ifndef BOX_WIN_H +# define BOX_WIN_H -#ifdef __cplusplus -extern "C" { +#if 0 +# define UNICODE +# define BITMAP WINDOWS_BITMAP +# include +# undef BITMAP #endif + #define szClassName L"86BoxMainWnd" #define szSubClassName L"86BoxSubWnd" #define szStatusBarClassName L"86BoxStatusBar" -void leave_fullscreen(); + +extern HINSTANCE hinstance; +extern HWND ghwnd; +extern HWND status_hwnd; +extern HWND hwndStatus; +extern int status_is_open; +extern int mousecapture; + +extern char openfilestring[260]; +extern WCHAR wopenfilestring[260]; + +extern int pause; + + +#ifdef __cplusplus +extern "C" { +#endif + +extern void leave_fullscreen(void); + +extern void status_open(HWND hwnd); + +extern void deviceconfig_open(HWND hwnd, struct device_t *device); +extern void joystickconfig_open(HWND hwnd, int joy_nr, int type); + +extern int getfile(HWND hwnd, char *f, char *fn); +extern int getsfile(HWND hwnd, char *f, char *fn); + +extern void get_executable_name(WCHAR *s, int size); +extern void set_window_title(WCHAR *s); + +extern void startblit(void); +extern void endblit(void); + +extern void win_settings_open(HWND hwnd); +extern void win_menu_update(); + +extern void update_status_bar_panes(HWND hwnds); + +extern int fdd_type_to_icon(int type); + +extern void hard_disk_add_open(HWND hwnd, int is_existing); #ifdef __cplusplus } #endif -void status_open(HWND hwnd); -extern HWND status_hwnd; -extern int status_is_open; - -void deviceconfig_open(HWND hwnd, struct device_t *device); -void joystickconfig_open(HWND hwnd, int joy_nr, int type); - -extern char openfilestring[260]; -extern WCHAR wopenfilestring[260]; - -int getfile(HWND hwnd, char *f, char *fn); -int getsfile(HWND hwnd, char *f, char *fn); - -void get_executable_name(WCHAR *s, int size); -void set_window_title(WCHAR *s); - -void startblit(); -void endblit(); - -extern int pause; - -void win_settings_open(HWND hwnd); -void win_menu_update(); - -void update_status_bar_panes(HWND hwnds); - -int fdd_type_to_icon(int type); - -extern HWND hwndStatus; - -void hard_disk_add_open(HWND hwnd, int is_existing); +#endif /*BOX_WIN_H*/ diff --git a/src/WIN/win_dynld.c b/src/WIN/win_dynld.c new file mode 100644 index 000000000..229febc3a --- /dev/null +++ b/src/WIN/win_dynld.c @@ -0,0 +1,64 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Try to load a support DLL. + * + * Version: @(#)win_dynld.c 1.0.1 2017/05/21 + * + * Author: Fred N. van Kempen, + * Copyright 2017 Fred N. van Kempen + */ +#include +#include +#include +#include +#include +#include +#include "plat_dynld.h" +#include "../ibm.h" + + +void * +dynld_module(const char *name, dllimp_t *table) +{ + HANDLE h; + dllimp_t *imp; + void *func; + char **foo; + + /* See if we can load the desired module. */ + if ((h = LoadLibrary(name)) == NULL) { + pclog("DynLd(\"%s\"): library not found!\n", name); + return(NULL); + } + + /* Now load the desired function pointers. */ + for (imp=table; imp->name!=NULL; imp++) { + func = GetProcAddress(h, imp->name); + if (func == NULL) { + pclog("DynLd(\"%s\"): function '%s' not found!\n", + name, imp->name); + CloseHandle(h); + return(NULL); + } + + /* To overcome typing issues.. */ + *(char **)imp->func = (char *)func; + } + + /* All good. */ + return((void *)h); +} + + +void +dynld_close(void *handle) +{ + if (handle != NULL) + CloseHandle((HANDLE *)handle); +} diff --git a/src/WIN/win_language.c b/src/WIN/win_language.c index e87964d37..00abb7faf 100644 --- a/src/WIN/win_language.c +++ b/src/WIN/win_language.c @@ -21,7 +21,7 @@ LCID dwLanguage; uint32_t dwLangID, dwSubLangID; -#define STRINGS_NUM 154 +#define STRINGS_NUM 155 /* FIXME: should be in resource.h !! --FvK */ WCHAR lpResourceString[STRINGS_NUM][512]; diff --git a/src/net_ne2000.c b/src/net_ne2000.c index 51fdd7b4e..81800086d 100644 --- a/src/net_ne2000.c +++ b/src/net_ne2000.c @@ -11,7 +11,7 @@ * NOTE: Its still a mess, but we're getting there. The file will * also implement an NE1000 for 8-bit ISA systems. * - * Version: @(#)net_ne2000.c 1.0.4 2017/05/17 + * Version: @(#)net_ne2000.c 1.0.5 2017/05/21 * * Authors: Fred N. van Kempen, * Peter Grehan, grehan@iprg.nokia.com> @@ -1842,10 +1842,21 @@ nic_init(int board) !dev->disable_netbios); if (network_attach(dev, dev->physaddr, nic_rx) < 0) { +#if 0 + msgbox_error_wstr(ghwnd, L"Unable to init platform network"); +#endif pclog(1, "%s: unable to init platform network type %d\n", dev->name, network_type); +#if 0 + /* + * To avoid crashes, we ignore the fact that even though + * there is no active platform support, we just continue + * initializing. If we return an error here, the device + * handling code will throw a fatal error... --FvK + */ free(dev); return(NULL); +#endif } if (dev->is_rtl8029as) @@ -1987,20 +1998,6 @@ static device_config_t ne1000_config[] = } }, }, - { - "net_type", "Network type", CONFIG_SELECTION, "", 0, - { - { - "PCap", 0 - }, - { - "SLiRP", 1 - }, - { - "" - } - }, - }, { "mac", "MAC Address", CONFIG_MAC, "", -1 }, @@ -2063,20 +2060,6 @@ static device_config_t ne2000_config[] = } }, }, - { - "net_type", "Network type", CONFIG_SELECTION, "", 0, - { - { - "PCap", 0 - }, - { - "SLiRP", 1 - }, - { - "" - } - }, - }, { "mac", "MAC Address", CONFIG_MAC, "", -1 }, @@ -2113,20 +2096,6 @@ static device_config_t rtl8029as_config[] = } }, }, - { - "net_type", "Network type", CONFIG_SELECTION, "", 0, - { - { - "PCap", 0 - }, - { - "SLiRP", 1 - }, - { - "" - } - }, - }, { "mac", "MAC Address", CONFIG_MAC, "", -1 }, diff --git a/src/net_pcap.c b/src/net_pcap.c index 3ca2e9089..448738715 100644 --- a/src/net_pcap.c +++ b/src/net_pcap.c @@ -1,6 +1,6 @@ /* * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM + * running old operating systems and software designed for IBM * PC systems and compatibles from 1981 through fairly recent * system designs based on the PCI bus. * @@ -8,7 +8,7 @@ * * Handle WinPcap library processing. * - * Version: @(#)net_pcap.c 1.0.2 2017/05/17 + * Version: @(#)net_pcap.c 1.0.3 2017/05/21 * * Author: Fred N. van Kempen, */ @@ -22,59 +22,61 @@ #include "thread.h" #include "device.h" #include "network.h" +#include "plat_dynld.h" +static void *pcap_handle; /* handle to WinPcap DLL */ static pcap_t *pcap; /* handle to WinPcap library */ static thread_t *poll_tid; static NETRXCB poll_rx; /* network RX function to call */ static void *poll_arg; /* network RX function arg */ -#ifdef WALTJE -int pcap_do_log = 1; -# define ENABLE_PCAP_LOG -#else -int pcap_do_log = 0; -#endif +/* Pointers to the real functions. */ +static const char *(*f_pcap_lib_version)(void); +static int (*f_pcap_findalldevs)(pcap_if_t **,char *); +static void (*f_pcap_freealldevs)(pcap_if_t *); +static pcap_t *(*f_pcap_open_live)(const char *,int,int,int,char *); +static int (*f_pcap_compile)(pcap_t *,struct bpf_program *, + const char *,int,bpf_u_int32); +static int (*f_pcap_setfilter)(pcap_t *,struct bpf_program *); +static const u_char *(*f_pcap_next)(pcap_t *,struct pcap_pkthdr *); +static int (*f_pcap_sendpacket)(pcap_t *,const u_char *,int); +static void (*f_pcap_close)(pcap_t *); +static dllimp_t pcap_imports[] = { + { "pcap_lib_version", &f_pcap_lib_version }, + { "pcap_findalldevs", &f_pcap_findalldevs }, + { "pcap_freealldevs", &f_pcap_freealldevs }, + { "pcap_open_live", &f_pcap_open_live }, + { "pcap_compile", &f_pcap_compile }, + { "pcap_setfilter", &f_pcap_setfilter }, + { "pcap_next", &f_pcap_next }, + { "pcap_sendpacket", &f_pcap_sendpacket }, + { "pcap_close", &f_pcap_close }, + { NULL, NULL }, +}; -static void -pcap_log(const char *format, ...) -{ -#ifdef ENABLE_PCAP_LOG - va_list ap; - - if (pcap_do_log) { - va_start(ap, format); - vprintf(format, ap); - va_end(ap); - fflush(stdout); - } -#endif -} -#define pclog pcap_log - - -/* Check if the interface has a packet for us. */ +/* Handle the receiving of frames from the channel. */ static void poll_thread(void *arg) { - const unsigned char *data; uint8_t *mac = (uint8_t *)arg; + const uint8_t *data = NULL; struct pcap_pkthdr h; - event_t *evt; uint32_t mac_cmp32[2]; uint16_t mac_cmp16[2]; + event_t *evt; pclog("PCAP: polling thread started, arg %08lx\n", arg); /* Create a waitable event. */ evt = thread_create_event(); - pclog("PCAP: poll event is %08lx\n", evt); + /* As long as the channel is open.. */ while (pcap != NULL) { /* Wait for the next packet to arrive. */ - data = pcap_next(pcap, &h); + data = f_pcap_next(pcap, &h); if (data != NULL) { /* Received MAC. */ mac_cmp32[0] = *(uint32_t *)(data+6); @@ -105,6 +107,43 @@ poll_thread(void *arg) } +/* Initialize the (Win)Pcap module for use. */ +int +network_pcap_init(netdev_t *list) +{ + char errbuf[PCAP_ERRBUF_SIZE]; + pcap_if_t *devlist, *dev; + int i = 0; + + /* Local variables. */ + pcap = NULL; + + /* Try loading the DLL. */ + pcap_handle = dynld_module("wpcap.dll", pcap_imports); + if (pcap_handle == NULL) return(-1); + + /* Retrieve the device list from the local machine */ + if (f_pcap_findalldevs(&devlist, errbuf) == -1) { + pclog("PCAP: error in pcap_findalldevs: %s\n", errbuf); + return(-1); + } + + for (dev=devlist; dev!=NULL; dev=dev->next) { + strcpy(list->device, dev->name); + if (dev->description) + strcpy(list->description, dev->description); + else + memset(list->description, '\0', sizeof(list->description)); + list++; i++; + } + + /* Release the memory. */ + f_pcap_freealldevs(devlist); + + return(i); +} + + /* Initialize WinPcap for us. */ int network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg) @@ -114,20 +153,13 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg) struct bpf_program fp; char *dev; - /* Messy, but gets rid of a lot of useless info. */ - dev = (char *)pcap_lib_version(); - if (dev == NULL) { - /* Hmm, WinPcap doesn't seem to be alive.. */ - pclog("PCAP: WinPcap library not found, disabling network!\n"); - network_type = -1; - return(-1); - } + /* Did we already load the DLL? */ + if (pcap_handle == NULL) return(-1); - /* OK, good for now.. */ - strcpy(temp, dev); + strcpy(temp, f_pcap_lib_version()); dev = strchr(temp, '('); if (dev != NULL) *(dev-1) = '\0'; - pclog("Initializing WinPcap, version %s\n", temp); + pclog("PCAP: initializing, %s\n", temp); /* Get the value of our capture interface. */ dev = network_pcap; @@ -137,38 +169,35 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg) } pclog(" Network interface: '%s'\n", dev); - pcap = pcap_open_live(dev, /* interface name */ - 1518, /* maximum packet size */ - 1, /* promiscuous mode? */ - 10, /* timeout in msec */ - temp); /* error buffer */ + pcap = f_pcap_open_live(dev, /* interface name */ + 1518, /* maximum packet size */ + 1, /* promiscuous mode? */ + 10, /* timeout in msec */ + temp); /* error buffer */ if (pcap == NULL) { - pclog("Unable to open WinPcap: %s!\n", temp); + pclog(" Unable to open device: %s!\n", temp); return(-1); } /* Create a MAC address based packet filter. */ - pclog("Building packet filter ..."); + pclog(" Installing packet filter for MAC=%02x:%02x:%02x:%02x:%02x\n", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); sprintf(filter_exp, "( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - if (pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { - pclog("..."); - if (pcap_setfilter(pcap, &fp) == -1) { - pclog(" error installing filter!\n"); - } else { - pclog("!\nUsing filter\t[%s]\n", filter_exp); - } + if (f_pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { + if (f_pcap_setfilter(pcap, &fp) == -1) + pclog(" Error installing filter (%s) !\n", filter_exp); } else { - pclog(" could not compile filter!\n"); + pclog(" Could not compile filter (%s) !\n", filter_exp); } /* Save the callback info. */ poll_rx = func; poll_arg = arg; - pclog("PCAP: creating thread..\n"); + pclog(" Starting thread..\n"); poll_tid = thread_create(poll_thread, mac); return(0); @@ -199,7 +228,13 @@ network_pcap_close(void) #endif /* OK, now shut down WinPcap itself. */ - pcap_close(pc); + f_pcap_close(pc); + + /* Unload the DLL if possible. */ + if (pcap_handle != NULL) { + dynld_close(pcap_handle); + pcap_handle = NULL; + } } poll_rx = NULL; poll_arg = NULL; @@ -211,49 +246,5 @@ void network_pcap_in(uint8_t *bufp, int len) { if (pcap != NULL) - pcap_sendpacket(pcap, bufp, len); -} - - -/* Retrieve an easy-to-use list of devices. */ -int -network_devlist(netdev_t *list) -{ - char errbuf[PCAP_ERRBUF_SIZE]; - char *temp_dev; - pcap_if_t *devlist, *dev; - int i = 0; - - /* Create a first entry that's always there - needed by UI. */ - strcpy(list->device, "none"); - strcpy(list->description, "None"); - list++; i++; - - /* See if WinPcap is even present, and get out of here if it's not. */ - temp_dev = (char *)pcap_lib_version(); - if (temp_dev == NULL) { - /* Hmm, WinPcap doesn't seem to be alive.. */ - pclog("PCAP: WinPcap library not found, not processing the networks list further!\n"); - return(i); - } - - /* Retrieve the device list from the local machine */ - if (pcap_findalldevs(&devlist, errbuf) == -1) { - pclog("NETWORK: error in pcap_findalldevs: %s\n", errbuf); - return(i); - } - - for (dev=devlist; dev!=NULL; dev=dev->next) { - strcpy(list->device, dev->name); - if (dev->description) - strcpy(list->description, dev->description); - else - memset(list->description, '\0', sizeof(list->description)); - list++; i++; - } - - /* Release the memory. */ - pcap_freealldevs(devlist); - - return(i); + f_pcap_sendpacket(pcap, bufp, len); } diff --git a/src/network.c b/src/network.c index 63a8c0f9d..90bd69aac 100644 --- a/src/network.c +++ b/src/network.c @@ -12,7 +12,7 @@ * it should be malloc'ed and then linked to the NETCARD def. * Will be done later. * - * Version: @(#)network.c 1.0.4 2017/05/17 + * Version: @(#)network.c 1.0.5 2017/05/21 * * Authors: Kotori, * Fred N. van Kempen, @@ -25,6 +25,14 @@ #include "device.h" #include "network.h" #include "net_ne2000.h" +#ifndef unix +# define UNICODE +# define BITMAP WINDOWS_BITMAP +# include +# undef BITMAP +# include "win.h" +# include "win_language.h" +#endif static netcard_t net_cards[] = { @@ -59,11 +67,20 @@ char network_pcap[512]; void network_init(void) { + int i; + network_type = NET_TYPE_NONE; network_card = 0; - /* Initialize list of PCap devices. */ - network_ndev = network_devlist(network_devs); + /* Create a first device entry that's always there, as needed by UI. */ + strcpy(network_devs[0].device, "none"); + strcpy(network_devs[0].description, "None"); + network_ndev = 1; + + /* Initialize the Pcap system module, if present. */ + i = network_pcap_init(&network_devs[network_ndev]); + if (i > 0) + network_ndev += i; } @@ -79,7 +96,7 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx) { int ret = -1; - if (! network_card) return(ret); + if (network_card == 0) return(ret); /* Save the card's callback info. */ net_cards[network_card].private = dev; @@ -89,6 +106,10 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx) switch(network_type) { case NET_TYPE_PCAP: ret = network_pcap_setup(mac, rx, dev); + if (ret < 0) { + msgbox_error(ghwnd, 2202); + network_type = NET_TYPE_NONE; + } break; case NET_TYPE_SLIRP: @@ -128,7 +149,7 @@ network_close(void) void network_reset(void) { - pclog("NETWORK: reset (type=%d, card=%d\n", network_type, network_card); + pclog("NETWORK: reset (type=%d, card=%d)\n", network_type, network_card); /* Just in case.. */ network_close(); @@ -136,11 +157,10 @@ network_reset(void) /* If no active card, we're done. */ if ((network_type==NET_TYPE_NONE) || (network_card==0)) return; - pclog("NETWORK: set up for %s, card=%s\n", + pclog("NETWORK: set up for %s, card='%s'\n", (network_type==NET_TYPE_SLIRP)?"SLiRP":"WinPcap", net_cards[network_card].name); - pclog("NETWORK: reset (card=%d)\n", network_card); /* Add the (new?) card to the I/O system. */ if (net_cards[network_card].device) { pclog("NETWORK: adding device '%s'\n", diff --git a/src/network.h b/src/network.h index 30a8427b8..b8b98e2ae 100644 --- a/src/network.h +++ b/src/network.h @@ -8,7 +8,7 @@ * * Definitions for the network module. * - * Version: @(#)network.h 1.0.4 2017/05/17 + * Version: @(#)network.h 1.0.5 2017/05/21 * * Authors: Kotori, * Fred N. van Kempen, @@ -62,16 +62,15 @@ extern void network_close(void); extern void network_reset(void); extern void network_tx(uint8_t *, int); +extern int network_pcap_init(netdev_t *); extern int network_pcap_setup(uint8_t *, NETRXCB, void *); extern void network_pcap_close(void); extern void network_pcap_in(uint8_t *, int); -extern int network_devlist(netdev_t *); extern int network_slirp_setup(uint8_t *, NETRXCB, void *); extern void network_slirp_close(void); extern void network_slirp_in(uint8_t *, int); -extern int network_devlist(netdev_t *); extern int network_dev_to_id(char *); extern int network_card_available(int); extern char *network_card_getname(int); From a4cd4b2866201150e1bbc87a83302192f4d300bf Mon Sep 17 00:00:00 2001 From: TC1995 Date: Mon, 22 May 2017 13:52:45 +0200 Subject: [PATCH 2/4] Increased HD heads limit to 255, larger SCSI hdds now work. --- src/config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index a335ab55a..04557b544 100644 --- a/src/config.c +++ b/src/config.c @@ -971,9 +971,9 @@ static void loadconfig_hard_disks(void) { hdc[c].spt = 99; } - if (hdc[c].hpc > 64) + if (hdc[c].hpc > 255) { - hdc[c].hpc = 64; + hdc[c].hpc = 255; } if (hdc[c].tracks > 266305) { From 77430348fca19fee4e927d1f0e8e6f68b3beb89b Mon Sep 17 00:00:00 2001 From: waltje Date: Wed, 24 May 2017 00:27:42 -0400 Subject: [PATCH 3/4] Another network cleaning (MAC address madness, BIOS stuff), WIN platform cleanup, Makefile[.local] cleanup. --- src/Makefile.local | 42 ++ src/Makefile.mingw | 134 ++--- src/WIN/win.c | 23 +- src/WIN/win.h | 11 +- src/WIN/win_crashdump.c | 344 +++++++------ src/WIN/win_d3d-fs.h | 13 - src/WIN/win_d3d.cc | 7 +- src/WIN/win_d3d.h | 27 +- src/WIN/{win_d3d-fs.cc => win_d3d_fs.cc} | 18 +- src/WIN/win_ddraw-fs.h | 11 - src/WIN/win_ddraw-screenshot.h | 4 - src/WIN/win_ddraw.cc | 5 - src/WIN/win_ddraw.h | 22 +- src/WIN/{win_ddraw-fs.cc => win_ddraw_fs.cc} | 32 +- ...-screenshot.cc => win_ddraw_screenshot.cc} | 18 +- src/WIN/win_deviceconfig.c | 9 +- src/config.c | 9 - src/net_ne2000.c | 457 +++++++++--------- src/net_pcap.c | 4 +- src/network.c | 12 +- src/pc.c | 12 +- 21 files changed, 653 insertions(+), 561 deletions(-) create mode 100644 src/Makefile.local delete mode 100644 src/WIN/win_d3d-fs.h rename src/WIN/{win_d3d-fs.cc => win_d3d_fs.cc} (99%) delete mode 100644 src/WIN/win_ddraw-fs.h delete mode 100644 src/WIN/win_ddraw-screenshot.h rename src/WIN/{win_ddraw-fs.cc => win_ddraw_fs.cc} (97%) rename src/WIN/{win_ddraw-screenshot.cc => win_ddraw_screenshot.cc} (94%) diff --git a/src/Makefile.local b/src/Makefile.local new file mode 100644 index 000000000..9b9988201 --- /dev/null +++ b/src/Makefile.local @@ -0,0 +1,42 @@ +# +# 86Box A hypervisor and IBM PC system emulator that specializes in +# running old operating systems and software designed for IBM +# PC systems and compatibles from 1981 through fairly recent +# system designs based on the PCI bus. +# +# This file is part of the 86Box distribution. +# +# Prefix for localizing the general Makefile.mingw for local +# settings, so we can avoid changing the main one for all of +# our local setups. +# +# Version: @(#)Makefile.local 1.0.2 2017/05/23 +# +# Author: Fred N. van Kempen, +# + +######################################################################### +# Anything here will override defaults in Makefile.MinGW. # +######################################################################### + + +DEBUG = y +OPTIM = n +COPTIM = -O1 + +# Name of the executable. +PROG = yourexe + +# Various compile-time options. +STUFF = #-DROM_TRACE=0xC800 -DIO_TRACE=0x70 +EXTRAS = #-DYOURNAME + + + +######################################################################### +# Include the master Makefile.MinGW for the rest. # +######################################################################### +include Makefile.mingw + + +# End of Makefile.local. diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 49f095965..4ba3565e2 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -8,7 +8,7 @@ # # Modified Makefile for Win32 MinGW 32-bit environment. # -# Version: @(#)Makefile.mingw 1.0.14 2017/05/21 +# Version: @(#)Makefile.mingw 1.0.16 2017/05/22 # # Authors: Kotori, # Fred N. van Kempen, @@ -17,21 +17,33 @@ # # Name of the executable. +ifndef PROG PROG = 86Box +endif # Various compile-time options. # -DROM_TRACE=0xcd800 traces ROM access from segment C800 # -DIO_TACE=0x66 traces I/O on port 0x66 +ifndef STUFF STUFF = +endif # Add feature selections here. # -DBUGGER adds the ISA BusBugger emulation. -EXTRAS = +ifndef EXTRAS +EXTRAS = lala +endif # Do we want a debugging build? +ifndef DEBUG DEBUG = n +endif +ifndef OPTIM OPTIM = y +endif +ifndef X64 X64 = n +endif ######################################################################### @@ -43,27 +55,33 @@ CPP = g++.exe CC = gcc.exe WINDRES = windres.exe -OPTS = -DWIN32 -I$(PLAT) -I$(X64INC) $(EXTRAS) $(STUFF) +OPTS = -DWIN32 -I$(PLAT) $(EXTRAS) $(STUFF) ifeq ($(DEBUG), y) ifeq ($(VRAMDUMP), y) DFLAGS = -march=i686 -ggdb -DDEBUG -DENABLE_VRAM_DUMP else DFLAGS = -march=i686 -ggdb -DDEBUG endif +ifndef COPTIM COPTIM = -Og +endif else ifeq ($(OPTIM), y) DFLAGS = -march=native +ifndef COPTIM COPTIM = -O6 +endif else ifeq ($(X64), y) DFLAGS = else DFLAGS = -march=i686 endif +ifndef COPTIM COPTIM = -O3 endif endif +endif ifeq ($(OPTIM), y) AOPTIM = -mtune=native else @@ -102,17 +120,17 @@ CPUOBJ = cpu.o 386.o 386_dynarec.o 386_dynarec_ops.o 808x.o \ codegen_timing_winchip.o $(PLATCG) \ x86seg.o x87.o SYSOBJ = model.o \ - headland.o \ - i430hx.o i430lx.o i430fx.o i430nx.o i430vx.o i440fx.o \ - neat.o \ - ali1429.o \ - opti495.o \ - scat.o \ - sis496.o \ - wd76c10.o \ - acer386sx.o acerm3a.o amstrad.o \ - compaq.o olivetti_m24.o jim.o ps1.o ps2.o ps2_mca.o \ - tandy_eeprom.o tandy_rom.o + headland.o \ + i430hx.o i430lx.o i430fx.o i430nx.o i430vx.o i440fx.o \ + neat.o \ + ali1429.o \ + opti495.o \ + scat.o \ + sis496.o \ + wd76c10.o \ + acer386sx.o acerm3a.o amstrad.o \ + compaq.o olivetti_m24.o jim.o ps1.o ps2.o ps2_mca.o \ + tandy_eeprom.o tandy_rom.o DEVOBJ = bugger.o lpt.o serial.o \ um8669f.o pc87306.o sis85c471.o w83877f.o \ keyboard.o \ @@ -133,53 +151,53 @@ DEVOBJ = bugger.o lpt.o serial.o \ cdrom_dosbox.o cdrom_image.o cdrom_ioctl.o cdrom_null.o USBOBJ = usb.o NETOBJ = network.o \ - net_pcap.o net_slirp.o \ - net_ne2000.o + net_pcap.o net_slirp.o \ + net_ne2000.o SCSIOBJ = scsi.o scsi_disk.o scsi_buslogic.o scsi_aha154x.o SNDOBJ = sound.o \ - convolve.o convolve-sse.o envelope.o extfilt.o \ - filter.o pot.o sid.o voice.o wave6581__ST.o \ - wave6581_P_T.o wave6581_PS_.o wave6581_PST.o \ - wave8580__ST.o wave8580_P_T.o wave8580_PS_.o \ - wave8580_PST.o wave.o \ - dbopl.o nukedopl.o openal.o \ - snd_speaker.o snd_ps1.o snd_pssj.o \ - snd_adlib.o snd_adlibgold.o snd_ad1848.o \ - snd_sb.o snd_sb_dsp.o snd_cms.o snd_dbopl.o \ - snd_emu8k.o snd_gus.o snd_opl.o \ - snd_mpu401.o snd_pas16.o snd_resid.o \ - snd_sn76489.o snd_ssi2001.o snd_wss.o \ - snd_ym7128.o + convolve.o convolve-sse.o envelope.o extfilt.o \ + filter.o pot.o sid.o voice.o wave6581__ST.o \ + wave6581_P_T.o wave6581_PS_.o wave6581_PST.o \ + wave8580__ST.o wave8580_P_T.o wave8580_PS_.o \ + wave8580_PST.o wave.o \ + dbopl.o nukedopl.o openal.o \ + snd_speaker.o snd_ps1.o snd_pssj.o \ + snd_adlib.o snd_adlibgold.o snd_ad1848.o \ + snd_sb.o snd_sb_dsp.o snd_cms.o snd_dbopl.o \ + snd_emu8k.o snd_gus.o snd_opl.o \ + snd_mpu401.o snd_pas16.o snd_resid.o \ + snd_sn76489.o snd_ssi2001.o snd_wss.o \ + snd_ym7128.o VIDOBJ = video.o \ - vid_cga.o vid_cga_comp.o vid_mda.o vid_ega.o \ - vid_vga.o vid_svga.o vid_svga_render.o \ - vid_hercules.o vid_herculesplus.o vid_incolor.o \ - vid_colorplus.o \ - vid_genius.o \ - vid_s3.o vid_s3_virge.o \ - vid_et4000.o vid_et4000w32.o vid_icd2061.o \ - vid_oti067.o \ - vid_paradise.o \ - vid_tvga.o vid_tgui9440.o vid_tkd8001_ramdac.o \ - vid_ati_eeprom.o vid_ati18800.o vid_ati28800.o \ - vid_ati68860_ramdac.o vid_ati_mach64.o \ - vid_ics2595.o \ - vid_sdac_ramdac.o \ - vid_stg_ramdac.o \ - vid_unk_ramdac.o \ - vid_wy700.o \ - vid_voodoo.o \ - vid_pcjr.o vid_ps1_svga.o \ - vid_olivetti_m24.o \ - vid_pc1512.o vid_pc1640.o vid_pc200.o \ - vid_tandy.o vid_tandysl.o + vid_cga.o vid_cga_comp.o vid_mda.o vid_ega.o \ + vid_vga.o vid_svga.o vid_svga_render.o \ + vid_hercules.o vid_herculesplus.o vid_incolor.o \ + vid_colorplus.o \ + vid_genius.o \ + vid_s3.o vid_s3_virge.o \ + vid_et4000.o vid_et4000w32.o vid_icd2061.o \ + vid_oti067.o \ + vid_paradise.o \ + vid_tvga.o vid_tgui9440.o vid_tkd8001_ramdac.o \ + vid_ati_eeprom.o vid_ati18800.o vid_ati28800.o \ + vid_ati68860_ramdac.o vid_ati_mach64.o \ + vid_ics2595.o \ + vid_sdac_ramdac.o \ + vid_stg_ramdac.o \ + vid_unk_ramdac.o \ + vid_wy700.o \ + vid_voodoo.o \ + vid_pcjr.o vid_ps1_svga.o \ + vid_olivetti_m24.o \ + vid_pc1512.o vid_pc1640.o vid_pc200.o \ + vid_tandy.o vid_tandysl.o WINOBJ = win.o \ - win_d3d.o win_d3d-fs.o \ - win_ddraw.o win_ddraw-fs.o win_ddraw-screenshot.o \ - win_language.o win_status.o win_opendir.o win_dynld.o \ - win_video.o win_serial.o win_mouse.o \ - win_joystick.o win_midi.o \ - win_settings.o win_deviceconfig.o win_joystickconfig.o \ + win_ddraw.o win_ddraw_fs.o win_ddraw_screenshot.o \ + win_d3d.o win_d3d_fs.o \ + win_language.o win_status.o win_opendir.o win_dynld.o \ + win_video.o win_serial.o win_mouse.o \ + win_joystick.o win_midi.o \ + win_settings.o win_deviceconfig.o win_joystickconfig.o \ 86Box.res OBJ = $(MAINOBJ) $(CPUOBJ) $(SYSOBJ) $(DEVOBJ) $(USBOBJ) \ $(NETOBJ) $(SCSIOBJ) $(SNDOBJ) $(VIDOBJ) $(WINOBJ) @@ -197,7 +215,7 @@ LIBS = -mwindows -lcomctl32 -lwinmm -lopenal.dll -lopenal -lddraw \ # Build rules. %.o: %.c @echo $< - @$(CC) $(CFLAGS) -c $< + $(CC) $(CFLAGS) -c $< %.o: %.cc @echo $< diff --git a/src/WIN/win.c b/src/WIN/win.c index af72b0ef1..4b6c771d0 100644 --- a/src/WIN/win.c +++ b/src/WIN/win.c @@ -1,21 +1,10 @@ /* Copyright holders: Sarah Walker, Tenshi see COPYING for more details */ -#define UNICODE -#define _WIN32_WINNT 0x0501 -#define BITMAP WINDOWS_BITMAP -#include -#include -#undef BITMAP - -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include #include "../86box.h" #include "../device.h" #include "../disc.h" @@ -45,10 +34,12 @@ #include "win.h" #include "win_ddraw.h" -#include "win_ddraw-fs.h" #include "win_d3d.h" -#include "win_d3d-fs.h" #include "win_language.h" +#include +#include +#include +#include #include "resource.h" diff --git a/src/WIN/win.h b/src/WIN/win.h index 255c15a6e..1d4feec57 100644 --- a/src/WIN/win.h +++ b/src/WIN/win.h @@ -8,13 +8,16 @@ */ #ifndef BOX_WIN_H # define BOX_WIN_H - -#if 0 -# define UNICODE +# ifndef NO_UNICODE +# define UNICODE +# endif # define BITMAP WINDOWS_BITMAP +//# ifdef _WIN32_WINNT +//# undef _WIN32_WINNT +//# define _WIN32_WINNT 0x0501 +//# endif # include # undef BITMAP -#endif #define szClassName L"86BoxMainWnd" diff --git a/src/WIN/win_crashdump.c b/src/WIN/win_crashdump.c index 3fee061b3..957ce296e 100644 --- a/src/WIN/win_crashdump.c +++ b/src/WIN/win_crashdump.c @@ -12,174 +12,214 @@ #include "../86box.h" #include "win_crashdump.h" -PVOID hExceptionHandler; -char* ExceptionHandlerBuffer; + #define ExceptionHandlerBufferSize (10240) -LONG CALLBACK MakeCrashDump(PEXCEPTION_POINTERS ExceptionInfo) { - // Win32-specific functions will be used wherever possible, just in case the C stdlib-equivalents try to allocate memory. - // (The Win32-specific functions are generally just wrappers over NT system calls anyway.) - - if ((ExceptionInfo->ExceptionRecord->ExceptionCode >> 28) != 0xC) { - // The exception code is not a fatal exception (highest 4 bits of ntstatus = 0xC) - // Not going to crash, let's not make a crash dump - return EXCEPTION_CONTINUE_SEARCH; - } - - // So, the program is about to crash. Oh no what do? - // Let's create a crash dump file as a debugging-aid. - - // First, get the path to 86Box.exe. - char* CurrentBufferPointer; - GetModuleFileName(NULL,ExceptionHandlerBuffer,ExceptionHandlerBufferSize); - if (GetLastError() != ERROR_SUCCESS) { - // Could not get the full path of 86Box.exe. Just create the file in the current directory. - CurrentBufferPointer = ExceptionHandlerBuffer; - } else { - // Walk through the string backwards looking for the last backslash, so as to remove the "86Box.exe" filename from the string. - CurrentBufferPointer = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; - for (; CurrentBufferPointer > ExceptionHandlerBuffer; CurrentBufferPointer--) { - if (CurrentBufferPointer[0] == '\\') { - // Found the backslash, null terminate the string after it. - CurrentBufferPointer[1] = 0; - break; - } - } - - CurrentBufferPointer = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; - } - - // What would a good filename be? It should contain the current date and time so as to be (hopefully!) unique. - SYSTEMTIME SystemTime; - GetSystemTime(&SystemTime); - sprintf(CurrentBufferPointer, - "86box-%d%02d%02d-%02d-%02d-%02d-%03d.dmp", - SystemTime.wYear, - SystemTime.wMonth, - SystemTime.wDay, - SystemTime.wHour, - SystemTime.wMinute, - SystemTime.wSecond, - SystemTime.wMilliseconds); - - DWORD Error; - - // Now the filename is in the buffer, the file can be created. - HANDLE hDumpFile = CreateFile( - ExceptionHandlerBuffer, // The filename of the file to open. - GENERIC_WRITE, // The permissions to request. - 0, // Make sure other processes can't touch the crash dump at all while it's open. - NULL, // Leave the security descriptor undefined, it doesn't matter. - OPEN_ALWAYS, // Opens the file if it exists, creates a new file if it doesn't. - FILE_ATTRIBUTE_NORMAL, // File attributes / etc don't matter. - NULL); // A template file is not being used. - - // Check to make sure the file was actually created. - if (hDumpFile == INVALID_HANDLE_VALUE) { - // CreateFile() failed, so just do nothing more. - return EXCEPTION_CONTINUE_SEARCH; - } - - // Now the file is open, let's write the data we were passed out in a human-readable format. - - // Let's get the name of the module where the exception occured. - HMODULE hMods[1024]; - MODULEINFO modInfo; - HMODULE ipModule = 0; - DWORD cbNeeded; - // Try to get a list of all loaded modules. - if (EnumProcessModules(GetCurrentProcess(), hMods, sizeof(hMods), &cbNeeded)) { - // The list was obtained, walk through each of the modules. - for (DWORD i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) { - // For each module, get the module information (base address, size, entry point) - GetModuleInformation(GetCurrentProcess(), hMods[i], &modInfo, sizeof(MODULEINFO)); - // If the exception address is located in the range of where this module is loaded... - if ( - (ExceptionInfo->ExceptionRecord->ExceptionAddress >= modInfo.lpBaseOfDll) && - (ExceptionInfo->ExceptionRecord->ExceptionAddress < (modInfo.lpBaseOfDll + modInfo.SizeOfImage)) - ) { - // ...this is the module we're looking for! - ipModule = hMods[i]; - break; - } +static PVOID hExceptionHandler; +static char *ExceptionHandlerBuffer; + + +LONG CALLBACK MakeCrashDump(PEXCEPTION_POINTERS ExceptionInfo) +{ + SYSTEMTIME SystemTime; + HANDLE hDumpFile; + DWORD Error; + char *BufPtr; + + /* + * Win32-specific functions will be used wherever possible, + * just in case the C stdlib-equivalents try to allocate + * memory. + * (The Win32-specific functions are generally just wrappers + * over NT system calls anyway.) + */ + if ((ExceptionInfo->ExceptionRecord->ExceptionCode >> 28) != 0xC) { + /* + * ExceptionCode is not a fatal exception (high 4b of + * ntstatus = 0xC) Not going to crash, let's not make + * a crash dump. + */ + return(EXCEPTION_CONTINUE_SEARCH); + } + + /* + * So, the program is about to crash. Oh no what do? + * Let's create a crash dump file as a debugging-aid. + * + * First, get the path to the executable. + */ + GetModuleFileName(NULL,ExceptionHandlerBuffer,ExceptionHandlerBufferSize); + if (GetLastError() != ERROR_SUCCESS) { + /* Could not get full path, create in current directory. */ + BufPtr = ExceptionHandlerBuffer; + } else { + /* + * Walk through the string backwards looking for the + * last backslash, so as to remove the "86Box.exe" + * filename from the string. + */ + BufPtr = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; + for (; BufPtr > ExceptionHandlerBuffer; BufPtr--) { + if (BufPtr[0] == '\\') { + /* Found backslash, terminate the string after it. */ + BufPtr[1] = 0; + break; } } + + BufPtr = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; + } - // Start to put the crash-dump string into the buffer. + /* + * What would a good filename be? + * + * It should contain the current date and time so as + * to be (hopefully!) unique. + */ + GetSystemTime(&SystemTime); + sprintf(CurrentBufferPointer, + "86box-%d%02d%02d-%02d-%02d-%02d-%03d.dmp", + SystemTime.wYear, + SystemTime.wMonth, + SystemTime.wDay, + SystemTime.wHour, + SystemTime.wMinute, + SystemTime.wSecond, + SystemTime.wMilliseconds); + + /* Now the filename is in the buffer, the file can be created. */ + hDumpFile = CreateFile( + ExceptionHandlerBuffer, // The filename of the file to open. + GENERIC_WRITE, // The permissions to request. + 0, // Make sure other processes can't + // touch the crash dump at all + // while it's open. + NULL, // Leave the security descriptor + // undefined, it doesn't matter. + OPEN_ALWAYS, // Opens the file if it exists, + // creates a new file if it doesn't. + FILE_ATTRIBUTE_NORMAL, // File attributes / etc don't matter. + NULL); // A template file is not being used. - sprintf(ExceptionHandlerBuffer, - "86Box version %s crashed on %d-%02d-%02d %02d:%02d:%02d.%03d\r\n\r\n" - "" - "Exception details:\r\n" - "Exception NTSTATUS code: 0x%08x\r\n" - "Occured at address: 0x%p", - emulator_version, SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay, SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds, - - ExceptionInfo->ExceptionRecord->ExceptionCode, - ExceptionInfo->ExceptionRecord->ExceptionAddress); - + /* Check to make sure the file was actually created. */ + if (hDumpFile == INVALID_HANDLE_VALUE) { + /* CreateFile() failed, so just do nothing more. */ + return(EXCEPTION_CONTINUE_SEARCH); + } - // If we found the module that the exception occured in, get the full path to the module the exception occured at and include it. - CurrentBufferPointer = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; - if (ipModule != 0) { - sprintf(CurrentBufferPointer," ["); - GetModuleFileName(ipModule,&CurrentBufferPointer[2],ExceptionHandlerBufferSize - strlen(ExceptionHandlerBuffer)); - if (GetLastError() == ERROR_SUCCESS) { - CurrentBufferPointer = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; - sprintf(CurrentBufferPointer,"]"); - CurrentBufferPointer += 1; + // Now the file is open, let's write the data we were passed out in a human-readable format. + + // Let's get the name of the module where the exception occured. + HMODULE hMods[1024]; + MODULEINFO modInfo; + HMODULE ipModule = 0; + DWORD cbNeeded; + + // Try to get a list of all loaded modules. + if (EnumProcessModules(GetCurrentProcess(), + hMods, sizeof(hMods), &cbNeeded)) { + // The list was obtained, walk through each of the modules. + for (DWORD i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) { + // For each module, get the module information + // (base address, size, entry point) + GetModuleInformation(GetCurrentProcess(), + hMods[i], &modInfo, sizeof(MODULEINFO)); + // If the exception address is located in the range of + // where this module is loaded... + if ( (ExceptionInfo->ExceptionRecord->ExceptionAddress >= modInfo.lpBaseOfDll) && + (ExceptionInfo->ExceptionRecord->ExceptionAddress < (modInfo.lpBaseOfDll + modInfo.SizeOfImage))) { + // ...this is the module we're looking for! + ipModule = hMods[i]; + break; } } + } - // Continue to create the crash-dump string. - sprintf(CurrentBufferPointer, - "\r\n" - "Number of parameters: %d\r\n" - "Exception parameters: ", - ExceptionInfo->ExceptionRecord->NumberParameters); - - // Add the exception parameters to the crash-dump string. - for (int i = 0; i < ExceptionInfo->ExceptionRecord->NumberParameters; i++) { - CurrentBufferPointer = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; - sprintf(CurrentBufferPointer,"0x%p ",ExceptionInfo->ExceptionRecord->ExceptionInformation[i]); + // Start to put the crash-dump string into the buffer. + sprintf(ExceptionHandlerBuffer, + "86Box version %s crashed on %d-%02d-%02d %02d:%02d:%02d.%03d\r\n\r\n" + "" + "Exception details:\r\n" + "Exception NTSTATUS code: 0x%08x\r\n" + "Occured at address: 0x%p", + emulator_version, + SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay, + SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, + SystemTime.wMilliseconds, + ExceptionInfo->ExceptionRecord->ExceptionCode, + ExceptionInfo->ExceptionRecord->ExceptionAddress); + + // If we found the module that the exception occured in, get the full path to the module the exception occured at and include it. + BufPtr = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; + if (ipModule != 0) { + sprintf(BufPtr," ["); + GetModuleFileName(ipModule, &BufPtr[2], + ExceptionHandlerBufferSize - strlen(ExceptionHandlerBuffer)); + if (GetLastError() == ERROR_SUCCESS) { + BufPtr = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; + sprintf(BufPtr,"]"); + BufPtr += 1; } + } - CurrentBufferPointer = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer) - 1]; + // Continue to create the crash-dump string. + sprintf(BufPtr, + "\r\n" + "Number of parameters: %d\r\n" + "Exception parameters: ", + ExceptionInfo->ExceptionRecord->NumberParameters); - PCONTEXT Registers = ExceptionInfo->ContextRecord; + // Add the exception parameters to the crash-dump string. + for (int i = 0; i < ExceptionInfo->ExceptionRecord->NumberParameters; i++) { + BufPtr = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer)]; + sprintf(BufPtr,"0x%p ", + ExceptionInfo->ExceptionRecord->ExceptionInformation[i]); + } + BufPtr = &ExceptionHandlerBuffer[strlen(ExceptionHandlerBuffer) - 1]; + + PCONTEXT Registers = ExceptionInfo->ContextRecord; - #if defined(__i386__) && !defined(__x86_64) - // This binary is being compiled for x86, include a register dump. - sprintf(CurrentBufferPointer, - "\r\n" - "Register dump:\r\n" - "eax=0x%08x ebx=0x%08x ecx=0x%08x edx=0x%08x ebp=0x%08x esp=0x%08x esi=0x%08x edi=0x%08x eip=0x%08x\r\n" - "\r\n", - Registers->Eax, Registers->Ebx, Registers->Ecx, Registers->Edx, Registers->Ebp, Registers->Esp, Registers->Esi, Registers->Edi, Registers->Eip); - #else - // Register dump is supported by no other architectures right now. MinGW headers seem to lack the x64 CONTEXT structure definition. - sprintf(CurrentBufferPointer,"\r\n"); - #endif +#if defined(__i386__) && !defined(__x86_64) + // This binary is being compiled for x86, include a register dump. + sprintf(BufPtr, + "\r\n" + "Register dump:\r\n" + "eax=0x%08x ebx=0x%08x ecx=0x%08x edx=0x%08x ebp=0x%08x esp=0x%08x esi=0x%08x edi=0x%08x eip=0x%08x\r\n" + "\r\n", + Registers->Eax, Registers->Ebx, Registers->Ecx, Registers->Edx, Registers->Ebp, Registers->Esp, Registers->Esi, Registers->Edi, Registers->Eip); +#else + // Register dump is supported by no other architectures right now. MinGW headers seem to lack the x64 CONTEXT structure definition. + sprintf(BufPtr,"\r\n"); +#endif - // The crash-dump string has been created, write it to disk. - WriteFile(hDumpFile, - ExceptionHandlerBuffer, - strlen(ExceptionHandlerBuffer), - NULL, - NULL); - - // Finally, close the file. - CloseHandle(hDumpFile); - - // And return, therefore causing the crash, but only after the crash dump has been created. - - return EXCEPTION_CONTINUE_SEARCH; + // The crash-dump string has been created, write it to disk. + WriteFile(hDumpFile, ExceptionHandlerBuffer, + strlen(ExceptionHandlerBuffer), NULL, NULL); + + // Finally, close the file. + CloseHandle(hDumpFile); + + // And return, therefore causing the crash, + // but only after the crash dump has been created. + return(EXCEPTION_CONTINUE_SEARCH); } -void InitCrashDump() { - // An exception handler should not allocate memory, so allocate 10kb for it to use if it gets called, an amount which should be more than enough. - ExceptionHandlerBuffer = malloc(ExceptionHandlerBufferSize); - // Register the exception handler. Zero first argument means this exception handler gets called last, therefore, crash dump is only made, when a crash is going to happen. - hExceptionHandler = AddVectoredExceptionHandler(0,MakeCrashDump); + +void InitCrashDump(void) +{ + /* + * An exception handler should not allocate memory, + * so allocate 10kb for it to use if it gets called, + * an amount which should be more than enough. + */ + ExceptionHandlerBuffer = malloc(ExceptionHandlerBufferSize); + + /* + * Register the exception handler. + * Zero first argument means this exception handler gets + * called last, therefore, crash dump is only made, when + * a crash is going to happen. + */ + hExceptionHandler = AddVectoredExceptionHandler(0, MakeCrashDump); } diff --git a/src/WIN/win_d3d-fs.h b/src/WIN/win_d3d-fs.h deleted file mode 100644 index 41ca32e21..000000000 --- a/src/WIN/win_d3d-fs.h +++ /dev/null @@ -1,13 +0,0 @@ -/* Copyright holders: Sarah Walker, Tenshi - see COPYING for more details -*/ -#ifdef __cplusplus -extern "C" { -#endif - int d3d_fs_init(HWND h); - void d3d_fs_close(); - void d3d_fs_reset(); - void d3d_fs_resize(int x, int y); -#ifdef __cplusplus -} -#endif diff --git a/src/WIN/win_d3d.cc b/src/WIN/win_d3d.cc index 258bcd4f8..ce2d9a3b5 100644 --- a/src/WIN/win_d3d.cc +++ b/src/WIN/win_d3d.cc @@ -2,14 +2,9 @@ see COPYING for more details */ #include -#define UNICODE -#define BITMAP WINDOWS_BITMAP -#include -#undef BITMAP -#include +#include "../video/video.h" #include "win.h" #include "win_d3d.h" -#include "../video/video.h" #include "win_cgapal.h" #include "resource.h" diff --git a/src/WIN/win_d3d.h b/src/WIN/win_d3d.h index 7210d454b..5994a87b1 100644 --- a/src/WIN/win_d3d.h +++ b/src/WIN/win_d3d.h @@ -1,13 +1,32 @@ /* Copyright holders: Sarah Walker, Tenshi see COPYING for more details */ +#ifndef WIN_D3D_H +# define WIN_D3D_H +# define UNICODE +# define BITMAP WINDOWS_BITMAP +# include +# include +# undef BITMAP + + #ifdef __cplusplus extern "C" { #endif - int d3d_init(HWND h); - void d3d_close(); - void d3d_reset(); - void d3d_resize(int x, int y); + +extern int d3d_init(HWND h); +extern void d3d_close(void); +extern void d3d_reset(void); +extern void d3d_resize(int x, int y); + +extern int d3d_fs_init(HWND h); +extern void d3d_fs_close(void); +extern void d3d_fs_reset(void); +extern void d3d_fs_resize(int x, int y); + #ifdef __cplusplus } #endif + + +#endif /*WIN_D3D_H*/ diff --git a/src/WIN/win_d3d-fs.cc b/src/WIN/win_d3d_fs.cc similarity index 99% rename from src/WIN/win_d3d-fs.cc rename to src/WIN/win_d3d_fs.cc index 4e6a367cb..9e410ec3b 100644 --- a/src/WIN/win_d3d-fs.cc +++ b/src/WIN/win_d3d_fs.cc @@ -3,15 +3,10 @@ */ #include #include -#define UNICODE -#define BITMAP WINDOWS_BITMAP -#include -#undef BITMAP -#include #include "../86box.h" #include "../video/video.h" #include "win.h" -#include "win_d3d-fs.h" +#include "win_d3d.h" #include "win_cgapal.h" #include "resource.h" @@ -110,6 +105,7 @@ static CUSTOMVERTEX d3d_verts[] = {2048.0f, 2048.0f, 1.0f, 1.0f, 1.0f, 1.0f}, }; + void cgapal_rebuild(void) { int c; @@ -133,6 +129,7 @@ void cgapal_rebuild(void) } } + int d3d_fs_init(HWND h) { HRESULT hr; @@ -197,6 +194,7 @@ int d3d_fs_init(HWND h) return 1; } + static void d3d_fs_close_objects(void) { if (d3dTexture) @@ -211,6 +209,7 @@ static void d3d_fs_close_objects(void) } } + static void d3d_fs_init_objects(void) { D3DLOCKED_RECT dr; @@ -248,6 +247,7 @@ static void d3d_fs_init_objects(void) d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); } + /*void d3d_resize(int x, int y) { HRESULT hr; @@ -258,6 +258,7 @@ static void d3d_fs_init_objects(void) d3d_reset(); }*/ + void d3d_fs_reset(void) { HRESULT hr; @@ -293,6 +294,7 @@ void d3d_fs_reset(void) device_force_redraw(); } + void d3d_fs_close(void) { if (d3dTexture) @@ -318,6 +320,7 @@ void d3d_fs_close(void) DestroyWindow(d3d_device_window); } + static void d3d_fs_size(RECT window_rect, double *l, double *t, double *r, double *b, int w, int h) { int ratio_w, ratio_h; @@ -368,6 +371,7 @@ static void d3d_fs_size(RECT window_rect, double *l, double *t, double *r, doubl } } + static void d3d_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) { HRESULT hr = D3D_OK; @@ -466,6 +470,7 @@ static void d3d_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h) PostMessage(ghwnd, WM_RESETD3D, 0, 0); } + static void d3d_fs_blit_memtoscreen_8(int x, int y, int w, int h) { HRESULT hr = D3D_OK; @@ -573,6 +578,7 @@ static void d3d_fs_blit_memtoscreen_8(int x, int y, int w, int h) PostMessage(ghwnd, WM_RESETD3D, 0, 0); } + void d3d_fs_take_screenshot(wchar_t *fn) { LPDIRECT3DSURFACE9 d3dSurface = NULL; diff --git a/src/WIN/win_ddraw-fs.h b/src/WIN/win_ddraw-fs.h deleted file mode 100644 index 048c9c160..000000000 --- a/src/WIN/win_ddraw-fs.h +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright holders: Sarah Walker, Tenshi - see COPYING for more details -*/ -#ifdef __cplusplus -extern "C" { -#endif - int ddraw_fs_init(HWND h); - void ddraw_fs_close(); -#ifdef __cplusplus -} -#endif diff --git a/src/WIN/win_ddraw-screenshot.h b/src/WIN/win_ddraw-screenshot.h deleted file mode 100644 index 4739174a1..000000000 --- a/src/WIN/win_ddraw-screenshot.h +++ /dev/null @@ -1,4 +0,0 @@ -/* Copyright holders: Tenshi - see COPYING for more details -*/ -void ddraw_common_take_screenshot(wchar_t *fn, IDirectDrawSurface7 *pDDSurface); diff --git a/src/WIN/win_ddraw.cc b/src/WIN/win_ddraw.cc index af329eb29..dd985baf8 100644 --- a/src/WIN/win_ddraw.cc +++ b/src/WIN/win_ddraw.cc @@ -3,13 +3,8 @@ */ #include #include -#define UNICODE -#define BITMAP WINDOWS_BITMAP -#include -#undef BITMAP #include "../video/video.h" #include "win_ddraw.h" -#include "win_ddraw-screenshot.h" #include "win_cgapal.h" diff --git a/src/WIN/win_ddraw.h b/src/WIN/win_ddraw.h index a4044899d..5090aa0cc 100644 --- a/src/WIN/win_ddraw.h +++ b/src/WIN/win_ddraw.h @@ -1,12 +1,30 @@ /* Copyright holders: Sarah Walker, Tenshi see COPYING for more details */ +#ifndef WIN_DDRAW_H +# define WIN_DDRAW_H +# define UNICODE +# define BITMAP WINDOWS_BITMAP +# include +# undef BITMAP + + #ifdef __cplusplus extern "C" { #endif - int ddraw_init(HWND h); - void ddraw_close(); + +extern int ddraw_init(HWND h); +extern void ddraw_close(void); + +extern int ddraw_fs_init(HWND h); +extern void ddraw_fs_close(void); + +extern void ddraw_common_take_screenshot(wchar_t *fn, + IDirectDrawSurface7 *pDDSurface); + #ifdef __cplusplus } #endif + +#endif /*WIN_DDRAW_H*/ diff --git a/src/WIN/win_ddraw-fs.cc b/src/WIN/win_ddraw_fs.cc similarity index 97% rename from src/WIN/win_ddraw-fs.cc rename to src/WIN/win_ddraw_fs.cc index 42fd984ed..88649f7e9 100644 --- a/src/WIN/win_ddraw-fs.cc +++ b/src/WIN/win_ddraw_fs.cc @@ -2,16 +2,22 @@ see COPYING for more details */ #include -#define UNICODE -#define BITMAP WINDOWS_BITMAP -#include -#undef BITMAP #include "../video/video.h" -#include "win_ddraw-fs.h" -#include "win_ddraw-screenshot.h" +#include "win_ddraw.h" #include "win_cgapal.h" +static LPDIRECTDRAW lpdd = NULL; +static LPDIRECTDRAW7 lpdd7 = NULL; +static LPDIRECTDRAWSURFACE7 lpdds_pri = NULL; +static LPDIRECTDRAWSURFACE7 lpdds_back = NULL; +static LPDIRECTDRAWSURFACE7 lpdds_back2 = NULL; +static LPDIRECTDRAWCLIPPER lpdd_clipper = NULL; +static DDSURFACEDESC2 ddsd; +static HWND ddraw_hwnd; +static int ddraw_w, ddraw_h; + + extern "C" void fatal(const char *format, ...); extern "C" void pclog(const char *format, ...); @@ -22,19 +28,9 @@ extern "C" void ddraw_fs_close(void); extern "C" void video_blit_complete(void); -static void ddraw_fs_blit_memtoscreen(int x, int y, int y1, int y2, int w, int h); -static void ddraw_fs_blit_memtoscreen_8(int x, int y, int w, int h); +static void ddraw_fs_blit_memtoscreen(int, int, int, int, int, int); +static void ddraw_fs_blit_memtoscreen_8(int, int, int, int); -static LPDIRECTDRAW lpdd = NULL; -static LPDIRECTDRAW7 lpdd7 = NULL; -static LPDIRECTDRAWSURFACE7 lpdds_pri = NULL; -static LPDIRECTDRAWSURFACE7 lpdds_back = NULL; -static LPDIRECTDRAWSURFACE7 lpdds_back2 = NULL; -static LPDIRECTDRAWCLIPPER lpdd_clipper = NULL; -static DDSURFACEDESC2 ddsd; - -static HWND ddraw_hwnd; -static int ddraw_w, ddraw_h; int ddraw_fs_init(HWND h) { diff --git a/src/WIN/win_ddraw-screenshot.cc b/src/WIN/win_ddraw_screenshot.cc similarity index 94% rename from src/WIN/win_ddraw-screenshot.cc rename to src/WIN/win_ddraw_screenshot.cc index bb3cb6660..717b94348 100644 --- a/src/WIN/win_ddraw-screenshot.cc +++ b/src/WIN/win_ddraw_screenshot.cc @@ -5,25 +5,20 @@ #include #define UNICODE #define BITMAP WINDOWS_BITMAP -#include +#include #undef BITMAP #include "../video/video.h" #include "win.h" -#include "win_ddraw-screenshot.h" +#include "win_ddraw.h" #include "win_language.h" -extern "C" void fatal(const char *format, ...); +HBITMAP hbitmap; +int xs, ys, ys2; + + extern "C" void pclog(const char *format, ...); -extern "C" void device_force_redraw(void); - -extern "C" void ddraw_init(HWND h); -extern "C" void ddraw_close(void); - -HBITMAP hbitmap; - -int xs, ys, ys2; void CopySurface(IDirectDrawSurface7 *pDDSurface) { @@ -58,6 +53,7 @@ void CopySurface(IDirectDrawSurface7 *pDDSurface) return ; } + void DoubleLines(uint8_t *dst, uint8_t *src) { int i = 0; diff --git a/src/WIN/win_deviceconfig.c b/src/WIN/win_deviceconfig.c index 457a38f75..c64dd3af7 100644 --- a/src/WIN/win_deviceconfig.c +++ b/src/WIN/win_deviceconfig.c @@ -1,19 +1,18 @@ /* Copyright holders: Sarah Walker see COPYING for more details */ -#define BITMAP WINDOWS_BITMAP -#include -#include -#undef BITMAP - #include "../ibm.h" #include "../config.h" #include "../device.h" #include "resource.h" +#define NO_UNICODE /*FIXME: not Unicode? */ #include "win.h" +#include + static device_t *config_device; + static BOOL CALLBACK deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND h; diff --git a/src/config.c b/src/config.c index 04557b544..26e65cfe6 100644 --- a/src/config.c +++ b/src/config.c @@ -6,8 +6,6 @@ #include #include #include -#include - #include "cdrom.h" #include "config.h" #include "device.h" @@ -30,15 +28,8 @@ #include "sound/snd_opl.h" #include "sound/sound.h" #include "video/video.h" - -#ifndef __unix -#define UNICODE -#define BITMAP WINDOWS_BITMAP -#include -#undef BITMAP #include "win.h" #include "win_language.h" -#endif wchar_t config_file_default[256]; diff --git a/src/net_ne2000.c b/src/net_ne2000.c index e0435367c..88b97cf40 100644 --- a/src/net_ne2000.c +++ b/src/net_ne2000.c @@ -11,7 +11,7 @@ * NOTE: Its still a mess, but we're getting there. The file will * also implement an NE1000 for 8-bit ISA systems. * - * Version: @(#)net_ne2000.c 1.0.5 2017/05/21 + * Version: @(#)net_ne2000.c 1.0.6 2017/05/23 * * Authors: Fred N. van Kempen, * Peter Grehan, grehan@iprg.nokia.com> @@ -37,8 +37,9 @@ #include "network.h" #include "net_ne2000.h" #include "bswap.h" + #ifdef WALTJE -# define ENABLE_NE2000_LOG 1 +# define ENABLE_NE2000_LOG 2 #endif @@ -202,7 +203,7 @@ typedef struct { uint8_t mem[NE2K_MEMSIZ]; /* on-chip packet memory */ int board; - int is_rtl8029as; + int is_pci; char name[32]; uint32_t base_address; int base_irq; @@ -210,11 +211,10 @@ typedef struct { bios_size, bios_mask; bar_t pci_bar[2]; - int disable_netbios; + uint8_t pci_regs[256]; int tx_timer_index; int tx_timer_active; uint8_t maclocal[6]; /* configured MAC (local) address */ - uint8_t pci_regs[256]; uint8_t eeprom[128]; /* for RTL8029AS */ rom_t bios_rom; } nic_t; @@ -234,10 +234,10 @@ nelog(int lvl, const char *fmt, ...) va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); + fflush(stdout); } #endif } -#define pclog nelog /* reset - restore state to power-up, cancelling all i/o */ @@ -247,7 +247,7 @@ nic_reset(void *priv, int reset) nic_t *dev = (nic_t *)priv; int i; - pclog(1, "%s: reset\n", dev->name); + nelog(1, "%s: reset\n", dev->name); /* Initialize the MAC address area by doubling the physical address */ dev->macaddr[0] = dev->physaddr[0]; @@ -264,9 +264,8 @@ nic_reset(void *priv, int reset) dev->macaddr[11] = dev->physaddr[5]; /* ne2k signature */ - for (i = 12; i < 32; i++) { + for (i=12; i<32; i++) dev->macaddr[i] = 0x57; - } /* Zero out registers and memory */ memset(&dev->CR, 0x00, sizeof(dev->CR) ); @@ -324,7 +323,7 @@ chipmem_read(nic_t *dev, uint32_t addr, unsigned int len) uint32_t retval = 0; if ((len == 2) && (addr & 0x1)) { - pclog(1, "%s: unaligned chipmem word read\n", dev->name); + nelog(3, "%s: unaligned chipmem word read\n", dev->name); } /* ROM'd MAC address */ @@ -352,9 +351,9 @@ chipmem_read(nic_t *dev, uint32_t addr, unsigned int len) return(retval); } - pclog(1, "%s: out-of-bounds chipmem read, %04X\n", dev->name, addr); + nelog(3, "%s: out-of-bounds chipmem read, %04X\n", dev->name, addr); - if (dev->is_rtl8029as) { + if (dev->is_pci) { return(0xff); } else { switch(len) { @@ -373,7 +372,7 @@ static void chipmem_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len) { if ((len == 2) && (addr & 0x1)) { - pclog(1, "%s: unaligned chipmem word write\n", dev->name); + nelog(3, "%s: unaligned chipmem word write\n", dev->name); } if ((addr >= NE2K_MEMSTART) && (addr < NE2K_MEMEND)) { @@ -386,7 +385,7 @@ chipmem_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len) dev->mem[addr-NE2K_MEMSTART+3] = val >> 24; } } else { - pclog(1, "%s: out-of-bounds chipmem write, %04X\n", dev->name, addr); + nelog(3, "%s: out-of-bounds chipmem write, %04X\n", dev->name, addr); } } @@ -411,11 +410,11 @@ asic_read(nic_t *dev, uint32_t off, unsigned int len) and the source-address and length registers must have been initialised. */ if (len > dev->remote_bytes) { - pclog(1, "%s: DMA read underrun iolen=%d remote_bytes=%d\n", + nelog(3, "%s: DMA read underrun iolen=%d remote_bytes=%d\n", dev->name, len, dev->remote_bytes); } - pclog(2, "%s: DMA read: addr=%4x remote_bytes=%d\n", + nelog(3, "%s: DMA read: addr=%4x remote_bytes=%d\n", dev->name, dev->remote_dma,dev->remote_bytes); retval = chipmem_read(dev, dev->remote_dma, len); @@ -457,7 +456,7 @@ asic_read(nic_t *dev, uint32_t off, unsigned int len) break; default: - pclog(1, "%s: ASIC read invalid address %04x\n", + nelog(3, "%s: ASIC read invalid address %04x\n", dev->name, (unsigned)off); break; } @@ -469,17 +468,17 @@ asic_read(nic_t *dev, uint32_t off, unsigned int len) static void asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) { - pclog(2, "%s: asic write addr=0x%02x, value=0x%04x\n", + nelog(3, "%s: asic write addr=0x%02x, value=0x%04x\n", dev->name, (unsigned)off, (unsigned) val); switch(off) { case 0x00: /* Data register - see asic_read for a description */ if ((len > 1) && (dev->DCR.wdsize == 0)) { - pclog(2, "%s: DMA write length %d on byte mode operation\n", + nelog(3, "%s: DMA write length %d on byte mode operation\n", dev->name, len); break; } if (dev->remote_bytes == 0) { - pclog(2, "%s: DMA write, byte count 0\n", dev->name); + nelog(3, "%s: DMA write, byte count 0\n", dev->name); } chipmem_write(dev, dev->remote_dma, val, len); @@ -517,7 +516,7 @@ asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) break; default: /* this is invalid, but happens under win95 device detection */ - pclog(1, "%s: ASIC write invalid address %04x, ignoring\n", + nelog(3, "%s: ASIC write invalid address %04x, ignoring\n", dev->name, (unsigned)off); break; } @@ -533,7 +532,7 @@ page0_read(nic_t *dev, uint32_t off, unsigned int len) if (len > 1) { /* encountered with win98 hardware probe */ - pclog(1, "%s: bad length! Page0 read from register 0x%02x, len=%u\n", + nelog(3, "%s: bad length! Page0 read from register 0x%02x, len=%u\n", dev->name, off, len); return(retval); } @@ -567,7 +566,7 @@ page0_read(nic_t *dev, uint32_t off, unsigned int len) case 0x06: /* FIFO */ /* reading FIFO is only valid in loopback mode */ - pclog(1, "%s: reading FIFO not supported yet\n", dev->name); + nelog(3, "%s: reading FIFO not supported yet\n", dev->name); retval = dev->fifo; break; @@ -591,19 +590,19 @@ page0_read(nic_t *dev, uint32_t off, unsigned int len) break; case 0x0a: /* reserved / RTL8029ID0 */ - if (dev->is_rtl8029as) { + if (dev->is_pci) { retval = 0x50; } else { - pclog(1, "%s: reserved Page0 read - 0x0a\n", dev->name); + nelog(3, "%s: reserved Page0 read - 0x0a\n", dev->name); retval = 0xff; } break; case 0x0b: /* reserved / RTL8029ID1 */ - if (dev->is_rtl8029as) { + if (dev->is_pci) { retval = 0x43; } else { - pclog(1, "%s: reserved Page0 read - 0x0b\n", dev->name); + nelog(3, "%s: reserved Page0 read - 0x0b\n", dev->name); retval = 0xff; } break; @@ -632,12 +631,12 @@ page0_read(nic_t *dev, uint32_t off, unsigned int len) break; default: - pclog(1, "%s: Page0 register 0x%02x out of range\n", + nelog(3, "%s: Page0 register 0x%02x out of range\n", dev->name, off); break; } - pclog(2, "%s: Page0 read from register 0x%02x, value=0x%02x\n", + nelog(3, "%s: Page0 read from register 0x%02x, value=0x%02x\n", dev->name, off, retval); return(retval); @@ -659,7 +658,7 @@ page0_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) return; } - pclog(2, "%s: Page0 write to register 0x%02x, value=0x%02x\n", + nelog(3, "%s: Page0 write to register 0x%02x, value=0x%02x\n", dev->name, off, val); switch(off) { @@ -749,7 +748,7 @@ page0_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) case 0x0c: /* RCR */ /* Check if the reserved bits are set */ if (val & 0xc0) { - pclog(1, "%s: RCR write, reserved bits set\n", + nelog(3, "%s: RCR write, reserved bits set\n", dev->name); } @@ -762,30 +761,30 @@ page0_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) dev->RCR.monitor = ((val & 0x20) == 0x20); /* Monitor bit is a little suspicious... */ - if (val & 0x20) pclog(1, "%s: RCR write, monitor bit set!\n", + if (val & 0x20) nelog(3, "%s: RCR write, monitor bit set!\n", dev->name); break; case 0x0d: /* TCR */ /* Check reserved bits */ - if (val & 0xe0) pclog(1, "%s: TCR write, reserved bits set\n", + if (val & 0xe0) nelog(3, "%s: TCR write, reserved bits set\n", dev->name); /* Test loop mode (not supported) */ if (val & 0x06) { dev->TCR.loop_cntl = (val & 0x6) >> 1; - pclog(1, "%s: TCR write, loop mode %d not supported\n", + nelog(3, "%s: TCR write, loop mode %d not supported\n", dev->name, dev->TCR.loop_cntl); } else { dev->TCR.loop_cntl = 0; } /* Inhibit-CRC not supported. */ - if (val & 0x01) pclog(1, + if (val & 0x01) nelog(3, "%s: TCR write, inhibit-CRC not supported\n",dev->name); /* Auto-transmit disable very suspicious */ - if (val & 0x08) pclog(1, + if (val & 0x08) nelog(3, "%s: TCR write, auto transmit disable not supported\n", dev->name); @@ -795,16 +794,16 @@ page0_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) case 0x0e: /* DCR */ /* the loopback mode is not suppported yet */ - if (! (val & 0x08)) pclog(1, + if (! (val & 0x08)) nelog(3, "%s: DCR write, loopback mode selected\n", dev->name); /* It is questionable to set longaddr and auto_rx, since * they are not supported on the NE2000. Print a warning * and continue. */ if (val & 0x04) - pclog(1, "%s: DCR write - LAS set ???\n", dev->name); + nelog(3, "%s: DCR write - LAS set ???\n", dev->name); if (val & 0x10) - pclog(1, "%s: DCR write - AR set ???\n", dev->name); + nelog(3, "%s: DCR write - AR set ???\n", dev->name); /* Set other values. */ dev->DCR.wdsize = ((val & 0x01) == 0x01); @@ -818,7 +817,7 @@ page0_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) case 0x0f: /* IMR */ /* Check for reserved bit */ if (val & 0x80) - pclog(1, "%s: IMR write, reserved bit set\n",dev->name); + nelog(3, "%s: IMR write, reserved bit set\n",dev->name); /* Set other values */ dev->IMR.rx_inte = ((val & 0x01) == 0x01); @@ -843,7 +842,7 @@ page0_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) break; default: - pclog(1, "%s: Page0 write, bad register 0x%02x\n", + nelog(3, "%s: Page0 write, bad register 0x%02x\n", dev->name, off); break; } @@ -855,7 +854,7 @@ page0_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) static uint32_t page1_read(nic_t *dev, uint32_t off, unsigned int len) { - pclog(2, "%s: Page1 read from register 0x%02x, len=%u\n", + nelog(3, "%s: Page1 read from register 0x%02x, len=%u\n", dev->name, off, len); switch(off) { @@ -868,7 +867,7 @@ page1_read(nic_t *dev, uint32_t off, unsigned int len) return(dev->physaddr[off - 1]); case 0x07: /* CURR */ - pclog(2, "%s: returning current page: 0x%02x\n", + nelog(3, "%s: returning current page: 0x%02x\n", dev->name, (dev->curr_page)); return(dev->curr_page); @@ -883,7 +882,7 @@ page1_read(nic_t *dev, uint32_t off, unsigned int len) return(dev->mchash[off - 8]); default: - pclog(1, "%s: Page1 read register 0x%02x out of range\n", + nelog(3, "%s: Page1 read register 0x%02x out of range\n", dev->name, off); return(0); } @@ -893,7 +892,7 @@ page1_read(nic_t *dev, uint32_t off, unsigned int len) static void page1_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) { - pclog(2, "%s: Page1 write to register 0x%02x, len=%u, value=0x%04x\n", + nelog(3, "%s: Page1 write to register 0x%02x, len=%u, value=0x%04x\n", dev->name, off, len, val); switch(off) { @@ -904,7 +903,7 @@ page1_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) case 0x05: case 0x06: dev->physaddr[off - 1] = val; - if (off == 6) pclog(1, + if (off == 6) nelog(3, "%s: physical address set to %02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, dev->physaddr[0], dev->physaddr[1], @@ -928,7 +927,7 @@ page1_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) break; default: - pclog(1, "%s: Page1 write register 0x%02x out of range\n", + nelog(3, "%s: Page1 write register 0x%02x out of range\n", dev->name, off); break; } @@ -940,7 +939,7 @@ page1_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) static uint32_t page2_read(nic_t *dev, uint32_t off, unsigned int len) { - pclog(2, "%s: Page2 read from register 0x%02x, len=%u\n", + nelog(3, "%s: Page2 read from register 0x%02x, len=%u\n", dev->name, off, len); switch(off) { @@ -969,7 +968,7 @@ page2_read(nic_t *dev, uint32_t off, unsigned int len) case 0x09: case 0x0a: case 0x0b: - pclog(1, "%s: reserved Page2 read - register 0x%02x\n", + nelog(3, "%s: reserved Page2 read - register 0x%02x\n", dev->name, off); return(0xff); @@ -1005,7 +1004,7 @@ page2_read(nic_t *dev, uint32_t off, unsigned int len) (dev->IMR.rx_inte)); default: - pclog(1, "%s: Page2 register 0x%02x out of range\n", + nelog(3, "%s: Page2 register 0x%02x out of range\n", dev->name, off); break; } @@ -1020,7 +1019,7 @@ page2_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) /* Maybe all writes here should be BX_PANIC()'d, since they affect internal operation, but let them through for now and print a warning. */ - pclog(2, "%s: Page2 write to register 0x%02x, len=%u, value=0x%04x\n", + nelog(3, "%s: Page2 write to register 0x%02x, len=%u, value=0x%04x\n", dev->name, off, len, val); switch(off) { case 0x01: /* CLDA0 */ @@ -1040,7 +1039,7 @@ page2_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) break; case 0x04: - pclog(1, "page 2 write to reserved register 0x04\n"); + nelog(3, "page 2 write to reserved register 0x04\n"); break; case 0x05: /* Local Next-packet pointer */ @@ -1067,12 +1066,12 @@ page2_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) case 0x0d: case 0x0e: case 0x0f: - pclog(1, "%s: Page2 write to reserved register 0x%02x\n", + nelog(3, "%s: Page2 write to reserved register 0x%02x\n", dev->name, off); break; default: - pclog(1, "%s: Page2 write, illegal register 0x%02x\n", + nelog(3, "%s: Page2 write, illegal register 0x%02x\n", dev->name, off); break; } @@ -1083,7 +1082,7 @@ page2_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) static uint32_t page3_read(nic_t *dev, uint32_t off, unsigned int len) { - if (dev->is_rtl8029as) switch(off) { + if (dev->is_pci) switch(off) { case 0x3: /* CONFIG0 */ return(0x00); @@ -1097,7 +1096,7 @@ page3_read(nic_t *dev, uint32_t off, unsigned int len) break; } - pclog(1, "%s: Page3 read register 0x%02x attempted\n", dev->name, off); + nelog(3, "%s: Page3 read register 0x%02x attempted\n", dev->name, off); return(0x00); } @@ -1105,7 +1104,7 @@ page3_read(nic_t *dev, uint32_t off, unsigned int len) static void page3_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) { - pclog(1, "%s: Page3 write register 0x%02x attempted\n", dev->name, off); + nelog(3, "%s: Page3 write register 0x%02x attempted\n", dev->name, off); } @@ -1121,7 +1120,7 @@ read_cr(nic_t *dev) (dev->CR.tx_packet << 2) | (dev->CR.start << 1) | (dev->CR.stop)); - pclog(2, "%s: read CR returns 0x%02x\n", dev->name, retval); + nelog(3, "%s: read CR returns 0x%02x\n", dev->name, retval); return(retval); } @@ -1130,11 +1129,11 @@ read_cr(nic_t *dev) static void write_cr(nic_t *dev, uint32_t val) { - pclog(2, "%s: wrote 0x%02x to CR\n", dev->name, val); + nelog(3, "%s: wrote 0x%02x to CR\n", dev->name, val); /* Validate remote-DMA */ if ((val & 0x38) == 0x00) { - pclog(2, "%s: CR write - invalid rDMA value 0\n", dev->name); + nelog(3, "%s: CR write - invalid rDMA value 0\n", dev->name); val |= 0x20; /* dma_cmd == 4 is a safe default */ } @@ -1150,9 +1149,8 @@ write_cr(nic_t *dev, uint32_t val) /* If start command issued, the RST bit in the ISR */ /* must be cleared */ - if ((val & 0x02) && !dev->CR.start) { + if ((val & 0x02) && !dev->CR.start) dev->ISR.reset = 0; - } dev->CR.start = ((val & 0x02) == 0x02); dev->CR.pgsel = (val & 0xc0) >> 6; @@ -1162,14 +1160,14 @@ write_cr(nic_t *dev, uint32_t val) /* Set up DMA read from receive ring */ dev->remote_start = dev->remote_dma = dev->bound_ptr * 256; dev->remote_bytes = (uint16_t) chipmem_read(dev, dev->bound_ptr * 256 + 2, 2); - pclog(2, "%s: sending buffer #x%x length %d\n", + nelog(3, "%s: sending buffer #x%x length %d\n", dev->name, dev->remote_start, dev->remote_bytes); } /* Check for start-tx */ if ((val & 0x04) && dev->TCR.loop_cntl) { if (dev->TCR.loop_cntl != 1) { - pclog(1, "%s: loop mode %d not supported\n", + nelog(3, "%s: loop mode %d not supported\n", dev->name, dev->TCR.loop_cntl); } else { nic_rx(dev, @@ -1177,15 +1175,15 @@ write_cr(nic_t *dev, uint32_t val) dev->tx_bytes); } } else if (val & 0x04) { - if (dev->CR.stop || (!dev->CR.start && !dev->is_rtl8029as)) { + if (dev->CR.stop || (!dev->CR.start && !dev->is_pci)) { if (dev->tx_bytes == 0) /* njh@bandsman.co.uk */ { return; /* Solaris9 probe */ } - pclog(1, "%s: CR write - tx start, dev in reset\n", dev->name); + nelog(3, "%s: CR write - tx start, dev in reset\n", dev->name); } if (dev->tx_bytes == 0) - pclog(1, "%s: CR write - tx start, tx bytes == 0\n", dev->name); + nelog(3, "%s: CR write - tx start, tx bytes == 0\n", dev->name); /* Send the packet to the system driver */ dev->CR.tx_packet = 1; @@ -1194,7 +1192,7 @@ write_cr(nic_t *dev, uint32_t val) /* some more debug */ if (dev->tx_timer_active) - pclog(1, "%s: CR write, tx timer still active\n", dev->name); + nelog(3, "%s: CR write, tx timer still active\n", dev->name); nic_tx(dev, val); } @@ -1206,9 +1204,8 @@ write_cr(nic_t *dev, uint32_t val) dev->ISR.rdma_done = 1; if (dev->IMR.rdma_inte) { picint(1 << dev->base_irq); - if (! dev->is_rtl8029as) { + if (! dev->is_pci) picintc(1 << dev->base_irq); - } } } } @@ -1220,7 +1217,7 @@ nic_read(nic_t *dev, uint32_t addr, unsigned len) uint32_t retval = 0; int off = addr - dev->base_address; - pclog(2, "%s: read addr %x, len %d\n", dev->name, addr, len); + nelog(3, "%s: read addr %x, len %d\n", dev->name, addr, len); if (off >= 0x10) { retval = asic_read(dev, off - 0x10, len); @@ -1244,7 +1241,7 @@ nic_read(nic_t *dev, uint32_t addr, unsigned len) break; default: - pclog(1, "%s: unknown value of pgsel in read - %d\n", + nelog(3, "%s: unknown value of pgsel in read - %d\n", dev->name, dev->CR.pgsel); break; } @@ -1284,7 +1281,7 @@ nic_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len) { int off = addr - dev->base_address; - pclog(2, "%s: write addr %x, value %x len %d\n", dev->name, addr, val, len); + nelog(3, "%s: write addr %x, value %x len %d\n", dev->name, addr, val, len); /* The high 16 bytes of i/o space are for the ne2000 asic - the low 16 bytes are for the DS8390, with the current @@ -1312,7 +1309,7 @@ nic_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len) break; default: - pclog(1, "%s: unknown value of pgsel in write - %d\n", + nelog(3, "%s: unknown value of pgsel in write - %d\n", dev->name, dev->CR.pgsel); break; } @@ -1348,7 +1345,7 @@ nic_writel(uint16_t addr, uint32_t val, void *priv) static void nic_ioset(nic_t *dev, uint16_t addr) { - if (dev->is_rtl8029as) { + if (dev->is_pci) { io_sethandler(addr, 16, nic_readb, nic_readw, nic_readl, nic_writeb, nic_writew, nic_writel, dev); @@ -1375,7 +1372,7 @@ nic_ioset(nic_t *dev, uint16_t addr) static void nic_ioremove(nic_t *dev, int16_t addr) { - if (dev->is_rtl8029as) { + if (dev->is_pci) { io_removehandler(addr, 16, nic_readb, nic_readw, nic_readl, nic_writeb, nic_writew, nic_writel, dev); @@ -1407,13 +1404,14 @@ nic_update_bios(nic_t *dev) reg_bios_enable = 1; /* PCI BIOS stuff, just enable_disable. */ - if (!dev->disable_netbios && reg_bios_enable) { + if ((dev->bios_addr > 0) && reg_bios_enable) { mem_mapping_enable(&dev->bios_rom.mapping); - mem_mapping_set_addr(&dev->bios_rom.mapping, dev->bios_addr, 0x10000); - pclog(1, "%s: BIOS now at: %06X\n", dev->name, dev->bios_addr); + mem_mapping_set_addr(&dev->bios_rom.mapping, + dev->bios_addr, dev->bios_size); + nelog(1, "%s: BIOS now at: %06X\n", dev->name, dev->bios_addr); } else { mem_mapping_disable(&dev->bios_rom.mapping); - if (dev->is_rtl8029as) + if (dev->is_pci) dev->pci_bar[1].addr = 0; } } @@ -1517,7 +1515,7 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) dev->base_address = dev->pci_bar[0].addr & 0xff00; /* Log the new base. */ - pclog(1, "%s: PCI: new I/O base is %04X\n", + nelog(1, "%s: PCI: new I/O base is %04X\n", dev->name, dev->base_address); /* We're done, so get out of the here. */ if (val & PCI_COMMAND_IO) @@ -1527,8 +1525,8 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) case 0x30: case 0x31: case 0x32: case 0x33: dev->pci_bar[1].addr_regs[addr & 3] = val; dev->pci_bar[1].addr_regs[1] &= dev->bios_mask; - dev->bios_addr = dev->pci_bar[1].addr & 0xffffe000; dev->pci_bar[1].addr &= 0xffffe000; + dev->bios_addr = dev->pci_bar[1].addr; dev->pci_bar[1].addr |= 0x1801; nic_update_bios(dev); return; @@ -1540,7 +1538,7 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) case 0x3C: dev->pci_regs[addr] = val; if (val != 0xFF) { - pclog(1, "%s: IRQ now: %i\n", dev->name, val); + nelog(1, "%s: IRQ now: %i\n", dev->name, val); dev->base_irq = irq; } return; @@ -1607,28 +1605,25 @@ nic_rx(void *priv, uint8_t *buf, int io_len) { static uint8_t bcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; nic_t *dev = (nic_t *)priv; - int pages; - int avail; - int idx; - int nextpage; uint8_t pkthdr[4]; - uint8_t *pktbuf = (uint8_t *) buf; uint8_t *startptr; - uint32_t mac_cmp32[2]; - uint16_t mac_cmp16[2]; + int pages, avail; + int idx, nextpage; + int endbytes; if (io_len != 60) - pclog(2, "%s: rx_frame with length %d\n", dev->name, io_len); + nelog(2, "%s: rx_frame with length %d\n", dev->name, io_len); - if ((dev->CR.stop != 0) || (dev->page_start == 0)) return; + if ((dev->CR.stop != 0) || (dev->page_start == 0)) return; /* Add the pkt header + CRC to the length, and work out how many 256-byte pages the frame would occupy */ - pages = (io_len + 4 + 4 + 255)/256; + pages = (io_len + sizeof(pkthdr) + sizeof(uint32_t) + 255)/256; if (dev->curr_page < dev->bound_ptr) { avail = dev->bound_ptr - dev->curr_page; } else { - avail = (dev->page_stop - dev->page_start) - (dev->curr_page - dev->bound_ptr); + avail = (dev->page_stop - dev->page_start) - + (dev->curr_page - dev->bound_ptr); } /* Avoid getting into a buffer overflow condition by not attempting @@ -1639,90 +1634,91 @@ nic_rx(void *priv, uint8_t *buf, int io_len) || (avail == pages) #endif ) { - pclog(1, "%s: no space\n", dev->name); + nelog(1, "%s: no space\n", dev->name); return; } if ((io_len < 40/*60*/) && !dev->RCR.runts_ok) { - pclog(1, "%s: rejected small packet, length %d\n", dev->name, io_len); + nelog(1, "%s: rejected small packet, length %d\n", dev->name, io_len); return; } - /* some computers don't care... */ - if (io_len < 60) { - io_len=60; - } + /* Some computers don't care... */ + if (io_len < 60) + io_len = 60; - /* Do address filtering if not in promiscuous mode */ + nelog(2, "%s: rx_frame %x:%x:%x:%x:%x:%x > %x:%x:%x:%x:%x:%x len %d\n", + dev->name, + buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], + io_len); + + /* Do address filtering if not in promiscuous mode. */ if (! dev->RCR.promisc) { - /* Received. */ - mac_cmp32[0] = *(uint32_t *) (buf); - mac_cmp16[0] = *(uint16_t *) (((uint8_t *) buf) + 4); - - /* Local. */ - mac_cmp32[1] = *(uint32_t *) (bcast_addr); - mac_cmp16[1] = *(uint16_t *) (bcast_addr+4); - if ((mac_cmp32[0] == mac_cmp32[1]) && (mac_cmp16[0] == mac_cmp16[1])) { + /* If this is a broadcast frame.. */ + if (! memcmp(buf, bcast_addr, 6)) { + /* Broadcast not enabled, we're done. */ if (! dev->RCR.broadcast) { + nelog(2, "%s: rx_frame BC disabled\n", dev->name); return; } - } else if (pktbuf[0] & 0x01) { - if (! dev->RCR.multicast) { - return; - } - idx = mcast_index(buf); - if (!(dev->mchash[idx >> 3] & (1 << (idx & 0x7)))) { - return; - } - } else if (0 != memcmp(buf, dev->physaddr, 6)) { - return; } - } else { - pclog(2, "%s: rx_frame promiscuous receive\n", dev->name); - } - pclog(2, "%s: rx_frame %d to %x:%x:%x:%x:%x:%x from %x:%x:%x:%x:%x:%x\n", - dev->name, io_len, - pktbuf[0], pktbuf[1], pktbuf[2], pktbuf[3], pktbuf[4], pktbuf[5], - pktbuf[6], pktbuf[7], pktbuf[8], pktbuf[9], pktbuf[10], pktbuf[11]); + /* If this is a multicast frame.. */ + else if (buf[0] & 0x01) { + /* Multicast not enabled, we're done. */ + if (! dev->RCR.multicast) { +#if 1 + nelog(2, "%s: rx_frame MC disabled\n", dev->name); +#endif + return; + } + + /* Are we listening to this multicast address? */ + idx = mcast_index(buf); + if (! (dev->mchash[idx>>3] & (1<<(idx&0x7)))) { + nelog(2, "%s: rx_frame MC not listed\n", dev->name); + return; + } + } + + /* Unicast, must be for us.. */ + else if (memcmp(buf, dev->physaddr, 6)) return; + } else { + nelog(2, "%s: rx_frame promiscuous receive\n", dev->name); + } nextpage = dev->curr_page + pages; - if (nextpage >= dev->page_stop) { - nextpage -= dev->page_stop - dev->page_start; - } + if (nextpage >= dev->page_stop) + nextpage -= (dev->page_stop - dev->page_start); - /* Setup packet header */ - pkthdr[0] = 0; /* rx status - old behavior - pkthdr[0] = 1; /* Probably better to set it all the time - rather than set it to 0, which is clearly wrong. */ - if (pktbuf[0] & 0x01) { - pkthdr[0] |= 0x20; /* rx status += multicast packet */ - } + /* Set up packet header. */ + pkthdr[0] = 0x01; /* RXOK - packet is OK */ + if (buf[0] & 0x01) + pkthdr[0] |= 0x20; /* MULTICAST packet */ pkthdr[1] = nextpage; /* ptr to next packet */ - pkthdr[2] = (io_len + 4) & 0xff; /* length-low */ - pkthdr[3] = (io_len + 4) >> 8; /* length-hi */ + pkthdr[2] = (io_len + sizeof(pkthdr))&0xff; /* length-low */ + pkthdr[3] = (io_len + sizeof(pkthdr))>>8; /* length-hi */ + nelog(2, "%s: rx_frame pkthdr [%02x %02x %02x %02x]\n", + dev->name, pkthdr[0], pkthdr[1], pkthdr[2], pkthdr[3]); - /* copy into buffer, update curpage, and signal interrupt if config'd */ - startptr = & dev->mem[dev->curr_page * 256 - NE2K_MEMSTART]; + /* Copy into buffer, update curpage, and signal interrupt if config'd */ + startptr = &dev->mem[(dev->curr_page * 256) - NE2K_MEMSTART]; + memcpy(startptr, pkthdr, sizeof(pkthdr)); if ((nextpage > dev->curr_page) || ((dev->curr_page + pages) == dev->page_stop)) { - *(uint32_t *) startptr = *(uint32_t *) pkthdr; - memcpy(startptr + 4, buf, io_len); - dev->curr_page = nextpage; + memcpy(startptr+sizeof(pkthdr), buf, io_len); } else { - int endbytes = (dev->page_stop - dev->curr_page) * 256; - *(uint32_t *) startptr = *(uint32_t *) pkthdr; - memcpy(startptr + 4, buf, endbytes - 4); - startptr = & dev->mem[dev->page_start * 256 - NE2K_MEMSTART]; - memcpy(startptr, (void *)(pktbuf + endbytes - 4), io_len - endbytes + 8); - dev->curr_page = nextpage; + endbytes = (dev->page_stop - dev->curr_page) * 256; + memcpy(startptr+sizeof(pkthdr), buf, endbytes-sizeof(pkthdr)); + startptr = &dev->mem[(dev->page_start * 256) - NE2K_MEMSTART]; + memcpy(startptr, buf+endbytes-sizeof(pkthdr), io_len-endbytes+8); } + dev->curr_page = nextpage; dev->RSR.rx_ok = 1; - if (pktbuf[0] & 0x80) { + if (buf[0] & 0x80) dev->RSR.rx_mbit = 1; - } - dev->ISR.pkt_rx = 1; if (dev->IMR.rx_inte) @@ -1736,8 +1732,8 @@ nic_rom_init(nic_t *dev, wchar_t *s) FILE *f = romfopen(s, L"rb"); uint32_t temp; - if (f != NULL) { - dev->disable_netbios = 1; + if (f == NULL) { + dev->bios_addr = 0x00000; nic_update_bios(dev); return; } @@ -1754,14 +1750,11 @@ nic_rom_init(nic_t *dev, wchar_t *s) dev->bios_mask = (dev->bios_size >> 8) & 0xff; dev->bios_mask = (0x100 - dev->bios_mask) & 0xff; -#if 1 - /* Shouldn't we use the configured address?? --FvK */ - rom_init(&dev->bios_rom, s, 0xd0000, - dev->bios_size, dev->bios_size - 1, 0, MEM_MAPPING_EXTERNAL); -#else rom_init(&dev->bios_rom, s, dev->bios_addr, dev->bios_size, dev->bios_size - 1, 0, MEM_MAPPING_EXTERNAL); -#endif + + nelog(1, "%s: BIOS enabled at %06lX (size %ld)\n", + dev->name, dev->bios_addr, dev->bios_size); } @@ -1788,37 +1781,41 @@ nic_init(int board) dev = malloc(sizeof(nic_t)); memset(dev, 0x00, sizeof(nic_t)); dev->board = board; - dev->is_rtl8029as = (PCI && (board == NE2K_RTL8029AS)) ? 1 : 0; - if (board == NE2K_RTL8029AS) { - strcpy(dev->name, "RTL8029AS"); - } else if (board == NE2K_NE1000) { - strcpy(dev->name, "NE1000"); - } else { - strcpy(dev->name, "NE2000"); + switch(dev->board) { + case NE2K_NE1000: + strcpy(dev->name, "NE1000"); + dev->maclocal[0] = 0x00; /* 00:00:D8 (NE1000 ISA OID) */ + dev->maclocal[1] = 0x00; + dev->maclocal[2] = 0xD8; + break; + + case NE2K_NE2000: + strcpy(dev->name, "NE2000"); + dev->maclocal[0] = 0x00; /* 00:A0:0C (NE2000 compatible OID) */ + dev->maclocal[1] = 0xA0; + dev->maclocal[2] = 0x0C; + break; + + case NE2K_RTL8029AS: + dev->is_pci = (PCI) ? 1 : 0; + strcpy(dev->name, "RTL8029AS"); + dev->maclocal[0] = 0x00; /* 00:20:18 (RTL 8029AS PCI OID) */ + dev->maclocal[1] = 0x20; + dev->maclocal[2] = 0x18; + break; } dev->base_irq = device_get_config_int("irq"); - dev->disable_netbios = device_get_config_int("disable_netbios"); - if (dev->is_rtl8029as) { + if (dev->is_pci) dev->base_address = 0x340; - } else { + else dev->base_address = device_get_config_int("addr"); - } + dev->bios_addr = device_get_config_int("bios_addr"); /* See if we have a local MAC address configured. */ mac = device_get_config_int_ex("mac", -1); - /* Set up our MAC address. */ -#if 1 - if (dev->is_rtl8029as) { - dev->maclocal[0] = 0xDE /* 0x00 */; /* 00:20:18 (RTL 8029AS PCI vendor prefix). */ - dev->maclocal[1] = 0x20; - dev->maclocal[2] = 0x18; - } else { - dev->maclocal[0] = 0xDE /* 0x00 */; /* 00:00:D8 (NE2000 ISA vendor prefix). */ - dev->maclocal[1] = 0x00; - dev->maclocal[2] = 0xD8; - } + /* Set up our BIA. */ if (mac & 0xff000000) { /* Generating new MAC. */ dev->maclocal[3] = disc_random_generate(); @@ -1828,33 +1825,20 @@ nic_init(int board) } else { dev->maclocal[3] = (mac>>16) & 0xff; dev->maclocal[4] = (mac>>8) & 0xff; -#if 1 dev->maclocal[5] = (mac & 0xfe); -#else - dev->maclocal[5] = (mac & 0xff) | 1; -#endif } -#else - dev->maclocal[0] = 0xac; - dev->maclocal[1] = 0xde; - dev->maclocal[2] = 0x48; - dev->maclocal[3] = 0x88; - dev->maclocal[4] = 0xbb; - dev->maclocal[5] = 0xaa; -#endif memcpy(dev->physaddr, dev->maclocal, sizeof(dev->maclocal)); - pclog(1,"%s: I/O=%04x, IRQ=%d, MAC=%02x:%02x:%02x:%02x:%02x:%02x BIOS=%d\n", + nelog(1,"%s: I/O=%04x, IRQ=%d, MAC=%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, dev->base_address, dev->base_irq, dev->physaddr[0], dev->physaddr[1], dev->physaddr[2], - dev->physaddr[3], dev->physaddr[4], dev->physaddr[5], - !dev->disable_netbios); + dev->physaddr[3], dev->physaddr[4], dev->physaddr[5]); if (network_attach(dev, dev->physaddr, nic_rx) < 0) { #if 0 msgbox_error_wstr(ghwnd, L"Unable to init platform network"); #endif - pclog(1, "%s: unable to init platform network type %d\n", + nelog(1, "%s: unable to init platform network type %d\n", dev->name, network_type); #if 0 /* @@ -1868,18 +1852,18 @@ nic_init(int board) #endif } - if (dev->is_rtl8029as) + if (dev->is_pci) pci_add(nic_pci_read, nic_pci_write, dev); nic_ioset(dev, dev->base_address); - if (! dev->disable_netbios) { - nic_rom_init(dev, dev->is_rtl8029as ? L"roms/rtl8029as.rom" + if (dev->bios_addr > 0) { + nic_rom_init(dev, dev->is_pci ? L"roms/rtl8029as.rom" : L"roms/ne2000.rom"); - if (dev->is_rtl8029as) + if (dev->is_pci) mem_mapping_disable(&dev->bios_rom.mapping); } - if (dev->is_rtl8029as) { + if (dev->is_pci) { dev->pci_regs[0x04] = 1; dev->pci_regs[0x05] = 0; dev->pci_regs[0x07] = 2; @@ -1888,19 +1872,18 @@ nic_init(int board) dev->pci_regs[0x0B] = 2; dev->pci_bar[0].addr_regs[0] = 1; - - if (! dev->disable_netbios) { - dev->pci_bar[1].addr = 0; - dev->bios_addr = 0; - } else { + + if (dev->bios_addr > 0) { + /* What is it.. F800 or D000 (bios_addr) ? */ dev->pci_bar[1].addr = 0x000F8000; dev->pci_bar[1].addr_regs[1] = dev->bios_mask; dev->pci_bar[1].addr |= 0x1801; - dev->bios_addr = 0xD0000; + } else { + dev->pci_bar[1].addr = 0; } dev->pci_regs[0x3C] = dev->base_irq; - pclog(1, "%s: IRQ=%i\n", dev->name, dev->pci_regs[0x3C]); + nelog(1, "%s: IRQ=%i\n", dev->name, dev->pci_regs[0x3C]); dev->pci_regs[0x3D] = 1; memset(dev->eeprom, 0x00, sizeof(dev->eeprom)); @@ -1918,8 +1901,8 @@ nic_init(int board) nic_reset(dev, 0); - pclog(1, "%s: %s init 0x%X %d\n", dev->name, - dev->is_rtl8029as?"PCI":"ISA", dev->base_address, dev->base_irq); + nelog(1, "%s: %s init 0x%X %d\n", dev->name, + dev->is_pci?"PCI":"ISA", dev->base_address, dev->base_irq); return(dev); } @@ -1937,7 +1920,7 @@ nic_close(void *priv) free(dev); - pclog(1, "%s: closed\n", dev->name); + nelog(1, "%s: closed\n", dev->name); } @@ -2011,7 +1994,21 @@ static device_config_t ne1000_config[] = "mac", "MAC Address", CONFIG_MAC, "", -1 }, { - "disable_netbios", "Disable network BIOS", CONFIG_BINARY, "", 0 + "bios_addr", "BIOS address", CONFIG_SELECTION, "", 0, + { + { + "Disabled", 0x00000 + }, + { + "D000", 0xD0000 + }, + { + "C000", 0xC0000 + }, + { + "" + } + }, }, { "", "", -1 @@ -2073,7 +2070,21 @@ static device_config_t ne2000_config[] = "mac", "MAC Address", CONFIG_MAC, "", -1 }, { - "disable_netbios", "Disable network BIOS", CONFIG_BINARY, "", 0 + "bios_addr", "BIOS address", CONFIG_SELECTION, "", 0, + { + { + "Disabled", 0x00000 + }, + { + "D000", 0xD0000 + }, + { + "C000", 0xC0000 + }, + { + "" + } + }, }, { "", "", -1 @@ -2109,7 +2120,21 @@ static device_config_t rtl8029as_config[] = "mac", "MAC Address", CONFIG_MAC, "", -1 }, { - "disable_netbios", "Disable network BIOS", CONFIG_BINARY, "", 0 + "bios_addr", "BIOS address", CONFIG_SELECTION, "", 0, + { + { + "Disabled", 0x00000 + }, + { + "D000", 0xD0000 + }, + { + "C000", 0xC0000 + }, + { + "" + } + }, }, { "", "", -1 diff --git a/src/net_pcap.c b/src/net_pcap.c index 448738715..a1b2292b0 100644 --- a/src/net_pcap.c +++ b/src/net_pcap.c @@ -8,7 +8,7 @@ * * Handle WinPcap library processing. * - * Version: @(#)net_pcap.c 1.0.3 2017/05/21 + * Version: @(#)net_pcap.c 1.0.4 2017/05/23 * * Author: Fred N. van Kempen, */ @@ -180,7 +180,7 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg) } /* Create a MAC address based packet filter. */ - pclog(" Installing packet filter for MAC=%02x:%02x:%02x:%02x:%02x\n", + pclog(" Installing packet filter for MAC=%02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); sprintf(filter_exp, "( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )", diff --git a/src/network.c b/src/network.c index 90bd69aac..c4cd9c547 100644 --- a/src/network.c +++ b/src/network.c @@ -12,7 +12,7 @@ * it should be malloc'ed and then linked to the NETCARD def. * Will be done later. * - * Version: @(#)network.c 1.0.5 2017/05/21 + * Version: @(#)network.c 1.0.6 2017/05/22 * * Authors: Kotori, * Fred N. van Kempen, @@ -25,14 +25,8 @@ #include "device.h" #include "network.h" #include "net_ne2000.h" -#ifndef unix -# define UNICODE -# define BITMAP WINDOWS_BITMAP -# include -# undef BITMAP -# include "win.h" -# include "win_language.h" -#endif +#include "win.h" +#include "win_language.h" static netcard_t net_cards[] = { diff --git a/src/pc.c b/src/pc.c index 7e05e9260..66e0bb4ef 100644 --- a/src/pc.c +++ b/src/pc.c @@ -57,18 +57,10 @@ #include "video/video.h" #include "video/vid_voodoo.h" #include "amstrad.h" -#ifdef WALTJE -# define UNICODE -# include "plat_dir.h" -#endif - -#ifndef __unix -#define UNICODE -#define BITMAP WINDOWS_BITMAP -#include -#undef BITMAP #include "win.h" #include "win_language.h" +#ifdef WALTJE +# include "plat_dir.h" #endif From a6ae4da9ae8bed5d6744378f93847cae2cdd5708 Mon Sep 17 00:00:00 2001 From: waltje Date: Wed, 24 May 2017 00:35:51 -0400 Subject: [PATCH 4/4] Plus the updated Makefile.mingw... --- src/Makefile.mingw | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Makefile.mingw b/src/Makefile.mingw index 4ba3565e2..ed0cb81f8 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -8,7 +8,7 @@ # # Modified Makefile for Win32 MinGW 32-bit environment. # -# Version: @(#)Makefile.mingw 1.0.16 2017/05/22 +# Version: @(#)Makefile.mingw 1.0.16 2017/05/23 # # Authors: Kotori, # Fred N. van Kempen, @@ -31,7 +31,7 @@ endif # Add feature selections here. # -DBUGGER adds the ISA BusBugger emulation. ifndef EXTRAS -EXTRAS = lala +EXTRAS = endif # Do we want a debugging build? @@ -215,7 +215,7 @@ LIBS = -mwindows -lcomctl32 -lwinmm -lopenal.dll -lopenal -lddraw \ # Build rules. %.o: %.c @echo $< - $(CC) $(CFLAGS) -c $< + @$(CC) $(CFLAGS) -c $< %.o: %.cc @echo $<