1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#include <autoconf.h>
14#include <sel4utils/gen_config.h>
15#include <sel4/types.h>
16#include <sel4utils/thread.h>
17#include <sel4utils/helpers.h>
18#include <utils/zf_log.h>
19#include <utils/stack.h>
20#include <stdbool.h>
21
22int sel4utils_arch_init_context(void *entry_point, void *stack_top, seL4_UserContext *context)
23{
24    context->pc = (seL4_Word) entry_point;
25    context->sp = (seL4_Word) stack_top;
26    if (!IS_ALIGNED((uintptr_t)stack_top, STACK_CALL_ALIGNMENT_BITS)) {
27        ZF_LOGE("Initial stack pointer must be %d byte aligned", STACK_CALL_ALIGNMENT);
28        return -1;
29    }
30    return 0;
31}
32
33int sel4utils_arch_init_context_with_args(sel4utils_thread_entry_fn entry_point,
34                                          void *arg0, void *arg1, void *arg2,
35                                          bool local_stack, void *stack_top,
36                                          seL4_UserContext *context,
37                                          vka_t *vka, vspace_t *local_vspace, vspace_t *remote_vspace)
38{
39
40    context->x0 = (seL4_Word) arg0;
41    context->x1 = (seL4_Word) arg1;
42    context->x2 = (seL4_Word) arg2;
43
44    return sel4utils_arch_init_context(entry_point, stack_top, context);
45}
46