Commit Graph

86 Commits

Author SHA1 Message Date
asvitkine
b3b5db5456 [Michael Schmitt]
Attached is a patch to SheepShaver to fix memory allocation problems when OS X 10.5 is the host. It also relaxes the 512 MB RAM limit on OS X hosts.


Problem
-------
Some users have been unable to run SheepShaver on OS X 10.5 (Leopard) hosts. The symptom is error "ERROR: Cannot map RAM: File already exists".

SheepShaver allocates RAM at fixed addresses. If it is running in "Real" addressing mode, and can't allocate at address 0, then it was hard-coded to allocate the RAM area at 0x20000000. The ROM area as allocated at 0x40800000.

The normal configuration is for SheepShaver to run under SDL, which is a Cocoa wrapper. By the time SheepShaver does its memory allocations, the Cocoa application has already started. The result is the SheepShaver memory address space already contains libraries, fonts, Input Managers, and IOKit areas.

On Leopard hosts these areas can land on the same addresses SheepShaver needs, so SheepShaver's memory allocation fails.


Solution
--------
The approach is to change SheepShaver (on Unix & OS X hosts) to allocate the RAM area anywhere it can find the space, rather than at a fixed address.

This could result in the RAM allocated higher than the ROM area, which causes a crash. To prevent this from occurring, the RAM and ROM areas are allocated contiguously.

Previously the ROM starting address was a constant ROM_BASE, which was used throughout the source files. The ROM start address is now a variable ROMBase. ROMBase is allocated and set by main_*.cpp just like RAMBase.

A side-effect of this change is that it lifts the 512 MB RAM limit for OS X hosts. The limit was because the fixed RAM and ROM addresses were such that the RAM could only be 512 MB before it overlapped the ROM area.


Impact
------
The change to make ROMBase a variable is throughout all hosts & addressing modes.

The RAM and ROM areas will only shift when run on Unix & OS X hosts, otherwise the same fixed allocation address is used as before.

This change is limited to "Real" addressing mode. Unlike Basilisk II, SheepShaver *pre-calculates* the offset for "Direct" addressing mode; the offset is compiled into the program. If the RAM address were allowed to shift, it could result in the RAM area wrapping around address 0.


Changes to main_unix.cpp
------------------------
1. Real addressing mode no longer defines a RAM_BASE constant.

2. The base address of the Mac ROM (ROMBase) is defined and exported by this program.

3. Memory management helper vm_mac_acquire is renamed to vm_mac_acquire_fixed. Added a new memory management helper vm_mac_acquire, which allocates memory at any address.

4. Changed and rearranged the allocation of RAM and ROM areas.

Before it worked like this:

  - Allocate ROM area
  - If can, attempt to allocate RAM at address zero
  - If RAM not allocated at 0, allocate at fixed address

We still want to try allocating the RAM at zero, and if using DIRECT addressing we're still going to use the fixed addresses. So we don't know where the ROM should be until after we do the RAM. The new logic is:

  - If can, attempt to allocate RAM at address zero
  - If RAM not allocated at 0
      if REAL addressing
         allocate RAM and ROM together. The ROM address is aligned to a 1 MB boundary
      else (direct addressing)
         allocate RAM at fixed address
  - If ROM hasn't been allocated yet, allocate at fixed address

5. Calculate ROMBase and ROMBaseHost based on where the ROM was loaded.

6. There is a crash if the RAM is allocated too high. To try and catch this, check if it was allocated higher than the kernel data address.

7. Change subsequent code from using constant ROM_BASE to variable ROMBase.


Changes to Other Programs
-------------------------
emul_op.cpp, main.cpp, name_registery.cpp, rom_patches.cpp, rsrc_patches.cpp, emul_ppc.cpp, sheepshaver_glue.cpp, ppc-translate-cpp:
Change from constant ROM_BASE to variable ROMBase.

ppc_asm.S: It was setting register to a hard-coded literal address: 0x40b0d000. Changed to set it to ROMBase + 0x30d000.

ppc_asm.tmpl: It defined a macro ASM_LO16 but it assumed that the macro would always be used with operands that included a register specification. This is not true. Moved the register specification from the macro to the macro invocations.

