about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLuqman Aden <me@luqman.ca>2013-03-18 00:07:53 -0700
committerLuqman Aden <me@luqman.ca>2013-03-18 00:07:53 -0700
commita692777224150e2dadb5ec02c6ecd5c10ce0dd98 (patch)
tree325868bbf654f2964ae7e82d71d4a6b7b909ef44
parentd1778767cca290e844d5aa9d044dcc2f9edc9d8c (diff)
downloadrust-a692777224150e2dadb5ec02c6ecd5c10ce0dd98.tar.gz
rust-a692777224150e2dadb5ec02c6ecd5c10ce0dd98.zip
rt: Inline get_sp_limit/set_sp_limit/get_sp for x86.
-rw-r--r--src/rt/arch/i386/record_sp.S60
-rw-r--r--src/rt/arch/i386/sp.h48
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 20cafa3dffb..e69de29bb2d 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 cd798847607..4f4c84c8175 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