add OpenHarmony 1.0 baseline
This commit is contained in:
parent
94f5f466b4
commit
6df931fc98
|
@ -0,0 +1,13 @@
|
|||
### 该问题是怎么引起的?
|
||||
|
||||
|
||||
|
||||
### 重现步骤
|
||||
|
||||
|
||||
|
||||
### 报错信息
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
### 相关的Issue
|
||||
|
||||
|
||||
### 原因(目的、解决的问题等)
|
||||
|
||||
|
||||
### 描述(做了什么,变更了什么)
|
||||
|
||||
|
||||
### 测试用例(新增、改动、可能影响的功能)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/out
|
||||
/fs/proc
|
||||
/test
|
||||
/include
|
||||
.config*
|
||||
cscope*
|
||||
tags
|
||||
.vscode
|
||||
*.o
|
||||
.idea
|
||||
*.img
|
||||
*.swp
|
||||
*.rej
|
||||
*.orig
|
||||
*.a
|
||||
*.so
|
||||
.config.cmd
|
||||
.settings
|
||||
.cproject
|
||||
.project
|
||||
platform/include/menuconfig.h
|
||||
platform/board.ld
|
||||
apps/init/init
|
||||
apps/shell/shell
|
||||
lib/libc/musl
|
|
@ -0,0 +1,68 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import("//build/lite/config/subsystem/lite_subsystem.gni")
|
||||
|
||||
declare_args() {
|
||||
enable_ohos_kernel_liteos_a_ext_build = true
|
||||
LOSCFG_TEST_APPS = false
|
||||
}
|
||||
|
||||
lite_subsystem("kernel") {
|
||||
subsystem_components = []
|
||||
|
||||
if (enable_ohos_kernel_liteos_a_ext_build == false) {
|
||||
subsystem_components += [
|
||||
"//kernel/liteos_a/kernel",
|
||||
"//kernel/liteos_a/net",
|
||||
"//kernel/liteos_a/lib",
|
||||
"//kernel/liteos_a/compat",
|
||||
"//kernel/liteos_a/fs",
|
||||
"//kernel/liteos_a/arch:platform_cpu",
|
||||
]
|
||||
if (LOSCFG_SHELL) {
|
||||
subsystem_components += [ "//kernel/liteos_a/shell" ]
|
||||
}
|
||||
} else {
|
||||
deps = [":make"]
|
||||
}
|
||||
}
|
||||
|
||||
action("make") {
|
||||
script = "//build/lite/build_ext_components.py"
|
||||
outputs = [ "$target_gen_dir/liteos_a_build_log.txt" ]
|
||||
exec_path = rebase_path(rebase_path(".", root_build_dir))
|
||||
outdir = rebase_path(get_path_info(".", "out_dir"))
|
||||
command = "make clean OUTDIR=$outdir && make rootfs VERSION=\"${ohos_version}\" -j 16 OUTDIR=$outdir"
|
||||
args = [
|
||||
"--path=$exec_path",
|
||||
"--prebuilts=sh build.sh ${board_name} ${ohos_build_compiler} ${ohos_build_type}",
|
||||
"--command=${command}"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,381 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see extra/config/Kconfig-language.txt
|
||||
#
|
||||
mainmenu "Huawei LiteOS Configuration"
|
||||
|
||||
menu "Compiler"
|
||||
choice
|
||||
prompt "LiteOS_Compiler_Type"
|
||||
default COMPILER_CLANG_LLVM
|
||||
help
|
||||
Enable arm-himix100 or aarch64-himix100 or compiler.
|
||||
|
||||
config COMPILER_HIMIX_32
|
||||
bool "arm-linux-ohoseabi"
|
||||
depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300
|
||||
|
||||
config COMPILER_CLANG_LLVM
|
||||
bool "clang-llvm"
|
||||
depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300
|
||||
|
||||
endchoice
|
||||
endmenu
|
||||
|
||||
menu "Platform"
|
||||
|
||||
######################### config options of bsp #####################
|
||||
source "../../kernel/liteos_a/platform/Kconfig"
|
||||
|
||||
######################### config options of cpu arch ################
|
||||
source "../../kernel/liteos_a/arch/Kconfig"
|
||||
|
||||
######################### config options of rootfs #####################
|
||||
source "../../kernel/liteos_a/kernel/common/Kconfig"
|
||||
endmenu
|
||||
|
||||
######################### config options of kernel #####################
|
||||
source "../../kernel/liteos_a/kernel/Kconfig"
|
||||
######################### config options of lib ########################
|
||||
source "../../kernel/liteos_a/lib/Kconfig"
|
||||
######################### config options of compatibility ##############
|
||||
menu "Compat"
|
||||
source "../../kernel/liteos_a/compat/posix/Kconfig"
|
||||
source "../../kernel/liteos_a/bsd/Kconfig"
|
||||
endmenu
|
||||
|
||||
######################### config options of framework ##################
|
||||
#source "../../frameworks/m2mcomm/Kconfig"
|
||||
|
||||
######################## config options of filesystem ##################
|
||||
menu "FileSystem"
|
||||
source "../../kernel/liteos_a/fs/vfs/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/fat/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/ramfs/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/nfs/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/proc/Kconfig"
|
||||
source "../../kernel/liteos_a/fs/jffs2/Kconfig"
|
||||
endmenu
|
||||
|
||||
######################## config options of net ############################
|
||||
source "../../kernel/liteos_a/net/Kconfig"
|
||||
|
||||
######################## config options of debug ########################
|
||||
menu "Debug"
|
||||
config COMPILE_DEBUG
|
||||
bool "Enable GCC -g Option"
|
||||
default n
|
||||
help
|
||||
Answer Y to add -g option in gcc command. But the LiteOS size will be much larger.
|
||||
|
||||
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
|
||||
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
|
||||
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 DEBUG_VERSION
|
||||
bool "Enable a Debug Version"
|
||||
default n
|
||||
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,ramfs proc and memory check.
|
||||
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 "../../kernel/liteos_a/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.
|
||||
source "../../kernel/liteos_a/net/telnet/Kconfig"
|
||||
config EXC_INTERACTION
|
||||
bool "Enable exc interaction"
|
||||
default n
|
||||
depends on SHELL
|
||||
help
|
||||
Answer Y to enable exception interaction for LiteOS, when the system enter exception, user can also interact with system by shell
|
||||
command like readreg, writereg,task,hwi.
|
||||
|
||||
config 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_MUL_MODULE
|
||||
bool "Enable Memory module statistics"
|
||||
default n
|
||||
depends on MEM_DEBUG
|
||||
help
|
||||
Answer Y to enable LiteOS support memory statistics depend on different module
|
||||
config MEM_MUL_POOL
|
||||
bool "Enable Memory multi-pool control"
|
||||
default y
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
help
|
||||
Answer Y to enable LiteOS support memory multi-pool control
|
||||
config MEM_HEAD_BACKUP
|
||||
bool "Enable Node Head Backup"
|
||||
default 0
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
help
|
||||
Answer Y to enable node head backup
|
||||
config MEM_RECORDINFO
|
||||
bool "Enable Mem Record"
|
||||
default n
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
help
|
||||
Answer Y to enable mem record
|
||||
config MEM_LEAKCHECK
|
||||
bool "Enable Function call stack of Mem operation recorded"
|
||||
default n
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
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 BASE_MEM_NODE_SIZE_CHECK
|
||||
bool "Enable size check or not"
|
||||
default n
|
||||
depends on DEBUG_VERSION && MEM_DEBUG
|
||||
config SLAB_INFO_STATISTIC
|
||||
bool "Enable SLAB Statistic"
|
||||
default n
|
||||
depends on DEBUG_VERSION && KERNEL_MEM_SLAB && 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.
|
||||
|
||||
config NULL_ADDRESS_PROTECT
|
||||
bool "Enable NULL Address protect"
|
||||
default n
|
||||
depends on (PLATFORM_HI3518EV200 || PLATFORM_HI3516CV300 || PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300) && DEBUG_VERSION
|
||||
help
|
||||
Answer Y to set mem address 0~1M prohibit to access, read or write will trigger exception.
|
||||
|
||||
choice
|
||||
prompt "Enable Uart"
|
||||
default DRIVERS_HDF_PLATFORM_UART
|
||||
help
|
||||
Enable simple uart (without vfs) only for litekernel.
|
||||
Enable general uart (with vfs) for full code.
|
||||
source "../../vendor/hisi/hi35xx/platform/uart/Kconfig"
|
||||
config PLATFORM_UART_WITHOUT_VFS
|
||||
bool "Simple Uart"
|
||||
config PLATFORM_NO_UART
|
||||
bool "NO Uart"
|
||||
|
||||
endchoice
|
||||
endmenu
|
||||
|
||||
######################## config options os drivers ########################
|
||||
menu "Driver"
|
||||
config DRIVERS
|
||||
bool "Enable Driver"
|
||||
default y
|
||||
help
|
||||
Answer Y to enable LiteOS support driver.
|
||||
|
||||
source "../../vendor/hisi/hi35xx/platform/hiedmac/Kconfig"
|
||||
source "../../kernel/liteos_a/bsd/dev/usb/Kconfig"
|
||||
source "../../drivers/hdf/lite/Kconfig"
|
||||
|
||||
config DRIVERS_NETDEV
|
||||
bool "Enable Net Device"
|
||||
default y
|
||||
depends on DRIVERS && NET_LWIP_SACK
|
||||
help
|
||||
Answer Y to enable LiteOS support net device.
|
||||
|
||||
choice
|
||||
depends on DRIVERS_NETDEV
|
||||
prompt "MAC"
|
||||
default n
|
||||
help
|
||||
Enable higmac for hi3516a hi3519 hi3559a_cortex-a53_aarch64.
|
||||
Enable hieth-sf for hi3516cv300 hi3516ev200 and hi3518ev200.
|
||||
source "../../vendor/hisi/hi35xx/platform/hieth-sf/Kconfig"
|
||||
endchoice
|
||||
|
||||
source "../../drivers/liteos/mem/Kconfig"
|
||||
source "../../vendor/hisi/hi35xx/platform/mmc/Kconfig"
|
||||
|
||||
|
||||
config DRIVERS_MTD
|
||||
bool "Enable MTD"
|
||||
default y
|
||||
depends on DRIVERS && FS_VFS
|
||||
help
|
||||
Answer Y to enable LiteOS support jffs2 multipartion.
|
||||
|
||||
source "../../vendor/hisi/hi35xx/platform/mtd/spi_nor/Kconfig"
|
||||
source "../../drivers/liteos/random/Kconfig"
|
||||
source "../../drivers/liteos/tzdriver/Kconfig"
|
||||
source "../../drivers/liteos/video/Kconfig"
|
||||
source "../../drivers/liteos/hievent/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
menu "Security"
|
||||
source "../../kernel/liteos_a/security/Kconfig"
|
||||
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
|
|
@ -0,0 +1,202 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
LITEOSTOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
|
||||
export OS=$(shell uname -s)
|
||||
ifneq ($(OS), Linux)
|
||||
LITEOSTOPDIR := $(shell dirname $(subst \,/,$(LITEOSTOPDIR))/./)
|
||||
endif
|
||||
|
||||
LITEOSTHIRDPARTY := $(LITEOSTOPDIR)/../../third_party
|
||||
|
||||
export LITEOSTOPDIR
|
||||
export LITEOSTHIRDPARTY
|
||||
|
||||
-include $(LITEOSTOPDIR)/tools/build/config.mk
|
||||
|
||||
RM = -rm -rf
|
||||
MAKE = make
|
||||
__LIBS = libs
|
||||
APPS = apps
|
||||
ROOTFSDIR = rootfsdir
|
||||
ROOTFS = rootfs
|
||||
|
||||
LITEOS_TARGET = liteos
|
||||
LITEOS_LIBS_TARGET = libs_target
|
||||
LITEOS_MENUCONFIG_H = $(LITEOSTOPDIR)/include/generated/autoconf.h
|
||||
LITEOS_PLATFORM_BASE = $(LITEOSTOPDIR)/platform
|
||||
LITEOS_PLATFORM_MENUCONFIG_H = $(LITEOS_PLATFORM_BASE)/include/menuconfig.h
|
||||
|
||||
ifeq ($(LOSCFG_PLATFORM_HI3518EV300), y)
|
||||
FSTYPE = jffs2
|
||||
endif
|
||||
ifeq ($(LOSCFG_PLATFORM_HI3516DV300), y)
|
||||
FSTYPE = vfat
|
||||
endif
|
||||
ROOTFS_DIR = $(OUT)/rootfs
|
||||
ROOTFS_ZIP = $(OUT)/rootfs.zip
|
||||
VERSION =
|
||||
|
||||
all: $(OUT) $(BUILD) $(LITEOS_TARGET) $(APPS)
|
||||
lib: $(OUT) $(BUILD) $(LITEOS_LIBS_TARGET)
|
||||
|
||||
help:
|
||||
$(HIDE)echo "-------------------------------------------------------"
|
||||
$(HIDE)echo "1.====make help: get help infomation of make"
|
||||
$(HIDE)echo "2.====make: make a debug version based the .config"
|
||||
$(HIDE)echo "3.====make debug: make a debug version based the .config"
|
||||
$(HIDE)echo "4.====make release: make a release version for all platform"
|
||||
$(HIDE)echo "5.====make release PLATFORM=xxx: make a release version only for platform xxx"
|
||||
$(HIDE)echo "6.====make rootfsdir: make a original rootfs dir"
|
||||
$(HIDE)echo "7.====make rootfs FSTYPE=***: make a original rootfs img"
|
||||
$(HIDE)echo "8.====make test: make the testsuits_app and put it into the rootfs dir"
|
||||
$(HIDE)echo "9.====make test_apps FSTYPE=***: make a rootfs img with the testsuits_app in it"
|
||||
$(HIDE)echo "xxx should be one of (hi3516cv300 hi3516ev200 hi3556av100/cortex-a53_aarch32 hi3559av100/cortex-a53_aarch64)"
|
||||
$(HIDE)echo "*** should be one of (jffs2)"
|
||||
$(HIDE)echo "-------------------------------------------------------"
|
||||
|
||||
debug:
|
||||
$(HIDE)echo "=============== make a debug version ==============="
|
||||
$(HIDE) $(MAKE) all
|
||||
|
||||
release:
|
||||
ifneq ($(PLATFORM),)
|
||||
$(HIDE)echo "=============== make a release version for platform $(PLATFORM) ==============="
|
||||
$(HIDE)$(SCRIPTS_PATH)/mklibversion.sh $(PLATFORM)
|
||||
else
|
||||
$(HIDE)echo "================make a release version for all platform ==============="
|
||||
$(HIDE)$(SCRIPTS_PATH)/mklibversion.sh
|
||||
endif
|
||||
|
||||
##### make dynload #####
|
||||
-include $(LITEOS_MK_PATH)/dynload.mk
|
||||
|
||||
#-----need move when make version-----#
|
||||
##### make lib #####
|
||||
$(__LIBS): $(OUT) $(CXX_INCLUDE)
|
||||
|
||||
$(OUT): $(LITEOS_MENUCONFIG_H)
|
||||
$(HIDE)mkdir -p $(OUT)/lib
|
||||
$(HIDE)$(CC) -I$(LITEOS_PLATFORM_BASE)/include -I$(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board \
|
||||
-E $(LITEOS_PLATFORM_BASE)/board.ld.S \
|
||||
-o $(LITEOS_PLATFORM_BASE)/board.ld -P
|
||||
|
||||
$(BUILD):
|
||||
$(HIDE)mkdir -p $(BUILD)
|
||||
|
||||
$(LITEOS_LIBS_TARGET): $(__LIBS)
|
||||
$(HIDE)for dir in $(LIB_SUBDIRS); \
|
||||
do $(MAKE) -C $$dir all || exit 1; \
|
||||
done
|
||||
$(HIDE)echo "=============== make lib done ==============="
|
||||
|
||||
##### make menuconfig #####
|
||||
export CONFIG_=LOSCFG_
|
||||
MENUCONFIG_PATH = $(LITEOSTOPDIR)/tools/menuconfig
|
||||
KCONFIG_FILE_PATH = $(LITEOSTOPDIR)/Kconfig
|
||||
|
||||
menuconfig:$(MENUCONFIG_PATH)/mconf
|
||||
$< $(KCONFIG_FILE_PATH)
|
||||
|
||||
genconfig:$(MENUCONFIG_PATH)/conf
|
||||
$(HIDE)mkdir -p include/config include/generated
|
||||
$< --silentoldconfig $(KCONFIG_FILE_PATH)
|
||||
-mv -f $(LITEOS_MENUCONFIG_H) $(LITEOS_PLATFORM_MENUCONFIG_H)
|
||||
##### menuconfig end #######
|
||||
|
||||
$(LITEOS_MENUCONFIG_H):
|
||||
ifneq ($(LITEOS_PLATFORM_MENUCONFIG_H), $(wildcard $(LITEOS_PLATFORM_MENUCONFIG_H)))
|
||||
$(HIDE)$(MAKE) genconfig
|
||||
endif
|
||||
$(LITEOS_TARGET): $(__LIBS)
|
||||
$(HIDE)touch $(LOSCFG_ENTRY_SRC)
|
||||
|
||||
$(HIDE)for dir in $(LITEOS_SUBDIRS); \
|
||||
do $(MAKE) -C $$dir all || exit 1; \
|
||||
done
|
||||
|
||||
$(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) $(LITEOS_DYNLDFLAGS) -Map=$(OUT)/$@.map -o $(OUT)/$@ --start-group $(LITEOS_LIBDEP) --end-group
|
||||
# $(SIZE) -t --common $(OUT)/lib/*.a >$(OUT)/$@.objsize
|
||||
$(OBJCOPY) -O binary $(OUT)/$@ $(LITEOS_TARGET_DIR)/$@.bin
|
||||
$(OBJDUMP) -t $(OUT)/$@ |sort >$(OUT)/$@.sym.sorted
|
||||
$(OBJDUMP) -d $(OUT)/$@ >$(OUT)/$@.asm
|
||||
# $(NM) -S --size-sort $(OUT)/$@ >$(OUT)/$@.size
|
||||
|
||||
$(APPS): $(LITEOS_TARGET)
|
||||
$(HIDE)$(MAKE) -C apps all
|
||||
|
||||
prepare:
|
||||
$(HIDE)mkdir -p $(OUT)/musl
|
||||
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
|
||||
$(HIDE)cp -f $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/usr/lib/$(LLVM_TARGET)/a7_softfp_neon-vfpv4/libc.so $(OUT)/musl
|
||||
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/lib/$(LLVM_TARGET)/c++/a7_softfp_neon-vfpv4/libc++.so $(OUT)/musl
|
||||
else
|
||||
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/target/usr/lib/libc.so $(OUT)/musl
|
||||
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libstdc++.so.6 $(OUT)/musl
|
||||
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libgcc_s.so.1 $(OUT)/musl
|
||||
$(STRIP) $(OUT)/musl/*
|
||||
endif
|
||||
|
||||
$(ROOTFSDIR): prepare $(APPS)
|
||||
$(HIDE)$(MAKE) clean -C apps
|
||||
$(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT)/bin $(OUT)/musl $(ROOTFS_DIR))
|
||||
ifneq ($(VERSION),)
|
||||
$(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR))
|
||||
endif
|
||||
|
||||
$(ROOTFS): $(ROOTFSDIR)
|
||||
$(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE))
|
||||
$(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS)
|
||||
ifneq ($(OUT), $(LITEOS_TARGET_DIR))
|
||||
$(HIDE)mv $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)rootfs
|
||||
endif
|
||||
|
||||
clean:
|
||||
$(HIDE)for dir in $(LITEOS_SUBDIRS); \
|
||||
do $(MAKE) -C $$dir clean|| exit 1; \
|
||||
done
|
||||
$(HIDE)$(MAKE) -C apps clean
|
||||
$(HIDE)$(RM) $(__OBJS) $(LITEOS_TARGET) $(OUT) $(BUILD) $(LITEOS_MENUCONFIG_H) *.bak *~
|
||||
$(HIDE)$(RM) $(LITEOS_PLATFORM_MENUCONFIG_H)
|
||||
$(HIDE)$(RM) include
|
||||
$(HIDE)$(MAKE) cleanrootfs
|
||||
$(HIDE)echo "clean $(LITEOS_PLATFORM) finish"
|
||||
|
||||
cleanall:
|
||||
$(HIDE)$(RM) $(LITEOSTOPDIR)/out
|
||||
$(HIDE)find $(LITEOS_PLATFORM_BASE)/ -name board.ld -exec rm -rf {} \;
|
||||
$(HIDE)cd sample/sample_osdrv;make clean;cd ../..;
|
||||
$(HIDE)echo "clean all"
|
||||
|
||||
cleanrootfs:
|
||||
$(HIDE)$(RM) $(OUT)/rootfs
|
||||
$(HIDE)$(RM) $(OUT)/rootfs.zip
|
||||
$(HIDE)$(RM) $(OUT)/rootfs.img
|
||||
|
||||
.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help
|
|
@ -0,0 +1,49 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include ../.config
|
||||
include ./module.mk
|
||||
|
||||
HIDE := @
|
||||
APPS := app
|
||||
|
||||
all: $(APPS)
|
||||
|
||||
# Make
|
||||
$(APPS):
|
||||
ifneq ($(APP_SUBDIRS), )
|
||||
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir ; done
|
||||
endif
|
||||
|
||||
clean:
|
||||
ifneq ($(APP_SUBDIRS), )
|
||||
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir clean; done
|
||||
endif
|
||||
|
||||
.PHONY: all $(APPS) clean
|
|
@ -0,0 +1,60 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# common dir config
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
# output dir config
|
||||
OBJOUT := $(APPSTOPDIR)/out
|
||||
APPSOUT := $(OBJOUT)/apps
|
||||
LIBSOUT := $(OBJOUT)/libs
|
||||
IMGOUT := $(OUT)
|
||||
|
||||
# common flags config
|
||||
BASE_OPTS := -ffunction-sections -fdata-sections -fno-omit-frame-pointer -D_GNU_SOURCE \
|
||||
$(LITEOS_SSP) $(LITEOS_CORE_COPTS) $(WARNING_AS_ERROR) $(LLVM_EXTRA_OPTS) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
CFLAGS := -std=c99 -fno-exceptions $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
|
||||
CXXFLAGS := -std=c++11 -fexceptions -fpermissive -frtti $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
|
||||
LDCFLAGS := -lc
|
||||
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
|
||||
LLVM_SYSROOT := --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
|
||||
LDCXXFLGS := -lc++ -lc++abi -lc
|
||||
else
|
||||
BASE_OPTS += -Wl,-z,relro,-z,now
|
||||
LDCXXFLGS := -lstdc++ -lsupc++ -lc
|
||||
endif
|
||||
COMMON_INCLUDE := -I $(LITEOSTHIRDPARTY)/bounds_checking_function/include
|
||||
|
||||
# alias variable config
|
||||
HIDE := @
|
||||
MAKE := make
|
||||
RM := -rm -rf
|
||||
CP := -cp -rf
|
||||
MV := -mv
|
|
@ -0,0 +1,63 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
INIT_DIR := $(dir $(shell pwd))/init/
|
||||
|
||||
ifeq ($(APPSTOPDIR), )
|
||||
APPSTOPDIR := $(shell pwd)/../
|
||||
LITEOSTOPDIR = $(APPSTOPDIR)/../
|
||||
endif
|
||||
include $(INIT_DIR)/../config.mk
|
||||
|
||||
APPS_OUT := $(OUT)/bin
|
||||
LOCAL_SRCS := src/init.c
|
||||
LOCAL_OBJ := src/init.o
|
||||
|
||||
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
|
||||
LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-bitwise-op-parentheses -Wnonnull $(LLVM_SYSROOT)
|
||||
LDCFLAGS += $(LLVM_EXTRA_LD_OPTS) $(LLVM_SYSROOT)
|
||||
endif
|
||||
INITNAME := init
|
||||
|
||||
all: $(INITNAME)
|
||||
|
||||
$(LOCAL_OBJ): %.o : %.c
|
||||
$(HIDE) $(CC) $(CFLAGS) $(LOCAL_FLAGS) -fPIE $(LOCAL_INCLUDE) -c $< -o $@
|
||||
|
||||
$(INITNAME):$(LOCAL_OBJ)
|
||||
$(HIDE) $(CC) -pie -s $(LDPATH) $(BASE_OPTS) -o $(INITNAME) $^ $(LDCFLAGS)
|
||||
$(HIDE) mkdir -p $(APPS_OUT)
|
||||
$(HIDE) $(MV) $(INITNAME) $(APPS_OUT)
|
||||
$(HIDE) $(RM) $(LOCAL_OBJ)
|
||||
|
||||
clean:
|
||||
$(HIDE) $(RM) $(LOCAL_OBJ)
|
||||
$(HIDE) $(RM) $(INITNAME)
|
||||
|
||||
.PHONY: all $(INITNAME) clean
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main(int argc, char * const *argv)
|
||||
{
|
||||
int ret;
|
||||
const char *shellPath = "/bin/shell";
|
||||
|
||||
ret = fork();
|
||||
if (ret < 0) {
|
||||
printf("Failed to fork for shell\n");
|
||||
} else if (ret == 0) {
|
||||
(void)execve(shellPath, NULL, NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
ret = waitpid(-1, 0, WNOHANG);
|
||||
if (ret == 0) {
|
||||
sleep(1);
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
APP_SUBDIRS :=
|
||||
|
||||
##compile modules config##
|
||||
|
||||
ifeq ($(LOSCFG_SHELL), y)
|
||||
APP_SUBDIRS += shell
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_USER_INIT_DEBUG), y)
|
||||
APP_SUBDIRS += init
|
||||
endif
|
|
@ -0,0 +1,78 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
SHELL_DIR := $(dir $(shell pwd))/shell/
|
||||
|
||||
ifeq ($(APPSTOPDIR), )
|
||||
APPSTOPDIR := $(shell pwd)/../
|
||||
LITEOSTOPDIR = $(APPSTOPDIR)/../
|
||||
endif
|
||||
include $(SHELL_DIR)/../config.mk
|
||||
APPS_OUT := $(OUT)/bin
|
||||
|
||||
SECUREC_INCLUDE := $(LITEOSTHIRDPARTY)/bounds_checking_function/include
|
||||
|
||||
LOCAL_SRCS = $(wildcard src/main.c)\
|
||||
$(wildcard src/shcmd.c)\
|
||||
$(wildcard src/shmsg.c)\
|
||||
$(wildcard src/shcmdparse.c)\
|
||||
$(wildcard builtin/cd.c)
|
||||
LOCAL_SRCS += $(wildcard $(LITEOSTHIRDPARTY)/bounds_checking_function/src/*.c)
|
||||
LOCAL_OBJ := $(LOCAL_SRCS:.c=.o)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(SHELL_DIR)/include/ \
|
||||
-I $(SECUREC_INCLUDE)\
|
||||
|
||||
LOCAL_FLAGS += $(CFLAGS)
|
||||
|
||||
LDPATH := -L$(SHELL_DIR)/
|
||||
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
|
||||
LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-bitwise-op-parentheses $(LLVM_SYSROOT)
|
||||
LDCFLAGS += $(LLVM_EXTRA_LD_OPTS) $(LLVM_SYSROOT)
|
||||
endif
|
||||
|
||||
SHELLNAME := shell
|
||||
|
||||
all: $(SHELLNAME)
|
||||
|
||||
$(LOCAL_OBJ): %.o : %.c
|
||||
$(HIDE) $(CC) $(LOCAL_FLAGS) -fPIE $(LOCAL_INCLUDE) -c $< -o $@
|
||||
|
||||
$(SHELLNAME): $(LOCAL_OBJ)
|
||||
$(HIDE) $(CC) -pie -s $(LDPATH) $(BASE_OPTS) -o $(SHELLNAME) $^ $(LDCFLAGS)
|
||||
$(HIDE) mkdir -p $(APPS_OUT)
|
||||
$(HIDE) $(MV) $(SHELLNAME) $(APPS_OUT)
|
||||
$(HIDE) $(RM) $(LOCAL_OBJ)
|
||||
|
||||
clean:
|
||||
$(HIDE) $(RM) $(LOCAL_OBJ)
|
||||
$(HIDE) $(RM) $(SHELLNAME)
|
||||
|
||||
.PHONY: all $(SHELLNAME) clean
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include "unistd.h"
|
||||
#include "shcmd.h"
|
||||
#include "sherr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
int Chdir(const char *tgtDir)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!tgtDir) {
|
||||
return SH_ERROR;
|
||||
}
|
||||
|
||||
ret = chdir(tgtDir);
|
||||
if (ret == 0) {
|
||||
ret = OsShellSetWorkingDirtectory(tgtDir, strlen(tgtDir) + 1); /* 1: the length of '\0' */
|
||||
if (ret != SH_NOK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SHCMD_H
|
||||
#define _SHCMD_H
|
||||
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "shell_list.h"
|
||||
#include "shcmdparse.h"
|
||||
#include "sherr.h"
|
||||
#include "show.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct {
|
||||
unsigned int count;
|
||||
SH_List list;
|
||||
char cmdString[0];
|
||||
} CmdKeyLink;
|
||||
|
||||
#define NEED_NEW_LINE(timesPrint, lineCap) ((timesPrint) % (lineCap) == 0)
|
||||
#define SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGNT))
|
||||
|
||||
extern unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr);
|
||||
extern unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size);
|
||||
extern int OsTabCompletion(char *cmdKey, unsigned int *len);
|
||||
extern void OsShellCmdPush(const char *string, CmdKeyLink *cmdKeyLink);
|
||||
extern void OsShellHistoryShow(unsigned int value, ShellCB *shellCB);
|
||||
extern unsigned int OsShellKeyInit(ShellCB *shellCB);
|
||||
extern void OsShellKeyDeInit(CmdKeyLink *cmdKeyLink);
|
||||
extern int OsShellSetWorkingDirtectory(const char *dir, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _SHCMD_H */
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SHCMDPARSE_H
|
||||
#define _SHCMDPARSE_H
|
||||
|
||||
#include "string.h"
|
||||
#include "show.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Description: the info struct after cmd parser
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int paramCnt; /* count of para */
|
||||
CmdType cmdType; /* cmd type, judge cmd keyword */
|
||||
char cmdKeyword[CMD_KEY_LEN]; /* cmd keyword str */
|
||||
char *paramArray[CMD_MAX_PARAS];
|
||||
} CmdParsed;
|
||||
|
||||
extern unsigned int OsCmdParse(char *cmdStr, CmdParsed *cmdParsed);
|
||||
extern char *OsCmdParseStrdup(const char *str);
|
||||
extern unsigned int OsCmdParseOneToken(CmdParsed *cmdParsed, unsigned int index, const char *token);
|
||||
extern unsigned int OsCmdTokenSplit(char *cmdStr, char split, CmdParsed *cmdParsed);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _SHCMDPARSE_H */
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SHELL_H
|
||||
#define _SHELL_H
|
||||
|
||||
#include "pthread.h"
|
||||
#include "semaphore.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Max len of show str */
|
||||
#define SHOW_MAX_LEN CMD_MAX_LEN
|
||||
|
||||
#define SHELL_PROCESS_PRIORITY_INIT 15
|
||||
|
||||
#define PATH_MAX 256
|
||||
#define CMD_MAX_PARAS 32
|
||||
#define CMD_KEY_LEN 16U
|
||||
#define CMD_MAX_LEN (256U + CMD_KEY_LEN)
|
||||
#define CMD_KEY_NUM 32
|
||||
#define CMD_HISTORY_LEN 10
|
||||
#define CMD_MAX_PATH 256
|
||||
#define DEFAULT_SCREEN_WIDTH 80
|
||||
#define DEFAULT_SCREEN_HEIGNT 24
|
||||
|
||||
#define SWITCH_QUOTES_STATUS(qu) do { \
|
||||
if ((qu) == TRUE) { \
|
||||
(qu) = FALSE; \
|
||||
} else { \
|
||||
(qu) = TRUE; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define QUOTES_STATUS_CLOSE(qu) ((qu) == FALSE)
|
||||
#define QUOTES_STATUS_OPEN(qu) ((qu) == TRUE)
|
||||
|
||||
typedef size_t bool;
|
||||
|
||||
typedef struct {
|
||||
unsigned int consoleID;
|
||||
pthread_t shellTaskHandle;
|
||||
pthread_t shellEntryHandle;
|
||||
void *cmdKeyLink;
|
||||
void *cmdHistoryKeyLink;
|
||||
void *cmdMaskKeyLink;
|
||||
unsigned int shellBufOffset;
|
||||
unsigned int shellKeyType;
|
||||
sem_t shellSem;
|
||||
pthread_mutex_t keyMutex;
|
||||
pthread_mutex_t historyMutex;
|
||||
char shellBuf[SHOW_MAX_LEN];
|
||||
char shellWorkingDirectory[PATH_MAX];
|
||||
} ShellCB;
|
||||
|
||||
/* All support cmd types */
|
||||
typedef enum {
|
||||
CMD_TYPE_SHOW = 0,
|
||||
CMD_TYPE_STD = 1,
|
||||
CMD_TYPE_EX = 2,
|
||||
CMD_TYPE_BUTT
|
||||
} CmdType;
|
||||
|
||||
typedef enum {
|
||||
CMD_KEY_UP = 0,
|
||||
CMD_KEY_DOWN = 1,
|
||||
CMD_KEY_RIGHT = 2,
|
||||
CMD_KEY_LEFT = 4,
|
||||
CMD_KEY_BUTT
|
||||
} CmdKeyDirection;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _SHELL_H */
|
|
@ -0,0 +1,595 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SHELL_LIST_H
|
||||
#define _SHELL_LIST_H
|
||||
|
||||
#include "sherr.h"
|
||||
#include "stdint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef size_t bool;
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* Structure of a node in a doubly linked list.
|
||||
*/
|
||||
typedef struct SH_List {
|
||||
struct SH_List *pstPrev; /**< Current node's pointer to the previous node */
|
||||
struct SH_List *pstNext; /**< Current node's pointer to the next node */
|
||||
} SH_List;
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Node in a doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
static inline void SH_ListInit(SH_List *list)
|
||||
{
|
||||
list->pstNext = list;
|
||||
list->pstPrev = list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Point to the next node pointed to by the current node.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to point to the next node pointed to by the current node.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param object [IN] Node in the doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define SH_LIST_FIRST(object) ((object)->pstNext)
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Point to the previous node pointed to by the current node.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to point to the previous node pointed to by the current node.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param object [IN] Node in the doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define SH_LIST_LAST(object) ((object)->pstPrev)
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Insert a new node to a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new node to a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list where the new node is inserted.
|
||||
* @param node [IN] New node to be inserted.
|
||||
*
|
||||
* @retval None
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see SH_ListDelete
|
||||
*/
|
||||
static inline void SH_ListAdd(SH_List *list, SH_List *node)
|
||||
{
|
||||
node->pstNext = list->pstNext;
|
||||
node->pstPrev = list;
|
||||
list->pstNext->pstPrev = node;
|
||||
list->pstNext = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Insert a node to the tail of a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new node to the tail of a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list where the new node is inserted.
|
||||
* @param node [IN] New node to be inserted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see SH_ListAdd | SH_ListHeadInsert
|
||||
*/
|
||||
static inline void SH_ListTailInsert(SH_List *list, SH_List *node)
|
||||
{
|
||||
if ((list == NULL) || (node == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SH_ListAdd(list->pstPrev, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Insert a node to the head of a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new node to the head of a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list where the new node is inserted.
|
||||
* @param node [IN] New node to be inserted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see SH_ListAdd | SH_ListTailInsert
|
||||
*/
|
||||
static inline void SH_ListHeadInsert(SH_List *list, SH_List *node)
|
||||
{
|
||||
if ((list == NULL) || (node == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SH_ListAdd(list, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to delete a specified node from a doubly linked list.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param node [IN] Node to be deleted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see SH_ListAdd
|
||||
*/
|
||||
static inline void SH_ListDelete(SH_List *node)
|
||||
{
|
||||
node->pstNext->pstPrev = node->pstPrev;
|
||||
node->pstPrev->pstNext = node->pstNext;
|
||||
node->pstNext = NULL;
|
||||
node->pstPrev = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Identify whether a specified doubly linked list is empty.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to return whether a doubly linked list is empty.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be a legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list.
|
||||
*
|
||||
* @retval TRUE The doubly linked list is empty.
|
||||
* @retval FALSE The doubly linked list is not empty.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
static inline bool SH_ListEmpty(SH_List *list)
|
||||
{
|
||||
if (list == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return (bool)(list->pstNext == list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Insert a new list to a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new list to a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param oldList [IN] Doubly linked list where the new list is inserted.
|
||||
* @param newList [IN] New list to be inserted.
|
||||
*
|
||||
* @retval None
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see SH_ListDelete
|
||||
*/
|
||||
static inline void SH_ListAddList(SH_List *oldList, SH_List *newList)
|
||||
{
|
||||
SH_List *oldListHead = oldList->pstNext;
|
||||
SH_List *oldListTail = oldList;
|
||||
SH_List *newListHead = newList;
|
||||
SH_List *newListTail = newList->pstPrev;
|
||||
|
||||
oldListTail->pstNext = newListHead;
|
||||
newListHead->pstPrev = oldListTail;
|
||||
oldListHead->pstPrev = newListTail;
|
||||
newListTail->pstNext = oldListHead;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Insert a doubly list to the tail of a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new doubly list to the tail of a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param oldList [IN] Doubly linked list where the new list is inserted.
|
||||
* @param newList [IN] New list to be inserted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see SH_ListAddList | SH_ListHeadInsertList
|
||||
*/
|
||||
static inline void SH_ListTailInsertList(SH_List *oldList, SH_List *newList)
|
||||
{
|
||||
SH_ListAddList(oldList->pstPrev, newList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Insert a doubly list to the head of a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to insert a new doubly list to the head of a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameters passed in should be ensured to be legal pointers.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param oldList [IN] Doubly linked list where the new list is inserted.
|
||||
* @param newList [IN] New list to be inserted.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see SH_ListAddList | SH_ListTailInsertList
|
||||
*/
|
||||
static inline void SH_ListHeadInsertList(SH_List *oldList, SH_List *newList)
|
||||
{
|
||||
SH_ListAddList(oldList, newList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Obtain the offset of a field to a structure address.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the offset of a field to a structure address.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param type [IN] Structure name.
|
||||
* @param field [IN] Name of the field of which the offset is to be measured.
|
||||
*
|
||||
* @retval Offset of the field to the structure address.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define OFFSET_OF_FIELD(type, field) ((uintptr_t)&((type *)0)->field)
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Obtain the pointer to a doubly linked list in a structure.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the pointer to a doubly linked list in a structure.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval Pointer to the doubly linked list in the structure.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define LOS_OFF_SET_OF(type, member) ((uintptr_t)&((type *)0)->member)
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Obtain the pointer to a structure that contains a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to obtain the pointer to a structure that contains a doubly linked list.
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Current node's pointer to the next node.
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval Pointer to the structure that contains the doubly linked list.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define SH_LIST_ENTRY(item, type, member) \
|
||||
((type *)(void *)((char *)(item) - LOS_OFF_SET_OF(type, member)))
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Iterate over a doubly linked list of given type.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list of given type.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define SH_LIST_FOR_EACH_ENTRY(item, list, type, member) \
|
||||
for (item = SH_LIST_ENTRY((list)->pstNext, type, member); \
|
||||
&(item)->member != (list); \
|
||||
item = SH_LIST_ENTRY((item)->member.pstNext, type, member))
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief iterate over a doubly linked list safe against removal of list entry.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list safe against removal of list entry.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param next [IN] Save the next node.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
* @param type [IN] Structure name.
|
||||
* @param member [IN] Member name of the doubly linked list in the structure.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define SH_LIST_FOR_EACH_ENTRY_SAFE(item, next, list, type, member) \
|
||||
for (item = SH_LIST_ENTRY((list)->pstNext, type, member), \
|
||||
next = SH_LIST_ENTRY((item)->member.pstNext, type, member); \
|
||||
&(item)->member != (list); \
|
||||
item = next, next = SH_LIST_ENTRY((item)->member.pstNext, type, member))
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Delete initialize a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete initialize a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The parameter passed in should be ensured to be s legal pointer.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Doubly linked list.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
static inline void SH_ListDelInit(SH_List *list)
|
||||
{
|
||||
list->pstNext->pstPrev = list->pstPrev;
|
||||
list->pstPrev->pstNext = list->pstNext;
|
||||
SH_ListInit(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief iterate over a doubly linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define SH_LIST_FOR_EACH(item, list) \
|
||||
for (item = (list)->pstNext; \
|
||||
(item) != (list); \
|
||||
item = (item)->pstNext)
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Iterate over a doubly linked list safe against removal of list entry.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to iterate over a doubly linked list safe against removal of list entry.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param item [IN] Pointer to the structure that contains the doubly linked list that is to be traversed.
|
||||
* @param next [IN] Save the next node.
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define SH_LIST_FOR_EACH_SAFE(item, next, list) \
|
||||
for (item = (list)->pstNext, next = (item)->pstNext; \
|
||||
(item) != (list); \
|
||||
item = next, next = (item)->pstNext)
|
||||
|
||||
/**
|
||||
* @ingroup shell_list
|
||||
* @brief Initialize a double linked list.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to initialize a double linked list.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param list [IN] Pointer to the doubly linked list to be traversed.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>shell_list.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
#define SH_LIST_HEAD(list) SH_List list = { &(list), &(list) }
|
||||
|
||||
#define SH_ListPeekHeadType(list, type, element) do { \
|
||||
type *__t; \
|
||||
if ((list)->pstNext == list) { \
|
||||
__t = NULL; \
|
||||
} else { \
|
||||
__t = SH_LIST_ENTRY((list)->pstNext, type, element); \
|
||||
} \
|
||||
__t; \
|
||||
} while (0)
|
||||
|
||||
#define SH_ListRemoveHeadType(list, type, element) do { \
|
||||
type *__t; \
|
||||
if ((list)->pstNext == list) { \
|
||||
__t = NULL; \
|
||||
} else { \
|
||||
__t = SH_LIST_ENTRY((list)->pstNext, type, element); \
|
||||
SH_ListDelete((list)->pstNext); \
|
||||
} \
|
||||
__t; \
|
||||
} while (0)
|
||||
|
||||
#define SH_ListNextType(list, item, type, element) do { \
|
||||
type *__t; \
|
||||
if ((item)->pstNext == list) { \
|
||||
__t = NULL; \
|
||||
} else { \
|
||||
__t = SH_LIST_ENTRY((item)->pstNext, type, element); \
|
||||
} \
|
||||
__t; \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _SHELL_LIST_H */
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SHELL_PRI_H
|
||||
#define _SHELL_PRI_H
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "bits/alltypes.h"
|
||||
#include "shcmd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern void *ShellEntry(void *argv);
|
||||
extern void *ShellTask(void *argv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _SHELL_PRI_H */
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SHERR_H
|
||||
#define _SHERR_H
|
||||
|
||||
#include "sys/types.h"
|
||||
#include "bits/alltypes.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define SH_ERROR -1
|
||||
#define SH_OK 0
|
||||
#define SH_NOK -1
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
# define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _SHERR_H */
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SHMSG_H
|
||||
#define _SHMSG_H
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define SHELL_ENTRY_STACKSIZE 0x1000
|
||||
#define SHELL_TASK_STACKSIZE 0x3000
|
||||
|
||||
#define SHELL_EXEC_COMMAND "exec "
|
||||
#define SHELL_EXEC_COMMAND_BYTES 5
|
||||
|
||||
#define CONSOLE_IOC_MAGIC 'c'
|
||||
#define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7)
|
||||
|
||||
#define COLOR_NONE "\e[0m"
|
||||
#define COLOR_RED "\e[0;31m"
|
||||
#define COLOR_L_RED "\e[1;31m"
|
||||
#define SHELL_PROMPT COLOR_L_RED"OHOS # "COLOR_NONE
|
||||
|
||||
typedef void (*OutputFunc)(const char *fmt, ...);
|
||||
extern int ShellTaskInit(ShellCB *shellCB);
|
||||
extern int ShellEntryInit(ShellCB *shellCB);
|
||||
extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB);
|
||||
extern int ShellNotify(ShellCB *shellCB);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _SHMSG_H */
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SHOW_H
|
||||
#define _SHOW_H
|
||||
|
||||
#include "stdarg.h"
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern char *OsShellGetWorkingDirtectory();
|
||||
extern unsigned int OsShellInit();
|
||||
extern int OsShellDeinit(ShellCB *shellCB);
|
||||
extern ShellCB *OsGetShellCb();
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _SHOW_H */
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "show.h"
|
||||
#include "shmsg.h"
|
||||
#include "shcmd.h"
|
||||
#include "semaphore.h"
|
||||
#include "securec.h"
|
||||
#include "unistd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
ShellCB *g_shellCB = NULL;
|
||||
|
||||
ShellCB *OsGetShellCb()
|
||||
{
|
||||
return g_shellCB;
|
||||
}
|
||||
|
||||
void ShellDeinit(ShellCB *shellCB)
|
||||
{
|
||||
(void)pthread_mutex_destroy(&shellCB->historyMutex);
|
||||
(void)pthread_mutex_destroy(&shellCB->keyMutex);
|
||||
OsShellKeyDeInit((CmdKeyLink *)shellCB->cmdKeyLink);
|
||||
OsShellKeyDeInit((CmdKeyLink *)shellCB->cmdHistoryKeyLink);
|
||||
(void)free(shellCB);
|
||||
}
|
||||
|
||||
static int OsShellCreateTask(ShellCB *shellCB)
|
||||
{
|
||||
struct sched_param param = { 0 };
|
||||
int ret;
|
||||
|
||||
ret = sched_getparam(getpid(), ¶m);
|
||||
if (ret != SH_OK) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
param.sched_priority = SHELL_PROCESS_PRIORITY_INIT;
|
||||
|
||||
ret = sched_setparam(getpid(), ¶m);
|
||||
if (ret != SH_OK) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
ret = ShellTaskInit(shellCB);
|
||||
if (ret != SH_OK) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
ret = ShellEntryInit(shellCB);
|
||||
if (ret != SH_OK) {
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
(void)pthread_join(shellCB->shellTaskHandle, NULL);
|
||||
(void)pthread_join(shellCB->shellEntryHandle, NULL);
|
||||
|
||||
OUT:
|
||||
ShellDeinit(shellCB);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int ret = SH_NOK;
|
||||
ShellCB *shellCB = NULL;
|
||||
|
||||
shellCB = (ShellCB *)malloc(sizeof(ShellCB));
|
||||
if (shellCB == NULL) {
|
||||
goto ERR_OUT1;
|
||||
}
|
||||
ret = memset_s(shellCB, sizeof(ShellCB), 0, sizeof(ShellCB));
|
||||
if (ret != SH_OK) {
|
||||
goto ERR_OUT1;
|
||||
}
|
||||
|
||||
ret = pthread_mutex_init(&shellCB->keyMutex, NULL);
|
||||
if (ret != SH_OK) {
|
||||
goto ERR_OUT1;
|
||||
}
|
||||
|
||||
ret = pthread_mutex_init(&shellCB->historyMutex, NULL);
|
||||
if (ret != SH_OK) {
|
||||
goto ERR_OUT2;
|
||||
}
|
||||
|
||||
ret = (int)OsShellKeyInit(shellCB);
|
||||
if (ret != SH_OK) {
|
||||
goto ERR_OUT3;
|
||||
}
|
||||
(void)strncpy_s(shellCB->shellWorkingDirectory, PATH_MAX, "/", 2); /* 2:space for "/" */
|
||||
|
||||
sem_init(&shellCB->shellSem, 0, 0);
|
||||
|
||||
g_shellCB = shellCB;
|
||||
return OsShellCreateTask(shellCB);
|
||||
|
||||
ERR_OUT3:
|
||||
(void)pthread_mutex_destroy(&shellCB->historyMutex);
|
||||
ERR_OUT2:
|
||||
(void)pthread_mutex_destroy(&shellCB->keyMutex);
|
||||
ERR_OUT1:
|
||||
(void)free(shellCB);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,611 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "shcmd.h"
|
||||
#include "show.h"
|
||||
#include "stdlib.h"
|
||||
#include "unistd.h"
|
||||
#include "dirent.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define SHELL_INIT_MAGIC_FLAG 0xABABABAB
|
||||
#define CTRL_C 0x03 /* 0x03: ctrl+c ASCII */
|
||||
|
||||
static void OsFreeCmdPara(CmdParsed *cmdParsed)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < cmdParsed->paramCnt; i++) {
|
||||
if ((cmdParsed->paramArray[i]) != NULL) {
|
||||
free((cmdParsed->paramArray[i]));
|
||||
cmdParsed->paramArray[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int OsStrSeparateTabStrGet(const char **tabStr, CmdParsed *parsed, unsigned int tabStrLen)
|
||||
{
|
||||
char *shiftStr = NULL;
|
||||
char *tempStr = (char *)malloc(SHOW_MAX_LEN << 1);
|
||||
if (tempStr == NULL) {
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
(void)memset_s(tempStr, SHOW_MAX_LEN << 1, 0, SHOW_MAX_LEN << 1);
|
||||
shiftStr = tempStr + SHOW_MAX_LEN;
|
||||
|
||||
if (strncpy_s(tempStr, SHOW_MAX_LEN - 1, *tabStr, tabStrLen)) {
|
||||
free(tempStr);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
parsed->cmdType = CMD_TYPE_STD;
|
||||
|
||||
/* cut useless or repeat space */
|
||||
if (OsCmdKeyShift(tempStr, shiftStr, SHOW_MAX_LEN - 1)) {
|
||||
free(tempStr);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
/* get exact position of string to complete */
|
||||
/* situation different if end space lost or still exist */
|
||||
if ((strlen(shiftStr) == 0) || (tempStr[strlen(tempStr) - 1] != shiftStr[strlen(shiftStr) - 1])) {
|
||||
*tabStr = "";
|
||||
} else {
|
||||
if (OsCmdTokenSplit(shiftStr, ' ', parsed)) {
|
||||
free(tempStr);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
*tabStr = parsed->paramArray[parsed->paramCnt - 1];
|
||||
}
|
||||
|
||||
free(tempStr);
|
||||
return SH_OK;
|
||||
}
|
||||
|
||||
char *OsShellGetWorkingDirtectory()
|
||||
{
|
||||
return OsGetShellCb()->shellWorkingDirectory;
|
||||
}
|
||||
|
||||
int OsShellSetWorkingDirtectory(const char *dir, size_t len)
|
||||
{
|
||||
if (dir == NULL) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
int ret = strncpy_s(OsGetShellCb()->shellWorkingDirectory, sizeof(OsGetShellCb()->shellWorkingDirectory),
|
||||
dir, len);
|
||||
if (ret != SH_OK) {
|
||||
return SH_NOK;
|
||||
}
|
||||
return SH_OK;
|
||||
}
|
||||
|
||||
static int OsStrSeparate(const char *tabStr, char *strPath, char *nameLooking, unsigned int tabStrLen)
|
||||
{
|
||||
char *strEnd = NULL;
|
||||
char *cutPos = NULL;
|
||||
CmdParsed parsed = {0};
|
||||
char *shellWorkingDirectory = OsShellGetWorkingDirtectory();
|
||||
int ret;
|
||||
|
||||
ret = OsStrSeparateTabStrGet(&tabStr, &parsed, tabStrLen);
|
||||
if (ret != SH_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* get fullpath str */
|
||||
if (*tabStr != '/') {
|
||||
if (strncpy_s(strPath, CMD_MAX_PATH, shellWorkingDirectory, CMD_MAX_PATH - 1)) {
|
||||
OsFreeCmdPara(&parsed);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
if (strcmp(shellWorkingDirectory, "/")) {
|
||||
if (strncat_s(strPath, CMD_MAX_PATH - 1, "/", CMD_MAX_PATH - strlen(strPath) - 1)) {
|
||||
OsFreeCmdPara(&parsed);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strncat_s(strPath, CMD_MAX_PATH - 1, tabStr, CMD_MAX_PATH - strlen(strPath) - 1)) {
|
||||
OsFreeCmdPara(&parsed);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
/* split str by last '/' */
|
||||
strEnd = strrchr(strPath, '/');
|
||||
if (strEnd != NULL) {
|
||||
if (strncpy_s(nameLooking, CMD_MAX_PATH, strEnd + 1, CMD_MAX_PATH - 1)) { /* get cmp str */
|
||||
OsFreeCmdPara(&parsed);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
cutPos = strrchr(strPath, '/');
|
||||
if (cutPos != NULL) {
|
||||
*(cutPos + 1) = '\0';
|
||||
}
|
||||
|
||||
OsFreeCmdPara(&parsed);
|
||||
return SH_OK;
|
||||
}
|
||||
|
||||
static int OsShowPageInputControl(void)
|
||||
{
|
||||
char readChar;
|
||||
|
||||
while (1) {
|
||||
if (read(STDIN_FILENO, &readChar, 1) != 1) { /* get one char from stdin */
|
||||
printf("\n");
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
if ((readChar == 'q') || (readChar == 'Q') || (readChar == CTRL_C)) {
|
||||
printf("\n");
|
||||
return 0;
|
||||
} else if (readChar == '\r') {
|
||||
printf("\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int OsShowPageControl(unsigned int timesPrint, unsigned int lineCap, unsigned int count)
|
||||
{
|
||||
if (NEED_NEW_LINE(timesPrint, lineCap)) {
|
||||
printf("\n");
|
||||
if (SCREEN_IS_FULL(timesPrint, lineCap) && (timesPrint < count)) {
|
||||
printf("--More--");
|
||||
return OsShowPageInputControl();
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int OsSurePrintAll(unsigned int count)
|
||||
{
|
||||
char readChar = 0;
|
||||
printf("\nDisplay all %u possibilities?(y/n)", count);
|
||||
while (1) {
|
||||
if (read(0, &readChar, 1) != 1) {
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
if ((readChar == 'n') || (readChar == 'N') || (readChar == CTRL_C)) {
|
||||
printf("\n");
|
||||
return 0;
|
||||
} else if ((readChar == 'y') || (readChar == 'Y') || (readChar == '\r')) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int OsPrintMatchList(unsigned int count, const char *strPath, const char *nameLooking, unsigned int printLen)
|
||||
{
|
||||
unsigned int timesPrint = 0;
|
||||
unsigned int lineCap;
|
||||
int ret;
|
||||
DIR *openDir = NULL;
|
||||
struct dirent *readDir = NULL;
|
||||
char formatChar[10] = {0}; /* 10:for formatChar length */
|
||||
|
||||
printLen = (printLen > (DEFAULT_SCREEN_WIDTH - 2)) ? (DEFAULT_SCREEN_WIDTH - 2) : printLen; /* 2:revered 2 bytes */
|
||||
lineCap = DEFAULT_SCREEN_WIDTH / (printLen + 2); /* 2:DEFAULT_SCREEN_WIDTH revered 2 bytes */
|
||||
if (snprintf_s(formatChar, sizeof(formatChar) - 1, 7, "%%-%us ", printLen) < 0) { /* 7:format-len */
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
if (count > (lineCap * DEFAULT_SCREEN_HEIGNT)) {
|
||||
ret = OsSurePrintAll(count);
|
||||
if (ret != 1) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
openDir = opendir(strPath);
|
||||
if (openDir == NULL) {
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
for (readDir = readdir(openDir); readDir != NULL; readDir = readdir(openDir)) {
|
||||
if (strncmp(nameLooking, readDir->d_name, strlen(nameLooking)) != 0) {
|
||||
continue;
|
||||
}
|
||||
printf(formatChar, readDir->d_name);
|
||||
timesPrint++;
|
||||
ret = OsShowPageControl(timesPrint, lineCap, count);
|
||||
if (ret != 1) {
|
||||
if (closedir(openDir) < 0) {
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
if (closedir(openDir) < 0) {
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
return SH_OK;
|
||||
}
|
||||
|
||||
static void StrncmpCut(const char *s1, char *s2, size_t n)
|
||||
{
|
||||
if ((n == 0) || (s1 == NULL) || (s2 == NULL)) {
|
||||
return;
|
||||
}
|
||||
do {
|
||||
if (*s1 && *s2 && (*s1 == *s2)) {
|
||||
s1++;
|
||||
s2++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (--n != 0);
|
||||
if (n > 0) {
|
||||
/* NULL pad the remaining n-1 bytes */
|
||||
while (n-- != 0) {
|
||||
*s2++ = 0;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void OsCompleteStr(char *result, const char *target, char *cmdKey, unsigned int *len)
|
||||
{
|
||||
unsigned int size = strlen(result) - strlen(target);
|
||||
char *des = cmdKey + *len;
|
||||
char *src = result + strlen(target);
|
||||
|
||||
while (size-- > 0) {
|
||||
printf("%c", *src);
|
||||
if (*len == (SHOW_MAX_LEN - 1)) {
|
||||
*des = '\0';
|
||||
break;
|
||||
}
|
||||
*des++ = *src++;
|
||||
(*len)++;
|
||||
}
|
||||
}
|
||||
|
||||
static int OsExecNameMatch(const char *strPath, const char *nameLooking, char *strObj, unsigned int *maxLen)
|
||||
{
|
||||
int count = 0;
|
||||
DIR *openDir = NULL;
|
||||
struct dirent *readDir = NULL;
|
||||
|
||||
openDir = opendir(strPath);
|
||||
if (openDir == NULL) {
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
for (readDir = readdir(openDir); readDir != NULL; readDir = readdir(openDir)) {
|
||||
if (strncmp(nameLooking, readDir->d_name, strlen(nameLooking)) != 0) {
|
||||
continue;
|
||||
}
|
||||
if (count == 0) {
|
||||
if (strncpy_s(strObj, CMD_MAX_PATH, readDir->d_name, CMD_MAX_PATH - 1)) {
|
||||
(void)closedir(openDir);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
*maxLen = strlen(readDir->d_name);
|
||||
} else {
|
||||
/* strncmp&cut the same strings of name matched */
|
||||
StrncmpCut(readDir->d_name, strObj, strlen(strObj));
|
||||
if (strlen(readDir->d_name) > *maxLen) {
|
||||
*maxLen = strlen(readDir->d_name);
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
if (closedir(openDir) < 0) {
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int OsTabMatchFile(char *cmdKey, unsigned int *len)
|
||||
{
|
||||
unsigned int maxLen = 0;
|
||||
int count;
|
||||
char *strOutput = NULL;
|
||||
char *strCmp = NULL;
|
||||
char *dirOpen = (char *)malloc(CMD_MAX_PATH * 3); /* 3:dirOpen\strOutput\strCmp */
|
||||
if (dirOpen == NULL) {
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
(void)memset_s(dirOpen, CMD_MAX_PATH * 3, 0, CMD_MAX_PATH * 3); /* 3:dirOpen\strOutput\strCmp */
|
||||
strOutput = dirOpen + CMD_MAX_PATH;
|
||||
strCmp = strOutput + CMD_MAX_PATH;
|
||||
|
||||
if (OsStrSeparate(cmdKey, dirOpen, strCmp, *len)) {
|
||||
free(dirOpen);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
count = OsExecNameMatch(dirOpen, strCmp, strOutput, &maxLen);
|
||||
/* one or more matched */
|
||||
if (count >= 1) {
|
||||
OsCompleteStr(strOutput, strCmp, cmdKey, len);
|
||||
|
||||
if (count == 1) {
|
||||
free(dirOpen);
|
||||
return 1;
|
||||
}
|
||||
if (OsPrintMatchList((unsigned int)count, dirOpen, strCmp, maxLen) == -1) {
|
||||
free(dirOpen);
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
free(dirOpen);
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* Description: Pass in the string and clear useless space ,which inlcude:
|
||||
* 1) The overmatch space which is not be marked by Quote's area
|
||||
* Squeeze the overmatch space into one space
|
||||
* 2) Clear all space before first vaild charatctor
|
||||
* Input: cmdKey : Pass in the buff string, which is ready to be operated
|
||||
* cmdOut : Pass out the buffer string ,which has already been operated
|
||||
* size : cmdKey length
|
||||
*/
|
||||
unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size)
|
||||
{
|
||||
char *output = NULL;
|
||||
char *outputBak = NULL;
|
||||
unsigned int len;
|
||||
int ret;
|
||||
bool quotes = FALSE;
|
||||
|
||||
if ((cmdKey == NULL) || (cmdOut == NULL)) {
|
||||
return (unsigned int)SH_ERROR;
|
||||
}
|
||||
|
||||
len = strlen(cmdKey);
|
||||
if ((*cmdKey == '\n') || (len >= size)) {
|
||||
return (unsigned int)SH_ERROR;
|
||||
}
|
||||
output = (char *)malloc(len + 1);
|
||||
if (output == NULL) {
|
||||
printf("malloc failure in %s[%d]", __FUNCTION__, __LINE__);
|
||||
return (unsigned int)SH_ERROR;
|
||||
}
|
||||
|
||||
/* Backup the 'output' start address */
|
||||
outputBak = output;
|
||||
/* Scan each charactor in 'cmdKey',and squeeze the overmuch space and ignore invaild charactor */
|
||||
for (; *cmdKey != '\0'; cmdKey++) {
|
||||
/* Detected a Double Quotes, switch the matching status */
|
||||
if (*(cmdKey) == '\"') {
|
||||
SWITCH_QUOTES_STATUS(quotes);
|
||||
}
|
||||
/* Ignore the current charactor in following situation */
|
||||
/* 1) Quotes matching status is FALSE (which said that the space is not been marked by double quotes) */
|
||||
/* 2) Current charactor is a space */
|
||||
/* 3) Next charactor is a space too, or the string is been seeked to the end already(\0) */
|
||||
/* 4) Invaild charactor, such as single quotes */
|
||||
if ((*cmdKey == ' ') && ((*(cmdKey + 1) == ' ') || (*(cmdKey + 1) == '\0')) && QUOTES_STATUS_CLOSE(quotes)) {
|
||||
continue;
|
||||
}
|
||||
if (*cmdKey == '\'') {
|
||||
continue;
|
||||
}
|
||||
*output = *cmdKey;
|
||||
output++;
|
||||
}
|
||||
*output = '\0';
|
||||
/* Restore the 'output' start address */
|
||||
output = outputBak;
|
||||
len = strlen(output);
|
||||
/* Clear the space which is located at the first charactor in buffer */
|
||||
if (*output == ' ') {
|
||||
output++;
|
||||
len--;
|
||||
}
|
||||
/* Copy out the buffer which is been operated already */
|
||||
ret = strncpy_s(cmdOut, size, output, len);
|
||||
if (ret != SH_OK) {
|
||||
printf("%s,%d strncpy_s failed, err:%d!\n", __FUNCTION__, __LINE__, ret);
|
||||
free(outputBak);
|
||||
return SH_ERROR;
|
||||
}
|
||||
cmdOut[len] = '\0';
|
||||
|
||||
free(outputBak);
|
||||
return SH_OK;
|
||||
}
|
||||
int OsTabCompletion(char *cmdKey, unsigned int *len)
|
||||
{
|
||||
int count;
|
||||
char *cmdMainStr = cmdKey;
|
||||
|
||||
if ((cmdKey == NULL) || (len == NULL)) {
|
||||
return (int)SH_ERROR;
|
||||
}
|
||||
|
||||
/* cut left space */
|
||||
while (*cmdMainStr == 0x20) {
|
||||
cmdMainStr++;
|
||||
}
|
||||
|
||||
count = OsTabMatchFile(cmdKey, len);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
unsigned int OsShellKeyInit(ShellCB *shellCB)
|
||||
{
|
||||
CmdKeyLink *cmdKeyLink = NULL;
|
||||
CmdKeyLink *cmdHistoryLink = NULL;
|
||||
|
||||
if (shellCB == NULL) {
|
||||
return SH_ERROR;
|
||||
}
|
||||
|
||||
cmdKeyLink = (CmdKeyLink *)malloc(sizeof(CmdKeyLink));
|
||||
if (cmdKeyLink == NULL) {
|
||||
printf("Shell CmdKeyLink memory alloc error!\n");
|
||||
return SH_ERROR;
|
||||
}
|
||||
cmdHistoryLink = (CmdKeyLink *)malloc(sizeof(CmdKeyLink));
|
||||
if (cmdHistoryLink == NULL) {
|
||||
free(cmdKeyLink);
|
||||
printf("Shell CmdHistoryLink memory alloc error!\n");
|
||||
return SH_ERROR;
|
||||
}
|
||||
|
||||
cmdKeyLink->count = 0;
|
||||
SH_ListInit(&(cmdKeyLink->list));
|
||||
shellCB->cmdKeyLink = (void *)cmdKeyLink;
|
||||
|
||||
cmdHistoryLink->count = 0;
|
||||
SH_ListInit(&(cmdHistoryLink->list));
|
||||
shellCB->cmdHistoryKeyLink = (void *)cmdHistoryLink;
|
||||
shellCB->cmdMaskKeyLink = (void *)cmdHistoryLink;
|
||||
return SH_OK;
|
||||
}
|
||||
|
||||
void OsShellKeyDeInit(CmdKeyLink *cmdKeyLink)
|
||||
{
|
||||
CmdKeyLink *cmdtmp = NULL;
|
||||
if (cmdKeyLink == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (!SH_ListEmpty(&(cmdKeyLink->list))) {
|
||||
cmdtmp = SH_LIST_ENTRY(cmdKeyLink->list.pstNext, CmdKeyLink, list);
|
||||
SH_ListDelete(&cmdtmp->list);
|
||||
free(cmdtmp);
|
||||
}
|
||||
|
||||
cmdKeyLink->count = 0;
|
||||
free(cmdKeyLink);
|
||||
}
|
||||
|
||||
void OsShellCmdPush(const char *string, CmdKeyLink *cmdKeyLink)
|
||||
{
|
||||
CmdKeyLink *cmdNewNode = NULL;
|
||||
unsigned int len;
|
||||
|
||||
if ((string == NULL) || (strlen(string) == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
len = strlen(string);
|
||||
cmdNewNode = (CmdKeyLink *)malloc(sizeof(CmdKeyLink) + len + 1);
|
||||
if (cmdNewNode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
(void)memset_s(cmdNewNode, sizeof(CmdKeyLink) + len + 1, 0, sizeof(CmdKeyLink) + len + 1);
|
||||
if (strncpy_s(cmdNewNode->cmdString, len + 1, string, len)) {
|
||||
free(cmdNewNode);
|
||||
return;
|
||||
}
|
||||
|
||||
SH_ListTailInsert(&(cmdKeyLink->list), &(cmdNewNode->list));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void OsShellHistoryShow(unsigned int value, ShellCB *shellCB)
|
||||
{
|
||||
CmdKeyLink *cmdtmp = NULL;
|
||||
CmdKeyLink *cmdNode = shellCB->cmdHistoryKeyLink;
|
||||
CmdKeyLink *cmdMask = shellCB->cmdMaskKeyLink;
|
||||
int ret;
|
||||
|
||||
(void)pthread_mutex_lock(&shellCB->historyMutex);
|
||||
if (value == CMD_KEY_DOWN) {
|
||||
if (cmdMask == cmdNode) {
|
||||
goto END;
|
||||
}
|
||||
|
||||
cmdtmp = SH_LIST_ENTRY(cmdMask->list.pstNext, CmdKeyLink, list);
|
||||
if (cmdtmp != cmdNode) {
|
||||
cmdMask = cmdtmp;
|
||||
} else {
|
||||
goto END;
|
||||
}
|
||||
} else if (value == CMD_KEY_UP) {
|
||||
cmdtmp = SH_LIST_ENTRY(cmdMask->list.pstPrev, CmdKeyLink, list);
|
||||
if (cmdtmp != cmdNode) {
|
||||
cmdMask = cmdtmp;
|
||||
} else {
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
while (shellCB->shellBufOffset--) {
|
||||
printf("\b \b");
|
||||
}
|
||||
printf("%s", cmdMask->cmdString);
|
||||
shellCB->shellBufOffset = strlen(cmdMask->cmdString);
|
||||
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
|
||||
ret = memcpy_s(shellCB->shellBuf, SHOW_MAX_LEN, cmdMask->cmdString, shellCB->shellBufOffset);
|
||||
if (ret != SH_OK) {
|
||||
printf("%s, %d memcpy failed!\n", __FUNCTION__, __LINE__);
|
||||
goto END;
|
||||
}
|
||||
shellCB->cmdMaskKeyLink = (void *)cmdMask;
|
||||
|
||||
END:
|
||||
(void)pthread_mutex_unlock(&shellCB->historyMutex);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr)
|
||||
{
|
||||
/* TODO: complete the usrspace command */
|
||||
unsigned int ret = SH_OK;
|
||||
if (cmdParsed && cmdStr) {
|
||||
ret = SH_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "shcmd.h"
|
||||
#include "sherr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* Filter out double quote or single-quoted strings at both ends
|
||||
*/
|
||||
char *OsCmdParseStrdup(const char *str)
|
||||
{
|
||||
char *tempStr = NULL;
|
||||
char *newStr = NULL;
|
||||
|
||||
newStr = (char *)malloc(strlen(str) + 1);
|
||||
if (newStr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tempStr = newStr;
|
||||
for (; *str != '\0'; str++) {
|
||||
if ((*str == '\"') || (*str == '\'')) {
|
||||
continue;
|
||||
}
|
||||
*newStr = *str;
|
||||
newStr++;
|
||||
}
|
||||
*newStr = '\0';
|
||||
return tempStr;
|
||||
}
|
||||
|
||||
unsigned int OsCmdParseParaGet(char **value, const char *paraTokenStr)
|
||||
{
|
||||
if ((paraTokenStr == NULL) || (value == NULL)) {
|
||||
return (unsigned int)SH_ERROR;
|
||||
}
|
||||
*value = OsCmdParseStrdup(paraTokenStr);
|
||||
if (*value == NULL) {
|
||||
return SH_NOK;
|
||||
}
|
||||
return SH_OK;
|
||||
}
|
||||
|
||||
unsigned int OsCmdParseOneToken(CmdParsed *cmdParsed, unsigned int index, const char *token)
|
||||
{
|
||||
unsigned int ret = SH_OK;
|
||||
unsigned int tempLen;
|
||||
|
||||
if (cmdParsed == NULL) {
|
||||
return (unsigned int)SH_ERROR;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
if (cmdParsed->cmdType != CMD_TYPE_STD) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if ((token != NULL) && (cmdParsed->paramCnt < CMD_MAX_PARAS)) {
|
||||
tempLen = cmdParsed->paramCnt;
|
||||
ret = OsCmdParseParaGet(&(cmdParsed->paramArray[tempLen]), token);
|
||||
if (ret != SH_OK) {
|
||||
return ret;
|
||||
}
|
||||
cmdParsed->paramCnt++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned int OsCmdTokenSplit(char *cmdStr, char split, CmdParsed *cmdParsed)
|
||||
{
|
||||
enum {
|
||||
STAT_INIT,
|
||||
STAT_TOKEN_IN,
|
||||
STAT_TOKEN_OUT
|
||||
} state = STAT_INIT;
|
||||
unsigned int count = 0;
|
||||
char *p = NULL;
|
||||
char *token = cmdStr;
|
||||
unsigned int ret = SH_OK;
|
||||
bool quotes = FALSE;
|
||||
|
||||
if (cmdStr == NULL) {
|
||||
return (unsigned int)SH_ERROR;
|
||||
}
|
||||
|
||||
for (p = cmdStr; (*p != '\0') && (ret == SH_OK); p++) {
|
||||
if (*p == '\"') {
|
||||
SWITCH_QUOTES_STATUS(quotes);
|
||||
}
|
||||
switch (state) {
|
||||
case STAT_INIT:
|
||||
case STAT_TOKEN_IN:
|
||||
if ((*p == split) && QUOTES_STATUS_CLOSE(quotes)) {
|
||||
*p = '\0';
|
||||
ret = OsCmdParseOneToken(cmdParsed, count++, token);
|
||||
state = STAT_TOKEN_OUT;
|
||||
}
|
||||
break;
|
||||
case STAT_TOKEN_OUT:
|
||||
if (*p != split) {
|
||||
token = p;
|
||||
state = STAT_TOKEN_IN;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (((ret == SH_OK) && (state == STAT_TOKEN_IN)) || (state == STAT_INIT)) {
|
||||
ret = OsCmdParseOneToken(cmdParsed, count, token);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned int OsCmdParse(char *cmdStr, CmdParsed *cmdParsed)
|
||||
{
|
||||
if ((cmdStr == NULL) || (cmdParsed == NULL) || (strlen(cmdStr) == 0)) {
|
||||
return (unsigned int)SH_ERROR;
|
||||
}
|
||||
return OsCmdTokenSplit(cmdStr, ' ', cmdParsed);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,640 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "stdio.h"
|
||||
#include "unistd.h"
|
||||
#include "sys/prctl.h"
|
||||
#include "sys/ioctl.h"
|
||||
#include "syscall.h"
|
||||
#include "sys/wait.h"
|
||||
#include "pthread.h"
|
||||
#include "securec.h"
|
||||
#include "shmsg.h"
|
||||
#include "shell_pri.h"
|
||||
#include "shcmd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
char *GetCmdline(ShellCB *shellCB)
|
||||
{
|
||||
CmdKeyLink *cmdkey = shellCB->cmdKeyLink;
|
||||
CmdKeyLink *cmdNode = NULL;
|
||||
|
||||
(void)pthread_mutex_lock(&shellCB->keyMutex);
|
||||
if ((cmdkey == NULL) || SH_ListEmpty(&cmdkey->list)) {
|
||||
(void)pthread_mutex_unlock(&shellCB->keyMutex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cmdNode = SH_LIST_ENTRY(cmdkey->list.pstNext, CmdKeyLink, list);
|
||||
SH_ListDelete(&(cmdNode->list));
|
||||
(void)pthread_mutex_unlock(&shellCB->keyMutex);
|
||||
|
||||
return cmdNode->cmdString;
|
||||
}
|
||||
|
||||
static void ShellSaveHistoryCmd(char *string, ShellCB *shellCB)
|
||||
{
|
||||
CmdKeyLink *cmdHistory = shellCB->cmdHistoryKeyLink;
|
||||
CmdKeyLink *cmdkey = SH_LIST_ENTRY(string, CmdKeyLink, cmdString);
|
||||
CmdKeyLink *cmdNxt = NULL;
|
||||
|
||||
if ((string == NULL) || (*string == '\n') || (strlen(string) == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
(void)pthread_mutex_lock(&shellCB->historyMutex);
|
||||
if (cmdHistory->count != 0) {
|
||||
cmdNxt = SH_LIST_ENTRY(cmdHistory->list.pstPrev, CmdKeyLink, list);
|
||||
if (strcmp(string, cmdNxt->cmdString) == 0) {
|
||||
free((void *)cmdkey);
|
||||
(void)pthread_mutex_unlock(&shellCB->historyMutex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdHistory->count == CMD_HISTORY_LEN) {
|
||||
cmdNxt = SH_LIST_ENTRY(cmdHistory->list.pstNext, CmdKeyLink, list);
|
||||
SH_ListDelete(&(cmdNxt->list));
|
||||
SH_ListTailInsert(&(cmdHistory->list), &(cmdkey->list));
|
||||
free((void *)cmdNxt);
|
||||
(void)pthread_mutex_unlock(&shellCB->historyMutex);
|
||||
return;
|
||||
}
|
||||
|
||||
SH_ListTailInsert(&(cmdHistory->list), &(cmdkey->list));
|
||||
cmdHistory->count++;
|
||||
|
||||
(void)pthread_mutex_unlock(&shellCB->historyMutex);
|
||||
return;
|
||||
}
|
||||
|
||||
int ShellPend(ShellCB *shellCB)
|
||||
{
|
||||
if (shellCB == NULL) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
return sem_wait(&shellCB->shellSem);
|
||||
}
|
||||
|
||||
int ShellNotify(ShellCB *shellCB)
|
||||
{
|
||||
if (shellCB == NULL) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
return sem_post(&shellCB->shellSem);
|
||||
}
|
||||
|
||||
enum {
|
||||
STAT_NOMAL_KEY,
|
||||
STAT_ESC_KEY,
|
||||
STAT_MULTI_KEY
|
||||
};
|
||||
|
||||
static int ShellCmdLineCheckUDRL(const char ch, ShellCB *shellCB)
|
||||
{
|
||||
int ret = SH_OK;
|
||||
if (ch == 0x1b) { /* 0x1b: ESC */
|
||||
shellCB->shellKeyType = STAT_ESC_KEY;
|
||||
return ret;
|
||||
} else if (ch == 0x5b) { /* 0x5b: first Key combination */
|
||||
if (shellCB->shellKeyType == STAT_ESC_KEY) {
|
||||
shellCB->shellKeyType = STAT_MULTI_KEY;
|
||||
return ret;
|
||||
}
|
||||
} else if (ch == 0x41) { /* up */
|
||||
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
|
||||
OsShellHistoryShow(CMD_KEY_UP, shellCB);
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
return ret;
|
||||
}
|
||||
} else if (ch == 0x42) { /* down */
|
||||
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
OsShellHistoryShow(CMD_KEY_DOWN, shellCB);
|
||||
return ret;
|
||||
}
|
||||
} else if (ch == 0x43) { /* right */
|
||||
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
return ret;
|
||||
}
|
||||
} else if (ch == 0x44) { /* left */
|
||||
if (shellCB->shellKeyType == STAT_MULTI_KEY) {
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
void ShellTaskNotify(ShellCB *shellCB)
|
||||
{
|
||||
int ret;
|
||||
|
||||
(void)pthread_mutex_lock(&shellCB->keyMutex);
|
||||
OsShellCmdPush(shellCB->shellBuf, shellCB->cmdKeyLink);
|
||||
(void)pthread_mutex_unlock(&shellCB->keyMutex);
|
||||
|
||||
ret = ShellNotify(shellCB);
|
||||
if (ret != SH_OK) {
|
||||
printf("command execute failed, \"%s\"", shellCB->shellBuf);
|
||||
}
|
||||
}
|
||||
|
||||
void ParseEnterKey(OutputFunc outputFunc, ShellCB *shellCB)
|
||||
{
|
||||
if ((shellCB == NULL) || (outputFunc == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shellCB->shellBufOffset == 0) {
|
||||
shellCB->shellBuf[shellCB->shellBufOffset] = '\n';
|
||||
shellCB->shellBuf[shellCB->shellBufOffset + 1] = '\0';
|
||||
goto NOTIFY;
|
||||
}
|
||||
|
||||
if (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1)) {
|
||||
shellCB->shellBuf[shellCB->shellBufOffset] = '\0';
|
||||
}
|
||||
NOTIFY:
|
||||
outputFunc("\n");
|
||||
shellCB->shellBufOffset = 0;
|
||||
ShellTaskNotify(shellCB);
|
||||
}
|
||||
|
||||
void ParseDeleteKey(OutputFunc outputFunc, ShellCB *shellCB)
|
||||
{
|
||||
if ((shellCB == NULL) || (outputFunc == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((shellCB->shellBufOffset > 0) && (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1))) {
|
||||
shellCB->shellBuf[shellCB->shellBufOffset - 1] = '\0';
|
||||
shellCB->shellBufOffset--;
|
||||
outputFunc("\b \b");
|
||||
}
|
||||
}
|
||||
|
||||
void ParseTabKey(OutputFunc outputFunc, ShellCB *shellCB)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if ((shellCB == NULL) || (outputFunc == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((shellCB->shellBufOffset > 0) && (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1))) {
|
||||
ret = OsTabCompletion(shellCB->shellBuf, &shellCB->shellBufOffset);
|
||||
if (ret > 1) {
|
||||
outputFunc(SHELL_PROMPT"%s", shellCB->shellBuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
{
|
||||
if ((shellCB == NULL) || (outputFunc == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ch != '\0') && (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1))) {
|
||||
shellCB->shellBuf[shellCB->shellBufOffset] = ch;
|
||||
shellCB->shellBufOffset++;
|
||||
outputFunc("%c", ch);
|
||||
}
|
||||
|
||||
shellCB->shellKeyType = STAT_NOMAL_KEY;
|
||||
}
|
||||
|
||||
void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB)
|
||||
{
|
||||
const char ch = c;
|
||||
int ret;
|
||||
|
||||
if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != '\0')) {
|
||||
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
|
||||
}
|
||||
|
||||
switch (ch) {
|
||||
case '\r':
|
||||
case '\n': /* enter */
|
||||
ParseEnterKey(outputFunc, shellCB);
|
||||
break;
|
||||
case '\b': /* backspace */
|
||||
case 0x7F: /* delete(0x7F) */
|
||||
ParseDeleteKey(outputFunc, shellCB);
|
||||
break;
|
||||
case '\t': /* tab */
|
||||
ParseTabKey(outputFunc, shellCB);
|
||||
break;
|
||||
default:
|
||||
/* parse the up/down/right/left key */
|
||||
ret = ShellCmdLineCheckUDRL(ch, shellCB);
|
||||
if (ret == SH_OK) {
|
||||
return;
|
||||
}
|
||||
ParseNormalChar(ch, outputFunc, shellCB);
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int ShellMsgNameGet(CmdParsed *cmdParsed, const char *cmdType)
|
||||
{
|
||||
(void)cmdParsed;
|
||||
(void)cmdType;
|
||||
return SH_ERROR;
|
||||
}
|
||||
|
||||
char *GetCmdName(const char *cmdline, unsigned int len)
|
||||
{
|
||||
unsigned int loop;
|
||||
const char *tmpStr = NULL;
|
||||
bool quotes = FALSE;
|
||||
char *cmdName = NULL;
|
||||
if (cmdline == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cmdName = (char *)malloc(len + 1);
|
||||
if (cmdName == NULL) {
|
||||
printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Scan the 'cmdline' string for command */
|
||||
/* Notice: Command string must not have any special name */
|
||||
for (tmpStr = cmdline, loop = 0; (*tmpStr != '\0') && (loop < len); ) {
|
||||
/* If reach a double quotes, switch the quotes matching status */
|
||||
if (*tmpStr == '\"') {
|
||||
SWITCH_QUOTES_STATUS(quotes);
|
||||
/* Ignore the double quote charactor itself */
|
||||
tmpStr++;
|
||||
continue;
|
||||
}
|
||||
/* If detected a space which the quotes matching status is false */
|
||||
/* which said has detected the first space for seperator, finish this scan operation */
|
||||
if ((*tmpStr == ' ') && (QUOTES_STATUS_CLOSE(quotes))) {
|
||||
break;
|
||||
}
|
||||
cmdName[loop] = *tmpStr++;
|
||||
loop++;
|
||||
}
|
||||
cmdName[loop] = '\0';
|
||||
|
||||
return cmdName;
|
||||
}
|
||||
|
||||
static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, const CmdParsed *cmdParsed)
|
||||
{
|
||||
int ret;
|
||||
pid_t forkPid;
|
||||
|
||||
if (strncmp(cmdline, SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) {
|
||||
forkPid = fork();
|
||||
if (forkPid < 0) {
|
||||
printf("Faild to fork from shell\n");
|
||||
return;
|
||||
} else if (forkPid == 0) {
|
||||
ret = setpgrp();
|
||||
if (ret == -1) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = execve((const char *)cmdParsed->paramArray[0], (char * const *)cmdParsed->paramArray, NULL);
|
||||
if (ret == -1) {
|
||||
perror("execve");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(void)syscall(__NR_shellexec, cmdName, cmdline);
|
||||
}
|
||||
}
|
||||
|
||||
static void ParseAndExecCmdline(CmdParsed *cmdParsed, const char *cmdline, unsigned int len)
|
||||
{
|
||||
int i;
|
||||
unsigned int ret;
|
||||
char shellWorkingDirectory[PATH_MAX + 1] = { 0 };
|
||||
char *cmdlineOrigin = NULL;
|
||||
char *cmdName = NULL;
|
||||
|
||||
cmdlineOrigin = strdup(cmdline);
|
||||
if (cmdlineOrigin == NULL) {
|
||||
printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
cmdName = GetCmdName(cmdline, len);
|
||||
if (cmdName == NULL) {
|
||||
free(cmdlineOrigin);
|
||||
printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = OsCmdParse((char *)cmdline, cmdParsed);
|
||||
if (ret != SH_OK) {
|
||||
printf("cmd parse failure in %s[%d]\n", __FUNCTION__, __LINE__);
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
DoCmdExec(cmdName, cmdlineOrigin, len, cmdParsed);
|
||||
|
||||
if (getcwd(shellWorkingDirectory, PATH_MAX) != NULL) {
|
||||
(void)OsShellSetWorkingDirtectory(shellWorkingDirectory, (PATH_MAX + 1));
|
||||
}
|
||||
|
||||
OUT:
|
||||
for (i = 0; i < cmdParsed->paramCnt; i++) {
|
||||
if (cmdParsed->paramArray[i] != NULL) {
|
||||
free(cmdParsed->paramArray[i]);
|
||||
cmdParsed->paramArray[i] = NULL;
|
||||
}
|
||||
}
|
||||
free(cmdName);
|
||||
free(cmdlineOrigin);
|
||||
}
|
||||
|
||||
unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *outputlen)
|
||||
{
|
||||
unsigned int shiftLen, execLen, newLen;
|
||||
unsigned int removeLen = strlen("./"); /* "./" needs to be removed if it exists */
|
||||
unsigned int ret;
|
||||
char *newCmd = NULL;
|
||||
char *execCmd = SHELL_EXEC_COMMAND;
|
||||
const char *cmdBuf = input;
|
||||
unsigned int cmdBufLen = strlen(cmdBuf);
|
||||
char *shiftStr = (char *)malloc(cmdBufLen + 1);
|
||||
errno_t err;
|
||||
|
||||
if (shiftStr == NULL) {
|
||||
printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
|
||||
return SH_NOK;
|
||||
}
|
||||
(void)memset_s(shiftStr, cmdBufLen + 1, 0, cmdBufLen + 1);
|
||||
|
||||
/* Call function 'OsCmdKeyShift' to squeeze and clear useless or overmuch space if string buffer */
|
||||
ret = OsCmdKeyShift(cmdBuf, shiftStr, cmdBufLen + 1);
|
||||
shiftLen = strlen(shiftStr);
|
||||
if ((ret != SH_OK) || (shiftLen == 0)) {
|
||||
ret = SH_NOK;
|
||||
goto END_FREE_SHIFTSTR;
|
||||
}
|
||||
*output = shiftStr;
|
||||
*outputlen = shiftLen;
|
||||
|
||||
/* Check and parse "./", located at the first two charaters of the cmd */
|
||||
if ((shiftLen > removeLen) && (shiftStr[0] == '.') && (shiftStr[1] == '/')) {
|
||||
execLen = strlen(execCmd);
|
||||
newLen = execLen + shiftLen - removeLen; /* i.e., newLen - execLen == shiftLen - removeLen */
|
||||
newCmd = (char *)malloc(newLen + 1);
|
||||
if (newCmd == NULL) {
|
||||
ret = SH_NOK;
|
||||
printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__);
|
||||
goto END_FREE_SHIFTSTR;
|
||||
}
|
||||
|
||||
err = memcpy_s(newCmd, newLen, execCmd, execLen);
|
||||
if (err != EOK) {
|
||||
printf("memcpy_s failure in %s[%d]\n", __FUNCTION__, __LINE__);
|
||||
ret = SH_NOK;
|
||||
goto END_FREE_NEWCMD;
|
||||
}
|
||||
|
||||
err = memcpy_s(newCmd + execLen, newLen - execLen, shiftStr + removeLen, shiftLen - removeLen);
|
||||
if (err != EOK) {
|
||||
printf("memcpy_s failure in %s[%d]\n", __FUNCTION__, __LINE__);
|
||||
ret = SH_NOK;
|
||||
goto END_FREE_NEWCMD;
|
||||
}
|
||||
newCmd[newLen] = '\0';
|
||||
|
||||
*output = newCmd;
|
||||
*outputlen = newLen;
|
||||
ret = SH_OK;
|
||||
goto END_FREE_SHIFTSTR;
|
||||
} else {
|
||||
ret = SH_OK;
|
||||
goto END;
|
||||
}
|
||||
END_FREE_NEWCMD:
|
||||
free(newCmd);
|
||||
END_FREE_SHIFTSTR:
|
||||
free(shiftStr);
|
||||
END:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ExecCmdline(const char *cmdline)
|
||||
{
|
||||
unsigned int ret;
|
||||
char *output = NULL;
|
||||
unsigned int outputlen;
|
||||
CmdParsed cmdParsed;
|
||||
|
||||
if (cmdline == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* strip out unnecessary characters */
|
||||
ret = PreHandleCmdline(cmdline, &output, &outputlen);
|
||||
if (ret == SH_NOK) {
|
||||
return;
|
||||
}
|
||||
|
||||
(void)memset_s(&cmdParsed, sizeof(CmdParsed), 0, sizeof(CmdParsed));
|
||||
ParseAndExecCmdline(&cmdParsed, output, outputlen);
|
||||
free(output);
|
||||
}
|
||||
|
||||
void RecycleZombieChild(void)
|
||||
{
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
static void ShellCmdProcess(ShellCB *shellCB)
|
||||
{
|
||||
char *buf = NULL;
|
||||
while (1) {
|
||||
/* recycle zombine child process */
|
||||
RecycleZombieChild();
|
||||
buf = GetCmdline(shellCB);
|
||||
if (buf == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
ExecCmdline(buf);
|
||||
ShellSaveHistoryCmd(buf, shellCB);
|
||||
shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink;
|
||||
printf(SHELL_PROMPT);
|
||||
}
|
||||
}
|
||||
|
||||
void *ShellTask(void *argv)
|
||||
{
|
||||
int ret;
|
||||
ShellCB *shellCB = (ShellCB *)argv;
|
||||
|
||||
if (shellCB == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = prctl(PR_SET_NAME, "ShellTask");
|
||||
if (ret != SH_OK) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
printf(SHELL_PROMPT);
|
||||
while (1) {
|
||||
ret = ShellPend(shellCB);
|
||||
if (ret == SH_OK) {
|
||||
ShellCmdProcess(shellCB);
|
||||
} else if (ret != SH_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ShellTaskInit(ShellCB *shellCB)
|
||||
{
|
||||
unsigned int ret;
|
||||
size_t stackSize = SHELL_TASK_STACKSIZE;
|
||||
void *arg = NULL;
|
||||
pthread_attr_t attr;
|
||||
|
||||
if (shellCB == NULL) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
if (ret != SH_OK) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
pthread_attr_setstacksize(&attr, stackSize);
|
||||
arg = (void *)shellCB;
|
||||
ret = pthread_create(&shellCB->shellTaskHandle, &attr, &ShellTask, arg);
|
||||
if (ret != SH_OK) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ShellKernelReg(unsigned int shellHandle)
|
||||
{
|
||||
return ioctl(0, CONSOLE_CONTROL_REG_USERTASK, shellHandle);
|
||||
}
|
||||
|
||||
void *ShellEntry(void *argv)
|
||||
{
|
||||
char ch;
|
||||
int ret;
|
||||
int n;
|
||||
pid_t tid = syscall(__NR_gettid);
|
||||
ShellCB *shellCB = (ShellCB *)argv;
|
||||
|
||||
if (shellCB == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
(void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN);
|
||||
|
||||
ret = prctl(PR_SET_NAME, "ShellEntry");
|
||||
if (ret != SH_OK) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = ShellKernelReg((int)tid);
|
||||
if (ret != 0) {
|
||||
printf("another shell is already running!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
/* is console ready for shell ? */
|
||||
if (ret != SH_OK)
|
||||
break;
|
||||
|
||||
n = read(0, &ch, 1);
|
||||
if (n == 1) {
|
||||
ShellCmdLineParse(ch, (OutputFunc)printf, shellCB);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ShellEntryInit(ShellCB *shellCB)
|
||||
{
|
||||
int ret;
|
||||
size_t stackSize = SHELL_ENTRY_STACKSIZE;
|
||||
void *arg = NULL;
|
||||
pthread_attr_t attr;
|
||||
|
||||
if (shellCB == NULL) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
ret = pthread_attr_init(&attr);
|
||||
if (ret != SH_OK) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
pthread_attr_setstacksize(&attr, stackSize);
|
||||
arg = (void *)shellCB;
|
||||
ret = pthread_create(&shellCB->shellEntryHandle, &attr, &ShellEntry, arg);
|
||||
if (ret != SH_OK) {
|
||||
return SH_NOK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,33 @@
|
|||
config ARCH_ARM
|
||||
bool
|
||||
|
||||
source "arch/arm/Kconfig"
|
||||
|
||||
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.
|
|
@ -0,0 +1,77 @@
|
|||
# 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_V7A
|
||||
bool
|
||||
|
||||
config ARCH_ARM_VER
|
||||
string
|
||||
default "armv7-a" if ARCH_ARM_V7A
|
||||
|
||||
#
|
||||
# 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_A7
|
||||
bool
|
||||
select ARCH_ARM_V7A
|
||||
select ARCH_ARM_AARCH32
|
||||
select ARCH_FPU_VFP_V4
|
||||
select ARCH_FPU_VFP_D32
|
||||
select ARCH_FPU_VFP_NEON
|
||||
|
||||
config ARCH_CPU
|
||||
string
|
||||
default "cortex-a7" if ARCH_CORTEX_A7
|
|
@ -0,0 +1,99 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
# strip quotation mark in configuration
|
||||
|
||||
LOSCFG_ARCH_CPU_STRIP := $(subst $\",,$(LOSCFG_ARCH_CPU))
|
||||
LOSCFG_ARCH_CPU = $(LOSCFG_ARCH_CPU_STRIP)
|
||||
|
||||
LOSCFG_ARCH_FPU_STRIP := $(subst $\",,$(LOSCFG_ARCH_FPU))
|
||||
LOSCFG_ARCH_FPU = $(LOSCFG_ARCH_FPU_STRIP)
|
||||
|
||||
ifeq ($(LOSCFG_ARCH_ARM_AARCH32), y)
|
||||
LITEOS_ARCH_ARM := arm
|
||||
else ifeq ($(LOSCFG_ARCH_ARM_AARCH64), y)
|
||||
LITEOS_ARCH_ARM :=
|
||||
endif
|
||||
|
||||
LITEOS_BASELIB += -l$(LOSCFG_ARCH_CPU)
|
||||
LIB_SUBDIRS += arch/arm/$(LITEOS_ARCH_ARM)
|
||||
|
||||
# CPU compile options
|
||||
ifeq ($(LOSCFG_ARCH_ARM_AARCH64), y)
|
||||
ifeq ($(LOSCFG_ARCH_FPU_DISABLE), y)
|
||||
EXTENSION := +nofp
|
||||
endif
|
||||
endif
|
||||
LITEOS_CPU_OPTS := -mcpu=$(LOSCFG_ARCH_CPU)$(EXTENSION)
|
||||
|
||||
# FPU compile options
|
||||
# -mfloat and -mfpu is ignored with AArch64 targets
|
||||
ifeq ($(LOSCFG_ARCH_ARM_AARCH32), y)
|
||||
LITEOS_FLOAT_OPTS := -mfloat-abi=softfp
|
||||
LITEOS_FPU_OPTS := -mfpu=$(LOSCFG_ARCH_FPU)
|
||||
# gcc libc folder style is combine with core and fpu
|
||||
# for example, cortex-a7 with softfp abi and neon vfp4 is: a7_softfp_neon_vfp4
|
||||
LITEOS_GCCLIB := $(subst cortex-,,$(LOSCFG_ARCH_CPU))_softfp_$(LOSCFG_ARCH_FPU)
|
||||
endif
|
||||
|
||||
LITEOS_CORE_COPTS = $(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS)
|
||||
LITEOS_INTERWORK += $(LITEOS_CORE_COPTS)
|
||||
LITEOS_NODEBUG += $(LITEOS_CORE_COPTS)
|
||||
LITEOS_ASOPTS += $(LITEOS_CPU_OPTS)
|
||||
LITEOS_CXXOPTS_BASE += $(LITEOS_CORE_COPTS)
|
||||
|
||||
ARCH_INCLUDE := -I $(LITEOSTOPDIR)/arch/arm/include \
|
||||
-I $(LITEOSTOPDIR)/arch/arm/$(LITEOS_ARCH_ARM)/include \
|
||||
-I $(LITEOSTOPDIR)/arch/arm/$(LITEOS_ARCH_ARM)/src/include
|
||||
|
||||
LITEOS_PLATFORM_INCLUDE += $(ARCH_INCLUDE)
|
||||
LITEOS_CXXINCLUDE += $(ARCH_INCLUDE)
|
||||
|
||||
# expose FPU info to assembly code
|
||||
ifeq ($(LOSCFG_ARCH_FPU_DISABLE), y)
|
||||
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_DISABLE
|
||||
else ifeq ($(LOSCFG_ARCH_FPU_VFP_D16), y)
|
||||
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D16
|
||||
else ifeq ($(LOSCFG_ARCH_FPU_VFP_D32), y)
|
||||
LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D32
|
||||
endif
|
||||
|
||||
# extra definition for other module
|
||||
LITEOS_CPU_TYPE = $(LOSCFG_ARCH_CPU)
|
||||
LITEOS_ARM_ARCH := -march=$(subst $\",,$(LOSCFG_ARCH_ARM_VER))
|
||||
|
||||
# linux style macros
|
||||
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7A) = -D__LINUX_ARM_ARCH__=7
|
||||
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7R) = -D__LINUX_ARM_ARCH__=7
|
||||
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7M) = -D__LINUX_ARM_ARCH__=7
|
||||
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8A) = -D__LINUX_ARM_ARCH__=8
|
||||
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8R) = -D__LINUX_ARM_ARCH__=8
|
||||
LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8M) = -D__LINUX_ARM_ARCH__=8
|
||||
|
||||
AS_OBJS_LIBC_FLAGS += $(LINUX_ARCH_y)
|
|
@ -0,0 +1,55 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
MODULE_NAME := $(LOSCFG_ARCH_CPU)
|
||||
|
||||
LOCAL_SRCS := $(wildcard src/*.c) $(wildcard src/*.S)
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/kernel/base/include \
|
||||
-I $(LITEOSTOPDIR)/kernel/extended/include \
|
||||
-I $(LITEOSTOPDIR)/arch/arm/arm/include \
|
||||
|
||||
ifeq ($(LITEOS_ARM_ARCH), -march=armv7-a)
|
||||
LOCAL_SRCS += $(wildcard src/armv7a/*.S)
|
||||
endif
|
||||
|
||||
ifeq ($(LOSCFG_KERNEL_SMP), y)
|
||||
LOCAL_SRCS += src/startup/reset_vector_mp.S
|
||||
else
|
||||
LOCAL_SRCS += src/startup/reset_vector_up.S
|
||||
endif
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
ifeq ($(LOSCFG_GDB), y)
|
||||
LOCAL_FLAGS += $(AS_OBJS_LIBC_FLAGS)
|
||||
endif
|
||||
include $(MODULE)
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _ARCH_CONFIG_H
|
||||
#define _ARCH_CONFIG_H
|
||||
|
||||
#include "menuconfig.h"
|
||||
|
||||
#define CPSR_INT_DISABLE 0xC0 /* Disable both FIQ and IRQ */
|
||||
#define CPSR_IRQ_DISABLE 0x80 /* IRQ disabled when =1 */
|
||||
#define CPSR_FIQ_DISABLE 0x40 /* FIQ disabled when =1 */
|
||||
#define CPSR_THUMB_ENABLE 0x20 /* Thumb mode when =1 */
|
||||
#define CPSR_USER_MODE 0x10
|
||||
#define CPSR_FIQ_MODE 0x11
|
||||
#define CPSR_IRQ_MODE 0x12
|
||||
#define CPSR_SVC_MODE 0x13
|
||||
#define CPSR_ABT_MODE 0x17
|
||||
#define CPSR_UNDEF_MODE 0x1B
|
||||
#define CPSR_MASK_MODE 0x1F
|
||||
|
||||
/* Define exception type ID */
|
||||
#define OS_EXCEPT_RESET 0x00
|
||||
#define OS_EXCEPT_UNDEF_INSTR 0x01
|
||||
#define OS_EXCEPT_SWI 0x02
|
||||
#define OS_EXCEPT_PREFETCH_ABORT 0x03
|
||||
#define OS_EXCEPT_DATA_ABORT 0x04
|
||||
#define OS_EXCEPT_FIQ 0x05
|
||||
#define OS_EXCEPT_ADDR_ABORT 0x06
|
||||
#define OS_EXCEPT_IRQ 0x07
|
||||
|
||||
/* Define core num */
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#define CORE_NUM LOSCFG_KERNEL_SMP_CORE_NUM
|
||||
#else
|
||||
#define CORE_NUM 1
|
||||
#endif
|
||||
|
||||
/* Initial bit32 stack value. */
|
||||
#define OS_STACK_INIT 0xCACACACA
|
||||
/* Bit32 stack top magic number. */
|
||||
#define OS_STACK_MAGIC_WORD 0xCCCCCCCC
|
||||
|
||||
#ifdef LOSCFG_GDB
|
||||
#define OS_EXC_UNDEF_STACK_SIZE 512
|
||||
#define OS_EXC_ABT_STACK_SIZE 512
|
||||
#else
|
||||
#define OS_EXC_UNDEF_STACK_SIZE 40
|
||||
#define OS_EXC_ABT_STACK_SIZE 40
|
||||
#endif
|
||||
#define OS_EXC_FIQ_STACK_SIZE 64
|
||||
#define OS_EXC_IRQ_STACK_SIZE 64
|
||||
#define OS_EXC_SVC_STACK_SIZE 0x2000
|
||||
#define OS_EXC_STACK_SIZE 0x1000
|
||||
|
||||
#define REG_R0 0
|
||||
#define REG_R1 1
|
||||
#define REG_R2 2
|
||||
#define REG_R3 3
|
||||
#define REG_R4 4
|
||||
#define REG_R5 5
|
||||
#define REG_R6 6
|
||||
#define REG_R7 7
|
||||
#define REG_R8 8
|
||||
#define REG_R9 9
|
||||
#define REG_R10 10
|
||||
#define REG_R11 11
|
||||
#define REG_R12 12
|
||||
#define REG_R13 13
|
||||
#define REG_R14 14
|
||||
#define REG_R15 15
|
||||
#define REG_CPSR 16
|
||||
#define REG_SP REG_R13
|
||||
#define REG_LR REG_R14
|
||||
#define REG_PC REG_R15
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_typedef.h"
|
||||
#pragma once
|
||||
|
||||
size_t _arm_user_copy(void *dst, const void *src, size_t len);
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _ARM_USER_GET_H
|
||||
#define _ARM_USER_GET_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
errno_t _arm_get_user(void *dst, const void *src, size_t dstTypeLen, size_t srcTypeLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _ARM_USER_GET_H */
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _ARM_USER_PUT_H
|
||||
#define _ARM_USER_PUT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
errno_t _arm_put_user(void *dst, const void *src, size_t dstTypeLen, size_t srcTypeLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _ARM_USER_PUT_H */
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_arch_mmu architecture mmu
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef __LOS_ARCH_MMU_H__
|
||||
#define __LOS_ARCH_MMU_H__
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_mux.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef struct ArchMmu {
|
||||
LosMux mtx; /**< arch mmu page table entry modification mutex lock */
|
||||
VADDR_T *virtTtb; /**< translation table base virtual addr */
|
||||
PADDR_T physTtb; /**< translation table base phys addr */
|
||||
UINT32 asid; /**< TLB asid */
|
||||
LOS_DL_LIST ptList; /**< page table vm page list */
|
||||
} LosArchMmu;
|
||||
|
||||
BOOL OsArchMmuInit(LosArchMmu *archMmu, VADDR_T *virtTtb);
|
||||
STATUS_T LOS_ArchMmuQuery(const LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T *paddr, UINT32 *flags);
|
||||
STATUS_T LOS_ArchMmuUnmap(LosArchMmu *archMmu, VADDR_T vaddr, size_t count);
|
||||
STATUS_T LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_t count, UINT32 flags);
|
||||
STATUS_T LOS_ArchMmuChangeProt(LosArchMmu *archMmu, VADDR_T vaddr, size_t count, UINT32 flags);
|
||||
STATUS_T LOS_ArchMmuMove(LosArchMmu *archMmu, VADDR_T oldVaddr, VADDR_T newVaddr, size_t count, UINT32 flags);
|
||||
VOID LOS_ArchMmuContextSwitch(LosArchMmu *archMmu);
|
||||
STATUS_T LOS_ArchMmuDestroy(LosArchMmu *archMmu);
|
||||
VOID OsArchMmuInitPerCPU(VOID);
|
||||
VADDR_T *OsGFirstTableGet(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __LOS_VM_PAGE_H__ */
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_asid mmu address space id
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef __LOS_ASID_H__
|
||||
#define __LOS_ASID_H__
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define MMU_ARM_ASID_BITS 8
|
||||
|
||||
/* allocate and free asid */
|
||||
STATUS_T OsAllocAsid(UINT32 *asid);
|
||||
VOID OsFreeAsid(UINT32 asid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __LOS_VM_PAGE_H__ */
|
||||
|
|
@ -0,0 +1,892 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_atomic Atomic
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef __LOS_ATOMIC_H__
|
||||
#define __LOS_ATOMIC_H__
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
typedef volatile INT32 Atomic;
|
||||
typedef volatile INT64 Atomic64;
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic read.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic read and return the result value of the read.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The reading pointer.
|
||||
*
|
||||
* @retval #INT32 The result value of the read.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v)
|
||||
{
|
||||
return *(volatile INT32 *)v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic setting.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic setting operation.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer to be setting.
|
||||
* @param setVal [IN] The value to be setting.
|
||||
*
|
||||
* @retval none.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE VOID LOS_AtomicSet(Atomic *v, INT32 setVal)
|
||||
{
|
||||
*(volatile INT32 *)v = setVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic addition.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic addition and return the result value of the augend.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>If the addtion result is not in the range of representable values for 32-bit signed integer,
|
||||
* an int integer overflow may occur to the return value</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The augend pointer.
|
||||
* @param addVal [IN] The addend.
|
||||
*
|
||||
* @retval #INT32 The result value of the augend.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 LOS_AtomicAdd(Atomic *v, INT32 addVal)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %1, [%2]\n"
|
||||
"add %1, %1, %3\n"
|
||||
"strex %0, %1, [%2]"
|
||||
: "=&r"(status), "=&r"(val)
|
||||
: "r"(v), "r"(addVal)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic subtraction.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic subtraction and return the result value of the minuend.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>If the subtraction result is not in the range of representable values for 32-bit signed integer,
|
||||
* an int integer overflow may occur to the return value</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The minuend pointer.
|
||||
* @param subVal [IN] The subtrahend.
|
||||
*
|
||||
* @retval #INT32 The result value of the minuend.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 LOS_AtomicSub(Atomic *v, INT32 subVal)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %1, [%2]\n"
|
||||
"sub %1, %1, %3\n"
|
||||
"strex %0, %1, [%2]"
|
||||
: "=&r"(status), "=&r"(val)
|
||||
: "r"(v), "r"(subVal)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic addSelf.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic addSelf.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT_MAX to avoid integer overflow after adding 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The addSelf variable pointer.
|
||||
*
|
||||
* @retval none.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE VOID LOS_AtomicInc(Atomic *v)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"add %0, %0, #1\n"
|
||||
"strex %1, %0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic addSelf.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic addSelf and return the result of addSelf.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT_MAX to avoid integer overflow after adding 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The addSelf variable pointer.
|
||||
*
|
||||
* @retval #INT32 The return value of variable addSelf.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 LOS_AtomicIncRet(Atomic *v)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"add %0, %0, #1\n"
|
||||
"strex %1, %0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT_MIN to avoid overflow after reducing 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The auto-decrement variable pointer.
|
||||
*
|
||||
* @retval none.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE VOID LOS_AtomicDec(Atomic *v)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"sub %0, %0, #1\n"
|
||||
"strex %1, %0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic auto-decrement and return the result of auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT_MIN to avoid overflow after reducing 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The auto-decrement variable pointer.
|
||||
*
|
||||
* @retval #INT32 The return value of variable auto-decrement.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 LOS_AtomicDecRet(Atomic *v)
|
||||
{
|
||||
INT32 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"sub %0, %0, #1\n"
|
||||
"strex %1, %0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic64 read.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic64 read and return the result value of the read.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The reading pointer.
|
||||
*
|
||||
* @retval #INT64 The result value of the read.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT64 LOS_Atomic64Read(const Atomic64 *v)
|
||||
{
|
||||
INT64 val;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %0, %H0, [%1]"
|
||||
: "=&r"(val)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (0);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic64 setting.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic64 setting operation.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer to be setting.
|
||||
* @param setVal [IN] The value to be setting.
|
||||
*
|
||||
* @retval none.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE VOID LOS_Atomic64Set(Atomic64 *v, INT64 setVal)
|
||||
{
|
||||
INT64 tmp;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %1, %H1, [%2]\n"
|
||||
"strexd %0, %3, %H3, [%2]"
|
||||
: "=&r"(status), "=&r"(tmp)
|
||||
: "r"(v), "r"(setVal)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic64 addition.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic64 addition and return the result value of the augend.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>If the addtion result is not in the range of representable values for 64-bit signed integer,
|
||||
* an int integer overflow may occur to the return value</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The augend pointer.
|
||||
* @param addVal [IN] The addend.
|
||||
*
|
||||
* @retval #INT64 The result value of the augend.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT64 LOS_Atomic64Add(Atomic64 *v, INT64 addVal)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %1, %H1, [%2]\n"
|
||||
"adds %Q1, %Q1, %Q3\n"
|
||||
"adc %R1, %R1, %R3\n"
|
||||
"strexd %0, %1, %H1, [%2]"
|
||||
: "=&r"(status), "=&r"(val)
|
||||
: "r"(v), "r"(addVal)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic64 subtraction.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic64 subtraction and return the result value of the minuend.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>If the subtraction result is not in the range of representable values for 64-bit signed integer,
|
||||
* an int integer overflow may occur to the return value</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The minuend pointer.
|
||||
* @param subVal [IN] The subtrahend.
|
||||
*
|
||||
* @retval #INT64 The result value of the minuend.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT64 LOS_Atomic64Sub(Atomic64 *v, INT64 subVal)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %1, %H1, [%2]\n"
|
||||
"subs %Q1, %Q1, %Q3\n"
|
||||
"sbc %R1, %R1, %R3\n"
|
||||
"strexd %0, %1, %H1, [%2]"
|
||||
: "=&r"(status), "=&r"(val)
|
||||
: "r"(v), "r"(subVal)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic64 addSelf.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic64 addSelf .
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT64_MAX to avoid integer overflow after adding 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The addSelf variable pointer.
|
||||
*
|
||||
* @retval none.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE VOID LOS_Atomic64Inc(Atomic64 *v)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
|
||||
"adds %Q0, %Q0, #1\n"
|
||||
"adc %R0, %R0, #0\n"
|
||||
"strexd %1, %0, %H0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic64 addSelf.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic64 addSelf and return the result of addSelf.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT64_MAX to avoid integer overflow after adding 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The addSelf variable pointer.
|
||||
*
|
||||
* @retval #INT64 The return value of variable addSelf.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT64 LOS_Atomic64IncRet(Atomic64 *v)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
|
||||
"adds %Q0, %Q0, #1\n"
|
||||
"adc %R0, %R0, #0\n"
|
||||
"strexd %1, %0, %H0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic64 auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic64 auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT64_MIN to avoid overflow after reducing 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The auto-decrement variable pointer.
|
||||
*
|
||||
* @retval none.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE VOID LOS_Atomic64Dec(Atomic64 *v)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
|
||||
"subs %Q0, %Q0, #1\n"
|
||||
"sbc %R0, %R0, #0\n"
|
||||
"strexd %1, %0, %H0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic64 auto-decrement.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implementating the atomic64 auto-decrement and return the result of auto-decrement.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The pointer v must not be NULL.</li>
|
||||
* <li>The value which v point to must not be INT64_MIN to avoid overflow after reducing 1.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param v [IN] The auto-decrement variable pointer.
|
||||
*
|
||||
* @retval #INT64 The return value of variable auto-decrement.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT64 LOS_Atomic64DecRet(Atomic64 *v)
|
||||
{
|
||||
INT64 val;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
|
||||
"subs %Q0, %Q0, #1\n"
|
||||
"sbc %R0, %R0, #0\n"
|
||||
"strexd %1, %0, %H0, [%3]"
|
||||
: "=&r"(val), "=&r"(status), "+m"(*v)
|
||||
: "r"(v)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 8-bit variable.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 8-bit variable and
|
||||
* return the previous value of the atomic variable.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The exchange value.
|
||||
*
|
||||
* @retval #INT32 The previous value of the atomic variable
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 LOS_AtomicXchgByte(volatile INT8 *v, INT32 val)
|
||||
{
|
||||
INT32 prevVal;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexb %0, [%3]\n"
|
||||
"strexb %1, %4, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 16-bit variable.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 16-bit variable and
|
||||
* return the previous value of the atomic variable.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The exchange value.
|
||||
*
|
||||
* @retval #INT32 The previous value of the atomic variable
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 LOS_AtomicXchg16bits(volatile INT16 *v, INT32 val)
|
||||
{
|
||||
INT32 prevVal;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexh %0, [%3]\n"
|
||||
"strexh %1, %4, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 32-bit variable.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 32-bit variable
|
||||
* and return the previous value of the atomic variable.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The exchange value.
|
||||
*
|
||||
* @retval #INT32 The previous value of the atomic variable
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT32 LOS_AtomicXchg32bits(Atomic *v, INT32 val)
|
||||
{
|
||||
INT32 prevVal;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"strex %1, %4, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 64-bit variable.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 64-bit variable
|
||||
* and return the previous value of the atomic variable.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The exchange value.
|
||||
*
|
||||
* @retval #INT64 The previous value of the atomic variable
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE INT64 LOS_AtomicXchg64bits(Atomic64 *v, INT64 val)
|
||||
{
|
||||
INT64 prevVal;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
|
||||
"strexd %1, %4, %H4, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 8-bit variable with compare.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 8-bit variable, if the value of variable is equal to oldVal.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The new value.
|
||||
* @param oldVal [IN] The old value.
|
||||
*
|
||||
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
|
||||
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE BOOL LOS_AtomicCmpXchgByte(volatile INT8 *v, INT32 val, INT32 oldVal)
|
||||
{
|
||||
INT32 prevVal;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexb %0, [%3]\n"
|
||||
"mov %1, #0\n"
|
||||
"teq %0, %4\n"
|
||||
"strexbeq %1, %5, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(oldVal), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 16-bit variable with compare.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 16-bit variable, if the value of variable is equal to oldVal.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The new value.
|
||||
* @param oldVal [IN] The old value.
|
||||
*
|
||||
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
|
||||
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE BOOL LOS_AtomicCmpXchg16bits(volatile INT16 *v, INT32 val, INT32 oldVal)
|
||||
{
|
||||
INT32 prevVal;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexh %0, [%3]\n"
|
||||
"mov %1, #0\n"
|
||||
"teq %0, %4\n"
|
||||
"strexheq %1, %5, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(oldVal), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 32-bit variable with compare.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 32-bit variable, if the value of variable is equal to oldVal.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The new value.
|
||||
* @param oldVal [IN] The old value.
|
||||
*
|
||||
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
|
||||
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE BOOL LOS_AtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal)
|
||||
{
|
||||
INT32 prevVal;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrex %0, [%3]\n"
|
||||
"mov %1, #0\n"
|
||||
"teq %0, %4\n"
|
||||
"strexeq %1, %5, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(oldVal), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_atomic
|
||||
* @brief Atomic exchange for 64-bit variable with compare.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to implement the atomic exchange for 64-bit variable, if the value of variable is equal to oldVal.
|
||||
* @attention
|
||||
* <ul>The pointer v must not be NULL.</ul>
|
||||
*
|
||||
* @param v [IN] The variable pointer.
|
||||
* @param val [IN] The new value.
|
||||
* @param oldVal [IN] The old value.
|
||||
*
|
||||
* @retval TRUE The previous value of the atomic variable is not equal to oldVal.
|
||||
* @retval FALSE The previous value of the atomic variable is equal to oldVal.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_atomic.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see
|
||||
*/
|
||||
STATIC INLINE BOOL LOS_AtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal)
|
||||
{
|
||||
INT64 prevVal;
|
||||
UINT32 status;
|
||||
|
||||
do {
|
||||
__asm__ __volatile__("ldrexd %0, %H0, [%3]\n"
|
||||
"mov %1, #0\n"
|
||||
"teq %0, %4\n"
|
||||
"teqeq %H0, %H4\n"
|
||||
"strexdeq %1, %5, %H5, [%3]"
|
||||
: "=&r"(prevVal), "=&r"(status), "+m"(*v)
|
||||
: "r"(v), "r"(oldVal), "r"(val)
|
||||
: "cc");
|
||||
} while (__builtin_expect(status != 0, 0));
|
||||
|
||||
return prevVal != oldVal;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __LOS_ATOMIC_H__ */
|
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_hw Hardware
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_HW_CPU_H
|
||||
#define _LOS_HW_CPU_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_toolchain.h"
|
||||
#include "los_hw_arch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* ARM System Registers */
|
||||
#define DSB __asm__ volatile("dsb" ::: "memory")
|
||||
#define DMB __asm__ volatile("dmb" ::: "memory")
|
||||
#define ISB __asm__ volatile("isb" ::: "memory")
|
||||
#define BARRIER __asm__ volatile("":::"memory")
|
||||
|
||||
#define ARM_SYSREG_READ(REG) \
|
||||
({ \
|
||||
UINT32 _val; \
|
||||
__asm__ volatile("mrc " REG : "=r" (_val)); \
|
||||
_val; \
|
||||
})
|
||||
|
||||
#define ARM_SYSREG_WRITE(REG, val) \
|
||||
({ \
|
||||
__asm__ volatile("mcr " REG :: "r" (val)); \
|
||||
ISB; \
|
||||
})
|
||||
|
||||
#define ARM_SYSREG64_READ(REG) \
|
||||
({ \
|
||||
UINT64 _val; \
|
||||
__asm__ volatile("mrrc " REG : "=r" (_val)); \
|
||||
_val; \
|
||||
})
|
||||
|
||||
#define ARM_SYSREG64_WRITE(REG, val) \
|
||||
({ \
|
||||
__asm__ volatile("mcrr " REG :: "r" (val)); \
|
||||
ISB; \
|
||||
})
|
||||
|
||||
#define CP14_REG(CRn, Op1, CRm, Op2) "p14, "#Op1", %0, "#CRn","#CRm","#Op2
|
||||
#define CP15_REG(CRn, Op1, CRm, Op2) "p15, "#Op1", %0, "#CRn","#CRm","#Op2
|
||||
#define CP15_REG64(CRn, Op1) "p15, "#Op1", %0, %H0,"#CRn
|
||||
|
||||
/*
|
||||
* Identification registers (c0)
|
||||
*/
|
||||
#define MIDR CP15_REG(c0, 0, c0, 0) /* Main ID Register */
|
||||
#define MPIDR CP15_REG(c0, 0, c0, 5) /* Multiprocessor Affinity Register */
|
||||
#define CCSIDR CP15_REG(c0, 1, c0, 0) /* Cache Size ID Registers */
|
||||
#define CLIDR CP15_REG(c0, 1, c0, 1) /* Cache Level ID Register */
|
||||
#define VPIDR CP15_REG(c0, 4, c0, 0) /* Virtualization Processor ID Register */
|
||||
#define VMPIDR CP15_REG(c0, 4, c0, 5) /* Virtualization Multiprocessor ID Register */
|
||||
|
||||
/*
|
||||
* System control registers (c1)
|
||||
*/
|
||||
#define SCTLR CP15_REG(c1, 0, c0, 0) /* System Control Register */
|
||||
#define ACTLR CP15_REG(c1, 0, c0, 1) /* Auxiliary Control Register */
|
||||
#define CPACR CP15_REG(c1, 0, c0, 2) /* Coprocessor Access Control Register */
|
||||
|
||||
/*
|
||||
* Memory protection and control registers (c2 & c3)
|
||||
*/
|
||||
#define TTBR0 CP15_REG(c2, 0, c0, 0) /* Translation Table Base Register 0 */
|
||||
#define TTBR1 CP15_REG(c2, 0, c0, 1) /* Translation Table Base Register 1 */
|
||||
#define TTBCR CP15_REG(c2, 0, c0, 2) /* Translation Table Base Control Register */
|
||||
#define DACR CP15_REG(c3, 0, c0, 0) /* Domain Access Control Register */
|
||||
|
||||
/*
|
||||
* Memory system fault registers (c5 & c6)
|
||||
*/
|
||||
#define DFSR CP15_REG(c5, 0, c0, 0) /* Data Fault Status Register */
|
||||
#define IFSR CP15_REG(c5, 0, c0, 1) /* Instruction Fault Status Register */
|
||||
#define DFAR CP15_REG(c6, 0, c0, 0) /* Data Fault Address Register */
|
||||
#define IFAR CP15_REG(c6, 0, c0, 2) /* Instruction Fault Address Register */
|
||||
|
||||
/*
|
||||
* Process, context and thread ID registers (c13)
|
||||
*/
|
||||
#define FCSEIDR CP15_REG(c13, 0, c0, 0) /* FCSE Process ID Register */
|
||||
#define CONTEXTIDR CP15_REG(c13, 0, c0, 1) /* Context ID Register */
|
||||
#define TPIDRURW CP15_REG(c13, 0, c0, 2) /* User Read/Write Thread ID Register */
|
||||
#define TPIDRURO CP15_REG(c13, 0, c0, 3) /* User Read-Only Thread ID Register */
|
||||
#define TPIDRPRW CP15_REG(c13, 0, c0, 4) /* PL1 only Thread ID Register */
|
||||
|
||||
#define MPIDR_CPUID_MASK (0xffU)
|
||||
|
||||
STATIC INLINE VOID *ArchCurrTaskGet(VOID)
|
||||
{
|
||||
return (VOID *)(UINTPTR)ARM_SYSREG_READ(TPIDRPRW);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchCurrTaskSet(VOID *val)
|
||||
{
|
||||
ARM_SYSREG_WRITE(TPIDRPRW, (UINT32)(UINTPTR)val);
|
||||
}
|
||||
|
||||
STATIC INLINE VOID ArchCurrUserTaskSet(UINTPTR val)
|
||||
{
|
||||
ARM_SYSREG_WRITE(TPIDRURO, (UINT32)val);
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 ArchCurrCpuid(VOID)
|
||||
{
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
return ARM_SYSREG_READ(MPIDR) & MPIDR_CPUID_MASK;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE UINT64 OsHwIDGet(VOID)
|
||||
{
|
||||
return ARM_SYSREG_READ(MPIDR);
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsMainIDGet(VOID)
|
||||
{
|
||||
return ARM_SYSREG_READ(MIDR);
|
||||
}
|
||||
|
||||
/* CPU interrupt mask handle implementation */
|
||||
#if LOSCFG_ARM_ARCH >= 6
|
||||
|
||||
STATIC INLINE UINT32 ArchIntLock(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__(
|
||||
"mrs %0, cpsr \n"
|
||||
"cpsid if "
|
||||
: "=r"(intSave)
|
||||
:
|
||||
: "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 ArchIntUnlock(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__(
|
||||
"mrs %0, cpsr \n"
|
||||
"cpsie if "
|
||||
: "=r"(intSave)
|
||||
:
|
||||
: "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
STATIC INLINE UINT32 ArchIntLock(VOID)
|
||||
{
|
||||
UINT32 intSave, temp;
|
||||
__asm__ __volatile__(
|
||||
"mrs %0, cpsr \n"
|
||||
"orr %1, %0, #0xc0 \n"
|
||||
"msr cpsr_c, %1 "
|
||||
:"=r"(intSave), "=r"(temp)
|
||||
: :"memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 ArchIntUnlock(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
__asm__ __volatile__(
|
||||
"mrs %0, cpsr \n"
|
||||
"bic %0, %0, #0xc0 \n"
|
||||
"msr cpsr_c, %0 "
|
||||
: "=r"(intSave)
|
||||
: : "memory");
|
||||
return intSave;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
STATIC INLINE VOID ArchIntRestore(UINT32 intSave)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"msr cpsr_c, %0 "
|
||||
:
|
||||
: "r"(intSave)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
#define PSR_I_BIT 0x00000080U
|
||||
|
||||
STATIC INLINE UINT32 OsIntLocked(VOID)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
asm volatile(
|
||||
"mrs %0, cpsr "
|
||||
: "=r" (intSave)
|
||||
:
|
||||
: "memory", "cc");
|
||||
|
||||
return intSave & PSR_I_BIT;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 ArchSPGet(VOID)
|
||||
{
|
||||
UINT32 val;
|
||||
__asm__ __volatile__("mov %0, sp" : "=r"(val));
|
||||
return val;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_HW_CPU_H */
|
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_mmu_descriptor_v6 MMU Descriptor v6
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef __LOS_MMU_DESCRIPTOR_V6_H__
|
||||
#define __LOS_MMU_DESCRIPTOR_V6_H__
|
||||
|
||||
#include "los_vm_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define __iomem
|
||||
#ifndef IS_ALIGNED
|
||||
#define IS_ALIGNED(a, b) (!(((UINTPTR)(a)) & (((UINTPTR)(b))-1)))
|
||||
#endif
|
||||
|
||||
#define MMU_DESCRIPTOR_TEX_0 0
|
||||
#define MMU_DESCRIPTOR_TEX_1 1
|
||||
#define MMU_DESCRIPTOR_TEX_2 2
|
||||
#define MMU_DESCRIPTOR_TEX_MASK 7
|
||||
|
||||
#define MMU_DESCRIPTOR_CACHE_BUFFER_SHIFT 2
|
||||
#define MMU_DESCRIPTOR_CACHE_BUFFER(x) ((x) << MMU_DESCRIPTOR_CACHE_BUFFER_SHIFT)
|
||||
#define MMU_DESCRIPTOR_NON_CACHEABLE MMU_DESCRIPTOR_CACHE_BUFFER(0)
|
||||
#define MMU_DESCRIPTOR_WRITE_BACK_ALLOCATE MMU_DESCRIPTOR_CACHE_BUFFER(1)
|
||||
#define MMU_DESCRIPTOR_WRITE_THROUGH_NO_ALLOCATE MMU_DESCRIPTOR_CACHE_BUFFER(2)
|
||||
#define MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE MMU_DESCRIPTOR_CACHE_BUFFER(3)
|
||||
|
||||
/* user space mmu access permission define begin */
|
||||
#define MMU_DESCRIPTOR_DOMAIN_MANAGER 0
|
||||
#define MMU_DESCRIPTOR_DOMAIN_CLIENT 1
|
||||
#define MMU_DESCRIPTOR_DOMAIN_NA 2
|
||||
|
||||
/* L1 descriptor type */
|
||||
#define MMU_DESCRIPTOR_L1_TYPE_INVALID (0x0 << 0)
|
||||
#define MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE (0x1 << 0)
|
||||
#define MMU_DESCRIPTOR_L1_TYPE_SECTION (0x2 << 0)
|
||||
#define MMU_DESCRIPTOR_L1_TYPE_MASK (0x3 << 0)
|
||||
|
||||
/* L2 descriptor type */
|
||||
#define MMU_DESCRIPTOR_L2_TYPE_INVALID (0x0 << 0)
|
||||
#define MMU_DESCRIPTOR_L2_TYPE_LARGE_PAGE (0x1 << 0)
|
||||
#define MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE (0x2 << 0)
|
||||
#define MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE_XN (0x3 << 0)
|
||||
#define MMU_DESCRIPTOR_L2_TYPE_MASK (0x3 << 0)
|
||||
|
||||
#define MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(x) IS_ALIGNED(x, MMU_DESCRIPTOR_L1_SMALL_SIZE)
|
||||
#define MMU_DESCRIPTOR_L1_SMALL_SIZE 0x100000
|
||||
#define MMU_DESCRIPTOR_L1_SMALL_MASK (MMU_DESCRIPTOR_L1_SMALL_SIZE - 1)
|
||||
#define MMU_DESCRIPTOR_L1_SMALL_FRAME (~MMU_DESCRIPTOR_L1_SMALL_MASK)
|
||||
#define MMU_DESCRIPTOR_L1_SMALL_SHIFT 20
|
||||
#define MMU_DESCRIPTOR_L1_SECTION_ADDR(x) ((x) & MMU_DESCRIPTOR_L1_SMALL_FRAME)
|
||||
#define MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(x) ((x) & ~((1 << 10)-1))
|
||||
#define MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE 4
|
||||
#define MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS 0x4000U
|
||||
#define MMU_DESCRIPTOR_L1_SMALL_DOMAIN_MASK (~(0x0f << 5)) /* 4k page section domain mask */
|
||||
#define MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT (MMU_DESCRIPTOR_DOMAIN_CLIENT << 5)
|
||||
|
||||
#define MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE (1 << 3)
|
||||
#define MMU_DESCRIPTOR_L1_SECTION_NON_SECURE (1 << 19)
|
||||
#define MMU_DESCRIPTOR_L1_SECTION_SHAREABLE (1 << 16)
|
||||
#define MMU_DESCRIPTOR_L1_SECTION_NON_GLOBAL (1 << 17)
|
||||
#define MMU_DESCRIPTOR_L1_SECTION_XN (1 << 4)
|
||||
|
||||
/* TEX CB */
|
||||
#define MMU_DESCRIPTOR_L1_TEX_SHIFT 12 /* type extension field shift */
|
||||
#define MMU_DESCRIPTOR_L1_TEX(x) \
|
||||
((x) << MMU_DESCRIPTOR_L1_TEX_SHIFT) /* type extension */
|
||||
#define MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED \
|
||||
(MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_NON_CACHEABLE)
|
||||
#define MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED \
|
||||
(MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_WRITE_BACK_ALLOCATE)
|
||||
#define MMU_DESCRIPTOR_L1_TYPE_DEVICE_NON_SHARED \
|
||||
(MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_2) | MMU_DESCRIPTOR_NON_CACHEABLE)
|
||||
#define MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE \
|
||||
(MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_1) | MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE)
|
||||
#define MMU_DESCRIPTOR_L1_TEX_TYPE_MASK \
|
||||
(MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_MASK) | MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE)
|
||||
|
||||
#define MMU_DESCRIPTOR_L1_AP2_SHIFT 15
|
||||
#define MMU_DESCRIPTOR_L1_AP2(x) ((x) << MMU_DESCRIPTOR_L1_AP2_SHIFT)
|
||||
#define MMU_DESCRIPTOR_L1_AP2_0 (MMU_DESCRIPTOR_L1_AP2(0))
|
||||
#define MMU_DESCRIPTOR_L1_AP2_1 (MMU_DESCRIPTOR_L1_AP2(1))
|
||||
#define MMU_DESCRIPTOR_L1_AP01_SHIFT 10
|
||||
#define MMU_DESCRIPTOR_L1_AP01(x) ((x) << MMU_DESCRIPTOR_L1_AP01_SHIFT)
|
||||
#define MMU_DESCRIPTOR_L1_AP01_0 (MMU_DESCRIPTOR_L1_AP01(0))
|
||||
#define MMU_DESCRIPTOR_L1_AP01_1 (MMU_DESCRIPTOR_L1_AP01(1))
|
||||
#define MMU_DESCRIPTOR_L1_AP01_3 (MMU_DESCRIPTOR_L1_AP01(3))
|
||||
#define MMU_DESCRIPTOR_L1_AP_P_NA_U_NA (MMU_DESCRIPTOR_L1_AP2_0 | MMU_DESCRIPTOR_L1_AP01_0)
|
||||
#define MMU_DESCRIPTOR_L1_AP_P_RW_U_RW (MMU_DESCRIPTOR_L1_AP2_0 | MMU_DESCRIPTOR_L1_AP01_3)
|
||||
#define MMU_DESCRIPTOR_L1_AP_P_RW_U_NA (MMU_DESCRIPTOR_L1_AP2_0 | MMU_DESCRIPTOR_L1_AP01_1)
|
||||
#define MMU_DESCRIPTOR_L1_AP_P_RO_U_RO (MMU_DESCRIPTOR_L1_AP2_1 | MMU_DESCRIPTOR_L1_AP01_3)
|
||||
#define MMU_DESCRIPTOR_L1_AP_P_RO_U_NA (MMU_DESCRIPTOR_L1_AP2_1 | MMU_DESCRIPTOR_L1_AP01_1)
|
||||
#define MMU_DESCRIPTOR_L1_AP_MASK (MMU_DESCRIPTOR_L1_AP2_1 | MMU_DESCRIPTOR_L1_AP01_3)
|
||||
|
||||
#define MMU_DESCRIPTOR_L2_SMALL_SIZE 0x1000
|
||||
#define MMU_DESCRIPTOR_L2_SMALL_MASK (MMU_DESCRIPTOR_L2_SMALL_SIZE - 1)
|
||||
#define MMU_DESCRIPTOR_L2_SMALL_FRAME (~MMU_DESCRIPTOR_L2_SMALL_MASK)
|
||||
#define MMU_DESCRIPTOR_L2_SMALL_SHIFT 12
|
||||
#define MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 \
|
||||
(MMU_DESCRIPTOR_L1_SMALL_SIZE >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)
|
||||
#define MMU_DESCRIPTOR_IS_L2_SIZE_ALIGNED(x) IS_ALIGNED(x, MMU_DESCRIPTOR_L2_SMALL_SIZE)
|
||||
#define MMU_DESCRIPTOR_L2_TEX_SHIFT 6 /* type extension field shift */
|
||||
#define MMU_DESCRIPTOR_L2_TEX(x) \
|
||||
((x) << MMU_DESCRIPTOR_L2_TEX_SHIFT) /* type extension */
|
||||
#define MMU_DESCRIPTOR_L2_TYPE_STRONGLY_ORDERED \
|
||||
(MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_NON_CACHEABLE)
|
||||
#define MMU_DESCRIPTOR_L2_TYPE_DEVICE_SHARED \
|
||||
(MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_WRITE_BACK_ALLOCATE)
|
||||
#define MMU_DESCRIPTOR_L2_TYPE_DEVICE_NON_SHARED \
|
||||
(MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_2) | MMU_DESCRIPTOR_NON_CACHEABLE)
|
||||
#define MMU_DESCRIPTOR_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE \
|
||||
(MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_1) | MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE)
|
||||
#define MMU_DESCRIPTOR_L2_TEX_TYPE_MASK \
|
||||
(MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_MASK) | MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE)
|
||||
#define MMU_DESCRIPTOR_L2_AP2_SHIFT 9
|
||||
#define MMU_DESCRIPTOR_L2_AP2(x) ((x) << MMU_DESCRIPTOR_L2_AP2_SHIFT)
|
||||
#define MMU_DESCRIPTOR_L2_AP2_0 (MMU_DESCRIPTOR_L2_AP2(0))
|
||||
#define MMU_DESCRIPTOR_L2_AP2_1 (MMU_DESCRIPTOR_L2_AP2(1))
|
||||
#define MMU_DESCRIPTOR_L2_AP01_SHIFT 4
|
||||
#define MMU_DESCRIPTOR_L2_AP01(x) ((x) << MMU_DESCRIPTOR_L2_AP01_SHIFT)
|
||||
#define MMU_DESCRIPTOR_L2_AP01_0 (MMU_DESCRIPTOR_L2_AP01(0))
|
||||
#define MMU_DESCRIPTOR_L2_AP01_1 (MMU_DESCRIPTOR_L2_AP01(1))
|
||||
#define MMU_DESCRIPTOR_L2_AP01_3 (MMU_DESCRIPTOR_L2_AP01(3))
|
||||
#define MMU_DESCRIPTOR_L2_AP_P_NA_U_NA (MMUDESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_0)
|
||||
#define MMU_DESCRIPTOR_L2_AP_P_RW_U_RW (MMU_DESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_3)
|
||||
#define MMU_DESCRIPTOR_L2_AP_P_RW_U_NA (MMU_DESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_1)
|
||||
#define MMU_DESCRIPTOR_L2_AP_P_RO_U_RO (MMU_DESCRIPTOR_L2_AP2_1 | MMU_DESCRIPTOR_L2_AP01_3)
|
||||
#define MMU_DESCRIPTOR_L2_AP_P_RO_U_NA (MMU_DESCRIPTOR_L2_AP2_1 | MMU_DESCRIPTOR_L2_AP01_1)
|
||||
#define MMU_DESCRIPTOR_L2_AP_MASK (MMU_DESCRIPTOR_L2_AP2_1 | MMU_DESCRIPTOR_L2_AP01_3)
|
||||
|
||||
#define MMU_DESCRIPTOR_L2_SHAREABLE (1 << 10)
|
||||
#define MMU_DESCRIPTOR_L2_NON_GLOBAL (1 << 11)
|
||||
#define MMU_DESCRIPTOR_L2_SMALL_PAGE_ADDR(x) ((x) & MMU_DESCRIPTOR_L2_SMALL_FRAME)
|
||||
|
||||
#define MMU_DESCRIPTOR_TTBCR_PD0 (1 << 4)
|
||||
#define MMU_DESCRIPTOR_TTBR_WRITE_BACK_ALLOCATE 1
|
||||
#define MMU_DESCRIPTOR_TTBR_RGN(x) (((x) & 0x3) << 3)
|
||||
#define MMU_DESCRIPTOR_TTBR_IRGN(x) ((((x) & 0x1) << 6) | ((((x) >> 1) & 0x1) << 0))
|
||||
#define MMU_DESCRIPTOR_TTBR_S (1 << 1)
|
||||
#define MMU_DESCRIPTOR_TTBR_NOS (1 << 5)
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#define MMU_TTBRx_SHARABLE_FLAGS (MMU_DESCRIPTOR_TTBR_S | MMU_DESCRIPTOR_TTBR_NOS)
|
||||
#else
|
||||
#define MMU_TTBRx_SHARABLE_FLAGS 0
|
||||
#endif
|
||||
|
||||
#define MMU_TTBRx_FLAGS \
|
||||
(MMU_DESCRIPTOR_TTBR_RGN(MMU_DESCRIPTOR_TTBR_WRITE_BACK_ALLOCATE) | \
|
||||
MMU_DESCRIPTOR_TTBR_IRGN(MMU_DESCRIPTOR_TTBR_WRITE_BACK_ALLOCATE) | \
|
||||
MMU_TTBRx_SHARABLE_FLAGS)
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#define MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS \
|
||||
(MMU_DESCRIPTOR_L1_TYPE_SECTION | \
|
||||
MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
|
||||
MMU_DESCRIPTOR_L1_AP_P_RW_U_NA | \
|
||||
MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \
|
||||
MMU_DESCRIPTOR_L1_SECTION_SHAREABLE)
|
||||
#else
|
||||
#define MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS \
|
||||
(MMU_DESCRIPTOR_L1_TYPE_SECTION | \
|
||||
MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
|
||||
MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \
|
||||
MMU_DESCRIPTOR_L1_AP_P_RW_U_NA)
|
||||
#endif
|
||||
|
||||
#define MMU_INITIAL_MAP_STRONGLY_ORDERED \
|
||||
(MMU_DESCRIPTOR_L1_TYPE_SECTION | \
|
||||
MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED | \
|
||||
MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \
|
||||
MMU_DESCRIPTOR_L1_AP_P_RW_U_NA)
|
||||
|
||||
#define MMU_INITIAL_MAP_DEVICE \
|
||||
(MMU_DESCRIPTOR_L1_TYPE_SECTION | \
|
||||
MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED | \
|
||||
MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \
|
||||
MMU_DESCRIPTOR_L1_AP_P_RW_U_NA)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __LOS_MMU_DESCRIPTOR_V6_H__ */
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_pte_ops page table entry operations
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef __LOS_PTE_OPS_H__
|
||||
#define __LOS_PTE_OPS_H__
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "arm.h"
|
||||
#include "los_mmu_descriptor_v6.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
STATIC INLINE VOID OsSavePte1(PTE_T *pte1Ptr, PTE_T pte1)
|
||||
{
|
||||
DMB;
|
||||
*pte1Ptr = pte1;
|
||||
DSB;
|
||||
}
|
||||
|
||||
STATIC INLINE ADDR_T OsTruncPte1(ADDR_T addr)
|
||||
{
|
||||
return MMU_DESCRIPTOR_L1_SECTION_ADDR(addr);
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsGetPte1Index(vaddr_t va)
|
||||
{
|
||||
return va >> MMU_DESCRIPTOR_L1_SMALL_SHIFT;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsClearPte1(PTE_T *pte1Ptr)
|
||||
{
|
||||
OsSavePte1(pte1Ptr, 0);
|
||||
}
|
||||
|
||||
STATIC INLINE PTE_T *OsGetPte1Ptr(PTE_T *pte1BasePtr, vaddr_t va)
|
||||
{
|
||||
return (pte1BasePtr + OsGetPte1Index(va));
|
||||
}
|
||||
|
||||
STATIC INLINE PTE_T OsGetPte1(PTE_T *pte1BasePtr, vaddr_t va)
|
||||
{
|
||||
return *OsGetPte1Ptr(pte1BasePtr, va);
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsIsPte1PageTable(PTE_T pte1)
|
||||
{
|
||||
return (pte1 & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsIsPte1Invalid(PTE_T pte1)
|
||||
{
|
||||
return (pte1 & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_INVALID;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsIsPte1Section(PTE_T pte1)
|
||||
{
|
||||
return (pte1 & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_SECTION;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsGetPte2Index(vaddr_t va)
|
||||
{
|
||||
return (va % MMU_DESCRIPTOR_L1_SMALL_SIZE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT;
|
||||
}
|
||||
|
||||
STATIC INLINE PTE_T *OsGetPte2Ptr(PTE_T *pte2BasePtr, vaddr_t va)
|
||||
{
|
||||
return (pte2BasePtr + OsGetPte2Index(va));
|
||||
}
|
||||
|
||||
STATIC INLINE PTE_T OsGetPte2(PTE_T *pte2BasePtr, vaddr_t va)
|
||||
{
|
||||
return *(pte2BasePtr + OsGetPte2Index(va));
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsSavePte2(PTE_T *pte2Ptr, PTE_T pte2)
|
||||
{
|
||||
DMB;
|
||||
*pte2Ptr = pte2;
|
||||
DSB;
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsSavePte2Continuous(PTE_T *pte2BasePtr, UINT32 index, PTE_T pte2, UINT32 count)
|
||||
{
|
||||
UINT32 saveCounts = 0;
|
||||
if (count == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
DMB;
|
||||
do {
|
||||
pte2BasePtr[index++] = pte2;
|
||||
count--;
|
||||
pte2 += MMU_DESCRIPTOR_L2_SMALL_SIZE;
|
||||
saveCounts++;
|
||||
} while ((count != 0) && (index != MMU_DESCRIPTOR_L2_NUMBERS_PER_L1));
|
||||
DSB;
|
||||
|
||||
return saveCounts;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsClearPte2Continuous(PTE_T *pte2Ptr, UINT32 count)
|
||||
{
|
||||
UINT32 index = 0;
|
||||
|
||||
DMB;
|
||||
while (count > 0) {
|
||||
pte2Ptr[index++] = 0;
|
||||
count--;
|
||||
}
|
||||
DSB;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsIsPte2SmallPage(PTE_T pte2)
|
||||
{
|
||||
return (pte2 & MMU_DESCRIPTOR_L2_TYPE_MASK) == MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsIsPte2SmallPageXN(PTE_T pte2)
|
||||
{
|
||||
return (pte2 & MMU_DESCRIPTOR_L2_TYPE_MASK) == MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE_XN;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsIsPte2LargePage(PTE_T pte2)
|
||||
{
|
||||
return (pte2 & MMU_DESCRIPTOR_L2_TYPE_MASK) == MMU_DESCRIPTOR_L2_TYPE_LARGE_PAGE;
|
||||
}
|
||||
|
||||
STATIC INLINE BOOL OsIsPte2Invalid(PTE_T pte2)
|
||||
{
|
||||
return (pte2 & MMU_DESCRIPTOR_L2_TYPE_MASK) == MMU_DESCRIPTOR_L2_TYPE_INVALID;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __LOS_PTE_OPS_H__ */
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_tlb_v6 MMU TLB v6
|
||||
* @ingroup kernel
|
||||
*/
|
||||
#ifndef __LOS_TLB_V6_H__
|
||||
#define __LOS_TLB_V6_H__
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "menuconfig.h"
|
||||
#include "arm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
STATIC INLINE VOID OsArmInvalidateTlbBarrier(VOID)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
OsArmWriteBpiallis(0);
|
||||
#else
|
||||
OsArmWriteBpiall(0);
|
||||
#endif
|
||||
DSB;
|
||||
ISB;
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsArmInvalidateTlbMvaNoBarrier(VADDR_T va)
|
||||
{
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
OsArmWriteTlbimvaais(va & 0xfffff000);
|
||||
#else
|
||||
OsArmWriteTlbimvaa(va & 0xfffff000);
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsArmInvalidateTlbMvaRangeNoBarrier(VADDR_T start, UINT32 count)
|
||||
{
|
||||
UINT32 index = 0;
|
||||
|
||||
while (count > 0) {
|
||||
OsArmInvalidateTlbMvaNoBarrier(start + (index << MMU_DESCRIPTOR_L2_SMALL_SHIFT));
|
||||
index++;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC INLINE VOID OsCleanTLB(VOID)
|
||||
{
|
||||
UINT32 val = 0;
|
||||
__asm volatile("mcr p15, 0, %0, c8, c7, 0" : : "r"(val));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __LOS_TLB_V6_H__ */
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include "asm.h"
|
||||
|
||||
.fpu vfpv4
|
||||
.arch armv7a
|
||||
.macro DCACHE_LINE_SIZE, reg, tmp
|
||||
mrc p15, 0, \tmp, c0, c0, 1
|
||||
lsr \tmp, \tmp, #16
|
||||
and \tmp, \tmp, #0xf
|
||||
mov \reg, #4
|
||||
mov \reg, \reg, lsl \tmp
|
||||
.endm
|
||||
|
||||
|
||||
FUNCTION(arm_inv_cache_range)
|
||||
push {r2, r3}
|
||||
DCACHE_LINE_SIZE r2, r3
|
||||
sub r3, r2, #1
|
||||
tst r0, r3
|
||||
bic r0, r0, r3
|
||||
|
||||
mcrne p15, 0, r0, c7, c14, 1
|
||||
|
||||
tst r1, r3
|
||||
bic r1, r1, r3
|
||||
mcrne p15, 0, r1, c7, c14, 1
|
||||
1:
|
||||
mcr p15, 0, r0, c7, c6, 1
|
||||
add r0, r0, r2
|
||||
cmp r0, r1
|
||||
blo 1b
|
||||
dsb
|
||||
pop {r2, r3}
|
||||
mov pc, lr
|
||||
|
||||
FUNCTION(arm_clean_cache_range)
|
||||
push {r2, r3}
|
||||
DCACHE_LINE_SIZE r2, r3
|
||||
sub r3, r2, #1
|
||||
bic r0, r0, r3
|
||||
|
||||
1:
|
||||
mcr p15, 0, r0, c7, c10, 1
|
||||
add r0, r0, r2
|
||||
cmp r0, r1
|
||||
blo 1b
|
||||
dsb
|
||||
pop {r2, r3}
|
||||
mov pc, lr
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "asm.h"
|
||||
|
||||
.syntax unified
|
||||
.arm
|
||||
|
||||
// errno_t _arm_get_user(void *dst, const void *src, size_t dstTypeLen, size_t srcTypeLen)
|
||||
FUNCTION(_arm_get_user)
|
||||
stmdb sp!, {r0, r1, r2, r3, lr}
|
||||
cmp r2, #0
|
||||
beq .Lget_user_return
|
||||
cmp r2, r3
|
||||
bne .Lget_user_err
|
||||
cmp r2, #1
|
||||
bhi .Lget_user_half
|
||||
.Lget_user_byte:
|
||||
0: ldrbt r3, [r1], #0
|
||||
1: strb r3, [r0], #0
|
||||
b .Lget_user_return
|
||||
.Lget_user_half:
|
||||
cmp r2, #2
|
||||
bhi .Lget_user_word
|
||||
2: ldrht r3, [r1], #0
|
||||
3: strh r3, [r0], #0
|
||||
b .Lget_user_return
|
||||
.Lget_user_word:
|
||||
cmp r2, #4
|
||||
bhi .Lget_user_err
|
||||
4: ldrt r3, [r1], #0
|
||||
5: str r3, [r0], #0
|
||||
.Lget_user_return:
|
||||
ldmia sp!, {r0, r1, r2, r3, lr}
|
||||
mov r0, 0
|
||||
bx lr
|
||||
.Lget_user_err:
|
||||
ldmia sp!, {r0, r1, r2, r3, lr}
|
||||
mov r0, #-14
|
||||
bx lr
|
||||
|
||||
.pushsection __exc_table, "a"
|
||||
.long 0b, .Lget_user_err
|
||||
.long 1b, .Lget_user_err
|
||||
.long 2b, .Lget_user_err
|
||||
.long 3b, .Lget_user_err
|
||||
.long 4b, .Lget_user_err
|
||||
.long 5b, .Lget_user_err
|
||||
.popsection
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "asm.h"
|
||||
|
||||
.syntax unified
|
||||
.arm
|
||||
|
||||
// errno_t _arm_put_user(void *dst, const void *src, size_t dstTypeLen, size_t srcTypeLen)
|
||||
FUNCTION(_arm_put_user)
|
||||
stmdb sp!, {r0, r1, r2, r3, lr}
|
||||
cmp r2, #0
|
||||
beq .Lget_user_return
|
||||
cmp r2, r3
|
||||
bne .Lget_user_err
|
||||
cmp r2, #1
|
||||
bhi .Lget_user_half
|
||||
.Lget_user_byte:
|
||||
0: ldrb r3, [r1], #0
|
||||
1: strbt r3, [r0], #0
|
||||
b .Lget_user_return
|
||||
.Lget_user_half:
|
||||
cmp r2, #2
|
||||
bhi .Lget_user_word
|
||||
2: ldrh r3, [r1], #0
|
||||
3: strht r3, [r0], #0
|
||||
b .Lget_user_return
|
||||
.Lget_user_word:
|
||||
cmp r2, #4
|
||||
bhi .Lget_user_err
|
||||
4: ldr r3, [r1], #0
|
||||
5: strt r3, [r0], #0
|
||||
.Lget_user_return:
|
||||
ldmia sp!, {r0, r1, r2, r3, lr}
|
||||
mov r0, 0
|
||||
bx lr
|
||||
.Lget_user_err:
|
||||
ldmia sp!, {r0, r1, r2, r3, lr}
|
||||
mov r0, #-14
|
||||
bx lr
|
||||
|
||||
.pushsection __exc_table, "a"
|
||||
.long 0b, .Lget_user_err
|
||||
.long 1b, .Lget_user_err
|
||||
.long 2b, .Lget_user_err
|
||||
.long 3b, .Lget_user_err
|
||||
.long 4b, .Lget_user_err
|
||||
.long 5b, .Lget_user_err
|
||||
.popsection
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __ASM_H
|
||||
#define __ASM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define FUNCTION(x) .global x; .text; .code 32; x:
|
||||
#define MPIDR_CPUID_MASK 0xFFU
|
||||
|
||||
/*
|
||||
* ------------------------------------------
|
||||
* stackTop | cpu n | ... | cpu 1 | cpu 0 | stackBottom
|
||||
* ------------------------------------------
|
||||
* | stackSize | ... | stackSize | stackSize |
|
||||
*/
|
||||
.macro EXC_SP_SET stackBottom, stackSize, reg0, reg1
|
||||
mrc p15, 0, \reg0, c0, c0, 5
|
||||
and \reg0, \reg0, #MPIDR_CPUID_MASK /* get cpu id */
|
||||
mov \reg1, #\stackSize
|
||||
mul \reg1, \reg1, \reg0 /* calculate current cpu stack offset */
|
||||
ldr \reg0, =\stackBottom
|
||||
sub \reg0, \reg0, \reg1 /* calculate current cpu stack bottom */
|
||||
mov sp, \reg0 /* set sp */
|
||||
.endm
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* __ASM_H */
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_EXC_PRI_H
|
||||
#define _LOS_EXC_PRI_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
STATIC INLINE VOID OsSetCurrCpuSp(UINTPTR regSp)
|
||||
{
|
||||
__asm__ __volatile__("mov sp, %0" :: "r"(regSp));
|
||||
}
|
||||
|
||||
#define OS_SYSTEM_NORMAL 0
|
||||
#define OS_SYSTEM_EXC_CURR_CPU 1
|
||||
#define OS_SYSTEM_EXC_OTHER_CPU 2
|
||||
|
||||
extern UINT32 OsGetSystemStatus(VOID);
|
||||
extern VOID BackTraceSub(UINTPTR regFP);
|
||||
extern VOID OsExcInit(VOID);
|
||||
extern VOID OsKillUserProcess(UINTPTR sp);
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_EXC_PRI_H */
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_HW_PRI_H
|
||||
#define _LOS_HW_PRI_H
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_hw.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "los_signal.h"
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if defined(LOSCFG_ARCH_FPU_VFP_D16)
|
||||
#define FP_REGS_NUM 16
|
||||
#elif defined (LOSCFG_ARCH_FPU_VFP_D32)
|
||||
#define FP_REGS_NUM 32
|
||||
#endif
|
||||
#define GEN_REGS_NUM 13
|
||||
|
||||
/* The size of this structure must be smaller than or equal to the size specified by OS_TSK_STACK_ALIGN (16 bytes). */
|
||||
typedef struct {
|
||||
#if !defined(LOSCFG_ARCH_FPU_DISABLE)
|
||||
UINT64 D[FP_REGS_NUM]; /* D0-D31 */
|
||||
UINT32 regFPSCR; /* FPSCR */
|
||||
UINT32 regFPEXC; /* FPEXC */
|
||||
#endif
|
||||
UINT32 resved; /* It's stack 8 aligned */
|
||||
UINT32 regPSR;
|
||||
UINT32 R[GEN_REGS_NUM]; /* R0-R12 */
|
||||
UINT32 SP; /* R13 */
|
||||
UINT32 LR; /* R14 */
|
||||
UINT32 PC; /* R15 */
|
||||
} TaskContext;
|
||||
|
||||
typedef struct {
|
||||
#if !defined(LOSCFG_ARCH_FPU_DISABLE)
|
||||
UINT64 D[FP_REGS_NUM]; /* D0-D31 */
|
||||
UINT32 regFPSCR; /* FPSCR */
|
||||
UINT32 regFPEXC; /* FPEXC */
|
||||
#endif
|
||||
UINT32 resved;
|
||||
TASK_IRQ_CONTEXT
|
||||
} TaskIrqContext;
|
||||
|
||||
/*
|
||||
* Description : task stack initialization
|
||||
* Input : taskID -- task ID
|
||||
* stackSize -- task stack size
|
||||
* topStack -- stack top of task (low address)
|
||||
* Return : pointer to the task context
|
||||
*/
|
||||
extern VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag);
|
||||
extern VOID OsUserCloneParentStack(LosTaskCB *childTaskCB, LosTaskCB *parentTaskCB);
|
||||
extern VOID OsUserTaskStackInit(TaskContext *context, TSK_ENTRY_FUNC taskEntry, UINTPTR stack);
|
||||
extern void arm_clean_cache_range(UINTPTR start, UINTPTR end);
|
||||
extern void arm_inv_cache_range(UINTPTR start, UINTPTR end);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_HW_PRI_H */
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_HWI_PRI_H
|
||||
#define _LOS_HWI_PRI_H
|
||||
|
||||
#include "los_hwi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* The hwi form does not contain exceptions for Aarch32
|
||||
*/
|
||||
#define OS_HWI_FORM_EXC_NUM 0
|
||||
#if OS_HWI_FORM_EXC_NUM != 0
|
||||
#error "OS_HWI_FORM_EXC_NUM must be zero"
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_NO_SHARED_IRQ
|
||||
#define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pfnHook != NULL)
|
||||
#else
|
||||
#define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pstNext != NULL)
|
||||
#endif
|
||||
extern VOID OsHwiInit(VOID);
|
||||
extern VOID OsIncHwiFormCnt(UINT32 index);
|
||||
extern UINT32 OsGetHwiFormCnt(UINT32 index);
|
||||
extern CHAR *OsGetHwiFormName(UINT32 index);
|
||||
extern VOID OsInterrupt(UINT32 intNum);
|
||||
extern VOID SyscallHandleInit(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
#endif /* _LOS_HWI_PRI_H */
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "asm.h"
|
||||
|
||||
FUNCTION(longjmp)
|
||||
ldmfd r0,{r4-r12}
|
||||
add r0,#(4 * 9)
|
||||
ldr r13,[r0]
|
||||
add r0,#4
|
||||
ldr r14,[r0]
|
||||
cmp r1,#0
|
||||
moveq r1,#1
|
||||
mov r0,r1
|
||||
mov pc,lr
|
||||
|
||||
FUNCTION(setjmp)
|
||||
stmea r0,{r4-r12}
|
||||
add r0,#(4 * 9)
|
||||
str r13,[r0]
|
||||
add r0,#4
|
||||
str r14,[r0]
|
||||
mov r0,#0
|
||||
mov pc,lr
|
|
@ -0,0 +1,882 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_arch_mmu architecture mmu
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#include "los_arch_mmu.h"
|
||||
#include "los_asid.h"
|
||||
#include "los_pte_ops.h"
|
||||
#include "los_tlb_v6.h"
|
||||
#include "los_printf.h"
|
||||
#include "los_vm_phys.h"
|
||||
#include "los_vm_common.h"
|
||||
#include "los_vm_map.h"
|
||||
#include "los_vm_boot.h"
|
||||
#include "los_mmu_descriptor_v6.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \
|
||||
__attribute__((section(".bss.prebss.translation_table"))) UINT8 \
|
||||
g_firstPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS];
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \
|
||||
__attribute__((section(".bss.prebss.translation_table"))) UINT8 \
|
||||
g_tempPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS];
|
||||
UINT8 *g_mmuJumpPageTable = g_tempPageTable;
|
||||
#else
|
||||
extern CHAR __mmu_ttlb_begin; /* defined in .ld script */
|
||||
UINT8 *g_mmuJumpPageTable = (UINT8 *)&__mmu_ttlb_begin; /* temp page table, this is only used when system power up */
|
||||
#endif
|
||||
|
||||
STATIC INLINE PTE_T *OsGetPte2BasePtr(PTE_T pte1)
|
||||
{
|
||||
PADDR_T pa = MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(pte1);
|
||||
return LOS_PaddrToKVaddr(pa);
|
||||
}
|
||||
|
||||
STATIC INLINE UINT32 OsUnmapL1Invalid(vaddr_t *vaddr, UINT32 *count)
|
||||
{
|
||||
UINT32 unmapCount;
|
||||
|
||||
unmapCount = MIN2((MMU_DESCRIPTOR_L1_SMALL_SIZE - (*vaddr % MMU_DESCRIPTOR_L1_SMALL_SIZE)) >>
|
||||
MMU_DESCRIPTOR_L2_SMALL_SHIFT, *count);
|
||||
*vaddr += unmapCount << MMU_DESCRIPTOR_L2_SMALL_SHIFT;
|
||||
*count -= unmapCount;
|
||||
|
||||
return unmapCount;
|
||||
}
|
||||
|
||||
STATIC INT32 OsMapParamCheck(UINT32 flags, VADDR_T vaddr, PADDR_T paddr)
|
||||
{
|
||||
#if !WITH_ARCH_MMU_PICK_SPOT
|
||||
if (flags & VM_MAP_REGION_FLAG_NS) {
|
||||
/* WITH_ARCH_MMU_PICK_SPOT is required to support NS memory */
|
||||
LOS_Panic("NS mem is not supported\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(flags & VM_MAP_REGION_FLAG_PERM_READ)) {
|
||||
VM_ERR("miss read flag");
|
||||
return LOS_ERRNO_VM_INVALID_ARGS;
|
||||
}
|
||||
|
||||
/* paddr and vaddr must be aligned */
|
||||
if (!MMU_DESCRIPTOR_IS_L2_SIZE_ALIGNED(vaddr) || !MMU_DESCRIPTOR_IS_L2_SIZE_ALIGNED(paddr)) {
|
||||
return LOS_ERRNO_VM_INVALID_ARGS;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC VOID OsCvtPte2AttsToFlags(PTE_T l1Entry, PTE_T l2Entry, UINT32 *flags)
|
||||
{
|
||||
*flags = 0;
|
||||
/* NS flag is only present on L1 entry */
|
||||
if (l1Entry & MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE) {
|
||||
*flags |= VM_MAP_REGION_FLAG_NS;
|
||||
}
|
||||
|
||||
switch (l2Entry & MMU_DESCRIPTOR_L2_TEX_TYPE_MASK) {
|
||||
case MMU_DESCRIPTOR_L2_TYPE_STRONGLY_ORDERED:
|
||||
*flags |= VM_MAP_REGION_FLAG_UNCACHED;
|
||||
break;
|
||||
case MMU_DESCRIPTOR_L2_TYPE_DEVICE_SHARED:
|
||||
case MMU_DESCRIPTOR_L2_TYPE_DEVICE_NON_SHARED:
|
||||
*flags |= VM_MAP_REGION_FLAG_UNCACHED_DEVICE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_READ;
|
||||
|
||||
switch (l2Entry & MMU_DESCRIPTOR_L2_AP_MASK) {
|
||||
case MMU_DESCRIPTOR_L2_AP_P_RO_U_NA:
|
||||
break;
|
||||
case MMU_DESCRIPTOR_L2_AP_P_RW_U_NA:
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_WRITE;
|
||||
break;
|
||||
case MMU_DESCRIPTOR_L2_AP_P_RO_U_RO:
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_USER;
|
||||
break;
|
||||
case MMU_DESCRIPTOR_L2_AP_P_RW_U_RW:
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ((l2Entry & MMU_DESCRIPTOR_L2_TYPE_MASK) != MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE_XN) {
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_EXECUTE;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC VOID OsPutL2Table(const LosArchMmu *archMmu, UINT32 l1Index, paddr_t l2Paddr)
|
||||
{
|
||||
LosVmPage *vmPage = NULL;
|
||||
UINT32 index;
|
||||
PTE_T ttEntry;
|
||||
/* check if any l1 entry points to this l2 table */
|
||||
for (index = 0; index < MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE; index++) {
|
||||
ttEntry = archMmu->virtTtb[ROUNDDOWN(l1Index, MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE) + index];
|
||||
if ((ttEntry & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* we can free this l2 table */
|
||||
vmPage = LOS_VmPageGet(l2Paddr);
|
||||
if (vmPage == NULL) {
|
||||
LOS_Panic("bad page table paddr %#x\n", l2Paddr);
|
||||
return;
|
||||
}
|
||||
|
||||
LOS_ListDelete(&vmPage->node);
|
||||
LOS_PhysPageFree(vmPage);
|
||||
}
|
||||
|
||||
STATIC VOID OsTryUnmapL1PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 scanIndex, UINT32 scanCount)
|
||||
{
|
||||
/*
|
||||
* Check if all pages related to this l1 entry are deallocated.
|
||||
* We only need to check pages that we did not clear above starting
|
||||
* from page_idx and wrapped around SECTION.
|
||||
*/
|
||||
UINT32 l1Index;
|
||||
PTE_T l1Entry;
|
||||
PTE_T *pte2BasePtr = NULL;
|
||||
|
||||
pte2BasePtr = OsGetPte2BasePtr(OsGetPte1(archMmu->virtTtb, vaddr));
|
||||
if (pte2BasePtr == NULL) {
|
||||
VM_ERR("pte2 base ptr is NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
while (scanCount) {
|
||||
if (scanIndex == MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) {
|
||||
scanIndex = 0;
|
||||
}
|
||||
if (pte2BasePtr[scanIndex++]) {
|
||||
break;
|
||||
}
|
||||
scanCount--;
|
||||
}
|
||||
|
||||
if (!scanCount) {
|
||||
l1Index = OsGetPte1Index(vaddr);
|
||||
l1Entry = archMmu->virtTtb[l1Index];
|
||||
/* we can kill l1 entry */
|
||||
OsClearPte1(&archMmu->virtTtb[l1Index]);
|
||||
OsArmInvalidateTlbMvaNoBarrier(l1Index << MMU_DESCRIPTOR_L1_SMALL_SHIFT);
|
||||
|
||||
/* try to free l2 page itself */
|
||||
OsPutL2Table(archMmu, l1Index, MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(l1Entry));
|
||||
}
|
||||
}
|
||||
|
||||
/* convert user level mmu flags to L1 descriptors flags */
|
||||
STATIC UINT32 OsCvtSecFlagsToAttrs(UINT32 flags)
|
||||
{
|
||||
UINT32 mmuFlags = MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT;
|
||||
switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) {
|
||||
case VM_MAP_REGION_FLAG_CACHED:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_SHAREABLE;
|
||||
#endif
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_WRITE_COMBINING:
|
||||
case VM_MAP_REGION_FLAG_UNCACHED:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED;
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_UNCACHED_DEVICE:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED;
|
||||
break;
|
||||
default:
|
||||
return LOS_ERRNO_VM_INVALID_ARGS;
|
||||
}
|
||||
|
||||
switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE)) {
|
||||
case 0:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RO_U_NA;
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_PERM_WRITE:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RW_U_NA;
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_PERM_USER:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RO_U_RO;
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RW_U_RW;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(flags & VM_MAP_REGION_FLAG_PERM_EXECUTE)) {
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_XN;
|
||||
}
|
||||
|
||||
if (flags & VM_MAP_REGION_FLAG_NS) {
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_NON_SECURE;
|
||||
}
|
||||
|
||||
if (flags & VM_MAP_REGION_FLAG_PERM_USER) {
|
||||
mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_NON_GLOBAL;
|
||||
}
|
||||
|
||||
return mmuFlags;
|
||||
}
|
||||
|
||||
STATIC VOID OsCvtSecAttsToFlags(PTE_T l1Entry, UINT32 *flags)
|
||||
{
|
||||
*flags = 0;
|
||||
if (l1Entry & MMU_DESCRIPTOR_L1_SECTION_NON_SECURE) {
|
||||
*flags |= VM_MAP_REGION_FLAG_NS;
|
||||
}
|
||||
|
||||
switch (l1Entry & MMU_DESCRIPTOR_L1_TEX_TYPE_MASK) {
|
||||
case MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED:
|
||||
*flags |= VM_MAP_REGION_FLAG_UNCACHED;
|
||||
break;
|
||||
case MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED:
|
||||
case MMU_DESCRIPTOR_L1_TYPE_DEVICE_NON_SHARED:
|
||||
*flags |= VM_MAP_REGION_FLAG_UNCACHED_DEVICE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_READ;
|
||||
|
||||
switch (l1Entry & MMU_DESCRIPTOR_L1_AP_MASK) {
|
||||
case MMU_DESCRIPTOR_L1_AP_P_RO_U_NA:
|
||||
break;
|
||||
case MMU_DESCRIPTOR_L1_AP_P_RW_U_NA:
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_WRITE;
|
||||
break;
|
||||
case MMU_DESCRIPTOR_L1_AP_P_RO_U_RO:
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_USER;
|
||||
break;
|
||||
case MMU_DESCRIPTOR_L1_AP_P_RW_U_RW:
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(l1Entry & MMU_DESCRIPTOR_L1_SECTION_XN)) {
|
||||
*flags |= VM_MAP_REGION_FLAG_PERM_EXECUTE;
|
||||
}
|
||||
}
|
||||
|
||||
STATIC UINT32 OsUnmapL2PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 *count)
|
||||
{
|
||||
UINT32 unmapCount;
|
||||
UINT32 pte2Index;
|
||||
PTE_T *pte2BasePtr = NULL;
|
||||
|
||||
pte2BasePtr = OsGetPte2BasePtr(OsGetPte1((PTE_T *)archMmu->virtTtb, vaddr));
|
||||
if (pte2BasePtr == NULL) {
|
||||
LOS_Panic("%s %d, pte2 base ptr is NULL\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
pte2Index = OsGetPte2Index(vaddr);
|
||||
unmapCount = MIN2(MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 - pte2Index, *count);
|
||||
|
||||
/* unmap page run */
|
||||
OsClearPte2Continuous(&pte2BasePtr[pte2Index], unmapCount);
|
||||
|
||||
/* invalidate tlb */
|
||||
OsArmInvalidateTlbMvaRangeNoBarrier(vaddr, unmapCount);
|
||||
|
||||
*count -= unmapCount;
|
||||
return unmapCount;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsUnmapSection(LosArchMmu *archMmu, vaddr_t *vaddr, UINT32 *count)
|
||||
{
|
||||
OsClearPte1(OsGetPte1Ptr((PTE_T *)archMmu->virtTtb, *vaddr));
|
||||
OsArmInvalidateTlbMvaNoBarrier(*vaddr);
|
||||
|
||||
*vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
|
||||
*count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
|
||||
|
||||
return MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
|
||||
}
|
||||
|
||||
|
||||
BOOL OsArchMmuInit(LosArchMmu *archMmu, VADDR_T *virtTtb)
|
||||
{
|
||||
if (OsAllocAsid(&archMmu->asid) != LOS_OK) {
|
||||
VM_ERR("alloc arch mmu asid failed");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
status_t retval = LOS_MuxInit(&archMmu->mtx, NULL);
|
||||
if (retval != LOS_OK) {
|
||||
VM_ERR("Create mutex for arch mmu failed, status: %d", retval);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
LOS_ListInit(&archMmu->ptList);
|
||||
archMmu->virtTtb = virtTtb;
|
||||
archMmu->physTtb = (VADDR_T)(UINTPTR)virtTtb - KERNEL_ASPACE_BASE + SYS_MEM_BASE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STATUS_T LOS_ArchMmuQuery(const LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T *paddr, UINT32 *flags)
|
||||
{
|
||||
PTE_T l1Entry = OsGetPte1(archMmu->virtTtb, vaddr);
|
||||
PTE_T l2Entry;
|
||||
PTE_T* l2Base = NULL;
|
||||
|
||||
if (OsIsPte1Invalid(l1Entry)) {
|
||||
return LOS_ERRNO_VM_NOT_FOUND;
|
||||
} else if (OsIsPte1Section(l1Entry)) {
|
||||
if (paddr != NULL) {
|
||||
*paddr = MMU_DESCRIPTOR_L1_SECTION_ADDR(l1Entry) + (vaddr & (MMU_DESCRIPTOR_L1_SMALL_SIZE - 1));
|
||||
}
|
||||
|
||||
if (flags != NULL) {
|
||||
OsCvtSecAttsToFlags(l1Entry, flags);
|
||||
}
|
||||
} else if (OsIsPte1PageTable(l1Entry)) {
|
||||
l2Base = OsGetPte2BasePtr(l1Entry);
|
||||
if (l2Base == NULL) {
|
||||
return LOS_ERRNO_VM_NOT_FOUND;
|
||||
}
|
||||
l2Entry = OsGetPte2(l2Base, vaddr);
|
||||
if (OsIsPte2SmallPage(l2Entry) || OsIsPte2SmallPageXN(l2Entry)) {
|
||||
if (paddr != NULL) {
|
||||
*paddr = MMU_DESCRIPTOR_L2_SMALL_PAGE_ADDR(l2Entry) + (vaddr & (MMU_DESCRIPTOR_L2_SMALL_SIZE - 1));
|
||||
}
|
||||
|
||||
if (flags != NULL) {
|
||||
OsCvtPte2AttsToFlags(l1Entry, l2Entry, flags);
|
||||
}
|
||||
} else if (OsIsPte2LargePage(l2Entry)) {
|
||||
LOS_Panic("%s %d, large page unimplemented\n", __FUNCTION__, __LINE__);
|
||||
} else {
|
||||
return LOS_ERRNO_VM_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATUS_T LOS_ArchMmuUnmap(LosArchMmu *archMmu, VADDR_T vaddr, size_t count)
|
||||
{
|
||||
PTE_T l1Entry;
|
||||
INT32 unmapped = 0;
|
||||
UINT32 unmapCount = 0;
|
||||
|
||||
while (count > 0) {
|
||||
l1Entry = OsGetPte1(archMmu->virtTtb, vaddr);
|
||||
if (OsIsPte1Invalid(l1Entry)) {
|
||||
unmapCount = OsUnmapL1Invalid(&vaddr, &count);
|
||||
} else if (OsIsPte1Section(l1Entry)) {
|
||||
if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(vaddr) && count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) {
|
||||
unmapCount = OsUnmapSection(archMmu, &vaddr, &count);
|
||||
} else {
|
||||
LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
} else if (OsIsPte1PageTable(l1Entry)) {
|
||||
unmapCount = OsUnmapL2PTE(archMmu, vaddr, &count);
|
||||
OsTryUnmapL1PTE(archMmu, vaddr, OsGetPte2Index(vaddr) + unmapCount,
|
||||
MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 - unmapCount);
|
||||
vaddr += unmapCount << MMU_DESCRIPTOR_L2_SMALL_SHIFT;
|
||||
} else {
|
||||
LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
unmapped += unmapCount;
|
||||
}
|
||||
OsArmInvalidateTlbBarrier();
|
||||
return unmapped;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMapSection(const LosArchMmu *archMmu, UINT32 flags, VADDR_T *vaddr,
|
||||
PADDR_T *paddr, UINT32 *count)
|
||||
{
|
||||
UINT32 mmuFlags = 0;
|
||||
|
||||
mmuFlags |= OsCvtSecFlagsToAttrs(flags);
|
||||
OsSavePte1(OsGetPte1Ptr(archMmu->virtTtb, *vaddr),
|
||||
OsTruncPte1(*paddr) | mmuFlags | MMU_DESCRIPTOR_L1_TYPE_SECTION);
|
||||
*count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
|
||||
*vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
|
||||
*paddr += MMU_DESCRIPTOR_L1_SMALL_SIZE;
|
||||
|
||||
return MMU_DESCRIPTOR_L2_NUMBERS_PER_L1;
|
||||
}
|
||||
|
||||
STATIC STATUS_T OsGetL2Table(LosArchMmu *archMmu, UINT32 l1Index, paddr_t *ppa)
|
||||
{
|
||||
UINT32 index;
|
||||
PTE_T ttEntry;
|
||||
VADDR_T *kvaddr = NULL;
|
||||
LosVmPage *vmPage = NULL;
|
||||
UINT32 l2Offset = (MMU_DESCRIPTOR_L2_SMALL_SIZE / MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE) *
|
||||
(l1Index & (MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE - 1));
|
||||
/* lookup an existing l2 page table */
|
||||
for (index = 0; index < MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE; index++) {
|
||||
ttEntry = archMmu->virtTtb[ROUNDDOWN(l1Index, MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE) + index];
|
||||
if ((ttEntry & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE) {
|
||||
*ppa = (PADDR_T)ROUNDDOWN(MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(ttEntry), MMU_DESCRIPTOR_L2_SMALL_SIZE) +
|
||||
l2Offset;
|
||||
return LOS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* not found: allocate one (paddr) */
|
||||
vmPage = LOS_PhysPageAlloc();
|
||||
if (vmPage == NULL) {
|
||||
VM_ERR("have no memory to save l2 page");
|
||||
return LOS_ERRNO_VM_NO_MEMORY;
|
||||
}
|
||||
LOS_ListAdd(&archMmu->ptList, &vmPage->node);
|
||||
kvaddr = OsVmPageToVaddr(vmPage);
|
||||
(VOID)memset_s(kvaddr, MMU_DESCRIPTOR_L2_SMALL_SIZE, 0, MMU_DESCRIPTOR_L2_SMALL_SIZE);
|
||||
|
||||
/* get physical address */
|
||||
*ppa = LOS_PaddrQuery(kvaddr) + l2Offset;
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID OsMapL1PTE(LosArchMmu *archMmu, PTE_T *pte1Ptr, vaddr_t vaddr, UINT32 flags)
|
||||
{
|
||||
paddr_t pte2Base = 0;
|
||||
|
||||
if (OsGetL2Table(archMmu, OsGetPte1Index(vaddr), &pte2Base) != LOS_OK) {
|
||||
LOS_Panic("%s %d, failed to allocate pagetable\n", __FUNCTION__, __LINE__);
|
||||
}
|
||||
|
||||
*pte1Ptr = pte2Base | MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE;
|
||||
if (flags & VM_MAP_REGION_FLAG_NS) {
|
||||
*pte1Ptr |= MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE;
|
||||
}
|
||||
*pte1Ptr &= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_MASK;
|
||||
*pte1Ptr |= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT; // use client AP
|
||||
OsSavePte1(OsGetPte1Ptr(archMmu->virtTtb, vaddr), *pte1Ptr);
|
||||
}
|
||||
|
||||
/* convert user level mmu flags to L2 descriptors flags */
|
||||
STATIC UINT32 OsCvtPte2FlagsToAttrs(uint32_t flags)
|
||||
{
|
||||
UINT32 mmuFlags = 0;
|
||||
|
||||
switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) {
|
||||
case VM_MAP_REGION_FLAG_CACHED:
|
||||
#if (LOSCFG_KERNEL_SMP == YES)
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_SHAREABLE;
|
||||
#endif
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE;
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_WRITE_COMBINING:
|
||||
case VM_MAP_REGION_FLAG_UNCACHED:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_STRONGLY_ORDERED;
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_UNCACHED_DEVICE:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_DEVICE_SHARED;
|
||||
break;
|
||||
default:
|
||||
return LOS_ERRNO_VM_INVALID_ARGS;
|
||||
}
|
||||
|
||||
switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE)) {
|
||||
case 0:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RO_U_NA;
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_PERM_WRITE:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RW_U_NA;
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_PERM_USER:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RO_U_RO;
|
||||
break;
|
||||
case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE:
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RW_U_RW;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(flags & VM_MAP_REGION_FLAG_PERM_EXECUTE)) {
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE_XN;
|
||||
} else {
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE;
|
||||
}
|
||||
|
||||
if (flags & VM_MAP_REGION_FLAG_PERM_USER) {
|
||||
mmuFlags |= MMU_DESCRIPTOR_L2_NON_GLOBAL;
|
||||
}
|
||||
|
||||
return mmuFlags;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsMapL2PageContinous(PTE_T pte1, UINT32 flags, VADDR_T *vaddr, PADDR_T *paddr, UINT32 *count)
|
||||
{
|
||||
PTE_T *pte2BasePtr = NULL;
|
||||
UINT32 archFlags;
|
||||
UINT32 saveCounts;
|
||||
|
||||
pte2BasePtr = OsGetPte2BasePtr(pte1);
|
||||
if (pte2BasePtr == NULL) {
|
||||
LOS_Panic("%s %d, pte1 %#x error\n", __FUNCTION__, __LINE__, pte1);
|
||||
}
|
||||
|
||||
/* compute the arch flags for L2 4K pages */
|
||||
archFlags = OsCvtPte2FlagsToAttrs(flags);
|
||||
saveCounts = OsSavePte2Continuous(pte2BasePtr, OsGetPte2Index(*vaddr), *paddr | archFlags, *count);
|
||||
*paddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
|
||||
*vaddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT);
|
||||
*count -= saveCounts;
|
||||
return saveCounts;
|
||||
}
|
||||
|
||||
status_t LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_t count, UINT32 flags)
|
||||
{
|
||||
PTE_T l1Entry;
|
||||
UINT32 saveCounts = 0;
|
||||
INT32 mapped = 0;
|
||||
INT32 checkRst;
|
||||
|
||||
checkRst = OsMapParamCheck(flags, vaddr, paddr);
|
||||
if (checkRst < 0) {
|
||||
return checkRst;
|
||||
}
|
||||
|
||||
/* see what kind of mapping we can use */
|
||||
while (count > 0) {
|
||||
if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(vaddr) &&
|
||||
MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(paddr) &&
|
||||
count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) {
|
||||
/* compute the arch flags for L1 sections cache, r ,w ,x, domain and type */
|
||||
saveCounts = OsMapSection(archMmu, flags, &vaddr, &paddr, &count);
|
||||
} else {
|
||||
/* have to use a L2 mapping, we only allocate 4KB for L1, support 0 ~ 1GB */
|
||||
l1Entry = OsGetPte1(archMmu->virtTtb, vaddr);
|
||||
if (OsIsPte1Invalid(l1Entry)) {
|
||||
OsMapL1PTE(archMmu, &l1Entry, vaddr, flags);
|
||||
saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count);
|
||||
} else if (OsIsPte1PageTable(l1Entry)) {
|
||||
saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count);
|
||||
} else {
|
||||
LOS_Panic("%s %d, unimplemented tt_entry %x\n", __FUNCTION__, __LINE__, l1Entry);
|
||||
}
|
||||
}
|
||||
mapped += saveCounts;
|
||||
}
|
||||
|
||||
return mapped;
|
||||
}
|
||||
|
||||
STATUS_T LOS_ArchMmuChangeProt(LosArchMmu *archMmu, VADDR_T vaddr, size_t count, UINT32 flags)
|
||||
{
|
||||
STATUS_T status;
|
||||
PADDR_T paddr = 0;
|
||||
|
||||
if ((archMmu == NULL) || (vaddr == 0) || (count == 0)) {
|
||||
VM_ERR("invalid args: archMmu %p, vaddr %p, count %d", archMmu, vaddr, count);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
count--;
|
||||
status = LOS_ArchMmuQuery(archMmu, vaddr, &paddr, NULL);
|
||||
if (status != LOS_OK) {
|
||||
vaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE;
|
||||
continue;
|
||||
}
|
||||
|
||||
status = LOS_ArchMmuUnmap(archMmu, vaddr, 1);
|
||||
if (status < 0) {
|
||||
VM_ERR("invalid args:aspace %p, vaddr %p, count %d",
|
||||
__FUNCTION__, __LINE__, archMmu, vaddr, count);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
status = LOS_ArchMmuMap(archMmu, vaddr, paddr, 1, flags);
|
||||
if (status < 0) {
|
||||
VM_ERR("invalid args:aspace %p, vaddr %p, count %d",
|
||||
archMmu, vaddr, count);
|
||||
return LOS_NOK;
|
||||
}
|
||||
vaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE;
|
||||
}
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATUS_T LOS_ArchMmuMove(LosArchMmu *archMmu, VADDR_T oldVaddr, VADDR_T newVaddr, size_t count, UINT32 flags)
|
||||
{
|
||||
STATUS_T status;
|
||||
PADDR_T paddr = 0;
|
||||
|
||||
if ((archMmu == NULL) || (oldVaddr == 0) || (newVaddr == 0) || (count == 0)) {
|
||||
VM_ERR("invalid args: archMmu %p, oldVaddr %p, newVddr %p, count %d",
|
||||
archMmu, oldVaddr, newVaddr, count);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
while (count > 0) {
|
||||
count--;
|
||||
status = LOS_ArchMmuQuery(archMmu, oldVaddr, &paddr, NULL);
|
||||
if (status != LOS_OK) {
|
||||
oldVaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE;
|
||||
newVaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE;
|
||||
continue;
|
||||
}
|
||||
// we need to clear the mapping here and remain the phy page.
|
||||
status = LOS_ArchMmuUnmap(archMmu, oldVaddr, 1);
|
||||
if (status < 0) {
|
||||
VM_ERR("invalid args: archMmu %p, vaddr %p, count %d",
|
||||
archMmu, oldVaddr, count);
|
||||
return LOS_NOK;
|
||||
}
|
||||
|
||||
status = LOS_ArchMmuMap(archMmu, newVaddr, paddr, 1, flags);
|
||||
if (status < 0) {
|
||||
VM_ERR("invalid args:archMmu %p, old_vaddr %p, new_addr %p, count %d",
|
||||
archMmu, oldVaddr, newVaddr, count);
|
||||
return LOS_NOK;
|
||||
}
|
||||
oldVaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE;
|
||||
newVaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE;
|
||||
}
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
VOID LOS_ArchMmuContextSwitch(LosArchMmu *archMmu)
|
||||
{
|
||||
UINT32 ttbr;
|
||||
UINT32 ttbcr = OsArmReadTtbcr();
|
||||
if (archMmu) {
|
||||
ttbr = MMU_TTBRx_FLAGS | (archMmu->physTtb);
|
||||
/* enable TTBR0 */
|
||||
ttbcr &= ~MMU_DESCRIPTOR_TTBCR_PD0;
|
||||
} else {
|
||||
ttbr = 0;
|
||||
/* disable TTBR0 */
|
||||
ttbcr |= MMU_DESCRIPTOR_TTBCR_PD0;
|
||||
}
|
||||
|
||||
/* from armv7a arm B3.10.4, we should do synchronization changes of ASID and TTBR. */
|
||||
OsArmWriteContextidr(LOS_GetKVmSpace()->archMmu.asid);
|
||||
ISB;
|
||||
OsArmWriteTtbr0(ttbr);
|
||||
ISB;
|
||||
OsArmWriteTtbcr(ttbcr);
|
||||
ISB;
|
||||
if (archMmu) {
|
||||
OsArmWriteContextidr(archMmu->asid);
|
||||
ISB;
|
||||
}
|
||||
}
|
||||
|
||||
STATUS_T LOS_ArchMmuDestroy(LosArchMmu *archMmu)
|
||||
{
|
||||
LosVmPage *page = NULL;
|
||||
/* free all of the pages allocated in archMmu->ptList */
|
||||
while ((page = LOS_ListRemoveHeadType(&archMmu->ptList, LosVmPage, node)) != NULL) {
|
||||
LOS_PhysPageFree(page);
|
||||
}
|
||||
|
||||
OsArmWriteTlbiasid(archMmu->asid);
|
||||
OsFreeAsid(archMmu->asid);
|
||||
(VOID)LOS_MuxDestroy(&archMmu->mtx);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC VOID OsSwitchTmpTTB(VOID)
|
||||
{
|
||||
PTE_T *tmpTtbase = NULL;
|
||||
errno_t err;
|
||||
LosVmSpace *kSpace = LOS_GetKVmSpace();
|
||||
|
||||
/* ttbr address should be 16KByte align */
|
||||
tmpTtbase = LOS_MemAllocAlign(m_aucSysMem0, MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS,
|
||||
MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS);
|
||||
if (tmpTtbase == NULL) {
|
||||
VM_ERR("memory alloc failed");
|
||||
return;
|
||||
}
|
||||
|
||||
kSpace->archMmu.virtTtb = tmpTtbase;
|
||||
err = memcpy_s(kSpace->archMmu.virtTtb, MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS,
|
||||
g_firstPageTable, MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS);
|
||||
if (err != EOK) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, tmpTtbase);
|
||||
kSpace->archMmu.virtTtb = (VADDR_T *)g_firstPageTable;
|
||||
VM_ERR("memcpy failed, errno: %d", err);
|
||||
return;
|
||||
}
|
||||
kSpace->archMmu.physTtb = LOS_PaddrQuery(kSpace->archMmu.virtTtb);
|
||||
OsArmWriteTtbr0(kSpace->archMmu.physTtb | MMU_TTBRx_FLAGS);
|
||||
ISB;
|
||||
}
|
||||
|
||||
VADDR_T *OsGFirstTableGet()
|
||||
{
|
||||
return (VADDR_T *)g_firstPageTable;
|
||||
}
|
||||
|
||||
STATIC VOID OsSetKSectionAttr(VOID)
|
||||
{
|
||||
/* every section should be page aligned */
|
||||
UINTPTR textStart = (UINTPTR)&__text_start;
|
||||
UINTPTR textEnd = (UINTPTR)&__text_end;
|
||||
UINTPTR rodataStart = (UINTPTR)&__rodata_start;
|
||||
UINTPTR rodataEnd = (UINTPTR)&__rodata_end;
|
||||
UINTPTR ramDataStart = (UINTPTR)&__ram_data_start;
|
||||
UINTPTR bssEnd = (UINTPTR)&__bss_end;
|
||||
UINT32 bssEndBoundary = ROUNDUP(bssEnd, MB);
|
||||
LosArchMmuInitMapping mmuKernelMappings[] = {
|
||||
{
|
||||
.phys = SYS_MEM_BASE + textStart - KERNEL_VMM_BASE,
|
||||
.virt = textStart,
|
||||
.size = ROUNDUP(textEnd - textStart, MMU_DESCRIPTOR_L2_SMALL_SIZE),
|
||||
.flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_EXECUTE,
|
||||
.name = "kernel_text"
|
||||
},
|
||||
{
|
||||
.phys = SYS_MEM_BASE + rodataStart - KERNEL_VMM_BASE,
|
||||
.virt = rodataStart,
|
||||
.size = ROUNDUP(rodataEnd - rodataStart, MMU_DESCRIPTOR_L2_SMALL_SIZE),
|
||||
.flags = VM_MAP_REGION_FLAG_PERM_READ,
|
||||
.name = "kernel_rodata"
|
||||
},
|
||||
{
|
||||
.phys = SYS_MEM_BASE + ramDataStart - KERNEL_VMM_BASE,
|
||||
.virt = ramDataStart,
|
||||
.size = ROUNDUP(bssEndBoundary - ramDataStart, MMU_DESCRIPTOR_L2_SMALL_SIZE),
|
||||
.flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE,
|
||||
.name = "kernel_data_bss"
|
||||
}
|
||||
};
|
||||
LosVmSpace *kSpace = LOS_GetKVmSpace();
|
||||
status_t status;
|
||||
UINT32 length;
|
||||
paddr_t oldTtPhyBase;
|
||||
int i;
|
||||
LosArchMmuInitMapping *kernelMap = NULL;
|
||||
UINT32 kmallocLength;
|
||||
|
||||
/* use second-level mapping of default READ and WRITE */
|
||||
kSpace->archMmu.virtTtb = (PTE_T *)g_firstPageTable;
|
||||
kSpace->archMmu.physTtb = LOS_PaddrQuery(kSpace->archMmu.virtTtb);
|
||||
status = LOS_ArchMmuUnmap(&kSpace->archMmu, KERNEL_VMM_BASE,
|
||||
(bssEndBoundary - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT);
|
||||
if (status != ((bssEndBoundary - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
|
||||
VM_ERR("unmap failed, status: %d", status);
|
||||
return;
|
||||
}
|
||||
|
||||
status = LOS_ArchMmuMap(&kSpace->archMmu, KERNEL_VMM_BASE, SYS_MEM_BASE,
|
||||
(textStart - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
|
||||
VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE |
|
||||
VM_MAP_REGION_FLAG_PERM_EXECUTE);
|
||||
if (status != ((textStart - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
|
||||
VM_ERR("mmap failed, status: %d", status);
|
||||
return;
|
||||
}
|
||||
|
||||
length = sizeof(mmuKernelMappings) / sizeof(LosArchMmuInitMapping);
|
||||
for (i = 0; i < length; i++) {
|
||||
kernelMap = &mmuKernelMappings[i];
|
||||
status = LOS_ArchMmuMap(&kSpace->archMmu, kernelMap->virt, kernelMap->phys,
|
||||
kernelMap->size >> MMU_DESCRIPTOR_L2_SMALL_SHIFT, kernelMap->flags);
|
||||
if (status != (kernelMap->size >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
|
||||
VM_ERR("mmap failed, status: %d", status);
|
||||
return;
|
||||
}
|
||||
LOS_VmSpaceReserve(kSpace, kernelMap->size, kernelMap->virt);
|
||||
}
|
||||
|
||||
kmallocLength = KERNEL_VMM_BASE + SYS_MEM_SIZE_DEFAULT - bssEndBoundary;
|
||||
status = LOS_ArchMmuMap(&kSpace->archMmu, bssEndBoundary,
|
||||
SYS_MEM_BASE + bssEndBoundary - KERNEL_VMM_BASE,
|
||||
kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT,
|
||||
VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE);
|
||||
if (status != (kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) {
|
||||
VM_ERR("unmap failed, status: %d", status);
|
||||
return;
|
||||
}
|
||||
LOS_VmSpaceReserve(kSpace, kmallocLength, bssEndBoundary);
|
||||
|
||||
/* we need free tmp ttbase */
|
||||
oldTtPhyBase = OsArmReadTtbr0();
|
||||
oldTtPhyBase = oldTtPhyBase & MMU_DESCRIPTOR_L2_SMALL_FRAME;
|
||||
OsArmWriteTtbr0(kSpace->archMmu.physTtb | MMU_TTBRx_FLAGS);
|
||||
ISB;
|
||||
|
||||
/* we changed page table entry, so we need to clean TLB here */
|
||||
OsCleanTLB();
|
||||
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, (VOID *)(UINTPTR)(oldTtPhyBase - SYS_MEM_BASE + KERNEL_VMM_BASE));
|
||||
}
|
||||
|
||||
/* disable TTBCR0 and set the split between TTBR0 and TTBR1 */
|
||||
VOID OsArchMmuInitPerCPU(VOID)
|
||||
{
|
||||
UINT32 n = __builtin_clz(KERNEL_ASPACE_BASE) + 1;
|
||||
UINT32 ttbcr = MMU_DESCRIPTOR_TTBCR_PD0 | n;
|
||||
|
||||
OsArmWriteTtbr1(OsArmReadTtbr0());
|
||||
ISB;
|
||||
OsArmWriteTtbcr(ttbcr);
|
||||
ISB;
|
||||
OsArmWriteTtbr0(0);
|
||||
ISB;
|
||||
}
|
||||
|
||||
VOID OsInitMappingStartUp(VOID)
|
||||
{
|
||||
OsArmInvalidateTlbBarrier();
|
||||
|
||||
OsSwitchTmpTTB();
|
||||
|
||||
OsSetKSectionAttr();
|
||||
|
||||
OsArchMmuInitPerCPU();
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_asid mmu address space id
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_asid.h"
|
||||
#include "los_spinlock.h"
|
||||
#include "los_mmu_descriptor_v6.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
STATIC SPIN_LOCK_INIT(g_cpuAsidLock);
|
||||
STATIC UINTPTR g_asidPool[BITMAP_NUM_WORDS(1UL << MMU_ARM_ASID_BITS)];
|
||||
|
||||
/* allocate and free asid */
|
||||
status_t OsAllocAsid(UINT32 *asid)
|
||||
{
|
||||
UINT32 flags;
|
||||
LOS_SpinLockSave(&g_cpuAsidLock, &flags);
|
||||
UINT32 firstZeroBit = LOS_BitmapFfz(g_asidPool, 1UL << MMU_ARM_ASID_BITS);
|
||||
if (firstZeroBit >= 0 && firstZeroBit < (1UL << MMU_ARM_ASID_BITS)) {
|
||||
LOS_BitmapSetNBits(g_asidPool, firstZeroBit, 1);
|
||||
*asid = firstZeroBit;
|
||||
LOS_SpinUnlockRestore(&g_cpuAsidLock, flags);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LOS_SpinUnlockRestore(&g_cpuAsidLock, flags);
|
||||
return firstZeroBit;
|
||||
}
|
||||
|
||||
VOID OsFreeAsid(UINT32 asid)
|
||||
{
|
||||
UINT32 flags;
|
||||
LOS_SpinLockSave(&g_cpuAsidLock, &flags);
|
||||
LOS_BitmapClrNBits(g_asidPool, asid, 1);
|
||||
LOS_SpinUnlockRestore(&g_cpuAsidLock, flags);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,313 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "asm.h"
|
||||
#include "arch_config.h"
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
|
||||
.extern OsLockDepCheckOut
|
||||
#endif
|
||||
.extern g_taskSpin
|
||||
.extern g_percpu
|
||||
.global OsStartToRun
|
||||
.global OsTaskSchedule
|
||||
.global OsIrqHandler
|
||||
.global ArchSpinUnlock
|
||||
.global OsSchedToUserSpinUnlock
|
||||
|
||||
.equ OS_TASK_STATUS_RUNNING, 0x0010U
|
||||
.equ OS_PERCPU_STRUCT_SIZE, 0x28U
|
||||
.equ OS_PERCPU_TASK_LOCK_OFFSET, 0x14U
|
||||
.fpu vfpv4
|
||||
|
||||
/* macros to align and unalign the stack on 8 byte boundary for ABI compliance */
|
||||
.macro STACK_ALIGN, reg
|
||||
MOV \reg, sp
|
||||
TST SP, #4
|
||||
SUBEQ SP, #4
|
||||
PUSH { \reg }
|
||||
.endm
|
||||
|
||||
.macro STACK_RESTORE, reg
|
||||
POP { \reg }
|
||||
MOV sp, \reg
|
||||
.endm
|
||||
|
||||
/* macros to save and restore fpu regs */
|
||||
.macro PUSH_FPU_REGS reg1
|
||||
#if !defined(LOSCFG_ARCH_FPU_DISABLE)
|
||||
VMRS \reg1, FPEXC
|
||||
PUSH {\reg1}
|
||||
VMRS \reg1, FPSCR
|
||||
PUSH {\reg1}
|
||||
#if defined(LOSCFG_ARCH_FPU_VFP_D32)
|
||||
VPUSH {D16-D31}
|
||||
#endif
|
||||
VPUSH {D0-D15}
|
||||
#endif
|
||||
.endm
|
||||
|
||||
.macro POP_FPU_REGS reg1
|
||||
#if !defined(LOSCFG_ARCH_FPU_DISABLE)
|
||||
VPOP {D0-D15}
|
||||
#if defined(LOSCFG_ARCH_FPU_VFP_D32)
|
||||
VPOP {D16-D31}
|
||||
#endif
|
||||
POP {\reg1}
|
||||
VMSR FPSCR, \reg1
|
||||
POP {\reg1}
|
||||
VMSR FPEXC, \reg1
|
||||
#endif
|
||||
.endm
|
||||
|
||||
/* R0: new task */
|
||||
OsStartToRun:
|
||||
|
||||
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE)
|
||||
|
||||
LDRH R1, [R0, #4]
|
||||
ORR R1, #OS_TASK_STATUS_RUNNING
|
||||
STRH R1, [R0, #4]
|
||||
|
||||
/* R0 is new task, save it on tpidrprw */
|
||||
MCR p15, 0, R0, c13, c0, 4
|
||||
ISB
|
||||
|
||||
VPUSH {S0} /* fpu */
|
||||
VPOP {S0}
|
||||
VPUSH {D0}
|
||||
VPOP {D0}
|
||||
|
||||
B OsTaskContextLoad
|
||||
|
||||
/*
|
||||
* R0: new task
|
||||
* R1: run task
|
||||
*/
|
||||
OsTaskSchedule:
|
||||
MRS R2, CPSR
|
||||
STMFD SP!, {LR}
|
||||
STMFD SP!, {LR}
|
||||
/* jump sp */
|
||||
SUB SP, SP, #4
|
||||
|
||||
/* push r0-r12*/
|
||||
STMFD SP!, {R0-R12}
|
||||
STMFD SP!, {R2}
|
||||
|
||||
/* 8 bytes stack align */
|
||||
SUB SP, SP, #4
|
||||
|
||||
/* save fpu registers */
|
||||
PUSH_FPU_REGS R2
|
||||
|
||||
/* store sp on running task */
|
||||
STR SP, [R1]
|
||||
|
||||
OsTaskContextLoad:
|
||||
/* clear the flag of ldrex */
|
||||
CLREX
|
||||
|
||||
/* switch to new task's sp */
|
||||
LDR SP, [R0]
|
||||
|
||||
/* restore fpu registers */
|
||||
POP_FPU_REGS R2
|
||||
|
||||
/* 8 bytes stack align */
|
||||
ADD SP, SP, #4
|
||||
|
||||
LDMFD SP!, {R0}
|
||||
MOV R4, R0
|
||||
AND R0, R0, #CPSR_MASK_MODE
|
||||
CMP R0, #CPSR_USER_MODE
|
||||
BNE OsKernelTaskLoad
|
||||
|
||||
#ifdef LOSCFG_KERNEL_SMP
|
||||
#ifdef LOSCFG_KERNEL_SMP_LOCKDEP
|
||||
/* 8 bytes stack align */
|
||||
SUB SP, SP, #4
|
||||
LDR R0, =g_taskSpin
|
||||
BL OsLockDepCheckOut
|
||||
ADD SP, SP, #4
|
||||
#endif
|
||||
/* R0 = &g_taskSpin.rawLock */
|
||||
LDR R0, =g_taskSpin
|
||||
BL ArchSpinUnlock
|
||||
LDR R2, =g_percpu
|
||||
MRC P15, 0, R3, C0, C0, 5
|
||||
UXTB R3, R3
|
||||
MOV R1, #OS_PERCPU_STRUCT_SIZE
|
||||
MLA R3, R1, R3, R2
|
||||
MOV R2, #0
|
||||
STR R2, [R3, #OS_PERCPU_TASK_LOCK_OFFSET]
|
||||
#endif
|
||||
|
||||
MVN R3, #CPSR_INT_DISABLE
|
||||
AND R4, R4, R3
|
||||
MSR SPSR_cxsf, R4
|
||||
|
||||
/* restore r0-r12, lr */
|
||||
LDMFD SP!, {R0-R12}
|
||||
LDMFD SP, {R13, R14}^
|
||||
ADD SP, SP, #(2 * 4)
|
||||
LDMFD SP!, {PC}^
|
||||
|
||||
OsKernelTaskLoad:
|
||||
MSR SPSR_cxsf, R4
|
||||
/* restore r0-r12, lr */
|
||||
LDMFD SP!, {R0-R12}
|
||||
ADD SP, SP, #4
|
||||
LDMFD SP!, {LR, PC}^
|
||||
|
||||
OsIrqHandler:
|
||||
SUB LR, LR, #4
|
||||
|
||||
/* push r0-r3 to irq stack */
|
||||
STMFD SP, {R0-R3}
|
||||
SUB R0, SP, #(4 * 4)
|
||||
MRS R1, SPSR
|
||||
MOV R2, LR
|
||||
|
||||
/* disable irq, switch to svc mode */
|
||||
CPSID i, #0x13
|
||||
|
||||
/* push spsr and pc in svc stack */
|
||||
STMFD SP!, {R1, R2}
|
||||
STMFD SP, {LR}
|
||||
|
||||
AND R3, R1, #CPSR_MASK_MODE
|
||||
CMP R3, #CPSR_USER_MODE
|
||||
BNE OsIrqFromKernel
|
||||
|
||||
/* push user sp, lr in svc stack */
|
||||
STMFD SP, {R13, R14}^
|
||||
|
||||
OsIrqFromKernel:
|
||||
/* from svc not need save sp and lr */
|
||||
SUB SP, SP, #(2 * 4)
|
||||
|
||||
/* pop r0-r3 form irq stack*/
|
||||
LDMFD R0, {R0-R3}
|
||||
|
||||
/* push caller saved regs as trashed regs in svc stack */
|
||||
STMFD SP!, {R0-R3, R12}
|
||||
|
||||
/* 8 bytes stack align */
|
||||
SUB SP, SP, #4
|
||||
|
||||
/*
|
||||
* save fpu regs in case in case those been
|
||||
* altered in interrupt handlers.
|
||||
*/
|
||||
PUSH_FPU_REGS R0
|
||||
#ifdef LOSCFG_IRQ_USE_STANDALONE_STACK
|
||||
PUSH {R4}
|
||||
MOV R4, SP
|
||||
EXC_SP_SET __svc_stack_top, OS_EXC_SVC_STACK_SIZE, R1, R2
|
||||
#endif
|
||||
|
||||
BLX HalIrqHandler
|
||||
|
||||
#ifdef LOSCFG_IRQ_USE_STANDALONE_STACK
|
||||
MOV SP, R4
|
||||
POP {R4}
|
||||
#endif
|
||||
|
||||
/* process pending signals */
|
||||
BL OsTaskProcSignal
|
||||
|
||||
/* check if needs to schedule */
|
||||
CMP R0, #0
|
||||
BLNE OsSchedPreempt
|
||||
|
||||
MOV R0,SP
|
||||
MOV R1,R7
|
||||
BL OsSaveSignalContextIrq
|
||||
|
||||
/* restore fpu regs */
|
||||
POP_FPU_REGS R0
|
||||
|
||||
ADD SP, SP, #4
|
||||
|
||||
OsIrqContextRestore:
|
||||
LDR R0, [SP, #(4 * 7)]
|
||||
MSR SPSR_cxsf, R0
|
||||
AND R0, R0, #CPSR_MASK_MODE
|
||||
CMP R0, #CPSR_USER_MODE
|
||||
|
||||
LDMFD SP!, {R0-R3, R12}
|
||||
|
||||
BNE OsIrqContextRestoreToKernel
|
||||
|
||||
/* load user sp and lr, and jump cpsr */
|
||||
LDMFD SP, {R13, R14}^
|
||||
ADD SP, SP, #(3 * 4)
|
||||
|
||||
/* return to user mode */
|
||||
LDMFD SP!, {PC}^
|
||||
|
||||
OsIrqContextRestoreToKernel:
|
||||
/* svc mode not load sp */
|
||||
ADD SP, SP, #4
|
||||
LDMFD SP!, {LR}
|
||||
/* jump cpsr and return to svc mode */
|
||||
ADD SP, SP, #4
|
||||
LDMFD SP!, {PC}^
|
||||
|
||||
FUNCTION(ArchSpinLock)
|
||||
mov r1, #1
|
||||
1:
|
||||
ldrex r2, [r0]
|
||||
cmp r2, #0
|
||||
wfene
|
||||
strexeq r2, r1, [r0]
|
||||
cmpeq r2, #0
|
||||
bne 1b
|
||||
dmb
|
||||
bx lr
|
||||
|
||||
FUNCTION(ArchSpinTrylock)
|
||||
mov r1, #1
|
||||
mov r2, r0
|
||||
ldrex r0, [r2]
|
||||
cmp r0, #0
|
||||
strexeq r0, r1, [r2]
|
||||
dmb
|
||||
bx lr
|
||||
|
||||
FUNCTION(ArchSpinUnlock)
|
||||
mov r1, #0
|
||||
dmb
|
||||
str r1, [r0]
|
||||
dsb
|
||||
sev
|
||||
bx lr
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_hw_pri.h"
|
||||
#include "los_task_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* support cpu vendors */
|
||||
CpuVendor g_cpuTable[] = {
|
||||
/* armv7-a */
|
||||
{ 0xc07, "Cortex-A7" },
|
||||
{ 0xc09, "Cortex-A9" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
/* logical cpu mapping */
|
||||
UINT64 g_cpuMap[LOSCFG_KERNEL_CORE_NUM] = {
|
||||
[0 ... LOSCFG_KERNEL_CORE_NUM - 1] = (UINT64)(-1)
|
||||
};
|
||||
|
||||
/* bit[30] is enable FPU */
|
||||
#define FP_EN (1U << 30)
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsTaskExit(VOID)
|
||||
{
|
||||
__asm__ __volatile__("swi 0");
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_GDB
|
||||
STATIC VOID OsTaskEntrySetupLoopFrame(UINT32) __attribute__((noinline, naked));
|
||||
VOID OsTaskEntrySetupLoopFrame(UINT32 arg0)
|
||||
{
|
||||
asm volatile("\tsub fp, sp, #0x4\n"
|
||||
"\tpush {fp, lr}\n"
|
||||
"\tadd fp, sp, #0x4\n"
|
||||
"\tpush {fp, lr}\n"
|
||||
|
||||
"\tadd fp, sp, #0x4\n"
|
||||
"\tbl OsTaskEntry\n"
|
||||
|
||||
"\tpop {fp, lr}\n"
|
||||
"\tpop {fp, pc}\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag)
|
||||
{
|
||||
UINT32 index = 1;
|
||||
TaskContext *taskContext = NULL;
|
||||
|
||||
if (initFlag == TRUE) {
|
||||
OsStackInit(topStack, stackSize);
|
||||
}
|
||||
taskContext = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));
|
||||
|
||||
/* initialize the task context */
|
||||
#ifdef LOSCFG_GDB
|
||||
taskContext->PC = (UINTPTR)OsTaskEntrySetupLoopFrame;
|
||||
#else
|
||||
taskContext->PC = (UINTPTR)OsTaskEntry;
|
||||
#endif
|
||||
taskContext->LR = (UINTPTR)OsTaskExit; /* LR should be kept, to distinguish it's THUMB or ARM instruction */
|
||||
taskContext->resved = 0x0;
|
||||
taskContext->R[0] = taskID; /* R0 */
|
||||
taskContext->R[index++] = 0x01010101; /* R1, 0x01010101 : reg initialed magic word */
|
||||
for (; index < GEN_REGS_NUM; index++) {
|
||||
taskContext->R[index] = taskContext->R[index - 1] + taskContext->R[1]; /* R2 - R12 */
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_INTERWORK_THUMB
|
||||
taskContext->regPSR = PSR_MODE_SVC_THUMB; /* CPSR (Enable IRQ and FIQ interrupts, THUMNB-mode) */
|
||||
#else
|
||||
taskContext->regPSR = PSR_MODE_SVC_ARM; /* CPSR (Enable IRQ and FIQ interrupts, ARM-mode) */
|
||||
#endif
|
||||
|
||||
#if !defined(LOSCFG_ARCH_FPU_DISABLE)
|
||||
/* 0xAAA0000000000000LL : float reg initialed magic word */
|
||||
for (index = 0; index < FP_REGS_NUM; index++) {
|
||||
taskContext->D[index] = 0xAAA0000000000000LL + index; /* D0 - D31 */
|
||||
}
|
||||
taskContext->regFPSCR = 0;
|
||||
taskContext->regFPEXC = FP_EN;
|
||||
#endif
|
||||
|
||||
return (VOID *)taskContext;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT VOID OsUserCloneParentStack(LosTaskCB *childTaskCB, LosTaskCB *parentTaskCB)
|
||||
{
|
||||
TaskContext *context = (TaskContext *)childTaskCB->stackPointer;
|
||||
VOID *cloneStack = (VOID *)(((UINTPTR)parentTaskCB->topOfStack + parentTaskCB->stackSize) - sizeof(TaskContext));
|
||||
|
||||
LOS_ASSERT(parentTaskCB->taskStatus & OS_TASK_STATUS_RUNNING);
|
||||
|
||||
(VOID)memcpy_s(childTaskCB->stackPointer, sizeof(TaskContext), cloneStack, sizeof(TaskContext));
|
||||
context->R[0] = 0;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsUserTaskStackInit(TaskContext *context, TSK_ENTRY_FUNC taskEntry, UINTPTR stack)
|
||||
{
|
||||
LOS_ASSERT(context != NULL);
|
||||
|
||||
#ifdef LOSCFG_INTERWORK_THUMB
|
||||
context->regPSR = PSR_MODE_USR_THUMB;
|
||||
#else
|
||||
context->regPSR = PSR_MODE_USR_ARM;
|
||||
#endif
|
||||
context->R[0] = stack;
|
||||
context->SP = TRUNCATE(stack, LOSCFG_STACK_POINT_ALIGN_SIZE);
|
||||
context->LR = 0;
|
||||
context->PC = (UINTPTR)taskEntry;
|
||||
}
|
||||
|
||||
VOID Sev(VOID)
|
||||
{
|
||||
__asm__ __volatile__ ("sev" : : : "memory");
|
||||
}
|
||||
|
||||
VOID Wfe(VOID)
|
||||
{
|
||||
__asm__ __volatile__ ("wfe" : : : "memory");
|
||||
}
|
||||
|
||||
VOID Wfi(VOID)
|
||||
{
|
||||
__asm__ __volatile__ ("wfi" : : : "memory");
|
||||
}
|
||||
|
||||
VOID Dmb(VOID)
|
||||
{
|
||||
__asm__ __volatile__ ("dmb" : : : "memory");
|
||||
}
|
||||
|
||||
VOID Dsb(VOID)
|
||||
{
|
||||
__asm__ __volatile__("dsb" : : : "memory");
|
||||
}
|
||||
|
||||
VOID Isb(VOID)
|
||||
{
|
||||
__asm__ __volatile__("isb" : : : "memory");
|
||||
}
|
||||
|
||||
VOID FlushICache(VOID)
|
||||
{
|
||||
/*
|
||||
* Use ICIALLUIS instead of ICIALLU. ICIALLUIS operates on all processors in the Inner
|
||||
* shareable domain of the processor that performs the operation.
|
||||
*/
|
||||
__asm__ __volatile__ ("mcr p15, 0, %0, c7, c1, 0" : : "r" (0) : "memory");
|
||||
}
|
||||
|
||||
VOID DCacheFlushRange(UINT32 start, UINT32 end)
|
||||
{
|
||||
arm_clean_cache_range(start, end);
|
||||
}
|
||||
|
||||
VOID DCacheInvRange(UINT32 start, UINT32 end)
|
||||
{
|
||||
arm_inv_cache_range(start, end);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,412 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "asm.h"
|
||||
#include "arch_config.h"
|
||||
|
||||
.extern g_losTask
|
||||
.extern g_intCount
|
||||
.extern g_curNestCount
|
||||
.extern OsExcHandleEntry
|
||||
.extern __svc_stack_top
|
||||
.extern __exc_stack_top
|
||||
.extern __stack_chk_guard
|
||||
.extern OsRandomStackGuard
|
||||
#ifdef LOSCFG_GDB
|
||||
.extern OsUndefIncExcHandleEntry
|
||||
#if __LINUX_ARM_ARCH__ >= 7
|
||||
.extern OsPrefetchAbortExcHandleEntry
|
||||
.extern OsDataAbortExcHandleEntry
|
||||
#endif
|
||||
#endif
|
||||
.extern OsArmSharedPageFault
|
||||
.extern OsArmA32SyscallHandle
|
||||
.extern LOS_Exit
|
||||
|
||||
.global _osExceptFiqHdl
|
||||
.global _osExceptAddrAbortHdl
|
||||
.global _osExceptDataAbortHdl
|
||||
.global _osExceptPrefetchAbortHdl
|
||||
.global _osExceptSwiHdl
|
||||
.global _osExceptUndefInstrHdl
|
||||
.global __stack_chk_guard_setup
|
||||
|
||||
|
||||
.fpu vfpv4
|
||||
|
||||
.macro PUSH_FPU_REGS reg1
|
||||
#if !defined(LOSCFG_ARCH_FPU_DISABLE)
|
||||
VMRS \reg1, FPEXC
|
||||
PUSH {\reg1}
|
||||
VMRS \reg1, FPSCR
|
||||
PUSH {\reg1}
|
||||
#if defined(LOSCFG_ARCH_FPU_VFP_D32)
|
||||
VPUSH {D16-D31}
|
||||
#endif
|
||||
VPUSH {D0-D15}
|
||||
#endif
|
||||
.endm
|
||||
|
||||
.macro POP_FPU_REGS reg1
|
||||
#if !defined(LOSCFG_ARCH_FPU_DISABLE)
|
||||
VPOP {D0-D15}
|
||||
#if defined(LOSCFG_ARCH_FPU_VFP_D32)
|
||||
VPOP {D16-D31}
|
||||
#endif
|
||||
POP {\reg1}
|
||||
VMSR FPSCR, \reg1
|
||||
POP {\reg1}
|
||||
VMSR FPEXC, \reg1
|
||||
#endif
|
||||
.endm
|
||||
|
||||
#ifdef LOSCFG_GDB
|
||||
.macro GDB_HANDLE fun
|
||||
SUB SP, SP, #12
|
||||
|
||||
STMFD SP!, {R0-R12}
|
||||
MRS R1, SPSR
|
||||
STMFD SP!, {R1} @save spsr
|
||||
|
||||
ADD R0, SP, #14 * 4
|
||||
MOV R3, LR @save pc
|
||||
|
||||
MRS R1, CPSR
|
||||
MRS R2, SPSR
|
||||
MOV R4, SP
|
||||
|
||||
ORR R2, R2, #(CPSR_INT_DISABLE)
|
||||
MSR CPSR_c, R2
|
||||
|
||||
STR SP, [R0] @SP
|
||||
STR LR, [R0, #4] @LR
|
||||
STR R3, [R0, #8] @PC
|
||||
|
||||
ORR R1, R1, #(CPSR_INT_DISABLE)
|
||||
BIC R1, R1, #OS_PSR_THUMB
|
||||
MSR CPSR_c, R1
|
||||
MOV R0, R4
|
||||
|
||||
BL \fun
|
||||
|
||||
ADD SP, SP, #4
|
||||
LDMFD SP!, {R0-R12}
|
||||
|
||||
MOV R0, SP
|
||||
ADD SP, SP, #8
|
||||
|
||||
LDR R1, [R0, #8] @get pc
|
||||
STMFD SP!, {R1}
|
||||
|
||||
AND R1, R1, #0x03
|
||||
CMP R1, #0
|
||||
BEQ 1f
|
||||
LDR R1, [R0, #-14 * 4]
|
||||
ORR R1, R1, #OS_PSR_THUMB
|
||||
B 2f
|
||||
1:
|
||||
LDR R1, [R0, #-14 * 4]
|
||||
|
||||
2:
|
||||
MSR SPSR, R1
|
||||
|
||||
LDR R1, [R0, #-12 * 4] @get R1
|
||||
STMFD SP!, {R1}
|
||||
LDR R1, [R0,#-13 * 4] @get R0
|
||||
STMFD SP!, {R1}
|
||||
|
||||
LDMFD SP!, {R0-R1, PC}^
|
||||
.endm
|
||||
#endif
|
||||
|
||||
@ Description: Stack-Protector Init
|
||||
__stack_chk_guard_setup:
|
||||
PUSH {FP, LR}
|
||||
BL OsRandomStackGuard
|
||||
LDR R1, =__stack_chk_guard
|
||||
MOV R3, R0
|
||||
ORR R2, R3, #0X80000000
|
||||
STR R2, [R1]
|
||||
POP {FP, PC}
|
||||
|
||||
@ Description: Undefined instruction exception handler
|
||||
_osExceptUndefInstrHdl:
|
||||
#ifdef LOSCFG_GDB
|
||||
GDB_HANDLE OsUndefIncExcHandleEntry
|
||||
#else
|
||||
@ LR offset to return from this exception: 0.
|
||||
STMFD SP, {R0-R7} @ Push working registers, but don`t change SP.
|
||||
|
||||
MOV R0, #OS_EXCEPT_UNDEF_INSTR @ Set exception ID to OS_EXCEPT_UNDEF_INSTR.
|
||||
|
||||
B _osExceptDispatch @ Branch to global exception handler.
|
||||
|
||||
#endif
|
||||
|
||||
@ Description: Software interrupt exception handler
|
||||
_osExceptSwiHdl:
|
||||
SUB SP, SP, #(4 * 16)
|
||||
STMIA SP, {R0-R12}
|
||||
MRS R3, SPSR
|
||||
MOV R4, LR
|
||||
|
||||
AND R1, R3, #CPSR_MASK_MODE @ Interrupted mode
|
||||
CMP R1, #CPSR_USER_MODE @ User mode
|
||||
BNE OsKernelSVCHandler @ Branch if not user mode
|
||||
|
||||
@ we enter from user mode, we need get the values of USER mode r13(sp) and r14(lr).
|
||||
@ stmia with ^ will return the user mode registers (provided that r15 is not in the register list).
|
||||
MOV R0, SP
|
||||
STMFD SP!, {R3} @ Save the CPSR
|
||||
ADD R3, SP, #(4 * 17) @ Offset to pc/cpsr storage
|
||||
STMFD R3!, {R4} @ Save the CPSR and r15(pc)
|
||||
STMFD R3, {R13, R14}^ @ Save user mode r13(sp) and r14(lr)
|
||||
SUB SP, SP, #4
|
||||
PUSH_FPU_REGS R1
|
||||
|
||||
MOV FP, #0 @ Init frame pointer
|
||||
CPSIE I
|
||||
BLX OsArmA32SyscallHandle
|
||||
CPSID I
|
||||
|
||||
POP_FPU_REGS R1
|
||||
ADD SP, SP,#4
|
||||
LDMFD SP!, {R3} @ Fetch the return SPSR
|
||||
MSR SPSR_cxsf, R3 @ Set the return mode SPSR
|
||||
|
||||
@ we are leaving to user mode, we need to restore the values of USER mode r13(sp) and r14(lr).
|
||||
@ ldmia with ^ will return the user mode registers (provided that r15 is not in the register list)
|
||||
|
||||
LDMFD SP!, {R0-R12}
|
||||
LDMFD SP, {R13, R14}^ @ Restore user mode R13/R14
|
||||
ADD SP, SP, #(2 * 4)
|
||||
LDMFD SP!, {PC}^ @ Return to user
|
||||
|
||||
OsKernelSVCHandler:
|
||||
ADD R0, SP, #(4 * 16)
|
||||
MOV R5, R0
|
||||
STMFD R0!, {R4} @ Store PC
|
||||
STMFD R0!, {R4}
|
||||
STMFD R0!, {R5}
|
||||
|
||||
STMFD SP!, {R3} @ Push task`s CPSR (i.e. exception SPSR).
|
||||
SUB SP, SP, #(4 * 2) @ user sp and lr
|
||||
|
||||
MOV R0, #OS_EXCEPT_SWI @ Set exception ID to OS_EXCEPT_SWI.
|
||||
|
||||
B _osExceptionSwi @ Branch to global exception handler.
|
||||
|
||||
@ Description: Prefectch abort exception handler
|
||||
_osExceptPrefetchAbortHdl:
|
||||
#ifdef LOSCFG_GDB
|
||||
#if __LINUX_ARM_ARCH__ >= 7
|
||||
GDB_HANDLE OsPrefetchAbortExcHandleEntry
|
||||
#endif
|
||||
#else
|
||||
SUB LR, LR, #4 @ LR offset to return from this exception: -4.
|
||||
STMFD SP, {R0-R7} @ Push working registers, but don`t change SP.
|
||||
MOV R5, LR
|
||||
MRS R1, SPSR
|
||||
|
||||
MOV R0, #OS_EXCEPT_PREFETCH_ABORT @ Set exception ID to OS_EXCEPT_PREFETCH_ABORT.
|
||||
|
||||
AND R4, R1, #CPSR_MASK_MODE @ Interrupted mode
|
||||
CMP R4, #CPSR_USER_MODE @ User mode
|
||||
BEQ _osExcPageFault @ Branch if user mode
|
||||
|
||||
_osKernelExceptPrefetchAbortHdl:
|
||||
MOV LR, R5
|
||||
B _osExceptDispatch @ Branch to global exception handler.
|
||||
#endif
|
||||
|
||||
@ Description: Data abort exception handler
|
||||
_osExceptDataAbortHdl:
|
||||
#ifdef LOSCFG_GDB
|
||||
#if __LINUX_ARM_ARCH__ >= 7
|
||||
GDB_HANDLE OsDataAbortExcHandleEntry
|
||||
#endif
|
||||
#else
|
||||
SUB LR, LR, #8 @ LR offset to return from this exception: -8.
|
||||
STMFD SP, {R0-R7} @ Push working registers, but don`t change SP.
|
||||
MOV R5, LR
|
||||
MRS R1, SPSR
|
||||
|
||||
MOV R0, #OS_EXCEPT_DATA_ABORT @ Set exception ID to OS_EXCEPT_DATA_ABORT.
|
||||
|
||||
B _osExcPageFault
|
||||
#endif
|
||||
|
||||
@ Description: Address abort exception handler
|
||||
_osExceptAddrAbortHdl:
|
||||
SUB LR, LR, #8 @ LR offset to return from this exception: -8.
|
||||
STMFD SP, {R0-R7} @ Push working registers, but don`t change SP.
|
||||
|
||||
MOV R0, #OS_EXCEPT_ADDR_ABORT @ Set exception ID to OS_EXCEPT_ADDR_ABORT.
|
||||
|
||||
B _osExceptDispatch @ Branch to global exception handler.
|
||||
|
||||
@ Description: Fast interrupt request exception handler
|
||||
_osExceptFiqHdl:
|
||||
SUB LR, LR, #4 @ LR offset to return from this exception: -4.
|
||||
STMFD SP, {R0-R7} @ Push working registers.
|
||||
|
||||
MOV R0, #OS_EXCEPT_FIQ @ Set exception ID to OS_EXCEPT_FIQ.
|
||||
|
||||
B _osExceptDispatch @ Branch to global exception handler.
|
||||
|
||||
_osExcPageFault:
|
||||
SUB R3, SP, #(8 * 4) @ Save the start address of working registers.
|
||||
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to SVC mode, and disable all interrupts
|
||||
MOV R2, SP
|
||||
STMFD SP!, {R5} @ Push original PC
|
||||
STMFD SP!, {LR} @ Push original svc LR
|
||||
STMFD SP!, {R2} @ Push original svc SP
|
||||
STMFD SP!, {R8-R12} @ Push original R12-R8,
|
||||
LDMFD R3!, {R4-R11} @ Move original R7-R0 from exception stack to original stack.
|
||||
STMFD SP!, {R4-R11}
|
||||
STMFD SP!, {R1}
|
||||
SUB SP, SP, #8
|
||||
STMIA SP, {R13, R14}^ @ Save user mode r13(sp) and r14(lr)
|
||||
|
||||
MOV R4, SP
|
||||
BIC SP, SP, #7
|
||||
PUSH_FPU_REGS R1
|
||||
|
||||
CMP R0, #OS_EXCEPT_DATA_ABORT
|
||||
BNE 1f
|
||||
MRC P15, 0, R2, C6, C0, 0
|
||||
MRC P15, 0, R3, C5, C0, 0
|
||||
B 2f
|
||||
1: MRC P15, 0, R2, C6, C0, 2
|
||||
MRC P15, 0, R3, C5, C0, 1
|
||||
|
||||
2: MOV R1, R4
|
||||
MOV R5, R0
|
||||
MOV R8, R2
|
||||
MOV R9, R3
|
||||
CPSIE I
|
||||
BLX OsArmSharedPageFault
|
||||
CPSID I
|
||||
|
||||
POP_FPU_REGS R1
|
||||
MOV SP, R4
|
||||
CMP R0, #0
|
||||
BEQ _OsExcReturn
|
||||
|
||||
MOV R0, R5 @ exc type
|
||||
B _osExceptionSwi
|
||||
|
||||
@ Description: Exception handler
|
||||
@ Parameter : R0 Exception Type
|
||||
@ Regs Hold : R3 Exception`s CPSR
|
||||
_osExceptDispatch:
|
||||
MRS R2, SPSR @ Save CPSR before exception.
|
||||
MOV R1, LR @ Save PC before exception.
|
||||
SUB R3, SP, #(8 * 4) @ Save the start address of working registers.
|
||||
|
||||
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to SVC mode, and disable all interrupts
|
||||
MOV R5, SP
|
||||
EXC_SP_SET __exc_stack_top, OS_EXC_STACK_SIZE, R6, R7
|
||||
|
||||
STMFD SP!, {R1} @ Push Exception PC
|
||||
STMFD SP!, {LR} @ Push SVC LR
|
||||
STMFD SP!, {R5} @ Push SVC SP
|
||||
STMFD SP!, {R8-R12} @ Push original R12-R8,
|
||||
LDMFD R3!, {R4-R11} @ Move original R7-R0 from exception stack to original stack.
|
||||
STMFD SP!, {R4-R11}
|
||||
STMFD SP!, {R2} @ Push task`s CPSR (i.e. exception SPSR).
|
||||
|
||||
CMP R0, #OS_EXCEPT_DATA_ABORT
|
||||
BNE 1f
|
||||
MRC P15, 0, R8, C6, C0, 0
|
||||
MRC P15, 0, R9, C5, C0, 0
|
||||
B 3f
|
||||
1: CMP R0, #OS_EXCEPT_PREFETCH_ABORT
|
||||
BNE 2f
|
||||
MRC P15, 0, R8, C6, C0, 2
|
||||
MRC P15, 0, R9, C5, C0, 1
|
||||
B 3f
|
||||
2: MOV R8, #0
|
||||
MOV R9, #0
|
||||
|
||||
3: AND R2, R2, #CPSR_MASK_MODE
|
||||
CMP R2, #CPSR_USER_MODE @ User mode
|
||||
BNE 4f
|
||||
STMFD SP, {R13, R14}^ @ save user mode sp and lr
|
||||
4:
|
||||
SUB SP, SP, #(4 * 2)
|
||||
|
||||
_osExceptionSwi:
|
||||
MOV R1, SP @ The second argument to the exception
|
||||
|
||||
MRC P15, 0, R4, C0, C0, 5
|
||||
AND R4, R4, #MPIDR_CPUID_MASK @ Get Current cpu id
|
||||
LSL R2, R4, #2
|
||||
LDR R3, =g_curNestCount @ if(g_curNestCount > 0) dump to _osExceptionGetSP
|
||||
ADD R3, R3, R2
|
||||
LDR R4, [R3]
|
||||
|
||||
CMP R4, #0
|
||||
BNE _osExceptionGetSP
|
||||
|
||||
LDR R3, =g_intCount @ Judge the exception is occur in task stack or system stack
|
||||
ADD R3, R3, R2
|
||||
LDR R4, [R3]
|
||||
|
||||
CMP R4, #0 @ if (g_intCount[ArchCurrCpuid()] > 0)
|
||||
BNE _osExceptionGetSP @ can not switch svc stack
|
||||
|
||||
EXC_SP_SET __svc_stack_top, OS_EXC_SVC_STACK_SIZE, R6, R7 @ Switch to unified exception stack.
|
||||
ADD R4, R4, #1
|
||||
STR R4, [R3]
|
||||
|
||||
_osExceptionGetSP:
|
||||
MOV R2, R8 @ far
|
||||
MOV R3, R9 @ fsr
|
||||
LDR R5, =OsExcHandleEntry @ OsExcHandleEntry(UINT32 excType, ExcContext * excBufAddr)
|
||||
BX R5
|
||||
|
||||
_OsExcReturn:
|
||||
LDR R0, [SP, #(2 * 4)]
|
||||
AND R0, R0, #CPSR_MASK_MODE
|
||||
CMP R0, #CPSR_USER_MODE @ User mode
|
||||
BNE _OsExcReturnToKernel
|
||||
LDMFD SP, {R13, R14}^ @ load user mode sp and lr
|
||||
|
||||
_OsExcReturnToKernel:
|
||||
ADD SP, SP, #(2 * 4)
|
||||
LDMFD SP!, {R1}
|
||||
MSR SPSR_cxsf, R1 @ Set the return mode SPSR
|
||||
LDMFD SP!, {R0-R12}
|
||||
ADD SP, SP, #4
|
||||
LDMFD SP!, {LR, PC}^
|
||||
|
||||
.end
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "arch_config.h"
|
||||
|
||||
.equ MPIDR_CPUID_MASK, 0xffU
|
||||
|
||||
.extern g_saveAR
|
||||
.extern g_saveSRContext
|
||||
|
||||
.global OsSRSaveRegister
|
||||
.global OsSRRestoreRegister
|
||||
|
||||
.fpu vfpv4
|
||||
@.fpu neon
|
||||
.arch armv7a
|
||||
|
||||
.text
|
||||
|
||||
OsSRSaveRegister:
|
||||
PUSH {R2}
|
||||
LDR R2, =g_saveAR
|
||||
STR R0, [R2]
|
||||
STR R1, [R2, #4]
|
||||
POP {R2}
|
||||
|
||||
MRC P15, 0, R0, c0, c0, 5
|
||||
AND R0, R0, #MPIDR_CPUID_MASK
|
||||
MOV R1, #72 @This number is the total number of bytes in the task context register(R0~R15, SPSR, CPSR).
|
||||
MUL R1, R1, R0
|
||||
|
||||
LDR R0, =g_saveSRContext
|
||||
ADD R0, R0, R1
|
||||
ADD R0, R0, #72
|
||||
|
||||
MOV R1, SP
|
||||
STMFD R0!, {R1}
|
||||
|
||||
MRS R1, SPSR
|
||||
STMFD R0!, {R1}
|
||||
|
||||
MOV R1, LR
|
||||
STMFD R0!, {R1} @PC
|
||||
STMFD R0!, {R1} @LR
|
||||
|
||||
STMFD R0!, {R12}
|
||||
|
||||
MOV R12, R0
|
||||
|
||||
LDR R0, =g_saveAR
|
||||
LDR R0, [R0]
|
||||
LDR R1, =g_saveAR
|
||||
LDR R1, [R1, #4]
|
||||
|
||||
STMFD R12!, {R0-R3}
|
||||
STMFD R12!, {R4-R11}
|
||||
|
||||
MRS R0, CPSR
|
||||
STMFD R12!, {R0}
|
||||
|
||||
BX LR
|
||||
|
||||
OsSRRestoreRegister:
|
||||
MRC P15, 0, R0, c0, c0, 5
|
||||
AND R0, R0, #MPIDR_CPUID_MASK
|
||||
MOV R1, #72 @This number is the total number of bytes in the task context register(R0~R15, SPSR, CPSR).
|
||||
MUL R1, R1, R0
|
||||
|
||||
LDR R12, =g_saveSRContext
|
||||
ADD R12, R12, R1
|
||||
|
||||
LDMFD R12!, {R0}
|
||||
MSR CPSR_cxsf, R0
|
||||
|
||||
LDMFD R12!, {R4-R11}
|
||||
LDMFD R12!, {R0-R3}
|
||||
|
||||
PUSH {R2}
|
||||
LDR R2, =g_saveAR
|
||||
STR R0, [R2]
|
||||
STR R1, [R2, #4]
|
||||
POP {R2}
|
||||
|
||||
MOV R0, R12
|
||||
LDMFD R0!, {R12}
|
||||
LDMFD R0!, {R1} @LR
|
||||
LDMFD R0!, {R1} @PC
|
||||
|
||||
MOV LR, R1
|
||||
|
||||
LDMFD R0!, {R1}
|
||||
MSR SPSR_cxsf, R1
|
||||
|
||||
LDMFD R0!, {R1}
|
||||
MOV SP, R1
|
||||
|
||||
LDR R0, =g_saveAR
|
||||
LDR R0, [R0]
|
||||
LDR R1, =g_saveAR
|
||||
LDR R1, [R1, #4]
|
||||
|
||||
BX LR
|
||||
|
||||
.end
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_sys_pri.h"
|
||||
#include "los_hwi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond)
|
||||
{
|
||||
if ((systemClock == 0) ||
|
||||
(tickPerSecond == 0) ||
|
||||
(tickPerSecond > systemClock)) {
|
||||
return LOS_ERRNO_TICK_CFG_INVALID;
|
||||
}
|
||||
HalClockInit();
|
||||
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsTickStart(VOID)
|
||||
{
|
||||
HalClockStart();
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt)
|
||||
{
|
||||
UINT64 cycle = HalClockGetCycles();
|
||||
|
||||
*highCnt = cycle >> 32; /* 32: offset 32 bits and retain high bits */
|
||||
*lowCnt = cycle & 0xFFFFFFFFU;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID)
|
||||
{
|
||||
DOUBLE nanos;
|
||||
|
||||
nanos = (DOUBLE)HalClockGetCycles() * OS_SYS_NS_PER_SECOND / g_sysClock;
|
||||
return (UINT64)nanos;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID LOS_Udelay(UINT32 usecs)
|
||||
{
|
||||
HalDelayUs(usecs);
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_MINOR VOID LOS_Mdelay(UINT32 msecs)
|
||||
{
|
||||
HalDelayUs(msecs * 1000); /* 1000 : 1ms = 1000us */
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,351 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_hwi.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_tickless_pri.h"
|
||||
#include "los_spinlock.h"
|
||||
#ifdef LOSCFG_KERNEL_CPUP
|
||||
#include "los_cpup_pri.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* spinlock for hwi module, only available on SMP mode */
|
||||
LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_hwiSpin);
|
||||
#define HWI_LOCK(state) LOS_SpinLockSave(&g_hwiSpin, &(state))
|
||||
#define HWI_UNLOCK(state) LOS_SpinUnlockRestore(&g_hwiSpin, (state))
|
||||
|
||||
size_t g_intCount[LOSCFG_KERNEL_CORE_NUM] = {0};
|
||||
HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM];
|
||||
STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0};
|
||||
STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0};
|
||||
|
||||
VOID OsIncHwiFormCnt(UINT32 index)
|
||||
{
|
||||
g_hwiFormCnt[index]++;
|
||||
}
|
||||
|
||||
UINT32 OsGetHwiFormCnt(UINT32 index)
|
||||
{
|
||||
return g_hwiFormCnt[index];
|
||||
}
|
||||
|
||||
CHAR *OsGetHwiFormName(UINT32 index)
|
||||
{
|
||||
return g_hwiFormName[index];
|
||||
}
|
||||
|
||||
typedef VOID (*HWI_PROC_FUNC0)(VOID);
|
||||
typedef VOID (*HWI_PROC_FUNC2)(INT32, VOID *);
|
||||
VOID OsInterrupt(UINT32 intNum)
|
||||
{
|
||||
HwiHandleForm *hwiForm = NULL;
|
||||
UINT32 *intCnt = NULL;
|
||||
|
||||
intCnt = &g_intCount[ArchCurrCpuid()];
|
||||
*intCnt = *intCnt + 1;
|
||||
|
||||
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
|
||||
OsCpupIrqStart();
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_KERNEL_TICKLESS
|
||||
OsTicklessUpdate(intNum);
|
||||
#endif
|
||||
hwiForm = (&g_hwiForm[intNum]);
|
||||
#ifndef LOSCFG_NO_SHARED_IRQ
|
||||
while (hwiForm->pstNext != NULL) {
|
||||
hwiForm = hwiForm->pstNext;
|
||||
#endif
|
||||
if (hwiForm->uwParam) {
|
||||
HWI_PROC_FUNC2 func = (HWI_PROC_FUNC2)hwiForm->pfnHook;
|
||||
if (func != NULL) {
|
||||
UINTPTR *param = (UINTPTR *)(hwiForm->uwParam);
|
||||
func((INT32)(*param), (VOID *)(*(param + 1)));
|
||||
}
|
||||
} else {
|
||||
HWI_PROC_FUNC0 func = (HWI_PROC_FUNC0)hwiForm->pfnHook;
|
||||
if (func != NULL) {
|
||||
func();
|
||||
}
|
||||
}
|
||||
#ifndef LOSCFG_NO_SHARED_IRQ
|
||||
}
|
||||
#endif
|
||||
++g_hwiFormCnt[intNum];
|
||||
|
||||
*intCnt = *intCnt - 1;
|
||||
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
|
||||
OsCpupIrqEnd(intNum);
|
||||
#endif
|
||||
}
|
||||
|
||||
STATIC HWI_ARG_T OsHwiCpIrqParam(const HwiIrqParam *irqParam)
|
||||
{
|
||||
HwiIrqParam *paramByAlloc = NULL;
|
||||
|
||||
if (irqParam != NULL) {
|
||||
paramByAlloc = (HwiIrqParam *)LOS_MemAlloc(m_aucSysMem0, sizeof(HwiIrqParam));
|
||||
if (paramByAlloc == NULL) {
|
||||
return LOS_NOK;
|
||||
}
|
||||
(VOID)memcpy_s(paramByAlloc, sizeof(HwiIrqParam), irqParam, sizeof(HwiIrqParam));
|
||||
}
|
||||
/* When "irqParam" is NULL, the function return 0(LOS_OK). */
|
||||
return (HWI_ARG_T)paramByAlloc;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_NO_SHARED_IRQ
|
||||
STATIC UINT32 OsHwiDelNoShared(HWI_HANDLE_T hwiNum)
|
||||
{
|
||||
UINT32 intSave;
|
||||
|
||||
HWI_LOCK(intSave);
|
||||
g_hwiForm[hwiNum].pfnHook = NULL;
|
||||
if (g_hwiForm[hwiNum].uwParam) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, (VOID *)g_hwiForm[hwiNum].uwParam);
|
||||
}
|
||||
g_hwiForm[hwiNum].uwParam = 0;
|
||||
|
||||
HWI_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsHwiCreateNoShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler, const HwiIrqParam *irqParam)
|
||||
{
|
||||
HWI_ARG_T retParam;
|
||||
UINT32 intSave;
|
||||
|
||||
HWI_LOCK(intSave);
|
||||
if (g_hwiForm[hwiNum].pfnHook == NULL) {
|
||||
g_hwiForm[hwiNum].pfnHook = hwiHandler;
|
||||
|
||||
retParam = OsHwiCpIrqParam(irqParam);
|
||||
if (retParam == LOS_NOK) {
|
||||
HWI_UNLOCK(intSave);
|
||||
return OS_ERRNO_HWI_NO_MEMORY;
|
||||
}
|
||||
g_hwiForm[hwiNum].uwParam = retParam;
|
||||
} else {
|
||||
HWI_UNLOCK(intSave);
|
||||
return OS_ERRNO_HWI_ALREADY_CREATED;
|
||||
}
|
||||
HWI_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
#else
|
||||
STATIC UINT32 OsHwiDelShared(HWI_HANDLE_T hwiNum, const HwiIrqParam *irqParam)
|
||||
{
|
||||
HwiHandleForm *hwiForm = NULL;
|
||||
HwiHandleForm *hwiFormtmp = NULL;
|
||||
UINT32 hwiValid = FALSE;
|
||||
UINT32 intSave;
|
||||
|
||||
HWI_LOCK(intSave);
|
||||
hwiForm = &g_hwiForm[hwiNum];
|
||||
hwiFormtmp = hwiForm;
|
||||
|
||||
if ((hwiForm->uwParam & IRQF_SHARED) && ((irqParam == NULL) || (irqParam->pDevId == NULL))) {
|
||||
HWI_UNLOCK(intSave);
|
||||
return OS_ERRNO_HWI_SHARED_ERROR;
|
||||
}
|
||||
|
||||
if ((hwiForm->pstNext != NULL) && !(hwiForm->uwParam & IRQF_SHARED)) {
|
||||
hwiForm = hwiForm->pstNext;
|
||||
if (hwiForm->uwParam) {
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, (VOID *)hwiForm->uwParam);
|
||||
}
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, hwiForm);
|
||||
hwiFormtmp->pstNext = NULL;
|
||||
|
||||
g_hwiFormName[hwiNum] = NULL;
|
||||
|
||||
HWI_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
hwiForm = hwiForm->pstNext;
|
||||
while (hwiForm != NULL) {
|
||||
if (((HwiIrqParam *)(hwiForm->uwParam))->pDevId != irqParam->pDevId) {
|
||||
hwiFormtmp = hwiForm;
|
||||
hwiForm = hwiForm->pstNext;
|
||||
} else {
|
||||
hwiFormtmp->pstNext = hwiForm->pstNext;
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, (VOID *)hwiForm->uwParam);
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, hwiForm);
|
||||
|
||||
hwiValid = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hwiValid != TRUE) {
|
||||
HWI_UNLOCK(intSave);
|
||||
return OS_ERRNO_HWI_HWINUM_UNCREATE;
|
||||
}
|
||||
|
||||
if (g_hwiForm[hwiNum].pstNext == NULL) {
|
||||
g_hwiForm[hwiNum].uwParam = 0;
|
||||
g_hwiFormName[hwiNum] = NULL;
|
||||
}
|
||||
|
||||
HWI_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC UINT32 OsHwiCreateShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler, const HwiIrqParam *irqParam)
|
||||
{
|
||||
UINT32 intSave;
|
||||
HwiHandleForm *hwiFormNode = NULL;
|
||||
HwiHandleForm *hwiForm = NULL;
|
||||
HwiIrqParam *hwiParam = NULL;
|
||||
HWI_MODE_T modeResult = hwiMode & IRQF_SHARED;
|
||||
|
||||
if (modeResult && ((irqParam == NULL) || (irqParam->pDevId == NULL))) {
|
||||
return OS_ERRNO_HWI_SHARED_ERROR;
|
||||
}
|
||||
|
||||
HWI_LOCK(intSave);
|
||||
|
||||
hwiForm = &g_hwiForm[hwiNum];
|
||||
if ((hwiForm->pstNext != NULL) && ((modeResult == 0) || (!(hwiForm->uwParam & IRQF_SHARED)))) {
|
||||
HWI_UNLOCK(intSave);
|
||||
return OS_ERRNO_HWI_SHARED_ERROR;
|
||||
}
|
||||
|
||||
while (hwiForm->pstNext != NULL) {
|
||||
hwiForm = hwiForm->pstNext;
|
||||
hwiParam = (HwiIrqParam *)(hwiForm->uwParam);
|
||||
if (hwiParam->pDevId == irqParam->pDevId) {
|
||||
HWI_UNLOCK(intSave);
|
||||
return OS_ERRNO_HWI_ALREADY_CREATED;
|
||||
}
|
||||
}
|
||||
|
||||
hwiFormNode = (HwiHandleForm *)LOS_MemAlloc(m_aucSysMem0, sizeof(HwiHandleForm));
|
||||
if (hwiFormNode == NULL) {
|
||||
HWI_UNLOCK(intSave);
|
||||
return OS_ERRNO_HWI_NO_MEMORY;
|
||||
}
|
||||
|
||||
hwiFormNode->uwParam = OsHwiCpIrqParam(irqParam);
|
||||
if (hwiFormNode->uwParam == LOS_NOK) {
|
||||
HWI_UNLOCK(intSave);
|
||||
(VOID)LOS_MemFree(m_aucSysMem0, hwiFormNode);
|
||||
return OS_ERRNO_HWI_NO_MEMORY;
|
||||
}
|
||||
|
||||
hwiFormNode->pfnHook = hwiHandler;
|
||||
hwiFormNode->pstNext = (struct tagHwiHandleForm *)NULL;
|
||||
hwiForm->pstNext = hwiFormNode;
|
||||
|
||||
if ((irqParam != NULL) && (irqParam->pName != NULL)) {
|
||||
g_hwiFormName[hwiNum] = (CHAR *)irqParam->pName;
|
||||
}
|
||||
|
||||
g_hwiForm[hwiNum].uwParam = modeResult;
|
||||
|
||||
HWI_UNLOCK(intSave);
|
||||
return LOS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Description : initialization of the hardware interrupt
|
||||
*/
|
||||
LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID)
|
||||
{
|
||||
UINT32 hwiNum;
|
||||
|
||||
for (hwiNum = 0; hwiNum < OS_HWI_MAX_NUM; hwiNum++) {
|
||||
g_hwiForm[hwiNum].pfnHook = NULL;
|
||||
g_hwiForm[hwiNum].uwParam = 0;
|
||||
g_hwiForm[hwiNum].pstNext = NULL;
|
||||
}
|
||||
|
||||
(VOID)memset_s(g_hwiFormName, (sizeof(CHAR *) * OS_HWI_MAX_NUM), 0, (sizeof(CHAR *) * OS_HWI_MAX_NUM));
|
||||
|
||||
HalIrqInit();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
(VOID)hwiPrio;
|
||||
if (hwiHandler == NULL) {
|
||||
return OS_ERRNO_HWI_PROC_FUNC_NULL;
|
||||
}
|
||||
if ((hwiNum > OS_USER_HWI_MAX) || ((INT32)hwiNum < OS_USER_HWI_MIN)) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_NO_SHARED_IRQ
|
||||
ret = OsHwiCreateNoShared(hwiNum, hwiMode, hwiHandler, irqParam);
|
||||
#else
|
||||
ret = OsHwiCreateShared(hwiNum, hwiMode, hwiHandler, irqParam);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam)
|
||||
{
|
||||
UINT32 ret;
|
||||
|
||||
if ((hwiNum > OS_USER_HWI_MAX) || ((INT32)hwiNum < OS_USER_HWI_MIN)) {
|
||||
return OS_ERRNO_HWI_NUM_INVALID;
|
||||
}
|
||||
|
||||
#ifdef LOSCFG_NO_SHARED_IRQ
|
||||
ret = OsHwiDelNoShared(hwiNum);
|
||||
#else
|
||||
ret = OsHwiDelShared(hwiNum, irqParam);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,505 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#define ASSEMBLY
|
||||
#include "arch_config.h"
|
||||
#include "los_vm_boot.h"
|
||||
#include "los_vm_zone.h"
|
||||
#include "los_mmu_descriptor_v6.h"
|
||||
#undef ASSEMBLY
|
||||
|
||||
|
||||
.global __exc_stack_top
|
||||
.global __irq_stack_top
|
||||
.global __fiq_stack_top
|
||||
.global __svc_stack_top
|
||||
.global __abt_stack_top
|
||||
.global __undef_stack_top
|
||||
.global __exc_stack
|
||||
.global __irq_stack
|
||||
.global __fiq_stack
|
||||
.global __svc_stack
|
||||
.global __abt_stack
|
||||
.global __undef_stack
|
||||
|
||||
.extern __bss_start
|
||||
.extern __bss_end
|
||||
.extern hal_clock_initialize_start
|
||||
.extern los_bss_init
|
||||
.extern _osExceptFiqHdl
|
||||
.extern _osExceptAddrAbortHdl
|
||||
.extern _osExceptDataAbortHdl
|
||||
.extern _osExceptPrefetchAbortHdl
|
||||
.extern _osExceptSwiHdl
|
||||
.extern _osExceptUndefInstrHdl
|
||||
.extern __stack_chk_guard_setup
|
||||
.extern g_firstPageTable
|
||||
.extern g_mmuJumpPageTable
|
||||
|
||||
.equ MPIDR_CPUID_MASK, 0xffU
|
||||
|
||||
.fpu vfpv4
|
||||
.arm
|
||||
|
||||
/* param0 is stack bottom, param1 is stack size, r12 hold cpu id */
|
||||
.macro EXC_SP_SET param0, param1
|
||||
ldr r1, =\param0
|
||||
mov r0, \param1
|
||||
bl sp_set
|
||||
.endm
|
||||
|
||||
/* param0 is stack top, param1 is stack size, param2 is magic num */
|
||||
.macro STACK_MAGIC_SET param0, param1, param2
|
||||
ldr r0, =\param0
|
||||
mov r1, \param1
|
||||
ldr r2, =\param2
|
||||
bl excstack_magic
|
||||
.endm
|
||||
|
||||
/* param0 is physical address, param1 virtual address, param2 is sizes, param3 is flag */
|
||||
.macro PAGE_TABLE_SET param0, param1, param2, param3
|
||||
ldr r6, =\param0
|
||||
ldr r7, =\param1
|
||||
ldr r8, =\param2
|
||||
ldr r10, =\param3
|
||||
bl page_table_build
|
||||
.endm
|
||||
.code 32
|
||||
.section ".vectors","ax"
|
||||
|
||||
.global __exception_handlers
|
||||
__exception_handlers:
|
||||
/*
|
||||
*Assumption: ROM code has these vectors at the hardware reset address.
|
||||
*A simple jump removes any address-space dependencies [i.e. safer]
|
||||
*/
|
||||
b reset_vector
|
||||
b _osExceptUndefInstrHdl
|
||||
b _osExceptSwiHdl
|
||||
b _osExceptPrefetchAbortHdl
|
||||
b _osExceptDataAbortHdl
|
||||
b _osExceptAddrAbortHdl
|
||||
b OsIrqHandler
|
||||
b _osExceptFiqHdl
|
||||
|
||||
/* Startup code which will get the machine into supervisor mode */
|
||||
.global reset_vector
|
||||
.type reset_vector,function
|
||||
reset_vector:
|
||||
/* clear register TPIDRPRW */
|
||||
mov r0, #0
|
||||
mcr p15, 0, r0, c13, c0, 4
|
||||
/* do some early cpu setup: i/d cache disable, mmu disabled */
|
||||
mrc p15, 0, r0, c1, c0, 0
|
||||
bic r0, #(1<<12)
|
||||
bic r0, #(1<<2 | 1<<0)
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
|
||||
/* r11: delta of physical address and virtual address */
|
||||
adr r11, pa_va_offset
|
||||
ldr r0, [r11]
|
||||
sub r11, r11, r0
|
||||
|
||||
mrc p15, 0, r12, c0, c0, 5 /* r12: get cpuid */
|
||||
and r12, r12, #MPIDR_CPUID_MASK
|
||||
cmp r12, #0
|
||||
bne secondary_cpu_init
|
||||
|
||||
/* if we need to relocate to proper location or not */
|
||||
adr r4, __exception_handlers /* r4: base of load address */
|
||||
ldr r5, =SYS_MEM_BASE /* r5: base of physical address */
|
||||
subs r12, r4, r5 /* r12: delta of load address and physical address */
|
||||
beq reloc_img_to_bottom_done /* if we load image at the bottom of physical address */
|
||||
|
||||
/* we need to relocate image at the bottom of physical address */
|
||||
ldr r7, =__exception_handlers /* r7: base of linked address (or vm address) */
|
||||
ldr r6, =__bss_start /* r6: end of linked address (or vm address) */
|
||||
sub r6, r7 /* r6: delta of linked address (or vm address) */
|
||||
add r6, r4 /* r6: end of load address */
|
||||
|
||||
reloc_img_to_bottom_loop:
|
||||
ldr r7, [r4], #4
|
||||
str r7, [r5], #4
|
||||
cmp r4, r6
|
||||
bne reloc_img_to_bottom_loop
|
||||
sub pc, r12
|
||||
nop
|
||||
sub r11, r11, r12 /* r11: eventual address offset */
|
||||
|
||||
reloc_img_to_bottom_done:
|
||||
ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */
|
||||
add r4, r4, r11
|
||||
bl page_table_clear
|
||||
|
||||
PAGE_TABLE_SET SYS_MEM_BASE, KERNEL_VMM_BASE, KERNEL_VMM_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
|
||||
PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
|
||||
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_DEVICE_BASE, PERIPH_DEVICE_SIZE, MMU_INITIAL_MAP_DEVICE
|
||||
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_CACHED_BASE, PERIPH_CACHED_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
|
||||
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_UNCACHED_BASE, PERIPH_UNCACHED_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
|
||||
|
||||
orr r8, r4, #MMU_TTBRx_FLAGS /* r8 = r4 and set cacheable attributes on translation walk */
|
||||
ldr r4, =g_mmuJumpPageTable /* r4: jump pagetable vaddr */
|
||||
add r4, r4, r11
|
||||
ldr r4, [r4]
|
||||
add r4, r4, r11 /* r4: jump pagetable paddr */
|
||||
bl page_table_clear
|
||||
|
||||
/* build 1M section mapping, in order to jump va during turing on mmu:pa == pa, va == pa */
|
||||
mov r6, pc
|
||||
mov r7, r6 /* r7: pa (MB aligned)*/
|
||||
lsr r6, r6, #20 /* r6: va l1 index */
|
||||
ldr r10, =MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
|
||||
add r12, r10, r6, lsl #20 /* r12: pa |flags */
|
||||
str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[paIndex] = pt entry */
|
||||
rsb r7, r11, r6, lsl #20 /* r7: va */
|
||||
str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[vaIndex] = pt entry */
|
||||
|
||||
bl _bootaddr_setup
|
||||
|
||||
bl mmu_setup /* set up the mmu */
|
||||
|
||||
/* clear out the interrupt and exception stack and set magic num to check the overflow */
|
||||
ldr r0, =__undef_stack
|
||||
ldr r1, =__exc_stack_top
|
||||
bl stack_init
|
||||
|
||||
STACK_MAGIC_SET __undef_stack, #OS_EXC_UNDEF_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __abt_stack, #OS_EXC_ABT_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __irq_stack, #OS_EXC_IRQ_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __fiq_stack, #OS_EXC_FIQ_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __svc_stack, #OS_EXC_SVC_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __exc_stack, #OS_EXC_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
|
||||
warm_reset:
|
||||
/* initialize interrupt/exception environments */
|
||||
mov r0, #(CPSR_IRQ_DISABLE |CPSR_FIQ_DISABLE|CPSR_IRQ_MODE)
|
||||
msr cpsr, r0
|
||||
EXC_SP_SET __irq_stack_top, #OS_EXC_IRQ_STACK_SIZE
|
||||
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_UNDEF_MODE)
|
||||
msr cpsr, r0
|
||||
EXC_SP_SET __undef_stack_top, #OS_EXC_UNDEF_STACK_SIZE
|
||||
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_ABT_MODE)
|
||||
msr cpsr, r0
|
||||
EXC_SP_SET __abt_stack_top, #OS_EXC_ABT_STACK_SIZE
|
||||
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_FIQ_MODE)
|
||||
msr cpsr, r0
|
||||
EXC_SP_SET __fiq_stack_top, #OS_EXC_FIQ_STACK_SIZE
|
||||
|
||||
/* initialize CPSR (machine state register) */
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE)
|
||||
msr cpsr, r0
|
||||
|
||||
/* Note: some functions in LIBGCC1 will cause a "restore from SPSR"!! */
|
||||
msr spsr, r0
|
||||
|
||||
/* get cpuid and keep it in r12 */
|
||||
mrc p15, 0, r12, c0, c0, 5
|
||||
and r12, r12, #MPIDR_CPUID_MASK
|
||||
|
||||
/* set svc stack, every cpu has OS_EXC_SVC_STACK_SIZE stack */
|
||||
ldr r0, =__svc_stack_top
|
||||
mov r2, #OS_EXC_SVC_STACK_SIZE
|
||||
mul r2, r2, r12
|
||||
sub r0, r0, r2
|
||||
mov sp, r0
|
||||
|
||||
/* enable fpu+neon */
|
||||
#ifndef LOSCFG_TEE_ENABLE
|
||||
MRC p15, 0, r0, c1, c1, 2
|
||||
ORR r0, r0, #0xC00
|
||||
BIC r0, r0, #0xC000
|
||||
MCR p15, 0, r0, c1, c1, 2
|
||||
|
||||
LDR r0, =(0xF << 20)
|
||||
MCR p15, 0, r0, c1, c0, 2
|
||||
#endif
|
||||
|
||||
MOV r3, #0x40000000
|
||||
VMSR FPEXC, r3
|
||||
|
||||
LDR r0, =__exception_handlers
|
||||
MCR p15, 0, r0, c12, c0, 0
|
||||
|
||||
cmp r12, #0
|
||||
bne cpu_start
|
||||
|
||||
clear_bss:
|
||||
ldr r1, =__bss_start
|
||||
ldr r2, =__bss_end
|
||||
mov r0, #0
|
||||
|
||||
bss_loop:
|
||||
cmp r1, r2
|
||||
strlo r0, [r1], #4
|
||||
blo bss_loop
|
||||
|
||||
#if defined(LOSCFG_CC_STACKPROTECTOR_ALL) || \
|
||||
defined(LOSCFG_CC_STACKPROTECTOR_STRONG) || \
|
||||
defined(LOSCFG_CC_STACKPROTECTOR)
|
||||
bl __stack_chk_guard_setup
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_GDB_DEBUG
|
||||
/* GDB_START - generate a compiled_breadk,This function will get GDB stubs started, with a proper environment */
|
||||
bl GDB_START
|
||||
.word 0xe7ffdeff
|
||||
#endif
|
||||
|
||||
bl main
|
||||
|
||||
_start_hang:
|
||||
b _start_hang
|
||||
|
||||
mmu_setup:
|
||||
mov r12, #0
|
||||
mcr p15, 0, r12, c8, c7, 0 /* Set c8 to control the TLB and set the mapping to invalid */
|
||||
isb
|
||||
mcr p15, 0, r12, c2, c0, 2 /* Initialize the c2 register */
|
||||
isb
|
||||
orr r12, r4, #MMU_TTBRx_FLAGS
|
||||
mcr p15, 0, r12, c2, c0, 0 /* Set attributes and set temp page table */
|
||||
isb
|
||||
mov r12, #0x7 /* 0b0111 */
|
||||
mcr p15, 0, r12, c3, c0, 0 /* Set DACR with 0b0111, client and manager domian */
|
||||
isb
|
||||
mrc p15, 0, r12, c1, c0, 1 /* ACTLR, Auxlliary Control Register */
|
||||
orr r12, r12, #(1 << 6) /* SMP, Enables coherent requests to the processor. */
|
||||
orr r12, r12, #(1 << 2) /* Enable D-side prefetch */
|
||||
orr r12, r12, #(1 << 11) /* Global BP Enable bit */
|
||||
mcr p15, 0, r12, c1, c0, 1 /* ACTLR, Auxlliary Control Register */
|
||||
dsb
|
||||
mrc p15, 0, r12, c1, c0, 0
|
||||
bic r12, #(1 << 29 | 1 << 28)
|
||||
orr r12, #(1 << 0)
|
||||
bic r12, #(1 << 1)
|
||||
orr r12, #(1 << 2)
|
||||
orr r12, #(1 << 12)
|
||||
mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */
|
||||
isb
|
||||
ldr pc, =1f /* Convert to VA */
|
||||
1:
|
||||
mcr p15, 0, r8, c2, c0, 0 /* Go to the base address saved in C2: Jump to the page table */
|
||||
isb
|
||||
mov r12, #0
|
||||
mcr p15, 0, r12, c8, c7, 0
|
||||
isb
|
||||
sub lr, r11 /* adjust lr with delta of physical address and virtual address */
|
||||
bx lr
|
||||
|
||||
.code 32
|
||||
|
||||
.global reset_platform
|
||||
.type reset_platform,function
|
||||
reset_platform:
|
||||
#ifdef A7SEM_HAL_ROM_MONITOR
|
||||
/* initialize CPSR (machine state register) */
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE)
|
||||
msr cpsr, r0
|
||||
b warm_reset
|
||||
#else
|
||||
mov r0, #0
|
||||
mov pc, r0 // Jump to reset vector
|
||||
#endif
|
||||
cpu_start:
|
||||
ldr r4, =g_firstPageTable /* r4 = physical address of translation table and clear it */
|
||||
add r4, r4, r11
|
||||
orr r8, r4, #MMU_TTBRx_FLAGS
|
||||
|
||||
ldr r4, =g_mmuJumpPageTable /* r4 = tt_trampoline vaddr */
|
||||
add r4, r4, r11
|
||||
ldr r4, [r4]
|
||||
add r4, r4, r11 /* r4 = tt_trampoline paddr */
|
||||
|
||||
bl mmu_setup
|
||||
bl secondary_cpu_start
|
||||
b .
|
||||
|
||||
secondary_cpu_init:
|
||||
#ifdef LOSCFG_TEE_ENABLE
|
||||
/* enable fpu+neon */
|
||||
ldr r0, =0x60c00
|
||||
MCR p15, 0, r0, c1, c1, 2
|
||||
|
||||
LDR r0, =(0xF << 20)
|
||||
MCR p15, 0, r0, c1, c0, 2
|
||||
cps #0x16
|
||||
mov r1, #0x25
|
||||
mcr p15, 0, r1, c1, c1, 0
|
||||
cps #0x13
|
||||
#endif
|
||||
bl warm_reset
|
||||
|
||||
/*
|
||||
* set sp for current cpu
|
||||
* r1 is stack bottom, r0 is stack size, r12 hold cpu id
|
||||
*/
|
||||
sp_set:
|
||||
mrc p15, 0, r12, c0, c0, 5
|
||||
and r12, r12, #MPIDR_CPUID_MASK
|
||||
mul r3, r0, r12
|
||||
sub r2, r1, r3
|
||||
mov sp, r2
|
||||
bx lr /* set sp */
|
||||
|
||||
/*
|
||||
* r4: page table base address
|
||||
* r5 and r6 will be used as variable
|
||||
*/
|
||||
page_table_clear:
|
||||
mov r5, #0
|
||||
mov r6, #0
|
||||
0:
|
||||
str r5, [r4, r6, lsl #2]
|
||||
add r6, #1
|
||||
cmp r6, #0x1000 /* r6 < 4096 */
|
||||
blt 0b
|
||||
bx lr
|
||||
|
||||
/*
|
||||
* r4: page table base address
|
||||
* r6: physical address
|
||||
* r7: virtual address
|
||||
* r8: sizes
|
||||
* r10: flags
|
||||
* r9 and r12 will be used as variable
|
||||
*/
|
||||
page_table_build:
|
||||
mov r9, r6
|
||||
bfc r9, #20, #12 /* r9: pa % MB */
|
||||
add r8, r8, r9
|
||||
add r8, r8, #(1 << 20)
|
||||
sub r8, r8, #1
|
||||
lsr r6, #20 /* r6 = physical address / MB */
|
||||
lsr r7, #20 /* r7 = virtual address / MB */
|
||||
lsr r8, #20 /* r8 = roundup(size, MB) */
|
||||
|
||||
page_table_build_loop:
|
||||
orr r12, r10, r6, lsl #20 /* r12: flags | physAddr */
|
||||
str r12, [r4, r7, lsl #2] /* gPgTable[l1Index] = physAddr | flags */
|
||||
add r6, #1 /* physAddr+ */
|
||||
add r7, #1 /* l1Index++ */
|
||||
subs r8, #1 /* sizes-- */
|
||||
bne page_table_build_loop
|
||||
bx lr
|
||||
|
||||
/*
|
||||
* init stack to initial value
|
||||
* r0 is stack mem start, r1 is stack mem end
|
||||
*/
|
||||
stack_init:
|
||||
ldr r2, =OS_STACK_INIT
|
||||
ldr r3, =OS_STACK_INIT
|
||||
/* Main loop sets 32 bytes at a time. */
|
||||
stack_init_loop:
|
||||
.irp offset, #0, #8, #16, #24
|
||||
strd r2, r3, [r0, \offset]
|
||||
.endr
|
||||
add r0, #32
|
||||
cmp r0, r1
|
||||
blt stack_init_loop
|
||||
bx lr
|
||||
|
||||
pa_va_offset:
|
||||
.word .
|
||||
|
||||
/*
|
||||
* set magic num to stack top for all cpu
|
||||
* r0 is stack top, r1 is stack size, r2 is magic num
|
||||
*/
|
||||
excstack_magic:
|
||||
mov r3, #0
|
||||
excstack_magic_loop:
|
||||
str r2, [r0]
|
||||
add r0, r0, r1
|
||||
add r3, r3, #1
|
||||
cmp r3, #CORE_NUM
|
||||
blt excstack_magic_loop
|
||||
bx lr
|
||||
|
||||
/*
|
||||
* 0xe51ff004 = "ldr pc, [pc, #-4]"
|
||||
* next addr value will be the real booting addr
|
||||
*/
|
||||
_bootaddr_setup:
|
||||
mov r0, #0
|
||||
ldr r1, =0xe51ff004
|
||||
str r1, [r0]
|
||||
|
||||
add r0, r0, #4
|
||||
ldr r1, =SYS_MEM_BASE
|
||||
str r1, [r0]
|
||||
|
||||
dsb
|
||||
isb
|
||||
|
||||
bx lr
|
||||
|
||||
init_done:
|
||||
.long 0xDEADB00B
|
||||
|
||||
.code 32
|
||||
.data
|
||||
|
||||
init_flag:
|
||||
.balign 4
|
||||
.long 0
|
||||
|
||||
/*
|
||||
* Temporary interrupt stack
|
||||
*/
|
||||
.section ".int_stack", "wa", %nobits
|
||||
.align 3
|
||||
|
||||
__undef_stack:
|
||||
.space OS_EXC_UNDEF_STACK_SIZE * CORE_NUM
|
||||
__undef_stack_top:
|
||||
|
||||
__abt_stack:
|
||||
.space OS_EXC_ABT_STACK_SIZE * CORE_NUM
|
||||
__abt_stack_top:
|
||||
|
||||
__irq_stack:
|
||||
.space OS_EXC_IRQ_STACK_SIZE * CORE_NUM
|
||||
__irq_stack_top:
|
||||
|
||||
__fiq_stack:
|
||||
.space OS_EXC_FIQ_STACK_SIZE * CORE_NUM
|
||||
__fiq_stack_top:
|
||||
|
||||
__svc_stack:
|
||||
.space OS_EXC_SVC_STACK_SIZE * CORE_NUM
|
||||
__svc_stack_top:
|
||||
|
||||
__exc_stack:
|
||||
.space OS_EXC_STACK_SIZE * CORE_NUM
|
||||
__exc_stack_top:
|
|
@ -0,0 +1,473 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define ASSEMBLY
|
||||
#include "arch_config.h"
|
||||
#include "los_vm_boot.h"
|
||||
#include "los_vm_zone.h"
|
||||
#include "los_mmu_descriptor_v6.h"
|
||||
#undef ASSEMBLY
|
||||
|
||||
|
||||
.global __exc_stack_top
|
||||
.global __irq_stack_top
|
||||
.global __fiq_stack_top
|
||||
.global __svc_stack_top
|
||||
.global __abt_stack_top
|
||||
.global __undef_stack_top
|
||||
.global __exc_stack
|
||||
.global __irq_stack
|
||||
.global __fiq_stack
|
||||
.global __svc_stack
|
||||
.global __abt_stack
|
||||
.global __undef_stack
|
||||
|
||||
.extern __bss_start
|
||||
.extern __bss_end
|
||||
.extern hal_clock_initialize_start
|
||||
.extern los_bss_init
|
||||
.extern _osExceptFiqHdl
|
||||
.extern _osExceptAddrAbortHdl
|
||||
.extern _osExceptDataAbortHdl
|
||||
.extern _osExceptPrefetchAbortHdl
|
||||
.extern _osExceptSwiHdl
|
||||
.extern _osExceptUndefInstrHdl
|
||||
.extern __stack_chk_guard_setup
|
||||
.extern g_firstPageTable
|
||||
.extern g_mmuJumpPageTable
|
||||
|
||||
.equ MPIDR_CPUID_MASK, 0xffU
|
||||
|
||||
.fpu vfpv4
|
||||
.arm
|
||||
|
||||
/* param0 is stack bottom, param1 is stack size, r11 hold cpu id */
|
||||
.macro EXC_SP_SET param0, param1
|
||||
ldr r1, =\param0
|
||||
mov r0, \param1
|
||||
bl sp_set
|
||||
.endm
|
||||
|
||||
/* param0 is stack top, param1 is stack size, param2 is magic num */
|
||||
.macro STACK_MAGIC_SET param0, param1, param2
|
||||
ldr r0, =\param0
|
||||
mov r1, \param1
|
||||
ldr r2, =\param2
|
||||
bl excstack_magic
|
||||
.endm
|
||||
|
||||
/* param0 is physical address, param1 virtual address, param2 is sizes, param3 is flag */
|
||||
.macro PAGE_TABLE_SET param0, param1, param2, param3
|
||||
ldr r6, =\param0
|
||||
ldr r7, =\param1
|
||||
ldr r8, =\param2
|
||||
ldr r10, =\param3
|
||||
bl page_table_build
|
||||
.endm
|
||||
.code 32
|
||||
.section ".vectors","ax"
|
||||
|
||||
__exception_handlers:
|
||||
/*
|
||||
*Assumption: ROM code has these vectors at the hardware reset address.
|
||||
*A simple jump removes any address-space dependencies [i.e. safer]
|
||||
*/
|
||||
b reset_vector
|
||||
b _osExceptUndefInstrHdl
|
||||
b _osExceptSwiHdl
|
||||
b _osExceptPrefetchAbortHdl
|
||||
b _osExceptDataAbortHdl
|
||||
b _osExceptAddrAbortHdl
|
||||
b OsIrqHandler
|
||||
b _osExceptFiqHdl
|
||||
|
||||
/* Startup code which will get the machine into supervisor mode */
|
||||
.global reset_vector
|
||||
.type reset_vector,function
|
||||
reset_vector:
|
||||
/* do some early cpu setup: i/d cache disable, mmu disabled */
|
||||
mrc p15, 0, r0, c1, c0, 0
|
||||
bic r0, #(1<<12)
|
||||
bic r0, #(1<<2 | 1<<0)
|
||||
mcr p15, 0, r0, c1, c0, 0
|
||||
|
||||
/* r11: delta of physical address and virtual address */
|
||||
adr r11, pa_va_offset
|
||||
ldr r0, [r11]
|
||||
sub r11, r11, r0
|
||||
|
||||
/* if we need to relocate to proper location or not */
|
||||
adr r4, __exception_handlers /* r4: base of load address */
|
||||
ldr r5, =SYS_MEM_BASE /* r5: base of physical address */
|
||||
subs r12, r4, r5 /* r12: delta of load address and physical address */
|
||||
beq reloc_img_to_bottom_done /* if we load image at the bottom of physical address */
|
||||
|
||||
/* we need to relocate image at the bottom of physical address */
|
||||
ldr r7, =__exception_handlers /* r7: base of linked address (or vm address) */
|
||||
ldr r6, =__bss_start /* r6: end of linked address (or vm address) */
|
||||
sub r6, r7 /* r6: delta of linked address (or vm address) */
|
||||
add r6, r4 /* r6: end of load address */
|
||||
|
||||
reloc_img_to_bottom_loop:
|
||||
ldr r7, [r4], #4
|
||||
str r7, [r5], #4
|
||||
cmp r4, r6
|
||||
bne reloc_img_to_bottom_loop
|
||||
sub pc, r12
|
||||
nop
|
||||
sub r11, r11, r12 /* r11: eventual address offset */
|
||||
|
||||
reloc_img_to_bottom_done:
|
||||
ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */
|
||||
add r4, r4, r11
|
||||
bl page_table_clear
|
||||
|
||||
PAGE_TABLE_SET SYS_MEM_BASE, KERNEL_VMM_BASE, KERNEL_VMM_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
|
||||
PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
|
||||
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_DEVICE_BASE, PERIPH_DEVICE_SIZE, MMU_INITIAL_MAP_DEVICE
|
||||
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_CACHED_BASE, PERIPH_CACHED_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
|
||||
PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_UNCACHED_BASE, PERIPH_UNCACHED_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED
|
||||
|
||||
orr r8, r4, #MMU_TTBRx_FLAGS /* r8 = r4 and set cacheable attributes on translation walk */
|
||||
ldr r4, =g_mmuJumpPageTable /* r4: jump pagetable vaddr */
|
||||
add r4, r4, r11
|
||||
ldr r4, [r4]
|
||||
add r4, r4, r11 /* r4: jump pagetable paddr */
|
||||
bl page_table_clear
|
||||
|
||||
/* build 1M section mapping, in order to jump va during turing on mmu:pa == pa, va == pa */
|
||||
mov r6, pc
|
||||
mov r7, r6 /* r7: pa (MB aligned)*/
|
||||
lsr r6, r6, #20 /* r6: va l1 index */
|
||||
ldr r10, =MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS
|
||||
add r12, r10, r6, lsl #20 /* r12: pa |flags */
|
||||
str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[paIndex] = pt entry */
|
||||
rsb r7, r11, r6, lsl #20 /* r7: va */
|
||||
str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[vaIndex] = pt entry */
|
||||
|
||||
bl mmu_setup /* set up the mmu */
|
||||
|
||||
/* get cpuid and keep it in r11 */
|
||||
mrc p15, 0, r11, c0, c0, 5
|
||||
and r11, r11, #MPIDR_CPUID_MASK
|
||||
cmp r11, #0
|
||||
bne excstatck_loop_done
|
||||
|
||||
excstatck_loop:
|
||||
/* clear out the interrupt and exception stack and set magic num to check the overflow */
|
||||
ldr r0, =__undef_stack
|
||||
ldr r1, =__exc_stack_top
|
||||
bl stack_init
|
||||
|
||||
STACK_MAGIC_SET __undef_stack, #OS_EXC_UNDEF_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __abt_stack, #OS_EXC_ABT_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __irq_stack, #OS_EXC_IRQ_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __fiq_stack, #OS_EXC_FIQ_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __svc_stack, #OS_EXC_SVC_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
STACK_MAGIC_SET __exc_stack, #OS_EXC_STACK_SIZE, OS_STACK_MAGIC_WORD
|
||||
|
||||
excstatck_loop_done:
|
||||
warm_reset:
|
||||
/* initialize interrupt/exception environments */
|
||||
mov r0, #(CPSR_IRQ_DISABLE |CPSR_FIQ_DISABLE|CPSR_IRQ_MODE)
|
||||
msr cpsr, r0
|
||||
EXC_SP_SET __irq_stack_top, #OS_EXC_IRQ_STACK_SIZE
|
||||
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_UNDEF_MODE)
|
||||
msr cpsr, r0
|
||||
EXC_SP_SET __undef_stack_top, #OS_EXC_UNDEF_STACK_SIZE
|
||||
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_ABT_MODE)
|
||||
msr cpsr, r0
|
||||
EXC_SP_SET __abt_stack_top, #OS_EXC_ABT_STACK_SIZE
|
||||
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_FIQ_MODE)
|
||||
msr cpsr, r0
|
||||
EXC_SP_SET __fiq_stack_top, #OS_EXC_FIQ_STACK_SIZE
|
||||
|
||||
/* initialize CPSR (machine state register) */
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE)
|
||||
msr cpsr, r0
|
||||
|
||||
/* Note: some functions in LIBGCC1 will cause a "restore from SPSR"!! */
|
||||
msr spsr, r0
|
||||
|
||||
/* set svc stack, every cpu has OS_EXC_SVC_STACK_SIZE stack */
|
||||
ldr r0, =__svc_stack_top
|
||||
mov r2, #OS_EXC_SVC_STACK_SIZE
|
||||
mul r2, r2, r11
|
||||
sub r0, r0, r2
|
||||
mov sp, r0
|
||||
|
||||
/* enable fpu+neon */
|
||||
MRC p15, 0, r0, c1, c1, 2
|
||||
ORR r0, r0, #0xC00
|
||||
BIC r0, r0, #0xC000
|
||||
MCR p15, 0, r0, c1, c1, 2
|
||||
|
||||
LDR r0, =(0xF << 20)
|
||||
MCR p15, 0, r0, c1, c0, 2
|
||||
|
||||
MOV r3, #0x40000000
|
||||
VMSR FPEXC, r3
|
||||
|
||||
LDR r0, =__exception_handlers
|
||||
MCR p15, 0, r0, c12, c0, 0
|
||||
|
||||
cmp r11, #0
|
||||
bne cpu_start
|
||||
|
||||
clear_bss:
|
||||
ldr r1, =__bss_start
|
||||
ldr r2, =__bss_end
|
||||
mov r0, #0
|
||||
|
||||
bss_loop:
|
||||
cmp r1, r2
|
||||
strlo r0, [r1], #4
|
||||
blo bss_loop
|
||||
|
||||
#if defined(LOSCFG_CC_STACKPROTECTOR_ALL) || \
|
||||
defined(LOSCFG_CC_STACKPROTECTOR_STRONG) || \
|
||||
defined(LOSCFG_CC_STACKPROTECTOR)
|
||||
bl __stack_chk_guard_setup
|
||||
#endif
|
||||
|
||||
#ifdef LOSCFG_GDB_DEBUG
|
||||
/* GDB_START - generate a compiled_breadk,This function will get GDB stubs started, with a proper environment */
|
||||
bl GDB_START
|
||||
.word 0xe7ffdeff
|
||||
#endif
|
||||
|
||||
bl main
|
||||
|
||||
_start_hang:
|
||||
b _start_hang
|
||||
|
||||
mmu_setup:
|
||||
mov r12, #0
|
||||
mcr p15, 0, r12, c8, c7, 0 /* Set c8 to control the TLB and set the mapping to invalid */
|
||||
isb
|
||||
|
||||
mcr p15, 0, r12, c2, c0, 2 /* Initialize the c2 register */
|
||||
isb
|
||||
|
||||
orr r12, r4, #MMU_TTBRx_FLAGS
|
||||
mcr p15, 0, r12, c2, c0, 0 /* Set attributes and set temp page table */
|
||||
isb
|
||||
|
||||
mov r12, #0x7 /* 0b0111 */
|
||||
mcr p15, 0, r12, c3, c0, 0 /* Set DACR with 0b0111, client and manager domian */
|
||||
isb
|
||||
|
||||
mrc p15, 0, r12, c1, c0, 0
|
||||
bic r12, #(1 << 29 | 1 << 28)
|
||||
orr r12, #(1 << 0)
|
||||
bic r12, #(1 << 1)
|
||||
orr r12, #(1 << 2)
|
||||
orr r12, #(1 << 12)
|
||||
mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */
|
||||
isb
|
||||
|
||||
ldr pc, =1f /* Convert to VA */
|
||||
1:
|
||||
mcr p15, 0, r8, c2, c0, 0 /* Go to the base address saved in C2: Jump to the page table */
|
||||
isb
|
||||
|
||||
mov r12, #0
|
||||
mcr p15, 0, r12, c8, c7, 0
|
||||
isb
|
||||
|
||||
sub lr, r11 /* adjust lr with delta of physical address and virtual address */
|
||||
bx lr
|
||||
|
||||
.code 32
|
||||
|
||||
.global reset_platform
|
||||
.type reset_platform,function
|
||||
reset_platform:
|
||||
#ifdef A7SEM_HAL_ROM_MONITOR
|
||||
/* initialize CPSR (machine state register) */
|
||||
mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE)
|
||||
msr cpsr, r0
|
||||
b warm_reset
|
||||
#else
|
||||
mov r0, #0
|
||||
mov pc, r0 // Jump to reset vector
|
||||
#endif
|
||||
cpu_start:
|
||||
bl secondary_cpu_start
|
||||
b .
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* set sp for current cpu
|
||||
* r1 is stack bottom, r0 is stack size, r11 hold cpu id
|
||||
*/
|
||||
sp_set:
|
||||
mul r3, r0, r11
|
||||
sub r2, r1, r3
|
||||
mov sp, r2
|
||||
bx lr /* set sp */
|
||||
|
||||
/*
|
||||
* r4: page table base address
|
||||
* r5 and r6 will be used as variable
|
||||
*/
|
||||
page_table_clear:
|
||||
mov r5, #0
|
||||
mov r6, #0
|
||||
0:
|
||||
str r5, [r4, r6, lsl #2]
|
||||
add r6, #1
|
||||
cmp r6, #0x1000 /* r6 < 4096 */
|
||||
blt 0b
|
||||
bx lr
|
||||
|
||||
/*
|
||||
* r4: page table base address
|
||||
* r6: physical address
|
||||
* r7: virtual address
|
||||
* r8: sizes
|
||||
* r10: flags
|
||||
* r9 and r12 will be used as variable
|
||||
*/
|
||||
page_table_build:
|
||||
mov r9, r6
|
||||
bfc r9, #20, #12 /* r9: pa % MB */
|
||||
add r8, r8, r9
|
||||
add r8, r8, #(1 << 20)
|
||||
sub r8, r8, #1
|
||||
lsr r6, #20 /* r6 = physical address / MB */
|
||||
lsr r7, #20 /* r7 = virtual address / MB */
|
||||
lsr r8, #20 /* r8 = roundup(size, MB) */
|
||||
|
||||
page_table_build_loop:
|
||||
orr r12, r10, r6, lsl #20 /* r12: flags | physAddr */
|
||||
str r12, [r4, r7, lsl #2] /* gPgTable[l1Index] = physAddr | flags */
|
||||
add r6, #1 /* physAddr+ */
|
||||
add r7, #1 /* l1Index++ */
|
||||
subs r8, #1 /* sizes-- */
|
||||
bne page_table_build_loop
|
||||
bx lr
|
||||
|
||||
/*
|
||||
* init stack to initial value
|
||||
* r0 is stack mem start, r1 is stack mem end
|
||||
*/
|
||||
stack_init:
|
||||
ldr r2, =OS_STACK_INIT
|
||||
ldr r3, =OS_STACK_INIT
|
||||
/* Main loop sets 32 bytes at a time. */
|
||||
stack_init_loop:
|
||||
.irp offset, #0, #8, #16, #24
|
||||
strd r2, r3, [r0, \offset]
|
||||
.endr
|
||||
add r0, #32
|
||||
cmp r0, r1
|
||||
blt stack_init_loop
|
||||
bx lr
|
||||
|
||||
pa_va_offset:
|
||||
.word .
|
||||
|
||||
/*
|
||||
* set magic num to stack top for all cpu
|
||||
* r0 is stack top, r1 is stack size, r2 is magic num
|
||||
*/
|
||||
excstack_magic:
|
||||
mov r3, #0
|
||||
excstack_magic_loop:
|
||||
str r2, [r0]
|
||||
add r0, r0, r1
|
||||
add r3, r3, #1
|
||||
cmp r3, #CORE_NUM
|
||||
blt excstack_magic_loop
|
||||
bx lr
|
||||
|
||||
/*
|
||||
* 0xe51ff004 = "ldr pc, [pc, #-4]"
|
||||
* next addr value will be the real booting addr
|
||||
*/
|
||||
_bootaddr_setup:
|
||||
mov r0, #0
|
||||
ldr r1, =0xe51ff004
|
||||
str r1, [r0]
|
||||
|
||||
add r0, r0, #4
|
||||
ldr r1, =SYS_MEM_BASE
|
||||
str r1, [r0]
|
||||
|
||||
dsb
|
||||
isb
|
||||
|
||||
bx lr
|
||||
|
||||
init_done:
|
||||
.long 0xDEADB00B
|
||||
|
||||
.code 32
|
||||
.data
|
||||
|
||||
init_flag:
|
||||
.balign 4
|
||||
.long 0
|
||||
|
||||
/*
|
||||
* Temporary interrupt stack
|
||||
*/
|
||||
.section ".int_stack", "wa", %nobits
|
||||
.align 3
|
||||
|
||||
__undef_stack:
|
||||
.space OS_EXC_UNDEF_STACK_SIZE * CORE_NUM
|
||||
__undef_stack_top:
|
||||
|
||||
__abt_stack:
|
||||
.space OS_EXC_ABT_STACK_SIZE * CORE_NUM
|
||||
__abt_stack_top:
|
||||
|
||||
__irq_stack:
|
||||
.space OS_EXC_IRQ_STACK_SIZE * CORE_NUM
|
||||
__irq_stack_top:
|
||||
|
||||
__fiq_stack:
|
||||
.space OS_EXC_FIQ_STACK_SIZE * CORE_NUM
|
||||
__fiq_stack_top:
|
||||
|
||||
__svc_stack:
|
||||
.space OS_EXC_SVC_STACK_SIZE * CORE_NUM
|
||||
__svc_stack_top:
|
||||
|
||||
__exc_stack:
|
||||
.space OS_EXC_STACK_SIZE * CORE_NUM
|
||||
__exc_stack_top:
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_strncpy_from_user.h"
|
||||
#include "los_user_get.h"
|
||||
#include "los_vm_map.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
|
||||
{
|
||||
CHAR character;
|
||||
INT32 i;
|
||||
INT32 maxCount;
|
||||
size_t offset = 0;
|
||||
|
||||
if ((!LOS_IsKernelAddress((VADDR_T)(UINTPTR)dst)) || (!LOS_IsUserAddress((VADDR_T)(UINTPTR)src)) || (count <= 0)) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
maxCount = (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, (size_t)count)) ? \
|
||||
count : (USER_ASPACE_TOP_MAX - (UINTPTR)src);
|
||||
|
||||
for (i = 0; i < maxCount; ++i) {
|
||||
if (LOS_GetUser(&character, src + offset) != LOS_OK) {
|
||||
return -EFAULT;
|
||||
}
|
||||
*(CHAR *)(dst + offset) = character;
|
||||
if (character == '\0') {
|
||||
return offset;
|
||||
}
|
||||
++offset;
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_strnlen_user.h"
|
||||
#include "los_user_get.h"
|
||||
#include "los_vm_map.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
INT32 LOS_StrnlenUser(const CHAR *src, INT32 count)
|
||||
{
|
||||
CHAR character;
|
||||
INT32 maxCount;
|
||||
INT32 i;
|
||||
size_t offset = 0;
|
||||
|
||||
if ((!LOS_IsUserAddress((VADDR_T)(UINTPTR)src)) || (count <= 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
maxCount = (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, (size_t)count)) ? \
|
||||
count : (USER_ASPACE_TOP_MAX - (UINTPTR)src);
|
||||
|
||||
for (i = 0; i < maxCount; ++i) {
|
||||
if (LOS_GetUser(&character, src + offset) != LOS_OK) {
|
||||
return 0;
|
||||
}
|
||||
++offset;
|
||||
if (character == '\0') {
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
||||
return count + 1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "user_copy.h"
|
||||
#include "arm_user_copy.h"
|
||||
#include "securec.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_vm_map.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
size_t arch_copy_from_user(void *dst, const void *src, size_t len)
|
||||
{
|
||||
return LOS_ArchCopyFromUser(dst, src, len);
|
||||
}
|
||||
|
||||
size_t LOS_ArchCopyFromUser(void *dst, const void *src, size_t len)
|
||||
{
|
||||
if (!LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, len)) {
|
||||
return len;
|
||||
}
|
||||
|
||||
return _arm_user_copy(dst, src, len);
|
||||
}
|
||||
|
||||
size_t arch_copy_to_user(void *dst, const void *src, size_t len)
|
||||
{
|
||||
return LOS_ArchCopyToUser(dst, src, len);
|
||||
}
|
||||
|
||||
size_t LOS_ArchCopyToUser(void *dst, const void *src, size_t len)
|
||||
{
|
||||
if (!LOS_IsUserAddressRange((VADDR_T)(UINTPTR)dst, len)) {
|
||||
return len;
|
||||
}
|
||||
|
||||
return _arm_user_copy(dst, src, len);
|
||||
}
|
||||
|
||||
INT32 LOS_CopyFromKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count)
|
||||
{
|
||||
INT32 ret;
|
||||
|
||||
if (!LOS_IsUserAddressRange((VADDR_T)(UINTPTR)dest, count)) {
|
||||
ret = memcpy_s(dest, max, src, count);
|
||||
} else {
|
||||
ret = ((max >= count) ? _arm_user_copy(dest, src, count) : ERANGE_AND_RESET);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
INT32 LOS_CopyToKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count)
|
||||
{
|
||||
INT32 ret;
|
||||
|
||||
if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)src, count)) {
|
||||
ret = memcpy_s(dest, max, src, count);
|
||||
} else {
|
||||
ret = ((max >= count) ? _arm_user_copy(dest, src, count) : ERANGE_AND_RESET);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
INT32 LOS_UserMemClear(unsigned char *buf, UINT32 len)
|
||||
{
|
||||
INT32 ret = 0;
|
||||
if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, len)) {
|
||||
(VOID)memset_s(buf, len, 0, len);
|
||||
} else {
|
||||
unsigned char *tmp = (unsigned char *)LOS_MemAlloc(OS_SYS_MEM_ADDR, len);
|
||||
if (tmp == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
(VOID)memset_s(tmp, len, 0, len);
|
||||
if (_arm_user_copy(buf, tmp, len) != 0) {
|
||||
ret = -EFAULT;
|
||||
}
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, tmp);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_CHECKSUM_H__
|
||||
#define __LINUX_CHECKSUM_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
unsigned int csum_partial(const void *buf, int len, unsigned int wsum);
|
||||
unsigned int csum_partial_copy_nocheck(const void *src, void *dst, int len, unsigned int wsum);
|
||||
unsigned short in_cksum(const void *buf, int len);
|
||||
unsigned short in_cksum_copy(const void *src, void *dst, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_exc Exception handling
|
||||
* @ingroup kernel
|
||||
*/
|
||||
#ifndef _LOS_EXC_H
|
||||
#define _LOS_EXC_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "arch_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Register information structure
|
||||
*
|
||||
* Description: register information stored when an exception occurs on an LPC2458 platform.
|
||||
*
|
||||
* Note: The following register names without uw are the register names used in the chip manual.
|
||||
*/
|
||||
#ifdef LOSCFG_ARCH_ARM_AARCH64
|
||||
#define EXC_GEN_REGS_NUM 30
|
||||
typedef struct {
|
||||
UINT64 X[EXC_GEN_REGS_NUM]; /**< Register X0-X29 */
|
||||
UINT64 LR; /**< Program returning address. X30 */
|
||||
UINT64 SP;
|
||||
UINT64 regELR;
|
||||
UINT64 SPSR;
|
||||
} ExcContext;
|
||||
#else
|
||||
typedef struct {
|
||||
UINT32 USP; /**< User mode stack pointer */
|
||||
UINT32 ULR; /**< User mode program returning address */
|
||||
UINT32 regCPSR; /**< Current program status register (CPSR) */
|
||||
UINT32 R0; /**< Register R0 */
|
||||
UINT32 R1; /**< Register R1 */
|
||||
UINT32 R2; /**< Register R2 */
|
||||
UINT32 R3; /**< Register R3 */
|
||||
UINT32 R4; /**< Register R4 */
|
||||
UINT32 R5; /**< Register R5 */
|
||||
UINT32 R6; /**< Register R6 */
|
||||
UINT32 R7; /**< Register R7 */
|
||||
UINT32 R8; /**< Register R8 */
|
||||
UINT32 R9; /**< Register R9 */
|
||||
UINT32 R10; /**< Register R10 */
|
||||
UINT32 R11; /**< Register R11 */
|
||||
UINT32 R12; /**< Register R12 */
|
||||
UINT32 SP; /**< Stack pointer */
|
||||
UINT32 LR; /**< Program returning address. */
|
||||
UINT32 PC; /**< PC pointer of the exceptional function */
|
||||
} ExcContext;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* Exception information structure
|
||||
*
|
||||
* Description: exception information stored when an exception occurs on an LPC2458 platform.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
UINT16 phase; /**< Phase in which an exception occurs */
|
||||
UINT16 type; /**< Exception type */
|
||||
UINT16 nestCnt; /**< Count of nested exception */
|
||||
UINT16 reserved; /**< Reserved for alignment */
|
||||
ExcContext *context; /**< Hardware context when an exception occurs */
|
||||
} ExcInfo;
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* @brief Kernel FP Register address obtain function.
|
||||
*
|
||||
* @par Description:
|
||||
* The API is used to obtain the FP Register address.
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #UINTPTR The FP Register address.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_exc.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
STATIC INLINE UINTPTR Get_Fp(VOID)
|
||||
{
|
||||
UINTPTR regFp;
|
||||
|
||||
#ifdef LOSCFG_ARCH_ARM_AARCH64
|
||||
__asm__ __volatile__("mov %0, X29" : "=r"(regFp));
|
||||
#else
|
||||
__asm__ __volatile__("mov %0, fp" : "=r"(regFp));
|
||||
#endif
|
||||
|
||||
return regFp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* @brief Define an exception handling function hook.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to define the exception handling function hook based on the type of
|
||||
* the exception handling function and record exceptions.
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_exc.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
typedef VOID (*EXC_PROC_FUNC)(UINT32, ExcContext *, UINT32, UINT32);
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* @brief Register an exception handling hook.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to register an exception handling hook.
|
||||
* @attention If the hook is registered for multiple times, the hook registered at the last time is effective.
|
||||
* @attention The hook can be registered as NULL, indicating that the hook registration is canceled.
|
||||
* @param excHook [IN] Type #EXC_PROC_FUNC: hook function.
|
||||
*
|
||||
* @retval #LOS_OK The exception handling hook is successfully registered.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_exc.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_ExcRegHook(EXC_PROC_FUNC excHook);
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* @brief Kernel panic function.
|
||||
*
|
||||
* @par Description:
|
||||
* Stack function that prints kernel panics.
|
||||
* @attention After this function is called and stack information is printed, the system will fail to respond.
|
||||
* @attention The input parameter can be NULL.
|
||||
* @param fmt [IN] Type #CHAR* : variadic argument.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_exc.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
VOID LOS_Panic(const CHAR *fmt, ...);
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* @brief Kernel backtrace function.
|
||||
*
|
||||
* @par Description:
|
||||
* Backtrace function that prints task call stack information traced from the running task.
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_exc.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsBackTrace(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_exc
|
||||
* @brief Kernel task backtrace function.
|
||||
*
|
||||
* @par Description:
|
||||
* Backtrace function that prints task call stack information traced from the input task.
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input taskID should be valid.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param taskID [IN] Type #UINT32 Task ID.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_exc.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID OsTaskBackTrace(UINT32 taskID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_EXC_H */
|
|
@ -0,0 +1,318 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_hw Hardware
|
||||
* @ingroup kernel
|
||||
*/
|
||||
#ifndef _LOS_HW_H
|
||||
#define _LOS_HW_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "los_hw_cpu.h"
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OS_SCHEDULE_IN_IRQ 0x0
|
||||
#define OS_SCHEDULE_IN_TASK 0x1
|
||||
|
||||
#define PSR_T_ARM 0x00000000u
|
||||
#define PSR_T_THUMB 0x00000020u
|
||||
#define PSR_MODE_SVC 0x00000013u
|
||||
#define PSR_MODE_SYS 0x0000001Fu
|
||||
#define PSR_FIQ_DIS 0x00000040u
|
||||
#define PSR_IRQ_DIS 0x00000080u
|
||||
#define PSR_MODE_USR 0x00000010u
|
||||
|
||||
#define PSR_MODE_SVC_THUMB (PSR_MODE_SVC | PSR_T_THUMB | PSR_FIQ_DIS | PSR_IRQ_DIS)
|
||||
#define PSR_MODE_SVC_ARM (PSR_MODE_SVC | PSR_T_ARM | PSR_FIQ_DIS | PSR_IRQ_DIS)
|
||||
|
||||
#define PSR_MODE_SYS_THUMB (PSR_MODE_SYS | PSR_T_THUMB)
|
||||
#define PSR_MODE_SYS_ARM (PSR_MODE_SYS | PSR_T_ARM)
|
||||
|
||||
#define PSR_MODE_USR_THUMB (PSR_MODE_USR | PSR_T_THUMB)
|
||||
#define PSR_MODE_USR_ARM (PSR_MODE_USR | PSR_T_ARM)
|
||||
|
||||
#define LOS_CHECK_SCHEDULE ((!OS_INT_ACTIVE) && OsPreemptable())
|
||||
|
||||
typedef struct {
|
||||
const UINT32 partNo;
|
||||
const CHAR *cpuName;
|
||||
} CpuVendor;
|
||||
|
||||
extern CpuVendor g_cpuTable[];
|
||||
extern UINT64 g_cpuMap[];
|
||||
|
||||
#define CPU_MAP_GET(cpuid) g_cpuMap[(cpuid)]
|
||||
#define CPU_MAP_SET(cpuid, hwid) g_cpuMap[(cpuid)] = (hwid)
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Set Event.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to send an event to all cores within a muti-processor system.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API is not implemented.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see wfe.
|
||||
*/
|
||||
extern VOID Sev(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Wait for event.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to suspend execution until events occurs if the event register is not set.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API is not implemented.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see sev.
|
||||
*/
|
||||
extern VOID Wfe(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Wait for interrupt.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to suspend execution until interrupt or a debug request occurs.</li>
|
||||
* </ul>
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID Wfi(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Data Memory Barrier.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used as a memory barrier</li>
|
||||
* </ul>
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID Dmb(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Data Synchronization Barrier.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used as a special kind of memory barrier</li>
|
||||
* </ul>
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID Dsb(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Instruction Synchronization Barrier.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to flush the pipeline in the processor,
|
||||
* so that all instructions following the ISB are fetched from cache or memory,
|
||||
* after the instruction has been completed.</li>
|
||||
* </ul>
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID Isb(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Invalidate instruction cache.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to invalidate the instruction cache.</li>
|
||||
* </ul>
|
||||
* @attention None.
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID FlushICache(VOID);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Flush data cache.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to flush the data cache to the memory.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input end address must be greater than the input start address.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param start [IN] Type #int Flush start address.
|
||||
* @param end [IN] Type #int Flush end address.
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID DCacheFlushRange(UINTPTR start, UINTPTR end);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Invalidate data cache.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to Invalidate the data in cache.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The input end address must be greater than the input start address.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param start [IN] Type #int Invalidate start address.
|
||||
* @param end [IN] Type #int Invalidate end address .
|
||||
*
|
||||
* @retval #None.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
extern VOID DCacheInvRange(UINTPTR start, UINTPTR end);
|
||||
|
||||
/**
|
||||
* @ingroup los_hw
|
||||
* @brief Get cpu core name.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to get cpu core name.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param
|
||||
* @retval #CHAR * cpu core name.
|
||||
*
|
||||
* @par Dependency:
|
||||
* los_hw.h: the header file that contains the API declaration.
|
||||
* @see None.
|
||||
*/
|
||||
STATIC INLINE const CHAR *LOS_CpuInfo(VOID)
|
||||
{
|
||||
INT32 i;
|
||||
UINT32 midr = OsMainIDGet();
|
||||
/* [15:4] is the primary part number */
|
||||
UINT32 partNo = (midr & 0xFFF0) >> 0x4;
|
||||
|
||||
for (i = 0; g_cpuTable[i].partNo != 0; i++) {
|
||||
if (partNo == g_cpuTable[i].partNo) {
|
||||
return g_cpuTable[i].cpuName;
|
||||
}
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_HW_H */
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_hw Hardware
|
||||
* @ingroup kernel
|
||||
*/
|
||||
|
||||
#ifndef _LOS_HW_ARCH_H
|
||||
#define _LOS_HW_ARCH_H
|
||||
|
||||
# if defined(__GNUC__)
|
||||
# if defined(__aarch64__)
|
||||
# define LOSCFG_ARM_AARCH64 1
|
||||
# endif
|
||||
#
|
||||
# define LOSCFG_ARM_ARCH __ARM_ARCH
|
||||
# else
|
||||
# error "unsupported compiler!"
|
||||
# endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_HW_TICK_PRI_H
|
||||
#define _LOS_HW_TICK_PRI_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond);
|
||||
extern VOID OsTickStart(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_HW_TICK_PRI_H */
|
|
@ -0,0 +1,422 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup los_hwi Hardware interrupt
|
||||
* @ingroup kernel
|
||||
*/
|
||||
#ifndef _LOS_HWI_H
|
||||
#define _LOS_HWI_H
|
||||
|
||||
#include "los_base.h"
|
||||
#include "los_hw_cpu.h"
|
||||
#include "hal_hwi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Count of interrupts.
|
||||
*/
|
||||
extern size_t g_intCount[];
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* An interrupt is active.
|
||||
*/
|
||||
#define OS_INT_ACTIVE ({ \
|
||||
size_t intCount; \
|
||||
UINT32 intSave_ = LOS_IntLock(); \
|
||||
intCount = g_intCount[ArchCurrCpuid()]; \
|
||||
LOS_IntRestore(intSave_); \
|
||||
intCount; \
|
||||
})
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* An interrupt is inactive.
|
||||
*/
|
||||
#define OS_INT_INACTIVE (!(OS_INT_ACTIVE))
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Highest priority of a hardware interrupt.
|
||||
*/
|
||||
#define OS_HWI_PRIO_HIGHEST 0
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Lowest priority of a hardware interrupt.
|
||||
*/
|
||||
#define OS_HWI_PRIO_LOWEST 31
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Max name length of a hardware interrupt.
|
||||
*/
|
||||
#define OS_HWI_MAX_NAMELEN 10
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* 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_hwi
|
||||
* 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_hwi
|
||||
* 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_hwi
|
||||
* 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_hwi
|
||||
* 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_hwi
|
||||
* 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_hwi
|
||||
* 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_hwi
|
||||
* 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_hwi
|
||||
* Hardware interrupt error code: The API is called during an interrupt, which is forbidden.
|
||||
*
|
||||
* Value: 0x02000908
|
||||
*
|
||||
* * Solution: Do not call the API during an interrupt.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08)
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code:the hwi support SHARED error.
|
||||
*
|
||||
* Value: 0x02000909
|
||||
*
|
||||
* * Solution: Check the input params hwiMode and irqParam of LOS_HwiCreate or
|
||||
* LOS_HwiDelete whether adapt the current hwi.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x09)
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code:Invalid interrupt Arg when interrupt mode is IRQF_SHARED.
|
||||
*
|
||||
* Value: 0x0200090a
|
||||
*
|
||||
* * Solution: Check the interrupt Arg, Arg should not be NULL and pDevId should not be NULL.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_ARG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0a)
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Hardware interrupt error code:The interrupt corresponded to the hwi number or devid has not been created.
|
||||
*
|
||||
* Value: 0x0200090b
|
||||
*
|
||||
* * Solution: Check the hwi number or devid, make sure the hwi number or devid need to delete.
|
||||
*/
|
||||
#define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b)
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Define the type of a hardware interrupt number.
|
||||
*/
|
||||
typedef UINT32 HWI_HANDLE_T;
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Define the type of a hardware interrupt priority.
|
||||
*/
|
||||
typedef UINT16 HWI_PRIOR_T;
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Define the type of hardware interrupt mode configurations.
|
||||
*/
|
||||
typedef UINT16 HWI_MODE_T;
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Define the type of the parameter used for the hardware interrupt creation function.
|
||||
* The function of this parameter varies among platforms.
|
||||
*/
|
||||
typedef UINTPTR HWI_ARG_T;
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* Define the type of a hardware interrupt handling function.
|
||||
*/
|
||||
typedef VOID (*HWI_PROC_FUNC)(VOID);
|
||||
|
||||
/*
|
||||
* These flags used only by the kernel as part of the
|
||||
* irq handling routines.
|
||||
*
|
||||
* IRQF_SHARED - allow sharing the irq among several devices
|
||||
*/
|
||||
#define IRQF_SHARED 0x8000U
|
||||
|
||||
typedef struct tagHwiHandleForm {
|
||||
HWI_PROC_FUNC pfnHook;
|
||||
HWI_ARG_T uwParam;
|
||||
struct tagHwiHandleForm *pstNext;
|
||||
} HwiHandleForm;
|
||||
|
||||
typedef struct tagIrqParam {
|
||||
int swIrq;
|
||||
VOID *pDevId;
|
||||
const CHAR *pName;
|
||||
} HwiIrqParam;
|
||||
|
||||
extern HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM];
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief Disable all interrupts.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to disable all IRQ and FIQ interrupts in the CPSR.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #UINT32 CPSR value obtained before all interrupts are disabled.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_IntRestore
|
||||
*/
|
||||
STATIC INLINE UINT32 LOS_IntLock(VOID)
|
||||
{
|
||||
return ArchIntLock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief Enable all interrupts.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to enable all IRQ and FIQ interrupts in the CPSR.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>None.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @retval #UINT32 CPSR value obtained after all interrupts are enabled.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_IntLock
|
||||
*/
|
||||
STATIC INLINE UINT32 LOS_IntUnLock(VOID)
|
||||
{
|
||||
return ArchIntUnlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief Restore interrupts.
|
||||
*
|
||||
* @par Description:
|
||||
* <ul>
|
||||
* <li>This API is used to restore the CPSR value obtained before all interrupts are disabled.</li>
|
||||
* </ul>
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>This API can be called only after all interrupts are disabled, and the input parameter value should be
|
||||
* the value returned by LOS_IntLock.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param intSave [IN] Type #UINT32 : CPSR value obtained before all interrupts are disabled.
|
||||
*
|
||||
* @retval None.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see LOS_IntLock
|
||||
*/
|
||||
STATIC INLINE VOID LOS_IntRestore(UINT32 intSave)
|
||||
{
|
||||
ArchIntRestore(intSave);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief Create a hardware interrupt.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to configure a hardware interrupt and register a hardware interrupt handling function.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The hardware interrupt module is usable only when the configuration item for
|
||||
* hardware interrupt tailoring is enabled.</li>
|
||||
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. </li>
|
||||
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
|
||||
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
|
||||
* <li>The parameter handler of this interface is a interrupt handler, it should be correct, otherwise,
|
||||
* the system may be abnormal.</li>
|
||||
* <li>The input irqParam could be NULL, if not, it should be address which point to a struct HwiIrqParam</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param hwiNum [IN] Type #HWI_HANDLE_T: hardware interrupt number.
|
||||
* for an ARM926 platform is [0,31].
|
||||
* @param hwiPrio [IN] Type #HWI_PRIOR_T: hardware interrupt priority. The value range is
|
||||
* [0, GIC_MAX_INTERRUPT_PREEMPTION_LEVEL - 1] << PRIORITY_SHIFT.
|
||||
* @param hwiMode [IN] Type #HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily.
|
||||
* @param hwiHandler [IN] Type #HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered.
|
||||
* @param irqParam [IN] Type #HwiIrqParam: input parameter of the interrupt handler used when
|
||||
* a hardware interrupt is triggered.
|
||||
*
|
||||
* @retval #OS_ERRNO_HWI_PROC_FUNC_NULL Null hardware interrupt handling function.
|
||||
* @retval #OS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
|
||||
* @retval #OS_ERRNO_HWI_NO_MEMORY Insufficient memory for hardware interrupt creation.
|
||||
* @retval #OS_ERRNO_HWI_ALREADY_CREATED The interrupt handler being created has already been created.
|
||||
* @retval #LOS_OK The interrupt is successfully created.
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum,
|
||||
HWI_PRIOR_T hwiPrio,
|
||||
HWI_MODE_T hwiMode,
|
||||
HWI_PROC_FUNC hwiHandler,
|
||||
HwiIrqParam *irqParam);
|
||||
|
||||
/**
|
||||
* @ingroup los_hwi
|
||||
* @brief delete a hardware interrupt.
|
||||
*
|
||||
* @par Description:
|
||||
* This API is used to delete a hardware interrupt.
|
||||
*
|
||||
* @attention
|
||||
* <ul>
|
||||
* <li>The hardware interrupt module is usable only when the configuration item for
|
||||
* hardware interrupt tailoring is enabled.</li>
|
||||
* <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX].</li>
|
||||
* <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
|
||||
* <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param hwiNum [IN] Type #HWI_HANDLE_T: hardware interrupt number.
|
||||
* @param irqParam [IN] Type #HwiIrqParam *: id of hardware interrupt which will base on
|
||||
* when delete the hardware interrupt.
|
||||
*
|
||||
* @retval #OS_ERRNO_HWI_NUM_INVALID Invalid interrupt number.
|
||||
* @retval #OS_ERRNO_HWI_SHARED_ERROR Invalid interrupt mode.
|
||||
* @retval #LOS_OK The interrupt is successfully deleted.
|
||||
* @retval #LOS_NOK The interrupt is failed deleted based on the pDev_ID.
|
||||
|
||||
* @par Dependency:
|
||||
* <ul><li>los_hwi.h: the header file that contains the API declaration.</li></ul>
|
||||
* @see None.
|
||||
*/
|
||||
extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_HWI_H */
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_STRNCPY_FROM_USER_H
|
||||
#define _LOS_STRNCPY_FROM_USER_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* @brief Copy a string end with NULL from userspace to kernelspace
|
||||
*
|
||||
* This function validates that usermode has access to src before copying the
|
||||
* data.
|
||||
*
|
||||
* @param dst The destination buffer in kernel space.
|
||||
* @param src The source buffer in user space.
|
||||
* @param count Max number of bytes to copy.
|
||||
*
|
||||
* @return Return -EFAULT if src is not in user space or count <= 0 or copy out of range. Return the length of
|
||||
* the string if success, if count is smaller than the length of the string then copy count bytes and return count.
|
||||
*/
|
||||
INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_STRNCPY_FROM_USER_H */
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_STRNLEN_USER_H
|
||||
#define _LOS_STRNLEN_USER_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* @brief Get the length of string including final NULL.
|
||||
*
|
||||
* This function validates that usermode has access to src before measuring the string.
|
||||
*
|
||||
* @param src The string in userspace to measure.
|
||||
* @param count Max count.
|
||||
*
|
||||
* @return Return the length of the string including final NULL. Return 0 if src is not in user space or count <= 0 or
|
||||
* visit the memory out of range. Return a number larger than count if the string is too long, User should handle
|
||||
* this situation.
|
||||
*/
|
||||
INT32 LOS_StrnlenUser(const CHAR *src, INT32 count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_STRNLEN_USER_H */
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_SYS_STACK_H
|
||||
#define _LOS_SYS_STACK_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef LOSCFG_AARCH64
|
||||
extern UINTPTR __stack_startup;
|
||||
extern UINTPTR __stack_startup_top;
|
||||
#else
|
||||
extern UINTPTR __fiq_stack_top;
|
||||
extern UINTPTR __svc_stack_top;
|
||||
extern UINTPTR __abt_stack_top;
|
||||
extern UINTPTR __undef_stack_top;
|
||||
extern UINTPTR __exc_stack_top;
|
||||
extern UINTPTR __fiq_stack;
|
||||
extern UINTPTR __svc_stack;
|
||||
extern UINTPTR __abt_stack;
|
||||
extern UINTPTR __undef_stack;
|
||||
extern UINTPTR __exc_stack;
|
||||
#endif
|
||||
extern UINTPTR __irq_stack_top;
|
||||
extern UINTPTR __irq_stack;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_USER_GET_H
|
||||
#define _LOS_USER_GET_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "arm_user_get.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* @brief Get data from userspace into kernelspace
|
||||
*
|
||||
* This function validates that usermode has access to src before copying the
|
||||
* data.
|
||||
*
|
||||
* @param dst The destination buffer in kernel space.
|
||||
* @param src The source buffer in user space.
|
||||
*
|
||||
* @note The data type is simple such as char, short, int, long in 32bits platform.
|
||||
*
|
||||
* @return Return -EFAULT if error. Return 0 if success.
|
||||
*/
|
||||
#define LOS_GetUser(dst, src) _arm_get_user((dst), (src), sizeof(*(dst)), sizeof(*(src)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_USER_GET_H */
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _LOS_USER_PUT_H
|
||||
#define _LOS_USER_PUT_H
|
||||
|
||||
#include "los_typedef.h"
|
||||
#include "arm_user_put.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/*
|
||||
* @brief put data from kernelspace into userspace
|
||||
*
|
||||
* This function validates that usermode has access to dst before copying the
|
||||
* data.
|
||||
*
|
||||
* @param dst The destination buffer in user space.
|
||||
* @param src The source buffer in kernel space.
|
||||
*
|
||||
* @note The data type is simple such as char, short, int, long in 32bits platform.
|
||||
*
|
||||
* @return Return -EFAULT if error. Return 0 if success.
|
||||
*/
|
||||
#define LOS_PutUser(src, dst) _arm_put_user((dst), (src), sizeof(*(dst)), sizeof(*(src)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _LOS_USER_PUT_H */
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "los_typedef.h"
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* @brief Copy data from userspace into kernelspace
|
||||
*
|
||||
* This function validates that usermode has access to src before copying the
|
||||
* data.
|
||||
*
|
||||
* @param dst The destination buffer.
|
||||
* @param src The source buffer.
|
||||
* @param len The number of bytes to copy.
|
||||
*
|
||||
* @return bytes not copied
|
||||
*/
|
||||
size_t LOS_ArchCopyFromUser(void *dst, const void *src, size_t len);
|
||||
|
||||
/*
|
||||
* @brief Copy data from kernelspace into userspace
|
||||
*
|
||||
* This function validates that usermode has access to dst before copying the
|
||||
* data.
|
||||
*
|
||||
* @param dst The destination buffer.
|
||||
* @param src The source buffer.
|
||||
* @param len The number of bytes to copy.
|
||||
*
|
||||
* @return bytes not copied
|
||||
*/
|
||||
size_t LOS_ArchCopyToUser(void *dst, const void *src, size_t len);
|
||||
|
||||
/*
|
||||
* @brief Copy data from src to dst
|
||||
*
|
||||
* This function will use different copy methods to copy src data to dst, according to
|
||||
* the different spaces (userspace or kernelspace) of dst data.
|
||||
*
|
||||
* @param dst The destination buffer, can be userspace address.
|
||||
* @param max The maxsimum number of bytes to copy.
|
||||
* @param src The source buffer.
|
||||
* @param len The number of bytes to copy.
|
||||
*
|
||||
* @return zero on success; non-zero on failure.
|
||||
*/
|
||||
INT32 LOS_CopyFromKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count);
|
||||
|
||||
/*
|
||||
* @brief Copy data from src to dst
|
||||
*
|
||||
* This function will use different copy methods to copy src data to dst, according to
|
||||
* the different spaces (userspace or kernelspace) of src data.
|
||||
*
|
||||
* @param dst The destination buffer.
|
||||
* @param max The maxsimum number of bytes to copy.
|
||||
* @param src The source buffer, can be userspace address.
|
||||
* @param len The number of bytes to copy.
|
||||
*
|
||||
* @return zero on success; non-zero on failure.
|
||||
*/
|
||||
INT32 LOS_CopyToKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count);
|
||||
|
||||
/*
|
||||
* @brief Clear data in buf
|
||||
*
|
||||
* This function will clear buf from buf to buf + len.
|
||||
*
|
||||
* @param buf The destination buffer, can be userspace address.
|
||||
* @param len The number of bytes to clear.
|
||||
*
|
||||
* @return zero on success; non-zero on failure.
|
||||
*/
|
||||
INT32 LOS_UserMemClear(unsigned char *buf, UINT32 len);
|
|
@ -0,0 +1,32 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
ifeq ($(LOSCFG_ARCH_ARM), y)
|
||||
-include $(LITEOSTOPDIR)/arch/arm/arm.mk
|
||||
endif
|
|
@ -0,0 +1,6 @@
|
|||
config COMPAT_BSD
|
||||
bool "Enable FreeBSD"
|
||||
default y
|
||||
|
||||
help
|
||||
Answer Y to enable LiteOS support FreeBSD.
|
|
@ -0,0 +1,54 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
LOCAL_SRCS := $(wildcard kern/*.c)
|
||||
|
||||
LOCAL_SRCS += $(wildcard $(LITEOS_ARCH_ARM)/*.c)
|
||||
LOCAL_SRCS += $(wildcard $(LITEOS_ARCH_ARM)/*.S)
|
||||
|
||||
ifeq ($(LOSCFG_DRIVERS_RANDOM), y)
|
||||
LOCAL_SRCS += $(wildcard crypto/rijndael/*.c) \
|
||||
$(wildcard crypto/sha2/*.c) \
|
||||
$(wildcard dev/random/*.c) \
|
||||
$(wildcard libkern/*.c)
|
||||
|
||||
endif
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/kernel/base/include \
|
||||
-I $(LITEOSTOPDIR)/bsd \
|
||||
-I $(LITEOSTOPDIR)/bsd/kern \
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
include $(MODULE)
|
|
@ -0,0 +1 @@
|
|||
../../../../third_party/FreeBSD/sys/arm/arm/autoconf.c
|
|
@ -0,0 +1 @@
|
|||
../../../../third_party/FreeBSD/lib/libc/arm/string/hw_user_copy.S
|
|
@ -0,0 +1 @@
|
|||
../../../../third_party/FreeBSD/sys/arm/arm/in_cksum.c
|
|
@ -0,0 +1 @@
|
|||
../../../../third_party/FreeBSD/sys/arm/arm/in_cksum_arm.S
|
|
@ -0,0 +1 @@
|
|||
../../../../../third_party/FreeBSD/sys/arm/include/_bus.h
|
|
@ -0,0 +1 @@
|
|||
../../../../third_party/FreeBSD/sys/arm/arm/nexus.c
|
|
@ -0,0 +1,42 @@
|
|||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other materials
|
||||
# provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software without specific prior written
|
||||
# permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
include $(LITEOSTOPDIR)/config.mk
|
||||
|
||||
MODULE_NAME := $(notdir $(shell pwd))
|
||||
|
||||
LOCAL_SRCS := $(wildcard src/*.c)
|
||||
|
||||
LOCAL_INCLUDE := \
|
||||
-I $(LITEOSTOPDIR)/kernel/base/include \
|
||||
-I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include
|
||||
|
||||
LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS)
|
||||
|
||||
include $(MODULE)
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/asm/atomic.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/asm/barrier.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/asm/io.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/asm/page.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/atomic.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/compat.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/compiler.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/completion.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/ctype.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/delay.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/errno.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/fcntl.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/fs.h
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/hrtimer.h
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue