ruby-changes:53625
From: samuel <ko1@a...>
Date: Tue, 20 Nov 2018 19:14:17 +0900 (JST)
Subject: [ruby-changes:53625] samuel:r65847 (trunk): Initial effort to support 32-bit Linux.
samuel 2018-11-20 19:13:59 +0900 (Tue, 20 Nov 2018) New Revision: 65847 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65847 Log: Initial effort to support 32-bit Linux. Added directories: trunk/coroutine/x86/ Added files: trunk/coroutine/x86/Context.h trunk/coroutine/x86/Context.s Modified files: trunk/configure.ac Index: configure.ac =================================================================== --- configure.ac (revision 65846) +++ configure.ac (revision 65847) @@ -2332,6 +2332,11 @@ AS_CASE(["$target_cpu-$target_os"], https://github.com/ruby/ruby/blob/trunk/configure.ac#L2332 AC_DEFINE(FIBER_USE_COROUTINE, "coroutine/amd64/Context.h") AC_LIBOBJ([coroutine/amd64/Context]) ], + [*86-*], [ + AC_MSG_RESULT(x86) + AC_DEFINE(FIBER_USE_COROUTINE, "coroutine/x86/Context.h") + AC_LIBOBJ([coroutine/x86/Context]) + ] [*], [ AC_MSG_RESULT(no) ] Index: coroutine/x86/Context.h =================================================================== --- coroutine/x86/Context.h (nonexistent) +++ coroutine/x86/Context.h (revision 65847) @@ -0,0 +1,61 @@ https://github.com/ruby/ruby/blob/trunk/coroutine/x86/Context.h#L1 +// +// File file is part of the "Coroutine" project and released under the MIT License. +// +// Created by Samuel Williams on 3/11/2018. +// Copyright, 2018, by Samuel Williams. All rights reserved. +// + +#pragma once + +#include <assert.h> +#include <string.h> + +#if __cplusplus +extern "C" { +#endif + +#define COROUTINE void __attribute__((fastcall)) + +const size_t COROUTINE_REGISTERS = 4; + +// The fiber context (stack pointer). +typedef struct +{ + void **stack_pointer; +} coroutine_context; + +// The initialization function. +typedef void(* coroutine_start)(coroutine_context *from, coroutine_context *self) __attribute__((fastcall)); + +void coroutine_initialize( + coroutine_context *context, + coroutine_start start, + void *stack_pointer, + size_t stack_size +) { + /* Force 16-byte alignment */ + context->stack_pointer = (void**)((uintptr_t)stack_pointer & ~0xF); + + if (!start) { + assert(!context->stack_pointer); + /* We are main coroutine for this thread */ + return; + } + + *--context->stack_pointer = NULL; + *--context->stack_pointer = (void*)start; + + context->stack_pointer -= COROUTINE_REGISTERS; + memset(context->stack_pointer, 0, sizeof(void*) * COROUTINE_REGISTERS); +} + +coroutine_context * coroutine_transfer(coroutine_context * current, coroutine_context * target) __attribute__((fastcall)); + +inline void coroutine_destroy(coroutine_context * context) +{ + context->stack_pointer = NULL; +} + +#if __cplusplus +} +#endif Index: coroutine/x86/Context.s =================================================================== --- coroutine/x86/Context.s (nonexistent) +++ coroutine/x86/Context.s (revision 65847) @@ -0,0 +1,39 @@ https://github.com/ruby/ruby/blob/trunk/coroutine/x86/Context.s#L1 +## +## File file is part of the "Coroutine" project and released under the MIT License. +## +## Created by Samuel Williams on 3/11/2018. +## Copyright, 2018, by Samuel Williams. All rights reserved. +## + +.text + +.globl coroutine_transfer +coroutine_transfer: + +# For older linkers +.globl _coroutine_transfer +_coroutine_transfer: + + # Save caller registers + pushl %ebp + pushl %ebx + pushl %edi + pushl %esi + + # Save caller stack pointer + movl %esp, (%ecx) + + # Restore callee stack pointer + movl (%edx), %esp + + # Restore callee stack + popl %esi + popl %edi + popl %ebx + popl %ebp + + # Save the first argument as the return value + movl %ecx, %eax + + # Jump to the address on the stack + ret -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/