1 /*
2  * Copyright (C) 2016 YunOS Project. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <k_api.h>
18 
cpu_task_stack_init(cpu_stack_t * stack_base,size_t stack_size,void * arg,task_entry_t entry)19 void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size,
20                           void *arg, task_entry_t entry)
21 {
22     cpu_stack_t *stk;
23     register int *gp asm("x3");
24     uint32_t temp = (uint32_t)(stack_base + stack_size);
25 
26     temp &= 0xFFFFFFF8UL;
27 
28     stk = (cpu_stack_t *)temp;
29 
30     *(--stk) = (uint32_t)entry;                   /* PC            */
31     *(--stk) = (uint32_t)0x15151515L;             /* X15           */
32     *(--stk) = (uint32_t)0x14141414L;             /* X14           */
33     *(--stk) = (uint32_t)0x13131313L;             /* X13           */
34     *(--stk) = (uint32_t)0x12121212L;             /* X12           */
35     *(--stk) = (uint32_t)0x11111111L;             /* X11           */
36     *(--stk) = (uint32_t)arg;                     /* X10           */
37     *(--stk) = (uint32_t)0x09090909L;             /* X9            */
38     *(--stk) = (uint32_t)0x08080808L;             /* X8            */
39     *(--stk) = (uint32_t)0x07070707L;             /* X7            */
40     *(--stk) = (uint32_t)0x06060606L;             /* X6            */
41     *(--stk) = (uint32_t)0x05050505L;             /* X5            */
42     *(--stk) = (uint32_t)0x04040404L;             /* X4            */
43     *(--stk) = (uint32_t)gp;                      /* X3            */
44     *(--stk) = (uint32_t)krhino_task_deathbed;    /* X1            */
45 
46     return stk;
47 }
48 
49