• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #include <sched/sched.h>
13 #include <arch/machine/registers.h>
14 #include <object/thread.h>
15 #include <common/vars.h>
16 #include <mm/kmalloc.h>
17 #include <lib/printk.h>
18 
arch_idle_ctx_init(struct thread_ctx * idle_ctx,void (* func)(void))19 void arch_idle_ctx_init(struct thread_ctx *idle_ctx, void (*func)(void))
20 {
21     /* Initialize to run the function `idle_thread_routine` */
22     int i = 0;
23     arch_exec_ctx_t *ec = &(idle_ctx->ec);
24 
25     /* X0-X30 all zero */
26     for (i = 0; i < REG_NUM; i++)
27         ec->reg[i] = 0;
28     /* SPSR_EL1 => Exit to EL1 */
29     ec->reg[SPSR_EL1] = SPSR_EL1_KERNEL;
30     /* ELR_EL1 => Next PC */
31     ec->reg[ELR_EL1] = (u64)func;
32 }
33 
arch_switch_context(struct thread * target)34 void arch_switch_context(struct thread *target)
35 {
36     struct per_cpu_info *info;
37 
38     info = get_per_cpu_info();
39 
40     /* Set the `cur_exec_ctx` in the per_cpu info. */
41     info->cur_exec_ctx = (u64)target->thread_ctx;
42 }
43