Blame sysdeps/unix/sysv/linux/sparc/sparc64/makecontext.c

Packit 6c4009
/* Copyright (C) 2001-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Jakub Jelinek <jakub@redhat.com>.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <stdarg.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <ucontext.h>
Packit 6c4009
Packit 6c4009
extern void __start_context (ucontext_t *ucp);
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
Packit 6c4009
{
Packit 6c4009
  extern void __makecontext_ret (void);
Packit 6c4009
  unsigned long *sp, *topsp;
Packit 6c4009
  va_list ap;
Packit 6c4009
  int i;
Packit 6c4009
Packit 6c4009
  sp = (unsigned long *) ((long) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
Packit 6c4009
  sp -= (argc > 6 ? argc : 6) + 32;
Packit 6c4009
  sp = (unsigned long *) (((long) sp) & -16L);
Packit 6c4009
  topsp = sp + (argc > 6 ? argc : 6) + 16;
Packit 6c4009
Packit 6c4009
  ucp->uc_mcontext.mc_gregs[MC_PC] = (long) func;
Packit 6c4009
  ucp->uc_mcontext.mc_gregs[MC_NPC] = ((long) func) + 4;
Packit 6c4009
  ucp->uc_mcontext.mc_gregs[MC_O6] = ((long) sp) - 0x7ff;
Packit 6c4009
  ucp->uc_mcontext.mc_gregs[MC_O7] = ((long) __start_context) - 8;
Packit 6c4009
  ucp->uc_mcontext.mc_fp = ((long) topsp) - 0x7ff;
Packit 6c4009
  ucp->uc_mcontext.mc_i7 = 0;
Packit 6c4009
  topsp[14] = 0;
Packit 6c4009
  topsp[15] = 0;
Packit 6c4009
  sp[8] = (long) ucp->uc_link;
Packit 6c4009
  va_start (ap, argc);
Packit 6c4009
  for (i = 0; i < argc; ++i)
Packit 6c4009
    if (i < 6)
Packit 6c4009
      ucp->uc_mcontext.mc_gregs[MC_O0 + i] = va_arg (ap, long);
Packit 6c4009
    else
Packit 6c4009
      sp[16 + i] = va_arg (ap, long);
Packit 6c4009
  va_end (ap);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
weak_alias (__makecontext, makecontext)