From a692777224150e2dadb5ec02c6ecd5c10ce0dd98 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Mon, 18 Mar 2013 00:07:53 -0700 Subject: [PATCH] rt: Inline get_sp_limit/set_sp_limit/get_sp for x86. --- src/rt/arch/i386/record_sp.S | 60 ------------------------------------ src/rt/arch/i386/sp.h | 48 +++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 63 deletions(-) diff --git a/src/rt/arch/i386/record_sp.S b/src/rt/arch/i386/record_sp.S index 20cafa3dffbf5..e69de29bb2d1d 100644 --- a/src/rt/arch/i386/record_sp.S +++ b/src/rt/arch/i386/record_sp.S @@ -1,60 +0,0 @@ -.text - -#if defined(__APPLE__) || defined(_WIN32) -#define RECORD_SP_LIMIT _record_sp_limit -#define GET_SP_LIMIT _get_sp_limit -#define GET_SP _get_sp -#else -#define RECORD_SP_LIMIT record_sp_limit -#define GET_SP_LIMIT get_sp_limit -#define GET_SP get_sp -#endif - -.globl RECORD_SP_LIMIT -.globl GET_SP_LIMIT -.globl GET_SP - -#if defined(__linux__) || defined(__FreeBSD__) -RECORD_SP_LIMIT: - movl 4(%esp), %eax - movl %eax, %gs:48 - ret -#endif - -#if defined(__APPLE__) -RECORD_SP_LIMIT: - movl $0x48+90*4, %eax - movl 4(%esp), %ecx - movl %ecx, %gs:(%eax) - ret -#endif - -#if defined(_WIN32) -RECORD_SP_LIMIT: - movl 4(%esp), %eax - movl %eax, %fs:0x14 - ret -#endif - -#if defined(__linux__) || defined(__FreeBSD__) -GET_SP_LIMIT: - movl %gs:48, %eax - ret -#endif - -#if defined(__APPLE__) -GET_SP_LIMIT: - movl $0x48+90*4, %ecx - movl %gs:(%ecx), %eax - ret -#endif - -#if defined(_WIN32) -GET_SP_LIMIT: - movl %fs:0x14, %eax - ret -#endif - -GET_SP: - movl %esp, %eax - ret diff --git a/src/rt/arch/i386/sp.h b/src/rt/arch/i386/sp.h index cd79884760777..4f4c84c817573 100644 --- a/src/rt/arch/i386/sp.h +++ b/src/rt/arch/i386/sp.h @@ -16,14 +16,56 @@ #include "../../rust_globals.h" // Gets a pointer to the vicinity of the current stack pointer -extern "C" uintptr_t get_sp(); +extern "C" ALWAYS_INLINE uintptr_t get_sp() { + uintptr_t sp; + asm volatile ( + "movl %%esp, %0" + : "=m"(sp)); + return sp; +} // Gets the pointer to the end of the Rust stack from a platform- // specific location in the thread control block -extern "C" CDECL uintptr_t get_sp_limit(); +extern "C" CDECL ALWAYS_INLINE uintptr_t get_sp_limit() { + uintptr_t limit; + +#if defined(__linux__) || defined(__FreeBSD__) + asm volatile ( + "movl %%gs:48, %0" + : "=r"(limit)); +#elif defined(__APPLE__) + asm volatile ( + "movl $0x48+90*4, %%ecx\n\t" + "movl %%gs:(%%ecx), %0" + : "=r"(limit) + :: "ecx"); +#elif defined(_WIN32) + asm volatile ( + "movl %%fs:0x14, %0" + : "=r"(limit)); +#endif + + return limit; +} // Records the pointer to the end of the Rust stack in a platform- // specific location in the thread control block -extern "C" CDECL void record_sp_limit(void *limit); +extern "C" CDECL ALWAYS_INLINE void record_sp_limit(void *limit) { +#if defined(__linux__) || defined(__FreeBSD__) + asm volatile ( + "movl %0, %%gs:48" + :: "r"(limit)); +#elif defined(__APPLE__) + asm volatile ( + "movl $0x48+90*4, %%eax\n\t" + "movl %0, %%gs:(%%eax)" + :: "r"(limit) + : "eax"); +#elif defined(_WIN32) + asm volatile ( + "movl %0, %%fs:0x14" + :: "r"(limit)); +#endif +} #endif