1
0
mirror of https://github.com/upx/upx synced 2025-09-28 19:06:07 +08:00

New ACC version.

committer: mfx <mfx> 1084307588 +0000
This commit is contained in:
Markus F.X.J. Oberhumer 2004-05-11 20:33:08 +00:00
parent ed8a71bba1
commit b10f68d20a
11 changed files with 346 additions and 10 deletions

View File

@ -27,7 +27,7 @@
#ifndef __ACC_H_INCLUDED
#define __ACC_H_INCLUDED 1
#define ACC_VERSION 20040202L
#define ACC_VERSION 20040511L
#if !defined(ACC_CONFIG_INCLUDE)
# define ACC_CONFIG_INCLUDE(file) file
@ -45,18 +45,23 @@
#endif
/* disable pedantic warnings */
/* disable pedantic warnings for undefined preprocessing symbols */
#if defined(__INTEL_COMPILER) && defined(__linux__)
# pragma warning(disable: 193) /* #193: zero used for undefined preprocessing identifier */
# pragma warning(disable: 193)
#endif
#if defined(__KEIL__) && defined(__C166__)
# pragma warning disable = 322
#elif 0 && defined(__C251__)
# pragma warning disable = 322
#endif
#if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
# if (_MSC_VER >= 1300)
# pragma warning(disable: 4668) /* -Wall: 4668: 'symbol' is not defined as a preprocessor macro, replacing with '0' */
# pragma warning(disable: 4668)
# endif
#endif
#if 0 && defined(__WATCOMC__)
# if (__WATCOMC__ < 1060)
# pragma warning 203 9 /* W203: Preprocessing symbol '%s' has not been declared */
# pragma warning 203 9
# endif
#endif
@ -65,8 +70,8 @@
#include ACC_CONFIG_INCLUDE("acc_init.h")
#include ACC_CONFIG_INCLUDE("acc_os.h")
#include ACC_CONFIG_INCLUDE("acc_cc.h")
#include ACC_CONFIG_INCLUDE("acc_mm.h")
#include ACC_CONFIG_INCLUDE("acc_arch.h")
#include ACC_CONFIG_INCLUDE("acc_mm.h")
#include ACC_CONFIG_INCLUDE("acc_defs.h")
#if defined(ACC_CONFIG_NO_HEADER)

View File

@ -18,11 +18,14 @@
*
* ACC_ARCH_UNKNOWN [default]
* ACC_ARCH_ALPHA
* ACC_ARCH_AMD64
* ACC_ARCH_AMD64 aka x86-64 or ia32e
* ACC_ARCH_C166
* ACC_ARCH_IA16 Intel Architecture (8088, 8086, 80186, 80286)
* ACC_ARCH_IA32 Intel Architecture (80386+)
* ACC_ARCH_IA64 Intel Architecture (Itanium)
* ACC_ARCH_M68K Motorola 680x0
* ACC_ARCH_MCS251
* ACC_ARCH_MCS51
* ACC_ARCH_PPC64 Power PC
* ACC_ARCH_SPARC64
*
@ -41,6 +44,18 @@
#elif defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64)
# define ACC_ARCH_AMD64 1
# define ACC_INFO_ARCH "amd64"
#elif (UINT_MAX <= ACC_0xffffL) && defined(__AVR__)
# define ACC_ARCH_AVR 1
# define ACC_INFO_ARCH "avr"
#elif (UINT_MAX == ACC_0xffffL) && defined(__C166__)
# define ACC_ARCH_C166 1
# define ACC_INFO_ARCH "c166"
#elif (UINT_MAX == ACC_0xffffL) && defined(__C251__)
# define ACC_ARCH_MCS251 1
# define ACC_INFO_ARCH "mcs-251"
#elif (UINT_MAX == ACC_0xffffL) && defined(__C51__)
# define ACC_ARCH_MCS51 1
# define ACC_INFO_ARCH "mcs-51"
#elif defined(__386__) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_M_I386)
# define ACC_ARCH_IA32 1
# define ACC_INFO_ARCH "ia32"

View File

