1/*
2            Copyright Jiaxun Yang 2018.
3   Distributed under the Boost Software License, Version 1.0.
4      (See accompanying file LICENSE_1_0.txt or copy at
5          http://www.boost.org/LICENSE_1_0.txt)
6*/
7
8/*******************************************************
9 *                                                     *
10 *  -------------------------------------------------  *
11 *  |  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  *
12 *  -------------------------------------------------  *
13 *  |     0     |     8     |    16     |     24    |  *
14 *  -------------------------------------------------  *
15 *  |    F24    |    F25    |    F26    |    F27    |  *
16 *  -------------------------------------------------  *
17 *  -------------------------------------------------  *
18 *  |  8  |  9  |  10 |  11 |  12 |  13 |  14 |  15 |  *
19 *  -------------------------------------------------  *
20 *  |     32    |    40     |     48    |     56    |  *
21 *  -------------------------------------------------  *
22 *  |    F28    |    F29    |    F30    |    F31    |  *
23 *  -------------------------------------------------  *
24 *  -------------------------------------------------  *
25 *  |  16 |  17 |  18 |  19 |  20 |  21 |  22 |  23 |  *
26 *  -------------------------------------------------  *
27 *  |     64    |    72     |     80    |     88    |  *
28 *  -------------------------------------------------  *
29 *  |    S0     |    S1     |     S2    |     S3    |  *
30 *  -------------------------------------------------  *
31 *  -------------------------------------------------  *
32 *  |  24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  *
33 *  -------------------------------------------------  *
34 *  |  96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 |  *
35 *  -------------------------------------------------  *
36 *  |    S4     |    S5     |     S6    |     S7    |  *
37 *  -------------------------------------------------  *
38 *  -------------------------------------------------  *
39 *  |  32 |  33 |  34 |  35 |  36 |  37 |  38 |  39 |  *
40 *  -------------------------------------------------  *
41 *  | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 |  *
42 *  -------------------------------------------------  *
43 *  |    FP     |    GP     |     RA    |     PC    |  *
44 *  -------------------------------------------------  *
45 *                                                     *
46 * *****************************************************/
47
48.file "jump_mips64_n64_elf_gas.S"
49.text
50.globl jump_fcontext
51.align 3
52.type jump_fcontext,@function
53.ent jump_fcontext
54jump_fcontext:
55    # reserve space on stack
56    daddiu $sp, $sp, -160
57
58    sd  $s0, 64($sp)  # save S0
59    sd  $s1, 72($sp)  # save S1
60    sd  $s2, 80($sp)  # save S2
61    sd  $s3, 88($sp)  # save S3
62    sd  $s4, 96($sp)  # save S4
63    sd  $s5, 104($sp) # save S5
64    sd  $s6, 112($sp) # save S6
65    sd  $s7, 120($sp) # save S7
66    sd  $fp, 128($sp) # save FP
67    sd  $ra, 144($sp) # save RA
68    sd  $ra, 152($sp) # save RA as PC
69
70#if defined(__mips_hard_float)
71    s.d  $f24, 0($sp)   # save F24
72    s.d  $f25, 8($sp)   # save F25
73    s.d  $f26, 16($sp)  # save F26
74    s.d  $f27, 24($sp)  # save F27
75    s.d  $f28, 32($sp)  # save F28
76    s.d  $f29, 40($sp)  # save F29
77    s.d  $f30, 48($sp)  # save F30
78    s.d  $f31, 56($sp)  # save F31
79#endif
80
81    # store SP (pointing to old context-data) in v0 as return
82    move  $v0, $sp
83
84    # get SP (pointing to new context-data) from a0 param
85    move  $sp, $a0
86
87#if defined(__mips_hard_float)
88    l.d  $f24, 0($sp)   # restore F24
89    l.d  $f25, 8($sp)   # restore F25
90    l.d  $f26, 16($sp)  # restore F26
91    l.d  $f27, 24($sp)  # restore F27
92    l.d  $f28, 32($sp)  # restore F28
93    l.d  $f29, 40($sp)  # restore F29
94    l.d  $f30, 48($sp)  # restore F30
95    l.d  $f31, 56($sp)  # restore F31
96#endif
97
98    ld  $s0, 64($sp)  # restore S0
99    ld  $s1, 72($sp)  # restore S1
100    ld  $s2, 80($sp)  # restore S2
101    ld  $s3, 88($sp)  # restore S3
102    ld  $s4, 96($sp)  # restore S4
103    ld  $s5, 104($sp) # restore S5
104    ld  $s6, 112($sp) # restore S6
105    ld  $s7, 120($sp) # restore S7
106    ld  $fp, 128($sp) # restore FP
107    ld  $ra, 144($sp) # restore RAa
108
109    # load PC
110    ld  $t9, 152($sp)
111
112    # adjust stack
113    daddiu $sp, $sp, 160
114
115    move  $a0, $v0 # move old sp from v0 to a0 as param
116    move  $v1, $a1 # move *data from a1 to v1 as return
117
118    # jump to context
119    jr  $t9
120.end jump_fcontext
121.size jump_fcontext, .-jump_fcontext
122
123/* Mark that we don't need executable stack.  */
124.section .note.GNU-stack,"",%progbits
125