Skip to content

Commit

Permalink
rt: Inline get_sp_limit/set_sp_limit/get_sp for x86.
Browse files Browse the repository at this point in the history
  • Loading branch information
luqmana committed Mar 18, 2013
1 parent d177876 commit a692777
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 63 deletions.
60 changes: 0 additions & 60 deletions src/rt/arch/i386/record_sp.S
Original file line number Diff line number Diff line change
@@ -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
48 changes: 45 additions & 3 deletions src/rt/arch/i386/sp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 comments on commit a692777

@bors
Copy link
Contributor

@bors bors commented on a692777 Mar 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at luqmana@a692777

@bors
Copy link
Contributor

@bors bors commented on a692777 Mar 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging luqmana/rust/inline-rt = a692777 into auto

@bors
Copy link
Contributor

@bors bors commented on a692777 Mar 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

luqmana/rust/inline-rt = a692777 merged ok, testing candidate = 6d4499c

@bors
Copy link
Contributor

@bors bors commented on a692777 Mar 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a692777 Mar 25, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 6d4499c

Please sign in to comment.