|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Try to include the right system headers and get other system-specific
5: * stuff right & other collected kludges.
6: *
7: * If you think about modifying this, think twice. Some systems rely on
8: * the exact order of the #include statements. That's also the reason
9: * why everything gets included unconditionally regardless of whether
10: * it's actually needed by the .c file.
11: *
12: * Copyright 1996, 1997 Bernd Schmidt
13: */
1.1.1.4 ! root 14: #ifndef UAE_SYSDEPS_H
! 15: #define UAE_SYSDEPS_H
! 16:
! 17: #ifdef HAVE_CONFIG_H
! 18: #include "config.h"
! 19: #endif
! 20: #include "sysconfig.h"
! 21:
! 22: #ifdef WINUAE_FOR_HATARI
! 23: #include "compat.h"
! 24: #endif
! 25:
! 26: #ifndef UAE
! 27: #define UAE
! 28: #endif
1.1 root 29:
1.1.1.4 ! root 30: #ifdef __cplusplus
! 31: #include <string>
! 32: using namespace std;
! 33: #else
! 34: #include <string.h>
! 35: #include <ctype.h>
! 36: #endif
1.1 root 37: #include <stdio.h>
38: #include <stdlib.h>
39: #include <errno.h>
40: #include <assert.h>
41: #include <limits.h>
1.1.1.4 ! root 42: //#ifdef WINUAE_FOR_HATARI
! 43: //#include "compat.h"
! 44: //#endif
! 45:
! 46: #ifndef UAE
! 47: #define UAE
! 48: #endif
! 49:
! 50: #if defined(__x86_64__) || defined(_M_AMD64)
! 51: #define CPU_x86_64 1
! 52: #define CPU_64_BIT 1
! 53: #elif defined(__i386__) || defined(_M_IX86)
! 54: #define CPU_i386 1
! 55: #elif defined(__arm__) || defined(_M_ARM)
! 56: #define CPU_arm 1
! 57: #elif defined(__powerpc__) || defined(_M_PPC) || defined(__ppc__) || defined(__ppc64__)
! 58: #define CPU_powerpc 1
! 59: #else
! 60: #error unrecognized CPU type
! 61: #endif
! 62:
! 63: #ifdef _WIN32
! 64: /* Parameters are passed in ECX, EDX for both x86 and x86-64 (RCX, RDX).
! 65: * For x86-64, __fastcall is the default, so it isn't really required. */
! 66: #define JITCALL __fastcall
! 67: #elif defined(CPU_x86_64)
! 68: /* Parameters are passed in RDI, RSI by default (System V AMD64 ABI). */
! 69: #define JITCALL
! 70: #elif defined(HAVE_FUNC_ATTRIBUTE_REGPARM)
! 71: /* Parameters are passed in EAX, EDX on x86 with regparm(2). */
! 72: #define JITCALL __attribute__((regparm(2)))
! 73: /* This was originally regparm(3), but as far as I can see only two register
! 74: * params are supported by the JIT code. It probably just worked anyway
! 75: * if all functions used max two arguments. */
! 76: #elif !defined(JIT)
! 77: #define JITCALL
! 78: #endif
! 79: #define REGPARAM
! 80: #define REGPARAM2 JITCALL
! 81: #define REGPARAM3 JITCALL
! 82:
! 83: #ifdef WINUAE_FOR_HATARI
! 84: #include "uae/types.h"
! 85: #else
! 86: #include <tchar.h>
! 87: #endif
1.1 root 88:
89: #ifndef __STDC__
90: #ifndef _MSC_VER
91: #error "Your compiler is not ANSI. Get a real one."
92: #endif
93: #endif
94:
95: #include <stdarg.h>
96:
97: #ifdef HAVE_SYS_TYPES_H
98: #include <sys/types.h>
99: #endif
100:
101: #ifdef HAVE_VALUES_H
102: #include <values.h>
103: #endif
104:
105: #ifdef HAVE_STRINGS_H
106: #include <strings.h>
107: #endif
108: #ifdef HAVE_STRING_H
109: #include <string.h>
110: #endif
111:
112: #ifdef HAVE_UNISTD_H
113: #include <unistd.h>
114: #endif
115: #ifdef HAVE_FCNTL_H
116: #include <fcntl.h>
117: #endif
118:
119: #ifdef HAVE_UTIME_H
120: #include <utime.h>
121: #endif
122:
123: #ifdef HAVE_SYS_STAT_H
124: #include <sys/stat.h>
125: #endif
126:
127: #if TIME_WITH_SYS_TIME
128: # include <sys/time.h>
129: # include <time.h>
130: #else
131: # if HAVE_SYS_TIME_H
132: # include <sys/time.h>
133: # else
134: # include <time.h>
135: # endif
136: #endif
137:
138: #if HAVE_DIRENT_H
139: # include <dirent.h>
140: #else
141: # define dirent direct
142: # if HAVE_SYS_NDIR_H
143: # include <sys/ndir.h>
144: # endif
145: # if HAVE_SYS_DIR_H
146: # include <sys/dir.h>
147: # endif
148: # if HAVE_NDIR_H
149: # include <ndir.h>
150: # endif
151: #endif
152:
153: #ifdef HAVE_SYS_UTIME_H
154: # include <sys/utime.h>
155: #endif
156:
157: #include <errno.h>
158: #include <assert.h>
159:
160: #if EEXIST == ENOTEMPTY
161: #define BROKEN_OS_PROBABLY_AIX
162: #endif
163:
164: #ifdef __NeXT__
165: #define S_IRUSR S_IREAD
166: #define S_IWUSR S_IWRITE
167: #define S_IXUSR S_IEXEC
168: #define S_ISDIR(val) (S_IFDIR & val)
169: struct utimbuf
170: {
171: time_t actime;
172: time_t modtime;
173: };
174: #endif
175:
176: #ifndef L_tmpnam
177: #define L_tmpnam 128 /* ought to be safe */
178: #endif
179:
180: /* If char has more then 8 bits, good night. */
181: typedef unsigned char uae_u8;
182: typedef signed char uae_s8;
183: typedef char uae_char;
184:
185: typedef struct { uae_u8 RGB[3]; } RGB;
186:
187: #if SIZEOF_SHORT == 2
188: typedef unsigned short uae_u16;
189: typedef short uae_s16;
190: #elif SIZEOF_INT == 2
191: typedef unsigned int uae_u16;
192: typedef int uae_s16;
193: #else
194: #error No 2 byte type, you lose.
195: #endif
196:
197: #if SIZEOF_INT == 4
198: typedef unsigned int uae_u32;
199: typedef int uae_s32;
200: #elif SIZEOF_LONG == 4
201: typedef unsigned long uae_u32;
202: typedef long uae_s32;
203: #else
204: #error No 4 byte type, you lose.
205: #endif
206:
207: typedef uae_u32 uaecptr;
208:
209: #undef uae_s64
210: #undef uae_u64
211:
212: #if SIZEOF_LONG_LONG == 8
213: #define uae_s64 long long
214: #define uae_u64 unsigned long long
215: #define VAL64(a) (a ## LL)
216: #define UVAL64(a) (a ## uLL)
217: #elif SIZEOF___INT64 == 8
218: #define uae_s64 __int64
219: #define uae_u64 unsigned __int64
220: #define VAL64(a) (a)
221: #define UVAL64(a) (a)
222: #elif SIZEOF_LONG == 8
223: #define uae_s64 long;
224: #define uae_u64 unsigned long;
225: #define VAL64(a) (a ## l)
226: #define UVAL64(a) (a ## ul)
227: #endif
228:
1.1.1.4 ! root 229: void atomic_and(volatile uae_atomic *p, uae_u32 v);
! 230: void atomic_or(volatile uae_atomic *p, uae_u32 v);
! 231: uae_atomic atomic_inc(volatile uae_atomic *p);
! 232: uae_atomic atomic_dec(volatile uae_atomic *p);
! 233: uae_u32 atomic_bit_test_and_reset(volatile uae_atomic *p, uae_u32 v);
! 234:
1.1.1.3 root 235:
1.1 root 236: #ifdef HAVE_STRDUP
237: #define my_strdup _tcsdup
238: #else
239: extern TCHAR *my_strdup (const TCHAR*s);
240: #endif
241: extern TCHAR *my_strdup_ansi (const char*);
1.1.1.4 ! root 242: extern void my_trim (TCHAR*);
! 243: extern TCHAR *my_strdup_trim (const TCHAR*);
1.1 root 244: extern TCHAR *au (const char*);
245: extern char *ua (const TCHAR*);
246: extern TCHAR *aucp (const char *s, unsigned int cp);
247: extern char *uacp (const TCHAR *s, unsigned int cp);
248: extern TCHAR *au_fs (const char*);
249: extern char *ua_fs (const TCHAR*, int);
250: extern char *ua_copy (char *dst, int maxlen, const TCHAR *src);
251: extern TCHAR *au_copy (TCHAR *dst, int maxlen, const char *src);
252: extern char *ua_fs_copy (char *dst, int maxlen, const TCHAR *src, int defchar);
253: extern TCHAR *au_fs_copy (TCHAR *dst, int maxlen, const char *src);
254: extern char *uutf8 (const TCHAR *s);
255: extern TCHAR *utf8u (const char *s);
256: extern void unicode_init (void);
257: extern void to_lower (TCHAR *s, int len);
258: extern void to_upper (TCHAR *s, int len);
1.1.1.4 ! root 259:
1.1 root 260: /* We can only rely on GNU C getting enums right. Mickeysoft VSC++ is known
261: * to have problems, and it's likely that other compilers choke too. */
262: #ifdef __GNUC__
263: #define ENUMDECL typedef enum
264: #define ENUMNAME(name) name
265:
266: /* While we're here, make abort more useful. */
1.1.1.4 ! root 267: #define abort() \
1.1 root 268: do { \
269: write_log ("Internal error; file %s, line %d\n", __FILE__, __LINE__); \
270: (abort) (); \
271: } while (0)
1.1.1.4 ! root 272: #else
1.1 root 273: #define ENUMDECL enum
274: #define ENUMNAME(name) ; typedef int name
275: #endif
276:
277: /*
278: * Porters to weird systems, look! This is the preferred way to get
279: * filesys.c (and other stuff) running on your system. Define the
280: * appropriate macros and implement wrappers in a machine-specific file.
281: *
282: * I guess the Mac port could use this (Ernesto?)
283: */
284:
285: #undef DONT_HAVE_POSIX
286: #undef DONT_HAVE_REAL_POSIX /* define if open+delete doesn't do what it should */
287: #undef DONT_HAVE_STDIO
288: #undef DONT_HAVE_MALLOC
289:
290: #if defined(WARPUP)
291: #define DONT_HAVE_POSIX
292: #endif
293:
1.1.1.4 ! root 294: #if !defined(FSUAE) && defined _WIN32
1.1 root 295:
1.1.1.4 ! root 296: //#ifdef FSUAE
! 297: //#error _WIN32 should not be defined here
! 298: //#endif
1.1 root 299: #if defined __WATCOMC__
300:
301: #define O_NDELAY 0
302: #include <direct.h>
303: #define dirent direct
304: #define mkdir(a,b) mkdir(a)
305: #define strcasecmp stricmp
306:
307: #elif defined __MINGW32__
308:
1.1.1.4 ! root 309: #include <winsock.h>
! 310:
1.1 root 311: #define O_NDELAY 0
1.1.1.4 ! root 312:
! 313: #define FILEFLAG_DIR 0x1
! 314: #define FILEFLAG_ARCHIVE 0x2
! 315: #define FILEFLAG_WRITE 0x4
! 316: #define FILEFLAG_READ 0x8
! 317: #define FILEFLAG_EXECUTE 0x10
! 318: #define FILEFLAG_SCRIPT 0x20
! 319: #define FILEFLAG_PURE 0x40
! 320:
1.1 root 321: #define mkdir(a,b) mkdir(a)
322:
323: #elif defined _MSC_VER
324:
325: #ifdef HAVE_GETTIMEOFDAY
326: #include <winsock.h> // for 'struct timeval' definition
327: extern void gettimeofday( struct timeval *tv, void *blah );
328: #endif
329:
330: #define O_NDELAY 0
331:
332: #define FILEFLAG_DIR 0x1
333: #define FILEFLAG_ARCHIVE 0x2
334: #define FILEFLAG_WRITE 0x4
335: #define FILEFLAG_READ 0x8
336: #define FILEFLAG_EXECUTE 0x10
337: #define FILEFLAG_SCRIPT 0x20
338: #define FILEFLAG_PURE 0x40
339:
340: #include <io.h>
341: #define O_BINARY _O_BINARY
342: #define O_WRONLY _O_WRONLY
343: #define O_RDONLY _O_RDONLY
344: #define O_RDWR _O_RDWR
345: #define O_CREAT _O_CREAT
346: #define O_TRUNC _O_TRUNC
347: #define strcasecmp _tcsicmp
348: #define strncasecmp _tcsncicmp
349: #define W_OK 0x2
350: #define R_OK 0x4
351: #define STAT struct stat
352: #define DIR struct DIR
353: struct direct
354: {
355: TCHAR d_name[1];
356: };
357: #include <sys/utime.h>
358: #define utimbuf __utimbuf64
359: #define USE_ZFILE
360:
361: #undef S_ISDIR
362: #undef S_IWUSR
363: #undef S_IRUSR
364: #undef S_IXUSR
365: #define S_ISDIR(a) (a&FILEFLAG_DIR)
366: #define S_ISARC(a) (a&FILEFLAG_ARCHIVE)
367: #define S_IWUSR FILEFLAG_WRITE
368: #define S_IRUSR FILEFLAG_READ
369: #define S_IXUSR FILEFLAG_EXECUTE
370:
371: #endif
372:
373: #endif /* _WIN32 */
374:
375: #ifdef DONT_HAVE_POSIX
376:
377: #define access posixemu_access
378: extern int posixemu_access (const TCHAR *, int);
379: #define open posixemu_open
380: extern int posixemu_open (const TCHAR *, int, int);
381: #define close posixemu_close
382: extern void posixemu_close (int);
383: #define read posixemu_read
384: extern int posixemu_read (int, TCHAR *, int);
385: #define write posixemu_write
386: extern int posixemu_write (int, const TCHAR *, int);
387: #undef lseek
388: #define lseek posixemu_seek
389: extern int posixemu_seek (int, int, int);
390: #define stat(a,b) posixemu_stat ((a), (b))
391: extern int posixemu_stat (const TCHAR *, STAT *);
392: #define mkdir posixemu_mkdir
393: extern int mkdir (const TCHAR *, int);
394: #define rmdir posixemu_rmdir
395: extern int posixemu_rmdir (const TCHAR *);
396: #define unlink posixemu_unlink
397: extern int posixemu_unlink (const TCHAR *);
398: #define truncate posixemu_truncate
399: extern int posixemu_truncate (const TCHAR *, long int);
400: #define rename posixemu_rename
401: extern int posixemu_rename (const TCHAR *, const TCHAR *);
402: #define chmod posixemu_chmod
403: extern int posixemu_chmod (const TCHAR *, int);
404: #define tmpnam posixemu_tmpnam
405: extern void posixemu_tmpnam (TCHAR *);
406: #define utime posixemu_utime
407: extern int posixemu_utime (const TCHAR *, struct utimbuf *);
408: #define opendir posixemu_opendir
409: extern DIR * posixemu_opendir (const TCHAR *);
410: #define readdir posixemu_readdir
411: extern struct dirent* readdir (DIR *);
412: #define closedir posixemu_closedir
413: extern void closedir (DIR *);
414:
415: /* This isn't the best place for this, but it fits reasonably well. The logic
416: * is that you probably don't have POSIX errnos if you don't have the above
417: * functions. */
418: extern long dos_errno (void);
419:
420: #endif
421:
422: #ifdef DONT_HAVE_STDIO
423:
424: extern FILE *stdioemu_fopen (const TCHAR *, const TCHAR *);
425: #define fopen(a,b) stdioemu_fopen(a, b)
426: extern int stdioemu_fseek (FILE *, int, int);
427: #define fseek(a,b,c) stdioemu_fseek(a, b, c)
428: extern int stdioemu_fread (TCHAR *, int, int, FILE *);
429: #define fread(a,b,c,d) stdioemu_fread(a, b, c, d)
430: extern int stdioemu_fwrite (const TCHAR *, int, int, FILE *);
431: #define fwrite(a,b,c,d) stdioemu_fwrite(a, b, c, d)
432: extern int stdioemu_ftell (FILE *);
433: #define ftell(a) stdioemu_ftell(a)
434: extern int stdioemu_fclose (FILE *);
435: #define fclose(a) stdioemu_fclose(a)
436:
437: #endif
438:
439: #ifdef DONT_HAVE_MALLOC
440:
441: #define malloc(a) mallocemu_malloc(a)
442: extern void *mallocemu_malloc (int size);
443: #define free(a) mallocemu_free(a)
444: extern void mallocemu_free (void *ptr);
445:
446: #endif
447:
448: #ifdef X86_ASSEMBLY
449: #define ASM_SYM_FOR_FUNC(a) __asm__(a)
450: #else
451: #define ASM_SYM_FOR_FUNC(a)
452: #endif
453:
454: //#include "target.h"
455:
456: #ifdef UAE_CONSOLE
457: #undef write_log
458: #define write_log write_log_standard
459: #endif
460:
461: #if __GNUC__ - 1 > 1 || __GNUC_MINOR__ - 1 > 6
1.1.1.4 ! root 462: extern void write_log (const TCHAR *, ...);
! 463: extern void write_log (const char *, ...) __attribute__ ((format (printf, 1, 2)));
1.1 root 464: #else
465: extern void write_log (const TCHAR *, ...);
1.1.1.4 ! root 466: extern void write_log (const char *, ...);
1.1 root 467: #endif
468: extern void write_dlog (const TCHAR *, ...);
1.1.1.3 root 469: extern int read_log(void);
1.1 root 470:
471: extern void flush_log (void);
1.1.1.4 ! root 472: extern TCHAR *setconsolemode (TCHAR *buffer, int maxlen);
1.1 root 473: extern void close_console (void);
474: extern void reopen_console (void);
1.1.1.4 ! root 475: extern void activate_console (void);
1.1.1.3 root 476: //extern void console_out (const TCHAR *);
477: //extern void console_out_f (const TCHAR *, ...);
1.1 root 478: extern void console_flush (void);
479: extern int console_get (TCHAR *, int);
1.1.1.4 ! root 480: extern bool console_isch (void);
1.1 root 481: extern TCHAR console_getch (void);
1.1.1.3 root 482: //extern void f_out (void *, const TCHAR *, ...);
1.1 root 483: extern TCHAR* buf_out (TCHAR *buffer, int *bufsize, const TCHAR *format, ...);
1.1.1.3 root 484: //extern void gui_message (const TCHAR *,...);
1.1 root 485: extern int gui_message_multibutton (int flags, const TCHAR *format,...);
486: #define write_log_err write_log
487: extern void logging_init (void);
1.1.1.4 ! root 488: extern FILE *log_open (const TCHAR *name, int append, int bootlog, TCHAR*);
1.1 root 489: extern void log_close (FILE *f);
490:
491:
492: #ifndef O_BINARY
493: #define O_BINARY 0
494: #endif
495:
496: #ifndef STATIC_INLINE
497: #if __GNUC__ - 1 > 1 && __GNUC_MINOR__ - 1 >= 0
498: #define STATIC_INLINE static __inline__ __attribute__ ((always_inline))
499: #define NOINLINE __attribute__ ((noinline))
500: #define NORETURN __attribute__ ((noreturn))
501: #elif _MSC_VER
502: #define STATIC_INLINE static __forceinline
503: #define NOINLINE __declspec(noinline)
504: #define NORETURN __declspec(noreturn)
505: #else
506: #define STATIC_INLINE static __inline__
507: #define NOINLINE
508: #define NORETURN
509: #endif
510: #endif
511: /* Every Amiga hardware clock cycle takes this many "virtual" cycles. This
512: used to be hardcoded as 1, but using higher values allows us to time some
513: stuff more precisely.
1.1.1.3 root 514: 512 is the official value from now on - it can't change, unless we want
515: _another_ config option "finegrain2_m68k_speed".
516:
1.1 root 517: We define this value here rather than in events.h so that gencpu.c sees
518: it. */
1.1.1.3 root 519: #define CYCLE_UNIT 512
520:
521: /* This one is used by cfgfile.c. We could reduce the CYCLE_UNIT back to 1,
522: I'm not 100% sure this code is bug free yet. */
523: #define OFFICIAL_CYCLE_UNIT 512
1.1 root 524:
525: /*
526: * You can specify numbers from 0 to 5 here. It is possible that higher
527: * numbers will make the CPU emulation slightly faster, but if the setting
528: * is too high, you will run out of memory while compiling.
529: * Best to leave this as it is.
530: */
531: #define CPU_EMU_SIZE 0
532:
533: /*
534: * Byte-swapping functions
535: */
536:
537: /* Try to use system bswap_16/bswap_32 functions. */
538: #if defined HAVE_BSWAP_16 && defined HAVE_BSWAP_32
539: # include <byteswap.h>
540: # ifdef HAVE_BYTESWAP_H
541: # include <byteswap.h>
542: # endif
543: #else
544: /* Else, if using SDL, try SDL's endian functions. */
545: # ifdef USE_SDL
546: # include <SDL_endian.h>
547: # define bswap_16(x) SDL_Swap16(x)
548: # define bswap_32(x) SDL_Swap32(x)
549: # else
550: /* Otherwise, we'll roll our own. */
551: # define bswap_16(x) (((x) >> 8) | (((x) & 0xFF) << 8))
552: # define bswap_32(x) (((x) << 24) | (((x) << 8) & 0x00FF0000) | (((x) >> 8) & 0x0000FF00) | ((x) >> 24))
553: # endif
554: #endif
555:
556: #ifndef __cplusplus
557:
558: #define xmalloc(T, N) malloc(sizeof (T) * (N))
559: #define xcalloc(T, N) calloc(sizeof (T), N)
560: #define xfree(T) free(T)
561: #define xrealloc(T, TP, N) realloc(TP, sizeof (T) * (N))
562:
563: #if 0
564: extern void *xmalloc (size_t);
565: extern void *xcalloc (size_t, size_t);
566: extern void xfree (const void*);
567: #endif
568:
569: #else
570:
571: #define xmalloc(T, N) static_cast<T*>(malloc (sizeof (T) * (N)))
572: #define xcalloc(T, N) static_cast<T*>(calloc (sizeof (T), N))
573: #define xrealloc(T, TP, N) static_cast<T*>(realloc (TP, sizeof (T) * (N)))
574: #define xfree(T) free(T)
575:
576: #endif
1.1.1.4 ! root 577:
! 578: #define DBLEQU(f, i) (abs ((f) - (i)) < 0.000001)
! 579:
! 580: #ifdef HAVE_VAR_ATTRIBUTE_UNUSED
! 581: #define NOWARN_UNUSED(x) __attribute__((unused)) x
! 582: #else
! 583: #define NOWARN_UNUSED(x) x
! 584: #endif
! 585:
! 586: #endif /* UAE_SYSDEPS_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.