• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
3 *
4 * UniProton is licensed under Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *          http://license.coscl.org.cn/MulanPSL2
8 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11 * See the Mulan PSL v2 for more details.
12 * Create: 2022-11-22
13 * Description: 线程调度的汇编部分。
14 */
15#include "prt_buildef.h"
16#include "prt_asm_arm_external.h"
17
18    .global g_sysStackHigh
19    .global OsHwiDispatch, OsMainSchedule
20
21    .type   OsMainSchedule, function
22
23// save x2~x30, xzr
24.macro GENERAL_REGS_SAVE
25    stp x3, x2, [sp,#-16]!
26    stp x5, x4, [sp,#-16]!
27    stp x7, x6, [sp,#-16]!
28    stp x9, x8, [sp,#-16]!
29    stp x11, x10, [sp,#-16]!
30    stp x13, x12, [sp,#-16]!
31    stp x15, x14, [sp,#-16]!
32    stp x17, x16, [sp,#-16]!
33    stp x19, x18, [sp,#-16]!
34    stp x21, x20, [sp,#-16]!
35    stp x23, x22, [sp,#-16]!
36    stp x25, x24, [sp,#-16]!
37    stp x27, x26, [sp,#-16]!
38    stp x29, x28, [sp,#-16]!
39    stp xzr, x30, [sp,#-16]!
40.endm
41
42    .section .os.text, "ax"
43
44/*
45 * 描述: Task调度处理函数。 X0 is g_runningTask
46 */
47    .globl OsTaskTrap
48    .type OsTaskTrap, @function
49    .align 4
50
51OsTaskTrap:
52    LDR    x1, =g_runningTask /* OsTaskTrap是函数调用过来,x0 x1寄存器是caller save,此处能直接使用 */
53    LDR    x0, [x1] /* x0 is the &g_pRunningTask->sp */
54
55    stp    x1, x0, [sp,#-16]!
56    GENERAL_REGS_SAVE
57
58    /* TskTrap需要保存CPSR,由于不能直接访问,需要拼接获取当前CPSR入栈 */
59    mrs    x3, DAIF /* CPSR:DAIF 4种事件的mask, bits[9:6] */
60    mrs    x2, NZCV /* NZCV:Condition flags, bits[31:28] */
61    orr    x3, x3, x2
62    orr    x3, x3, #(0x1U << 2) /* 当前的 exception level,bits[3:2] 00:EL0,01:El1,10:El2,11:EL3 */
63    orr    x3, x3, #(0x1U) /* 当前栈的选择,bits[0] 0:SP_EL0,1:SP_ELX */
64
65    mov    x2, x30    // 用返回地址x30作为现场恢复点
66    sub    sp, sp, #16  // 跳过esr_el1, far_el1, 异常时才有用
67    stp    x2, x3, [sp,#-16]!
68
69    // 存入SP指针到g_pRunningTask->sp
70    mov    x1, sp
71    str    x1, [x0]   // x0 is the &g_pRunningTask->sp
72
73    ldr    x0, =g_sysStackHigh
74    ldr    x0, [x0]
75    mov    sp, x0
76    B      OsMainSchedule
77loop1:
78    B      loop1
79
80/*
81 * 描述: hwi分发
82 */
83    .globl OsHwiDispatcher
84    .type OsHwiDispatcher, @function
85    .align 4
86OsHwiDispatcher:
87    GENERAL_REGS_SAVE
88
89    mrs    x3, spsr_el1
90    mrs    x2, elr_el1
91    sub    sp, sp, #16  // 跳过esr_el1, far_el1, 异常时才有用
92    stp    x2, x3, [sp,#-16]!
93
94    MOV    x0, SP
95
96    BL     OsHwiDispatch   // 跳转C代码继续处理中断
97
98    // 中断嵌套,tick嵌套场景, 会从OsHwiDispatch返回
99    b     OsContextLoad
100
101/*
102 * 描述: void OsTskContextLoad(uintptr_t stackPointer)
103 */
104    .globl OsTskContextLoad
105    .type OsTskContextLoad, @function
106    .align 4
107OsTskContextLoad:
108    ldr    X0, [X0]
109    mov    SP, X0            // X0 is stackPointer
110
111OsContextLoad:
112    ldp    x2, x3, [sp],#16
113    add    sp, sp, #16        // 跳过far, esr, HCR_EL2.TRVM==1的时候,EL1不能写far, esr
114    msr    spsr_el1, x3
115    msr    elr_el1, x2
116    dsb    sy
117    isb
118    ldp    xzr, x30, [sp],#16
119    ldp    x29, x28, [sp],#16
120    ldp    x27, x26, [sp],#16
121    ldp    x25, x24, [sp],#16
122    ldp    x23, x22, [sp],#16
123    ldp    x21, x20, [sp],#16
124    ldp    x19, x18, [sp],#16
125    ldp    x17, x16, [sp],#16
126    ldp    x15, x14, [sp],#16
127    ldp    x13, x12, [sp],#16
128    ldp    x11, x10, [sp],#16
129    ldp    x9, x8, [sp],#16
130    ldp    x7, x6, [sp],#16
131    ldp    x5, x4, [sp],#16
132    ldp    x3, x2, [sp],#16
133    ldp    x1, x0, [sp],#16
134    eret
135
136    .globl OsSetSysStackSP
137    .type OsSetSysStackSP, @function
138    .align 4
139OsSetSysStackSP:
140    MOV    SP, X0
141    MOV    X0, X1
142    BL     OsHwiDispatchHandle
143
144    .text
145