From 00b6a4565e8e39f432e48511de374e6fb8a619b8 Mon Sep 17 00:00:00 2001 From: "fur%netscape.com" Date: Sun, 28 Feb 1999 00:18:23 +0000 Subject: [PATCH] A bunch of grunge work to reduce the amount of OS-dependent code in ElectricalFire sources. The end result eliminated nearly all of the differences between FreeBSD and Linux in the source code. It also increased the amount of sharing between Win32 and unix code. + Renamed files and classes that were inappropriately named, i.e. the names started with 'x86Win32', but the code was for generic x86, not specific to Win32. + Eliminated several gratuitous duplicated files, e.g. x86Linux.s and x86FreeBSD.s were essentially identical. + Shared code that had been duplicated in x86Win32_Support.cpp, x86Linux_Support.cpp and x86FreeBSD_Support.cpp. Created x86GenStub.cpp, which contains only XP code, to replace them all. git-svn-id: svn://10.0.0.236/trunk@22373 18797224-902f-48f8-a5cc-f745e15eee43 --- .../ef/Compiler/CodeGenerator/md/x86/Makefile | 17 +-- .../CodeGenerator/md/x86/x86Emitter.cpp | 28 +--- .../md/x86/x86FreeBSD_Support.cpp | 125 ----------------- .../CodeGenerator/md/x86/x86FreeBSD_Support.h | 31 ---- .../CodeGenerator/md/x86/x86Linux_Support.cpp | 132 ------------------ .../CodeGenerator/md/x86/x86Linux_Support.h | 31 ---- .../md/x86/{x86FreeBSD.s => x86Stub_gas.s} | 40 +++--- 7 files changed, 25 insertions(+), 379 deletions(-) delete mode 100644 mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD_Support.cpp delete mode 100644 mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD_Support.h delete mode 100644 mozilla/ef/Compiler/CodeGenerator/md/x86/x86Linux_Support.cpp delete mode 100644 mozilla/ef/Compiler/CodeGenerator/md/x86/x86Linux_Support.h rename mozilla/ef/Compiler/CodeGenerator/md/x86/{x86FreeBSD.s => x86Stub_gas.s} (95%) diff --git a/mozilla/ef/Compiler/CodeGenerator/md/x86/Makefile b/mozilla/ef/Compiler/CodeGenerator/md/x86/Makefile index f3dc079aed0..526b70b0e66 100644 --- a/mozilla/ef/Compiler/CodeGenerator/md/x86/Makefile +++ b/mozilla/ef/Compiler/CodeGenerator/md/x86/Makefile @@ -28,6 +28,7 @@ CPPSRCS = x86.nad.burg.cpp \ x86Emitter.cpp \ x86Float.cpp \ x86Formatter.cpp \ + x86GenStub.cpp \ x86Instruction.cpp \ x86StdCall.cpp \ $(OS_SUPPORT) \ @@ -36,8 +37,6 @@ CPPSRCS = x86.nad.burg.cpp \ LOCAL_MD_EXPORTS_x86 = x86ArgumentList.h \ x86Float.h \ x86Formatter.h \ - x86Linux_Support.h \ - x86FreeBSD_Support.h \ x86Opcode.h \ x86StdCall.h \ x86Cpu.h \ @@ -61,17 +60,9 @@ include $(DEPTH)/config/config.mk # Generation of OS-specific support files # ifeq ($(OS_ARCH),WINNT) -OS_SUPPORT = x86Win32_Support.cpp -endif - -ifeq ($(OS_ARCH),Linux) -ASFILES = x86Linux.s -OS_SUPPORT = x86Linux_Support.cpp -endif - -ifeq ($(OS_ARCH),FreeBSD) -ASFILES = x86FreeBSD.s -OS_SUPPORT = x86FreeBSD_Support.cpp +OS_SUPPORT = x86Stub.cpp +else +ASFILES = x86Stub_gas.s endif ####################################################################### diff --git a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Emitter.cpp b/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Emitter.cpp index d35c0197c60..ff7149f9e90 100644 --- a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Emitter.cpp +++ b/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Emitter.cpp @@ -694,33 +694,7 @@ emit_Logic_L(Primitive& inPrimitive, x86DoubleOpDirCode insnType) redefineTemporary(insnHi, vrHi, 0); } -#if defined(WIN32) -# include "x86Arith64.h" -#elif defined(LINUX) || defined(FREEBSD) -extern "C" { -extern void x86Mul64Bit(void); -extern void x86Div64Bit(void); -extern void x86Mod64Bit(void); -extern void x86Shl64Bit(void); -extern void x86Shr64Bit(void); -extern void x86Sar64Bit(void); -extern void x86ThreeWayCMP_L(void); -extern void x86ThreeWayCMPC_L(void) {trespass("Not implemented");} -extern void x86Extract64Bit(void); -}; -#endif - -#if !defined(WIN32) && !defined(LINUX) && !defined(FREEBSD) -static void x86Mul64Bit() {trespass("Not implemented");} -static void x86Div64Bit() {trespass("Not implemented");} -static void x86Mod64Bit() {trespass("Not implemented");} -static void x86Shl64Bit() {trespass("Not implemented");} -static void x86Shr64Bit() {trespass("Not implemented");} -static void x86Sar64Bit() {trespass("Not implemented");} -static void x86ThreeWayCMP_L() {trespass("Not implemented");} -static void x86ThreeWayCMPC_L() {trespass("Not implemented");} -static void x86Extract64Bit() {trespass("Not implemented");} -#endif +#include "x86Arith64.h" void x86Emitter:: emit_Mul_L(Primitive& inPrimitive) diff --git a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD_Support.cpp b/mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD_Support.cpp deleted file mode 100644 index c2d46f65bd3..00000000000 --- a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD_Support.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -/* - x86FreeBSD_Support.cpp -*/ - -#include "NativeCodeCache.h" -#include -#include "Fundamentals.h" -#include "MemoryAccess.h" -#include "x86FreeBSD_Support.h" - - -void* JNIenv = 0; - -extern ClassWorld world; - -#ifdef DEBUG -// Pointer to the instruction after the call (used by exception handler to check -// I wanted to use: -// void* compileStubReEntryPoint = (void*) ((Uint8*)staticCompileStub + 17); -// but MSDev appears to have a bug, in that compileStubReEntryPoint will be set == (void*)staticCompileStub -// which is clearly wrong. -void* compileStubAddress = (void*)staticCompileStub; -void* compileStubReEntryPoint = (Uint8*)compileStubAddress + 17; -#endif // DEBUG - -void * -generateNativeStub(NativeCodeCache& inCache, const CacheEntry& inCacheEntry, void *nativeFunction) -{ - Method* method = inCacheEntry.descriptor.method; - Uint32 nWords = method->getSignature().nArguments; - - assert(method->getModifiers() & CR_METHOD_NATIVE); - - extern Uint32 sysInvokeNativeStubs[]; - Uint8 stubSize = 10; - void* stub; - - // Write out the native stub - stub = inCache.acquireMemory(stubSize); - Uint8* where = (Uint8*)stub; - *where++ = 0x68; // pushl - writeLittleWordUnaligned(where, (uint32)(nativeFunction)); - where += 4; - *where++ = 0xe9; // jmp - writeLittleWordUnaligned(where, (Uint8 *) sysInvokeNativeStubs[nWords] - (where + 4)); - - // Return the address of the stub. - return ((void*)stub); -} - -void * -generateJNIGlue(NativeCodeCache& inCache, - const CacheEntry& inCacheEntry, - void *nativeFunction) -{ - void* stub; - Method* method = inCacheEntry.descriptor.method; - assert(method->getModifiers() & CR_METHOD_NATIVE); - - Uint8 stubSize = 12; - - // Write out the JNI compile stub - stub = inCache.acquireMemory(stubSize); - Uint8* where = (Uint8*) stub; - *where++ = 0x58; // popl %eax - *where++ = 0x68; // pushl - writeLittleWordUnaligned(where, (Uint32) JNIenv); - where += 4; - *where++ = 0xe9; // jmp - writeLittleWordUnaligned(where, reinterpret_cast(nativeFunction) - Uint32(where + 4)); - return stub; -} - -void * -generateCompileStub(NativeCodeCache& inCache, const CacheEntry& inCacheEntry) -{ - void* stub; - uint8 stubSize = 10; - - // Write out the dynamic compile stub - stub = inCache.acquireMemory(stubSize); - Uint8* where = (Uint8*)stub; - *where++ = 0x68; // pushl - writeLittleWordUnaligned(where, (uint32)(&inCacheEntry)); - where += 4; - *where++ = 0xe9; // jmp - writeLittleWordUnaligned(where, (Uint8 *) staticCompileStub - (where + 4)); - - // Return the address of the dynamic stub. - return ((void*)stub); -} - -void* -backPatchMethod(void* inMethodAddress, void* inLastPC, void* /*inUserDefined*/) -{ - - uint32 curAddress = (uint32) inLastPC; - uint32 methodAddress = (uint32) inMethodAddress; - - // Compute the relative branch - uint32* relativeBranch = ((uint32*)inLastPC)-1; - int32 offset = methodAddress - curAddress; - - // Backpatch the method. - writeLittleWordUnaligned((void*)relativeBranch, offset); - - return (inMethodAddress); -} diff --git a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD_Support.h b/mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD_Support.h deleted file mode 100644 index fff5dcec58c..00000000000 --- a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD_Support.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef _X86_FREEBSD_SUPPORT_H_ -#define _X86_FREEBSD_SUPPORT_H_ - -#include "prtypes.h" - -PR_BEGIN_EXTERN_C - -extern void staticCompileStub(); - -PR_END_EXTERN_C - -#endif // _X86_FREEBSD_SUPPORT_H_ - diff --git a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Linux_Support.cpp b/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Linux_Support.cpp deleted file mode 100644 index 7db239cfa43..00000000000 --- a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Linux_Support.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -/* - x86Linux_Support.cpp -*/ - -#include "NativeCodeCache.h" -#include -#include "Fundamentals.h" -#include "MemoryAccess.h" -#include "x86Linux_Support.h" - - -void* JNIenv = 0; - -extern ClassWorld world; - -#ifdef DEBUG -// Pointer to the instruction after the call (used by exception handler to check -// I wanted to use: -// void* compileStubReEntryPoint = (void*) ((Uint8*)staticCompileStub + 17); -// but MSDev appears to have a bug, in that compileStubReEntryPoint will be set == (void*)staticCompileStub -// which is clearly wrong. -void* compileStubAddress = (void*)staticCompileStub; -void* compileStubReEntryPoint = (Uint8*)compileStubAddress + 17; -#endif // DEBUG - -void * -generateJNIGlue(NativeCodeCache& inCache, - const CacheEntry& inCacheEntry, - void *nativeFunction) -{ - void* stub; - Method* method = inCacheEntry.descriptor.method; - assert(method->getModifiers() & CR_METHOD_NATIVE); - - Uint8 stubSize = 12; - - // Write out the JNI compile stub - stub = inCache.acquireMemory(stubSize); - Uint8* where = (Uint8*) stub; - *where++ = 0x58; // popl %eax - *where++ = 0x68; // pushl - writeLittleWordUnaligned(where, (Uint32) JNIenv); - where += 4; - *where++ = 0xe9; // jmp - writeLittleWordUnaligned(where, reinterpret_cast(nativeFunction) - Uint32(where + 4)); - return stub; -} - -void * -generateNativeStub(NativeCodeCache& inCache, const CacheEntry& inCacheEntry, void *nativeFunction) -{ - Method* method = inCacheEntry.descriptor.method; - Uint32 nWords = method->getArgsSize()/sizeof(Int32); - - assert(method->getModifiers() & CR_METHOD_NATIVE); - assert(nWords <= 256); - - extern Uint32 sysInvokeNativeStubs[]; - Uint8 stubSize = 10; - void* stub; - - // Write out the native stub - stub = inCache.acquireMemory(stubSize); - Uint8* where = (Uint8*)stub; - *where++ = 0x68; // pushl - writeLittleWordUnaligned(where, (uint32)(nativeFunction)); - where += 4; - *where++ = 0xe9; // jmp - writeLittleWordUnaligned(where, (Uint8 *) sysInvokeNativeStubs[nWords] - (where + 4)); - - // Return the address of the stub. - return ((void*)stub); -} - -void * -generateCompileStub(NativeCodeCache& inCache, const CacheEntry& inCacheEntry) -{ - void* stub; - Uint8* where; - - Uint8 stubSize = 10; - - // Write out the dynamic compile stub - stub = inCache.acquireMemory(stubSize); - where = (Uint8*)stub; - - // movl $inCacheEntry, %eax - *where++ = 0xb8; - writeLittleWordUnaligned(where, (uint32)&inCacheEntry); - where += 4; - - // jmp compileStub - *where++ = 0xe9; // jmp - writeLittleWordUnaligned(where, (Uint8 *) staticCompileStub - (where + 4)); - - // Return the address of the dynamic stub. - return ((void*)stub); -} - -void* -backPatchMethod(void* inMethodAddress, void* inLastPC, void* /*inUserDefined*/) -{ - - uint32 curAddress = (uint32) inLastPC; - uint32 methodAddress = (uint32) inMethodAddress; - - // Compute the relative branch - uint32* relativeBranch = ((uint32*)inLastPC)-1; - int32 offset = methodAddress - curAddress; - - // Backpatch the method. - writeLittleWordUnaligned((void*)relativeBranch, offset); - - return (inMethodAddress); -} diff --git a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Linux_Support.h b/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Linux_Support.h deleted file mode 100644 index 9f52c26bece..00000000000 --- a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Linux_Support.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef _X86_LINUX_SUPPORT_H_ -#define _X86_LINUX_SUPPORT_H_ - -#include "prtypes.h" - -PR_BEGIN_EXTERN_C - -extern void staticCompileStub(); - -PR_END_EXTERN_C - -#endif // _X86_LINUX_SUPPORT_H_ - diff --git a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD.s b/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Stub_gas.s similarity index 95% rename from mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD.s rename to mozilla/ef/Compiler/CodeGenerator/md/x86/x86Stub_gas.s index a3f1220597b..7d47f2aa428 100644 --- a/mozilla/ef/Compiler/CodeGenerator/md/x86/x86FreeBSD.s +++ b/mozilla/ef/Compiler/CodeGenerator/md/x86/x86Stub_gas.s @@ -16,7 +16,7 @@ * Reserved. */ - .file "x86FreeBSD.S" + .file "x86Linux.S" #define ALIGN .align 16 #define SYMBOL_NAME(name) name @@ -35,29 +35,29 @@ GLOBAL_ENTRY_START(staticCompileStub) - push %eax /* Save all volatiles */ - push %ebx - push %ecx - push %edx - push 20(%esp) /* Push the second argument to compileAndBackPatchMethod (return address) */ - push 20(%esp) /* Push the first argument to compileAndBackPatchMethod (cacheEntry) */ + push %ebp /* Make stack frame */ + mov %esp,%ebp + + /* Even though ESI and EDI are non-volatile (callee-saved) registers, we need to + preserve them here in case an exception is thrown. The exception-handling + code expects to encounter this specially-prepared stack "guard" frame when + unwinding the stack. See x86ExceptionHandler.cpp. */ + push %edi + push %esi + push %ebx /* XXX - Why push EBX ? It's caller-saved */ + + /* Call compileAndBackPatchMethod() with 2 args */ + push 16(%esp) /* Push the second argument to compileAndBackPatchMethod (return address) */ + push %eax /* Push the first argument to compileAndBackPatchMethod (cacheEntry) */ call compileAndBackPatchMethod - pop %edx /* Remove passes arguments */ - pop %edx /* Remove passes arguments */ - mov %eax, 16(%esp) /* Overwrite cacheEntry with function address */ - pop %edx /* Restore volatiles */ - pop %ecx - pop %ebx - pop %eax - ret /* Jump to function leaving the return address at the top of the stack */ + + mov %ebp,%esp /* Pop stack frame */ + pop %ebp + + jmp *%eax /* Jump to function leaving the return address at the top of the stack */ GLOBAL_ENTRY_END(staticCompileStub) -GLOBAL_ENTRY_START(compileStub) - push 0xefbeadde /* This is a dummy immediate that will be filled in by */ - jmp staticCompileStub /* generateCompileStub with the cacheEntry */ -GLOBAL_ENTRY_END(compileStub) - /* * 64bit Arithmetic Support Functions *