@ -63,6 +63,7 @@
#define HAVE_LIMITS_H 1
#define HAVE_MALLOC_H 1
#define HAVE_MEMORY_H 1
#define HAVE_SETJMP_H 1
#define HAVE_SIGNAL_H 1
#define HAVE_STDARG_H 1
#define HAVE_STDDEF_H 1
@ -285,6 +286,7 @@
#define HAVE_GETTIMEOFDAY 1
#define HAVE_GMTIME 1
#define HAVE_LOCALTIME 1
#define HAVE_LONGJMP 1
#define HAVE_LSTAT 1
#define HAVE_MEMCMP 1
#define HAVE_MEMCPY 1
@ -293,6 +295,7 @@
#define HAVE_MKTIME 1
#define HAVE_QSORT 1
#define HAVE_RAISE 1
#define HAVE_SETJMP 1
#define HAVE_SIGNAL 1
#define HAVE_SNPRINTF 1
#define HAVE_STAT 1
@ -322,6 +325,7 @@
#if (ACC_OS_POSIX)
# if (ACC_CC_TINYC)
# undef HAVE_ALLOCA
# elif defined(__dietlibc__)
# endif
# if (ACC_OS_POSIX_MACOSX && ACC_CC_MWERKS) && defined(__MSL__)
/* FIXME ??? */
@ -422,6 +426,9 @@
# if ((_MSC_VER < 800) && ACC_OS_WIN16)
# undef HAVE_ALLOCA
# endif
# if (_MSC_VER < 1000) && defined(__cplusplus)
# undef HAVE_SETJMP
# endif
#elif (ACC_OS_WIN32 && ACC_CC_GNUC) && defined(__MINGW32__)
# if (ACC_CC_GNUC < 0x025f00ul)
# undef HAVE_SNPRINTF
@ -554,6 +561,10 @@
# else
# error "ACC_MM"
# endif
#elif (ACC_ARCH_AVR || ACC_ARCH_C166 || ACC_ARCH_MCS51 || ACC_ARCH_MCS251)
# define SIZEOF_PTRDIFF_T 2
# define SIZEOF_SIZE_T 2
# define SIZEOF_VOID_P 2
#else
# define SIZEOF_PTRDIFF_T SIZEOF_LONG
# define SIZEOF_SIZE_T SIZEOF_LONG

View File

@ -59,6 +59,10 @@
# define ACC_CC_IBMC 1
# define ACC_INFO_CC "IBM C"
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__IBMC__)
#elif defined(__KEIL__) && defined(__C166__)
# define ACC_CC_KEILC 1
# define ACC_INFO_CC "Keil C"
# define ACC_INFO_CCVER ACC_CPP_MACRO_EXPAND(__C166__)
#elif defined(__LCC__)
# define ACC_CC_LCC 1
# define ACC_INFO_CC "lcc"

View File

@ -424,7 +424,9 @@
ACCCHK_ASSERT( (int) ((unsigned char) ((signed char) -1)) == 255)
#endif
#if (ACC_CC_NDPC)
#if (ACC_CC_KEILC)
/* Keil C is broken */
#elif (ACC_CC_NDPC)
/* NDP C is broken */
#elif !defined(ACC_BROKEN_INTEGRAL_PROMOTION) && (SIZEOF_INT > 1)
/* check that the compiler correctly promotes integrals */

View File

@ -50,21 +50,29 @@
************************************************************************/
#if !defined(ACC_UNUSED)
# if (ACC_CC_BORLANDC || ACC_CC_HIGHC || ACC_CC_NDPC || ACC_CC_TURBOC)
# if (ACC_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
# define ACC_UNUSED(var) ((void) &var)
# elif (ACC_CC_BORLANDC || ACC_CC_HIGHC || ACC_CC_NDPC || ACC_CC_TURBOC)
# define ACC_UNUSED(var) if (&var) ; else
# elif (ACC_CC_MSC && (_MSC_VER < 900))
# define ACC_UNUSED(var) if (&var) ; else
# elif (ACC_CC_GNUC)
# define ACC_UNUSED(var) ((void) var)
# elif (ACC_CC_KEILC)
# define ACC_UNUSED(var)
# else
# define ACC_UNUSED(var) ((void) &var)
# endif
#endif
#if !defined(ACC_UNUSED_FUNC)
# if (ACC_CC_BORLANDC || ACC_CC_NDPC || ACC_CC_TURBOC)
# if (ACC_CC_BORLANDC && (__BORLANDC__ >= 0x0600))
# define ACC_UNUSED_FUNC(func) ((void) func)
# elif (ACC_CC_BORLANDC || ACC_CC_NDPC || ACC_CC_TURBOC)
# define ACC_UNUSED_FUNC(func) if (func) ; else
# elif (ACC_CC_MSC && (_MSC_VER < 900))
# define ACC_UNUSED_FUNC(func) if (func) ; else
# elif (ACC_CC_KEILC)
# define ACC_UNUSED_FUNC(func)
# else
# define ACC_UNUSED_FUNC(func) ((void) func)
# endif

View File

@ -39,6 +39,9 @@
#if defined(HAVE_DIRENT_H)
# include <dirent.h>
#endif
#if defined(HAVE_SETJMP_H)
# include <setjmp.h>
#endif
#if defined(HAVE_SIGNAL_H)
# include <signal.h>
#endif

View File

