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