Compare commits
35 Commits
weekly_202
...
OpenHarmon
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4ae10d163 | ||
|
|
7bb53531de | ||
|
|
740afd70b6 | ||
|
|
9fcf128322 | ||
|
|
d58d8042e6 | ||
|
|
b9292feaa8 | ||
|
|
800ca76df2 | ||
|
|
0846a8a1db | ||
|
|
a0b126246e | ||
|
|
a598b64da0 | ||
|
|
2a73894de0 | ||
|
|
923c05cd89 | ||
|
|
a55fd7c6d1 | ||
|
|
df4557ff41 | ||
|
|
73723d73ac | ||
|
|
6b8290e37c | ||
|
|
a4bea97b8b | ||
|
|
d89faf63a2 | ||
|
|
b035f5bf7c | ||
|
|
b0d7e9fc04 | ||
|
|
e21e3d5d1f | ||
|
|
124dd73f79 | ||
|
|
fef2e372ff | ||
|
|
d46d13e655 | ||
|
|
90d798ae8a | ||
|
|
1ee52d1e1f | ||
|
|
724e7fa786 | ||
|
|
078adec486 | ||
|
|
d0e0bb5934 | ||
|
|
9e8ae74620 | ||
|
|
0d5a1ce9be | ||
|
|
2a7b31018f | ||
|
|
54db6c8e7e | ||
|
|
ef186b476e | ||
|
|
72cb77e14f |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -14,8 +14,3 @@ targets/cortex-m7_nucleo_f767zi_gcc/build
|
||||
*.o
|
||||
*.d
|
||||
*.su
|
||||
|
||||
# Menuconfig temp files
|
||||
/config.h
|
||||
/.config
|
||||
/.config.old
|
||||
|
||||
324
BUILD.gn
324
BUILD.gn
@@ -27,298 +27,42 @@
|
||||
# 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")
|
||||
|
||||
LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
|
||||
|
||||
declare_args() {
|
||||
liteos_name = "OHOS_Image"
|
||||
liteos_config_file = "${ohos_build_type}.config"
|
||||
liteos_kernel_only = false
|
||||
}
|
||||
|
||||
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" +
|
||||
" BOARD_COMPANY=$device_company" +
|
||||
" 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")
|
||||
|
||||
liteos_arch_cflags = []
|
||||
if (defined(LOSCFG_ARCH_ARM)) {
|
||||
mcpu = LOSCFG_ARCH_CPU
|
||||
if (defined(LOSCFG_ARCH_ARM_AARCH64) && defined(LOSCFG_ARCH_FPU_DISABLE)) {
|
||||
mcpu += "+nofp"
|
||||
}
|
||||
liteos_arch_cflags += [ "-mcpu=$mcpu" ]
|
||||
if (defined(LOSCFG_ARCH_ARM_AARCH32) && defined(LOSCFG_ARCH_FPU)) {
|
||||
liteos_arch_cflags += [ "-mfpu=$LOSCFG_ARCH_FPU" ]
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
cflags += [ "-Wa,-mimplicit-it=thumb" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config("stdinc_config") {
|
||||
std_include = exec_script("//build/lite/run_shell_cmd.py",
|
||||
[ "$cc -print-file-name=include" ],
|
||||
"trim string")
|
||||
cflags = [
|
||||
"-isystem",
|
||||
std_include,
|
||||
]
|
||||
cflags += [ "-nostdinc" ]
|
||||
asmflags = cflags
|
||||
if (defined(LOSCFG_LIBC_NEWLIB)) {
|
||||
cflags -= [ "-nostdinc" ]
|
||||
}
|
||||
}
|
||||
|
||||
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",
|
||||
"-Wno-address-of-packed-member",
|
||||
]
|
||||
asmflags = cflags
|
||||
}
|
||||
|
||||
config("dialect_config") {
|
||||
cflags_c = [ "-std=c99" ]
|
||||
cflags_cc = [ "-std=c++11" ]
|
||||
}
|
||||
|
||||
config("misc_config") {
|
||||
defines = [ "__LITEOS__" ]
|
||||
defines += [ "__LITEOS_M__" ]
|
||||
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",
|
||||
]
|
||||
|
||||
if (!defined(LOSCFG_COMPILER_CLANG_LLVM)) {
|
||||
cflags += [ "-fno-aggressive-loop-optimizations" ]
|
||||
}
|
||||
|
||||
asmflags = cflags
|
||||
asmflags += [ "-DCLZ=CLZ" ]
|
||||
}
|
||||
|
||||
config("los_config") {
|
||||
configs = [
|
||||
#":arch_config",
|
||||
":kconfig_config",
|
||||
|
||||
":stdinc_config",
|
||||
":dialect_config",
|
||||
":optimize_config",
|
||||
":ssp_config",
|
||||
|
||||
#":warn_config",
|
||||
":misc_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")
|
||||
|
||||
# board and soc decoupling feature, device_path should contains board
|
||||
BOARD_SOC_FEATURE = device_path != string_replace(device_path, "/board/", "")
|
||||
|
||||
config("public") {
|
||||
configs = [
|
||||
"arch:public",
|
||||
"kernel:public",
|
||||
"kal:public",
|
||||
"components:public",
|
||||
"utils:public",
|
||||
]
|
||||
|
||||
if (BOARD_SOC_FEATURE) {
|
||||
configs += [ "//device/board/$device_company:public" ]
|
||||
configs += [ "//device/soc/$LOSCFG_SOC_COMPANY:public" ]
|
||||
} else {
|
||||
if (HAVE_DEVICE_SDK) {
|
||||
configs += [ "$device_path:public" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
group("modules") {
|
||||
deps = [
|
||||
"arch",
|
||||
"components",
|
||||
"kal",
|
||||
"kernel",
|
||||
"testsuites",
|
||||
"utils",
|
||||
HDFTOPDIR,
|
||||
]
|
||||
|
||||
if (BOARD_SOC_FEATURE) {
|
||||
deps += [ "//device/board/$device_company" ]
|
||||
deps += [ "//device/soc/$LOSCFG_SOC_COMPANY" ]
|
||||
} else {
|
||||
if (HAVE_DEVICE_SDK) {
|
||||
deps += [ device_path ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# when HAVE_DEVICE_SDK is not reached, gn raises an error. so we just use it as
|
||||
# not needed
|
||||
not_needed([ "HAVE_DEVICE_SDK" ])
|
||||
|
||||
static_library("libkernel") {
|
||||
deps = [ ":modules" ]
|
||||
complete_static_lib = false
|
||||
}
|
||||
import("config.gni")
|
||||
|
||||
group("kernel") {
|
||||
deps = [ ":libkernel" ]
|
||||
}
|
||||
|
||||
group("liteos_m") {
|
||||
}
|
||||
|
||||
executable("liteos") {
|
||||
configs += [
|
||||
":public",
|
||||
":los_config",
|
||||
deps = [
|
||||
"kernel:kernel",
|
||||
"utils:utils",
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
]
|
||||
|
||||
ldflags = [
|
||||
"-static",
|
||||
"-Wl,--gc-sections",
|
||||
"-Wl,-Map=$liteos_name.map",
|
||||
]
|
||||
|
||||
output_dir = target_out_dir
|
||||
|
||||
if (liteos_kernel_only) {
|
||||
deps = [ ":kernel" ]
|
||||
} else {
|
||||
deps = [ "//build/lite:ohos" ]
|
||||
if (enable_ohos_kernel_liteos_m_cppsupport == true) {
|
||||
deps += [ "components/cppsupport:cppsupport" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_cpup == true) {
|
||||
deps += [ "components/cpup:cpup" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_exchook == true) {
|
||||
deps += [ "components/exchook:exchook" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_backtrace == true) {
|
||||
deps += [ "components/backtrace:backtrace" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_fs == true) {
|
||||
deps += [ "components/fs:fs" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_pm == true) {
|
||||
deps += [ "components/power:pm" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_kal == true) {
|
||||
deps += [ "kal:kal" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_shell== true) {
|
||||
deps += [ "components/shell:shell" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_test == true) {
|
||||
deps += [ "testsuits:test" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_lwip == true) {
|
||||
deps += [ ohos_kernel_liteos_m_lwip_path ]
|
||||
}
|
||||
}
|
||||
|
||||
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'"
|
||||
}
|
||||
|
||||
655
Kconfig
655
Kconfig
@@ -1,655 +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.
|
||||
|
||||
mainmenu "Huawei LiteOS Configuration"
|
||||
|
||||
menu "Compiler"
|
||||
choice
|
||||
prompt "Compiler type"
|
||||
default COMPILER_GCC
|
||||
help
|
||||
Choose compiler type.
|
||||
|
||||
config COMPILER_GCC
|
||||
bool "GCC"
|
||||
|
||||
config CROSS_COMPILE
|
||||
string "GCC cross-compile toolchain prefix"
|
||||
depends on COMPILER_GCC
|
||||
default "arm-none-eabi-" if ARCH_ARM_AARCH32
|
||||
|
||||
config COMPILER_CLANG_LLVM
|
||||
bool "Clang"
|
||||
|
||||
config LLVM_TARGET
|
||||
string "Clang LLVM target"
|
||||
depends on COMPILER_CLANG_LLVM
|
||||
default "arm-liteos" if ARCH_ARM_AARCH32
|
||||
|
||||
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
|
||||
|
||||
menu "Platform"
|
||||
|
||||
######################### config options of bsp #####################
|
||||
config PLATFORM
|
||||
string
|
||||
default "virt" if PLATFORM_QEMU_ARM_VIRT_CM7 || PLATFORM_QEMU_ARM_VIRT_CM4 || PRODUCT_QEMU_RISCV32_VIRT || PLATFORM_QEMU_CSKY_SMARTL || PLATFORM_QEMU_XTENSA_ESP32
|
||||
|
||||
config PRODUCT_NAME
|
||||
string
|
||||
default "arm_virt" if PRODUCT_QEMU_ARM
|
||||
default "arm_mps2_an386" if PRODUCT_QEMU_ARM_MPS2_AN386
|
||||
default "riscv32_virt" if PRODUCT_QEMU_RISCV32_VIRT
|
||||
default "csky_smartl_e802" if PRODUCT_QEMU_CSKY_SMARTL_E802
|
||||
default "xtensa_esp32" if PRODUCT_QEMU_XTENSA_ESP32
|
||||
|
||||
config DEVICE_COMPANY
|
||||
string
|
||||
default "qemu" if PLATFORM_QEMU_ARM_VIRT_CM7 || PLATFORM_QEMU_ARM_VIRT_CM4 || PRODUCT_QEMU_RISCV32_VIRT || PLATFORM_QEMU_CSKY_SMARTL || PLATFORM_QEMU_XTENSA_ESP32
|
||||
|
||||
choice
|
||||
prompt "Chip"
|
||||
default PLATFORM_QEMU_ARM_VIRT_CM7
|
||||
help
|
||||
Qemu ARM Virt variants (based on different CPU types):
|
||||
- qemu_arm_virt_cm7
|
||||
- qemu_arm_virt_cm4
|
||||
- qemu_riscv32_virt
|
||||
- qemu_csky_smartl
|
||||
- qemu_xtensa_esp32
|
||||
|
||||
config PLATFORM_QEMU_ARM_VIRT_CM7
|
||||
bool "qemu_arm_virt_cm7"
|
||||
select ARCH_CORTEX_M7
|
||||
help
|
||||
QEMU ARM Virtual Platform using Cortex-M7 CPU.
|
||||
|
||||
config PLATFORM_QEMU_ARM_VIRT_CM4
|
||||
bool "qemu_arm_virt_cm4"
|
||||
select ARCH_CORTEX_M4
|
||||
help
|
||||
QEMU ARM Virtual Platform using Cortex-M4 CPU.
|
||||
|
||||
config PLATFORM_QEMU_RISCV32_VIRT
|
||||
bool "qemu_riscv32_virt"
|
||||
select ARCH_RISCV32
|
||||
help
|
||||
QEMU RISCV Virtual Platform using riscv32 CPU.
|
||||
|
||||
config PLATFORM_QEMU_CSKY_SMARTL
|
||||
bool "qemu_csky_smartl"
|
||||
select ARCH_CSKY
|
||||
help
|
||||
QEMU SmartL Virtual Platform using csky CPU.
|
||||
|
||||
config PLATFORM_QEMU_XTENSA_ESP32
|
||||
bool "qemu_xtensa_esp32"
|
||||
select ARCH_XTENSA
|
||||
help
|
||||
QEMU ESP32 Virtual Platform using xtensa CPU.
|
||||
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Product"
|
||||
help
|
||||
Select your target board.
|
||||
|
||||
config PRODUCT_QEMU_ARM
|
||||
bool "arm_virt" if PLATFORM_QEMU_ARM_VIRT_CM7
|
||||
|
||||
config PRODUCT_QEMU_ARM_MPS2_AN386
|
||||
bool "arm_mps2_an386" if PLATFORM_QEMU_ARM_VIRT_CM4
|
||||
|
||||
config PRODUCT_QEMU_RISCV32_VIRT
|
||||
bool "riscv32_virt" if PLATFORM_QEMU_RISCV32_VIRT
|
||||
|
||||
config PRODUCT_QEMU_CSKY_SMARTL_E802
|
||||
bool "csky_smartl_e802" if PLATFORM_QEMU_CSKY_SMARTL
|
||||
|
||||
config PRODUCT_QEMU_XTENSA_ESP32
|
||||
bool "xtensa_esp32" if PLATFORM_QEMU_XTENSA_ESP32
|
||||
|
||||
endchoice
|
||||
|
||||
|
||||
######################### config options of cpu arch ################
|
||||
source "arch/Kconfig"
|
||||
|
||||
# Device Kconfig import
|
||||
osource "$(DEVICE_PATH)/Kconfig"
|
||||
|
||||
config SOC_COMPANY
|
||||
string "SoC company name to locate soc build path"
|
||||
help
|
||||
This option specifies the SoC company name, used to locate the build path for soc. This option is set by the
|
||||
SoC's Kconfig file, and should be exactly the same with SoC company path, and the user should generally avoid
|
||||
modifying it via the menu configuration.
|
||||
|
||||
orsource "../../device/board/*/Kconfig.liteos_m.shields"
|
||||
|
||||
orsource "../../device/board/$(BOARD_COMPANY)/Kconfig.liteos_m.defconfig.boards"
|
||||
|
||||
choice
|
||||
prompt "Board Selection"
|
||||
|
||||
orsource "../../device/board/$(BOARD_COMPANY)/Kconfig.liteos_m.boards"
|
||||
|
||||
endchoice
|
||||
|
||||
orsource "../../device/soc/*/Kconfig.liteos_m.defconfig"
|
||||
|
||||
choice
|
||||
prompt "SoC Series Selection"
|
||||
|
||||
orsource "../../device/soc/*/Kconfig.liteos_m.series"
|
||||
|
||||
endchoice
|
||||
|
||||
orsource "../../device/soc/*/Kconfig.liteos_m.soc"
|
||||
|
||||
config QUICK_START
|
||||
bool "Enable QUICK_START"
|
||||
default n
|
||||
depends on DRIVERS && FS_VFS
|
||||
help
|
||||
Answer Y to enable LiteOS support quick start.
|
||||
endmenu
|
||||
|
||||
######################### config options of kernel #####################
|
||||
menu "Kernel"
|
||||
|
||||
######################### config options of extended #####################
|
||||
|
||||
config KERNEL_EXTKERNEL
|
||||
bool "Enable Extend Kernel"
|
||||
default y
|
||||
help
|
||||
This option will enable extend Kernel of LiteOS. Extend kernel include
|
||||
cppsupport, cpup, etc. You can select one or some
|
||||
of them.
|
||||
|
||||
config KERNEL_BACKTRACE
|
||||
bool "Enable Backtrace"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
help
|
||||
If you wish to build LiteOS with support for backtrace.
|
||||
|
||||
choice
|
||||
prompt "Select Backtrace Type"
|
||||
depends on KERNEL_BACKTRACE
|
||||
|
||||
config BACKTRACE_TYPE_1
|
||||
bool "1: Call stack analysis for cortex-m series by scanning the stack"
|
||||
depends on ARCH_ARM && !ARCH_ARM9
|
||||
|
||||
config BACKTRACE_TYPE_2
|
||||
bool "2: Call stack analysis for risc-v by using frame pointer"
|
||||
depends on ARCH_RISCV
|
||||
|
||||
config BACKTRACE_TYPE_3
|
||||
bool "3: Call stack analysis for risc-v by scanning the stack"
|
||||
depends on ARCH_RISCV
|
||||
|
||||
config BACKTRACE_TYPE_4
|
||||
bool "4: Call stack analysis for xtensa by scanning the stack"
|
||||
depends on ARCH_XTENSA
|
||||
|
||||
config BACKTRACE_TYPE_5
|
||||
bool "5: Call stack analysis for c-sky by scanning the stack"
|
||||
depends on ARCH_CSKY
|
||||
|
||||
config BACKTRACE_TYPE_6
|
||||
bool "6: Call stack analysis for arm9 by scanning the stack"
|
||||
depends on ARCH_ARM9
|
||||
|
||||
endchoice
|
||||
|
||||
config BACKTRACE_TYPE
|
||||
int
|
||||
default 0 if ! KERNEL_BACKTRACE
|
||||
default 1 if BACKTRACE_TYPE_1
|
||||
default 2 if BACKTRACE_TYPE_2
|
||||
default 3 if BACKTRACE_TYPE_3
|
||||
default 4 if BACKTRACE_TYPE_4
|
||||
default 5 if BACKTRACE_TYPE_5
|
||||
default 6 if BACKTRACE_TYPE_6
|
||||
|
||||
config BACKTRACE_DEPTH
|
||||
int "Backtrace depth"
|
||||
default 15
|
||||
depends on KERNEL_BACKTRACE
|
||||
|
||||
config KERNEL_CPPSUPPORT
|
||||
bool "Enable C++ Support"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
help
|
||||
If you wish to build LiteOS with support for C++.
|
||||
|
||||
config BASE_CORE_CPUP
|
||||
bool
|
||||
default n
|
||||
|
||||
config KERNEL_CPUP
|
||||
bool "Enable Cpup"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
select BASE_CORE_CPUP
|
||||
help
|
||||
If you wish to build LiteOS with support for cpup.
|
||||
|
||||
config CPUP_INCLUDE_IRQ
|
||||
bool "Enable Cpup include irq"
|
||||
default y
|
||||
depends on KERNEL_CPUP
|
||||
help
|
||||
If you wish to include irq usage for cpup.
|
||||
|
||||
config DYNLINK
|
||||
bool "Enable Dynamic Link Feature"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL && ARCH_ARM
|
||||
help
|
||||
If you wish to build LiteOS with support for dynamic link.
|
||||
|
||||
config KERNEL_PM
|
||||
bool "Enable Power Management"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
help
|
||||
Configuration item for low power frame tailoring.
|
||||
If you wish to build LiteOS with support for power management.
|
||||
|
||||
config KERNEL_PM_TASK_PTIORITY
|
||||
int "Power Management Task Priority"
|
||||
default 1
|
||||
range 1 31
|
||||
depends on KERNEL_PM
|
||||
help
|
||||
Configuration item for priority of low-power task.
|
||||
|
||||
config KERNEL_PM_TASK_STACKSIZE
|
||||
int "Power Management Task Stack Size"
|
||||
default 1024
|
||||
depends on KERNEL_PM
|
||||
help
|
||||
Configuration item for stack size of low-power task.
|
||||
|
||||
config KERNEL_PM_DEBUG
|
||||
bool "Power Management Debug"
|
||||
default n
|
||||
depends on KERNEL_PM
|
||||
help
|
||||
Configuration item for low power frame debug tailoring.
|
||||
|
||||
config DEBUG_HOOK
|
||||
bool
|
||||
default n
|
||||
|
||||
config PLATFORM_EXC
|
||||
bool "Enable Hook Feature"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
select DEBUG_HOOK
|
||||
|
||||
config KERNEL_LMK
|
||||
bool "Enable Low Memory Killer"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL
|
||||
help
|
||||
Configuration item for low momery killer tailoring.
|
||||
If you wish to build LiteOS with support for low memory killer.
|
||||
|
||||
config KERNEL_LMK_DEBUG
|
||||
bool "Low Memory Killer Debug"
|
||||
default n
|
||||
depends on KERNEL_LMK
|
||||
help
|
||||
Configuration item forlow memory killer debug tailoring.
|
||||
|
||||
######################### config options of trace #########################
|
||||
source "components/trace/Kconfig"
|
||||
|
||||
######################### config options of lms #########################
|
||||
source "components/lms/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
######################### config options of lib ########################
|
||||
menu "Lib"
|
||||
config LIB_LIBC
|
||||
bool "Enable Libc"
|
||||
default y
|
||||
help
|
||||
Answer Y to enable libc for full code.
|
||||
|
||||
endmenu
|
||||
|
||||
|
||||
######################### config options of compatibility ##############
|
||||
menu "Compat"
|
||||
|
||||
rsource "kal/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
######################## config options of filesystem ##################
|
||||
menu "FileSystem"
|
||||
|
||||
rsource "components/fs/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
######################## config options of net ############################
|
||||
menu "Net"
|
||||
config NET_LWIP
|
||||
bool "Enable Lwip"
|
||||
default n
|
||||
select NET_LWIP_SACK
|
||||
|
||||
help
|
||||
Answer Y to enable LiteOS support lwip.
|
||||
|
||||
config NET_LWIP_SACK
|
||||
bool
|
||||
default n
|
||||
|
||||
endmenu
|
||||
|
||||
######################## config options of debug ########################
|
||||
menu "Debug"
|
||||
config GDB
|
||||
bool "Enable gdb functions"
|
||||
default n
|
||||
help
|
||||
Answer Y to enable gdb functions.
|
||||
|
||||
config PLATFORM_ADAPT
|
||||
bool "Enable Os_adapt"
|
||||
default y
|
||||
help
|
||||
Answer Y to add os_adapt.c to LiteOS.
|
||||
|
||||
config ENABLE_OOM_LOOP_TASK
|
||||
bool "Enable Oom loop task"
|
||||
default n
|
||||
depends on KERNEL_VM
|
||||
help
|
||||
Answer Y to enable oom loop kthread to check system out of memory.
|
||||
|
||||
config DO_ALIGN
|
||||
bool "Enable do align for hi3518e"
|
||||
default y
|
||||
depends on PLATFORM_HI3518EV200
|
||||
help
|
||||
Answer Y to enable do align for hi3518e.
|
||||
|
||||
|
||||
config ENABLE_MAGICKEY
|
||||
bool "Enable MAGIC KEY"
|
||||
default y
|
||||
help
|
||||
Answer Y to enable LiteOS Magic key.
|
||||
ctrl + r : Magic key check switch;
|
||||
ctrl + z : Show all magic op key;
|
||||
ctrl + t : Show task information;
|
||||
ctrl + p : System panic;
|
||||
ctrl + e : Check system memory pool.
|
||||
|
||||
config THUMB
|
||||
bool "Enable Thumb"
|
||||
default n
|
||||
depends on ARCH_ARM
|
||||
help
|
||||
Answer Y to build thumb version. This will make LiteOS smaller.
|
||||
|
||||
config PLATFORM_DVFS
|
||||
bool "Enable Dvfs"
|
||||
default n
|
||||
depends on COMPAT_LINUXKPI
|
||||
help
|
||||
Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for
|
||||
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
|
||||
bool "Enable a Debug Version"
|
||||
default y
|
||||
help
|
||||
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
|
||||
memory check, etc.
|
||||
If you select this option that means you enable a debug version for LiteOS.
|
||||
That means you want a opposite behaviour compared to release version.
|
||||
|
||||
config DEBUG_KERNEL
|
||||
bool "Enable Debug LiteOS Kernel Resource"
|
||||
default n
|
||||
depends on DEBUG_VERSION
|
||||
help
|
||||
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.
|
||||
That means you want a opposite behaviour compared to release version.
|
||||
|
||||
config DEBUG_QUEUE
|
||||
bool "Enable Queue Debugging"
|
||||
default n
|
||||
depends on DEBUG_KERNEL
|
||||
help
|
||||
Answer Y to enable debug queue.
|
||||
|
||||
config DEBUG_DEADLOCK
|
||||
bool "Enable Mutex Deadlock Debugging"
|
||||
default n
|
||||
depends on DEBUG_KERNEL
|
||||
help
|
||||
Answer Y to enable debug mutex deadlock.
|
||||
|
||||
config DEBUG_SEMAPHORE
|
||||
bool "Enable Semaphore Debugging"
|
||||
default n
|
||||
depends on DEBUG_KERNEL
|
||||
help
|
||||
Answer Y to enable debug semaphore.
|
||||
|
||||
source "components/shell/Kconfig"
|
||||
config NET_LWIP_SACK_TFTP
|
||||
bool "Enable Tftp"
|
||||
default y
|
||||
depends on SHELL && NET_LWIP_SACK && DEBUG_VERSION
|
||||
help
|
||||
Answer Y to enable LiteOS support tftp cmd and tftp tool.
|
||||
osource "net/telnet/Kconfig"
|
||||
config SCHED_DEBUG
|
||||
bool "Enable sched debug Feature"
|
||||
default n
|
||||
depends on DEBUG_VERSION
|
||||
help
|
||||
If you wish to build LiteOS with support for sched debug.
|
||||
|
||||
config USER_INIT_DEBUG
|
||||
bool "Enable user init Debug"
|
||||
default n
|
||||
depends on DEBUG_VERSION
|
||||
|
||||
config SHELL_CMD_DEBUG
|
||||
bool "Enable shell cmd Debug"
|
||||
default n
|
||||
depends on DEBUG_VERSION && SHELL
|
||||
|
||||
config USB_DEBUG
|
||||
bool "Enable USB Debug"
|
||||
default n
|
||||
depends on SHELL && DRIVERS_USB && DEBUG_VERSION
|
||||
help
|
||||
Answer Y to enable LiteOS support usb debug.
|
||||
use shell command to open the specified debug level print.
|
||||
config MEM_DEBUG
|
||||
bool "Enable MEM Debug"
|
||||
default n
|
||||
depends on DEBUG_VERSION
|
||||
help
|
||||
Answer Y to enable LiteOS support mem debug.
|
||||
|
||||
config MEM_LEAKCHECK
|
||||
bool "Enable Function call stack of Mem operation recorded"
|
||||
default n
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
select KERNEL_BACKTRACE
|
||||
help
|
||||
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
|
||||
bool "Enable integrity check or not"
|
||||
default n
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
config MEM_WATERLINE
|
||||
bool "Enable memory pool waterline or not"
|
||||
default n
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
|
||||
config VM_OVERLAP_CHECK
|
||||
bool "Enable VM overlap check or not"
|
||||
default n
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
help
|
||||
Answer Y to enable vm overlap check.
|
||||
|
||||
endmenu
|
||||
|
||||
######################## config options os drivers ########################
|
||||
menu "Driver"
|
||||
source "drivers/Kconfig"
|
||||
endmenu
|
||||
|
||||
######################## config options os security #######################
|
||||
menu "Security"
|
||||
osource "security/Kconfig"
|
||||
config SECURE_TRUSTZONE
|
||||
bool "Enable ARM TrustZone"
|
||||
default n
|
||||
depends on ARCH_ARM
|
||||
config SECURE_HEAP_SIZE
|
||||
int "TrustZone Heap Size (bytes)"
|
||||
default 2048
|
||||
depends on SECURE_TRUSTZONE
|
||||
config SECURE_STACK_DEFAULT_SIZE
|
||||
int "TrustZone Stack Size (bytes)"
|
||||
default 512
|
||||
depends on SECURE_TRUSTZONE
|
||||
help
|
||||
The secure stack must be allocated before the task calls non-secure functions.
|
||||
endmenu
|
||||
|
||||
menu "Test"
|
||||
config TEST
|
||||
bool
|
||||
default n
|
||||
config KERNEL_TEST
|
||||
bool "Enable Kernel Test"
|
||||
default n
|
||||
select TEST
|
||||
config KERNEL_TEST_FULL
|
||||
bool "Full Kernel Test"
|
||||
default n
|
||||
depends on KERNEL_TEST
|
||||
endmenu
|
||||
|
||||
menu "Stack Smashing Protector (SSP) Compiler Feature"
|
||||
|
||||
choice
|
||||
prompt "Enable stack buffer overflow detection"
|
||||
default CC_STACKPROTECTOR_STRONG
|
||||
---help---
|
||||
This option turns on the -fstack-protector GCC feature. This
|
||||
feature puts, at the beginning of functions, a canary value on
|
||||
the stack just before the return address, and validates
|
||||
the value just before actually returning. Stack based buffer
|
||||
overflows (that need to overwrite this return address) now also
|
||||
overwrite the canary, which gets detected and the attack is then
|
||||
neutralized via a kernel panic.
|
||||
|
||||
This feature requires gcc version 4.2 or above, or a distribution
|
||||
gcc with the feature backported. Older versions are automatically
|
||||
detected and for those versions, this configuration option is
|
||||
ignored. (and a warning is printed during bootup)
|
||||
|
||||
config CC_NO_STACKPROTECTOR
|
||||
bool "-fno-stack-protector"
|
||||
|
||||
config CC_STACKPROTECTOR
|
||||
bool "-fstack-protector"
|
||||
|
||||
config CC_STACKPROTECTOR_STRONG
|
||||
bool "-fstack-protector-strong"
|
||||
|
||||
config CC_STACKPROTECTOR_ALL
|
||||
bool "-fstack-protector-all"
|
||||
|
||||
endchoice
|
||||
|
||||
endmenu
|
||||
122
Makefile
122
Makefile
@@ -1,122 +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.
|
||||
|
||||
LITEOSTOPDIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
|
||||
export LITEOSTOPDIR
|
||||
|
||||
LITEOS_TARGET = liteos
|
||||
HIDE := @
|
||||
KCONFIG_CMDS := $(notdir $(wildcard $(dir $(shell which menuconfig))*config))
|
||||
|
||||
ohos_kernel ?= liteos_m
|
||||
$(foreach line,$(shell hb env | sed 's/\[OHOS INFO\]/ohos/g;s/ /_/g;s/:_/=/g' || true),$(eval $(line)))
|
||||
ifneq ($(ohos_kernel),liteos_m)
|
||||
$(error The selected product ($(ohos_product)) is not a liteos_m kernel type product)
|
||||
endif
|
||||
|
||||
ifeq ($(PRODUCT_PATH),)
|
||||
PRODUCT_PATH:=$(ohos_product_path)
|
||||
endif
|
||||
|
||||
ifeq ($(DEVICE_PATH),)
|
||||
DEVICE_PATH:=$(ohos_device_path)
|
||||
endif
|
||||
|
||||
ifeq ($(BOARD_COMPANY),)
|
||||
BOARD_COMPANY:=$(ohos_device_company)
|
||||
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)
|
||||
LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h
|
||||
LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config
|
||||
|
||||
# export los_config.mk related environment variables
|
||||
export LITEOS_MENUCONFIG_H
|
||||
export LITEOS_CONFIG_FILE
|
||||
export BOARD_COMPANY
|
||||
export DEVICE_PATH
|
||||
export PRODUCT_PATH
|
||||
|
||||
# export kconfig related environment variables
|
||||
export CONFIG_=LOSCFG_
|
||||
export srctree=$(LITEOSTOPDIR)
|
||||
|
||||
-include $(LITEOS_CONFIG_FILE)
|
||||
|
||||
define HELP =
|
||||
Usage: make [TARGET]... [PARAMETER=VALUE]...
|
||||
|
||||
Targets:
|
||||
help: display this help and exit
|
||||
clean: clean compiled objects
|
||||
cleanall: clean all build outputs
|
||||
all: do build (Default target)
|
||||
update_config: update product kernel config (use menuconfig)
|
||||
xxconfig: invoke xxconfig command of kconfiglib (xxconfig is one of $(KCONFIG_CMDS))
|
||||
|
||||
Parameters:
|
||||
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:
|
||||
$(HIDE)hb build -f --gn-args "liteos_kernel_only=true liteos_name=\"$(LITEOS_TARGET)\""
|
||||
|
||||
help:
|
||||
$(HIDE)echo "$$HELP"
|
||||
|
||||
$(filter-out menuconfig,$(KCONFIG_CMDS)):
|
||||
$(HIDE)$@ $(args)
|
||||
|
||||
$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG)
|
||||
$(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H)
|
||||
|
||||
update_config menuconfig:
|
||||
$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)"
|
||||
|
||||
clean:
|
||||
$(HIDE)hb clean
|
||||
$(HIDE)echo "clean $(LOSCFG_PLATFORM) finish"
|
||||
|
||||
cleanall: clean
|
||||
$(HIDE)echo "clean all done"
|
||||
|
||||
.PHONY: all clean cleanall help update_config $(KCONFIG_CMDS) $(KCONFIG_CONFIG)
|
||||
4
OAT.xml
4
OAT.xml
@@ -29,11 +29,11 @@
|
||||
</policylist>
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="文件属于FreeBSD仓库软连接,本仓库屏蔽告警,在FreeBSD仓库进行处理">
|
||||
<filteritem type="filepath" name="arch/risc-v/nuclei/gcc/nmsis/Library/.*" desc="文件属于三方芯片的二进制代码,属于社区贡献,不用提供额外的说明"/>
|
||||
<filteritem type="filepath" name="kernel/arch/risc-v/nuclei/gcc/nmsis/Library/.*" desc="文件属于三方芯片的二进制代码,属于社区贡献,不用提供额外的说明"/>
|
||||
<filteritem type="filepath" name="targets/riscv_nuclei_demo_soc_gcc/.*" desc="文件属于nuclei三方芯片的源代码,文件头说明跟随liteos_m/LICENSE,不用额外说明"/>
|
||||
<filteritem type="filepath" name="targets/riscv_nuclei_gd32vf103_soc_gcc/.*" desc="文件属于nuclei三方芯片的源代码,文件头说明跟随liteos_m/LICENSE,不用额外说明"/>
|
||||
<filteritem type="filepath" name="NOTICE" desc="NOTICE文件"/>
|
||||
<filteritem type="filepath" name="arch/risc-v/nuclei" desc="该文件的license为apache 2.0符合"/>
|
||||
<filteritem type="filepath" name="kernel/arch/risc-v/nuclei" desc="该文件的license为apache 2.0符合"/>
|
||||
</filefilter>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
|
||||
|
||||
112
README.md
112
README.md
@@ -1,4 +1,4 @@
|
||||
# LiteOS-M Kernel<a name="EN-US_TOPIC_0000001096757661"></a>
|
||||
# LiteOS Cortex-M<a name="EN-US_TOPIC_0000001096757661"></a>
|
||||
|
||||
- [Introduction](#section11660541593)
|
||||
- [Directory Structure](#section161941989596)
|
||||
@@ -8,125 +8,69 @@
|
||||
|
||||
## Introduction<a name="section11660541593"></a>
|
||||
|
||||
OpenHarmony LiteOS-M is a lightweight operating system kernel designed for the Internet of Things (IoT) field. It features small footprint, low power consumption, and high performance. It has a simple code structure, including the minimum kernel function set, kernel abstraction layer, optional components, and project directory. The LiteOS-M kernel is divided into the hardware layer and hardware-irrelevant layers. The hardware layer provides a unified hardware abstraction layer (HAL) interface for easier hardware adaptation. A range of compilation toolchains can be used with different chip architectures to meet the expansion of diversified hardware and compilation toolchains in the Artificial Intelligence of Things (AIoT) field.
|
||||
**Figure1** shows the architecture of the LiteOS-M kernel.
|
||||
The OpenHarmony LiteOS Cortex-M is the kernel designed for the lightweight operating system \(OS\) for the Internet of Things \(IoT\) field. It features small size, low power consumption, and high performance. In addition, it has a simple code structure, including the minimum kernel function set, kernel abstraction layer, optional components, and project directory, and is divided into the hardware-related and hardware-irrelevant layers. The hardware-related layers provide unified hardware abstraction layer \(HAL\) interfaces to improve hardware adaptability. The combination and classification of different compilation toolchains and chip architectures meet the requirements of the Artificial Intelligence of Things \(AIoT\) field for rich hardware and compilation toolchains. [Figure1](#fig0865152210223) shows the architecture of the OpenHarmony LiteOS Cortex-M kernel.
|
||||
|
||||
**Figure 1** Architecture of the OpenHarmony LiteOS-M kernel<a name="fig0865152210223"></a>
|
||||
|
||||

|
||||
**Figure 1** Architecture of OpenHarmony the LiteOS Cortex-M kernel<a name="fig0865152210223"></a>
|
||||

|
||||
|
||||
## Directory Structure<a name="section161941989596"></a>
|
||||
|
||||
The directory structure is as follows. For more details, see [arch_spec.md](arch_spec.md).
|
||||
The directory structure is listed as below, for the detailed directories, please refer to [arch_spec.md](arch_spec.md).
|
||||
|
||||
```
|
||||
/kernel/liteos_m
|
||||
├── components # Optional components
|
||||
│ ├── backtrace # Backtrace support
|
||||
│ ├── cppsupport # C++ support
|
||||
│ └── cpup # CPU percent (CPUP)
|
||||
│ ├── dynlink # Dynamic loading and linking
|
||||
│ ├── exchook # Exception hooks
|
||||
│ ├── fs # File systems
|
||||
│ └── net # Networking functions
|
||||
│ ├── cpup # CPU possession (CPUP)
|
||||
│ ├── exchook # Exception hook
|
||||
│ ├── fs # File system
|
||||
│ └── net # Network support
|
||||
├── kal # Kernel abstraction layer
|
||||
│ ├── cmsis # CMSIS API support
|
||||
│ ├── cmsis # CMSIS-compliant API support
|
||||
│ └── posix # POSIX API support
|
||||
├── kernel # Minimum kernel function set
|
||||
├── kernel # Minimum function set support
|
||||
│ ├── arch # Code of the kernel instruction architecture layer
|
||||
│ │ ├── arm # Code of the Arm32 architecture
|
||||
│ │ ├── arm # Code of the ARM32 architecture
|
||||
│ │ └── include # APIs exposed externally
|
||||
│ ├── include # APIs exposed externally
|
||||
│ └── src # Source code of the minimum kernel function set
|
||||
│ └── src # Source code of the minimum function set of the kernel
|
||||
├── targets # Board-level projects
|
||||
├── utils # Common directory
|
||||
├── utils # Common code
|
||||
```
|
||||
|
||||
## Constraints<a name="section119744591305"></a>
|
||||
|
||||
OpenHarmony LiteOS-M supports only C and C++.
|
||||
Programming languages: C and C++
|
||||
|
||||
It applies only to Cortex-M3, Cortex-M4, Cortex-M7, and RISC-V chip architectures.
|
||||
|
||||
As for dynamic loading module, the shared library to be loaded needs signature verification or source restriction to ensure security.
|
||||
Currently applicable architectures: Cortex-M3, Cortex-M4, Cortex-M7, and RISC-V
|
||||
|
||||
## Usage<a name="section3732185231214"></a>
|
||||
|
||||
The OpenHarmony LiteOS-M kernel build system is a modular build system based on Generate Ninja (GN) and Ninja. It supports module-based configuration, tailoring, and assembling, and helps you build custom products. This document describes how to build a LiteOS-M project based on GN and Ninja. For details about the methods such as GCC+Makefile, IAR, and Keil MDK, visit the community websites.
|
||||
|
||||
### Setting Up the Environment
|
||||
|
||||
Before setting up the environment for a development board, you must set up the basic system environment for OpenHarmony first. The basic system environment includes the OpenHarmony build environment and development environment. For details, see [Setting Up Ubuntu Development Environment](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/quick-start/quickstart-lite-env-setup-linux.md). You need to install Python3.7+, GN, Ninja, and hb. For the LiteOS-M kernel, you also need to install the Make build tool and [GNU Arm Embedded Toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads).
|
||||
|
||||
### Obtaining the OpenHarmony Source Code
|
||||
|
||||
Obtain the latest OpenHarmony source code through Git clone on a Linux server. For details about how to obtain the source code, see [Source Code Acquisition](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/get-code/sourcecode-acquire.md). This document assumes that the clone directory is `~/openHarmony` after the complete OpenHarmony repository code is obtained.
|
||||
|
||||
### Obtaining the Source Code of the Sample Project
|
||||
|
||||
The following uses the development board Nucleo-F767Zi as an example to describe how to build and run the `OpenHarmony LiteOS-M` kernel project. In the local directory, run the following command to clone the sample code:
|
||||
|
||||
```
|
||||
git clone https://gitee.com/harylee/nucleo_f767zi.git
|
||||
```
|
||||
|
||||
The code is cloned to **~/nucleo_f767zi**. Run the following commands to copy the **device** and **vendor** directories in the code directory to the corresponding directories of the **openHarmony** project:
|
||||
|
||||
```
|
||||
mkdir ~/openHarmony/device/st
|
||||
|
||||
cp -r ~/nucleo_f767zi/device/st/nucleo_f767zi ~/openHarmony/device/st/nucleo_f767zi
|
||||
|
||||
chmod +x ~/openHarmony/device/st/nucleo_f767zi/build.sh
|
||||
|
||||
cp -r ~/nucleo_f767zi/vendor/st ~/openHarmony/vendor/st
|
||||
```
|
||||
|
||||
For details about the directory of the sample code, see [Board-Level Directory Specifications](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/porting/porting-chip-board-overview.md). If you need to port the development board, see [Board-Level OS Porting](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/porting/porting-chip-board.md).
|
||||
|
||||
### Building and Running
|
||||
|
||||
Before the build, configure the **bin** directory of the cross compilation toolchain in the **PATH** environment variable or set **board_toolchain_path** in the **device/st/nucleo_f767zi/liteos_m/config.gni** file to the **bin** directory of the cross compilation toolchain.
|
||||
In the **OpenHarmony** root directory, run the **hb set** command to set the product path, select **nucleo_f767zi**, and run the **hb build** command to start the build.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
user@dev:~/OpenHarmony$ hb set
|
||||
|
||||
[OHOS INFO] Input code path: # Press Enter and select nucleo_f767zi.
|
||||
|
||||
OHOS Which product do you need? nucleo_f767zi@st
|
||||
|
||||
user@dev:~/OpenHarmony$ hb build
|
||||
```
|
||||
|
||||
The image is generated in the **~/openHarmony/out/nucleo_f767zi/** directory. You can download the image file to the board by using the STM32 ST-LINK Utility software and run the image.
|
||||
|
||||
### Community Porting Project Links
|
||||
|
||||
The LiteOS-M kernel porting projects for specific development boards are provided by community developers. The following provides the links to these projects. If you have porting projects for more development boards, you can provide your links to share your projects.
|
||||
LiteOS Cortex-M provides projects for three chip architectures, which are located in the **targets** directory. The methods of compiling and using these projects are as follows:
|
||||
|
||||
- Cortex-M3:
|
||||
|
||||
- STM32F103 https://gitee.com/rtos_lover/stm32f103_simulator_keil
|
||||
|
||||
This repository provides the Keil project code for building the OpenHarmony LiteOS-M kernel based on the STM32F103 chip architecture. This code supports build in Keil MDK mode.
|
||||
The **kernel/liteos\_m/targets/cortex-m3\_stm32f103\_simulator\_keil** directory is the Keil project directory created based on the STM32F103 chip architecture. You can download and install Keil development tools from the Internet. To compile the Cortex-M3 project, go to the **cortex-m3\_stm32f103\_simulator\_keil/project** directory and double-click the **los\_demo.uvproj** file to open the desired project. After the compilation is successful, burn the file to the corresponding board using JLINK or STM32 ST-LINK Utility.
|
||||
|
||||
- Cortex-M4:
|
||||
|
||||
- STM32F429IGTb https://gitee.com/harylee/stm32f429ig_firechallenger
|
||||
|
||||
This repository provides the project code for porting the OpenHarmony LiteOS-M kernel to support the STM32F429IGTb development board. The code supports build in Ninja, GCC, and IAR modes.
|
||||
The **kernel/liteos\_m/targets/cortex-m4\_stm32f429ig\_fire-challenger\_iar** directory is the IAR project directory created based on the STM32F429IG chip architecture. You can download and install IAR development tools from the Internet. To compile the Cortex-M4 project, go to the **cortex-m4\_stm32f429ig\_fire-challenger\_iar/project** directory and double-click the **los\_demo.eww** file to open the desired project. After the compilation is successful, burn the file to the corresponding board using JLINK or STM32 ST-LINK Utility.
|
||||
|
||||
- Cortex-M7:
|
||||
|
||||
- Nucleo-F767ZI https://gitee.com/harylee/nucleo_f767zi
|
||||
The **kernel/liteos\_m/targets/cortex-m7\_nucleo\_f767zi\_gcc** directory is the Makefile project directory created based on the STM32F767ZI chip architecture. The compilation commands are as follows:
|
||||
|
||||
This repository provides the project code for porting the OpenHarmony LiteOS-M kernel to support the Nucleo-F767ZI development board. The code supports build in Ninja, GCC, and IAR modes.
|
||||
```
|
||||
cd kernel/liteos_m/targets/cortex-m7_nucleo_f767zi_gcc
|
||||
make clean; make
|
||||
```
|
||||
|
||||
After the compilation is successful, the executable file **NUCLEO-F767.hex** is generated in the **cortex-m7\_nucleo\_f767zi\_gcc/build** directory. Burn the file to the corresponding board using STM32 ST-LINK Utility.
|
||||
|
||||
## Repositories Involved<a name="section1371113476307"></a>
|
||||
|
||||
[Kernel Subsystem](https://gitee.com/openharmony/docs/blob/HEAD/en/readme/kernel-subsystem.md)
|
||||
[Kernel subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/kernel.md)
|
||||
|
||||
**kernel\_liteos\_m**
|
||||
|
||||
|
||||
13
README_zh.md
13
README_zh.md
@@ -23,7 +23,6 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系
|
||||
│ ├── backtrace # 回溯栈支持
|
||||
│ ├── cppsupport # C++支持
|
||||
│ ├── cpup # CPUP功能
|
||||
│ ├── dynlink # 动态加载与链接
|
||||
│ ├── exchook # 异常钩子
|
||||
│ ├── fs # 文件系统
|
||||
│ └── net # Network功能
|
||||
@@ -46,19 +45,17 @@ OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系
|
||||
|
||||
适用架构:当前只适用于cortex-m3、cortex-m4、cortex-m7、risc-v芯片架构。
|
||||
|
||||
动态加载模块:待加载的共享库需要验签或者限制来源,确保安全性。
|
||||
|
||||
## 使用说明<a name="section3732185231214"></a>
|
||||
|
||||
OpenHarmony LiteOS-M内核的编译构建系统是一个基于gn和ninja的组件化构建系统,支持按组件配置、裁剪和拼装,按需构建出定制化的产品。本文主要介绍如何基于gn和ninja编译LiteOS-M工程,GCC+Makefile、IAR、Keil MDK等编译方式可以参考社区爱好者贡献的站点。
|
||||
OpenHarmony LiteOS-M内核的编译构建系统是一个基于gn和ninja的组件化构建系统,支持按组件配置、裁剪和拼装,按需构建出定制化的产品。编译构建系统的详细信息可以参考[轻量和小型系统编译构建指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/%E8%BD%BB%E9%87%8F%E5%92%8C%E5%B0%8F%E5%9E%8B%E7%B3%BB%E7%BB%9F%E7%BC%96%E8%AF%91%E6%9E%84%E5%BB%BA%E6%8C%87%E5%AF%BC.md)。本文主要介绍如何基于gn和ninja编译LiteOS-M工程,GCC+Makefile、IAR、Keil MDK等编译方式可以参考社区爱好者贡献的站点。
|
||||
|
||||
### 搭建系统基础环境
|
||||
|
||||
在搭建各个开发板环境前,需要完成OpenHarmony系统基础环境搭建。系统基础环境主要是指OpenHarmony的编译环境和开发环境,详细介绍请参考官方站点[Ubuntu编译环境准备](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/quick-start/quickstart-lite-env-setup-linux.md)。开发者需要根据环境搭建文档,完成下述软件的安装:Python3.7+、gn、ninja、hb。对于LiteOS-M内核,还需要安装Make构建工具和[ARM GCC编译工具链](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)。
|
||||
在搭建各个开发板环境前,需要完成OpenHarmony系统基础环境搭建。系统基础环境主要是指OpenHarmony的编译环境和开发环境,详细介绍请参考官方站点[Ubuntu编译环境准备](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Ubuntu%E7%BC%96%E8%AF%91%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87.md)。开发者需要根据环境搭建文档,完成下述软件的安装:Python3.7+、gn、ninja、hb。对于LiteOS-M内核,还需要安装Make构建工具和[ARM GCC编译工具链](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)。
|
||||
|
||||
### 获取OpenHarmony源码
|
||||
|
||||
开发者需要在Linux服务器上通过Git克隆获取OpenHarmony最新源码,详细的源码获取方式,请见[源码获取](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/get-code/sourcecode-acquire.md)。获取OpenHarmony完整仓代码后,假设克隆目录为`~/openHarmony`。
|
||||
开发者需要在Linux服务器上通过Git克隆获取OpenHarmony最新源码,详细的源码获取方式,请见[源码获取](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)。获取OpenHarmony完整仓代码后,假设克隆目录为`~/openHarmony`。
|
||||
|
||||
### 获取示例工程源码
|
||||
|
||||
@@ -80,7 +77,7 @@ chmod +x ~/openHarmony/device/st/nucleo_f767zi/build.sh
|
||||
cp -r ~/nucleo_f767zi/vendor/st ~/openHarmony/vendor/st
|
||||
```
|
||||
|
||||
关于示例代码目录的说明,可以参考资料站点[板级目录规范](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/porting/porting-chip-board-overview.md)。如果需要自行移植开发板,请参考[板级系统移植](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/porting/porting-chip-board.md)。
|
||||
关于示例代码目录的说明,可以参考资料站点[板级目录规范](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/porting/%E7%A7%BB%E6%A4%8D%E6%A6%82%E8%BF%B0-0.md#section6204129143013)。如果需要自行移植开发板,请参考[板级系统移植](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/porting/%E6%9D%BF%E7%BA%A7%E7%B3%BB%E7%BB%9F%E7%A7%BB%E6%A4%8D.md)。
|
||||
|
||||
### 编译运行
|
||||
|
||||
@@ -123,7 +120,7 @@ LiteOS-M内核移植的具体开发板的工程由社区开发者提供,可以
|
||||
|
||||
## 相关仓<a name="section1371113476307"></a>
|
||||
|
||||
[内核子系统](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/readme/%E5%86%85%E6%A0%B8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
|
||||
[内核子系统](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)
|
||||
|
||||
**kernel\_liteos\_m**
|
||||
|
||||
|
||||
@@ -1,52 +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_m/liteos.gni")
|
||||
|
||||
config("arch_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
module_group("arch") {
|
||||
modules = []
|
||||
if ("$board_cpu" == "arm9" || "$board_cpu" == "cortex-m3" ||
|
||||
"$board_cpu" == "cortex-m4" || "$board_cpu" == "cortex-m7" ||
|
||||
"$board_cpu" == "cortex-m33") {
|
||||
modules += [ "arm" ]
|
||||
} else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802") {
|
||||
modules += [ "csky" ]
|
||||
} else if ("$board_cpu" == "") {
|
||||
if ("$board_arch" == "rv32imac" || "$board_arch" == "rv32imafdc") {
|
||||
modules += [ "risc-v" ]
|
||||
} else if ("$board" == "esp32") {
|
||||
modules += [ "xtensa" ]
|
||||
}
|
||||
}
|
||||
configs = [ ":arch_config" ]
|
||||
}
|
||||
53
arch/Kconfig
53
arch/Kconfig
@@ -1,53 +0,0 @@
|
||||
config ARCH_ARM
|
||||
bool
|
||||
|
||||
rsource "arm/Kconfig"
|
||||
|
||||
config ARCH_CSKY
|
||||
bool
|
||||
|
||||
config ARCH_RISCV
|
||||
bool
|
||||
|
||||
config ARCH_RISCV32
|
||||
bool
|
||||
select ARCH_RISCV
|
||||
|
||||
config ARCH_XTENSA
|
||||
bool
|
||||
|
||||
comment "Extra Configurations"
|
||||
|
||||
config ARCH_FPU_DISABLE
|
||||
bool "Disable Floating Pointer Unit"
|
||||
default n
|
||||
help
|
||||
This option will bypass floating procedure in system.
|
||||
|
||||
config ARCH_SECURE_MONITOR_MODE
|
||||
bool "Run On Secure Monitor Mode"
|
||||
default n
|
||||
depends on ARCH_ARM_AARCH64
|
||||
help
|
||||
This option will make the system run on EL3.
|
||||
|
||||
config ARCH_INTERRUPT_PREEMPTION
|
||||
bool "Enable Interrupt Preemption"
|
||||
default n
|
||||
depends on ARCH_ARM_AARCH64
|
||||
help
|
||||
This option will support high priority interrupt preemption.
|
||||
|
||||
config IRQ_USE_STANDALONE_STACK
|
||||
bool "Use Interrupt Stack"
|
||||
default y
|
||||
depends on ARCH_ARM_AARCH64 || ARCH_ARM_AARCH32
|
||||
help
|
||||
This option will support using standalone interrupt stack.
|
||||
|
||||
config ARCH_UNALIGNED_EXC
|
||||
bool "Enable Unaligned Exception"
|
||||
default y
|
||||
depends on ARCH_ARM
|
||||
help
|
||||
This option will enable unaligned exception.
|
||||
@@ -1,39 +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_m/liteos.gni")
|
||||
|
||||
config("arm_config") {
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
module_group("arm") {
|
||||
modules = [ "$board_cpu/gcc" ]
|
||||
configs = [ ":arm_config" ]
|
||||
}
|
||||
108
arch/arm/Kconfig
108
arch/arm/Kconfig
@@ -1,108 +0,0 @@
|
||||
# ARM Architecture
|
||||
|
||||
#
|
||||
# ARM has 32-bit(Aarch32) and 64-bit(Aarch64) implementations
|
||||
#
|
||||
config ARCH_ARM_AARCH32
|
||||
bool
|
||||
select ARCH_ARM
|
||||
help
|
||||
32-bit ARM architecture implementations, Except the M-profile.
|
||||
It is not limited to ARMv7-A but also ARMv7-R, ARMv8-A 32-bit and etc.
|
||||
|
||||
#
|
||||
# Architecture Versions
|
||||
#
|
||||
config ARCH_ARM_V7M
|
||||
bool
|
||||
|
||||
config ARCH_ARM_V5TE
|
||||
bool
|
||||
|
||||
config ARCH_ARM_VER
|
||||
string
|
||||
default "armv7-m" if ARCH_ARM_V7M
|
||||
default "armv5te" if ARCH_ARM_V5TE
|
||||
|
||||
#
|
||||
# VFP Hardware
|
||||
#
|
||||
config ARCH_FPU_VFP_V3
|
||||
bool
|
||||
help
|
||||
An optional extension to the Arm, Thumb, and ThumbEE instruction sets in the ARMv7-A and ARMv7-R profiles.
|
||||
VFPv3U is a variant of VFPv3 that supports the trapping of floating-point exceptions to support code.
|
||||
|
||||
config ARCH_FPU_VFP_V4
|
||||
bool
|
||||
help
|
||||
An optional extension to the Arm, Thumb, and ThumbEE instruction sets in the ARMv7-A and ARMv7-R profiles.
|
||||
VFPv4U is a variant of VFPv4 that supports the trapping of floating-point exceptions to support code.
|
||||
VFPv4 and VFPv4U add both the Half-precision Extension and the fused multiply-add instructions to the features of VFPv3.
|
||||
|
||||
config ARCH_FPU_VFP_D16
|
||||
bool
|
||||
depends on ARCH_ARM_AARCH32
|
||||
help
|
||||
VPU implemented with 16 doubleword registers (16 x 64-bit).
|
||||
|
||||
config ARCH_FPU_VFP_D32
|
||||
bool
|
||||
depends on ARCH_ARM_AARCH32
|
||||
help
|
||||
VPU implemented with 32 doubleword registers (32 x 64-bit).
|
||||
|
||||
config ARCH_FPU_VFP_NEON
|
||||
bool
|
||||
help
|
||||
Advanced SIMD extension (NEON) support.
|
||||
|
||||
config ARCH_FPU
|
||||
string
|
||||
default "vfpv3" if ARCH_FPU_VFP_V3 && ARCH_FPU_VFP_D32
|
||||
default "vfpv3-d16" if ARCH_FPU_VFP_V3 && ARCH_FPU_VFP_D16
|
||||
default "neon-vfpv4" if ARCH_FPU_VFP_V4 && ARCH_FPU_VFP_D32 && ARCH_FPU_VFP_NEON
|
||||
default "vfpv4" if ARCH_FPU_VFP_V4 && ARCH_FPU_VFP_D32
|
||||
default "vfpv4-d16" if ARCH_FPU_VFP_V4 && ARCH_FPU_VFP_D16
|
||||
|
||||
#
|
||||
# Supported Processor Cores
|
||||
#
|
||||
config ARCH_CORTEX_M3
|
||||
bool
|
||||
select ARCH_ARM_V7M
|
||||
select ARCH_ARM_AARCH32
|
||||
|
||||
config ARCH_CORTEX_M4
|
||||
bool
|
||||
select ARCH_ARM_V7M
|
||||
select ARCH_ARM_AARCH32
|
||||
|
||||
config ARCH_CORTEX_M7
|
||||
bool
|
||||
select ARCH_ARM_V7M
|
||||
select ARCH_ARM_AARCH32
|
||||
select ARCH_FPU_VFP_V4
|
||||
select ARCH_FPU_VFP_D32
|
||||
select ARCH_FPU_VFP_NEON
|
||||
|
||||
config ARCH_CORTEX_M33
|
||||
bool
|
||||
select ARCH_ARM_V7M
|
||||
select ARCH_ARM_AARCH32
|
||||
select ARCH_FPU_VFP_V4
|
||||
select ARCH_FPU_VFP_D32
|
||||
select ARCH_FPU_VFP_NEON
|
||||
|
||||
config ARCH_ARM9
|
||||
bool
|
||||
select ARCH_ARM_V5TE
|
||||
select ARCH_ARM_AARCH32
|
||||
|
||||
config ARCH_CPU
|
||||
string
|
||||
default "cortex-m3" if ARCH_CORTEX_M3
|
||||
default "cortex-m4" if ARCH_CORTEX_M4
|
||||
default "cortex-m7" if ARCH_CORTEX_M7
|
||||
default "cortex-m33" if ARCH_CORTEX_M33
|
||||
default "arm9" if ARCH_ARM9
|
||||
@@ -1,51 +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 _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
@@ -1,51 +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 _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
@@ -1,38 +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_m/liteos.gni")
|
||||
|
||||
module_group("gcc") {
|
||||
if (defined(LOSCFG_SECURE_TRUSTZONE)) {
|
||||
modules = [ "TZ" ]
|
||||
} else {
|
||||
modules = [ "NTZ" ]
|
||||
}
|
||||
}
|
||||
@@ -1,51 +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 _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
@@ -1,123 +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 "los_timer.h"
|
||||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = 0,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
tick->freq = OS_SYS_CLOCK;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
NVIC_ClearPendingIRQ(SysTick_IRQn);
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT32 val = SysTick->VAL;
|
||||
*period = SysTick->LOAD;
|
||||
if (val != 0) {
|
||||
hwCycle = *period - val;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
__WFI();
|
||||
__ISB();
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
@@ -1,51 +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 _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
@@ -1,535 +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 "los_interrupt.h"
|
||||
#include "securec.h"
|
||||
#include <stdarg.h>
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_context.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
|
||||
/*lint -save -e40 -e522 -e533*/
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/*lint -restore*/
|
||||
#ifdef __ICCARM__
|
||||
#pragma location = ".data.vector"
|
||||
#pragma data_alignment=LOSCFG_ARCH_HWI_VECTOR_ALIGN
|
||||
#elif defined(__CC_ARM) || defined(__GNUC__)
|
||||
LITE_OS_SEC_VEC
|
||||
#endif
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
HWI_PROC_FUNC pfnHandler;
|
||||
VOID *pParm;
|
||||
} HWI_HANDLER_FUNC;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
WEAK VOID SysTick_Handler(VOID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalIntNumGet
|
||||
Description : Get an interrupt number
|
||||
Input : None
|
||||
Output : None
|
||||
Return : Interrupt Indexes number
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
|
||||
{
|
||||
return __get_IPSR();
|
||||
}
|
||||
|
||||
inline UINT32 ArchIsIntActive(VOID)
|
||||
{
|
||||
return (g_intCount > 0);
|
||||
}
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiDefaultHandler
|
||||
Description : default handler of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
/*lint -e529*/
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HalIntNumGet();
|
||||
PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
WEAK VOID HalPreInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WEAK VOID HalAftInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalInterrupt
|
||||
Description : Hardware interrupt entry function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
{
|
||||
UINT32 hwiIndex;
|
||||
UINT32 intSave;
|
||||
|
||||
#if (LOSCFG_KERNEL_RUNSTOP == 1)
|
||||
SCB->SCR &= (UINT32) ~((UINT32)SCB_SCR_SLEEPDEEP_Msk);
|
||||
#endif
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount++;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
hwiIndex = HalIntNumGet();
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
if (g_hwiHandlerForm[hwiIndex].pfnHandler != 0) {
|
||||
g_hwiHandlerForm[hwiIndex].pfnHandler((VOID *)g_hwiHandlerForm[hwiIndex].pParm);
|
||||
}
|
||||
#else
|
||||
if (g_hwiHandlerForm[hwiIndex] != 0) {
|
||||
g_hwiHandlerForm[hwiIndex]();
|
||||
}
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount--;
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchHwiCreate
|
||||
Description : create hardware interrupt
|
||||
Input : hwiNum --- hwi num to create
|
||||
hwiPrio --- priority of the hwi
|
||||
mode --- unused
|
||||
handler --- hwi handler
|
||||
arg --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return OS_ERRNO_HWI_ALREADY_CREATED;
|
||||
}
|
||||
|
||||
if (hwiPrio > OS_HWI_PRIO_LOWEST) {
|
||||
return OS_ERRNO_HWI_PRIO_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
#else
|
||||
OsSetVector(hwiNum, handler);
|
||||
#endif
|
||||
NVIC_EnableIRQ((IRQn_Type)hwiNum);
|
||||
NVIC_SetPriority((IRQn_Type)hwiNum, hwiPrio);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
NVIC_DisableIRQ((IRQn_Type)hwiNum);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#define FAULT_STATUS_REG_BIT 32
|
||||
#define USGFAULT (1 << 18)
|
||||
#define BUSFAULT (1 << 17)
|
||||
#define MEMFAULT (1 << 16)
|
||||
#define DIV0FAULT (1 << 4)
|
||||
#define UNALIGNFAULT (1 << 3)
|
||||
#define HARDFAULT_IRQN (-13)
|
||||
|
||||
ExcInfo g_excInfo = {0};
|
||||
|
||||
UINT8 g_uwExcTbl[FAULT_STATUS_REG_BIT] = {
|
||||
0, 0, 0, 0, 0, 0, OS_EXC_UF_DIVBYZERO, OS_EXC_UF_UNALIGNED,
|
||||
0, 0, 0, 0, OS_EXC_UF_NOCP, OS_EXC_UF_INVPC, OS_EXC_UF_INVSTATE, OS_EXC_UF_UNDEFINSTR,
|
||||
0, 0, 0, OS_EXC_BF_STKERR, OS_EXC_BF_UNSTKERR, OS_EXC_BF_IMPRECISERR, OS_EXC_BF_PRECISERR, OS_EXC_BF_IBUSERR,
|
||||
0, 0, 0, OS_EXC_MF_MSTKERR, OS_EXC_MF_MUNSTKERR, 0, OS_EXC_MF_DACCVIOL, OS_EXC_MF_IACCVIOL
|
||||
};
|
||||
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
STATIC VOID OsExcNvicDump(VOID)
|
||||
{
|
||||
#define OS_NR_NVIC_EXC_DUMP_TYPES 7
|
||||
UINT32 *base = NULL;
|
||||
UINT32 len, i, j;
|
||||
UINT32 rgNvicBases[OS_NR_NVIC_EXC_DUMP_TYPES] = {
|
||||
OS_NVIC_SETENA_BASE, OS_NVIC_SETPEND_BASE, OS_NVIC_INT_ACT_BASE,
|
||||
OS_NVIC_PRI_BASE, OS_NVIC_EXCPRI_BASE, OS_NVIC_SHCSR, OS_NVIC_INT_CTRL
|
||||
};
|
||||
UINT32 rgNvicLens[OS_NR_NVIC_EXC_DUMP_TYPES] = {
|
||||
OS_NVIC_INT_ENABLE_SIZE, OS_NVIC_INT_PEND_SIZE, OS_NVIC_INT_ACT_SIZE,
|
||||
OS_NVIC_INT_PRI_SIZE, OS_NVIC_EXCPRI_SIZE, OS_NVIC_SHCSR_SIZE,
|
||||
OS_NVIC_INT_CTRL_SIZE
|
||||
};
|
||||
CHAR strRgEnable[] = "enable";
|
||||
CHAR strRgPending[] = "pending";
|
||||
CHAR strRgActive[] = "active";
|
||||
CHAR strRgPriority[] = "priority";
|
||||
CHAR strRgException[] = "exception";
|
||||
CHAR strRgShcsr[] = "shcsr";
|
||||
CHAR strRgIntCtrl[] = "control";
|
||||
CHAR *strRgs[] = {
|
||||
strRgEnable, strRgPending, strRgActive, strRgPriority,
|
||||
strRgException, strRgShcsr, strRgIntCtrl
|
||||
};
|
||||
|
||||
PRINTK("\r\nOS exception NVIC dump:\n");
|
||||
for (i = 0; i < OS_NR_NVIC_EXC_DUMP_TYPES; i++) {
|
||||
base = (UINT32 *)rgNvicBases[i];
|
||||
len = rgNvicLens[i];
|
||||
PRINTK("interrupt %s register, base address: %p, size: 0x%x\n", strRgs[i], base, len);
|
||||
len = (len >> 2); /* 2: Gets the next register offset */
|
||||
for (j = 0; j < len; j++) {
|
||||
PRINTK("0x%x ", *(base + j));
|
||||
if ((j != 0) && ((j % 16) == 0)) { /* 16: print wrap line */
|
||||
PRINTK("\n");
|
||||
}
|
||||
}
|
||||
PRINTK("\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsExcTypeInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
CHAR *phaseStr[] = {"exc in init", "exc in task", "exc in hwi"};
|
||||
|
||||
PRINTK("Type = %d\n", excInfo->type);
|
||||
PRINTK("ThrdPid = %d\n", excInfo->thrdPid);
|
||||
PRINTK("Phase = %s\n", phaseStr[excInfo->phase]);
|
||||
PRINTK("FaultAddr = 0x%x\n", excInfo->faultAddr);
|
||||
}
|
||||
|
||||
STATIC VOID OsExcCurTaskInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
PRINTK("Current task info:\n");
|
||||
if (excInfo->phase == OS_EXC_IN_TASK) {
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
|
||||
PRINTK("Task name = %s\n", taskCB->taskName);
|
||||
PRINTK("Task ID = %d\n", taskCB->taskID);
|
||||
PRINTK("Task SP = %p\n", taskCB->stackPointer);
|
||||
PRINTK("Task ST = 0x%x\n", taskCB->topOfStack);
|
||||
PRINTK("Task SS = 0x%x\n", taskCB->stackSize);
|
||||
} else if (excInfo->phase == OS_EXC_IN_HWI) {
|
||||
PRINTK("Exception occur in interrupt phase!\n");
|
||||
} else {
|
||||
PRINTK("Exception occur in system init phase!\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsExcRegInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
PRINTK("Exception reg dump:\n");
|
||||
PRINTK("PC = 0x%x\n", excInfo->context->uwPC);
|
||||
PRINTK("LR = 0x%x\n", excInfo->context->uwLR);
|
||||
PRINTK("SP = 0x%x\n", excInfo->context->uwSP);
|
||||
PRINTK("R0 = 0x%x\n", excInfo->context->uwR0);
|
||||
PRINTK("R1 = 0x%x\n", excInfo->context->uwR1);
|
||||
PRINTK("R2 = 0x%x\n", excInfo->context->uwR2);
|
||||
PRINTK("R3 = 0x%x\n", excInfo->context->uwR3);
|
||||
PRINTK("R4 = 0x%x\n", excInfo->context->uwR4);
|
||||
PRINTK("R5 = 0x%x\n", excInfo->context->uwR5);
|
||||
PRINTK("R6 = 0x%x\n", excInfo->context->uwR6);
|
||||
PRINTK("R7 = 0x%x\n", excInfo->context->uwR7);
|
||||
PRINTK("R8 = 0x%x\n", excInfo->context->uwR8);
|
||||
PRINTK("R9 = 0x%x\n", excInfo->context->uwR9);
|
||||
PRINTK("R10 = 0x%x\n", excInfo->context->uwR10);
|
||||
PRINTK("R11 = 0x%x\n", excInfo->context->uwR11);
|
||||
PRINTK("R12 = 0x%x\n", excInfo->context->uwR12);
|
||||
PRINTK("PriMask = 0x%x\n", excInfo->context->uwPriMask);
|
||||
PRINTK("xPSR = 0x%x\n", excInfo->context->uwxPSR);
|
||||
}
|
||||
|
||||
STATIC VOID OsExcBackTraceInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
UINTPTR LR[LOSCFG_BACKTRACE_DEPTH] = {0};
|
||||
UINT32 index;
|
||||
|
||||
OsBackTraceHookCall(LR, LOSCFG_BACKTRACE_DEPTH, 0, excInfo->context->uwSP);
|
||||
|
||||
PRINTK("----- backtrace start -----\n");
|
||||
for (index = 0; index < LOSCFG_BACKTRACE_DEPTH; index++) {
|
||||
if (LR[index] == 0) {
|
||||
break;
|
||||
}
|
||||
PRINTK("backtrace %d -- lr = 0x%x\n", index, LR[index]);
|
||||
}
|
||||
PRINTK("----- backtrace end -----\n");
|
||||
}
|
||||
|
||||
STATIC VOID OsExcMemPoolCheckInfo(VOID)
|
||||
{
|
||||
PRINTK("\r\nmemory pools check:\n");
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
MemInfoCB memExcInfo[OS_SYS_MEM_NUM];
|
||||
UINT32 errCnt;
|
||||
UINT32 i;
|
||||
|
||||
(VOID)memset_s(memExcInfo, sizeof(memExcInfo), 0, sizeof(memExcInfo));
|
||||
|
||||
errCnt = OsMemExcInfoGet(OS_SYS_MEM_NUM, memExcInfo);
|
||||
if (errCnt < OS_SYS_MEM_NUM) {
|
||||
errCnt += OsMemboxExcInfoGet(OS_SYS_MEM_NUM - errCnt, memExcInfo + errCnt);
|
||||
}
|
||||
|
||||
if (errCnt == 0) {
|
||||
PRINTK("all memory pool check passed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < errCnt; i++) {
|
||||
PRINTK("pool num = %d\n", i);
|
||||
PRINTK("pool type = %d\n", memExcInfo[i].type);
|
||||
PRINTK("pool addr = 0x%x\n", memExcInfo[i].startAddr);
|
||||
PRINTK("pool size = 0x%x\n", memExcInfo[i].size);
|
||||
PRINTK("pool free = 0x%x\n", memExcInfo[i].free);
|
||||
PRINTK("pool blkNum = %d\n", memExcInfo[i].blockSize);
|
||||
PRINTK("pool error node addr = 0x%x\n", memExcInfo[i].errorAddr);
|
||||
PRINTK("pool error node len = 0x%x\n", memExcInfo[i].errorLen);
|
||||
PRINTK("pool error node owner = %d\n", memExcInfo[i].errorOwner);
|
||||
}
|
||||
#endif
|
||||
UINT32 ret = LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR);
|
||||
if (ret == LOS_OK) {
|
||||
PRINTK("system heap memcheck over, all passed!\n");
|
||||
}
|
||||
|
||||
PRINTK("memory pool check end!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
PRINTK("*************Exception Information**************\n");
|
||||
OsExcTypeInfo(excInfo);
|
||||
OsExcCurTaskInfo(excInfo);
|
||||
OsExcRegInfo(excInfo);
|
||||
OsExcBackTraceInfo(excInfo);
|
||||
OsGetAllTskInfo();
|
||||
OsExcNvicDump();
|
||||
OsExcMemPoolCheckInfo();
|
||||
#endif
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr)
|
||||
{
|
||||
UINT16 tmpFlag = (excType >> 16) & OS_NULL_SHORT; /* 16: Get Exception Type */
|
||||
g_intCount++;
|
||||
g_excInfo.nestCnt++;
|
||||
|
||||
g_excInfo.type = excType & OS_NULL_SHORT;
|
||||
|
||||
if (tmpFlag & OS_EXC_FLAG_FAULTADDR_VALID) {
|
||||
g_excInfo.faultAddr = faultAddr;
|
||||
} else {
|
||||
g_excInfo.faultAddr = OS_EXC_IMPRECISE_ACCESS_ADDR;
|
||||
}
|
||||
if (g_losTask.runTask != NULL) {
|
||||
if (tmpFlag & OS_EXC_FLAG_IN_HWI) {
|
||||
g_excInfo.phase = OS_EXC_IN_HWI;
|
||||
g_excInfo.thrdPid = pid;
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_TASK;
|
||||
g_excInfo.thrdPid = g_losTask.runTask->taskID;
|
||||
}
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_INIT;
|
||||
g_excInfo.thrdPid = OS_NULL_INT;
|
||||
}
|
||||
if (excType & OS_EXC_FLAG_NO_FLOAT) {
|
||||
g_excInfo.context = (EXC_CONTEXT_S *)((CHAR *)excBufAddr - LOS_OFF_SET_OF(EXC_CONTEXT_S, uwR4));
|
||||
} else {
|
||||
g_excInfo.context = excBufAddr;
|
||||
}
|
||||
|
||||
OsDoExcHook(EXC_INTERRUPT);
|
||||
OsExcInfoDisplay(&g_excInfo);
|
||||
ArchSysExit();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiInit
|
||||
Description : initialization of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
{
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
UINT32 index;
|
||||
g_hwiForm[0] = 0; /* [0] Top of Stack */
|
||||
g_hwiForm[1] = Reset_Handler; /* [1] reset */
|
||||
for (index = 2; index < OS_VECTOR_CNT; index++) { /* 2: The starting position of the interrupt */
|
||||
g_hwiForm[index] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
|
||||
}
|
||||
/* Exception handler register */
|
||||
g_hwiForm[NonMaskableInt_IRQn + OS_SYS_VECTOR_CNT] = HalExcNMI;
|
||||
g_hwiForm[HARDFAULT_IRQN + OS_SYS_VECTOR_CNT] = HalExcHardFault;
|
||||
g_hwiForm[MemoryManagement_IRQn + OS_SYS_VECTOR_CNT] = HalExcMemFault;
|
||||
g_hwiForm[BusFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcBusFault;
|
||||
g_hwiForm[UsageFault_IRQn + OS_SYS_VECTOR_CNT] = HalExcUsageFault;
|
||||
g_hwiForm[SVCall_IRQn + OS_SYS_VECTOR_CNT] = HalExcSvcCall;
|
||||
g_hwiForm[PendSV_IRQn + OS_SYS_VECTOR_CNT] = HalPendSV;
|
||||
g_hwiForm[SysTick_IRQn + OS_SYS_VECTOR_CNT] = SysTick_Handler;
|
||||
|
||||
/* Interrupt vector table location */
|
||||
SCB->VTOR = (UINT32)(UINTPTR)g_hwiForm;
|
||||
#endif
|
||||
#if (__CORTEX_M >= 0x03U) /* only for Cortex-M3 and above */
|
||||
NVIC_SetPriorityGrouping(OS_NVIC_AIRCR_PRIGROUP);
|
||||
#endif
|
||||
|
||||
/* Enable USGFAULT, BUSFAULT, MEMFAULT */
|
||||
*(volatile UINT32 *)OS_NVIC_SHCSR |= (USGFAULT | BUSFAULT | MEMFAULT);
|
||||
|
||||
/* Enable DIV 0 and unaligned exception */
|
||||
#ifdef LOSCFG_ARCH_UNALIGNED_EXC
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT | UNALIGNFAULT);
|
||||
#else
|
||||
*(volatile UINT32 *)OS_NVIC_CCR |= (DIV0FAULT);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,237 +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 "los_mpu.h"
|
||||
#include "los_config.h"
|
||||
#include "los_context.h"
|
||||
|
||||
#if (LOSCFG_MPU_ENABLE == 1)
|
||||
|
||||
#define SIZE_4G_BYTE 0x100000000
|
||||
#define MPU_MAX_REGION_NUM 8
|
||||
|
||||
STATIC UINT8 g_regionNumBeUsed[MPU_MAX_REGION_NUM] = {0};
|
||||
|
||||
typedef enum {
|
||||
MPU_AP_FORBID_USER_FORBID = 0x0, /* Privileged:No access Unprivileged:No access */
|
||||
MPU_AP_RW_USER_FORBID = 0x1, /* Privileged:Read/Write Unprivileged:No access */
|
||||
MPU_AP_RW_USER_RO = 0x2, /* Privileged:Read/Write Unprivileged:Read-only */
|
||||
MPU_AP_RW_USER_RW = 0x3, /* Privileged:Read/Write Unprivileged:Read/Write */
|
||||
MPU_AP_NA_USER_NA = 0x4, /* Privileged:UNPREDICTABLE Unprivileged:UNPREDICTABLE */
|
||||
MPU_AP_RO_USER_FORBID = 0x5, /* Privileged:Read-only Unprivileged:No access */
|
||||
MPU_AP_RO_USER_RO = 0x6, /* Privileged:Read-only Unprivileged:Read-only */
|
||||
} MpuApConfig;
|
||||
|
||||
VOID ArchMpuEnable(UINT32 defaultRegionEnable)
|
||||
{
|
||||
UINT32 intSave = ArchIntLock();
|
||||
MPU->CTRL = (MPU_CTRL_ENABLE_Msk | ((defaultRegionEnable << MPU_CTRL_PRIVDEFENA_Pos) & MPU_CTRL_PRIVDEFENA_Msk));
|
||||
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
|
||||
__DSB();
|
||||
__ISB();
|
||||
ArchIntRestore(intSave);
|
||||
}
|
||||
VOID ArchMpuDisable(VOID)
|
||||
{
|
||||
UINT32 intSave = ArchIntLock();
|
||||
MPU->CTRL = 0;
|
||||
__DSB();
|
||||
__ISB();
|
||||
ArchIntRestore(intSave);
|
||||
}
|
||||
|
||||
STATIC VOID HalMpuRASRAddMemAttr(MPU_CFG_PARA *para, UINT32 *RASR)
|
||||
{
|
||||
BOOL cachable = 0;
|
||||
BOOL buffable = 0;
|
||||
switch (para->memType) {
|
||||
case MPU_MEM_ON_CHIP_ROM:
|
||||
case MPU_MEM_ON_CHIP_RAM:
|
||||
cachable = 1;
|
||||
buffable = 0;
|
||||
break;
|
||||
case MPU_MEM_XIP_PSRAM:
|
||||
cachable = 1;
|
||||
buffable = 1;
|
||||
break;
|
||||
case MPU_MEM_XIP_NOR_FLASH:
|
||||
cachable = 0;
|
||||
buffable = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
(*RASR) |= ((cachable << MPU_RASR_C_Pos) | (buffable << MPU_RASR_B_Pos));
|
||||
}
|
||||
|
||||
STATIC UINT32 HalMpuEncodeSize(UINT64 size)
|
||||
{
|
||||
UINT32 encodeSize = 0;
|
||||
if (size > SIZE_4G_BYTE) {
|
||||
return 0;
|
||||
}
|
||||
if ((size & 0x1F) != 0) { /* size should aligned to 32 byte at least. */
|
||||
return 0;
|
||||
}
|
||||
size = (size >> 2);
|
||||
while (size != 0) {
|
||||
if (((size & 1) != 0) && ((size & 0xFFFFFFFE) != 0)) { /* size != 2^x (5 <= x <= 32) 128B - 4GB */
|
||||
return 0;
|
||||
}
|
||||
size = (size >> 1);
|
||||
encodeSize++;
|
||||
}
|
||||
return encodeSize;
|
||||
}
|
||||
|
||||
STATIC UINT32 HalMpuEncodeAP(MpuAccessPermission permission)
|
||||
{
|
||||
UINT32 ap;
|
||||
switch (permission) {
|
||||
case MPU_RW_BY_PRIVILEGED_ONLY:
|
||||
ap = MPU_AP_RW_USER_FORBID;
|
||||
break;
|
||||
case MPU_RW_ANY:
|
||||
ap = MPU_AP_RW_USER_RW;
|
||||
break;
|
||||
case MPU_RO_BY_PRIVILEGED_ONLY:
|
||||
ap = MPU_AP_RO_USER_FORBID;
|
||||
break;
|
||||
case MPU_RO_ANY:
|
||||
ap = MPU_AP_RO_USER_RO;
|
||||
break;
|
||||
default:
|
||||
ap = MPU_AP_RW_USER_RW;
|
||||
break;
|
||||
}
|
||||
return ap;
|
||||
}
|
||||
|
||||
STATIC UINT32 HalMpuGetRASR(UINT32 encodeSize, MPU_CFG_PARA *para)
|
||||
{
|
||||
UINT32 RASR;
|
||||
UINT32 ap;
|
||||
ap = HalMpuEncodeAP(para->permission);
|
||||
RASR = MPU_RASR_ENABLE_Msk;
|
||||
RASR |= ((encodeSize << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk);
|
||||
RASR |= ((ap << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | ((para->executable << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) |
|
||||
((para->shareability << MPU_RASR_S_Pos) & MPU_RASR_S_Msk);
|
||||
HalMpuRASRAddMemAttr(para, &RASR);
|
||||
return RASR;
|
||||
}
|
||||
|
||||
UINT32 ArchMpuSetRegion(UINT32 regionId, MPU_CFG_PARA *para)
|
||||
{
|
||||
UINT32 RASR;
|
||||
UINT32 RBAR;
|
||||
UINT32 RNR;
|
||||
UINT32 encodeSize;
|
||||
UINT32 intSave;
|
||||
UINT64 size;
|
||||
|
||||
if ((regionId >= MPU_MAX_REGION_NUM) || (para == NULL)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if ((MPU_TYPE_DREGION_Msk & MPU->TYPE) == 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
RNR = regionId;
|
||||
encodeSize = HalMpuEncodeSize(para->size);
|
||||
if (encodeSize == 0) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
size = para->size - 1; /* size aligned after encode check */
|
||||
if ((para->baseAddr & size) != 0) { /* base addr should aligned to region size */
|
||||
return LOS_NOK;
|
||||
}
|
||||
RBAR = para->baseAddr & MPU_RBAR_ADDR_Msk;
|
||||
RASR = HalMpuGetRASR(encodeSize, para);
|
||||
intSave = ArchIntLock();
|
||||
if (g_regionNumBeUsed[regionId]) {
|
||||
ArchIntRestore(intSave);
|
||||
return LOS_NOK;
|
||||
}
|
||||
MPU->RNR = RNR;
|
||||
MPU->RBAR = RBAR;
|
||||
MPU->RASR = RASR;
|
||||
__DSB();
|
||||
__ISB();
|
||||
g_regionNumBeUsed[regionId] = 1; /* Set mpu region used flag */
|
||||
ArchIntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 ArchMpuDisableRegion(UINT32 regionId)
|
||||
{
|
||||
volatile UINT32 type;
|
||||
UINT32 intSave;
|
||||
|
||||
if (regionId >= MPU_MAX_REGION_NUM) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
intSave = ArchIntLock();
|
||||
if (!g_regionNumBeUsed[regionId]) {
|
||||
ArchIntRestore(intSave);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
type = MPU->TYPE;
|
||||
if ((MPU_TYPE_DREGION_Msk & type) != 0) {
|
||||
MPU->RNR = regionId;
|
||||
MPU->RASR = 0;
|
||||
__DSB();
|
||||
__ISB();
|
||||
}
|
||||
g_regionNumBeUsed[regionId] = 0; /* clear mpu region used flag */
|
||||
ArchIntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
INT32 ArchMpuUnusedRegionGet(VOID)
|
||||
{
|
||||
INT32 id;
|
||||
UINT32 intSave = ArchIntLock();
|
||||
for (id = 0; id < MPU_MAX_REGION_NUM; id++) {
|
||||
if (!g_regionNumBeUsed[id]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
ArchIntRestore(intSave);
|
||||
|
||||
if (id == MPU_MAX_REGION_NUM) {
|
||||
return -1;
|
||||
} else {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,51 +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 _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
@@ -1,155 +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 "los_context.h"
|
||||
#include "securec.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchInit
|
||||
Description : arch init function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
HalHwiInit();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchSysExit
|
||||
Description : Task exit function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
|
||||
{
|
||||
LOS_IntLock();
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchTskStackInit
|
||||
Description : Task stack initialization function
|
||||
Input : taskID --- TaskID
|
||||
stackSize --- Total size of the stack
|
||||
topStack --- Top of task's stack
|
||||
Output : None
|
||||
Return : Context pointer
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = NULL;
|
||||
errno_t result;
|
||||
|
||||
/* initialize the task stack, write magic num to stack top */
|
||||
result = memset_s(topStack, stackSize, (INT32)(OS_TASK_STACK_INIT & 0xFF), stackSize);
|
||||
if (result != EOK) {
|
||||
printf("memset_s is failed:%s[%d]\r\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
*((UINT32 *)(topStack)) = OS_TASK_MAGIC_WORD;
|
||||
|
||||
context = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));
|
||||
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
context->S16 = 0xAA000010;
|
||||
context->S17 = 0xAA000011;
|
||||
context->S18 = 0xAA000012;
|
||||
context->S19 = 0xAA000013;
|
||||
context->S20 = 0xAA000014;
|
||||
context->S21 = 0xAA000015;
|
||||
context->S22 = 0xAA000016;
|
||||
context->S23 = 0xAA000017;
|
||||
context->S24 = 0xAA000018;
|
||||
context->S25 = 0xAA000019;
|
||||
context->S26 = 0xAA00001A;
|
||||
context->S27 = 0xAA00001B;
|
||||
context->S28 = 0xAA00001C;
|
||||
context->S29 = 0xAA00001D;
|
||||
context->S30 = 0xAA00001E;
|
||||
context->S31 = 0xAA00001F;
|
||||
context->S0 = 0xAA000000;
|
||||
context->S1 = 0xAA000001;
|
||||
context->S2 = 0xAA000002;
|
||||
context->S3 = 0xAA000003;
|
||||
context->S4 = 0xAA000004;
|
||||
context->S5 = 0xAA000005;
|
||||
context->S6 = 0xAA000006;
|
||||
context->S7 = 0xAA000007;
|
||||
context->S8 = 0xAA000008;
|
||||
context->S9 = 0xAA000009;
|
||||
context->S10 = 0xAA00000A;
|
||||
context->S11 = 0xAA00000B;
|
||||
context->S12 = 0xAA00000C;
|
||||
context->S13 = 0xAA00000D;
|
||||
context->S14 = 0xAA00000E;
|
||||
context->S15 = 0xAA00000F;
|
||||
context->FPSCR = 0x00000000;
|
||||
context->NO_NAME = 0xAA000011;
|
||||
#endif
|
||||
|
||||
context->uwR4 = 0x04040404L;
|
||||
context->uwR5 = 0x05050505L;
|
||||
context->uwR6 = 0x06060606L;
|
||||
context->uwR7 = 0x07070707L;
|
||||
context->uwR8 = 0x08080808L;
|
||||
context->uwR9 = 0x09090909L;
|
||||
context->uwR10 = 0x10101010L;
|
||||
context->uwR11 = 0x11111111L;
|
||||
context->uwPriMask = 0;
|
||||
context->uwR0 = taskID;
|
||||
context->uwR1 = 0x01010101L;
|
||||
context->uwR2 = 0x02020202L;
|
||||
context->uwR3 = 0x03030303L;
|
||||
context->uwR12 = 0x12121212L;
|
||||
context->uwLR = (UINT32)(UINTPTR)ArchSysExit;
|
||||
context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
|
||||
context->uwxPSR = 0x01000000L;
|
||||
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
OsSchedStart();
|
||||
HalStartToRun();
|
||||
return LOS_OK; /* never return */
|
||||
}
|
||||
@@ -1,699 +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 _LOS_ARCH_INTERRUPT_H
|
||||
#define _LOS_ARCH_INTERRUPT_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Maximum number of used hardware interrupts.
|
||||
*/
|
||||
#ifndef OS_HWI_MAX_NUM
|
||||
#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Highest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_HIGHEST
|
||||
#define OS_HWI_PRIO_HIGHEST 0
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Lowest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_LOWEST
|
||||
#define OS_HWI_PRIO_LOWEST 7
|
||||
#endif
|
||||
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Define the type of a hardware interrupt vector table function.
|
||||
*/
|
||||
typedef VOID (**HWI_VECTOR_FUNC)(void);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern UINT32 g_intCount;
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of M-Core system interrupt vector.
|
||||
*/
|
||||
#define OS_SYS_VECTOR_CNT 16
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of M-Core interrupt vector.
|
||||
*/
|
||||
#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* AIRCR register priority group parameter .
|
||||
*/
|
||||
#define OS_NVIC_AIRCR_PRIGROUP 7
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Boot interrupt vector table.
|
||||
*/
|
||||
extern UINT32 _BootVectors[];
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt number.
|
||||
*
|
||||
* Value: 0x02000900
|
||||
*
|
||||
* Solution: Ensure that the interrupt number is valid. The value range of the interrupt number applicable for a Cortex-A7 platform is [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Null hardware interrupt handling function.
|
||||
*
|
||||
* Value: 0x02000901
|
||||
*
|
||||
* Solution: Pass in a valid non-null hardware interrupt handling function.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
|
||||
*
|
||||
* Value: 0x02000902
|
||||
*
|
||||
* Solution: Increase the configured maximum number of supported hardware interrupts.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
|
||||
*
|
||||
* Value: 0x02000903
|
||||
*
|
||||
* Solution: Expand the configured memory.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: The interrupt has already been created.
|
||||
*
|
||||
* Value: 0x02000904
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt priority.
|
||||
*
|
||||
* Value: 0x02000905
|
||||
*
|
||||
* Solution: Ensure that the interrupt priority is valid. The value range of the interrupt priority applicable for a Cortex-A7 platform is [0,15].
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Incorrect interrupt creation mode.
|
||||
*
|
||||
* Value: 0x02000906
|
||||
*
|
||||
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST of which the value can be 0 or 1.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
|
||||
*
|
||||
* Value: 0x02000907
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* SysTick control and status register.
|
||||
*/
|
||||
#define OS_SYSTICK_CONTROL_REG 0xE000E010
|
||||
|
||||
/* *
|
||||
* @ingroup los_hw
|
||||
* SysTick current value register.
|
||||
*/
|
||||
#define OS_SYSTICK_CURRENT_REG 0xE000E018
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt Priority-Level Registers.
|
||||
*/
|
||||
#define OS_NVIC_PRI_BASE 0xE000E400
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt enable register for 0-31.
|
||||
*/
|
||||
#define OS_NVIC_SETENA_BASE 0xE000E100
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* interrupt pending register.
|
||||
*/
|
||||
#define OS_NVIC_SETPEND_BASE 0xE000E200
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt active register.
|
||||
*/
|
||||
#define OS_NVIC_INT_ACT_BASE 0xE000E300
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt disable register for 0-31.
|
||||
*/
|
||||
#define OS_NVIC_CLRENA_BASE 0xE000E180
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt control and status register.
|
||||
*/
|
||||
#define OS_NVIC_INT_CTRL 0xE000ED04
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Vector table offset register.
|
||||
*/
|
||||
#define OS_NVIC_VTOR 0xE000ED08
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Application interrupt and reset control register
|
||||
*/
|
||||
#define OS_NVIC_AIRCR 0xE000ED0C
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* System exception priority register.
|
||||
*/
|
||||
#define OS_NVIC_EXCPRI_BASE 0xE000ED18
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 1 :reset.
|
||||
*/
|
||||
#define OS_EXC_RESET 1
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 2 :Non-Maskable Interrupt.
|
||||
*/
|
||||
#define OS_EXC_NMI 2
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 3 :(hard)fault.
|
||||
*/
|
||||
#define OS_EXC_HARD_FAULT 3
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 4 :MemManage fault.
|
||||
*/
|
||||
#define OS_EXC_MPU_FAULT 4
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 5 :Bus fault.
|
||||
*/
|
||||
#define OS_EXC_BUS_FAULT 5
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 6 :Usage fault.
|
||||
*/
|
||||
#define OS_EXC_USAGE_FAULT 6
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 11 :SVCall.
|
||||
*/
|
||||
#define OS_EXC_SVC_CALL 11
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 12 :Debug monitor.
|
||||
*/
|
||||
#define OS_EXC_DBG_MONITOR 12
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 14 :PendSV.
|
||||
*/
|
||||
#define OS_EXC_PEND_SV 14
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Interrupt No. 15 :SysTick.
|
||||
*/
|
||||
#define OS_EXC_SYS_TICK 15
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg);
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Hardware interrupt entry function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used as all hardware interrupt handling function entry.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalInterrupt(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Get an interrupt number.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the current interrupt number.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval: Interrupt Indexes number.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 HalIntNumGet(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Default vector handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure interrupt for null function.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalHwiDefaultHandler(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Reset the vector table.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to reset the vector table.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID Reset_Handler(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Pended System Call.
|
||||
*
|
||||
* @par Description:
|
||||
* PendSV can be pended and is useful for an OS to pend an exception
|
||||
* so that an action can be performed after other important tasks are completed.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalPendSV(VOID);
|
||||
|
||||
|
||||
#define OS_EXC_IN_INIT 0
|
||||
#define OS_EXC_IN_TASK 1
|
||||
#define OS_EXC_IN_HWI 2
|
||||
|
||||
#define OS_EXC_MAX_BUF_LEN 25
|
||||
#define OS_EXC_MAX_NEST_DEPTH 1
|
||||
|
||||
#define OS_NVIC_SHCSR 0xE000ED24
|
||||
#define OS_NVIC_CCR 0xE000ED14
|
||||
|
||||
#define OS_NVIC_INT_ENABLE_SIZE 0x20
|
||||
#define OS_NVIC_INT_PRI_SIZE 0xF0
|
||||
#define OS_NVIC_EXCPRI_SIZE 0xC
|
||||
#define OS_NVIC_INT_CTRL_SIZE 4
|
||||
#define OS_NVIC_SHCSR_SIZE 4
|
||||
|
||||
#define OS_NVIC_INT_PEND_SIZE OS_NVIC_INT_ACT_SIZE
|
||||
#define OS_NVIC_INT_ACT_SIZE OS_NVIC_INT_ENABLE_SIZE
|
||||
|
||||
#define OS_EXC_FLAG_NO_FLOAT 0x10000000
|
||||
#define OS_EXC_FLAG_FAULTADDR_VALID 0x01
|
||||
#define OS_EXC_FLAG_IN_HWI 0x02
|
||||
|
||||
#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB
|
||||
|
||||
#define OS_EXC_EVENT 0x00000001
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* the struct of register files
|
||||
*
|
||||
* description: the register files that saved when exception triggered
|
||||
*
|
||||
* notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet.
|
||||
*/
|
||||
typedef struct TagExcContext {
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
|
||||
UINT32 S16;
|
||||
UINT32 S17;
|
||||
UINT32 S18;
|
||||
UINT32 S19;
|
||||
UINT32 S20;
|
||||
UINT32 S21;
|
||||
UINT32 S22;
|
||||
UINT32 S23;
|
||||
UINT32 S24;
|
||||
UINT32 S25;
|
||||
UINT32 S26;
|
||||
UINT32 S27;
|
||||
UINT32 S28;
|
||||
UINT32 S29;
|
||||
UINT32 S30;
|
||||
UINT32 S31;
|
||||
#endif
|
||||
UINT32 uwR4;
|
||||
UINT32 uwR5;
|
||||
UINT32 uwR6;
|
||||
UINT32 uwR7;
|
||||
UINT32 uwR8;
|
||||
UINT32 uwR9;
|
||||
UINT32 uwR10;
|
||||
UINT32 uwR11;
|
||||
UINT32 uwPriMask;
|
||||
/* auto save */
|
||||
UINT32 uwSP;
|
||||
UINT32 uwR0;
|
||||
UINT32 uwR1;
|
||||
UINT32 uwR2;
|
||||
UINT32 uwR3;
|
||||
UINT32 uwR12;
|
||||
UINT32 uwLR;
|
||||
UINT32 uwPC;
|
||||
UINT32 uwxPSR;
|
||||
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined (__FPU_USED) && (__FPU_USED== 1U)))
|
||||
UINT32 S0;
|
||||
UINT32 S1;
|
||||
UINT32 S2;
|
||||
UINT32 S3;
|
||||
UINT32 S4;
|
||||
UINT32 S5;
|
||||
UINT32 S6;
|
||||
UINT32 S7;
|
||||
UINT32 S8;
|
||||
UINT32 S9;
|
||||
UINT32 S10;
|
||||
UINT32 S11;
|
||||
UINT32 S12;
|
||||
UINT32 S13;
|
||||
UINT32 S14;
|
||||
UINT32 S15;
|
||||
UINT32 FPSCR;
|
||||
UINT32 NO_NAME;
|
||||
#endif
|
||||
} EXC_CONTEXT_S;
|
||||
|
||||
typedef VOID (*EXC_PROC_FUNC)(UINT32, EXC_CONTEXT_S *);
|
||||
VOID HalExcHandleEntry(UINT32 excType, UINT32 faultAddr, UINT32 pid, EXC_CONTEXT_S *excBufAddr);
|
||||
|
||||
VOID HalExcNMI(VOID);
|
||||
VOID HalExcHardFault(VOID);
|
||||
VOID HalExcMemFault(VOID);
|
||||
VOID HalExcBusFault(VOID);
|
||||
VOID HalExcUsageFault(VOID);
|
||||
VOID HalExcSvcCall(VOID);
|
||||
VOID HalHwiInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the bus status register was being pushed.
|
||||
*/
|
||||
#define OS_EXC_BF_STKERR 1
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the bus status register was out of the stack.
|
||||
*/
|
||||
#define OS_EXC_BF_UNSTKERR 2
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Bus status register imprecise data access violation.
|
||||
*/
|
||||
#define OS_EXC_BF_IMPRECISERR 3
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Bus status register exact data access violation.
|
||||
*/
|
||||
#define OS_EXC_BF_PRECISERR 4
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Bus status register access violation while pointing.
|
||||
*/
|
||||
#define OS_EXC_BF_IBUSERR 5
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the memory management status register was being pushed.
|
||||
*/
|
||||
#define OS_EXC_MF_MSTKERR 6
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: An error occurred while the memory management status register was out of the stack.
|
||||
*/
|
||||
#define OS_EXC_MF_MUNSTKERR 7
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Memory management status register data access violation.
|
||||
*/
|
||||
#define OS_EXC_MF_DACCVIOL 8
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Memory management status register access violation.
|
||||
*/
|
||||
#define OS_EXC_MF_IACCVIOL 9
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage indicating that the divisor is zero during the division operation.
|
||||
*/
|
||||
#define OS_EXC_UF_DIVBYZERO 10
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Usage error, error caused by unaligned access.
|
||||
*/
|
||||
#define OS_EXC_UF_UNALIGNED 11
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage attempting to execute coprocessor related instruction.
|
||||
*/
|
||||
#define OS_EXC_UF_NOCP 12
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Usage error attempting to load EXC_RETURN to PC illegally on exception return.
|
||||
*/
|
||||
#define OS_EXC_UF_INVPC 13
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage, attempting to cut to ARM state.
|
||||
*/
|
||||
#define OS_EXC_UF_INVSTATE 14
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Incorrect usage. Executed instruction whose code is undefined.
|
||||
*/
|
||||
#define OS_EXC_UF_UNDEFINSTR 15
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: NMI
|
||||
*/
|
||||
|
||||
#define OS_EXC_CAUSE_NMI 16
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: hard fault
|
||||
*/
|
||||
#define OS_EXC_CAUSE_HARDFAULT 17
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: The task handler exits.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_TASK_EXIT 18
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: A fatal error.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_FATAL_ERR 19
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: Hard Fault caused by a debug event.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_DEBUGEVT 20
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Cortex-M exception types: A hard fault that occurs when a quantity is oriented.
|
||||
*/
|
||||
#define OS_EXC_CAUSE_VECTBL 21
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Exception information structure
|
||||
*
|
||||
* Description: Exception information saved when an exception is triggered on the Cortex-M7 platform.
|
||||
*
|
||||
*/
|
||||
typedef struct TagExcInfo {
|
||||
/**< Exception occurrence phase: 0 means that an exception occurs in initialization,
|
||||
* 1 means that an exception occurs in a task, and 2 means that an exception occurs in an interrupt */
|
||||
UINT16 phase;
|
||||
/**< Exception type. When exceptions occur, check the numbers 1 - 21 listed above */
|
||||
UINT16 type;
|
||||
/**< If the exact address access error indicates the wrong access address when the exception occurred */
|
||||
UINT32 faultAddr;
|
||||
/**< An exception occurs in an interrupt, indicating the interrupt number.
|
||||
* An exception occurs in the task, indicating the task ID, or 0xFFFFFFFF if it occurs during initialization */
|
||||
UINT32 thrdPid;
|
||||
/**< Number of nested exceptions. Currently only registered hook functions are supported
|
||||
* when an exception is entered for the first time */
|
||||
UINT16 nestCnt;
|
||||
/**< reserve */
|
||||
UINT16 reserved;
|
||||
/**< Hardware context at the time an exception to the automatic stack floating-point register occurs */
|
||||
EXC_CONTEXT_S *context;
|
||||
} ExcInfo;
|
||||
|
||||
extern UINT32 g_curNestCount;
|
||||
extern UINT32 g_intCount;
|
||||
extern UINT8 g_uwExcTbl[32];
|
||||
extern ExcInfo g_excInfo;
|
||||
|
||||
#define MAX_INT_INFO_SIZE (8 + 0x164)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_INTERRUPT_H */
|
||||
@@ -1,51 +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 _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
@@ -1,155 +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 "los_context.h"
|
||||
#include "securec.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchInit
|
||||
Description : arch init function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
HalHwiInit();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchSysExit
|
||||
Description : Task exit function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
|
||||
{
|
||||
LOS_IntLock();
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchTskStackInit
|
||||
Description : Task stack initialization function
|
||||
Input : taskID --- TaskID
|
||||
stackSize --- Total size of the stack
|
||||
topStack --- Top of task's stack
|
||||
Output : None
|
||||
Return : Context pointer
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = NULL;
|
||||
errno_t result;
|
||||
|
||||
/* initialize the task stack, write magic num to stack top */
|
||||
result = memset_s(topStack, stackSize, (INT32)(OS_TASK_STACK_INIT & 0xFF), stackSize);
|
||||
if (result != EOK) {
|
||||
printf("memset_s is failed:%s[%d]\r\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
*((UINT32 *)(topStack)) = OS_TASK_MAGIC_WORD;
|
||||
|
||||
context = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));
|
||||
|
||||
#if ((defined(__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
|
||||
(defined(__FPU_USED) && (__FPU_USED == 1U)))
|
||||
context->S16 = 0xAA000010;
|
||||
context->S17 = 0xAA000011;
|
||||
context->S18 = 0xAA000012;
|
||||
context->S19 = 0xAA000013;
|
||||
context->S20 = 0xAA000014;
|
||||
context->S21 = 0xAA000015;
|
||||
context->S22 = 0xAA000016;
|
||||
context->S23 = 0xAA000017;
|
||||
context->S24 = 0xAA000018;
|
||||
context->S25 = 0xAA000019;
|
||||
context->S26 = 0xAA00001A;
|
||||
context->S27 = 0xAA00001B;
|
||||
context->S28 = 0xAA00001C;
|
||||
context->S29 = 0xAA00001D;
|
||||
context->S30 = 0xAA00001E;
|
||||
context->S31 = 0xAA00001F;
|
||||
context->S0 = 0xAA000000;
|
||||
context->S1 = 0xAA000001;
|
||||
context->S2 = 0xAA000002;
|
||||
context->S3 = 0xAA000003;
|
||||
context->S4 = 0xAA000004;
|
||||
context->S5 = 0xAA000005;
|
||||
context->S6 = 0xAA000006;
|
||||
context->S7 = 0xAA000007;
|
||||
context->S8 = 0xAA000008;
|
||||
context->S9 = 0xAA000009;
|
||||
context->S10 = 0xAA00000A;
|
||||
context->S11 = 0xAA00000B;
|
||||
context->S12 = 0xAA00000C;
|
||||
context->S13 = 0xAA00000D;
|
||||
context->S14 = 0xAA00000E;
|
||||
context->S15 = 0xAA00000F;
|
||||
context->FPSCR = 0x00000000;
|
||||
context->NO_NAME = 0xAA000011;
|
||||
#endif
|
||||
|
||||
context->uwR4 = 0x04040404L;
|
||||
context->uwR5 = 0x05050505L;
|
||||
context->uwR6 = 0x06060606L;
|
||||
context->uwR7 = 0x07070707L;
|
||||
context->uwR8 = 0x08080808L;
|
||||
context->uwR9 = 0x09090909L;
|
||||
context->uwR10 = 0x10101010L;
|
||||
context->uwR11 = 0x11111111L;
|
||||
context->uwPriMask = 0;
|
||||
context->uwR0 = taskID;
|
||||
context->uwR1 = 0x01010101L;
|
||||
context->uwR2 = 0x02020202L;
|
||||
context->uwR3 = 0x03030303L;
|
||||
context->uwR12 = 0x12121212L;
|
||||
context->uwLR = (UINT32)(UINTPTR)ArchSysExit;
|
||||
context->uwPC = (UINT32)(UINTPTR)OsTaskEntry;
|
||||
context->uwxPSR = 0x01000000L;
|
||||
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
OsSchedStart();
|
||||
HalStartToRun();
|
||||
return LOS_OK; /* never return */
|
||||
}
|
||||
@@ -1,122 +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 "los_timer.h"
|
||||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = 0,
|
||||
.irqNum = SysTick_IRQn,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
UINT32 ret;
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
tick->freq = OS_SYS_CLOCK;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ret = SysTick_Config(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
if (ret == 1) {
|
||||
return LOS_ERRNO_TICK_PER_SEC_TOO_SMALL;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
NVIC_ClearPendingIRQ(SysTick_IRQn);
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle = 0;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
UINT32 val = SysTick->VAL;
|
||||
*period = SysTick->LOAD;
|
||||
if (val != 0) {
|
||||
hwCycle = *period - val;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
__DSB();
|
||||
__WFI();
|
||||
__ISB();
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -1,56 +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 _ARCH_ELF_H
|
||||
#define _ARCH_ELF_H
|
||||
|
||||
#include "elf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define check_arch(ehdr) ((ehdr)->e_machine == EM_ARM)
|
||||
|
||||
#define R_ARCH_NONE R_ARM_NONE
|
||||
#define R_ARCH_GLOB_DAT R_ARM_GLOB_DAT
|
||||
#define R_ARCH_JUMP_SLOT R_ARM_JUMP_SLOT
|
||||
#define R_ARCH_ABS32 R_ARM_ABS32
|
||||
#define R_ARCH_RELATIVE R_ARM_RELATIVE
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _ARCH_ELF_H */
|
||||
|
||||
@@ -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_m/liteos.gni")
|
||||
|
||||
module_group("csky") {
|
||||
modules = [ "v2/gcc" ]
|
||||
}
|
||||
@@ -1,45 +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_m/liteos.gni")
|
||||
|
||||
module_name = "arch"
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"los_context.c",
|
||||
"los_dispatch.S",
|
||||
"los_exc.S",
|
||||
"los_interrupt.c",
|
||||
"los_timer.c",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
@@ -1,391 +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 _LOS_ARCH_INTERRUPT_H
|
||||
#define _LOS_ARCH_INTERRUPT_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Maximum number of used hardware interrupts.
|
||||
*/
|
||||
#ifndef OS_HWI_MAX_NUM
|
||||
#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Highest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_HIGHEST
|
||||
#define OS_HWI_PRIO_HIGHEST 0
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Lowest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_LOWEST
|
||||
#define OS_HWI_PRIO_LOWEST 3
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Check the interrupt priority.
|
||||
*/
|
||||
#define HWI_PRI_VALID(pri) (((pri) >= OS_HWI_PRIO_HIGHEST) && ((pri) <= OS_HWI_PRIO_LOWEST))
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Define the type of a hardware interrupt vector table function.
|
||||
*/
|
||||
typedef VOID (**HWI_VECTOR_FUNC)(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern UINT32 g_intCount;
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of C-sky system interrupt vector.
|
||||
*/
|
||||
#define OS_SYS_VECTOR_CNT 32
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of C-sky interrupt vector.
|
||||
*/
|
||||
#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
|
||||
|
||||
#define PSR_VEC_OFFSET 16U
|
||||
#define VIC_REG_BASE 0xE000E100UL
|
||||
|
||||
typedef struct {
|
||||
UINT32 ISER[4U];
|
||||
UINT32 RESERVED0[12U];
|
||||
UINT32 IWER[4U];
|
||||
UINT32 RESERVED1[12U];
|
||||
UINT32 ICER[4U];
|
||||
UINT32 RESERVED2[12U];
|
||||
UINT32 IWDR[4U];
|
||||
UINT32 RESERVED3[12U];
|
||||
UINT32 ISPR[4U];
|
||||
UINT32 RESERVED4[12U];
|
||||
UINT32 ISSR[4U];
|
||||
UINT32 RESERVED5[12U];
|
||||
UINT32 ICPR[4U];
|
||||
UINT32 RESERVED6[12U];
|
||||
UINT32 ICSR[4U];
|
||||
UINT32 RESERVED7[12U];
|
||||
UINT32 IABR[4U];
|
||||
UINT32 RESERVED8[60U];
|
||||
UINT32 IPR[32U];
|
||||
UINT32 RESERVED9[480U];
|
||||
UINT32 ISR;
|
||||
UINT32 IPTR;
|
||||
UINT32 TSPEND;
|
||||
UINT32 TSABR;
|
||||
UINT32 TSPR;
|
||||
} VIC_TYPE;
|
||||
|
||||
extern VIC_TYPE *VIC_REG;
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt number.
|
||||
*
|
||||
* Value: 0x02000900
|
||||
*
|
||||
* Solution: Ensure that the interrupt number is valid.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Null hardware interrupt handling function.
|
||||
*
|
||||
* Value: 0x02000901
|
||||
*
|
||||
* Solution: Pass in a valid non-null hardware interrupt handling function.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
|
||||
*
|
||||
* Value: 0x02000902
|
||||
*
|
||||
* Solution: Increase the configured maximum number of supported hardware interrupts.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
|
||||
*
|
||||
* Value: 0x02000903
|
||||
*
|
||||
* Solution: Expand the configured memory.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: The interrupt has already been created.
|
||||
*
|
||||
* Value: 0x02000904
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt priority.
|
||||
*
|
||||
* Value: 0x02000905
|
||||
*
|
||||
* Solution: Ensure that the interrupt priority is valid.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Incorrect interrupt creation mode.
|
||||
*
|
||||
* Value: 0x02000906
|
||||
*
|
||||
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
|
||||
*
|
||||
* Value: 0x02000907
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt number.
|
||||
*
|
||||
* Value: 0x02000900
|
||||
*
|
||||
* Solution: Ensure that the interrupt number is valid.
|
||||
*/
|
||||
#define LOS_ERRNO_HWI_NUM_INVALID OS_ERRNO_HWI_NUM_INVALID
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg);
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Hardware interrupt entry function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used as all hardware interrupt handling function entry.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalInterrupt(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Get an interrupt number.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to get the current interrupt number.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param: None.
|
||||
*
|
||||
* @retval: Interrupt Indexes number.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 HalIntNumGet(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Default vector handling function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure interrupt for null function.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param:None.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID HalHwiDefaultHandler(VOID);
|
||||
|
||||
#define OS_EXC_IN_INIT 0
|
||||
#define OS_EXC_IN_TASK 1
|
||||
#define OS_EXC_IN_HWI 2
|
||||
|
||||
#define OS_VIC_INT_ENABLE_SIZE 0x4
|
||||
#define OS_VIC_INT_WAKER_SIZE 0x4
|
||||
#define OS_VIC_INT_ICER_SIZE 0x4
|
||||
#define OS_VIC_INT_ISPR_SIZE 0x4
|
||||
#define OS_VIC_INT_IABR_SIZE 0x4
|
||||
#define OS_VIC_INT_IPR_SIZE 0x4
|
||||
#define OS_VIC_INT_ISR_SIZE 0x4
|
||||
#define OS_VIC_INT_IPTR_SIZE 0x4
|
||||
|
||||
#define OS_EXC_FLAG_FAULTADDR_VALID 0x01
|
||||
|
||||
#define OS_EXC_IMPRECISE_ACCESS_ADDR 0xABABABAB
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* the struct of register files
|
||||
*
|
||||
* description: the register files that saved when exception triggered
|
||||
*
|
||||
* notes:the following register with prefix 'uw' correspond to the registers in the cpu data sheet.
|
||||
*/
|
||||
typedef struct TagExcContext {
|
||||
UINT32 R0;
|
||||
UINT32 R1;
|
||||
UINT32 R2;
|
||||
UINT32 R3;
|
||||
UINT32 R4;
|
||||
UINT32 R5;
|
||||
UINT32 R6;
|
||||
UINT32 R7;
|
||||
UINT32 R8;
|
||||
UINT32 R9;
|
||||
UINT32 R10;
|
||||
UINT32 R11;
|
||||
UINT32 R12;
|
||||
UINT32 R13;
|
||||
UINT32 R14;
|
||||
UINT32 R15;
|
||||
UINT32 EPSR;
|
||||
UINT32 EPC;
|
||||
} EXC_CONTEXT_S;
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* @brief: Exception handler function.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to handle Exception.
|
||||
*
|
||||
* @attention:
|
||||
* <ul><li>None.</li></ul>
|
||||
*
|
||||
* @param excBufAddr [IN] The address of stack pointer at which the error occurred.
|
||||
* @param faultAddr [IN] The address at which the error occurred.
|
||||
*
|
||||
* @retval:None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_arch_interrupt.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(EXC_CONTEXT_S *excBufAddr, UINT32 faultAddr);
|
||||
|
||||
VOID IrqEntry(VOID);
|
||||
|
||||
VOID HandleEntry(VOID);
|
||||
|
||||
VOID HalHwiInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Exception information structure
|
||||
*
|
||||
* Description: Exception information saved when an exception is triggered on the Csky platform.
|
||||
*
|
||||
*/
|
||||
typedef struct TagExcInfo {
|
||||
UINT16 phase;
|
||||
UINT16 type;
|
||||
UINT32 faultAddr;
|
||||
UINT32 thrdPid;
|
||||
UINT16 nestCnt;
|
||||
UINT16 reserved;
|
||||
EXC_CONTEXT_S *context;
|
||||
} ExcInfo;
|
||||
|
||||
extern ExcInfo g_excInfo;
|
||||
|
||||
#define MAX_INT_INFO_SIZE (8 + 0x164)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_INTERRUPT_H */
|
||||
@@ -1,51 +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 _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
@@ -1,144 +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 "los_context.h"
|
||||
#include "securec.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
STATIC UINT32 g_sysNeedSched = FALSE;
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchInit
|
||||
Description : arch init function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
HalHwiInit();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchSysExit
|
||||
Description : Task exit function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
|
||||
{
|
||||
LOS_IntLock();
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchTskStackInit
|
||||
Description : Task stack initialization function
|
||||
Input : taskID --- TaskID
|
||||
stackSize --- Total size of the stack
|
||||
topStack --- Top of task's stack
|
||||
Output : None
|
||||
Return : Context pointer
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = NULL;
|
||||
errno_t result;
|
||||
|
||||
/* initialize the task stack, write magic num to stack top */
|
||||
result = memset_s(topStack, stackSize, (INT32)(OS_TASK_STACK_INIT & 0xFF), stackSize);
|
||||
if (result != EOK) {
|
||||
printf("memset_s is failed:%s[%d]\r\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
*((UINT32 *)(topStack)) = OS_TASK_MAGIC_WORD;
|
||||
|
||||
context = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));
|
||||
|
||||
context->R0 = taskID;
|
||||
context->R1 = 0x01010101L;
|
||||
context->R2 = 0x02020202L;
|
||||
context->R3 = 0x03030303L;
|
||||
context->R4 = 0x04040404L;
|
||||
context->R5 = 0x05050505L;
|
||||
context->R6 = 0x06060606L;
|
||||
context->R7 = 0x07070707L;
|
||||
context->R8 = 0x08080808L;
|
||||
context->R9 = 0x09090909L;
|
||||
context->R10 = 0x10101010L;
|
||||
context->R11 = 0x11111111L;
|
||||
context->R12 = 0x12121212L;
|
||||
context->R13 = 0x13131313L;
|
||||
context->R15 = (UINT32)ArchSysExit;
|
||||
context->EPSR = 0xe0000144L;
|
||||
context->EPC = (UINT32)OsTaskEntry;
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
OsSchedStart();
|
||||
HalStartToRun();
|
||||
return LOS_OK; /* never return */
|
||||
}
|
||||
|
||||
VOID HalIrqEndCheckNeedSched(VOID)
|
||||
{
|
||||
if (g_sysNeedSched && g_taskScheduled && LOS_CHECK_SCHEDULE) {
|
||||
ArchTaskSchedule();
|
||||
}
|
||||
}
|
||||
|
||||
VOID ArchTaskSchedule(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
g_sysNeedSched = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_sysNeedSched = FALSE;
|
||||
BOOL isSwitch = OsSchedTaskSwitch();
|
||||
if (isSwitch) {
|
||||
HalTaskContextSwitch();
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
return;
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2020, 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.
|
||||
*/
|
||||
|
||||
#define OS_TASK_STATUS_RUNNING 0x0010
|
||||
#define VIC_TSPDR 0XE000EC08
|
||||
|
||||
.section .text
|
||||
.align 2
|
||||
.type HalStartToRun, %function
|
||||
.global HalStartToRun
|
||||
HalStartToRun:
|
||||
lrw r1, g_losTask
|
||||
lrw r2, g_losTask + 4
|
||||
|
||||
ldw r0, (r2)
|
||||
|
||||
st.w r0, (r1)
|
||||
st.w r0, (r2)
|
||||
|
||||
ldw sp, (r0)
|
||||
|
||||
ldw r0, (sp, 64)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 60)
|
||||
mtcr r0, epsr
|
||||
ldw r15, (sp, 56)
|
||||
ldm r0-r13, (sp)
|
||||
|
||||
rte
|
||||
|
||||
.align 2
|
||||
.type HalTaskContextSwitch, %function
|
||||
.global HalTaskContextSwitch
|
||||
HalTaskContextSwitch:
|
||||
|
||||
subi sp, 68
|
||||
stm r0-r13, (sp)
|
||||
stw r15, (sp, 56)
|
||||
mfcr r1, psr
|
||||
stw r1, (sp, 60)
|
||||
stw r15, (sp, 64)
|
||||
lrw r2, g_losTask
|
||||
ldw r0, (r2)
|
||||
stw sp, (r0)
|
||||
|
||||
lrw r3, g_losTask + 4
|
||||
ldw r0, (r3)
|
||||
stw r0, (r2)
|
||||
|
||||
ldw sp, (r0)
|
||||
ldw r0, (sp, 64)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 60)
|
||||
mtcr r0, epsr
|
||||
ldw r15, (sp, 56)
|
||||
ldm r0-r13, (sp)
|
||||
|
||||
addi sp, 68
|
||||
|
||||
rte
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2020, 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 HalExcHandleEntry
|
||||
.extern g_trapStackBase
|
||||
|
||||
.section .text
|
||||
.align 2
|
||||
.global HandleEntry
|
||||
HandleEntry:
|
||||
mov r10, sp
|
||||
lrw r14, g_trapStackBase
|
||||
|
||||
stm r0-r15, (sp)
|
||||
stw r10, (sp, 56)
|
||||
mfcr r0, epsr
|
||||
stw r0, (sp, 64)
|
||||
mfcr r0, epc
|
||||
stw r0, (sp, 68)
|
||||
mov r0, sp
|
||||
|
||||
mfcr r1, epc
|
||||
|
||||
mov sp, r10
|
||||
lrw r2, HalExcHandleEntry
|
||||
jmp r2
|
||||
|
||||
.section .text
|
||||
.align 2
|
||||
.global IrqEntry
|
||||
IrqEntry:
|
||||
psrset ee
|
||||
subi sp, 72
|
||||
stm r0-r15, (sp)
|
||||
mfcr r0, epsr
|
||||
stw r0, (sp, 64)
|
||||
mfcr r0, epc
|
||||
stw r0, (sp, 68)
|
||||
|
||||
jbsr HalInterrupt
|
||||
|
||||
ldw r0, (sp, 68)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 64)
|
||||
bseti r0, r0, 6
|
||||
mtcr r0, epsr
|
||||
ldm r0-r15, (sp)
|
||||
addi sp, 72
|
||||
rte
|
||||
@@ -1,580 +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 "los_interrupt.h"
|
||||
#include <stdarg.h>
|
||||
#include "securec.h"
|
||||
#include "los_context.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
|
||||
#define INT_OFFSET 6
|
||||
#define PRI_OFF_PER_INT 8
|
||||
#define PRI_PER_REG 4
|
||||
#define PRI_OFF_IN_REG 6
|
||||
#define PRI_BITS 2
|
||||
#define PRI_HI 0
|
||||
#define PRI_LOW 7
|
||||
#define MASK_8_BITS 0xFF
|
||||
#define MASK_32_BITS 0xFFFFFFFF
|
||||
#define BYTES_OF_128_INT 4
|
||||
#define TIM_INT_NUM 1
|
||||
|
||||
#define OS_USER_HWI_MIN 0
|
||||
#define OS_USER_HWI_MAX (LOSCFG_PLATFORM_HWI_LIMIT - 1)
|
||||
#define HWI_ALIGNSIZE 0x400
|
||||
|
||||
UINT32 g_intCount = 0;
|
||||
CHAR g_trapStackBase[OS_TRAP_STACK_SIZE];
|
||||
|
||||
VIC_TYPE *VIC_REG = (VIC_TYPE *)VIC_REG_BASE;
|
||||
|
||||
UINT32 HwiNumValid(UINT32 num)
|
||||
{
|
||||
return ((num) >= OS_USER_HWI_MIN) && ((num) <= OS_USER_HWI_MAX);
|
||||
}
|
||||
|
||||
UINT32 HalGetPsr(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ volatile("mfcr %0, psr" : "=r" (intSave) : : "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
UINT32 HalSetVbr(UINT32 intSave)
|
||||
{
|
||||
__asm__ volatile("mtcr %0, vbr" : : "r"(intSave) : "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
UINT32 ArchIntLock(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__(
|
||||
"mfcr %0, psr \n"
|
||||
"psrclr ie"
|
||||
: "=r"(intSave)
|
||||
:
|
||||
: "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
UINT32 ArchIntUnLock(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__(
|
||||
"mfcr %0, psr \n"
|
||||
"psrset ie"
|
||||
: "=r"(intSave)
|
||||
:
|
||||
: "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
VOID ArchIntRestore(UINT32 intSave)
|
||||
{
|
||||
__asm__ __volatile__("mtcr %0, psr" : : "r"(intSave));
|
||||
}
|
||||
|
||||
UINT32 ArchIntLocked(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ volatile("mfcr %0, psr" : "=r" (intSave) : : "memory");
|
||||
return !(intSave & (1 << INT_OFFSET));
|
||||
}
|
||||
|
||||
UINT32 HalIrqUnmask(UINT32 hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
VIC_REG->ISER[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
|
||||
VIC_REG->ISSR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 HalIrqSetPriority(UINT32 hwiNum, UINT8 priority)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
if (!HWI_PRI_VALID(priority)) {
|
||||
return OS_ERRNO_HWI_PRIO_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
VIC_REG->IPR[hwiNum / PRI_PER_REG] |= (((priority << PRI_OFF_IN_REG) << (hwiNum % PRI_PER_REG)) * PRI_OFF_PER_INT);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 HalIrqMask(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
VIC_REG->ICER[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 HalIrqPending(UINT32 hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
VIC_REG->ISPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 HalIrqClear(UINT32 hwiNum)
|
||||
{
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return LOS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
VIC_REG->ICPR[hwiNum / OS_SYS_VECTOR_CNT] = (UINT32)(1UL << (hwiNum % OS_SYS_VECTOR_CNT));
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC __attribute__((aligned(HWI_ALIGNSIZE))) g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
HWI_PROC_FUNC pfnHandler;
|
||||
VOID *pParm;
|
||||
} HWI_HANDLER_FUNC;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)IrqEntry;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg;
|
||||
HalIrqUnmask(num);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = IrqEntry;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector;
|
||||
HalIrqUnmask(num);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalIntNumGet
|
||||
Description : Get an interrupt number
|
||||
Input : None
|
||||
Output : None
|
||||
Return : Interrupt Indexes number
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR UINT32 HalIntNumGet(VOID)
|
||||
{
|
||||
return HalGetPsr();
|
||||
}
|
||||
|
||||
inline UINT32 ArchIsIntActive(VOID)
|
||||
{
|
||||
return (g_intCount > 0);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiDefaultHandler
|
||||
Description : default handler of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_MINOR VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HalIntNumGet();
|
||||
irqNum = (irqNum >> PSR_VEC_OFFSET) & MASK_8_BITS;
|
||||
PRINT_ERR("%s irqnum:%x\n", __FUNCTION__, irqNum);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
WEAK VOID HalPreInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WEAK VOID HalAftInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalInterrupt
|
||||
Description : Hardware interrupt entry function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT VOID HalInterrupt(VOID)
|
||||
{
|
||||
UINT32 hwiIndex;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount++;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
hwiIndex = HalIntNumGet();
|
||||
hwiIndex = (hwiIndex >> PSR_VEC_OFFSET) & MASK_8_BITS;
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
if (g_hwiHandlerForm[hwiIndex].pfnHandler != 0) {
|
||||
g_hwiHandlerForm[hwiIndex].pfnHandler((VOID *)g_hwiHandlerForm[hwiIndex].pParm);
|
||||
}
|
||||
#else
|
||||
if (g_hwiHandlerForm[hwiIndex] != 0) {
|
||||
g_hwiHandlerForm[hwiIndex]();
|
||||
}
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount--;
|
||||
HalIrqEndCheckNeedSched();
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchHwiCreate
|
||||
Description : create hardware interrupt
|
||||
Input : hwiNum --- hwi num to create
|
||||
hwiPrio --- priority of the hwi
|
||||
mode --- unused
|
||||
handler --- hwi handler
|
||||
arg --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
if (g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] != 0) {
|
||||
return OS_ERRNO_HWI_ALREADY_CREATED;
|
||||
}
|
||||
if (g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] != 0) {
|
||||
return OS_ERRNO_HWI_ALREADY_CREATED;
|
||||
}
|
||||
if (hwiPrio > OS_HWI_PRIO_LOWEST) {
|
||||
return OS_ERRNO_HWI_PRIO_INVALID;
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
#else
|
||||
OsSetVector(hwiNum, handler);
|
||||
#endif
|
||||
HalIrqUnmask(hwiNum);
|
||||
(VOID)HalIrqSetPriority(hwiNum, (UINT8)hwiPrio);
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
HalIrqMask(hwiNum);
|
||||
intSave = LOS_IntLock();
|
||||
g_hwiHandlerForm[hwiNum + OS_SYS_VECTOR_CNT] = 0;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ExcInfo g_excInfo = {0};
|
||||
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
STATIC VOID OsExcTypeInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
CHAR *phaseStr[] = {"exc in init", "exc in task", "exc in hwi"};
|
||||
|
||||
PRINTK("Type = %d\n", excInfo->type);
|
||||
PRINTK("ThrdPid = %d\n", excInfo->thrdPid);
|
||||
PRINTK("Phase = %s\n", phaseStr[excInfo->phase]);
|
||||
PRINTK("FaultAddr = 0x%x\n", excInfo->faultAddr);
|
||||
}
|
||||
|
||||
STATIC VOID OsExcCurTaskInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
PRINTK("Current task info:\n");
|
||||
if (excInfo->phase == OS_EXC_IN_TASK) {
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
|
||||
PRINTK("Task name = %s\n", taskCB->taskName);
|
||||
PRINTK("Task ID = %d\n", taskCB->taskID);
|
||||
PRINTK("Task SP = 0x%x\n", (UINTPTR)taskCB->stackPointer);
|
||||
PRINTK("Task ST = 0x%x\n", taskCB->topOfStack);
|
||||
PRINTK("Task SS = 0x%x\n", taskCB->stackSize);
|
||||
} else if (excInfo->phase == OS_EXC_IN_HWI) {
|
||||
PRINTK("Exception occur in interrupt phase!\n");
|
||||
} else {
|
||||
PRINTK("Exception occur in system init phase!\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsExcRegInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
EXC_CONTEXT_S *excContext = excInfo->context;
|
||||
PRINTK("Exception reg dump:\n");
|
||||
PRINTK("R0 = 0x%x\n"
|
||||
"R1 = 0x%x\n"
|
||||
"R2 = 0x%x\n"
|
||||
"R3 = 0x%x\n"
|
||||
"R4 = 0x%x\n"
|
||||
"R5 = 0x%x\n"
|
||||
"R6 = 0x%x\n"
|
||||
"R7 = 0x%x\n"
|
||||
"R8 = 0x%x\n"
|
||||
"R9 = 0x%x\n"
|
||||
"R10 = 0x%x\n"
|
||||
"R11 = 0x%x\n"
|
||||
"R12 = 0x%x\n"
|
||||
"R13 = 0x%x\n"
|
||||
"R14 = 0x%x\n"
|
||||
"R15 = 0x%x\n"
|
||||
"EPSR = 0x%x\n"
|
||||
"EPC = 0x%x\n",
|
||||
excContext->R0, excContext->R1, excContext->R2, excContext->R3, excContext->R4, excContext->R5,
|
||||
excContext->R6, excContext->R7, excContext->R8, excContext->R9, excContext->R10, excContext->R11,
|
||||
excContext->R12, excContext->R13, excContext->R14, excContext->R15, excContext->EPSR,
|
||||
excContext->EPC);
|
||||
}
|
||||
|
||||
STATIC VOID OsExcBackTraceInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
UINTPTR LR[LOSCFG_BACKTRACE_DEPTH] = {0};
|
||||
UINT32 index;
|
||||
|
||||
OsBackTraceHookCall(LR, LOSCFG_BACKTRACE_DEPTH, 0, excInfo->context->R14);
|
||||
|
||||
PRINTK("----- backtrace start -----\n");
|
||||
for (index = 0; index < LOSCFG_BACKTRACE_DEPTH; index++) {
|
||||
if (LR[index] == 0) {
|
||||
break;
|
||||
}
|
||||
PRINTK("backtrace %d -- lr = 0x%x\n", index, LR[index]);
|
||||
}
|
||||
PRINTK("----- backtrace end -----\n");
|
||||
}
|
||||
|
||||
STATIC VOID OsExcMemPoolCheckInfo(VOID)
|
||||
{
|
||||
PRINTK("\r\nmemory pools check:\n");
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
MemInfoCB memExcInfo[OS_SYS_MEM_NUM];
|
||||
UINT32 errCnt;
|
||||
UINT32 i;
|
||||
|
||||
(VOID)memset_s(memExcInfo, sizeof(memExcInfo), 0, sizeof(memExcInfo));
|
||||
|
||||
errCnt = OsMemExcInfoGet(OS_SYS_MEM_NUM, memExcInfo);
|
||||
if (errCnt < OS_SYS_MEM_NUM) {
|
||||
errCnt += OsMemboxExcInfoGet(OS_SYS_MEM_NUM - errCnt, memExcInfo + errCnt);
|
||||
}
|
||||
|
||||
if (errCnt == 0) {
|
||||
PRINTK("all memory pool check passed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < errCnt; i++) {
|
||||
PRINTK("pool num = %d\n", i);
|
||||
PRINTK("pool type = %d\n", memExcInfo[i].type);
|
||||
PRINTK("pool addr = 0x%x\n", memExcInfo[i].startAddr);
|
||||
PRINTK("pool size = 0x%x\n", memExcInfo[i].size);
|
||||
PRINTK("pool free = 0x%x\n", memExcInfo[i].free);
|
||||
PRINTK("pool blkNum = %d\n", memExcInfo[i].blockSize);
|
||||
PRINTK("pool error node addr = 0x%x\n", memExcInfo[i].errorAddr);
|
||||
PRINTK("pool error node len = 0x%x\n", memExcInfo[i].errorLen);
|
||||
PRINTK("pool error node owner = %d\n", memExcInfo[i].errorOwner);
|
||||
}
|
||||
#endif
|
||||
UINT32 ret = LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR);
|
||||
if (ret == LOS_OK) {
|
||||
PRINTK("system heap memcheck over, all passed!\n");
|
||||
}
|
||||
|
||||
PRINTK("memory pool check end!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
PRINTK("*************Exception Information**************\n");
|
||||
OsExcTypeInfo(excInfo);
|
||||
OsExcCurTaskInfo(excInfo);
|
||||
OsExcRegInfo(excInfo);
|
||||
OsExcBackTraceInfo(excInfo);
|
||||
OsGetAllTskInfo();
|
||||
OsExcMemPoolCheckInfo();
|
||||
#endif
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalExcHandleEntry(EXC_CONTEXT_S *excBufAddr, UINT32 faultAddr)
|
||||
{
|
||||
UINT16 tmpFlag = ((excBufAddr->EPSR >> PSR_VEC_OFFSET) & MASK_8_BITS);
|
||||
g_excInfo.nestCnt++;
|
||||
UINT32 excType = (HalGetPsr() >> PSR_VEC_OFFSET) & MASK_8_BITS;
|
||||
g_excInfo.type = excType;
|
||||
|
||||
g_excInfo.faultAddr = faultAddr;
|
||||
|
||||
if (g_losTask.runTask != NULL) {
|
||||
if (tmpFlag > 0) {
|
||||
g_excInfo.phase = OS_EXC_IN_HWI;
|
||||
g_excInfo.thrdPid = tmpFlag;
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_TASK;
|
||||
g_excInfo.thrdPid = g_losTask.runTask->taskID;
|
||||
}
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_INIT;
|
||||
g_excInfo.thrdPid = OS_NULL_INT;
|
||||
}
|
||||
g_excInfo.context = excBufAddr;
|
||||
|
||||
OsDoExcHook(EXC_INTERRUPT);
|
||||
OsExcInfoDisplay(&g_excInfo);
|
||||
ArchSysExit();
|
||||
}
|
||||
|
||||
/* stack protector */
|
||||
WEAK UINT32 __stack_chk_guard = 0xd00a0dff;
|
||||
|
||||
WEAK VOID __stack_chk_fail(VOID)
|
||||
{
|
||||
/* __builtin_return_address is a builtin function, building in gcc */
|
||||
LOS_Panic("stack-protector: Kernel stack is corrupted in: %x\n",
|
||||
__builtin_return_address(0));
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiInit
|
||||
Description : initialization of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT VOID HalHwiInit(VOID)
|
||||
{
|
||||
UINT32 i;
|
||||
|
||||
for (i = 1; i < OS_SYS_VECTOR_CNT; i++) {
|
||||
g_hwiForm[i] = (HWI_PROC_FUNC)HandleEntry;
|
||||
}
|
||||
|
||||
for (i = OS_SYS_VECTOR_CNT; i < (LOSCFG_PLATFORM_HWI_LIMIT + OS_SYS_VECTOR_CNT); i++) {
|
||||
g_hwiForm[i] = (HWI_PROC_FUNC)IrqEntry;
|
||||
}
|
||||
|
||||
HalSetVbr((UINT32)&g_hwiForm);
|
||||
for (int i = 0; i < BYTES_OF_128_INT; i++) {
|
||||
VIC_REG->IABR[i] = 0x0;
|
||||
VIC_REG->ICPR[i] = MASK_32_BITS;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,151 +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 "los_timer.h"
|
||||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
typedef struct {
|
||||
UINT32 CTRL;
|
||||
UINT32 LOAD;
|
||||
UINT32 VAL;
|
||||
UINT32 CALIB;
|
||||
} CORE_TIM_TYPE;
|
||||
|
||||
#define OS_CYCLE_PER_TICK (OS_SYS_CLOCK / LOSCFG_BASE_CORE_TICK_PER_SECOND)
|
||||
|
||||
#define CORE_TIM_BASE (0xE000E010UL)
|
||||
#define SysTick ((CORE_TIM_TYPE *)CORE_TIM_BASE)
|
||||
|
||||
#define CORETIM_ENABLE (1UL << 0)
|
||||
#define CORETIM_INTMASK (1UL << 1)
|
||||
#define CORETIM_SOURCE (1UL << 2)
|
||||
#define CORETIM_MODE (1UL << 16)
|
||||
|
||||
#define TIM_INT_NUM 1
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = 0,
|
||||
.irqNum = TIM_INT_NUM,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalTickStart
|
||||
Description : Configure Tick Interrupt Start
|
||||
Input : none
|
||||
output : none
|
||||
return : LOS_OK - Success , or LOS_ERRNO_TICK_CFG_INVALID - failed
|
||||
**************************************************************************** */
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
tick->freq = OS_SYS_CLOCK;
|
||||
|
||||
SysTick->LOAD = (OS_CYCLE_PER_TICK - 1);
|
||||
SysTick->VAL = 0;
|
||||
SysTick->CTRL |= (CORETIM_SOURCE | CORETIM_ENABLE | CORETIM_INTMASK);
|
||||
|
||||
VIC_REG->IWER[0] = 0x1 << TIM_INT_NUM;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
SysTick->CTRL &= ~CORETIM_ENABLE;
|
||||
SysTick->LOAD = (UINT32)(nextResponseTime - 1UL); /* set reload register */
|
||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||
SysTick->CTRL |= CORETIM_ENABLE;
|
||||
}
|
||||
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 hwCycle;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
*period = SysTick->LOAD;
|
||||
hwCycle = *period - SysTick->VAL;
|
||||
LOS_IntRestore(intSave);
|
||||
return (UINT64)hwCycle;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
SysTick->CTRL &= ~CORETIM_ENABLE;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
SysTick->CTRL |= CORETIM_ENABLE;
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
VOID Wfi(VOID)
|
||||
{
|
||||
__asm__ volatile("wait");
|
||||
}
|
||||
|
||||
VOID Dsb(VOID)
|
||||
{
|
||||
__asm__ volatile("sync" : : : "memory");
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
Dsb();
|
||||
Wfi();
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -1,254 +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 _LOS_ATOMIC_H
|
||||
#define _LOS_ATOMIC_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef volatile INT32 Atomic;
|
||||
typedef volatile INT64 Atomic64;
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicRead(const Atomic *v)
|
||||
{
|
||||
return *v;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomicSet(Atomic *v, INT32 setVal)
|
||||
{
|
||||
*v = setVal;
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicAdd(Atomic *v, INT32 addVal)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
*v += addVal;
|
||||
val = *v;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicSub(Atomic *v, INT32 subVal)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
*v -= subVal;
|
||||
val = *v;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomicInc(Atomic *v)
|
||||
{
|
||||
(VOID)ArchAtomicAdd(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomicDec(Atomic *v)
|
||||
{
|
||||
(VOID)ArchAtomicSub(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicIncRet(Atomic *v)
|
||||
{
|
||||
return ArchAtomicAdd(v, 1);
|
||||
}
|
||||
|
||||
#ifndef ARCH_ARM
|
||||
STATIC INLINE INT32 ArchAtomicDecRet(Atomic *v)
|
||||
{
|
||||
return ArchAtomicSub(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT32 ArchAtomicXchg32bits(Atomic *v, INT32 val)
|
||||
{
|
||||
INT32 prevVal;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
prevVal = *v;
|
||||
*v = val;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL ArchAtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal)
|
||||
{
|
||||
INT32 prevVal;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
prevVal = *v;
|
||||
if (prevVal == oldVal) {
|
||||
*v = val;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64Read(const Atomic64 *v)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
val = *v;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomic64Set(Atomic64 *v, INT64 setVal)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
*v = setVal;
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64Add(Atomic64 *v, INT64 addVal)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
*v += addVal;
|
||||
val = *v;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64Sub(Atomic64 *v, INT64 subVal)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
*v -= subVal;
|
||||
val = *v;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomic64Inc(Atomic64 *v)
|
||||
{
|
||||
(VOID)ArchAtomic64Add(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64IncRet(Atomic64 *v)
|
||||
{
|
||||
return ArchAtomic64Add(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchAtomic64Dec(Atomic64 *v)
|
||||
{
|
||||
(VOID)ArchAtomic64Sub(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomic64DecRet(Atomic64 *v)
|
||||
{
|
||||
return ArchAtomic64Sub(v, 1);
|
||||
}
|
||||
|
||||
STATIC INLINE INT64 ArchAtomicXchg64bits(Atomic64 *v, INT64 val)
|
||||
{
|
||||
INT64 prevVal;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
prevVal = *v;
|
||||
*v = val;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL ArchAtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal)
|
||||
{
|
||||
INT64 prevVal;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
prevVal = *v;
|
||||
if (prevVal == oldVal) {
|
||||
*v = val;
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
|
||||
#define LOS_AtomicRead ArchAtomicRead
|
||||
#define LOS_AtomicSet ArchAtomicSet
|
||||
#define LOS_AtomicAdd ArchAtomicAdd
|
||||
#define LOS_AtomicSub ArchAtomicSub
|
||||
#define LOS_AtomicInc ArchAtomicInc
|
||||
#define LOS_AtomicIncRet ArchAtomicIncRet
|
||||
#define LOS_AtomicDec ArchAtomicDec
|
||||
#define LOS_AtomicDecRet ArchAtomicDecRet
|
||||
#define LOS_Atomic64Read ArchAtomic64Read
|
||||
#define LOS_Atomic64Set ArchAtomic64Set
|
||||
#define LOS_Atomic64Add ArchAtomic64Add
|
||||
#define LOS_Atomic64Sub ArchAtomic64Sub
|
||||
#define LOS_Atomic64Inc ArchAtomic64Inc
|
||||
#define LOS_Atomic64IncRet ArchAtomic64IncRet
|
||||
#define LOS_Atomic64Dec ArchAtomic64Dec
|
||||
#define LOS_Atomic64DecRet ArchAtomic64DecRet
|
||||
#define LOS_AtomicXchg32bits ArchAtomicXchg32bits
|
||||
#define LOS_AtomicXchg64bits ArchAtomicXchg64bits
|
||||
#define LOS_AtomicCmpXchg32bits ArchAtomicCmpXchg32bits
|
||||
#define LOS_AtomicCmpXchg64bits ArchAtomicCmpXchg64bits
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ATOMIC_H */
|
||||
|
||||
@@ -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_m/liteos.gni")
|
||||
|
||||
module_group("risc-v") {
|
||||
modules = [ "riscv32/gcc" ]
|
||||
}
|
||||
@@ -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_m/liteos.gni")
|
||||
|
||||
module_group("xtensa") {
|
||||
modules = [ "lx6/gcc" ]
|
||||
}
|
||||
@@ -1,46 +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_m/liteos.gni")
|
||||
|
||||
module_name = "arch"
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"los_context.c",
|
||||
"los_dispatch.S",
|
||||
"los_exc.S",
|
||||
"los_interrupt.c",
|
||||
"los_timer.c",
|
||||
"los_window.S",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ARCH_INTERRUPT_H
|
||||
#define _LOS_ARCH_INTERRUPT_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_interrupt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct {
|
||||
UINT32 pc;
|
||||
UINT32 ps;
|
||||
UINT32 regA[16];
|
||||
UINT32 sar;
|
||||
UINT32 excCause;
|
||||
UINT32 excVaddr;
|
||||
UINT32 lbeg;
|
||||
UINT32 lend;
|
||||
UINT32 lcount;
|
||||
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
|
||||
UINT32 temp;
|
||||
UINT16 cpenable;
|
||||
UINT16 cpstored;
|
||||
UINT32 fcr;
|
||||
UINT32 fsr;
|
||||
UINT32 regF[16];
|
||||
#endif
|
||||
UINT32 res[4];
|
||||
} EXC_CONTEXT_S;
|
||||
|
||||
#define VECTOR_START _init_start
|
||||
extern CHAR *VECTOR_START;
|
||||
#define INIT_VECTOR_START ((UINTPTR)&VECTOR_START)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Maximum number of used hardware interrupts.
|
||||
*/
|
||||
#ifndef OS_HWI_MAX_NUM
|
||||
#define OS_HWI_MAX_NUM LOSCFG_PLATFORM_HWI_LIMIT
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Highest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_HIGHEST
|
||||
#define OS_HWI_PRIO_HIGHEST 0
|
||||
#endif
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Lowest priority of a hardware interrupt.
|
||||
*/
|
||||
#ifndef OS_HWI_PRIO_LOWEST
|
||||
#define OS_HWI_PRIO_LOWEST 7
|
||||
#endif
|
||||
|
||||
#define OS_EXC_IN_INIT 0
|
||||
#define OS_EXC_IN_TASK 1
|
||||
#define OS_EXC_IN_HWI 2
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Define the type of a hardware interrupt vector table function.
|
||||
*/
|
||||
typedef VOID (**HWI_VECTOR_FUNC)(VOID);
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern UINT32 g_intCount;
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of Xtensa system interrupt vector.
|
||||
*/
|
||||
#define OS_SYS_VECTOR_CNT 0
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Count of Xtensa interrupt vector.
|
||||
*/
|
||||
#define OS_VECTOR_CNT (OS_SYS_VECTOR_CNT + OS_HWI_MAX_NUM)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt number.
|
||||
*
|
||||
* Value: 0x02000900
|
||||
*
|
||||
* Solution: Ensure that the interrupt number is valid.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Null hardware interrupt handling function.
|
||||
*
|
||||
* Value: 0x02000901
|
||||
*
|
||||
* Solution: Pass in a valid non-null hardware interrupt handling function.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation.
|
||||
*
|
||||
* Value: 0x02000902
|
||||
*
|
||||
* Solution: Increase the configured maximum number of supported hardware interrupts.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Insufficient memory for hardware interrupt initialization.
|
||||
*
|
||||
* Value: 0x02000903
|
||||
*
|
||||
* Solution: Expand the configured memory.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: The interrupt has already been created.
|
||||
*
|
||||
* Value: 0x02000904
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Invalid interrupt priority.
|
||||
*
|
||||
* Value: 0x02000905
|
||||
*
|
||||
* Solution: Ensure that the interrupt priority is valid.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: Incorrect interrupt creation mode.
|
||||
*
|
||||
* Value: 0x02000906
|
||||
*
|
||||
* Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06)
|
||||
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Hardware interrupt error code: The interrupt has already been created as a fast interrupt.
|
||||
*
|
||||
* Value: 0x02000907
|
||||
*
|
||||
* Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07)
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg);
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_arch_interrupt
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
extern VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector);
|
||||
#endif
|
||||
|
||||
VOID HalInterrupt(VOID);
|
||||
UINT32 HalIntNumGet(VOID);
|
||||
VOID HalHwiDefaultHandler(VOID);
|
||||
VOID HalExcHandleEntry(UINTPTR faultAddr, EXC_CONTEXT_S *excBufAddr, UINT32 type);
|
||||
VOID HalHwiInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Exception information structure
|
||||
*
|
||||
* Description: Exception information saved when an exception is triggered on the Xtensa platform.
|
||||
*
|
||||
*/
|
||||
typedef struct TagExcInfo {
|
||||
UINT16 phase;
|
||||
UINT16 type;
|
||||
UINT32 faultAddr;
|
||||
UINT32 thrdPid;
|
||||
UINT16 nestCnt;
|
||||
UINT16 reserved;
|
||||
EXC_CONTEXT_S *context;
|
||||
} ExcInfo;
|
||||
|
||||
extern UINT32 g_curNestCount;
|
||||
extern ExcInfo g_excInfo;
|
||||
|
||||
#define MAX_INT_INFO_SIZE (8 + 0x164)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_INTERRUPT_H */
|
||||
@@ -1,171 +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 _LOS_ARCH_MACRO_H
|
||||
#define _LOS_ARCH_MACRO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
.macro POP_ALL_REG SP PC PState
|
||||
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
|
||||
l16ui a3, \SP, CONTEXT_OFF_CPENABLE
|
||||
wsr a3, CPENABLE
|
||||
rsync
|
||||
l16ui a3, \SP, CONTEXT_OFF_CPSTORED
|
||||
bbci.l a3, 0, 2f
|
||||
|
||||
l32i a3, \SP, CONTEXT_OFF_FCR
|
||||
wur.FCR a3
|
||||
l32i a3, \SP, CONTEXT_OFF_FSR
|
||||
wur.FSR a3
|
||||
|
||||
lsi f0, \SP, CONTEXT_OFF_F0
|
||||
lsi f1, \SP, CONTEXT_OFF_F1
|
||||
lsi f2, \SP, CONTEXT_OFF_F2
|
||||
lsi f3, \SP, CONTEXT_OFF_F3
|
||||
lsi f4, \SP, CONTEXT_OFF_F4
|
||||
lsi f5, \SP, CONTEXT_OFF_F5
|
||||
lsi f6, \SP, CONTEXT_OFF_F6
|
||||
lsi f7, \SP, CONTEXT_OFF_F7
|
||||
lsi f8, \SP, CONTEXT_OFF_F8
|
||||
lsi f9, \SP, CONTEXT_OFF_F9
|
||||
lsi f10, \SP, CONTEXT_OFF_F10
|
||||
lsi f11, \SP, CONTEXT_OFF_F11
|
||||
lsi f12, \SP, CONTEXT_OFF_F12
|
||||
lsi f13, \SP, CONTEXT_OFF_F13
|
||||
lsi f14, \SP, CONTEXT_OFF_F14
|
||||
lsi f15, \SP, CONTEXT_OFF_F15
|
||||
|
||||
2:
|
||||
movi a4, 0
|
||||
s16i a4, \SP, CONTEXT_OFF_CPSTORED
|
||||
#endif
|
||||
l32i a3, \SP, CONTEXT_OFF_LBEG
|
||||
l32i a4, \SP, CONTEXT_OFF_LEND
|
||||
wsr a3, LBEG
|
||||
l32i a3, \SP, CONTEXT_OFF_LCOUNT
|
||||
wsr a4, LEND
|
||||
wsr a3, LCOUNT
|
||||
l32i a3, \SP, CONTEXT_OFF_SAR
|
||||
l32i a1, \SP, CONTEXT_OFF_A1
|
||||
wsr a3, SAR
|
||||
l32i a3, \SP, CONTEXT_OFF_A3
|
||||
l32i a4, \SP, CONTEXT_OFF_A4
|
||||
l32i a5, \SP, CONTEXT_OFF_A5
|
||||
l32i a6, \SP, CONTEXT_OFF_A6
|
||||
l32i a7, \SP, CONTEXT_OFF_A7
|
||||
l32i a8, \SP, CONTEXT_OFF_A8
|
||||
l32i a9, \SP, CONTEXT_OFF_A9
|
||||
l32i a10, \SP, CONTEXT_OFF_A10
|
||||
l32i a11, \SP, CONTEXT_OFF_A11
|
||||
l32i a12, \SP, CONTEXT_OFF_A12
|
||||
l32i a13, \SP, CONTEXT_OFF_A13
|
||||
l32i a14, \SP, CONTEXT_OFF_A14
|
||||
l32i a15, \SP, CONTEXT_OFF_A15
|
||||
l32i a0, \SP, CONTEXT_OFF_PS
|
||||
wsr a0, \PState
|
||||
l32i a0, \SP, CONTEXT_OFF_PC
|
||||
wsr a0, \PC
|
||||
l32i a0, \SP, CONTEXT_OFF_A0
|
||||
l32i a2, \SP, CONTEXT_OFF_A2
|
||||
.endm
|
||||
|
||||
.macro PUSH_ALL_REG SP
|
||||
s32i a0, \SP, CONTEXT_OFF_A0
|
||||
s32i a1, \SP, CONTEXT_OFF_A1
|
||||
s32i a2, \SP, CONTEXT_OFF_A2
|
||||
s32i a3, \SP, CONTEXT_OFF_A3
|
||||
s32i a4, \SP, CONTEXT_OFF_A4
|
||||
s32i a5, \SP, CONTEXT_OFF_A5
|
||||
s32i a6, \SP, CONTEXT_OFF_A6
|
||||
s32i a7, \SP, CONTEXT_OFF_A7
|
||||
s32i a8, \SP, CONTEXT_OFF_A8
|
||||
s32i a9, \SP, CONTEXT_OFF_A9
|
||||
s32i a10, \SP, CONTEXT_OFF_A10
|
||||
s32i a11, \SP, CONTEXT_OFF_A11
|
||||
s32i a12, \SP, CONTEXT_OFF_A12
|
||||
s32i a13, \SP, CONTEXT_OFF_A13
|
||||
s32i a14, \SP, CONTEXT_OFF_A14
|
||||
s32i a15, \SP, CONTEXT_OFF_A15
|
||||
rsr a3, SAR
|
||||
s32i a3, \SP, CONTEXT_OFF_SAR
|
||||
rsr a3, LBEG
|
||||
s32i a3, \SP, CONTEXT_OFF_LBEG
|
||||
rsr a3, LEND
|
||||
s32i a3, \SP, CONTEXT_OFF_LEND
|
||||
rsr a3, LCOUNT
|
||||
s32i a3, \SP, CONTEXT_OFF_LCOUNT
|
||||
rsr a3, PS
|
||||
s32i a3, \SP, CONTEXT_OFF_PS
|
||||
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
|
||||
rsr a3, CPENABLE
|
||||
beqz a3, 1f
|
||||
s16i a3, \SP, CONTEXT_OFF_CPSTORED
|
||||
s16i a3, \SP, CONTEXT_OFF_CPENABLE
|
||||
|
||||
bbci.l a3, 0, 1f
|
||||
rur.FCR a3
|
||||
s32i a3, \SP, CONTEXT_OFF_FCR
|
||||
rur.FSR a3
|
||||
s32i a3, \SP, CONTEXT_OFF_FSR
|
||||
|
||||
ssi f0, \SP, CONTEXT_OFF_F0
|
||||
ssi f1, \SP, CONTEXT_OFF_F1
|
||||
ssi f2, \SP, CONTEXT_OFF_F2
|
||||
ssi f3, \SP, CONTEXT_OFF_F3
|
||||
ssi f4, \SP, CONTEXT_OFF_F4
|
||||
ssi f5, \SP, CONTEXT_OFF_F5
|
||||
ssi f6, \SP, CONTEXT_OFF_F6
|
||||
ssi f7, \SP, CONTEXT_OFF_F7
|
||||
ssi f8, \SP, CONTEXT_OFF_F8
|
||||
ssi f9, \SP, CONTEXT_OFF_F9
|
||||
ssi f10, \SP, CONTEXT_OFF_F10
|
||||
ssi f11, \SP, CONTEXT_OFF_F11
|
||||
ssi f12, \SP, CONTEXT_OFF_F12
|
||||
ssi f13, \SP, CONTEXT_OFF_F13
|
||||
ssi f14, \SP, CONTEXT_OFF_F14
|
||||
ssi f15, \SP, CONTEXT_OFF_F15
|
||||
1:
|
||||
#endif
|
||||
.endm
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_MACRO_H */
|
||||
|
||||
@@ -1,172 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Special Register Fields and Values
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _ARCH_REGS_H
|
||||
#define _ARCH_REGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* PS register -- imprecise exception */
|
||||
#define SPREG_PS_DEPC_SHIFT 4
|
||||
#define SPREG_PS_DEPC_MASK 0x00000004
|
||||
#define SPREG_PS_DEPC SPREG_PS_DEPC_MASK
|
||||
/* PS register -- interrupt part */
|
||||
#define SPREG_PS_DI_SHIFT 3
|
||||
#define SPREG_PS_DI_MASK 0x0000000F
|
||||
#define SPREG_PS_DI SPREG_PS_DI_MASK
|
||||
#define SPREG_PS_DI_DEPC 0x0000000C
|
||||
/* PS register -- stack part */
|
||||
#define SPREG_PS_STACK_SHIFT 5
|
||||
#define SPREG_PS_STACK_MASK 0x000000E0
|
||||
#define SPREG_PS_STACK_INTERRUPT 0x00000000
|
||||
#define SPREG_PS_STACK_CROSS 0x00000020
|
||||
#define SPREG_PS_STACK_IDLE 0x00000040
|
||||
#define SPREG_PS_STACK_KERNEL 0x00000060
|
||||
#define SPREG_PS_STACK_PAGE 0x000000E0
|
||||
#define SPREG_PS_STACK_FIRSTINT 0x00000080
|
||||
#define SPREG_PS_STACK_FIRSTKER 0x000000A0
|
||||
/* PS register -- entry no rotate */
|
||||
#define SPREG_PS_ENTRYNR_SHIFT 22
|
||||
#define SPREG_PS_ENTRYNR_MASK 0x00400000
|
||||
#define SPREG_PS_ENTRYNR SPREG_PS_ENTRYNR_MASK
|
||||
|
||||
/* Exccause Register -- cause */
|
||||
#define SPREG_EXCCAUSE_CAUSE_SHIFT 0
|
||||
#define SPREG_EXCCAUSE_CAUSE_BITS 4
|
||||
#define SPREG_EXCCAUSE_CAUSE_MASK 0x0000000F
|
||||
|
||||
/**
|
||||
* @ingroup Execute level of core
|
||||
*/
|
||||
#define EXEC_LEVEL_APPLICATION_CODE 2
|
||||
#define EXEC_LEVEL_EXCEPTION_HANDLER 3
|
||||
#define EXEC_LEVEL_INTERRUPT_HANDLER 4
|
||||
#define EXEC_LEVEL_NON_INTERRUPTIBLE 5
|
||||
|
||||
/**
|
||||
* @ingroup Schedule Flag stored on Task Context
|
||||
*/
|
||||
#define OS_SCHED_FLAG_TASKPREEMT 4 /* Task Preemted through LOS_Schedule */
|
||||
|
||||
/**
|
||||
* @ingroup Context Fields Define
|
||||
*/
|
||||
#define CONTEXT_OFF_EPC 0
|
||||
#define CONTEXT_OFF_PC 0 /* reuse with EPC */
|
||||
#define CONTEXT_OFF_PS 4
|
||||
#define CONTEXT_OFF_A0 8
|
||||
#define CONTEXT_OFF_A1 12
|
||||
#define CONTEXT_OFF_A2 16
|
||||
#define CONTEXT_OFF_A3 20
|
||||
#define CONTEXT_OFF_A4 24
|
||||
#define CONTEXT_OFF_A5 28
|
||||
#define CONTEXT_OFF_A6 32
|
||||
#define CONTEXT_OFF_A7 36
|
||||
#define CONTEXT_OFF_A8 40
|
||||
#define CONTEXT_OFF_A9 44
|
||||
#define CONTEXT_OFF_A10 48
|
||||
#define CONTEXT_OFF_A11 52
|
||||
#define CONTEXT_OFF_A12 56
|
||||
#define CONTEXT_OFF_A13 60
|
||||
#define CONTEXT_OFF_A14 64
|
||||
#define CONTEXT_OFF_A15 68
|
||||
#define CONTEXT_OFF_RESERVED 72
|
||||
#define CONTEXT_OFF_SAR 72
|
||||
#define CONTEXT_OFF_SCHED_FLAG 76 /* reuse with exccause */
|
||||
#define CONTEXT_OFF_EXCCAUSE 76
|
||||
#define CONTEXT_OFF_EXCVADDR 80
|
||||
#define CONTEXT_OFF_LBEG 84
|
||||
#define CONTEXT_OFF_LEND 88
|
||||
#define CONTEXT_OFF_LCOUNT 92
|
||||
|
||||
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
|
||||
#define CONTEXT_OFF_TMP0 96
|
||||
#define CONTEXT_OFF_CPENABLE 100
|
||||
#define CONTEXT_OFF_CPSTORED 102
|
||||
#define CONTEXT_OFF_FCR 104
|
||||
#define CONTEXT_OFF_FSR 108
|
||||
#define CONTEXT_OFF_F0 112
|
||||
#define CONTEXT_OFF_F1 116
|
||||
#define CONTEXT_OFF_F2 120
|
||||
#define CONTEXT_OFF_F3 124
|
||||
#define CONTEXT_OFF_F4 128
|
||||
#define CONTEXT_OFF_F5 132
|
||||
#define CONTEXT_OFF_F6 136
|
||||
#define CONTEXT_OFF_F7 140
|
||||
#define CONTEXT_OFF_F8 144
|
||||
#define CONTEXT_OFF_F9 148
|
||||
#define CONTEXT_OFF_F10 152
|
||||
#define CONTEXT_OFF_F11 156
|
||||
#define CONTEXT_OFF_F12 160
|
||||
#define CONTEXT_OFF_F13 164
|
||||
#define CONTEXT_OFF_F14 168
|
||||
#define CONTEXT_OFF_F15 172
|
||||
#define CONTEXT_SIZE 192
|
||||
#else
|
||||
#define CONTEXT_SIZE 112
|
||||
#endif
|
||||
#define EXCCAUSE_LEVEL1INTERRUPT 4
|
||||
#define XTENSA_LOGREG_NUM 16
|
||||
#define INDEX_OF_SP 1
|
||||
#define INDEX_OF_ARGS0 6
|
||||
|
||||
#define WINDOWSTARTBITS 16
|
||||
#define WINDOWBASEBITS 4
|
||||
#define WINDOWSTARTMASK ((1 << WINDOWSTARTBITS) - 1)
|
||||
|
||||
#define WOE_ENABLE 0x40000
|
||||
#define BIT_CALLINC 16
|
||||
#define LEVEL_MASK 0xf
|
||||
#define INT_MASK 5
|
||||
#define LEVEL1_INT_MASK 1
|
||||
#define USER_VECTOR_MODE 0x20
|
||||
#define LEVEL1 1
|
||||
#define LEVEL2 2
|
||||
#define LEVEL3 3
|
||||
#define LEVEL4 4
|
||||
#define LEVEL5 5
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _ARCH_REGS_H */
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_ARCH_TIMER_H
|
||||
#define _LOS_ARCH_TIMER_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
VOID SysTick_Handler(VOID);
|
||||
|
||||
#define TIM0_GROUP0 0x3FF5F000
|
||||
#define TIM0_GROUP1 0x3FF60000
|
||||
#define TIM1_GROUP0 0x3FF5F024
|
||||
#define TIM1_GROUP1 0x3FF60024
|
||||
|
||||
#define TIM0_INT_ENABLE_GROUP0 0x3FF5F098
|
||||
#define TIM0_INT_ENABLE_GROUP1 0x3FF60098
|
||||
#define TIM0_INT_CLEAR_GROUP0 0x3FF5F0A4
|
||||
#define TIM0_INT_CLEAR_GROUP1 0x3FF600A4
|
||||
|
||||
typedef struct {
|
||||
UINT32 CTRL;
|
||||
UINT64 VAL;
|
||||
UINT32 UPDATE;
|
||||
UINT64 ALARM;
|
||||
UINT64 LOAD;
|
||||
UINT32 LOAD_TRI;
|
||||
} Systick_t;
|
||||
|
||||
STATIC INLINE UINT32 GetCcount(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__("rsr %0, ccount" : "=a"(intSave) :);
|
||||
return intSave;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ResetCcount(VOID)
|
||||
{
|
||||
__asm__ __volatile__("wsr %0, ccount; rsync" : :"a"(0));
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 GetCcompare(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__("rsr %0, ccompare0" : "=a"(intSave) :);
|
||||
return intSave;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID SetCcompare(UINT32 newCompareVal)
|
||||
{
|
||||
__asm__ __volatile__("wsr %0, ccompare0; rsync" : : "a"(newCompareVal));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_ARCH_TIMER_H */
|
||||
@@ -1,177 +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 "los_context.h"
|
||||
#include "securec.h"
|
||||
#include "los_arch_regs.h"
|
||||
#include "los_arch_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_interrupt.h"
|
||||
#include "los_arch_timer.h"
|
||||
#include "los_timer.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
STATIC UINT32 g_sysNeedSched = FALSE;
|
||||
|
||||
UINT32 g_stackDefault[] = {
|
||||
0x00000000, /* REG_OFF_PC */
|
||||
0x00000000, /* REG_OFF_PS */
|
||||
0x00000A00, /* REG_OFF_AR00 */
|
||||
0x00000A01, /* REG_OFF_AR01 */
|
||||
0x00000A02, /* REG_OFF_AR02 */
|
||||
0x00000A03, /* REG_OFF_AR03 */
|
||||
0x00000A04, /* REG_OFF_AR04 */
|
||||
0x00000A05, /* REG_OFF_AR05 */
|
||||
0x00000A06, /* REG_OFF_AR06 */
|
||||
0x00000A07, /* REG_OFF_AR07 */
|
||||
0x00000A08, /* REG_OFF_AR08 */
|
||||
0x00000A09, /* REG_OFF_AR09 */
|
||||
0x00000A10, /* REG_OFF_AR10 */
|
||||
0x00000A11, /* REG_OFF_AR11 */
|
||||
0x00000A12, /* REG_OFF_AR12 */
|
||||
0x00000A13, /* REG_OFF_AR13 */
|
||||
0x00000A14, /* REG_OFF_AR14 */
|
||||
0x00000A15, /* REG_OFF_AR15 */
|
||||
0x00000000, /* REG_OFF_RESERVED */
|
||||
0x00000000, /* REG_OFF_EXCCAUSE */
|
||||
0x00000000, /* REG_OFF_EXCVASSR */
|
||||
0x00000000, /* REG_OFF_LCOUNT */
|
||||
0x00000000, /* REG_OFF_LEND */
|
||||
0x00000000, /* REG_OFF_LBEG */
|
||||
#if (defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U))
|
||||
0x00000000, /* REG_OFF_TMP0 */
|
||||
0x00000001, /* REG_OFF_CPENABLE | CONTEXT_OFF_CPSTORED */
|
||||
0x00000000, /* REG_OFF_FCR */
|
||||
0x00000000, /* REG_OFF_FSR */
|
||||
0x00000000, /* REG_OFF_F0 */
|
||||
0x00000000, /* REG_OFF_F1 */
|
||||
0x00000000, /* REG_OFF_F2 */
|
||||
0x00000000, /* REG_OFF_F3 */
|
||||
0x00000000, /* REG_OFF_F4 */
|
||||
0x00000000, /* REG_OFF_F5 */
|
||||
0x00000000, /* REG_OFF_F6 */
|
||||
0x00000000, /* REG_OFF_F7 */
|
||||
0x00000000, /* REG_OFF_F8 */
|
||||
0x00000000, /* REG_OFF_F9 */
|
||||
0x00000000, /* REG_OFF_F10 */
|
||||
0x00000000, /* REG_OFF_F11 */
|
||||
0x00000000, /* REG_OFF_F12 */
|
||||
0x00000000, /* REG_OFF_F13 */
|
||||
0x00000000, /* REG_OFF_F14 */
|
||||
0x00000000, /* REG_OFF_F15 */
|
||||
#endif
|
||||
0x00000000, /* REG_OFF_SPILL_RESERVED */
|
||||
0x00000000, /* REG_OFF_SPILL_RESERVED */
|
||||
0x00000000, /* REG_OFF_SPILL_RESERVED */
|
||||
0x00000000, /* REG_OFF_SPILL_RESERVED */
|
||||
};
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID ArchInit(VOID)
|
||||
{
|
||||
HalHwiInit();
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID ArchSysExit(VOID)
|
||||
{
|
||||
LOS_IntLock();
|
||||
while (1) {
|
||||
}
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID *ArchTskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack)
|
||||
{
|
||||
TaskContext *context = NULL;
|
||||
errno_t result;
|
||||
|
||||
/* initialize the task stack, write magic num to stack top */
|
||||
result = memset_s(topStack, stackSize, (INT32)(OS_TASK_STACK_INIT & 0xFF), stackSize);
|
||||
if (result != EOK) {
|
||||
printf("memset_s is failed:%s[%d]\r\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
*((UINT32 *)(topStack)) = OS_TASK_MAGIC_WORD;
|
||||
|
||||
context = (TaskContext *)((((UINTPTR)topStack + stackSize) - sizeof(TaskContext)));
|
||||
|
||||
/* initialize the task context */
|
||||
result = memcpy_s(context, sizeof(TaskContext), g_stackDefault, sizeof(TaskContext));
|
||||
if (result != EOK) {
|
||||
PRINT_ERR("[%s] memcpy_s failed!\n", __func__);
|
||||
}
|
||||
|
||||
context->pc = (UINT32)(UINTPTR)OsTaskEntry;
|
||||
context->regA[INDEX_OF_SP] = (UINTPTR)topStack + stackSize; /* endStack */
|
||||
context->regA[INDEX_OF_ARGS0] = taskID; /* argument1 */
|
||||
context->ps = SPREG_PS_STACK_CROSS | WOE_ENABLE | 1 << BIT_CALLINC; /* set to kernel stack */
|
||||
|
||||
return (VOID *)context;
|
||||
}
|
||||
|
||||
VOID HalStartToRun(VOID)
|
||||
{
|
||||
__asm__ volatile ("call0 OsStartToRun");
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchStartSchedule(VOID)
|
||||
{
|
||||
(VOID)LOS_IntLock();
|
||||
OsSchedStart();
|
||||
HalStartToRun();
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID ArchTaskSchedule(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (OS_INT_ACTIVE) {
|
||||
g_sysNeedSched = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_sysNeedSched = FALSE;
|
||||
BOOL isSwitch = OsSchedTaskSwitch();
|
||||
if (isSwitch) {
|
||||
HalTaskContextSwitch();
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
VOID HalIrqEndCheckNeedSched(VOID)
|
||||
{
|
||||
if (g_sysNeedSched && g_taskScheduled && LOS_CHECK_SCHEDULE) {
|
||||
ArchTaskSchedule();
|
||||
}
|
||||
}
|
||||
@@ -1,128 +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 "los_arch_regs.h"
|
||||
#include "los_arch_macro.h"
|
||||
|
||||
.section .text
|
||||
.literal_position
|
||||
.align 4
|
||||
.type HalTaskContextSwitch, %function
|
||||
.global HalTaskContextSwitch
|
||||
HalTaskContextSwitch:
|
||||
|
||||
entry sp, 16
|
||||
addi a2, sp, -CONTEXT_SIZE
|
||||
PUSH_ALL_REG a2
|
||||
call0 SaveRetAddr
|
||||
beqi a3, 1, .switchdone
|
||||
movi a4, g_losTask
|
||||
l32i a5, a4, 0 /* get run task */
|
||||
s32i a2, a5, 0 /* store sp */
|
||||
l32i a5, a4, 4 /* get new task */
|
||||
s32i a5, a4, 0 /* run task = new task */
|
||||
l32i a4, a5, 0 /* get new sp */
|
||||
rsr a5, PS
|
||||
movi a3, ~(WOE_ENABLE | LEVEL_MASK)
|
||||
and a2, a5, a3
|
||||
addi a2, a2, 3
|
||||
wsr a2, PS
|
||||
rsync
|
||||
call0 SpillWindow
|
||||
mov a2, a4
|
||||
POP_ALL_REG a2 EPC5 EPS5
|
||||
rfi 5
|
||||
|
||||
.switchdone:
|
||||
retw
|
||||
|
||||
.type HakSpillWindow, %function
|
||||
.global HakSpillWindow
|
||||
HakSpillWindow:
|
||||
|
||||
entry sp, 32
|
||||
|
||||
addi a2, sp, -CONTEXT_SIZE
|
||||
PUSH_ALL_REG a2
|
||||
|
||||
rsr a5, PS
|
||||
movi a3, ~(WOE_ENABLE | LEVEL_MASK) /* disable woe and int */
|
||||
and a3, a5, a3
|
||||
addi a3, a3, LEVEL3
|
||||
wsr a3, PS
|
||||
rsync
|
||||
|
||||
mov a4, a2
|
||||
call0 SpillWindow
|
||||
|
||||
l32i a5, a4, CONTEXT_OFF_PS /* restroe PS */
|
||||
wsr a5, PS
|
||||
rsync
|
||||
l32i a0, a4, CONTEXT_OFF_A0
|
||||
l32i a1, a4, CONTEXT_OFF_A1
|
||||
|
||||
retw
|
||||
|
||||
.type OsStartToRun, %function
|
||||
.global OsStartToRun
|
||||
OsStartToRun:
|
||||
|
||||
movi a2, g_losTask
|
||||
l32i a3, a2, 4 /* get new task */
|
||||
l32i sp, a3, 0 /* get sp */
|
||||
|
||||
rsr a4, PS
|
||||
movi a3, ~(WOE_ENABLE | LEVEL_MASK)
|
||||
and a2, a4, a3
|
||||
addi a2, a2, LEVEL3
|
||||
wsr a2, PS
|
||||
rsync
|
||||
|
||||
mov a5, a1
|
||||
l32i a1, a1, CONTEXT_OFF_A1
|
||||
call0 SpillWindow
|
||||
|
||||
mov a2, a5
|
||||
POP_ALL_REG a2 EPC5 EPS5
|
||||
rfi 5
|
||||
|
||||
.global SaveRetAddr
|
||||
.type SaveRetAddr, @function
|
||||
.literal_position
|
||||
.align 4
|
||||
|
||||
SaveRetAddr:
|
||||
|
||||
movi a3, 1
|
||||
s32i a3, a2, CONTEXT_OFF_A3
|
||||
s32i a0, a2, CONTEXT_OFF_PC /* save pc */
|
||||
movi a3, 0
|
||||
ret
|
||||
@@ -1,370 +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 "los_arch_regs.h"
|
||||
#include "los_arch_macro.h"
|
||||
|
||||
.extern HalInterrupt
|
||||
.extern UserException
|
||||
|
||||
.section .iram,"ax"
|
||||
.literal_position
|
||||
.type HandleEntry,@function
|
||||
.align 4
|
||||
HandleEntry:
|
||||
|
||||
mov a0, sp
|
||||
addi sp, sp, -CONTEXT_SIZE
|
||||
|
||||
PUSH_ALL_REG a1
|
||||
s32i a0, sp, CONTEXT_OFF_A1
|
||||
rsr a0, EPC1
|
||||
s32i a0, sp, CONTEXT_OFF_PC
|
||||
rsr a0, EXCSAVE1
|
||||
s32i a0, sp, CONTEXT_OFF_A0
|
||||
|
||||
wsr a1, EXCSAVE1
|
||||
l32i a1, a1, CONTEXT_OFF_A1
|
||||
call0 SpillWindow
|
||||
rsr a1, EXCSAVE1
|
||||
rsr a0, EXCCAUSE
|
||||
s32i a0, sp, CONTEXT_OFF_EXCCAUSE
|
||||
rsr a0, EXCVADDR
|
||||
s32i a0, sp, CONTEXT_OFF_EXCVADDR
|
||||
movi a0, INT_MASK | USER_VECTOR_MODE | WOE_ENABLE
|
||||
wsr a0, PS
|
||||
|
||||
rsr a6, EPC1
|
||||
mov a7, sp
|
||||
rsr a8, EXCCAUSE
|
||||
call4 HalExcHandleEntry
|
||||
1:
|
||||
j 1b
|
||||
|
||||
.begin literal_prefix .DebugExceptionHandler
|
||||
.section .DebugExceptionHandler.text, "ax"
|
||||
.global DebugExceptionHandler
|
||||
.align 4
|
||||
.literal_position
|
||||
DebugExceptionHandler:
|
||||
|
||||
call0 UserException
|
||||
|
||||
.end literal_prefix
|
||||
|
||||
.begin literal_prefix .NMIExceptionHandler
|
||||
.section .NMIExceptionHandler.text, "ax"
|
||||
.global NMIExceptionHandler
|
||||
.align 4
|
||||
.literal_position
|
||||
NMIExceptionHandler:
|
||||
|
||||
call0 UserException
|
||||
|
||||
.end literal_prefix
|
||||
|
||||
.begin literal_prefix .DoubleExceptionHandler
|
||||
.section .DoubleExceptionHandler.text, "ax"
|
||||
.global DoubleExceptionHandler
|
||||
.align 4
|
||||
.literal_position
|
||||
DoubleExceptionHandler:
|
||||
|
||||
movi a0, INT_MASK | USER_VECTOR_MODE | WOE_ENABLE
|
||||
wsr a0, PS
|
||||
rsr a2, EXCCAUSE
|
||||
call0 UserException
|
||||
|
||||
.end literal_prefix
|
||||
|
||||
.begin literal_prefix .KernelExceptionHandler
|
||||
.section .KernelExceptionHandler.text, "ax"
|
||||
.global KernelExceptionHandler
|
||||
.align 4
|
||||
.literal_position
|
||||
KernelExceptionHandler:
|
||||
|
||||
wsr a0, EXCSAVE1
|
||||
call0 KernelException
|
||||
|
||||
.end literal_prefix
|
||||
|
||||
.section .iram,"ax"
|
||||
.align 4
|
||||
KernelException:
|
||||
|
||||
movi a0,5
|
||||
wsr a0,EXCCAUSE
|
||||
call0 UserException
|
||||
rfe
|
||||
|
||||
.begin literal_prefix .UserExceptionHandler
|
||||
.section .UserExceptionHandler.text, "ax"
|
||||
.global UserExceptionHandler
|
||||
.type UserExceptionHandler,@function
|
||||
.align 4
|
||||
.literal_position
|
||||
UserExceptionHandler:
|
||||
|
||||
wsr a0, EXCSAVE1
|
||||
call0 UserException
|
||||
|
||||
.end literal_prefix
|
||||
|
||||
.section .iram,"ax"
|
||||
.type UserException,@function
|
||||
.align 4
|
||||
UserException:
|
||||
|
||||
rsr a0, EXCCAUSE
|
||||
beqi a0, 4, InterruptEntry1
|
||||
call0 HandleEntry
|
||||
1:
|
||||
j 1b
|
||||
|
||||
.section .iram,"ax"
|
||||
.type InterruptEntry1,@function
|
||||
.align 4
|
||||
InterruptEntry1:
|
||||
|
||||
mov a0, sp
|
||||
addi sp, sp, -CONTEXT_SIZE
|
||||
|
||||
PUSH_ALL_REG a1
|
||||
|
||||
s32i a0, sp, CONTEXT_OFF_A1
|
||||
rsr a0, EPC1
|
||||
s32i a0, sp, CONTEXT_OFF_PC
|
||||
rsr a0, EXCSAVE1
|
||||
s32i a0, sp, CONTEXT_OFF_A0
|
||||
|
||||
wsr a1, EXCSAVE1
|
||||
l32i a1, a1, CONTEXT_OFF_A1
|
||||
call0 SpillWindow
|
||||
rsr a1, EXCSAVE1
|
||||
|
||||
movi a0, LEVEL1_INT_MASK | USER_VECTOR_MODE | WOE_ENABLE
|
||||
wsr a0, PS
|
||||
rsync
|
||||
|
||||
call4 HalInterrupt
|
||||
mov a2, a1
|
||||
POP_ALL_REG a2 EPC1 PS
|
||||
rfe
|
||||
|
||||
.begin literal_prefix .InterruptEntry2
|
||||
.section .InterruptEntry2.text, "ax"
|
||||
.global InterruptEntry2
|
||||
.type InterruptEntry2,@function
|
||||
.align 4
|
||||
.literal_position
|
||||
InterruptEntry2:
|
||||
|
||||
wsr a0, EXCSAVE2
|
||||
movi a4, LEVEL2
|
||||
call0 HandleEntry
|
||||
|
||||
.end literal_prefix
|
||||
|
||||
.begin literal_prefix .InterruptEntry3
|
||||
.section .InterruptEntry3.text, "ax"
|
||||
.global InterruptEntry3
|
||||
.type InterruptEntry3,@function
|
||||
.align 4
|
||||
.literal_position
|
||||
InterruptEntry3:
|
||||
|
||||
wsr a0, EXCSAVE3
|
||||
movi a4, LEVEL3
|
||||
call0 HandleEntry
|
||||
|
||||
.end literal_prefix
|
||||
|
||||
.begin literal_prefix .InterruptEntry4
|
||||
.section .InterruptEntry4.text, "ax"
|
||||
.global InterruptEntry4
|
||||
.type InterruptEntry4,@function
|
||||
.align 4
|
||||
.literal_position
|
||||
InterruptEntry4:
|
||||
|
||||
wsr a0, EXCSAVE4
|
||||
movi a4, LEVEL4
|
||||
call0 HandleEntry
|
||||
|
||||
.end literal_prefix
|
||||
|
||||
.begin literal_prefix .InterruptEntry5
|
||||
.section .InterruptEntry5.text, "ax"
|
||||
.global InterruptEntry5
|
||||
.type InterruptEntry5,@function
|
||||
.align 4
|
||||
.literal_position
|
||||
InterruptEntry5:
|
||||
|
||||
wsr a0, EXCSAVE5
|
||||
movi a4, LEVEL5
|
||||
call0 HandleEntry
|
||||
|
||||
.end literal_prefix
|
||||
|
||||
.section .WindowVectors.text, "ax"
|
||||
|
||||
.org 0x0
|
||||
.global OverFlowGroup1
|
||||
OverFlowGroup1:
|
||||
|
||||
addi a5, a5, -16
|
||||
s32i a3, a5, 12
|
||||
s32i a2, a5, 8
|
||||
s32i a1, a5, 4
|
||||
s32i a0, a5, 0
|
||||
addi a5, a5, 16
|
||||
rfwo
|
||||
|
||||
.org 0x40
|
||||
.global UnderFlowGroup1
|
||||
UnderFlowGroup1:
|
||||
|
||||
addi a5, a5, -16
|
||||
l32i a3, a5, 12
|
||||
l32i a2, a5, 8
|
||||
l32i a1, a5, 4
|
||||
l32i a0, a5, 0
|
||||
addi a5, a5, 16
|
||||
rfwu
|
||||
|
||||
.org 0x80
|
||||
.global OverFlowGroup2
|
||||
OverFlowGroup2:
|
||||
|
||||
addi a9, a9, -16
|
||||
s32i a3, a9, 12
|
||||
s32i a2, a9, 8
|
||||
s32i a1, a9, 4
|
||||
s32i a0, a9, 0
|
||||
addi a9, a9, 16
|
||||
|
||||
addi a1, a1, -12
|
||||
l32i a0, a1, 0
|
||||
addi a1, a1, 12
|
||||
|
||||
addi a0, a0, -32
|
||||
|
||||
s32i a7, a0, 12
|
||||
s32i a6, a0, 8
|
||||
s32i a5, a0, 4
|
||||
s32i a4, a0, 0
|
||||
|
||||
rfwo
|
||||
|
||||
.org 0xC0
|
||||
.global UnderFlowGroup2
|
||||
UnderFlowGroup2:
|
||||
|
||||
addi a9, a9, -16
|
||||
l32i a3, a9, 12
|
||||
l32i a2, a9, 8
|
||||
l32i a1, a9, 4
|
||||
l32i a0, a9, 0
|
||||
addi a9, a9, 16
|
||||
|
||||
addi a1, a1, -12
|
||||
l32i a4, a1, 0
|
||||
addi a1, a1, 12
|
||||
|
||||
addi a4, a4, -32
|
||||
l32i a7, a4, 12
|
||||
l32i a6, a4, 8
|
||||
l32i a5, a4, 4
|
||||
l32i a4, a4, 0
|
||||
rfwu
|
||||
|
||||
.org 0x100
|
||||
.global OverFlowGroup3
|
||||
OverFlowGroup3:
|
||||
|
||||
addi a13, a13, -16
|
||||
s32i a3, a13, 12
|
||||
s32i a2, a13, 8
|
||||
s32i a1, a13, 4
|
||||
s32i a0, a13, 0
|
||||
addi a13, a13, 16
|
||||
|
||||
addi a1, a1, -12
|
||||
l32i a0, a1, 0
|
||||
addi a1, a1, 12
|
||||
|
||||
addi a0, a0, -48
|
||||
|
||||
s32i a11, a0, 28
|
||||
s32i a10, a0, 24
|
||||
s32i a9, a0, 20
|
||||
s32i a8, a0, 16
|
||||
s32i a7, a0, 12
|
||||
s32i a6, a0, 8
|
||||
s32i a5, a0, 4
|
||||
s32i a4, a0, 0
|
||||
rfwo
|
||||
|
||||
.org 0x140
|
||||
.global UnderFlowGroup3
|
||||
UnderFlowGroup3:
|
||||
|
||||
addi a13, a13, -16
|
||||
l32i a3, a13, 12
|
||||
l32i a2, a13, 8
|
||||
l32i a1, a13, 4
|
||||
l32i a0, a13, 0
|
||||
addi a13, a13, 16
|
||||
|
||||
addi a1, a1, -12
|
||||
l32i a4, a1, 0
|
||||
addi a1, a1, 12
|
||||
|
||||
addi a4, a4, -48
|
||||
l32i a11, a0, 28
|
||||
l32i a10, a0, 24
|
||||
l32i a9, a0, 20
|
||||
l32i a8, a0, 16
|
||||
l32i a7, a4, 12
|
||||
l32i a6, a4, 8
|
||||
l32i a5, a4, 4
|
||||
l32i a4, a4, 0
|
||||
rfwu
|
||||
|
||||
.global EnableExceptionInterface
|
||||
.section .iram,"ax"
|
||||
.type EnableExceptionInterface,@function
|
||||
.align 4
|
||||
EnableExceptionInterface:
|
||||
entry a1,16
|
||||
retw
|
||||
@@ -1,554 +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 "los_interrupt.h"
|
||||
#include <stdarg.h>
|
||||
#include "securec.h"
|
||||
#include "los_context.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_hook.h"
|
||||
#include "los_task.h"
|
||||
#include "los_sched.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_membox.h"
|
||||
#include "los_arch_regs.h"
|
||||
|
||||
UINT32 g_intCount = 0;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC __attribute__((aligned(LOSCFG_ARCH_HWI_VECTOR_ALIGN))) g_hwiForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
|
||||
typedef struct {
|
||||
HWI_PROC_FUNC pfnHandler;
|
||||
VOID *pParm;
|
||||
} HWI_HANDLER_FUNC;
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_HANDLER_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {{ (HWI_PROC_FUNC)0, (HWI_ARG_T)0 }};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector, VOID *arg)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalInterrupt;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pfnHandler = vector;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT].pParm = arg;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt handler form mapping handling function array.
|
||||
*/
|
||||
STATIC HWI_PROC_FUNC g_hwiHandlerForm[OS_VECTOR_CNT] = {0};
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Set interrupt vector table.
|
||||
*/
|
||||
VOID OsSetVector(UINT32 num, HWI_PROC_FUNC vector)
|
||||
{
|
||||
if ((num + OS_SYS_VECTOR_CNT) < OS_VECTOR_CNT) {
|
||||
g_hwiForm[num + OS_SYS_VECTOR_CNT] = HalInterrupt;
|
||||
g_hwiHandlerForm[num + OS_SYS_VECTOR_CNT] = vector;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
UINT32 HwiNumValid(UINT32 num)
|
||||
{
|
||||
return (num >= OS_SYS_VECTOR_CNT) && (num <= OS_VECTOR_CNT);
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Lock all interrupt.
|
||||
*/
|
||||
UINT32 ArchIntLock(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
__asm__ volatile("rsil %0, %1" : "=r"(ret) : "i"(INT_MASK) : "memory");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Restore interrupt status.
|
||||
*/
|
||||
VOID ArchIntRestore(UINT32 intSave)
|
||||
{
|
||||
__asm__ volatile("wsr.ps %0; rsync" : : "r"(intSave) : "memory");
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Unlock interrupt.
|
||||
*/
|
||||
UINT32 ArchIntUnLock(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
__asm__ volatile("rsil %0, %1" : "=r"(intSave) : "i"(0) : "memory");
|
||||
|
||||
return intSave;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Determine if the interrupt is locked
|
||||
*/
|
||||
STATIC INLINE UINT32 ArchIntLocked(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ volatile("rsr %0, ps " : "=r"(intSave) : : "memory");
|
||||
|
||||
return (intSave & SPREG_PS_DI_MASK);
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Trigger the interrupt
|
||||
*/
|
||||
UINT32 HalIrqPending(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
__asm__ __volatile__("wsr %0, intset; rsync" : : "a"(0x1U << hwiNum));
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Unmask the interrupt
|
||||
*/
|
||||
UINT32 HalIrqUnmask(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 ier;
|
||||
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
__asm__ __volatile__("rsr %0, intenable" : "=a"(ier) : : "memory");
|
||||
__asm__ __volatile__("wsr %0, intenable; rsync" : : "a"(ier | ((UINT32)0x1U << hwiNum)));
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Mask the interrupt
|
||||
*/
|
||||
UINT32 HalIrqMask(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 ier;
|
||||
|
||||
if (!HwiNumValid(hwiNum)) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
__asm__ __volatile__("rsr %0, intenable" : "=a"(ier) : : "memory");
|
||||
__asm__ __volatile__("wsr %0, intenable; rsync" : : "a"(ier & ~((UINT32)0x1U << hwiNum)));
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalIntNumGet
|
||||
Description : Get an interrupt number
|
||||
Input : None
|
||||
Output : None
|
||||
Return : Interrupt Indexes number
|
||||
**************************************************************************** */
|
||||
UINT32 HalIntNumGet(VOID)
|
||||
{
|
||||
UINT32 ier;
|
||||
UINT32 intenable;
|
||||
UINT32 intSave;
|
||||
|
||||
__asm__ __volatile__("rsr %0, interrupt" : "=a"(ier) : : "memory");
|
||||
__asm__ __volatile__("rsr %0, intenable" : "=a"(intenable) : : "memory");
|
||||
|
||||
intSave = ier & intenable;
|
||||
|
||||
return __builtin_ffs(intSave) - 1;
|
||||
}
|
||||
|
||||
/* *
|
||||
* @ingroup los_hwi
|
||||
* Clear the interrupt
|
||||
*/
|
||||
UINT32 HalIrqClear(HWI_HANDLE_T vector)
|
||||
{
|
||||
if (!HwiNumValid(vector)) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
__asm__ __volatile__("wsr %0, intclear; rsync" : : "a"(0x1U << vector));
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
INLINE UINT32 ArchIsIntActive(VOID)
|
||||
{
|
||||
return (g_intCount > 0);
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiDefaultHandler
|
||||
Description : default handler of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
VOID HalHwiDefaultHandler(VOID)
|
||||
{
|
||||
UINT32 irqNum = HalIntNumGet();
|
||||
PRINT_ERR("%s irqnum:%d\n", __FUNCTION__, irqNum);
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
WEAK VOID HalPreInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WEAK VOID HalAftInterruptHandler(UINT32 arg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalInterrupt
|
||||
Description : Hardware interrupt entry function
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
VOID HalInterrupt(VOID)
|
||||
{
|
||||
UINT32 hwiIndex;
|
||||
UINT32 intSave;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount++;
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
hwiIndex = HalIntNumGet();
|
||||
HalIrqClear(hwiIndex);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_ENTER, hwiIndex);
|
||||
|
||||
HalPreInterruptHandler(hwiIndex);
|
||||
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
if (g_hwiHandlerForm[hwiIndex].pfnHandler != 0) {
|
||||
g_hwiHandlerForm[hwiIndex].pfnHandler((VOID *)g_hwiHandlerForm[hwiIndex].pParm);
|
||||
}
|
||||
#else
|
||||
if (g_hwiHandlerForm[hwiIndex] != 0) {
|
||||
g_hwiHandlerForm[hwiIndex]();
|
||||
}
|
||||
#endif
|
||||
|
||||
HalAftInterruptHandler(hwiIndex);
|
||||
|
||||
OsHookCall(LOS_HOOK_TYPE_ISR_EXIT, hwiIndex);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
g_intCount--;
|
||||
LOS_IntRestore(intSave);
|
||||
HalIrqEndCheckNeedSched();
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchHwiCreate
|
||||
Description : create hardware interrupt
|
||||
Input : hwiNum --- hwi num to create
|
||||
hwiPrio --- priority of the hwi
|
||||
mode --- unused
|
||||
handler --- hwi handler
|
||||
arg --- param of the hwi handler
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T mode,
|
||||
HWI_PROC_FUNC handler,
|
||||
HWI_ARG_T arg)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (handler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
if (g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] != (HWI_PROC_FUNC)HalHwiDefaultHandler) {
|
||||
return OS_ERRNO_HWI_ALREADY_CREATED;
|
||||
}
|
||||
|
||||
if (hwiPrio > OS_HWI_PRIO_LOWEST) {
|
||||
return OS_ERRNO_HWI_PRIO_INVALID;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(hwiNum, handler, arg);
|
||||
#else
|
||||
OsSetVector(hwiNum, handler);
|
||||
#endif
|
||||
HalIrqUnmask(hwiNum);
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : ArchHwiDelete
|
||||
Description : Delete hardware interrupt
|
||||
Input : hwiNum --- hwi num to delete
|
||||
Output : None
|
||||
Return : LOS_OK on success or error code on failure
|
||||
**************************************************************************** */
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (hwiNum >= OS_HWI_MAX_NUM) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
HalIrqMask(hwiNum);
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
g_hwiForm[hwiNum + OS_SYS_VECTOR_CNT] = (HWI_PROC_FUNC)HalHwiDefaultHandler;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
ExcInfo g_excInfo = {0};
|
||||
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
|
||||
STATIC VOID OsExcTypeInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
CHAR *phaseStr[] = {"exc in init", "exc in task", "exc in hwi"};
|
||||
|
||||
PRINTK("Type = %d\n", excInfo->type);
|
||||
PRINTK("ThrdPid = %d\n", excInfo->thrdPid);
|
||||
PRINTK("Phase = %s\n", phaseStr[excInfo->phase]);
|
||||
PRINTK("FaultAddr = 0x%x\n", excInfo->faultAddr);
|
||||
}
|
||||
|
||||
STATIC VOID OsExcCurTaskInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
PRINTK("Current task info:\n");
|
||||
if (excInfo->phase == OS_EXC_IN_TASK) {
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
|
||||
PRINTK("Task name = %s\n", taskCB->taskName);
|
||||
PRINTK("Task ID = %d\n", taskCB->taskID);
|
||||
PRINTK("Task SP = 0x%x\n", (UINTPTR)taskCB->stackPointer);
|
||||
PRINTK("Task ST = 0x%x\n", taskCB->topOfStack);
|
||||
PRINTK("Task SS = 0x%x\n", taskCB->stackSize);
|
||||
} else if (excInfo->phase == OS_EXC_IN_HWI) {
|
||||
PRINTK("Exception occur in interrupt phase!\n");
|
||||
} else {
|
||||
PRINTK("Exception occur in system init phase!\n");
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsExcRegInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
INT32 index;
|
||||
PRINTK("Exception reg dump:\n");
|
||||
PRINTK("sar = 0x%x\n", excInfo->context->sar);
|
||||
PRINTK("excCause = 0x%x\n", excInfo->context->excCause);
|
||||
PRINTK("excVaddr = 0x%x\n", excInfo->context->excVaddr);
|
||||
PRINTK("lbeg = 0x%x\n", excInfo->context->lbeg);
|
||||
PRINTK("lend = 0x%x\n", excInfo->context->lend);
|
||||
PRINTK("lcount = 0x%x\n", excInfo->context->lcount);
|
||||
PRINTK("pc = 0x%x\n", excInfo->context->pc);
|
||||
PRINTK("ps = 0x%x\n", excInfo->context->ps);
|
||||
for (index = 0; index < XTENSA_LOGREG_NUM; index++) {
|
||||
PRINTK("regA%d = 0x%x\n", index, excInfo->context->regA[index]);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsExcBackTraceInfo(const ExcInfo *excInfo)
|
||||
{
|
||||
UINTPTR LR[LOSCFG_BACKTRACE_DEPTH] = {0};
|
||||
UINT32 index;
|
||||
|
||||
OsBackTraceHookCall(LR, LOSCFG_BACKTRACE_DEPTH, 0, excInfo->context->regA[1]);
|
||||
|
||||
PRINTK("----- backtrace start -----\n");
|
||||
for (index = 0; index < LOSCFG_BACKTRACE_DEPTH; index++) {
|
||||
if (LR[index] == 0) {
|
||||
break;
|
||||
}
|
||||
PRINTK("backtrace %d -- lr = 0x%x\n", index, LR[index]);
|
||||
}
|
||||
PRINTK("----- backtrace end -----\n");
|
||||
}
|
||||
|
||||
STATIC VOID OsExcMemPoolCheckInfo(VOID)
|
||||
{
|
||||
PRINTK("\r\nmemory pools check:\n");
|
||||
#if (LOSCFG_PLATFORM_EXC == 1)
|
||||
MemInfoCB memExcInfo[OS_SYS_MEM_NUM];
|
||||
UINT32 errCnt;
|
||||
UINT32 i;
|
||||
|
||||
(VOID)memset_s(memExcInfo, sizeof(memExcInfo), 0, sizeof(memExcInfo));
|
||||
|
||||
errCnt = OsMemExcInfoGet(OS_SYS_MEM_NUM, memExcInfo);
|
||||
if (errCnt < OS_SYS_MEM_NUM) {
|
||||
errCnt += OsMemboxExcInfoGet(OS_SYS_MEM_NUM - errCnt, memExcInfo + errCnt);
|
||||
}
|
||||
|
||||
if (errCnt == 0) {
|
||||
PRINTK("all memory pool check passed!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < errCnt; i++) {
|
||||
PRINTK("pool num = %d\n", i);
|
||||
PRINTK("pool type = %d\n", memExcInfo[i].type);
|
||||
PRINTK("pool addr = 0x%x\n", memExcInfo[i].startAddr);
|
||||
PRINTK("pool size = 0x%x\n", memExcInfo[i].size);
|
||||
PRINTK("pool free = 0x%x\n", memExcInfo[i].free);
|
||||
PRINTK("pool blkNum = %d\n", memExcInfo[i].blockSize);
|
||||
PRINTK("pool error node addr = 0x%x\n", memExcInfo[i].errorAddr);
|
||||
PRINTK("pool error node len = 0x%x\n", memExcInfo[i].errorLen);
|
||||
PRINTK("pool error node owner = %d\n", memExcInfo[i].errorOwner);
|
||||
}
|
||||
#endif
|
||||
UINT32 ret = LOS_MemIntegrityCheck(LOSCFG_SYS_HEAP_ADDR);
|
||||
if (ret == LOS_OK) {
|
||||
PRINTK("system heap memcheck over, all passed!\n");
|
||||
}
|
||||
|
||||
PRINTK("memory pool check end!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC VOID OsExcInfoDisplay(const ExcInfo *excInfo)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_PRINTF != 0)
|
||||
PRINTK("*************Exception Information**************\n");
|
||||
OsExcTypeInfo(excInfo);
|
||||
OsExcCurTaskInfo(excInfo);
|
||||
OsExcRegInfo(excInfo);
|
||||
OsExcBackTraceInfo(excInfo);
|
||||
OsGetAllTskInfo();
|
||||
OsExcMemPoolCheckInfo();
|
||||
#endif
|
||||
}
|
||||
|
||||
VOID HalExcHandleEntry(UINTPTR faultAddr, EXC_CONTEXT_S *excBufAddr, UINT32 type)
|
||||
{
|
||||
g_excInfo.nestCnt++;
|
||||
g_excInfo.faultAddr = faultAddr;
|
||||
g_excInfo.type = type;
|
||||
|
||||
LosTaskCB *taskCB = g_losTask.runTask;
|
||||
|
||||
if ((taskCB == NULL) || (taskCB == OS_TCB_FROM_TID(g_taskMaxNum))) {
|
||||
g_excInfo.phase = OS_EXC_IN_INIT;
|
||||
g_excInfo.thrdPid = OS_NULL_INT;
|
||||
} else if (HalIntNumGet() != OS_NULL_INT) {
|
||||
g_excInfo.phase = OS_EXC_IN_HWI;
|
||||
g_excInfo.thrdPid = HalIntNumGet();
|
||||
} else {
|
||||
g_excInfo.phase = OS_EXC_IN_TASK;
|
||||
g_excInfo.thrdPid = g_losTask.runTask->taskID;
|
||||
}
|
||||
|
||||
g_excInfo.context = excBufAddr;
|
||||
|
||||
OsDoExcHook(EXC_INTERRUPT);
|
||||
OsExcInfoDisplay(&g_excInfo);
|
||||
ArchSysExit();
|
||||
}
|
||||
|
||||
/* Stack protector */
|
||||
WEAK UINT32 __stack_chk_guard = 0xd00a0dff;
|
||||
|
||||
WEAK VOID __stack_chk_fail(VOID)
|
||||
{
|
||||
/* __builtin_return_address is a builtin function, building in gcc */
|
||||
LOS_Panic("stack-protector: Kernel stack is corrupted in: 0x%x\n",
|
||||
__builtin_return_address(0));
|
||||
}
|
||||
|
||||
/* ****************************************************************************
|
||||
Function : HalHwiInit
|
||||
Description : initialization of the hardware interrupt
|
||||
Input : None
|
||||
Output : None
|
||||
Return : None
|
||||
**************************************************************************** */
|
||||
VOID HalHwiInit(VOID)
|
||||
{
|
||||
EnableExceptionInterface();
|
||||
for (UINT32 i = 0; i < OS_HWI_MAX_NUM; i++) {
|
||||
g_hwiForm[i + OS_SYS_VECTOR_CNT] = HalHwiDefaultHandler;
|
||||
HalIrqMask(i);
|
||||
}
|
||||
asm volatile ("wsr %0, vecbase" : : "r"(INIT_VECTOR_START));
|
||||
return;
|
||||
}
|
||||
@@ -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 "los_timer.h"
|
||||
#include "los_config.h"
|
||||
#include "los_tick.h"
|
||||
#include "los_arch_interrupt.h"
|
||||
#include "los_arch_timer.h"
|
||||
#include "los_debug.h"
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler);
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime);
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period);
|
||||
STATIC VOID SysTickLock(VOID);
|
||||
STATIC VOID SysTickUnlock(VOID);
|
||||
|
||||
STATIC ArchTickTimer g_archTickTimer = {
|
||||
.freq = 0,
|
||||
.irqNum = OS_TICK_INT_NUM,
|
||||
.init = SysTickStart,
|
||||
.getCycle = SysTickCycleGet,
|
||||
.reload = SysTickReload,
|
||||
.lock = SysTickLock,
|
||||
.unlock = SysTickUnlock,
|
||||
.tickHandler = NULL,
|
||||
};
|
||||
|
||||
STATIC UINT32 SysTickStart(HWI_PROC_FUNC handler)
|
||||
{
|
||||
ArchTickTimer *tick = &g_archTickTimer;
|
||||
|
||||
tick->freq = OS_SYS_CLOCK;
|
||||
|
||||
#if (LOSCFG_USE_SYSTEM_DEFINED_INTERRUPT == 1)
|
||||
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
|
||||
OsSetVector(tick->irqNum, handler, NULL);
|
||||
#else
|
||||
OsSetVector(tick->irqNum, handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ResetCcount();
|
||||
SetCcompare(LOSCFG_BASE_CORE_TICK_RESPONSE_MAX);
|
||||
|
||||
__asm__ __volatile__("wsr %0, ccompare1; rsync" : : "a"(0));
|
||||
__asm__ __volatile__("wsr %0, ccompare2; rsync" : : "a"(0));
|
||||
|
||||
HalIrqUnmask(tick->irqNum);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickReload(UINT64 nextResponseTime)
|
||||
{
|
||||
UINT32 timerL;
|
||||
timerL = GetCcount();
|
||||
timerL += nextResponseTime;
|
||||
SetCcompare(timerL);
|
||||
}
|
||||
|
||||
STATIC UINT64 SysTickCycleGet(UINT32 *period)
|
||||
{
|
||||
UINT32 tickCycleH;
|
||||
UINT32 tickCycleL;
|
||||
UINT32 temp;
|
||||
static UINT64 tickCycle = 0;
|
||||
|
||||
(VOID)period;
|
||||
UINT32 intSave = LOS_IntLock();
|
||||
temp = tickCycle & 0xFFFFFFFF;
|
||||
tickCycleH = tickCycle >> SHIFT_32_BIT;
|
||||
tickCycleL = GetCcount();
|
||||
if (tickCycleL < temp) {
|
||||
tickCycleH++;
|
||||
}
|
||||
tickCycle = (((UINT64)tickCycleH) << SHIFT_32_BIT) | tickCycleL;
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return tickCycle;
|
||||
}
|
||||
|
||||
STATIC VOID SysTickLock(VOID)
|
||||
{
|
||||
HalIrqMask(OS_TICK_INT_NUM);
|
||||
}
|
||||
|
||||
STATIC VOID SysTickUnlock(VOID)
|
||||
{
|
||||
HalIrqUnmask(OS_TICK_INT_NUM);
|
||||
}
|
||||
|
||||
ArchTickTimer *ArchSysTickTimerGet(VOID)
|
||||
{
|
||||
return &g_archTickTimer;
|
||||
}
|
||||
|
||||
VOID Wfi(VOID)
|
||||
{
|
||||
__asm__ volatile("waiti 0" : : : "memory");
|
||||
}
|
||||
|
||||
VOID Dsb(VOID)
|
||||
{
|
||||
__asm__ volatile("dsync" : : : "memory");
|
||||
}
|
||||
|
||||
UINT32 ArchEnterSleep(VOID)
|
||||
{
|
||||
Dsb();
|
||||
Wfi();
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
@@ -1,187 +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 "los_arch_regs.h"
|
||||
|
||||
.text
|
||||
.align 4
|
||||
.literal_position
|
||||
.global SpillWindow
|
||||
SpillWindow:
|
||||
|
||||
rsr a2, WINDOWBASE /* read windowbase reg */
|
||||
|
||||
movi a3, WINDOWSTARTBITS
|
||||
sub a3, a3, a2 /* get the num of high bits */
|
||||
addi a3, a3, -1
|
||||
|
||||
ssl a3 /* set left shift bit */
|
||||
rsr a3, WINDOWSTART /* read windowstart reg */
|
||||
sll a3, a3
|
||||
movi a2, WINDOWSTARTMASK
|
||||
and a3, a3, a2
|
||||
|
||||
beqi a3, 0, .Linvalidwindowstart /* if a3 == 0 goto Linvalidwindowstart */
|
||||
|
||||
rsr a2, WINDOWBASE /* read windowbase reg */
|
||||
|
||||
addi a2, a2, 1
|
||||
ssr a2
|
||||
rsr a2, WINDOWSTART
|
||||
srl a2, a2
|
||||
or a2, a2, a3
|
||||
movi a3, 0
|
||||
|
||||
.bitclear0:
|
||||
bbsi.l a2, 0, .bitcleardone
|
||||
srli a2, a2, 1
|
||||
addi a3, a3, 1
|
||||
j .bitclear0
|
||||
|
||||
.bitcleardone:
|
||||
srli a2, a2, 1 /* drop the first bit */
|
||||
|
||||
wsr a2, WINDOWSTART
|
||||
rsr a2, WINDOWBASE
|
||||
|
||||
add a2, a2, a3
|
||||
wsr a2, WINDOWBASE
|
||||
rsync
|
||||
|
||||
rsr a2, WINDOWSTART
|
||||
|
||||
.Lspillstart:
|
||||
beqi a2, 0, .Ldone
|
||||
bbsi.l a2, 0, .Lspill4
|
||||
bbsi.l a2, 1, .Lspill8
|
||||
bbsi.l a2, 2, .Lspill12
|
||||
j .Linvalidwindow
|
||||
|
||||
.Lspill4:
|
||||
s32e a4, a9, -16
|
||||
s32e a5, a9, -12
|
||||
s32e a6, a9, -8
|
||||
s32e a7, a9, -4
|
||||
|
||||
srli a6, a2, 1
|
||||
rotw 1
|
||||
j .Lspillstart
|
||||
|
||||
.Lspill8:
|
||||
s32e a4, a13, -16
|
||||
s32e a5, a13, -12
|
||||
s32e a6, a13, -8
|
||||
s32e a7, a13, -4
|
||||
|
||||
l32i a3, a5, -12 /* call[i - 1]'s sp */
|
||||
addi a3, a3, -16 /* base area */
|
||||
|
||||
s32e a8, a3, -16
|
||||
s32e a9, a3, -12
|
||||
s32e a10, a3, -8
|
||||
s32e a11, a3, -4
|
||||
|
||||
srli a10, a2, 2
|
||||
rotw 2
|
||||
j .Lspillstart
|
||||
|
||||
.Lspill12:
|
||||
rotw 1
|
||||
s32e a0, a13, -16
|
||||
s32e a1, a13, -12
|
||||
s32e a2, a13, -8
|
||||
s32e a3, a13, -4
|
||||
|
||||
l32i a3, a1, -12 /* call[i - 1]'s sp */
|
||||
addi a3, a3, -16 /* base area */
|
||||
|
||||
s32e a4, a3, -32
|
||||
s32e a5, a3, -28
|
||||
s32e a6, a3, -24
|
||||
s32e a7, a3, -20
|
||||
s32e a8, a3, -16
|
||||
s32e a9, a3, -12
|
||||
s32e a10, a3, -8
|
||||
s32e a11, a3, -4
|
||||
|
||||
rotw -1
|
||||
srli a14, a2, 3
|
||||
rotw 3
|
||||
j .Lspillstart
|
||||
|
||||
.Ldone:
|
||||
rotw 1
|
||||
rsr a2, WINDOWBASE
|
||||
ssl a2
|
||||
movi a2, 1
|
||||
sll a2, a2
|
||||
wsr a2, WINDOWSTART
|
||||
rsync
|
||||
movi a2, 0
|
||||
ret
|
||||
|
||||
.Linvalidwindowstart:
|
||||
movi a2, 1
|
||||
ret
|
||||
|
||||
.Linvalidwindow:
|
||||
movi a3, 1
|
||||
slli a2, a2, 1
|
||||
or a2, a2, a3
|
||||
rsr a3, WINDOWBASE
|
||||
|
||||
.RestoreWindowBase:
|
||||
bbsi.l a2, WINDOWSTARTBITS - 1, .RestoreWindow
|
||||
slli a2, a2, 1
|
||||
addi a3, a3, -1
|
||||
j .RestoreWindowBase
|
||||
|
||||
.RestoreWindow:
|
||||
extui a3, a3, 0, WINDOWSTARTBITS /* the original bit */
|
||||
|
||||
addi a3, a3, 1
|
||||
ssl a3
|
||||
sll a3, a2
|
||||
slli a2, a2, 32 - WINDOWSTARTBITS
|
||||
srl a2, a2
|
||||
|
||||
or a2, a2, a3
|
||||
extui a2, a2, 0, WINDOWSTARTBITS
|
||||
wsr a2, WINDOWSTART
|
||||
|
||||
movi a3, 31
|
||||
rsr a2, SAR
|
||||
sub a2, a3, a2
|
||||
wsr a2, WINDOWBASE
|
||||
rsync
|
||||
|
||||
movi a2, 2
|
||||
ret
|
||||
@@ -4,7 +4,6 @@
|
||||
│ ├── backtrace --- Backtrace
|
||||
│ ├── cppsupport --- C++
|
||||
│ ├── cpup --- CPUP
|
||||
│ ├── dynlink --- Dynamic loader & linker
|
||||
│ ├── exchook --- Exception hook
|
||||
│ ├── fs --- File System
|
||||
│ └── net --- Network
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
│ ├── backtrace --- 回溯栈支持
|
||||
│ ├── cppsupport --- C++支持
|
||||
│ ├── cpup --- CPUP功能
|
||||
│ ├── dynlink --- 动态加载与链接
|
||||
│ ├── exchook --- 异常钩子
|
||||
│ ├── fs --- 文件系统
|
||||
│ └── net --- 网络功能
|
||||
|
||||
@@ -1,64 +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_m/liteos.gni")
|
||||
|
||||
group("components") {
|
||||
deps = [
|
||||
"backtrace",
|
||||
"cppsupport",
|
||||
"cpup",
|
||||
"dynlink",
|
||||
"exchook",
|
||||
"fs",
|
||||
"lmk",
|
||||
"lms",
|
||||
"net",
|
||||
"power",
|
||||
"shell",
|
||||
"trace",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
configs = [
|
||||
"backtrace:public",
|
||||
"cppsupport:public",
|
||||
"cpup:public",
|
||||
"dynlink:public",
|
||||
"exchook:public",
|
||||
"fs:public",
|
||||
"net:public",
|
||||
"power:public",
|
||||
"shell:public",
|
||||
"trace:public",
|
||||
"lmk:public",
|
||||
"lms:public",
|
||||
]
|
||||
}
|
||||
@@ -27,14 +27,13 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_KERNEL_BACKTRACE)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
static_library("backtrace") {
|
||||
sources = [ "los_backtrace.c" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
include_dirs = [
|
||||
"../../kernel/include",
|
||||
"../../kernel/arch/include",
|
||||
"../../utils",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -32,22 +32,9 @@
|
||||
#include "los_backtrace.h"
|
||||
#include "los_task.h"
|
||||
#include "los_debug.h"
|
||||
#if (LOSCFG_BACKTRACE_TYPE == 4)
|
||||
#include "los_arch_regs.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if (LOSCFG_BACKTRACE_TYPE != 0)
|
||||
/* This function is used to judge whether the data in the stack is a code section address.
|
||||
The default code section is only one, but there may be more than one. Modify the
|
||||
judgment condition to support multiple code sections. */
|
||||
WEAK BOOL OsStackDataIsCodeAddr(UINTPTR value)
|
||||
{
|
||||
if ((value >= CODE_START_ADDR) && (value < CODE_END_ADDR)) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if (LOSCFG_BACKTRACE_TYPE == 1)
|
||||
#define OS_BACKTRACE_START 2
|
||||
/* Thumb instruction, so the pc must be an odd number */
|
||||
@@ -193,10 +180,12 @@ STATIC INLINE UINTPTR OsAddrIsValid(UINTPTR sp)
|
||||
return pc;
|
||||
}
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 2)
|
||||
STATIC INLINE BOOL OsBackTraceFpCheck(UINT32 value);
|
||||
#define OS_BACKTRACE_START 1
|
||||
#define OS_RA_OFFSET 4
|
||||
#define OS_FP_OFFSET 8
|
||||
#define OS_FP_ALIGN(value) (((UINT32)(value) & (UINT32)(LOSCFG_STACK_POINT_ALIGN_SIZE - 1)) == 0)
|
||||
#define OS_FP_CHECK(value) (((UINT32)(value) != FP_INIT_VALUE) && OS_FP_ALIGN(value))
|
||||
|
||||
STATIC INLINE UINTPTR OsFpGet(VOID)
|
||||
{
|
||||
@@ -206,41 +195,12 @@ STATIC INLINE UINTPTR OsFpGet(VOID)
|
||||
return fp;
|
||||
}
|
||||
|
||||
WEAK BOOL IsValidFP(UINTPTR fp)
|
||||
{
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINTPTR stackTop, stackBottom;
|
||||
UINTPTR irqStackTop, irqStackBottom;
|
||||
|
||||
if ((fp == FP_INIT_VALUE) || !OS_FP_ALIGN(fp)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (LOS_TaskIsRunning()) {
|
||||
taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet());
|
||||
stackTop = taskCB->topOfStack;
|
||||
stackBottom = taskCB->topOfStack + taskCB->stackSize;
|
||||
irqStackTop = (UINTPTR)CSTACK_START_ADDR;
|
||||
irqStackBottom = (UINTPTR)CSTACK_SECTION_END;
|
||||
} else {
|
||||
stackTop = 0;
|
||||
stackBottom = 0;
|
||||
irqStackTop = (UINTPTR)CSTACK_START_ADDR;
|
||||
irqStackBottom = (UINTPTR)CSTACK_SECTION_END;
|
||||
}
|
||||
|
||||
if (((fp > stackTop) && (fp <= stackBottom)) || ((fp > irqStackTop) && (fp <= irqStackBottom))) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
|
||||
{
|
||||
UINTPTR backFp;
|
||||
UINTPTR tmpFp;
|
||||
UINTPTR backRa;
|
||||
UNUSED(SP);
|
||||
UINT32 backFp = OsFpGet();
|
||||
UINT32 tmpFp;
|
||||
UINT32 backRa;
|
||||
UINT32 count = 0;
|
||||
UINT32 index = 0;
|
||||
|
||||
@@ -248,31 +208,21 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
|
||||
return;
|
||||
}
|
||||
|
||||
if (SP != 0) {
|
||||
backFp = SP;
|
||||
} else {
|
||||
backFp = OsFpGet();
|
||||
}
|
||||
|
||||
if (!IsValidFP(backFp)) {
|
||||
PRINT_ERR("BackTrace failed! Invalid fp 0x%x\n", backFp);
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
while (OS_FP_CHECK(backFp)) {
|
||||
tmpFp = backFp;
|
||||
backRa = *((UINTPTR *)(UINTPTR)(tmpFp - OS_RA_OFFSET));
|
||||
backFp = *((UINTPTR *)(UINTPTR)(tmpFp - OS_FP_OFFSET));
|
||||
backRa = *((UINT32 *)(UINTPTR)(tmpFp - OS_RA_OFFSET));
|
||||
backFp = *((UINT32 *)(UINTPTR)(tmpFp - OS_FP_OFFSET));
|
||||
if (index++ < jumpCount) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LR[count] = backRa;
|
||||
count++;
|
||||
if ((count == LRSize) || (backFp == tmpFp)) {
|
||||
if ((count == LRSize) || (backFp == tmpFp) ||
|
||||
(!OsStackDataIsCodeAddr(backRa))) {
|
||||
break;
|
||||
}
|
||||
} while (IsValidFP(backFp));
|
||||
}
|
||||
|
||||
if (count < LRSize) {
|
||||
LR[count] = 0;
|
||||
@@ -390,323 +340,6 @@ STATIC INLINE UINTPTR OsAddrIsValid(UINTPTR sp)
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 4)
|
||||
#define OS_BACKTRACE_START 0
|
||||
#define ALIGN_MASK (4 - 1)
|
||||
#define OS_REG_LR_OFFSET (CONTEXT_SIZE - 8)
|
||||
|
||||
UINT32 IsSpAligned(UINT32 value)
|
||||
{
|
||||
return (value & (UINT32)(ALIGN_MASK)) == 0;
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR HalGetLr(VOID)
|
||||
{
|
||||
UINTPTR regLr;
|
||||
|
||||
__asm__ __volatile__("mov %0, a0" : "=r"(regLr));
|
||||
|
||||
return regLr;
|
||||
}
|
||||
|
||||
/* This function is used to check sp address. */
|
||||
BOOL IsValidSP(UINTPTR regSP, UINTPTR start, UINTPTR end)
|
||||
{
|
||||
return (regSP >= start) && (regSP <= end) && IsSpAligned(regSP);
|
||||
}
|
||||
|
||||
/* This function is used to check return address. */
|
||||
BOOL IsValidRa(UINTPTR regRA)
|
||||
{
|
||||
regRA &= ~VIR_TEXT_ADDR_MASK;
|
||||
regRA |= TEXT_ADDR_MASK;
|
||||
|
||||
return OsStackDataIsCodeAddr(regRA);
|
||||
}
|
||||
|
||||
BOOL FindSuitableStack(UINTPTR regSP, UINTPTR *start, UINTPTR *end)
|
||||
{
|
||||
UINT32 stackStart;
|
||||
UINT32 stackEnd;
|
||||
BOOL found = FALSE;
|
||||
|
||||
if (LOS_TaskIsRunning()) {
|
||||
UINT32 taskID = LOS_CurTaskIDGet();
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
stackStart = taskCB->topOfStack;
|
||||
stackEnd = taskCB->topOfStack + taskCB->stackSize;
|
||||
if (IsValidSP(regSP, stackStart, stackEnd)) {
|
||||
found = TRUE;
|
||||
goto FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsValidSP(regSP, CSTACK_START_ADDR, CSTACK_END_ADDR)) {
|
||||
stackStart = CSTACK_START_ADDR;
|
||||
stackEnd = CSTACK_END_ADDR;
|
||||
found = TRUE;
|
||||
goto FOUND;
|
||||
}
|
||||
|
||||
FOUND:
|
||||
if (found == TRUE) {
|
||||
*start = stackStart;
|
||||
*end = stackEnd;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
UINT32 HalBackTraceGet(UINTPTR sp, UINT32 retAddr, UINTPTR *callChain, UINT32 maxDepth, UINT32 jumpCount)
|
||||
{
|
||||
UINTPTR tmpSp;
|
||||
UINT32 tmpRa;
|
||||
UINTPTR backRa = retAddr;
|
||||
UINTPTR backSp = sp;
|
||||
UINTPTR stackStart;
|
||||
UINT32 stackEnd;
|
||||
UINT32 count = 0;
|
||||
UINT32 index = 0;
|
||||
|
||||
if (FindSuitableStack(sp, &stackStart, &stackEnd) == FALSE) {
|
||||
PRINTK("sp:0x%x error, backtrace failed!\n", sp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (IsValidSP(backSp, stackStart, stackEnd)) {
|
||||
if (callChain == NULL) {
|
||||
PRINTK("trace%u ra:0x%x sp:0x%x\n", count, (backRa << WINDOW_INCREMENT_SHIFT) >>
|
||||
WINDOW_INCREMENT_SHIFT, backSp);
|
||||
} else {
|
||||
if (index++ < jumpCount) {
|
||||
continue;
|
||||
}
|
||||
backRa &= ~VIR_TEXT_ADDR_MASK;
|
||||
backRa |= TEXT_ADDR_MASK;
|
||||
callChain[count++] = backRa;
|
||||
}
|
||||
|
||||
tmpRa = backRa;
|
||||
tmpSp = backSp;
|
||||
backRa = *((UINT32 *)(UINTPTR)(tmpSp - RA_OFFSET));
|
||||
backSp = *((UINT32 *)(UINTPTR)(tmpSp - SP_OFFSET));
|
||||
|
||||
if ((tmpRa == backRa) || (backSp == tmpSp) || (count == maxDepth) || !IsValidRa(backRa)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
|
||||
{
|
||||
UINTPTR reglr;
|
||||
if (LR == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SP == 0) {
|
||||
__asm__ __volatile__("mov %0, sp" : "=a"(SP) : :);
|
||||
__asm__ __volatile__("mov %0, a0" : "=a"(reglr) : :);
|
||||
} else {
|
||||
reglr = *(UINT32 *)(SP - OS_REG_LR_OFFSET);
|
||||
}
|
||||
HakSpillWindow();
|
||||
HalBackTraceGet(SP, reglr, LR, LRSize, jumpCount);
|
||||
}
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 5)
|
||||
#define OS_BACKTRACE_START 0
|
||||
|
||||
UINT32 IsAligned(UINT32 val, UINT32 align)
|
||||
{
|
||||
return ((val & (align - 1)) == 0);
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR OsSpGet(VOID)
|
||||
{
|
||||
UINTPTR regSp;
|
||||
|
||||
__asm__ __volatile__("mov %0, sp" : "=r"(regSp));
|
||||
|
||||
return regSp;
|
||||
}
|
||||
|
||||
/* This function is used to check sp. */
|
||||
BOOL IsValidSP(UINTPTR regSP, UINTPTR start, UINTPTR end)
|
||||
{
|
||||
return (regSP >= start) && (regSP <= end);
|
||||
}
|
||||
|
||||
BOOL FindSuitableStack(UINTPTR regSP, UINTPTR *start, UINTPTR *end)
|
||||
{
|
||||
UINT32 stackStart;
|
||||
UINT32 stackEnd;
|
||||
BOOL found = FALSE;
|
||||
|
||||
if (LOS_TaskIsRunning()) {
|
||||
UINT32 taskID = LOS_CurTaskIDGet();
|
||||
LosTaskCB *taskCB = OS_TCB_FROM_TID(taskID);
|
||||
stackStart = taskCB->topOfStack;
|
||||
stackEnd = taskCB->topOfStack + taskCB->stackSize;
|
||||
if (IsValidSP(regSP, stackStart, stackEnd)) {
|
||||
found = TRUE;
|
||||
goto FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsValidSP(regSP, CSTACK_START_ADDR, CSTACK_END_ADDR)) {
|
||||
stackStart = CSTACK_START_ADDR;
|
||||
stackEnd = CSTACK_END_ADDR;
|
||||
found = TRUE;
|
||||
goto FOUND;
|
||||
}
|
||||
|
||||
FOUND:
|
||||
if (found == TRUE) {
|
||||
*start = stackStart;
|
||||
*end = stackEnd;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
|
||||
{
|
||||
UINTPTR stackPointer;
|
||||
UINTPTR topOfStack;
|
||||
UINTPTR tmpStack = 0;
|
||||
UINTPTR stackBottom;
|
||||
UINTPTR checkBL;
|
||||
UINT32 count = 0;
|
||||
UINT32 index = 0;
|
||||
|
||||
if (LR == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SP == 0) {
|
||||
SP = OsSpGet();
|
||||
}
|
||||
|
||||
stackPointer = SP;
|
||||
|
||||
if (FindSuitableStack(stackPointer, &topOfStack, &stackBottom) == FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
while ((stackPointer < stackBottom) && (count < LRSize)) {
|
||||
if (IsValidSP(*(UINT32 *)stackPointer, topOfStack, stackBottom)
|
||||
&& OsStackDataIsCodeAddr(*(UINT32 *)(stackPointer + STACK_OFFSET))
|
||||
&& IsAligned(*(UINT32 *)stackPointer, ALGIN_CODE)) {
|
||||
if (tmpStack == *(UINT32 *)stackPointer) {
|
||||
break;
|
||||
}
|
||||
tmpStack = *(UINT32 *)stackPointer;
|
||||
checkBL = *(UINT32 *)(stackPointer + STACK_OFFSET);
|
||||
if (count++ < jumpCount) {
|
||||
continue;
|
||||
}
|
||||
stackPointer = tmpStack;
|
||||
LR[index++] = checkBL;
|
||||
continue;
|
||||
}
|
||||
stackPointer += STACK_OFFSET;
|
||||
}
|
||||
|
||||
if (index < LRSize) {
|
||||
LR[index] = 0;
|
||||
}
|
||||
}
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 6)
|
||||
#define OS_BACKTRACE_START 1
|
||||
#define STACK_OFFSET 4
|
||||
#define THUMB_OFFSET 2
|
||||
#define THUMB_BIT 16
|
||||
#define ARM_ALIGN_CODE 4
|
||||
#define THUMB_ALIGN_CODE 2
|
||||
#define BL_CMD_OFFSET 4
|
||||
#define ARM_BL_MASK 0xEB000000
|
||||
#define THUMB_BL_MASK 0xF000F000
|
||||
#define CLEAR_LOW_BIT_MASK 0xFFFFFFFE
|
||||
|
||||
STATIC INLINE BOOL IsAligned(UINT32 val, UINT32 align)
|
||||
{
|
||||
return ((val & (align - 1)) == 0);
|
||||
}
|
||||
|
||||
STATIC INLINE UINTPTR OsSpGet(VOID)
|
||||
{
|
||||
UINTPTR SP;
|
||||
__asm volatile("mov %0, sp" : "=r"(SP));
|
||||
return SP;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL IsArmValidLr(UINTPTR lr)
|
||||
{
|
||||
return ((*(UINT32 *)(lr - BL_CMD_OFFSET) & ARM_BL_MASK) == ARM_BL_MASK);
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL IsThumbValidLr(UINTPTR lr)
|
||||
{
|
||||
lr = (*(UINT16 *)(lr - BL_CMD_OFFSET) << THUMB_BIT) + *(UINT16 *)(lr - THUMB_OFFSET);
|
||||
return ((lr & THUMB_BL_MASK) == THUMB_BL_MASK);
|
||||
}
|
||||
|
||||
VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP)
|
||||
{
|
||||
UINT32 count = 0;
|
||||
UINT32 index = 0;
|
||||
LosTaskCB *taskCB = NULL;
|
||||
UINT32 taskID;
|
||||
UINT32 stackStart, stackEnd;
|
||||
UINTPTR framePtr, tmpFramePtr, linkReg;
|
||||
|
||||
if (LR == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SP == 0) {
|
||||
SP = OsSpGet();
|
||||
}
|
||||
|
||||
if (LOS_TaskIsRunning()) {
|
||||
taskID = LOS_CurTaskIDGet();
|
||||
taskCB = OS_TCB_FROM_TID(taskID);
|
||||
stackStart = taskCB->topOfStack;
|
||||
stackEnd = stackStart + taskCB->stackSize;
|
||||
} else {
|
||||
stackStart = CSTACK_START_ADDR;
|
||||
stackEnd = CSTACK_END_ADDR;
|
||||
}
|
||||
|
||||
while ((SP > stackStart) && (SP < stackEnd)) {
|
||||
linkReg = *(UINTPTR *)SP;
|
||||
if (!OsStackDataIsCodeAddr(linkReg)) {
|
||||
SP += STACK_OFFSET;
|
||||
continue;
|
||||
}
|
||||
if (((!IsAligned(linkReg, ARM_ALIGN_CODE)) || !IsArmValidLr(linkReg)) &&
|
||||
((!IsAligned(linkReg - 1, THUMB_ALIGN_CODE)) || !IsThumbValidLr(linkReg - 1))) {
|
||||
SP += STACK_OFFSET;
|
||||
continue;
|
||||
}
|
||||
if (index >= jumpCount) {
|
||||
LR[count++] = linkReg & CLEAR_LOW_BIT_MASK;
|
||||
if (count == LRSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
++index;
|
||||
SP += STACK_OFFSET;
|
||||
}
|
||||
|
||||
/* if linkReg is not enough,clean up the last of the effective LR as the end. */
|
||||
if (count < LRSize) {
|
||||
LR[count] = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error Unknown backtrace type.
|
||||
#endif
|
||||
@@ -774,9 +407,10 @@ VOID LOS_BackTrace(VOID)
|
||||
PRINTK("----- traceback end -----\r\n");
|
||||
}
|
||||
|
||||
VOID OsBackTraceInit(VOID)
|
||||
VOID OSBackTraceInit(VOID)
|
||||
{
|
||||
OsBackTraceHookSet(LOS_RecordLR);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ extern "C" {
|
||||
#pragma section=CSTACK_SECTION_NAME
|
||||
|
||||
/* Default only one code section. In fact, there may be more than one.
|
||||
You can define more than one and redefine the OsStackDataIsCodeAddr function
|
||||
You can define more than one and modify the OsStackDataIsCodeAddr function
|
||||
to support searching in multiple code sections */
|
||||
#define CODE_START_ADDR ((UINTPTR)__section_begin(CODE_SECTION_NAME))
|
||||
#define CODE_END_ADDR ((UINTPTR)__section_end(CODE_SECTION_NAME))
|
||||
@@ -84,7 +84,7 @@ extern CHAR *CODE_SECTION_START(CODE_SECTION_NAME);
|
||||
extern CHAR *CODE_SECTION_END(CODE_SECTION_NAME);
|
||||
|
||||
/* Default only one code section. In fact, there may be more than one.
|
||||
You can define more than one and redefine the OsStackDataIsCodeAddr function
|
||||
You can define more than one and modify the OsStackDataIsCodeAddr function
|
||||
to support searching in multiple code sections */
|
||||
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START(CODE_SECTION_NAME))
|
||||
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END(CODE_SECTION_NAME))
|
||||
@@ -106,7 +106,7 @@ extern CHAR *CSTACK_SECTION_START;
|
||||
extern CHAR *CSTACK_SECTION_END;
|
||||
|
||||
/* Default only one code section. In fact, there may be more than one.
|
||||
You can define more than one and redefine the OsStackDataIsCodeAddr function
|
||||
You can define more than one and modify the OsStackDataIsCodeAddr function
|
||||
to support searching in multiple code sections */
|
||||
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
|
||||
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
|
||||
@@ -138,85 +138,22 @@ extern CHAR *CSTACK_SECTION_END;
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 4)
|
||||
/* The default code section start address */
|
||||
#define CODE_SECTION_START __text_start
|
||||
/* The default code section end address */
|
||||
#define CODE_SECTION_END __text_end
|
||||
/* The default C stack section start address */
|
||||
#define CSTACK_SECTION_START __init_stack_s
|
||||
/* The default C stack section end address */
|
||||
#define CSTACK_SECTION_END __init_stack_e
|
||||
|
||||
extern CHAR *CODE_SECTION_START;
|
||||
extern CHAR *CODE_SECTION_END;
|
||||
extern CHAR *CSTACK_SECTION_START;
|
||||
extern CHAR *CSTACK_SECTION_END;
|
||||
|
||||
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
|
||||
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
|
||||
#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START)
|
||||
#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END)
|
||||
|
||||
#define VIR_TEXT_ADDR_MASK 0x80000000
|
||||
#define TEXT_ADDR_MASK 0x40000000
|
||||
#define RA_OFFSET 16
|
||||
#define SP_OFFSET 12
|
||||
#define WINDOW_INCREMENT_SHIFT 2
|
||||
|
||||
UINT32 HalBackTraceGet(UINTPTR sp, UINT32 retAddr, UINTPTR *callChain, UINT32 maxDepth, UINT32 jumpCount);
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 5)
|
||||
/* The default code section start address */
|
||||
#define CODE_SECTION_START __text_start
|
||||
/* The default code section end address */
|
||||
#define CODE_SECTION_END __text_end
|
||||
/* The default C stack section start address */
|
||||
#define CSTACK_SECTION_START __init_stack_s
|
||||
/* The default C stack section end address */
|
||||
#define CSTACK_SECTION_END __ram_end
|
||||
|
||||
extern CHAR *CODE_SECTION_START;
|
||||
extern CHAR *CODE_SECTION_END;
|
||||
extern CHAR *CSTACK_SECTION_START;
|
||||
extern CHAR *CSTACK_SECTION_END;
|
||||
|
||||
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
|
||||
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
|
||||
#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START)
|
||||
#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END)
|
||||
|
||||
#define ALGIN_CODE 2
|
||||
#define STACK_OFFSET 4
|
||||
#elif (LOSCFG_BACKTRACE_TYPE == 6)
|
||||
extern CHAR *__svc_stack;
|
||||
extern CHAR *__svc_stack_top;
|
||||
/* The default code section start address */
|
||||
#define CODE_SECTION_START __text_start
|
||||
/* The default code section end address */
|
||||
#define CODE_SECTION_END __text_end
|
||||
/* The default C stack section start address */
|
||||
#define CSTACK_SECTION_START __svc_stack
|
||||
/* The default C stack section end address */
|
||||
#define CSTACK_SECTION_END __svc_stack_top
|
||||
|
||||
extern CHAR *CODE_SECTION_START;
|
||||
extern CHAR *CODE_SECTION_END;
|
||||
extern CHAR *CSTACK_SECTION_START;
|
||||
extern CHAR *CSTACK_SECTION_END;
|
||||
|
||||
/* Default only one code section. In fact, there may be more than one.
|
||||
You can define more than one and redefine the OsStackDataIsCodeAddr function
|
||||
to support searching in multiple code sections */
|
||||
#define CODE_START_ADDR ((UINTPTR)&CODE_SECTION_START)
|
||||
#define CODE_END_ADDR ((UINTPTR)&CODE_SECTION_END)
|
||||
#define CSTACK_START_ADDR ((UINTPTR)&CSTACK_SECTION_START)
|
||||
#define CSTACK_END_ADDR ((UINTPTR)&CSTACK_SECTION_END)
|
||||
|
||||
#endif
|
||||
|
||||
/* This function is used to judge whether the data in the stack is a code section address.
|
||||
The default code section is only one, but there may be more than one. Modify the
|
||||
judgment condition to support multiple code sections. */
|
||||
STATIC INLINE BOOL OsStackDataIsCodeAddr(UINTPTR value)
|
||||
{
|
||||
if ((value >= CODE_START_ADDR) && (value < CODE_END_ADDR)) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* This function is currently used to register the memory leak check hook,
|
||||
other uses do not need to be called temporarily. */
|
||||
VOID OsBackTraceInit(VOID);
|
||||
VOID OSBackTraceInit(VOID);
|
||||
|
||||
/* This function is used to print the function call stack. */
|
||||
VOID LOS_BackTrace(VOID);
|
||||
@@ -230,5 +167,4 @@ VOID LOS_RecordLR(UINTPTR *LR, UINT32 LRSize, UINT32 jumpCount, UINTPTR SP);
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -27,14 +27,8 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_KERNEL_CPPSUPPORT)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
static_library("cppsupport") {
|
||||
sources = [ "los_cppsupport.c" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
include_dirs = [ "../../utils" ]
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "los_cppsupport.h"
|
||||
|
||||
|
||||
typedef VOID (*InitFunc)(VOID);
|
||||
|
||||
INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd)
|
||||
@@ -38,10 +39,12 @@ INT32 LOS_CppSystemInit(UINTPTR initArrayStart, UINTPTR initArrayEnd)
|
||||
UINTPTR *start;
|
||||
InitFunc initFunc = NULL;
|
||||
|
||||
for (start = (UINTPTR *)initArrayStart; start < (UINTPTR *)initArrayEnd; start++) {
|
||||
for (start = (UINTPTR *)initArrayStart; start < (UINTPTR *)initArrayEnd; start++){
|
||||
initFunc = (InitFunc)(*start);
|
||||
initFunc();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,14 +27,13 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_BASE_CORE_CPUP)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
static_library("cpup") {
|
||||
sources = [ "los_cpup.c" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
include_dirs = [
|
||||
"../../kernel/include",
|
||||
"../../kernel/arch/include",
|
||||
"../../utils",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,39 +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.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_KERNEL_DYNLINK)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [ "los_dynlink.c" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
@@ -1,935 +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 "los_dynlink.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "unistd.h"
|
||||
#include "fcntl.h"
|
||||
#include "errno.h"
|
||||
#include "limits.h"
|
||||
#include "sys/stat.h"
|
||||
#include "securec.h"
|
||||
#include "arch_elf.h"
|
||||
#include "los_task.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_mux.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if (LOSCFG_DYNLINK == 1)
|
||||
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM)
|
||||
/**
|
||||
* Place instructions below in .icf linker file:
|
||||
*
|
||||
* keep {section .TABLE.START};
|
||||
* keep {section .sym.*};
|
||||
* keep {section .table.end};
|
||||
* define block SYMBOL_TABLE with fixed order
|
||||
* {
|
||||
* section .TABLE.START,
|
||||
* section .sym.*,
|
||||
* section .table.end
|
||||
* };
|
||||
* place in ROM_region {readonly, block SYMBOL_TABLE};
|
||||
*/
|
||||
const SymInfo symTableStart __attribute__((section(".TABLE.START"))) = {
|
||||
.name = "start",
|
||||
.addr = 0
|
||||
};
|
||||
|
||||
const SymInfo symTableEnd __attribute__((section(".table.end"))) = {
|
||||
.name = "end",
|
||||
.addr = 0
|
||||
};
|
||||
#pragma section=".TABLE.START"
|
||||
#pragma section=".table.end"
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
/**
|
||||
* Place instructions below in rodata segment of .ld linker file:
|
||||
*
|
||||
* __sym_table_start = .;
|
||||
* KEEP(*( SORT (.sym.*)));
|
||||
* __sym_table_end = .;
|
||||
*/
|
||||
extern char __sym_table_start[];
|
||||
extern char __sym_table_end[];
|
||||
#else
|
||||
#error Unknown compiler.
|
||||
#endif
|
||||
|
||||
STATIC LOS_DL_LIST g_dynSharedObjLink;
|
||||
STATIC UINT32 g_dynlinkMux;
|
||||
|
||||
STATIC DynSharedObj *OsIsPreLoaded(const CHAR *fileName)
|
||||
{
|
||||
DynSharedObj *dso = NULL;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(dso, &g_dynSharedObjLink, DynSharedObj, dsoNode) {
|
||||
if (!strcmp(fileName, dso->fileName)) {
|
||||
++dso->ref;
|
||||
return dso;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC INT32 OsVerifyEhdr(const LD_ELF_EHDR *ehdr, UINT32 fileLen)
|
||||
{
|
||||
if (memcmp(ehdr->e_ident, LD_ELFMAG, LD_SELFMAG) != LOS_OK) {
|
||||
PRINT_ERR("The file is not elf format\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
if (ehdr->e_type != ET_DYN) {
|
||||
PRINT_ERR("The file is not shared library\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
if (!check_arch(ehdr)) {
|
||||
PRINT_ERR("The file can not load in current platform\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
if (ehdr->e_phnum > PHDR_NUM_MAX) {
|
||||
PRINT_ERR("The num of program header is out of limit\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
if (ehdr->e_phoff > fileLen) {
|
||||
PRINT_ERR("The offset of program header is invalid, elf file is bad\n");
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsReadELFInfo(INT32 fd, UINT8 *buffer, size_t readSize, off_t offset)
|
||||
{
|
||||
ssize_t byteNum;
|
||||
off_t returnPos;
|
||||
|
||||
if (readSize > 0) {
|
||||
returnPos = lseek(fd, offset, SEEK_SET);
|
||||
if (returnPos != offset) {
|
||||
PRINT_ERR("Failed to seek the position!, offset: %#x\n", offset);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
byteNum = read(fd, buffer, readSize);
|
||||
if (byteNum <= 0) {
|
||||
PRINT_ERR("Failed to read from offset: %#x!\n", offset);
|
||||
return LOS_NOK;
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsGetFileLength(UINT32 *fileLen, const CHAR *fileName)
|
||||
{
|
||||
struct stat buf;
|
||||
INT32 ret;
|
||||
|
||||
ret = stat(fileName, &buf);
|
||||
if (ret < 0) {
|
||||
PRINT_ERR("Failed to stat file: %s, errno: %d\n", fileName, errno);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
if (buf.st_size > FILE_LENGTH_MAX) {
|
||||
PRINT_ERR("The file: %s length is out of limit!\n", fileName);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
*fileLen = (UINT32)buf.st_size;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsReadEhdr(INT32 fd, UINT32 fileLen, DynLinkInfo *dlInfo)
|
||||
{
|
||||
INT32 ret;
|
||||
|
||||
ret = OsReadELFInfo(fd, (UINT8 *)&dlInfo->elfEhdr, sizeof(LD_ELF_EHDR), 0);
|
||||
if (ret != LOS_OK) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = OsVerifyEhdr(&dlInfo->elfEhdr, fileLen);
|
||||
if (ret != LOS_OK) {
|
||||
return -ELIBBAD;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsReadPhdrs(INT32 fd, UINT32 fileLen, DynLinkInfo *dlInfo)
|
||||
{
|
||||
INT32 ret;
|
||||
UINT32 size;
|
||||
LD_ELF_EHDR *ehdr = &dlInfo->elfEhdr;
|
||||
|
||||
if ((ehdr->e_phnum == 0) || (ehdr->e_phentsize != sizeof(LD_ELF_PHDR))) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
size = sizeof(LD_ELF_PHDR) * ehdr->e_phnum;
|
||||
if ((ehdr->e_phoff + size) > fileLen) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
dlInfo->elfPhdr = (LD_ELF_PHDR *)LOS_MemAlloc(OS_SYS_MEM_ADDR, size);
|
||||
if (dlInfo->elfPhdr == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = OsReadELFInfo(fd, (UINT8 *)dlInfo->elfPhdr, size, ehdr->e_phoff);
|
||||
if (ret != LOS_OK) {
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dlInfo->elfPhdr);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
|
||||
ERR:
|
||||
PRINT_ERR("the file is bad\n");
|
||||
return -ELIBBAD;
|
||||
}
|
||||
|
||||
STATIC DynSharedObj *OsLoadInit(const CHAR *fileName, VOID *pool)
|
||||
{
|
||||
DynSharedObj *dso = NULL;
|
||||
UINT32 allocSize, nameLen;
|
||||
UINT32 fileLen = 0;
|
||||
INT32 ret;
|
||||
|
||||
nameLen = strlen(fileName);
|
||||
if (nameLen > PATH_MAX) {
|
||||
PRINT_ERR("file name length is too long\n");
|
||||
errno = ENAMETOOLONG;
|
||||
return NULL;
|
||||
}
|
||||
allocSize = sizeof(DynSharedObj) + nameLen + 1;
|
||||
|
||||
dso = (DynSharedObj *)LOS_MemAlloc(OS_SYS_MEM_ADDR, allocSize);
|
||||
if (dso == NULL) {
|
||||
PRINT_ERR("failed to alloc for dso\n");
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(dso, allocSize, 0, allocSize);
|
||||
|
||||
dso->dlInfo = (DynLinkInfo *)LOS_MemAlloc(OS_SYS_MEM_ADDR, sizeof(DynLinkInfo));
|
||||
if (dso->dlInfo == NULL) {
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
PRINT_ERR("failed to alloc for loadInfo\n");
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
(VOID)memset_s(dso->dlInfo, sizeof(DynLinkInfo), 0, sizeof(DynLinkInfo));
|
||||
|
||||
ret = OsGetFileLength(&fileLen, fileName);
|
||||
if (ret != LOS_OK) {
|
||||
errno = ENOENT;
|
||||
goto ERR1;
|
||||
}
|
||||
|
||||
dso->fd = open(fileName, O_RDONLY);
|
||||
if (dso->fd < 0) {
|
||||
PRINT_ERR("Failed to open ELF file: %s!\n", fileName);
|
||||
goto ERR1;
|
||||
}
|
||||
|
||||
ret = OsReadEhdr(dso->fd, fileLen, dso->dlInfo);
|
||||
if (ret != LOS_OK) {
|
||||
errno = -ret;
|
||||
goto ERR2;
|
||||
}
|
||||
|
||||
ret = OsReadPhdrs(dso->fd, fileLen, dso->dlInfo);
|
||||
if (ret != LOS_OK) {
|
||||
errno = -ret;
|
||||
goto ERR2;
|
||||
}
|
||||
|
||||
strcpy(dso->buf, fileName);
|
||||
dso->fileName = dso->buf;
|
||||
dso->ref = 1;
|
||||
dso->pool = (pool ? pool : OS_SYS_MEM_ADDR);
|
||||
LOS_ListInit(&dso->dsoNode);
|
||||
|
||||
return dso;
|
||||
|
||||
ERR2:
|
||||
close(dso->fd);
|
||||
ERR1:
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC INT32 OsReserveSpace(const DynLinkInfo *dlInfo, UINT32 *boundary)
|
||||
{
|
||||
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
|
||||
INT32 phdrNum = dlInfo->elfEhdr.e_phnum;
|
||||
UINTPTR addrMin = SIZE_MAX;
|
||||
UINTPTR addrMax = 0;
|
||||
UINT32 offStart = 0;
|
||||
UINT64 size;
|
||||
INT32 i;
|
||||
|
||||
for (i = 0; i < phdrNum; ++i, ++elfPhdrTemp) {
|
||||
if (elfPhdrTemp->p_type == PT_TLS) {
|
||||
PRINT_ERR("unsupport tls\n");
|
||||
return 0;
|
||||
}
|
||||
if (elfPhdrTemp->p_type != PT_LOAD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (*boundary == 0) {
|
||||
*boundary = elfPhdrTemp->p_align;
|
||||
}
|
||||
|
||||
if (elfPhdrTemp->p_vaddr < addrMin) {
|
||||
addrMin = elfPhdrTemp->p_vaddr;
|
||||
offStart = elfPhdrTemp->p_offset;
|
||||
}
|
||||
if ((elfPhdrTemp->p_vaddr + elfPhdrTemp->p_memsz) > addrMax) {
|
||||
addrMax = elfPhdrTemp->p_vaddr + elfPhdrTemp->p_memsz;
|
||||
}
|
||||
}
|
||||
|
||||
if ((addrMin == addrMax) || (addrMax < addrMin)) {
|
||||
return 0;
|
||||
}
|
||||
size = ELF_ALIGN_UP(addrMax, *boundary) - ELF_ALIGN_DOWN(addrMin, *boundary) + ELF_ALIGN_DOWN(offStart, *boundary);
|
||||
|
||||
return (size > UINT_MAX) ? 0 : (UINT32)size;
|
||||
}
|
||||
|
||||
STATIC UINTPTR OsDoLoadFile(INT32 fd, UINTPTR addr, const LD_ELF_PHDR *elfPhdr, UINT32 boundary)
|
||||
{
|
||||
INT32 ret;
|
||||
UINT32 offset = elfPhdr->p_offset - ELF_ALIGN_OFFSET(elfPhdr->p_vaddr, boundary);
|
||||
UINT32 size = elfPhdr->p_filesz + ELF_ALIGN_OFFSET(elfPhdr->p_vaddr, boundary);
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr = ELF_ALIGN_DOWN(addr, boundary);
|
||||
ret = OsReadELFInfo(fd, (UINT8 *)addr, size, offset);
|
||||
if (ret != LOS_OK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
STATIC INT32 OsLoadELFFile(DynSharedObj *dso, UINT32 boundary)
|
||||
{
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
|
||||
const LD_ELF_EHDR *elfEhdr = &dlInfo->elfEhdr;
|
||||
UINTPTR loadBase = dso->loadBase;
|
||||
UINTPTR vAddr, loadAddr, bssStart, bssEnd;
|
||||
INT32 i;
|
||||
|
||||
for (i = 0; i < elfEhdr->e_phnum; ++i, ++elfPhdrTemp) {
|
||||
if (elfPhdrTemp->p_type != PT_LOAD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((elfPhdrTemp->p_flags & PF_R) == 0) {
|
||||
return -ENOEXEC;
|
||||
}
|
||||
vAddr = elfPhdrTemp->p_vaddr;
|
||||
|
||||
loadAddr = OsDoLoadFile(dso->fd, (vAddr + loadBase), elfPhdrTemp, boundary);
|
||||
if (loadAddr == 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if ((elfPhdrTemp->p_memsz > elfPhdrTemp->p_filesz) && (elfPhdrTemp->p_flags & PF_W)) {
|
||||
bssStart = loadAddr + ELF_ALIGN_OFFSET(vAddr, boundary) + elfPhdrTemp->p_filesz;
|
||||
bssEnd = loadAddr + ELF_ALIGN_OFFSET(vAddr, boundary) + elfPhdrTemp->p_memsz;
|
||||
(VOID)memset_s((VOID *)bssStart, bssEnd - bssStart, 0, bssEnd - bssStart);
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsLoadLibrary(DynSharedObj *dso)
|
||||
{
|
||||
UINT32 loadSize;
|
||||
UINT32 boundary = 0;
|
||||
INT32 ret;
|
||||
|
||||
loadSize = OsReserveSpace(dso->dlInfo, &boundary);
|
||||
if (loadSize == 0) {
|
||||
PRINT_ERR("failed to reserve space!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dso->loadBase = (UINTPTR)LOS_MemAllocAlign(dso->pool, loadSize, boundary);
|
||||
if (dso->loadBase == 0) {
|
||||
PRINT_ERR("failed to alloc memory for loading shared library\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = OsLoadELFFile(dso, boundary);
|
||||
if (ret != LOS_OK) {
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
PRINT_ERR("failed to load shared library\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsGetDynBase(DynSharedObj *dso)
|
||||
{
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
const LD_ELF_PHDR *elfPhdrTemp = dlInfo->elfPhdr;
|
||||
INT32 phdrNum = dlInfo->elfEhdr.e_phnum;
|
||||
INT32 i;
|
||||
|
||||
for (i = 0; i < phdrNum; ++i, ++elfPhdrTemp) {
|
||||
if (elfPhdrTemp->p_type != PT_DYNAMIC) {
|
||||
continue;
|
||||
}
|
||||
dlInfo->dynBase = dso->loadBase + elfPhdrTemp->p_vaddr;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsParseDynamic(DynSharedObj *dso)
|
||||
{
|
||||
LD_ELF_DYN *dyn = NULL;
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
RelocInfoTab *relInfoTab = &dlInfo->relInfoTab;
|
||||
|
||||
for (dyn = (LD_ELF_DYN *)dlInfo->dynBase; dyn->d_tag != DT_NULL; ++dyn) {
|
||||
switch (dyn->d_tag) {
|
||||
case DT_NEEDED:
|
||||
PRINT_ERR("shared library should not depend on others\n");
|
||||
return -ENOTSUP;
|
||||
case DT_TEXTREL:
|
||||
PRINT_ERR("you should recompile shared library with -fPIC\n");
|
||||
return -EFAULT;
|
||||
case DT_HASH:
|
||||
dlInfo->hashTab = (UINT32 *)(dso->loadBase + dyn->d_un.d_ptr);
|
||||
break;
|
||||
case DT_SYMTAB:
|
||||
dlInfo->symTab = (LD_ELF_SYM *)(dso->loadBase + dyn->d_un.d_ptr);
|
||||
break;
|
||||
case DT_STRTAB:
|
||||
dlInfo->symStrings = (CHAR *)(dso->loadBase + dyn->d_un.d_ptr);
|
||||
break;
|
||||
case DT_REL:
|
||||
relInfoTab->rel.relTab = dso->loadBase + dyn->d_un.d_ptr;
|
||||
relInfoTab->rel.relEntSize = sizeof(LD_ELF_REL);
|
||||
break;
|
||||
case DT_RELSZ:
|
||||
relInfoTab->rel.relTabSize = dyn->d_un.d_val;
|
||||
break;
|
||||
case DT_RELA:
|
||||
relInfoTab->rela.relTab = dso->loadBase + dyn->d_un.d_ptr;
|
||||
relInfoTab->rela.relEntSize = sizeof(LD_ELF_RELA);
|
||||
break;
|
||||
case DT_RELASZ:
|
||||
relInfoTab->rela.relTabSize = dyn->d_un.d_val;
|
||||
break;
|
||||
case DT_JMPREL:
|
||||
relInfoTab->jmpRel.relTab = dso->loadBase + dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_PLTRELSZ:
|
||||
relInfoTab->jmpRel.relTabSize = dyn->d_un.d_val;
|
||||
break;
|
||||
case DT_PLTREL:
|
||||
relInfoTab->jmpRel.relEntSize = (dyn->d_un.d_val == DT_REL) ? sizeof(LD_ELF_REL) : sizeof(LD_ELF_RELA);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsGetHashVal(const CHAR *name)
|
||||
{
|
||||
UINT32 hashVal = 0;
|
||||
UINT32 tmp;
|
||||
const UINT8 *str = (const UINT8 *)name;
|
||||
|
||||
while (*str) {
|
||||
hashVal = (*str) + (hashVal << WORD_SHIFT);
|
||||
tmp = hashVal & HASH_MASK;
|
||||
if (tmp != 0) {
|
||||
hashVal ^= tmp >> HASH_SHIFT;
|
||||
}
|
||||
|
||||
hashVal &= ~tmp;
|
||||
++str;
|
||||
}
|
||||
|
||||
return hashVal;
|
||||
}
|
||||
|
||||
STATIC LD_ELF_SYM *OsFindSymInDso(const DynLinkInfo *dlInfo, const CHAR *name)
|
||||
{
|
||||
LD_ELF_SYM *symTab = dlInfo->symTab;
|
||||
LD_ELF_SYM *sym = NULL;
|
||||
CHAR *symStr = dlInfo->symStrings;
|
||||
UINT32 *hashTab = dlInfo->hashTab;
|
||||
UINT32 bucketNum = hashTab[0];
|
||||
UINT32 *bucket = &hashTab[BUCKET_IDX];
|
||||
UINT32 *chain = &bucket[bucketNum];
|
||||
UINT32 hashVal = OsGetHashVal(name);
|
||||
UINT32 symIdx;
|
||||
|
||||
for (symIdx = bucket[hashVal % bucketNum]; symIdx; symIdx = chain[symIdx]) {
|
||||
if (strcmp(name, symStr + symTab[symIdx].st_name) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sym = symTab + symIdx;
|
||||
if ((sym->st_value == 0) || (sym->st_shndx == 0)) {
|
||||
return NULL;
|
||||
}
|
||||
return symTab + symIdx;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC SymInfo *OsFindSymInTable(const CHAR *name)
|
||||
{
|
||||
#if defined(__ICCARM__) || defined(__CC_ARM)
|
||||
SymInfo *symTab = (SymInfo *)__section_end(".TABLE.START");
|
||||
UINT32 symTableSize = ((UINTPTR)__section_begin(".table.end") -
|
||||
(UINTPTR)__section_end(".TABLE.START")) / sizeof(SymInfo);
|
||||
#elif defined(__CLANG_ARM) || defined(__GNUC__)
|
||||
SymInfo *symTab = (SymInfo *)__sym_table_start;
|
||||
UINT32 symTableSize = (__sym_table_end - __sym_table_start) / sizeof(SymInfo);
|
||||
#endif
|
||||
INT32 startIdx = 0;
|
||||
INT32 endIdx = symTableSize - 1;
|
||||
INT32 ret, midIdx;
|
||||
|
||||
while (startIdx <= endIdx) {
|
||||
midIdx = startIdx + ((UINT32)(endIdx - startIdx) >> 1);
|
||||
ret = strcmp(symTab[midIdx].name, name);
|
||||
if (ret > 0) {
|
||||
endIdx = midIdx - 1;
|
||||
} else if (ret < 0) {
|
||||
startIdx = midIdx + 1;
|
||||
} else {
|
||||
return symTab + midIdx;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC UINTPTR OsFindSym(const DynSharedObj *dso, INT32 symIdx)
|
||||
{
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
CHAR *symStrings = dlInfo->symStrings;
|
||||
CHAR *symStr = NULL;
|
||||
LD_ELF_SYM *symTab = dlInfo->symTab;
|
||||
LD_ELF_SYM *sym = NULL;
|
||||
LD_ELF_SYM *symInDso = NULL;
|
||||
SymInfo *symInTab = NULL;
|
||||
|
||||
sym = symTab + symIdx;
|
||||
symStr = symStrings + sym->st_name;
|
||||
if ((symInDso = OsFindSymInDso(dlInfo, symStr)) != NULL) {
|
||||
return dso->loadBase + symInDso->st_value;
|
||||
} else if ((symInTab = OsFindSymInTable(symStr)) != NULL) {
|
||||
return symInTab->addr;
|
||||
} else {
|
||||
PRINT_ERR("failed to relocate %s, symbol: %s not found\n", dso->fileName, symStr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INT32 OsDoReloc(const DynSharedObj *dso, INT32 type, UINTPTR relocAddr, UINT32 addend, UINTPTR symAddr)
|
||||
{
|
||||
switch (type) {
|
||||
case R_ARCH_NONE:
|
||||
break;
|
||||
case R_ARCH_GLOB_DAT:
|
||||
case R_ARCH_JUMP_SLOT:
|
||||
*(UINTPTR *)relocAddr = symAddr + addend;
|
||||
break;
|
||||
case R_ARCH_ABS32:
|
||||
*(UINTPTR *)relocAddr = symAddr + ((addend != 0) ? addend : *(UINTPTR *)relocAddr);
|
||||
break;
|
||||
case R_ARCH_RELATIVE:
|
||||
*(UINTPTR *)relocAddr = dso->loadBase + ((addend != 0) ? addend : *(UINTPTR *)relocAddr);
|
||||
break;
|
||||
default:
|
||||
PRINT_ERR("failed to relocate %s, unsupported reloc type: %d\n", dso->fileName, type);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsDoRelocSyms(DynSharedObj *dso, RelocInfo *relInfo)
|
||||
{
|
||||
UINT32 relStride = relInfo->relEntSize / sizeof(UINT32);
|
||||
UINT32 *relTab = (UINT32 *)relInfo->relTab;
|
||||
UINT32 addend;
|
||||
UINTPTR relocAddr, symAddr;
|
||||
INT32 i, symIdx, ret, type;
|
||||
|
||||
for (i = 0; i < relInfo->relTabSize; i += relInfo->relEntSize, relTab += relStride) {
|
||||
type = REL_TYPE(relTab[1]);
|
||||
if (type == R_ARCH_NONE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
symIdx = REL_SYM(relTab[1]);
|
||||
if (symIdx == 0) {
|
||||
symAddr = 0;
|
||||
} else {
|
||||
symAddr = OsFindSym(dso, symIdx);
|
||||
if (symAddr == 0) {
|
||||
return -EFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
relocAddr = dso->loadBase + relTab[0];
|
||||
addend = (relInfo->relEntSize == sizeof(LD_ELF_REL)) ? 0 : relTab[relStride - 1];
|
||||
ret = OsDoReloc(dso, type, relocAddr, addend, symAddr);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsRelocSyms(DynSharedObj *dso)
|
||||
{
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
RelocInfo *relInfo = (RelocInfo *)&dlInfo->relInfoTab;
|
||||
INT32 relTypes = sizeof(RelocInfoTab) / sizeof(RelocInfo);
|
||||
INT32 i, ret;
|
||||
|
||||
for (i = 0; i < relTypes; ++i, ++relInfo) {
|
||||
if (relInfo->relTab == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = OsDoRelocSyms(dso, relInfo);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INT32 OsDoDynLink(DynSharedObj *dso)
|
||||
{
|
||||
INT32 ret;
|
||||
|
||||
ret = OsGetDynBase(dso);
|
||||
if (ret != LOS_OK) {
|
||||
PRINT_ERR("there are no dynamic segments in elf file\n");
|
||||
return -ELIBBAD;
|
||||
}
|
||||
|
||||
ret = OsParseDynamic(dso);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsRelocSyms(dso);
|
||||
if (ret != LOS_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID OsDeLoadInit(DynSharedObj *dso)
|
||||
{
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
dso->dlInfo->elfPhdr = NULL;
|
||||
close(dso->fd);
|
||||
}
|
||||
|
||||
STATIC VOID OsGetInitFini(DynSharedObj *dso)
|
||||
{
|
||||
LD_ELF_DYN *dyn = NULL;
|
||||
DynLinkInfo *dlInfo = dso->dlInfo;
|
||||
InitFiniTab *initFiniTab = &dso->initFiniTab;
|
||||
|
||||
for (dyn = (LD_ELF_DYN *)dlInfo->dynBase; dyn->d_tag != DT_NULL; ++dyn) {
|
||||
switch (dyn->d_tag) {
|
||||
case DT_INIT:
|
||||
initFiniTab->init.func = dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_INIT_ARRAY:
|
||||
initFiniTab->init.array = dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_INIT_ARRAYSZ:
|
||||
initFiniTab->init.arraySz = dyn->d_un.d_val;
|
||||
break;
|
||||
case DT_FINI:
|
||||
initFiniTab->fini.func = dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_FINI_ARRAY:
|
||||
initFiniTab->fini.array = dyn->d_un.d_ptr;
|
||||
break;
|
||||
case DT_FINI_ARRAYSZ:
|
||||
initFiniTab->fini.arraySz = dyn->d_un.d_val;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsDoInit(DynSharedObj *dso)
|
||||
{
|
||||
InitFiniTab *initFiniTab = &dso->initFiniTab;
|
||||
INIT_FINI_FUNC initFunc = NULL;
|
||||
UINTPTR *func = NULL;
|
||||
UINT32 funcNum;
|
||||
|
||||
OsGetInitFini(dso);
|
||||
if (initFiniTab->init.func != 0) {
|
||||
initFunc = (INIT_FINI_FUNC)(dso->loadBase + initFiniTab->init.func);
|
||||
initFunc();
|
||||
}
|
||||
|
||||
if (initFiniTab->init.array == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
funcNum = initFiniTab->init.arraySz / sizeof(UINTPTR);
|
||||
func = (UINTPTR *)(dso->loadBase + initFiniTab->init.array);
|
||||
while (funcNum--) {
|
||||
initFunc = (INIT_FINI_FUNC)(*func);
|
||||
initFunc();
|
||||
++func;
|
||||
}
|
||||
}
|
||||
|
||||
VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool)
|
||||
{
|
||||
INT32 ret;
|
||||
DynSharedObj *dso = NULL;
|
||||
|
||||
if (fileName == NULL) {
|
||||
PRINT_ERR("invalid file name\n");
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
|
||||
dso = OsIsPreLoaded(fileName);
|
||||
if (dso != NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
return dso;
|
||||
}
|
||||
|
||||
dso = OsLoadInit(fileName, pool);
|
||||
if (dso == NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = OsLoadLibrary(dso);
|
||||
if (ret != LOS_OK) {
|
||||
errno = -ret;
|
||||
goto ERR1;
|
||||
}
|
||||
|
||||
ret = OsDoDynLink(dso);
|
||||
if (ret != LOS_OK) {
|
||||
errno = -ret;
|
||||
goto ERR2;
|
||||
}
|
||||
|
||||
OsDoInit(dso);
|
||||
|
||||
LOS_ListAdd(&g_dynSharedObjLink, &dso->dsoNode);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
OsDeLoadInit(dso);
|
||||
|
||||
return dso;
|
||||
|
||||
ERR2:
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
ERR1:
|
||||
close(dso->fd);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo->elfPhdr);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC DynSharedObj *OsCheckHandle(VOID *handle)
|
||||
{
|
||||
DynSharedObj *dso = NULL;
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(dso, &g_dynSharedObjLink, DynSharedObj, dsoNode) {
|
||||
if (handle == dso) {
|
||||
return dso;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VOID *LOS_FindSym(VOID *handle, const CHAR *name)
|
||||
{
|
||||
LD_ELF_SYM *sym = NULL;
|
||||
DynSharedObj *dso = NULL;
|
||||
VOID *symAddr = NULL;
|
||||
|
||||
if ((handle == NULL) || (name == NULL)) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
|
||||
dso = OsCheckHandle(handle);
|
||||
if (dso == NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
sym = OsFindSymInDso(dso->dlInfo, name);
|
||||
if (sym == NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
PRINT_ERR("failed to find symbol: %s\n", name);
|
||||
errno = EFAULT;
|
||||
return NULL;
|
||||
}
|
||||
symAddr = (VOID *)(dso->loadBase + sym->st_value);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
return symAddr;
|
||||
|
||||
ERR:
|
||||
PRINT_ERR("invalid input param\n");
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC VOID OsDoFini(DynSharedObj *dso)
|
||||
{
|
||||
InitFiniTab *initFiniTab = &dso->initFiniTab;
|
||||
INIT_FINI_FUNC finiFunc = NULL;
|
||||
UINTPTR *func = NULL;
|
||||
UINT32 funcNum;
|
||||
|
||||
if (initFiniTab->fini.array != 0) {
|
||||
funcNum = initFiniTab->fini.arraySz / sizeof(UINTPTR);
|
||||
func = (UINTPTR *)(dso->loadBase + initFiniTab->fini.array) + funcNum;
|
||||
while (funcNum--) {
|
||||
--func;
|
||||
finiFunc = (INIT_FINI_FUNC)(*func);
|
||||
finiFunc();
|
||||
}
|
||||
}
|
||||
|
||||
if (initFiniTab->fini.func != 0) {
|
||||
finiFunc = (INIT_FINI_FUNC)(dso->loadBase + initFiniTab->fini.func);
|
||||
finiFunc();
|
||||
}
|
||||
}
|
||||
|
||||
INT32 LOS_SoUnload(VOID *handle)
|
||||
{
|
||||
DynSharedObj *dso = NULL;
|
||||
|
||||
if (handle == NULL) {
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
(VOID)LOS_MuxPend(g_dynlinkMux, LOS_WAIT_FOREVER);
|
||||
dso = OsCheckHandle(handle);
|
||||
if (dso == NULL) {
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
goto ERR;
|
||||
}
|
||||
|
||||
if (dso->ref > 1) {
|
||||
--dso->ref;
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
OsDoFini(dso);
|
||||
|
||||
LOS_ListDelete(&dso->dsoNode);
|
||||
(VOID)LOS_MuxPost(g_dynlinkMux);
|
||||
|
||||
LOS_MemFree(dso->pool, (VOID *)dso->loadBase);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso->dlInfo);
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, dso);
|
||||
|
||||
return LOS_OK;
|
||||
ERR:
|
||||
PRINT_ERR("invalid handle\n");
|
||||
errno = EINVAL;
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
INT32 LOS_DynlinkInit(VOID)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
LOS_ListInit(&g_dynSharedObjLink);
|
||||
ret = LOS_MuxCreate(&g_dynlinkMux);
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#endif /* LOSCFG_DYNLINK */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@@ -1,201 +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 _LOS_DYNLINK_H
|
||||
#define _LOS_DYNLINK_H
|
||||
|
||||
#include "elf.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_list.h"
|
||||
#include "los_memory.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef LOSCFG_AARCH64
|
||||
typedef Elf64_Ehdr LD_ELF_EHDR;
|
||||
typedef Elf64_Phdr LD_ELF_PHDR;
|
||||
typedef Elf64_Sym LD_ELF_SYM;
|
||||
typedef Elf64_Dyn LD_ELF_DYN;
|
||||
typedef Elf64_Rel LD_ELF_REL;
|
||||
typedef Elf64_Rela LD_ELF_RELA;
|
||||
#define REL_TYPE(x) ELF64_R_TYPE(x)
|
||||
#define REL_SYM(x) ELF64_R_SYM(x)
|
||||
#define REL_INFO ELF64_R_INFO
|
||||
#else
|
||||
typedef Elf32_Ehdr LD_ELF_EHDR;
|
||||
typedef Elf32_Phdr LD_ELF_PHDR;
|
||||
typedef Elf32_Sym LD_ELF_SYM;
|
||||
typedef Elf32_Dyn LD_ELF_DYN;
|
||||
typedef Elf32_Rel LD_ELF_REL;
|
||||
typedef Elf32_Rela LD_ELF_RELA;
|
||||
#define REL_TYPE(x) ELF32_R_TYPE(x)
|
||||
#define REL_SYM(x) ELF32_R_SYM(x)
|
||||
#define REL_INFO ELF32_R_INFO
|
||||
#endif
|
||||
|
||||
#define LD_ELFMAG "\177ELF"
|
||||
#define LD_SELFMAG 4
|
||||
#define PHDR_NUM_MAX 128
|
||||
#define DYNAMIC_CNT 32
|
||||
#define HASH_MASK 0xf0000000
|
||||
#define WORD_SHIFT 4
|
||||
#define HASH_SHIFT 24
|
||||
#define BUCKET_IDX 2
|
||||
|
||||
#define ELF_ALIGN_UP(a, b) (((a) + ((b) - 1)) & ~((b) - 1))
|
||||
#define ELF_ALIGN_DOWN(a, b) ((a) & ~((b) - 1))
|
||||
#define ELF_ALIGN_OFFSET(a, b) ((a) & ((b) - 1))
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
#ifndef FILE_LENGTH_MAX
|
||||
#define FILE_LENGTH_MAX 0x40000
|
||||
#endif
|
||||
typedef VOID (*INIT_FINI_FUNC)(VOID);
|
||||
|
||||
typedef struct {
|
||||
UINTPTR relTab;
|
||||
UINT32 relTabSize;
|
||||
UINT32 relEntSize;
|
||||
} RelocInfo;
|
||||
|
||||
typedef struct {
|
||||
RelocInfo rel;
|
||||
RelocInfo rela;
|
||||
RelocInfo jmpRel;
|
||||
} RelocInfoTab;
|
||||
|
||||
typedef struct {
|
||||
UINTPTR func;
|
||||
UINTPTR array;
|
||||
UINT32 arraySz;
|
||||
} InitFiniInfo;
|
||||
|
||||
typedef struct {
|
||||
InitFiniInfo init;
|
||||
InitFiniInfo fini;
|
||||
} InitFiniTab;
|
||||
|
||||
typedef struct {
|
||||
LD_ELF_EHDR elfEhdr;
|
||||
LD_ELF_PHDR *elfPhdr;
|
||||
UINTPTR dynBase;
|
||||
UINT32 *hashTab;
|
||||
LD_ELF_SYM *symTab;
|
||||
CHAR *symStrings;
|
||||
RelocInfoTab relInfoTab;
|
||||
} DynLinkInfo;
|
||||
|
||||
typedef struct {
|
||||
CHAR *fileName;
|
||||
INT32 fd;
|
||||
DynLinkInfo *dlInfo;
|
||||
UINTPTR loadBase;
|
||||
InitFiniTab initFiniTab;
|
||||
LOS_DL_LIST dsoNode;
|
||||
UINT32 ref;
|
||||
VOID *pool;
|
||||
CHAR buf[];
|
||||
} DynSharedObj;
|
||||
|
||||
typedef struct {
|
||||
CHAR *name;
|
||||
UINTPTR addr;
|
||||
} SymInfo;
|
||||
|
||||
#define SYM_EXPORT(func) \
|
||||
const SymInfo sym_##func __attribute__((section(".sym."#func))) = { \
|
||||
.name = #func, \
|
||||
.addr = (UINTPTR)func \
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief Load the shared library file named by the NULL-terminated string filename and
|
||||
* return a valid handle for the loaded library.
|
||||
*
|
||||
* @param fileName The name pointer of shared library.
|
||||
* @param pool The heap for shared library to load. If the parameter, pool, is NULL, then
|
||||
* the dynamic loader & linker module will use the default heap and the pool is not NULL,
|
||||
* then the shared library will be loaded to the heap by pool.
|
||||
*
|
||||
* @note When the heap, pool, is not NULL, you should call LOS_MemInit() to initialize the
|
||||
* pool before calling LOS_SoLoad(). By the way, the system will comsume a certain amount
|
||||
* of memory to initialize the pool. LOS_SoLoad must not be called in interrupt callback.
|
||||
*
|
||||
* @return Return NULL if error. Return non-NULL if success.
|
||||
*/
|
||||
VOID *LOS_SoLoad(const CHAR *fileName, VOID *pool);
|
||||
|
||||
/*
|
||||
* @brief Get the address of symbol named by the parameter, name, from the parameter, handle.
|
||||
*
|
||||
* @param handle The handle for the loaded shared library.
|
||||
* @param name The name of symbol to search.
|
||||
*
|
||||
* @note LOS_FindSym must not be called in interrupt callback.
|
||||
*
|
||||
* @return Return NULL if error. Return non-NULL if success.
|
||||
*/
|
||||
VOID *LOS_FindSym(VOID *handle, const CHAR *name);
|
||||
|
||||
/*
|
||||
* @brief Decrement the reference count on the loaded shared library refered to by handle.
|
||||
* If the reference count drops to zero, then the library is unloaded.
|
||||
*
|
||||
* This function validates that the handle is valid.
|
||||
*
|
||||
* @param handle The handle for the loaded shared library by LOS_SoLoad() interface.
|
||||
*
|
||||
* @note LOS_SoUnload must not be called in interrupt callback.
|
||||
*
|
||||
* @return Return 1 if error. Return 0 if success.
|
||||
*/
|
||||
INT32 LOS_SoUnload(VOID *handle);
|
||||
|
||||
/*
|
||||
* @brief Initialization for dynamic loader & linker module.
|
||||
*
|
||||
* @param VOID.
|
||||
*
|
||||
* @return Return LOS_NOK if error. Return LOS_OK if success.
|
||||
*/
|
||||
INT32 LOS_DynlinkInit(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_DYNLINK_H */
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 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.
|
||||
|
||||
# Description: The script is used to calculate the memory size that the specified shared library
|
||||
# will occupy when loading to the RAM.
|
||||
|
||||
READELF=readelf
|
||||
RM=rm
|
||||
SIZE=0x0
|
||||
SIZE_ALL=0x0
|
||||
SIZE_MAX=0
|
||||
TMP_FILE=tmp.txt
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "Usage: ./so_parse lib.so"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
parse_line()
|
||||
{
|
||||
MEM_SIZE=$(echo $1 | awk '{print $6}')
|
||||
echo ${MEM_SIZE}
|
||||
}
|
||||
|
||||
${READELF} -l $1 | while read line; do
|
||||
HEAD_STRING=$(echo ${line} | awk '{print $1}')
|
||||
if [[ "${HEAD_STRING}" == *"LOAD"* ]]; then
|
||||
SIZE=`parse_line "${line}"`
|
||||
SIZE=`echo ${SIZE}`
|
||||
SIZE_ALL=$((SIZE_ALL+SIZE))
|
||||
fi
|
||||
echo ${SIZE_ALL} >> ${TMP_FILE}
|
||||
done
|
||||
|
||||
NEED_SIZE=`tail -n 1 ${TMP_FILE}`
|
||||
echo "${NEED_SIZE} kb memory to reserve for $1!"
|
||||
${RM} -f ${TMP_FILE}
|
||||
|
||||
@@ -27,17 +27,15 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_PLATFORM_EXC)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
static_library("exchook") {
|
||||
sources = [
|
||||
"los_exc_info.c",
|
||||
"los_exchook.c",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
include_dirs = [
|
||||
"../../kernel/arch/include",
|
||||
"../../kernel/include",
|
||||
"../../utils",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ VOID OsExcRegister(ExcInfoType type, EXC_INFO_SAVE_CALLBACK func, VOID *arg)
|
||||
{
|
||||
ExcInfoArray *excInfo = NULL;
|
||||
if ((type >= OS_EXC_TYPE_MAX) || (func == NULL)) {
|
||||
PRINT_ERR("OsExcRegister ERROR!\n");
|
||||
PRINT_ERR("HalExcRegister ERROR!\n");
|
||||
return;
|
||||
}
|
||||
excInfo = &(g_excArray[type]);
|
||||
|
||||
@@ -27,13 +27,34 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
module_group(module_name) {
|
||||
modules = [
|
||||
"vfs",
|
||||
"littlefs",
|
||||
"fatfs",
|
||||
static_library("fs_operations") {
|
||||
sources = [
|
||||
"./fs.c",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"../../../kernel/arch/include",
|
||||
"../../../kernel/include",
|
||||
"../../../utils",
|
||||
"../../../kal/posix/include",
|
||||
"./",
|
||||
]
|
||||
|
||||
deps = [ "//kernel/liteos_m/kal/posix" ]
|
||||
}
|
||||
|
||||
declare_args() {
|
||||
enable_ohos_kernel_liteos_m_fatfs = true
|
||||
enable_ohos_kernel_liteos_m_littlefs = true
|
||||
}
|
||||
|
||||
group("fs") {
|
||||
deps = []
|
||||
deps += [ ".:fs_operations" ]
|
||||
if (enable_ohos_kernel_liteos_m_fatfs == true) {
|
||||
deps += [ "fatfs:fatfs" ]
|
||||
}
|
||||
if (enable_ohos_kernel_liteos_m_littlefs == true) {
|
||||
deps += [ "littlefs:littlefs" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +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.
|
||||
|
||||
rsource "vfs/Kconfig"
|
||||
rsource "littlefs/Kconfig"
|
||||
rsource "fatfs/Kconfig"
|
||||
|
||||
config SUPPORT_FATFS
|
||||
bool
|
||||
default n
|
||||
depends on FS_FAT
|
||||
|
||||
config SUPPORT_LITTLEFS
|
||||
bool
|
||||
default n
|
||||
depends on FS_LITTLEFS
|
||||
@@ -27,21 +27,25 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_FS_FAT)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
static_library("fatfs") {
|
||||
sources = [
|
||||
"$LITEOSTHIRDPARTY/FatFs/source/diskio.c",
|
||||
"$LITEOSTHIRDPARTY/FatFs/source/ff.c",
|
||||
"$LITEOSTHIRDPARTY/FatFs/source/ffsystem.c",
|
||||
"$LITEOSTHIRDPARTY/FatFs/source/ffunicode.c",
|
||||
"//third_party/FatFs/source/diskio.c",
|
||||
"//third_party/FatFs/source/ff.c",
|
||||
"//third_party/FatFs/source/ffsystem.c",
|
||||
"//third_party/FatFs/source/ffunicode.c",
|
||||
"fatfs.c",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
include_dirs += [ "$LITEOSTHIRDPARTY/FatFs/source" ]
|
||||
include_dirs = [
|
||||
"../",
|
||||
"../../../kernel/arch/include",
|
||||
"../../../kernel/include",
|
||||
"../../../utils",
|
||||
"../../../kal/cmsis",
|
||||
"../../../kal/posix/include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"//third_party/FatFs/source/",
|
||||
]
|
||||
|
||||
deps = [ "//kernel/liteos_m/kal/posix" ]
|
||||
}
|
||||
|
||||
@@ -1,74 +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.
|
||||
|
||||
config FS_FAT
|
||||
bool "Enable FAT"
|
||||
default n
|
||||
depends on FS_VFS
|
||||
select SUPPORT_FATFS
|
||||
select KAL_CMSIS
|
||||
help
|
||||
Answer Y to enable LiteOS support fat filesystem.
|
||||
|
||||
config FS_FAT_CACHE
|
||||
bool "Enable FAT Cache"
|
||||
default y
|
||||
depends on FS_FAT
|
||||
help
|
||||
Answer Y to enable LiteOS fat filesystem support cache.
|
||||
|
||||
config FS_FAT_CACHE_SYNC_THREAD
|
||||
bool "Enable FAT Cache Sync Thread"
|
||||
default n
|
||||
depends on FS_FAT_CACHE
|
||||
help
|
||||
Answer Y to enable LiteOS fat filesystem support cache sync thread.
|
||||
|
||||
config FS_FAT_CHINESE
|
||||
bool "Enable Chinese"
|
||||
default y
|
||||
depends on FS_FAT
|
||||
help
|
||||
Answer Y to enable LiteOS fat filesystem support Chinese.
|
||||
|
||||
config FS_FAT_VIRTUAL_PARTITION
|
||||
bool "Enabel Virtual Partition"
|
||||
default n
|
||||
depends on FS_FAT
|
||||
|
||||
config FS_FAT_VOLUMES
|
||||
int
|
||||
depends on FS_FAT
|
||||
default 32 if PLATFORM_HI3731
|
||||
default 16
|
||||
|
||||
config FS_FAT_DISK
|
||||
bool "Enable partinfo for storage device"
|
||||
depends on FS_FAT
|
||||
default y
|
||||
@@ -1432,7 +1432,6 @@ int fatfs_format(const char *dev, int sectors, int option)
|
||||
INT32 index;
|
||||
FRESULT res;
|
||||
INT32 ret;
|
||||
MKFS_PARM opt = {0};
|
||||
|
||||
if (dev == NULL) {
|
||||
errno = EFAULT;
|
||||
@@ -1459,9 +1458,7 @@ int fatfs_format(const char *dev, int sectors, int option)
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
opt.fmt = option,
|
||||
opt.n_sect = sectors,
|
||||
res = f_mkfs(dev, &opt, g_workBuffer, FF_MAX_SS);
|
||||
res = f_mkfs(dev, option, sectors, g_workBuffer, FF_MAX_SS);
|
||||
if (res != FR_OK) {
|
||||
errno = FatfsErrno(res);
|
||||
ret = FS_FAILURE;
|
||||
@@ -1498,4 +1495,4 @@ struct FileOps g_fatfsFops = {
|
||||
.Getattr = fatfs_stat,
|
||||
.Fsync = fatfs_fsync,
|
||||
.Fstat = fatfs_fstat,
|
||||
};
|
||||
};
|
||||
@@ -28,10 +28,8 @@
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_fs.h"
|
||||
#include "los_config.h"
|
||||
#include "fs_operations.h"
|
||||
#include "los_config.h"
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
#include "fatfs.h"
|
||||
#endif
|
||||
@@ -47,12 +45,18 @@
|
||||
#include "sys/stat.h"
|
||||
#include "unistd.h"
|
||||
|
||||
struct FsMap g_fsmap[MAX_FILESYSTEM_LEN] = {0};
|
||||
struct FsMap *g_fs = NULL;
|
||||
|
||||
#ifdef LOSCFG_NET_LWIP_SACK
|
||||
#define _BSD_SOURCE
|
||||
#include "lwip/lwipopts.h"
|
||||
#include "lwip/sockets.h"
|
||||
#define CONFIG_NSOCKET_DESCRIPTORS LWIP_CONFIG_NUM_SOCKETS
|
||||
#else
|
||||
#define CONFIG_NSOCKET_DESCRIPTORS 0
|
||||
#endif
|
||||
|
||||
#include "vfs_config.h"
|
||||
#define CONFIG_NFILE_DESCRIPTORS FAT_MAX_OPEN_FILES /* only for random currently */
|
||||
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
#include "hks_client.h"
|
||||
@@ -155,9 +159,6 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct FsMap g_fsmap[MAX_FILESYSTEM_LEN] = {0};
|
||||
static struct FsMap *g_fs = NULL;
|
||||
|
||||
static void InitMountInfo(void)
|
||||
{
|
||||
#if (LOSCFG_SUPPORT_FATFS == 1)
|
||||
@@ -190,9 +191,9 @@ static struct FsMap *MountFindfs(const char *fileSystemtype)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int LOS_FsMount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
int mount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
static int initFlag = 0;
|
||||
|
||||
@@ -215,7 +216,7 @@ int LOS_FsMount(const char *source, const char *target,
|
||||
return g_fs->fsMops->Mount(source, target, filesystemtype, mountflags, data);
|
||||
}
|
||||
|
||||
int LOS_FsUmount(const char *target)
|
||||
int umount(const char *target)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -228,7 +229,7 @@ int LOS_FsUmount(const char *target)
|
||||
return g_fs->fsMops->Umount(target);
|
||||
}
|
||||
|
||||
int LOS_FsUmount2(const char *target, int flag)
|
||||
int umount2(const char *target, int flag)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -241,7 +242,7 @@ int LOS_FsUmount2(const char *target, int flag)
|
||||
return g_fs->fsMops->Umount2(target, flag);
|
||||
}
|
||||
|
||||
int LOS_Open(const char *path, int oflag, ...)
|
||||
int open(const char *path, int oflag, ...)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
unsigned flags = O_RDONLY | O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_LARGEFILE | O_TRUNC | O_EXCL | O_DIRECTORY;
|
||||
@@ -296,7 +297,7 @@ int LOS_Open(const char *path, int oflag, ...)
|
||||
return g_fs->fsFops->Open(path, oflag);
|
||||
}
|
||||
|
||||
int LOS_Close(int fd)
|
||||
int close(int fd)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
@@ -319,7 +320,7 @@ int LOS_Close(int fd)
|
||||
return g_fs->fsFops->Close(fd);
|
||||
}
|
||||
|
||||
ssize_t LOS_Read(int fd, void *buf, size_t nbyte)
|
||||
ssize_t read(int fd, void *buf, size_t nbyte)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
@@ -354,10 +355,11 @@ ssize_t LOS_Read(int fd, void *buf, size_t nbyte)
|
||||
errno = ENOSYS;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
return g_fs->fsFops->Read(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
ssize_t LOS_Write(int fd, const void *buf, size_t nbyte)
|
||||
ssize_t write(int fd, const void *buf, size_t nbyte)
|
||||
{
|
||||
#ifdef LOSCFG_RANDOM_DEV
|
||||
if (fd == RANDOM_DEV_FD) {
|
||||
@@ -381,7 +383,7 @@ ssize_t LOS_Write(int fd, const void *buf, size_t nbyte)
|
||||
return g_fs->fsFops->Write(fd, buf, nbyte);
|
||||
}
|
||||
|
||||
off_t LOS_Lseek(int fd, off_t offset, int whence)
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -394,7 +396,7 @@ off_t LOS_Lseek(int fd, off_t offset, int whence)
|
||||
return g_fs->fsFops->Seek(fd, offset, whence);
|
||||
}
|
||||
|
||||
int LOS_Unlink(const char *path)
|
||||
int unlink(const char *path)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -407,7 +409,7 @@ int LOS_Unlink(const char *path)
|
||||
return g_fs->fsFops->Unlink(path);
|
||||
}
|
||||
|
||||
int LOS_Fstat(int fd, struct stat *buf)
|
||||
int fstat(int fd, struct stat *buf)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -420,7 +422,7 @@ int LOS_Fstat(int fd, struct stat *buf)
|
||||
return g_fs->fsFops->Fstat(fd, buf);
|
||||
}
|
||||
|
||||
int LOS_Stat(const char *path, struct stat *buf)
|
||||
int stat(const char *path, struct stat *buf)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -433,7 +435,7 @@ int LOS_Stat(const char *path, struct stat *buf)
|
||||
return g_fs->fsFops->Getattr(path, buf);
|
||||
}
|
||||
|
||||
int LOS_Fsync(int fd)
|
||||
int fsync(int fd)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -446,7 +448,7 @@ int LOS_Fsync(int fd)
|
||||
return g_fs->fsFops->Fsync(fd);
|
||||
}
|
||||
|
||||
int LOS_Mkdir(const char *path, mode_t mode)
|
||||
int mkdir(const char *path, mode_t mode)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -459,7 +461,7 @@ int LOS_Mkdir(const char *path, mode_t mode)
|
||||
return g_fs->fsFops->Mkdir(path, mode);
|
||||
}
|
||||
|
||||
DIR *LOS_Opendir(const char *dirName)
|
||||
DIR *opendir(const char *dirName)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -472,7 +474,7 @@ DIR *LOS_Opendir(const char *dirName)
|
||||
return g_fs->fsFops->Opendir(dirName);
|
||||
}
|
||||
|
||||
struct dirent *LOS_Readdir(DIR *dir)
|
||||
struct dirent *readdir(DIR *dir)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -485,7 +487,7 @@ struct dirent *LOS_Readdir(DIR *dir)
|
||||
return g_fs->fsFops->Readdir(dir);
|
||||
}
|
||||
|
||||
int LOS_Closedir(DIR *dir)
|
||||
int closedir(DIR *dir)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -498,7 +500,7 @@ int LOS_Closedir(DIR *dir)
|
||||
return g_fs->fsFops->Closedir(dir);
|
||||
}
|
||||
|
||||
int LOS_Rmdir(const char *path)
|
||||
int rmdir(const char *path)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -511,7 +513,7 @@ int LOS_Rmdir(const char *path)
|
||||
return g_fs->fsFops->Rmdir(path);
|
||||
}
|
||||
|
||||
int LOS_Rename(const char *oldName, const char *newName)
|
||||
int rename(const char *oldName, const char *newName)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -524,7 +526,7 @@ int LOS_Rename(const char *oldName, const char *newName)
|
||||
return g_fs->fsFops->Rename(oldName, newName);
|
||||
}
|
||||
|
||||
int LOS_Statfs(const char *path, struct statfs *buf)
|
||||
int statfs(const char *path, struct statfs *buf)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -537,7 +539,7 @@ int LOS_Statfs(const char *path, struct statfs *buf)
|
||||
return g_fs->fsMops->Statfs(path, buf);
|
||||
}
|
||||
|
||||
int LOS_Ftruncate(int fd, off_t length)
|
||||
int ftruncate(int fd, off_t length)
|
||||
{
|
||||
if (g_fs == NULL) {
|
||||
errno = ENODEV;
|
||||
@@ -27,21 +27,23 @@
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_FS_LITTLEFS)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
static_library("littlefs") {
|
||||
sources = [
|
||||
"$LITEOSTHIRDPARTY/littlefs/bd/lfs_rambd.c",
|
||||
"$LITEOSTHIRDPARTY/littlefs/lfs.c",
|
||||
"$LITEOSTHIRDPARTY/littlefs/lfs_util.c",
|
||||
"lfs_api.c",
|
||||
"//third_party/littlefs/lfs.c",
|
||||
"//third_party/littlefs/lfs_util.c",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
include_dirs += [ "$LITEOSTHIRDPARTY/littlefs" ]
|
||||
include_dirs += [ "$LITEOSTHIRDPARTY/littlefs/bd" ]
|
||||
include_dirs = [
|
||||
"../../../kernel/arch/include",
|
||||
"../../../kernel/include",
|
||||
"../../../utils",
|
||||
"../../../kal/cmsis",
|
||||
"../../../kal/posix/include",
|
||||
"./",
|
||||
"../",
|
||||
"//third_party/littlefs",
|
||||
]
|
||||
|
||||
deps = [ "//kernel/liteos_m/kal/posix" ]
|
||||
}
|
||||
|
||||
@@ -1,45 +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.
|
||||
|
||||
config FS_LITTLEFS
|
||||
bool "Enable Little FS"
|
||||
default n
|
||||
depends on FS_VFS
|
||||
select SUPPORT_LITTLEFS
|
||||
help
|
||||
Answer Y to enable LiteOS support Little FS filesystem.
|
||||
|
||||
if FS_LITTLEFS
|
||||
config LFS_MAX_MOUNT_SIZE
|
||||
int "Maximum number of mount points"
|
||||
default 3
|
||||
help
|
||||
This is a global maximum number of mount points.
|
||||
|
||||
endif # FS_LITTLEFS
|
||||
@@ -40,29 +40,29 @@ FileDirInfo g_lfsDir[LFS_MAX_OPEN_DIRS] = {0};
|
||||
struct FileOpInfo g_fsOp[LOSCFG_LFS_MAX_MOUNT_SIZE] = {0};
|
||||
static LittleFsHandleStruct g_handle[LITTLE_FS_MAX_OPEN_FILES] = {0};
|
||||
struct dirent g_nameValue;
|
||||
static pthread_mutex_t g_FslocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t g_fsLocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static const char *g_littlefsMntName[LOSCFG_LFS_MAX_MOUNT_SIZE] = {"/a", "/b", "/c"};
|
||||
|
||||
LittleFsHandleStruct *LfsAllocFd(const char *fileName, int *fd)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) {
|
||||
if (g_handle[i].useFlag == 0) {
|
||||
*fd = i;
|
||||
g_handle[i].useFlag = 1;
|
||||
g_handle[i].pathName = strdup(fileName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return &(g_handle[i]);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
*fd = INVALID_FD;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void LfsFreeFd(int fd)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
g_handle[fd].useFlag = 0;
|
||||
if (g_handle[fd].pathName != NULL) {
|
||||
free((void *)g_handle[fd].pathName);
|
||||
@@ -72,21 +72,21 @@ static void LfsFreeFd(int fd)
|
||||
if (g_handle[fd].lfsHandle != NULL) {
|
||||
g_handle[fd].lfsHandle = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
}
|
||||
|
||||
BOOL CheckFileIsOpen(const char *fileName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
for (int i = 0; i < LITTLE_FS_MAX_OPEN_FILES; i++) {
|
||||
if (g_handle[i].useFlag == 1) {
|
||||
if (strcmp(g_handle[i].pathName, fileName) == 0) {
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -103,22 +103,22 @@ static BOOL LfsFdIsValid(int fd)
|
||||
|
||||
FileDirInfo *GetFreeDir(const char *dirName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
|
||||
if (g_lfsDir[i].useFlag == 0) {
|
||||
g_lfsDir[i].useFlag = 1;
|
||||
g_lfsDir[i].dirName = strdup(dirName);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return &(g_lfsDir[i]);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void FreeDirInfo(const char *dirName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
|
||||
if (g_lfsDir[i].useFlag == 1 && strcmp(g_lfsDir[i].dirName, dirName) == 0) {
|
||||
g_lfsDir[i].useFlag = 0;
|
||||
@@ -126,24 +126,23 @@ void FreeDirInfo(const char *dirName)
|
||||
free(g_lfsDir[i].dirName);
|
||||
g_lfsDir[i].dirName = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
}
|
||||
|
||||
BOOL CheckDirIsOpen(const char *dirName)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
for (int i = 0; i < LFS_MAX_OPEN_DIRS; i++) {
|
||||
if (g_lfsDir[i].useFlag == 1) {
|
||||
if (strcmp(g_lfsDir[i].dirName, dirName) == 0) {
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -165,35 +164,35 @@ BOOL CheckPathIsMounted(const char *pathName, struct FileOpInfo **fileOpInfo)
|
||||
char tmpName[LITTLEFS_MAX_LFN_LEN] = {0};
|
||||
int len = GetFirstLevelPathLen(pathName);
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
(void)strncpy_s(tmpName, LITTLEFS_MAX_LFN_LEN, pathName, len);
|
||||
if (strcmp(tmpName, g_fsOp[i].dirName) == 0) {
|
||||
*fileOpInfo = &(g_fsOp[i]);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
struct FileOpInfo *AllocMountRes(const char* target, const struct FileOps *fileOps)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 0 && strcmp(target, g_littlefsMntName[i]) == 0) {
|
||||
g_fsOp[i].useFlag = 1;
|
||||
g_fsOp[i].fsVops = fileOps;
|
||||
g_fsOp[i].dirName = strdup(target);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return &(g_fsOp[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -203,26 +202,26 @@ int SetDefaultMountPath(int pathNameIndex, const char* target)
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
g_littlefsMntName[pathNameIndex] = strdup(target);
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return VFS_OK;
|
||||
}
|
||||
|
||||
struct FileOpInfo *GetMountRes(const char *target, int *mountIndex)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) {
|
||||
*mountIndex = i;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return &(g_fsOp[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -232,33 +231,33 @@ int FreeMountResByIndex(int mountIndex)
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
if (g_fsOp[mountIndex].useFlag == 1 && g_fsOp[mountIndex].dirName != NULL) {
|
||||
g_fsOp[mountIndex].useFlag = 0;
|
||||
free(g_fsOp[mountIndex].dirName);
|
||||
g_fsOp[mountIndex].dirName = NULL;
|
||||
}
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
|
||||
return VFS_OK;
|
||||
}
|
||||
|
||||
int FreeMountRes(const char *target)
|
||||
{
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
for (int i = 0; i < LOSCFG_LFS_MAX_MOUNT_SIZE; i++) {
|
||||
if (g_fsOp[i].useFlag == 1) {
|
||||
if (g_fsOp[i].dirName && strcmp(target, g_fsOp[i].dirName) == 0) {
|
||||
g_fsOp[i].useFlag = 0;
|
||||
free(g_fsOp[i].dirName);
|
||||
g_fsOp[i].dirName = NULL;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return VFS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
@@ -290,7 +289,7 @@ static int ConvertFlagToLfsOpenFlag (int oflags)
|
||||
lfsOpenFlag |= LFS_O_WRONLY;
|
||||
}
|
||||
|
||||
if (oflags == O_RDONLY) {
|
||||
if (oflags & O_RDONLY) {
|
||||
lfsOpenFlag |= LFS_O_RDONLY;
|
||||
}
|
||||
|
||||
@@ -322,7 +321,6 @@ const struct FileOps g_lfsFops = {
|
||||
.Rename = LfsRename,
|
||||
.Getattr = LfsStat,
|
||||
.Fsync = LfsFsync,
|
||||
.Fstat = LfsFstat,
|
||||
};
|
||||
|
||||
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
|
||||
@@ -530,7 +528,7 @@ struct dirent *LfsReaddir(DIR *dir)
|
||||
|
||||
ret = lfs_dir_read(dirInfo->lfsHandle, (lfs_dir_t *)(&(dirInfo->dir)), &lfsInfo);
|
||||
if (ret == TRUE) {
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
(void)strncpy_s(g_nameValue.d_name, sizeof(g_nameValue.d_name), lfsInfo.name, strlen(lfsInfo.name) + 1);
|
||||
if (lfsInfo.type == LFS_TYPE_DIR) {
|
||||
g_nameValue.d_type = DT_DIR;
|
||||
@@ -539,7 +537,7 @@ struct dirent *LfsReaddir(DIR *dir)
|
||||
}
|
||||
|
||||
g_nameValue.d_reclen = lfsInfo.size;
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
|
||||
return &g_nameValue;
|
||||
}
|
||||
@@ -687,9 +685,9 @@ int LfsClose(int fd)
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&g_FslocalMutex);
|
||||
pthread_mutex_lock(&g_fsLocalMutex);
|
||||
ret = lfs_file_close(g_handle[fd].lfsHandle, &(g_handle[fd].file));
|
||||
pthread_mutex_unlock(&g_FslocalMutex);
|
||||
pthread_mutex_unlock(&g_fsLocalMutex);
|
||||
|
||||
LfsFreeFd(fd);
|
||||
|
||||
@@ -773,33 +771,3 @@ int LfsFsync(int fd)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LfsFstat(int fd, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
struct lfs_info info;
|
||||
|
||||
if (buf == NULL) {
|
||||
errno = EFAULT;
|
||||
return FS_FAILURE;
|
||||
}
|
||||
|
||||
if (LfsFdIsValid(fd) == FALSE) {
|
||||
errno = EBADF;
|
||||
return VFS_ERROR;
|
||||
}
|
||||
|
||||
ret = lfs_stat(g_handle[fd].lfsHandle, g_handle[fd].pathName, &info);
|
||||
if (ret == 0) {
|
||||
buf->st_size = info.size;
|
||||
if (info.type == LFS_TYPE_REG) {
|
||||
buf->st_mode = S_IFREG;
|
||||
} else {
|
||||
buf->st_mode = S_IFDIR;
|
||||
}
|
||||
} else {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = VFS_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -32,6 +32,7 @@
|
||||
#ifndef _LFS_API_H_
|
||||
#define _LFS_API_H_
|
||||
|
||||
#include "bits/alltypes.h"
|
||||
#include "fcntl.h"
|
||||
#include "sys/stat.h"
|
||||
|
||||
@@ -45,6 +46,8 @@
|
||||
|
||||
#define INVALID_FD (-1)
|
||||
|
||||
typedef unsigned mode_t;
|
||||
|
||||
#ifndef VFS_ERROR
|
||||
#define VFS_ERROR (-1)
|
||||
#endif
|
||||
@@ -90,6 +93,7 @@ typedef struct {
|
||||
|
||||
LittleFsHandleStruct *GetFreeFd(int *fd);
|
||||
|
||||
int InitMountInfo(const char *fileSystemType, const struct MountOps *fsMops);
|
||||
int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags,
|
||||
const void *data);
|
||||
|
||||
@@ -108,8 +112,9 @@ int LfsClose(int fd);
|
||||
int LfsRename(const char *oldName, const char *newName);
|
||||
int LfsStat(const char *path, struct stat *buf);
|
||||
int LfsFsync(int fd);
|
||||
int LfsFstat(int fd, struct stat *buf);
|
||||
int SetDefaultMountPath(int pathNameIndex, const char* target);
|
||||
|
||||
const struct FsMap *MountFindfs(const char *filesystemtype);
|
||||
|
||||
#endif /* _LFS_API_H_ */
|
||||
|
||||
|
||||
@@ -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_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_FS_VFS)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [ "los_fs.c" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
config FS_VFS
|
||||
bool "Enable FS VFS"
|
||||
default y
|
||||
help
|
||||
Answer Y to enable LiteOS support VFS.
|
||||
@@ -1,101 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_vfs fs
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_VFS_H_
|
||||
#define _LOS_VFS_H_
|
||||
|
||||
#include "los_config.h"
|
||||
#include "dirent.h"
|
||||
#include "sys/mount.h"
|
||||
#include "sys/statfs.h"
|
||||
#include "sys/stat.h"
|
||||
#include "unistd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
int LOS_Open(const char *path, int oflag, ...);
|
||||
|
||||
int LOS_Close(int fd);
|
||||
|
||||
ssize_t LOS_Read(int fd, void *buf, size_t nbyte);
|
||||
|
||||
ssize_t LOS_Write(int fd, const void *buf, size_t nbyte);
|
||||
|
||||
off_t LOS_Lseek(int fd, off_t offset, int whence);
|
||||
|
||||
int LOS_Unlink(const char *path);
|
||||
|
||||
int LOS_Fstat(int fd, struct stat *buf);
|
||||
|
||||
int LOS_Stat(const char *path, struct stat *buf);
|
||||
|
||||
int LOS_Fsync(int fd);
|
||||
|
||||
int LOS_Mkdir(const char *path, mode_t mode);
|
||||
|
||||
DIR *LOS_Opendir(const char *dirName);
|
||||
|
||||
struct dirent *LOS_Readdir(DIR *dir);
|
||||
|
||||
int LOS_Closedir(DIR *dir);
|
||||
|
||||
int LOS_Rmdir(const char *path);
|
||||
|
||||
int LOS_Rename(const char *oldName, const char *newName);
|
||||
|
||||
int LOS_Statfs(const char *path, struct statfs *buf);
|
||||
|
||||
int LOS_Ftruncate(int fd, off_t length);
|
||||
|
||||
int LOS_FsUmount2(const char *target, int flag);
|
||||
|
||||
int LOS_FsUmount(const char *target);
|
||||
|
||||
int LOS_FsMount(const char *source, const char *target,
|
||||
const char *filesystemtype, unsigned long mountflags,
|
||||
const void *data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_FS_H_ */
|
||||
@@ -1,143 +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 _VFS_CONFIG_H_
|
||||
#define _VFS_CONFIG_H_
|
||||
|
||||
#define PATH_MAX 256
|
||||
#define CONFIG_DISABLE_MQUEUE // disable posix mqueue inode configure
|
||||
|
||||
/* file system configur */
|
||||
|
||||
#define CONFIG_FS_WRITABLE // enable file system can be written
|
||||
#define CONFIG_FS_READABLE // enable file system can be read
|
||||
#define CONFIG_DEBUG_FS // enable vfs debug function
|
||||
|
||||
|
||||
/* fatfs cache configur */
|
||||
/* config block size for fat file system, only can be 0,32,64,128,256,512,1024 */
|
||||
#define CONFIG_FS_FAT_SECTOR_PER_BLOCK 64
|
||||
|
||||
/* config block num for fat file system */
|
||||
#define CONFIG_FS_FAT_READ_NUMS 7
|
||||
#define CONFIG_FS_FAT_BLOCK_NUMS 28
|
||||
|
||||
#ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD
|
||||
|
||||
/* config the priority of sync task */
|
||||
|
||||
#define CONFIG_FS_FAT_SYNC_THREAD_PRIO 10
|
||||
|
||||
/* config dirty ratio of bcache for fat file system */
|
||||
|
||||
#define CONFIG_FS_FAT_DIRTY_RATIO 60
|
||||
|
||||
/* config time interval of sync thread for fat file system, in milliseconds */
|
||||
|
||||
#define CONFIG_FS_FAT_SYNC_INTERVAL 5000
|
||||
#endif
|
||||
|
||||
#define CONFIG_FS_FLASH_BLOCK_NUM 1
|
||||
|
||||
#define CONFIG_FS_MAX_LNK_CNT 40
|
||||
|
||||
/* nfs configure */
|
||||
|
||||
#define CONFIG_NFS_MACHINE_NAME "IPC" // nfs device name is IPC
|
||||
#define CONFIG_NFS_MACHINE_NAME_SIZE 3 // size of nfs machine name
|
||||
|
||||
|
||||
/* file descriptors configure */
|
||||
|
||||
#define CONFIG_NFILE_STREAMS 1 // enable file stream
|
||||
#define CONFIG_STDIO_BUFFER_SIZE 0
|
||||
#define CONFIG_NUNGET_CHARS 0
|
||||
#define MIN_START_FD 3 // 0,1,2 are used for stdin,stdout,stderr respectively
|
||||
|
||||
/* net configure */
|
||||
|
||||
#ifdef LOSCFG_NET_LWIP_SACK // enable socket and net function
|
||||
#include "lwip/lwipopts.h"
|
||||
#define CONFIG_NSOCKET_DESCRIPTORS LWIP_CONFIG_NUM_SOCKETS // max numbers of socket descriptor
|
||||
#define CONFIG_NET_SENDFILE 1 // enable sendfile function
|
||||
#define CONFIG_NET_TCP 1 // enable sendfile and send function
|
||||
#else
|
||||
#define CONFIG_NSOCKET_DESCRIPTORS 0
|
||||
#define CONFIG_NET_SENDFILE 0 // disable sendfile function
|
||||
#define CONFIG_NET_TCP 0 // disable sendfile and send function
|
||||
#endif
|
||||
|
||||
/* max numbers of other descriptors except socket descriptors */
|
||||
|
||||
#ifdef LOSCFG_FS_FAT
|
||||
#include "fatfs.h"
|
||||
#define __FAT_NFILE FAT_MAX_OPEN_FILES
|
||||
#else
|
||||
#define __FAT_NFILE 0
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_FS_LITTLEFS
|
||||
#include "lfs_api.h"
|
||||
#define __LFS_NFILE LITTLE_FS_MAX_OPEN_FILES
|
||||
#else
|
||||
#define __LFS_NFILE 0
|
||||
#endif
|
||||
|
||||
#define CONFIG_NFILE_DESCRIPTORS (__FAT_NFILE + __LFS_NFILE)
|
||||
|
||||
#define NR_OPEN_DEFAULT CONFIG_NFILE_DESCRIPTORS
|
||||
|
||||
/* time configure */
|
||||
|
||||
#define CONFIG_NTIME_DESCRIPTORS 0
|
||||
|
||||
/* mqueue configure */
|
||||
|
||||
#define CONFIG_NQUEUE_DESCRIPTORS 256
|
||||
|
||||
#undef FD_SETSIZE
|
||||
#define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)
|
||||
#define CONFIG_NEXPANED_DESCRIPTORS (CONFIG_NTIME_DESCRIPTORS + CONFIG_NQUEUE_DESCRIPTORS)
|
||||
#define FD_SET_TOTAL_SIZE (FD_SETSIZE + CONFIG_NEXPANED_DESCRIPTORS)
|
||||
#define TIMER_FD_OFFSET FD_SETSIZE
|
||||
#define MQUEUE_FD_OFFSET (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS)
|
||||
|
||||
/* directory configure */
|
||||
|
||||
#define VFS_USING_WORKDIR // enable current working directory
|
||||
|
||||
/* permission configure */
|
||||
#define DEFAULT_DIR_MODE 0777
|
||||
#define DEFAULT_FILE_MODE 0666
|
||||
|
||||
#define MAX_DIRENT_NUM 14 // 14 means 4096 length buffer can store 14 dirent, see struct DIR
|
||||
|
||||
#endif
|
||||
@@ -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_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_KERNEL_LMK)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [ "los_lmk.c" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
@@ -1,206 +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 "los_lmk.h"
|
||||
#include "los_interrupt.h"
|
||||
#if (LOSCFG_KERNEL_LMK_DEBUG == 1)
|
||||
#include "los_debug.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK == 1)
|
||||
STATIC LosLmkOps g_losLmkOps;
|
||||
|
||||
STATIC BOOL OsIsLmkOpsNodeRegistered(LosLmkOpsNode *lmkNode)
|
||||
{
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
|
||||
if (LOS_ListEmpty(&g_losLmkOps.lmkOpsList)) {
|
||||
return FALSE;
|
||||
}
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
if (lmkNode == opsNode) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
UINT32 LOS_LmkOpsNodeRegister(LosLmkOpsNode *lmkNode)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
|
||||
if (lmkNode == NULL) {
|
||||
return LOS_ERRNO_LMK_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (OsIsLmkOpsNodeRegistered(lmkNode)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_LMK_ALREADY_REGISTERED;
|
||||
}
|
||||
if (LOS_ListEmpty(&g_losLmkOps.lmkOpsList)) {
|
||||
LOS_ListHeadInsert(&g_losLmkOps.lmkOpsList, &lmkNode->node);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
// the priority of registered node <= the first node
|
||||
opsNode = LOS_DL_LIST_ENTRY(g_losLmkOps.lmkOpsList.pstNext, LosLmkOpsNode, node);
|
||||
if (lmkNode->priority <= opsNode->priority) {
|
||||
LOS_ListHeadInsert(&g_losLmkOps.lmkOpsList, &lmkNode->node);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
// the priority of registered node > the last node
|
||||
opsNode = LOS_DL_LIST_ENTRY(g_losLmkOps.lmkOpsList.pstPrev, LosLmkOpsNode, node);
|
||||
if (lmkNode->priority >= opsNode->priority) {
|
||||
LOS_ListTailInsert(&g_losLmkOps.lmkOpsList, &lmkNode->node);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
// the priority of registered node > the first node and < the last node
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
if (lmkNode->priority < opsNode->priority) {
|
||||
LOS_ListHeadInsert((&opsNode->node)->pstPrev, &lmkNode->node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 LOS_LmkOpsNodeUnregister(LosLmkOpsNode *lmkNode)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
if (lmkNode == NULL) {
|
||||
return LOS_ERRNO_LMK_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
if (LOS_ListEmpty(&g_losLmkOps.lmkOpsList) || !OsIsLmkOpsNodeRegistered(lmkNode)) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_LMK_NOT_REGISTERED;
|
||||
}
|
||||
LOS_ListDelete(&lmkNode->node);
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 LOS_LmkTasksKill(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
FreeMemByKillingTask freeMem = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
// if tasks already killed, no need to do it again.
|
||||
if (g_losLmkOps.isMemFreed) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_LMK_MEMORY_ALREADY_FREED;
|
||||
} else {
|
||||
g_losLmkOps.isMemFreed = TRUE;
|
||||
}
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
freeMem = opsNode->freeMem;
|
||||
LOS_IntRestore(intSave);
|
||||
if (freeMem != NULL) {
|
||||
ret = freeMem();
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_ERRNO_LMK_FREE_MEMORY_FAILURE;
|
||||
}
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
UINT32 LOS_LmkTasksRestore(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 ret;
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
RestoreKilledTask restore = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
|
||||
// if no tasks killed, no need to restore.
|
||||
if (!g_losLmkOps.isMemFreed) {
|
||||
LOS_IntRestore(intSave);
|
||||
return LOS_ERRNO_LMK_RESTORE_NOT_NEEDED;
|
||||
} else {
|
||||
g_losLmkOps.isMemFreed = FALSE;
|
||||
}
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
restore = opsNode->restoreTask;
|
||||
LOS_IntRestore(intSave);
|
||||
if (restore != NULL) {
|
||||
ret = restore();
|
||||
if (ret != LOS_OK) {
|
||||
return LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE;
|
||||
}
|
||||
}
|
||||
intSave = LOS_IntLock();
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK_DEBUG == 1)
|
||||
VOID LOS_LmkOpsNodeInfoShow(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LosLmkOpsNode *opsNode = NULL;
|
||||
|
||||
intSave = LOS_IntLock();
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(opsNode, &g_losLmkOps.lmkOpsList, LosLmkOpsNode, node) {
|
||||
PRINTK("Priority: %-4u Free:0x%-8x Restore:0x%-8x\n", opsNode->priority,
|
||||
(UINT32)(UINTPTR)opsNode->freeMem, (UINT32)(UINTPTR)opsNode->restoreTask);
|
||||
}
|
||||
LOS_IntRestore(intSave);
|
||||
}
|
||||
#endif
|
||||
|
||||
VOID OsLmkInit(VOID)
|
||||
{
|
||||
g_losLmkOps.isMemFreed = FALSE;
|
||||
LOS_ListInit(&g_losLmkOps.lmkOpsList);
|
||||
}
|
||||
#endif
|
||||
@@ -1,236 +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 _LOS_LMK_H
|
||||
#define _LOS_LMK_H
|
||||
|
||||
#include "los_config.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_list.h"
|
||||
#include "los_error.h"
|
||||
|
||||
typedef UINT32 (*FreeMemByKillingTask)(VOID);
|
||||
typedef UINT32 (*RestoreKilledTask)(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: Invalid parameter.
|
||||
*
|
||||
* Value: 0x02002101
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_INVALID_PARAMETER LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x01)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: LosLmkOpsNode already registered.
|
||||
*
|
||||
* Value: 0x02002102
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_ALREADY_REGISTERED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x02)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: LosLmkOpsNode not yet registered.
|
||||
*
|
||||
* Value: 0x02002103
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_NOT_REGISTERED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x03)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: Failed to free memory by invoking the registered functions.
|
||||
*
|
||||
* Value: 0x02002104
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_FREE_MEMORY_FAILURE LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x04)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: The registered free memory functions have been invoked.
|
||||
*
|
||||
* Value: 0x02002105
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_MEMORY_ALREADY_FREED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x05)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: Failed to restore the killed tasks by invoking the registered functions.
|
||||
*
|
||||
* Value: 0x02002106
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x06)
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* Lmk error code: No need to restore when no free memory functions have been invoked.
|
||||
*
|
||||
* Value: 0x02002107
|
||||
*
|
||||
*/
|
||||
#define LOS_ERRNO_LMK_RESTORE_NOT_NEEDED LOS_ERRNO_OS_ERROR(LOS_MOD_LMK, 0x07)
|
||||
|
||||
typedef struct {
|
||||
UINT32 priority; /**< The priority in the LMK list, the higher priority with a smaller number. */
|
||||
UINT32 (*freeMem)(VOID); /**< Release the memory of tasks in the LMK list. Return LOS_OK for a successful release. */
|
||||
UINT32 (*restoreTask)(VOID); /**< Restore the tasks killed by freeMem(). Return LOS_OK for a successful restore. */
|
||||
LOS_DL_LIST node; /**< LosLmkOpsNode node. */
|
||||
} LosLmkOpsNode;
|
||||
|
||||
typedef struct {
|
||||
LOS_DL_LIST lmkOpsList; /**< The registered LosLmkOpsNode will be inserted in this list. */
|
||||
BOOL isMemFreed; /**< Flag that if LOS_LmkTasksKill has been invoked. */
|
||||
} LosLmkOps;
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Register a low memory killer node.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to register a low memory killer node. A LosLmkOpsNode node
|
||||
* can be registered only once.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param lmkNode [IN] The LosLmkOpsNode node to be registered.
|
||||
*
|
||||
* @retval LOS_OK The LosLmkOpsNode node is registered successfully.
|
||||
* @retval LOS_ERRNO_LMK_INVALID_PARAMETER The paramter is invalid.
|
||||
* @retval LOS_ERRNO_LMK_ALREADY_REGISTERED The LosLmkOpsNode node already registered.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 LOS_LmkOpsNodeRegister(LosLmkOpsNode *lmkNode);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Unregister a low memory killer node.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to unregister a low memory killer node.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param lmkNode [IN] The LosLmkOpsNode node to be registered.
|
||||
*
|
||||
* @retval LOS_OK The LosLmkOpsNode node is unregistered successfully.
|
||||
* @retval LOS_ERRNO_LMK_NOT_REGISTERED The LosLmkOpsNode node is not yet registered.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 LOS_LmkOpsNodeUnregister(LosLmkOpsNode *lmkNode);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Initialize low memory killer framework.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize the low memory killer framework.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
VOID OsLmkInit(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Restore the tasks killed by the task which triggers low memory killer.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to restore the tasks killed by the task which triggers low memory killer.
|
||||
* This function will be invoked by the developer as needed.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval LOS_OK All the restore killed tasks functions are invoked successfully.
|
||||
* @retval LOS_ERRNO_LMK_RESTORE_NOT_NEEDED No need to restore since no tasks killed to free memory.
|
||||
* @retval LOS_ERRNO_LMK_RESTORE_TASKS_FAILURE Failed to restore the killed tasks by invoking the registered functions.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 LOS_LmkTasksRestore(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Kill the tasks to release the used memory.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to kill the tasks to release the used memory when low memory killer is triggered.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval LOS_OK All the free memory functions are invoked successfully.
|
||||
* @retval LOS_ERRNO_LMK_MEMORY_ALREADY_FREED The registered free memory functions have been invoked.
|
||||
* @retval LOS_ERRNO_LMK_FREE_MEMORY_FAILURE Failed to free memory by invoking the registered functions.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
UINT32 LOS_LmkTasksKill(VOID);
|
||||
|
||||
#if (LOSCFG_KERNEL_LMK_DEBUG == 1)
|
||||
/**
|
||||
* @ingroup los_lmk
|
||||
* @brief Output the low memory killer node priorities.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to output the low memory killer node priorities.
|
||||
*
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_lmk.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
VOID LOS_LmkOpsNodeInfoShow(VOID);
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,43 +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_m/liteos.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_KERNEL_LMS)
|
||||
module_name = get_path_info(rebase_path("."), "name")
|
||||
kernel_module(module_name) {
|
||||
sources = [
|
||||
"lms_libc.c",
|
||||
"los_lms.c",
|
||||
]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
config KERNEL_LMS
|
||||
bool "Enable Lite Memory Sanitizer"
|
||||
default n
|
||||
depends on KERNEL_EXTKERNEL && DEBUG_VERSION && KERNEL_BACKTRACE
|
||||
help
|
||||
Select y to build LiteOS with memory sanitizer.
|
||||
|
||||
config LMS_MAX_RECORD_POOL_NUM
|
||||
int "Lms check pool max num"
|
||||
default 50
|
||||
depends on KERNEL_LMS
|
||||
help
|
||||
The Max num of lms check pool
|
||||
|
||||
config LMS_LOAD_CHECK
|
||||
bool "Enable lms read check"
|
||||
default y
|
||||
depends on KERNEL_LMS
|
||||
help
|
||||
Select y to enable read check.
|
||||
|
||||
config LMS_STORE_CHECK
|
||||
bool "Enable lms write check"
|
||||
default y
|
||||
depends on KERNEL_LMS
|
||||
help
|
||||
Select y to enable write check.
|
||||
|
||||
config LMS_CHECK_STRICT
|
||||
bool "Enable lms strict check, byte-by-byte"
|
||||
default n
|
||||
depends on KERNEL_LMS
|
||||
help
|
||||
Select y to enable byte-by-byte check in lms
|
||||
|
||||
config LMS_LIBC_FULL_CHECK
|
||||
bool "Enable libc all function do lms check"
|
||||
default n
|
||||
depends on KERNEL_LMS
|
||||
help
|
||||
Select y to enable libc full check
|
||||
@@ -1,122 +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 "string.h"
|
||||
#include "los_lms_pri.h"
|
||||
|
||||
#undef memset
|
||||
void *memset(void *addr, int c, size_t len)
|
||||
{
|
||||
__asan_storeN_noabort((UINTPTR)addr, len);
|
||||
return __memset(addr, c, len);
|
||||
}
|
||||
|
||||
#undef memmove
|
||||
void *memmove(void *dest, const void *src, size_t len)
|
||||
{
|
||||
__asan_loadN_noabort((UINTPTR)src, len);
|
||||
__asan_storeN_noabort((UINTPTR)dest, len);
|
||||
return __memmove(dest, src, len);
|
||||
}
|
||||
|
||||
#undef memcpy
|
||||
void *memcpy(void *dest, const void *src, size_t len)
|
||||
{
|
||||
__asan_loadN_noabort((UINTPTR)src, len);
|
||||
__asan_storeN_noabort((UINTPTR)dest, len);
|
||||
return __memcpy(dest, src, len);
|
||||
}
|
||||
|
||||
#undef strcat
|
||||
char *strcat (char *s, const char *append)
|
||||
{
|
||||
if ((s == NULL) || (append == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CHAR *end = s;
|
||||
size_t len = strlen(append);
|
||||
for (; *end != '\0'; ++end) {
|
||||
}
|
||||
|
||||
__asan_storeN_noabort((UINTPTR)end, len + 1);
|
||||
__asan_loadN_noabort((UINTPTR)append, len + 1);
|
||||
|
||||
return __strcat(s, append);
|
||||
}
|
||||
|
||||
#undef strcpy
|
||||
char *strcpy(char *dest, const char *src)
|
||||
{
|
||||
if ((dest == NULL) || (src == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t len = strlen(src);
|
||||
__asan_storeN_noabort((UINTPTR)dest, len + 1);
|
||||
__asan_loadN_noabort((UINTPTR)src, len + 1);
|
||||
|
||||
return __strcpy(dest, src);
|
||||
}
|
||||
|
||||
#undef strncat
|
||||
char *strncat(char *dest, const char *src, size_t n)
|
||||
{
|
||||
if ((dest == NULL) || (src == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CHAR *end = dest;
|
||||
size_t len = strlen(src);
|
||||
size_t size = len > n ? n : len;
|
||||
for (; *end != '\0'; ++end) {
|
||||
}
|
||||
|
||||
__asan_storeN_noabort((UINTPTR)end, size + 1);
|
||||
__asan_loadN_noabort((UINTPTR)src, size + 1);
|
||||
|
||||
return __strncat(dest, src, n);
|
||||
}
|
||||
|
||||
#undef strncpy
|
||||
char *strncpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
if ((dest == NULL) || (src == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t len = strlen(src);
|
||||
size_t size = len > n ? n : len;
|
||||
|
||||
__asan_storeN_noabort((UINTPTR)dest, n);
|
||||
__asan_loadN_noabort((UINTPTR)src, size + 1);
|
||||
return __strncpy(dest, src, n);
|
||||
}
|
||||
@@ -1,780 +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 "los_lms_pri.h"
|
||||
#include "los_config.h"
|
||||
#include "los_debug.h"
|
||||
#if (LOSCFG_KERNEL_SMP == 1)
|
||||
#include "los_spinlock.h"
|
||||
#else
|
||||
#include "los_interrupt.h"
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_BACKTRACE_TYPE != 0)
|
||||
#include "los_backtrace.h"
|
||||
#endif
|
||||
#include "los_sched.h"
|
||||
|
||||
LITE_OS_SEC_BSS STATIC LmsMemListNode g_lmsCheckPoolArray[LOSCFG_LMS_MAX_RECORD_POOL_NUM];
|
||||
LITE_OS_SEC_BSS STATIC LOS_DL_LIST g_lmsCheckPoolList;
|
||||
STATIC UINT32 g_checkDepth = 0;
|
||||
LmsHook *g_lms = NULL;
|
||||
|
||||
#if (LOSCFG_KERNEL_SMP == 1)
|
||||
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_lmsSpin);
|
||||
#define LMS_LOCK(state) LOS_SpinLockSave(&g_lmsSpin, &(state))
|
||||
#define LMS_UNLOCK(state) LOS_SpinUnlockRestore(&g_lmsSpin, (state))
|
||||
#else
|
||||
#define LMS_LOCK(state) (state) = LOS_IntLock()
|
||||
#define LMS_UNLOCK(state) LOS_IntRestore(state)
|
||||
#endif
|
||||
|
||||
#define OS_MEM_ALIGN_BACK(value, align) (((UINT32)(value)) & ~((UINT32)((align) - 1)))
|
||||
#define IS_ALIGNED(value, align) ((((UINTPTR)(value)) & ((UINTPTR)((align) - 1))) == 0)
|
||||
#define OS_MEM_ALIGN_SIZE sizeof(UINTPTR)
|
||||
#define POOL_ADDR_ALIGNSIZE 64
|
||||
#define LMS_POOL_UNUSED 0
|
||||
#define LMS_POOL_USED 1
|
||||
#define INVALID_SHADOW_VALUE 0xFFFFFFFF
|
||||
|
||||
STATIC UINT32 OsLmsPoolResize(UINT32 size)
|
||||
{
|
||||
return OS_MEM_ALIGN_BACK(LMS_POOL_RESIZE(size), POOL_ADDR_ALIGNSIZE);
|
||||
}
|
||||
|
||||
STATIC LmsMemListNode *OsLmsGetPoolNode(const VOID *pool)
|
||||
{
|
||||
UINTPTR poolAddr = (UINTPTR)pool;
|
||||
LmsMemListNode *current = NULL;
|
||||
LOS_DL_LIST *listHead = &g_lmsCheckPoolList;
|
||||
|
||||
if (LOS_ListEmpty(&g_lmsCheckPoolList)) {
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(current, listHead, LmsMemListNode, node) {
|
||||
if (current->poolAddr == poolAddr) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC LmsMemListNode *OsLmsGetPoolNodeFromAddr(UINTPTR addr)
|
||||
{
|
||||
LmsMemListNode *current = NULL;
|
||||
LOS_DL_LIST *listHead = &g_lmsCheckPoolList;
|
||||
|
||||
if (LOS_ListEmpty(&g_lmsCheckPoolList)) {
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(current, listHead, LmsMemListNode, node) {
|
||||
if ((addr >= current->poolAddr) && (addr < current->poolAddr + current->poolSize)) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
STATIC LmsMemListNode *OsLmsCheckPoolCreate(VOID)
|
||||
{
|
||||
UINT32 i;
|
||||
LmsMemListNode *current = NULL;
|
||||
for (i = 0; i < LOSCFG_LMS_MAX_RECORD_POOL_NUM; i++) {
|
||||
current = &g_lmsCheckPoolArray[i];
|
||||
if (current->used == LMS_POOL_UNUSED) {
|
||||
current->used = LMS_POOL_USED;
|
||||
return current;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINTPTR poolAddr = (UINTPTR)pool;
|
||||
UINT32 realSize;
|
||||
LmsMemListNode *lmsPoolNode = NULL;
|
||||
|
||||
if (pool == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
|
||||
lmsPoolNode = OsLmsGetPoolNodeFromAddr((UINTPTR)pool);
|
||||
if (lmsPoolNode != NULL) { /* if pool range already on checklist */
|
||||
if (lmsPoolNode->poolAddr != (UINTPTR)pool) { /* pool is a subset of lmsPoolNode->poolAddr */
|
||||
/* do not add it again, just return */
|
||||
PRINT_DEBUG("[LMS]pool %p already on lms checklist !\n", pool);
|
||||
LMS_UNLOCK(intSave);
|
||||
return size; /* return size indicate the shadow memory init successful */
|
||||
} else { /* Re-initialize the same pool, maybe with different size */
|
||||
/* delete the old node, then add a new one */
|
||||
lmsPoolNode->used = LMS_POOL_UNUSED;
|
||||
LOS_ListDelete(&(lmsPoolNode->node));
|
||||
}
|
||||
}
|
||||
|
||||
lmsPoolNode = OsLmsCheckPoolCreate();
|
||||
if (lmsPoolNode == NULL) {
|
||||
PRINT_DEBUG("[LMS]the num of lms check pool is max already !\n");
|
||||
LMS_UNLOCK(intSave);
|
||||
return 0;
|
||||
}
|
||||
realSize = OsLmsPoolResize(size);
|
||||
|
||||
lmsPoolNode->poolAddr = poolAddr;
|
||||
lmsPoolNode->poolSize = realSize;
|
||||
lmsPoolNode->shadowStart = (UINTPTR)poolAddr + realSize;
|
||||
lmsPoolNode->shadowSize = poolAddr + size - lmsPoolNode->shadowStart;
|
||||
/* init shadow value */
|
||||
(VOID)memset((VOID *)lmsPoolNode->shadowStart, LMS_SHADOW_AFTERFREE_U8, lmsPoolNode->shadowSize);
|
||||
|
||||
LOS_ListAdd(&g_lmsCheckPoolList, &(lmsPoolNode->node));
|
||||
|
||||
LMS_UNLOCK(intSave);
|
||||
return realSize;
|
||||
}
|
||||
|
||||
VOID LOS_LmsCheckPoolDel(const VOID *pool)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (pool == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
LmsMemListNode *delNode = OsLmsGetPoolNode(pool);
|
||||
if (delNode == NULL) {
|
||||
PRINT_ERR("[LMS]pool %p is not on lms checklist !\n", pool);
|
||||
goto Release;
|
||||
}
|
||||
delNode->used = LMS_POOL_UNUSED;
|
||||
LOS_ListDelete(&(delNode->node));
|
||||
Release:
|
||||
LMS_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
VOID OsLmsInit(VOID)
|
||||
{
|
||||
memset(g_lmsCheckPoolArray, 0, sizeof(g_lmsCheckPoolArray));
|
||||
LOS_ListInit(&g_lmsCheckPoolList);
|
||||
static LmsHook hook = {
|
||||
.init = LOS_LmsCheckPoolAdd,
|
||||
.mallocMark = OsLmsLosMallocMark,
|
||||
.freeMark = OsLmsLosFreeMark,
|
||||
.simpleMark = OsLmsSimpleMark,
|
||||
.check = OsLmsCheckValid,
|
||||
};
|
||||
g_lms = &hook;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsLmsMem2Shadow(LmsMemListNode *node, UINTPTR memAddr, UINTPTR *shadowAddr, UINT32 *shadowOffset)
|
||||
{
|
||||
if ((memAddr < node->poolAddr) || (memAddr >= node->poolAddr + node->poolSize)) { /* check ptr valid */
|
||||
PRINT_ERR("[LMS]memAddr %p is not in pool region [%p, %p)\n", memAddr, node->poolAddr,
|
||||
node->poolAddr + node->poolSize);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
UINT32 memOffset = memAddr - node->poolAddr;
|
||||
*shadowAddr = node->shadowStart + memOffset / LMS_SHADOW_U8_REFER_BYTES;
|
||||
*shadowOffset = ((memOffset % LMS_SHADOW_U8_REFER_BYTES) / LMS_SHADOW_U8_CELL_NUM) *
|
||||
LMS_SHADOW_BITS_PER_CELL; /* (memOffset % 16) / 4 */
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsLmsGetShadowInfo(LmsMemListNode *node, UINTPTR memAddr, LmsAddrInfo *info)
|
||||
{
|
||||
UINTPTR shadowAddr;
|
||||
UINT32 shadowOffset;
|
||||
UINT32 shadowValue;
|
||||
|
||||
if (OsLmsMem2Shadow(node, memAddr, &shadowAddr, &shadowOffset) != LOS_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
shadowValue = ((*(UINT8 *)shadowAddr) >> shadowOffset) & LMS_SHADOW_MASK;
|
||||
info->memAddr = memAddr;
|
||||
info->shadowAddr = shadowAddr;
|
||||
info->shadowOffset = shadowOffset;
|
||||
info->shadowValue = shadowValue;
|
||||
}
|
||||
|
||||
VOID OsLmsSetShadowValue(LmsMemListNode *node, UINTPTR startAddr, UINTPTR endAddr, UINT8 value)
|
||||
{
|
||||
UINTPTR shadowStart;
|
||||
UINTPTR shadowEnd;
|
||||
UINT32 startOffset;
|
||||
UINT32 endOffset;
|
||||
|
||||
UINT8 shadowValueMask;
|
||||
UINT8 shadowValue;
|
||||
|
||||
/* endAddr -1, then we mark [startAddr, endAddr) to value */
|
||||
if (OsLmsMem2Shadow(node, startAddr, &shadowStart, &startOffset) ||
|
||||
OsLmsMem2Shadow(node, endAddr - 1, &shadowEnd, &endOffset)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shadowStart == shadowEnd) { /* in the same u8 */
|
||||
/* because endAddr - 1, the endOffset falls into the previous cell,
|
||||
so endOffset + 2 is required for calculation */
|
||||
shadowValueMask = LMS_SHADOW_MASK_U8;
|
||||
shadowValueMask =
|
||||
(shadowValueMask << startOffset) & (~(shadowValueMask << (endOffset + LMS_SHADOW_BITS_PER_CELL)));
|
||||
shadowValue = value & shadowValueMask;
|
||||
*(UINT8 *)shadowStart &= ~shadowValueMask;
|
||||
*(UINT8 *)shadowStart |= shadowValue;
|
||||
} else {
|
||||
/* Adjust startAddr to left util it reach the beginning of a u8 */
|
||||
if (startOffset > 0) {
|
||||
shadowValueMask = LMS_SHADOW_MASK_U8;
|
||||
shadowValueMask = shadowValueMask << startOffset;
|
||||
shadowValue = value & shadowValueMask;
|
||||
*(UINT8 *)shadowStart &= ~shadowValueMask;
|
||||
*(UINT8 *)shadowStart |= shadowValue;
|
||||
shadowStart += 1;
|
||||
}
|
||||
|
||||
/* Adjust endAddr to right util it reach the end of a u8 */
|
||||
if (endOffset < (LMS_SHADOW_U8_CELL_NUM - 1) * LMS_SHADOW_BITS_PER_CELL) {
|
||||
shadowValueMask = LMS_SHADOW_MASK_U8;
|
||||
shadowValueMask &= ~(shadowValueMask << (endOffset + LMS_SHADOW_BITS_PER_CELL));
|
||||
shadowValue = value & shadowValueMask;
|
||||
*(UINT8 *)shadowEnd &= ~shadowValueMask;
|
||||
*(UINT8 *)shadowEnd |= shadowValue;
|
||||
shadowEnd -= 1;
|
||||
}
|
||||
|
||||
if (shadowEnd + 1 > shadowStart) {
|
||||
memset((VOID *)shadowStart, value & LMS_SHADOW_MASK_U8, shadowEnd + 1 - shadowStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VOID OsLmsGetShadowValue(LmsMemListNode *node, UINTPTR addr, UINT32 *shadowValue)
|
||||
{
|
||||
UINTPTR shadowAddr;
|
||||
UINT32 shadowOffset;
|
||||
if (OsLmsMem2Shadow(node, addr, &shadowAddr, &shadowOffset) != LOS_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
*shadowValue = ((*(UINT8 *)shadowAddr) >> shadowOffset) & LMS_SHADOW_MASK;
|
||||
}
|
||||
|
||||
VOID OsLmsSimpleMark(UINTPTR startAddr, UINTPTR endAddr, UINT32 value)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (endAddr <= startAddr) {
|
||||
PRINT_DEBUG("[LMS]mark 0x%x, 0x%x, 0x%x\n", startAddr, endAddr, (UINTPTR)__builtin_return_address(0));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IS_ALIGNED(startAddr, OS_MEM_ALIGN_SIZE) || !IS_ALIGNED(endAddr, OS_MEM_ALIGN_SIZE)) {
|
||||
PRINT_ERR("[LMS]mark addr is not aligned! 0x%x, 0x%x\n", startAddr, endAddr);
|
||||
return;
|
||||
}
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
|
||||
LmsMemListNode *node = OsLmsGetPoolNodeFromAddr(startAddr);
|
||||
if (node == NULL) {
|
||||
LMS_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
OsLmsSetShadowValue(node, startAddr, endAddr, value);
|
||||
LMS_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
VOID OsLmsLosMallocMark(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINTPTR curNodeStartAddr = (UINTPTR)curNodeStart;
|
||||
UINTPTR nextNodeStartAddr = (UINTPTR)nextNodeStart;
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
LmsMemListNode *node = OsLmsGetPoolNodeFromAddr((UINTPTR)curNodeStart);
|
||||
if (node == NULL) {
|
||||
LMS_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
OsLmsSetShadowValue(node, curNodeStartAddr, curNodeStartAddr + nodeHeadSize, LMS_SHADOW_REDZONE_U8);
|
||||
OsLmsSetShadowValue(node, curNodeStartAddr + nodeHeadSize, nextNodeStartAddr, LMS_SHADOW_ACCESSABLE_U8);
|
||||
OsLmsSetShadowValue(node, nextNodeStartAddr, nextNodeStartAddr + nodeHeadSize, LMS_SHADOW_REDZONE_U8);
|
||||
LMS_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
VOID OsLmsCheckValid(UINTPTR checkAddr, BOOL isFreeCheck)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 shadowValue = INVALID_SHADOW_VALUE;
|
||||
LMS_LOCK(intSave);
|
||||
LmsMemListNode *node = OsLmsGetPoolNodeFromAddr(checkAddr);
|
||||
if (node == NULL) {
|
||||
LMS_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
OsLmsGetShadowValue(node, checkAddr, &shadowValue);
|
||||
LMS_UNLOCK(intSave);
|
||||
if ((shadowValue == LMS_SHADOW_ACCESSABLE) || ((isFreeCheck) && (shadowValue == LMS_SHADOW_PAINT))) {
|
||||
return;
|
||||
}
|
||||
|
||||
OsLmsReportError(checkAddr, MEM_REGION_SIZE_1, isFreeCheck ? FREE_ERRORMODE : COMMON_ERRMODE);
|
||||
}
|
||||
|
||||
VOID OsLmsLosFreeMark(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 shadowValue = INVALID_SHADOW_VALUE;
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
LmsMemListNode *node = OsLmsGetPoolNodeFromAddr((UINTPTR)curNodeStart);
|
||||
if (node == NULL) {
|
||||
LMS_UNLOCK(intSave);
|
||||
return;
|
||||
}
|
||||
|
||||
UINTPTR curNodeStartAddr = (UINTPTR)curNodeStart;
|
||||
UINTPTR nextNodeStartAddr = (UINTPTR)nextNodeStart;
|
||||
|
||||
OsLmsGetShadowValue(node, curNodeStartAddr + nodeHeadSize, &shadowValue);
|
||||
if ((shadowValue != LMS_SHADOW_ACCESSABLE) && (shadowValue != LMS_SHADOW_PAINT)) {
|
||||
LMS_UNLOCK(intSave);
|
||||
OsLmsReportError(curNodeStartAddr + nodeHeadSize, MEM_REGION_SIZE_1, FREE_ERRORMODE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (*((UINT8 *)curNodeStart) == 0) { /* if merge the node has memset with 0 */
|
||||
OsLmsSetShadowValue(node, curNodeStartAddr, curNodeStartAddr + nodeHeadSize, LMS_SHADOW_AFTERFREE_U8);
|
||||
}
|
||||
OsLmsSetShadowValue(node, curNodeStartAddr + nodeHeadSize, nextNodeStartAddr, LMS_SHADOW_AFTERFREE_U8);
|
||||
|
||||
if (*((UINT8 *)nextNodeStart) == 0) { /* if merge the node has memset with 0 */
|
||||
OsLmsSetShadowValue(node, nextNodeStartAddr, nextNodeStartAddr + nodeHeadSize, LMS_SHADOW_AFTERFREE_U8);
|
||||
}
|
||||
|
||||
LMS_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
VOID LOS_LmsAddrProtect(UINTPTR addrStart, UINTPTR addrEnd)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (addrEnd <= addrStart) {
|
||||
return;
|
||||
}
|
||||
LMS_LOCK(intSave);
|
||||
LmsMemListNode *node = OsLmsGetPoolNodeFromAddr(addrStart);
|
||||
if (node != NULL) {
|
||||
OsLmsSetShadowValue(node, addrStart, addrEnd, LMS_SHADOW_REDZONE_U8);
|
||||
}
|
||||
LMS_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
VOID LOS_LmsAddrDisableProtect(UINTPTR addrStart, UINTPTR addrEnd)
|
||||
{
|
||||
UINT32 intSave;
|
||||
if (addrEnd <= addrStart) {
|
||||
return;
|
||||
}
|
||||
LMS_LOCK(intSave);
|
||||
LmsMemListNode *node = OsLmsGetPoolNodeFromAddr(addrStart);
|
||||
if (node != NULL) {
|
||||
OsLmsSetShadowValue(node, addrStart, addrEnd, LMS_SHADOW_ACCESSABLE_U8);
|
||||
}
|
||||
LMS_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
STATIC UINT32 OsLmsCheckAddr(UINTPTR addr)
|
||||
{
|
||||
UINT32 intSave;
|
||||
UINT32 shadowValue = INVALID_SHADOW_VALUE;
|
||||
/* do not check nested or before all cpu start */
|
||||
LMS_LOCK(intSave);
|
||||
if ((g_checkDepth != 0) || (!g_taskScheduled)) {
|
||||
LMS_UNLOCK(intSave);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LmsMemListNode *node = OsLmsGetPoolNodeFromAddr(addr);
|
||||
if (node == NULL) {
|
||||
LMS_UNLOCK(intSave);
|
||||
return LMS_SHADOW_ACCESSABLE_U8;
|
||||
}
|
||||
|
||||
OsLmsGetShadowValue(node, addr, &shadowValue);
|
||||
LMS_UNLOCK(intSave);
|
||||
return shadowValue;
|
||||
}
|
||||
|
||||
#if (LOSCFG_LMS_CHECK_STRICT == 1)
|
||||
STATIC INLINE UINT32 OsLmsCheckAddrRegion(UINTPTR addr, UINT32 size)
|
||||
{
|
||||
UINT32 i;
|
||||
for (i = 0; i < size; i++) {
|
||||
if (OsLmsCheckAddr(addr + i)) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
#else
|
||||
STATIC INLINE UINT32 OsLmsCheckAddrRegion(UINTPTR addr, UINT32 size)
|
||||
{
|
||||
if (OsLmsCheckAddr(addr) || OsLmsCheckAddr(addr + size - 1)) {
|
||||
return LOS_NOK;
|
||||
} else {
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
VOID OsLmsPrintPoolListInfo(VOID)
|
||||
{
|
||||
UINT32 count = 0;
|
||||
UINT32 intSave;
|
||||
LmsMemListNode *current = NULL;
|
||||
LOS_DL_LIST *listHead = &g_lmsCheckPoolList;
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
LOS_DL_LIST_FOR_EACH_ENTRY(current, listHead, LmsMemListNode, node)
|
||||
{
|
||||
count++;
|
||||
PRINT_DEBUG(
|
||||
"[LMS]memory pool[%1u]: totalsize 0x%-8x memstart 0x%-8x memstop 0x%-8x memsize 0x%-8x shadowstart 0x%-8x "
|
||||
"shadowSize 0x%-8x\n",
|
||||
count, current->poolSize + current->shadowSize, current->poolAddr, current->poolAddr + current->poolSize,
|
||||
current->poolSize, current->shadowStart, current->shadowSize);
|
||||
}
|
||||
|
||||
LMS_UNLOCK(intSave);
|
||||
}
|
||||
|
||||
VOID OsLmsPrintMemInfo(UINTPTR addr)
|
||||
{
|
||||
#define LMS_DUMP_OFFSET 16
|
||||
#define LMS_DUMP_RANGE_DOUBLE 2
|
||||
|
||||
PRINTK("\n[LMS] Dump info around address [0x%8x]:\n", addr);
|
||||
const UINT32 printY = LMS_DUMP_OFFSET * LMS_DUMP_RANGE_DOUBLE + 1;
|
||||
const UINT32 printX = LMS_MEM_BYTES_PER_SHADOW_CELL * LMS_DUMP_RANGE_DOUBLE;
|
||||
UINTPTR dumpAddr = addr - addr % printX - LMS_DUMP_OFFSET * printX;
|
||||
UINT32 shadowValue = 0;
|
||||
UINTPTR shadowAddr = 0;
|
||||
UINT32 shadowOffset = 0;
|
||||
LmsMemListNode *nodeInfo = NULL;
|
||||
INT32 isCheckAddr, x, y;
|
||||
|
||||
nodeInfo = OsLmsGetPoolNodeFromAddr(addr);
|
||||
if (nodeInfo == NULL) {
|
||||
PRINT_ERR("[LMS]addr is not in checkpool\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (y = 0; y < printY; y++, dumpAddr += printX) {
|
||||
if (dumpAddr < nodeInfo->poolAddr) { /* find util dumpAddr in pool region */
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((dumpAddr + printX) >=
|
||||
nodeInfo->poolAddr + nodeInfo->poolSize) { /* finish if dumpAddr exceeds pool's upper region */
|
||||
goto END;
|
||||
}
|
||||
|
||||
PRINTK("\n\t[0x%x]: ", dumpAddr);
|
||||
for (x = 0; x < printX; x++) {
|
||||
if ((dumpAddr + x) == addr) {
|
||||
PRINTK("[%02x]", *(UINT8 *)(dumpAddr + x));
|
||||
} else {
|
||||
PRINTK(" %02x ", *(UINT8 *)(dumpAddr + x));
|
||||
}
|
||||
}
|
||||
|
||||
if (OsLmsMem2Shadow(nodeInfo, dumpAddr, &shadowAddr, &shadowOffset) != LOS_OK) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
PRINTK("|\t[0x%x | %2u]: ", shadowAddr, shadowOffset);
|
||||
|
||||
for (x = 0; x < printX; x += LMS_MEM_BYTES_PER_SHADOW_CELL) {
|
||||
OsLmsGetShadowValue(nodeInfo, dumpAddr + x, &shadowValue);
|
||||
isCheckAddr = dumpAddr + x - (UINTPTR)addr + LMS_MEM_BYTES_PER_SHADOW_CELL;
|
||||
if ((isCheckAddr > 0) && (isCheckAddr <= LMS_MEM_BYTES_PER_SHADOW_CELL)) {
|
||||
PRINTK("[%1x]", shadowValue);
|
||||
} else {
|
||||
PRINTK(" %1x ", shadowValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
END:
|
||||
PRINTK("\n");
|
||||
}
|
||||
|
||||
STATIC VOID OsLmsGetErrorInfo(UINTPTR addr, UINT32 size, LmsAddrInfo *info)
|
||||
{
|
||||
LmsMemListNode *node = OsLmsGetPoolNodeFromAddr(addr);
|
||||
OsLmsGetShadowInfo(node, addr, info);
|
||||
if (info->shadowValue != LMS_SHADOW_ACCESSABLE_U8) {
|
||||
return;
|
||||
} else {
|
||||
OsLmsGetShadowInfo(node, addr + size - 1, info);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsLmsPrintErrInfo(LmsAddrInfo *info, UINT32 errMod)
|
||||
{
|
||||
switch (info->shadowValue) {
|
||||
case LMS_SHADOW_AFTERFREE:
|
||||
PRINT_ERR("Use after free error detected\n");
|
||||
break;
|
||||
case LMS_SHADOW_REDZONE:
|
||||
PRINT_ERR("Heap buffer overflow error detected\n");
|
||||
break;
|
||||
case LMS_SHADOW_ACCESSABLE:
|
||||
PRINT_ERR("No error\n");
|
||||
break;
|
||||
default:
|
||||
PRINT_ERR("UnKnown Error detected\n");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (errMod) {
|
||||
case FREE_ERRORMODE:
|
||||
PRINT_ERR("Illegal Double free address at: [0x%lx]\n", info->memAddr);
|
||||
break;
|
||||
case LOAD_ERRMODE:
|
||||
PRINT_ERR("Illegal READ address at: [0x%lx]\n", info->memAddr);
|
||||
break;
|
||||
case STORE_ERRMODE:
|
||||
PRINT_ERR("Illegal WRITE address at: [0x%lx]\n", info->memAddr);
|
||||
break;
|
||||
case COMMON_ERRMODE:
|
||||
PRINT_ERR("Common Error at: [0x%lx]\n", info->memAddr);
|
||||
break;
|
||||
default:
|
||||
PRINT_ERR("UnKnown Error mode at: [0x%lx]\n", info->memAddr);
|
||||
break;
|
||||
}
|
||||
|
||||
PRINT_ERR("Shadow memory address: [0x%lx : %1u] Shadow memory value: [%u] \n", info->shadowAddr,
|
||||
info->shadowOffset, info->shadowValue);
|
||||
}
|
||||
|
||||
VOID OsLmsReportError(UINTPTR p, UINT32 size, UINT32 errMod)
|
||||
{
|
||||
UINT32 intSave;
|
||||
LmsAddrInfo info;
|
||||
|
||||
LMS_LOCK(intSave);
|
||||
g_checkDepth += 1;
|
||||
memset(&info, 0, sizeof(LmsAddrInfo));
|
||||
|
||||
PRINT_ERR("***** Kernel Address Sanitizer Error Detected Start *****\n");
|
||||
|
||||
OsLmsGetErrorInfo(p, size, &info);
|
||||
|
||||
OsLmsPrintErrInfo(&info, errMod);
|
||||
#if (LOSCFG_BACKTRACE_TYPE != 0)
|
||||
LOS_BackTrace();
|
||||
#endif
|
||||
OsLmsPrintMemInfo(info.memAddr);
|
||||
g_checkDepth -= 1;
|
||||
LMS_UNLOCK(intSave);
|
||||
PRINT_ERR("***** Kernel Address Sanitizer Error Detected End *****\n");
|
||||
}
|
||||
|
||||
#if (LOSCFG_LMS_STORE_CHECK == 1)
|
||||
VOID __asan_store1_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddr(p) != LMS_SHADOW_ACCESSABLE_U8) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_1, STORE_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_store2_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, MEM_REGION_SIZE_2) != LOS_OK) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_2, STORE_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_store4_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, MEM_REGION_SIZE_4) != LOS_OK) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_4, STORE_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_store8_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, MEM_REGION_SIZE_8) != LOS_OK) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_8, STORE_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_store16_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, MEM_REGION_SIZE_16) != LOS_OK) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_16, STORE_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_storeN_noabort(UINTPTR p, UINT32 size)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, size) != LOS_OK) {
|
||||
OsLmsReportError(p, size, STORE_ERRMODE);
|
||||
}
|
||||
}
|
||||
#else
|
||||
VOID __asan_store1_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_store2_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_store4_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_store8_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_store16_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_storeN_noabort(UINTPTR p, UINT32 size)
|
||||
{
|
||||
(VOID)p;
|
||||
(VOID)size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if (LOSCFG_LMS_LOAD_CHECK == 1)
|
||||
VOID __asan_load1_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddr(p) != LMS_SHADOW_ACCESSABLE_U8) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_1, LOAD_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_load2_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, MEM_REGION_SIZE_2) != LOS_OK) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_2, LOAD_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_load4_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, MEM_REGION_SIZE_4) != LOS_OK) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_4, LOAD_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_load8_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, MEM_REGION_SIZE_8) != LOS_OK) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_8, LOAD_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_load16_noabort(UINTPTR p)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, MEM_REGION_SIZE_16) != LOS_OK) {
|
||||
OsLmsReportError(p, MEM_REGION_SIZE_16, LOAD_ERRMODE);
|
||||
}
|
||||
}
|
||||
|
||||
VOID __asan_loadN_noabort(UINTPTR p, UINT32 size)
|
||||
{
|
||||
if (OsLmsCheckAddrRegion(p, size) != LOS_OK) {
|
||||
OsLmsReportError(p, size, LOAD_ERRMODE);
|
||||
}
|
||||
}
|
||||
#else
|
||||
VOID __asan_load1_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_load2_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_load4_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_load8_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_load16_noabort(UINTPTR p)
|
||||
{
|
||||
(VOID)p;
|
||||
}
|
||||
|
||||
VOID __asan_loadN_noabort(UINTPTR p, UINT32 size)
|
||||
{
|
||||
(VOID)p;
|
||||
(VOID)size;
|
||||
}
|
||||
#endif
|
||||
VOID __asan_handle_no_return(VOID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1,59 +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 _LOS_LMS_H
|
||||
#define _LOS_LMS_H
|
||||
|
||||
#include "los_compiler.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef LOSCFG_KERNEL_LMS
|
||||
|
||||
UINT32 LOS_LmsCheckPoolAdd(const VOID *pool, UINT32 size);
|
||||
VOID LOS_LmsCheckPoolDel(const VOID *pool);
|
||||
VOID LOS_LmsAddrProtect(UINTPTR addrStart, UINTPTR addrEnd);
|
||||
VOID LOS_LmsAddrDisableProtect(UINTPTR addrStart, UINTPTR addrEnd);
|
||||
|
||||
#endif /* LOSCFG_KERNEL_LMS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_LMS_H */
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_LMS_PRI_H
|
||||
#define _LOS_LMS_PRI_H
|
||||
|
||||
#include "los_lms.h"
|
||||
#include "los_compiler.h"
|
||||
#include "los_list.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define COMMON_ERRMODE 3
|
||||
#define FREE_ERRORMODE 2
|
||||
#define STORE_ERRMODE 1
|
||||
#define LOAD_ERRMODE 0
|
||||
|
||||
#define SANITIZER_INTERFACE_ATTRIBUTE
|
||||
#define ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
|
||||
|
||||
#define LMS_SHADOW_BITS_PER_CELL 2
|
||||
#define LMS_MEM_BYTES_PER_SHADOW_CELL 4
|
||||
#define LMS_SHADOW_U8_CELL_NUM 4
|
||||
#define LMS_SHADOW_U8_REFER_BYTES 16
|
||||
|
||||
#define LMS_POOL_RESIZE(size) ((size) / (LMS_SHADOW_U8_REFER_BYTES + 1) * LMS_SHADOW_U8_REFER_BYTES)
|
||||
#define LMS_ADDR_ALIGN(p) (((UINTPTR)(p) + sizeof(UINTPTR) - 1) & ~((UINTPTR)(sizeof(UINTPTR) - 1)))
|
||||
|
||||
#define LMS_SHADOW_ACCESSABLE 0x00
|
||||
#define LMS_SHADOW_AFTERFREE 0x03
|
||||
#define LMS_SHADOW_REDZONE 0x02
|
||||
#define LMS_SHADOW_PAINT 0x01
|
||||
#define LMS_SHADOW_MASK 0x03
|
||||
|
||||
#define LMS_SHADOW_ACCESSABLE_U8 0x00
|
||||
#define LMS_SHADOW_AFTERFREE_U8 0xFF
|
||||
#define LMS_SHADOW_REDZONE_U8 0xAA
|
||||
#define LMS_SHADOW_MASK_U8 0xFF
|
||||
#define LMS_SHADOW_PAINT_U8 0x55
|
||||
|
||||
#define MEM_REGION_SIZE_1 1
|
||||
#define MEM_REGION_SIZE_2 2
|
||||
#define MEM_REGION_SIZE_4 4
|
||||
#define MEM_REGION_SIZE_8 8
|
||||
#define MEM_REGION_SIZE_16 16
|
||||
|
||||
typedef struct {
|
||||
LOS_DL_LIST node;
|
||||
UINT32 used;
|
||||
UINTPTR poolAddr;
|
||||
UINT32 poolSize;
|
||||
UINTPTR shadowStart;
|
||||
UINT32 shadowSize;
|
||||
} LmsMemListNode;
|
||||
|
||||
typedef struct {
|
||||
UINTPTR memAddr;
|
||||
UINTPTR shadowAddr;
|
||||
UINT32 shadowOffset;
|
||||
UINT32 shadowValue;
|
||||
} LmsAddrInfo;
|
||||
|
||||
typedef struct {
|
||||
UINT32 (*init)(const VOID *pool, UINT32 size);
|
||||
VOID (*mallocMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID (*freeMark)(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID (*simpleMark)(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
|
||||
VOID (*check)(UINTPTR checkAddr, BOOL isFreeCheck);
|
||||
} LmsHook;
|
||||
extern LmsHook* g_lms;
|
||||
|
||||
VOID OsLmsInit(VOID);
|
||||
VOID OsLmsCheckValid(UINTPTR checkAddr, BOOL isFreeCheck);
|
||||
VOID OsLmsLosMallocMark(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID OsLmsLosFreeMark(const VOID *curNodeStart, const VOID *nextNodeStart, UINT32 nodeHeadSize);
|
||||
VOID OsLmsSimpleMark(UINTPTR startAddr, UINTPTR endAddr, UINT32 value);
|
||||
|
||||
VOID OsLmsPrintPoolListInfo(VOID);
|
||||
VOID OsLmsReportError(UINTPTR p, UINT32 size, UINT32 errMod);
|
||||
|
||||
VOID CheckValid(const CHAR *dest, const CHAR *src);
|
||||
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store1_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store4_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load4_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load1_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_loadN_noabort(UINTPTR p, UINT32 size);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_storeN_noabort(UINTPTR p, UINT32 size);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store2_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load2_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store8_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load8_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_load16_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_store16_noabort(UINTPTR p);
|
||||
extern SANITIZER_INTERFACE_ATTRIBUTE VOID __asan_handle_no_return(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_LMS_PRI_H */
|
||||
@@ -1,42 +1,50 @@
|
||||
# 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.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
import("$LITEOSTHIRDPARTY/lwip/lwip.gni")
|
||||
import("$LITEOSTOPDIR/components/net/lwip-2.1/lwip_porting.gni")
|
||||
|
||||
module_switch = defined(LOSCFG_NET_LWIP_SACK)
|
||||
module_name = "lwip"
|
||||
kernel_module(module_name) {
|
||||
sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES - [ "$LWIPDIR/api/sockets.c" ]
|
||||
include_dirs = [ "//utils/native/lite/include" ]
|
||||
}
|
||||
|
||||
config("public") {
|
||||
include_dirs = LWIP_PORTING_INCLUDE_DIRS + LWIP_INCLUDE_DIRS
|
||||
}
|
||||
# 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.
|
||||
|
||||
import("lwip_porting.gni")
|
||||
import("//third_party/lwip/lwip.gni")
|
||||
|
||||
config("lwip_depends") {
|
||||
defines = [ "_BSD_SOURCE = 1" ]
|
||||
}
|
||||
|
||||
static_library("lwip") {
|
||||
include_dirs = [
|
||||
"//kernel/liteos_m/kal/posix/include",
|
||||
"//kernel/liteos_m/kernel/arch/include",
|
||||
]
|
||||
|
||||
include_dirs += LWIP_PORTING_INCLUDE_DIRS
|
||||
include_dirs += LWIP_INCLUDE_DIRS
|
||||
|
||||
sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES
|
||||
|
||||
configs += [ ":lwip_depends" ]
|
||||
|
||||
deps = [ "//kernel/liteos_m/kal/posix" ]
|
||||
}
|
||||
@@ -39,27 +39,6 @@
|
||||
#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
|
||||
#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
|
||||
|
||||
#if LWIP_DHCP
|
||||
#include <lwip/dhcp.h>
|
||||
#include <lwip/prot/dhcp.h>
|
||||
|
||||
err_t dhcp_is_bound(struct netif *netif)
|
||||
{
|
||||
struct dhcp *dhcp = NULL;
|
||||
|
||||
LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG);
|
||||
|
||||
dhcp = netif_dhcp_data(netif);
|
||||
LWIP_ERROR("netif->dhcp != NULL", (dhcp != NULL), return ERR_ARG);
|
||||
|
||||
if (dhcp->state == DHCP_STATE_BOUND) {
|
||||
return ERR_OK;
|
||||
} else {
|
||||
return ERR_INPROGRESS;
|
||||
}
|
||||
}
|
||||
#endif /* LWIP_DHCP */
|
||||
|
||||
static struct netif *netif_find_by_name(const char *name)
|
||||
{
|
||||
struct netif *netif = NULL;
|
||||
|
||||
@@ -1,46 +1,44 @@
|
||||
# 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.
|
||||
|
||||
import("//kernel/liteos_m/liteos.gni")
|
||||
|
||||
LWIP_PORTING_DIR = get_path_info(".", "abspath")
|
||||
|
||||
LWIP_PORTING_INCLUDE_DIRS = [ "$LWIP_PORTING_DIR/porting/include" ]
|
||||
|
||||
LWIP_PORTING_FILES = [
|
||||
"$LWIP_PORTING_DIR/porting/src/driverif.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/netdb_porting.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/sockets_porting.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/sys_arch.c",
|
||||
"$LWIP_PORTING_DIR/enhancement/src/fixme.c",
|
||||
"$LWIP_PORTING_DIR/enhancement/src/lwip_ifaddrs.c",
|
||||
]
|
||||
|
||||
if (defined(LOSCFG_SHELL)) {
|
||||
LWIP_PORTING_FILES += [ "$LWIP_PORTING_DIR/porting/src/api_shell.c" ]
|
||||
}
|
||||
# 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.
|
||||
import("//kernel/liteos_m/config.gni")
|
||||
LWIP_PORTING_DIR = "//kernel/liteos_m/components/net/lwip-2.1"
|
||||
|
||||
LWIP_PORTING_INCLUDE_DIRS = [ "$LWIP_PORTING_DIR/porting/include" ]
|
||||
|
||||
LWIP_PORTING_FILES = [
|
||||
"$LWIP_PORTING_DIR/porting/src/driverif.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/lwip_init.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/netdb_porting.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/sockets_porting.c",
|
||||
"$LWIP_PORTING_DIR/porting/src/sys_arch.c",
|
||||
if (enable_ohos_kernel_liteos_m_shell== true) {
|
||||
"$LWIP_PORTING_DIR/porting/src/api_shell.c",
|
||||
}
|
||||
"$LWIP_PORTING_DIR/enhancement/src/fixme.c",
|
||||
"$LWIP_PORTING_DIR/enhancement/src/lwip_ifaddrs.c",
|
||||
]
|
||||
@@ -44,6 +44,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "securec.h"
|
||||
#include "memory_pool.h"
|
||||
|
||||
#ifdef htons
|
||||
#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
|
||||
@@ -93,21 +94,33 @@
|
||||
|
||||
#define LWIP_RAND rand
|
||||
|
||||
#ifndef LWIP_LOGGER
|
||||
#define LWIP_LOGGER(msg)
|
||||
extern void HilogPrintf(const char *fmt, ...);
|
||||
|
||||
#ifndef HILOG_INFO
|
||||
#define HILOG_INFO(...)
|
||||
#ifndef HILOG_MODULE_APP
|
||||
#define HILOG_MODULE_APP 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern void LwipLogPrintf(const char *fmt, ...);
|
||||
#define LWIP_PLATFORM_DIAG(vars) LwipLogPrintf vars
|
||||
#define LWIP_PLATFORM_ASSERT(x) do { \
|
||||
LWIP_PLATFORM_DIAG(("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__)); \
|
||||
} while (0)
|
||||
#ifndef HILOG_ERROR
|
||||
#define HILOG_ERROR(...)
|
||||
#endif
|
||||
|
||||
#define LWIP_PLATFORM_DIAG(vars) HilogPrintf vars
|
||||
#define LWIP_PLATFORM_ASSERT(x) do {HILOG_ERROR(HILOG_MODULE_APP, \
|
||||
"Assertion \"%s\" errno %d line %d in %s\n", \
|
||||
x, errno, __LINE__, __FILE__);} while (0)
|
||||
|
||||
#define mem_clib_malloc LWIP_MEM_ALLOC
|
||||
#define mem_clib_free LWIP_MEM_FREE
|
||||
#define mem_clib_calloc LWIP_MEM_CALLOC
|
||||
|
||||
#define init_waitqueue_head(...)
|
||||
#define poll_check_waiters(...)
|
||||
#define IOCTL_CMD_CASE_HANDLER()
|
||||
|
||||
#ifndef _BSD_SOURCE
|
||||
#define _BSD_SOURCE 1
|
||||
#endif
|
||||
#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("114.114.114.114")))
|
||||
#define DNS_SERVER_ADDRESS_SECONDARY(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("114.114.115.115")))
|
||||
|
||||
#endif /* _LWIP_PORTING_CC_H_ */
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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,
|
||||
@@ -29,6 +29,18 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**********************************************************************************
|
||||
|
||||
* Notice of Export Control Law
|
||||
===============================================
|
||||
* Huawei LiteOS may be subject to applicable export control laws and regulations, which
|
||||
* might include those applicable to Huawei LiteOS of U.S. and the country in which you
|
||||
* are located.
|
||||
* Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance
|
||||
* with such applicable export control laws and regulations.
|
||||
***********************************************************************************/
|
||||
|
||||
|
||||
#ifndef LWIP_API_SHELL_H
|
||||
#define LWIP_API_SHELL_H
|
||||
|
||||
|
||||
@@ -1,38 +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 _LWIP_PORTING_DHCP_H_
|
||||
#define _LWIP_PORTING_DHCP_H_
|
||||
|
||||
#include_next <lwip/dhcp.h>
|
||||
|
||||
err_t dhcp_is_bound(struct netif *netif);
|
||||
|
||||
#endif /* _LWIP_PORTING_DHCP_H_ */
|
||||
@@ -43,6 +43,9 @@
|
||||
(ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
|
||||
|
||||
/* directly map this to the lwip internal functions */
|
||||
#define inet_addr(cp) ipaddr_addr(cp)
|
||||
#define inet_aton(cp, addr) ip4addr_aton(cp, (ip4_addr_t*)addr)
|
||||
#define inet_ntoa(addr) ip4addr_ntoa((const ip4_addr_t*)&(addr))
|
||||
#define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
|
||||
#endif /* LWIP_IPV4 */
|
||||
#if LWIP_IPV6
|
||||
|
||||
@@ -134,10 +134,7 @@
|
||||
#define LWIP_NETIF_LOOPBACK 1
|
||||
#define LWIP_POSIX_SOCKETS_IO_NAMES 0
|
||||
#define LWIP_RAW 1
|
||||
#ifdef LOSCFG_FS_VFS
|
||||
#include "vfs_config.h"
|
||||
#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS
|
||||
#endif
|
||||
#define LWIP_SOCKET_OFFSET FAT_MAX_OPEN_FILES
|
||||
#define LWIP_SO_RCVBUF 1
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
@@ -219,15 +216,79 @@
|
||||
#define LWIP_ENABLE_NET_CAPABILITY 1
|
||||
#define LWIP_ENABLE_CAP_NET_BROADCAST 0
|
||||
|
||||
// Options for liteos_m
|
||||
// Options for GT
|
||||
#undef LWIP_NETIF_PROMISC
|
||||
#define LWIP_NETIF_PROMISC 0
|
||||
|
||||
#define MEMP_MEM_MALLOC 1
|
||||
#undef LWIP_ICMP
|
||||
#define LWIP_ICMP 0
|
||||
|
||||
#undef LWIP_DHCP
|
||||
#define LWIP_DHCP 0
|
||||
|
||||
#undef LWIP_IGMP
|
||||
#define LWIP_IGMP 0
|
||||
|
||||
#undef LWIP_IPV6
|
||||
#define LWIP_IPV6 0
|
||||
|
||||
#undef LWIP_IPV6_DHCP6
|
||||
#define LWIP_IPV6_DHCP6 0
|
||||
|
||||
#undef TCP_SND_BUF
|
||||
#define TCP_SND_BUF (65535 / 3)
|
||||
|
||||
#undef TCP_WND
|
||||
#define TCP_WND ((TCP_SND_BUF * 2) / 3)
|
||||
|
||||
#undef TCP_SND_QUEUELEN
|
||||
#define TCP_SND_QUEUELEN (2 * (TCP_SND_BUF / TCP_MSS))
|
||||
|
||||
#undef MEMP_NUM_NETDB
|
||||
#define MEMP_NUM_NETDB 1
|
||||
|
||||
#undef MEMP_NUM_ARP_QUEUE
|
||||
#define MEMP_NUM_ARP_QUEUE 4
|
||||
|
||||
#undef MEMP_NUM_NETBUF
|
||||
#define MEMP_NUM_NETBUF 12
|
||||
|
||||
#undef MEMP_NUM_NETCONN
|
||||
#define MEMP_NUM_NETCONN 32
|
||||
|
||||
#undef MEMP_NUM_PBUF
|
||||
#define MEMP_NUM_PBUF 0
|
||||
|
||||
#undef PBUF_POOL_SIZE
|
||||
#define PBUF_POOL_SIZE 0
|
||||
|
||||
#undef MEMP_NUM_RAW_PCB
|
||||
#define MEMP_NUM_RAW_PCB 8
|
||||
|
||||
#undef MEMP_NUM_REASSDATA
|
||||
#define MEMP_NUM_REASSDATA 12
|
||||
|
||||
#undef MEMP_NUM_TCPIP_MSG_API
|
||||
#define MEMP_NUM_TCPIP_MSG_API 32
|
||||
|
||||
#undef MEMP_NUM_TCPIP_MSG_INPKT
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT 32
|
||||
|
||||
#undef MEMP_NUM_TCP_PCB
|
||||
#define MEMP_NUM_TCP_PCB 8
|
||||
|
||||
#undef MEMP_NUM_TCP_PCB_LISTEN
|
||||
#define MEMP_NUM_TCP_PCB_LISTEN 4
|
||||
|
||||
#undef MEMP_NUM_TCP_SEG
|
||||
#define MEMP_NUM_TCP_SEG 64
|
||||
|
||||
#undef MEMP_NUM_UDP_PCB
|
||||
#define MEMP_NUM_UDP_PCB 4
|
||||
|
||||
#undef TCPIP_THREAD_STACKSIZE
|
||||
#define TCPIP_THREAD_STACKSIZE 0x1000
|
||||
|
||||
#undef LWIP_SOCKET_SELECT
|
||||
#define LWIP_SOCKET_SELECT 1
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#ifndef _LWIP_PORTING_NETDB_H_
|
||||
#define _LWIP_PORTING_NETDB_H_
|
||||
|
||||
#include "lwip/arch.h"
|
||||
#include <netdb.h>
|
||||
#include_next <lwip/netdb.h>
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#ifndef _LWIP_PORTING_NETIF_H_
|
||||
#define _LWIP_PORTING_NETIF_H_
|
||||
|
||||
#include "lwip/arch.h"
|
||||
#include <net/if.h>
|
||||
#include <netinet/ip.h>
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#ifndef _LWIP_PORTING_SOCKETS_H_
|
||||
#define _LWIP_PORTING_SOCKETS_H_
|
||||
|
||||
#include "lwip/arch.h"
|
||||
#include <sys/socket.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/tcp.h>
|
||||
@@ -42,6 +41,7 @@
|
||||
#include <limits.h>
|
||||
#include <fcntl.h>
|
||||
#include_next <lwip/sockets.h>
|
||||
#include <fatfs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -63,7 +63,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
// For BSD 4.4 socket sa_len compatibility
|
||||
#define DF_NADDR(addr) ip_addr_t naddr = (addr)
|
||||
#define DF_NADDR(addr)
|
||||
#define SA_LEN(addr, _) (IP_IS_V4_VAL(addr) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
|
||||
#define sa_len sa_data[0] * 0 + SA_LEN(naddr, _)
|
||||
#define sin_len sin_zero[0]
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
* 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.
|
||||
* 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.
|
||||
* 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.
|
||||
* 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,
|
||||
@@ -29,6 +29,18 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**********************************************************************************
|
||||
|
||||
* Notice of Export Control Law
|
||||
===============================================
|
||||
* Huawei LiteOS may be subject to applicable export control laws and regulations, which
|
||||
* might include those applicable to Huawei LiteOS of U.S. and the country in which you
|
||||
* are located.
|
||||
* Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance
|
||||
* with such applicable export control laws and regulations.
|
||||
***********************************************************************************/
|
||||
|
||||
|
||||
#define LWIP_STATIC static
|
||||
#define DHCP_STATE_OFF 0
|
||||
#define LWIP_EXT_POLL_SUPPORT 1
|
||||
@@ -41,7 +53,9 @@
|
||||
#include "lwip/icmp.h"
|
||||
#include "los_config.h"
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "shcmd.h"
|
||||
#include "shell.h"
|
||||
#include "los_debug.h"
|
||||
#include "los_task.h"
|
||||
|
||||
@@ -331,7 +345,7 @@ LWIP_STATIC int OsPingFunc(u32_t *parg)
|
||||
int ret = 0;
|
||||
u32_t intrvl;
|
||||
char *data_buf = NULL;
|
||||
BOOL timeout_flag = FALSE;
|
||||
BOOL timeout_flag = false;
|
||||
char buf[50];
|
||||
|
||||
u32_t destip = parg[0];
|
||||
@@ -396,14 +410,14 @@ LWIP_STATIC int OsPingFunc(u32_t *parg)
|
||||
do {
|
||||
pfd.events = POLLIN;
|
||||
pfd.revents = 0;
|
||||
timeout_flag = FALSE;
|
||||
ret = lwip_poll(&pfd, 1, LWIP_SHELL_CMD_PING_TIMEOUT);
|
||||
timeout_flag = false;
|
||||
ret = poll(&pfd, 1, LWIP_SHELL_CMD_PING_TIMEOUT);
|
||||
if (ret < 0) {
|
||||
perror("Ping: poll\n");
|
||||
goto FAILURE;
|
||||
} else if (ret == 0) {
|
||||
/* first type timeout event */
|
||||
timeout_flag = TRUE;
|
||||
timeout_flag = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -443,7 +457,7 @@ LWIP_STATIC int OsPingFunc(u32_t *parg)
|
||||
} while (timout_ms >= 0);
|
||||
|
||||
/* all timeout events are true timeout */
|
||||
if ((timout_ms < 0) || (timeout_flag == TRUE)) {
|
||||
if ((timout_ms < 0) || (timeout_flag == true)) {
|
||||
failed_cnt++;
|
||||
i++;
|
||||
PRINTK("\nPing: destination unreachable ...");
|
||||
@@ -586,7 +600,6 @@ u32_t OsShellPing(int argc, const char **argv)
|
||||
stPingTask.uwArg = (UINTPTR)parg;
|
||||
ret = LOS_TaskCreate((UINT32 *)(&ping_taskid), &stPingTask);
|
||||
if (ret != LOS_OK) {
|
||||
free(parg);
|
||||
PRINTK("ping_task create failed 0x%08x.\n", ret);
|
||||
count = LWIP_SHELL_CMD_PING_RETRY_TIMES;
|
||||
} else {
|
||||
@@ -602,6 +615,8 @@ u32_t OsShellPing(int argc, const char **argv)
|
||||
PRINTK("Ping cmd failed due some errors\n");
|
||||
}
|
||||
|
||||
free(parg);
|
||||
|
||||
return LOS_OK;
|
||||
ping_error:
|
||||
lwip_ping_usage();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user