1// Copyright 2020 The Marl Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#if defined(__mips__) && _MIPS_SIM == _ABI64
16
17#define MARL_BUILD_ASM 1
18#include "osfiber_asm_mips64.h"
19
20// void marl_fiber_swap(marl_fiber_context* from, const marl_fiber_context* to)
21// a0: from
22// v0: to
23.text
24.global MARL_ASM_SYMBOL(marl_fiber_swap)
25.align 4
26MARL_ASM_SYMBOL(marl_fiber_swap):
27
28 // Save context 'from'
29
30 // Store callee-preserved registers
31 sd $s0, MARL_REG_s0($a0)
32 sd $s1, MARL_REG_s1($a0)
33 sd $s2, MARL_REG_s2($a0)
34 sd $s3, MARL_REG_s3($a0)
35 sd $s4, MARL_REG_s4($a0)
36 sd $s5, MARL_REG_s5($a0)
37 sd $s6, MARL_REG_s6($a0)
38 sd $s7, MARL_REG_s7($a0)
39
40 s.d $f24, MARL_REG_f24($a0)
41 s.d $f25, MARL_REG_f25($a0)
42 s.d $f26, MARL_REG_f26($a0)
43 s.d $f27, MARL_REG_f27($a0)
44 s.d $f28, MARL_REG_f28($a0)
45 s.d $f29, MARL_REG_f29($a0)
46 s.d $f31, MARL_REG_f30($a0)
47 s.d $f31, MARL_REG_f31($a0)
48
49 sd $gp, MARL_REG_gp($a0)
50 sd $sp, MARL_REG_sp($a0)
51 sd $fp, MARL_REG_fp($a0)
52 sd $ra, MARL_REG_ra($a0)
53
54 move $v0, $a1 // Function have no return, so safe to touch v0
55
56 // Recover callee-preserved registers
57 ld $s0, MARL_REG_s0($v0)
58 ld $s1, MARL_REG_s1($v0)
59 ld $s2, MARL_REG_s2($v0)
60 ld $s3, MARL_REG_s3($v0)
61 ld $s4, MARL_REG_s4($v0)
62 ld $s5, MARL_REG_s5($v0)
63 ld $s6, MARL_REG_s6($v0)
64 ld $s7, MARL_REG_s7($v0)
65
66 l.d $f24, MARL_REG_f24($v0)
67 l.d $f25, MARL_REG_f25($v0)
68 l.d $f26, MARL_REG_f26($v0)
69 l.d $f27, MARL_REG_f27($v0)
70 l.d $f28, MARL_REG_f28($v0)
71 l.d $f29, MARL_REG_f29($v0)
72 l.d $f31, MARL_REG_f30($v0)
73 l.d $f31, MARL_REG_f31($v0)
74
75 ld $gp, MARL_REG_gp($v0)
76 ld $sp, MARL_REG_sp($v0)
77 ld $fp, MARL_REG_fp($v0)
78 ld $ra, MARL_REG_ra($v0)
79
80 // Recover arguments
81 ld $a0, MARL_REG_a0($v0)
82 ld $a1, MARL_REG_a1($v0)
83
84 jr $ra
85
86#endif // defined(__mips__) && _MIPS_SIM == _ABI64
87