summaryrefslogtreecommitdiff
path: root/ports/sysdeps/unix/sysv/linux/hppa/makecontext.c
blob: 69a18135d9d22a42dd9eccc4df7ca0e1a9eb485f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* Create new context.
   Copyright (C) 2008 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Helge Deller <deller@gmx.de>, 2008.

   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.  */

#include <libintl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysdep.h>
#include <ucontext.h>

/* XXX: This implementation only handles integer arguments.  */

void
__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
{
  unsigned int *sp;
  va_list ap;
  int i;

  if (argc > 8)
    {
      fprintf (stderr, _("\
makecontext: does not know how to handle more than 8 arguments\n"));
      exit (-1);
    }

  /* Get stack pointer.  */
  sp = (unsigned int *) ucp->uc_stack.ss_sp;

  /* Store address to jump to.  */
  ucp->uc_mcontext.sc_gr[2] = (unsigned long) func;

  va_start (ap, argc);
  /* Handle arguments.  */
  for (i = 0; i < argc; ++i)
    switch (i)
      {
      case 0:
      case 1:
      case 2:
      case 3:
      	ucp->uc_mcontext.sc_gr[26-i] = va_arg (ap, int);
	break;
      case 4:
      case 5:
      case 6:
      case 7:
	if (sizeof(unsigned long) == 4) {
		/* 32bit: put arg7-arg4 on stack.  */
		sp[7-i] = va_arg (ap, int);
	} else {
		/* 64bit: r19-r22 are arg7-arg4.  */
		ucp->uc_mcontext.sc_gr[22+4-i] = va_arg (ap, int);
	}
	break;
      }
  va_end (ap);

}


weak_alias(__makecontext, makecontext)