main_beos.cpp, main_windows.cpp: Since the subprograms are all expecting a variable ROMBase, all the main_*.cpp pgrams have to define and export it. The ROM_BASE constant is moved here for consistency. The mains for beos and windows just allocate the ROM at the same fixed address as before, set ROMBaseHost and ROMBase to that address, and then use ROMBase for the subsequent code.

cpu_emulation.h: removed ROM_BASE constant. This value is moved to the main_*.cpp modules, to be consistent with RAM_BASE.

user_strings_unix.cpp, user_strings_unix.h: Added new error messages related to errors that occur when the RAM and ROM are allocated anywhere.
2009-08-18 18:26:11 +00:00
asvitkine
a98f16a1bd support both foo.sheepvm and foo.sheepvm/ command-line parameters 2009-08-18 02:36:59 +00:00
asvitkine
5b958defa7 support for .sheepvm bundles on macosx, containing "prefs" and "nvram" files 2009-07-23 19:12:51 +00:00
asvitkine
04bec66567 don't re-declare sigsegv_info_t, instead use the one from the header 2009-02-11 20:44:49 +00:00
asvitkine
ca2b9b5832 [Patch from Mike Sliczniak]
This first patch gets B2 and SS to build under Leopard and Tiger.

I tested this on a 32-bit intel 10.5.6 mac like so:

B2
./autogen.sh --disable-standalone-gui --enable-vosf --enable-sdl-video --enable-sdl-audio --enable-addressing=real --without-esd --without-gtk --without-mon --without-x

SS
./autogen.sh --disable-standalone-gui --enable-vosf -enable-sdl-video --disable-sdl-audio --enable-addressing=real --without-esd --without-gtk --without-mon --without-x --enable-jit

There is also a little tweak so that you can use sdl audio in SheepShaver when building for Mac OS X.
2009-02-11 19:23:53 +00:00
asvitkine
d885e5ccf4 [patch from Kelvin Delbarre] SDL's Quartz video implementation maps command
clicks to right-clicks and option-clicks to middle-clicks, a feature intended
for Mac users with single-button mice who are running SDL-based games that
require a multi-button mouse. This is unhelpful in SheepShaver, where we want
command-clicks and option-clicks to be passed through unchanged to the emulated
Mac OS. We can disable the unwanted behavior by setting an environment variable
SDL_HAS3BUTTONMOUSE intended for this very purpose.

A similar change in main_windows.cpp is NOT required, because only the Quartz
video implementation is involved.

By SDL convention, putenv is used in preference to setenv, although for Unix
platforms it doesn't matter.
2008-06-22 20:30:12 +00:00
gbeauche
054c37ca0c Happy New Year! 2008-01-01 09:47:39 +00:00
gbeauche
19e145ad16 Sync with new SIGSEGV API. 2007-12-30 09:18:40 +00:00
asvitkine
dc524bb30a use the new SDL 1.2.12 env variable to allow the OS to launch the screensaver
when sheepshaver is running - must be linking to sdl 1.2.12 or later for it
to take effect
2007-08-27 21:45:13 +00:00
gbeauche
9dfecc4279 Update CPU table to kernel 2.6.17+ code (POWER6, Cell, PA6T). Fix detection
of the CPU string (separator is actually ','). Fix detection of CPU clock
frequency when it is expressed as a float.
2006-10-26 05:25:19 +00:00
gbeauche
484469962b Don't let SDL catch SIGINT and SIGTERM signals. This is not suitable for
SheepShaver since we are typically translating SDL_QUIT events to PowerOff()
on MacOS side. And, if MacOS is not fully booted, it's not really convenient
to shut it down, even with ctrl-C. i.e. you had to kill -9 it.
2006-05-09 19:53:31 +00:00
gbeauche
bc13355b57 Add linker scripts from Basilisk II and make it possible to allocate up to
1 GB of Mac memory. Only tested on Linux/x86_64 so far but with a somewhat
interesting (MacOS, ROM, RAM size) matrix.

