|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Miscellaneous machine dependent support functions and definitions
5: *
6: * Copyright 1996 Bernd Schmidt
7: */
8:
9:
10: #include "sysconfig.h"
11: #include "sysdeps.h"
12:
13: #include "config.h"
14: #include "options.h"
15: #include "machdep/m68k.h"
1.1.1.3 root 16: #include "events.h"
1.1.1.5 root 17: #include "custom.h"
1.1 root 18:
1.1.1.2 root 19: #ifndef USE_UNDERSCORE
20: #define LARGE_ALIGNMENT ".align 16\n"
21: #else
22: #define LARGE_ALIGNMENT ".align 4,0x90\n"
23: #endif
24:
1.1 root 25: struct flag_struct regflags;
26:
1.1.1.6 ! root 27: /* All the Win32 configurations handle this in od-win32/win32.c */
! 28: #ifndef _WIN32
1.1 root 29:
1.1.1.6 ! root 30: #include <signal.h>
1.1.1.2 root 31:
1.1.1.6 ! root 32: static volatile frame_time_t last_time, best_time;
! 33: static volatile int loops_to_go;
1.1.1.2 root 34:
1.1.1.6 ! root 35: #ifndef HAVE_SETITIMER
! 36: #define TIME_UNIT 1000000
1.1.1.2 root 37: #else
1.1.1.6 ! root 38: #define TIME_UNIT 100000
1.1.1.2 root 39: #endif
40:
1.1.1.6 ! root 41: static void set_alarm (void)
! 42: {
! 43: #ifndef HAVE_SETITIMER
! 44: alarm (1);
! 45: #else
! 46: struct itimerval t;
! 47: t.it_value.tv_sec = 0;
! 48: t.it_value.tv_usec = TIME_UNIT;
! 49: t.it_interval.tv_sec = 0;
! 50: t.it_interval.tv_usec = TIME_UNIT;
! 51: setitimer (ITIMER_REAL, &t, NULL);
1.1.1.2 root 52: #endif
1.1 root 53: }
1.1.1.2 root 54:
1.1.1.6 ! root 55: static int first_loop = 1;
1.1.1.2 root 56:
57: #ifdef __cplusplus
58: static RETSIGTYPE alarmhandler(...)
59: #else
60: static RETSIGTYPE alarmhandler(int foo)
61: #endif
62: {
63: frame_time_t bar;
64: bar = read_processor_time ();
1.1.1.6 ! root 65: if (! first_loop && bar - last_time < best_time)
1.1.1.2 root 66: best_time = bar - last_time;
1.1.1.6 ! root 67: first_loop = 0;
1.1.1.2 root 68: if (--loops_to_go > 0) {
69: signal (SIGALRM, alarmhandler);
70: last_time = read_processor_time();
1.1.1.6 ! root 71: set_alarm ();
1.1.1.2 root 72: }
73: }
74:
1.1.1.4 root 75: #include <setjmp.h>
76: jmp_buf catch_test;
77:
1.1.1.3 root 78: #ifdef __cplusplus
79: static RETSIGTYPE illhandler(...)
80: #else
81: static RETSIGTYPE illhandler(int foo)
82: #endif
83: {
84: rpt_available = 0;
1.1.1.4 root 85: longjmp(catch_test,1);
1.1.1.3 root 86: }
87:
1.1.1.2 root 88: void machdep_init (void)
89: {
1.1.1.3 root 90: rpt_available = 1;
1.1.1.5 root 91: fprintf (stderr,"Testing the RDTSC instruction ... ");
1.1.1.3 root 92: signal (SIGILL, illhandler);
1.1.1.5 root 93: if (setjmp (catch_test) == 0)
94: read_processor_time ();
1.1.1.3 root 95: signal (SIGILL, SIG_DFL);
1.1.1.5 root 96: fprintf (stderr,"done.\n");
1.1.1.3 root 97: if (! rpt_available) {
98: fprintf (stderr, "Your processor does not support the RDTSC instruction.\n");
99: return;
100: }
101: fprintf (stderr, "Calibrating delay loop.. ");
102: fflush (stderr);
1.1.1.2 root 103: best_time = (frame_time_t)-1;
104: loops_to_go = 5;
105: signal (SIGALRM, alarmhandler);
106: /* We want exact values... */
107: sync (); sync (); sync ();
108: last_time = read_processor_time();
1.1.1.6 ! root 109: set_alarm ();
1.1.1.2 root 110: while (loops_to_go != 0)
1.1.1.6 ! root 111: usleep (10000);
1.1.1.2 root 112: fprintf (stderr, "ok - %.2f BogoMIPS\n",
1.1.1.6 ! root 113: ((double)best_time / TIME_UNIT), best_time);
! 114: syncbase = best_time * (1000000 / TIME_UNIT);
1.1.1.2 root 115: }
116:
117: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.