Skip to content

Commit 91b1db6

Browse files
committed
---
yaml --- r: 6215 b: refs/heads/master c: ff5b319 h: refs/heads/master i: 6213: ef5b097 6211: 83f8578 6207: add8616 v: v3
1 parent 9749b16 commit 91b1db6

File tree

7 files changed

+63
-61
lines changed

7 files changed

+63
-61
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 2edd3135adcf4a3812487df75c503a95fbbc1a38
2+
refs/heads/master: ff5b319ce551e6b9b79ce8f127e25d26d0f4d085

trunk/mk/rt.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ RUNTIME_HDR_$(1) := rt/globals.h \
106106
rt/test/rust_test_harness.h \
107107
rt/test/rust_test_runtime.h \
108108
rt/test/rust_test_util.h \
109-
rt/arch/$$(HOST_$(1))/context.h
109+
rt/arch/$$(HOST_$(1))/context.h \
110+
rt/arch/$$(HOST_$(1))/regs.h
110111

111112
ifeq ($$(HOST_$(1)), i386)
112113
LIBUV_ARCH_$(1) := ia32

trunk/src/rt/arch/i386/regs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is not used by i386, but we keep it here so all
2+
// architectures have the same set of header files.

trunk/src/rt/arch/x86_64/_context.S

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
#include "x86_64_regs.h"
2-
1+
#include "regs.h"
2+
#define ARG0 RUSTRT_ARG0_S
3+
#define ARG1 RUSTRT_ARG1_S
4+
35
.text
46

57
/*
@@ -41,7 +43,10 @@ First four arguments:
4143
/*
4244
Stores current registers into arg0/RCX and restores
4345
registers found in arg1/RDX. This is used by our
44-
implementation of getcontext.
46+
implementation of getcontext. Only saves/restores nonvolatile
47+
registers and the register used for the first argument.
48+
Volatile registers in general ought to be saved by the caller
49+
anyhow.
4550
*/
4651

4752
// swap_registers(registers_t *oregs, registers_t *regs)
@@ -56,60 +61,53 @@ swap_registers:
5661
// return address. We can therefore just return normally to
5762
// jump back into the old code.
5863

59-
# if defined(RUSTRT_ARG0_S)
60-
mov RUSTRT_ARG0_S, %rdi
61-
mov RUSTRT_ARG1_S, %rsi
62-
# endif
63-
6464
// Save instruction pointer:
6565
pop %rax
66-
mov %rax, (RUSTRT_IP*8)(%rdi)
66+
mov %rax, (RUSTRT_IP*8)(RUSTRT_ARG0_S)
6767

6868
// Save non-volatile integer registers:
6969
// (including RSP)
70-
mov %rbx, (RUSTRT_RBX*8)(%rdi)
71-
mov %rsp, (RUSTRT_RSP*8)(%rdi)
72-
mov %rbp, (RUSTRT_RBP*8)(%rdi)
73-
mov %r12, (RUSTRT_R12*8)(%rdi)
74-
mov %r13, (RUSTRT_R13*8)(%rdi)
75-
mov %r14, (RUSTRT_R14*8)(%rdi)
76-
mov %r15, (RUSTRT_R15*8)(%rdi)
77-
78-
// Save relevant argument registers:
79-
mov %rcx, (RUSTRT_RCX*8)(%rdi)
80-
mov %rdi, (RUSTRT_RDI*8)(%rdi)
70+
mov %rbx, (RUSTRT_RBX*8)(ARG0)
71+
mov %rsp, (RUSTRT_RSP*8)(ARG0)
72+
mov %rbp, (RUSTRT_RBP*8)(ARG0)
73+
mov %r12, (RUSTRT_R12*8)(ARG0)
74+
mov %r13, (RUSTRT_R13*8)(ARG0)
75+
mov %r14, (RUSTRT_R14*8)(ARG0)
76+
mov %r15, (RUSTRT_R15*8)(ARG0)
77+
78+
// Save 0th argument register:
79+
mov ARG0, (RUSTRT_ARG0*8)(ARG0)
8180

8281
// Save non-volatile XMM registers:
83-
movapd %xmm0, (RUSTRT_XMM0*8)(%rdi)
84-
movapd %xmm1, (RUSTRT_XMM1*8)(%rdi)
85-
movapd %xmm2, (RUSTRT_XMM2*8)(%rdi)
86-
movapd %xmm3, (RUSTRT_XMM3*8)(%rdi)
87-
movapd %xmm4, (RUSTRT_XMM4*8)(%rdi)
88-
movapd %xmm5, (RUSTRT_XMM5*8)(%rdi)
82+
movapd %xmm0, (RUSTRT_XMM0*8)(ARG0)
83+
movapd %xmm1, (RUSTRT_XMM1*8)(ARG0)
84+
movapd %xmm2, (RUSTRT_XMM2*8)(ARG0)
85+
movapd %xmm3, (RUSTRT_XMM3*8)(ARG0)
86+
movapd %xmm4, (RUSTRT_XMM4*8)(ARG0)
87+
movapd %xmm5, (RUSTRT_XMM5*8)(ARG0)
8988

