21 |
|
* along with this program; if not, write to the Free Software |
22 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
|
*/ |
24 |
+ |
|
25 |
+ |
#import <AppKit/AppKit.h> |
26 |
+ |
#undef check |
27 |
+ |
|
28 |
|
#define PTHREADS // Why is this here? |
29 |
|
#include "sysdeps.h" |
30 |
|
|
65 |
|
#include "debug.h" |
66 |
|
|
67 |
|
|
64 |
– |
#import <AppKit/AppKit.h> |
65 |
– |
|
68 |
|
#include "main_macosx.h" // To bridge between main() and misc. classes |
69 |
|
|
70 |
|
|
78 |
|
bool CPUIs68060; |
79 |
|
int FPUType; |
80 |
|
bool TwentyFourBitAddressing; |
81 |
+ |
bool ThirtyThreeBitAddressing = false; |
82 |
|
|
83 |
|
|
84 |
|
// Global variables |
111 |
|
|
112 |
|
|
113 |
|
/* |
114 |
+ |
* Map memory that can be accessed from the Mac side |
115 |
+ |
*/ |
116 |
+ |
|
117 |
+ |
void *vm_acquire_mac(size_t size) |
118 |
+ |
{ |
119 |
+ |
void *m = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_33BIT); |
120 |
+ |
if (m == NULL) { |
121 |
+ |
ThirtyThreeBitAddressing = false; |
122 |
+ |
m = vm_acquire(size); |
123 |
+ |
} |
124 |
+ |
return m; |
125 |
+ |
} |
126 |
+ |
|
127 |
+ |
|
128 |
+ |
/* |
129 |
|
* SIGSEGV handler |
130 |
|
*/ |
131 |
|
|
329 |
|
else |
330 |
|
#endif |
331 |
|
{ |
332 |
< |
RAMBaseHost = (uint8 *)vm_acquire(RAMSize); |
333 |
< |
ROMBaseHost = (uint8 *)vm_acquire(0x100000); |
334 |
< |
if (RAMBaseHost == VM_MAP_FAILED || ROMBaseHost == VM_MAP_FAILED) { |
332 |
> |
#ifdef USE_33BIT_ADDRESSING |
333 |
> |
// Speculatively enables 33-bit addressing |
334 |
> |
ThirtyThreeBitAddressing = true; |
335 |
> |
#endif |
336 |
> |
uint8 *ram_rom_area = (uint8 *)vm_acquire_mac(RAMSize + 0x100000); |
337 |
> |
if (ram_rom_area == VM_MAP_FAILED) { |
338 |
|
ErrorAlert(STR_NO_MEM_ERR); |
339 |
|
QuitEmulator(); |
340 |
|
} |
341 |
+ |
RAMBaseHost = ram_rom_area; |
342 |
+ |
ROMBaseHost = RAMBaseHost + RAMSize; |
343 |
|
} |
344 |
|
|
345 |
|
#if USE_SCRATCHMEM_SUBTERFUGE |
428 |
|
|
429 |
|
// Free ROM/RAM areas |
430 |
|
if (RAMBaseHost != VM_MAP_FAILED) { |
431 |
< |
vm_release(RAMBaseHost, RAMSize); |
431 |
> |
vm_release(RAMBaseHost, RAMSize + 0x100000); |
432 |
|
RAMBaseHost = NULL; |
433 |
|
} |
411 |
– |
if (ROMBaseHost != VM_MAP_FAILED) { |
412 |
– |
vm_release(ROMBaseHost, 0x100000); |
413 |
– |
ROMBaseHost = NULL; |
414 |
– |
} |
434 |
|
|
435 |
|
#if USE_SCRATCHMEM_SUBTERFUGE |
436 |
|
// Delete scratch memory area |
458 |
|
|
459 |
|
void QuitEmulator(void) |
460 |
|
{ |
442 |
– |
extern NSApplication *NSApp; |
443 |
– |
|
444 |
– |
|
461 |
|
QuitEmuNoExit(); |
462 |
|
|
463 |
|
// Stop run loop? |
499 |
|
#endif |
500 |
|
|
501 |
|
|
502 |
+ |
#ifdef HAVE_PTHREADS |
503 |
+ |
/* |
504 |
+ |
* Pthread configuration |
505 |
+ |
*/ |
506 |
+ |
|
507 |
+ |
void Set_pthread_attr(pthread_attr_t *attr, int priority) |
508 |
+ |
{ |
509 |
+ |
pthread_attr_init(attr); |
510 |
+ |
#if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) |
511 |
+ |
// Some of these only work for superuser |
512 |
+ |
if (geteuid() == 0) { |
513 |
+ |
pthread_attr_setinheritsched(attr, PTHREAD_EXPLICIT_SCHED); |
514 |
+ |
pthread_attr_setschedpolicy(attr, SCHED_FIFO); |
515 |
+ |
struct sched_param fifo_param; |
516 |
+ |
fifo_param.sched_priority = ((sched_get_priority_min(SCHED_FIFO) |
517 |
+ |
+ sched_get_priority_max(SCHED_FIFO)) |
518 |
+ |
/ 2 + priority); |
519 |
+ |
pthread_attr_setschedparam(attr, &fifo_param); |
520 |
+ |
} |
521 |
+ |
if (pthread_attr_setscope(attr, PTHREAD_SCOPE_SYSTEM) != 0) { |
522 |
+ |
#ifdef PTHREAD_SCOPE_BOUND_NP |
523 |
+ |
// If system scope is not available (eg. we're not running |
524 |
+ |
// with CAP_SCHED_MGT capability on an SGI box), try bound |
525 |
+ |
// scope. It exposes pthread scheduling to the kernel, |
526 |
+ |
// without setting realtime priority. |
527 |
+ |
pthread_attr_setscope(attr, PTHREAD_SCOPE_BOUND_NP); |
528 |
+ |
#endif |
529 |
+ |
} |
530 |
+ |
#endif |
531 |
+ |
} |
532 |
+ |
#endif // HAVE_PTHREADS |
533 |
+ |
|
534 |
+ |
|
535 |
|
/* |
536 |
|
* Mutexes |
537 |
|
*/ |