Removed unused context-switching assembly code.

This commit is contained in:
Maya Nitu 2014-12-22 18:20:43 +02:00
parent 34d6800092
commit 98ed882511
7 changed files with 2 additions and 570 deletions

View File

@ -35,7 +35,7 @@
# that's per-target so you're allowed to conditionally add files based on the
# target.
################################################################################
NATIVE_LIBS := rust_builtin hoedown morestack miniz context_switch \
NATIVE_LIBS := rust_builtin hoedown morestack miniz \
rustrt_native rust_test_helpers
# $(1) is the target triple
@ -58,8 +58,7 @@ NATIVE_DEPS_rustrt_native_$(1) := \
arch/$$(HOST_$(1))/record_sp.S
NATIVE_DEPS_rust_test_helpers_$(1) := rust_test_helpers.c
NATIVE_DEPS_morestack_$(1) := arch/$$(HOST_$(1))/morestack.S
NATIVE_DEPS_context_switch_$(1) := \
arch/$$(HOST_$(1))/_context.S
################################################################################
# You shouldn't find it that necessary to edit anything below this line.

View File

@ -1,69 +0,0 @@
// Mark stack as non-executable
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack, "", %progbits
#endif
.text
.code 32
.arm
#if defined(__APPLE__)
.align 2
#else
.align
#endif
#if defined(__APPLE__)
#define SWAP_REGISTERS _rust_swap_registers
#define BOOTSTRAP_TASK _rust_bootstrap_green_task
#else
#define SWAP_REGISTERS rust_swap_registers
#define BOOTSTRAP_TASK rust_bootstrap_green_task
#endif
.globl SWAP_REGISTERS
SWAP_REGISTERS:
str r0, [r0, #0]
str r3, [r0, #12]
str r4, [r0, #16]
str r5, [r0, #20]
str r6, [r0, #24]
str r7, [r0, #28]
str r8, [r0, #32]
str r9, [r0, #36]
str r10, [r0, #40]
str r11, [r0, #44]
str r12, [r0, #48]
str sp, [r0, #52]
str lr, [r0, #56]
mrs r2, cpsr
str r2, [r0, #64]
ldr r0, [r1, #0]
ldr r3, [r1, #12]
ldr r4, [r1, #16]
ldr r5, [r1, #20]
ldr r6, [r1, #24]
ldr r7, [r1, #28]
ldr r8, [r1, #32]
ldr r9, [r1, #36]
ldr r10, [r1, #40]
ldr r11, [r1, #44]
ldr r12, [r1, #48]
ldr sp, [r1, #52]
ldr lr, [r1, #56]
ldr r2, [r1, #64]
msr cpsr_cxsf, r2
mov pc, lr
// For reasons of this existence, see the comments in x86_64/_context.S
.globl BOOTSTRAP_TASK
BOOTSTRAP_TASK:
mov r0, r0
mov r1, r3
mov r2, r4
mov pc, r5

View File

@ -1,65 +0,0 @@
// Mark stack as non-executable
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack, "", @progbits
#endif
.text
/*
Callee save registers:
ebp, ebx, esi, edi
Caller save registers:
eax, ecx, edx
*/
/*
Saves a set of registers. This is used by our implementation of
getcontext.
The registers_t variable is in (%esp)
*/
#if defined(__APPLE__) || defined(_WIN32)
#define SWAP_REGISTERS _rust_swap_registers
#else
#define SWAP_REGISTERS rust_swap_registers
#endif
// swap_registers(registers_t *oregs, registers_t *regs)
.globl SWAP_REGISTERS
SWAP_REGISTERS:
// save the old context
movl 4(%esp), %eax
movl %ebx, 4(%eax)
movl %ebp, 16(%eax)
movl %esi, 20(%eax)
movl %edi, 24(%eax)
// save the flags
pushf
popl %ecx
movl %ecx, 44(%eax)
// save the return address as the instruction pointer
// and save the stack pointer of the caller
popl %ecx
movl %esp, 28(%eax)
movl %ecx, 48(%eax)
// restore the new context
movl 4(%esp), %eax
movl 4(%eax), %ebx
movl 16(%eax), %ebp
movl 20(%eax), %esi
movl 24(%eax), %edi
movl 28(%eax), %esp
// restore the flags
movl 44(%eax), %ecx
push %ecx
popf
// Return!
jmp *48(%eax)

View File

@ -1,88 +0,0 @@
// Mark stack as non-executable
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack, "", @progbits
#endif
.text
.globl rust_swap_registers
.align 2
.set nomips16
.ent rust_swap_registers
rust_swap_registers:
.set noreorder
.set nomacro
.set noat
sw $1, 1 * 4($4)
sw $2, 2 * 4($4)
sw $3, 3 * 4($4)
sw $4, 4 * 4($4)
sw $5, 5 * 4($4)
sw $6, 6 * 4($4)
sw $7, 7 * 4($4)
sw $8, 8 * 4($4)
sw $9, 9 * 4($4)
sw $10, 10 * 4($4)
sw $11, 11 * 4($4)
sw $12, 12 * 4($4)
sw $13, 13 * 4($4)
sw $14, 14 * 4($4)
sw $15, 15 * 4($4)
sw $16, 16 * 4($4)
sw $17, 17 * 4($4)
sw $18, 18 * 4($4)
sw $19, 19 * 4($4)
sw $20, 20 * 4($4)
sw $21, 21 * 4($4)
sw $22, 22 * 4($4)
sw $23, 23 * 4($4)
sw $24, 24 * 4($4)
sw $25, 25 * 4($4)
sw $26, 26 * 4($4)
sw $27, 27 * 4($4)
sw $28, 28 * 4($4)
sw $29, 29 * 4($4)
sw $30, 30 * 4($4)
sw $31, 31 * 4($4)
lw $1, 1 * 4($5)
lw $2, 2 * 4($5)
lw $3, 3 * 4($5)
lw $4, 4 * 4($5)
lw $6, 6 * 4($5)
lw $7, 7 * 4($5)
lw $8, 8 * 4($5)
lw $9, 9 * 4($5)
lw $10, 10 * 4($5)
lw $11, 11 * 4($5)
lw $12, 12 * 4($5)
lw $13, 13 * 4($5)
lw $14, 14 * 4($5)
lw $15, 15 * 4($5)
lw $16, 16 * 4($5)
lw $17, 17 * 4($5)
lw $18, 18 * 4($5)
lw $19, 19 * 4($5)
lw $20, 20 * 4($5)
lw $21, 21 * 4($5)
lw $22, 22 * 4($5)
lw $23, 23 * 4($5)
lw $24, 24 * 4($5)
lw $25, 25 * 4($5)
lw $26, 26 * 4($5)
lw $27, 27 * 4($5)
lw $28, 28 * 4($5)
lw $29, 29 * 4($5)
lw $30, 30 * 4($5)
lw $31, 31 * 4($5)
lw $5, 5 * 4($5)
jr $31
nop
.end rust_swap_registers

View File

@ -1,88 +0,0 @@
// Mark stack as non-executable
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack, "", @progbits
#endif
.text
.globl rust_swap_registers
.align 2
.set nomips16
.ent rust_swap_registers
rust_swap_registers:
.set noreorder
.set nomacro
.set noat
sw $1, 1 * 4($4)
sw $2, 2 * 4($4)
sw $3, 3 * 4($4)
sw $4, 4 * 4($4)
sw $5, 5 * 4($4)
sw $6, 6 * 4($4)
sw $7, 7 * 4($4)
sw $8, 8 * 4($4)
sw $9, 9 * 4($4)
sw $10, 10 * 4($4)
sw $11, 11 * 4($4)
sw $12, 12 * 4($4)
sw $13, 13 * 4($4)
sw $14, 14 * 4($4)
sw $15, 15 * 4($4)
sw $16, 16 * 4($4)
sw $17, 17 * 4($4)
sw $18, 18 * 4($4)
sw $19, 19 * 4($4)
sw $20, 20 * 4($4)
sw $21, 21 * 4($4)
sw $22, 22 * 4($4)
sw $23, 23 * 4($4)
sw $24, 24 * 4($4)
sw $25, 25 * 4($4)
sw $26, 26 * 4($4)
sw $27, 27 * 4($4)
sw $28, 28 * 4($4)
sw $29, 29 * 4($4)
sw $30, 30 * 4($4)
sw $31, 31 * 4($4)
lw $1, 1 * 4($5)
lw $2, 2 * 4($5)
lw $3, 3 * 4($5)
lw $4, 4 * 4($5)
lw $6, 6 * 4($5)
lw $7, 7 * 4($5)
lw $8, 8 * 4($5)
lw $9, 9 * 4($5)
lw $10, 10 * 4($5)
lw $11, 11 * 4($5)
lw $12, 12 * 4($5)
lw $13, 13 * 4($5)
lw $14, 14 * 4($5)
lw $15, 15 * 4($5)
lw $16, 16 * 4($5)
lw $17, 17 * 4($5)
lw $18, 18 * 4($5)
lw $19, 19 * 4($5)
lw $20, 20 * 4($5)
lw $21, 21 * 4($5)
lw $22, 22 * 4($5)
lw $23, 23 * 4($5)
lw $24, 24 * 4($5)
lw $25, 25 * 4($5)
lw $26, 26 * 4($5)
lw $27, 27 * 4($5)
lw $28, 28 * 4($5)
lw $29, 29 * 4($5)
lw $30, 30 * 4($5)
lw $31, 31 * 4($5)
lw $5, 5 * 4($5)
jr $31
nop
.end rust_swap_registers

View File

@ -1,192 +0,0 @@
// Mark stack as non-executable
#if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack, "", @progbits
#endif
#include "regs.h"
#define ARG0 RUSTRT_ARG0_S
#define ARG1 RUSTRT_ARG1_S
.text
/*
According to ABI documentation found at
http://www.x86-64.org/documentation.html
and Microsoft discussion at
http://msdn.microsoft.com/en-US/library/9z1stfyw%28v=VS.80%29.aspx.
BOTH CALLING CONVENTIONS
Callee save registers:
R12--R15, RDI, RSI, RBX, RBP, RSP
XMM0--XMM5
Caller save registers:
RAX, RCX, RDX, R8--R11
XMM6--XMM15
Floating point stack
MAC/AMD CALLING CONVENTIONS
Integer arguments go in registers:
rdi, rsi, rdx, rcx, r8, r9
User flags have no specified role and are not preserved
across calls, with the exception of DF in %rFLAGS,
which must be clear (set to "forward" direction)
on function entry and return.
MICROSOFT CALLING CONVENTIONS
Return value: RAX
First four arguments:
RCX, RDX, R8, R9
XMM0, XMM1, XMM2, XMM3
*/
/*
Stores current registers into arg0/RCX and restores
registers found in arg1/RDX. This is used by our
implementation of getcontext. Only saves/restores nonvolatile
registers and the register used for the first argument.
Volatile registers in general ought to be saved by the caller
anyhow.
*/
#if defined(__APPLE__)
#define SWAP_REGISTERS _rust_swap_registers
#else
#define SWAP_REGISTERS rust_swap_registers
#endif
// swap_registers(registers_t *oregs, registers_t *regs)
.globl SWAP_REGISTERS
SWAP_REGISTERS:
// n.b. when we enter, the return address is at the top of
// the stack (i.e., 0(%RSP)) and the argument is in
// RUSTRT_ARG0_S. We
// simply save all NV registers into oregs.
// We then restore all NV registers from regs. This restores
// the old stack pointer, which should include the proper
// return address. We can therefore just return normally to
// jump back into the old code.
// Save instruction pointer:
pop %rax
mov %rax, (RUSTRT_IP*8)(RUSTRT_ARG0_S)
// Save non-volatile integer registers:
// (including RSP)
mov %rbx, (RUSTRT_RBX*8)(ARG0)
mov %rsp, (RUSTRT_RSP*8)(ARG0)
mov %rbp, (RUSTRT_RBP*8)(ARG0)
mov %r12, (RUSTRT_R12*8)(ARG0)
mov %r13, (RUSTRT_R13*8)(ARG0)
mov %r14, (RUSTRT_R14*8)(ARG0)
mov %r15, (RUSTRT_R15*8)(ARG0)
#if defined(__MINGW32__) || defined(_WINDOWS)
mov %rdi, (RUSTRT_RDI*8)(ARG0)
mov %rsi, (RUSTRT_RSI*8)(ARG0)
#endif
// Save 0th argument register:
mov ARG0, (RUSTRT_ARG0*8)(ARG0)
// Save non-volatile XMM registers:
#if defined(__MINGW32__) || defined(_WINDOWS)
movapd %xmm6, (RUSTRT_XMM6*8)(ARG0)
movapd %xmm7, (RUSTRT_XMM7*8)(ARG0)
movapd %xmm8, (RUSTRT_XMM8*8)(ARG0)
movapd %xmm9, (RUSTRT_XMM9*8)(ARG0)
movapd %xmm10, (RUSTRT_XMM10*8)(ARG0)
movapd %xmm11, (RUSTRT_XMM11*8)(ARG0)
movapd %xmm12, (RUSTRT_XMM12*8)(ARG0)
movapd %xmm13, (RUSTRT_XMM13*8)(ARG0)
movapd %xmm14, (RUSTRT_XMM14*8)(ARG0)
movapd %xmm15, (RUSTRT_XMM15*8)(ARG0)
#else
movapd %xmm0, (RUSTRT_XMM0*8)(ARG0)
movapd %xmm1, (RUSTRT_XMM1*8)(ARG0)
movapd %xmm2, (RUSTRT_XMM2*8)(ARG0)
movapd %xmm3, (RUSTRT_XMM3*8)(ARG0)
movapd %xmm4, (RUSTRT_XMM4*8)(ARG0)
movapd %xmm5, (RUSTRT_XMM5*8)(ARG0)
#endif
// Restore non-volatile integer registers:
// (including RSP)
mov (RUSTRT_RBX*8)(ARG1), %rbx
mov (RUSTRT_RSP*8)(ARG1), %rsp
mov (RUSTRT_RBP*8)(ARG1), %rbp
mov (RUSTRT_R12*8)(ARG1), %r12
mov (RUSTRT_R13*8)(ARG1), %r13
mov (RUSTRT_R14*8)(ARG1), %r14
mov (RUSTRT_R15*8)(ARG1), %r15
#if defined(__MINGW32__) || defined(_WINDOWS)
mov (RUSTRT_RDI*8)(ARG1), %rdi
mov (RUSTRT_RSI*8)(ARG1), %rsi
#endif
// Restore 0th argument register:
mov (RUSTRT_ARG0*8)(ARG1), ARG0
// Restore non-volatile XMM registers:
#if defined(__MINGW32__) || defined(_WINDOWS)
movapd (RUSTRT_XMM6*8)(ARG1), %xmm6
movapd (RUSTRT_XMM7*8)(ARG1), %xmm7
movapd (RUSTRT_XMM8*8)(ARG1), %xmm8
movapd (RUSTRT_XMM9*8)(ARG1), %xmm9
movapd (RUSTRT_XMM10*8)(ARG1), %xmm10
movapd (RUSTRT_XMM11*8)(ARG1), %xmm11
movapd (RUSTRT_XMM12*8)(ARG1), %xmm12
movapd (RUSTRT_XMM13*8)(ARG1), %xmm13
movapd (RUSTRT_XMM14*8)(ARG1), %xmm14
movapd (RUSTRT_XMM15*8)(ARG1), %xmm15
#else
movapd (RUSTRT_XMM0*8)(ARG1), %xmm0
movapd (RUSTRT_XMM1*8)(ARG1), %xmm1
movapd (RUSTRT_XMM2*8)(ARG1), %xmm2
movapd (RUSTRT_XMM3*8)(ARG1), %xmm3
movapd (RUSTRT_XMM4*8)(ARG1), %xmm4
movapd (RUSTRT_XMM5*8)(ARG1), %xmm5
#endif
// Jump to the instruction pointer
// found in regs:
jmp *(RUSTRT_IP*8)(ARG1)
// This function below, rust_bootstrap_green_task, is used to initialize a green
// task. This code is the very first code that is run whenever a green task
// starts. The only assumptions that this code makes is that it has a register
// context previously set up by Context::new() and some values are in some
// special registers.
//
// In theory the register context could be set up and then the context switching
// would plop us directly into some 'extern "C" fn', but not all platforms have
// the argument registers saved throughout a context switch (linux doesn't save
// rdi/rsi, the first two argument registers). Instead of modifying all context
// switches, instead the initial data for starting a green thread is shoved into
// unrelated registers (r12/13, etc) which always need to be saved on context
// switches anyway.
//
// With this strategy we get the benefit of being able to pass a fair bit of
// contextual data from the start of a green task to its init function, as well
// as not hindering any context switches.
//
// If you alter this code in any way, you likely need to update
// src/libgreen/context.rs as well.
#if defined(__APPLE__)
#define BOOTSTRAP _rust_bootstrap_green_task
#else
#define BOOTSTRAP rust_bootstrap_green_task
#endif
.globl BOOTSTRAP
BOOTSTRAP:
mov %r12, RUSTRT_ARG0_S
mov %r13, RUSTRT_ARG1_S
mov %r14, RUSTRT_ARG2_S
jmpq *%r15

View File

@ -1,65 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This is loosely kept in sync with src/libstd/rt/context.rs
#define RUSTRT_RBX 0
#define RUSTRT_RSP 1
#define RUSTRT_RBP 2
// RCX on Windows, RDI elsewhere
#define RUSTRT_ARG0 3
#define RUSTRT_R12 4
#define RUSTRT_R13 5
#define RUSTRT_R14 6
#define RUSTRT_R15 7
#define RUSTRT_IP 8
#if defined(__MINGW32__) || defined(_WINDOWS)
#define RUSTRT_RDI 9
#define RUSTRT_RSI 10
#define RUSTRT_ST1 11
#define RUSTRT_ST2 12
#define RUSTRT_XMM6 14
#define RUSTRT_XMM7 16
#define RUSTRT_XMM8 18
#define RUSTRT_XMM9 20
#define RUSTRT_XMM10 22
#define RUSTRT_XMM11 24
#define RUSTRT_XMM12 26
#define RUSTRT_XMM13 28
#define RUSTRT_XMM14 30
#define RUSTRT_XMM15 32
#define RUSTRT_MAX 34
#else
// Not used, just padding
#define RUSTRT_XXX 9
#define RUSTRT_XMM0 10
#define RUSTRT_XMM1 12
#define RUSTRT_XMM2 14
#define RUSTRT_XMM3 16
#define RUSTRT_XMM4 18
#define RUSTRT_XMM5 20
#define RUSTRT_MAX 22
#endif
// ARG0 is the register in which the first argument goes.
// Naturally this depends on your operating system.
#if defined(__MINGW32__) || defined(_WINDOWS)
# define RUSTRT_ARG0_S %rcx
# define RUSTRT_ARG1_S %rdx
# define RUSTRT_ARG2_S %r8
# define RUSTRT_ARG3_S %r9
#else
# define RUSTRT_ARG0_S %rdi
# define RUSTRT_ARG1_S %rsi
# define RUSTRT_ARG2_S %rdx
# define RUSTRT_ARG3_S %rcx
# define RUSTRT_ARG4_S %r8
# define RUSTRT_ARG5_S %r9
#endif