9089
// Restore non-volatile integer registers:
9190
// (including RSP)
92-
mov (RUSTRT_RBX*8)(%rsi), %rbx
93-
mov (RUSTRT_RSP*8)(%rsi), %rsp
94-
mov (RUSTRT_RBP*8)(%rsi), %rbp
95-
mov (RUSTRT_R12*8)(%rsi), %r12
96-
mov (RUSTRT_R13*8)(%rsi), %r13
97-
mov (RUSTRT_R14*8)(%rsi), %r14
98-
mov (RUSTRT_R15*8)(%rsi), %r15
99-
100-
// Restore relevant argument registers:
101-
mov (RUSTRT_RCX*8)(%rsi), %rcx
102-
mov (RUSTRT_RDI*8)(%rsi), %rdi
91+
mov (RUSTRT_RBX*8)(ARG1), %rbx
92+
mov (RUSTRT_RSP*8)(ARG1), %rsp
93+
mov (RUSTRT_RBP*8)(ARG1), %rbp
94+
mov (RUSTRT_R12*8)(ARG1), %r12
95+
mov (RUSTRT_R13*8)(ARG1), %r13
96+
mov (RUSTRT_R14*8)(ARG1), %r14
97+
mov (RUSTRT_R15*8)(ARG1), %r15
98+
99+
// Restore 0th argument register:
100+
mov (RUSTRT_ARG0*8)(ARG1), ARG0
103101

104102
// Restore non-volatile XMM registers:
105-
movapd (RUSTRT_XMM0*8)(%rsi), %xmm0
106-
movapd (RUSTRT_XMM1*8)(%rsi), %xmm1
107-
movapd (RUSTRT_XMM2*8)(%rsi), %xmm2
108-
movapd (RUSTRT_XMM3*8)(%rsi), %xmm3
109-
movapd (RUSTRT_XMM4*8)(%rsi), %xmm4
110-
movapd (RUSTRT_XMM5*8)(%rsi), %xmm5
103+
movapd (RUSTRT_XMM0*8)(ARG1), %xmm0
104+
movapd (RUSTRT_XMM1*8)(ARG1), %xmm1
105+
movapd (RUSTRT_XMM2*8)(ARG1), %xmm2
106+
movapd (RUSTRT_XMM3*8)(ARG1), %xmm3
107+
movapd (RUSTRT_XMM4*8)(ARG1), %xmm4
108+
movapd (RUSTRT_XMM5*8)(ARG1), %xmm5
111109

112110
// Jump to the instruction pointer
113111
// found in regs:
114-
jmp *(RUSTRT_IP*8)(%rsi)
112+
jmp *(RUSTRT_IP*8)(ARG1)
115113

trunk/src/rt/arch/x86_64/context.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ void context::call(void *f, void *arg, void *stack) {
2626
swap(*this);
2727

2828
// set up the stack
29-
uint32_t *sp = (uint32_t *)stack;
29+
uint64_t *sp = (uint64_t *)stack;
3030
sp = align_down(sp);
31+
*--sp = 0xdeadbeef; // takes place of ret. addr.
3132

3233
regs.data[RUSTRT_ARG0] = (uint64_t)arg;
3334
regs.data[RUSTRT_RSP] = (uint64_t)sp;

trunk/src/rt/arch/x86_64/context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ T align_down(T sp)
2323
// The struct in which we store the saved data. This is mostly the
2424
// volatile registers and instruction pointer, but it also includes
2525
// RCX/RDI which are used to pass arguments. The indices for each
26-
// register are found in <x86_64_regs.h>:
27-
#include "x86_64_regs.h"
26+
// register are found in "regs.h":
27+
#include "regs.h"
2828
struct registers_t {
2929
uint64_t data[RUSTRT_MAX];
3030
};
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#define RUSTRT_RBX 0
2-
#define RUSTRT_RSP 1
3-
#define RUSTRT_RBP 2
4-
#define RUSTRT_RDI 3
5-
#define RUSTRT_RCX 4
6-
#define RUSTRT_R12 5
7-
#define RUSTRT_R13 6
8-
#define RUSTRT_R14 7
9-
#define RUSTRT_R15 8
10-
#define RUSTRT_IP 9
1+
#define RUSTRT_RBX 0
2+
#define RUSTRT_RSP 1
3+
#define RUSTRT_RBP 2
4+
#define RUSTRT_ARG0 3 // RCX on Windows, RDI elsewhere
5+
#define RUSTRT_R12 4
6+
#define RUSTRT_R13 5
7+
#define RUSTRT_R14 6
8+
#define RUSTRT_R15 7
9+
#define RUSTRT_IP 8
10+
#define RUSTRT_XXX 9 // Not used, just padding
1111
#define RUSTRT_XMM0 10
1212
#define RUSTRT_XMM1 12
1313
#define RUSTRT_XMM2 14
@@ -19,11 +19,11 @@
1919
// ARG0 is the register in which the first argument goes.
2020
// Naturally this depends on your operating system.
2121
#if defined(__MINGW32__) || defined(_WINDOWS)
22-
# define RUSTRT_ARG0 RUSTRT_RCX
2322
# define RUSTRT_ARG0_S %rcx
2423
# define RUSTRT_ARG1_S %rdx
2524
#else
26-
# define RUSTRT_ARG0 RUSTRT_RDI
25+
# define RUSTRT_ARG0_S %rdi
26+
# define RUSTRT_ARG1_S %rsi
2727
#endif
2828

2929

0 commit comments

Comments
 (0)