@ -161,6 +161,8 @@ ACCLIB_EXTERN(acc_hsize_t, acc_hfwrite) (ACC_FILE_P, const acc_hvoid_p, acc_hsiz
ACCLIB_EXTERN(long, acc_hread) (int, acc_hvoid_p, long);
ACCLIB_EXTERN(long, acc_hwrite) (int, const acc_hvoid_p, long);
#endif
ACCLIB_EXTERN(long, acc_safe_hread) (int, acc_hvoid_p, long);
ACCLIB_EXTERN(long, acc_safe_hwrite) (int, const acc_hvoid_p, long);
/*************************************************************************
@ -316,6 +318,13 @@ ACCLIB_EXTERN(acc_uint32l_t, acc_umuldiv32) (acc_uint32l_t, acc_uint32l_t, acc_u
// uclock
**************************************************************************/
#if defined(acc_int32e_t)
ACCLIB_EXTERN(int, acc_tsc_read) (acc_uint32e_t*);
ACCLIB_EXTERN(int, acc_tsc_read_add) (acc_uint32e_t*);
#define acc_rdtsc(x) acc_tsc_read(x)
#endif
typedef struct { /* all private */
acclib_handle_t h;
int mode;

View File

@ -113,6 +113,61 @@ extern "C" {
#endif
#elif (ACC_ARCH_C166)
#if !defined(__MODEL__)
# error "FIXME - C166 __MODEL__"
#elif ((__MODEL__) == 0)
# define ACC_MM_SMALL 1
#elif ((__MODEL__) == 1)
# define ACC_MM_SMALL 1
#elif ((__MODEL__) == 2)
# define ACC_MM_LARGE 1
#elif ((__MODEL__) == 3)
# define ACC_MM_TINY 1
#elif ((__MODEL__) == 4)
# define ACC_MM_XTINY 1
#elif ((__MODEL__) == 5)
# define ACC_MM_XSMALL 1
#else
# error "FIXME - C166 __MODEL__"
#endif
#elif (ACC_ARCH_MCS251)
#if !defined(__MODEL__)
# error "FIXME - MCS251 __MODEL__"
#elif ((__MODEL__) == 0)
# define ACC_MM_SMALL 1
#elif ((__MODEL__) == 2)
# define ACC_MM_LARGE 1
#elif ((__MODEL__) == 3)
# define ACC_MM_TINY 1
#elif ((__MODEL__) == 4)
# define ACC_MM_XTINY 1
#elif ((__MODEL__) == 5)
# define ACC_MM_XSMALL 1
#else
# error "FIXME - MCS251 __MODEL__"
#endif
#elif (ACC_ARCH_MCS51)
#if !defined(__MODEL__)
# error "FIXME - MCS51 __MODEL__"
#elif ((__MODEL__) == 1)
# define ACC_MM_SMALL 1
#elif ((__MODEL__) == 2)
# define ACC_MM_LARGE 1
#elif ((__MODEL__) == 3)
# define ACC_MM_TINY 1
#elif ((__MODEL__) == 4)
# define ACC_MM_XTINY 1
#elif ((__MODEL__) == 5)
# define ACC_MM_XSMALL 1
#else
# error "FIXME - MCS51 __MODEL__"
#endif
#else
# define ACC_MM_FLAT 1

97
src/acc/acclib/hsread.ch Normal file
View File

@ -0,0 +1,97 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#define __ACCLIB_HSREAD_CH_INCLUDED 1
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
/***********************************************************************
// huge pointer layer - safe read/write
// handles partial pipe writes and interrupted system calls
************************************************************************/
ACCLIB_PUBLIC(long, acc_safe_hread) (int fd, acc_hvoid_p buf, long size)
{
acc_hbyte_p b = (acc_hbyte_p) buf;
long l = 0;
int saved_errno;
saved_errno = errno;
while (l < size)
{
long n = size - l;
#if (ACC_HAVE_MM_HUGE_PTR)
# define __ACCLIB_REQUIRE_HREAD_CH 1
errno = 0; n = acc_hread(fd, b, n);
#elif (ACC_OS_DOS32) && defined(__DJGPP__)
errno = 0; n = _read(fd, b, n);
#else
errno = 0; n = read(fd, b, n);
#endif
if (n == 0)
break;
if (n < 0) {
#if defined(EINTR)
if (errno == (EINTR)) continue;
#endif
if (errno == 0) errno = 1;
return l;
}
b += n; l += n;
}
errno = saved_errno;
return l;
}
ACCLIB_PUBLIC(long, acc_safe_hwrite) (int fd, const acc_hvoid_p buf, long size)
{
const acc_hbyte_p b = (const acc_hbyte_p) buf;
long l = 0;
int saved_errno;
saved_errno = errno;
while (l < size)
{
long n = size - l;
#if (ACC_HAVE_MM_HUGE_PTR)
# define __ACCLIB_REQUIRE_HREAD_CH 1
errno = 0; n = acc_hwrite(fd, b, n);
#elif (ACC_OS_DOS32) && defined(__DJGPP__)
errno = 0; n = _write(fd, b, n);
#else
errno = 0; n = write(fd, b, n);
#endif
if (n == 0)
break;
if (n < 0) {
#if defined(EINTR)
if (errno == (EINTR)) continue;
#endif
if (errno == 0) errno = 1;
return l;
}
b += n; l += n;
}
errno = saved_errno;
return l;
}
/*
vi:ts=4:et
*/

127
src/acc/acclib/rdtsc.ch Normal file
View File

@ -0,0 +1,127 @@
/* ACC -- Automatic Compiler Configuration
Copyright (C) 1996-2004 Markus Franz Xaver Johannes Oberhumer
All Rights Reserved.
This software is a copyrighted work licensed under the terms of
the GNU General Public License. Please consult the file "ACC_LICENSE"
for details.
Markus F.X.J. Oberhumer
<markus@oberhumer.com>
http://www.oberhumer.com/
*/
#define __ACCLIB_RDTSC_CH_INCLUDED 1
#if !defined(ACCLIB_PUBLIC)
# define ACCLIB_PUBLIC(r,f) r __ACCLIB_FUNCNAME(f)
#endif
#if defined(acc_int32e_t)
/*************************************************************************
// read TSC
**************************************************************************/
ACCLIB_PUBLIC(int, acc_tsc_read) (acc_uint32e_t* t)
{
#if ((ACC_ARCH_AMD64 || ACC_ARCH_IA32) && ACC_CC_GNUC)
__asm__ __volatile__(
"clc \n" ".byte 0x0f, 0x31\n"
"movl %%eax,(%0)\n" "movl %%edx,4(%0)\n"
# if (ACC_CC_GNUC >= 0x020000ul)
: : "r" (t) : "cc", "memory", "eax", "edx"
# else
: : "r" (t) : "ax", "dx"
# endif
);
return 0;
#elif (ACC_ARCH_IA32 && ACC_CC_INTELC) && defined(__linux__)
__asm__ __volatile__(
"clc \n" ".byte 0x0f, 0x31\n"
"movl %%eax,(%0)\n" "movl %%edx,4(%0)\n"
: : "r" (t) : "memory", "eax", "edx"
);
return 0;
#elif (ACC_ARCH_IA32 && (ACC_OS_DOS32 || ACC_OS_WIN32) && (ACC_CC_DMC || ACC_CC_INTELC || ACC_CC_MSC))
ACC_UNUSED(t);
__asm {
mov ecx, t
clc
# if (ACC_CC_MSC && (_MSC_VER < 1200))
_emit 0x0f
_emit 0x31
# else
rdtsc
# endif
mov [ecx], eax
mov [ecx+4], edx
}
return 0;
#else
t[0] = t[1] = 0;
return -1;
#endif
}
/*************************************************************************
// read and add TSC
**************************************************************************/
ACCLIB_PUBLIC(int, acc_tsc_read_add) (acc_uint32e_t* t)
{
#if ((ACC_ARCH_AMD64 || ACC_ARCH_IA32) && ACC_CC_GNUC)
__asm__ __volatile__(
"clc \n" ".byte 0x0f, 0x31\n"
"addl %%eax,(%0)\n" "adcl $0,%%edx\n" "addl %%edx,4(%0)\n"
# if (ACC_CC_GNUC >= 0x020000ul)
: : "r" (t) : "cc", "memory", "eax", "edx"
# else
: : "r" (t) : "ax", "dx"
# endif
);
return 0;
#elif (ACC_ARCH_IA32 && ACC_CC_INTELC) && defined(__linux__)
__asm__ __volatile__(
"clc \n" ".byte 0x0f, 0x31\n"
"addl %%eax,(%0)\n" "adcl $0,%%edx\n" "addl %%edx,4(%0)\n"
: : "r" (t) : "memory", "eax", "edx"
);
return 0;
#elif (ACC_ARCH_IA32 && (ACC_OS_DOS32 || ACC_OS_WIN32) && (ACC_CC_DMC || ACC_CC_INTELC || ACC_CC_MSC))
ACC_UNUSED(t);
__asm {
mov ecx, t
clc
# if (ACC_CC_MSC && (_MSC_VER < 1200))
_emit 0x0f
_emit 0x31
# else
rdtsc
# endif
add [ecx], eax
adc edx, 0
add [ecx+4], edx
}
return 0;
#else
acc_uint32e_t v[2];
int r;
r = acc_tsc_read(v);
t[0] += v[0];
if (t[0] < v[0]) t[1] += 1;
t[1] += v[1];
return r;
#endif
}
#endif /* defined(acc_int32e_t) */
/*
vi:ts=4:et
*/