Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
鸿蒙内核源码分析
注释鸿蒙内核源码
提交
5d3039f7
注释鸿蒙内核源码
项目概览
鸿蒙内核源码分析
/
注释鸿蒙内核源码
通知
270
Star
29
Fork
11
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
106
Wiki
分析
仓库
DevOps
项目成员
Pages
注释鸿蒙内核源码
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
106
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5d3039f7
编写于
3月 08, 2021
作者:
鸿蒙内核源码分析
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
注解异常分发汇编代码
百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码
https://weharmony.gitee.io
上级
77d0c64f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
93 addition
and
91 deletion
+93
-91
arch/arm/arm/src/include/asm.h
arch/arm/arm/src/include/asm.h
+66
-66
arch/arm/arm/src/los_hw_exc.S
arch/arm/arm/src/los_hw_exc.S
+26
-24
zzz/git/push.sh
zzz/git/push.sh
+1
-1
未找到文件。
arch/arm/arm/src/include/asm.h
浏览文件 @
5d3039f7
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __ASM_H
#define __ASM_H
#ifdef __cplusplus
#if __cplusplus
extern
"C"
{
#endif
/* __cplusplus */
#endif
/* __cplusplus */
#define FUNCTION(x) .global x; .text; .code 32; x:
#define MPIDR_CPUID_MASK 0xFFU
/*
* ------------------------------------------
* stackTop | cpu n | ... | cpu 1 | cpu 0 | stackBottom
* ------------------------------------------
* | stackSize | ... | stackSize | stackSize |
*/
.
macro
EXC_SP_SET
stackBottom
,
stackSize
,
reg0
,
reg1
mrc
p15
,
0
,
\
reg0
,
c0
,
c0
,
5
and
\
reg0
,
\
reg0
,
#
MPIDR_CPUID_MASK
/* get cpu id */
mov
\
reg1
,
#\
stackSize
mul
\
reg1
,
\
reg1
,
\
reg0
/* calculate current cpu stack offset */
ldr
\
reg0
,
=
\
stackBottom
sub
\
reg0
,
\
reg0
,
\
reg1
/* calculate current cpu stack bottom */
mov
sp
,
\
reg0
/* set sp */
.
endm
#ifdef __cplusplus
#if __cplusplus
}
#endif
/* __cplusplus */
#endif
/* __cplusplus */
#endif
/* __ASM_H */
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __ASM_H
#define __ASM_H
#ifdef __cplusplus
#if __cplusplus
extern
"C"
{
#endif
/* __cplusplus */
#endif
/* __cplusplus */
#define FUNCTION(x) .global x; .text; .code 32; x:
#define MPIDR_CPUID_MASK 0xFFU
/*
* ------------------------------------------
* stackTop | cpu n | ... | cpu 1 | cpu 0 | stackBottom
* ------------------------------------------
* | stackSize | ... | stackSize | stackSize |
*/
.
macro
EXC_SP_SET
stackBottom
,
stackSize
,
reg0
,
reg1
mrc
p15
,
0
,
\
reg0
,
c0
,
c0
,
5
@获取
CPU
信息
and
\
reg0
,
\
reg0
,
#
MPIDR_CPUID_MASK
/* get cpu id */
@获取当前运行
CPUID
mov
\
reg1
,
#\
stackSize
@
reg1
记录
栈大小
mul
\
reg1
,
\
reg1
,
\
reg0
/* calculate current cpu stack offset */
@计算当前
CPU
栈的偏移位置
ldr
\
reg0
,
=
\
stackBottom
@
reg0
记录栈底
sub
\
reg0
,
\
reg0
,
\
reg1
/* calculate current cpu stack bottom */
@相减得到栈顶
mov
sp
,
\
reg0
/* set sp */
@设置
SP
,
将
SP
移到栈顶
.
endm
#ifdef __cplusplus
#if __cplusplus
}
#endif
/* __cplusplus */
#endif
/* __cplusplus */
#endif
/* __ASM_H */
arch/arm/arm/src/los_hw_exc.S
浏览文件 @
5d3039f7
...
...
@@ -277,9 +277,9 @@ _osExceptAddrAbortHdl: @地址异常处理
_osExceptFiqHdl
:
@快中断异常处理
SUB
LR
,
LR
,
#
4
@
LR
offset
to
return
from
this
exception
:
-
4
.
STMFD
SP
,
{
R0
-
R7
}
@
Push
working
registers
.
@
R0
~
R7
入栈保存
MOV
R0
,
#
OS_EXCEPT_FIQ
@
Set
exception
ID
to
OS_EXCEPT_FIQ
.
@
设置参数异常类型
,
将作为参数传给
_osExceptDispatch
B
_osExceptDispatch
@
Branch
to
global
exception
handler
.
_osExcPageFault
:
@缺页异常处理函数
...
...
@@ -328,41 +328,43 @@ _osExcPageFault: @缺页异常处理函数
@
Parameter
:
R0
Exception
Type
异常类型
@
Regs
Hold
:
R3
Exception
`
s
CPSR
发生异常时的
CPSR
值
@
note_thinking
鸿蒙官方的注释错了
,
应该是
Regs
Hold
:
R2
_osExceptDispatch
:
@处理异常分发
MRS
R2
,
SPSR
@
Save
CPSR
before
exception
.
MOV
R1
,
LR
@
Save
PC
before
exception
.
MRS
R2
,
SPSR
@
Save
CPSR
before
exception
.
先用
R2
保存
CPSR
MOV
R1
,
LR
@
Save
PC
before
exception
.
在用
R1
保存
PC
寄存器
SUB
R3
,
SP
,
#(
8
*
4
)
@
Save
the
start
address
of
working
registers
.
@
保存工作寄存器的起始地址
,
R0
~
R7
八个寄存器
MSR
CPSR_c
,
#(
CPSR_INT_DISABLE
|
CPSR_SVC_MODE
)
@
Switch
to
SVC
mode
,
and
disable
all
interrupts
MOV
R5
,
SP
EXC_SP_SET
__exc_stack_top
,
OS_EXC_STACK_SIZE
,
R6
,
R7
STMFD
SP
!,
{
R1
}
@
Push
Exception
PC
STMFD
SP
!,
{
LR
}
@
Push
SVC
LR
STMFD
SP
!,
{
R5
}
@
Push
SVC
SP
STMFD
SP
!,
{
R8
-
R12
}
@
Push
original
R12
-
R8
,
@
切换到
SVC
模式
,
屏蔽掉所有中断
MOV
R5
,
SP
@
R5
=
SP
,
保存
SP
位置
EXC_SP_SET
__exc_stack_top
,
OS_EXC_STACK_SIZE
,
R6
,
R7
@
切换到当前
CPU
的
SVC
模式栈处理
STMFD
SP
!,
{
R1
}
@
Push
Exception
PC
保存上一个工作模式的
PC
STMFD
SP
!,
{
LR
}
@
Push
SVC
LR
保存上一个工作模式的
LR
STMFD
SP
!,
{
R5
}
@
Push
SVC
SP
保存上一个工作模式的
SP
STMFD
SP
!,
{
R8
-
R12
}
@
Push
original
R12
-
R8
,
保存上一个工作模式的
R8
-
R12
LDMFD
R3
!,
{
R4
-
R11
}
@
Move
original
R7
-
R0
from
exception
stack
to
original
stack
.
STMFD
SP
!,
{
R4
-
R11
}
@
将保存在上一个工作模式的
R0
~
R7
取出
STMFD
SP
!,
{
R4
-
R11
}
@
将上一个工作模式的
R0
~
R7
保存到新的栈中
STMFD
SP
!,
{
R2
}
@
Push
task
`
s
CPSR
(
i
.
e
.
exception
SPSR
)
.
@
任务的
CPSR
入栈
CMP
R0
,
#
OS_EXCEPT_DATA_ABORT
@
是数据异常吗
?
BNE
1
f
@
不是跳到
锚点
1
处
MRC
P15
,
0
,
R8
,
C6
,
C0
,
0
@
R8
=
C6
(
内存失效的地址
)
0
(
访问数据失效
)
MRC
P15
,
0
,
R9
,
C5
,
C0
,
0
@
R9
=
C5
(
内存失效的状态
)
0
(
无效整个指令
cache
)
B
3
f
@
跳到锚点
3
处执行
1
:
CMP
R0
,
#
OS_EXCEPT_PREFETCH_ABORT
@
是预取异常吗
?
BNE
2
f
@
不是
跳到
锚点
2
处
BNE
2
f
@
不是
,
跳到
锚点
2
:
处运行
MRC
P15
,
0
,
R8
,
C6
,
C0
,
2
@
R8
=
C6
(
内存失效的地址
)
2
(
访问指令失效
)
MRC
P15
,
0
,
R9
,
C5
,
C0
,
1
@
R9
=
C5
(
内存失效的状态
)
1
(
虚拟地址
)
B
3
f
@
跳到锚点
3
处执行
2
:
MOV
R8
,
#
0
MOV
R9
,
#
0
3
:
AND
R2
,
R2
,
#
CPSR_MASK_MODE
CMP
R2
,
#
CPSR_USER_MODE
@
User
mode
BNE
4
f
@
不是用户模式
STMFD
SP
,
{
R13
,
R14
}^
@
save
user
mode
sp
and
lr
B
3
f
@
直接跳到
锚点
3
:
处执行
2
:
MOV
R8
,
#
0
@
R8
=
0
MOV
R9
,
#
0
@
R9
=
0
3
:
AND
R2
,
R2
,
#
CPSR_MASK_MODE
@
获取当前工作模式
CMP
R2
,
#
CPSR_USER_MODE
@
User
mode
是否为用户模式
BNE
4
f
@
不是用户模式
,
跳到
锚点
4
:
处运行
STMFD
SP
,
{
R13
,
R14
}^
@
save
user
mode
sp
and
lr
保存用户模式的
SP
和
LR
4
:
SUB
SP
,
SP
,
#(
4
*
2
)
@
sp
=
sp
-(
4
*
2
)
SUB
SP
,
SP
,
#(
4
*
2
)
@
sp
=
sp
-(
4
*
2
)
指向真正的栈顶
_osExceptionSwi
:
@软中断的处理,系统调用就是由软中断实现的
MOV
R1
,
SP
@
The
second
argument
to
the
exception
...
...
zzz/git/push.sh
浏览文件 @
5d3039f7
git add
-A
git commit
-m
'
(异常接管篇) | 社会很单纯,复杂的是人
git commit
-m
'
注解异常分发汇编代码
百万汉字注解 + 百篇博客分析 => 挖透鸿蒙内核源码
https://weharmony.gitee.io
'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录