From 321d2f0e5667fd3d10e9cd41aa80818bad71ebdc Mon Sep 17 00:00:00 2001 From: David McCullough Date: Wed, 6 Feb 2002 14:35:12 +0000 Subject: Add in clone (untested) Fix up setjmp/longjmp which were quite broken not withstanding all the new versions. Needs a little more test time before I'll trust this code totally. --- libc/sysdeps/linux/m68k/Makefile | 2 +- libc/sysdeps/linux/m68k/__longjmp.S | 24 ++++++++ libc/sysdeps/linux/m68k/bits/setjmp.h | 47 ++++++++-------- libc/sysdeps/linux/m68k/bsd-_setjmp.S | 24 ++++++++ libc/sysdeps/linux/m68k/bsd-setjmp.S | 23 ++++++++ libc/sysdeps/linux/m68k/clone.S | 75 +++++++++++++++++++++++++ libc/sysdeps/linux/m68k/setjmp.S | 101 ++++++---------------------------- 7 files changed, 187 insertions(+), 109 deletions(-) create mode 100644 libc/sysdeps/linux/m68k/__longjmp.S create mode 100644 libc/sysdeps/linux/m68k/bsd-_setjmp.S create mode 100644 libc/sysdeps/linux/m68k/bsd-setjmp.S create mode 100644 libc/sysdeps/linux/m68k/clone.S (limited to 'libc/sysdeps/linux') diff --git a/libc/sysdeps/linux/m68k/Makefile b/libc/sysdeps/linux/m68k/Makefile index f9f90ee44..2337a6ea7 100644 --- a/libc/sysdeps/linux/m68k/Makefile +++ b/libc/sysdeps/linux/m68k/Makefile @@ -36,7 +36,7 @@ CRT0=crt0.S CRT0_OBJ=$(patsubst %.S,%.o, $(CRT0)) endif -SSRC=setjmp.S vfork.S # longjmp.S _start.S clone.S +SSRC= __longjmp.S bsd-_setjmp.S bsd-setjmp.S clone.S setjmp.S vfork.S SOBJS=$(patsubst %.S,%.o, $(SSRC)) CSRC=ptrace.c diff --git a/libc/sysdeps/linux/m68k/__longjmp.S b/libc/sysdeps/linux/m68k/__longjmp.S new file mode 100644 index 000000000..d218f2ef5 --- /dev/null +++ b/libc/sysdeps/linux/m68k/__longjmp.S @@ -0,0 +1,24 @@ + +/* Copyright (C) 2002, David McCullough */ +/* This file is released under the LGPL, any version you like */ + +#define _ASM +#define _SETJMP_H +#include + +.globl __longjmp; +.type __longjmp,@function +.align 4; \ +__longjmp: + moveal %sp@(4), %a0 + movel %sp@(8), %d0 + bne 1f + movel #1, %d0 +1: + moveml %a0@(JB_REGS), %d2-%d7/%a2-%a7 +#if defined(__HAVE_68881__) || defined(__HAVE_FPU__) + fmovemx %a0@(JB_FPREGS), %fp2-%fp7 +#endif + movel %a0@(JB_PC), %sp@ + rts + diff --git a/libc/sysdeps/linux/m68k/bits/setjmp.h b/libc/sysdeps/linux/m68k/bits/setjmp.h index 2c2b3ee15..ea8045df7 100644 --- a/libc/sysdeps/linux/m68k/bits/setjmp.h +++ b/libc/sysdeps/linux/m68k/bits/setjmp.h @@ -1,36 +1,18 @@ -/* Copyright (C) 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Define the machine-dependent type `jmp_buf'. m68k version. */ +/* Copyright (C) 2002, David McCullough */ +/* This file is released under the LGPL, any version you like */ #ifndef _SETJMP_H # error "Never include directly; use instead." #endif +#ifndef _ASM + typedef struct { - /* There are eight 4-byte data registers, but D0 is not saved. */ - long int __dregs[7]; - - /* There are six 4-byte address registers, plus the FP and SP. */ - int *__aregs[6]; - int *__fp; - int *__sp; + unsigned long __dregs[6]; /* save d2 - d7 */ + unsigned long __aregs[6]; /* save a2 - a7 */ + unsigned long __pc; /* the return address */ #if defined __HAVE_68881__ || defined __HAVE_FPU__ /* There are eight floating point registers which @@ -40,6 +22,21 @@ typedef struct } __jmp_buf[1]; +#endif /* _ASM */ + +#define JB_REGS 0 +#define JB_DREGS 0 +#define JB_AREGS 24 +#define JB_PC 48 +#define JB_FPREGS 52 + +#if defined __HAVE_68881__ || defined __HAVE_FPU__ +# define JB_SIZE 76 +#else +# define JB_SIZE 52 +#endif + + /* Test if longjmp to JMPBUF would unwind the frame containing a local variable at ADDRESS. */ #define _JMPBUF_UNWINDS(jmpbuf, address) \ diff --git a/libc/sysdeps/linux/m68k/bsd-_setjmp.S b/libc/sysdeps/linux/m68k/bsd-_setjmp.S new file mode 100644 index 000000000..0380c3dee --- /dev/null +++ b/libc/sysdeps/linux/m68k/bsd-_setjmp.S @@ -0,0 +1,24 @@ + +/* Copyright (C) 2002, David McCullough */ +/* This file is released under the LGPL, any version you like */ + +#define _ASM +#define _SETJMP_H +#include + +.globl _setjmp; +.type _setjmp,@function +.align 4; + +_setjmp: + moveal %sp@(4), %a0 + movel %sp@(0), %a0@(JB_PC) + moveml %d2-%d7/%a2-%a7, %a0@(JB_REGS) +#if defined(__HAVE_68881__) || defined(__HAVE_FPU__) + fmovemx %fp2-%fp7, %a0@(JB_FPREGS) +#endif + clrl %d0 + movl %d0, JB_SIZE(%a0) /* No signal mask set. */ + rts + + diff --git a/libc/sysdeps/linux/m68k/bsd-setjmp.S b/libc/sysdeps/linux/m68k/bsd-setjmp.S new file mode 100644 index 000000000..b83573c80 --- /dev/null +++ b/libc/sysdeps/linux/m68k/bsd-setjmp.S @@ -0,0 +1,23 @@ + +/* Copyright (C) 2002, David McCullough */ +/* This file is released under the LGPL, any version you like */ + +#define _ASM +#define _SETJMP_H +#include + +.globl setjmp; +.type setjmp,@function +.align 4; + +setjmp: + moveal %sp@(4), %a0 + movel %sp@(0), %a0@(JB_PC) + moveml %d2-%d7/%a2-%a7, %a0@(JB_REGS) +#if defined(__HAVE_68881__) || defined(__HAVE_FPU__) + fmovemx %fp2-%fp7, %a0@(JB_FPREGS) +#endif + clrl %d0 + lea __sigjmp_save-.-8, %a0 + jmp 0(%pc, %a0) + diff --git a/libc/sysdeps/linux/m68k/clone.S b/libc/sysdeps/linux/m68k/clone.S new file mode 100644 index 000000000..1f900685e --- /dev/null +++ b/libc/sysdeps/linux/m68k/clone.S @@ -0,0 +1,75 @@ +/* Adapted from glibc */ +/* Copyright (C) 1996, 1997 Free Software Foundation, Inc. */ + +/* clone is even more special than fork as it mucks with stacks + and invokes a function in the right context after its all over. */ + +#define _ERRNO_H +#include +#include + +/* int _clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */ + +.text +.align 4 +.type __clone,@function +.globl __clone; +__clone: + /* Sanity check arguments. */ + movel #-EINVAL, %d0 + movel 4(%sp), %d1 /* no NULL function pointers */ + movel %d1, %a0 + tstl %d1 + jeq syscall_error + movel 8(%sp), %d1 /* no NULL stack pointers */ + movel %d1, %a1 + tstl %d1 + jeq syscall_error + + /* Allocate space and copy the argument onto the new stack. */ + movel 16(%sp), -(%a1) + + /* Do the system call */ +#if 1 /* defined (CONFIG_COLDFIRE) */ + movel %d2, %d1 /* save %d2 and get stack pointer */ + movel %a1, %d2 + movel %d1, %a1 +#else + exg %d2, %a1 /* save %d2 and get stack pointer */ +#endif + movel 12(%sp), %d1 /* get flags */ + movel #__NR_clone, %d0 + trap #0 +#if 1 /* defined (CONFIG_COLDFIRE) */ + movel %d2, %d1 /* restore %d2 */ + movel %a1, %d2 + movel %d1, %a1 +#else + exg %d2, %a1 /* restore %d2 */ +#endif + + tstl %d0 + jmi syscall_error + jeq thread_start + + rts + +syscall_error: + negl %d0 + movel %d0, %sp@- + lea __errno_location-.-8, %a0 + jsr 0(%pc, %a0) + movel %d0, %a0 + movel %sp@+, %a0@ + moveq #-1, %d0 + + rts + +thread_start: + /*subl %fp, %fp*/ /* terminate the stack frame */ + jsr (%a0) + movel %d0, -(%sp) + movel #__NR_exit, %d0 + trap #0 + /*jsr exit*/ + diff --git a/libc/sysdeps/linux/m68k/setjmp.S b/libc/sysdeps/linux/m68k/setjmp.S index d104d78ac..d7ca5dd6d 100644 --- a/libc/sysdeps/linux/m68k/setjmp.S +++ b/libc/sysdeps/linux/m68k/setjmp.S @@ -1,88 +1,23 @@ -/* These are predefined by new versions of GNU cpp. */ -#ifndef __USER_LABEL_PREFIX__ -#define __USER_LABEL_PREFIX__ _ -#endif - -#ifndef __REGISTER_PREFIX__ -#define __REGISTER_PREFIX__ -#endif - -/* ANSI concatenation macros. */ - -#define CONCAT1(a, b) CONCAT2(a, b) -#define CONCAT2(a, b) a ## b - -/* Use the right prefix for global labels. */ - -#define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x) +/* Copyright (C) 2002, David McCullough */ +/* This file is released under the LGPL, any version you like */ -/* Use the right prefix for registers. */ +#define _ASM +#define _SETJMP_H +#include -#define REG(x) CONCAT1 (__REGISTER_PREFIX__, x) +.globl __sigsetjmp; +.type __sigsetjmp,@function +.align 4; -#define d0 REG (d0) -#define d1 REG (d1) -#define d2 REG (d2) -#define d3 REG (d3) -#define d4 REG (d4) -#define d5 REG (d5) -#define d6 REG (d6) -#define d7 REG (d7) -#define a0 REG (a0) -#define a1 REG (a1) -#define a2 REG (a2) -#define a3 REG (a3) -#define a4 REG (a4) -#define a5 REG (a5) -#define a6 REG (a6) -#define fp REG (fp) -#define sp REG (sp) - -.global SYM (__setjmp) -.global SYM (__longjmp) - -SYM (__setjmp): - moveal sp@(4),a0 - movel sp@(0),a0@(12) - movel sp,a0@(8) - moveml d2-d7/a2-a6,a0@(20) - clrl d0 - rts - -SYM (__longjmp): - moveal sp@(4),a0 - movel sp@(8),d0 - bne 1f - movel #1,d0 -1: - moveml a0@(20),d2-d7/a2-a6 - moveal a0@(8),sp - movel a0@(12),sp@ - rts - -#ifdef M68881 -.global SYM (__setjmp_68881) -.global SYM (__longjmp_68881) - -SYM (__setjmp_68881): - moveal sp@(4),a0 - movel sp@(0),a0@(12) - movel sp,a0@(8) - moveml d2-d7/a2-a6,a0@(20) - fmovemx fp2-fp7,a0@(64) - clrl d0 - rts - -SYM (__longjmp_68881): - moveal sp@(4),a0 - fmovemx a0@(64),fp2-fp7 - movel sp@(8),d0 - bne 1f - movel #1,d0 -1: - moveml a0@(20),d2-d7/a2-a6 - moveal a0@(8),sp - movel a0@(12),sp@ - rts +__sigsetjmp: + moveal %sp@(4), %a0 + movel %sp@(0), %a0@(JB_PC) + moveml %d2-%d7/%a2-%a7, %a0@(JB_REGS) +#if defined(__HAVE_68881__) || defined(__HAVE_FPU__) + fmovemx %fp2-%fp7, %a0@(JB_FPREGS) #endif + clrl %d0 + lea __sigjmp_save-.-8, %a0 + jmp 0(%pc, %a0) + -- cgit v1.2.3