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