XXX: It should be possible to allocate up to 1.5 GB by relocating the ROM
base to something like 0x60800000.
2006-05-06 10:42:51 +00:00
gbeauche
9b60acb2da Port --enable-standalone-gui support to SheepShaver
Others changes include:
- Factor out STR_SIG_INSTALL_ERR messages
- Process command line arguments early (prior to calling PrefsInit())
- GUI: set start_clicked only if the "Start" button was clicked
- GUI: save changes to the "Input" pane when the "Start" button was clicked
2006-05-01 22:33:34 +00:00
gbeauche
b6600ca3fe recognize POWER5+ CPUs (e.g. p5-520) 2006-01-18 22:12:26 +00:00
gbeauche
5c287d301d remove obsolete cygwin bits and fix allocation of NanoKernel region on
IRIX (aka make it POSIX compliant)
2005-12-11 23:18:47 +00:00
gbeauche
896cdc1fb7 Add upcoming 7448 and new PPC970FX CPU ids. 2005-07-06 05:11:56 +00:00
gbeauche
4d97079af9 Map latest 7447A CPU to a plain G4 (7400) 2005-07-06 04:58:34 +00:00
gbeauche
29207d9cf2 Move sigregs handling to dedicated header 2005-07-04 05:34:33 +00:00
gbeauche
a60b0fb78c Restore clobbered registers before calling SDL_PumpEvents(). 2005-06-30 22:26:12 +00:00
gbeauche
08c5f8b713 Improve idle wait mechanism. Now, the emulator thread can be suspended
(idle_wait) until events arrived and notified through TriggerInterrupt().
i.e. we no longer sleep a fixed amount of time on platforms that support
a thread wait/signal mechanism.
2005-06-30 10:17:58 +00:00
gbeauche
7ac6ad2f46 Clean-ups: comments, ticks per sec output, don't restore r13 twice. 2005-06-28 16:50:30 +00:00
gbeauche
38d03d02e9 The alternate stack trick never worked as you can't modify an active stack.
i.e. it returned EPERM and ran into stack corruption to eventually crash the
emulator. This is noticeable in !hw_mac_cursor_accl mode (e.g. fullscreen DGA).

In order to the sigalstack() to be effective, we must kludge the kernel to
think it's running on another stack. In practise, we provide another stack
for the SIGUSR2 handler. sigusr2_handler_init() fulfills that purpose.

I hope this fixes remaining issues forever. At some point, I had multiple
*_init() handlers in case this is necessary.
2005-06-28 16:47:32 +00:00
gbeauche
26ee263b6f Don't fake the TVECT value on non-BeOS native systems. This is important
for systems that use a global r2 as the TLS register, e.g. Linux/ppc with
newer glibc. Also remove the syscall junk which were simply workarounds
for this bug. Remove a duplicate r2 restoration in EmulOp.

BTW, it's possible to get SheepShaver running on Linux/ppc systems with
NPTL rather than SheepThreads.
2005-06-23 16:23:31 +00:00
gbeauche
e423a07632 Recognize POWER5 CPUs. ;-) 2005-06-08 12:12:50 +00:00
gbeauche
f9e3fd28a1 better logics in sigstack allocation on native platforms 2005-03-28 09:50:58 +00:00
gbeauche
d27832cb1c - Implement fullscreen DGA via fbdev access under Linux. Besides, r/w access
to /dev/mem is required on Linux to use XF86 DGA mode. Otherwise, there is
now a fallback to fbdev.
- Forward port some features from Basilisk II (set_window_name,
disable_mouse_accel).
- Don't SIGSTOP the emulation thread on suspend since that would completely
stop the process on Linux. Use a frame buffer lock instead (as B2 does)
2005-03-27 19:05:18 +00:00
gbeauche
663facbf97 Fix native Linux/ppc with recent enough glibc that supports TLS; r2 is used
in that case. Tell me if I broke other arches, e.g. r13 is no longer saved
in Video and Ethernet stubs, though it seems to be OK.

