Add XLM_ZERO_PAGE globals which points to a read-only page with all bits

set to zero.
This commit is contained in:
gbeauche 2003-12-05 12:36:11 +00:00
parent 091a219280
commit 44e54f730a
4 changed files with 31 additions and 4 deletions

View File

@ -220,8 +220,9 @@ system_info SysInfo; // System information
static void *sig_stack = NULL; // Stack for signal handlers
static void *extra_stack = NULL; // Stack for SIGSEGV inside interrupt handler
static uintptr SheepMem::base; // Address of SheepShaver data
static uintptr SheepMem::top; // Top of SheepShaver data (stack like storage)
uintptr SheepMem::zero_page = 0; // Address of ro page filled in with zeros
uintptr SheepMem::base; // Address of SheepShaver data
uintptr SheepMem::top; // Top of SheepShaver data (stack like storage)
static area_id SheepMemArea; // SheepShaver data area ID
@ -578,6 +579,7 @@ void SheepShaver::StartEmulator(void)
WriteMacInt32(XLM_PVR, PVR); // Theoretical PVR
WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed); // For DriverServicesLib patch
WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN); // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode)
WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage()); // Pointer to read-only page with all bits set to 0
#if !EMULATED_PPC
WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator
WriteMacInt32(XLM_ETHER_INIT, *(uint32 *)InitStreamModule); // DLPI ethernet driver functions
@ -2079,6 +2081,10 @@ bool SheepMem::Init(void)
if (SheepMemArea < 0)
return false;
// Create read-only area with all bits set to 0
static const uint8 const_zero_page[4096] = {0,};
zero_page = const_zero_page;
D(bug("SheepShaver area %ld at %p\n", SheepMemArea, base));
top = base + size;
return true;

View File

@ -213,6 +213,7 @@ static bool emul_thread_fatal = false; // Flag: MacOS thread crashed, tick thre
static sigregs sigsegv_regs; // Register dump when crashed
#endif
uintptr SheepMem::zero_page = 0; // Address of ro page filled in with zeros
uintptr SheepMem::base = 0x60000000; // Address of SheepShaver data
uintptr SheepMem::top = 0; // Top of SheepShaver data (stack like storage)
@ -672,6 +673,7 @@ int main(int argc, char **argv)
WriteMacInt32(XLM_PVR, PVR); // Theoretical PVR
WriteMacInt32(XLM_BUS_CLOCK, BusClockSpeed); // For DriverServicesLib patch
WriteMacInt16(XLM_EXEC_RETURN_OPCODE, M68K_EXEC_RETURN); // For Execute68k() (RTS from the executed 68k code will jump here and end 68k mode)
WriteMacInt32(XLM_ZERO_PAGE, SheepMem::ZeroPage()); // Pointer to read-only page with all bits set to 0
#if !EMULATED_PPC
WriteMacInt32(XLM_TOC, (uint32)TOC); // TOC pointer of emulator
#endif
@ -1773,14 +1775,25 @@ bool SheepMem::Init(void)
{
if (vm_acquire_fixed((char *)base, size) < 0)
return false;
zero_page = base + size;
int page_size = getpagesize();
if (vm_acquire_fixed((char *)zero_page, page_size) < 0)
return false;
if (vm_protect((char *)zero_page, page_size, VM_PAGE_READ) < 0)
return false;
top = base + size;
return true;
}
void SheepMem::Exit(void)
{
if (top)
vm_release((void *)base, size);
if (top) {
// The zero page is next to SheepShaver globals
vm_release((void *)base, size + getpagesize());
}
}

View File

@ -79,12 +79,14 @@ extern uint32 NativeFunction(int selector);
class SheepMem {
static uint32 align(uint32 size);
protected:
static uintptr zero_page;
static uintptr base;
static uintptr top;
static const uint32 size = 0x40000;
public:
static bool Init(void);
static void Exit(void);
static uintptr ZeroPage();
static uintptr Reserve(uint32 size);
static void Release(uint32 size);
friend class SheepVar;
@ -96,6 +98,11 @@ inline uint32 SheepMem::align(uint32 size)
return (size + 3) & -4;
}
inline uintptr SheepMem::ZeroPage()
{
return zero_page;
}
inline uintptr SheepMem::Reserve(uint32 size)
{
top -= align(size);

View File

@ -46,6 +46,7 @@
#define XLM_GET_1_IND_RESOURCE 0x2844 // Pointer to native Get1IndResource() routine
#define XLM_R_GET_RESOURCE 0x2848 // Pointer to native RGetResource() routine
#define XLM_EXEC_RETURN_OPCODE 0x284c // EXEC_RETURN opcode for Execute68k()
#define XLM_ZERO_PAGE 0x2850 // Pointer to read-only page with all bits set to 0
#define XLM_ETHER_INIT 0x28c0 // Pointer to ethernet InitStreamModule() function
#define XLM_ETHER_TERM 0x28c4 // Pointer to ethernet TerminateStreamModule() function