提交 6df931fc 编写于 作者: W wenjun

add OpenHarmony 1.0 baseline

上级 94f5f466
### 该问题是怎么引起的?
### 重现步骤
### 报错信息
### 相关的Issue
### 原因(目的、解决的问题等)
### 描述(做了什么,变更了什么)
### 测试用例(新增、改动、可能影响的功能)
/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
# 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}"
]
}
# 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
# 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
# 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
# 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
# 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
/*
* 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);
}
};
}
# 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
# 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
/*
* 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
/*
* 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 */
/*
* 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 */
/*
* 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 */
/*
* 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 */
/*
* 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 */
/*
* 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 */
/*
* 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 */
/*
* 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 */
/*
* 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(), &param);
if (ret != SH_OK) {
goto OUT;
}
param.sched_priority = SHELL_PROCESS_PRIORITY_INIT;
ret = sched_setparam(getpid(), &param);
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
/*
* 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
/*
* 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
/*
* 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
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.
# 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
# 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)
# 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)
/*
* 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
\ No newline at end of file
此差异已折叠。
/*
* 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);
/*
* 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 */
/*
* 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 */
/*
* 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__ */
/*
* 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__ */
此差异已折叠。
/*
* 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 */
/*
* 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__ */
此差异已折叠。
/*
* 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__ */
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
config COMPAT_BSD
bool "Enable FreeBSD"
default y
help
Answer Y to enable LiteOS support FreeBSD.
此差异已折叠。
../../../../third_party/FreeBSD/sys/arm/arm/autoconf.c
\ No newline at end of file
../../../../third_party/FreeBSD/lib/libc/arm/string/hw_user_copy.S
\ No newline at end of file
../../../../third_party/FreeBSD/sys/arm/arm/in_cksum.c
\ No newline at end of file
../../../../third_party/FreeBSD/sys/arm/arm/in_cksum_arm.S
\ No newline at end of file
../../../../../third_party/FreeBSD/sys/arm/include/_bus.h
\ No newline at end of file
../../../../third_party/FreeBSD/sys/arm/arm/nexus.c
\ No newline at end of file
此差异已折叠。
../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/asm/atomic.h
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册