Colateral feature: SheepShaver should now run on Linux/ppc64 with relevant
32-bit runtime. Native Linux/ppc64 support is harder as low mem globals are
32-bit in mind and e.g. the TLS register there is %r13, %r2 is the TOC
(PowerOpen/AIX ABI)
2005-02-27 21:52:06 +00:00
gbeauche
8500381648 Initial support for NetBSD/ppc in native mode (some crashes occur but I
could boot MacOS 9.0.4)
2005-02-20 18:08:50 +00:00
gbeauche
df0d5d2a41 Happy New Year 2005! 2005-01-30 21:48:22 +00:00
gbeauche
f401bb1494 really invalidate caches when ROM was patched in native mode 2005-01-30 21:25:24 +00:00
gbeauche
26314e240e Add InitAll() which covers common initializations so that to avoid duplicate
code and possible bugs (e.g. on BeOS/PPC). Likewise for ExitAll().
2005-01-30 21:19:07 +00:00
gbeauche
9b17e04150 Fix Kernel Data for Gossamer ROMs: PVR, CPUClockSpeed et al. 2005-01-30 18:49:48 +00:00
gbeauche
bf2185c208 fix build on unixish platforms 2004-11-22 23:17:32 +00:00
gbeauche
d6c7e0eb23 New SheepShaver globals layout, move ZeroPage into the middle. Since it is
a read-only page, it can also be used to detect overlaps between Procedure
space and Data space.

Provide native Windows implementation of shared MacOS KernelData allocation.
This is moved under main() so that to avoid a weird linking error. This native
implementation is independent of Cygwin IPC (and possible background server)
2004-11-22 21:33:32 +00:00
gbeauche
3ace37f4eb Implement Direct Addressing mode similarly to Basilisk II. This is to get
SheepShaver working on OSes that don't support maipping of Low Memory globals
at 0x00000000, e.g. Windows.
2004-11-13 14:09:16 +00:00
gbeauche
4f78562642 SDL audio support 2004-07-19 19:42:21 +00:00
gbeauche
b60874907e Better PowerPC / POWER CPU detection from Linux cpu_specs[] table. 2004-07-10 06:15:42 +00:00
gbeauche
9a93480546 Remap any newer G4/G5 processor to plain G4 for compatibility 2004-07-07 04:33:37 +00:00
gbeauche
ebdb5d29fd get timebase-frequency on osx too. 2004-07-04 05:19:44 +00:00
gbeauche
0669b02e5f Introducce TimebaseSpeed which represents exact timebase-frequency instead
of supposing it to be (BusClockSpeed/4), which is no longer true on G5 et al.
2004-07-03 10:39:07 +00:00
gbeauche
32a6ac321c Try to recognize and handle PowerPC 970 (G5). Untested as I don't have such
platforms handy.
2004-07-01 22:55:02 +00:00
gbeauche
eb9961585b Handle 750FX, 7450, 7455, 7457. 2004-06-29 20:25:55 +00:00
gbeauche
380d4f294e Make sure to initialize alt stacks before SIGSEGV handlers 2004-06-26 16:25:22 +00:00
gbeauche
3e5c98c7d4 Performance of VOSF is heuristically determined at run-time, so have to
initialize SIGSEGV handlers early, as in Basilisk II. Besides, also add
missing call to vm_init() in case host system doesn't have MAP_ANON.
2004-06-26 15:26:18 +00:00
gbeauche
0dcb2b4516 SDL support in SheepShaver too, though it doesn't work in native mode
on Linux/ppc as libSDL is pulling in libpthread which conflicts with
our sheepthreads.
2004-06-24 15:37:26 +00:00
gbeauche
e0a76f9e38 Don't handle XLM_IRQ_NEST atomically in emulated mode. That's useless since
this variable is modified only within a single thread and interrupts are
not handled asynchronously.
2004-06-22 17:10:08 +00:00
gbeauche
f2324520b7 Improve timing of periodic threads (from Basilisk II), aka. make 10 seconds
really last 10 seconds, not 18. ;-)
2004-06-22 12:20:17 +00:00
gbeauche
cb46ffe97a Get PVR information et al. through (slow) ioreg -c IOPlatformDevice 2004-06-17 05:15:25 +00:00
gbeauche
374101ee9e Make DR Cache executable by default in native PowerPC mode. 2004-05-31 10:55:42 +00:00
gbeauche
a533a9c455 Enable DR emulator with OldWorld ROMs too. It turned out that translated
code was also trying to access Serial memory.

Note however that I noticed some rare crashes with the DR emulator.
Probably caused by nested runs from EmulOps? We'd really want a native
68k emulator too for Execute68k() things.
2004-05-31 10:02:20 +00:00