107 |
|
#include "macos_util.h" |
108 |
|
#include "rom_patches.h" |
109 |
|
#include "user_strings.h" |
110 |
+ |
#include "vm_alloc.h" |
111 |
|
|
112 |
|
#define DEBUG 0 |
113 |
|
#include "debug.h" |
264 |
|
#endif |
265 |
|
|
266 |
|
|
266 |
– |
// Decode LZSS data |
267 |
– |
static void decode_lzss(const uint8 *src, uint8 *dest, int size) |
268 |
– |
{ |
269 |
– |
char dict[0x1000]; |
270 |
– |
int run_mask = 0, dict_idx = 0xfee; |
271 |
– |
for (;;) { |
272 |
– |
if (run_mask < 0x100) { |
273 |
– |
// Start new run |
274 |
– |
if (--size < 0) |
275 |
– |
break; |
276 |
– |
run_mask = *src++ | 0xff00; |
277 |
– |
} |
278 |
– |
bool bit = run_mask & 1; |
279 |
– |
run_mask >>= 1; |
280 |
– |
if (bit) { |
281 |
– |
// Verbatim copy |
282 |
– |
if (--size < 0) |
283 |
– |
break; |
284 |
– |
int c = *src++; |
285 |
– |
dict[dict_idx++] = c; |
286 |
– |
*dest++ = c; |
287 |
– |
dict_idx &= 0xfff; |
288 |
– |
} else { |
289 |
– |
// Copy from dictionary |
290 |
– |
if (--size < 0) |
291 |
– |
break; |
292 |
– |
int idx = *src++; |
293 |
– |
if (--size < 0) |
294 |
– |
break; |
295 |
– |
int cnt = *src++; |
296 |
– |
idx |= (cnt << 4) & 0xf00; |
297 |
– |
cnt = (cnt & 0x0f) + 3; |
298 |
– |
while (cnt--) { |
299 |
– |
char c = dict[idx++]; |
300 |
– |
dict[dict_idx++] = c; |
301 |
– |
*dest++ = c; |
302 |
– |
idx &= 0xfff; |
303 |
– |
dict_idx &= 0xfff; |
304 |
– |
} |
305 |
– |
} |
306 |
– |
} |
307 |
– |
} |
308 |
– |
|
309 |
– |
|
267 |
|
/* |
268 |
|
* Main program |
269 |
|
*/ |
421 |
|
} |
422 |
|
|
423 |
|
// Create Low Memory area (0x0000..0x3000) |
424 |
< |
if (mmap((char *)0x0000, 0x3000, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, zero_fd, 0) == (void *)-1) { |
424 |
> |
if (vm_acquire_fixed((char *)0, 0x3000) < 0) { |
425 |
|
sprintf(str, GetString(STR_LOW_MEM_MMAP_ERR), strerror(errno)); |
426 |
|
ErrorAlert(str); |
427 |
|
goto quit; |
451 |
|
D(bug("Kernel Data at %p, Emulator Data at %p\n", kernel_data, emulator_data)); |
452 |
|
|
453 |
|
// Create area for Mac ROM |
454 |
< |
if (mmap((char *)ROM_BASE, ROM_AREA_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, zero_fd, 0) == (void *)-1) { |
454 |
> |
if (vm_acquire_fixed((char *)ROM_BASE, ROM_AREA_SIZE) < 0) { |
455 |
|
sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno)); |
456 |
|
ErrorAlert(str); |
457 |
|
goto quit; |
458 |
|
} |
459 |
+ |
#if !EMULATED_PPC |
460 |
+ |
if (vm_protect((char *)ROM_BASE, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) { |
461 |
+ |
sprintf(str, GetString(STR_ROM_MMAP_ERR), strerror(errno)); |
462 |
+ |
ErrorAlert(str); |
463 |
+ |
goto quit; |
464 |
+ |
} |
465 |
+ |
#endif |
466 |
|
rom_area_mapped = true; |
467 |
|
D(bug("ROM area at %08x\n", ROM_BASE)); |
468 |
|
|
473 |
|
RAMSize = 8*1024*1024; |
474 |
|
} |
475 |
|
|
476 |
< |
mmap_RAMBase = mmap((void *)0x20000000, RAMSize, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, zero_fd, 0); |
477 |
< |
if (mmap_RAMBase == (void *)-1) { |
476 |
> |
mmap_RAMBase = (void *)0x20000000; |
477 |
> |
if (vm_acquire_fixed(mmap_RAMBase, RAMSize) < 0) { |
478 |
|
sprintf(str, GetString(STR_RAM_MMAP_ERR), strerror(errno)); |
479 |
|
ErrorAlert(str); |
480 |
|
goto quit; |
481 |
|
} |
482 |
+ |
#if !EMULATED_PPC |
483 |
+ |
if (vm_protect(mmap_RAMBase, RAMSize, VM_PAGE_READ | VM_PAGE_WRITE | VM_PAGE_EXECUTE) < 0) { |
484 |
+ |
sprintf(str, GetString(STR_RAM_MMAP_ERR), strerror(errno)); |
485 |
+ |
ErrorAlert(str); |
486 |
+ |
goto quit; |
487 |
+ |
} |
488 |
+ |
#endif |
489 |
|
RAMBase = (uint32)mmap_RAMBase; |
490 |
|
ram_area_mapped = true; |
491 |
|
D(bug("RAM area at %08x\n", RAMBase)); |
511 |
|
rom_tmp = new uint8[ROM_SIZE]; |
512 |
|
actual = read(rom_fd, (void *)rom_tmp, ROM_SIZE); |
513 |
|
close(rom_fd); |
514 |
< |
if (actual == ROM_SIZE) { |
515 |
< |
// Plain ROM image |
516 |
< |
memcpy((void *)ROM_BASE, rom_tmp, ROM_SIZE); |
517 |
< |
delete[] rom_tmp; |
547 |
< |
} else { |
548 |
< |
if (strncmp((char *)rom_tmp, "<CHRP-BOOT>", 11) == 0) { |
549 |
< |
// CHRP compressed ROM image |
550 |
< |
D(bug("CHRP ROM image\n")); |
551 |
< |
uint32 lzss_offset, lzss_size; |
552 |
< |
|
553 |
< |
char *s = strstr((char *)rom_tmp, "constant lzss-offset"); |
554 |
< |
if (s == NULL) { |
555 |
< |
ErrorAlert(GetString(STR_ROM_SIZE_ERR)); |
556 |
< |
goto quit; |
557 |
< |
} |
558 |
< |
s -= 7; |
559 |
< |
if (sscanf(s, "%06x", &lzss_offset) != 1) { |
560 |
< |
ErrorAlert(GetString(STR_ROM_SIZE_ERR)); |
561 |
< |
goto quit; |
562 |
< |
} |
563 |
< |
s = strstr((char *)rom_tmp, "constant lzss-size"); |
564 |
< |
if (s == NULL) { |
565 |
< |
ErrorAlert(GetString(STR_ROM_SIZE_ERR)); |
566 |
< |
goto quit; |
567 |
< |
} |
568 |
< |
s -= 7; |
569 |
< |
if (sscanf(s, "%06x", &lzss_size) != 1) { |
570 |
< |
ErrorAlert(GetString(STR_ROM_SIZE_ERR)); |
571 |
< |
goto quit; |
572 |
< |
} |
573 |
< |
D(bug("Offset of compressed data: %08x\n", lzss_offset)); |
574 |
< |
D(bug("Size of compressed data: %08x\n", lzss_size)); |
575 |
< |
|
576 |
< |
D(bug("Uncompressing ROM...\n")); |
577 |
< |
decode_lzss(rom_tmp + lzss_offset, (uint8 *)ROM_BASE, lzss_size); |
578 |
< |
delete[] rom_tmp; |
579 |
< |
} else if (rom_size != 4*1024*1024) { |
514 |
> |
|
515 |
> |
// Decode Mac ROM |
516 |
> |
if (!DecodeROM(rom_tmp, actual)) { |
517 |
> |
if (rom_size != 4*1024*1024) { |
518 |
|
ErrorAlert(GetString(STR_ROM_SIZE_ERR)); |
519 |
|
goto quit; |
520 |
|
} else { |
522 |
|
goto quit; |
523 |
|
} |
524 |
|
} |
525 |
+ |
delete[] rom_tmp; |
526 |
|
|
527 |
|
// Load NVRAM |
528 |
|
XPRAMInit(); |
582 |
|
#if !EMULATED_PPC |
583 |
|
MakeExecutable(0, (void *)ROM_BASE, ROM_AREA_SIZE); |
584 |
|
#endif |
585 |
< |
mprotect((char *)ROM_BASE, ROM_AREA_SIZE, PROT_EXEC | PROT_READ); |
585 |
> |
vm_protect((char *)ROM_BASE, ROM_AREA_SIZE, VM_PAGE_READ | VM_PAGE_EXECUTE); |
586 |
|
|
587 |
|
// Initialize Kernel Data |
588 |
|
memset(kernel_data, 0, sizeof(KernelData)); |
794 |
|
|
795 |
|
// Delete RAM area |
796 |
|
if (ram_area_mapped) |
797 |
< |
munmap(mmap_RAMBase, RAMSize); |
797 |
> |
vm_release(mmap_RAMBase, RAMSize); |
798 |
|
|
799 |
|
// Delete ROM area |
800 |
|
if (rom_area_mapped) |
801 |
< |
munmap((char *)ROM_BASE, ROM_AREA_SIZE); |
801 |
> |
vm_release((char *)ROM_BASE, ROM_AREA_SIZE); |
802 |
|
|
803 |
|
// Delete Kernel Data area |
804 |
|
if (kernel_area >= 0) { |
1091 |
|
} |
1092 |
|
|
1093 |
|
|
1094 |
+ |
/* |
1095 |
+ |
* Pthread configuration |
1096 |
+ |
*/ |
1097 |
+ |
|
1098 |
+ |
void Set_pthread_attr(pthread_attr_t *attr, int priority) |
1099 |
+ |
{ |
1100 |
+ |
// nothing to do |
1101 |
+ |
} |
1102 |
+ |
|
1103 |
+ |
|
1104 |
|
/* |
1105 |
|
* Mutexes |
1106 |
|
*/ |