blob: 7b09c5843182cbc43da5650367b70688b57dac0e [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
19void yarn_fiber_trampoline(void(*target)(void*), void* arg)
20{
21 target(arg);
22}
23
24void yarn_fiber_set_target(struct yarn_fiber_context* ctx, void* stack, uint32_t stack_size, void(*target)(void*), void* arg)
25{
26 uintptr_t* stack_top = (uintptr_t*)((uint8_t*)(stack) + stack_size);
27 ctx->LR = (uintptr_t)&yarn_fiber_trampoline;
28 ctx->r0 = (uintptr_t)target;
29 ctx->r1 = (uintptr_t)arg;
30 ctx->SP = ((uintptr_t)stack_top) & ~(uintptr_t)15;
31}
32
33#endif // defined(__aarch64__)