1/*******************************************************
2 *  -------------------------------------------------  *
3 *  |  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  *
4 *  -------------------------------------------------  *
5 *  |     0     |     8     |    16     |    24     |  *
6 *  -------------------------------------------------  *
7 *  |   t.fctx  |   t.data  |    r2     |    r6     |  *
8 *  -------------------------------------------------  *
9 *  -------------------------------------------------  *
10 *  |  8  |  9  |  10 |  11 |  12 |  13 |  14 |  15 |  *
11 *  -------------------------------------------------  *
12 *  |     32    |    40     |     48    |     56    |  *
13 *  -------------------------------------------------  *
14 *  |     r7    |     r8    |     r9    |    r10    |  *
15 *  -------------------------------------------------  *
16 *  -------------------------------------------------  *
17 *  |  16 |  17 |  18 |  19 |  20 |  21 |  22 |  23 |  *
18 *  -------------------------------------------------  *
19 *  |     64    |     72    |     80    |     88    |  *
20 *  -------------------------------------------------  *
21 *  |    r11    |    r12    |    r13    |    r14    |  *
22 *  -------------------------------------------------  *
23 *  -------------------------------------------------  *
24 *  |  24 |  25 |  26 |  27 |  28 | 29  |  30 |  31 |  *
25 *  -------------------------------------------------  *
26 *  |     96    |    104    |    112    |    120    |  *
27 *  -------------------------------------------------  *
28 *  |     f8    |     f9    |    f10    |    f11    |  *
29 *  -------------------------------------------------  *
30 *  -------------------------------------------------  *
31 *  |  32 |  33 |  34 |  35 |  36 |  37 |  38 |  39 |  *
32 *  -------------------------------------------------  *
33 *  |    128    |    136    |    144    |    152    |  *
34 *  -------------------------------------------------  *
35 *  |    f12    |    f13    |    f14    |    f15    |  *
36 *  -------------------------------------------------  *
37 *  -------------------------------------------------  *
38 *  |  40 |  41 |  42 |  43 |  44 |  45 |  46 |  47 |  *
39 *  -------------------------------------------------  *
40 *  |    160    |    168    |    176    |           |  *
41 *  -------------------------------------------------  *
42 *  |    fpc    |     pc    |           |           |  *
43 *  -------------------------------------------------  *
44 *******************************************************/
45
46.text
47.align	8
48.global	make_fcontext
49.type	make_fcontext, @function
50
51#define ARG_OFFSET         0
52#define GR_OFFSET	   16
53#define R14_OFFSET	   88
54#define FP_OFFSET	   96
55#define FPC_OFFSET	   160
56#define PC_OFFSET	   168
57#define CONTEXT_SIZE	   176
58
59/*
60
61fcontext_t make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) );
62
63Create and return a context below SP to call FN.
64
65Incoming args
66r2 - The stack location where to create the context
67r3 - The size of the context
68r4 - The address of the context function
69
70*/
71
72make_fcontext:
73	.machine "z10"
74	/* Align the stack to an 8 byte boundary.  */
75	nill    %r2,0xfff0
76
77	/* Allocate stack space for the context.  */
78	aghi	%r2,-CONTEXT_SIZE
79
80	/* Set the r2 save slot to zero.  This indicates jump_fcontext
81	   that this is a special context.  */
82	mvghi	GR_OFFSET(%r2),0
83
84	/* Save the floating point control register.  */
85	stfpc	FPC_OFFSET(%r2)
86
87	/* Store the address of the target function as new pc.  */
88	stg	%r4,PC_OFFSET(%r2)
89
90	/* Store a pointer to the finish routine as r14. If a function
91	   called via context routines just returns that value will be
92	   loaded and used as return address.  Hence the program will
93	   just exit.  */
94	larl	%r1,finish
95	stg	%r1,R14_OFFSET(%r2)
96
97	/* Return as usual with the new context returned in r2.  */
98	br	%r14
99
100finish:
101	/* In finish tasks, you load the exit code and exit the
102	   make_fcontext This is called when the context-function is
103	   entirely executed.  */
104	lghi	%r2,0
105	brasl	%r14,_exit@PLT
106
107.size   make_fcontext,.-make_fcontext
108.section .note.GNU-stack,"",%progbits
109