OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [tools/] [riscv-gnu-toolchain-master/] [glibc/] [sysdeps/] [unix/] [sysv/] [linux/] [riscv/] [makecontext.c] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 serginhofr
#include <sysdep.h>
2
#include <sys/asm.h>
3
#include <sys/ucontext.h>
4
#include <stdarg.h>
5
#include <assert.h>
6
 
7
void __makecontext (ucontext_t *ucp, void (*func) (void), int argc,
8
                    long a0, long a1, long a2, long a3, long a4, ...)
9
{
10
  extern void __start_context(void) attribute_hidden;
11
  long i, sp;
12
 
13
  assert(REG_NARGS == 8);
14
 
15
  /* Set up the stack. */
16
  sp = ((long)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ALMASK;
17
 
18
  /* Set up the register context.
19
     ra = s0 = 0, terminating the stack for backtracing purposes.
20
     s1 = the function we must call.
21
     s2 = the subsequent context to run.  */
22
  ucp->uc_mcontext.gregs[REG_RA] = 0;
23
  ucp->uc_mcontext.gregs[REG_S0 + 0] = 0;
24
  ucp->uc_mcontext.gregs[REG_S0 + 1] = (long)func;
25
  ucp->uc_mcontext.gregs[REG_S0 + 2] = (long)ucp->uc_link;
26
  ucp->uc_mcontext.gregs[REG_SP] = sp;
27
  ucp->uc_mcontext.gregs[REG_PC] = (long)&__start_context;
28
 
29
  /* Put args in a0-a7, then put any remaining args on the stack. */
30
  ucp->uc_mcontext.gregs[REG_A0 + 0] = a0;
31
  ucp->uc_mcontext.gregs[REG_A0 + 1] = a1;
32
  ucp->uc_mcontext.gregs[REG_A0 + 2] = a2;
33
  ucp->uc_mcontext.gregs[REG_A0 + 3] = a3;
34
  ucp->uc_mcontext.gregs[REG_A0 + 4] = a4;
35
 
36
  if (__builtin_expect (argc > 5, 0))
37
    {
38
      va_list vl;
39
      va_start(vl, a4);
40
 
41
      long reg_args = argc < REG_NARGS ? argc : REG_NARGS;
42
      sp = (sp - (argc - reg_args) * sizeof(long)) & ALMASK;
43
      for (i = 5; i < reg_args; i++)
44
        ucp->uc_mcontext.gregs[REG_A0 + i] = va_arg(vl, long);
45
      for (i = 0; i < argc - reg_args; i++)
46
        ((long*)sp)[i] = va_arg(vl, long);
47
 
48
      va_end(vl);
49
    }
50
}
51
 
52
weak_alias (__makecontext, makecontext)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.