1/*******************************************************
2 *                                                     *
3 *  -------------------------------------------------  *
4 *  |  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  *
5 *  -------------------------------------------------  *
6 *  |     0     |     8     |    16     |     24    |  *
7 *  -------------------------------------------------  *
8 *  |    FS0    |    FS1    |    FS2    |    FS3    |  *
9 *  -------------------------------------------------  *
10 *  -------------------------------------------------  *
11 *  |  8  |  9  |  10 |  11 |  12 |  13 |  14 |  15 |  *
12 *  -------------------------------------------------  *
13 *  |     32    |    40     |     48    |     56    |  *
14 *  -------------------------------------------------  *
15 *  |    FS4    |    FS5    |    FS6    |    FS7    |  *
16 *  -------------------------------------------------  *
17 *  -------------------------------------------------  *
18 *  |  16 |  17 |  18 |  19 |  20 |  21 |  22 |  23 |  *
19 *  -------------------------------------------------  *
20 *  |     64    |    72     |     80    |     88    |  *
21 *  -------------------------------------------------  *
22 *  |    S0     |    S1     |     S2    |     S3    |  *
23 *  -------------------------------------------------  *
24 *  -------------------------------------------------  *
25 *  |  24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  *
26 *  -------------------------------------------------  *
27 *  |  96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 |  *
28 *  -------------------------------------------------  *
29 *  |    S4     |    S5     |     S6    |     S7    |  *
30 *  -------------------------------------------------  *
31 *  -------------------------------------------------  *
32 *  |  32 |  33 |  34 |  35 |  36 |  37 |  38 |  39 |  *
33 *  -------------------------------------------------  *
34 *  | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 |  *
35 *  -------------------------------------------------  *
36 *  |    S8     |    FP     |     RA    |     PC    |  *
37 *  -------------------------------------------------  *
38 *                                                     *
39 * *****************************************************/
40
41.file "jump_loongarch64_sysv_elf_gas.S"
42.text
43.globl jump_fcontext
44.align 2
45.type jump_fcontext,@function
46jump_fcontext:
47    # reserve space on stack
48    addi.d  $sp, $sp, -160
49
50    # save fs0 - fs7
51    fst.d  $fs0, $sp, 0
52    fst.d  $fs1, $sp, 8
53    fst.d  $fs2, $sp, 16
54    fst.d  $fs3, $sp, 24
55    fst.d  $fs4, $sp, 32
56    fst.d  $fs5, $sp, 40
57    fst.d  $fs6, $sp, 48
58    fst.d  $fs7, $sp, 56
59
60    # save s0 - s8, fp, ra
61    st.d  $s0, $sp, 64
62    st.d  $s1, $sp, 72
63    st.d  $s2, $sp, 80
64    st.d  $s3, $sp, 88
65    st.d  $s4, $sp, 96
66    st.d  $s5, $sp, 104
67    st.d  $s6, $sp, 112
68    st.d  $s7, $sp, 120
69    st.d  $s8, $sp, 128
70    st.d  $fp, $sp, 136
71    st.d  $ra, $sp, 144
72
73    # save RA as PC
74    st.d  $ra, $sp, 152
75
76    # store SP (pointing to context-data) in A2
77    move  $a2, $sp
78
79    # restore SP (pointing to context-data) from A0
80    move  $sp, $a0
81
82    # load fs0 - fs7
83    fld.d  $fs0, $sp, 0
84    fld.d  $fs1, $sp, 8
85    fld.d  $fs2, $sp, 16
86    fld.d  $fs3, $sp, 24
87    fld.d  $fs4, $sp, 32
88    fld.d  $fs5, $sp, 40
89    fld.d  $fs6, $sp, 48
90    fld.d  $fs7, $sp, 56
91
92    #load s0 - s7
93    ld.d  $s0, $sp, 64
94    ld.d  $s1, $sp, 72
95    ld.d  $s2, $sp, 80
96    ld.d  $s3, $sp, 88
97    ld.d  $s4, $sp, 96
98    ld.d  $s5, $sp, 104
99    ld.d  $s6, $sp, 112
100    ld.d  $s7, $sp, 120
101    ld.d  $s8, $sp, 128
102    ld.d  $fp, $sp, 136
103    ld.d  $ra, $sp, 144
104
105    # return transfer_t from jump
106    # pass transfer_t as first arg in context function
107    # a0 == FCTX, a1 == DATA
108    move  $a0, $a2
109
110    # load PC
111    ld.d  $a2, $sp, 152
112
113    # restore stack
114    addi.d  $sp, $sp, 160
115
116    # jump to context
117    jr  $a2
118.size jump_fcontext, .-jump_fcontext
119
120/* Mark that we don't need executable stack.  */
121.section .note.GNU-stack,"",%progbits
122