ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/user_strings_unix.cpp
Revision: 1.19
Committed: 2009-08-18T18:26:11Z (15 years, 3 months ago) by asvitkine
Branch: MAIN
CVS Tags: HEAD
Changes since 1.18: +2 -0 lines
Log Message:
[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.

File Contents

# Content
1 /*
2 * user_strings_unix.cpp - Localizable strings, Unix specific strings
3 *
4 * SheepShaver (C) 1997-2008 Christian Bauer and Marc Hellwig
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "sysdeps.h"
22 #include "user_strings.h"
23
24
25 // Platform-specific string definitions
26 user_string_def platform_strings[] = {
27 // Common strings that have a platform-specific variant
28 {STR_VOLUME_IS_MOUNTED_WARN, "The volume '%s' is mounted under Linux. Basilisk II will try to unmount it."},
29 {STR_EXTFS_CTRL, "Unix Root"},
30 {STR_EXTFS_NAME, "Unix Directory Tree"},
31 {STR_EXTFS_VOLUME_NAME, "Unix"},
32
33 // Purely platform-specific strings
34 {STR_NO_DEV_ZERO_ERR, "Cannot open /dev/zero: %s."},
35 {STR_LOW_MEM_MMAP_ERR, "Cannot map Low Memory Globals: %s."},
36 {STR_KD_SHMGET_ERR, "Cannot create SHM segment for Kernel Data: %s."},
37 {STR_KD_SHMAT_ERR, "Cannot map first Kernel Data area: %s."},
38 {STR_KD2_SHMAT_ERR, "Cannot map second Kernel Data area: %s."},
39 {STR_ROM_MMAP_ERR, "Cannot map ROM: %s."},
40 {STR_RAM_MMAP_ERR, "Cannot map RAM: %s."},
41 {STR_RAM_ROM_MMAP_ERR, "Cannot map area for RAM and ROM: %s."},
42 {STR_RAM_AREA_TOO_HIGH_ERR, "Cannot map usable RAM area. Try to decrease the MacOS RAM size."},
43 {STR_DR_CACHE_MMAP_ERR, "Cannot map DR Cache: %s."},
44 {STR_DR_EMULATOR_MMAP_ERR, "Cannot map DR Emulator: %s."},
45 {STR_SHEEP_MEM_MMAP_ERR, "Cannot map SheepShaver Data area: %s."},
46 {STR_SIGALTSTACK_ERR, "Cannot install alternate signal stack (%s). It seems that you need a newer kernel."},
47 {STR_SIG_INSTALL_ERR, "Cannot install %s handler (%s)."},
48 {STR_NO_XSERVER_ERR, "Cannot connect to X server %s."},
49 {STR_NO_XVISUAL_ERR, "Cannot obtain appropriate X visual."},
50 {STR_UNSUPP_DEPTH_ERR, "Unsupported color depth of screen."},
51 {STR_PROC_CPUINFO_WARN, "Cannot open /proc/cpuinfo (%s). Assuming 100MHz PowerPC 604."},
52 {STR_BLOCKING_NET_SOCKET_WARN, "Cannot set non-blocking I/O to net socket (%s). Ethernet will not be available."},
53 {STR_NO_SHEEP_NET_DRIVER_WARN, "Cannot open %s (%s). Ethernet will not be available."},
54 {STR_SHEEP_NET_ATTACH_WARN, "Cannot attach to Ethernet card (%s). Ethernet will not be available."},
55 {STR_TUN_TAP_CONFIG_WARN, "Cannot configure TUN/TAP device (%s). Ethernet will not be available."},
56 {STR_SLIRP_NO_DNS_FOUND_WARN, "Cannot get DNS address. Ethernet will not be available."},
57 {STR_NO_AUDIO_DEV_WARN, "Cannot open %s (%s). Audio output will be disabled."},
58 {STR_NO_AUDIO_WARN, "No audio device found, audio output will be disabled."},
59 {STR_NO_ESD_WARN, "Cannot open ESD connection. Audio output will be disabled."},
60 {STR_AUDIO_FORMAT_WARN, "/dev/dsp doesn't support signed 16 bit format. Audio output will be disabled."},
61 {STR_SCSI_DEVICE_OPEN_WARN, "Cannot open %s (%s). SCSI Manager access to this device will be disabled."},
62 {STR_SCSI_DEVICE_NOT_SCSI_WARN, "%s doesn't seem to comply to the Generic SCSI API. SCSI Manager access to this device will be disabled."},
63 {STR_KEYCODE_FILE_WARN, "Cannot open keycode translation file %s (%s)."},
64 {STR_KEYCODE_VENDOR_WARN, "Cannot find vendor '%s' in keycode translation file %s."},
65 {STR_PREFS_MENU_FILE_GTK, "/_File"},
66 {STR_PREFS_ITEM_START_GTK, "/File/_Start SheepShaver"},
67 {STR_PREFS_ITEM_ZAP_PRAM_GTK, "/File/_Zap PRAM File"},
68 {STR_PREFS_ITEM_SEPL_GTK, "/File/sepl"},
69 {STR_PREFS_ITEM_QUIT_GTK, "/File/_Quit SheepShaver"},
70 {STR_HELP_MENU_GTK, "/_Help"},
71 {STR_HELP_ITEM_ABOUT_GTK, "/Help/_About SheepShaver"},
72 {STR_DSPDEVICE_FILE_CTRL, "Audio Output Device"},
73 {STR_MIXERDEVICE_FILE_CTRL, "Audio Mixer Device"},
74 {STR_BROWSE_TITLE, "Browse file"},
75 {STR_BROWSE_CTRL, "Browse..."},
76 {STR_INPUT_PANE_TITLE, "Keyboard/Mouse"},
77 {STR_KEYCODES_CTRL, "Use Raw Keycodes"},
78 {STR_KEYCODE_FILE_CTRL, "Keycode Translation File"},
79 {STR_MOUSEWHEELMODE_CTRL, "Mouse Wheel Function"},
80 {STR_MOUSEWHEELMODE_PAGE_LAB, "Page Up/Down"},
81 {STR_MOUSEWHEELMODE_CURSOR_LAB, "Cursor Up/Down"},
82 {STR_MOUSEWHEELLINES_CTRL, "Lines To Scroll"},
83 {STR_SUSPEND_WINDOW_TITLE, "SheepShaver suspended. Press Space to reactivate."},
84 {STR_VOSF_INIT_ERR, "Cannot initialize Video on SEGV signals."},
85
86 {STR_OPEN_WINDOW_ERR, "Cannot open Mac window."},
87 {STR_WINDOW_TITLE_GRABBED, "SheepShaver (mouse grabbed, press Ctrl-F5 to release)"},
88
89 {STR_NO_B2_EXE_FOUND, "Could not start %s (%s)."},
90
91 {-1, NULL} // End marker
92 };
93
94
95 /*
96 * Fetch pointer to string, given the string number
97 */
98
99 const char *GetString(int num)
100 {
101 // First search for platform-specific string
102 int i = 0;
103 while (platform_strings[i].num >= 0) {
104 if (platform_strings[i].num == num)
105 return platform_strings[i].str;
106 i++;
107 }
108
109 // Not found, search for common string
110 i = 0;
111 while (common_strings[i].num >= 0) {
112 if (common_strings[i].num == num)
113 return common_strings[i].str;
114 i++;
115 }
116 return NULL;
117 }