about summary refs log tree commit diff
path: root/ports/sysdeps/unix/sysv/linux/m68k
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@linux-m68k.org>2012-07-16 16:54:37 +0200
committerAndreas Schwab <schwab@linux-m68k.org>2012-07-16 19:23:33 +0200
commitaaf5420c6d1d2f0135a89d08f22200f0dc0777bd (patch)
tree24d0ed283829c1a49d5aeffedde67162cfa7fc27 /ports/sysdeps/unix/sysv/linux/m68k
parentd0cd7d02120a1700a9b9f2b5601c35142f1be44b (diff)
downloadglibc-aaf5420c6d1d2f0135a89d08f22200f0dc0777bd.tar.gz
glibc-aaf5420c6d1d2f0135a89d08f22200f0dc0777bd.tar.xz
glibc-aaf5420c6d1d2f0135a89d08f22200f0dc0777bd.zip
m68k: add support for {get,make,set,swap}context
Diffstat (limited to 'ports/sysdeps/unix/sysv/linux/m68k')
-rw-r--r--ports/sysdeps/unix/sysv/linux/m68k/m680x0/Makefile3
-rw-r--r--ports/sysdeps/unix/sysv/linux/m68k/m680x0/getcontext.S63
-rw-r--r--ports/sysdeps/unix/sysv/linux/m68k/m680x0/makecontext.S100
-rw-r--r--ports/sysdeps/unix/sysv/linux/m68k/m680x0/setcontext.S94
-rw-r--r--ports/sysdeps/unix/sysv/linux/m68k/m680x0/swapcontext.S108
-rw-r--r--ports/sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym20
6 files changed, 388 insertions, 0 deletions
diff --git a/ports/sysdeps/unix/sysv/linux/m68k/m680x0/Makefile b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/Makefile
new file mode 100644
index 0000000000..91bd35800a
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/Makefile
@@ -0,0 +1,3 @@
+ifeq ($(subdir),stdlib)
+gen-as-const-headers += ucontext_i.sym
+endif
diff --git a/ports/sysdeps/unix/sysv/linux/m68k/m680x0/getcontext.S b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/getcontext.S
new file mode 100644
index 0000000000..4f31d2afc8
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/getcontext.S
@@ -0,0 +1,63 @@
+/* Save current context.
+   Copyright (C) 2012 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__getcontext)
+	/* Load address of the context data structure.  */
+	move.l	4(%sp), %a0
+
+	/* Save the preserved registers and the return address.  */
+	movem.l	%d2-%d7, oGREGS+2*4(%a0)
+	movem.l	%a2-%a6, oGREGS+10*4(%a0)
+	lea	4(%sp), %a1
+	move.l	%a1, oSP(%a0)
+	move.l	(%sp), oPC(%a0)
+	fmovem.l %fpsr/%fpcr/%fpiar, oFPREGS(%a0)
+	fmovem.x %fp2-%fp7, oFP2(%a0)
+	cfi_def_cfa (%a0, 0)
+	cfi_offset (%d2, oGREGS+2*4)
+	cfi_offset (%d3, oGREGS+3*4)
+	cfi_offset (%pc, oPC)
+
+	/* Save the current signal mask.  */
+	lea	oSIGMASK(%a0), %a1
+	move.l	%a1, %d3
+	clr.l	%d2
+	move.l	#SIG_SETMASK, %d1
+	move.l	#__NR_sigprocmask, %d0
+	trap	#0
+	/* Restore registers.  */
+	move.l	oGREGS+2*4(%a0), %d2
+	cfi_restore (%d2)
+	move.l	oGREGS+3*4(%a0), %d3
+	cfi_restore (%d3)
+	cfi_def_cfa (%sp, 4)
+	cfi_offset (%pc, -4)
+	cmp.l	#-4095, %d0		/* Check %d0 for error.  */
+	jcc	SYSCALL_ERROR_LABEL	/* Jump to error handler.  */
+
+0:	/* All done, return 0 for success.  */
+	clr.l	%d0
+	rts
+PSEUDO_END(__getcontext)
+
+weak_alias (__getcontext, getcontext)
diff --git a/ports/sysdeps/unix/sysv/linux/m68k/m680x0/makecontext.S b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/makecontext.S
new file mode 100644
index 0000000000..a7048b1d3a
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/makecontext.S
@@ -0,0 +1,100 @@
+/* Create new context.
+   Copyright (C) 2012 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__makecontext)
+	move.l	4(%sp), %a0
+
+	/* Get the address of the function we are supposed to run.  */
+	move.l	8(%sp), oPC(%a0)
+
+	/* Compute the address of the stack.  The information comes from
+	   to us_stack element.  */
+	move.l	oSS_SP(%a0), %a1
+	add.l	oSS_SIZE(%a0), %a1
+
+	/* Remember the number of parameters for the exit handler since
+	   it has to remove them.  We store the number in the D7 register
+	   which the function we will call must preserve.  */
+	move.l	12(%sp), %d1
+	move.l	%d1, oGREGS+7*4(%a0)
+
+	/* Make room on the new stack for the parameters.
+	   Room for the arguments, return address (== 1f) and
+	   oLINK pointer is needed.  */
+	neg.l	%d1
+	lea	-8(%a1,%d1.l*4), %a1
+	neg.l	%d1
+
+	/* Store the future stack pointer.  */
+	move.l	%a1, oSP(%a0)
+
+	/* Put the next context on the new stack (from the uc_link
+	   element).  */
+	move.l	oLINK(%a0), 4(%a1,%d1.l*4)
+
+	/* Copy all the parameters.  */
+1:	subq.l	#1,%d1
+	jmi	2f
+	move.l	16(%sp,%d1.l*4), 4(%a1,%d1.l*4)
+	jra	1b
+2:
+
+	/* If the function we call returns we must continue with the
+	   context which is given in the uc_link element.  To do this
+	   set the return address for the function the user provides
+	   to a little bit of helper code which does the magic (see
+	   below).  */
+	lea	1f(%pc), %a0
+	move.l	%a0, (%a1)
+	/* 'makecontext' returns no value.  */
+	rts
+
+	/* This is the helper code which gets called if a function which
+	   is registered with 'makecontext' returns.  In this case we
+	   have to install the context listed in the uc_link element of
+	   the context 'makecontext' manipulated at the time of the
+	   'makecontext' call.  If the pointer is NULL the process must
+	   terminate.  */
+	cfi_endproc
+1:
+	/* This removes the parameters passed to the function given to
+	   'makecontext' from the stack.  D7 contains the number of
+	   parameters (see above).  */
+	lea	(%sp,%d7.l*4), %sp
+
+	tst.l	(%sp)			/* Check the next context.  */
+	jeq	2f			/* If it is zero exit.  */
+
+	jbsr	JUMPTARGET(__setcontext)
+	/* If this returns (which can happen if the syscall fails) we'll
+	   exit the program with the return error value (-1).  */
+
+	move.l	%d0, (%sp)
+2:	jbsr	HIDDEN_JUMPTARGET(exit)
+	/* The 'exit' call should never return.  In case it does cause
+	   the process to terminate.  */
+	illegal
+	cfi_startproc
+END(__makecontext)
+
+weak_alias (__makecontext, makecontext)
diff --git a/ports/sysdeps/unix/sysv/linux/m68k/m680x0/setcontext.S b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/setcontext.S
new file mode 100644
index 0000000000..a8d53a555f
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/setcontext.S
@@ -0,0 +1,94 @@
+/* Install given context.
+   Copyright (C) 2012 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+ENTRY(__setcontext)
+	/* Load address of the context data structure.  */
+	move.l	4(%sp), %a0
+
+	/* Get the current signal mask.  Note that we preserve D2/D3 in case
+	   the system call fails and we return from the function with an
+	   error.  */
+	move.l	%d3, -(%sp)
+	cfi_adjust_cfa_offset (4)
+	cfi_rel_offset (%d3, 0)
+	move.l	%d2, -(%sp)
+	cfi_adjust_cfa_offset (4)
+	cfi_rel_offset (%d2, 0)
+	clr.l	%d3
+	lea	oSIGMASK(%a0), %a1
+	move.l	%a1, %d2
+	move.l	#SIG_SETMASK, %d1
+	move.l	#__NR_sigprocmask, %d0
+	trap	#0
+	cmp.l	#-4095, %d0		/* Check %d0 for error.  */
+	jcs	0f
+	move.l	(%sp)+, %d2
+	cfi_adjust_cfa_offset (-4)
+	cfi_restore (d2)
+	move.l	(%sp)+, %d3
+	cfi_adjust_cfa_offset (-4)
+	cfi_restore (d3)
+	jra	SYSCALL_ERROR_LABEL	/* Jump to error handler if error.  */
+
+0:	/* Load the new stack pointer.  */
+	move.l	oSP(%a0), %sp
+	cfi_def_cfa (%a0, 0)
+	cfi_offset (%d2, oGREGS+2*4)
+	cfi_offset (%d3, oGREGS+3*4)
+	cfi_offset (%d4, oGREGS+4*4)
+	cfi_offset (%d5, oGREGS+5*4)
+	cfi_offset (%d6, oGREGS+6*4)
+	cfi_offset (%d7, oGREGS+7*4)
+	cfi_offset (%a2, oGREGS+10*4)
+	cfi_offset (%a3, oGREGS+11*4)
+	cfi_offset (%a4, oGREGS+12*4)
+	cfi_offset (%a5, oGREGS+13*4)
+	cfi_offset (%a6, oGREGS+14*4)
+	cfi_offset (%fp2, oFP2+0*12)
+	cfi_offset (%fp3, oFP2+1*12)
+	cfi_offset (%fp4, oFP2+2*12)
+	cfi_offset (%fp5, oFP2+3*12)
+	cfi_offset (%fp6, oFP2+4*12)
+	cfi_offset (%fp7, oFP2+5*12)
+	cfi_offset (%pc, oPC)
+
+	/* Load the values of all the preserved registers (except SP).  */
+	movem.l	oGREGS+2*4(%a0), %d2-%d7
+	movem.l	oGREGS+10*4(%a0), %a2-%a6
+	fmovem.l oFPREGS(%a0), %fpsr/%fpcr/%fpiar
+	fmovem.x oFP2(%a0), %fp2-%fp7
+	clr.l	%d0
+
+	/* Fetch the address to return to.  */
+	movl	oPC(%a0), %a1
+
+	/* End FDE here, we fall into another context.  */
+	cfi_endproc
+	cfi_startproc
+	cfi_register (%pc, %a1)
+
+	jmp	(%a1)
+
+	cfi_offset (%pc, -4)
+PSEUDO_END(__setcontext)
+
+weak_alias (__setcontext, setcontext)
diff --git a/ports/sysdeps/unix/sysv/linux/m68k/m680x0/swapcontext.S b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/swapcontext.S
new file mode 100644
index 0000000000..b65aed8ffa
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/swapcontext.S
@@ -0,0 +1,108 @@
+/* Save current context and install the given one.
+   Copyright (C) 2012 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, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+#include "ucontext_i.h"
+
+
+ENTRY(__swapcontext)
+	/* Load address of the context data structure we save in.  */
+	move.l	4(%sp), %a0
+
+	/* Save the preserved registers and the return address.  */
+	movem.l	%d2-%d7, oGREGS+2*4(%a0)
+	movem.l	%a2-%a6, oGREGS+10*4(%a0)
+	lea	4(%sp), %a1
+	move.l	%a1, oSP(%a0)
+	move.l	(%sp), oPC(%a0)
+	fmovem.l %fpsr/%fpcr/%fpiar, oFPREGS(%a0)
+	fmovem.x %fp2-%fp7, oFP2(%a0)
+	cfi_def_cfa (%a0, 0)
+	cfi_offset (%d2, oGREGS+2*4)
+	cfi_offset (%d3, oGREGS+3*4)
+	cfi_offset (%a2, oGREGS+10*4)
+	cfi_offset (%pc, oPC)
+
+	/* Load address of the context data structure we have to load.  */
+	move.l	8(%sp), %a1
+
+	/* Save the current signal mask and install the new one.  */
+	lea	oSIGMASK(%a0), %a2
+	move.l	%a2, %d3
+	lea	oSIGMASK(%a1), %a2
+	move.l	%a2, %d2
+	move.l	#SIG_SETMASK, %d1
+	move.l	#__NR_sigprocmask, %d0
+	trap	#0
+	cmp.l	#-4095, %d0		/* Check %d0 for error.  */
+	jcs	0f
+	/* Restore registers.  */
+	move.l	oGREGS+2*4(%a0), %d2
+	cfi_restore (%d2)
+	move.l	oGREGS+3*4(%a0), %d3
+	cfi_restore (%d3)
+	move.l	oGREGS+10*4(%a0), %a2
+	cfi_restore (%a2)
+	jra	SYSCALL_ERROR_LABEL	/* Jump to error handler.  */
+
+0:	/* Load the new stack pointer.  */
+	move.l	oSP(%a1), %sp
+	cfi_def_cfa (%a1, 0)
+	cfi_offset (%d2, oGREGS+2*4)
+	cfi_offset (%d3, oGREGS+3*4)
+	cfi_offset (%d4, oGREGS+4*4)
+	cfi_offset (%d5, oGREGS+5*4)
+	cfi_offset (%d6, oGREGS+6*4)
+	cfi_offset (%d7, oGREGS+7*4)
+	cfi_offset (%a2, oGREGS+10*4)
+	cfi_offset (%a3, oGREGS+11*4)
+	cfi_offset (%a4, oGREGS+12*4)
+	cfi_offset (%a5, oGREGS+13*4)
+	cfi_offset (%a6, oGREGS+14*4)
+	cfi_offset (%fp2, oFP2+0*12)
+	cfi_offset (%fp3, oFP2+1*12)
+	cfi_offset (%fp4, oFP2+2*12)
+	cfi_offset (%fp5, oFP2+3*12)
+	cfi_offset (%fp6, oFP2+4*12)
+	cfi_offset (%fp7, oFP2+5*12)
+	cfi_offset (%pc, oPC)
+
+	/* Load the values of all the preserved registers (except SP).  */
+	movem.l	oGREGS+2*4(%a1), %d2-%d7
+	movem.l	oGREGS+10*4(%a1), %a2-%a6
+	fmovem.l oFPREGS(%a1), %fpsr/%fpcr/%fpiar
+	fmovem.x oFP2(%a1), %fp2-%fp7
+
+	/* Clear D0 to indicate success.  */
+	clr.l	%d0
+
+	/* Fetch the address to return to.  */
+	move.l	oPC(%a1), %a0
+
+	/* End FDE here, we fall into another context.  */
+	cfi_endproc
+	cfi_startproc
+	cfi_register (%pc, %a0)
+
+	jmp	(%a0)
+
+	cfi_offset (%pc, -4)
+PSEUDO_END(__swapcontext)
+
+weak_alias (__swapcontext, swapcontext)
diff --git a/ports/sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym
new file mode 100644
index 0000000000..46bd4bf15f
--- /dev/null
+++ b/ports/sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym
@@ -0,0 +1,20 @@
+#include <stddef.h>
+#include <signal.h>
+#include <sys/ucontext.h>
+
+--
+
+SIG_SETMASK
+
+#define ucontext(member)	offsetof (ucontext_t, member)
+#define mcontext(member)	ucontext (uc_mcontext.member)
+
+oLINK		ucontext (uc_link)
+oSS_SP		ucontext (uc_stack.ss_sp)
+oSS_SIZE	ucontext (uc_stack.ss_size)
+oGREGS		mcontext (gregs)
+oSP		mcontext (gregs[R_SP])
+oPC		mcontext (gregs[R_PC])
+oFPREGS		mcontext (fpregs)
+oFP2		mcontext (fpregs.f_fpregs[2])
+oSIGMASK	ucontext (uc_sigmask)