blob: 95abb0647c1a1d4e62d1857b36b454aae981889c [file] [log] [blame]
Ben Claytonad9f5102019-08-06 22:47:58 +01001// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
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// http://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(__aarch64__)
16
17#include "OSFiber_asm_aarch64.h"
18
19// void yarn_fiber_swap(yarn_fiber_context* from, const yarn_fiber_context* to)
20// x0: from
21// x1: to
22.text
23.global YARN_ASM_SYMBOL(yarn_fiber_swap)
24.align 4
25YARN_ASM_SYMBOL(yarn_fiber_swap):
26
27 // Save context 'from'
28 // TODO: pairs of str can be combined with stp.
29
30 // Store special purpose registers
31 str x16, [x0, #YARN_REG_r16]
32 str x17, [x0, #YARN_REG_r17]
33 str x18, [x0, #YARN_REG_r18]
34
35 // Store callee-preserved registers
36 str x19, [x0, #YARN_REG_r19]
37 str x20, [x0, #YARN_REG_r20]
38 str x21, [x0, #YARN_REG_r21]
39 str x22, [x0, #YARN_REG_r22]
40 str x23, [x0, #YARN_REG_r23]
41 str x24, [x0, #YARN_REG_r24]
42 str x25, [x0, #YARN_REG_r25]
43 str x26, [x0, #YARN_REG_r26]
44 str x27, [x0, #YARN_REG_r27]
45 str x28, [x0, #YARN_REG_r28]
46
47 str d8, [x0, #YARN_REG_v8]
48 str d9, [x0, #YARN_REG_v9]
49 str d10, [x0, #YARN_REG_v10]
50 str d11, [x0, #YARN_REG_v11]
51 str d12, [x0, #YARN_REG_v12]
52 str d13, [x0, #YARN_REG_v13]
53 str d14, [x0, #YARN_REG_v14]
54 str d15, [x0, #YARN_REG_v15]
55
56 // Store sp and lr
57 mov x2, sp
58 str x2, [x0, #YARN_REG_SP]
59 str x30, [x0, #YARN_REG_LR]
60
61 // Load context 'to'
62 mov x7, x1
63
64 // Load special purpose registers
65 ldr x16, [x7, #YARN_REG_r16]
66 ldr x17, [x7, #YARN_REG_r17]
67 ldr x18, [x7, #YARN_REG_r18]
68
69 // Load callee-preserved registers
70 ldr x19, [x7, #YARN_REG_r19]
71 ldr x20, [x7, #YARN_REG_r20]
72 ldr x21, [x7, #YARN_REG_r21]
73 ldr x22, [x7, #YARN_REG_r22]
74 ldr x23, [x7, #YARN_REG_r23]
75 ldr x24, [x7, #YARN_REG_r24]
76 ldr x25, [x7, #YARN_REG_r25]
77 ldr x26, [x7, #YARN_REG_r26]
78 ldr x27, [x7, #YARN_REG_r27]
79 ldr x28, [x7, #YARN_REG_r28]
80
81 ldr d8, [x7, #YARN_REG_v8]
82 ldr d9, [x7, #YARN_REG_v9]
83 ldr d10, [x7, #YARN_REG_v10]
84 ldr d11, [x7, #YARN_REG_v11]
85 ldr d12, [x7, #YARN_REG_v12]
86 ldr d13, [x7, #YARN_REG_v13]
87 ldr d14, [x7, #YARN_REG_v14]
88 ldr d15, [x7, #YARN_REG_v15]
89
90 // Load parameter registers
91 ldr x0, [x7, #YARN_REG_r0]
92 ldr x1, [x7, #YARN_REG_r1]
93
94 // Load sp and lr
95 ldr x30, [x7, #YARN_REG_LR]
96 ldr x2, [x7, #YARN_REG_SP]
97 mov sp, x2
98
99 ret
100
101#endif // defined(__aarch64__)