Compare commits

..

49 Commits

Author SHA1 Message Date
openharmony_ci 1eb753cd25
!1075 【挑单】time相关系统调用内核栈信息泄露排查
Merge pull request !1075 from zhushengle/OpenHarmony_1.0.1_release
2022-11-23 08:14:13 +00:00
zhushengle 19769f795b fix: time相关系统调用内核栈信息泄露排查
Close #I620AB
Signed-off-by: zhushengle <zhushengle@huawei.com>
2022-11-19 11:26:04 +08:00
openharmony_ci 5b44332cff !642 解决release1.0.1分支内核关闭中断后在写BUFF满了后卡住问题
Merge pull request !642 from wanghao-free/OpenHarmony_1.0.1_release
2021-09-30 01:56:11 +00:00
wanghao-free 0d50fad855 fix:解决release1.0.1分支内核关闭中断后在写BUFF满了后卡住问题
主干存在该问题,release分支先合入

添加cnt==0以及关中断的判断条件,在符合这种情况时跳出死循环,避免卡住

Signed-off-by: wanghao-free <wanghao453@huawei.com>
2021-09-28 20:10:13 -07:00
openharmony_ci a37c850d1b !622 解决OsLockDepCheckIn异常处理中存在锁嵌套调用 导致死锁异常信息不正常输出问题
Merge pull request !622 from wanghao-free/OpenHarmony_1.0.1_release
2021-09-22 06:50:00 +00:00
wanghao-free 1eca7a502a fix: 解决OsLockDepCheckIn异常处理中存在锁嵌套调用
导致死锁异常信息不正常输出问题

主干存在该问题,修改同步release分支

新增加异常信息打印输出函数,用局部数组保存输出信息,避免锁嵌套问题

Close #I457ZZ

Signed-off-by: wanghao-free <wanghao453@huawei.com>
2021-09-14 23:35:56 -07:00
openharmony_ci 80e24fa9db !618 回退错误合入的解决getgroups的list比设置的list多一个gid问题的修改
Merge pull request !618 from wanghao-free/OpenHarmony_1.0.1_release
2021-09-09 14:54:09 +00:00
wanghao-free 15bded54c9 fix: 回退错误合入的解决getgroups的list比设置的list多一个gid问题的修改
主干不存在该问题.

回退原因是要求维护这边合入的人没有跟问题修改人赵天宇确认,实际上这个问题单解决不在内核这边,
内核这边的提交需要回退

Close #I48FMK

Signed-off-by: wanghao-free <wanghao453@huawei.com>
2021-09-09 02:30:38 -07:00
openharmony_ci 2a0db42072 !616 release分支解决nanosleep 接口的rmtp参数被错误清零问题
Merge pull request !616 from wanghao-free/OpenHarmony_1.0.1_release
2021-09-09 08:34:13 +00:00
openharmony_ci de82bf893a !615 shell命令中rm -r指令尝试删除/dev下节点系统出错
Merge pull request !615 from 高荣鑫/OpenHarmony_1.0.1_release
2021-09-09 06:40:27 +00:00
openharmony_ci a0bb06189d !614 修复子进程setgroups时会额外加上父进程gid,导致getgroups的list比设置的list多一个gid的问题
Merge pull request !614 from 刘占伟/OpenHarmony_1.0.1_release
2021-09-09 06:39:12 +00:00
openharmony_ci a8513ae614 !613 解决sd卡读写操作时对卡进行热插拔后,disk资源未释放问题
Merge pull request !613 from 董逸群/OpenHarmony_1.0.1_release
2021-09-09 06:38:33 +00:00
wanghao-free 0c203c1e57 fix: 解决nanosleep 接口的rmtp参数被错误清零问题
主干不存在该问题,已解决.

nanosleep 使线程进入到了可被信号中断的状态,当线程睡眠被信号
中断,线程回复运行态时,若rmtp不为NULL,则会将sleep剩余的时间
记录在rmtp参数中返回,但是如果线程sleep过程中未被信号唤醒,
则忽略该参数。

由于鸿蒙中nanosleep是不可被打断的,即rmtp应该被忽略,而不是清零。

Close #I48FMT

Signed-off-by: wanghao-free <wanghao453@huawei.com>
2021-09-08 20:04:54 -07:00
gao-rongxin 93658ba478 fix: 解决shell命令中rm -r指令尝试删除/dev下节点系统出错的问题
主干不存在该问题,已解决.

shell命令rm中当opendir时没有正确判断opendir的返回值,
导致后续访问空指针.

检查opendir的返回值,当opendir失败时返回-1.

Close #I48FLX

Signed-off-by: gao-rongxin <gaorongxin1@huawei.com>
2021-09-08 19:49:51 -07:00
liu-zhanwei 58aea01f5a fix: 修复子进程setgroups时会额外加上父进程gid,导致getgroups的list比设置的list多一个gid的问题
主干不存在该问题,已解决.

子进程setgroups时会额外加上父进程gid,导致groups总是多出一个,与posix标准不符
setgroups时,若经过了入参校验,传入的list直接覆盖设置为groups,当groups个数为0,则getgroups直接返回0

close:  #I48FMK
Signed-off-by: liu-zhanwei <liuzhanwei4@huawei.com>
2021-09-08 19:24:16 -07:00
dong-yiqun d39ed70c65 fix:解决disk资源未释放导致的资源泄露问题
主干存在该问题,还未解决.

因为对于热插入的sd卡,如果被其中一个线程操作拿住锁资源,

热插拔会导致disk资源状态未修改为UNUSED,造成资源泄露

现在修改为在拔出sd卡时,销毁disk锁资源之前,先将disk状态修改成UNUSED

Close #I3ZOIO

Signed-off-by: dong-yiqun <dongyiqun@huawei.com>
2021-09-09 10:23:36 +08:00
openharmony_ci 3e6bab5158 !612 修改commit msg后重新上传,解决OsMountRootfs失败问题
Merge pull request !612 from wanghao-free/OpenHarmony_1.0.1_release
2021-09-08 09:56:11 +00:00
wanghao-free 672cff7ee5 fix: 解决OsMountRootfs失败问题
主干存在该问题,下一步同步主干.

挂载rootfs需要emmc驱动,emmc驱动还没有初始化好,内核就尝试挂载rootfs了,
现修改为通过一个事件同步,emmc驱动完成后写事件,内核读到这个事件再挂载rootfs

close: #I43WLG
Signed-off-by: wanghao-free <wanghao453@huawei.com>
2021-09-08 01:43:22 -07:00
openharmony_ci 3ad07bc40f !560 解决调用system_console_deinit接口进行卸载console调试口,系统挂死
Merge pull request !560 from xukunrui/OpenHarmony_1.0.1_release
2021-08-20 03:53:35 +00:00
xukunrui 1e8d5baf8c 解决调用system_console_deinit接口进行卸载console调试口,系统挂死
Signed-off-by: xukunrui <xukunrui1@huawei.com>
2021-08-18 14:13:56 +08:00
openharmony_ci b744cfa164 !385 SIOCGIFCONF iotcl,用户态到内核态申请内存大小错误
Merge pull request !385 from 刘建东/cherry-pick-1625021431
2021-07-05 00:49:11 +00:00
YOUR_NAME 51a24eaeb2 fixed 4496e71 from https://gitee.com/life-liu/kernel_liteos_a/pulls/373
fixed bfd27e7 from https://gitee.com/life-liu/kernel_liteos_a/pulls/355
fix: SIOCGIFCONF ioctl malloc size error in kernel

use struct ifconf and ifc_buf size malloc memory

close: #I3XEZ3

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-06-30 11:31:08 +08:00
openharmony_ci 07fb6c150e !330 修改lwip_enhanced编译脚本,更新lwip_enhanced lwip版本到2.1.2
Merge pull request !330 from 刘建东/pr_329
2021-06-17 17:01:38 +08:00
openharmony_ci 7ceaf68832 !319 fix: avoid compile warning ignored
Merge pull request !319 from MGY917/citu_clean_release
2021-06-17 15:53:35 +08:00
YOUR_NAME 309e7569f8 chore: update lwip_enhanced lwip version to 2.1.2
update lwip version to 2.1.2 for lwip_enhanced

close: #I3VXAP

Signed-off-by: liujiandong <liujiandong1@huawei.com>
2021-06-17 15:21:24 +08:00
openharmony_ci e42cb26b14 !324 fix: v1.1.0的reset_vector_up/mp.S bug修复同步自master
Merge pull request !324 from MGY917/start_up_bug_fix
2021-06-17 13:54:56 +08:00
Guangyao Ma 8ab4c9a6bc fix: v1.1.0的reset_vector_up/mp.S bug修复同步自master
Close #I3VQGN

Change-Id: I3772fde91067433c18b34fe2157abf05fa75fd73
Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
2021-06-16 17:23:40 +08:00
Guangyao Ma a40dc411b2 fix: avoid compile warning ignored
Close #I3VOAO

Change-Id: I42103e0e7061e50f8d63df98ea9f5cecd49fe6f4
Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
2021-06-15 20:06:09 +08:00
openharmony_ci ebe33aa2f6 !299 删除PRINTK维测log
Merge pull request !299 from 刘建东/OpenHarmony_1.0.1_release
2021-06-09 13:51:24 +08:00
YOUR_NAME ece0e8ae06 IssueNo:#I3UKNE
Description:delete PRINTK log
Sig:phone
Feature or Bugfix:Bugfix
Binary Source:No

Signed-off-by: YOUR_NAME <liujiandong1@huawei.com>
2021-06-07 12:01:52 +08:00
openharmony_ci c059be5ec8 !237 lwip crash问题增加维测log
Merge pull request !237 from 刘建东/OpenHarmony_1.0.1_release
2021-05-13 09:33:15 +08:00
YOUR_NAME 723b3ff8e2 IssueNo:#I3R13T
Description:add log for lwip crash
Sig:phone
Feature or Bugfix:Bugfix
Binary Source:No
2021-05-12 17:15:44 +08:00
openharmony_ci 7cf342c29f !195 clang编译的系统镜像内核栈回溯功能失效
Merge pull request !195 from zhangfanfan2/OpenHarmony_1.0.1_release
2021-04-28 14:44:13 +08:00
YOUR_NAME 3b9ccc839e fix:solve the problem of stack backtrace failure for llvm.
Change-Id: I0b0426e0e529cb6517d6a2712c6862ebbcea2239
2021-04-28 10:33:10 +08:00
openharmony_ci 4f1e1619a5 !161 【轻量级 PR】:调度中存在有符号数与无符号数比较
Merge pull request !161 from zhushengle/N/A
2021-04-20 14:12:58 +08:00
openharmony_ci 6523c496c8 !159 同步master 分支已修复问题: setitimer 中定时给进程发信号时未持有调度锁,导致踩内存等问题
Merge pull request !159 from zhushengle/OpenHarmony_1.0.1_release
2021-04-20 14:12:53 +08:00
zhushengle 7648648887 调度中存在有符号数与无符号数比较 2021-04-20 10:06:48 +08:00
zhushengle 1c0bbb66de fix:setitimer are downregulated for multicore scenarios, and are static, resulting in inconsistent behavior.
Close #I3EBOI

Change-Id: I71a86b8f2b7451e886a08dfc7f274287107df916
2021-04-20 09:54:00 +08:00
zhushengle d44f3904cf fix:the setitimer signals the process to be locked at a fixed time. There is a static problem.
Close #I3H7TO

Change-Id: Iccfb458ed43f761fde1f943e0005f4ac1bf425bc
2021-04-20 09:25:36 +08:00
openharmony_ci 5cbb83dc6e !126 Add issue and PR template for release
Merge pull request !126 from 马明帅/add_issus_pr_template_for_release
2021-04-08 08:40:31 +08:00
mamingshuai 13fa3d4403 add issue and pr template 2021-04-07 14:49:43 +08:00
openharmony_ci e9522d44bf !121 release【bug】sigaction中sigsuspend的后执行信号顺序与预期不符,信号注册时未屏蔽用户传入信号屏蔽字段
Merge pull request !121 from give-me-five/OpenHarmony_1.0.1_release
2021-04-04 17:40:08 +08:00
x_xiny f30790c5c8 signal
Change-Id: Ia42e914b7a19b7d519010e371f808baa1c6588c0
2021-04-04 16:23:24 +08:00
openharmony_ci a0bb801f67 !114 Fix OHOS shell cannot ls a file for branch release
Merge pull request !114 from ysy4tc3/fork_release
2021-04-01 14:47:03 +08:00
Far 170aa8ba6f Description: fix OHOS shell cannot ls a file
Change-Id: Ie13485cc2406882985405db0599666690c25dc1f
2021-04-01 09:44:37 +08:00
openharmony_ci 83b0e8f867 !89 内核构建增加从vendor下面copy配置文件的方式
Merge pull request !89 from zhangfanfan2/OpenHarmony_1.0.1_release
2021-03-24 09:46:05 +08:00
YOUR_NAME 6b5d6be42d [Desc]Modify the vendor configuration file path because the product_path
is changed to an absolute path.

Change-Id: If034609155528a76cca72f3f0d85096f09478cd2
2021-03-23 22:42:12 +08:00
openharmony_ci 8b27064848 !84 update readme
Merge pull request !84 from Harylee/release
2021-03-23 10:08:37 +08:00
openharmony_ci 1ad74ab8e4 !79 update ReadME.md
Merge pull request !79 from Harylee/noEmployeeNum_ChangeID_13291521_lihao
2021-03-22 19:12:48 +08:00
2880 changed files with 23585 additions and 283428 deletions

View File

@ -10,18 +10,3 @@
### 测试用例(新增、改动、可能影响的功能) ### 测试用例(新增、改动、可能影响的功能)
### 是否涉及对外变更典型的如对外API规格变更、新增对外接口等等
必须选择一项在MarkDown模式下用[x]替换[ ]即可勾选对应选项):
- [ ] 是,涉及对外变更: 需要在commit message中按【[模板要求](https://gitee.com/openharmony/kernel_liteos_a/wikis/Commit%20message%20%E8%A7%84%E8%8C%83)】描述变更点
- [ ] 否,不涉及对外变更
### 是否需要同步至release3.0LTS ... )分支?
必须选择一项在MarkDown模式下用[x]替换[ ]即可勾选对应选项):
- [ ] 是,需要同步的分支:
- [ ] 否
理由:

35
.gitignore vendored
View File

@ -1,24 +1,23 @@
# General ignored file types /out
/test
/include
.config*
cscope*
tags
.vscode
*.o *.o
.idea
*.img
*.swp
*.rej
*.orig
*.a *.a
*.so *.so
*.swp .config.cmd
# IDE settings
.vscode
.idea
.settings .settings
.cproject .cproject
.project .project
platform/include/menuconfig.h
# VIM files platform/board.ld
cscope* apps/init/init
tags apps/shell/shell
# Menuconfig temp files
/config.h
/.config
/.config.old
# Build temp files
/out

428
BUILD.gn Normal file → Executable file
View File

@ -28,415 +28,55 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//build/lite/config/component/lite_component.gni") import("//build/lite/config/component/lite_component.gni")
import("//build/lite/config/subsystem/lite_subsystem.gni")
LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
declare_args() {
tee_enable = false
liteos_name = "OHOS_Image"
liteos_container_enable = false
liteos_skip_make = false
liteos_is_mini = false
}
tee = ""
if (tee_enable) {
tee = "_tee"
}
declare_args() {
liteos_config_file = "${ohos_build_type}${tee}.config"
}
liteos_config_file =
rebase_path(liteos_config_file, "", "$product_path/kernel_configs")
print("liteos_config_file:", liteos_config_file)
exec_script("//build/lite/run_shell_cmd.py",
[ "env" + " CONFIG_=LOSCFG_" + " KCONFIG_CONFIG_HEADER='y=true'" +
" KCONFIG_CONFIG=$liteos_config_file" +
" DEVICE_PATH=$device_path" + " srctree=" + rebase_path(".") +
" genconfig" + " --header-path $LITEOS_MENUCONFIG_H" +
" --file-list kconfig_files.txt" +
" --env-list kconfig_env.txt" + " --config-out config.gni" ],
"",
[ liteos_config_file ])
import("liteos.gni")
assert(ARCH != "", "ARCH not set!")
assert(ARCH == arch, "ARCH not match! details: $ARCH != $arch")
assert(tee_enable == defined(LOSCFG_TEE_ENABLE), "TEE switch not match!")
assert(ohos_build_compiler == "clang" == defined(LOSCFG_COMPILER_CLANG_LLVM),
"compiler not match!")
generate_notice_file("kernel_notice_file") { generate_notice_file("kernel_notice_file") {
module_name = "kernel" module_name = "kernel"
module_source_dir_list = [ module_source_dir_list = [
"$LITEOSTHIRDPARTY/FreeBSD", "//third_party/FreeBSD",
"$LITEOSTHIRDPARTY/musl", "//third_party/musl",
"$LITEOSTHIRDPARTY/zlib", "//third_party/zlib",
"$LITEOSTHIRDPARTY/FatFs", "//third_party/FatFs",
"$LITEOSTHIRDPARTY/lwip", "//third_party/Linux_Kernel",
"$LITEOSTHIRDPARTY/NuttX", "//third_party/lwip",
"$LITEOSTHIRDPARTY/mtd-utils", "//third_party/NuttX",
"//third_party/mtd-utils",
] ]
} }
liteos_arch_cflags = [] declare_args() {
if (defined(LOSCFG_ARCH_ARM)) { enable_ohos_kernel_liteos_a_ext_build = true
mcpu = LOSCFG_ARCH_CPU LOSCFG_TEST_APPS = false
if (defined(LOSCFG_ARCH_ARM_AARCH64) && defined(LOSCFG_ARCH_FPU_DISABLE)) { tee_enable = ""
mcpu += "+nofp"
} }
liteos_arch_cflags += [ "-mcpu=$mcpu" ]
if (defined(LOSCFG_ARCH_ARM_AARCH32)) { lite_subsystem("kernel") {
liteos_arch_cflags += [ subsystem_components = []
"-mfloat-abi=softfp",
"-mfpu=$LOSCFG_ARCH_FPU", if (enable_ohos_kernel_liteos_a_ext_build == false) {
subsystem_components += [
"//kernel/liteos_a/kernel",
"//kernel/liteos_a/net",
"//kernel/liteos_a/lib",
"//kernel/liteos_a/compat",
"//kernel/liteos_a/fs",
"//kernel/liteos_a/arch:platform_cpu",
] ]
if (LOSCFG_SHELL) {
subsystem_components += [ "//kernel/liteos_a/shell" ]
} }
}
cc = "$ohos_current_cc_command " + string_join(" ", liteos_arch_cflags)
if (ohos_build_compiler == "clang") {
cc += " --target=$target_triple"
}
config("arch_config") {
cflags = liteos_arch_cflags
asmflags = cflags
ldflags = cflags
if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
if (!defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-mthumb-interwork" ]
}
}
if (defined(LOSCFG_THUMB)) {
cflags += [ "-mthumb" ]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-mimplicit-it=thumb" ]
} else { } else {
cflags += [ "-Wa,-mimplicit-it=thumb" ] deps = [ ":make" ]
} }
} }
}
config("stdinc_config") {
std_include = exec_script("//build/lite/run_shell_cmd.py",
[ "$cc -print-file-name=include" ],
"trim string")
cflags = [
"-isystem",
std_include,
]
if (!defined(LOSCFG_LIBC_NEWLIB)) {
cflags += [ "-nostdinc" ]
}
asmflags = cflags
}
config("ssp_config") {
cflags = []
if (defined(LOSCFG_CC_STACKPROTECTOR_ALL)) {
cflags += [ "-fstack-protector-all" ]
} else if (defined(LOSCFG_CC_STACKPROTECTOR_STRONG)) {
cflags += [ "-fstack-protector-strong" ]
} else if (defined(LOSCFG_CC_STACKPROTECTOR)) {
cflags += [
"-fstack-protector",
"--param",
"ssp-buffer-size=4",
]
} else {
cflags += [ "-fno-stack-protector" ]
}
asmflags = cflags
}
config("optimize_config") {
cflags = []
if (defined(LOSCFG_COMPILE_DEBUG)) {
cflags += [
"-g",
"-gdwarf-2",
]
optimization_cflag = "-O0"
}
if (defined(LOSCFG_COMPILE_OPTIMIZE)) {
optimization_cflag = "-O2"
}
if (defined(LOSCFG_COMPILE_OPTIMIZE_SIZE)) {
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
optimization_cflag = "-Oz"
} else {
optimization_cflag = "-Os"
}
}
if (defined(LOSCFG_COMPILE_LTO)) {
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-flto=thin" ]
} else {
#cflags += [ "-flto" ]
}
}
cflags += [ optimization_cflag ]
asmflags = cflags
}
config("kconfig_config") {
cflags = [
"-imacros",
"$LITEOS_MENUCONFIG_H",
]
asmflags = cflags
}
config("warn_config") {
cflags = [
"-Wall",
"-Werror",
"-Wpointer-arith",
"-Wstrict-prototypes",
"-Winvalid-pch",
]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-Wno-address-of-packed-member" ]
cflags += [
"-Wno-unused-but-set-variable",
"-Wno-strict-prototypes",
]
}
asmflags = cflags
}
config("dialect_config") {
cflags_c = [ "-std=c99" ]
cflags_cc = [ "-std=c++11" ]
}
config("misc_config") {
defines = [ "__LITEOS__" ]
defines += [ "__LITEOS_A__" ]
if (!defined(LOSCFG_DEBUG_VERSION)) {
defines += [ "NDEBUG" ]
}
cflags = [
"-fno-pic",
"-fno-builtin",
"-fms-extensions",
"-fno-strict-aliasing",
"-fno-common",
"-fsigned-char",
"-ffunction-sections",
"-fdata-sections",
"-fno-exceptions",
"-fno-omit-frame-pointer",
"-fno-short-enums",
"-mno-unaligned-access",
]
if (!defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-fno-aggressive-loop-optimizations" ]
}
asmflags = cflags
}
config("container_config") {
if (liteos_container_enable) {
cflags = [
"-DLOSCFG_KERNEL_CONTAINER",
"-DLOSCFG_PID_CONTAINER",
"-DLOSCFG_UTS_CONTAINER",
"-DLOSCFG_MNT_CONTAINER",
"-DLOSCFG_CHROOT",
"-DLOSCFG_IPC_CONTAINER",
"-DLOSCFG_TIME_CONTAINER",
"-DLOSCFG_USER_CONTAINER",
"-DLOSCFG_NET_CONTAINER",
"-DLOSCFG_PROC_PROCESS_DIR",
"-DLOSCFG_KERNEL_PLIMITS",
"-DLOSCFG_KERNEL_MEM_PLIMIT",
"-DLOSCFG_KERNEL_IPC_PLIMIT",
"-DLOSCFG_KERNEL_DEV_PLIMIT",
"-DLOSCFG_KERNEL_SCHED_PLIMIT",
]
}
}
config("los_config") {
configs = [
":arch_config",
":kconfig_config",
":stdinc_config",
":dialect_config",
":optimize_config",
":ssp_config",
":warn_config",
":misc_config",
":container_config",
]
}
cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi"
HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
config("public") {
configs = [
"arch:public",
"kernel:public",
"compat:public",
"bsd:public",
"fs:public",
"drivers:public",
"security:public",
"net:public",
"shell:public",
"lib:public",
]
configs += [
"$HDFTOPDIR:public",
"$DRIVERS_LITEOS_DIR:public",
]
if (HAVE_DEVICE_SDK) {
configs += [ "$device_path:public" ]
}
}
group("modules") {
deps = [
"arch",
"bsd",
"compat",
"drivers",
"fs",
"kernel",
"lib",
"net",
"security",
"shell",
"syscall",
"testsuites/kernel:kernel_test",
]
deps += [
"$DRIVERS_LITEOS_DIR",
"$HDFTOPDIR",
]
if (HAVE_DEVICE_SDK) {
deps += [ device_path ]
}
}
group("apps") {
deps = [ "apps" ]
}
group("tests") {
deps = [ "testsuites" ]
}
group("kernel") {
deps = [ ":build_kernel_image" ]
}
group("liteos_a") {
deps = [ ":kernel" ]
if (!liteos_is_mini) {
deps += [
":apps",
":tests",
"$THIRDPARTY_MUSL_DIR/scripts/build_lite:strip",
]
if (liteos_skip_make == false) {
deps += [ ":make" ]
}
}
}
executable("liteos") {
configs = [] # clear default configs
configs += [ ":arch_config" ]
configs += [ ":public" ]
ldflags = [
"-static",
"-nostdlib",
"-Wl,--gc-sections",
"-Wl,-Map=$liteos_name.map",
"-Wl,--no-eh-frame-hdr",
]
if (defined(LOSCFG_LIBC_NEWLIB)) {
ldflags += [
"-Wl,--wrap=_free_r",
"-Wl,--wrap,_malloc_usable_size_r",
"-Wl,--wrap,_malloc_r",
"-Wl,--wrap,_memalign_r",
"-Wl,--wrap,_realloc_r",
"-Wl,--wrap,_fseeko_r",
]
ldflags -= [ "-nostdlib" ]
}
libgcc = exec_script("//build/lite/run_shell_cmd.py",
[ "$cc -print-libgcc-file-name" ],
"trim string")
libs = [ libgcc ]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
ldflags +=
[ "-Wl,-T" + rebase_path("tools/build/liteos_llvm.ld", root_build_dir) ]
inputs = [ "tools/build/liteos_llvm.ld" ]
} else {
ldflags +=
[ "-Wl,-T" + rebase_path("tools/build/liteos.ld", root_build_dir) ]
ldflags += [ "-nostartfiles" ]
inputs = [ "tools/build/liteos.ld" ]
}
inputs += [ "$root_out_dir/board.ld" ]
output_dir = target_out_dir
deps = [
":modules",
"platform:copy_board.ld",
]
}
copy("copy_liteos") {
deps = [ ":liteos" ]
sources = [ "$target_out_dir/unstripped/bin/liteos" ]
outputs = [ "$root_out_dir/$liteos_name" ]
}
build_ext_component("build_kernel_image") {
deps = [ ":copy_liteos" ]
exec_path = rebase_path(root_out_dir)
objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
command = "$objcopy -O binary $liteos_name $liteos_name.bin"
command +=
" && sh -c '$objdump -t $liteos_name | sort >$liteos_name.sym.sorted'"
command += " && sh -c '$objdump -d $liteos_name >$liteos_name.asm'"
}
build_ext_component("make") { build_ext_component("make") {
exec_path = rebase_path(".", root_build_dir) exec_path = rebase_path(".", root_build_dir)
outdir = rebase_path("$target_out_dir/${target_name}_out") tee_enable = "false"
sysroot_path = rebase_path(ohos_current_sysroot) if (board_name == "hi3516dv300" && enable_tee_ree) {
arch_cflags = string_join(" ", target_arch_cflags) tee_enable = "tee"
command = "./build.sh \"$board_name\" \"$ohos_build_compiler\" \"$root_build_dir\" \"$ohos_build_type\" \"$tee_enable\""
command += " \"$device_company\" \"$product_path\" \"$outdir\" \"$ohos_version\" \"$sysroot_path\" \"$arch_cflags\""
command += " \"$device_path\" \"$compile_prefix\" \"$liteos_config_file\""
if (liteos_skip_make) {
print("build_ext_component \"$target_name\" skipped:", command)
command = "true"
} }
prebuilts = "sh build.sh ${board_name} ${ohos_build_compiler} ${root_build_dir} ${ohos_build_type} ${tee_enable} \"${device_company}\" \"${product_path}\""
outdir = rebase_path(get_path_info(".", "out_dir"))
command = "make clean OUTDIR=$outdir && make rootfs VERSION=\"${ohos_version}\" -j 16 OUTDIR=$outdir"
} }

View File

@ -1,338 +0,0 @@
# (2022-03-30)
### Bug Fixes
* **arm-virt:** HW_RANDOM_ENABLE配置支持arm virt平台 ([68f9f49](https://gitee.com/openharmony/kernel_liteos_a/commits/68f9f49c2a62d3271db14ccb896c9f9fc78a60e4))
* A核代码静态告警定期清理 ([9ba725c](https://gitee.com/openharmony/kernel_liteos_a/commits/9ba725c3d486dd28fe9b2489b0f95a65354d7d86)), closes [#I4I0O8](https://gitee.com/openharmony/kernel_liteos_a/issues/I4I0O8)
* change default permission of procfs to 0550 ([a776c04](https://gitee.com/openharmony/kernel_liteos_a/commits/a776c04a3da414f73ef7136a543c029cc6dd75be)), closes [#I4NY49](https://gitee.com/openharmony/kernel_liteos_a/issues/I4NY49)
* change the execFile field in TCB to execVnode ([e4a0662](https://gitee.com/openharmony/kernel_liteos_a/commits/e4a06623ceb49b5bead60d45c0534db88b9c666f)), closes [#I4CLL9](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CLL9)
* close file when process interpretor failed ([a375bf5](https://gitee.com/openharmony/kernel_liteos_a/commits/a375bf5668a5e86e082d0e124b538e423023a259)), closes [#I4ATQX](https://gitee.com/openharmony/kernel_liteos_a/issues/I4ATQX)
* codex 清理 ([9ab3e35](https://gitee.com/openharmony/kernel_liteos_a/commits/9ab3e351d38cdae2ec083048a50a253bc2a3b604)), closes [#I4BL3S](https://gitee.com/openharmony/kernel_liteos_a/issues/I4BL3S)
* dyload open close failed ([5e87d8c](https://gitee.com/openharmony/kernel_liteos_a/commits/5e87d8c183471166294e2caa041ab4da8570c6a1)), closes [#I452Z7](https://gitee.com/openharmony/kernel_liteos_a/issues/I452Z7)
* fix ppoll ([a55f68f](https://gitee.com/openharmony/kernel_liteos_a/commits/a55f68f957e9f8ad74bd9e0c1b3d27775e0f8c75))
* fix some function declarations ([63fd8bc](https://gitee.com/openharmony/kernel_liteos_a/commits/63fd8bc39b21fffb6990f74e879eefecafad6c88))
* implicit declaration of function 'syscall' in apps/shell ([bd0c083](https://gitee.com/openharmony/kernel_liteos_a/commits/bd0c0835fc58ed5f941dbbc9adfac74253eeb874))
* LOS_Panic和魔法键功能中的使用PRINTK打印依赖任务调度特殊情况下存在打印不出来的问题 ([53addea](https://gitee.com/openharmony/kernel_liteos_a/commits/53addea304de09e0df457b690403ac652bbcea72)), closes [#I4NOC7](https://gitee.com/openharmony/kernel_liteos_a/issues/I4NOC7)
* los_stat_pri.h中缺少依赖的头文件 ([2cd03c5](https://gitee.com/openharmony/kernel_liteos_a/commits/2cd03c55b7a614c648adc965ebfe494d491fe20f)), closes [#I4KEZ1](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KEZ1)
* los_trace.h接口注释错误修正 ([6d24961](https://gitee.com/openharmony/kernel_liteos_a/commits/6d249618aecc216388f9b1a2b48fe0ac6dd19ff2)), closes [#I4CYPZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CYPZ)
* MMU竞态问题修复 ([748e0d8](https://gitee.com/openharmony/kernel_liteos_a/commits/748e0d8ffb6ee9c8757ed056f575e3abc6c10702)), closes [#I2WARC](https://gitee.com/openharmony/kernel_liteos_a/issues/I2WARC)
* **mtd:** 去除mtd对hisilicon驱动的依赖 ([f7d010d](https://gitee.com/openharmony/kernel_liteos_a/commits/f7d010dfa4cb825096267528e131a9e2735d7505)), closes [#I49FKL](https://gitee.com/openharmony/kernel_liteos_a/issues/I49FKL)
* OsFutexWaitParamCheck函数中absTime为0时直接返回不需要打印 ([3f71be7](https://gitee.com/openharmony/kernel_liteos_a/commits/3f71be75355f11037d9de80cc4d7da0f01905003)), closes [#I4D67E](https://gitee.com/openharmony/kernel_liteos_a/issues/I4D67E)
* OsLockDepCheckIn异常处理中存在g_lockdepAvailable锁嵌套调用, ([bf030b6](https://gitee.com/openharmony/kernel_liteos_a/commits/bf030b6bb5843151a5b8b8736246a1376a5fb9d0)), closes [#I457ZZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I457ZZ)
* pr模板补充说明 ([e3cd485](https://gitee.com/openharmony/kernel_liteos_a/commits/e3cd485db528490a16a8932d734faab263b44bc9))
* same file mode for procfs files ([c79bcd0](https://gitee.com/openharmony/kernel_liteos_a/commits/c79bcd028e1be34b45cba000077230fa2ef95e68)), closes [#I4ACTC](https://gitee.com/openharmony/kernel_liteos_a/issues/I4ACTC)
* shell支持exit退出完善帮助信息特殊处理不可见字符 ([cc6e112](https://gitee.com/openharmony/kernel_liteos_a/commits/cc6e11281e63b6bdc9be8e5d3c39f1258eb2ceaa))
* smp初始化中副核冗余的启动框架调用 ([5ce70a5](https://gitee.com/openharmony/kernel_liteos_a/commits/5ce70a50c3733b6ec8cc4b444837e366ec837f69)), closes [#I4F8A5](https://gitee.com/openharmony/kernel_liteos_a/issues/I4F8A5)
* solve SIGCHLD ignored in sigsuspend() ([5a80d4e](https://gitee.com/openharmony/kernel_liteos_a/commits/5a80d4e1a34c94204a0bb01443bf25a4fdb12750)), closes [#I47CKK](https://gitee.com/openharmony/kernel_liteos_a/issues/I47CKK)
* syscall review bugfix ([214f44e](https://gitee.com/openharmony/kernel_liteos_a/commits/214f44e935277c29d347c50b553a31ea7df36448)), closes [#149](https://gitee.com/openharmony/kernel_liteos_a/issues/149)
* **test:** misc09用例因依赖hosts文件而失败 ([f2f5c5f](https://gitee.com/openharmony/kernel_liteos_a/commits/f2f5c5fdc3202610de173e7046adab4df5e59142)), closes [#I48IZ0](https://gitee.com/openharmony/kernel_liteos_a/issues/I48IZ0)
* **test:** 修复sys部分用例因依赖passwd、group文件而失败 ([614cdcc](https://gitee.com/openharmony/kernel_liteos_a/commits/614cdccf91bd2d220c4c76418b53400ce714c6cb)), closes [#I48IUC](https://gitee.com/openharmony/kernel_liteos_a/issues/I48IUC)
* 中断中调用PRINTK概率卡死导致系统不能正常响应中断 ([9726ba1](https://gitee.com/openharmony/kernel_liteos_a/commits/9726ba11a79f3d2d1e616e12ef0bb44e4fc5cd20)), closes [#I4C9GC](https://gitee.com/openharmony/kernel_liteos_a/issues/I4C9GC)
* 临终遗言重定向内容缺失task相关信息对应的shell命令中申请的内存需要cacheline对齐 ([48ca854](https://gitee.com/openharmony/kernel_liteos_a/commits/48ca854bf07f8dcda9657f950601043a485a1b33)), closes [#I482S5](https://gitee.com/openharmony/kernel_liteos_a/issues/I482S5)
* 优化liteipc任务状态删除功能重复字段 ([5004ef4](https://gitee.com/openharmony/kernel_liteos_a/commits/5004ef4d87b54fb6d7f748ca8212ae155bcefac5)), closes [#I4FVHK](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FVHK)
* 优化trace buffer初始化删除swtmr 桩中的无效参数 ([b551270](https://gitee.com/openharmony/kernel_liteos_a/commits/b551270ef50cb206360e2eee3dd20ace5cecccb7)), closes [#I4DQ1X](https://gitee.com/openharmony/kernel_liteos_a/issues/I4DQ1X)
* 修复 virpart.c 不适配的格式化打印问题 ([de29140](https://gitee.com/openharmony/kernel_liteos_a/commits/de29140edf2567f4847876cb1ed5e0b6857420f3)), closes [#I4PEVP](https://gitee.com/openharmony/kernel_liteos_a/issues/I4PEVP)
* 修复A核文档失效的问题 ([456d255](https://gitee.com/openharmony/kernel_liteos_a/commits/456d255a81c2031be8ebecc2bf897af80c3d3c7a)), closes [#I4U7TF](https://gitee.com/openharmony/kernel_liteos_a/issues/I4U7TF)
* 修复A核测试用例失败的问题 ([59329ce](https://gitee.com/openharmony/kernel_liteos_a/commits/59329ce7c6b6a00084df427748e6283287a773c0)), closes [#I4SQDR](https://gitee.com/openharmony/kernel_liteos_a/issues/I4SQDR)
* 修复A核测试用例失败的问题 ([be68dc8](https://gitee.com/openharmony/kernel_liteos_a/commits/be68dc8bcaf8d965039ae1d792775f00a08adfac)), closes [#I4SQDP](https://gitee.com/openharmony/kernel_liteos_a/issues/I4SQDP)
* 修复dispatch单词拼写错误。 ([9b07aec](https://gitee.com/openharmony/kernel_liteos_a/commits/9b07aece2dfa3494cf35e8b388410341508d6224)), closes [#I4BLE8](https://gitee.com/openharmony/kernel_liteos_a/issues/I4BLE8)
* 修复futime提示错误22的BUG ([f2861dd](https://gitee.com/openharmony/kernel_liteos_a/commits/f2861ddfb424af7b99c278273601ce0fab1f37e6))
* 修复jffs2适配层错误释放锁的BUG ([011a55f](https://gitee.com/openharmony/kernel_liteos_a/commits/011a55ff21d95f969abac60bcff96f4c4d7a326d)), closes [#I4FH9M](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FH9M)
* 修复los_vm_scan.c中内部函数OsInactiveListIsLow冗余代码 ([bc32a1e](https://gitee.com/openharmony/kernel_liteos_a/commits/bc32a1ec0fa5d19c6d2672bcf4a01de5e1be3afb)), closes [#I4HKFF](https://gitee.com/openharmony/kernel_liteos_a/issues/I4HKFF)
* 修复LOSCFG_FS_FAT_CACHE宏关闭后编译失败的BUG ([63e71fe](https://gitee.com/openharmony/kernel_liteos_a/commits/63e71feca05a8d46a49822c713258738740f0712)), closes [#I3T3N0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3T3N0)
* 修复OsVmPhysFreeListAdd和OsVmPhysFreeListAddUnsafe函数内容重复 ([6827bd2](https://gitee.com/openharmony/kernel_liteos_a/commits/6827bd2a22b78aa05e20d6460412fc7b2d738929)), closes [#I4FL95](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FL95)
* 修复PR520缺陷 ([4033891](https://gitee.com/openharmony/kernel_liteos_a/commits/40338918d9132399ee0494d331930a05b7a13c67)), closes [#I4DEG5](https://gitee.com/openharmony/kernel_liteos_a/issues/I4DEG5)
* 修复shcmd.h需要用宏包起来的问题 ([6c4e4b1](https://gitee.com/openharmony/kernel_liteos_a/commits/6c4e4b16abe9c68fea43d40b2d39b4f0ed4bfc9c)), closes [#I4N50W](https://gitee.com/openharmony/kernel_liteos_a/issues/I4N50W)
* 修复xts权限用例压测异常问题 ([b0d31cb](https://gitee.com/openharmony/kernel_liteos_a/commits/b0d31cb43f5a8d1c3da574b2b957e3b0e98b3067)), closes [#I3ZJ1D](https://gitee.com/openharmony/kernel_liteos_a/issues/I3ZJ1D)
* 修复硬随机不可用时,地址随机化不可用问题 ([665c152](https://gitee.com/openharmony/kernel_liteos_a/commits/665c152c27bb86395ddd0395279255f6cdaf7255)), closes [#I4D4TK](https://gitee.com/openharmony/kernel_liteos_a/issues/I4D4TK)
* 修复进程用例导致门禁概率失败 ([1ed28b4](https://gitee.com/openharmony/kernel_liteos_a/commits/1ed28b4c80cfd222be08b0c2e71e6287e52bb276)), closes [#I4FO0N](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FO0N)
* 修复进程线程不稳定用例 ([f6ac03d](https://gitee.com/openharmony/kernel_liteos_a/commits/f6ac03d3e3c56236adc5734d4c059f1fbcc9e0c1)), closes [#I4F1XL](https://gitee.com/openharmony/kernel_liteos_a/issues/I4F1XL)
* 修复重复执行内存用例导致系统卡死问题 ([6c2b163](https://gitee.com/openharmony/kernel_liteos_a/commits/6c2b163c7d7c696ef89b17a0275f3cddb3d7cefb)), closes [#I4F7PO](https://gitee.com/openharmony/kernel_liteos_a/issues/I4F7PO)
* 修改MMU模块的注释错误 ([1a8e22d](https://gitee.com/openharmony/kernel_liteos_a/commits/1a8e22dcf15944153e013d004fd7bbf24557a8c7)), closes [#I4KMMJ](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KMMJ)
* 共享内存问题修复 ([9fdb80f](https://gitee.com/openharmony/kernel_liteos_a/commits/9fdb80f85f92d0167a0456455a94fc6f679797ce)), closes [#I47X2Z](https://gitee.com/openharmony/kernel_liteos_a/issues/I47X2Z)
* 内核ERR打印无进程和线程信息不方便问题定位。 ([cb423f8](https://gitee.com/openharmony/kernel_liteos_a/commits/cb423f845462b8cc474c3cba261dadf3943a08ef)), closes [#I4DAKM](https://gitee.com/openharmony/kernel_liteos_a/issues/I4DAKM)
* 内核ERR级别及以上的打印输出当前进程和线程名 ([540b201](https://gitee.com/openharmony/kernel_liteos_a/commits/540b2017c5460e300365d2039a08abd5945cec6b))
* 内源检视测试用例问题修复 ([a6ac759](https://gitee.com/openharmony/kernel_liteos_a/commits/a6ac7597f85043ba6de3a1b395ca676d85c65ea7))
* 删除冗余的头文件 ([8e614bb](https://gitee.com/openharmony/kernel_liteos_a/commits/8e614bb1616b75bc89eee7ad7da49b7a9c285b47)), closes [#I4KN63](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KN63)
* 增加pselect SYSCALL函数及测试用例 ([f601c16](https://gitee.com/openharmony/kernel_liteos_a/commits/f601c16b9e67d531dda51fc18389a53db4360b7b)), closes [#I45SXU](https://gitee.com/openharmony/kernel_liteos_a/issues/I45SXU)
* 增加内核epoll系统调用 ([2251b8a](https://gitee.com/openharmony/kernel_liteos_a/commits/2251b8a2d1f649422dd67f8551b085a7e0c63ec7)), closes [#I4FXPT](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FXPT)
* 实现了musl库net模块中的一些函数接口和相应的测试用例 ([3d00a7d](https://gitee.com/openharmony/kernel_liteos_a/commits/3d00a7d23a96f29c138cfc1672825b90b9e0c05e)), closes [#I4JQI1](https://gitee.com/openharmony/third_party_musl/issues/I4JQI1)
* 添加进程线程冒烟用例 ([2be5968](https://gitee.com/openharmony/kernel_liteos_a/commits/2be59680f2fb0801b43522cd38cc387c8ff38766)), closes [#I4EOGA](https://gitee.com/openharmony/kernel_liteos_a/issues/I4EOGA)
* 用户态进程主线程退出时,其他子线程刚好进入异常处理流程会导致系统卡死 ([d955790](https://gitee.com/openharmony/kernel_liteos_a/commits/d955790a44a679421798ec1ac2900b4d75dd75a4)), closes [#I4KGBT](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KGBT)
* 编码规范修改 ([d161a0b](https://gitee.com/openharmony/kernel_liteos_a/commits/d161a0b03de046c05fff45a2b625631b4e45a347))
* 编码规范问题修复 ([f60bc94](https://gitee.com/openharmony/kernel_liteos_a/commits/f60bc94cf231bc615ff6603ca0393b8fe33a8c47))
* 编译框架在做编译入口的统一 ([bdb9864](https://gitee.com/openharmony/kernel_liteos_a/commits/bdb9864436a6f128a4c3891bbd63e3c60352689f)), closes [#I4KRQN](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KRQN)
* 解决dmesg -s参数double lock问题 ([e151256](https://gitee.com/openharmony/kernel_liteos_a/commits/e1512566e322eb1fbc8f5d5997f9bfcd022feac7)), closes [#I4HIJK](https://gitee.com/openharmony/kernel_liteos_a/issues/I4HIJK)
* 进程退出前自己回收vmspace中的所有region ([298ccea](https://gitee.com/openharmony/kernel_liteos_a/commits/298ccea3fedaccc651b38973f0455fa1ce12e516)), closes [#I4CKQC](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CKQC)
* 通过g_uart_fputc_en关闭打印后shell进程不能正常启动 ([d21b05c](https://gitee.com/openharmony/kernel_liteos_a/commits/d21b05c0f69877130366ad37b852a0f30c11809d)), closes [#I4CTY2](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CTY2)
* 针对pr是否同步至release分支增加原因说明规则 ([b37a7b7](https://gitee.com/openharmony/kernel_liteos_a/commits/b37a7b79292d93dae6c4914952b5f3bb509e8721))
* 非当前进程销毁时销毁liteipc时错误的销毁了当前进程的liteipc资源 ([0f0e85b](https://gitee.com/openharmony/kernel_liteos_a/commits/0f0e85b7a6bf76d540925fbf661c483c8dba1cba)), closes [#I4FSA7](https://gitee.com/openharmony/kernel_liteos_a/issues/I4FSA7)
### Code Refactoring
* los_cir_buf.c中接口整合 ([0d325c5](https://gitee.com/openharmony/kernel_liteos_a/commits/0d325c56a1053043db05d53a6c8083f4d35f116b)), closes [#I4MC13](https://gitee.com/openharmony/kernel_liteos_a/issues/I4MC13)
### Features
* add option SIOCGIFBRDADDR for ioctl ([4ecc473](https://gitee.com/openharmony/kernel_liteos_a/commits/4ecc473843207d259613d26b8ee176d75e7f00fd)), closes [#I4DNRF](https://gitee.com/openharmony/kernel_liteos_a/issues/I4DNRF)
* add sync() to vfs ([f67c4da](https://gitee.com/openharmony/kernel_liteos_a/commits/f67c4dae5141914df2e069dce0196b14780649d8)), closes [#I480HV](https://gitee.com/openharmony/kernel_liteos_a/issues/I480HV)
* **build:** support gcc toolchain ([6e886d4](https://gitee.com/openharmony/kernel_liteos_a/commits/6e886d4233dec3b82a27642f174b920e5f98f6aa))
* L0-L1 支持Perf ([6e0a3f1](https://gitee.com/openharmony/kernel_liteos_a/commits/6e0a3f10bbbfe29d110c050da927684b6d77b961)), closes [#I47I9A](https://gitee.com/openharmony/kernel_liteos_a/issues/I47I9A)
* L0~L1 支持Lms ([e748fdb](https://gitee.com/openharmony/kernel_liteos_a/commits/e748fdbe578a1ddd8eb10b2e207042676231ba26)), closes [#I4HYAV](https://gitee.com/openharmony/kernel_liteos_a/issues/I4HYAV)
* liteipc 静态内存优化 ([5237924](https://gitee.com/openharmony/kernel_liteos_a/commits/52379242c109e0cf442784dbe811ff9d42d5f33a)), closes [#I4G4HP](https://gitee.com/openharmony/kernel_liteos_a/issues/I4G4HP)
* page cache backed by vnode instead of filep ([38a6b80](https://gitee.com/openharmony/kernel_liteos_a/commits/38a6b804e9291d2fdbd189825ebd7d56165ec51c)), closes [#I44TBS](https://gitee.com/openharmony/kernel_liteos_a/issues/I44TBS)
* 提供低功耗默认处理框架 ([212d1bd](https://gitee.com/openharmony/kernel_liteos_a/commits/212d1bd1e806530fe7e7a16ea986cb2c6fb084ed)), closes [#I4KBG9](https://gitee.com/openharmony/kernel_liteos_a/issues/I4KBG9)
* 支持AT_RANDOM以增强用户态栈保护能力 ([06ea037](https://gitee.com/openharmony/kernel_liteos_a/commits/06ea03715f0cfb8728fadd0d9c19a403dc8f6028)), closes [#I4CB8M](https://gitee.com/openharmony/kernel_liteos_a/issues/I4CB8M)
* 支持L1 低功耗框架 ([64e49ab](https://gitee.com/openharmony/kernel_liteos_a/commits/64e49aba7c9c7d2280c5b3f29f04b17b63209855)), closes [#I4JSOT](https://gitee.com/openharmony/kernel_liteos_a/issues/I4JSOT)
* 支持LOS_TaskJoin 和 LOS_TaskDetach ([37bc11f](https://gitee.com/openharmony/kernel_liteos_a/commits/37bc11fa8837a3019a0a56702f401ec1845f6547)), closes [#I4EENF](https://gitee.com/openharmony/kernel_liteos_a/issues/I4EENF)
* 新增解析异常和backtrace信息脚本 ([7019fdf](https://gitee.com/openharmony/kernel_liteos_a/commits/7019fdfcbb33c660e8aa9fd399d5fccbd7e23b49)), closes [#I47EVQ](https://gitee.com/openharmony/kernel_liteos_a/issues/I47EVQ)
* 调度tick响应时间计算优化 ([f47da44](https://gitee.com/openharmony/kernel_liteos_a/commits/f47da44b39be7fa3e9b5031d7b79b9bef1fd4fbc))
* 调度去进程化,优化进程线程依赖关系 ([dc479fb](https://gitee.com/openharmony/kernel_liteos_a/commits/dc479fb7bd9cb8441e4e47d44b42110ea07d76a2))
* 调度相关模块间依赖优化 ([0e3936c](https://gitee.com/openharmony/kernel_liteos_a/commits/0e3936c4f8b8bcfc48d283a6d53413e0fc0619b3)), closes [#I4RPRW](https://gitee.com/openharmony/kernel_liteos_a/issues/I4RPRW)
* 进程cpup占用率结构优化为动态分配 ([f06e090](https://gitee.com/openharmony/kernel_liteos_a/commits/f06e090a1085a654fd726fbc3c3a1c2bc703d663)), closes [#I4GLNT](https://gitee.com/openharmony/kernel_liteos_a/issues/I4GLNT)
* 进程rlimit修改为动态分配,减少静态内存占用 ([cf8446c](https://gitee.com/openharmony/kernel_liteos_a/commits/cf8446c94112ed6993a2e6e71e793d83a72689d5)), closes [#I4EZY5](https://gitee.com/openharmony/kernel_liteos_a/issues/I4EZY5)
### BREAKING CHANGES
* 1. 删除 LOS_CirBufLock()LOS_CirBufUnlock()内核对外接口
2. LOS_CirBufWrite()LOS_CirBufRead()由原先内部不进行上/解锁操作,变为默认已包含上/解锁操作。
* 新增支持API:
LOS_LmsCheckPoolAdd使能检测指定内存池
LOS_LmsCheckPoolDel不检测指定内存池
LOS_LmsAddrProtect为指定内存段上锁不允许访问
LOS_LmsAddrDisableProtect去能指定内存段的访问保护
* 1.新增一系列perf的对外API位于los_perf.h中.
LOS_PerfInit配置采样数据缓冲区
LOS_PerfStart开启Perf采样
LOS_PerfStop停止Perf采样
LOS_PerfConfig配置Perf采样事件
LOS_PerfDataRead读取采样数据
LOS_PerfNotifyHookReg 注册采样数据缓冲区的钩子函数
LOS_PerfFlushHookReg 注册缓冲区刷cache的钩子
2. 用户态新增perf命令
【Usage】:
./perf [start] /[start id] Start perf.
./perf [stop] Stop perf.
./perf [read nBytes] Read nBytes raw data from perf buffer and print out.
./perf [list] List events to be used in -e.
./perf [stat] or [record] <option> <command>
-e, event selector. use './perf list' to list available events.
-p, event period.
-o, perf data output filename.
-t, taskId filter(whiltelist), if not set perf will sample all tasks.
-s, type of data to sample defined in PerfSampleType los_perf.h.
-P, processId filter(whiltelist), if not set perf will sample all processes.
-d, whether to prescaler (once every 64 counts), which only take effect on cpu cycle hardware event.
# (2021-09-30)
### Bug Fixes
* A核代码告警清零 ([698756d](https://gitee.com/openharmony/kernel_liteos_a/commits/698756d1e6dfb11b9f874c02ce6a1496646f2c27)), closes [#I4378T](https://gitee.com/openharmony/kernel_liteos_a/issues/I4378T)
* A核告警消除 ([d16bfd0](https://gitee.com/openharmony/kernel_liteos_a/commits/d16bfd005a6dae78df2df3ad55cf21e0716dfae9)), closes [#I46KF6](https://gitee.com/openharmony/kernel_liteos_a/issues/I46KF6)
* 3518平台, 异常测试进程无法正常退出 ([23937a2](https://gitee.com/openharmony/kernel_liteos_a/commits/23937a239f50d1487e89f3184e4f4b933d6842c6)), closes [#I3V8R5](https://gitee.com/openharmony/kernel_liteos_a/issues/I3V8R5)
* add (void) to GetFileMappingList method ([56b8eca](https://gitee.com/openharmony/kernel_liteos_a/commits/56b8ecaf171671c0fe97f1dd1f191bebb7812a51)), closes [#I3XPXY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XPXY)
* add capability and amend smoke testcase ([c9d69e2](https://gitee.com/openharmony/kernel_liteos_a/commits/c9d69e2d1bde57c67068cc36f6a79327d5db5daf))
* add fchdir api ([e828cbd](https://gitee.com/openharmony/kernel_liteos_a/commits/e828cbdeac7d60bfd6ed98c75a9958ee8ec7b672))
* add fchmod api ([2f214bf](https://gitee.com/openharmony/kernel_liteos_a/commits/2f214bf4de6c31875c77e84b1763e96bc5ceb669))
* add fststfs api and unitest ([4c57aa2](https://gitee.com/openharmony/kernel_liteos_a/commits/4c57aa26ad3644ce2429effc8e8fe7fd3c52ebc2))
* add product_path parameter for driver build ([88fe4eb](https://gitee.com/openharmony/kernel_liteos_a/commits/88fe4eb3e1eafa6d1e32c7b96579a07f5a8c6e35)), closes [#I3PQ10](https://gitee.com/openharmony/drivers_adapter/issues/I3PQ10)
* add syscall for ppoll & add 2 testcases ([defedb6](https://gitee.com/openharmony/kernel_liteos_a/commits/defedb6fdf0806da4a39e22408544cdfb405f2ff))
* avoid compile warning ignored ([eca711b](https://gitee.com/openharmony/kernel_liteos_a/commits/eca711bb64a7c806ae34c8483cac73fe22b0104f)), closes [#I3VOAO](https://gitee.com/openharmony/kernel_liteos_a/issues/I3VOAO)
* A核codex修改 ([ec977a1](https://gitee.com/openharmony/kernel_liteos_a/commits/ec977a1c7e9ba4ea6621ceb1d0d10e586148208d)), closes [#I40B1S](https://gitee.com/openharmony/kernel_liteos_a/issues/I40B1S)
* BBOX使用预留物理内存缓存故障日志 ([2ad176e](https://gitee.com/openharmony/kernel_liteos_a/commits/2ad176e587d5ed7106831a25d386a88e26192e2b)), closes [#I41YIZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I41YIZ)
* bootargs解析与rootfs挂载解耦并支持自定义bootargs参数 ([80473f0](https://gitee.com/openharmony/kernel_liteos_a/commits/80473f0975fe6fd4c4eae3a8a473674ad2dd1293)), closes [#I41CL8](https://gitee.com/openharmony/kernel_liteos_a/issues/I41CL8)
* **build:** clang10.0.1支持lto去掉冗余判断 ([73223ae](https://gitee.com/openharmony/kernel_liteos_a/commits/73223ae7e652b7cd9f1e1848c32b2b2573d07b2a))
* **build:** fix rootfsdir.sh target directory not exist ([21bf2b8](https://gitee.com/openharmony/kernel_liteos_a/commits/21bf2b889931787fb18ca7ea238291fd57e76d51)), closes [#I3NHQ0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NHQ0)
* **build:** 去除冗余单板相关的宏配置 ([471de36](https://gitee.com/openharmony/kernel_liteos_a/commits/471de3663ea8b63f7448162edc0293b8723dcefc))
* clang10 lld could not recognized Oz ([87a0006](https://gitee.com/openharmony/kernel_liteos_a/commits/87a0006d5e1976fdf5efe4be383921610eb04ec6))
* clang相关编译选项隔离 ([77dcef4](https://gitee.com/openharmony/kernel_liteos_a/commits/77dcef4bc0c92d0141f7a3be0addd4d5cb533b0b)), closes [#I444AV](https://gitee.com/openharmony/kernel_liteos_a/issues/I444AV)
* codex ([101a55d](https://gitee.com/openharmony/kernel_liteos_a/commits/101a55d1199530d621f809976f0024aa8295cce8))
* codex clean ([b5370af](https://gitee.com/openharmony/kernel_liteos_a/commits/b5370af822c8e81ed2248ac8aa3bb479a0db9dae)), closes [#I3UOFN](https://gitee.com/openharmony/kernel_liteos_a/issues/I3UOFN)
* compile error when fatfs disabled ([fd3f407](https://gitee.com/openharmony/kernel_liteos_a/commits/fd3f4072b5c3dff710013ccdaddf114b0e13f435))
* console compile bug fix ([f8441a0](https://gitee.com/openharmony/kernel_liteos_a/commits/f8441a0cdea301449416b0c0477dc48a05b6ab4e))
* correct spelling ([c66fe03](https://gitee.com/openharmony/kernel_liteos_a/commits/c66fe0313f76ba41992b4864c93cf82934378ad3))
* Correctly handle the return value of LOS_EventRead in QuickstartListen. ([0e0ab81](https://gitee.com/openharmony/kernel_liteos_a/commits/0e0ab81ff9474cffd5e60a8ee741840eac5d737b)), closes [#I3PSLZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I3PSLZ)
* Ctrl-C move out of LOS_MAGIC_KEY_ENABLE ([40f239a](https://gitee.com/openharmony/kernel_liteos_a/commits/40f239a7d4673dc740c853b1011b5072e48385b7))
* Delete useless 'exc interaction' macros and function declarations. ([d2f2679](https://gitee.com/openharmony/kernel_liteos_a/commits/d2f26790716c9f76589c4a7d6fa5518f9ccd743c)), closes [#I3SDKY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3SDKY)
* dereference NULL point bug fix ([deaa564](https://gitee.com/openharmony/kernel_liteos_a/commits/deaa564a66b83c9fe19a37b8a061ec9064ece354))
* do not build toybox temporarily ([044f2c7](https://gitee.com/openharmony/kernel_liteos_a/commits/044f2c7c17c68e10aeccc3af0c222cfc722d194c))
* do not override existing libs ([8118408](https://gitee.com/openharmony/kernel_liteos_a/commits/8118408123e75f7f5a4ab9101e388be6bba0dcda))
* **doc:** 修复README_zh-HK.md的链接错误 ([f1b4c87](https://gitee.com/openharmony/kernel_liteos_a/commits/f1b4c87bc44650348504bc00b3f6f94491c341a0))
* fatfs memory leak ([fbfd71d](https://gitee.com/openharmony/kernel_liteos_a/commits/fbfd71dfe3b5555ef09e542d96a630dfba636daa))
* fix function name OsSchedSetIdleTaskSchedParam ([8f8c038](https://gitee.com/openharmony/kernel_liteos_a/commits/8f8c038b217d5ba2518413bfc1ba857587d47442))
* Fix kernel page fault exception handling causing system exception. ([a89fb57](https://gitee.com/openharmony/kernel_liteos_a/commits/a89fb57f5795236b93fd19ee2d7a059cae1b2b1b)), closes [#I3RAN4](https://gitee.com/openharmony/kernel_liteos_a/issues/I3RAN4)
* fix length typo ([12d98b1](https://gitee.com/openharmony/kernel_liteos_a/commits/12d98b144b70e726d3fd31ddc9d17ed855d0ec1b))
* fix mq function by enable mq_notify api ([4427142](https://gitee.com/openharmony/kernel_liteos_a/commits/4427142d734df8f95f4599093392904abacc5c93))
* Fix quickstart codingstyle ([2e011b6](https://gitee.com/openharmony/kernel_liteos_a/commits/2e011b672f6b96ea7e0db066a07e3f9fb6ba5df3)), closes [#I3OPOM](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OPOM)
* fix stored typo ([d25560f](https://gitee.com/openharmony/kernel_liteos_a/commits/d25560f8ac3216670d198cbbb25891c394e0b3c2))
* fix syscall faccessat,fstatfs,fstatat & add 6 testcases ([aa1cd24](https://gitee.com/openharmony/kernel_liteos_a/commits/aa1cd245a5711e5b53c328b688da5ddc2e783d5f))
* fix the inappropriate errno in FatFs ([af61187](https://gitee.com/openharmony/kernel_liteos_a/commits/af61187587411dca38ff62e720451f08f19c1c82)), closes [#I3O8IF](https://gitee.com/openharmony/kernel_liteos_a/issues/I3O8IF)
* fix typo in quickstart ([3b2ff4b](https://gitee.com/openharmony/kernel_liteos_a/commits/3b2ff4b71fc5ae1dc74180c33fd66f69da0059d1)), closes [#I3M1S8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3M1S8)
* Fix wrong judgment in los_trace.c to avoid null pointer access. ([4d863e9](https://gitee.com/openharmony/kernel_liteos_a/commits/4d863e985b6372f7895db57b602b662dba5cadd0)), closes [#I3RT9F](https://gitee.com/openharmony/kernel_liteos_a/issues/I3RT9F)
* Identical condition 'ret<0', second condition is always false. :bug: ([1348809](https://gitee.com/openharmony/kernel_liteos_a/commits/1348809807548dd481286a55a6677a9169fcd705))
* init进程收到子进程退出信号后调用fork重新拉起进程会导致系统卡死 ([35a2f3a](https://gitee.com/openharmony/kernel_liteos_a/commits/35a2f3af33a5dba1e0ba36587efced8fead97223)), closes [#I41HOY](https://gitee.com/openharmony/kernel_liteos_a/issues/I41HOY)
* kernel crashed after rmdir the umounted folder ([ac0d083](https://gitee.com/openharmony/kernel_liteos_a/commits/ac0d083b1c89c4ad3fdaab0347d11f174d0185cb))
* kernel crashed when delete a umounted folder ([f305d1f](https://gitee.com/openharmony/kernel_liteos_a/commits/f305d1f702a770010125a0f4f0152ffefeeec5c4))
* kernel crashed when delete a umounted folder ([c6e9212](https://gitee.com/openharmony/kernel_liteos_a/commits/c6e921241b1cf26bcbfeea44e20f6b596512e259))
* **kernel_test:** 内核mem/shm冒烟用例重复运行失败 ([0676578](https://gitee.com/openharmony/kernel_liteos_a/commits/0676578aae09c101d79e7a276823e849df293e29)), closes [#I3TH4W](https://gitee.com/openharmony/kernel_liteos_a/issues/I3TH4W)
* L1 toybox 命令功能实现 ([2ff44c4](https://gitee.com/openharmony/kernel_liteos_a/commits/2ff44c4938d2e66ce60e9497c505eb6e97efc8c2)), closes [#I41N2A](https://gitee.com/openharmony/third_party_toybox/issues/I41N2A)
* liteipc max data size too small ([4dc421e](https://gitee.com/openharmony/kernel_liteos_a/commits/4dc421e3decdaae60219d533c4a93dbc9334e35f))
* LiteOS_A BBOX Codex整改 ([6a5a032](https://gitee.com/openharmony/kernel_liteos_a/commits/6a5a0326d2b18ffacce5d38fb351530973c2f245)), closes [#I43RQU](https://gitee.com/openharmony/kernel_liteos_a/issues/I43RQU)
* Liteos-a创建的文件夹在Ubuntu中不可见 ([a9fc1e0](https://gitee.com/openharmony/kernel_liteos_a/commits/a9fc1e0e5d3e5eb8a34c568a8d147320a9afebe1)), closes [#I3XMY6](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XMY6)
* lookup new vnode may cause parent vnode freeing ([902a11d](https://gitee.com/openharmony/kernel_liteos_a/commits/902a11de9a4b08e799820fb87942cb2171b9e095)), closes [#I3MYP4](https://gitee.com/openharmony/kernel_liteos_a/issues/I3MYP4)
* **mini:** fix compile error in mini liteos_a ([e13cb3b](https://gitee.com/openharmony/kernel_liteos_a/commits/e13cb3bcc4e74d4c49c31d290d686f99a4e81e3f))
* minimal compile ([ac8c2c6](https://gitee.com/openharmony/kernel_liteos_a/commits/ac8c2c6d5b9ede0e46b48212f0b3447605a613c4))
* misspell ([08980ea](https://gitee.com/openharmony/kernel_liteos_a/commits/08980eac3c249ec6a6717d8a04fb0be7716053a1))
* mkdir -p is more robust ([e38f9a9](https://gitee.com/openharmony/kernel_liteos_a/commits/e38f9a98c9d373db8381af707c5996d1fefef64e))
* mksh compile bug fix ([d8263b1](https://gitee.com/openharmony/kernel_liteos_a/commits/d8263b1e91d76706d52df321ef642c1c8297e8e4)), closes [#I3ZMR7](https://gitee.com/openharmony/kernel_liteos_a/issues/I3ZMR7)
* modify event API description ([937734b](https://gitee.com/openharmony/kernel_liteos_a/commits/937734b1e9f5fc52e0ac727549bd2e4b4c864e3c))
* move nuttx head file back ([4c8a86e](https://gitee.com/openharmony/kernel_liteos_a/commits/4c8a86ece7cafa8f74441bacc74c7788c0a1b780)), closes [#I4443Q](https://gitee.com/openharmony/kernel_liteos_a/issues/I4443Q)
* nanosleep 接口的rmtp参数被错误清零 ([9458de9](https://gitee.com/openharmony/kernel_liteos_a/commits/9458de9ac664cd75540c8b638b9a6caf82812fc8)), closes [#I41U0R](https://gitee.com/openharmony/kernel_liteos_a/issues/I41U0R)
* no exception information output, when the system is abnormal ([5bf4d1c](https://gitee.com/openharmony/kernel_liteos_a/commits/5bf4d1c7128e6718611bbec23cb4373bcb3bfe55))
* no exception information output, when the system is abnormal ([28aa777](https://gitee.com/openharmony/kernel_liteos_a/commits/28aa777191e7b41e4f1f346ab79f8688edc59c6d))
* no exception information output, when the system is abnormal after holding ([0ed8adf](https://gitee.com/openharmony/kernel_liteos_a/commits/0ed8adfe3ae59672e284331d40ef3b9e0bc8e094))
* Optimiz macro of quickstart cmd ([cb140a4](https://gitee.com/openharmony/kernel_liteos_a/commits/cb140a4442c02dd0b1925cc58deecbf4da36dcea)), closes [#I3OSYT](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OSYT)
* Optimize /dev/quickstart permissions. ([4e24b57](https://gitee.com/openharmony/kernel_liteos_a/commits/4e24b572897c33e1b2723122c0e13d3931096bae)), closes [#I3OYUQ](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OYUQ)
* Optimize quickstart node implementation ([4abd2e0](https://gitee.com/openharmony/kernel_liteos_a/commits/4abd2e0247b14718bb21756fb446142140d30a88)), closes [#I3R8O8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3R8O8)
* OsGerCurrSchedTimeCycle 函数存在拼写错误 ([53ced1a](https://gitee.com/openharmony/kernel_liteos_a/commits/53ced1a85edc3d06230225ced3916772f432243f)), closes [#I446CX](https://gitee.com/openharmony/kernel_liteos_a/issues/I446CX)
* OsGetArgsAddr声明所在头文件不正确 ([14bd753](https://gitee.com/openharmony/kernel_liteos_a/commits/14bd753aa8beb49af887c8d0aedaefa446409760)), closes [#I41MWM](https://gitee.com/openharmony/kernel_liteos_a/issues/I41MWM)
* parent point of vnode found by VfsHashGet should be updated ([f32caa5](https://gitee.com/openharmony/kernel_liteos_a/commits/f32caa52c67eca20d58676be4e0439acbb4c5ac3)), closes [#I3NNFA](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NNFA)
* PathCacheFree try to free name field in struct PathCache ([9f47faf](https://gitee.com/openharmony/kernel_liteos_a/commits/9f47faff732609cf2249f104b94ed55f3ef133bb)), closes [#I3NTH9](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NTH9)
* PathCacheMemoryDump miscalculate the RAM usage of PathCache ([87da7c7](https://gitee.com/openharmony/kernel_liteos_a/commits/87da7c794c9bc8e311ae5242820fbf8aefd8d558)), closes [#I3OBXY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OBXY)
* Provide a separate configuration macro for boot environment in RAM. ([e28e06b](https://gitee.com/openharmony/kernel_liteos_a/commits/e28e06b08f5b28091153e584cb9d93014a9f2b10))
* Provide a separate configuration macro for boot environment in RAM. ([bc67393](https://gitee.com/openharmony/kernel_liteos_a/commits/bc67393a67f714e0a8165b6103e53699c676341c))
* Provide a separate configuration macro for boot environment in RAM. ([f13b90e](https://gitee.com/openharmony/kernel_liteos_a/commits/f13b90e4308ba3d60683799b9ce62fb3705ac277)), closes [#I3OADR](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OADR)
* race condition in liteipc ([7e2aef2](https://gitee.com/openharmony/kernel_liteos_a/commits/7e2aef2480b15f71ee0e089cef4443f578e03dbb)), closes [#I3PW5Y](https://gitee.com/openharmony/kernel_liteos_a/issues/I3PW5Y)
* rebuild mksh depends on rebuild.sh script ([bef4ab9](https://gitee.com/openharmony/kernel_liteos_a/commits/bef4ab9835dec865898c74337dfb7154718b94aa))
* remove redundant headfile ([73a7777](https://gitee.com/openharmony/kernel_liteos_a/commits/73a777777e1b834192f6bb2c0e8bd03c69765c11)), closes [#I3RTNR](https://gitee.com/openharmony/kernel_liteos_a/issues/I3RTNR)
* Remove redundant invalid codes ([fe05df4](https://gitee.com/openharmony/kernel_liteos_a/commits/fe05df40ae710632adb1bd54fb04ad4a8e0c1429)), closes [#I3R70T](https://gitee.com/openharmony/kernel_liteos_a/issues/I3R70T)
* Show conflicting files for git apply or patch -p command ([35f7957](https://gitee.com/openharmony/kernel_liteos_a/commits/35f79579758644cbcac6005f894be21f34f42b99)), closes [#I3NNUS](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NNUS)
* SIOCGIFCONF ioctl malloc size error in kernel ([bfd27e7](https://gitee.com/openharmony/kernel_liteos_a/commits/bfd27e78b259eedbd4c30548e80c9b4d789d26e1)), closes [#I3XEZ3](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XEZ3)
* smp启动代码解耦及内存映射关系解耦 ([3bb3173](https://gitee.com/openharmony/kernel_liteos_a/commits/3bb3173604dc4dea09301f61da402974185dc112)), closes [#I41P8Y](https://gitee.com/openharmony/kernel_liteos_a/issues/I41P8Y)
* some branch in format does not release the vnode mutex properly ([9b2b700](https://gitee.com/openharmony/kernel_liteos_a/commits/9b2b700fa0e3a8edadb38f09c917a3e3f013347f)), closes [#I3OFAY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OFAY)
* Sortlink, the response time to insert the node should be inserted into the back of the existing node. ([1323874](https://gitee.com/openharmony/kernel_liteos_a/commits/1323874389030c55fb053fead12ca1c6654d8851)), closes [#I3PSJ8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3PSJ8)
* statfs can't get f_bfree and f_bavail of a FAT12/FAT16 partition ([9503c4a](https://gitee.com/openharmony/kernel_liteos_a/commits/9503c4a9fc30aaa8ea2031d4fb794436f3c98055)), closes [#I3Q0VS](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Q0VS)
* SysOpenat返回值应该为进程fd而非系统全局fd。 ([3457c0b](https://gitee.com/openharmony/kernel_liteos_a/commits/3457c0b11debb2cf5d4abe325c2510a750654512)), closes [#I3TNAK](https://gitee.com/openharmony/kernel_liteos_a/issues/I3TNAK)
* the total used vnode number not increased after unlink a file under ([4f514a1](https://gitee.com/openharmony/kernel_liteos_a/commits/4f514a16af5a3f3b9c4ea182de774297afb17f66)), closes [#I3TS1Y](https://gitee.com/openharmony/kernel_liteos_a/issues/I3TS1Y)
* tick 动态化计算优化,消除中断执行时间对系统总体时间的影响,保证软件定时器的响应精度。 ([8df3e8c](https://gitee.com/openharmony/kernel_liteos_a/commits/8df3e8c96515a1907455a9bbc61426f43c803c62)), closes [#I43UQJ](https://gitee.com/openharmony/kernel_liteos_a/issues/I43UQJ)
* toybox update ([c3245b3](https://gitee.com/openharmony/kernel_liteos_a/commits/c3245b3ce317eb58c8dad58fdfc7f094b9b9794b))
* toybox命令升级 ([76f45b3](https://gitee.com/openharmony/kernel_liteos_a/commits/76f45b3fb2783d1cab45a6ba08787c29dfa2c948)), closes [#I41N2A](https://gitee.com/openharmony/third_party_toybox/issues/I41N2A)
* update LOS_DL_LIST_IS_END comment ([900269b](https://gitee.com/openharmony/kernel_liteos_a/commits/900269bd4645252d898f6d3b73de01d8548c960c))
* userfs分区的起始地址与大小改为通过bootargs配置 ([2e2b142](https://gitee.com/openharmony/kernel_liteos_a/commits/2e2b14205f4b81c7483ab42d62f144487097e9a4)), closes [#I3XNEY](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XNEY)
* VnodeInUseIter and VnodeFreeAll used to be recursive ([5f6656c](https://gitee.com/openharmony/kernel_liteos_a/commits/5f6656cb36a2ffb0b290aeb53981aba7501e80b2)), closes [#I3NN3U](https://gitee.com/openharmony/kernel_liteos_a/issues/I3NN3U)
* 以g_sysSchedStartTime是否为0判断时间轴是否生效存在极限场景导致调度时间不生效 ([67ac8c4](https://gitee.com/openharmony/kernel_liteos_a/commits/67ac8c4c586adc371ece56700fd42371ca7fc885)), closes [#I45HP5](https://gitee.com/openharmony/kernel_liteos_m/issues/I45HP5)
* 修复FATFS中不同内部接口不支持FAT12/FAT16 FAT表结束标志 ([33f5c70](https://gitee.com/openharmony/kernel_liteos_a/commits/33f5c70e6c8781758d2bfde0f60ca3d6ec7d543f)), closes [#I409R6](https://gitee.com/openharmony/kernel_liteos_a/issues/I409R6)
* 修复kill进程时因liteipc阻塞的进程概率无法退出问题 ([7de43bb](https://gitee.com/openharmony/kernel_liteos_a/commits/7de43bb004a12f926550f0b36ca3c2fa610feb27)), closes [#I3XX7K](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XX7K)
* 修复MagicKey数组越界访问 ([071cd62](https://gitee.com/openharmony/kernel_liteos_a/commits/071cd6268aeaaef702387dacaf4ef1ffbb7618fc)), closes [#I3U4N9](https://gitee.com/openharmony/kernel_liteos_a/issues/I3U4N9)
* 修复mprotect修改地址区间的权限后相应的区间名丢失问题 ([e425187](https://gitee.com/openharmony/kernel_liteos_a/commits/e425187d176a5e09bc5253faefc9cfc8454da0a3)), closes [#I43R40](https://gitee.com/openharmony/kernel_liteos_a/issues/I43R40)
* 修复mq_close关闭后仍然占用文件描述符的问题 ([590c7b4](https://gitee.com/openharmony/kernel_liteos_a/commits/590c7b4e22662781d05ad035a785e985d573ec33)), closes [#I3ZQDA](https://gitee.com/openharmony/kernel_liteos_a/issues/I3ZQDA)
* 修复mqueue问题 ([26ee8b8](https://gitee.com/openharmony/kernel_liteos_a/commits/26ee8b836e346e641de4ecd72284f5d377bca6f8)), closes [#I43P4T](https://gitee.com/openharmony/kernel_liteos_a/issues/I43P4T)
* 修复sigwait等待到的信号值与获取的siginfo中的值不一致 ([ed7defb](https://gitee.com/openharmony/kernel_liteos_a/commits/ed7defbd439c345a07159d40eb04433afd530004)), closes [#I3M12H](https://gitee.com/openharmony/kernel_liteos_a/issues/I3M12H)
* 修复了LOSCFG_FS_FAT_VIRTUAL_PARTITION宏开关错误作用域引起的功能错误 ([acda419](https://gitee.com/openharmony/kernel_liteos_a/commits/acda419a2d773ea890052a16ee66b4872f941fbb)), closes [#I3W1IW](https://gitee.com/openharmony/kernel_liteos_a/issues/I3W1IW)
* 修复了内核的VFAT测试用例 ([a8384b5](https://gitee.com/openharmony/kernel_liteos_a/commits/a8384b5db2274d50a350910d7cfd3fc36b4f4103)), closes [#I3XF3R](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XF3R)
* 修复内核access chmod chown接口 ([56a95b9](https://gitee.com/openharmony/kernel_liteos_a/commits/56a95b9ec903f815f9199ac65ca318e00a83b2ed)), closes [#I3Z5L6](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Z5L6)
* 修复内核c库的makefile中被优化函数替换的高频函数依然参与了编译的问题 ([6f6dc4f](https://gitee.com/openharmony/kernel_liteos_a/commits/6f6dc4f24c8ab05a6d42da46a9fa41d74a477bd7)), closes [#I3XGM8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XGM8)
* 修复内核堆完整性检查逻辑中访问非法指针导致系统异常问题。 ([30f5ab8](https://gitee.com/openharmony/kernel_liteos_a/commits/30f5ab89b72d45f596b15af82a8e8e01add7977d)), closes [#I3VJZT](https://gitee.com/openharmony/kernel_liteos_a/issues/I3VJZT)
* 修复启动框架debug模式下-Werror=maybe-uninitialized告警以及符号链接不进镜像的隐患 ([4c02415](https://gitee.com/openharmony/kernel_liteos_a/commits/4c024159a9600745863e49ee955308470a5b657b)), closes [#I3T5HR](https://gitee.com/openharmony/kernel_liteos_a/issues/I3T5HR)
* 修复开机概率挂死 ([2e82c36](https://gitee.com/openharmony/kernel_liteos_a/commits/2e82c361f73b2119613c3571c48faae8ec41d4eb)), closes [#I3SWY2](https://gitee.com/openharmony/kernel_liteos_a/issues/I3SWY2)
* 修复文档链接失效问题 ([42a3a6c](https://gitee.com/openharmony/kernel_liteos_a/commits/42a3a6c51bfca4ade8ce94084ea2f8eb1c86a137)), closes [#I45297](https://gitee.com/openharmony/kernel_liteos_a/issues/I45297)
* 修改/proc/mounts显示格式 ([6860246](https://gitee.com/openharmony/kernel_liteos_a/commits/6860246cfaac6f540665e79bbc4c3d54c419b092)), closes [#I3XGCS](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XGCS)
* 修改clock_gettime接口适配posix标准测试用例011输入clk_id错误时返回值ESRCH为EINVAL. ([f8cf6e6](https://gitee.com/openharmony/kernel_liteos_a/commits/f8cf6e6439ee017fe8e0d4ecfc9949c28fa6775f)), closes [#I3OUHI](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OUHI)
* 修改DoNanoSleep 以纳秒为单位 ([6917e08](https://gitee.com/openharmony/kernel_liteos_a/commits/6917e08431689ccbd5a30e9a39b67016ffb64d0a)), closes [#I3Z9DP](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Z9DP)
* 修改某些平台保存bbox日志失败的问题 ([8f6a1dd](https://gitee.com/openharmony/kernel_liteos_a/commits/8f6a1dd33c59164070e8d2fb5abbd3e76ef8ac8e)), closes [#I41UTP](https://gitee.com/openharmony/kernel_liteos_a/issues/I41UTP)
* 修改默认窗口宽度到400 ([09c491c](https://gitee.com/openharmony/kernel_liteos_a/commits/09c491ca1fd6d3110eafb0d07e45b25bdc3bd5d0)), closes [#I40LQX](https://gitee.com/openharmony/kernel_liteos_a/issues/I40LQX)
* 关闭jffs和fat后rootfs配置也被相应关闭导致nand介质的rootfs不可用。 ([0ea476b](https://gitee.com/openharmony/kernel_liteos_a/commits/0ea476b9741fabd3c255c2770688f587920cf509)), closes [#I3SBYN](https://gitee.com/openharmony/kernel_liteos_a/issues/I3SBYN)
* 内核态在console初始化完成后使用printf无法正常打印 ([44ce696](https://gitee.com/openharmony/kernel_liteos_a/commits/44ce6969048c2e252f3f9d66fa485c77bdab8ae7)), closes [#I3UG00](https://gitee.com/openharmony/kernel_liteos_a/issues/I3UG00)
* 去掉冗余的strip操作 ([7819d15](https://gitee.com/openharmony/kernel_liteos_a/commits/7819d15b3619681ae37a1349a6bec2440c829ae9)), closes [#I43767](https://gitee.com/openharmony/kernel_liteos_a/issues/I43767)
* 合并进程栈两个地址连续的region ([42f374d](https://gitee.com/openharmony/kernel_liteos_a/commits/42f374dd7a353f1c8227e92fa92827c1c7b32424)), closes [#I43QYJ](https://gitee.com/openharmony/kernel_liteos_a/issues/I43QYJ)
* 在内核提示No idle TCB时增加打印当前系统任务信息以方便问题定位。 ([11a9b00](https://gitee.com/openharmony/kernel_liteos_a/commits/11a9b00d43a6dbe9fba9f6eb07d78a9d226c28f8)), closes [#I434UC](https://gitee.com/openharmony/kernel_liteos_a/issues/I434UC)
* 增加表头,内容以制表符分栏。 ([e9ad6b7](https://gitee.com/openharmony/kernel_liteos_a/commits/e9ad6b71c3b1136414672cd21b339ded7a02dfb9)), closes [#I3W2M9](https://gitee.com/openharmony/kernel_liteos_a/issues/I3W2M9)
* 将用户态内存调测解析脚本移至tools目录下 ([85b4cb7](https://gitee.com/openharmony/kernel_liteos_a/commits/85b4cb7a67b717984d3ebf68115c7139cc61d690)), closes [#I42T9A](https://gitee.com/openharmony/kernel_liteos_a/issues/I42T9A)
* 恢复了FATFS设置卷标的功能 ([9515d53](https://gitee.com/openharmony/kernel_liteos_a/commits/9515d53dccc9a6458bfbaf8e15143928f05cb660)), closes [#I3Y5G8](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Y5G8)
* 解决kill进程时无法保证进程的已持有的内核资源合理释放. ([cf89f01](https://gitee.com/openharmony/kernel_liteos_a/commits/cf89f016e93f28f8d72e6f5de08640d08a155908)), closes [#I3S0N0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3S0N0)
* 解决不同环境下计算的rootfs的size偏小导致mcopy造成的disk full错误 ([c54879b](https://gitee.com/openharmony/kernel_liteos_a/commits/c54879b54875abece53b1f64072cfacbd2e1970e)), closes [#I3IA06](https://gitee.com/openharmony/kernel_liteos_a/issues/I3IA06)
* 设置qemu默认userfs大小/修改qemu驱动目录 ([1d952a2](https://gitee.com/openharmony/kernel_liteos_a/commits/1d952a254a6e7ec2f70f7112eb27355cfd01ba4d)), closes [#I3XW96](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XW96)
### Features
* active mksh & toybox ([cacb4f0](https://gitee.com/openharmony/kernel_liteos_a/commits/cacb4f0103ecb2d1b7af54d84957f88d3e9443d2)), closes [#I3VEOG](https://gitee.com/openharmony/kernel_liteos_a/issues/I3VEOG)
* Add /dev/quickstart to support synchronous communication between processes in user mode startup. ([46b63f7](https://gitee.com/openharmony/kernel_liteos_a/commits/46b63f71537789743ed2f3f337c1809ee4900d71)), closes [#I3OHO5](https://gitee.com/openharmony/kernel_liteos_a/issues/I3OHO5)
* add /proc/fd file to dump the pid/fd/path information ([600dded](https://gitee.com/openharmony/kernel_liteos_a/commits/600dded31e80df275ed08c326c0ce3d1857d8dd8)), closes [#I3WB5U](https://gitee.com/openharmony/kernel_liteos_a/issues/I3WB5U)
* add /proc/fs_cache to display cache info ([231cb6b](https://gitee.com/openharmony/kernel_liteos_a/commits/231cb6be27380948bc48136ae2e02c28450f47a8)), closes [#I3WWBD](https://gitee.com/openharmony/kernel_liteos_a/issues/I3WWBD)
* add /proc/fs_cache to display cache info ([53c6d96](https://gitee.com/openharmony/kernel_liteos_a/commits/53c6d96c6f97cb006216769f8b73f50fba3bc325)), closes [#I3WESD](https://gitee.com/openharmony/kernel_liteos_a/issues/I3WESD)
* add and fix some syscall ([ce849f2](https://gitee.com/openharmony/kernel_liteos_a/commits/ce849f2145e1569517c5244c9ffcaebed53f3a66))
* add blackbox for liteos_a ([a195aac](https://gitee.com/openharmony/kernel_liteos_a/commits/a195aac9fb60b0163f9eebb29084287d226bd14c)), closes [#I406NP](https://gitee.com/openharmony/kernel_liteos_a/issues/I406NP)
* add blackbox for liteos_a ([425975e](https://gitee.com/openharmony/kernel_liteos_a/commits/425975e4811023e31a520979c20ea2562224d9d0))
* add clear cache cmd to /proc/fs_cache ([3d1cf68](https://gitee.com/openharmony/kernel_liteos_a/commits/3d1cf683f37a6f75e9db2ce1f11ec93159b77663)), closes [#I3XLPH](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XLPH)
* add liteos patch ability ([98ca844](https://gitee.com/openharmony/kernel_liteos_a/commits/98ca8441fe75ee1c3318a6a09376fd72f5a51350))
* add support for gn build system ([a8805a6](https://gitee.com/openharmony/kernel_liteos_a/commits/a8805a65aab9109b915364fccf36c8328f636e48))
* add uid/gid for ProcFs ([6780659](https://gitee.com/openharmony/kernel_liteos_a/commits/67806596a3c0df9a54893d8c74ebe9da98d7fb06)), closes [#I3WGVP](https://gitee.com/openharmony/kernel_liteos_a/issues/I3WGVP)
* A核proc文件系统在echo模式下新增write的功能 ([f10dd7c](https://gitee.com/openharmony/kernel_liteos_a/commits/f10dd7c135d37a5fb0d78610d5ece5807d01eb1f)), closes [#I3T6MZ](https://gitee.com/openharmony/kernel_liteos_a/issues/I3T6MZ)
* build OHOS_Image from kernel ([abf4d8f](https://gitee.com/openharmony/kernel_liteos_a/commits/abf4d8fb252631aca9d46211762880a23be2a0b1))
* **build:** make liteos_config_file available as gn argument ([f9a9077](https://gitee.com/openharmony/kernel_liteos_a/commits/f9a907772f506ca7e2d84e96d4d17cffc7dae50f))
* **build:** 使用xts -notest选项时内核用例不参与编译构建和用例编译配置方式调整 ([9bdf716](https://gitee.com/openharmony/kernel_liteos_a/commits/9bdf716407c125c9877b6f49c2133112c18cdabc))
* don't apply module_swith on configs of config ([f3beb4b](https://gitee.com/openharmony/kernel_liteos_a/commits/f3beb4b273c9a76fbfaffe57302f27d2a74cd2ba))
* enable gn build for toybox and mksh ([c54bfa1](https://gitee.com/openharmony/kernel_liteos_a/commits/c54bfa16e3907482c252e9738192df869c63326e))
* fatfs支持符号链接功能 ([e50cf0b](https://gitee.com/openharmony/kernel_liteos_a/commits/e50cf0be6f6d118022b6d79c5177aece574ba150)), closes [#I3V8D1](https://gitee.com/openharmony/kernel_liteos_a/issues/I3V8D1)
* **file system:** add memory-based romfs ([c4595d2](https://gitee.com/openharmony/kernel_liteos_a/commits/c4595d25042b188570d991a815009764c37f3cb3)), closes [#I3S0CP](https://gitee.com/openharmony/kernel_liteos_a/issues/I3S0CP)
* introduce mksh toybox to rootfs ([41c7689](https://gitee.com/openharmony/kernel_liteos_a/commits/41c7689dfa49c52fb15705ce15ef22a278fbf2ef))
* L0-L1 支持Trace ([dc9ec68](https://gitee.com/openharmony/kernel_liteos_a/commits/dc9ec6856fe14aa604f037f55f17a3ba2bafb098)), closes [#I46WA0](https://gitee.com/openharmony/kernel_liteos_a/issues/I46WA0)
* L1支持低功耗投票框架 ([21d8ac8](https://gitee.com/openharmony/kernel_liteos_a/commits/21d8ac8752469f6e0dc2d50d28b75421f665385a)), closes [#I3VS5N](https://gitee.com/openharmony/kernel_liteos_a/issues/I3VS5N)
* **libc:** upgrade optimized-routines to v21.02 ([1ec8d5a](https://gitee.com/openharmony/kernel_liteos_a/commits/1ec8d5a454658e95c4acb821d0878f357f4e82ad))
* **make:** optimize makefiles and remove some unused files ([0e26094](https://gitee.com/openharmony/kernel_liteos_a/commits/0e260949c962158a263d4b0ad45fe9f6843d6e30))
* Open macro for ADC moudule ([c71ec9d](https://gitee.com/openharmony/kernel_liteos_a/commits/c71ec9d7e8574078a9dc2a8463f3141cca3d625a))
* **QEMU_ARM_VIRT_CA7:** 使能FAT文件系统编译选项 ([49856dc](https://gitee.com/openharmony/kernel_liteos_a/commits/49856dc1e0de1c5e92346c83eda641dfb1bb16be))
* support .mkshrc ([51a50c9](https://gitee.com/openharmony/kernel_liteos_a/commits/51a50c95b4cd47b6931523926b728d1c0ff8988b)), closes [#I3Y5KE](https://gitee.com/openharmony/third_party_mksh/issues/I3Y5KE)
* support link/symlink/readlink ([6eddc86](https://gitee.com/openharmony/kernel_liteos_a/commits/6eddc869d349be59860bfd84ff10b7579a9b00a9)), closes [#I3Q0OD](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Q0OD)
* support toybox in qemu ([5618319](https://gitee.com/openharmony/kernel_liteos_a/commits/561831928bb1ad1871b2d60d2bba2d67488cea5f)), closes [#I3V17D](https://gitee.com/openharmony/kernel_liteos_a/issues/I3V17D)
* timer_create支持以SIGEV_THREAD方式创建定时器 ([e5f6bf0](https://gitee.com/openharmony/kernel_liteos_a/commits/e5f6bf05567c2d193f3746caca502199e7b81e92)), closes [#I3SRFI](https://gitee.com/openharmony/kernel_liteos_a/issues/I3SRFI)
* using kconfiglib instead of kconfig ([8784694](https://gitee.com/openharmony/kernel_liteos_a/commits/878469468647a19f704e7ee2af696b0ba8ab775a))
* vfs support sdcard hotplug ([2db80ec](https://gitee.com/openharmony/kernel_liteos_a/commits/2db80ecb389176b53c77807567895470bb180a06)), closes [#I44WH1](https://gitee.com/openharmony/kernel_liteos_a/issues/I44WH1)
* **vfs:** vfs支持FD_CLOEXEC标记 ([27dca4d](https://gitee.com/openharmony/kernel_liteos_a/commits/27dca4d857ef8de6b4bb9302e0dd435be7e3284f)), closes [#I3U81W](https://gitee.com/openharmony/kernel_liteos_a/issues/I3U81W)
* 删除zpfs冗余代码 ([3393479](https://gitee.com/openharmony/kernel_liteos_a/commits/3393479c52f4a9dfe2394bb32beb4b98fca8e171))
* 基于汇编实现内核对用户态内存清零的功能 ([9db3407](https://gitee.com/openharmony/kernel_liteos_a/commits/9db3407589bb0b2d4a5772faac3130032bc0b8a9)), closes [#I3XXT0](https://gitee.com/openharmony/kernel_liteos_a/issues/I3XXT0)
* 增加mount的MS_RDONLY标志的支持 ([8729f6e](https://gitee.com/openharmony/kernel_liteos_a/commits/8729f6ee57ea57bc664d076ff112c8726fedded9)), closes [#I3Z1W6](https://gitee.com/openharmony/kernel_liteos_a/issues/I3Z1W6)
* 支持killpg和waitid ([dc3cc09](https://gitee.com/openharmony/kernel_liteos_a/commits/dc3cc094a75c6da65d87522930afea06106d3933))
* 新增toybox reboot命令 ([e567a10](https://gitee.com/openharmony/kernel_liteos_a/commits/e567a10d021c3e0fe02d6911dbe8687255c67ffa)), closes [#I3YQ7S](https://gitee.com/openharmony/third_party_toybox/issues/I3YQ7S)
* 给开发者提供系统信息导出Hidumper工具。 ([cb17fa5](https://gitee.com/openharmony/kernel_liteos_a/commits/cb17fa50ed28e6e8f59b7d68ede13c759b983311))
* 自研shell命令回补 ([7bc68f4](https://gitee.com/openharmony/kernel_liteos_a/commits/7bc68f454ff5fbf415712c9b8479b8c832f68417)), closes [#I44U0H](https://gitee.com/openharmony/third_party_toybox/issues/I44U0H)
### Performance Improvements
* assign '-1' to uninitialized variable: ret ([e0a27ba](https://gitee.com/openharmony/kernel_liteos_a/commits/e0a27badde20868cf3a5b4a44305b90af00e4f3f))
### Reverts
* Revert "fix: 修改默认窗口宽度到400" ([1878849](https://gitee.com/openharmony/kernel_liteos_a/commits/187884937cd087e39a28c033c41033163d6b4766)), closes [#I42X9V](https://gitee.com/openharmony/kernel_liteos_a/issues/I42X9V)
### BREAKING CHANGES
* 1.新增一系列trace的对外API位于los_trace.h中.
LOS_TRACE_EASY简易插桩
LOS_TRACE标准插桩
LOS_TraceInit配置Trace缓冲区的地址和大小
LOS_TraceStart开启事件记录
LOS_TraceStop停止事件记录
LOS_TraceRecordDump输出Trace缓冲区数据
LOS_TraceRecordGet获取Trace缓冲区的首地址
LOS_TraceReset清除Trace缓冲区中的事件
LOS_TraceEventMaskSet设置事件掩码仅记录某些模块的事件
LOS_TraceHwiFilterHookReg注册过滤特定中断号事件的钩子函数
* **vfs:** 执行exec类函数后进程拥有的文件描述符情况发生变化修改前默认关闭所有的进程文件描述符012重新打开修改后除非文件描述符拥有FD_CLOEXEC标记否则该描述符不会被关闭。

170
Kconfig Normal file → Executable file
View File

@ -26,73 +26,43 @@
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# For a description of the syntax of this configuration file,
# see extra/config/Kconfig-language.txt
#
mainmenu "Huawei LiteOS Configuration" mainmenu "Huawei LiteOS Configuration"
menu "Compiler" menu "Compiler"
choice choice
prompt "Compiler type" prompt "LiteOS_Compiler_Type"
default COMPILER_CLANG_LLVM default COMPILER_CLANG_LLVM
help help
Choose compiler type. Enable arm-himix100 or aarch64-himix100 or compiler.
config COMPILER_GCC config COMPILER_HIMIX_32
bool "GCC" bool "arm-linux-ohoseabi"
depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 || PLATFORM_QEMU_ARM_VIRT_CA7
config CROSS_COMPILE
string "GCC cross-compile toolchain prefix"
depends on COMPILER_GCC
default "arm-linux-ohoseabi-" if ARCH_ARM_AARCH32
config COMPILER_CLANG_LLVM config COMPILER_CLANG_LLVM
bool "Clang" bool "clang-llvm"
depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 || PLATFORM_QEMU_ARM_VIRT_CA7
config LLVM_TARGET
string "Clang LLVM target"
depends on COMPILER_CLANG_LLVM
default "arm-liteos-ohos" if ARCH_ARM_AARCH32
endchoice endchoice
config COMPILE_DEBUG
bool "Enable debug options"
default n
help
Answer Y to add -g option in compile command.
config COMPILE_OPTIMIZE
bool "Enable code optimization options"
default y
help
Answer Y to add optimization options for efficient code.
The final binary size will be smaller and execute faster.
But the debugging experience may be worst somehow.
config COMPILE_OPTIMIZE_SIZE
bool "Enable code size optimization options" if COMPILE_OPTIMIZE
default y
help
Answer Y to add optimization options for small code size.
The final binary size will be smaller.
But the compile time may be a bit longer.
config COMPILE_LTO
bool "Enable link time optimization (LTO)" if COMPILE_OPTIMIZE_SIZE
default y
help
Answer Y to add lto options for more smaller code size.
The final binary size will be smaller.
But the compile time may be much longer.
endmenu endmenu
menu "Platform" menu "Platform"
######################### config options of bsp ##################### ######################### config options of bsp #####################
source "platform/Kconfig" source "../../kernel/liteos_a/platform/Kconfig"
######################### config options of cpu arch ################ ######################### config options of cpu arch ################
source "arch/Kconfig" source "../../kernel/liteos_a/arch/Kconfig"
######################### config options of rootfs #####################
source "../../kernel/liteos_a/kernel/common/Kconfig"
######################### config options of patchfs #####################
source "../../kernel/liteos_a/kernel/common/patchfs/Kconfig"
config QUICK_START config QUICK_START
bool "Enable QUICK_START" bool "Enable QUICK_START"
@ -103,30 +73,44 @@ config QUICK_START
endmenu endmenu
######################### config options of kernel ##################### ######################### config options of kernel #####################
source "kernel/Kconfig" source "../../kernel/liteos_a/kernel/Kconfig"
######################### config options of lib ######################## ######################### config options of lib ########################
source "lib/Kconfig" source "../../kernel/liteos_a/lib/Kconfig"
######################### config options of compatibility ############## ######################### config options of compatibility ##############
menu "Compat" menu "Compat"
source "compat/posix/Kconfig" source "../../kernel/liteos_a/compat/posix/Kconfig"
source "bsd/Kconfig" source "../../kernel/liteos_a/bsd/Kconfig"
endmenu endmenu
######################### config options of framework ##################
#source "../../frameworks/m2mcomm/Kconfig"
######################## config options of filesystem ################## ######################## config options of filesystem ##################
menu "FileSystem" menu "FileSystem"
source "fs/Kconfig" source "../../kernel/liteos_a/fs/vfs/Kconfig"
source "../../kernel/liteos_a/fs/fat/Kconfig"
source "../../kernel/liteos_a/fs/ramfs/Kconfig"
source "../../kernel/liteos_a/fs/nfs/Kconfig"
source "../../kernel/liteos_a/fs/proc/Kconfig"
source "../../kernel/liteos_a/fs/jffs2/Kconfig"
source "../../kernel/liteos_a/fs/zpfs/Kconfig"
config ENABLE_READ_BUFFER
bool "Enable read buffer Option"
default n
help
Answer Y to add enable read buffer Option.
endmenu endmenu
######################## config options of net ############################ ######################## config options of net ############################
source "net/Kconfig" source "../../kernel/liteos_a/net/Kconfig"
######################## config options of debug ######################## ######################## config options of debug ########################
menu "Debug" menu "Debug"
config GDB config COMPILE_DEBUG
bool "Enable gdb functions" bool "Enable GCC -g Option"
default n default n
help help
Answer Y to enable gdb functions. Answer Y to add -g option in gcc command. But the LiteOS size will be much larger.
config PLATFORM_ADAPT config PLATFORM_ADAPT
bool "Enable Os_adapt" bool "Enable Os_adapt"
@ -137,7 +121,6 @@ config PLATFORM_ADAPT
config ENABLE_OOM_LOOP_TASK config ENABLE_OOM_LOOP_TASK
bool "Enable Oom loop task" bool "Enable Oom loop task"
default n default n
depends on KERNEL_VM
help help
Answer Y to enable oom loop kthread to check system out of memory. Answer Y to enable oom loop kthread to check system out of memory.
@ -163,10 +146,8 @@ config ENABLE_MAGICKEY
config THUMB config THUMB
bool "Enable Thumb" bool "Enable Thumb"
default n default n
depends on ARCH_ARM
help help
Answer Y to build thumb version. This will make LiteOS smaller. Answer Y to build thumb version. This will make LiteOS smaller.
config PLATFORM_DVFS config PLATFORM_DVFS
bool "Enable Dvfs" bool "Enable Dvfs"
default n default n
@ -175,21 +156,15 @@ config PLATFORM_DVFS
Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for
low power consumption. low power consumption.
config SAVE_EXCINFO
bool "Enable Saving Exception Information"
default n
help
Answer Y to enable LiteOS support saving exception information to storage medium.
config DEBUG_VERSION config DEBUG_VERSION
bool "Enable a Debug Version" bool "Enable a Debug Version"
default n default n
help help
If you do not select this option that means you enable a release version for LiteOS. If you do not select this option that means you enable a release version for LiteOS.
It also means you do not want to use debug modules, like shell,telnet,tftp,nfs and It also means you do not want to use debug modules, like shell,telnet,tftp,
memory check, etc. ,nfs,ramfs proc and memory check.
If you select this option that means you enable a debug version for LiteOS. If you select this option that means you enable a debug version for LiteOS.
That means you want an opposite behaviour compared to release version. That means you want a opposite behaviour compared to release version.
config DEBUG_KERNEL config DEBUG_KERNEL
bool "Enable Debug LiteOS Kernel Resource" bool "Enable Debug LiteOS Kernel Resource"
@ -198,7 +173,7 @@ config DEBUG_KERNEL
help help
If you select this option that means you enable debugging kernel resource. If you select this option that means you enable debugging kernel resource.
It also means you want to get queue, mutex, semaphore, memory debug information. It also means you want to get queue, mutex, semaphore, memory debug information.
That means you want an opposite behaviour compared to release version. That means you want a opposite behaviour compared to release version.
config DEBUG_QUEUE config DEBUG_QUEUE
bool "Enable Queue Debugging" bool "Enable Queue Debugging"
@ -221,26 +196,29 @@ config DEBUG_SEMAPHORE
help help
Answer Y to enable debug semaphore. Answer Y to enable debug semaphore.
source "shell/Kconfig" source "../../kernel/liteos_a/shell/Kconfig"
config NET_LWIP_SACK_TFTP config NET_LWIP_SACK_TFTP
bool "Enable Tftp" bool "Enable Tftp"
default y default y
depends on SHELL && NET_LWIP_SACK && DEBUG_VERSION depends on SHELL && NET_LWIP_SACK && DEBUG_VERSION
help help
Answer Y to enable LiteOS support tftp cmd and tftp tool. Answer Y to enable LiteOS support tftp cmd and tftp tool.
source "net/telnet/Kconfig" source "../../kernel/liteos_a/net/telnet/Kconfig"
config EXC_INTERACTION
bool "Enable exc interaction"
default n
depends on SHELL
help
Answer Y to enable exception interaction for LiteOS, when the system enter exception, user can also interact with system by shell
command like readreg, writereg,task,hwi.
config SCHED_DEBUG config SCHED_DEBUG
bool "Enable sched debug Feature" bool "Enable sched debug Feature"
default n default n
depends on DEBUG_VERSION depends on DEBUG_VERSION
help help
If you wish to build LiteOS with support for sched debug. If you wish to build LiteOS with support for sched debug.
config SCHED_EDF_DEBUG
bool "Enable sched EDF debug Feature"
default n
depends on SCHED_DEBUG
help
If you wish to build LiteOS with support for sched debug.
config USER_INIT_DEBUG config USER_INIT_DEBUG
bool "Enable user init Debug" bool "Enable user init Debug"
default n default n
@ -270,7 +248,7 @@ config MEM_LEAKCHECK
default n default n
depends on DEBUG_VERSION && MEM_DEBUG depends on DEBUG_VERSION && MEM_DEBUG
help help
Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the information of mem node. Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the infomations of mem node.
config BASE_MEM_NODE_INTEGRITY_CHECK config BASE_MEM_NODE_INTEGRITY_CHECK
bool "Enable integrity check or not " bool "Enable integrity check or not "
default n default n
@ -287,22 +265,36 @@ config VM_OVERLAP_CHECK
help help
Answer Y to enable vm overlap check. Answer Y to enable vm overlap check.
config NULL_ADDRESS_PROTECT
bool "Enable NULL Address protect"
default n
depends on (PLATFORM_HI3518EV200 || PLATFORM_HI3516CV300 || PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 || PLATFORM_QEMU_ARM_VIRT_CA7) && DEBUG_VERSION
help
Answer Y to set mem address 0~1M prohibit to access, read or write will trigger exception.
endmenu endmenu
######################## config options os drivers ######################## ######################## config options os drivers ########################
menu "Driver" menu "Driver"
source "drivers/Kconfig" config DRIVERS
bool "Enable Driver"
default y
help
Answer Y to enable LiteOS support driver.
source "../../kernel/liteos_a/bsd/dev/usb/Kconfig"
source "../../drivers/adapter/khdf/liteos/Kconfig"
source "drivers/char/mem/Kconfig"
source "drivers/char/random/Kconfig"
source "../../drivers/liteos/tzdriver/Kconfig"
source "drivers/char/video/Kconfig"
source "../../drivers/liteos/hievent/Kconfig"
endmenu endmenu
######################## config options os security #######################
menu "Security" menu "Security"
source "security/Kconfig" source "../../kernel/liteos_a/security/Kconfig"
endmenu
menu "Test"
config ENABLE_KERNEL_TEST
bool "Enable Kernel Test"
default n
endmenu endmenu
menu "Stack Smashing Protector (SSP) Compiler Feature" menu "Stack Smashing Protector (SSP) Compiler Feature"

280
Makefile Normal file → Executable file
View File

@ -27,51 +27,45 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LITEOSTOPDIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) LITEOSTOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
export OS=$(shell uname -s)
ifneq ($(OS), Linux)
LITEOSTOPDIR := $(shell dirname $(subst \,/,$(LITEOSTOPDIR))/./)
endif
LITEOSTHIRDPARTY := $(LITEOSTOPDIR)/../../third_party
export LITEOSTOPDIR export LITEOSTOPDIR
export LITEOSTHIRDPARTY
RM = -rm -rf
MAKE = make
__LIBS = libs
APPS = apps APPS = apps
ROOTFSDIR = rootfsdir
ROOTFS = rootfs ROOTFS = rootfs
LITEOS_TARGET = liteos LITEOS_TARGET = liteos
LITEOS_LIBS_TARGET = libs LITEOS_LIBS_TARGET = libs_target
KCONFIG_CMDS := $(notdir $(wildcard $(dir $(shell which menuconfig))*config)) LITEOS_MENUCONFIG_H = $(LITEOSTOPDIR)/include/generated/autoconf.h
LITEOS_PLATFORM_BASE = $(LITEOSTOPDIR)/platform
LITEOS_PLATFORM_MENUCONFIG_H = $(LITEOS_PLATFORM_BASE)/include/menuconfig.h
ohos_kernel ?= liteos_a
$(foreach line,$(shell hb env | sed 's/\[OHOS INFO\]/ohos/g;s/ /_/g;s/:_/=/g' || true),$(eval $(line)))
ifneq ($(ohos_kernel),liteos_a)
$(error The selected product ($(ohos_product)) is not a liteos_a kernel type product)
endif
ifeq ($(PRODUCT_PATH),)
PRODUCT_PATH:=$(ohos_product_path)
endif
ifeq ($(DEVICE_PATH),)
DEVICE_PATH:=$(ohos_device_path)
endif
ifeq ($(TEE:1=y),y)
tee = _tee
endif
ifeq ($(RELEASE:1=y),y)
CONFIG ?= $(PRODUCT_PATH)/kernel_configs/release$(tee).config
else
CONFIG ?= $(PRODUCT_PATH)/kernel_configs/debug$(tee).config
endif
KCONFIG_CONFIG ?= $(CONFIG)
SYSROOT_PATH ?= $(OUT)/sysroot
# export subdir Makefile related environment variables
export SYSROOT_PATH
export PRODUCT_PATH
export DEVICE_PATH
# export kconfig related environment variables
export CONFIG_=LOSCFG_ export CONFIG_=LOSCFG_
export srctree=$(LITEOSTOPDIR) MENUCONFIG_PATH = $(LITEOSTOPDIR)/tools/menuconfig
KCONFIG_FILE_PATH = $(LITEOSTOPDIR)/Kconfig
include $(LITEOSTOPDIR)/config.mk ifeq ($(OS), Linux)
MENUCONFIG_MCONF := $(MENUCONFIG_PATH)/mconf
MENUCONFIG_CONF := $(MENUCONFIG_PATH)/conf
else
MENUCONFIG_MCONF := $(MENUCONFIG_PATH)/kconfig-mconf.exe
MENUCONFIG_CONF := $(MENUCONFIG_PATH)/kconfig-conf.exe
endif
$(shell env CONFIG_=$(CONFIG_) $(MENUCONFIG_CONF) -s --olddefconfig $(KCONFIG_FILE_PATH))
-include $(LITEOSTOPDIR)/tools/build/config.mk
ifeq ($(LOSCFG_STORAGE_SPINOR), y) ifeq ($(LOSCFG_STORAGE_SPINOR), y)
FSTYPE = jffs2 FSTYPE = jffs2
@ -82,117 +76,155 @@ endif
ifeq ($(LOSCFG_STORAGE_SPINAND), y) ifeq ($(LOSCFG_STORAGE_SPINAND), y)
FSTYPE = yaffs2 FSTYPE = yaffs2
endif endif
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
FSTYPE = jffs2
endif
ROOTFS_DIR = $(OUT)/rootfs ROOTFS_DIR = $(OUT)/rootfs
ROOTFS_ZIP = $(OUT)/rootfs.zip ROOTFS_ZIP = $(OUT)/rootfs.zip
VERSION =
define HELP = all: $(OUT) $(BUILD) $(LITEOS_TARGET) $(APPS)
Usage: make [TARGET]... [PARAMETER=VALUE]... lib: $(OUT) $(BUILD) $(LITEOS_LIBS_TARGET)
Targets:
help: display this help and exit
clean: clean compiled objects
cleanall: clean all build outputs
all: make liteos kernel image and rootfs image (Default target)
$(APPS): build all apps
$(ROOTFS): make an original rootfs image
$(LITEOS_LIBS_TARGET): compile all kernel modules (libraries)
$(LITEOS_TARGET): make liteos kernel image
update_config: update product kernel config (use menuconfig)
xxconfig: invoke xxconfig command of kconfiglib (xxconfig is one of $(KCONFIG_CMDS))
Parameters:
FSTYPE: value should be one of (jffs2 vfat yaffs2)
TEE: boolean value(1 or y for true), enable tee
RELEASE: boolean value(1 or y for true), build release version
CONFIG: kernel config file to be use
args: arguments for xxconfig command
endef
export HELP
all: $(LITEOS_TARGET) $(ROOTFS)
help: help:
$(HIDE)echo "$$HELP" $(HIDE)echo "-------------------------------------------------------"
$(HIDE)echo "1.====make help: get help infomation of make"
$(HIDE)echo "2.====make: make a debug version based the .config"
$(HIDE)echo "3.====make debug: make a debug version based the .config"
$(HIDE)echo "4.====make release: make a release version for all platform"
$(HIDE)echo "5.====make release PLATFORM=xxx: make a release version only for platform xxx"
$(HIDE)echo "6.====make rootfsdir: make a original rootfs dir"
$(HIDE)echo "7.====make rootfs FSTYPE=***: make a original rootfs img"
$(HIDE)echo "8.====make test: make the testsuits_app and put it into the rootfs dir"
$(HIDE)echo "9.====make test_apps FSTYPE=***: make a rootfs img with the testsuits_app in it"
$(HIDE)echo "xxx should be one of (hi3516cv300 hi3516ev200 hi3556av100/cortex-a53_aarch32 hi3559av100/cortex-a53_aarch64)"
$(HIDE)echo "*** should be one of (jffs2)"
$(HIDE)echo "-------------------------------------------------------"
sysroot: debug:
$(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH)) $(HIDE)echo "=============== make a debug version ==============="
ifeq ($(origin SYSROOT_PATH),file) $(HIDE) $(MAKE) all
$(HIDE)mkdir -p $(SYSROOT_PATH)/build && cd $(SYSROOT_PATH)/build && \
ln -snf $(LITEOSTOPDIR)/../../third_party/musl/scripts/build_lite/Makefile && \ release:
$(MAKE) TARGETS=liteos_a_user \ ifneq ($(PLATFORM),)
ARCH=$(ARCH) \ $(HIDE)echo "=============== make a release version for platform $(PLATFORM) ==============="
TARGET=$(LOSCFG_LLVM_TARGET) \ $(HIDE)$(SCRIPTS_PATH)/mklibversion.sh $(PLATFORM)
ARCH_CFLAGS="$(LITEOS_CORE_COPTS) -w" \ else
TOPDIR="$(LITEOSTOPDIR)/../.." \ $(HIDE)echo "================make a release version for all platform ==============="
SYSROOTDIR="$(SYSROOT_PATH)" \ $(HIDE)$(SCRIPTS_PATH)/mklibversion.sh
$(if $(LOSCFG_COMPILER_CLANG_LLVM),CLANG="$(LITEOS_COMPILER_PATH)clang",GCC="$(CC)") \
BUILD_DEBUG=$(if $(patsubst y,,$(or $(RELEASE:1=y),n)),true,false)
endif endif
$(filter-out menuconfig,$(KCONFIG_CMDS)): ##### make dynload #####
$(HIDE)$@ $(args) -include $(LITEOS_MK_PATH)/dynload.mk
$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG) #-----need move when make version-----#
$(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H) ##### make lib #####
$(__LIBS): $(OUT) $(CXX_INCLUDE)
update_config menuconfig: $(OUT): $(LITEOS_MENUCONFIG_H)
$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)" $(HIDE)mkdir -p $(OUT)/lib
$(HIDE)$(CC) -I$(LITEOSTOPDIR)/kernel/base/include -I$(LITEOSTOPDIR)/../../$(LOSCFG_BOARD_CONFIG_PATH) \
-I$(LITEOS_PLATFORM_BASE)/include -E $(LITEOS_PLATFORM_BASE)/board.ld.S \
-o $(LITEOS_PLATFORM_BASE)/board.ld -P
$(LITEOS_LIBS_TARGET): sysroot $(BUILD):
$(HIDE)for dir in $(LIB_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done $(HIDE)mkdir -p $(BUILD)
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET) $(LITEOS_LIBS_TARGET): $(__LIBS)
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).map $(HIDE)for dir in $(LIB_SUBDIRS); \
#$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).objsize do $(MAKE) -C $$dir all || exit 1; \
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).bin done
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).sym.sorted $(HIDE)echo "=============== make lib done ==============="
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).asm
#$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).size
$(OUT)/$(LITEOS_TARGET): $(LITEOS_LIBS_TARGET) ##### make menuconfig #####
$(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) -Map=$@.map -o $@ --start-group $(LITEOS_LIBDEP) --end-group menuconfig:$(MENUCONFIG_MCONF)
$(OUT)/$(LITEOS_TARGET).map: $(OUT)/$(LITEOS_TARGET) $< $(KCONFIG_FILE_PATH)
$(OUT)/$(LITEOS_TARGET).objsize: $(LITEOS_LIBS_TARGET)
$(SIZE) -t --common $(OUT)/lib/*.a >$@
$(OUT)/$(LITEOS_TARGET).bin: $(OUT)/$(LITEOS_TARGET)
$(OBJCOPY) -O binary $< $@
$(OUT)/$(LITEOS_TARGET).sym.sorted: $(OUT)/$(LITEOS_TARGET)
$(OBJDUMP) -t $< |sort >$@
$(OUT)/$(LITEOS_TARGET).asm: $(OUT)/$(LITEOS_TARGET)
$(OBJDUMP) -d $< >$@
$(OUT)/$(LITEOS_TARGET).size: $(OUT)/$(LITEOS_TARGET)
$(NM) -S --size-sort $< >$@
$(APPS): sysroot genconfig:$(MENUCONFIG_CONF)
$(HIDE)mkdir -p include/config include/generated
$< --olddefconfig $(KCONFIG_FILE_PATH)
$< --silentoldconfig $(KCONFIG_FILE_PATH)
-mv -f $(LITEOS_MENUCONFIG_H) $(LITEOS_PLATFORM_MENUCONFIG_H)
##### menuconfig end #######
$(LITEOS_MENUCONFIG_H):
ifneq ($(LITEOS_PLATFORM_MENUCONFIG_H), $(wildcard $(LITEOS_PLATFORM_MENUCONFIG_H)))
$(HIDE)$(MAKE) genconfig
endif
$(LITEOS_TARGET): $(__LIBS)
$(HIDE)touch $(LOSCFG_ENTRY_SRC)
$(HIDE)for dir in $(LITEOS_SUBDIRS); \
do $(MAKE) -C $$dir all || exit 1; \
done
$(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) $(LITEOS_DYNLDFLAGS) -Map=$(OUT)/$@.map -o $(OUT)/$@ --start-group $(LITEOS_LIBDEP) --end-group
# $(SIZE) -t --common $(OUT)/lib/*.a >$(OUT)/$@.objsize
$(OBJCOPY) -O binary $(OUT)/$@ $(LITEOS_TARGET_DIR)/$@.bin
$(OBJDUMP) -t $(OUT)/$@ |sort >$(OUT)/$@.sym.sorted
$(OBJDUMP) -d $(OUT)/$@ >$(OUT)/$@.asm
# $(NM) -S --size-sort $(OUT)/$@ >$(OUT)/$@.size
$(APPS): $(LITEOS_TARGET)
$(HIDE)$(MAKE) -C apps all $(HIDE)$(MAKE) -C apps all
$(ROOTFS): $(APPS) prepare:
$(HIDE)mkdir -p $(OUT)/musl $(HIDE)mkdir -p $(OUT)/musl
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
$(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libc.so) $(OUT)/musl $(HIDE)cp -f $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/usr/lib/$(LLVM_TARGET)/a7_softfp_neon-vfpv4/libc.so $(OUT)/musl
$(HIDE)cp -fp $$($(GPP) $(LITEOS_CXXFLAGS) -print-file-name=libc++.so) $(OUT)/musl $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/lib/$(LLVM_TARGET)/c++/a7_softfp_neon-vfpv4/libc++.so $(OUT)/musl
else else
$(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libc.so) $(OUT)/musl $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/target/usr/lib/libc.so $(OUT)/musl
$(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libgcc_s.so.1) $(OUT)/musl $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libstdc++.so.6 $(OUT)/musl
$(HIDE)cp -fp $$($(GPP) $(LITEOS_CXXFLAGS) -print-file-name=libstdc++.so.6) $(OUT)/musl $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libgcc_s.so.1 $(OUT)/musl
$(STRIP) $(OUT)/musl/*
endif endif
$(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/rootfsdir.sh $(OUT) $(ROOTFS_DIR)
$(HIDE)shopt -s nullglob && $(STRIP) $(ROOTFS_DIR)/bin/* $(ROOTFS_DIR)/lib/* $(ROOTFSDIR): prepare $(APPS)
$(HIDE)$(MAKE) clean -C apps
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT)/bin $(OUT)/musl $(ROOTFS_DIR)
ifneq ($(VERSION),) ifneq ($(VERSION),)
$(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR) $(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR)
endif endif
$(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE)
$(ROOTFS): $(ROOTFSDIR)
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE)
$(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS) $(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS)
ifneq ($(OUT), $(LITEOS_TARGET_DIR))
rm -rf $(LITEOS_TARGET_DIR)rootfs
$(HIDE)mv $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)rootfs
endif
clean: clean:
$(HIDE)if [ -d $(SYSROOT_PATH)/build ]; then $(MAKE) -C $(SYSROOT_PATH)/build clean; fi $(HIDE)for dir in $(LITEOS_SUBDIRS); \
$(HIDE)for dir in $(LIB_SUBDIRS) apps; do $(MAKE) -C $$dir clean || exit 1; done do $(MAKE) -C $$dir clean|| exit 1; \
$(HIDE)$(RM) $(LITEOS_MENUCONFIG_H) done
$(HIDE)echo "clean $(LOSCFG_PLATFORM) finish" $(HIDE)$(MAKE) -C apps clean
$(HIDE)$(RM) $(__OBJS) $(LITEOS_TARGET) $(BUILD) $(LITEOS_MENUCONFIG_H) *.bak *~
$(HIDE)$(RM) $(LITEOS_PLATFORM_MENUCONFIG_H)
$(HIDE)$(RM) include
$(HIDE)$(MAKE) cleanrootfs
$(HIDE)echo "clean $(LITEOS_PLATFORM) finish"
cleanall: clean cleanall:
$(HIDE)$(RM) $(LITEOSTOPDIR)/out $(LITEOS_CONFIG_FILE) $(HIDE)$(RM) $(LITEOSTOPDIR)/out
$(HIDE)echo "clean all done" $(HIDE)find $(LITEOS_PLATFORM_BASE)/ -name board.ld -exec rm -rf {} \;
$(HIDE)cd sample/sample_osdrv;make clean;cd ../..;
$(HIDE)echo "clean all"
.PHONY: all clean cleanall sysroot help update_config cleanrootfs:
.PHONY: $(LITEOS_TARGET) $(ROOTFS) $(APPS) $(KCONFIG_CMDS) $(LITEOS_LIBS_TARGET) $(KCONFIG_CONFIG) $(HIDE)$(RM) $(OUT)/rootfs
$(HIDE)$(RM) $(OUT)/rootfs.zip
$(HIDE)$(RM) $(OUT)/rootfs.img
update_all_config:
$(HIDE)shopt -s globstar && for f in tools/build/config/**/*.config ; \
do \
echo updating $$f; \
test -f $$f && cp $$f .config && $(MENUCONFIG_CONF) -s --olddefconfig $(KCONFIG_FILE_PATH) && $(MENUCONFIG_CONF) --savedefconfig $$f $(KCONFIG_FILE_PATH); \
done
%.config:
$(HIDE)test -f tools/build/config/$@ && cp tools/build/config/$@ .config && $(MENUCONFIG_MCONF) $(KCONFIG_FILE_PATH) && $(MENUCONFIG_CONF) --savedefconfig tools/build/config/$@ $(KCONFIG_FILE_PATH)
.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help update_all_config

87
OAT.xml
View File

@ -1,87 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
This is the configuration file template for OpenHarmony OSS Audit Tool. Please copy it to your project root dir and modify it by referring to OpenHarmony/tools_oat/README.
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
<policyitem type="copyright" name="Huawei Technologies Co., Ltd. All rights reserved." path=".*" desc="original liteos copyright"/>
<policyitem type="copyright" name="Huawei Device Co., Ltd. All rights reserved." path=".*" desc="original liteos copyright"/>
<policyitem type="license" name="BSD-3-Clause" path=".*" desc="Liteos kernel use bsd3 license"/>
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="文件属于FreeBSD仓库软连接本仓库屏蔽告警在FreeBSD仓库进行处理">
<filteritem type="filepath" name="bsd/.*" desc="文件属于FreeBSD仓库软连接本仓库屏蔽告警在FreeBSD仓库进行处理"/>
<filteritem type="filepath" name="kernel/extended" desc="文件属于Nuttx仓库软连接本仓库屏蔽告警在Nuttx仓库进行处理"/>
<filteritem type="filepath" name="fs/include/fs" desc="文件属于Nuttx仓库软连接本仓库屏蔽告警在Nuttx仓库进行处理"/>
</filefilter>
<filefilter name="defaultFilter" desc="Files not to check">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for license header policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
<filteritem type="filepath" name="figures/architecture-of-the-openharmony-liteos-cortex-a-kernel.png" desc="architecture-of-the-openharmony-liteos-cortex-a-kernel"/>
<filteritem type="filepath" name="figures/OpenHarmony-LiteOS-A内核架构图.png" desc="LiteOS-A内核架构图"/>
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
</filefilter>
</filefilterlist>
<licensematcherlist>
<!--licensematcher name="uvwxyz License" desc="If the scanning result is InvalidLicense, you can define matching rules here. Note that quotation marks must be escaped.">
<licensetext name="
uvwxyz license textA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
" desc=""/>
<licensetext name="
uvwxyz license textB xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
" desc=""/>
</licensematcher-->
</licensematcherlist>
</oatconfig>
</configuration>

View File

@ -7,7 +7,7 @@
- [Preparations](#section1579912573329) - [Preparations](#section1579912573329)
- [Source Code Acquisition](#section11443189655) - [Source Code Acquisition](#section11443189655)
- [Compilation and Building](#section2081013992812) - [Compilation and Building](#section2081013992812)
- [Contribution](#section1371123476304)
- [Repositories Involved](#section1371113476307) - [Repositories Involved](#section1371113476307)
## Introduction<a name="section11660541593"></a> ## Introduction<a name="section11660541593"></a>
@ -62,38 +62,31 @@ The OpenHarmony LiteOS Cortex-A is a new-generation kernel developed based on th
## Constraints<a name="section119744591305"></a> ## Constraints<a name="section119744591305"></a>
- Programming languages: C and C++ - Programming languages: C and C++
- Applicable development boards: Hi3516D V300 - Applicable development boards: Hi3518E V300 and Hi3516D V300
- Hi3516D V300 uses the FAT file system by default. - Hi3518E V300 uses the JFFS2 file system by default, and Hi3516D V300 uses the FAT file system by default.
## Usage<a name="section741617511812"></a> ## Usage<a name="section741617511812"></a>
OpenHarmony LiteOS Cortex-A supports the [Hi3516D V300](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-appendix-hi3516.md). You can develop and run your applications based on this development board. OpenHarmony LiteOS Cortex-A supports the [Hi3518E V300](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/introduction-to-the-hi3518-development-board.md) and [Hi3516D V300](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/introduction-to-the-hi3516-development-board.md). You can develop and run your applications based on both development boards.
### Preparations<a name="section1579912573329"></a> ### Preparations<a name="section1579912573329"></a>
You need to set up the compilation environment on Ubuntu. You need to set up the compilation environment on Linux.
- [Setting Up Ubuntu Development Environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/Readme-EN.md) - For Hi3518E V300, see [Setting Up the Hi3518 Development Environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/setting-up-the-hi3518-development-environment.md).
- For Hi3516D V300, see [Setting Up the Hi3516 Development Environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/setting-up-the-hi3516-development-environment.md).
### Source Code Acquisition<a name="section11443189655"></a> ### Source Code Acquisition<a name="section11443189655"></a>
Download and decompress a set of source code on a Ubuntu server to acquire the [source code](https://gitee.com/openharmony/docs/blob/master/en/device-dev/get-code/sourcecode-acquire.md). Download and decompress a set of source code on a Linux server to acquire the [source code](https://repo.huaweicloud.com/harmonyos/os/1.0.1/code-1.0.1.tar.gz). For more acquisition methods, see [Source Code Acquisition](https://gitee.com/openharmony/docs/blob/master/en/device-dev/get-code/source-code-acquisition.md).
### Compilation and Building<a name="section2081013992812"></a> ### Compilation and Building<a name="section2081013992812"></a>
For details about how to develop the first application, see: [Developing the First Example Program Running on Hi3516](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-pkg-3516-helloworld.md) For details about how to develop the first application, see:
For compilation, please refer to the [compilation instructions](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-pkg-3516-build.md). - [Developing the First Example Program Running on Hi3518](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/developing-the-first-example-program-running-on-hi3518.md)
## Contribution<a name="section1371123476304"></a> - [Developing the First Example Program Running on Hi3516](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/developing-the-first-example-program-running-on-hi3516.md)
[How to involve](https://gitee.com/openharmony/docs/blob/HEAD/en/contribute/contribution-guide.md)
[Commit message spec](https://gitee.com/openharmony/kernel_liteos_a/wikis/Commit%20message%20%E8%A7%84%E8%8C%83)
[C&C++ Secure Coding Guide](https://gitee.com/openharmony/docs/blob/master/en/contribute/OpenHarmony-c-cpp-secure-coding-guide.md)
[LiteOS-A Kernel Coding Style Guide](https://gitee.com/openharmony/kernel_liteos_a/wikis/LiteOS-A%20%E5%86%85%E6%A0%B8%E7%BC%96%E7%A0%81%E8%A7%84%E8%8C%83%E6%8C%87%E5%8D%97)
## Repositories Involved<a name="section1371113476307"></a> ## Repositories Involved<a name="section1371113476307"></a>
@ -101,5 +94,5 @@ For compilation, please refer to the [compilation instructions](https://gitee.co
[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README.md) [drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README.md)
[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README.md) **kernel\_liteos\_a**

View File

@ -1,104 +0,0 @@
# LiteOS-A內核<a name="ZH-CN_TOPIC_0000001096612501"></a>
- [簡介](#section11660541593)
- [目錄](#section161941989596)
- [約束](#section119744591305)
- [使用說明](#section741617511812)
- [準備](#section1579912573329)
- [獲取源碼](#section11443189655)
- [編譯構建](#section2081013992812)
- [貢獻](#section1371123476304)
- [相關倉](#section1371113476307)
## 簡介<a name="section11660541593"></a>
OpenHarmony LiteOS-A內核是基於Huawei LiteOS內核演進發展的新一代內核Huawei LiteOS是面向IoT領域構建的輕量級物聯網操作系統。在IoT產業高速發展的潮流中OpenHarmony LiteOS-A內核能夠帶給用戶小體積、低功耗、高性能的體驗以及統一開放的生態系統能力新增了豐富的內核機制、更加全面的POSIX標準接口以及統一驅動框架**HDF**OpenHarmony Driver Foundation為設備廠商提供了更統一的接入方式為OpenHarmony的應用開發者提供了更友好的開發體驗。圖1為OpenHarmony LiteOS-A內核架構圖
**圖 1** OpenHarmony LiteOS-A內核架構圖<a name="fig27311582210"></a>
![](figures/OpenHarmony-LiteOS-A内核架构图.png "OpenHarmony-LiteOS-A內核架構圖")
## 目錄<a name="section161941989596"></a>
```
/kernel/liteos_a
├── apps # 用戶態的init和shell應用程序
├── arch # 體系架構的目錄如arm等
│ └── arm # arm架構代碼
├── bsd # freebsd相關的驅動和適配層模塊代碼引入例如USB等
├── compat # 內核接口兼容性目錄
│ └── posix # posix相關接口
├── drivers # 內核驅動
│ └── char # 字符設備
│ ├── mem # 訪問物理IO設備驅動
│ ├── quickstart # 系統快速啟動接口目錄
│ ├── random # 隨機數設備驅動
│ └── video # framebuffer驅動框架
├── fs # 文件系統模塊主要來源於NuttX開源項目
│ ├── fat # fat文件系統
│ ├── jffs2 # jffs2文件系統
│ ├── include # 對外暴露頭文件存放目錄
│ ├── nfs # nfs文件系統
│ ├── proc # proc文件系統
│ ├── ramfs # ramfs文件系統
│ └── vfs # vfs層
├── kernel # 進程、內存、IPC等模塊
│ ├── base # 基礎內核,包括調度、內存等模塊
│ ├── common # 內核通用組件
│ ├── extended # 擴展內核包括動態加載、vdso、liteipc等模塊
│ ├── include # 對外暴露頭文件存放目錄
│ └── user # 加載init進程
├── lib # 內核的lib庫
├── net # 網絡模塊主要來源於lwip開源項目
├── platform # 支持不同的芯片平台代碼如Hi3516DV300等
│ ├── hw # 時鐘與中斷相關邏輯代碼
│ ├── include # 對外暴露頭文件存放目錄
│ └── uart # 串口相關邏輯代碼
├── security # 安全特性相關的代碼包括進程權限管理和虛擬id映射管理
├── syscall # 系統調用
└── tools # 構建工具及相關配置和代碼
```
## 約束<a name="section119744591305"></a>
- 開發語言C/C++
- 適用於Hi3516DV300單板
- Hi3516DV300默認使用FAT文件系統。
## 使用說明<a name="section741617511812"></a>
OpenHarmony LiteOS-A內核支持[Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-appendix-hi3516.md)單板,開發者可基於此單板開發運行自己的應用程序。
### 準備<a name="section1579912573329"></a>
開發者需要在Ubuntu上搭建編譯環境
- [編譯環境凖備](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Readme-CN.md);
### 獲取源碼<a name="section11443189655"></a>
在Ubuntu服務器上下載並解壓一套源代碼源碼獲取方式參考[源碼獲取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md)。
### 編譯構建<a name="section2081013992812"></a>
開發者開發第一個應用程序可參考:[helloworld for Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-pkg-3516-helloworld.md)。
編譯可以參考:[編譯指導](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-pkg-3516-build.md)
## 貢獻<a name="section1371123476304"></a>
[如何貢獻](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/%E5%8F%82%E4%B8%8E%E8%B4%A1%E7%8C%AE.md)
[Commit message規範](https://gitee.com/openharmony/kernel_liteos_a/wikis/Commit%20message%20%E8%A7%84%E8%8C%83)
[OpenHarmony C&C++ 安全編程指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/contribute/OpenHarmony-c-cpp-secure-coding-guide.md)
[LiteOS-A 內核編碼規範指南](https://gitee.com/openharmony/kernel_liteos_a/wikis/LiteOS-A%20%E5%86%85%E6%A0%B8%E7%BC%96%E7%A0%81%E8%A7%84%E8%8C%83%E6%8C%87%E5%8D%97)
## 相關倉<a name="section1371113476307"></a>
[內核子系統](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README_zh.md)
[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README_zh-HK.md)

View File

@ -7,7 +7,7 @@
- [准备](#section1579912573329) - [准备](#section1579912573329)
- [获取源码](#section11443189655) - [获取源码](#section11443189655)
- [编译构建](#section2081013992812) - [编译构建](#section2081013992812)
- [贡献](#section1371123476304)
- [相关仓](#section1371113476307) - [相关仓](#section1371113476307)
## 简介<a name="section11660541593"></a> ## 简介<a name="section11660541593"></a>
@ -33,7 +33,6 @@ OpenHarmony LiteOS-A内核是基于Huawei LiteOS内核演进发展的新一代
│ ├── quickstart # 系统快速启动接口目录 │ ├── quickstart # 系统快速启动接口目录
│ ├── random # 随机数设备驱动 │ ├── random # 随机数设备驱动
│ └── video # framebuffer驱动框架 │ └── video # framebuffer驱动框架
├── figures # 内核架构图
├── fs # 文件系统模块主要来源于NuttX开源项目 ├── fs # 文件系统模块主要来源于NuttX开源项目
│ ├── fat # fat文件系统 │ ├── fat # fat文件系统
│ ├── jffs2 # jffs2文件系统 │ ├── jffs2 # jffs2文件系统
@ -54,50 +53,40 @@ OpenHarmony LiteOS-A内核是基于Huawei LiteOS内核演进发展的新一代
│ ├── hw # 时钟与中断相关逻辑代码 │ ├── hw # 时钟与中断相关逻辑代码
│ ├── include # 对外暴露头文件存放目录 │ ├── include # 对外暴露头文件存放目录
│ └── uart # 串口相关逻辑代码 │ └── uart # 串口相关逻辑代码
├── platform # 支持不同的芯片平台代码如Hi3516DV300等
├── security # 安全特性相关的代码包括进程权限管理和虚拟id映射管理 ├── security # 安全特性相关的代码包括进程权限管理和虚拟id映射管理
├── shell # 接收用户输入的命令,内核去执行
├── syscall # 系统调用 ├── syscall # 系统调用
├── testsuilts # 测试套件
└── tools # 构建工具及相关配置和代码 └── tools # 构建工具及相关配置和代码
``` ```
## 约束<a name="section119744591305"></a> ## 约束<a name="section119744591305"></a>
- 开发语言C/C++ - 开发语言C/C++
- 适用于Hi3516DV300单板 - 适用于Hi3518EV300、Hi3516DV300单板
- Hi3516DV300默认使用FAT文件系统。 - Hi3518EV300默认使用jffs2文件系统Hi3516DV300默认使用FAT文件系统。
## 使用说明<a name="section741617511812"></a> ## 使用说明<a name="section741617511812"></a>
OpenHarmony LiteOS-A内核支持[Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-appendix-hi3516.md)单板。开发者可基于此单板开发运行自己的应用程序。 OpenHarmony LiteOS-A内核支持Hi3518EV300[介绍](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3518%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md)、Hi3516DV300[介绍](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E5%BC%80%E5%8F%91%E6%9D%BF%E4%BB%8B%E7%BB%8D.md))单板,开发者可基于两种单板开发运行自己的应用程序。
### 准备<a name="section1579912573329"></a> ### 准备<a name="section1579912573329"></a>
开发者需要在Ubuntu上搭建编译环境: 开发者需要在Linux上搭建编译环境:
- [编译环境准备](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Readme-CN.md); - Hi3518EV300单板参考[环境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83.md)
- Hi3516DV300单板参考[环境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Hi3516%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83.md)。
### 获取源码<a name="section11443189655"></a> ### 获取源码<a name="section11443189655"></a>
Ubuntu服务器源码获取方式参考: [源码获取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md)。 Linux服务器上下载并解压一套源代码获取源码[下载链接](https://repo.huaweicloud.com/harmonyos/os/1.0.1/code-1.0.1.tar.gz))。更多源码获取方式,参考[源码获取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96.md)。
### 编译构建<a name="section2081013992812"></a> ### 编译构建<a name="section2081013992812"></a>
如果这是您的首次应用程序开发,可参考:[helloworld for Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-pkg-3516-helloworld.md)。 开发者开发第一个应用程序可参考:
编译可以参考:[编译指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-pkg-3516-build.md) - [helloworld for Hi3518EV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3518%E7%AC%AC%E4%B8%80%E4%B8%AA%E7%A4%BA%E4%BE%8B%E7%A8%8B%E5%BA%8F.md)
测试参考:[单元测试](testsuites/unittest/tools/README.md) - [helloworld for Hi3516DV300](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/%E5%BC%80%E5%8F%91Hi3516%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%A4%BA%E4%BE%8B.md)。
## 贡献<a name="section1371123476304"></a>
[如何贡献](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/contribute/%E5%8F%82%E4%B8%8E%E8%B4%A1%E7%8C%AE.md)
[Commit message规范](https://gitee.com/openharmony/kernel_liteos_a/wikis/Commit%20message%20%E8%A7%84%E8%8C%83)
[OpenHarmony C&C++ 安全编程指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/contribute/OpenHarmony-c-cpp-secure-coding-guide.md)
[LiteOS-A 内核编码规范指南](https://gitee.com/openharmony/kernel_liteos_a/wikis/LiteOS-A%20%E5%86%85%E6%A0%B8%E7%BC%96%E7%A0%81%E8%A7%84%E8%8C%83%E6%8C%87%E5%8D%97)
## 相关仓<a name="section1371113476307"></a> ## 相关仓<a name="section1371113476307"></a>
@ -105,5 +94,5 @@ OpenHarmony LiteOS-A内核支持[Hi3516DV300](https://gitee.com/openharmony/docs
[drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README_zh.md) [drivers\_liteos](https://gitee.com/openharmony/drivers_liteos/blob/master/README_zh.md)
[kernel\_liteos\_a](https://gitee.com/openharmony/kernel_liteos_a/blob/master/README_zh.md) **kernel\_liteos\_a**

View File

@ -1,62 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//kernel/liteos_a/liteos.gni")
group("apps") {
deps = []
if (defined(LOSCFG_SHELL)) {
deps += [
"mksh",
"shell",
"toybox",
]
}
if (defined(LOSCFG_USER_INIT_DEBUG)) {
deps += [ "init" ]
}
if (defined(LOSCFG_NET_LWIP_SACK_TFTP)) {
deps += [ "tftp" ]
}
if (defined(LOSCFG_DRIVERS_TRACE)) {
deps += [ "trace" ]
}
if (defined(LOSCFG_DRIVERS_PERF)) {
deps += [ "perf" ]
}
if (defined(LOSCFG_KERNEL_LMS)) {
deps += [ "lms:sample_usr_lms" ]
}
}

25
apps/Makefile Normal file → Executable file
View File

@ -27,14 +27,23 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
APPSTOPDIR := $(shell pwd) include ../.config
LITEOSTOPDIR ?= $(APPSTOPDIR)/.. include ./module.mk
export LITEOSTOPDIR
export APPSTOPDIR
include $(APPSTOPDIR)/config.mk HIDE := @
APPS := app
all clean: all: $(APPS)
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir $@ || exit 1; done
.PHONY: all clean # Make
$(APPS):
ifneq ($(APP_SUBDIRS), )
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir || exit 1; done
endif
clean:
ifneq ($(APP_SUBDIRS), )
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir clean; done
endif
.PHONY: all $(APPS) clean

65
apps/config.mk Normal file → Executable file
View File

@ -27,53 +27,34 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# common dir config
include $(LITEOSTOPDIR)/config.mk include $(LITEOSTOPDIR)/config.mk
# output dir config
OBJOUT := $(APPSTOPDIR)/out
APPSOUT := $(OBJOUT)/apps
LIBSOUT := $(OBJOUT)/libs
IMGOUT := $(OUT)
# common flags config # common flags config
BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_XOPEN_SOURCE=700 BASE_OPTS := -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-common -fno-strict-aliasing -D_GNU_SOURCE \
$(LITEOS_SSP) $(LITEOS_CORE_COPTS) $(WARNING_AS_ERROR) $(LLVM_EXTRA_OPTS) $(LITEOS_GCOV_OPTS)
ASFLAGS := CFLAGS := -std=c99 -fno-exceptions $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
CFLAGS := $(LITEOS_COPTS) $(BASE_OPTS) -fPIE CXXFLAGS := -std=c++11 -fexceptions -fpermissive -frtti $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
CXXFLAGS := $(LITEOS_CXXOPTS) $(BASE_OPTS) -fPIE LDCFLAGS := -lc
LDFLAGS := $(LITEOS_CORE_COPTS) -pie -Wl,-z,relro,-z,now -O2 ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
LLVM_SYSROOT := --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
CFLAGS := $(filter-out -fno-pic -fno-builtin -nostdinc -nostdlib,$(CFLAGS)) LDCXXFLGS := -lc++ -lc++abi -lc
CXXFLAGS := $(filter-out -fno-pic -fno-builtin -nostdinc -nostdlib -nostdinc++,$(CXXFLAGS)) else
BASE_OPTS += -Wl,-z,relro,-z,now
LDCXXFLGS := -lstdc++ -lsupc++ -lc
endif
COMMON_INCLUDE := -I $(LITEOSTHIRDPARTY)/bounds_checking_function/include
# alias variable config # alias variable config
HIDE := @ HIDE := @
MAKE := make MAKE := make
RM := rm -rf RM := -rm -rf
CP := cp -rf CP := -cp -rf
MV := mv -f MV := -mv
APP := $(APPSTOPDIR)/app.mk
##build modules config##
APP_SUBDIRS :=
ifeq ($(LOSCFG_SHELL), y)
APP_SUBDIRS += shell
APP_SUBDIRS += mksh
APP_SUBDIRS += toybox
endif
ifeq ($(LOSCFG_KERNEL_LMS), y)
APP_SUBDIRS += lms
endif
ifeq ($(LOSCFG_USER_INIT_DEBUG), y)
APP_SUBDIRS += init
endif
ifeq ($(LOSCFG_NET_LWIP_SACK_TFTP), y)
APP_SUBDIRS += tftp
endif
ifeq ($(LOSCFG_DRIVERS_TRACE), y)
APP_SUBDIRS += trace
endif
ifeq ($(LOSCFG_DRIVERS_PERF), y)
APP_SUBDIRS += perf
endif

36
apps/init/Makefile Normal file → Executable file
View File

@ -27,15 +27,43 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(APPSTOPDIR)/config.mk INIT_DIR := $(dir $(shell pwd))/init/
APP_NAME := $(notdir $(shell pwd)) ifeq ($(APPSTOPDIR), )
APPSTOPDIR := $(shell pwd)/../
LITEOSTOPDIR = $(APPSTOPDIR)/../
endif
include $(INIT_DIR)/../config.mk
APPS_OUT := $(OUT)/bin
LOCAL_SRCS := src/init.c LOCAL_SRCS := src/init.c
LOCAL_OBJ := src/init.o
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-bitwise-op-parentheses -Wnonnull $(LLVM_SYSROOT)
LDCFLAGS += $(LLVM_EXTRA_LD_OPTS) $(LLVM_SYSROOT)
endif
ifeq ($(LOSCFG_QUICK_START), y) ifeq ($(LOSCFG_QUICK_START), y)
LDFLAGS += --static LDCFLAGS += --static
CFLAGS += -DLOSCFG_QUICK_START CFLAGS += -DLOSCFG_QUICK_START
endif endif
include $(APP) INITNAME := init
all: $(INITNAME)
$(LOCAL_OBJ): %.o : %.c
$(HIDE) $(CC) $(CFLAGS) $(LOCAL_FLAGS) -fPIE $(LOCAL_INCLUDE) -c $< -o $@
$(INITNAME):$(LOCAL_OBJ)
$(HIDE) $(CC) -pie -s $(LDPATH) $(BASE_OPTS) -o $(INITNAME) $^ $(LDCFLAGS)
$(HIDE) mkdir -p $(APPS_OUT)
$(HIDE) $(MV) $(INITNAME) $(APPS_OUT)
$(HIDE) $(RM) $(LOCAL_OBJ)
clean:
$(HIDE) $(RM) $(LOCAL_OBJ)
$(HIDE) $(RM) $(INITNAME)
.PHONY: all $(INITNAME) clean

14
apps/init/src/init.c Normal file → Executable file
View File

@ -48,10 +48,8 @@
#endif #endif
int main(int argc, char * const *argv) int main(int argc, char * const *argv)
{ {
(void)argv;
int ret; int ret;
pid_t gid; const char *shellPath = "/bin/shell";
const char *shellPath = "/bin/mksh";
#ifdef LOSCFG_QUICK_START #ifdef LOSCFG_QUICK_START
const char *samplePath = "/dev/shm/sample_quickstart"; const char *samplePath = "/dev/shm/sample_quickstart";
@ -76,16 +74,6 @@ int main(int argc, char * const *argv)
if (ret < 0) { if (ret < 0) {
printf("Failed to fork for shell\n"); printf("Failed to fork for shell\n");
} else if (ret == 0) { } else if (ret == 0) {
gid = getpgrp();
if (gid < 0) {
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
exit(0);
}
ret = tcsetpgrp(STDIN_FILENO, gid);
if (ret != 0) {
printf("tcsetpgrp failed, errno %d\n", errno);
exit(0);
}
(void)execve(shellPath, NULL, NULL); (void)execve(shellPath, NULL, NULL);
exit(0); exit(0);
} }

View File

@ -1,77 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//build/lite/config/component/lite_component.gni")
lite_component("LMS-Sample") {
features = [ ":sample_usr_lms" ]
}
executable("sample_usr_lms") {
output_name = "sample_usr_lms"
sources = [ "src/sample_usr_lms.c" ]
include_dirs = []
defines = []
if (ohos_build_compiler == "gcc") {
cflags_c = [
"-O0",
"-fsanitize=kernel-address",
"-funwind-tables",
"-fasynchronous-unwind-tables",
]
} else {
cflags_c = [
"-O0",
"-fsanitize=kernel-address",
"-mllvm",
"-asan-instrumentation-with-call-threshold=0",
"-mllvm",
"-asan-stack=0",
"-mllvm",
"-asan-globals=0",
"-funwind-tables",
"-fasynchronous-unwind-tables",
]
}
ldflags = [
"-rdynamic",
"-lunwind",
"-lusrlms",
"-Wl,--wrap=realloc",
"-Wl,--wrap=calloc",
"-Wl,--wrap=malloc",
"-Wl,--wrap=free",
"-Wl,--wrap=valloc",
"-Wl,--wrap=aligned_alloc",
"-Wl,--wrap=memset",
"-Wl,--wrap=memcpy",
"-Wl,--wrap=memmove",
"-Wl,--wrap=strcpy",
"-Wl,--wrap=strcat",
]
deps = [ "$LITEOSTOPDIR/kernel/extended/lms/usr:usrlmslib" ]
}

View File

@ -1,250 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void BufWriteTest(void *buf, int start, int end)
{
for (int i = start; i <= end; i++) {
((char *)buf)[i] = 'a';
}
}
static void BufReadTest(void *buf, int start, int end)
{
char tmp;
for (int i = start; i <= end; i++) {
tmp = ((char *)buf)[i];
}
}
static void LmsMallocTest(void)
{
#define TEST_SIZE 16
printf("\n-------- LmsMallocTest Start --------\n");
char *buf = (char *)malloc(TEST_SIZE);
if (buf == NULL) {
return;
}
printf("[LmsMallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n");
BufReadTest(buf, -1, TEST_SIZE);
printf("[LmsMallocTest] write overflow error should be triggered, write range[0, TEST_SIZE]\n");
BufWriteTest(buf, 0, TEST_SIZE);
free(buf);
printf("\n-------- LmsMallocTest End --------\n");
}
static void LmsReallocTest(void)
{
#define TEST_SIZE 64
#define TEST_SIZE_MIN 32
printf("\n-------- LmsReallocTest Start --------\n");
char *buf = (char *)malloc(TEST_SIZE);
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n");
BufReadTest(buf, -1, TEST_SIZE);
char *buf1 = (char *)realloc(buf, TEST_SIZE_MIN);
if (buf1 == NULL) {
free(buf);
return;
}
buf = NULL;
printf("[LmsReallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE_MIN]\n");
BufReadTest(buf1, -1, TEST_SIZE_MIN);
free(buf1);
printf("\n-------- LmsReallocTest End --------\n");
}
static void LmsCallocTest(void)
{
#define TEST_SIZE 16
printf("\n-------- LmsCallocTest Start --------\n");
char *buf = (char *)calloc(4, 4); /* 4: test size */
if (buf == NULL) {
return;
}
printf("[LmsCallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n");
BufReadTest(buf, -1, TEST_SIZE);
free(buf);
printf("\n-------- LmsCallocTest End --------\n");
}
static void LmsVallocTest(void)
{
#define TEST_SIZE 4096
printf("\n-------- LmsVallocTest Start --------\n");
char *buf = (char *)valloc(TEST_SIZE);
if (buf == NULL) {
return;
}
printf("[LmsVallocTest] read overflow & underflow error should be triggered, read range[-1, TEST_SIZE]\n");
BufReadTest(buf, -1, TEST_SIZE);
free(buf);
printf("\n-------- LmsVallocTest End --------\n");
}
static void LmsAlignedAllocTest(void)
{
#define TEST_ALIGN_SIZE 64
#define TEST_SIZE 128
printf("\n-------- LmsAlignedAllocTest Start --------\n");
char *buf = (char *)aligned_alloc(TEST_ALIGN_SIZE, TEST_SIZE);
if (buf == NULL) {
return;
}
printf("[LmsAlignedAllocTest] read overflow & underflow error should be triggered, read range[-1,128]\n");
BufReadTest(buf, -1, 128);
free(buf);
printf("\n-------- LmsAlignedAllocTest End --------\n");
}
static void LmsMemsetTest(void)
{
#define TEST_SIZE 32
printf("\n-------- LmsMemsetTest Start --------\n");
char *buf = (char *)malloc(TEST_SIZE);
if (buf == NULL) {
return;
}
printf("[LmsMemsetTest] memset overflow & underflow error should be triggered, memset size:%d\n", TEST_SIZE + 1);
memset(buf, 0, TEST_SIZE + 1);
free(buf);
printf("\n-------- LmsMemsetTest End --------\n");
}
static void LmsMemcpyTest(void)
{
#define TEST_SIZE 20
printf("\n-------- LmsMemcpyTest Start --------\n");
char *buf = (char *)malloc(TEST_SIZE);
if (buf == NULL) {
return;
}
char localBuf[32] = {0}; /* 32: test size */
printf("[LmsMemcpyTest] memcpy overflow error should be triggered, memcpy size:%d\n", TEST_SIZE + 1);
memcpy(buf, localBuf, TEST_SIZE + 1);
free(buf);
printf("\n-------- LmsMemcpyTest End --------\n");
}
static void LmsMemmoveTest(void)
{
#define TEST_SIZE 20
printf("\n-------- LmsMemmoveTest Start --------\n");
char *buf = (char *)malloc(TEST_SIZE);
if (buf == NULL) {
return;
}
printf("[LmsMemmoveTest] memmove overflow error should be triggered\n");
memmove(buf + 12, buf, 10); /* 12 and 10: test size */
free(buf);
printf("\n-------- LmsMemmoveTest End --------\n");
}
static void LmsStrcpyTest(void)
{
#define TEST_SIZE 16
printf("\n-------- LmsStrcpyTest Start --------\n");
char *buf = (char *)malloc(TEST_SIZE);
if (buf == NULL) {
return;
}
char *testStr = "bbbbbbbbbbbbbbbbb";
printf("[LmsStrcpyTest] strcpy overflow error should be triggered, src string buf size:%d\n",
(int)strlen(testStr) + 1);
strcpy(buf, testStr);
free(buf);
printf("\n-------- LmsStrcpyTest End --------\n");
}
static void LmsStrcatTest(void)
{
#define TEST_SIZE 16
printf("\n-------- LmsStrcatTest Start --------\n");
char *buf = (char *)malloc(TEST_SIZE);
if (buf == NULL) {
return;
}
buf[0] = 'a';
buf[1] = 'b';
buf[2] = 0;
char *testStr = "cccccccccccccc";
printf("[LmsStrcatTest] strcat overflow error should be triggered, src string:%s dest string:%s"
"total buf size:%d\n",
testStr, buf, strlen(testStr) + strlen(buf) + 1);
strcat(buf, testStr);
free(buf);
printf("\n-------- LmsStrcatTest End --------\n");
}
static void LmsFreeTest(void)
{
#define TEST_SIZE 16
printf("\n-------- LmsFreeTest Start --------\n");
char *buf = (char *)malloc(TEST_SIZE);
if (buf == NULL) {
return;
}
printf("[LmsFreeTest] free size:%d\n", TEST_SIZE);
free(buf);
printf("[LmsFreeTest] Use after free error should be triggered, read range[1,1]\n");
BufReadTest(buf, 1, 1);
printf("[LmsFreeTest] double free error should be triggered\n");
free(buf);
printf("\n-------- LmsFreeTest End --------\n");
}
int main(int argc, char * const *argv)
{
(void)argc;
(void)argv;
printf("\n############### Lms Test start ###############\n");
char *tmp = (char *)malloc(5000); /* 5000: test mem size */
if (tmp == NULL) {
return -1;
}
LmsMallocTest();
LmsReallocTest();
LmsCallocTest();
LmsVallocTest();
LmsAlignedAllocTest();
LmsMemsetTest();
LmsMemcpyTest();
LmsMemmoveTest();
LmsStrcpyTest();
LmsStrcatTest();
LmsFreeTest();
free(tmp);
printf("\n############### Lms Test End ###############\n");
return 0;
}

View File

@ -1,100 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//build/lite/config/component/lite_component.gni")
import("//kernel/liteos_a/liteos.gni")
import("$THIRDPARTY_MKSH_DIR/mksh.gni")
group("mksh") {
deps = [ ":build_mksh" ]
}
copy("copy_mksh_src") {
sources = MKSH_SRC_DIR
outputs = [ "$target_out_dir/mksh_build" ]
}
build_ext_component("build_mksh") {
deps = [ ":copy_mksh_src" ]
deps += [ "$THIRDPARTY_MUSL_DIR:sysroot_lite" ]
exec_path = rebase_path("$target_out_dir/mksh_build")
cflags = [
"-flto",
"-fdata-sections",
"-ffunction-sections",
"-fstack-protector-strong",
"-D_FORTIFY_SOURCE=2",
"-DMKSH_DISABLE_TTY_WARNING",
"-DMKSH_SMALL=1",
"-DMKSH_ASSUME_UTF8=1",
"-DMKSH_SMALL_BUT_FAST=0",
"-DMKSH_S_NOVI=1",
"-DHAVE_CAN_FSTACKPROTECTORSTRONG=1",
"-DMKSH_LESS_CMDLINE_EDITING",
"-DMKSH_LESS_BUILDINS",
"-DMKSH_NO_INITCOMS",
"-DADAPT_FOR_LITEOS_A",
]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-Oz" ]
} else {
cflags += [ "-O2" ]
}
cflags = string_join(" ", cflags)
extra_flags = string_join(" ", target_arch_cflags)
if (ohos_build_compiler == "clang") {
extra_flags += " --target=$target_triple"
extra_flags += " --sysroot=" + rebase_path(ohos_current_sysroot)
}
command = "rm -rf .git && env"
command += " CC=\"$ohos_current_cc_command\""
command += " TARGET_OS=OpenHarmony"
command += " CFLAGS=\"$cflags $extra_flags\""
command += " LDFLAGS=\"-Wl,--gc-sections -flto -O2\""
command += " sh ./Build.sh -r"
# copy mksh and .mkshrc to out dir
command += " && mkdir -p "
command += rebase_path("$root_out_dir/bin", exec_path)
command += " && install -D mksh "
command += rebase_path("$root_out_dir/unstripped/bin/mksh", exec_path)
command += " && $ohos_current_strip_command mksh -o "
command += rebase_path("$root_out_dir/bin/mksh", exec_path)
command += " && install -D .mkshrc "
command += rebase_path("$root_out_dir/etc/.mkshrc", exec_path)
outputs = [
"$root_out_dir/unstripped/bin/mksh",
"$root_out_dir/bin/mksh",
"$root_out_dir/etc/.mkshrc",
]
}

View File

@ -1,56 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
include $(APPSTOPDIR)/config.mk
BUILD_DIR := $(OUT)/mksh_build
BUILD_LOG := $(BUILD_DIR)/build.log
CFLAGS += -DMKSH_DISABLE_TTY_WARNING -DMKSH_SMALL=1 -DMKSH_ASSUME_UTF8=1 -DMKSH_SMALL_BUT_FAST=0 -DMKSH_S_NOVI=1 -DHAVE_CAN_FSTACKPROTECTORSTRONG=1
CFLAGS += -DMKSH_LESS_CMDLINE_EDITING -DMKSH_LESS_BUILDINS -DMKSH_NO_INITCOMS -DADAPT_FOR_LITEOS_A
CFLAGS += -Wno-error
LDFLAGS += -Wl,--gc-sections
all:
ifneq ($(wildcard $(BUILD_DIR)/Rebuild.sh),)
$(HIDE)echo "not clean, rebuilding now"
$(HIDE)cd $(BUILD_DIR) && sh ./Rebuild.sh > $(BUILD_LOG) 2>&1
else
$(HIDE)mkdir -p $(BUILD_DIR)
$(HIDE)$(CP) $(LITEOSTHIRDPARTY)/mksh/. $(BUILD_DIR)
$(HIDE)cd $(BUILD_DIR) && CC="$(CC)" TARGET_OS=OpenHarmony CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" sh ./Build.sh -r > $(BUILD_LOG) 2>&1
endif
$(HIDE)mkdir -p $(OUT)/bin/ $(OUT)/etc/
$(HIDE)$(STRIP) $(BUILD_DIR)/mksh -o $(OUT)/bin/mksh
$(HIDE)$(CP) $(BUILD_DIR)/.mkshrc $(OUT)/etc/
clean:
$(HIDE)$(RM) $(BUILD_DIR)
.PHONY: all clean

18
arch/arm/gic/Makefile → apps/module.mk Normal file → Executable file
View File

@ -27,14 +27,18 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(LITEOSTOPDIR)/config.mk APP_SUBDIRS :=
MODULE_NAME := $(notdir $(shell pwd)) ##compile modules config##
ifeq ($(LOSCFG_ARCH_GIC_V2), y) ifeq ($(LOSCFG_SHELL), y)
LOCAL_SRCS := gic_v2.c APP_SUBDIRS += shell
else ifeq ($(LOSCFG_ARCH_GIC_V3), y)
LOCAL_SRCS := gic_v3.c
endif endif
include $(MODULE) ifeq ($(LOSCFG_USER_INIT_DEBUG), y)
APP_SUBDIRS += init
endif
ifeq ($(LOSCFG_NET_LWIP_SACK_TFTP), y)
APP_SUBDIRS += tftp
endif

View File

@ -1,62 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
include $(APPSTOPDIR)/config.mk
APP_NAME := $(notdir $(shell pwd))
SECUREC_DIR := $(LITEOSTHIRDPARTY)/bounds_checking_function
LOCAL_SRCS = $(wildcard src/*.c)
LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/*.c)
LOCAL_INCLUDE := \
-I include \
-I $(SECUREC_DIR)/include
LOCAL_FLAGS += $(LOCAL_INCLUDE)
ifeq ($(LOSCFG_PERF_HW_PMU), y)
CFLAGS += -DLOSCFG_PERF_HW_PMU
endif
ifeq ($(LOSCFG_PERF_TIMED_PMU), y)
CFLAGS += -DLOSCFG_PERF_TIMED_PMU
endif
ifeq ($(LOSCFG_PERF_SW_PMU), y)
CFLAGS += -DLOSCFG_PERF_SW_PMU
endif
ifeq ($(LOSCFG_FS_VFS), y)
CFLAGS += -DLOSCFG_FS_VFS
endif
CFLAGS += -DLOSCFG_PERF_BUFFER_SIZE=$(LOSCFG_PERF_BUFFER_SIZE)
include $(APP)

View File

@ -1,81 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 _OPTION_H
#define _OPTION_H
#include "perf.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define CMD_MAX_PARAMS 10
typedef int (*CALL_BACK)(const char *argv);
enum OptionType {
OPTION_TYPE_UINT,
OPTION_TYPE_STRING,
OPTION_TYPE_CALLBACK,
};
typedef struct {
int type;
const char *name;
const char **str;
unsigned int *value;
CALL_BACK cb;
} PerfOption;
typedef struct {
const char *path;
char *params[CMD_MAX_PARAMS];
} SubCmd;
#define OPTION_END() {.name = ""}
#define OPTION_UINT(n, v) {.type = OPTION_TYPE_UINT, .name = (n), .value = (v)}
#define OPTION_STRING(n, s) {.type = OPTION_TYPE_STRING, .name = (n), .str = (s)}
#define OPTION_CALLBACK(n, c) {.type = OPTION_TYPE_CALLBACK, .name = (n), .cb = (c)}
int ParseOptions(int argc, char **argv, PerfOption *opt, SubCmd *cmd);
int ParseEvents(const char *argv, PerfEventConfig *eventsCfg, unsigned int *len);
int ParseIds(const char *argv, int *arr, unsigned int *len);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif /* _OPTION_H */

View File

@ -1,163 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 _PERF_H
#define _PERF_H
#include <stdlib.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define PERF_MAX_EVENT 7
#define PERF_MAX_FILTER_TSKS 32
#ifdef PERF_DEBUG
#define printf_debug(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define printf_debug(fmt, ...)
#endif
/*
* Perf types
*/
enum PerfEventType {
PERF_EVENT_TYPE_HW, /* boards common hw events */
PERF_EVENT_TYPE_TIMED, /* hrtimer timed events */
PERF_EVENT_TYPE_SW, /* software trace events */
PERF_EVENT_TYPE_RAW, /* boards special hw events, see enum PmuEventType in corresponding arch headfile */
PERF_EVENT_TYPE_MAX
};
/*
* Common hardware pmu events
*/
enum PmuHwId {
PERF_COUNT_HW_CPU_CYCLES = 0, /* cpu cycle event */
PERF_COUNT_HW_INSTRUCTIONS, /* instruction event */
PERF_COUNT_HW_DCACHE_REFERENCES, /* dcache access event */
PERF_COUNT_HW_DCACHE_MISSES, /* dcache miss event */
PERF_COUNT_HW_ICACHE_REFERENCES, /* icache access event */
PERF_COUNT_HW_ICACHE_MISSES, /* icache miss event */
PERF_COUNT_HW_BRANCH_INSTRUCTIONS, /* software change of pc event */
PERF_COUNT_HW_BRANCH_MISSES, /* branch miss event */
PERF_COUNT_HW_MAX,
};
/*
* Common hrtimer timed events
*/
enum PmuTimedId {
PERF_COUNT_CPU_CLOCK = 0, /* hrtimer timed event */
};
/*
* Common software pmu events
*/
enum PmuSwId {
PERF_COUNT_SW_TASK_SWITCH = 1, /* task switch event */
PERF_COUNT_SW_IRQ_RESPONSE, /* irq response event */
PERF_COUNT_SW_MEM_ALLOC, /* memory alloc event */
PERF_COUNT_SW_MUX_PEND, /* mutex pend event */
PERF_COUNT_SW_MAX,
};
/*
* perf sample data types
* Config it through PerfConfigAttr->sampleType.
*/
enum PerfSampleType {
PERF_RECORD_CPU = 1U << 0, /* record current cpuid */
PERF_RECORD_TID = 1U << 1, /* record current task id */
PERF_RECORD_TYPE = 1U << 2, /* record event type */
PERF_RECORD_PERIOD = 1U << 3, /* record event period */
PERF_RECORD_TIMESTAMP = 1U << 4, /* record timestamp */
PERF_RECORD_IP = 1U << 5, /* record instruction pointer */
PERF_RECORD_CALLCHAIN = 1U << 6, /* record backtrace */
PERF_RECORD_PID = 1U << 7, /* record current process id */
};
/*
* perf configuration sub event information
*
* This structure is used to config specific events attributes.
*/
typedef struct {
unsigned int type; /* enum PerfEventType */
struct {
unsigned int eventId; /* the specific event corresponds to the PerfEventType */
unsigned int period; /* event period, for every "period"th occurrence of the event a
sample will be recorded */
} events[PERF_MAX_EVENT]; /* perf event list */
unsigned int eventsNr; /* total perf event number */
size_t predivided; /* whether to prescaler (once every 64 counts),
which only take effect on cpu cycle hardware event */
} PerfEventConfig;
/*
* perf configuration main information
*
* This structure is used to set perf sampling attributes, including events, tasks and other information.
*/
typedef struct {
PerfEventConfig eventsCfg; /* perf event config */
unsigned int taskIds[PERF_MAX_FILTER_TSKS]; /* perf task filter list (allowlist) */
unsigned int taskIdsNr; /* task numbers of task filter allowlist,
if set 0 perf will sample all tasks */
unsigned int processIds[PERF_MAX_FILTER_TSKS]; /* perf process filter list (allowlist) */
unsigned int processIdsNr; /* process numbers of process filter allowlist,
if set 0 perf will sample all processes */
unsigned int sampleType; /* type of data to sample defined in PerfSampleType */
size_t needSample; /* whether to sample data */
} PerfConfigAttr;
void PerfUsage(void);
void PerfDumpAttr(PerfConfigAttr *attr);
int PerfConfig(int fd, PerfConfigAttr *attr);
void PerfStart(int fd, size_t sectionId);
void PerfStop(int fd);
ssize_t PerfRead(int fd, char *buf, size_t size);
void PerfPrintBuffer(const char *buf, ssize_t num);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif /* _PERF_H */

View File

@ -1,57 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 _PERF_LIST_H
#define _PERF_LIST_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
typedef struct {
const char *name;
int event;
int type;
} PerfEvent;
extern const PerfEvent g_events[];
void PerfList(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif /* _PERF_LIST_H */

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 _PERF_RECORD_H
#define _PERF_RECORD_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
void PerfRecord(int fd, int argc, char **argv);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif /* _PERF_RECORD_H */

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 _PERF_STAT_H
#define _PERF_STAT_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
void PerfStat(int fd, int argc, char **argv);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif /* _PERF_STAT_H */

View File

@ -1,90 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include "perf.h"
#include "perf_list.h"
#include "perf_stat.h"
#include "perf_record.h"
int main(int argc, char **argv)
{
#define TWO_ARGS 2
#define THREE_ARGS 3
int fd = open("/dev/perf", O_RDWR);
if (fd == -1) {
printf("Perf open failed.\n");
exit(EXIT_FAILURE);
}
if (argc == 1) {
PerfUsage();
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "start") == 0) {
PerfStart(fd, 0);
} else if ((argc == THREE_ARGS) && strcmp(argv[1], "start") == 0) {
size_t id = strtoul(argv[THREE_ARGS - 1], NULL, 0);
PerfStart(fd, id);
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "stop") == 0) {
PerfStop(fd);
} else if ((argc == THREE_ARGS) && strcmp(argv[1], "read") == 0) {
size_t size = strtoul(argv[THREE_ARGS - 1], NULL, 0);
if (size == 0) {
goto EXIT:
}
char *buf = (char *)malloc(size);
if (buf != NULL) {
int len = PerfRead(fd, buf, size);
PerfPrintBuffer(buf, len);
free(buf);
buf = NULL;
}
} else if ((argc == TWO_ARGS) && strcmp(argv[1], "list") == 0) {
PerfList();
} else if ((argc >= THREE_ARGS) && strcmp(argv[1], "stat") == 0) {
PerfStat(fd, argc, argv);
} else if ((argc >= THREE_ARGS) && strcmp(argv[1], "record") == 0) {
PerfRecord(fd, argc, argv);
} else {
printf("Unsupported perf command.\n");
PerfUsage();
}
EXIT:
close(fd);
return 0;
}

View File

@ -1,182 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include <stdio.h>
#include <string.h>
#include "option.h"
#include "perf_list.h"
static int ParseOption(char **argv, int *index, PerfOption *opts)
{
int ret = 0;
const char *str = NULL;
while ((opts->name != NULL) && (*opts->name != 0)) {
if (strcmp(argv[*index], opts->name) == 0) {
switch (opts->type) {
case OPTION_TYPE_UINT:
*opts->value = strtoul(argv[++(*index)], NULL, 0);
break;
case OPTION_TYPE_STRING:
*opts->str = argv[++(*index)];
break;
case OPTION_TYPE_CALLBACK:
str = argv[++(*index)];
if ((*opts->cb)(str) != 0) {
printf("parse error\n");
ret = -1;
}
break;
default:
printf("invalid option\n");
ret = -1;
break;
}
return ret;
}
opts++;
}
return -1;
}
int ParseOptions(int argc, char **argv, PerfOption *opts, SubCmd *cmd)
{
int i;
int index = 0;
while ((index < argc) && (argv[index] != NULL) && (*argv[index] == '-')) {
if (ParseOption(argv, &index, opts) != 0) {
return -1;
}
index++;
}
if ((index < argc) && (argv[index] != NULL)) {
cmd->path = argv[index];
cmd->params[0] = argv[index];
index++;
} else {
printf("no subcmd to execute\n");
return -1;
}
for (i = 1; (index < argc) && (i < CMD_MAX_PARAMS); index++, i++) {
cmd->params[i] = argv[index];
}
printf_debug("subcmd = %s\n", cmd->path);
for (int j = 0; j < i; j++) {
printf_debug("paras[%d]:%s\n", j, cmd->params[j]);
}
return 0;
}
int ParseIds(const char *argv, int *arr, unsigned int *len)
{
int res, ret;
unsigned int index = 0;
char *sp = NULL;
char *this = NULL;
char *list = strdup(argv);
if (list == NULL) {
printf("no memory for ParseIds\n");
return -1;
}
sp = strtok_r(list, ",", &this);
while (sp) {
res = strtoul(sp, NULL, 0);
if (res < 0) {
ret = -1;
goto EXIT;
}
arr[index++] = res;
sp = strtok_r(NULL, ",", &this);
}
*len = index;
ret = 0;
EXIT:
free(list);
return ret;
}
static inline const PerfEvent *StrToEvent(const char *str)
{
const PerfEvent *evt = &g_events[0];
for (; evt->event != -1; evt++) {
if (strcmp(str, evt->name) == 0) {
return evt;
}
}
return NULL;
}
int ParseEvents(const char *argv, PerfEventConfig *eventsCfg, unsigned int *len)
{
int ret;
unsigned int index = 0;
const PerfEvent *event = NULL;
char *sp = NULL;
char *this = NULL;
char *list = strdup(argv);
if (list == NULL) {
printf("no memory for ParseEvents\n");
return -1;
}
sp = strtok_r(list, ",", &this);
while (sp) {
event = StrToEvent(sp);
if (event == NULL) {
ret = -1;
goto EXIT;
}
if (index == 0) {
eventsCfg->type = event->type;
} else if (eventsCfg->type != event->type) {
printf("events type must be same\n");
ret = -1;
goto EXIT;
}
eventsCfg->events[index].eventId = event->event;
sp = strtok_r(NULL, ",", &this);
index++;
}
*len = index;
ret = 0;
EXIT:
free(list);
return ret;
}

View File

@ -1,136 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include "perf.h"
#define PERF_IOC_MAGIC 'T'
#define PERF_START _IO(PERF_IOC_MAGIC, 1)
#define PERF_STOP _IO(PERF_IOC_MAGIC, 2)
void PerfUsage(void)
{
printf("\nUsage: ./perf start [id]. Start perf.\n");
printf("\nUsage: ./perf stop. Stop perf.\n");
printf("\nUsage: ./perf read <nBytes>. Read nBytes raw data from perf buffer and print out.\n");
printf("\nUsage: ./perf list. List events to be used in -e.\n");
printf("\nUsage: ./perf stat/record [option] <command>. \n"
"-e, event selector. use './perf list' to list available events.\n"
"-p, event period.\n"
"-o, perf data output filename.\n"
"-t, taskId filter(allowlist), if not set perf will sample all tasks.\n"
"-s, type of data to sample defined in PerfSampleType los_perf.h.\n"
"-P, processId filter(allowlist), if not set perf will sample all processes.\n"
"-d, whether to prescaler (once every 64 counts),"
"which only take effect on cpu cycle hardware event.\n"
);
}
static void PerfSetPeriod(PerfConfigAttr *attr)
{
int i;
for (i = 1; i < attr->eventsCfg.eventsNr; i++) {
attr->eventsCfg.events[i].period = attr->eventsCfg.events[0].period;
}
}
void PerfPrintBuffer(const char *buf, ssize_t num)
{
#define BYTES_PER_LINE 4
ssize_t i;
for (i = 0; i < num; i++) {
printf(" %02x", (unsigned char)buf[i]);
if (((i + 1) % BYTES_PER_LINE) == 0) {
printf("\n");
}
}
printf("\n");
}
void PerfDumpAttr(PerfConfigAttr *attr)
{
int i;
printf_debug("attr->type: %d\n", attr->eventsCfg.type);
for (i = 0; i < attr->eventsCfg.eventsNr; i++) {
printf_debug("attr->events[%d]: %d, 0x%x\n", i, attr->eventsCfg.events[i].eventId,
attr->eventsCfg.events[i].period);
}
printf_debug("attr->predivided: %d\n", attr->eventsCfg.predivided);
printf_debug("attr->sampleType: 0x%x\n", attr->sampleType);
for (i = 0; i < attr->taskIdsNr; i++) {
printf_debug("attr->taskIds[%d]: %d\n", i, attr->taskIds[i]);
}
for (i = 0; i < attr->processIdsNr; i++) {
printf_debug("attr->processIds[%d]: %d\n", i, attr->processIds[i]);
}
printf_debug("attr->needSample: %d\n", attr->needSample);
}
void PerfStart(int fd, size_t sectionId)
{
(void)ioctl(fd, PERF_START, sectionId);
}
void PerfStop(int fd)
{
(void)ioctl(fd, PERF_STOP, NULL);
}
int PerfConfig(int fd, PerfConfigAttr *attr)
{
if (attr == NULL) {
return -1;
}
PerfSetPeriod(attr);
PerfDumpAttr(attr);
return write(fd, attr, sizeof(PerfConfigAttr));
}
ssize_t PerfRead(int fd, char *buf, size_t size)
{
ssize_t len;
if (buf == NULL) {
printf("Read buffer is null.\n");
return 0;
}
len = read(fd, buf, size);
return len;
}

View File

@ -1,129 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include <stdio.h>
#include "perf.h"
#include "perf_list.h"
static const char *g_eventTypeStr[] = {
"[Hardware event]",
"[Timed event]",
"[Software event]",
};
const PerfEvent g_events[] = {
#ifdef LOSCFG_PERF_HW_PMU
{
.name = "cycles",
.event = PERF_COUNT_HW_CPU_CYCLES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "instruction",
.event = PERF_COUNT_HW_INSTRUCTIONS,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "dcache",
.event = PERF_COUNT_HW_DCACHE_REFERENCES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "dcache-miss",
.event = PERF_COUNT_HW_DCACHE_MISSES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "icache",
.event = PERF_COUNT_HW_ICACHE_REFERENCES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "icache-miss",
.event = PERF_COUNT_HW_ICACHE_MISSES,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "branch",
.event = PERF_COUNT_HW_BRANCH_INSTRUCTIONS,
.type = PERF_EVENT_TYPE_HW,
},
{
.name = "branch-miss",
.event = PERF_COUNT_HW_BRANCH_MISSES,
.type = PERF_EVENT_TYPE_HW,
},
#endif
#ifdef LOSCFG_PERF_TIMED_PMU
{
.name = "clock",
.event = PERF_COUNT_CPU_CLOCK,
.type = PERF_EVENT_TYPE_TIMED,
},
#endif
#ifdef LOSCFG_PERF_SW_PMU
{
.name = "task-switch",
.event = PERF_COUNT_SW_TASK_SWITCH,
.type = PERF_EVENT_TYPE_SW,
},
{
.name = "irq-in",
.event = PERF_COUNT_SW_IRQ_RESPONSE,
.type = PERF_EVENT_TYPE_SW,
},
{
.name = "mem-alloc",
.event = PERF_COUNT_SW_MEM_ALLOC,
.type = PERF_EVENT_TYPE_SW,
},
{
.name = "mux-pend",
.event = PERF_COUNT_SW_MUX_PEND,
.type = PERF_EVENT_TYPE_SW,
},
#endif
{
.name = "",
.event = -1,
.type = PERF_EVENT_TYPE_MAX,
}
};
void PerfList(void)
{
const PerfEvent *evt = &g_events[0];
printf("\n");
for (; evt->event != -1; evt++) {
printf("\t %-25s%30s\n", evt->name, g_eventTypeStr[evt->type]);
}
printf("\n");
}

View File

@ -1,203 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include <unistd.h>
#include <sys/wait.h>
#include <securec.h>
#ifdef LOSCFG_FS_VFS
#include <fcntl.h>
#include <errno.h>
#endif
#include "perf.h"
#include "option.h"
#include "perf_record.h"
#define PERF_FILE_MODE 0644
static PerfConfigAttr g_recordAttr;
static const char *g_savePath = "/storage/data/perf.data";
static inline int GetEvents(const char *argv)
{
return ParseEvents(argv, &g_recordAttr.eventsCfg, &g_recordAttr.eventsCfg.eventsNr);
}
static inline int GetTids(const char *argv)
{
return ParseIds(argv, (int *)g_recordAttr.taskIds, &g_recordAttr.taskIdsNr);
}
static inline int GetPids(const char *argv)
{
return ParseIds(argv, (int *)g_recordAttr.processIds, &g_recordAttr.processIdsNr);
}
static PerfOption g_recordOpts[] = {
OPTION_CALLBACK("-e", GetEvents),
OPTION_CALLBACK("-t", GetTids),
OPTION_CALLBACK("-P", GetPids),
OPTION_STRING("-o", &g_savePath),
OPTION_UINT("-p", &g_recordAttr.eventsCfg.events[0].period),
OPTION_UINT("-s", &g_recordAttr.sampleType),
OPTION_UINT("-d", &g_recordAttr.eventsCfg.predivided),
};
static int PerfRecordAttrInit(void)
{
PerfConfigAttr attr = {
.eventsCfg = {
#ifdef LOSCFG_PERF_HW_PMU
.type = PERF_EVENT_TYPE_HW,
.events = {
[0] = {PERF_COUNT_HW_CPU_CYCLES, 0xFFFF},
},
#elif defined LOSCFG_PERF_TIMED_PMU
.type = PERF_EVENT_TYPE_TIMED,
.events = {
[0] = {PERF_COUNT_CPU_CLOCK, 100},
},
#elif defined LOSCFG_PERF_SW_PMU
.type = PERF_EVENT_TYPE_SW,
.events = {
[0] = {PERF_COUNT_SW_TASK_SWITCH, 1},
},
#endif
.eventsNr = 1, /* 1 event */
.predivided = 0,
},
.taskIds = {0},
.taskIdsNr = 0,
.processIds = {0},
.processIdsNr = 0,
.needSample = 1,
.sampleType = PERF_RECORD_IP | PERF_RECORD_CALLCHAIN,
};
return memcpy_s(&g_recordAttr, sizeof(PerfConfigAttr), &attr, sizeof(PerfConfigAttr)) != EOK ? -1 : 0;
}
ssize_t PerfWriteFile(const char *filePath, const char *buf, ssize_t bufSize)
{
#ifdef LOSCFG_FS_VFS
int fd = -1;
ssize_t totalToWrite = bufSize;
ssize_t totalWrite = 0;
if (filePath == NULL || buf == NULL || bufSize == 0) {
return -1;
}
fd = open(filePath, O_CREAT | O_RDWR | O_TRUNC, PERF_FILE_MODE);
if (fd < 0) {
printf("create file [%s] failed, fd: %d, %s!\n", filePath, fd, strerror(errno));
return -1;
}
while (totalToWrite > 0) {
ssize_t writeThisTime = write(fd, buf, totalToWrite);
if (writeThisTime < 0) {
printf("failed to write file [%s], %s!\n", filePath, strerror(errno));
(void)close(fd);
return -1;
}
buf += writeThisTime;
totalToWrite -= writeThisTime;
totalWrite += writeThisTime;
}
(void)fsync(fd);
(void)close(fd);
return (totalWrite == bufSize) ? 0 : -1;
#else
(void)filePath;
PerfPrintBuffer(buf, bufSize);
return 0;
#endif
}
void PerfRecord(int fd, int argc, char **argv)
{
int ret;
int child;
char *buf;
ssize_t len;
SubCmd cmd = {0};
if (argc < 3) { /* perf record argc is at least 3 */
return;
}
ret = PerfRecordAttrInit();
if (ret != 0) {
printf("perf record attr init failed\n");
return;
}
ret = ParseOptions(argc - 2, &argv[2], g_recordOpts, &cmd); /* parse option and cmd begin at index 2 */
if (ret != 0) {
printf("parse error\n");
return;
}
ret = PerfConfig(fd, &g_recordAttr);
if (ret != 0) {
printf("perf config failed\n");
return;
}
PerfStart(fd, 0);
child = fork();
if (child < 0) {
printf("fork error\n");
PerfStop(fd);
return;
} else if (child == 0) {
(void)execve(cmd.path, cmd.params, NULL);
exit(0);
}
waitpid(child, 0, 0);
PerfStop(fd);
buf = (char *)malloc(LOSCFG_PERF_BUFFER_SIZE);
if (buf == NULL) {
printf("no memory for read perf 0x%x\n", LOSCFG_PERF_BUFFER_SIZE);
return;
}
len = PerfRead(fd, buf, LOSCFG_PERF_BUFFER_SIZE);
ret = PerfWriteFile(g_savePath, buf, len);
if (ret == 0) {
printf("save perf data success at %s\n", g_savePath);
} else {
printf("save perf data failed at %s\n", g_savePath);
}
free(buf);
}

View File

@ -1,149 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include <unistd.h>
#include <securec.h>
#include <sys/wait.h>
#include "perf.h"
#include "option.h"
#include "perf_stat.h"
static PerfConfigAttr g_statAttr;
static inline int GetEvents(const char *argv)
{
return ParseEvents(argv, &g_statAttr.eventsCfg, &g_statAttr.eventsCfg.eventsNr);
}
static inline int GetTids(const char *argv)
{
return ParseIds(argv, (int *)g_statAttr.taskIds, &g_statAttr.taskIdsNr);
}
static inline int GetPids(const char *argv)
{
return ParseIds(argv, (int *)g_statAttr.processIds, &g_statAttr.processIdsNr);
}
static PerfOption g_statOpts[] = {
OPTION_CALLBACK("-e", GetEvents),
OPTION_CALLBACK("-t", GetTids),
OPTION_CALLBACK("-P", GetPids),
OPTION_UINT("-p", &g_statAttr.eventsCfg.events[0].period),
OPTION_UINT("-s", &g_statAttr.sampleType),
OPTION_UINT("-d", &g_statAttr.eventsCfg.predivided),
};
static int PerfStatAttrInit(void)
{
PerfConfigAttr attr = {
.eventsCfg = {
#ifdef LOSCFG_PERF_HW_PMU
.type = PERF_EVENT_TYPE_HW,
.events = {
[0] = {PERF_COUNT_HW_CPU_CYCLES, 0xFFFF},
[1] = {PERF_COUNT_HW_INSTRUCTIONS, 0xFFFFFF00},
[2] = {PERF_COUNT_HW_ICACHE_REFERENCES, 0xFFFF},
[3] = {PERF_COUNT_HW_DCACHE_REFERENCES, 0xFFFF},
},
.eventsNr = 4, /* 4 events */
#elif defined LOSCFG_PERF_TIMED_PMU
.type = PERF_EVENT_TYPE_TIMED,
.events = {
[0] = {PERF_COUNT_CPU_CLOCK, 100},
},
.eventsNr = 1, /* 1 event */
#elif defined LOSCFG_PERF_SW_PMU
.type = PERF_EVENT_TYPE_SW,
.events = {
[0] = {PERF_COUNT_SW_TASK_SWITCH, 1},
[1] = {PERF_COUNT_SW_IRQ_RESPONSE, 1},
[2] = {PERF_COUNT_SW_MEM_ALLOC, 1},
[3] = {PERF_COUNT_SW_MUX_PEND, 1},
},
.eventsNr = 4, /* 4 events */
#endif
.predivided = 0,
},
.taskIds = {0},
.taskIdsNr = 0,
.processIds = {0},
.processIdsNr = 0,
.needSample = 0,
.sampleType = 0,
};
return memcpy_s(&g_statAttr, sizeof(PerfConfigAttr), &attr, sizeof(PerfConfigAttr)) != EOK ? -1 : 0;
}
void PerfStat(int fd, int argc, char **argv)
{
int ret;
int child;
SubCmd cmd = {0};
if (argc < 3) { /* perf stat argc is at least 3 */
return;
}
ret = PerfStatAttrInit();
if (ret != 0) {
printf("perf stat attr init failed\n");
return;
}
ret = ParseOptions(argc - 2, &argv[2], g_statOpts, &cmd); /* parse option and cmd begin at index 2 */
if (ret != 0) {
printf("parse error\n");
return;
}
ret = PerfConfig(fd, &g_statAttr);
if (ret != 0) {
printf("perf config failed\n");
return;
}
PerfStart(fd, 0);
child = fork();
if (child < 0) {
printf("fork error\n");
goto EXIT;
} else if (child == 0) {
(void)execve(cmd.path, cmd.params, NULL);
exit(0);
}
(void)waitpid(child, 0, 0);
EXIT:
PerfStop(fd);
}

51
apps/shell/Makefile Normal file → Executable file
View File

@ -27,19 +27,52 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(APPSTOPDIR)/config.mk SHELL_DIR := $(dir $(shell pwd))/shell/
APP_NAME := $(notdir $(shell pwd)) ifeq ($(APPSTOPDIR), )
APPSTOPDIR := $(shell pwd)/../
LITEOSTOPDIR = $(APPSTOPDIR)/../
endif
include $(SHELL_DIR)/../config.mk
APPS_OUT := $(OUT)/bin
SECUREC_DIR := $(LITEOSTHIRDPARTY)/bounds_checking_function SECUREC_INCLUDE := $(LITEOSTHIRDPARTY)/bounds_checking_function/include
LOCAL_SRCS = $(wildcard src/*.c builtin/*.c) LOCAL_SRCS = $(wildcard src/main.c)\
LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/*.c) $(wildcard src/shcmd.c)\
$(wildcard src/shmsg.c)\
$(wildcard src/shcmdparse.c)\
$(wildcard builtin/cd.c)
LOCAL_SRCS += $(wildcard $(LITEOSTHIRDPARTY)/bounds_checking_function/src/*.c)
LOCAL_OBJ := $(LOCAL_SRCS:.c=.o)
LOCAL_INCLUDE := \ LOCAL_INCLUDE := \
-I include \ -I $(SHELL_DIR)/include/ \
-I $(SECUREC_DIR)/include -I $(SECUREC_INCLUDE)\
LOCAL_FLAGS += $(LOCAL_INCLUDE) LOCAL_FLAGS += $(CFLAGS)
include $(APP) LDPATH := -L$(SHELL_DIR)/
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-bitwise-op-parentheses $(LLVM_SYSROOT)
LDCFLAGS += $(LLVM_EXTRA_LD_OPTS) $(LLVM_SYSROOT)
endif
SHELLNAME := shell
all: $(SHELLNAME)
$(LOCAL_OBJ): %.o : %.c
$(HIDE) $(CC) $(LOCAL_FLAGS) -fPIE $(LOCAL_INCLUDE) -c $< -o $@
$(SHELLNAME): $(LOCAL_OBJ)
$(HIDE) $(CC) -pie -s $(LDPATH) $(BASE_OPTS) -o $(SHELLNAME) $^ $(LDCFLAGS)
$(HIDE) mkdir -p $(APPS_OUT)
$(HIDE) $(MV) $(SHELLNAME) $(APPS_OUT)
$(HIDE) $(RM) $(LOCAL_OBJ)
clean:
$(HIDE) $(RM) $(LOCAL_OBJ)
$(HIDE) $(RM) $(SHELLNAME)
.PHONY: all $(SHELLNAME) clean

17
apps/shell/builtin/cd.c Normal file → Executable file
View File

@ -29,12 +29,19 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _GNU_SOURCE
#define _GNU_SOURCE #define _GNU_SOURCE
#endif
#include "unistd.h" #include "unistd.h"
#include "shcmd.h" #include "shcmd.h"
#include "sherr.h" #include "sherr.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
int Chdir(const char *tgtDir) int Chdir(const char *tgtDir)
{ {
@ -46,9 +53,17 @@ int Chdir(const char *tgtDir)
ret = chdir(tgtDir); ret = chdir(tgtDir);
if (ret == 0) { if (ret == 0) {
ret = OsShellSetWorkingDirectory(tgtDir, strlen(tgtDir) + 1); /* 1: the length of '\0' */ ret = OsShellSetWorkingDirtectory(tgtDir, strlen(tgtDir) + 1); /* 1: the length of '\0' */
if (ret != SH_NOK) {
return ret;
}
} }
return ret; return ret;
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

4
apps/shell/include/shcmd.h Normal file → Executable file
View File

@ -53,7 +53,7 @@ typedef struct {
} CmdKeyLink; } CmdKeyLink;
#define NEED_NEW_LINE(timesPrint, lineCap) ((timesPrint) % (lineCap) == 0) #define NEED_NEW_LINE(timesPrint, lineCap) ((timesPrint) % (lineCap) == 0)
#define SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGHT)) #define SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGNT))
extern unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr); extern unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr);
extern unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size); extern unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size);
@ -62,7 +62,7 @@ extern void OsShellCmdPush(const char *string, CmdKeyLink *cmdKeyLink);
extern void OsShellHistoryShow(unsigned int value, ShellCB *shellCB); extern void OsShellHistoryShow(unsigned int value, ShellCB *shellCB);
extern unsigned int OsShellKeyInit(ShellCB *shellCB); extern unsigned int OsShellKeyInit(ShellCB *shellCB);
extern void OsShellKeyDeInit(CmdKeyLink *cmdKeyLink); extern void OsShellKeyDeInit(CmdKeyLink *cmdKeyLink);
extern int OsShellSetWorkingDirectory(const char *dir, size_t len); extern int OsShellSetWorkingDirtectory(const char *dir, size_t len);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus

3
apps/shell/include/shell.h Normal file → Executable file
View File

@ -54,7 +54,7 @@ extern "C" {
#define CMD_HISTORY_LEN 10 #define CMD_HISTORY_LEN 10
#define CMD_MAX_PATH 256 #define CMD_MAX_PATH 256
#define DEFAULT_SCREEN_WIDTH 80 #define DEFAULT_SCREEN_WIDTH 80
#define DEFAULT_SCREEN_HEIGHT 24 #define DEFAULT_SCREEN_HEIGNT 24
#define SWITCH_QUOTES_STATUS(qu) do { \ #define SWITCH_QUOTES_STATUS(qu) do { \
if ((qu) == TRUE) { \ if ((qu) == TRUE) { \
@ -67,6 +67,7 @@ extern "C" {
#define QUOTES_STATUS_CLOSE(qu) ((qu) == FALSE) #define QUOTES_STATUS_CLOSE(qu) ((qu) == FALSE)
#define QUOTES_STATUS_OPEN(qu) ((qu) == TRUE) #define QUOTES_STATUS_OPEN(qu) ((qu) == TRUE)
typedef size_t bool;
typedef struct { typedef struct {
unsigned int consoleID; unsigned int consoleID;

View File

@ -351,13 +351,34 @@ static inline void SH_ListHeadInsertList(SH_List *oldList, SH_List *newList)
* </ul> * </ul>
* *
* @param type [IN] Structure name. * @param type [IN] Structure name.
* @param member [IN] Name of the member of which the offset is to be measured. * @param field [IN] Name of the field of which the offset is to be measured.
* *
* @retval Offset of the field to the structure address. * @retval Offset of the field to the structure address.
* @par Dependency: * @par Dependency:
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul> * <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
* @see * @see
*/ */
#define OFFSET_OF_FIELD(type, field) ((uintptr_t)&((type *)0)->field)
/**
* @ingroup shell_list
* @brief Obtain the pointer to a doubly linked list in a structure.
*
* @par Description:
* This API is used to obtain the pointer to a doubly linked list in a structure.
* @attention
* <ul>
* <li>None.</li>
* </ul>
*
* @param type [IN] Structure name.
* @param member [IN] Member name of the doubly linked list in the structure.
*
* @retval Pointer to the doubly linked list in the structure.
* @par Dependency:
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
* @see
*/
#define LOS_OFF_SET_OF(type, member) ((uintptr_t)&((type *)0)->member) #define LOS_OFF_SET_OF(type, member) ((uintptr_t)&((type *)0)->member)
/** /**

View File

@ -32,7 +32,9 @@
#ifndef _SHELL_PRI_H #ifndef _SHELL_PRI_H
#define _SHELL_PRI_H #define _SHELL_PRI_H
#include "shell.h" #include "sys/types.h"
#include "bits/alltypes.h"
#include "shcmd.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
@ -40,7 +42,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __cplusplus */ #endif /* __cplusplus */
extern void ShellEntry(ShellCB *shellCB); extern void *ShellEntry(void *argv);
extern void *ShellTask(void *argv); extern void *ShellTask(void *argv);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -32,6 +32,9 @@
#ifndef _SHERR_H #ifndef _SHERR_H
#define _SHERR_H #define _SHERR_H
#include "sys/types.h"
#include "bits/alltypes.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {

10
apps/shell/include/shmsg.h Normal file → Executable file
View File

@ -32,7 +32,6 @@
#ifndef _SHMSG_H #ifndef _SHMSG_H
#define _SHMSG_H #define _SHMSG_H
#include "shell_list.h"
#include "shell.h" #include "shell.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -45,12 +44,7 @@ extern "C" {
#define SHELL_TASK_STACKSIZE 0x3000 #define SHELL_TASK_STACKSIZE 0x3000
#define SHELL_EXEC_COMMAND "exec " #define SHELL_EXEC_COMMAND "exec "
#define SHELL_EXEC_COMMAND_BYTES 4 #define SHELL_EXEC_COMMAND_BYTES 5
#define CMD_EXEC_COMMAND SHELL_EXEC_COMMAND" "
#define CMD_EXEC_COMMAND_BYTES (SHELL_EXEC_COMMAND_BYTES + 1)
#define CMD_EXIT_COMMAND "exit"
#define CMD_EXIT_COMMAND_BYTES 4
#define CMD_EXIT_CODE_BASE_DEC 10
#define CONSOLE_IOC_MAGIC 'c' #define CONSOLE_IOC_MAGIC 'c'
#define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7) #define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7)
@ -62,7 +56,7 @@ extern "C" {
typedef void (*OutputFunc)(const char *fmt, ...); typedef void (*OutputFunc)(const char *fmt, ...);
extern int ShellTaskInit(ShellCB *shellCB); extern int ShellTaskInit(ShellCB *shellCB);
extern void ChildExec(const char *cmdName, char *const paramArray[], bool foreground); extern int ShellEntryInit(ShellCB *shellCB);
extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB); extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB);
extern int ShellNotify(ShellCB *shellCB); extern int ShellNotify(ShellCB *shellCB);

6
apps/shell/include/show.h Normal file → Executable file
View File

@ -42,10 +42,10 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __cplusplus */ #endif /* __cplusplus */
extern char *OsShellGetWorkingDirectory(void); extern char *OsShellGetWorkingDirtectory();
extern unsigned int OsShellInit(void); extern unsigned int OsShellInit();
extern int OsShellDeinit(ShellCB *shellCB); extern int OsShellDeinit(ShellCB *shellCB);
extern ShellCB *OsGetShellCb(void); extern ShellCB *OsGetShellCb();
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus

108
apps/shell/src/main.c Normal file → Executable file
View File

@ -29,27 +29,27 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#define _GNU_SOURCE
#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/syscall.h>
#include "show.h" #include "show.h"
#include "shmsg.h" #include "shmsg.h"
#include "shcmd.h" #include "shcmd.h"
#include "shell_pri.h"
#include "semaphore.h" #include "semaphore.h"
#include "securec.h" #include "securec.h"
#include "unistd.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
ShellCB *g_shellCB = NULL; ShellCB *g_shellCB = NULL;
ShellCB *OsGetShellCb(void) ShellCB *OsGetShellCb()
{ {
return g_shellCB; return g_shellCB;
} }
static void ShellDeinit(ShellCB *shellCB) void ShellDeinit(ShellCB *shellCB)
{ {
(void)pthread_mutex_destroy(&shellCB->historyMutex); (void)pthread_mutex_destroy(&shellCB->historyMutex);
(void)pthread_mutex_destroy(&shellCB->keyMutex); (void)pthread_mutex_destroy(&shellCB->keyMutex);
@ -65,86 +65,44 @@ static int OsShellCreateTask(ShellCB *shellCB)
ret = sched_getparam(getpid(), &param); ret = sched_getparam(getpid(), &param);
if (ret != SH_OK) { if (ret != SH_OK) {
return ret; goto OUT;
} }
param.sched_priority = SHELL_PROCESS_PRIORITY_INIT; param.sched_priority = SHELL_PROCESS_PRIORITY_INIT;
ret = sched_setparam(getpid(), &param); ret = sched_setparam(getpid(), &param);
if (ret != SH_OK) { if (ret != SH_OK) {
return ret; goto OUT;
} }
ret = ShellTaskInit(shellCB); ret = ShellTaskInit(shellCB);
if (ret != SH_OK) { if (ret != SH_OK) {
goto OUT;
}
ret = ShellEntryInit(shellCB);
if (ret != SH_OK) {
goto OUT;
}
(void)pthread_join(shellCB->shellTaskHandle, NULL);
(void)pthread_join(shellCB->shellEntryHandle, NULL);
OUT:
ShellDeinit(shellCB);
return ret; return ret;
} }
shellCB->shellEntryHandle = pthread_self(); int main()
return 0;
}
static int DoShellExec(char **argv)
{
int i, j;
int len = 0;
int ret = SH_NOK;
char *cmdLine = NULL;
if (strncmp(argv[0], SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
ChildExec(argv[1], argv + 1, FALSE);
}
for (i = 0; argv[i]; i++) {
len += strlen(argv[i]);
}
len += i + 1;
cmdLine = (char *)malloc(len);
if (!cmdLine) {
return ret;
}
errno_t ret1 = memset_s(cmdLine, len, 0, len);
if (ret1 != EOK) {
free(cmdLine);
return ret1;
}
for (j = 0; j < i; j++) {
(void)strcat_s(cmdLine, len, argv[j]);
(void)strcat_s(cmdLine, len, " ");
}
cmdLine[len - 2] = '\0'; /* 2, (len - 2) is the end of cmdline buf */
ret = syscall(__NR_shellexec, argv[0], cmdLine);
free(cmdLine);
return ret;
}
static void ShellSigChildHook(int sig)
{
(void)sig;
while (waitpid(-1, NULL, WNOHANG) > 0) {
continue;
}
}
int main(int argc, char **argv)
{ {
int ret = SH_NOK; int ret = SH_NOK;
ShellCB *shellCB = NULL; ShellCB *shellCB = NULL;
(void)signal(SIGCHLD, ShellSigChildHook);
if (argc > 1) {
ret = DoShellExec(argv + 1);
return ret;
}
setbuf(stdout, NULL); setbuf(stdout, NULL);
shellCB = (ShellCB *)malloc(sizeof(ShellCB)); shellCB = (ShellCB *)malloc(sizeof(ShellCB));
if (shellCB == NULL) { if (shellCB == NULL) {
return SH_NOK; goto ERR_OUT1;
} }
ret = memset_s(shellCB, sizeof(ShellCB), 0, sizeof(ShellCB)); ret = memset_s(shellCB, sizeof(ShellCB), 0, sizeof(ShellCB));
if (ret != SH_OK) { if (ret != SH_OK) {
@ -170,14 +128,7 @@ int main(int argc, char **argv)
sem_init(&shellCB->shellSem, 0, 0); sem_init(&shellCB->shellSem, 0, 0);
g_shellCB = shellCB; g_shellCB = shellCB;
ret = OsShellCreateTask(shellCB); return OsShellCreateTask(shellCB);
if (ret != SH_OK) {
ShellDeinit(shellCB);
g_shellCB = NULL;
return ret;
}
ShellEntry(shellCB);
ERR_OUT3: ERR_OUT3:
(void)pthread_mutex_destroy(&shellCB->historyMutex); (void)pthread_mutex_destroy(&shellCB->historyMutex);
@ -188,3 +139,8 @@ ERR_OUT1:
return ret; return ret;
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

47
apps/shell/src/shcmd.c Normal file → Executable file
View File

@ -36,6 +36,12 @@
#include "dirent.h" #include "dirent.h"
#include "securec.h" #include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define SHELL_INIT_MAGIC_FLAG 0xABABABAB #define SHELL_INIT_MAGIC_FLAG 0xABABABAB
#define CTRL_C 0x03 /* 0x03: ctrl+c ASCII */ #define CTRL_C 0x03 /* 0x03: ctrl+c ASCII */
@ -79,7 +85,7 @@ static int OsStrSeparateTabStrGet(const char **tabStr, CmdParsed *parsed, unsign
if ((strlen(shiftStr) == 0) || (tempStr[strlen(tempStr) - 1] != shiftStr[strlen(shiftStr) - 1])) { if ((strlen(shiftStr) == 0) || (tempStr[strlen(tempStr) - 1] != shiftStr[strlen(shiftStr) - 1])) {
*tabStr = ""; *tabStr = "";
} else { } else {
if (OsCmdParse(shiftStr, parsed)) { if (OsCmdTokenSplit(shiftStr, ' ', parsed)) {
free(tempStr); free(tempStr);
return (int)SH_ERROR; return (int)SH_ERROR;
} }
@ -90,12 +96,12 @@ static int OsStrSeparateTabStrGet(const char **tabStr, CmdParsed *parsed, unsign
return SH_OK; return SH_OK;
} }
char *OsShellGetWorkingDirectory(void) char *OsShellGetWorkingDirtectory()
{ {
return OsGetShellCb()->shellWorkingDirectory; return OsGetShellCb()->shellWorkingDirectory;
} }
int OsShellSetWorkingDirectory(const char *dir, size_t len) int OsShellSetWorkingDirtectory(const char *dir, size_t len)
{ {
if (dir == NULL) { if (dir == NULL) {
return SH_NOK; return SH_NOK;
@ -114,7 +120,7 @@ static int OsStrSeparate(const char *tabStr, char *strPath, char *nameLooking, u
char *strEnd = NULL; char *strEnd = NULL;
char *cutPos = NULL; char *cutPos = NULL;
CmdParsed parsed = {0}; CmdParsed parsed = {0};
char *shellWorkingDirectory = OsShellGetWorkingDirectory(); char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
int ret; int ret;
ret = OsStrSeparateTabStrGet(&tabStr, &parsed, tabStrLen); ret = OsStrSeparateTabStrGet(&tabStr, &parsed, tabStrLen);
@ -195,7 +201,7 @@ static int OsSurePrintAll(unsigned int count)
char readChar = 0; char readChar = 0;
printf("\nDisplay all %u possibilities?(y/n)", count); printf("\nDisplay all %u possibilities?(y/n)", count);
while (1) { while (1) {
if (read(STDIN_FILENO, &readChar, 1) != 1) { if (read(0, &readChar, 1) != 1) {
return (int)SH_ERROR; return (int)SH_ERROR;
} }
if ((readChar == 'n') || (readChar == 'N') || (readChar == CTRL_C)) { if ((readChar == 'n') || (readChar == 'N') || (readChar == CTRL_C)) {
@ -222,7 +228,7 @@ static int OsPrintMatchList(unsigned int count, const char *strPath, const char
return (int)SH_ERROR; return (int)SH_ERROR;
} }
if (count > (lineCap * DEFAULT_SCREEN_HEIGHT)) { if (count > (lineCap * DEFAULT_SCREEN_HEIGNT)) {
ret = OsSurePrintAll(count); ret = OsSurePrintAll(count);
if (ret != 1) { if (ret != 1) {
return ret; return ret;
@ -374,10 +380,10 @@ static int OsTabMatchFile(char *cmdKey, unsigned int *len)
} }
/* /*
* Description: Pass in the string and clear useless space ,which include: * Description: Pass in the string and clear useless space ,which inlcude:
* 1) The overmatch space which is not be marked by Quote's area * 1) The overmatch space which is not be marked by Quote's area
* Squeeze the overmatch space into one space * Squeeze the overmatch space into one space
* 2) Clear all space before first valid character * 2) Clear all space before first vaild charatctor
* Input: cmdKey : Pass in the buff string, which is ready to be operated * Input: cmdKey : Pass in the buff string, which is ready to be operated
* cmdOut : Pass out the buffer string ,which has already been operated * cmdOut : Pass out the buffer string ,which has already been operated
* size : cmdKey length * size : cmdKey length
@ -406,17 +412,17 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
/* Backup the 'output' start address */ /* Backup the 'output' start address */
outputBak = output; outputBak = output;
/* Scan each character in 'cmdKey',and squeeze the overmuch space and ignore invalid character */ /* Scan each charactor in 'cmdKey',and squeeze the overmuch space and ignore invaild charactor */
for (; *cmdKey != '\0'; cmdKey++) { for (; *cmdKey != '\0'; cmdKey++) {
/* Detected a Double Quotes, switch the matching status */ /* Detected a Double Quotes, switch the matching status */
if (*(cmdKey) == '\"') { if (*(cmdKey) == '\"') {
SWITCH_QUOTES_STATUS(quotes); SWITCH_QUOTES_STATUS(quotes);
} }
/* Ignore the current character in following situation */ /* Ignore the current charactor in following situation */
/* 1) Quotes matching status is FALSE (which said that the space is not been marked by double quotes) */ /* 1) Quotes matching status is FALSE (which said that the space is not been marked by double quotes) */
/* 2) Current character is a space */ /* 2) Current charactor is a space */
/* 3) Next character is a space too, or the string is been seeked to the end already(\0) */ /* 3) Next charactor is a space too, or the string is been seeked to the end already(\0) */
/* 4) Invalid character, such as single quotes */ /* 4) Invaild charactor, such as single quotes */
if ((*cmdKey == ' ') && ((*(cmdKey + 1) == ' ') || (*(cmdKey + 1) == '\0')) && QUOTES_STATUS_CLOSE(quotes)) { if ((*cmdKey == ' ') && ((*(cmdKey + 1) == ' ') || (*(cmdKey + 1) == '\0')) && QUOTES_STATUS_CLOSE(quotes)) {
continue; continue;
} }
@ -430,7 +436,7 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
/* Restore the 'output' start address */ /* Restore the 'output' start address */
output = outputBak; output = outputBak;
len = strlen(output); len = strlen(output);
/* Clear the space which is located at the first character in buffer */ /* Clear the space which is located at the first charactor in buffer */
if (*output == ' ') { if (*output == ' ') {
output++; output++;
len--; len--;
@ -447,15 +453,20 @@ unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
free(outputBak); free(outputBak);
return SH_OK; return SH_OK;
} }
int OsTabCompletion(char *cmdKey, unsigned int *len) int OsTabCompletion(char *cmdKey, unsigned int *len)
{ {
int count; int count;
char *cmdMainStr = cmdKey;
if ((cmdKey == NULL) || (len == NULL)) { if ((cmdKey == NULL) || (len == NULL)) {
return (int)SH_ERROR; return (int)SH_ERROR;
} }
/* cut left space */
while (*cmdMainStr == 0x20) {
cmdMainStr++;
}
count = OsTabMatchFile(cmdKey, len); count = OsTabMatchFile(cmdKey, len);
return count; return count;
@ -584,6 +595,7 @@ END:
unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr) unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr)
{ {
/* TODO: complete the usrspace command */
unsigned int ret = SH_OK; unsigned int ret = SH_OK;
if (cmdParsed && cmdStr) { if (cmdParsed && cmdStr) {
ret = SH_NOK; ret = SH_NOK;
@ -592,3 +604,8 @@ unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr)
return ret; return ret;
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

10
apps/shell/src/shcmdparse.c Normal file → Executable file
View File

@ -32,6 +32,11 @@
#include "shcmd.h" #include "shcmd.h"
#include "sherr.h" #include "sherr.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* /*
* Filter out double quote or single-quoted strings at both ends * Filter out double quote or single-quoted strings at both ends
@ -152,3 +157,8 @@ unsigned int OsCmdParse(char *cmdStr, CmdParsed *cmdParsed)
return OsCmdTokenSplit(cmdStr, ' ', cmdParsed); return OsCmdTokenSplit(cmdStr, ' ', cmdParsed);
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

204
apps/shell/src/shmsg.c Normal file → Executable file
View File

@ -29,8 +29,6 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#define _GNU_SOURCE
#include "stdlib.h" #include "stdlib.h"
#include "stdio.h" #include "stdio.h"
#include "unistd.h" #include "unistd.h"
@ -44,10 +42,12 @@
#include "shell_pri.h" #include "shell_pri.h"
#include "shcmd.h" #include "shcmd.h"
#define CHAR_CTRL_C '\x03' #ifdef __cplusplus
#define CHAR_CTRL_DEL '\x7F' #if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define VISIABLE_CHAR(ch) ((ch) > 0x1F && (ch) < 0x7F)
char *GetCmdline(ShellCB *shellCB) char *GetCmdline(ShellCB *shellCB)
{ {
@ -133,7 +133,7 @@ int ShellNotify(ShellCB *shellCB)
} }
enum { enum {
STAT_NORMAL_KEY, STAT_NOMAL_KEY,
STAT_ESC_KEY, STAT_ESC_KEY,
STAT_MULTI_KEY STAT_MULTI_KEY
}; };
@ -152,23 +152,23 @@ static int ShellCmdLineCheckUDRL(const char ch, ShellCB *shellCB)
} else if (ch == 0x41) { /* up */ } else if (ch == 0x41) { /* up */
if (shellCB->shellKeyType == STAT_MULTI_KEY) { if (shellCB->shellKeyType == STAT_MULTI_KEY) {
OsShellHistoryShow(CMD_KEY_UP, shellCB); OsShellHistoryShow(CMD_KEY_UP, shellCB);
shellCB->shellKeyType = STAT_NORMAL_KEY; shellCB->shellKeyType = STAT_NOMAL_KEY;
return ret; return ret;
} }
} else if (ch == 0x42) { /* down */ } else if (ch == 0x42) { /* down */
if (shellCB->shellKeyType == STAT_MULTI_KEY) { if (shellCB->shellKeyType == STAT_MULTI_KEY) {
shellCB->shellKeyType = STAT_NORMAL_KEY; shellCB->shellKeyType = STAT_NOMAL_KEY;
OsShellHistoryShow(CMD_KEY_DOWN, shellCB); OsShellHistoryShow(CMD_KEY_DOWN, shellCB);
return ret; return ret;
} }
} else if (ch == 0x43) { /* right */ } else if (ch == 0x43) { /* right */
if (shellCB->shellKeyType == STAT_MULTI_KEY) { if (shellCB->shellKeyType == STAT_MULTI_KEY) {
shellCB->shellKeyType = STAT_NORMAL_KEY; shellCB->shellKeyType = STAT_NOMAL_KEY;
return ret; return ret;
} }
} else if (ch == 0x44) { /* left */ } else if (ch == 0x44) { /* left */
if (shellCB->shellKeyType == STAT_MULTI_KEY) { if (shellCB->shellKeyType == STAT_MULTI_KEY) {
shellCB->shellKeyType = STAT_NORMAL_KEY; shellCB->shellKeyType = STAT_NOMAL_KEY;
return ret; return ret;
} }
} }
@ -205,21 +205,7 @@ void ParseEnterKey(OutputFunc outputFunc, ShellCB *shellCB)
shellCB->shellBuf[shellCB->shellBufOffset] = '\0'; shellCB->shellBuf[shellCB->shellBufOffset] = '\0';
} }
NOTIFY: NOTIFY:
shellCB->shellBufOffset = 0; outputFunc("\n");
ShellTaskNotify(shellCB);
}
void ParseCancelKey(OutputFunc outputFunc, ShellCB *shellCB)
{
if ((shellCB == NULL) || (outputFunc == NULL)) {
return;
}
if (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1)) {
shellCB->shellBuf[0] = CHAR_CTRL_C;
shellCB->shellBuf[1] = '\0';
}
shellCB->shellBufOffset = 0; shellCB->shellBufOffset = 0;
ShellTaskNotify(shellCB); ShellTaskNotify(shellCB);
} }
@ -255,7 +241,7 @@ void ParseTabKey(OutputFunc outputFunc, ShellCB *shellCB)
void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB) void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
{ {
if ((shellCB == NULL) || (outputFunc == NULL) || !VISIABLE_CHAR(ch)) { if ((shellCB == NULL) || (outputFunc == NULL)) {
return; return;
} }
@ -265,7 +251,7 @@ void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
outputFunc("%c", ch); outputFunc("%c", ch);
} }
shellCB->shellKeyType = STAT_NORMAL_KEY; shellCB->shellKeyType = STAT_NOMAL_KEY;
} }
void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB) void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
@ -273,7 +259,7 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
const char ch = c; const char ch = c;
int ret; int ret;
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != CHAR_CTRL_C) && (ch != '\0')) { if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != '\0')) {
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN); (void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
} }
@ -282,11 +268,8 @@ void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
case '\n': /* enter */ case '\n': /* enter */
ParseEnterKey(outputFunc, shellCB); ParseEnterKey(outputFunc, shellCB);
break; break;
case CHAR_CTRL_C: /* ctrl + c */
ParseCancelKey(outputFunc, shellCB);
break;
case '\b': /* backspace */ case '\b': /* backspace */
case CHAR_CTRL_DEL: /* delete(0x7F) */ case 0x7F: /* delete(0x7F) */
ParseDeleteKey(outputFunc, shellCB); ParseDeleteKey(outputFunc, shellCB);
break; break;
case '\t': /* tab */ case '\t': /* tab */
@ -334,12 +317,12 @@ char *GetCmdName(const char *cmdline, unsigned int len)
/* If reach a double quotes, switch the quotes matching status */ /* If reach a double quotes, switch the quotes matching status */
if (*tmpStr == '\"') { if (*tmpStr == '\"') {
SWITCH_QUOTES_STATUS(quotes); SWITCH_QUOTES_STATUS(quotes);
/* Ignore the double quote character itself */ /* Ignore the double quote charactor itself */
tmpStr++; tmpStr++;
continue; continue;
} }
/* If detected a space which the quotes matching status is false */ /* If detected a space which the quotes matching status is false */
/* which said has detected the first space for separator, finish this scan operation */ /* which said has detected the first space for seperator, finish this scan operation */
if ((*tmpStr == ' ') && (QUOTES_STATUS_CLOSE(quotes))) { if ((*tmpStr == ' ') && (QUOTES_STATUS_CLOSE(quotes))) {
break; break;
} }
@ -351,94 +334,29 @@ char *GetCmdName(const char *cmdline, unsigned int len)
return cmdName; return cmdName;
} }
void ChildExec(const char *cmdName, char *const paramArray[], bool foreground) static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, const CmdParsed *cmdParsed)
{ {
int ret; int ret;
pid_t gid; pid_t forkPid;
if (strncmp(cmdline, SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
forkPid = fork();
if (forkPid < 0) {
printf("Faild to fork from shell\n");
return;
} else if (forkPid == 0) {
ret = setpgrp(); ret = setpgrp();
if (ret == -1) { if (ret == -1) {
exit(1); exit(1);
} }
gid = getpgrp(); ret = execve((const char *)cmdParsed->paramArray[0], (char * const *)cmdParsed->paramArray, NULL);
if (gid < 0) {
printf("get group id failed, pgrpid %d, errno %d\n", gid, errno);
exit(1);
}
if (!foreground) {
ret = tcsetpgrp(STDIN_FILENO, gid);
if (ret != 0) {
printf("tcsetpgrp failed, errno %d\n", errno);
exit(1);
}
}
ret = execve(cmdName, paramArray, NULL);
if (ret == -1) { if (ret == -1) {
perror("execve"); perror("execve");
exit(-1); exit(-1);
} }
} }
int CheckExit(const char *cmdName, const CmdParsed *cmdParsed)
{
int ret = 0;
if (strlen(cmdName) != CMD_EXIT_COMMAND_BYTES || strncmp(cmdName, CMD_EXIT_COMMAND, CMD_EXIT_COMMAND_BYTES) != 0) {
return 0;
}
if (cmdParsed->paramCnt > 1) {
printf("exit: too many arguments\n");
return -1;
}
if (cmdParsed->paramCnt == 1) {
char *p = NULL;
ret = strtol(cmdParsed->paramArray[0], &p, CMD_EXIT_CODE_BASE_DEC);
if (*p != '\0') {
printf("exit: bad number: %s\n", cmdParsed->paramArray[0]);
return -1;
}
}
exit(ret);
}
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, CmdParsed *cmdParsed)
{
bool foreground = FALSE;
int ret;
pid_t forkPid;
if (strncmp(cmdline, CMD_EXEC_COMMAND, CMD_EXEC_COMMAND_BYTES) == 0) {
if ((cmdParsed->paramCnt > 1) && (strcmp(cmdParsed->paramArray[cmdParsed->paramCnt - 1], "&") == 0)) {
free(cmdParsed->paramArray[cmdParsed->paramCnt - 1]);
cmdParsed->paramArray[cmdParsed->paramCnt - 1] = NULL;
cmdParsed->paramCnt--;
foreground = TRUE;
}
forkPid = fork();
if (forkPid < 0) {
printf("Failed to fork from shell\n");
return;
} else if (forkPid == 0) {
ChildExec(cmdParsed->paramArray[0], cmdParsed->paramArray, foreground);
} else { } else {
if (!foreground) {
(void)waitpid(forkPid, 0, 0);
}
ret = tcsetpgrp(STDIN_FILENO, getpid());
if (ret != 0) {
printf("tcsetpgrp failed, errno %d\n", errno);
}
}
} else {
if (CheckExit(cmdName, cmdParsed) < 0) {
return;
}
(void)syscall(__NR_shellexec, cmdName, cmdline); (void)syscall(__NR_shellexec, cmdName, cmdline);
} }
} }
@ -473,7 +391,7 @@ static void ParseAndExecCmdline(CmdParsed *cmdParsed, const char *cmdline, unsig
DoCmdExec(cmdName, cmdlineOrigin, len, cmdParsed); DoCmdExec(cmdName, cmdlineOrigin, len, cmdParsed);
if (getcwd(shellWorkingDirectory, PATH_MAX) != NULL) { if (getcwd(shellWorkingDirectory, PATH_MAX) != NULL) {
(void)OsShellSetWorkingDirectory(shellWorkingDirectory, (PATH_MAX + 1)); (void)OsShellSetWorkingDirtectory(shellWorkingDirectory, (PATH_MAX + 1));
} }
OUT: OUT:
@ -493,7 +411,7 @@ unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *ou
unsigned int removeLen = strlen("./"); /* "./" needs to be removed if it exists */ unsigned int removeLen = strlen("./"); /* "./" needs to be removed if it exists */
unsigned int ret; unsigned int ret;
char *newCmd = NULL; char *newCmd = NULL;
char *execCmd = CMD_EXEC_COMMAND; char *execCmd = SHELL_EXEC_COMMAND;
const char *cmdBuf = input; const char *cmdBuf = input;
unsigned int cmdBufLen = strlen(cmdBuf); unsigned int cmdBufLen = strlen(cmdBuf);
char *shiftStr = (char *)malloc(cmdBufLen + 1); char *shiftStr = (char *)malloc(cmdBufLen + 1);
@ -515,7 +433,7 @@ unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *ou
*output = shiftStr; *output = shiftStr;
*outputlen = shiftLen; *outputlen = shiftLen;
/* Check and parse "./", located at the first two characters of the cmd */ /* Check and parse "./", located at the first two charaters of the cmd */
if ((shiftLen > removeLen) && (shiftStr[0] == '.') && (shiftStr[1] == '/')) { if ((shiftLen > removeLen) && (shiftStr[0] == '.') && (shiftStr[1] == '/')) {
execLen = strlen(execCmd); execLen = strlen(execCmd);
newLen = execLen + shiftLen - removeLen; /* i.e., newLen - execLen == shiftLen - removeLen */ newLen = execLen + shiftLen - removeLen; /* i.e., newLen - execLen == shiftLen - removeLen */
@ -579,18 +497,24 @@ static void ExecCmdline(const char *cmdline)
free(output); free(output);
} }
void RecycleZombieChild(void)
{
while (waitpid(-1, NULL, WNOHANG) > 0) {
continue;
}
}
static void ShellCmdProcess(ShellCB *shellCB) static void ShellCmdProcess(ShellCB *shellCB)
{ {
char *buf = NULL;
while (1) { while (1) {
char *buf = GetCmdline(shellCB); /* recycle zombine child process */
RecycleZombieChild();
buf = GetCmdline(shellCB);
if (buf == NULL) { if (buf == NULL) {
break; break;
} }
if (buf[0] == CHAR_CTRL_C) {
printf("^C");
buf[0] = '\n';
}
printf("\n");
ExecCmdline(buf); ExecCmdline(buf);
ShellSaveHistoryCmd(buf, shellCB); ShellSaveHistoryCmd(buf, shellCB);
shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink; shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink;
@ -653,22 +577,28 @@ int ShellTaskInit(ShellCB *shellCB)
static int ShellKernelReg(unsigned int shellHandle) static int ShellKernelReg(unsigned int shellHandle)
{ {
return ioctl(STDIN_FILENO, CONSOLE_CONTROL_REG_USERTASK, shellHandle); return ioctl(0, CONSOLE_CONTROL_REG_USERTASK, shellHandle);
} }
void ShellEntry(ShellCB *shellCB) void *ShellEntry(void *argv)
{ {
char ch; char ch;
int ret; int ret;
int n; int n;
pid_t tid = syscall(__NR_gettid); pid_t tid = syscall(__NR_gettid);
ShellCB *shellCB = (ShellCB *)argv;
if (shellCB == NULL) { if (shellCB == NULL) {
return; return NULL;
} }
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN); (void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
ret = prctl(PR_SET_NAME, "ShellEntry");
if (ret != SH_OK) {
return NULL;
}
ret = ShellKernelReg((int)tid); ret = ShellKernelReg((int)tid);
if (ret != 0) { if (ret != 0) {
printf("another shell is already running!\n"); printf("another shell is already running!\n");
@ -681,5 +611,37 @@ void ShellEntry(ShellCB *shellCB)
ShellCmdLineParse(ch, (OutputFunc)printf, shellCB); ShellCmdLineParse(ch, (OutputFunc)printf, shellCB);
} }
} }
return; return NULL;
} }
int ShellEntryInit(ShellCB *shellCB)
{
int ret;
size_t stackSize = SHELL_ENTRY_STACKSIZE;
void *arg = NULL;
pthread_attr_t attr;
if (shellCB == NULL) {
return SH_NOK;
}
ret = pthread_attr_init(&attr);
if (ret != SH_OK) {
return SH_NOK;
}
pthread_attr_setstacksize(&attr, stackSize);
arg = (void *)shellCB;
ret = pthread_create(&shellCB->shellEntryHandle, &attr, &ShellEntry, arg);
if (ret != SH_OK) {
return SH_NOK;
}
return ret;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

View File

@ -1,41 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//kernel/liteos_a/liteos.gni")
executable("tftp") {
sources = [
"src/main.c",
"src/tftpc.c",
]
deps = [ "$LITEOSTHIRDPARTY/bounds_checking_function:libsec_static" ]
include_dirs = [ "include" ]
}

View File

@ -27,19 +27,51 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include $(APPSTOPDIR)/config.mk ROOT_DIR := $(dir $(shell pwd))/tftp/
APP_NAME := $(notdir $(shell pwd)) ifeq ($(APPSTOPDIR), )
APPSTOPDIR := $(shell pwd)/../
LITEOSTOPDIR = $(APPSTOPDIR)/../
endif
include $(ROOT_DIR)/../config.mk
APPS_OUT := $(OUT)/bin
SECUREC_DIR := $(LITEOSTHIRDPARTY)/bounds_checking_function SECUREC_DIR := $(LITEOSTHIRDPARTY)/bounds_checking_function
LOCAL_SRCS = $(wildcard src/*.c) LOCAL_SRCS = $(wildcard src/*.c)
LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/*.c) LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/strncpy_s.c)
LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/memcpy_s.c)
LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/memset_s.c)
LOCAL_SRCS += $(wildcard $(SECUREC_DIR)/src/strncat_s.c)
LOCAL_OBJ := $(LOCAL_SRCS:.c=.o)
LOCAL_INCLUDE := \ LOCAL_INCLUDE := \
-I include \ -I $(ROOT_DIR)/include/ \
-I $(SECUREC_DIR)/include -I $(SECUREC_DIR)/include/\
LOCAL_FLAGS += $(LOCAL_INCLUDE) LOCAL_FLAGS += $(CFLAGS)
include $(APP) LDPATH := -L$(ROOT_DIR)/
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-bitwise-op-parentheses $(LLVM_SYSROOT)
LDCFLAGS += $(LLVM_EXTRA_LD_OPTS) $(LLVM_SYSROOT)
endif
TARGETNAME := tftp
all: $(TARGETNAME)
$(LOCAL_OBJ): %.o : %.c
$(HIDE) $(CC) $(LOCAL_FLAGS) -fPIE $(LOCAL_INCLUDE) -c $< -o $@
$(TARGETNAME): $(LOCAL_OBJ)
$(HIDE) $(CC) -pie -s $(LDPATH) $(BASE_OPTS) -o $(TARGETNAME) $^ $(LDCFLAGS)
$(HIDE) mkdir -p $(APPS_OUT)
$(HIDE) $(MV) $(TARGETNAME) $(APPS_OUT)
$(HIDE) $(RM) $(LOCAL_OBJ)
clean:
$(HIDE) $(RM) $(LOCAL_OBJ)
$(HIDE) $(RM) $(TARGETNAME)
.PHONY: all $(TARGETNAME) clean

View File

@ -42,7 +42,7 @@ extern "C" {
#define TFTP_NULL_UINT32 ((u32_t)0xffffffffUL) #define TFTP_NULL_UINT32 ((u32_t)0xffffffffUL)
#define TFTP_NULL_INT32 (-1) #define TFTP_NULL_INT32 -1
/** @cond liteos /** @cond liteos
* @defgroup TFTP_Interfaces * @defgroup TFTP_Interfaces
@ -114,7 +114,7 @@ typedef enum tagTFTPC_OpCode {
TFTPC_OP_RRQ = 1, /* read request */ TFTPC_OP_RRQ = 1, /* read request */
TFTPC_OP_WRQ, /* write request */ TFTPC_OP_WRQ, /* write request */
TFTPC_OP_DATA, /* data packet */ TFTPC_OP_DATA, /* data packet */
TFTPC_OP_ACK, /* acknowledgment */ TFTPC_OP_ACK, /* acknowledgement */
TFTPC_OP_ERROR, /* error code */ TFTPC_OP_ERROR, /* error code */
TFTPC_OP_OPT /* option code */ TFTPC_OP_OPT /* option code */
} TFTPC_OPCODE_E; } TFTPC_OPCODE_E;

View File

@ -50,11 +50,11 @@ static char *TftpError[] = {
"Error while sending data to the peer\n", "Error while sending data to the peer\n",
"Requested file is not found\n", "Requested file is not found\n",
"This is the error sent by the server when hostname cannot be resolved\n", "This is the error sent by the server when hostname cannot be resolved\n",
"Input parameters passed to TFTP interfaces are invalid\n", "Input paramters passed to TFTP interfaces are invalid\n",
"Error detected in TFTP packet or the error received from the TFTP server\n", "Error detected in TFTP packet or the error received from the TFTP server\n",
"Error during packet synhronization while sending or unexpected packet is received\n", "Error during packet synhronization while sending or unexpected packet is received\n",
"File size limit crossed, Max block can be 0xFFFF, each block containing 512 bytes\n", "File size limit crossed, Max block can be 0xFFFF, each block containing 512 bytes\n",
"File name length greater than 256\n", "File name lenght greater than 256\n",
"Hostname IP is not valid\n", "Hostname IP is not valid\n",
"TFTP server returned file access error\n", "TFTP server returned file access error\n",
"TFTP server returned error signifying that the DISK is full to write\n", "TFTP server returned error signifying that the DISK is full to write\n",
@ -66,11 +66,11 @@ static char *TftpError[] = {
"File create error\n", "File create error\n",
"File write error\n", "File write error\n",
"Max time expired while waiting for file to be recived\n", "Max time expired while waiting for file to be recived\n",
"Error when the received packet is less than 4bytes(error length) or greater than 512bytes\n", "Error when the received packet is less than 4bytes(error lenght) or greater than 512bytes\n",
"Returned by TFTP server for protocol user error\n", "Returned by TFTP server for protocol user error\n",
"The destination file path length greater than 256\n", "The destination file path length greater than 256\n",
"Returned by TFTP server for undefined transfer ID\n", "Returned by TFTP server for undefined transfer ID\n",
"IOCTL function failed at TFTP client while setting the socket to non-block\n", "IOCTL fucntion failed at TFTP client while setting the socket to non-block\n",
}; };
#ifndef ARRAY_SIZE #ifndef ARRAY_SIZE

View File

@ -189,7 +189,7 @@ u32_t lwip_tftp_recv_from_server(s32_t iSockNum, u32_t *pulSize, TFTPC_PACKET_S
if (iRet == -1) { if (iRet == -1) {
return TFTPC_SELECT_ERROR; return TFTPC_SELECT_ERROR;
} else if (iRet == 0) { } else if (iRet == 0) {
return TFTPC_TIMEOUT_ERROR; /* Select timeout occurred */ return TFTPC_TIMEOUT_ERROR; /* Select timeout occured */
} }
if (!FD_ISSET(iSockNum, &stReadfds)) { if (!FD_ISSET(iSockNum, &stReadfds)) {
@ -268,7 +268,7 @@ u32_t lwip_tftp_recv_from_server(s32_t iSockNum, u32_t *pulSize, TFTPC_PACKET_S
*pulSize = (u32_t)iRet; *pulSize = (u32_t)iRet;
/* If received packet is first block of data(for get operation) or if /* If received packet is first block of data(for get operation) or if
received packet is acknowledgment for write request (put operation) received packet is acknowledgement for write request (put operation)
store the received port number */ store the received port number */
if (((usOpcode == TFTPC_OP_DATA) && if (((usOpcode == TFTPC_OP_DATA) &&
(ntohs(pstRecvBuf->u.stTFTP_Data.usBlknum) == 1)) || (ntohs(pstRecvBuf->u.stTFTP_Data.usBlknum) == 1)) ||
@ -500,7 +500,7 @@ static void lwip_tftp_send_error(s32_t iSockNum, u32_t ulError, const char *szEr
} }
} }
/* INTERFACE to get a file using filename /* INTEFACE to get a file using filename
ulHostAddr - IP address of Host ulHostAddr - IP address of Host
szSrcFileName - Source file szSrcFileName - Source file
szDestDirPath - Destination file path szDestDirPath - Destination file path
@ -687,7 +687,7 @@ u32_t lwip_tftp_get_file_by_filename(u32_t ulHostAddr,
ulErrCode = lwip_tftp_recv_from_server(iSockNum, &ulRecvSize, pstRecvBuf, ulErrCode = lwip_tftp_recv_from_server(iSockNum, &ulRecvSize, pstRecvBuf,
&ulIgnorePkt, &stServerAddr, pstSendBuf); &ulIgnorePkt, &stServerAddr, pstSendBuf);
/* If select timeout occurred */ /* If select timeout occured */
if (ulErrCode == TFTPC_TIMEOUT_ERROR) { if (ulErrCode == TFTPC_TIMEOUT_ERROR) {
ulTotalTime++; ulTotalTime++;
if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) { if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) {
@ -982,7 +982,7 @@ u32_t lwip_tftp_put_file_by_filename(u32_t ulHostAddr, u16_t usTftpServPort, u8_
return TFTPC_MEMALLOC_ERROR; return TFTPC_MEMALLOC_ERROR;
} }
/* First time initialize the buffer */ /* First time intialize the buffer */
(void)memset_s((void *)pstSendBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S)); (void)memset_s((void *)pstSendBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
/* The destination path can only be one of the following: /* The destination path can only be one of the following:
@ -1221,7 +1221,7 @@ u32_t lwip_tftp_inner_put_file(s32_t iSockNum,
return TFTPC_MEMALLOC_ERROR; return TFTPC_MEMALLOC_ERROR;
} }
/* First time initialize the buffer */ /* First time intialize the buffer */
(void)memset_s((void *)pstRecvBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S)); (void)memset_s((void *)pstRecvBuf, sizeof(TFTPC_PACKET_S), 0, sizeof(TFTPC_PACKET_S));
/* Initialize from address to the server address at first */ /* Initialize from address to the server address at first */
@ -1235,7 +1235,7 @@ u32_t lwip_tftp_inner_put_file(s32_t iSockNum,
ulError = lwip_tftp_recv_from_server(iSockNum, &ulPktSize, ulError = lwip_tftp_recv_from_server(iSockNum, &ulPktSize,
pstRecvBuf, &ulIgnorePkt, pstRecvBuf, &ulIgnorePkt,
pstServerAddr, pstSendBuf); pstServerAddr, pstSendBuf);
/* If select timeout occurred */ /* If select timeout occured */
if (ulError == TFTPC_TIMEOUT_ERROR) { if (ulError == TFTPC_TIMEOUT_ERROR) {
ulTotalTime++; ulTotalTime++;
if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) { if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) {
@ -1419,7 +1419,7 @@ err_handler:
} }
#ifdef TFTP_TO_RAWMEM #ifdef TFTP_TO_RAWMEM
/* INTERFACE to get a file using filename /* INTEFACE to get a file using filename
ulHostAddr - IP address of Host ulHostAddr - IP address of Host
szSrcFileName - Source file szSrcFileName - Source file
szDestMemAddr - The target memory address in the client szDestMemAddr - The target memory address in the client
@ -1437,8 +1437,10 @@ u32_t lwip_tftp_get_file_by_filename_to_rawmem(u32_t ulHostAddr,
{ {
s32_t iSockNum = TFTP_NULL_INT32; s32_t iSockNum = TFTP_NULL_INT32;
u32_t ulSrcStrLen; u32_t ulSrcStrLen;
u32_t lDestStrLen;
u32_t ulSize; u32_t ulSize;
u32_t ulRecvSize = TFTP_NULL_UINT32; u32_t ulRecvSize = TFTP_NULL_UINT32;
s32_t iErrCode;
u32_t ulErrCode; u32_t ulErrCode;
u16_t usReadReq; u16_t usReadReq;
u16_t usTempServPort; u16_t usTempServPort;
@ -1524,7 +1526,7 @@ u32_t lwip_tftp_get_file_by_filename_to_rawmem(u32_t ulHostAddr,
ulErrCode = lwip_tftp_recv_from_server(iSockNum, &ulRecvSize, pstRecvBuf, &ulIgnorePkt, ulErrCode = lwip_tftp_recv_from_server(iSockNum, &ulRecvSize, pstRecvBuf, &ulIgnorePkt,
&stServerAddr, pstSendBuf); &stServerAddr, pstSendBuf);
/* If select timeout occurred */ /* If select timeout occured */
if (ulErrCode == TFTPC_TIMEOUT_ERROR) { if (ulErrCode == TFTPC_TIMEOUT_ERROR) {
ulTotalTime++; ulTotalTime++;
if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) { if (ulTotalTime < TFTPC_MAX_SEND_REQ_ATTEMPTS) {

View File

@ -1,84 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//build/lite/config/component/lite_component.gni")
import("//kernel/liteos_a/liteos.gni")
import("$THIRDPARTY_TOYBOX_DIR/toybox.gni")
group("toybox") {
deps = [ ":build_toybox" ]
}
copy("copy_toybox_src") {
sources = TOYBOX_SRC_DIR
outputs = [ "$target_out_dir/toybox_build" ]
}
copy("copy_toybox_config") {
deps = [ ":copy_toybox_src" ]
sources = [ "liteos_a_custom.config" ]
outputs = [ "$target_out_dir/{{source_file_part}}" ]
}
build_ext_component("build_toybox") {
deps = [
":copy_toybox_config",
":copy_toybox_src",
]
deps += [ "$THIRDPARTY_MUSL_DIR:sysroot_lite" ]
exec_path = rebase_path("$target_out_dir/toybox_build")
cflags = [
"-fstack-protector-strong",
"-D_FORTIFY_SOURCE=2",
]
cflags = string_join(" ", cflags)
extra_flags = string_join(" ", target_arch_cflags)
if (ohos_build_compiler == "clang") {
extra_flags += " --target=$target_triple"
extra_flags += " --sysroot=" + rebase_path(ohos_current_sysroot)
}
command = "rm -rf .git && cp -rfp porting/liteos_a/. . && env"
command += " CC=\"$ohos_current_cc_command\""
command += " STRIP=\"$ohos_current_strip_command\""
command += " OUTNAME=toybox"
command += " CFLAGS=\"$cflags $extra_flags\""
command += " make toybox"
command += " && install -D toybox "
command += rebase_path("$root_out_dir/bin/toybox", exec_path)
command += " && install -D generated/unstripped/toybox "
command += rebase_path("$root_out_dir/unstripped/bin/toybox", exec_path)
outputs = [
"$root_out_dir/unstripped/bin/toybox",
"$root_out_dir/bin/toybox",
]
}

View File

@ -1,53 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
include $(APPSTOPDIR)/config.mk
BUILD_DIR := $(OUT)/toybox_build
BUILD_LOG := $(BUILD_DIR)/build.log
CFLAGS += -Wno-error
all:
ifneq ($(wildcard $(BUILD_DIR)),)
$(HIDE)echo "not clean, rebuilding now"
else
$(HIDE)mkdir -p $(BUILD_DIR)
$(HIDE)$(CP) $(LITEOSTHIRDPARTY)/toybox/. $(BUILD_DIR)
$(HIDE)$(CP) $(LITEOSTHIRDPARTY)/toybox/porting/liteos_a/. $(BUILD_DIR)
$(HIDE)$(CP) liteos_a_custom.config $(BUILD_DIR)/../
endif
$(HIDE)unset KCONFIG_CONFIG CROSS_COMPILE && \
env CC="$(CC)" OUTNAME="$(OUT)/bin/toybox" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" STRIP="$(STRIP)" \
make -C $(BUILD_DIR) toybox -j> $(BUILD_LOG) 2>&1
clean:
$(HIDE)$(RM) $(BUILD_DIR)
.PHONY: all clean

View File

@ -1,186 +0,0 @@
# CONFIG_BASENAME is not set
# CONFIG_CAL is not set
# CONFIG_CAT is not set
# CONFIG_CATV is not set
# CONFIG_CKSUM is not set
# CONFIG_CRC32 is not set
# CONFIG_CMP is not set
# CONFIG_COMM is not set
# CONFIG_CP_PRESERVE is not set
# CONFIG_INSTALL is not set
# CONFIG_CPIO is not set
# CONFIG_CUT is not set
# CONFIG_DF is not set
# CONFIG_DIRNAME is not set
# CONFIG_ECHO is not set
# CONFIG_ENV is not set
# CONFIG_EXPAND is not set
# CONFIG_FALSE is not set
# CONFIG_FILE is not set
# CONFIG_FIND is not set
# CONFIG_GETCONF is not set
# CONFIG_GREP is not set
# CONFIG_EGREP is not set
# CONFIG_FGREP is not set
# CONFIG_HEAD is not set
# CONFIG_ICONV is not set
# CONFIG_ID is not set
# CONFIG_GROUPS is not set
# CONFIG_LOGNAME is not set
# CONFIG_WHOAMI is not set
# CONFIG_LINK is not set
# CONFIG_LN is not set
# CONFIG_LOGGER is not set
# CONFIG_MKFIFO is not set
# CONFIG_NICE is not set
# CONFIG_NL is not set
# CONFIG_NOHUP is not set
# CONFIG_OD is not set
# CONFIG_PASTE is not set
# CONFIG_PATCH is not set
# CONFIG_PRINTF is not set
# CONFIG_IOTOP is not set
# CONFIG_PGREP is not set
# CONFIG_PKILL is not set
# CONFIG_PWD is not set
# CONFIG_RENICE is not set
# CONFIG_SED is not set
# CONFIG_SLEEP is not set
# CONFIG_SORT is not set
# CONFIG_SORT_FLOAT is not set
# CONFIG_SPLIT is not set
# CONFIG_STRINGS is not set
# CONFIG_TAIL is not set
# CONFIG_TAR is not set
# CONFIG_TEE is not set
# CONFIG_TEST is not set
# CONFIG_TIME is not set
# CONFIG_TRUE is not set
# CONFIG_TTY is not set
# CONFIG_ULIMIT is not set
# CONFIG_ARCH is not set
# CONFIG_UNIQ is not set
# CONFIG_UNLINK is not set
# CONFIG_UUDECODE is not set
# CONFIG_UUENCODE is not set
# CONFIG_WC is not set
# CONFIG_WHO is not set
# CONFIG_XARGS is not set
# CONFIG_ACPI is not set
# CONFIG_ASCII is not set
# CONFIG_BASE64 is not set
# CONFIG_BLKID is not set
# CONFIG_FSTYPE is not set
# CONFIG_BLOCKDEV is not set
# CONFIG_BUNZIP2 is not set
# CONFIG_BZCAT is not set
# CONFIG_CHROOT is not set
# CONFIG_CHRT is not set
# CONFIG_CHVT is not set
# CONFIG_CLEAR is not set
# CONFIG_COUNT is not set
# CONFIG_DEVMEM is not set
# CONFIG_DOS2UNIX is not set
# CONFIG_UNIX2DOS is not set
# CONFIG_EJECT is not set
# CONFIG_FACTOR is not set
# CONFIG_FALLOCATE is not set
# CONFIG_FLOCK is not set
# CONFIG_FMT is not set
# CONFIG_FREERAMDISK is not set
# CONFIG_FSFREEZE is not set
# CONFIG_FSYNC is not set
# CONFIG_HELP_EXTRAS is not set
# CONFIG_HEXEDIT is not set
# CONFIG_HWCLOCK is not set
# CONFIG_I2CDETECT is not set
# CONFIG_I2CDUMP is not set
# CONFIG_I2CGET is not set
# CONFIG_I2CSET is not set
# CONFIG_INOTIFYD is not set
# CONFIG_INSMOD is not set
# CONFIG_IONICE is not set
# CONFIG_IORENICE is not set
# CONFIG_LOGIN is not set
# CONFIG_LOSETUP is not set
# CONFIG_LSATTR is not set
# CONFIG_CHATTR is not set
# CONFIG_LSMOD is not set
# CONFIG_LSPCI is not set
# CONFIG_LSPCI_TEXT is not set
# CONFIG_LSUSB is not set
# CONFIG_MAKEDEVS is not set
# CONFIG_MCOOKIE is not set
# CONFIG_MIX is not set
# CONFIG_MKPASSWD is not set
# CONFIG_MKSWAP is not set
# CONFIG_MODINFO is not set
# CONFIG_MOUNTPOINT is not set
# CONFIG_NBD_CLIENT is not set
# CONFIG_UNSHARE is not set
# CONFIG_NSENTER is not set
# CONFIG_ONEIT is not set
# CONFIG_PARTPROBE is not set
# CONFIG_PIVOT_ROOT is not set
# CONFIG_PMAP is not set
# CONFIG_PRINTENV is not set
# CONFIG_PWDX is not set
# CONFIG_READAHEAD is not set
# CONFIG_READLINK is not set
# CONFIG_REALPATH is not set
# CONFIG_RESET is not set
# CONFIG_REV is not set
# CONFIG_RMMOD is not set
# CONFIG_SETFATTR is not set
# CONFIG_SETSID is not set
# CONFIG_SHRED is not set
# CONFIG_STAT is not set
# CONFIG_SWAPOFF is not set
# CONFIG_SWAPON is not set
# CONFIG_SWITCH_ROOT is not set
# CONFIG_SYSCTL is not set
# CONFIG_TAC is not set
# CONFIG_NPROC is not set
# CONFIG_TASKSET is not set
# CONFIG_TIMEOUT is not set
# CONFIG_TRUNCATE is not set
# CONFIG_UPTIME is not set
# CONFIG_USLEEP is not set
# CONFIG_UUIDGEN is not set
# CONFIG_VCONFIG is not set
# CONFIG_VMSTAT is not set
# CONFIG_W is not set
# CONFIG_WATCH is not set
# CONFIG_WHICH is not set
# CONFIG_XXD is not set
# CONFIG_YES is not set
# CONFIG_FTPGET is not set
# CONFIG_FTPPUT is not set
# CONFIG_MICROCOM is not set
# CONFIG_NETCAT is not set
# CONFIG_NETCAT_LISTEN is not set
# CONFIG_NETSTAT is not set
# CONFIG_RFKILL is not set
# CONFIG_SNTP is not set
# CONFIG_TUNCTL is not set
# CONFIG_DMESG is not set
# CONFIG_GUNZIP is not set
# CONFIG_ZCAT is not set
# CONFIG_HOSTNAME is not set
# CONFIG_DNSDOMAINNAME is not set
# CONFIG_KILLALL is not set
# CONFIG_MD5SUM is not set
# CONFIG_SHA1SUM is not set
# CONFIG_MKNOD is not set
# CONFIG_MKTEMP is not set
# CONFIG_PASSWD is not set
# CONFIG_PIDOF is not set
# CONFIG_SEQ is not set
# CONFIG_SU is not set
# CONFIG_SYNC is not set
#
# pending (see toys/pending/README)
#
# CONFIG_GETTY is not set
# CONFIG_MDEV is not set
# CONFIG_MDEV_CONF is not set

View File

@ -1,34 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//kernel/liteos_a/liteos.gni")
executable("trace") {
sources = [ "src/trace.c" ]
}

View File

@ -1,36 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
include $(APPSTOPDIR)/config.mk
APP_NAME := $(notdir $(shell pwd))
LOCAL_SRCS := src/trace.c
include $(APP)

View File

@ -1,141 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdint.h>
#define TRACE_IOC_MAGIC 'T'
#define TRACE_START _IO(TRACE_IOC_MAGIC, 1)
#define TRACE_STOP _IO(TRACE_IOC_MAGIC, 2)
#define TRACE_RESET _IO(TRACE_IOC_MAGIC, 3)
#define TRACE_DUMP _IO(TRACE_IOC_MAGIC, 4)
#define TRACE_SET_MASK _IO(TRACE_IOC_MAGIC, 5)
#define TRACE_USR_MAX_PARAMS 3
typedef struct {
unsigned int eventType;
uintptr_t identity;
uintptr_t params[TRACE_USR_MAX_PARAMS];
} UsrEventInfo;
static void TraceUsage(void)
{
printf("\nUsage: ./trace [start] Start to trace events.\n");
printf("\nUsage: ./trace [stop] Stop trace.\n");
printf("\nUsage: ./trace [reset] Clear the trace record buffer.\n");
printf("\nUsage: ./trace [dump 0/1] Format printf trace data,"
"0/1 stands for whether to send data to studio for analysis.\n");
printf("\nUsage: ./trace [mask num] Set trace filter event mask.\n");
printf("\nUsage: ./trace [read nBytes] Read nBytes raw data from trace buffer.\n");
printf("\nUsage: ./trace [write type id params..] Write a user event, no more than 3 parameters.\n");
}
static void TraceRead(int fd, size_t size)
{
ssize_t i;
ssize_t len;
if (size == 0) {
return;
}
char *buffer = (char *)malloc(size);
if (buffer == NULL) {
printf("Read buffer malloc failed.\n");
return;
}
len = read(fd, buffer, size);
for (i = 0; i < len; i++) {
printf("%02x ", buffer[i] & 0xFF);
}
printf("\n");
free(buffer);
}
static void TraceWrite(int fd, int argc, char **argv)
{
int i;
UsrEventInfo info = {0};
info.eventType = strtoul(argv[2], NULL, 0); /* 2, argv number */
info.identity = strtoul(argv[3], NULL, 0); /* 3, argv number */
/* 4, argc -4 means user argv that does not contain argv[0]~argv[3] */
int paramNum = (argc - 4) > TRACE_USR_MAX_PARAMS ? TRACE_USR_MAX_PARAMS : (argc - 4);
for (i = 0; i < paramNum; i++) {
/* 4, argc -4 means user argv that does not contain argv[0]~argv[3] */
info.params[i] = strtoul(argv[4 + i], NULL, 0);
}
(void)write(fd, &info, sizeof(UsrEventInfo));
}
int main(int argc, char **argv)
{
int fd = open("/dev/trace", O_RDWR);
if (fd == -1) {
printf("Trace open failed.\n");
exit(EXIT_FAILURE);
}
if (argc == 1) {
TraceUsage();
} else if (argc == 2 && strcmp(argv[1], "start") == 0) { /* 2, argv num, no special meaning */
ioctl(fd, TRACE_START, NULL);
} else if (argc == 2 && strcmp(argv[1], "stop") == 0) { /* 2, argv num, no special meaning */
ioctl(fd, TRACE_STOP, NULL);
} else if (argc == 2 && strcmp(argv[1], "reset") == 0) { /* 2, argv num, no special meaning */
ioctl(fd, TRACE_RESET, NULL);
} else if (argc == 3 && strcmp(argv[1], "mask") == 0) { /* 3, argv num, no special meaning */
size_t mask = strtoul(argv[2], NULL, 0);
ioctl(fd, TRACE_SET_MASK, mask);
} else if (argc == 3 && strcmp(argv[1], "dump") == 0) { /* 3, argv num, no special meaning */
size_t flag = strtoul(argv[2], NULL, 0);
ioctl(fd, TRACE_DUMP, flag);
} else if (argc == 3 && strcmp(argv[1], "read") == 0) { /* 3, argv num, no special meaning */
size_t size = strtoul(argv[2], NULL, 0);
TraceRead(fd, size);
} else if (argc >= 4 && strcmp(argv[1], "write") == 0) { /* 4, argv num, no special meaning */
TraceWrite(fd, argc, argv);
} else {
printf("Unsupported trace command.\n");
TraceUsage();
}
close(fd);
return 0;
}

View File

@ -1,44 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//kernel/liteos_a/liteos.gni")
group("arch") {
deps = []
if (defined(LOSCFG_ARCH_ARM)) {
deps += [ "arm" ]
}
}
config("public") {
configs = []
if (defined(LOSCFG_ARCH_ARM)) {
configs += [ "arm:public" ]
}
}

0
arch/Kconfig Normal file → Executable file
View File

View File

@ -1,40 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//kernel/liteos_a/liteos.gni")
group("arm") {
deps = [ "gic" ]
deps += [ ARCH ]
}
config("public") {
include_dirs = [ "include" ]
configs = [ "$ARCH:public" ]
}

View File

@ -75,29 +75,3 @@ config ARCH_CORTEX_A7
config ARCH_CPU config ARCH_CPU
string string
default "cortex-a7" if ARCH_CORTEX_A7 default "cortex-a7" if ARCH_CORTEX_A7
#
# Supported GIC version
#
choice
prompt "GIC version"
default ARCH_GIC_V2
help
Interrupt Controller.
config ARCH_GIC_V2
bool "GIC Version 2"
help
This GIC(General Interrupt Controller) version 2 driver is compatatble with
GIC version 1 and version 2.
config ARCH_GIC_V3
bool "GIC Version 3"
depends on ARCH_ARM_V8A || ARCH_ARM_V8R
help
General Interrupt Controller version 3.
endchoice

View File

@ -36,16 +36,13 @@ LOSCFG_ARCH_FPU_STRIP := $(subst $\",,$(LOSCFG_ARCH_FPU))
LOSCFG_ARCH_FPU = $(LOSCFG_ARCH_FPU_STRIP) LOSCFG_ARCH_FPU = $(LOSCFG_ARCH_FPU_STRIP)
ifeq ($(LOSCFG_ARCH_ARM_AARCH32), y) ifeq ($(LOSCFG_ARCH_ARM_AARCH32), y)
ARCH := arm LITEOS_ARCH_ARM := arm
else ifeq ($(LOSCFG_ARCH_ARM_AARCH64), y) else ifeq ($(LOSCFG_ARCH_ARM_AARCH64), y)
ARCH := aarch64 LITEOS_ARCH_ARM :=
endif endif
LITEOS_BASELIB += -l$(LOSCFG_ARCH_CPU) LITEOS_BASELIB += -l$(LOSCFG_ARCH_CPU)
LITEOS_BASELIB += -lgic LIB_SUBDIRS += arch/arm/$(LITEOS_ARCH_ARM)
LIB_SUBDIRS += arch/arm/$(ARCH)
LIB_SUBDIRS += arch/arm/gic
# CPU compile options # CPU compile options
ifeq ($(LOSCFG_ARCH_ARM_AARCH64), y) ifeq ($(LOSCFG_ARCH_ARM_AARCH64), y)
@ -65,12 +62,38 @@ LITEOS_FPU_OPTS := -mfpu=$(LOSCFG_ARCH_FPU)
LITEOS_GCCLIB := $(subst cortex-,,$(LOSCFG_ARCH_CPU))_softfp_$(LOSCFG_ARCH_FPU) LITEOS_GCCLIB := $(subst cortex-,,$(LOSCFG_ARCH_CPU))_softfp_$(LOSCFG_ARCH_FPU)
endif endif
LITEOS_CORE_COPTS = $(or $(ARCH_CFLAGS),$(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS)) LITEOS_CORE_COPTS = $(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS)
LITEOS_INTERWORK += $(LITEOS_CORE_COPTS)
LITEOS_NODEBUG += $(LITEOS_CORE_COPTS)
LITEOS_ASOPTS += $(LITEOS_CPU_OPTS) LITEOS_ASOPTS += $(LITEOS_CPU_OPTS)
LITEOS_CXXOPTS_BASE += $(LITEOS_CORE_COPTS) LITEOS_CXXOPTS_BASE += $(LITEOS_CORE_COPTS)
ARCH_INCLUDE := -I $(LITEOSTOPDIR)/arch/arm/include \ ARCH_INCLUDE := -I $(LITEOSTOPDIR)/arch/arm/include \
-I $(LITEOSTOPDIR)/arch/arm/$(ARCH)/include \ -I $(LITEOSTOPDIR)/arch/arm/$(LITEOS_ARCH_ARM)/include \
-I $(LITEOSTOPDIR)/arch/arm/$(ARCH)/src/include -I $(LITEOSTOPDIR)/arch/arm/$(LITEOS_ARCH_ARM)/src/include
LITEOS_PLATFORM_INCLUDE += $(ARCH_INCLUDE) LITEOS_PLATFORM_INCLUDE += $(ARCH_INCLUDE)
LITEOS_CXXINCLUDE += $(ARCH_INCLUDE)
# expose FPU info to assembly code
ifeq ($(LOSCFG_ARCH_FPU_DISABLE), y)
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_DISABLE
else ifeq ($(LOSCFG_ARCH_FPU_VFP_D16), y)
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D16
else ifeq ($(LOSCFG_ARCH_FPU_VFP_D32), y)
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D32
endif
# extra definition for other module
LITEOS_CPU_TYPE = $(LOSCFG_ARCH_CPU)
LITEOS_ARM_ARCH := -march=$(subst $\",,$(LOSCFG_ARCH_ARM_VER))
# linux style macros
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7A) = -D__LINUX_ARM_ARCH__=7
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7R) = -D__LINUX_ARM_ARCH__=7
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7M) = -D__LINUX_ARM_ARCH__=7
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8A) = -D__LINUX_ARM_ARCH__=8
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8R) = -D__LINUX_ARM_ARCH__=8
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8M) = -D__LINUX_ARM_ARCH__=8
AS_OBJS_LIBC_FLAGS += $(LINUX_ARCH_y)

View File

@ -1,96 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//kernel/liteos_a/liteos.gni")
module_name = LOSCFG_ARCH_CPU
kernel_module(module_name) {
sources = [
"src/arm_generic_timer.c",
"src/clear_user.S",
"src/hw_user_get.S",
"src/hw_user_put.S",
"src/jmp.S",
"src/los_arch_mmu.c",
"src/los_asid.c",
"src/los_dispatch.S",
"src/los_exc.c",
"src/los_hw.c",
"src/los_hw_exc.S",
"src/los_hw_runstop.S",
"src/los_hw_tick.c",
"src/los_hwi.c",
"src/smp.c",
"src/strncpy_from_user.c",
"src/strnlen_user.c",
"src/user_copy.c",
]
if (LOSCFG_ARCH_ARM_VER == "armv7-a") {
sources += [ "src/armv7a/cache.S" ]
}
if (defined(LOSCFG_KERNEL_SMP)) {
sources += [ "src/startup/reset_vector_mp.S" ]
} else {
sources += [ "src/startup/reset_vector_up.S" ]
}
include_dirs = [ "src/include" ]
if (defined(LOSCFG_PERF_HW_PMU)) {
sources += [ "src/pmu/armv7_pmu.c" ]
}
if (defined(LOSCFG_GDB)) {
configs += [ ":as_objs_libc_flags" ]
}
public_configs = [ ":public" ]
}
config("public") {
include_dirs = [
"include",
"src/include",
]
}
config("as_objs_libc_flags") {
defines = [ "__ASSEMBLY__" ]
# linux style macros
if (defined(LOSCFG_ARCH_ARM_V7A) || defined(LOSCFG_ARCH_ARM_V7R) ||
defined(LOSCFG_ARCH_ARM_V7M)) {
defines += [ "__LINUX_ARM_ARCH__=7" ]
} else if (defined(LOSCFG_ARCH_ARM_V8A) || defined(LOSCFG_ARCH_ARM_V8R) ||
defined(LOSCFG_ARCH_ARM_V8M)) {
defines += [ "__LINUX_ARM_ARCH__=8" ]
}
}

23
arch/arm/arm/Makefile Normal file → Executable file
View File

@ -32,8 +32,13 @@ include $(LITEOSTOPDIR)/config.mk
MODULE_NAME := $(LOSCFG_ARCH_CPU) MODULE_NAME := $(LOSCFG_ARCH_CPU)
LOCAL_SRCS := $(wildcard src/*.c) $(wildcard src/*.S) LOCAL_SRCS := $(wildcard src/*.c) $(wildcard src/*.S)
LOCAL_INCLUDE := \
-I $(LITEOSTOPDIR)/kernel/base/include \
-I $(LITEOSTOPDIR)/kernel/extended/include \
-I $(LITEOSTOPDIR)/kernel/extended/dynload/include \
-I $(LITEOSTOPDIR)/arch/arm/arm/include \
ifeq ($(LOSCFG_ARCH_ARM_VER), "armv7-a") ifeq ($(LITEOS_ARM_ARCH), -march=armv7-a)
LOCAL_SRCS += $(wildcard src/armv7a/*.S) LOCAL_SRCS += $(wildcard src/armv7a/*.S)
endif endif
@ -43,21 +48,7 @@ else
LOCAL_SRCS += src/startup/reset_vector_up.S LOCAL_SRCS += src/startup/reset_vector_up.S
endif endif
ifeq ($(LOSCFG_PERF_HW_PMU), y) LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
LOCAL_SRCS += src/pmu/armv7_pmu.c
endif
LOCAL_FLAGS := $(LOCAL_INCLUDE)
AS_OBJS_LIBC_FLAGS = -D__ASSEMBLY__
# linux style macros
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7A) = -D__LINUX_ARM_ARCH__=7
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7R) = -D__LINUX_ARM_ARCH__=7
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7M) = -D__LINUX_ARM_ARCH__=7
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8A) = -D__LINUX_ARM_ARCH__=8
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8R) = -D__LINUX_ARM_ARCH__=8
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8M) = -D__LINUX_ARM_ARCH__=8
AS_OBJS_LIBC_FLAGS += $(LINUX_ARCH_y)
ifeq ($(LOSCFG_GDB), y) ifeq ($(LOSCFG_GDB), y)
LOCAL_FLAGS += $(AS_OBJS_LIBC_FLAGS) LOCAL_FLAGS += $(AS_OBJS_LIBC_FLAGS)

1
arch/arm/arm/include/arch_config.h Normal file → Executable file
View File

@ -32,6 +32,7 @@
#ifndef _ARCH_CONFIG_H #ifndef _ARCH_CONFIG_H
#define _ARCH_CONFIG_H #define _ARCH_CONFIG_H
#include "menuconfig.h"
#define CPSR_INT_DISABLE 0xC0 /* Disable both FIQ and IRQ */ #define CPSR_INT_DISABLE 0xC0 /* Disable both FIQ and IRQ */
#define CPSR_IRQ_DISABLE 0x80 /* IRQ disabled when =1 */ #define CPSR_IRQ_DISABLE 0x80 /* IRQ disabled when =1 */

4
arch/arm/arm/include/arm.h Normal file → Executable file
View File

@ -36,6 +36,10 @@
#define CPSR_MODE_USR 0x10 #define CPSR_MODE_USR 0x10
#define CPSR_MODE_MASK 0x1f #define CPSR_MODE_MASK 0x1f
#define DSB __asm__ volatile("dsb" ::: "memory")
#define ISB __asm__ volatile("isb" ::: "memory")
#define DMB __asm__ volatile("dmb" ::: "memory")
STATIC INLINE UINT32 OsArmReadSctlr(VOID) STATIC INLINE UINT32 OsArmReadSctlr(VOID)
{ {
UINT32 val; UINT32 val;

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2021-2021 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 _ARM_USER_CLEAR_H
#define _ARM_USER_CLEAR_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
size_t _arm_clear_user(void *addr, size_t bytes);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _ARM_USER_CLEAR_H */

0
arch/arm/arm/include/arm_user_copy.h Normal file → Executable file
View File

0
arch/arm/arm/include/arm_user_get.h Normal file → Executable file
View File

0
arch/arm/arm/include/arm_user_put.h Normal file → Executable file
View File

View File

@ -38,10 +38,7 @@
#define __LOS_ARCH_MMU_H__ #define __LOS_ARCH_MMU_H__
#include "los_typedef.h" #include "los_typedef.h"
#include "los_vm_phys.h" #include "los_mux.h"
#ifndef LOSCFG_PAGE_TABLE_FINE_LOCK
#include "los_spinlock.h"
#endif
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
@ -50,9 +47,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
typedef struct ArchMmu { typedef struct ArchMmu {
#ifndef LOSCFG_PAGE_TABLE_FINE_LOCK LosMux mtx; /**< arch mmu page table entry modification mutex lock */
SPIN_LOCK_S lock; /**< arch mmu page table entry modification spin lock */
#endif
VADDR_T *virtTtb; /**< translation table base virtual addr */ VADDR_T *virtTtb; /**< translation table base virtual addr */
PADDR_T physTtb; /**< translation table base phys addr */ PADDR_T physTtb; /**< translation table base phys addr */
UINT32 asid; /**< TLB asid */ UINT32 asid; /**< TLB asid */
@ -76,5 +71,5 @@ VADDR_T *OsGFirstTableGet(VOID);
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __LOS_ARCH_MMU_H__ */ #endif /* __LOS_VM_PAGE_H__ */

View File

@ -246,7 +246,7 @@ STATIC INLINE INT32 LOS_AtomicIncRet(Atomic *v)
* @brief Atomic auto-decrement. * @brief Atomic auto-decrement.
* *
* @par Description: * @par Description:
* This API is used to implement the atomic auto-decrement. * This API is used to implementating the atomic auto-decrement.
* @attention * @attention
* <ul> * <ul>
* <li>The pointer v must not be NULL.</li> * <li>The pointer v must not be NULL.</li>
@ -280,7 +280,7 @@ STATIC INLINE VOID LOS_AtomicDec(Atomic *v)
* @brief Atomic auto-decrement. * @brief Atomic auto-decrement.
* *
* @par Description: * @par Description:
* This API is used to implement the atomic auto-decrement and return the result of auto-decrement. * This API is used to implementating the atomic auto-decrement and return the result of auto-decrement.
* @attention * @attention
* <ul> * <ul>
* <li>The pointer v must not be NULL.</li> * <li>The pointer v must not be NULL.</li>
@ -531,7 +531,7 @@ STATIC INLINE INT64 LOS_Atomic64IncRet(Atomic64 *v)
* @brief Atomic64 auto-decrement. * @brief Atomic64 auto-decrement.
* *
* @par Description: * @par Description:
* This API is used to implement the atomic64 auto-decrement. * This API is used to implementating the atomic64 auto-decrement.
* @attention * @attention
* <ul> * <ul>
* <li>The pointer v must not be NULL.</li> * <li>The pointer v must not be NULL.</li>
@ -566,7 +566,7 @@ STATIC INLINE VOID LOS_Atomic64Dec(Atomic64 *v)
* @brief Atomic64 auto-decrement. * @brief Atomic64 auto-decrement.
* *
* @par Description: * @par Description:
* This API is used to implement the atomic64 auto-decrement and return the result of auto-decrement. * This API is used to implementating the atomic64 auto-decrement and return the result of auto-decrement.
* @attention * @attention
* <ul> * <ul>
* <li>The pointer v must not be NULL.</li> * <li>The pointer v must not be NULL.</li>

23
arch/arm/arm/include/los_hw_cpu.h Normal file → Executable file
View File

@ -51,10 +51,7 @@ extern "C" {
#define DSB __asm__ volatile("dsb" ::: "memory") #define DSB __asm__ volatile("dsb" ::: "memory")
#define DMB __asm__ volatile("dmb" ::: "memory") #define DMB __asm__ volatile("dmb" ::: "memory")
#define ISB __asm__ volatile("isb" ::: "memory") #define ISB __asm__ volatile("isb" ::: "memory")
#define WFI __asm__ volatile("wfi" ::: "memory")
#define BARRIER __asm__ volatile("":::"memory") #define BARRIER __asm__ volatile("":::"memory")
#define WFE __asm__ volatile("wfe" ::: "memory")
#define SEV __asm__ volatile("sev" ::: "memory")
#define ARM_SYSREG_READ(REG) \ #define ARM_SYSREG_READ(REG) \
({ \ ({ \
@ -147,7 +144,7 @@ STATIC INLINE VOID ArchCurrUserTaskSet(UINTPTR val)
STATIC INLINE UINT32 ArchCurrCpuid(VOID) STATIC INLINE UINT32 ArchCurrCpuid(VOID)
{ {
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
return ARM_SYSREG_READ(MPIDR) & MPIDR_CPUID_MASK; return ARM_SYSREG_READ(MPIDR) & MPIDR_CPUID_MASK;
#else #else
return 0; return 0;
@ -191,24 +188,6 @@ STATIC INLINE UINT32 ArchIntUnlock(VOID)
return intSave; return intSave;
} }
STATIC INLINE VOID ArchIrqDisable(VOID)
{
__asm__ __volatile__(
"cpsid i "
:
:
: "memory", "cc");
}
STATIC INLINE VOID ArchIrqEnable(VOID)
{
__asm__ __volatile__(
"cpsie i "
:
:
: "memory", "cc");
}
#else #else
STATIC INLINE UINT32 ArchIntLock(VOID) STATIC INLINE UINT32 ArchIntLock(VOID)

0
arch/arm/arm/include/los_mmu_descriptor_v6.h Normal file → Executable file
View File

View File

@ -69,11 +69,6 @@ STATIC INLINE VOID OsClearPte1(PTE_T *pte1Ptr)
OsSavePte1(pte1Ptr, 0); OsSavePte1(pte1Ptr, 0);
} }
STATIC INLINE PADDR_T OsGetPte1Paddr(PADDR_T PhysTtb, vaddr_t va)
{
return (PhysTtb + (OsGetPte1Index(va) * sizeof(PADDR_T)));
}
STATIC INLINE PTE_T *OsGetPte1Ptr(PTE_T *pte1BasePtr, vaddr_t va) STATIC INLINE PTE_T *OsGetPte1Ptr(PTE_T *pte1BasePtr, vaddr_t va)
{ {
return (pte1BasePtr + OsGetPte1Index(va)); return (pte1BasePtr + OsGetPte1Index(va));

View File

@ -37,6 +37,7 @@
#define __LOS_TLB_V6_H__ #define __LOS_TLB_V6_H__
#include "los_typedef.h" #include "los_typedef.h"
#include "menuconfig.h"
#include "arm.h" #include "arm.h"
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,100 +0,0 @@
/*
* Copyright (c) 2021-2021 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.
*/
#include "asm.h"
.syntax unified
.arm
// size_t _arm_clear_user(void *addr, size_t bytes)
FUNCTION(_arm_clear_user)
push {r0-r6, lr}
cmp r1, #0
beq .Lclear_user_return
tst r0, #7
beq .Lclear_user_aligned
.Lclear_user_byte:
mov r2, #0
0: strb r2, [r0], #1
subs r1, r1, #1
beq .Lclear_user_return
tst r0, #7
bne 0b
.Lclear_user_aligned:
eor r3, r3
eor r4, r4
bics r2, r1, #15
bne .Lclear_user_16bytes
bics r2, r1, #7
bne .Lclear_user_8bytes
b .Lclear_user_remaining
.Lclear_user_16bytes:
eor r5, r5
eor r6, r6
1: stmia r0!, {r3, r4, r5, r6}
subs r2, r2, #16
bne 1b
ands r1, r1, #15
beq .Lclear_user_return
bics r2, r1, #7
beq .Lclear_user_remaining
.Lclear_user_8bytes:
2: stmia r0!, {r3, r4}
ands r1, r1, #7
beq .Lclear_user_return
.Lclear_user_remaining:
mov r2, #0
3: strb r2, [r0], #1
subs r1, r1, #1
bne 3b
.Lclear_user_return:
pop {r0-r6, lr}
mov r0, #0
bx lr
.Lclear_user_err:
pop {r0, r1}
sub r0, r2, r0
sub r0, r1, r0
pop {r2-r6, lr}
bx lr
.pushsection __exc_table, "a"
.long 0b, .Lclear_user_err
.long 1b, .Lclear_user_err
.long 2b, .Lclear_user_err
.long 3b, .Lclear_user_err
.popsection

0
arch/arm/arm/src/hw_user_get.S Normal file → Executable file
View File

0
arch/arm/arm/src/hw_user_put.S Normal file → Executable file
View File

View File

@ -1,108 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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 _ARMV7_PMU_PRI_H
#define _ARMV7_PMU_PRI_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* counters overflow flag status reg */
#define ARMV7_FLAG_MASK 0xffffffff /* Mask for writable bits */
#define ARMV7_OVERFLOWED_MASK ARMV7_FLAG_MASK /* Mask for pmu overflowed */
/* pmnc config reg */
#define ARMV7_PMNC_E (1U << 0) /* Enable all counters */
#define ARMV7_PMNC_P (1U << 1) /* Reset all counters */
#define ARMV7_PMNC_C (1U << 2) /* Cycle counter reset */
#define ARMV7_PMNC_D (1U << 3) /* CCNT counts every 64th cpu cycle */
#define ARMV7_PMNC_X (1U << 4) /* Export to ETM */
#define ARMV7_PMNC_DP (1U << 5) /* Disable CCNT if non-invasive debug */
#define ARMV7_PMNC_MASK 0x3f /* Mask for writable bits */
/* pmxevtyper event selection reg */
#define ARMV7_EVTYPE_MASK 0xc80000ff /* Mask for writable bits */
/* armv7 counters index */
#define ARMV7_IDX_COUNTER0 1
#define ARMV7_IDX_CYCLE_COUNTER 0
#define ARMV7_IDX_MAX_COUNTER 9
#define ARMV7_MAX_COUNTERS 32
#define ARMV7_IDX_COUNTER_LAST (ARMV7_IDX_CYCLE_COUNTER + ARMV7_MAX_COUNTERS - 1)
#define ARMV7_COUNTER_MASK (ARMV7_MAX_COUNTERS - 1)
/* armv7 event counter index mapping */
#define ARMV7_CNT2BIT(x) (1UL << (x))
#define ARMV7_IDX2CNT(x) (((x) - ARMV7_IDX_COUNTER0) & ARMV7_COUNTER_MASK)
enum PmuEventType {
ARMV7_PERF_HW_CYCLES = 0xFF, /* cycles */
ARMV7_PERF_HW_INSTRUCTIONS = 0x08, /* instructions */
ARMV7_PERF_HW_DCACHES = 0x04, /* dcache */
ARMV7_PERF_HW_DCACHE_MISSES = 0x03, /* dcache-misses */
ARMV7_PERF_HW_ICACHES = 0x14, /* icache */
ARMV7_PERF_HW_ICACHE_MISSES = 0x01, /* icache-misses */
ARMV7_PERF_HW_BRANCHES = 0x0C, /* software change of pc */
ARMV7_PERF_HW_BRANCE_MISSES = 0x10, /* branch-misses */
ARMV7_PERF_HW_PRED_BRANCH = 0x12, /* predictable branches */
ARMV7_PERF_HW_NUM_CYC_IRQ = 0x50, /* number of cycles Irqs are interrupted */
ARMV7_PERF_HW_EXC_TAKEN = 0x09, /* exception_taken */
ARMV7_PERF_HW_DATA_READ = 0x06, /* data read */
ARMV7_PERF_HW_DATA_WRITE = 0x07, /* data write */
ARMV7_PERF_HW_STREX_PASSED = 0x80, /* strex passed */
ARMV7_PERF_HW_STREX_FAILED = 0x81, /* strex failed */
ARMV7_PERF_HW_LP_IN_TCM = 0x82, /* literal pool in TCM region */
ARMV7_PERF_HW_DMB_STALL = 0x90, /* DMB stall */
ARMV7_PERF_HW_ITCM_ACCESS = 0x91, /* ITCM access */
ARMV7_PERF_HW_DTCM_ACCESS = 0x92, /* DTCM access */
ARMV7_PERF_HW_DATA_EVICTION = 0x93, /* data eviction */
ARMV7_PERF_HW_SCU = 0x94, /* SCU coherency operation */
ARMV7_PERF_HW_INSCACHE_DEP_DW = 0x95, /* instruction cache dependent stall */
ARMV7_PERF_HW_DATA_CACHE_DEP_STALL = 0x96, /* data cache dependent stall */
ARMV7_PERF_HW_NOCACHE_NO_PER_DEP_STALL = 0x97, /* non-cacheable no peripheral dependent stall */
ARMV7_PERF_HW_NOCACHE_PER_DEP_STALL = 0x98, /* non-Cacheable peripheral dependent stall */
ARMV7_PERF_HW_DATA_CACHE_HP_DEP_STALL = 0x99, /* data cache high priority dependent stall */
ARMV7_PERF_HW_AXI_FAST_PERIPHERAL = 0x9A, /* Accesses_to_AXI_fast_peripheral_port(reads_and_writes) */
};
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _ARMV7_PMU_PRI_H */

0
arch/arm/arm/src/include/asm.h Normal file → Executable file
View File

View File

@ -40,28 +40,19 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#endif /* __cplusplus */ #endif /* __cplusplus */
STATIC INLINE VOID OsSetCurrCpuSp(UINTPTR regSp)
{
__asm__ __volatile__("mov sp, %0" :: "r"(regSp));
}
#define OS_SYSTEM_NORMAL 0 #define OS_SYSTEM_NORMAL 0
#define OS_SYSTEM_EXC_CURR_CPU 1 #define OS_SYSTEM_EXC_CURR_CPU 1
#define OS_SYSTEM_EXC_OTHER_CPU 2 #define OS_SYSTEM_EXC_OTHER_CPU 2
#define REGION_PATH_MAX 32
typedef struct {
#ifdef LOSCFG_KERNEL_VM
UINTPTR ip;
UINT32 len; /* f_path length */
CHAR f_path[REGION_PATH_MAX];
#else
UINTPTR ip;
#endif
} IpInfo;
extern UINT32 OsGetSystemStatus(VOID); extern UINT32 OsGetSystemStatus(VOID);
extern VOID BackTraceSub(UINTPTR regFP); extern VOID BackTraceSub(UINTPTR regFP);
extern VOID OsExcInit(VOID); extern VOID OsExcInit(VOID);
extern BOOL OsSystemExcIsReset(VOID); extern BOOL OsSystemExcIsReset(VOID);
extern UINT32 BackTraceGet(UINTPTR regFP, IpInfo *callChain, UINT32 maxDepth);
extern BOOL OsGetUsrIpInfo(UINTPTR ip, IpInfo *info);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus

59
arch/arm/arm/src/include/los_hw_pri.h Normal file → Executable file
View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
@ -34,7 +34,8 @@
#include "los_base.h" #include "los_base.h"
#include "los_hw.h" #include "los_hw.h"
#include "los_process_pri.h"
#include "los_signal.h"
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
@ -55,44 +56,23 @@ typedef struct {
UINT32 regFPSCR; /* FPSCR */ UINT32 regFPSCR; /* FPSCR */
UINT32 regFPEXC; /* FPEXC */ UINT32 regFPEXC; /* FPEXC */
#endif #endif
UINT32 R4; UINT32 resved; /* It's stack 8 aligned */
UINT32 R5; UINT32 regPSR;
UINT32 R6; UINT32 R[GEN_REGS_NUM]; /* R0-R12 */
UINT32 R7; UINT32 SP; /* R13 */
UINT32 R8; UINT32 LR; /* R14 */
UINT32 R9; UINT32 PC; /* R15 */
UINT32 R10;
UINT32 R11;
/* It has the same structure as IrqContext */
UINT32 reserved2; /**< Multiplexing registers, used in interrupts and system calls but with different meanings */
UINT32 reserved1; /**< Multiplexing registers, used in interrupts and system calls but with different meanings */
UINT32 USP; /**< User mode sp register */
UINT32 ULR; /**< User mode lr register */
UINT32 R0;
UINT32 R1;
UINT32 R2;
UINT32 R3;
UINT32 R12;
UINT32 LR;
UINT32 PC;
UINT32 regCPSR;
} TaskContext; } TaskContext;
typedef struct { typedef struct {
UINT32 reserved2; /**< Multiplexing registers, used in interrupts and system calls but with different meanings */ #if !defined(LOSCFG_ARCH_FPU_DISABLE)
UINT32 reserved1; /**< Multiplexing registers, used in interrupts and system calls but with different meanings */ UINT64 D[FP_REGS_NUM]; /* D0-D31 */
UINT32 USP; /**< User mode sp register */ UINT32 regFPSCR; /* FPSCR */
UINT32 ULR; /**< User mode lr register */ UINT32 regFPEXC; /* FPEXC */
UINT32 R0; #endif
UINT32 R1; UINT32 resved;
UINT32 R2; TASK_IRQ_CONTEXT
UINT32 R3; } TaskIrqContext;
UINT32 R12;
UINT32 LR;
UINT32 PC;
UINT32 regCPSR;
} IrqContext;
/* /*
* Description : task stack initialization * Description : task stack initialization
@ -102,9 +82,8 @@ typedef struct {
* Return : pointer to the task context * Return : pointer to the task context
*/ */
extern VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag); extern VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag);
extern VOID OsUserCloneParentStack(VOID *childStack, UINTPTR sp, UINTPTR parentTopOfStask, UINT32 parentStackSize); extern VOID OsUserCloneParentStack(LosTaskCB *childTaskCB, LosTaskCB *parentTaskCB);
extern VOID OsUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack); extern VOID OsUserTaskStackInit(TaskContext *context, TSK_ENTRY_FUNC taskEntry, UINTPTR stack);
extern VOID OsInitSignalContext(const VOID *sp, VOID *signalContext, UINTPTR sigHandler, UINT32 signo, UINT32 param);
extern void arm_clean_cache_range(UINTPTR start, UINTPTR end); extern void arm_clean_cache_range(UINTPTR start, UINTPTR end);
extern void arm_inv_cache_range(UINTPTR start, UINTPTR end); extern void arm_inv_cache_range(UINTPTR start, UINTPTR end);

View File

@ -55,11 +55,11 @@ extern "C" {
#define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pstNext != NULL) #define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pstNext != NULL)
#endif #endif
extern VOID OsHwiInit(VOID); extern VOID OsHwiInit(VOID);
extern VOID OsIncHwiFormCnt(UINT16 cpuid, UINT32 index); extern VOID OsIncHwiFormCnt(UINT32 index);
extern UINT32 OsGetHwiFormCnt(UINT16 cpuid, UINT32 index); extern UINT32 OsGetHwiFormCnt(UINT32 index);
extern CHAR *OsGetHwiFormName(UINT32 index); extern CHAR *OsGetHwiFormName(UINT32 index);
extern VOID OsInterrupt(UINT32 intNum); extern VOID OsInterrupt(UINT32 intNum);
extern VOID OsSyscallHandleInit(VOID); extern VOID SyscallHandleInit(VOID);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus

456
arch/arm/arm/src/los_arch_mmu.c Normal file → Executable file
View File

@ -39,26 +39,22 @@
#include "los_pte_ops.h" #include "los_pte_ops.h"
#include "los_tlb_v6.h" #include "los_tlb_v6.h"
#include "los_printf.h" #include "los_printf.h"
#include "los_vm_phys.h"
#include "los_vm_common.h" #include "los_vm_common.h"
#include "los_vm_map.h" #include "los_vm_map.h"
#include "los_vm_boot.h" #include "los_vm_boot.h"
#include "los_mmu_descriptor_v6.h" #include "los_mmu_descriptor_v6.h"
#include "los_process_pri.h"
#ifdef LOSCFG_KERNEL_MMU #ifdef __cplusplus
typedef struct { #if __cplusplus
LosArchMmu *archMmu; extern "C" {
VADDR_T *vaddr; #endif /* __cplusplus */
PADDR_T *paddr; #endif /* __cplusplus */
UINT32 *flags;
} MmuMapInfo;
#define TRY_MAX_TIMES 10
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \ __attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \
__attribute__((section(".bss.prebss.translation_table"))) UINT8 \ __attribute__((section(".bss.prebss.translation_table"))) UINT8 \
g_firstPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS]; g_firstPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS];
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \ __attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \
__attribute__((section(".bss.prebss.translation_table"))) UINT8 \ __attribute__((section(".bss.prebss.translation_table"))) UINT8 \
g_tempPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS]; g_tempPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS];
@ -68,86 +64,12 @@ extern CHAR __mmu_ttlb_begin; /* defined in .ld script */
UINT8 *g_mmuJumpPageTable = (UINT8 *)&__mmu_ttlb_begin; /* temp page table, this is only used when system power up */ UINT8 *g_mmuJumpPageTable = (UINT8 *)&__mmu_ttlb_begin; /* temp page table, this is only used when system power up */
#endif #endif
STATIC SPIN_LOCK_S *OsGetPteLock(LosArchMmu *archMmu, PADDR_T paddr, UINT32 *intSave)
{
SPIN_LOCK_S *lock = NULL;
#ifdef LOSCFG_PAGE_TABLE_FINE_LOCK
LosVmPage *vmPage = NULL;
vmPage = OsVmPaddrToPage(paddr);
if (vmPage == NULL) {
return NULL;
}
lock = &vmPage->lock;
#else
lock = &archMmu->lock;
#endif
LOS_SpinLockSave(lock, intSave);
return lock;
}
STATIC SPIN_LOCK_S *OsGetPte1Lock(LosArchMmu *archMmu, PADDR_T paddr, UINT32 *intSave)
{
return OsGetPteLock(archMmu, paddr, intSave);
}
STATIC INLINE VOID OsUnlockPte1(SPIN_LOCK_S *lock, UINT32 intSave)
{
if (lock == NULL) {
return;
}
LOS_SpinUnlockRestore(lock, intSave);
}
STATIC SPIN_LOCK_S *OsGetPte1LockTmp(LosArchMmu *archMmu, PADDR_T paddr, UINT32 *intSave)
{
SPIN_LOCK_S *spinLock = NULL;
#ifdef LOSCFG_PAGE_TABLE_FINE_LOCK
spinLock = OsGetPteLock(archMmu, paddr, intSave);
#else
(VOID)archMmu;
(VOID)paddr;
(VOID)intSave;
#endif
return spinLock;
}
STATIC INLINE VOID OsUnlockPte1Tmp(SPIN_LOCK_S *lock, UINT32 intSave)
{
#ifdef LOSCFG_PAGE_TABLE_FINE_LOCK
if (lock == NULL) {
return;
}
LOS_SpinUnlockRestore(lock, intSave);
#else
(VOID)lock;
(VOID)intSave;
#endif
}
STATIC INLINE SPIN_LOCK_S *OsGetPte2Lock(LosArchMmu *archMmu, PTE_T pte1, UINT32 *intSave)
{
PADDR_T pa = MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(pte1);
return OsGetPteLock(archMmu, pa, intSave);
}
STATIC INLINE VOID OsUnlockPte2(SPIN_LOCK_S *lock, UINT32 intSave)
{
return OsUnlockPte1(lock, intSave);
}
STATIC INLINE PTE_T *OsGetPte2BasePtr(PTE_T pte1) STATIC INLINE PTE_T *OsGetPte2BasePtr(PTE_T pte1)
{ {
PADDR_T pa = MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(pte1); PADDR_T pa = MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(pte1);
return LOS_PaddrToKVaddr(pa); return LOS_PaddrToKVaddr(pa);
} }
VADDR_T *OsGFirstTableGet(VOID)
{
return (VADDR_T *)g_firstPageTable;
}
STATIC INLINE UINT32 OsUnmapL1Invalid(vaddr_t *vaddr, UINT32 *count) STATIC INLINE UINT32 OsUnmapL1Invalid(vaddr_t *vaddr, UINT32 *count)
{ {
UINT32 unmapCount; UINT32 unmapCount;
@ -224,6 +146,7 @@ STATIC VOID OsCvtPte2AttsToFlags(PTE_T l1Entry, PTE_T l2Entry, UINT32 *flags)
STATIC VOID OsPutL2Table(const LosArchMmu *archMmu, UINT32 l1Index, paddr_t l2Paddr) STATIC VOID OsPutL2Table(const LosArchMmu *archMmu, UINT32 l1Index, paddr_t l2Paddr)
{ {
LosVmPage *vmPage = NULL;
UINT32 index; UINT32 index;
PTE_T ttEntry; PTE_T ttEntry;
/* check if any l1 entry points to this l2 table */ /* check if any l1 entry points to this l2 table */
@ -233,9 +156,8 @@ STATIC VOID OsPutL2Table(const LosArchMmu *archMmu, UINT32 l1Index, paddr_t l2Pa
return; return;
} }
} }
#ifdef LOSCFG_KERNEL_VM
/* we can free this l2 table */ /* we can free this l2 table */
LosVmPage *vmPage = LOS_VmPageGet(l2Paddr); vmPage = LOS_VmPageGet(l2Paddr);
if (vmPage == NULL) { if (vmPage == NULL) {
LOS_Panic("bad page table paddr %#x\n", l2Paddr); LOS_Panic("bad page table paddr %#x\n", l2Paddr);
return; return;
@ -243,35 +165,22 @@ STATIC VOID OsPutL2Table(const LosArchMmu *archMmu, UINT32 l1Index, paddr_t l2Pa
LOS_ListDelete(&vmPage->node); LOS_ListDelete(&vmPage->node);
LOS_PhysPageFree(vmPage); LOS_PhysPageFree(vmPage);
#else
(VOID)LOS_MemFree(OS_SYS_MEM_ADDR, LOS_PaddrToKVaddr(l2Paddr));
#endif
} }
STATIC VOID OsTryUnmapL1PTE(LosArchMmu *archMmu, PTE_T *l1Entry, vaddr_t vaddr, UINT32 scanIndex, UINT32 scanCount) STATIC VOID OsTryUnmapL1PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 scanIndex, UINT32 scanCount)
{ {
/* /*
* Check if all pages related to this l1 entry are deallocated. * Check if all pages related to this l1 entry are deallocated.
* We only need to check pages that we did not clear above starting * We only need to check pages that we did not clear above starting
* from scanIndex and wrapped around SECTION. * from page_idx and wrapped around SECTION.
*/ */
UINT32 l1Index; UINT32 l1Index;
PTE_T l1Entry;
PTE_T *pte2BasePtr = NULL; PTE_T *pte2BasePtr = NULL;
SPIN_LOCK_S *pte1Lock = NULL;
SPIN_LOCK_S *pte2Lock = NULL;
UINT32 pte1IntSave;
UINT32 pte2IntSave;
PTE_T pte1Val;
PADDR_T pte1Paddr;
pte1Paddr = OsGetPte1Paddr(archMmu->physTtb, vaddr); pte2BasePtr = OsGetPte2BasePtr(OsGetPte1(archMmu->virtTtb, vaddr));
pte2Lock = OsGetPte2Lock(archMmu, *l1Entry, &pte2IntSave);
if (pte2Lock == NULL) {
return;
}
pte2BasePtr = OsGetPte2BasePtr(*l1Entry);
if (pte2BasePtr == NULL) { if (pte2BasePtr == NULL) {
OsUnlockPte2(pte2Lock, pte2IntSave); VM_ERR("pte2 base ptr is NULL");
return; return;
} }
@ -286,27 +195,15 @@ STATIC VOID OsTryUnmapL1PTE(LosArchMmu *archMmu, PTE_T *l1Entry, vaddr_t vaddr,
} }
if (!scanCount) { if (!scanCount) {
/*
* The pte1 of kprocess is placed in kernel image when compiled. So the pte1Lock will be null.
* There is no situation to simultaneous access the pte1 of kprocess.
*/
pte1Lock = OsGetPte1LockTmp(archMmu, pte1Paddr, &pte1IntSave);
if (!OsIsPte1PageTable(*l1Entry)) {
OsUnlockPte1Tmp(pte1Lock, pte1IntSave);
OsUnlockPte2(pte2Lock, pte2IntSave);
return;
}
pte1Val = *l1Entry;
/* we can kill l1 entry */
OsClearPte1(l1Entry);
l1Index = OsGetPte1Index(vaddr); l1Index = OsGetPte1Index(vaddr);
l1Entry = archMmu->virtTtb[l1Index];
/* we can kill l1 entry */
OsClearPte1(&archMmu->virtTtb[l1Index]);
OsArmInvalidateTlbMvaNoBarrier(l1Index << MMU_DESCRIPTOR_L1_SMALL_SHIFT); OsArmInvalidateTlbMvaNoBarrier(l1Index << MMU_DESCRIPTOR_L1_SMALL_SHIFT);
/* try to free l2 page itself */ /* try to free l2 page itself */
OsPutL2Table(archMmu, l1Index, MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(pte1Val)); OsPutL2Table(archMmu, l1Index, MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(l1Entry));
OsUnlockPte1Tmp(pte1Lock, pte1IntSave);
} }
OsUnlockPte2(pte2Lock, pte2IntSave);
} }
STATIC UINT32 OsCvtSecCacheFlagsToMMUFlags(UINT32 flags) STATIC UINT32 OsCvtSecCacheFlagsToMMUFlags(UINT32 flags)
@ -316,7 +213,7 @@ STATIC UINT32 OsCvtSecCacheFlagsToMMUFlags(UINT32 flags)
switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) { switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) {
case VM_MAP_REGION_FLAG_CACHED: case VM_MAP_REGION_FLAG_CACHED:
mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE; mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_SHAREABLE; mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_SHAREABLE;
#endif #endif
break; break;
@ -438,54 +335,34 @@ STATIC VOID OsCvtSecAttsToFlags(PTE_T l1Entry, UINT32 *flags)
} }
} }
STATIC UINT32 OsUnmapL2PTE(LosArchMmu *archMmu, PTE_T *pte1, vaddr_t vaddr, UINT32 *count) STATIC UINT32 OsUnmapL2PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 *count)
{ {
UINT32 unmapCount; UINT32 unmapCount;
UINT32 pte2Index; UINT32 pte2Index;
UINT32 intSave;
PTE_T *pte2BasePtr = NULL; PTE_T *pte2BasePtr = NULL;
SPIN_LOCK_S *lock = NULL;
pte2BasePtr = OsGetPte2BasePtr(OsGetPte1((PTE_T *)archMmu->virtTtb, vaddr));
if (pte2BasePtr == NULL) {
LOS_Panic("%s %d, pte2 base ptr is NULL\n", __FUNCTION__, __LINE__);
}
pte2Index = OsGetPte2Index(vaddr); pte2Index = OsGetPte2Index(vaddr);
unmapCount = MIN2(MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 - pte2Index, *count); unmapCount = MIN2(MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 - pte2Index, *count);
lock = OsGetPte2Lock(archMmu, *pte1, &intSave);
if (lock == NULL) {
return unmapCount;
}
pte2BasePtr = OsGetPte2BasePtr(*pte1);
if (pte2BasePtr == NULL) {
OsUnlockPte2(lock, intSave);
return unmapCount;
}
/* unmap page run */ /* unmap page run */
OsClearPte2Continuous(&pte2BasePtr[pte2Index], unmapCount); OsClearPte2Continuous(&pte2BasePtr[pte2Index], unmapCount);
/* invalidate tlb */ /* invalidate tlb */
OsArmInvalidateTlbMvaRangeNoBarrier(vaddr, unmapCount); OsArmInvalidateTlbMvaRangeNoBarrier(vaddr, unmapCount);
OsUnlockPte2(lock, intSave);
*count -= unmapCount; *count -= unmapCount;
return unmapCount; return unmapCount;
} }
STATIC UINT32 OsUnmapSection(LosArchMmu *archMmu, PTE_T *l1Entry, vaddr_t *vaddr, UINT32 *count) STATIC UINT32 OsUnmapSection(LosArchMmu *archMmu, vaddr_t *vaddr, UINT32 *count)
{ {
UINT32 intSave;
PADDR_T pte1Paddr;
SPIN_LOCK_S *lock = NULL;
pte1Paddr = OsGetPte1Paddr(archMmu->physTtb, *vaddr);
lock = OsGetPte1Lock(archMmu, pte1Paddr, &intSave);
if (!OsIsPte1Section(*l1Entry)) {
OsUnlockPte1(lock, intSave);
return 0;
}
OsClearPte1(OsGetPte1Ptr((PTE_T *)archMmu->virtTtb, *vaddr)); OsClearPte1(OsGetPte1Ptr((PTE_T *)archMmu->virtTtb, *vaddr));
OsArmInvalidateTlbMvaNoBarrier(*vaddr); OsArmInvalidateTlbMvaNoBarrier(*vaddr);
OsUnlockPte1(lock, intSave);
*vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE; *vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
*count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1; *count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
@ -493,18 +370,20 @@ STATIC UINT32 OsUnmapSection(LosArchMmu *archMmu, PTE_T *l1Entry, vaddr_t *vaddr
return MMU_DESCRIPTOR_L2_NUMBERS_PER_L1; return MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
} }
BOOL OsArchMmuInit(LosArchMmu *archMmu, VADDR_T *virtTtb) BOOL OsArchMmuInit(LosArchMmu *archMmu, VADDR_T *virtTtb)
{ {
#ifdef LOSCFG_KERNEL_VM
if (OsAllocAsid(&archMmu->asid) != LOS_OK) { if (OsAllocAsid(&archMmu->asid) != LOS_OK) {
VM_ERR("alloc arch mmu asid failed"); VM_ERR("alloc arch mmu asid failed");
return FALSE; return FALSE;
} }
#endif
#ifndef LOSCFG_PAGE_TABLE_FINE_LOCK status_t retval = LOS_MuxInit(&archMmu->mtx, NULL);
LOS_SpinInit(&archMmu->lock); if (retval != LOS_OK) {
#endif VM_ERR("Create mutex for arch mmu failed, status: %d", retval);
return FALSE;
}
LOS_ListInit(&archMmu->ptList); LOS_ListInit(&archMmu->ptList);
archMmu->virtTtb = virtTtb; archMmu->virtTtb = virtTtb;
archMmu->physTtb = (VADDR_T)(UINTPTR)virtTtb - KERNEL_ASPACE_BASE + SYS_MEM_BASE; archMmu->physTtb = (VADDR_T)(UINTPTR)virtTtb - KERNEL_ASPACE_BASE + SYS_MEM_BASE;
@ -553,55 +432,45 @@ STATUS_T LOS_ArchMmuQuery(const LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T *pad
STATUS_T LOS_ArchMmuUnmap(LosArchMmu *archMmu, VADDR_T vaddr, size_t count) STATUS_T LOS_ArchMmuUnmap(LosArchMmu *archMmu, VADDR_T vaddr, size_t count)
{ {
PTE_T *l1Entry = NULL; PTE_T l1Entry;
INT32 unmapped = 0; INT32 unmapped = 0;
UINT32 unmapCount = 0; UINT32 unmapCount = 0;
INT32 tryTime = TRY_MAX_TIMES;
while (count > 0) { while (count > 0) {
l1Entry = OsGetPte1Ptr(archMmu->virtTtb, vaddr); l1Entry = OsGetPte1(archMmu->virtTtb, vaddr);
if (OsIsPte1Invalid(*l1Entry)) { if (OsIsPte1Invalid(l1Entry)) {
unmapCount = OsUnmapL1Invalid(&vaddr, &count); unmapCount = OsUnmapL1Invalid(&vaddr, &count);
} else if (OsIsPte1Section(*l1Entry)) { } else if (OsIsPte1Section(l1Entry)) {
if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(vaddr) && count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) { if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(vaddr) && count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) {
unmapCount = OsUnmapSection(archMmu, l1Entry, &vaddr, &count); unmapCount = OsUnmapSection(archMmu, &vaddr, &count);
} else { } else {
LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__); LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__);
} }
} else if (OsIsPte1PageTable(*l1Entry)) { } else if (OsIsPte1PageTable(l1Entry)) {
unmapCount = OsUnmapL2PTE(archMmu, l1Entry, vaddr, &count); unmapCount = OsUnmapL2PTE(archMmu, vaddr, &count);
OsTryUnmapL1PTE(archMmu, l1Entry, vaddr, OsGetPte2Index(vaddr) + unmapCount, OsTryUnmapL1PTE(archMmu, vaddr, OsGetPte2Index(vaddr) + unmapCount,
MMU_DESCRIPTOR_L2_NUMBERS_PER_L1); MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 - unmapCount);
vaddr += unmapCount << MMU_DESCRIPTOR_L2_SMALL_SHIFT; vaddr += unmapCount << MMU_DESCRIPTOR_L2_SMALL_SHIFT;
} else { } else {
LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__); LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__);
} }
tryTime = (unmapCount == 0) ? (tryTime - 1) : tryTime;
if (tryTime == 0) {
return LOS_ERRNO_VM_FAULT;
}
unmapped += unmapCount; unmapped += unmapCount;
} }
OsArmInvalidateTlbBarrier(); OsArmInvalidateTlbBarrier();
return unmapped; return unmapped;
} }
STATIC UINT32 OsMapSection(MmuMapInfo *mmuMapInfo, UINT32 *count) STATIC UINT32 OsMapSection(const LosArchMmu *archMmu, UINT32 flags, VADDR_T *vaddr,
PADDR_T *paddr, UINT32 *count)
{ {
UINT32 mmuFlags = 0; UINT32 mmuFlags = 0;
UINT32 intSave;
PADDR_T pte1Paddr;
SPIN_LOCK_S *lock = NULL;
mmuFlags |= OsCvtSecFlagsToAttrs(*mmuMapInfo->flags); mmuFlags |= OsCvtSecFlagsToAttrs(flags);
pte1Paddr = OsGetPte1Paddr(mmuMapInfo->archMmu->physTtb, *mmuMapInfo->vaddr); OsSavePte1(OsGetPte1Ptr(archMmu->virtTtb, *vaddr),
lock = OsGetPte1Lock(mmuMapInfo->archMmu, pte1Paddr, &intSave); OsTruncPte1(*paddr) | mmuFlags | MMU_DESCRIPTOR_L1_TYPE_SECTION);
OsSavePte1(OsGetPte1Ptr(mmuMapInfo->archMmu->virtTtb, *mmuMapInfo->vaddr),
OsTruncPte1(*mmuMapInfo->paddr) | mmuFlags | MMU_DESCRIPTOR_L1_TYPE_SECTION);
OsUnlockPte1(lock, intSave);
*count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1; *count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
*mmuMapInfo->vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE; *vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
*mmuMapInfo->paddr += MMU_DESCRIPTOR_L1_SMALL_SIZE; *paddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
return MMU_DESCRIPTOR_L2_NUMBERS_PER_L1; return MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
} }
@ -611,6 +480,7 @@ STATIC STATUS_T OsGetL2Table(LosArchMmu *archMmu, UINT32 l1Index, paddr_t *ppa)
UINT32 index; UINT32 index;
PTE_T ttEntry; PTE_T ttEntry;
VADDR_T *kvaddr = NULL; VADDR_T *kvaddr = NULL;
LosVmPage *vmPage = NULL;
UINT32 l2Offset = (MMU_DESCRIPTOR_L2_SMALL_SIZE / MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE) * UINT32 l2Offset = (MMU_DESCRIPTOR_L2_SMALL_SIZE / MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE) *
(l1Index & (MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE - 1)); (l1Index & (MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE - 1));
/* lookup an existing l2 page table */ /* lookup an existing l2 page table */
@ -623,36 +493,45 @@ STATIC STATUS_T OsGetL2Table(LosArchMmu *archMmu, UINT32 l1Index, paddr_t *ppa)
} }
} }
#ifdef LOSCFG_KERNEL_VM
/* not found: allocate one (paddr) */ /* not found: allocate one (paddr) */
LosVmPage *vmPage = LOS_PhysPageAlloc(); vmPage = LOS_PhysPageAlloc();
if (vmPage == NULL) { if (vmPage == NULL) {
VM_ERR("have no memory to save l2 page"); VM_ERR("have no memory to save l2 page");
return LOS_ERRNO_VM_NO_MEMORY; return LOS_ERRNO_VM_NO_MEMORY;
} }
LOS_ListAdd(&archMmu->ptList, &vmPage->node); LOS_ListAdd(&archMmu->ptList, &vmPage->node);
kvaddr = OsVmPageToVaddr(vmPage); kvaddr = OsVmPageToVaddr(vmPage);
#else
kvaddr = LOS_MemAlloc(OS_SYS_MEM_ADDR, MMU_DESCRIPTOR_L2_SMALL_SIZE);
if (kvaddr == NULL) {
VM_ERR("have no memory to save l2 page");
return LOS_ERRNO_VM_NO_MEMORY;
}
#endif
(VOID)memset_s(kvaddr, MMU_DESCRIPTOR_L2_SMALL_SIZE, 0, MMU_DESCRIPTOR_L2_SMALL_SIZE); (VOID)memset_s(kvaddr, MMU_DESCRIPTOR_L2_SMALL_SIZE, 0, MMU_DESCRIPTOR_L2_SMALL_SIZE);
/* get physical address */ /* get physical address */
*ppa = OsKVaddrToPaddr((VADDR_T)kvaddr) + l2Offset; *ppa = LOS_PaddrQuery(kvaddr) + l2Offset;
return LOS_OK; return LOS_OK;
} }
STATIC VOID OsMapL1PTE(LosArchMmu *archMmu, PTE_T *pte1Ptr, vaddr_t vaddr, UINT32 flags)
{
paddr_t pte2Base = 0;
if (OsGetL2Table(archMmu, OsGetPte1Index(vaddr), &pte2Base) != LOS_OK) {
LOS_Panic("%s %d, failed to allocate pagetable\n", __FUNCTION__, __LINE__);
}
*pte1Ptr = pte2Base | MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE;
if (flags & VM_MAP_REGION_FLAG_NS) {
*pte1Ptr |= MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE;
}
*pte1Ptr &= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_MASK;
*pte1Ptr |= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT; // use client AP
OsSavePte1(OsGetPte1Ptr(archMmu->virtTtb, vaddr), *pte1Ptr);
}
STATIC UINT32 OsCvtPte2CacheFlagsToMMUFlags(UINT32 flags) STATIC UINT32 OsCvtPte2CacheFlagsToMMUFlags(UINT32 flags)
{ {
UINT32 mmuFlags = 0; UINT32 mmuFlags = 0;
switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) { switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) {
case VM_MAP_REGION_FLAG_CACHED: case VM_MAP_REGION_FLAG_CACHED:
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
mmuFlags |= MMU_DESCRIPTOR_L2_SHAREABLE; mmuFlags |= MMU_DESCRIPTOR_L2_SHAREABLE;
#endif #endif
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE; mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
@ -726,93 +605,32 @@ STATIC UINT32 OsCvtPte2FlagsToAttrs(UINT32 flags)
return mmuFlags; return mmuFlags;
} }
STATIC UINT32 OsMapL1PTE(MmuMapInfo *mmuMapInfo, PTE_T *l1Entry, UINT32 *count) STATIC UINT32 OsMapL2PageContinous(PTE_T pte1, UINT32 flags, VADDR_T *vaddr, PADDR_T *paddr, UINT32 *count)
{
PADDR_T pte2Base = 0;
PADDR_T pte1Paddr;
SPIN_LOCK_S *pte1Lock = NULL;
SPIN_LOCK_S *pte2Lock = NULL;
PTE_T *pte2BasePtr = NULL;
UINT32 saveCounts, archFlags, pte1IntSave, pte2IntSave;
pte1Paddr = OsGetPte1Paddr(mmuMapInfo->archMmu->physTtb, *mmuMapInfo->vaddr);
pte1Lock = OsGetPte1Lock(mmuMapInfo->archMmu, pte1Paddr, &pte1IntSave);
if (!OsIsPte1Invalid(*l1Entry)) {
OsUnlockPte1(pte1Lock, pte1IntSave);
return 0;
}
if (OsGetL2Table(mmuMapInfo->archMmu, OsGetPte1Index(*mmuMapInfo->vaddr), &pte2Base) != LOS_OK) {
LOS_Panic("%s %d, failed to allocate pagetable\n", __FUNCTION__, __LINE__);
}
*l1Entry = pte2Base | MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE;
if (*mmuMapInfo->flags & VM_MAP_REGION_FLAG_NS) {
*l1Entry |= MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE;
}
*l1Entry &= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_MASK;
*l1Entry |= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT; // use client AP
OsSavePte1(OsGetPte1Ptr(mmuMapInfo->archMmu->virtTtb, *mmuMapInfo->vaddr), *l1Entry);
OsUnlockPte1(pte1Lock, pte1IntSave);
pte2Lock = OsGetPte2Lock(mmuMapInfo->archMmu, *l1Entry, &pte2IntSave);
if (pte2Lock == NULL) {
LOS_Panic("pte2 should not be null!\n");
}
pte2BasePtr = (PTE_T *)LOS_PaddrToKVaddr(pte2Base);
/* compute the arch flags for L2 4K pages */
archFlags = OsCvtPte2FlagsToAttrs(*mmuMapInfo->flags);
saveCounts = OsSavePte2Continuous(pte2BasePtr, OsGetPte2Index(*mmuMapInfo->vaddr), *mmuMapInfo->paddr | archFlags,
*count);
OsUnlockPte2(pte2Lock, pte2IntSave);
*mmuMapInfo->paddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*mmuMapInfo->vaddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*count -= saveCounts;
return saveCounts;
}
STATIC UINT32 OsMapL2PageContinous(MmuMapInfo *mmuMapInfo, PTE_T *pte1, UINT32 *count)
{ {
PTE_T *pte2BasePtr = NULL; PTE_T *pte2BasePtr = NULL;
UINT32 archFlags; UINT32 archFlags;
UINT32 saveCounts; UINT32 saveCounts;
UINT32 intSave;
SPIN_LOCK_S *lock = NULL;
lock = OsGetPte2Lock(mmuMapInfo->archMmu, *pte1, &intSave); pte2BasePtr = OsGetPte2BasePtr(pte1);
if (lock == NULL) {
return 0;
}
pte2BasePtr = OsGetPte2BasePtr(*pte1);
if (pte2BasePtr == NULL) { if (pte2BasePtr == NULL) {
OsUnlockPte2(lock, intSave); LOS_Panic("%s %d, pte1 %#x error\n", __FUNCTION__, __LINE__, pte1);
return 0;
} }
/* compute the arch flags for L2 4K pages */ /* compute the arch flags for L2 4K pages */
archFlags = OsCvtPte2FlagsToAttrs(*mmuMapInfo->flags); archFlags = OsCvtPte2FlagsToAttrs(flags);
saveCounts = OsSavePte2Continuous(pte2BasePtr, OsGetPte2Index(*mmuMapInfo->vaddr), *mmuMapInfo->paddr | archFlags, saveCounts = OsSavePte2Continuous(pte2BasePtr, OsGetPte2Index(*vaddr), *paddr | archFlags, *count);
*count); *paddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
OsUnlockPte2(lock, intSave); *vaddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*mmuMapInfo->paddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*mmuMapInfo->vaddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
*count -= saveCounts; *count -= saveCounts;
return saveCounts; return saveCounts;
} }
status_t LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_t count, UINT32 flags) status_t LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_t count, UINT32 flags)
{ {
PTE_T *l1Entry = NULL; PTE_T l1Entry;
UINT32 saveCounts = 0; UINT32 saveCounts = 0;
INT32 mapped = 0; INT32 mapped = 0;
INT32 tryTime = TRY_MAX_TIMES;
INT32 checkRst; INT32 checkRst;
MmuMapInfo mmuMapInfo = {
.archMmu = archMmu,
.vaddr = &vaddr,
.paddr = &paddr,
.flags = &flags,
};
checkRst = OsMapParamCheck(flags, vaddr, paddr); checkRst = OsMapParamCheck(flags, vaddr, paddr);
if (checkRst < 0) { if (checkRst < 0) {
@ -821,27 +639,24 @@ status_t LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_
/* see what kind of mapping we can use */ /* see what kind of mapping we can use */
while (count > 0) { while (count > 0) {
if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(*mmuMapInfo.vaddr) && if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(vaddr) &&
MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(*mmuMapInfo.paddr) && MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(paddr) &&
count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) { count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) {
/* compute the arch flags for L1 sections cache, r ,w ,x, domain and type */ /* compute the arch flags for L1 sections cache, r ,w ,x, domain and type */
saveCounts = OsMapSection(&mmuMapInfo, &count); saveCounts = OsMapSection(archMmu, flags, &vaddr, &paddr, &count);
} else { } else {
/* have to use a L2 mapping, we only allocate 4KB for L1, support 0 ~ 1GB */ /* have to use a L2 mapping, we only allocate 4KB for L1, support 0 ~ 1GB */
l1Entry = OsGetPte1Ptr(archMmu->virtTtb, *mmuMapInfo.vaddr); l1Entry = OsGetPte1(archMmu->virtTtb, vaddr);
if (OsIsPte1Invalid(*l1Entry)) { if (OsIsPte1Invalid(l1Entry)) {
saveCounts = OsMapL1PTE(&mmuMapInfo, l1Entry, &count); OsMapL1PTE(archMmu, &l1Entry, vaddr, flags);
} else if (OsIsPte1PageTable(*l1Entry)) { saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count);
saveCounts = OsMapL2PageContinous(&mmuMapInfo, l1Entry, &count); } else if (OsIsPte1PageTable(l1Entry)) {
saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count);
} else { } else {
LOS_Panic("%s %d, unimplemented tt_entry %x\n", __FUNCTION__, __LINE__, l1Entry); LOS_Panic("%s %d, unimplemented tt_entry %x\n", __FUNCTION__, __LINE__, l1Entry);
} }
} }
mapped += saveCounts; mapped += saveCounts;
tryTime = (saveCounts == 0) ? (tryTime - 1) : tryTime;
if (tryTime == 0) {
return LOS_ERRNO_VM_TIMED_OUT;
}
} }
return mapped; return mapped;
@ -888,7 +703,7 @@ STATUS_T LOS_ArchMmuMove(LosArchMmu *archMmu, VADDR_T oldVaddr, VADDR_T newVaddr
PADDR_T paddr = 0; PADDR_T paddr = 0;
if ((archMmu == NULL) || (oldVaddr == 0) || (newVaddr == 0) || (count == 0)) { if ((archMmu == NULL) || (oldVaddr == 0) || (newVaddr == 0) || (count == 0)) {
VM_ERR("invalid args: archMmu %p, oldVaddr %p, newVaddr %p, count %d", VM_ERR("invalid args: archMmu %p, oldVaddr %p, newVddr %p, count %d",
archMmu, oldVaddr, newVaddr, count); archMmu, oldVaddr, newVaddr, count);
return LOS_NOK; return LOS_NOK;
} }
@ -936,35 +751,30 @@ VOID LOS_ArchMmuContextSwitch(LosArchMmu *archMmu)
ttbcr |= MMU_DESCRIPTOR_TTBCR_PD0; ttbcr |= MMU_DESCRIPTOR_TTBCR_PD0;
} }
#ifdef LOSCFG_KERNEL_VM
/* from armv7a arm B3.10.4, we should do synchronization changes of ASID and TTBR. */ /* from armv7a arm B3.10.4, we should do synchronization changes of ASID and TTBR. */
OsArmWriteContextidr(LOS_GetKVmSpace()->archMmu.asid); OsArmWriteContextidr(LOS_GetKVmSpace()->archMmu.asid);
ISB; ISB;
#endif
OsArmWriteTtbr0(ttbr); OsArmWriteTtbr0(ttbr);
ISB; ISB;
OsArmWriteTtbcr(ttbcr); OsArmWriteTtbcr(ttbcr);
ISB; ISB;
#ifdef LOSCFG_KERNEL_VM
if (archMmu) { if (archMmu) {
OsArmWriteContextidr(archMmu->asid); OsArmWriteContextidr(archMmu->asid);
ISB; ISB;
} }
#endif
} }
STATUS_T LOS_ArchMmuDestroy(LosArchMmu *archMmu) STATUS_T LOS_ArchMmuDestroy(LosArchMmu *archMmu)
{ {
#ifdef LOSCFG_KERNEL_VM
LosVmPage *page = NULL; LosVmPage *page = NULL;
/* free all of the pages allocated in archMmu->ptList */ /* free all of the pages allocated in archMmu->ptList */
while ((page = LOS_ListRemoveHeadType(&archMmu->ptList, LosVmPage, node)) != NULL) { while ((page = LOS_ListRemoveHeadType(&archMmu->ptList, LosVmPage, node)) != NULL) {
LOS_PhysPageFree(page); LOS_PhysPageFree(page);
} }
OsArmWriteTlbiasidis(archMmu->asid); OsArmWriteTlbiasid(archMmu->asid);
OsFreeAsid(archMmu->asid); OsFreeAsid(archMmu->asid);
#endif (VOID)LOS_MuxDestroy(&archMmu->mtx);
return LOS_OK; return LOS_OK;
} }
@ -996,34 +806,38 @@ STATIC VOID OsSwitchTmpTTB(VOID)
ISB; ISB;
} }
STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached) VADDR_T *OsGFirstTableGet()
{
return (VADDR_T *)g_firstPageTable;
}
STATIC VOID OsSetKSectionAttr(VOID)
{ {
UINT32 offset = virtAddr - KERNEL_VMM_BASE;
/* every section should be page aligned */ /* every section should be page aligned */
UINTPTR textStart = (UINTPTR)&__text_start + offset; UINTPTR textStart = (UINTPTR)&__text_start;
UINTPTR textEnd = (UINTPTR)&__text_end + offset; UINTPTR textEnd = (UINTPTR)&__text_end;
UINTPTR rodataStart = (UINTPTR)&__rodata_start + offset; UINTPTR rodataStart = (UINTPTR)&__rodata_start;
UINTPTR rodataEnd = (UINTPTR)&__rodata_end + offset; UINTPTR rodataEnd = (UINTPTR)&__rodata_end;
UINTPTR ramDataStart = (UINTPTR)&__ram_data_start + offset; UINTPTR ramDataStart = (UINTPTR)&__ram_data_start;
UINTPTR bssEnd = (UINTPTR)&__bss_end + offset; UINTPTR bssEnd = (UINTPTR)&__bss_end;
UINT32 bssEndBoundary = ROUNDUP(bssEnd, MB); UINT32 bssEndBoundary = ROUNDUP(bssEnd, MB);
LosArchMmuInitMapping mmuKernelMappings[] = { LosArchMmuInitMapping mmuKernelMappings[] = {
{ {
.phys = SYS_MEM_BASE + textStart - virtAddr, .phys = SYS_MEM_BASE + textStart - KERNEL_VMM_BASE,
.virt = textStart, .virt = textStart,
.size = ROUNDUP(textEnd - textStart, MMU_DESCRIPTOR_L2_SMALL_SIZE), .size = ROUNDUP(textEnd - textStart, MMU_DESCRIPTOR_L2_SMALL_SIZE),
.flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_EXECUTE, .flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_EXECUTE,
.name = "kernel_text" .name = "kernel_text"
}, },
{ {
.phys = SYS_MEM_BASE + rodataStart - virtAddr, .phys = SYS_MEM_BASE + rodataStart - KERNEL_VMM_BASE,
.virt = rodataStart, .virt = rodataStart,
.size = ROUNDUP(rodataEnd - rodataStart, MMU_DESCRIPTOR_L2_SMALL_SIZE), .size = ROUNDUP(rodataEnd - rodataStart, MMU_DESCRIPTOR_L2_SMALL_SIZE),
.flags = VM_MAP_REGION_FLAG_PERM_READ, .flags = VM_MAP_REGION_FLAG_PERM_READ,
.name = "kernel_rodata" .name = "kernel_rodata"
}, },
{ {
.phys = SYS_MEM_BASE + ramDataStart - virtAddr, .phys = SYS_MEM_BASE + ramDataStart - KERNEL_VMM_BASE,
.virt = ramDataStart, .virt = ramDataStart,
.size = ROUNDUP(bssEndBoundary - ramDataStart, MMU_DESCRIPTOR_L2_SMALL_SIZE), .size = ROUNDUP(bssEndBoundary - ramDataStart, MMU_DESCRIPTOR_L2_SMALL_SIZE),
.flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE, .flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE,
@ -1033,29 +847,26 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
LosVmSpace *kSpace = LOS_GetKVmSpace(); LosVmSpace *kSpace = LOS_GetKVmSpace();
status_t status; status_t status;
UINT32 length; UINT32 length;
INT32 i; paddr_t oldTtPhyBase;
int i;
LosArchMmuInitMapping *kernelMap = NULL; LosArchMmuInitMapping *kernelMap = NULL;
UINT32 kmallocLength; UINT32 kmallocLength;
UINT32 flags;
/* use second-level mapping of default READ and WRITE */ /* use second-level mapping of default READ and WRITE */
kSpace->archMmu.virtTtb = (PTE_T *)g_firstPageTable; kSpace->archMmu.virtTtb = (PTE_T *)g_firstPageTable;
kSpace->archMmu.physTtb = LOS_PaddrQuery(kSpace->archMmu.virtTtb); kSpace->archMmu.physTtb = LOS_PaddrQuery(kSpace->archMmu.virtTtb);
status = LOS_ArchMmuUnmap(&kSpace->archMmu, virtAddr, status = LOS_ArchMmuUnmap(&kSpace->archMmu, KERNEL_VMM_BASE,
(bssEndBoundary - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT); (bssEndBoundary - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT);
if (status != ((bssEndBoundary - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) { if (status != ((bssEndBoundary - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
VM_ERR("unmap failed, status: %d", status); VM_ERR("unmap failed, status: %d", status);
return; return;
} }
flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE | VM_MAP_REGION_FLAG_PERM_EXECUTE; status = LOS_ArchMmuMap(&kSpace->archMmu, KERNEL_VMM_BASE, SYS_MEM_BASE,
if (uncached) { (textStart - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
flags |= VM_MAP_REGION_FLAG_UNCACHED; VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE |
} VM_MAP_REGION_FLAG_PERM_EXECUTE);
status = LOS_ArchMmuMap(&kSpace->archMmu, virtAddr, SYS_MEM_BASE, if (status != ((textStart - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
(textStart - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
flags);
if (status != ((textStart - virtAddr) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
VM_ERR("mmap failed, status: %d", status); VM_ERR("mmap failed, status: %d", status);
return; return;
} }
@ -1063,9 +874,6 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
length = sizeof(mmuKernelMappings) / sizeof(LosArchMmuInitMapping); length = sizeof(mmuKernelMappings) / sizeof(LosArchMmuInitMapping);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
kernelMap = &mmuKernelMappings[i]; kernelMap = &mmuKernelMappings[i];
if (uncached) {
kernelMap->flags |= VM_MAP_REGION_FLAG_UNCACHED;
}
status = LOS_ArchMmuMap(&kSpace->archMmu, kernelMap->virt, kernelMap->phys, status = LOS_ArchMmuMap(&kSpace->archMmu, kernelMap->virt, kernelMap->phys,
kernelMap->size >> MMU_DESCRIPTOR_L2_SMALL_SHIFT, kernelMap->flags); kernelMap->size >> MMU_DESCRIPTOR_L2_SMALL_SHIFT, kernelMap->flags);
if (status != (kernelMap->size >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) { if (status != (kernelMap->size >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
@ -1075,29 +883,16 @@ STATIC VOID OsSetKSectionAttr(UINTPTR virtAddr, BOOL uncached)
LOS_VmSpaceReserve(kSpace, kernelMap->size, kernelMap->virt); LOS_VmSpaceReserve(kSpace, kernelMap->size, kernelMap->virt);
} }
kmallocLength = virtAddr + SYS_MEM_SIZE_DEFAULT - bssEndBoundary; kmallocLength = KERNEL_VMM_BASE + SYS_MEM_SIZE_DEFAULT - bssEndBoundary;
flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE;
if (uncached) {
flags |= VM_MAP_REGION_FLAG_UNCACHED;
}
status = LOS_ArchMmuMap(&kSpace->archMmu, bssEndBoundary, status = LOS_ArchMmuMap(&kSpace->archMmu, bssEndBoundary,
SYS_MEM_BASE + bssEndBoundary - virtAddr, SYS_MEM_BASE + bssEndBoundary - KERNEL_VMM_BASE,
kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT, kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
flags); VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE);
if (status != (kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) { if (status != (kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
VM_ERR("mmap failed, status: %d", status); VM_ERR("mmap failed, status: %d", status);
return; return;
} }
LOS_VmSpaceReserve(kSpace, kmallocLength, bssEndBoundary); LOS_VmSpaceReserve(kSpace, kmallocLength, bssEndBoundary);
}
STATIC VOID OsKSectionNewAttrEnable(VOID)
{
LosVmSpace *kSpace = LOS_GetKVmSpace();
paddr_t oldTtPhyBase;
kSpace->archMmu.virtTtb = (PTE_T *)g_firstPageTable;
kSpace->archMmu.physTtb = LOS_PaddrQuery(kSpace->archMmu.virtTtb);
/* we need free tmp ttbase */ /* we need free tmp ttbase */
oldTtPhyBase = OsArmReadTtbr0(); oldTtPhyBase = OsArmReadTtbr0();
@ -1131,9 +926,14 @@ VOID OsInitMappingStartUp(VOID)
OsSwitchTmpTTB(); OsSwitchTmpTTB();
OsSetKSectionAttr(KERNEL_VMM_BASE, FALSE); OsSetKSectionAttr();
OsSetKSectionAttr(UNCACHED_VMM_BASE, TRUE);
OsKSectionNewAttrEnable(); OsArchMmuInitPerCPU();
} }
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@ -39,8 +39,11 @@
#include "los_spinlock.h" #include "los_spinlock.h"
#include "los_mmu_descriptor_v6.h" #include "los_mmu_descriptor_v6.h"
#ifdef __cplusplus
#ifdef LOSCFG_KERNEL_VM #if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
STATIC SPIN_LOCK_INIT(g_cpuAsidLock); STATIC SPIN_LOCK_INIT(g_cpuAsidLock);
STATIC UINTPTR g_asidPool[BITMAP_NUM_WORDS(1UL << MMU_ARM_ASID_BITS)]; STATIC UINTPTR g_asidPool[BITMAP_NUM_WORDS(1UL << MMU_ARM_ASID_BITS)];
@ -69,5 +72,9 @@ VOID OsFreeAsid(UINT32 asid)
LOS_BitmapClrNBits(g_asidPool, asid, 1); LOS_BitmapClrNBits(g_asidPool, asid, 1);
LOS_SpinUnlockRestore(&g_cpuAsidLock, flags); LOS_SpinUnlockRestore(&g_cpuAsidLock, flags);
} }
#endif
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

151
arch/arm/arm/src/los_dispatch.S Normal file → Executable file
View File

@ -32,7 +32,6 @@
#include "asm.h" #include "asm.h"
#include "arch_config.h" #include "arch_config.h"
.extern OsSaveSignalContext
.extern OsSchedToUserReleaseLock .extern OsSchedToUserReleaseLock
.global OsTaskSchedule .global OsTaskSchedule
.global OsTaskContextLoad .global OsTaskContextLoad
@ -86,16 +85,17 @@
*/ */
OsTaskSchedule: OsTaskSchedule:
MRS R2, CPSR MRS R2, CPSR
STMFD SP!, {LR}
STMFD SP!, {LR}
/* jump sp */
SUB SP, SP, #4
/* push r0-r12*/
STMFD SP!, {R0-R12}
STMFD SP!, {R2} STMFD SP!, {R2}
STMFD SP!, {LR}
STMFD SP!, {LR}
STMFD SP!, {R12}
/* jump R0 - R3 USP, ULR reserved */ /* 8 bytes stack align */
SUB SP, SP, #(8 * 4) SUB SP, SP, #4
/* push R4 - R11*/
STMFD SP!, {R4-R11}
/* save fpu registers */ /* save fpu registers */
PUSH_FPU_REGS R2 PUSH_FPU_REGS R2
@ -113,96 +113,131 @@ OsTaskContextLoad:
/* restore fpu registers */ /* restore fpu registers */
POP_FPU_REGS R2 POP_FPU_REGS R2
LDMFD SP!, {R4-R11} /* 8 bytes stack align */
LDR R3, [SP, #(11 * 4)] ADD SP, SP, #4
AND R0, R3, #CPSR_MASK_MODE
LDMFD SP!, {R0}
MOV R4, R0
AND R0, R0, #CPSR_MASK_MODE
CMP R0, #CPSR_USER_MODE CMP R0, #CPSR_USER_MODE
BNE OsKernelTaskLoad BNE OsKernelTaskLoad
MVN R2, #CPSR_INT_DISABLE
AND R3, R3, R2
STR R3, [SP, #(11 * 4)]
#ifdef LOSCFG_KERNEL_SMP #ifdef LOSCFG_KERNEL_SMP
/* 8 bytes stack align */
SUB SP, SP, #4
BL OsSchedToUserReleaseLock BL OsSchedToUserReleaseLock
ADD SP, SP, #4
#endif #endif
/* jump sp, reserved */ MVN R3, #CPSR_INT_DISABLE
ADD SP, SP, #(2 * 4) AND R4, R4, R3
MSR SPSR_cxsf, R4
/* restore r0-r12, lr */
LDMFD SP!, {R0-R12}
LDMFD SP, {R13, R14}^ LDMFD SP, {R13, R14}^
ADD SP, SP, #(2 * 4) ADD SP, SP, #(2 * 4)
LDMFD SP!, {R0-R3, R12, LR} LDMFD SP!, {PC}^
RFEIA SP!
OsKernelTaskLoad: OsKernelTaskLoad:
ADD SP, SP, #(4 * 4) MSR SPSR_cxsf, R4
LDMFD SP!, {R0-R3, R12, LR} /* restore r0-r12, lr */
RFEIA SP! LDMFD SP!, {R0-R12}
ADD SP, SP, #4
LDMFD SP!, {LR, PC}^
OsIrqHandler: OsIrqHandler:
SUB LR, LR, #4 SUB LR, LR, #4
/* Save pc and cpsr to svc sp, ARMv6 and above support */ /* push r0-r3 to irq stack */
SRSFD #0x13! STMFD SP, {R0-R3}
SUB R0, SP, #(4 * 4)
MRS R1, SPSR
MOV R2, LR
/* disable irq, switch to svc mode */ /* disable irq, switch to svc mode */
CPSID i, #0x13 CPSID i, #0x13
#ifdef LOSCFG_KERNEL_PERF /* push spsr and pc in svc stack */
PUSH {R0-R3, R12, LR} STMFD SP!, {R1, R2}
MOV R0, LR STMFD SP, {LR}
MOV R1, FP
BL OsPerfSetIrqRegs
POP {R0-R3, R12, LR}
#endif
STMFD SP!, {R0-R3, R12, LR} AND R3, R1, #CPSR_MASK_MODE
CMP R3, #CPSR_USER_MODE
BNE OsIrqFromKernel
/* push user sp, lr in svc stack */
STMFD SP, {R13, R14}^ STMFD SP, {R13, R14}^
SUB SP, SP, #(4 * 4)
STR R4, [SP, #0] OsIrqFromKernel:
/* from svc not need save sp and lr */
SUB SP, SP, #(2 * 4)
/* pop r0-r3 form irq stack*/
LDMFD R0, {R0-R3}
/* push caller saved regs as trashed regs in svc stack */
STMFD SP!, {R0-R3, R12}
/* 8 bytes stack align */
SUB SP, SP, #4
/* /*
* save fpu regs in case in case those been * save fpu regs in case in case those been
* altered in interrupt handlers. * altered in interrupt handlers.
*/ */
PUSH_FPU_REGS R0 PUSH_FPU_REGS R0
#ifdef LOSCFG_IRQ_USE_STANDALONE_STACK
PUSH {R4}
MOV R4, SP MOV R4, SP
EXC_SP_SET __svc_stack_top, OS_EXC_SVC_STACK_SIZE, R1, R2 EXC_SP_SET __svc_stack_top, OS_EXC_SVC_STACK_SIZE, R1, R2
#endif
BLX HalIrqHandler BLX HalIrqHandler
#ifdef LOSCFG_IRQ_USE_STANDALONE_STACK
MOV SP, R4 MOV SP, R4
POP {R4}
#endif
/* process pending signals */ /* process pending signals */
BLX OsTaskProcSignal BL OsTaskProcSignal
BLX OsSchedIrqEndCheckNeedSched
BL OsSchedIrqEndCheckNeedSched
MOV R0,SP
MOV R1,R7
BL OsSaveSignalContextIrq
/* restore fpu regs */ /* restore fpu regs */
POP_FPU_REGS R0 POP_FPU_REGS R0
LDR R4, [SP, #0]
#ifdef LOSCFG_KERNEL_VM ADD SP, SP, #4
/* Obtain the CPSR to determine the mode the system is in when the interrupt is triggered */
LDR R3, [SP, #(11 * 4)] OsIrqContextRestore:
AND R1, R3, #CPSR_MASK_MODE LDR R0, [SP, #(4 * 7)]
CMP R1, #CPSR_USER_MODE MSR SPSR_cxsf, R0
BNE 1f AND R0, R0, #CPSR_MASK_MODE
CMP R0, #CPSR_USER_MODE
LDMFD SP!, {R0-R3, R12}
BNE OsIrqContextRestoreToKernel
MOV R0, SP
STR R7, [SP, #0]
/* sp - sizeof(IrqContext) */
SUB SP, SP, #(12 * 4)
MOV R1, SP
BLX OsSaveSignalContext
MOV SP, R0
1:
#endif
ADD SP, SP, #(2 * 4)
/* load user sp and lr, and jump cpsr */ /* load user sp and lr, and jump cpsr */
LDMFD SP, {R13, R14}^ LDMFD SP, {R13, R14}^
ADD SP, SP, #(2 * 4) ADD SP, SP, #(3 * 4)
LDMFD SP!, {R0-R3, R12, LR}
RFEIA SP! /* return to user mode */
LDMFD SP!, {PC}^
OsIrqContextRestoreToKernel:
/* svc mode not load sp */
ADD SP, SP, #4
LDMFD SP!, {LR}
/* jump cpsr and return to svc mode */
ADD SP, SP, #4
LDMFD SP!, {PC}^
FUNCTION(ArchSpinLock) FUNCTION(ArchSpinLock)
mov r1, #1 mov r1, #1

481
arch/arm/arm/src/los_exc.c Normal file → Executable file
View File

@ -33,12 +33,15 @@
#include "los_memory_pri.h" #include "los_memory_pri.h"
#include "los_printf_pri.h" #include "los_printf_pri.h"
#include "los_task_pri.h" #include "los_task_pri.h"
#include "los_percpu_pri.h"
#include "los_hw_pri.h" #include "los_hw_pri.h"
#ifdef LOSCFG_SAVE_EXCINFO #ifdef LOSCFG_SHELL_EXCINFO
#include "los_excinfo_pri.h" #include "los_excinfo_pri.h"
#endif #endif
#ifdef LOSCFG_EXC_INTERACTION
#include "los_exc_interaction_pri.h"
#endif
#include "los_sys_stack_pri.h" #include "los_sys_stack_pri.h"
#include "los_stackinfo_pri.h"
#ifdef LOSCFG_COREDUMP #ifdef LOSCFG_COREDUMP
#include "los_coredump.h" #include "los_coredump.h"
#endif #endif
@ -52,21 +55,20 @@
#include "los_vm_phys.h" #include "los_vm_phys.h"
#include "los_vm_fault.h" #include "los_vm_fault.h"
#include "los_vm_common.h" #include "los_vm_common.h"
#ifdef LOSCFG_KERNEL_DYNLOAD
#include "los_load_elf.h" #include "los_load_elf.h"
#endif
#include "arm.h" #include "arm.h"
#include "los_bitmap.h" #include "los_bitmap.h"
#include "los_process_pri.h" #include "los_process_pri.h"
#include "los_exc_pri.h" #include "los_exc_pri.h"
#include "los_sched_pri.h"
#ifdef LOSCFG_FS_VFS #ifdef LOSCFG_FS_VFS
#include "console.h" #include "console.h"
#endif #endif
#ifdef LOSCFG_BLACKBOX
#include "los_blackbox.h"
#endif
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define INVALID_CPUID 0xFFFF #define INVALID_CPUID 0xFFFF
#define OS_EXC_VMM_NO_REGION 0x0U #define OS_EXC_VMM_NO_REGION 0x0U
@ -74,12 +76,12 @@
STATIC UINTPTR g_minAddr; STATIC UINTPTR g_minAddr;
STATIC UINTPTR g_maxAddr; STATIC UINTPTR g_maxAddr;
STATIC UINT32 g_currHandleExcCpuid = INVALID_CPUID; STATIC UINT32 g_currHandleExcCpuID = INVALID_CPUID;
VOID OsExcHook(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr); VOID OsExcHook(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr);
UINT32 g_curNestCount[LOSCFG_KERNEL_CORE_NUM] = { 0 }; UINT32 g_curNestCount[LOSCFG_KERNEL_CORE_NUM] = { 0 };
BOOL g_excFromUserMode[LOSCFG_KERNEL_CORE_NUM]; BOOL g_excFromUserMode[LOSCFG_KERNEL_CORE_NUM];
STATIC EXC_PROC_FUNC g_excHook = (EXC_PROC_FUNC)OsExcHook; STATIC EXC_PROC_FUNC g_excHook = (EXC_PROC_FUNC)OsExcHook;
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
STATIC SPIN_LOCK_INIT(g_excSerializerSpin); STATIC SPIN_LOCK_INIT(g_excSerializerSpin);
STATIC UINT32 g_currHandleExcPID = OS_INVALID_VALUE; STATIC UINT32 g_currHandleExcPID = OS_INVALID_VALUE;
STATIC UINT32 g_nextExcWaitCpu = INVALID_CPUID; STATIC UINT32 g_nextExcWaitCpu = INVALID_CPUID;
@ -88,7 +90,6 @@ STATIC UINT32 g_nextExcWaitCpu = INVALID_CPUID;
#define OS_MAX_BACKTRACE 15U #define OS_MAX_BACKTRACE 15U
#define DUMPSIZE 128U #define DUMPSIZE 128U
#define DUMPREGS 12U #define DUMPREGS 12U
#define COM_REGS 4U
#define INSTR_SET_MASK 0x01000020U #define INSTR_SET_MASK 0x01000020U
#define THUMB_INSTR_LEN 2U #define THUMB_INSTR_LEN 2U
#define ARM_INSTR_LEN 4U #define ARM_INSTR_LEN 4U
@ -106,18 +107,22 @@ STATIC UINT32 g_nextExcWaitCpu = INVALID_CPUID;
(IS_ALIGNED((ptr), sizeof(CHAR *)))) (IS_ALIGNED((ptr), sizeof(CHAR *))))
STATIC const StackInfo g_excStack[] = { STATIC const StackInfo g_excStack[] = {
{ &__undef_stack, OS_EXC_UNDEF_STACK_SIZE, "udf_stack" },
{ &__abt_stack, OS_EXC_ABT_STACK_SIZE, "abt_stack" },
{ &__fiq_stack, OS_EXC_FIQ_STACK_SIZE, "fiq_stack" },
{ &__svc_stack, OS_EXC_SVC_STACK_SIZE, "svc_stack" }, { &__svc_stack, OS_EXC_SVC_STACK_SIZE, "svc_stack" },
{ &__irq_stack, OS_EXC_IRQ_STACK_SIZE, "irq_stack" },
{ &__exc_stack, OS_EXC_STACK_SIZE, "exc_stack" } { &__exc_stack, OS_EXC_STACK_SIZE, "exc_stack" }
}; };
UINT32 OsGetSystemStatus(VOID) UINT32 OsGetSystemStatus(VOID)
{ {
UINT32 flag; UINT32 flag;
UINT32 cpuid = g_currHandleExcCpuid; UINT32 cpuID = g_currHandleExcCpuID;
if (cpuid == INVALID_CPUID) { if (cpuID == INVALID_CPUID) {
flag = OS_SYSTEM_NORMAL; flag = OS_SYSTEM_NORMAL;
} else if (cpuid == ArchCurrCpuid()) { } else if (cpuID == ArchCurrCpuid()) {
flag = OS_SYSTEM_EXC_CURR_CPU; flag = OS_SYSTEM_EXC_CURR_CPU;
} else { } else {
flag = OS_SYSTEM_EXC_OTHER_CPU; flag = OS_SYSTEM_EXC_OTHER_CPU;
@ -180,32 +185,20 @@ STATIC INT32 OsDecodeDataFSR(UINT32 regDFSR)
return ret; return ret;
} }
#ifdef LOSCFG_KERNEL_VM
UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT32 fsr) UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT32 fsr)
{ {
BOOL instructionFault = FALSE; PRINT_INFO("page fault entry!!!\n");
BOOL instruction_fault = FALSE;
UINT32 pfFlags = 0; UINT32 pfFlags = 0;
UINT32 fsrFlag; UINT32 fsrFlag;
BOOL write = FALSE; BOOL write = FALSE;
UINT32 ret;
PRINT_INFO("page fault entry!!!\n");
if (OsGetSystemStatus() == OS_SYSTEM_EXC_CURR_CPU) { if (OsGetSystemStatus() == OS_SYSTEM_EXC_CURR_CPU) {
return LOS_ERRNO_VM_NOT_FOUND; return LOS_ERRNO_VM_NOT_FOUND;
} }
#if defined(LOSCFG_KERNEL_SMP) && defined(LOSCFG_DEBUG_VERSION)
BOOL irqEnable = !(LOS_SpinHeld(&g_taskSpin) && OsSchedIsLock());
if (irqEnable) {
ArchIrqEnable();
} else {
PrintExcInfo("[ERR][%s] may be held scheduler lock when entering [%s] on cpu [%u]\n",
OsCurrTaskGet()->taskName, __FUNCTION__, ArchCurrCpuid());
}
#else
ArchIrqEnable();
#endif
if (excType == OS_EXCEPT_PREFETCH_ABORT) { if (excType == OS_EXCEPT_PREFETCH_ABORT) {
instructionFault = TRUE; instruction_fault = TRUE;
} else { } else {
write = !!BIT_GET(fsr, WNR_BIT); write = !!BIT_GET(fsr, WNR_BIT);
} }
@ -223,32 +216,18 @@ UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT3
BOOL user = (frame->regCPSR & CPSR_MODE_MASK) == CPSR_MODE_USR; BOOL user = (frame->regCPSR & CPSR_MODE_MASK) == CPSR_MODE_USR;
pfFlags |= write ? VM_MAP_PF_FLAG_WRITE : 0; pfFlags |= write ? VM_MAP_PF_FLAG_WRITE : 0;
pfFlags |= user ? VM_MAP_PF_FLAG_USER : 0; pfFlags |= user ? VM_MAP_PF_FLAG_USER : 0;
pfFlags |= instructionFault ? VM_MAP_PF_FLAG_INSTRUCTION : 0; pfFlags |= instruction_fault ? VM_MAP_PF_FLAG_INSTRUCTION : 0;
pfFlags |= VM_MAP_PF_FLAG_NOT_PRESENT; pfFlags |= VM_MAP_PF_FLAG_NOT_PRESENT;
OsSigIntLock(); return OsVmPageFaultHandler(far, pfFlags, frame);
ret = OsVmPageFaultHandler(far, pfFlags, frame);
OsSigIntUnlock();
break;
} }
default: default:
OsArmWriteTlbimvaais(ROUNDDOWN(far, PAGE_SIZE)); return LOS_ERRNO_VM_NOT_FOUND;
ret = LOS_OK;
break;
} }
#if defined(LOSCFG_KERNEL_SMP) && defined(LOSCFG_DEBUG_VERSION)
if (irqEnable) {
ArchIrqDisable();
} }
#else
ArchIrqDisable();
#endif
return ret;
}
#endif
STATIC VOID OsExcType(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr) STATIC VOID OsExcType(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr)
{ {
/* undefined exception handling or software interrupt */ /* undefinited exception handling or software interrupt */
if ((excType == OS_EXCEPT_UNDEF_INSTR) || (excType == OS_EXCEPT_SWI)) { if ((excType == OS_EXCEPT_UNDEF_INSTR) || (excType == OS_EXCEPT_SWI)) {
if ((excBufAddr->regCPSR & INSTR_SET_MASK) == 0) { /* work status: ARM */ if ((excBufAddr->regCPSR & INSTR_SET_MASK) == 0) { /* work status: ARM */
excBufAddr->PC = excBufAddr->PC - ARM_INSTR_LEN; excBufAddr->PC = excBufAddr->PC - ARM_INSTR_LEN;
@ -277,11 +256,10 @@ STATIC const CHAR *g_excTypeString[] = {
"irq" "irq"
}; };
#ifdef LOSCFG_KERNEL_VM
STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProcess) STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProcess)
{ {
struct Vnode *curVnode = NULL; struct file *curFilep = NULL;
struct Vnode *lastVnode = NULL; struct file *lastFilep = NULL;
LosVmMapRegion *curRegion = NULL; LosVmMapRegion *curRegion = NULL;
LosVmMapRegion *lastRegion = NULL; LosVmMapRegion *lastRegion = NULL;
@ -300,57 +278,46 @@ STATIC VADDR_T OsGetTextRegionBase(LosVmMapRegion *region, LosProcessCB *runProc
if ((lastRegion == NULL) || !LOS_IsRegionFileValid(lastRegion)) { if ((lastRegion == NULL) || !LOS_IsRegionFileValid(lastRegion)) {
goto DONE; goto DONE;
} }
curVnode = curRegion->unTypeData.rf.vnode; curFilep = curRegion->unTypeData.rf.file;
lastVnode = lastRegion->unTypeData.rf.vnode; lastFilep = lastRegion->unTypeData.rf.file;
} while (curVnode == lastVnode); } while (!strcmp(curFilep->f_path, lastFilep->f_path));
DONE: DONE:
#ifdef LOSCFG_KERNEL_DYNLOAD
if (curRegion->range.base == EXEC_MMAP_BASE) { if (curRegion->range.base == EXEC_MMAP_BASE) {
return 0; return 0;
} }
#endif
return curRegion->range.base; return curRegion->range.base;
} }
#endif
STATIC VOID OsExcSysInfo(UINT32 excType, const ExcContext *excBufAddr) STATIC VOID OsExcSysInfo(UINT32 excType, const ExcContext *excBufAddr)
{ {
LosTaskCB *runTask = OsCurrTaskGet(); LosTaskCB *runTask = OsCurrTaskGet();
LosProcessCB *runProcess = OsCurrProcessGet(); LosProcessCB *runProcess = OsCurrProcessGet();
LosVmMapRegion *region = NULL;
PrintExcInfo("excType: %s\n" PrintExcInfo("excType: %s\n"
"processName = %s\n" "processName = %s\n"
"processID = %u\n" "processID = %u\n"
#ifdef LOSCFG_KERNEL_VM
"process aspace = 0x%08x -> 0x%08x\n" "process aspace = 0x%08x -> 0x%08x\n"
#endif
"taskName = %s\n" "taskName = %s\n"
"taskID = %u\n", "taskID = %u\n",
g_excTypeString[excType], g_excTypeString[excType],
runProcess->processName, runProcess->processName,
runProcess->processID, runProcess->processID,
#ifdef LOSCFG_KERNEL_VM
runProcess->vmSpace->base, runProcess->vmSpace->base,
runProcess->vmSpace->base + runProcess->vmSpace->size, runProcess->vmSpace->base + runProcess->vmSpace->size,
#endif
runTask->taskName, runTask->taskName,
runTask->taskID); runTask->taskID);
#ifdef LOSCFG_KERNEL_VM
if (OsProcessIsUserMode(runProcess)) { if (OsProcessIsUserMode(runProcess)) {
PrintExcInfo("task user stack = 0x%08x -> 0x%08x\n", PrintExcInfo("task user stack = 0x%08x -> 0x%08x\n",
runTask->userMapBase, runTask->userMapBase + runTask->userMapSize); runTask->userMapBase, runTask->userMapBase + runTask->userMapSize);
} else } else {
#endif
{
PrintExcInfo("task kernel stack = 0x%08x -> 0x%08x\n", PrintExcInfo("task kernel stack = 0x%08x -> 0x%08x\n",
runTask->topOfStack, runTask->topOfStack + runTask->stackSize); runTask->topOfStack, runTask->topOfStack + runTask->stackSize);
} }
PrintExcInfo("pc = 0x%x ", excBufAddr->PC); PrintExcInfo("pc = 0x%x ", excBufAddr->PC);
#ifdef LOSCFG_KERNEL_VM
LosVmMapRegion *region = NULL;
if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
if (LOS_IsUserAddress((vaddr_t)excBufAddr->PC)) { if (LOS_IsUserAddress((vaddr_t)excBufAddr->PC)) {
region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)excBufAddr->PC); region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)excBufAddr->PC);
@ -367,9 +334,7 @@ STATIC VOID OsExcSysInfo(UINT32 excType, const ExcContext *excBufAddr)
(VADDR_T)excBufAddr->ULR - OsGetTextRegionBase(region, runProcess)); (VADDR_T)excBufAddr->ULR - OsGetTextRegionBase(region, runProcess));
} }
PrintExcInfo("\nusp = 0x%x", excBufAddr->USP); PrintExcInfo("\nusp = 0x%x", excBufAddr->USP);
} else } else {
#endif
{
PrintExcInfo("\nklr = 0x%x\n" PrintExcInfo("\nklr = 0x%x\n"
"ksp = 0x%x\n", "ksp = 0x%x\n",
excBufAddr->LR, excBufAddr->LR,
@ -421,7 +386,6 @@ EXC_PROC_FUNC OsExcRegHookGet(VOID)
return g_excHook; return g_excHook;
} }
#ifdef LOSCFG_KERNEL_VM
STATIC VOID OsDumpExcVaddrRegion(LosVmSpace *space, LosVmMapRegion *region) STATIC VOID OsDumpExcVaddrRegion(LosVmSpace *space, LosVmMapRegion *region)
{ {
INT32 i, numPages, pageCount; INT32 i, numPages, pageCount;
@ -483,7 +447,7 @@ STATIC VOID OsDumpProcessUsedMemRegion(LosProcessCB *runProcess, LosVmSpace *run
RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNodeTemp, pstRbNodeNext) RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNodeTemp, pstRbNodeNext)
} }
STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFlags) STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFalgs)
{ {
LosProcessCB *runProcess = NULL; LosProcessCB *runProcess = NULL;
LosVmSpace *runspace = NULL; LosVmSpace *runspace = NULL;
@ -504,10 +468,9 @@ STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFlags)
return; return;
} }
OsDumpProcessUsedMemRegion(runProcess, runspace, vmmFlags); OsDumpProcessUsedMemRegion(runProcess, runspace, vmmFalgs);
return; return;
} }
#endif
VOID OsDumpContextMem(const ExcContext *excBufAddr) VOID OsDumpContextMem(const ExcContext *excBufAddr)
{ {
@ -517,97 +480,73 @@ VOID OsDumpContextMem(const ExcContext *excBufAddr)
return; return;
} }
for (excReg = &(excBufAddr->R0); count < COM_REGS; excReg++, count++) { for (excReg = &(excBufAddr->R0); count <= DUMPREGS; excReg++, count++) {
if (IS_VALID_ADDR(*excReg)) { if (IS_VALID_ADDR(*excReg)) {
PrintExcInfo("\ndump mem around R%u:%p", count, (*excReg)); PrintExcInfo("\ndump mem around R%u:%p", count, (*excReg));
OsDumpMemByte(DUMPSIZE, ((*excReg) - (DUMPSIZE >> 1))); OsDumpMemByte(DUMPSIZE, ((*excReg) - (DUMPSIZE >> 1)));
} }
} }
for (excReg = &(excBufAddr->R4); count < DUMPREGS; excReg++, count++) {
if (IS_VALID_ADDR(*excReg)) {
PrintExcInfo("\ndump mem around R%u:%p", count, (*excReg));
OsDumpMemByte(DUMPSIZE, ((*excReg) - (DUMPSIZE >> 1)));
}
}
if (IS_VALID_ADDR(excBufAddr->R12)) {
PrintExcInfo("\ndump mem around R12:%p", excBufAddr->R12);
OsDumpMemByte(DUMPSIZE, (excBufAddr->R12 - (DUMPSIZE >> 1)));
}
if (IS_VALID_ADDR(excBufAddr->SP)) { if (IS_VALID_ADDR(excBufAddr->SP)) {
PrintExcInfo("\ndump mem around SP:%p", excBufAddr->SP); PrintExcInfo("\ndump mem around SP:%p", excBufAddr->SP);
OsDumpMemByte(DUMPSIZE, (excBufAddr->SP - (DUMPSIZE >> 1))); OsDumpMemByte(DUMPSIZE, (excBufAddr->SP - (DUMPSIZE >> 1)));
} }
} }
STATIC VOID OsExcRestore(VOID) STATIC VOID OsExcRestore(UINTPTR taskStackPointer)
{ {
UINT32 currCpuid = ArchCurrCpuid(); UINT32 currCpuID = ArchCurrCpuid();
g_excFromUserMode[currCpuid] = FALSE; g_excFromUserMode[currCpuID] = FALSE;
g_intCount[currCpuid] = 0; g_intCount[currCpuID] = 0;
g_curNestCount[currCpuid] = 0; g_curNestCount[currCpuID] = 0;
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
OsCpuStatusSet(CPU_RUNNING); OsPercpuGet()->excFlag = CPU_RUNNING;
#endif #endif
OsSchedLockSet(0); OsPercpuGet()->taskLockCnt = 0;
OsSetCurrCpuSp(taskStackPointer);
} }
STATIC VOID OsUserExcHandle(ExcContext *excBufAddr) STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
{ {
UINT32 intSave;
UINT32 currCpu = ArchCurrCpuid(); UINT32 currCpu = ArchCurrCpuid();
LosTaskCB *runTask = OsCurrTaskGet();
LosProcessCB *runProcess = OsCurrProcessGet(); LosProcessCB *runProcess = OsCurrProcessGet();
if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) { if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) {
return; return;
} }
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
LOS_SpinLock(&g_excSerializerSpin); LOS_SpinLock(&g_excSerializerSpin);
if (g_nextExcWaitCpu != INVALID_CPUID) { if (g_nextExcWaitCpu != INVALID_CPUID) {
g_currHandleExcCpuid = g_nextExcWaitCpu; g_currHandleExcCpuID = g_nextExcWaitCpu;
g_nextExcWaitCpu = INVALID_CPUID; g_nextExcWaitCpu = INVALID_CPUID;
} else { } else {
g_currHandleExcCpuid = INVALID_CPUID; g_currHandleExcCpuID = INVALID_CPUID;
} }
g_currHandleExcPID = OS_INVALID_VALUE; g_currHandleExcPID = OS_INVALID_VALUE;
LOS_SpinUnlock(&g_excSerializerSpin); LOS_SpinUnlock(&g_excSerializerSpin);
#else #else
g_currHandleExcCpuid = INVALID_CPUID; g_currHandleExcCpuID = INVALID_CPUID;
#endif #endif
runProcess->processStatus &= ~OS_PROCESS_FLAG_EXIT;
#ifdef LOSCFG_KERNEL_SMP OsExcRestore(excBufAddr->SP);
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_FS_VFS #ifdef LOSCFG_FS_VFS
OsWakeConsoleSendTask(); OsWakeConsoleSendTask();
#endif #endif
#endif #endif
#ifdef LOSCFG_BLACKBOX #ifdef LOSCFG_SHELL_EXCINFO
BBoxNotifyError("USER_CRASH", MODULE_SYSTEM, "Crash in user", 0);
#endif
SCHEDULER_LOCK(intSave);
#ifdef LOSCFG_SAVE_EXCINFO
OsProcessExitCodeCoreDumpSet(runProcess); OsProcessExitCodeCoreDumpSet(runProcess);
#endif #endif
OsProcessExitCodeSignalSet(runProcess, SIGUSR2); OsProcessExitCodeSignalSet(runProcess, SIGUSR2);
/* An exception was raised by a task during the exit process of
* the current process.
*/
if (runProcess->processStatus & OS_PROCESS_FLAG_EXIT) {
SCHEDULER_UNLOCK(intSave);
/* Exception handling All operations should be kept prior to that operation */
OsExcRestore();
OsRunningTaskToExit(runTask, OS_PRO_EXIT_OK);
} else {
SCHEDULER_UNLOCK(intSave);
/* Exception handling All operations should be kept prior to that operation */
OsExcRestore();
/* kill user exc process */ /* kill user exc process */
LOS_Exit(OS_PRO_EXIT_OK); LOS_Exit(OS_PRO_EXIT_OK);
}
/* User mode exception handling failed , which normally does not exist */ /* User mode exception handling failed , which normally does not exist */
g_curNestCount[currCpu]++; g_curNestCount[currCpu]++;
@ -618,17 +557,18 @@ STATIC VOID OsUserExcHandle(ExcContext *excBufAddr)
/* this function is used to validate fp or validate the checking range start and end. */ /* this function is used to validate fp or validate the checking range start and end. */
STATIC INLINE BOOL IsValidFP(UINTPTR regFP, UINTPTR start, UINTPTR end, vaddr_t *vaddr) STATIC INLINE BOOL IsValidFP(UINTPTR regFP, UINTPTR start, UINTPTR end, vaddr_t *vaddr)
{ {
LosProcessCB *runProcess = NULL;
LosVmSpace *runspace = NULL;
VADDR_T kvaddr = regFP; VADDR_T kvaddr = regFP;
PADDR_T paddr;
if (!((regFP > start) && (regFP < end) && IS_ALIGNED(regFP, sizeof(CHAR *)))) { if (!((regFP > start) && (regFP < end) && IS_ALIGNED(regFP, sizeof(CHAR *)))) {
return FALSE; return FALSE;
} }
#ifdef LOSCFG_KERNEL_VM
PADDR_T paddr;
if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
LosProcessCB *runProcess = OsCurrProcessGet(); runProcess = OsCurrProcessGet();
LosVmSpace *runspace = runProcess->vmSpace; runspace = runProcess->vmSpace;
if (runspace == NULL) { if (runspace == NULL) {
return FALSE; return FALSE;
} }
@ -639,7 +579,6 @@ STATIC INLINE BOOL IsValidFP(UINTPTR regFP, UINTPTR start, UINTPTR end, vaddr_t
kvaddr = (PADDR_T)(UINTPTR)LOS_PaddrToKVaddr(paddr); kvaddr = (PADDR_T)(UINTPTR)LOS_PaddrToKVaddr(paddr);
} }
#endif
if (vaddr != NULL) { if (vaddr != NULL) {
*vaddr = kvaddr; *vaddr = kvaddr;
} }
@ -655,7 +594,6 @@ STATIC INLINE BOOL FindSuitableStack(UINTPTR regFP, UINTPTR *start, UINTPTR *end
const StackInfo *stack = NULL; const StackInfo *stack = NULL;
vaddr_t kvaddr; vaddr_t kvaddr;
#ifdef LOSCFG_KERNEL_VM
if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
taskCB = OsCurrTaskGet(); taskCB = OsCurrTaskGet();
stackStart = taskCB->userMapBase; stackStart = taskCB->userMapBase;
@ -666,7 +604,6 @@ STATIC INLINE BOOL FindSuitableStack(UINTPTR regFP, UINTPTR *start, UINTPTR *end
} }
return found; return found;
} }
#endif
/* Search in the task stacks */ /* Search in the task stacks */
for (index = 0; index < g_taskMaxNum; index++) { for (index = 0; index < g_taskMaxNum; index++) {
@ -704,66 +641,18 @@ FOUND:
return found; return found;
} }
BOOL OsGetUsrIpInfo(UINTPTR ip, IpInfo *info) VOID BackTraceSub(UINTPTR regFP)
{
if (info == NULL) {
return FALSE;
}
#ifdef LOSCFG_KERNEL_VM
BOOL ret = FALSE;
const CHAR *name = NULL;
LosVmMapRegion *region = NULL;
LosProcessCB *runProcess = OsCurrProcessGet();
if (LOS_IsUserAddress((VADDR_T)ip) == FALSE) {
info->ip = ip;
name = "kernel";
ret = FALSE;
goto END;
}
region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)ip);
if (region == NULL) {
info->ip = ip;
name = "invalid";
ret = FALSE;
goto END;
}
info->ip = ip - OsGetTextRegionBase(region, runProcess);
name = OsGetRegionNameOrFilePath(region);
ret = TRUE;
if (strcmp(name, "/lib/libc.so") != 0) {
PRINT_ERR("ip = 0x%x, %s\n", info->ip, name);
}
END:
info->len = strlen(name);
if (strncpy_s(info->f_path, REGION_PATH_MAX, name, REGION_PATH_MAX - 1) != EOK) {
info->f_path[0] = '\0';
info->len = 0;
PRINT_ERR("copy f_path failed, %s\n", name);
}
return ret;
#else
info->ip = ip;
return FALSE;
#endif
}
UINT32 BackTraceGet(UINTPTR regFP, IpInfo *callChain, UINT32 maxDepth)
{ {
UINTPTR tmpFP, backLR; UINTPTR tmpFP, backLR;
UINTPTR stackStart, stackEnd; UINTPTR stackStart, stackEnd;
UINTPTR backFP = regFP; UINTPTR backFP = regFP;
UINT32 count = 0; UINT32 count = 0;
BOOL ret; LosVmMapRegion *region = NULL;
VADDR_T kvaddr; VADDR_T kvaddr;
if (FindSuitableStack(regFP, &stackStart, &stackEnd, &kvaddr) == FALSE) { if (FindSuitableStack(regFP, &stackStart, &stackEnd, &kvaddr) == FALSE) {
if (callChain == NULL) {
PrintExcInfo("traceback error fp = 0x%x\n", regFP); PrintExcInfo("traceback error fp = 0x%x\n", regFP);
} return;
return 0;
} }
/* /*
@ -775,59 +664,41 @@ UINT32 BackTraceGet(UINTPTR regFP, IpInfo *callChain, UINT32 maxDepth)
tmpFP = *(UINTPTR *)(UINTPTR)kvaddr; tmpFP = *(UINTPTR *)(UINTPTR)kvaddr;
if (IsValidFP(tmpFP, stackStart, stackEnd, NULL) == TRUE) { if (IsValidFP(tmpFP, stackStart, stackEnd, NULL) == TRUE) {
backFP = tmpFP; backFP = tmpFP;
if (callChain == NULL) {
PrintExcInfo("traceback fp fixed, trace using fp = 0x%x\n", backFP); PrintExcInfo("traceback fp fixed, trace using fp = 0x%x\n", backFP);
} }
}
while (IsValidFP(backFP, stackStart, stackEnd, &kvaddr) == TRUE) { while (IsValidFP(backFP, stackStart, stackEnd, &kvaddr) == TRUE) {
tmpFP = backFP; tmpFP = backFP;
#ifdef LOSCFG_COMPILER_CLANG_LLVM #ifdef LOSCFG_COMPILER_CLANG_LLVM
backFP = *(UINTPTR *)(UINTPTR)kvaddr; backFP = *(UINTPTR *)(UINTPTR)kvaddr;
if (IsValidFP(tmpFP + POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) { if (IsValidFP(tmpFP + POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
if (callChain == NULL) {
PrintExcInfo("traceback backLR check failed, backLP: 0x%x\n", tmpFP + POINTER_SIZE); PrintExcInfo("traceback backLR check failed, backLP: 0x%x\n", tmpFP + POINTER_SIZE);
} return;
return 0;
} }
backLR = *(UINTPTR *)(UINTPTR)kvaddr; backLR = *(UINTPTR *)(UINTPTR)kvaddr;
#else #else
backLR = *(UINTPTR *)(UINTPTR)kvaddr; backLR = *(UINTPTR *)(UINTPTR)kvaddr;
if (IsValidFP(tmpFP - POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) { if (IsValidFP(tmpFP - POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) {
if (callChain == NULL) {
PrintExcInfo("traceback backFP check failed, backFP: 0x%x\n", tmpFP - POINTER_SIZE); PrintExcInfo("traceback backFP check failed, backFP: 0x%x\n", tmpFP - POINTER_SIZE);
} return;
return 0;
} }
backFP = *(UINTPTR *)(UINTPTR)kvaddr; backFP = *(UINTPTR *)(UINTPTR)kvaddr;
#endif #endif
IpInfo info = {0}; if (LOS_IsUserAddress((VADDR_T)backLR) == TRUE) {
ret = OsGetUsrIpInfo((VADDR_T)backLR, &info); region = LOS_RegionFind(OsCurrProcessGet()->vmSpace, (VADDR_T)backLR);
if (callChain == NULL) {
PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x ", count, backLR, backFP);
if (ret) {
#ifdef LOSCFG_KERNEL_VM
PrintExcInfo("lr in %s --> 0x%x\n", info.f_path, info.ip);
#else
PrintExcInfo("\n");
#endif
} else {
PrintExcInfo("\n");
} }
if (region != NULL) {
PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x lr in %s --> 0x%x\n", count, backLR, backFP,
OsGetRegionNameOrFilePath(region), backLR - region->range.base);
region = NULL;
} else { } else {
(VOID)memcpy_s(&callChain[count], sizeof(IpInfo), &info, sizeof(IpInfo)); PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x\n", count, backLR, backFP);
} }
count++; count++;
if ((count == maxDepth) || (backFP == tmpFP)) { if ((count == OS_MAX_BACKTRACE) || (backFP == tmpFP)) {
break; break;
} }
} }
return count;
}
VOID BackTraceSub(UINTPTR regFP)
{
(VOID)BackTraceGet(regFP, NULL, OS_MAX_BACKTRACE);
} }
VOID BackTrace(UINT32 regFP) VOID BackTrace(UINT32 regFP)
@ -855,9 +726,8 @@ VOID OsExcHook(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr)
#ifndef LOSCFG_DEBUG_VERSION #ifndef LOSCFG_DEBUG_VERSION
if (g_excFromUserMode[ArchCurrCpuid()] != TRUE) { if (g_excFromUserMode[ArchCurrCpuid()] != TRUE) {
#endif #endif
#ifdef LOSCFG_KERNEL_VM
OsDumpProcessUsedMemNode(OS_EXC_VMM_NO_REGION); OsDumpProcessUsedMemNode(OS_EXC_VMM_NO_REGION);
#endif
OsExcStackInfo(); OsExcStackInfo();
#ifndef LOSCFG_DEBUG_VERSION #ifndef LOSCFG_DEBUG_VERSION
} }
@ -917,7 +787,7 @@ VOID OsTaskBackTrace(UINT32 taskID)
} }
PRINTK("TaskName = %s\n", taskCB->taskName); PRINTK("TaskName = %s\n", taskCB->taskName);
PRINTK("TaskID = 0x%x\n", taskCB->taskID); PRINTK("TaskID = 0x%x\n", taskCB->taskID);
BackTrace(((TaskContext *)(taskCB->stackPointer))->R11); /* R11 : FP */ BackTrace(((TaskContext *)(taskCB->stackPointer))->R[11]); /* R11 : FP */
} }
VOID OsBackTrace(VOID) VOID OsBackTrace(VOID)
@ -987,18 +857,40 @@ VOID OsDataAbortExcHandleEntry(ExcContext *excBufAddr)
#endif /* __LINUX_ARM_ARCH__ */ #endif /* __LINUX_ARM_ARCH__ */
#endif /* LOSCFG_GDB */ #endif /* LOSCFG_GDB */
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
#define EXC_WAIT_INTER 50U #define EXC_WAIT_INTER 50U
#define EXC_WAIT_TIME 2000U #define EXC_WAIT_TIME 2000U
STATIC VOID WaitAllCpuStop(UINT32 cpuid) STATIC VOID OsAllCpuStatusOutput(VOID)
{
UINT32 i;
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
switch (g_percpu[i].excFlag) {
case CPU_RUNNING:
PrintExcInfo("cpu%u is running.\n", i);
break;
case CPU_HALT:
PrintExcInfo("cpu%u is halted.\n", i);
break;
case CPU_EXC:
PrintExcInfo("cpu%u is in exc.\n", i);
break;
default:
break;
}
}
PrintExcInfo("The current handling the exception is cpu%u !\n", ArchCurrCpuid());
}
STATIC VOID WaitAllCpuStop(UINT32 cpuID)
{ {
UINT32 i; UINT32 i;
UINT32 time = 0; UINT32 time = 0;
while (time < EXC_WAIT_TIME) { while (time < EXC_WAIT_TIME) {
for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) { for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) {
if ((i != cpuid) && !OsCpuStatusIsHalt(i)) { if ((i != cpuID) && (g_percpu[i].excFlag != CPU_HALT)) {
LOS_Mdelay(EXC_WAIT_INTER); LOS_Mdelay(EXC_WAIT_INTER);
time += EXC_WAIT_INTER; time += EXC_WAIT_INTER;
break; break;
@ -1012,89 +904,90 @@ STATIC VOID WaitAllCpuStop(UINT32 cpuid)
return; return;
} }
STATIC VOID OsWaitOtherCoresHandleExcEnd(UINT32 currCpuid) STATIC VOID OsWaitOtherCoresHandleExcEnd(UINT32 currCpuID)
{ {
OsProcessSuspendAllTask();
while (1) { while (1) {
LOS_SpinLock(&g_excSerializerSpin); LOS_SpinLock(&g_excSerializerSpin);
if ((g_currHandleExcCpuid == INVALID_CPUID) || (g_currHandleExcCpuid == currCpuid)) { if ((g_currHandleExcCpuID == INVALID_CPUID) || (g_currHandleExcCpuID == currCpuID)) {
g_currHandleExcCpuid = currCpuid; g_currHandleExcCpuID = currCpuID;
g_currHandleExcPID = OsCurrProcessGet()->processID; g_currHandleExcPID = OsCurrProcessGet()->processID;
LOS_SpinUnlock(&g_excSerializerSpin); LOS_SpinUnlock(&g_excSerializerSpin);
break; break;
} }
if (g_nextExcWaitCpu == INVALID_CPUID) { if (g_nextExcWaitCpu == INVALID_CPUID) {
g_nextExcWaitCpu = currCpuid; g_nextExcWaitCpu = currCpuID;
} }
LOS_SpinUnlock(&g_excSerializerSpin); LOS_SpinUnlock(&g_excSerializerSpin);
LOS_Mdelay(EXC_WAIT_INTER); LOS_Mdelay(EXC_WAIT_INTER);
} }
} }
STATIC VOID OsCheckAllCpuStatus(VOID) STATIC VOID OsCheckAllCpuStatus(UINTPTR taskStackPointer)
{ {
UINT32 currCpuid = ArchCurrCpuid(); UINT32 currCpuID = ArchCurrCpuid();
UINT32 ret, target; UINT32 ret, target;
OsCpuStatusSet(CPU_EXC); OsPercpuGet()->excFlag = CPU_EXC;
LOCKDEP_CLEAR_LOCKS(); LOCKDEP_CLEAR_LOCKS();
LOS_SpinLock(&g_excSerializerSpin); LOS_SpinLock(&g_excSerializerSpin);
/* Only the current CPU anomaly */ if (g_currHandleExcCpuID == INVALID_CPUID) {
if (g_currHandleExcCpuid == INVALID_CPUID) { g_currHandleExcCpuID = currCpuID;
g_currHandleExcCpuid = currCpuid;
g_currHandleExcPID = OsCurrProcessGet()->processID; g_currHandleExcPID = OsCurrProcessGet()->processID;
LOS_SpinUnlock(&g_excSerializerSpin); LOS_SpinUnlock(&g_excSerializerSpin);
#ifndef LOSCFG_SAVE_EXCINFO if (g_excFromUserMode[currCpuID] == FALSE) {
if (g_excFromUserMode[currCpuid] == FALSE) { target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID));
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuid));
HalIrqSendIpi(target, LOS_MP_IPI_HALT); HalIrqSendIpi(target, LOS_MP_IPI_HALT);
} }
#endif } else if (g_excFromUserMode[currCpuID] == TRUE) {
} else if (g_excFromUserMode[currCpuid] == TRUE) {
/* Both cores raise exceptions, and the current core is a user-mode exception.
* Both cores are abnormal and come from the same process
*/
if (OsCurrProcessGet()->processID == g_currHandleExcPID) { if (OsCurrProcessGet()->processID == g_currHandleExcPID) {
LOS_SpinUnlock(&g_excSerializerSpin); LOS_SpinUnlock(&g_excSerializerSpin);
OsExcRestore(); OsExcRestore(taskStackPointer);
ret = LOS_TaskDelete(OsCurrTaskGet()->taskID); while (1) {
LOS_Panic("%s supend task :%u failed: 0x%x\n", __FUNCTION__, OsCurrTaskGet()->taskID, ret); ret = LOS_TaskSuspend(OsCurrTaskGet()->taskID);
PrintExcInfo("%s supend task :%u failed: 0x%x\n", __FUNCTION__, OsCurrTaskGet()->taskID, ret);
}
} }
LOS_SpinUnlock(&g_excSerializerSpin); LOS_SpinUnlock(&g_excSerializerSpin);
OsWaitOtherCoresHandleExcEnd(currCpuid); OsWaitOtherCoresHandleExcEnd(currCpuID);
} else { } else {
if ((g_currHandleExcCpuid < LOSCFG_KERNEL_CORE_NUM) && (g_excFromUserMode[g_currHandleExcCpuid] == TRUE)) { if (g_excFromUserMode[g_currHandleExcCpuID] == TRUE) {
g_currHandleExcCpuid = currCpuid; g_currHandleExcCpuID = currCpuID;
LOS_SpinUnlock(&g_excSerializerSpin); LOS_SpinUnlock(&g_excSerializerSpin);
target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuid)); target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID));
HalIrqSendIpi(target, LOS_MP_IPI_HALT); HalIrqSendIpi(target, LOS_MP_IPI_HALT);
} else { } else {
LOS_SpinUnlock(&g_excSerializerSpin); LOS_SpinUnlock(&g_excSerializerSpin);
while (1) {} while (1) {}
} }
} }
#ifndef LOSCFG_SAVE_EXCINFO
/* use halt ipi to stop other active cores */ /* use halt ipi to stop other active cores */
if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) { if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) {
WaitAllCpuStop(currCpuid); WaitAllCpuStop(currCpuID);
} }
#endif
} }
#endif #endif
STATIC VOID OsCheckCpuStatus(VOID) STATIC VOID OsCheckCpuStatus(UINTPTR taskStackPointer)
{ {
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
OsCheckAllCpuStatus(); OsCheckAllCpuStatus(taskStackPointer);
#else #else
g_currHandleExcCpuid = ArchCurrCpuid(); (VOID)taskStackPointer;
g_currHandleExcCpuID = ArchCurrCpuid();
#endif #endif
} }
LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr) LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr)
{ {
#if (LOSCFG_KERNEL_SMP == YES)
UINT16 runCount;
#endif
if ((excBufAddr->regCPSR & CPSR_MASK_MODE) == CPSR_USER_MODE) { if ((excBufAddr->regCPSR & CPSR_MASK_MODE) == CPSR_USER_MODE) {
g_minAddr = USER_ASPACE_BASE; g_minAddr = USER_ASPACE_BASE;
g_maxAddr = USER_ASPACE_BASE + USER_ASPACE_SIZE; g_maxAddr = USER_ASPACE_BASE + USER_ASPACE_SIZE;
@ -1105,9 +998,25 @@ LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr)
g_excFromUserMode[ArchCurrCpuid()] = FALSE; g_excFromUserMode[ArchCurrCpuid()] = FALSE;
} }
OsCheckCpuStatus(); OsCheckCpuStatus(excBufAddr->SP);
#ifdef LOSCFG_KERNEL_SMP if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
while (1) {
OsProcessSuspendAllTask();
#if (LOSCFG_KERNEL_SMP == YES)
LOS_SpinLock(&g_taskSpin);
runCount = OS_PROCESS_GET_RUNTASK_COUNT(OsCurrProcessGet()->processStatus);
LOS_SpinUnlock(&g_taskSpin);
if (runCount == 1) {
break;
}
#else
break;
#endif
}
}
#if (LOSCFG_KERNEL_SMP == YES)
#ifdef LOSCFG_FS_VFS #ifdef LOSCFG_FS_VFS
/* Wait for the end of the Console task to avoid multicore printing code */ /* Wait for the end of the Console task to avoid multicore printing code */
OsWaitConsoleSendTaskPend(OsCurrTaskGet()->taskID); OsWaitConsoleSendTaskPend(OsCurrTaskGet()->taskID);
@ -1117,45 +1026,26 @@ LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr)
LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far) LITE_OS_SEC_TEXT_INIT STATIC VOID OsPrintExcHead(UINT32 far)
{ {
#ifdef LOSCFG_BLACKBOX #ifdef LOSCFG_DEBUG_VERSION
#ifdef LOSCFG_SAVE_EXCINFO LosVmSpace *space = NULL;
SetExcInfoIndex(0); VADDR_T vaddr;
#endif #endif
#endif
#ifdef LOSCFG_KERNEL_VM
/* You are not allowed to add any other print information before this exception information */ /* You are not allowed to add any other print information before this exception information */
if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) {
#ifdef LOSCFG_DEBUG_VERSION #ifdef LOSCFG_DEBUG_VERSION
VADDR_T vaddr = ROUNDDOWN(far, PAGE_SIZE); vaddr = ROUNDDOWN(far, PAGE_SIZE);
LosVmSpace *space = LOS_SpaceGet(vaddr); space = LOS_SpaceGet(vaddr);
if (space != NULL) { if (space != NULL) {
LOS_DumpMemRegion(vaddr); LOS_DumpMemRegion(vaddr);
} }
#endif #endif
PrintExcInfo("##################excFrom: User!####################\n"); PrintExcInfo("##################excFrom: User!####################\n");
} else } else {
#endif
{
PrintExcInfo("##################excFrom: kernel!###################\n"); PrintExcInfo("##################excFrom: kernel!###################\n");
} }
} }
#ifdef LOSCFG_SAVE_EXCINFO
STATIC VOID OsSysStateSave(UINT32 *intCount, UINT32 *lockCount)
{
*intCount = g_intCount[ArchCurrCpuid()];
*lockCount = OsSchedLockCountGet();
g_intCount[ArchCurrCpuid()] = 0;
OsSchedLockSet(0);
}
STATIC VOID OsSysStateRestore(UINT32 intCount, UINT32 lockCount)
{
g_intCount[ArchCurrCpuid()] = intCount;
OsSchedLockSet(lockCount);
}
#endif
/* /*
* Description : EXC handler entry * Description : EXC handler entry
* Input : excType --- exc type * Input : excType --- exc type
@ -1163,13 +1053,8 @@ STATIC VOID OsSysStateRestore(UINT32 intCount, UINT32 lockCount)
*/ */
LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr) LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr)
{ {
#ifdef LOSCFG_SAVE_EXCINFO
UINT32 intCount;
UINT32 lockCount;
#endif
/* Task scheduling is not allowed during exception handling */ /* Task scheduling is not allowed during exception handling */
OsSchedLock(); OsPercpuGet()->taskLockCnt++;
g_curNestCount[ArchCurrCpuid()]++; g_curNestCount[ArchCurrCpuid()]++;
@ -1177,24 +1062,22 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
OsPrintExcHead(far); OsPrintExcHead(far);
#ifdef LOSCFG_KERNEL_SMP #if (LOSCFG_KERNEL_SMP == YES)
OsAllCpuStatusOutput(); OsAllCpuStatusOutput();
#endif #endif
#ifdef LOSCFG_SAVE_EXCINFO #ifdef LOSCFG_SHELL_EXCINFO
log_read_write_fn func = GetExcInfoRW(); log_read_write_fn func = GetExcInfoRW();
#endif #endif
if (g_excHook != NULL) { if (g_excHook != NULL) {
if (g_curNestCount[ArchCurrCpuid()] == 1) { if (g_curNestCount[ArchCurrCpuid()] == 1) {
#ifdef LOSCFG_SAVE_EXCINFO #ifdef LOSCFG_SHELL_EXCINFO
if (func != NULL) { if (func != NULL) {
#ifndef LOSCFG_BLACKBOX
SetExcInfoIndex(0); SetExcInfoIndex(0);
#endif g_intCount[ArchCurrCpuid()] = 0;
OsSysStateSave(&intCount, &lockCount);
OsRecordExcInfoTime(); OsRecordExcInfoTime();
OsSysStateRestore(intCount, lockCount); g_intCount[ArchCurrCpuid()] = 1;
} }
#endif #endif
g_excHook(excType, excBufAddr, far, fsr); g_excHook(excType, excBufAddr, far, fsr);
@ -1202,15 +1085,18 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
OsCallStackInfo(); OsCallStackInfo();
} }
#ifdef LOSCFG_SAVE_EXCINFO #ifdef LOSCFG_SHELL_EXCINFO
if (func != NULL) { if (func != NULL) {
PrintExcInfo("Be sure flash space bigger than GetExcInfoIndex():0x%x\n", GetExcInfoIndex()); PrintExcInfo("Be sure flash space bigger than GetExcInfoIndex():0x%x\n", GetExcInfoIndex());
OsSysStateSave(&intCount, &lockCount); g_intCount[ArchCurrCpuid()] = 0;
func(GetRecordAddr(), GetRecordSpace(), 0, GetExcInfoBuf()); func(GetRecordAddr(), GetRecordSpace(), 0, GetExcInfoBuf());
OsSysStateRestore(intCount, lockCount); g_intCount[ArchCurrCpuid()] = 1;
} }
#endif #endif
} }
#ifdef LOSCFG_EXC_INTERACTION
OsExcInteractionTaskKeep();
#endif
#ifdef LOSCFG_SHELL_CMD_DEBUG #ifdef LOSCFG_SHELL_CMD_DEBUG
SystemRebootFunc rebootHook = OsGetRebootHook(); SystemRebootFunc rebootHook = OsGetRebootHook();
@ -1220,9 +1106,6 @@ LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAd
} }
#endif #endif
#ifdef LOSCFG_BLACKBOX
BBoxNotifyError(EVENT_PANIC, MODULE_SYSTEM, "Crash in kernel", 1);
#endif
while (1) {} while (1) {}
} }
@ -1230,14 +1113,13 @@ __attribute__((noinline)) VOID LOS_Panic(const CHAR *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
OsVprintf(fmt, ap, EXC_OUTPUT); UartVprintf(fmt, ap);
va_end(ap); va_end(ap);
__asm__ __volatile__("swi 0"); __asm__ __volatile__("swi 0");
while (1) {}
} }
/* stack protector */ /* stack protector */
USED UINT32 __stack_chk_guard = 0xd00a0dff; UINT32 __stack_chk_guard = 0xd00a0dff;
VOID __stack_chk_fail(VOID) VOID __stack_chk_fail(VOID)
{ {
@ -1269,11 +1151,7 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCou
framePtr = Get_Fp(); framePtr = Get_Fp();
while ((framePtr > stackStart) && (framePtr < stackEnd) && IS_ALIGNED(framePtr, sizeof(CHAR *))) { while ((framePtr > stackStart) && (framePtr < stackEnd) && IS_ALIGNED(framePtr, sizeof(CHAR *))) {
tmpFramePtr = framePtr; tmpFramePtr = framePtr;
#ifdef LOSCFG_COMPILER_CLANG_LLVM
linkReg = *(UINTPTR *)(tmpFramePtr + sizeof(UINTPTR));
#else
linkReg = *(UINTPTR *)framePtr; linkReg = *(UINTPTR *)framePtr;
#endif
if (index >= jumpCount) { if (index >= jumpCount) {
LR[count++] = linkReg; LR[count++] = linkReg;
if (count == recordCount) { if (count == recordCount) {
@ -1281,11 +1159,7 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCou
} }
} }
index++; index++;
#ifdef LOSCFG_COMPILER_CLANG_LLVM
framePtr = *(UINTPTR *)framePtr;
#else
framePtr = *(UINTPTR *)(tmpFramePtr - sizeof(UINTPTR)); framePtr = *(UINTPTR *)(tmpFramePtr - sizeof(UINTPTR));
#endif
} }
/* if linkReg is not enough,clean up the last of the effective LR as the end. */ /* if linkReg is not enough,clean up the last of the effective LR as the end. */
@ -1294,3 +1168,8 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 recordCount, UINT32 jumpCou
} }
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

94
arch/arm/arm/src/los_hw.c Normal file → Executable file
View File

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2023 Huawei Device Co., Ltd. All rights reserved. * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
@ -32,6 +32,12 @@
#include "los_hw_pri.h" #include "los_hw_pri.h"
#include "los_task_pri.h" #include "los_task_pri.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* support cpu vendors */ /* support cpu vendors */
CpuVendor g_cpuTable[] = { CpuVendor g_cpuTable[] = {
/* armv7-a */ /* armv7-a */
@ -71,10 +77,13 @@ VOID OsTaskEntrySetupLoopFrame(UINT32 arg0)
LITE_OS_SEC_TEXT_INIT VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag) LITE_OS_SEC_TEXT_INIT VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag)
{ {
UINT32 index = 1;
TaskContext *taskContext = NULL;
if (initFlag == TRUE) { if (initFlag == TRUE) {
OsStackInit(topStack, stackSize); OsStackInit(topStack, stackSize);
} }
TaskContext *taskContext = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext)); taskContext = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));
/* initialize the task context */ /* initialize the task context */
#ifdef LOSCFG_GDB #ifdef LOSCFG_GDB
@ -83,17 +92,22 @@ LITE_OS_SEC_TEXT_INIT VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOI
taskContext->PC = (UINTPTR)OsTaskEntry; taskContext->PC = (UINTPTR)OsTaskEntry;
#endif #endif
taskContext->LR = (UINTPTR)OsTaskExit; /* LR should be kept, to distinguish it's THUMB or ARM instruction */ taskContext->LR = (UINTPTR)OsTaskExit; /* LR should be kept, to distinguish it's THUMB or ARM instruction */
taskContext->R0 = taskID; /* R0 */ taskContext->resved = 0x0;
taskContext->R[0] = taskID; /* R0 */
taskContext->R[index++] = 0x01010101; /* R1, 0x01010101 : reg initialed magic word */
for (; index < GEN_REGS_NUM; index++) {
taskContext->R[index] = taskContext->R[index - 1] + taskContext->R[1]; /* R2 - R12 */
}
#ifdef LOSCFG_THUMB #ifdef LOSCFG_INTERWORK_THUMB
taskContext->regCPSR = PSR_MODE_SVC_THUMB; /* CPSR (Enable IRQ and FIQ interrupts, THUMNB-mode) */ taskContext->regPSR = PSR_MODE_SVC_THUMB; /* CPSR (Enable IRQ and FIQ interrupts, THUMNB-mode) */
#else #else
taskContext->regCPSR = PSR_MODE_SVC_ARM; /* CPSR (Enable IRQ and FIQ interrupts, ARM-mode) */ taskContext->regPSR = PSR_MODE_SVC_ARM; /* CPSR (Enable IRQ and FIQ interrupts, ARM-mode) */
#endif #endif
#if !defined(LOSCFG_ARCH_FPU_DISABLE) #if !defined(LOSCFG_ARCH_FPU_DISABLE)
/* 0xAAA0000000000000LL : float reg initialed magic word */ /* 0xAAA0000000000000LL : float reg initialed magic word */
for (UINT32 index = 0; index < FP_REGS_NUM; index++) { for (index = 0; index < FP_REGS_NUM; index++) {
taskContext->D[index] = 0xAAA0000000000000LL + index; /* D0 - D31 */ taskContext->D[index] = 0xAAA0000000000000LL + index; /* D0 - D31 */
} }
taskContext->regFPSCR = 0; taskContext->regFPSCR = 0;
@ -103,61 +117,58 @@ LITE_OS_SEC_TEXT_INIT VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOI
return (VOID *)taskContext; return (VOID *)taskContext;
} }
VOID OsUserCloneParentStack(VOID *childStack, UINTPTR sp, UINTPTR parentTopOfStack, UINT32 parentStackSize) LITE_OS_SEC_TEXT VOID OsUserCloneParentStack(LosTaskCB *childTaskCB, LosTaskCB *parentTaskCB)
{ {
LosTaskCB *task = OsCurrTaskGet(); TaskContext *context = (TaskContext *)childTaskCB->stackPointer;
sig_cb *sigcb = &task->sig; VOID *cloneStack = (VOID *)(((UINTPTR)parentTaskCB->topOfStack + parentTaskCB->stackSize) - sizeof(TaskContext));
VOID *cloneStack = NULL;
if (sigcb->sigContext != NULL) { LOS_ASSERT(parentTaskCB->taskStatus & OS_TASK_STATUS_RUNNING);
cloneStack = (VOID *)((UINTPTR)sigcb->sigContext - sizeof(TaskContext));
} else { (VOID)memcpy_s(childTaskCB->stackPointer, sizeof(TaskContext), cloneStack, sizeof(TaskContext));
cloneStack = (VOID *)(((UINTPTR)parentTopOfStack + parentStackSize) - sizeof(TaskContext)); context->R[0] = 0;
} }
(VOID)memcpy_s(childStack, sizeof(TaskContext), cloneStack, sizeof(TaskContext)); LITE_OS_SEC_TEXT_INIT VOID OsUserTaskStackInit(TaskContext *context, TSK_ENTRY_FUNC taskEntry, UINTPTR stack)
((TaskContext *)childStack)->R0 = 0;
if (sp != 0) {
((TaskContext *)childStack)->USP = TRUNCATE(sp, LOSCFG_STACK_POINT_ALIGN_SIZE);
((TaskContext *)childStack)->ULR = 0;
}
}
LITE_OS_SEC_TEXT_INIT VOID OsUserTaskStackInit(TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
{ {
LOS_ASSERT(context != NULL); LOS_ASSERT(context != NULL);
#ifdef LOSCFG_THUMB #ifdef LOSCFG_INTERWORK_THUMB
context->regCPSR = PSR_MODE_USR_THUMB; context->regPSR = PSR_MODE_USR_THUMB;
#else #else
context->regCPSR = PSR_MODE_USR_ARM; context->regPSR = PSR_MODE_USR_ARM;
#endif #endif
context->R0 = stack; context->R[0] = stack;
context->USP = TRUNCATE(stack, LOSCFG_STACK_POINT_ALIGN_SIZE); context->SP = TRUNCATE(stack, LOSCFG_STACK_POINT_ALIGN_SIZE);
context->ULR = 0; context->LR = 0;
context->PC = (UINTPTR)taskEntry; context->PC = (UINTPTR)taskEntry;
} }
VOID OsInitSignalContext(const VOID *sp, VOID *signalContext, UINTPTR sigHandler, UINT32 signo, UINT32 param) VOID Sev(VOID)
{ {
IrqContext *newSp = (IrqContext *)signalContext; __asm__ __volatile__ ("sev" : : : "memory");
(VOID)memcpy_s(signalContext, sizeof(IrqContext), sp, sizeof(IrqContext));
newSp->PC = sigHandler;
newSp->R0 = signo;
newSp->R1 = param;
} }
DEPRECATED VOID Dmb(VOID) VOID Wfe(VOID)
{
__asm__ __volatile__ ("wfe" : : : "memory");
}
VOID Wfi(VOID)
{
__asm__ __volatile__ ("wfi" : : : "memory");
}
VOID Dmb(VOID)
{ {
__asm__ __volatile__ ("dmb" : : : "memory"); __asm__ __volatile__ ("dmb" : : : "memory");
} }
DEPRECATED VOID Dsb(VOID) VOID Dsb(VOID)
{ {
__asm__ __volatile__("dsb" : : : "memory"); __asm__ __volatile__("dsb" : : : "memory");
} }
DEPRECATED VOID Isb(VOID) VOID Isb(VOID)
{ {
__asm__ __volatile__("isb" : : : "memory"); __asm__ __volatile__("isb" : : : "memory");
} }
@ -181,3 +192,8 @@ VOID DCacheInvRange(UINT32 start, UINT32 end)
arm_inv_cache_range(start, end); arm_inv_cache_range(start, end);
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

293
arch/arm/arm/src/los_hw_exc.S Normal file → Executable file
View File

@ -47,10 +47,9 @@
.extern OsDataAbortExcHandleEntry .extern OsDataAbortExcHandleEntry
#endif #endif
#endif #endif
.extern OsSaveSignalContext
.extern OsRestorSignalContext
.extern OsArmSharedPageFault .extern OsArmSharedPageFault
.extern OsArmA32SyscallHandle .extern OsArmA32SyscallHandle
.extern LOS_Exit
.global _osExceptFiqHdl .global _osExceptFiqHdl
.global _osExceptAddrAbortHdl .global _osExceptAddrAbortHdl
@ -64,6 +63,7 @@
.global __stack_chk_guard_setup .global __stack_chk_guard_setup
#endif #endif
.fpu vfpv4 .fpu vfpv4
.macro PUSH_FPU_REGS reg1 .macro PUSH_FPU_REGS reg1
@ -173,77 +173,67 @@ _osExceptUndefInstrHdl:
#ifdef LOSCFG_GDB #ifdef LOSCFG_GDB
GDB_HANDLE OsUndefIncExcHandleEntry GDB_HANDLE OsUndefIncExcHandleEntry
#else #else
SRSFD #CPSR_SVC_MODE! @ Save pc and cpsr to svc sp, ARMv6 and above support @ LR offset to return from this exception: 0.
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to svc mode, and disable all interrupt STMFD SP, {R0-R7} @ Push working registers, but don`t change SP.
STMFD SP!, {R0-R3, R12, LR}
STMFD SP, {R13, R14}^ @ push user sp and lr
SUB SP, SP, #(2 * 4)
MOV R2, #0
MOV R3, #0
STMFD SP!, {R2-R3} @ far and fsr fields, are 0 under this anomaly
STMFD SP!, {R4-R11}
MOV R0, #OS_EXCEPT_UNDEF_INSTR @ Set exception ID to OS_EXCEPT_UNDEF_INSTR. MOV R0, #OS_EXCEPT_UNDEF_INSTR @ Set exception ID to OS_EXCEPT_UNDEF_INSTR.
B _osExceptDispatch @ Branch to global exception handler. B _osExceptDispatch @ Branch to global exception handler.
#endif #endif
@ Description: Software interrupt exception handler @ Description: Software interrupt exception handler
_osExceptSwiHdl: _osExceptSwiHdl:
SRSFD #CPSR_SVC_MODE! @ Save pc and cpsr to svc sp, ARMv6 and above support SUB SP, SP, #(4 * 16)
STMFD SP!, {R0-R3, R12, LR} STMIA SP, {R0-R12}
STMFD SP, {R13, R14}^ MRS R3, SPSR
SUB SP, SP, #(4 * 4) @ push user sp and lr and jump reserved field MOV R4, LR
STR R7, [SP, #0] @ Save system call number to reserved2 filed
#ifdef LOSCFG_KERNEL_SYSCALL
LDR R3, [SP, #(11 * 4)]
AND R1, R3, #CPSR_MASK_MODE @ Interrupted mode AND R1, R3, #CPSR_MASK_MODE @ Interrupted mode
CMP R1, #CPSR_USER_MODE @ User mode CMP R1, #CPSR_USER_MODE @ User mode
BNE _osKernelSVCHandler @ Branch if not user mode BNE OsKernelSVCHandler @ Branch if not user mode
CMP R7, #119 @ __NR_sigreturn @ we enter from user mode, we need get the values of USER mode r13(sp) and r14(lr).
BNE _osIsSyscall @ stmia with ^ will return the user mode registers (provided that r15 is not in the register list).
MOV R0, SP MOV R0, SP
BLX OsRestorSignalContext STMFD SP!, {R3} @ Save the CPSR
MOV SP, R0 ADD R3, SP, #(4 * 17) @ Offset to pc/cpsr storage
B _osSyscallReturn STMFD R3!, {R4} @ Save the CPSR and r15(pc)
STMFD R3, {R13, R14}^ @ Save user mode r13(sp) and r14(lr)
_osIsSyscall: SUB SP, SP, #4
STMFD SP!, {R4-R11}
PUSH_FPU_REGS R1 PUSH_FPU_REGS R1
MOV R0, SP
MOV FP, #0 @ Init frame pointer MOV FP, #0 @ Init frame pointer
CPSIE I CPSIE I
BLX OsArmA32SyscallHandle BLX OsArmA32SyscallHandle
CPSID I CPSID I
POP_FPU_REGS R1 POP_FPU_REGS R1
LDMFD SP!, {R4-R11} ADD SP, SP,#4
LDMFD SP!, {R3} @ Fetch the return SPSR
MSR SPSR_cxsf, R3 @ Set the return mode SPSR
MOV R0, SP @ we are leaving to user mode, we need to restore the values of USER mode r13(sp) and r14(lr).
SUB SP, SP, #(12 * 4) @ sp - sizeof(IrqContext), reserved for signal @ ldmia with ^ will return the user mode registers (provided that r15 is not in the register list)
MOV R1, SP
BLX OsSaveSignalContext
MOV SP, R0
_osSyscallReturn: LDMFD SP!, {R0-R12}
LDR R7, [SP, #0]
ADD SP, SP, #(2 * 4) @ jump reserved filed
LDMFD SP, {R13, R14}^ @ Restore user mode R13/R14 LDMFD SP, {R13, R14}^ @ Restore user mode R13/R14
ADD SP, SP, #(2 * 4) ADD SP, SP, #(2 * 4)
LDMFD SP!, {R0-R3, R12, LR} LDMFD SP!, {PC}^ @ Return to user
RFEIA SP! @ Return to user
OsKernelSVCHandler:
ADD R0, SP, #(4 * 16)
MOV R5, R0
STMFD R0!, {R4} @ Store PC
STMFD R0!, {R4}
STMFD R0!, {R5}
STMFD SP!, {R3} @ Push task`s CPSR (i.e. exception SPSR).
SUB SP, SP, #(4 * 2) @ user sp and lr
_osKernelSVCHandler:
#endif
MOV R0, #0
STR R0, [SP, #0]
STR R0, [SP, #4]
STMFD SP!, {R4-R11}
MOV R0, #OS_EXCEPT_SWI @ Set exception ID to OS_EXCEPT_SWI. MOV R0, #OS_EXCEPT_SWI @ Set exception ID to OS_EXCEPT_SWI.
B _osExceptDispatch @ Branch to global exception handler.
B _osExceptionSwi @ Branch to global exception handler.
@ Description: Prefectch abort exception handler @ Description: Prefectch abort exception handler
_osExceptPrefetchAbortHdl: _osExceptPrefetchAbortHdl:
@ -253,37 +243,18 @@ _osExceptPrefetchAbortHdl:
#endif #endif
#else #else
SUB LR, LR, #4 @ LR offset to return from this exception: -4. SUB LR, LR, #4 @ LR offset to return from this exception: -4.
STMFD SP, {R0-R7} @ Push working registers, but don`t change SP.
MOV R5, LR
MRS R1, SPSR
SRSFD #CPSR_SVC_MODE! @ Save pc and cpsr to svc sp, ARMv6 and above support MOV R0, #OS_EXCEPT_PREFETCH_ABORT @ Set exception ID to OS_EXCEPT_PREFETCH_ABORT.
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to svc mode, and disable all interrupt
STMFD SP!, {R0-R3, R12, LR}
STMFD SP, {R13, R14}^
SUB SP, SP, #(2 * 4)
MRC P15, 0, R2, C6, C0, 2 AND R4, R1, #CPSR_MASK_MODE @ Interrupted mode
MRC P15, 0, R3, C5, C0, 1 CMP R4, #CPSR_USER_MODE @ User mode
STMFD SP!, {R2-R3} @ Save far and fsr BEQ _osExcPageFault @ Branch if user mode
STMFD SP!, {R4-R11}
#ifdef LOSCFG_KERNEL_VM
LDR R0, [SP, #(19 * 4)]
AND R0, R0, #CPSR_MASK_MODE @ Interrupted mode
CMP R0, #CPSR_USER_MODE @ User mode
BNE _osKernelExceptPrefetchAbortHdl
MOV R1, SP
PUSH_FPU_REGS R0
MOV R0, #OS_EXCEPT_PREFETCH_ABORT
BLX OsArmSharedPageFault
CMP R0, #0
POP_FPU_REGS R0
BEQ _osExcPageFaultReturn
#endif
_osKernelExceptPrefetchAbortHdl: _osKernelExceptPrefetchAbortHdl:
MOV R0, #OS_EXCEPT_PREFETCH_ABORT MOV LR, R5
B _osExceptDispatch @ Branch to global exception handler. B _osExceptDispatch @ Branch to global exception handler.
#endif #endif
@ -295,105 +266,118 @@ _osExceptDataAbortHdl:
#endif #endif
#else #else
SUB LR, LR, #8 @ LR offset to return from this exception: -8. SUB LR, LR, #8 @ LR offset to return from this exception: -8.
STMFD SP, {R0-R7} @ Push working registers, but don`t change SP.
SRSFD #CPSR_SVC_MODE! @ Save pc and cpsr to svc sp, ARMv6 and above support MOV R5, LR
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to svc mode, and disable all interrupt MRS R1, SPSR
STMFD SP!, {R0-R3, R12, LR}
STMFD SP, {R13, R14}^
SUB SP, SP, #(2 * 4)
MRC P15, 0, R2, C6, C0, 0
MRC P15, 0, R3, C5, C0, 0
STMFD SP!, {R2-R3} @ Save far and fsr
STMFD SP!, {R4-R11}
#ifdef LOSCFG_KERNEL_VM
MOV R1, SP
PUSH_FPU_REGS R0
MOV R0, #OS_EXCEPT_DATA_ABORT @ Set exception ID to OS_EXCEPT_DATA_ABORT. MOV R0, #OS_EXCEPT_DATA_ABORT @ Set exception ID to OS_EXCEPT_DATA_ABORT.
BLX OsArmSharedPageFault
CMP R0, #0
POP_FPU_REGS R0
BEQ _osExcPageFaultReturn
#endif
MOV R0, #OS_EXCEPT_DATA_ABORT B _osExcPageFault
B _osExceptDispatch
#endif
#ifdef LOSCFG_KERNEL_VM
_osExcPageFaultReturn:
LDMFD SP!, {R4-R11}
MOV R0, SP
STR R7, [SP, #0]
SUB SP, SP, #(12 * 4) @ sp - sizeof(IrqContext), reserved for signal
MOV R1, SP
BLX OsSaveSignalContext
MOV SP, R0
ADD SP, SP, #(2 * 4)
LDMFD SP, {R13, R14}^
ADD SP, SP, #(2 * 4) @ Jump reserved fileds
LDMFD SP!, {R0-R3, R12, LR}
RFEIA SP!
#endif #endif
@ Description: Address abort exception handler @ Description: Address abort exception handler
_osExceptAddrAbortHdl: _osExceptAddrAbortHdl:
SUB LR, LR, #8 @ LR offset to return from this exception: -8. SUB LR, LR, #8 @ LR offset to return from this exception: -8.
STMFD SP, {R0-R7} @ Push working registers, but don`t change SP.
SRSFD #CPSR_SVC_MODE! @ Save pc and cpsr to svc sp, ARMv6 and above support
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to svc mode, and disable all interrupt
STMFD SP!, {R0-R3, R12, LR}
STMFD SP, {R13, R14}^
SUB SP, SP, #(2 * 4)
MOV R2, #0
MOV R3, #0
STMFD SP!, {R2-R3} @ far and fsr fields, are 0 under this anomaly
STMFD SP!, {R4-R11}
MOV R0, #OS_EXCEPT_ADDR_ABORT @ Set exception ID to OS_EXCEPT_ADDR_ABORT. MOV R0, #OS_EXCEPT_ADDR_ABORT @ Set exception ID to OS_EXCEPT_ADDR_ABORT.
B _osExceptDispatch @ Branch to global exception handler. B _osExceptDispatch @ Branch to global exception handler.
@ Description: Fast interrupt request exception handler @ Description: Fast interrupt request exception handler
_osExceptFiqHdl: _osExceptFiqHdl:
SUB LR, LR, #4 @ LR offset to return from this exception: -4. SUB LR, LR, #4 @ LR offset to return from this exception: -4.
STMFD SP, {R0-R7} @ Push working registers.
SRSFD #CPSR_SVC_MODE! @ Save pc and cpsr to svc sp, ARMv6 and above support MOV R0, #OS_EXCEPT_FIQ @ Set exception ID to OS_EXCEPT_FIQ.
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to svc mode, and disable all interrupt
STMFD SP!, {R0-R3, R12, LR}
STMFD SP, {R13, R14}^
SUB SP, SP, #(2 * 4)
MOV R2, #0 B _osExceptDispatch @ Branch to global exception handler.
MOV R3, #0
STMFD SP!, {R2-R3} @ far and fsr fields, are 0 under this anomaly _osExcPageFault:
SUB R3, SP, #(8 * 4) @ Save the start address of working registers.
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to SVC mode, and disable all interrupts
MOV R2, SP
STMFD SP!, {R5} @ Push original PC
STMFD SP!, {LR} @ Push original svc LR
STMFD SP!, {R2} @ Push original svc SP
STMFD SP!, {R8-R12} @ Push original R12-R8,
LDMFD R3!, {R4-R11} @ Move original R7-R0 from exception stack to original stack.
STMFD SP!, {R4-R11} STMFD SP!, {R4-R11}
STMFD SP!, {R1}
SUB SP, SP, #8
STMIA SP, {R13, R14}^ @ Save user mode r13(sp) and r14(lr)
MOV R4, SP
BIC SP, SP, #7
PUSH_FPU_REGS R1
CMP R0, #OS_EXCEPT_DATA_ABORT
BNE 1f
MRC P15, 0, R2, C6, C0, 0
MRC P15, 0, R3, C5, C0, 0
B 2f
1: MRC P15, 0, R2, C6, C0, 2
MRC P15, 0, R3, C5, C0, 1
2: MOV R1, R4
MOV R5, R0
MOV R8, R2
MOV R9, R3
CPSIE I
BLX OsArmSharedPageFault
CPSID I
POP_FPU_REGS R1
MOV SP, R4
CMP R0, #0
BEQ _OsExcReturn
MOV R0, R5 @ exc type
B _osExceptionSwi
@ Description: Exception handler @ Description: Exception handler
@ Parameter : R0 Exception Type @ Parameter : R0 Exception Type
@ Regs Hold : R3 Exception`s CPSR @ Regs Hold : R3 Exception`s CPSR
_osExceptDispatch: _osExceptDispatch:
LDR R8, [SP, #(8 * 4)] @ Get far MRS R2, SPSR @ Save CPSR before exception.
LDR R9, [SP, #(9 * 4)] @ Get fsr MOV R1, LR @ Save PC before exception.
SUB R3, SP, #(8 * 4) @ Save the start address of working registers.
ADD R2, SP, #(20 * 4) @ sp + sizeof(ExcContext), position of SVC stack before exception
STR R2, [SP, #(8 * 4)] @ Save svc sp
MOV R1, SP
#ifdef LOSCFG_KERNEL_VM
LDR R2, [SP, #(19 * 4)] @ Get CPSR
AND R2, R2, #CPSR_MASK_MODE @ Interrupted mode
CMP R2, #CPSR_USER_MODE @ User mode
BEQ _osExceptionGetSP
#endif
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 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,
LDMFD R3!, {R4-R11} @ Move original R7-R0 from exception stack to original stack.
STMFD SP!, {R4-R11}
STMFD SP!, {R2} @ Push task`s CPSR (i.e. exception SPSR).
CMP R0, #OS_EXCEPT_DATA_ABORT
BNE 1f
MRC P15, 0, R8, C6, C0, 0
MRC P15, 0, R9, C5, C0, 0
B 3f
1: CMP R0, #OS_EXCEPT_PREFETCH_ABORT
BNE 2f
MRC P15, 0, R8, C6, C0, 2
MRC P15, 0, R9, C5, C0, 1
B 3f
2: MOV R8, #0
MOV R9, #0
3: AND R2, R2, #CPSR_MASK_MODE
CMP R2, #CPSR_USER_MODE @ User mode
BNE 4f
STMFD SP, {R13, R14}^ @ save user mode sp and lr
4:
SUB SP, SP, #(4 * 2)
_osExceptionSwi:
MOV R1, SP @ The second argument to the exception
MRC P15, 0, R4, C0, C0, 5 MRC P15, 0, R4, C0, C0, 5
AND R4, R4, #MPIDR_CPUID_MASK @ Get Current cpu id AND R4, R4, #MPIDR_CPUID_MASK @ Get Current cpu id
LSL R2, R4, #2 LSL R2, R4, #2
@ -421,4 +405,19 @@ _osExceptionGetSP:
LDR R5, =OsExcHandleEntry @ OsExcHandleEntry(UINT32 excType, ExcContext * excBufAddr) LDR R5, =OsExcHandleEntry @ OsExcHandleEntry(UINT32 excType, ExcContext * excBufAddr)
BX R5 BX R5
_OsExcReturn:
LDR R0, [SP, #(2 * 4)]
AND R0, R0, #CPSR_MASK_MODE
CMP R0, #CPSR_USER_MODE @ User mode
BNE _OsExcReturnToKernel
LDMFD SP, {R13, R14}^ @ load user mode sp and lr
_OsExcReturnToKernel:
ADD SP, SP, #(2 * 4)
LDMFD SP!, {R1}
MSR SPSR_cxsf, R1 @ Set the return mode SPSR
LDMFD SP!, {R0-R12}
ADD SP, SP, #4
LDMFD SP!, {LR, PC}^
.end .end

View File

@ -32,6 +32,11 @@
#include "los_sys_pri.h" #include "los_sys_pri.h"
#include "los_hwi.h" #include "los_hwi.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond) LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond)
{ {
@ -60,8 +65,10 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt)
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID) LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID)
{ {
UINT64 cycle = HalClockGetCycles(); DOUBLE nanos;
return (cycle / g_sysClock) * OS_SYS_NS_PER_SECOND + (cycle % g_sysClock) * OS_SYS_NS_PER_SECOND / g_sysClock;
nanos = (DOUBLE)HalClockGetCycles() * OS_SYS_NS_PER_SECOND / g_sysClock;
return (UINT64)nanos;
} }
LITE_OS_SEC_TEXT_MINOR VOID LOS_Udelay(UINT32 usecs) LITE_OS_SEC_TEXT_MINOR VOID LOS_Udelay(UINT32 usecs)
@ -74,3 +81,8 @@ LITE_OS_SEC_TEXT_MINOR VOID LOS_Mdelay(UINT32 msecs)
HalDelayUs(msecs * 1000); /* 1000 : 1ms = 1000us */ HalDelayUs(msecs * 1000); /* 1000 : 1ms = 1000us */
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@ -36,7 +36,12 @@
#include "los_cpup_pri.h" #include "los_cpup_pri.h"
#endif #endif
#include "los_sched_pri.h" #include "los_sched_pri.h"
#include "los_hook.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/* spinlock for hwi module, only available on SMP mode */ /* spinlock for hwi module, only available on SMP mode */
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_hwiSpin); LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_hwiSpin);
@ -46,11 +51,16 @@ LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_hwiSpin);
size_t g_intCount[LOSCFG_KERNEL_CORE_NUM] = {0}; size_t g_intCount[LOSCFG_KERNEL_CORE_NUM] = {0};
HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM]; HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM];
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0}; STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
STATIC UINT32 g_hwiFormCnt[LOSCFG_KERNEL_CORE_NUM][OS_HWI_MAX_NUM] = {0}; STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
UINT32 OsGetHwiFormCnt(UINT16 cpuid, UINT32 index) VOID OsIncHwiFormCnt(UINT32 index)
{ {
return g_hwiFormCnt[cpuid][index]; g_hwiFormCnt[index]++;
}
UINT32 OsGetHwiFormCnt(UINT32 index)
{
return g_hwiFormCnt[index];
} }
CHAR *OsGetHwiFormName(UINT32 index) CHAR *OsGetHwiFormName(UINT32 index)
@ -69,18 +79,17 @@ VOID OsInterrupt(UINT32 intNum)
{ {
HwiHandleForm *hwiForm = NULL; HwiHandleForm *hwiForm = NULL;
UINT32 *intCnt = NULL; UINT32 *intCnt = NULL;
UINT16 cpuid = ArchCurrCpuid();
/* Must keep the operation at the beginning of the interface */ /* Must keep the operation at the beginning of the interface */
intCnt = &g_intCount[cpuid]; intCnt = &g_intCount[ArchCurrCpuid()];
*intCnt = *intCnt + 1; *intCnt = *intCnt + 1;
OsSchedIrqStartTime();
#ifdef LOSCFG_CPUP_INCLUDE_IRQ #ifdef LOSCFG_CPUP_INCLUDE_IRQ
OsCpupIrqStart(cpuid); OsCpupIrqStart();
#endif #endif
OsSchedIrqStartTime();
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, intNum);
hwiForm = (&g_hwiForm[intNum]); hwiForm = (&g_hwiForm[intNum]);
#ifndef LOSCFG_NO_SHARED_IRQ #ifndef LOSCFG_NO_SHARED_IRQ
while (hwiForm->pstNext != NULL) { while (hwiForm->pstNext != NULL) {
@ -101,14 +110,13 @@ VOID OsInterrupt(UINT32 intNum)
#ifndef LOSCFG_NO_SHARED_IRQ #ifndef LOSCFG_NO_SHARED_IRQ
} }
#endif #endif
++g_hwiFormCnt[cpuid][intNum]; ++g_hwiFormCnt[intNum];
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, intNum);
OsSchedIrqUsedTimeUpdate();
#ifdef LOSCFG_CPUP_INCLUDE_IRQ #ifdef LOSCFG_CPUP_INCLUDE_IRQ
OsCpupIrqEnd(cpuid, intNum); OsCpupIrqEnd(intNum);
#endif #endif
OsSchedIrqUpdateUsedTime();
/* Must keep the operation at the end of the interface */ /* Must keep the operation at the end of the interface */
*intCnt = *intCnt - 1; *intCnt = *intCnt - 1;
} }
@ -344,3 +352,8 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irq
return ret; return ret;
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@ -1,373 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include "armv7_pmu_pri.h"
#include "perf_pmu_pri.h"
#include "los_hw_cpu.h"
#include "asm/platform.h"
OS_PMU_INTS(LOSCFG_KERNEL_CORE_NUM, g_pmuIrqNr);
STATIC HwPmu g_armv7Pmu;
STATIC INLINE UINT32 Armv7PmncRead(VOID)
{
UINT32 value = 0;
__asm__ volatile("mrc p15, 0, %0, c9, c12, 0" : "=r"(value));
return value;
}
STATIC INLINE VOID Armv7PmncWrite(UINT32 value)
{
value &= ARMV7_PMNC_MASK;
__asm__ volatile("mcr p15, 0, %0, c9, c12, 0" : : "r"(value));
ISB;
}
STATIC INLINE UINT32 Armv7PmuOverflowed(UINT32 pmnc)
{
return pmnc & ARMV7_OVERFLOWED_MASK;
}
STATIC INLINE UINT32 Armv7PmuCntOverflowed(UINT32 pmnc, UINT32 index)
{
return pmnc & ARMV7_CNT2BIT(ARMV7_IDX2CNT(index));
}
STATIC INLINE UINT32 Armv7CntValid(UINT32 index)
{
return index <= ARMV7_IDX_COUNTER_LAST;
}
STATIC INLINE VOID Armv7PmuSelCnt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
__asm__ volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (counter));
ISB;
}
STATIC INLINE VOID Armv7PmuSetCntPeriod(UINT32 index, UINT32 period)
{
if (!Armv7CntValid(index)) {
PRINT_ERR("CPU writing wrong counter %u\n", index);
} else if (index == ARMV7_IDX_CYCLE_COUNTER) {
__asm__ volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (period));
} else {
Armv7PmuSelCnt(index);
__asm__ volatile("mcr p15, 0, %0, c9, c13, 2" : : "r" (period));
}
}
STATIC INLINE VOID Armv7BindEvt2Cnt(UINT32 index, UINT32 value)
{
PRINT_DEBUG("bind event: %u to counter: %u\n", value, index);
Armv7PmuSelCnt(index);
value &= ARMV7_EVTYPE_MASK;
__asm__ volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (value));
}
STATIC INLINE VOID Armv7EnableCnt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
PRINT_DEBUG("index : %u, counter: %u\n", index, counter);
__asm__ volatile("mcr p15, 0, %0, c9, c12, 1" : : "r" (ARMV7_CNT2BIT(counter)));
}
STATIC INLINE VOID Armv7DisableCnt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
PRINT_DEBUG("index : %u, counter: %u\n", index, counter);
__asm__ volatile("mcr p15, 0, %0, c9, c12, 2" : : "r" (ARMV7_CNT2BIT(counter)));
}
STATIC INLINE VOID Armv7EnableCntInterrupt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
__asm__ volatile("mcr p15, 0, %0, c9, c14, 1" : : "r" (ARMV7_CNT2BIT(counter)));
ISB;
}
STATIC INLINE VOID Armv7DisableCntInterrupt(UINT32 index)
{
UINT32 counter = ARMV7_IDX2CNT(index);
__asm__ volatile("mcr p15, 0, %0, c9, c14, 2" : : "r" (ARMV7_CNT2BIT(counter)));
/* Clear the overflow flag in case an interrupt is pending. */
__asm__ volatile("mcr p15, 0, %0, c9, c12, 3" : : "r" (ARMV7_CNT2BIT(counter)));
ISB;
}
STATIC INLINE UINT32 Armv7PmuGetOverflowStatus(VOID)
{
UINT32 value;
__asm__ volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (value));
value &= ARMV7_FLAG_MASK;
__asm__ volatile("mcr p15, 0, %0, c9, c12, 3" : : "r" (value));
return value;
}
STATIC VOID Armv7EnableEvent(Event *event)
{
UINT32 cnt = event->counter;
if (!Armv7CntValid(cnt)) {
PRINT_ERR("CPU enabling wrong PMNC counter IRQ enable %u\n", cnt);
return;
}
if (event->period == 0) {
PRINT_INFO("event period value not valid, counter: %u\n", cnt);
return;
}
/*
* Enable counter and interrupt, and set the counter to count
* the event that we're interested in.
*/
UINT32 intSave = LOS_IntLock();
Armv7DisableCnt(cnt);
/*
* Set event (if destined for PMNx counters)
* We only need to set the event for the cycle counter if we
* have the ability to perform event filtering.
*/
if (cnt != ARMV7_IDX_CYCLE_COUNTER) {
Armv7BindEvt2Cnt(cnt, event->eventId);
}
/* Enable interrupt for this counter */
Armv7EnableCntInterrupt(cnt);
Armv7EnableCnt(cnt);
LOS_IntRestore(intSave);
PRINT_DEBUG("enabled event: %u cnt: %u\n", event->eventId, cnt);
}
STATIC VOID Armv7DisableEvent(Event *event)
{
UINT32 cnt = event->counter;
if (!Armv7CntValid(cnt)) {
PRINT_ERR("CPU enabling wrong PMNC counter IRQ enable %u\n", cnt);
return;
}
UINT32 intSave = LOS_IntLock();
Armv7DisableCnt(cnt);
Armv7DisableCntInterrupt(cnt);
LOS_IntRestore(intSave);
}
STATIC VOID Armv7StartAllCnt(VOID)
{
PRINT_DEBUG("starting pmu...\n");
/* Enable all counters */
UINT32 reg = Armv7PmncRead() | ARMV7_PMNC_E;
if (g_armv7Pmu.cntDivided) {
reg |= ARMV7_PMNC_D;
} else {
reg &= ~ARMV7_PMNC_D;
}
Armv7PmncWrite(reg);
HalIrqUnmask(g_pmuIrqNr[ArchCurrCpuid()]);
}
STATIC VOID Armv7StopAllCnt(VOID)
{
PRINT_DEBUG("stopping pmu...\n");
/* Disable all counters */
Armv7PmncWrite(Armv7PmncRead() & ~ARMV7_PMNC_E);
HalIrqMask(g_pmuIrqNr[ArchCurrCpuid()]);
}
STATIC VOID Armv7ResetAllCnt(VOID)
{
UINT32 index;
/* The counter and interrupt enable registers are unknown at reset. */
for (index = ARMV7_IDX_CYCLE_COUNTER; index < ARMV7_IDX_MAX_COUNTER; index++) {
Armv7DisableCnt(index);
Armv7DisableCntInterrupt(index);
}
/* Initialize & Reset PMNC: C and P bits and D bits */
UINT32 reg = ARMV7_PMNC_P | ARMV7_PMNC_C | (g_armv7Pmu.cntDivided ? ARMV7_PMNC_D : 0);
Armv7PmncWrite(reg);
}
STATIC VOID Armv7SetEventPeriod(Event *event)
{
if (event->period != 0) {
PRINT_INFO("counter: %u, period: 0x%x\n", event->counter, event->period);
Armv7PmuSetCntPeriod(event->counter, PERIOD_CALC(event->period));
}
}
STATIC UINTPTR Armv7ReadEventCnt(Event *event)
{
UINT32 value = 0;
UINT32 index = event->counter;
if (!Armv7CntValid(index)) {
PRINT_ERR("CPU reading wrong counter %u\n", index);
} else if (index == ARMV7_IDX_CYCLE_COUNTER) {
__asm__ volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (value));
} else {
Armv7PmuSelCnt(index);
__asm__ volatile("mrc p15, 0, %0, c9, c13, 2" : "=r" (value));
}
if (value < PERIOD_CALC(event->period)) {
if (Armv7PmuCntOverflowed(Armv7PmuGetOverflowStatus(), event->counter)) {
value += event->period;
}
} else {
value -= PERIOD_CALC(event->period);
}
return value;
}
STATIC const UINT32 g_armv7Map[] = {
[PERF_COUNT_HW_CPU_CYCLES] = ARMV7_PERF_HW_CYCLES,
[PERF_COUNT_HW_INSTRUCTIONS] = ARMV7_PERF_HW_INSTRUCTIONS,
[PERF_COUNT_HW_DCACHE_REFERENCES] = ARMV7_PERF_HW_DCACHES,
[PERF_COUNT_HW_DCACHE_MISSES] = ARMV7_PERF_HW_DCACHE_MISSES,
[PERF_COUNT_HW_ICACHE_REFERENCES] = ARMV7_PERF_HW_ICACHES,
[PERF_COUNT_HW_ICACHE_MISSES] = ARMV7_PERF_HW_ICACHE_MISSES,
[PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV7_PERF_HW_BRANCHES,
[PERF_COUNT_HW_BRANCH_MISSES] = ARMV7_PERF_HW_BRANCE_MISSES,
};
UINT32 Armv7PmuMapEvent(UINT32 eventType, BOOL reverse)
{
if (!reverse) { /* Common event to armv7 real event */
if (eventType < ARRAY_SIZE(g_armv7Map)) {
return g_armv7Map[eventType];
}
return eventType;
} else { /* Armv7 real event to common event */
UINT32 i;
for (i = 0; i < ARRAY_SIZE(g_armv7Map); i++) {
if (g_armv7Map[i] == eventType) {
return i;
}
}
return PERF_HW_INVALID_EVENT_TYPE;
}
}
STATIC VOID Armv7PmuIrqHandler(VOID)
{
UINT32 index;
PerfRegs regs;
PerfEvent *events = &(g_armv7Pmu.pmu.events);
UINT32 eventNum = events->nr;
/* Get and reset the IRQ flags */
UINT32 pmnc = Armv7PmuGetOverflowStatus();
if (!Armv7PmuOverflowed(pmnc)) {
return;
}
(VOID)memset_s(&regs, sizeof(PerfRegs), 0, sizeof(PerfRegs));
OsPerfFetchIrqRegs(&regs);
Armv7StopAllCnt();
for (index = 0; index < eventNum; index++) {
Event *event = &(events->per[index]);
/*
* We have a single interrupt for all counters. Check that
* each counter has overflowed before we process it.
*/
if (!Armv7PmuCntOverflowed(pmnc, event->counter) || (event->period == 0)) {
continue;
}
Armv7PmuSetCntPeriod(event->counter, PERIOD_CALC(event->period));
OsPerfUpdateEventCount(event, event->period);
OsPerfHandleOverFlow(event, &regs);
}
Armv7StartAllCnt();
}
UINT32 OsGetPmuMaxCounter(VOID)
{
return ARMV7_IDX_MAX_COUNTER;
}
UINT32 OsGetPmuCycleCounter(VOID)
{
return ARMV7_IDX_CYCLE_COUNTER;
}
UINT32 OsGetPmuCounter0(VOID)
{
return ARMV7_IDX_COUNTER0;
}
STATIC HwPmu g_armv7Pmu = {
.canDivided = TRUE,
.enable = Armv7EnableEvent,
.disable = Armv7DisableEvent,
.start = Armv7StartAllCnt,
.stop = Armv7StopAllCnt,
.clear = Armv7ResetAllCnt,
.setPeriod = Armv7SetEventPeriod,
.readCnt = Armv7ReadEventCnt,
.mapEvent = Armv7PmuMapEvent,
};
UINT32 OsHwPmuInit(VOID)
{
UINT32 ret;
UINT32 index;
for (index = 0; index < LOSCFG_KERNEL_CORE_NUM; index++) {
ret = LOS_HwiCreate(g_pmuIrqNr[index], 0, 0, Armv7PmuIrqHandler, 0);
if (ret != LOS_OK) {
PRINT_ERR("pmu %u irq handler register failed\n", g_pmuIrqNr[index]);
return ret;
}
#ifdef LOSCFG_KERNEL_SMP
HalIrqSetAffinity(g_pmuIrqNr[index], CPUID_TO_AFFI_MASK(index));
#endif
}
ret = OsPerfHwInit(&g_armv7Pmu);
return ret;
}

View File

@ -1,104 +0,0 @@
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 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.
*/
#include "smp.h"
#include "arch_config.h"
#include "los_base.h"
#include "los_hw.h"
#include "los_atomic.h"
#include "los_arch_mmu.h"
#include "gic_common.h"
#include "los_task_pri.h"
#ifdef LOSCFG_KERNEL_SMP
extern VOID reset_vector(VOID);
struct OsCpuInit {
ArchCpuStartFunc cpuStart;
VOID *arg;
Atomic initFlag;
};
STATIC struct OsCpuInit g_cpuInit[CORE_NUM - 1] = {0};
VOID HalArchCpuOn(UINT32 cpuNum, ArchCpuStartFunc func, struct SmpOps *ops, VOID *arg)
{
struct OsCpuInit *cpuInit = &g_cpuInit[cpuNum - 1];
UINTPTR startEntry = (UINTPTR)&reset_vector - KERNEL_VMM_BASE + SYS_MEM_BASE;
INT32 ret;
cpuInit->cpuStart = func;
cpuInit->arg = arg;
cpuInit->initFlag = 0;
DCacheFlushRange((UINTPTR)cpuInit, (UINTPTR)cpuInit + sizeof(struct OsCpuInit));
LOS_ASSERT(ops != NULL);
ret = ops->SmpCpuOn(cpuNum, startEntry);
if (ret < 0) {
PRINT_ERR("cpu start failed, cpu num: %u, ret: %d\n", cpuNum, ret);
return;
}
while (!LOS_AtomicRead(&cpuInit->initFlag)) {
WFE;
}
}
VOID HalSecondaryCpuStart(VOID)
{
UINT32 cpuid = ArchCurrCpuid();
struct OsCpuInit *cpuInit = &g_cpuInit[cpuid - 1];
OsCurrTaskSet(OsGetMainTask());
LOS_AtomicSet(&cpuInit->initFlag, 1);
SEV;
#ifdef LOSCFG_KERNEL_MMU
OsArchMmuInitPerCPU();
#endif
/* store each core's hwid */
CPU_MAP_SET(cpuid, OsHwIDGet());
HalIrqInitPercpu();
cpuInit->cpuStart(cpuInit->arg);
while (1) {
WFI;
}
}
#endif

141
arch/arm/arm/src/startup/reset_vector_mp.S Normal file → Executable file
View File

@ -28,7 +28,6 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#define ASSEMBLY #define ASSEMBLY
#include "arch_config.h" #include "arch_config.h"
#include "los_vm_boot.h" #include "los_vm_boot.h"
@ -38,9 +37,17 @@
.global __exc_stack_top .global __exc_stack_top
.global __irq_stack_top
.global __fiq_stack_top
.global __svc_stack_top .global __svc_stack_top
.global __abt_stack_top
.global __undef_stack_top
.global __exc_stack .global __exc_stack
.global __irq_stack
.global __fiq_stack
.global __svc_stack .global __svc_stack
.global __abt_stack
.global __undef_stack
.extern __bss_start .extern __bss_start
.extern __bss_end .extern __bss_end
@ -55,8 +62,6 @@
.extern __stack_chk_guard_setup .extern __stack_chk_guard_setup
.extern g_firstPageTable .extern g_firstPageTable
.extern g_mmuJumpPageTable .extern g_mmuJumpPageTable
.extern g_archMmuInitMapping
.extern HalSecondaryCpuStart
.equ MPIDR_CPUID_MASK, 0xffU .equ MPIDR_CPUID_MASK, 0xffU
@ -80,6 +85,14 @@
bl excstack_magic bl excstack_magic
.endm .endm
/* param0 is physical address, param1 virtual address, param2 is sizes, param3 is flag */
.macro PAGE_TABLE_SET param0, param1, param2, param3
ldr r6, =\param0
ldr r7, =\param1
ldr r8, =\param2
ldr r10, =\param3
bl page_table_build
.endm
.code 32 .code 32
.section ".vectors","ax" .section ".vectors","ax"
@ -102,9 +115,9 @@ __exception_handlers:
.global reset_vector .global reset_vector
.type reset_vector,function .type reset_vector,function
#ifdef LOSCFG_BOOTENV_RAM #ifdef LOSCFG_QUICK_START
__quickstart_args_start: __quickstart_args_start:
.fill LOSCFG_BOOTENV_RAMSIZE,1,0 .fill 512,1,0
__quickstart_args_end: __quickstart_args_end:
.global OsGetArgsAddr .global OsGetArgsAddr
@ -121,9 +134,8 @@ reset_vector:
mcr p15, 0, r0, c13, c0, 4 mcr p15, 0, r0, c13, c0, 4
/* do some early cpu setup: i/d cache disable, mmu disabled */ /* do some early cpu setup: i/d cache disable, mmu disabled */
mrc p15, 0, r0, c1, c0, 0 mrc p15, 0, r0, c1, c0, 0
bic r0, #(1 << 12) /* i cache */ bic r0, #(1<<12)
bic r0, #(1 << 2) /* d cache */ bic r0, #(1<<2 | 1<<0)
bic r0, #(1 << 0) /* mmu */
mcr p15, 0, r0, c1, c0, 0 mcr p15, 0, r0, c1, c0, 0
/* enable fpu+neon */ /* enable fpu+neon */
@ -172,7 +184,6 @@ reloc_img_to_bottom_loop:
sub r11, r11, r12 /* r11: eventual address offset */ sub r11, r11, r12 /* r11: eventual address offset */
reloc_img_to_bottom_done: reloc_img_to_bottom_done:
#ifdef LOSCFG_KERNEL_MMU
ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */ ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */
add r4, r4, r11 add r4, r4, r11
mov r0, r4 mov r0, r4
@ -180,15 +191,12 @@ reloc_img_to_bottom_done:
mov r2, #MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS mov r2, #MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS
bl memset_optimized /* optimized memset since r0 is 64-byte aligned */ bl memset_optimized /* optimized memset since r0 is 64-byte aligned */
ldr r5, =g_archMmuInitMapping PAGE_TABLE_SET SYS_MEM_BASE, KERNEL_VMM_BASE, KERNEL_VMM_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
add r5, r5, r11 PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_NORMAL_NOCACHE
init_mmu_loop: PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_DEVICE_BASE, PERIPH_DEVICE_SIZE, MMU_INITIAL_MAP_DEVICE
ldmia r5!, {r6-r10} /* r6 = phys, r7 = virt, r8 = size, r9 = mmu_flags, r10 = name */ PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_CACHED_BASE, PERIPH_CACHED_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
cmp r8, 0 /* if size = 0, the mmu init done */ PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_UNCACHED_BASE, PERIPH_UNCACHED_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
beq init_mmu_done
bl page_table_build
b init_mmu_loop
init_mmu_done:
orr r8, r4, #MMU_TTBRx_FLAGS /* r8 = r4 and set cacheable attributes on translation walk */ orr r8, r4, #MMU_TTBRx_FLAGS /* r8 = r4 and set cacheable attributes on translation walk */
ldr r4, =g_mmuJumpPageTable /* r4: jump pagetable vaddr */ ldr r4, =g_mmuJumpPageTable /* r4: jump pagetable vaddr */
add r4, r4, r11 add r4, r4, r11
@ -205,17 +213,40 @@ init_mmu_done:
rsb r7, r11, r6, lsl #20 /* r7: va */ rsb r7, r11, r6, lsl #20 /* r7: va */
str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[vaIndex] = pt entry */ str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[vaIndex] = pt entry */
bl _bootaddr_setup
bl mmu_setup /* set up the mmu */ bl mmu_setup /* set up the mmu */
#endif
/* clear out the interrupt and exception stack and set magic num to check the overflow */ /* clear out the interrupt and exception stack and set magic num to check the overflow */
ldr r0, =__svc_stack ldr r0, =__undef_stack
ldr r1, =__exc_stack_top ldr r1, =__exc_stack_top
bl stack_init bl stack_init
STACK_MAGIC_SET __undef_stack, #OS_EXC_UNDEF_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __abt_stack, #OS_EXC_ABT_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __irq_stack, #OS_EXC_IRQ_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __fiq_stack, #OS_EXC_FIQ_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __svc_stack, #OS_EXC_SVC_STACK_SIZE, OS_STACK_MAGIC_WORD STACK_MAGIC_SET __svc_stack, #OS_EXC_SVC_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __exc_stack, #OS_EXC_STACK_SIZE, OS_STACK_MAGIC_WORD STACK_MAGIC_SET __exc_stack, #OS_EXC_STACK_SIZE, OS_STACK_MAGIC_WORD
warm_reset: warm_reset:
/* initialize interrupt/exception environments */
mov r0, #(CPSR_IRQ_DISABLE |CPSR_FIQ_DISABLE|CPSR_IRQ_MODE)
msr cpsr, r0
EXC_SP_SET __irq_stack_top, #OS_EXC_IRQ_STACK_SIZE
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_UNDEF_MODE)
msr cpsr, r0
EXC_SP_SET __undef_stack_top, #OS_EXC_UNDEF_STACK_SIZE
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_ABT_MODE)
msr cpsr, r0
EXC_SP_SET __abt_stack_top, #OS_EXC_ABT_STACK_SIZE
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_FIQ_MODE)
msr cpsr, r0
EXC_SP_SET __fiq_stack_top, #OS_EXC_FIQ_STACK_SIZE
/* initialize CPSR (machine state register) */ /* initialize CPSR (machine state register) */
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE) mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE)
msr cpsr, r0 msr cpsr, r0
@ -263,7 +294,7 @@ clear_bss:
_start_hang: _start_hang:
b _start_hang b _start_hang
#ifdef LOSCFG_KERNEL_MMU
mmu_setup: mmu_setup:
mov r12, #0 mov r12, #0
mcr p15, 0, r12, c8, c7, 0 /* Set c8 to control the TLB and set the mapping to invalid */ mcr p15, 0, r12, c8, c7, 0 /* Set c8 to control the TLB and set the mapping to invalid */
@ -276,18 +307,18 @@ mmu_setup:
mov r12, #0x7 /* 0b0111 */ mov r12, #0x7 /* 0b0111 */
mcr p15, 0, r12, c3, c0, 0 /* Set DACR with 0b0111, client and manager domian */ mcr p15, 0, r12, c3, c0, 0 /* Set DACR with 0b0111, client and manager domian */
isb isb
mrc p15, 0, r12, c1, c0, 1 /* ACTLR, Auxiliary Control Register */ mrc p15, 0, r12, c1, c0, 1 /* ACTLR, Auxlliary Control Register */
orr r12, r12, #(1 << 6) /* SMP, Enables coherent requests to the processor. */ orr r12, r12, #(1 << 6) /* SMP, Enables coherent requests to the processor. */
orr r12, r12, #(1 << 2) /* Enable D-side prefetch */ orr r12, r12, #(1 << 2) /* Enable D-side prefetch */
orr r12, r12, #(1 << 11) /* Global BP Enable bit */ orr r12, r12, #(1 << 11) /* Global BP Enable bit */
mcr p15, 0, r12, c1, c0, 1 /* ACTLR, Auxiliary Control Register */ mcr p15, 0, r12, c1, c0, 1 /* ACTLR, Auxlliary Control Register */
dsb dsb
mrc p15, 0, r12, c1, c0, 0 mrc p15, 0, r12, c1, c0, 0
bic r12, #(1 << 29 | 1 << 28) /* Disable TRE/AFE */ bic r12, #(1 << 29 | 1 << 28)
orr r12, #(1 << 0) /* mmu enable */ orr r12, #(1 << 0)
bic r12, #(1 << 1) bic r12, #(1 << 1)
orr r12, #(1 << 2) /* D cache enable */ orr r12, #(1 << 2)
orr r12, #(1 << 12) /* I cache enable */ orr r12, #(1 << 12)
mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */ mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */
isb isb
ldr pc, =1f /* Convert to VA */ ldr pc, =1f /* Convert to VA */
@ -299,7 +330,7 @@ mmu_setup:
isb isb
sub lr, r11 /* adjust lr with delta of physical address and virtual address */ sub lr, r11 /* adjust lr with delta of physical address and virtual address */
bx lr bx lr
#endif
.code 32 .code 32
.global reset_platform .global reset_platform
@ -314,9 +345,7 @@ reset_platform:
mov r0, #0 mov r0, #0
mov pc, r0 // Jump to reset vector mov pc, r0 // Jump to reset vector
#endif #endif
cpu_start: cpu_start:
#ifdef LOSCFG_KERNEL_MMU
ldr r4, =g_firstPageTable /* r4 = physical address of translation table and clear it */ ldr r4, =g_firstPageTable /* r4 = physical address of translation table and clear it */
add r4, r4, r11 add r4, r4, r11
orr r8, r4, #MMU_TTBRx_FLAGS orr r8, r4, #MMU_TTBRx_FLAGS
@ -327,9 +356,7 @@ cpu_start:
add r4, r4, r11 /* r4 = tt_trampoline paddr */ add r4, r4, r11 /* r4 = tt_trampoline paddr */
bl mmu_setup bl mmu_setup
#endif bl secondary_cpu_start
bl HalSecondaryCpuStart
b . b .
secondary_cpu_init: secondary_cpu_init:
@ -367,11 +394,10 @@ sp_set:
* r10: flags * r10: flags
* r9 and r12 will be used as variable * r9 and r12 will be used as variable
*/ */
#ifdef LOSCFG_KERNEL_MMU
page_table_build: page_table_build:
mov r10, r6 mov r9, r6
bfc r10, #20, #12 /* r9: pa % MB */ bfc r9, #20, #12 /* r9: pa % MB */
add r8, r8, r10 add r8, r8, r9
add r8, r8, #(1 << 20) add r8, r8, #(1 << 20)
sub r8, r8, #1 sub r8, r8, #1
lsr r6, #20 /* r6 = physical address / MB */ lsr r6, #20 /* r6 = physical address / MB */
@ -379,14 +405,14 @@ page_table_build:
lsr r8, #20 /* r8 = roundup(size, MB) */ lsr r8, #20 /* r8 = roundup(size, MB) */
page_table_build_loop: page_table_build_loop:
orr r12, r9, r6, lsl #20 /* r12: flags | physAddr */ orr r12, r10, r6, lsl #20 /* r12: flags | physAddr */
str r12, [r4, r7, lsl #2] /* gPgTable[l1Index] = physAddr | flags */ str r12, [r4, r7, lsl #2] /* gPgTable[l1Index] = physAddr | flags */
add r6, #1 /* physAddr+ */ add r6, #1 /* physAddr+ */
add r7, #1 /* l1Index++ */ add r7, #1 /* l1Index++ */
subs r8, #1 /* sizes-- */ subs r8, #1 /* sizes-- */
bne page_table_build_loop bne page_table_build_loop
bx lr bx lr
#endif
/* /*
* init stack to initial value * init stack to initial value
* r0 is stack mem start, r1 is stack mem end * r0 is stack mem start, r1 is stack mem end
@ -421,7 +447,24 @@ excstack_magic_loop:
blt excstack_magic_loop blt excstack_magic_loop
bx lr bx lr
#ifdef LOSCFG_KERNEL_MMU /*
* 0xe51ff004 = "ldr pc, [pc, #-4]"
* next addr value will be the real booting addr
*/
_bootaddr_setup:
mov r0, #0
ldr r1, =0xe51ff004
str r1, [r0]
add r0, r0, #4
ldr r1, =SYS_MEM_BASE
str r1, [r0]
dsb
isb
bx lr
memset_optimized: memset_optimized:
mov r3, r0 mov r3, r0
vdup.8 q0, r1 vdup.8 q0, r1
@ -433,7 +476,7 @@ memset_optimized_loop:
vstmia r3!, {d0 - d7} vstmia r3!, {d0 - d7}
bge memset_optimized_loop bge memset_optimized_loop
bx lr bx lr
#endif
init_done: init_done:
.long 0xDEADB00B .long 0xDEADB00B
@ -450,6 +493,22 @@ init_flag:
.section ".int_stack", "wa", %nobits .section ".int_stack", "wa", %nobits
.align 3 .align 3
__undef_stack:
.space OS_EXC_UNDEF_STACK_SIZE * CORE_NUM
__undef_stack_top:
__abt_stack:
.space OS_EXC_ABT_STACK_SIZE * CORE_NUM
__abt_stack_top:
__irq_stack:
.space OS_EXC_IRQ_STACK_SIZE * CORE_NUM
__irq_stack_top:
__fiq_stack:
.space OS_EXC_FIQ_STACK_SIZE * CORE_NUM
__fiq_stack_top:
__svc_stack: __svc_stack:
.space OS_EXC_SVC_STACK_SIZE * CORE_NUM .space OS_EXC_SVC_STACK_SIZE * CORE_NUM
__svc_stack_top: __svc_stack_top:

131
arch/arm/arm/src/startup/reset_vector_up.S Normal file → Executable file
View File

@ -38,9 +38,17 @@
.global __exc_stack_top .global __exc_stack_top
.global __irq_stack_top
.global __fiq_stack_top
.global __svc_stack_top .global __svc_stack_top
.global __abt_stack_top
.global __undef_stack_top
.global __exc_stack .global __exc_stack
.global __irq_stack
.global __fiq_stack
.global __svc_stack .global __svc_stack
.global __abt_stack
.global __undef_stack
.extern __bss_start .extern __bss_start
.extern __bss_end .extern __bss_end
@ -54,7 +62,6 @@
.extern __stack_chk_guard_setup .extern __stack_chk_guard_setup
.extern g_firstPageTable .extern g_firstPageTable
.extern g_mmuJumpPageTable .extern g_mmuJumpPageTable
.extern g_archMmuInitMapping
.equ MPIDR_CPUID_MASK, 0xffU .equ MPIDR_CPUID_MASK, 0xffU
@ -78,6 +85,14 @@
bl excstack_magic bl excstack_magic
.endm .endm
/* param0 is physical address, param1 virtual address, param2 is sizes, param3 is flag */
.macro PAGE_TABLE_SET param0, param1, param2, param3
ldr r6, =\param0
ldr r7, =\param1
ldr r8, =\param2
ldr r10, =\param3
bl page_table_build
.endm
.code 32 .code 32
.section ".vectors","ax" .section ".vectors","ax"
@ -101,9 +116,8 @@ __exception_handlers:
reset_vector: reset_vector:
/* do some early cpu setup: i/d cache disable, mmu disabled */ /* do some early cpu setup: i/d cache disable, mmu disabled */
mrc p15, 0, r0, c1, c0, 0 mrc p15, 0, r0, c1, c0, 0
bic r0, #(1 << 12) /* i cache */ bic r0, #(1<<12)
bic r0, #(1 << 2) /* d cache */ bic r0, #(1<<2 | 1<<0)
bic r0, #(1 << 0) /* mmu */
mcr p15, 0, r0, c1, c0, 0 mcr p15, 0, r0, c1, c0, 0
/* enable fpu+neon */ /* enable fpu+neon */
@ -147,7 +161,6 @@ reloc_img_to_bottom_loop:
sub r11, r11, r12 /* r11: eventual address offset */ sub r11, r11, r12 /* r11: eventual address offset */
reloc_img_to_bottom_done: reloc_img_to_bottom_done:
#ifdef LOSCFG_KERNEL_MMU
ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */ ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */
add r4, r4, r11 add r4, r4, r11
mov r0, r4 mov r0, r4
@ -155,15 +168,13 @@ reloc_img_to_bottom_done:
mov r2, #MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS mov r2, #MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS
bl memset_optimized /* optimized memset since r0 is 64-byte aligned */ bl memset_optimized /* optimized memset since r0 is 64-byte aligned */
ldr r5, =g_archMmuInitMapping
add r5, r5, r11 PAGE_TABLE_SET SYS_MEM_BASE, KERNEL_VMM_BASE, KERNEL_VMM_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
init_mmu_loop: PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_NORMAL_NOCACHE
ldmia r5!, {r6-r10} /* r6 = phys, r7 = virt, r8 = size, r9 = mmu_flags, r10 = name */ PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_DEVICE_BASE, PERIPH_DEVICE_SIZE, MMU_INITIAL_MAP_DEVICE
cmp r8, 0 /* if size = 0, the mmu init done */ PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_CACHED_BASE, PERIPH_CACHED_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
beq init_mmu_done PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_UNCACHED_BASE, PERIPH_UNCACHED_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
bl page_table_build
b init_mmu_loop
init_mmu_done:
orr r8, r4, #MMU_TTBRx_FLAGS /* r8 = r4 and set cacheable attributes on translation walk */ orr r8, r4, #MMU_TTBRx_FLAGS /* r8 = r4 and set cacheable attributes on translation walk */
ldr r4, =g_mmuJumpPageTable /* r4: jump pagetable vaddr */ ldr r4, =g_mmuJumpPageTable /* r4: jump pagetable vaddr */
add r4, r4, r11 add r4, r4, r11
@ -181,7 +192,7 @@ init_mmu_done:
str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[vaIndex] = pt entry */ str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[vaIndex] = pt entry */
bl mmu_setup /* set up the mmu */ bl mmu_setup /* set up the mmu */
#endif
/* get cpuid and keep it in r11 */ /* get cpuid and keep it in r11 */
mrc p15, 0, r11, c0, c0, 5 mrc p15, 0, r11, c0, c0, 5
and r11, r11, #MPIDR_CPUID_MASK and r11, r11, #MPIDR_CPUID_MASK
@ -190,15 +201,36 @@ init_mmu_done:
excstatck_loop: excstatck_loop:
/* clear out the interrupt and exception stack and set magic num to check the overflow */ /* clear out the interrupt and exception stack and set magic num to check the overflow */
ldr r0, =__svc_stack ldr r0, =__undef_stack
ldr r1, =__exc_stack_top ldr r1, =__exc_stack_top
bl stack_init bl stack_init
STACK_MAGIC_SET __undef_stack, #OS_EXC_UNDEF_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __abt_stack, #OS_EXC_ABT_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __irq_stack, #OS_EXC_IRQ_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __fiq_stack, #OS_EXC_FIQ_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __svc_stack, #OS_EXC_SVC_STACK_SIZE, OS_STACK_MAGIC_WORD STACK_MAGIC_SET __svc_stack, #OS_EXC_SVC_STACK_SIZE, OS_STACK_MAGIC_WORD
STACK_MAGIC_SET __exc_stack, #OS_EXC_STACK_SIZE, OS_STACK_MAGIC_WORD STACK_MAGIC_SET __exc_stack, #OS_EXC_STACK_SIZE, OS_STACK_MAGIC_WORD
excstatck_loop_done: excstatck_loop_done:
warm_reset: warm_reset:
/* initialize interrupt/exception environments */
mov r0, #(CPSR_IRQ_DISABLE |CPSR_FIQ_DISABLE|CPSR_IRQ_MODE)
msr cpsr, r0
EXC_SP_SET __irq_stack_top, #OS_EXC_IRQ_STACK_SIZE
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_UNDEF_MODE)
msr cpsr, r0
EXC_SP_SET __undef_stack_top, #OS_EXC_UNDEF_STACK_SIZE
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_ABT_MODE)
msr cpsr, r0
EXC_SP_SET __abt_stack_top, #OS_EXC_ABT_STACK_SIZE
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_FIQ_MODE)
msr cpsr, r0
EXC_SP_SET __fiq_stack_top, #OS_EXC_FIQ_STACK_SIZE
/* initialize CPSR (machine state register) */ /* initialize CPSR (machine state register) */
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE) mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE)
msr cpsr, r0 msr cpsr, r0
@ -228,6 +260,9 @@ warm_reset:
LDR r0, =__exception_handlers LDR r0, =__exception_handlers
MCR p15, 0, r0, c12, c0, 0 MCR p15, 0, r0, c12, c0, 0
cmp r11, #0
bne cpu_start
clear_bss: clear_bss:
ldr r0, =__bss_start ldr r0, =__bss_start
ldr r2, =__bss_end ldr r2, =__bss_end
@ -252,7 +287,6 @@ clear_bss:
_start_hang: _start_hang:
b _start_hang b _start_hang
#ifdef LOSCFG_KERNEL_MMU
mmu_setup: mmu_setup:
mov r12, #0 mov r12, #0
mcr p15, 0, r12, c8, c7, 0 /* Set c8 to control the TLB and set the mapping to invalid */ mcr p15, 0, r12, c8, c7, 0 /* Set c8 to control the TLB and set the mapping to invalid */
@ -270,11 +304,11 @@ mmu_setup:
isb isb
mrc p15, 0, r12, c1, c0, 0 mrc p15, 0, r12, c1, c0, 0
bic r12, #(1 << 29 | 1 << 28) /* Disable TRE/AFE */ bic r12, #(1 << 29 | 1 << 28)
orr r12, #(1 << 0) /* mmu enable */ orr r12, #(1 << 0)
bic r12, #(1 << 1) bic r12, #(1 << 1)
orr r12, #(1 << 2) /* D cache enable */ orr r12, #(1 << 2)
orr r12, #(1 << 12) /* I cache enable */ orr r12, #(1 << 12)
mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */ mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */
isb isb
@ -289,7 +323,7 @@ mmu_setup:
sub lr, r11 /* adjust lr with delta of physical address and virtual address */ sub lr, r11 /* adjust lr with delta of physical address and virtual address */
bx lr bx lr
#endif
.code 32 .code 32
.global reset_platform .global reset_platform
@ -304,6 +338,11 @@ reset_platform:
mov r0, #0 mov r0, #0
mov pc, r0 // Jump to reset vector mov pc, r0 // Jump to reset vector
#endif #endif
cpu_start:
bl secondary_cpu_start
b .
/* /*
* set sp for current cpu * set sp for current cpu
@ -323,11 +362,10 @@ sp_set:
* r10: flags * r10: flags
* r9 and r12 will be used as variable * r9 and r12 will be used as variable
*/ */
#ifdef LOSCFG_KERNEL_MMU
page_table_build: page_table_build:
mov r10, r6 mov r9, r6
bfc r10, #20, #12 /* r9: pa % MB */ bfc r9, #20, #12 /* r9: pa % MB */
add r8, r8, r10 add r8, r8, r9
add r8, r8, #(1 << 20) add r8, r8, #(1 << 20)
sub r8, r8, #1 sub r8, r8, #1
lsr r6, #20 /* r6 = physical address / MB */ lsr r6, #20 /* r6 = physical address / MB */
@ -335,14 +373,14 @@ page_table_build:
lsr r8, #20 /* r8 = roundup(size, MB) */ lsr r8, #20 /* r8 = roundup(size, MB) */
page_table_build_loop: page_table_build_loop:
orr r12, r9, r6, lsl #20 /* r12: flags | physAddr */ orr r12, r10, r6, lsl #20 /* r12: flags | physAddr */
str r12, [r4, r7, lsl #2] /* gPgTable[l1Index] = physAddr | flags */ str r12, [r4, r7, lsl #2] /* gPgTable[l1Index] = physAddr | flags */
add r6, #1 /* physAddr+ */ add r6, #1 /* physAddr+ */
add r7, #1 /* l1Index++ */ add r7, #1 /* l1Index++ */
subs r8, #1 /* sizes-- */ subs r8, #1 /* sizes-- */
bne page_table_build_loop bne page_table_build_loop
bx lr bx lr
#endif
/* /*
* init stack to initial value * init stack to initial value
* r0 is stack mem start, r1 is stack mem end * r0 is stack mem start, r1 is stack mem end
@ -377,7 +415,24 @@ excstack_magic_loop:
blt excstack_magic_loop blt excstack_magic_loop
bx lr bx lr
#ifdef LOSCFG_KERNEL_MMU /*
* 0xe51ff004 = "ldr pc, [pc, #-4]"
* next addr value will be the real booting addr
*/
_bootaddr_setup:
mov r0, #0
ldr r1, =0xe51ff004
str r1, [r0]
add r0, r0, #4
ldr r1, =SYS_MEM_BASE
str r1, [r0]
dsb
isb
bx lr
memset_optimized: memset_optimized:
mov r3, r0 mov r3, r0
vdup.8 q0, r1 vdup.8 q0, r1
@ -389,7 +444,7 @@ memset_optimized_loop:
vstmia r3!, {d0 - d7} vstmia r3!, {d0 - d7}
bge memset_optimized_loop bge memset_optimized_loop
bx lr bx lr
#endif
init_done: init_done:
.long 0xDEADB00B .long 0xDEADB00B
@ -406,6 +461,22 @@ init_flag:
.section ".int_stack", "wa", %nobits .section ".int_stack", "wa", %nobits
.align 3 .align 3
__undef_stack:
.space OS_EXC_UNDEF_STACK_SIZE * CORE_NUM
__undef_stack_top:
__abt_stack:
.space OS_EXC_ABT_STACK_SIZE * CORE_NUM
__abt_stack_top:
__irq_stack:
.space OS_EXC_IRQ_STACK_SIZE * CORE_NUM
__irq_stack_top:
__fiq_stack:
.space OS_EXC_FIQ_STACK_SIZE * CORE_NUM
__fiq_stack_top:
__svc_stack: __svc_stack:
.space OS_EXC_SVC_STACK_SIZE * CORE_NUM .space OS_EXC_SVC_STACK_SIZE * CORE_NUM
__svc_stack_top: __svc_stack_top:

12
arch/arm/arm/src/strncpy_from_user.c Normal file → Executable file
View File

@ -33,6 +33,11 @@
#include "los_user_get.h" #include "los_user_get.h"
#include "los_vm_map.h" #include "los_vm_map.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count) INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
{ {
@ -46,7 +51,7 @@ INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
} }
maxCount = (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, (size_t)count)) ? \ maxCount = (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, (size_t)count)) ? \
count : (INT32)(USER_ASPACE_TOP_MAX - (UINTPTR)src); count : (USER_ASPACE_TOP_MAX - (UINTPTR)src);
for (i = 0; i < maxCount; ++i) { for (i = 0; i < maxCount; ++i) {
if (LOS_GetUser(&character, src + offset) != LOS_OK) { if (LOS_GetUser(&character, src + offset) != LOS_OK) {
@ -62,3 +67,8 @@ INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
return offset; return offset;
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

10
arch/arm/arm/src/strnlen_user.c Normal file → Executable file
View File

@ -33,6 +33,11 @@
#include "los_user_get.h" #include "los_user_get.h"
#include "los_vm_map.h" #include "los_vm_map.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
INT32 LOS_StrnlenUser(const CHAR *src, INT32 count) INT32 LOS_StrnlenUser(const CHAR *src, INT32 count)
{ {
@ -61,3 +66,8 @@ INT32 LOS_StrnlenUser(const CHAR *src, INT32 count)
return count + 1; return count + 1;
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

21
arch/arm/arm/src/user_copy.c Normal file → Executable file
View File

@ -31,11 +31,15 @@
#include "user_copy.h" #include "user_copy.h"
#include "arm_user_copy.h" #include "arm_user_copy.h"
#include "arm_user_clear.h"
#include "securec.h" #include "securec.h"
#include "los_memory.h" #include "los_memory.h"
#include "los_vm_map.h" #include "los_vm_map.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
size_t arch_copy_from_user(void *dst, const void *src, size_t len) size_t arch_copy_from_user(void *dst, const void *src, size_t len)
{ {
@ -97,11 +101,22 @@ INT32 LOS_UserMemClear(unsigned char *buf, UINT32 len)
if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, len)) { if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, len)) {
(VOID)memset_s(buf, len, 0, len); (VOID)memset_s(buf, len, 0, len);
} else { } else {
if (_arm_clear_user(buf, len)) { unsigned char *tmp = (unsigned char *)LOS_MemAlloc(OS_SYS_MEM_ADDR, len);
return -EFAULT; if (tmp == NULL) {
return -ENOMEM;
} }
(VOID)memset_s(tmp, len, 0, len);
if (_arm_user_copy(buf, tmp, len) != 0) {
ret = -EFAULT;
}
LOS_MemFree(OS_SYS_MEM_ADDR, tmp);
} }
return ret; return ret;
} }
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

View File

@ -1,41 +0,0 @@
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 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.
import("//kernel/liteos_a/liteos.gni")
module_name = get_path_info(rebase_path("."), "name")
kernel_module(module_name) {
sources = []
if (defined(LOSCFG_ARCH_GIC_V2)) {
sources += [ "gic_v2.c" ]
} else if (defined(LOSCFG_ARCH_GIC_V3)) {
sources += [ "gic_v3.c" ]
}
}

0
arch/arm/include/in_cksum.h Normal file → Executable file
View File

Some files were not shown because too many files have changed in this diff Show More