From eb101e38818a2489737ac8b01e7f73a521a87631 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 5 Mar 2013 13:29:38 -0800 Subject: [PATCH] HP-UX port supplied by Mikulas Patocka --- AltairZ80/altairz80_defs.h | 2 +- makefile | 19 +++++++++++++++++-- scp.c | 6 +++++- sim_defs.h | 17 ++++++++++++++++- sim_ether.c | 10 ++++++++++ sim_fio.c | 4 ++-- sim_serial.h | 3 +++ sim_sock.c | 12 ++++++++++-- sim_timer.h | 3 ++- 9 files changed, 66 insertions(+), 10 deletions(-) diff --git a/AltairZ80/altairz80_defs.h b/AltairZ80/altairz80_defs.h index 471f4d83..39385c74 100644 --- a/AltairZ80/altairz80_defs.h +++ b/AltairZ80/altairz80_defs.h @@ -75,7 +75,7 @@ #define UNIT_CPU_V_SWITCHER (UNIT_V_UF+6) /* switcher 8086 <--> 8080/Z80 enabled */ #define UNIT_CPU_SWITCHER (1 << UNIT_CPU_V_SWITCHER) -#if defined (__linux) || defined (__linux__) || defined(__NetBSD__) || defined (__OpenBSD__) || defined (__FreeBSD__) || defined (__APPLE__) +#if defined (__linux) || defined (__linux__) || defined(__NetBSD__) || defined (__OpenBSD__) || defined (__FreeBSD__) || defined (__APPLE__) || defined (__hpux) #define UNIX_PLATFORM 1 #else #define UNIX_PLATFORM 0 diff --git a/makefile b/makefile index b01704e9..2dbede89 100644 --- a/makefile +++ b/makefile @@ -6,6 +6,7 @@ # OpenBSD # NetBSD # FreeBSD +# HP-UX # Windows (MinGW & cygwin) # Linux x86 targeting Android (using agcc script) # @@ -153,7 +154,17 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin) ifneq (,$(findstring NetBSD,$(OSTYPE))$(findstring FreeBSD,$(OSTYPE))) LIBEXT = so else - LIBEXT = a + ifeq (HP-UX,$(OSTYPE)) + ifeq (ia64,$(shell uname -m)) + LIBEXT = so + else + LIBEXT = sl + endif + OS_CCDEFS += -D_HPUX_SOURCE -D_LARGEFILE64_SOURCE + NO_LTO = 1 + else + LIBEXT = a + endif endif endif endif @@ -438,7 +449,11 @@ ifneq ($(DONT_USE_READER_THREAD),) NETWORK_OPT += -DDONT_USE_READER_THREAD endif -CC_STD = -std=c99 +ifeq (HP-UX,$(OSTYPE)) + CC_STD = -std=gnu99 +else + CC_STD = -std=c99 +endif CC_OUTSPEC = -o $@ CC = $(GCC) $(CC_STD) -U__STRICT_ANSI__ $(CFLAGS_G) $(CFLAGS_O) $(CFLAGS_GIT) -I . $(OS_CCDEFS) $(ROMS_OPT) LDFLAGS = $(OS_LDFLAGS) $(NETWORK_LDFLAGS) $(LDFLAGS_O) diff --git a/scp.c b/scp.c index e9a76f5c..0e61e906 100644 --- a/scp.c +++ b/scp.c @@ -781,7 +781,7 @@ static CTAB cmd_table[] = { { NULL, NULL, 0 } }; -#if defined(_WIN32) +#if defined(_WIN32) || defined(__hpux) static int setenv(const char *envname, const char *envval, int overwrite) { @@ -789,8 +789,12 @@ int setenv(const char *envname, const char *envval, int overwrite) int r; sprintf(envstr, "%s=%s", envname, envval); +#if defined(_WIN32) r = _putenv(envstr); free(envstr); +#else + r = putenv(envstr); +#endif return r; } #endif diff --git a/sim_defs.h b/sim_defs.h index d601afa9..21d2c9dd 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -120,6 +120,21 @@ #undef MEM_MAPPED /* avoid macro name collision */ #endif +/* avoid macro names collisions */ +#ifdef MAX +#undef MAX +#endif +#ifdef MIN +#undef MIN +#endif +#ifdef PMASK +#undef PMASK +#endif +#ifdef RS +#undef RS +#endif + + #ifndef TRUE #define TRUE 1 #define FALSE 0 @@ -700,7 +715,7 @@ extern int32 sim_asynch_latency; extern int32 sim_asynch_inst_latency; /* Thread local storage */ -#if defined(__GNUC__) && !defined(__APPLE__) +#if defined(__GNUC__) && !defined(__APPLE__) && !defined(__hpux) #define AIO_TLS __thread #elif defined(_MSC_VER) #define AIO_TLS __declspec(thread) diff --git a/sim_ether.c b/sim_ether.c index 2767ed86..31d4c22e 100644 --- a/sim_ether.c +++ b/sim_ether.c @@ -1877,6 +1877,16 @@ if (1) { pthread_cond_init (&dev->writer_cond, NULL); pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); +#if defined(__hpux) + { + /* libpcap needs sizeof(long) * 8192 bytes on the stack */ + size_t stack_size; + const size_t min_stack_size = sizeof(long) * 8192 * 3 / 2; + if (!pthread_attr_getstacksize(&attr, &stack_size) && stack_size < min_stack_size) { + pthread_attr_setstacksize(&attr, min_stack_size); + } + } +#endif pthread_create (&dev->reader_thread, &attr, _eth_reader, (void *)dev); pthread_create (&dev->writer_thread, &attr, _eth_writer, (void *)dev); pthread_attr_destroy(&attr); diff --git a/sim_fio.c b/sim_fio.c index 612972b4..10803288 100644 --- a/sim_fio.c +++ b/sim_fio.c @@ -219,7 +219,7 @@ FILE *sim_fopen (const char *file, const char *mode) #if defined (VMS) return fopen (file, mode, "ALQ=32", "DEQ=4096", "MBF=6", "MBC=127", "FOP=cbt,tef", "ROP=rah,wbh", "CTX=stm"); -#elif defined (USE_INT64) && defined (USE_ADDR64) && (defined (__linux) || defined (__linux__)) +#elif defined (USE_INT64) && defined (USE_ADDR64) && (defined (__linux) || defined (__linux__) || defined (__hpux)) return fopen64 (file, mode); #else return fopen (file, mode); @@ -312,7 +312,7 @@ return (t_addr)fileaddr; /* Linux */ -#if defined (__linux) || defined (__linux__) +#if defined (__linux) || defined (__linux__) || defined (__hpux) #define _SIM_IO_FSEEK_EXT_ 1 int sim_fseek (FILE *st, t_addr xpos, int origin) diff --git a/sim_serial.h b/sim_serial.h index 9b1d2a7c..91bc40b2 100644 --- a/sim_serial.h +++ b/sim_serial.h @@ -49,6 +49,9 @@ #elif defined (__unix__) || defined(__APPLE__) /* UNIX definitions */ #include +#ifdef __hpux +#include +#endif #include #include #include diff --git a/sim_sock.c b/sim_sock.c index ee9eb32f..cf33c058 100644 --- a/sim_sock.c +++ b/sim_sock.c @@ -148,6 +148,12 @@ typedef size_t socklen_t; #endif #endif +#if defined(__hpux) +#if !defined(EAI_OVERFLOW) +#define EAI_OVERFLOW EAI_FAIL +#endif +#endif + typedef int (WSAAPI *getnameinfo_func) (const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); static getnameinfo_func p_getnameinfo; @@ -779,10 +785,12 @@ SOCKET sim_accept_conn (SOCKET master, char **connectaddr) int32 sta, err; #if defined (macintosh) || defined (__linux) || defined (__linux__) || \ defined (__APPLE__) || defined (__OpenBSD__) || \ - defined(__NetBSD__) || defined(__FreeBSD__) + defined(__NetBSD__) || defined(__FreeBSD__) || \ + (defined(__hpux) && defined(_XOPEN_SOURCE_EXTENDED)) socklen_t size; #elif defined (_WIN32) || defined (__EMX__) || \ - (defined (__ALPHA) && defined (__unix__)) + (defined (__ALPHA) && defined (__unix__)) || \ + defined (__hpux) int size; #else size_t size; diff --git a/sim_timer.h b/sim_timer.h index 8d0586f4..9912325e 100644 --- a/sim_timer.h +++ b/sim_timer.h @@ -41,7 +41,8 @@ #define HAVE_STRUCT_TIMESPEC 1 /* OSX defined the structure but doesn't tell us */ #endif -#if !defined(CLOCK_REALTIME) +/* on HP-UX, CLOCK_REALTIME is enum, not preprocessor define */ +#if !defined(CLOCK_REALTIME) && !defined(__hpux) #define CLOCK_REALTIME 1 #define NEED_CLOCK_GETTIME 1 #if !defined(HAVE_STRUCT_TIMESPEC)