rt: Inline get_sp_limit/set_sp_limit/get_sp for x86.

This commit is contained in:
Luqman Aden 2013-03-18 00:07:53 -07:00
parent d1778767cc
commit a692777224
2 changed files with 45 additions and 63 deletions

View file

@ -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

View file

@ -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