From 6df931fc981500cf629a3dfb5e0a01f375d0fa05 Mon Sep 17 00:00:00 2001 From: wenjun Date: Tue, 8 Sep 2020 10:21:39 +0800 Subject: [PATCH] add OpenHarmony 1.0 baseline --- .gitee/ISSUE_TEMPLATE.zh-CN.md | 13 + .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md | 15 + .gitignore | 25 + BUILD.gn | 68 + Kconfig | 381 ++ Makefile | 202 + apps/Makefile | 49 + apps/config.mk | 60 + apps/init/Makefile | 63 + apps/init/src/init.c | 57 + apps/module.mk | 40 + apps/shell/Makefile | 78 + apps/shell/builtin/cd.c | 69 + apps/shell/include/shcmd.h | 73 + apps/shell/include/shcmdparse.h | 65 + apps/shell/include/shell.h | 110 + apps/shell/include/shell_list.h | 595 +++ apps/shell/include/shell_pri.h | 54 + apps/shell/include/sherr.h | 62 + apps/shell/include/shmsg.h | 69 + apps/shell/include/show.h | 56 + apps/shell/src/main.c | 144 + apps/shell/src/shcmd.c | 611 +++ apps/shell/src/shcmdparse.c | 164 + apps/shell/src/shmsg.c | 640 +++ arch/Kconfig | 33 + arch/arm/Kconfig | 77 + arch/arm/arm.mk | 99 + arch/arm/arm/Makefile | 55 + arch/arm/arm/include/arch_config.h | 103 + arch/arm/arm/include/arm.h | 1135 +++++ arch/arm/arm/include/arm_user_copy.h | 36 + arch/arm/arm/include/arm_user_get.h | 52 + arch/arm/arm/include/arm_user_put.h | 52 + arch/arm/arm/include/los_arch_mmu.h | 75 + arch/arm/arm/include/los_asid.h | 61 + arch/arm/arm/include/los_atomic.h | 892 ++++ arch/arm/arm/include/los_hw_cpu.h | 256 ++ arch/arm/arm/include/los_mmu_descriptor_v6.h | 224 + arch/arm/arm/include/los_pte_ops.h | 176 + arch/arm/arm/include/los_tlb_v6.h | 93 + arch/arm/arm/src/armv7a/cache.S | 80 + arch/arm/arm/src/hw_user_get.S | 77 + arch/arm/arm/src/hw_user_put.S | 77 + arch/arm/arm/src/include/asm.h | 66 + arch/arm/arm/src/include/los_exc_pri.h | 62 + arch/arm/arm/src/include/los_hw_pri.h | 96 + arch/arm/arm/src/include/los_hwi_pri.h | 69 + arch/arm/arm/src/jmp.S | 52 + arch/arm/arm/src/los_arch_mmu.c | 882 ++++ arch/arm/arm/src/los_asid.c | 80 + arch/arm/arm/src/los_dispatch.S | 313 ++ arch/arm/arm/src/los_exc.c | 1065 +++++ arch/arm/arm/src/los_hw.c | 199 + arch/arm/arm/src/los_hw_exc.S | 412 ++ arch/arm/arm/src/los_hw_runstop.S | 132 + arch/arm/arm/src/los_hw_tick.c | 88 + arch/arm/arm/src/los_hwi.c | 351 ++ arch/arm/arm/src/startup/reset_vector_mp.S | 505 +++ arch/arm/arm/src/startup/reset_vector_up.S | 473 ++ arch/arm/arm/src/strncpy_from_user.c | 74 + arch/arm/arm/src/strnlen_user.c | 73 + arch/arm/arm/src/user_copy.c | 122 + arch/arm/include/in_cksum.h | 52 + arch/arm/include/los_exc.h | 233 + arch/arm/include/los_hw.h | 318 ++ arch/arm/include/los_hw_arch.h | 50 + arch/arm/include/los_hw_tick_pri.h | 52 + arch/arm/include/los_hwi.h | 422 ++ arch/arm/include/los_strncpy_from_user.h | 64 + arch/arm/include/los_strnlen_user.h | 63 + arch/arm/include/los_sys_stack_pri.h | 67 + arch/arm/include/los_user_get.h | 65 + arch/arm/include/los_user_put.h | 65 + arch/arm/include/user_copy.h | 103 + arch/cpu.mk | 32 + bsd/Kconfig | 6 + bsd/Makefile | 54 + bsd/arm/autoconf.c | 1 + bsd/arm/hw_user_copy.S | 1 + bsd/arm/in_cksum.c | 1 + bsd/arm/in_cksum_arm.S | 1 + bsd/arm/include/_bus.h | 1 + bsd/arm/nexus.c | 1 + bsd/compat/linuxkpi/Makefile | 42 + bsd/compat/linuxkpi/include/asm/atomic.h | 1 + bsd/compat/linuxkpi/include/asm/barrier.h | 1 + bsd/compat/linuxkpi/include/asm/io.h | 1 + bsd/compat/linuxkpi/include/asm/page.h | 1 + bsd/compat/linuxkpi/include/linux/atomic.h | 1 + bsd/compat/linuxkpi/include/linux/compat.h | 1 + bsd/compat/linuxkpi/include/linux/compiler.h | 1 + .../linuxkpi/include/linux/completion.h | 1 + bsd/compat/linuxkpi/include/linux/ctype.h | 1 + bsd/compat/linuxkpi/include/linux/delay.h | 1 + .../linuxkpi/include/linux/dma-mapping.h | 1 + bsd/compat/linuxkpi/include/linux/errno.h | 1 + bsd/compat/linuxkpi/include/linux/fcntl.h | 1 + bsd/compat/linuxkpi/include/linux/fs.h | 1 + bsd/compat/linuxkpi/include/linux/hrtimer.h | 1 + bsd/compat/linuxkpi/include/linux/icmp.h | 1 + bsd/compat/linuxkpi/include/linux/interrupt.h | 1 + bsd/compat/linuxkpi/include/linux/io.h | 1 + bsd/compat/linuxkpi/include/linux/ioctl.h | 1 + bsd/compat/linuxkpi/include/linux/jiffies.h | 1 + bsd/compat/linuxkpi/include/linux/kernel.h | 1 + bsd/compat/linuxkpi/include/linux/list.h | 1 + bsd/compat/linuxkpi/include/linux/module.h | 1 + .../linuxkpi/include/linux/moduleparam.h | 1 + bsd/compat/linuxkpi/include/linux/mtd/mtd.h | 1 + .../linuxkpi/include/linux/mtd/mtd_list.h | 1 + bsd/compat/linuxkpi/include/linux/pagemap.h | 1 + bsd/compat/linuxkpi/include/linux/rbtree.h | 1 + bsd/compat/linuxkpi/include/linux/rtc.h | 1 + bsd/compat/linuxkpi/include/linux/rwsem.h | 1 + .../linuxkpi/include/linux/scatterlist.h | 1 + bsd/compat/linuxkpi/include/linux/sched.h | 1 + bsd/compat/linuxkpi/include/linux/semaphore.h | 1 + bsd/compat/linuxkpi/include/linux/slab.h | 1 + bsd/compat/linuxkpi/include/linux/spinlock.h | 1 + bsd/compat/linuxkpi/include/linux/stat.h | 1 + bsd/compat/linuxkpi/include/linux/string.h | 1 + bsd/compat/linuxkpi/include/linux/timer.h | 1 + bsd/compat/linuxkpi/include/linux/tree.h | 1 + bsd/compat/linuxkpi/include/linux/types.h | 1 + bsd/compat/linuxkpi/include/linux/wait.h | 1 + bsd/compat/linuxkpi/include/linux/wakelock.h | 1 + bsd/compat/linuxkpi/include/linux/workqueue.h | 1 + bsd/compat/linuxkpi/include/linux/zutil.h | 1 + bsd/compat/linuxkpi/include/tzdst.h | 1 + bsd/compat/linuxkpi/include/tzdst_pri.h | 1 + bsd/compat/linuxkpi/src/adp.c | 1 + bsd/compat/linuxkpi/src/linux_completion.c | 1 + bsd/compat/linuxkpi/src/linux_hrtimer.c | 1 + bsd/compat/linuxkpi/src/linux_interrupt.c | 1 + bsd/compat/linuxkpi/src/linux_sched.c | 1 + bsd/compat/linuxkpi/src/linux_semaphore.c | 1 + bsd/compat/linuxkpi/src/linux_timer.c | 1 + bsd/compat/linuxkpi/src/linux_wakelock.c | 1 + bsd/compat/linuxkpi/src/linux_workqueue.c | 1 + bsd/compat/linuxkpi/src/prctl.c | 1 + bsd/compat/linuxkpi/src/tzdst.c | 1 + bsd/crypto/rijndael/rijndael-alg-fst.c | 1 + bsd/crypto/rijndael/rijndael-api-fst.c | 1 + bsd/crypto/rijndael/rijndael-api-fst.h | 1 + bsd/crypto/rijndael/rijndael.h | 1 + bsd/crypto/rijndael/rijndael_local.h | 1 + bsd/crypto/sha2/sha256.h | 1 + bsd/crypto/sha2/sha256c.c | 1 + bsd/dev/random/hash.c | 1 + bsd/dev/random/hash.h | 1 + bsd/dev/random/randomdev.h | 1 + bsd/dev/random/uint128.h | 1 + bsd/dev/random/unit_test.h | 1 + bsd/dev/random/yarrow.c | 1 + bsd/dev/random/yarrow.h | 1 + bsd/dev/usb/Kconfig | 102 + bsd/dev/usb/Makefile | 131 + bsd/dev/usb/controller/ehci.c | 1 + bsd/dev/usb/controller/ehci.h | 1 + bsd/dev/usb/controller/ehci_pci.c | 1 + bsd/dev/usb/controller/ehcireg.h | 1 + bsd/dev/usb/controller/usb_controller.c | 1 + bsd/dev/usb/controller/xhci.c | 1 + bsd/dev/usb/controller/xhci.h | 1 + bsd/dev/usb/controller/xhci_pci.c | 1 + bsd/dev/usb/controller/xhcireg.h | 1 + bsd/dev/usb/implementation/_macro_ref.h | 1 + bsd/dev/usb/implementation/_thread_ref.h | 1 + bsd/dev/usb/implementation/_types_ref.h | 1 + bsd/dev/usb/implementation/bsd_busspace.c | 1 + bsd/dev/usb/implementation/bsd_kernel.c | 1 + bsd/dev/usb/implementation/bsd_kernel.h | 1 + bsd/dev/usb/implementation/freebsd_sys.h | 1 + bsd/dev/usb/implementation/freebsd_usb.h | 1 + .../implementation/global_implementation.h | 1 + bsd/dev/usb/implementation/usb_api_pri.h | 1 + bsd/dev/usb/implementation/usb_btree.c | 1 + bsd/dev/usb/implementation/usb_btree.h | 1 + .../usb/implementation/usb_busdma_loader.c | 1 + bsd/dev/usb/implementation/usb_init.c | 1 + bsd/dev/usb/implementation/usb_init.h | 1 + bsd/dev/usb/implementation/usb_version.c | 1 + bsd/dev/usb/implementation/usbdevs.h | 1 + bsd/dev/usb/input/uhid.c | 1 + bsd/dev/usb/input/usb_rdesc.h | 1 + bsd/dev/usb/linux_usb.c | 1 + bsd/dev/usb/linux_usb.h | 1 + bsd/dev/usb/net/if_axe.c | 1 + bsd/dev/usb/net/if_axereg.h | 1 + bsd/dev/usb/net/if_axge.c | 1 + bsd/dev/usb/net/if_axgereg.h | 1 + bsd/dev/usb/net/if_cdce.c | 1 + bsd/dev/usb/net/if_cdcereg.h | 1 + bsd/dev/usb/net/if_urndis.c | 1 + bsd/dev/usb/net/if_urndisreg.h | 1 + bsd/dev/usb/net/mii.h | 1 + bsd/dev/usb/net/usb_eth_drv.c | 1 + bsd/dev/usb/net/usb_eth_drv.h | 1 + bsd/dev/usb/net/usb_ethernet.c | 1 + bsd/dev/usb/net/usb_ethernet.h | 1 + bsd/dev/usb/quirk/usb_quirk.c | 1 + bsd/dev/usb/quirk/usb_quirk.h | 1 + bsd/dev/usb/serial.h | 1 + bsd/dev/usb/serial/u3g.c | 1 + bsd/dev/usb/serial/usb_serial.c | 1 + bsd/dev/usb/serial/usb_serial.h | 1 + bsd/dev/usb/storage/scsi.h | 1 + bsd/dev/usb/storage/scsi_all.h | 1 + bsd/dev/usb/storage/umass.c | 1 + bsd/dev/usb/storage/umass_fs.h | 1 + bsd/dev/usb/usb.h | 1 + bsd/dev/usb/usb_bus.h | 1 + bsd/dev/usb/usb_busdma.h | 1 + bsd/dev/usb/usb_cdc.h | 1 + bsd/dev/usb/usb_controller.h | 1 + bsd/dev/usb/usb_core.c | 1 + bsd/dev/usb/usb_core.h | 1 + bsd/dev/usb/usb_debug.c | 1 + bsd/dev/usb/usb_debug.h | 1 + bsd/dev/usb/usb_dev.c | 1 + bsd/dev/usb/usb_dev.h | 1 + bsd/dev/usb/usb_device.c | 1 + bsd/dev/usb/usb_device.h | 1 + bsd/dev/usb/usb_dynamic.c | 1 + bsd/dev/usb/usb_dynamic.h | 1 + bsd/dev/usb/usb_endian.h | 1 + bsd/dev/usb/usb_error.c | 1 + bsd/dev/usb/usb_freebsd_loader.h | 1 + bsd/dev/usb/usb_generic.c | 1 + bsd/dev/usb/usb_generic.h | 1 + bsd/dev/usb/usb_handle_request.c | 1 + bsd/dev/usb/usb_hid.c | 1 + bsd/dev/usb/usb_hub.c | 1 + bsd/dev/usb/usb_hub.h | 1 + bsd/dev/usb/usb_if.c | 1 + bsd/dev/usb/usb_if.h | 1 + bsd/dev/usb/usb_ioctl.h | 1 + bsd/dev/usb/usb_lookup.c | 1 + bsd/dev/usb/usb_mbuf.c | 1 + bsd/dev/usb/usb_mbuf.h | 1 + bsd/dev/usb/usb_parse.c | 1 + bsd/dev/usb/usb_process.c | 1 + bsd/dev/usb/usb_process.h | 1 + bsd/dev/usb/usb_request.c | 1 + bsd/dev/usb/usb_request.h | 1 + bsd/dev/usb/usb_transfer.c | 1 + bsd/dev/usb/usb_transfer.h | 1 + bsd/dev/usb/usb_util.c | 1 + bsd/dev/usb/usb_util.h | 1 + bsd/dev/usb/usbdi.h | 1 + bsd/dev/usb/usbdi_util.h | 1 + bsd/dev/usb/usbhid.h | 1 + bsd/kern/bus_if.c | 1 + bsd/kern/bus_if.h | 1 + bsd/kern/device_if.c | 1 + bsd/kern/device_if.h | 1 + bsd/kern/kern_condvar.c | 1 + bsd/kern/kern_timeout.c | 1 + bsd/kern/subr_bus.c | 1 + bsd/kern/subr_kobj.c | 1 + bsd/libkern/explicit_bzero.c | 1 + bsd/net/ppp_defs.h | 1 + bsd/sys/_callout.h | 1 + bsd/sys/bus.h | 1 + bsd/sys/callout.h | 1 + bsd/sys/cdefs.h | 1 + bsd/sys/condvar.h | 1 + bsd/sys/kernel.h | 1 + bsd/sys/kobj.h | 1 + bsd/sys/linker_set.h | 1 + bsd/sys/malloc.h | 1 + bsd/sys/module.h | 1 + bsd/sys/mutex.h | 1 + bsd/sys/priv.h | 1 + bsd/sys/queue.h | 1 + bsd/sys/sema.h | 1 + bsd/sys/sx.h | 1 + bsd/sys/systm.h | 1 + build.sh | 55 + compat/posix/Kconfig | 6 + compat/posix/Makefile | 42 + compat/posix/include/mqueue.h | 409 ++ compat/posix/include/time_posix.h | 86 + compat/posix/src/map_error.c | 122 + compat/posix/src/map_error.h | 49 + compat/posix/src/misc.c | 152 + compat/posix/src/mqueue.c | 610 +++ compat/posix/src/posix_memalign.c | 59 + compat/posix/src/pprivate.h | 87 + compat/posix/src/pthread.c | 817 ++++ compat/posix/src/pthread_attr.c | 287 ++ compat/posix/src/pthread_cond.c | 358 ++ compat/posix/src/pthread_mutex.c | 146 + compat/posix/src/sched.c | 150 + compat/posix/src/semaphore.c | 204 + compat/posix/src/socket.c | 188 + compat/posix/src/time.c | 984 ++++ config.mk | 61 + fs/fat/Kconfig | 43 + fs/fat/Makefile | 44 + fs/fat/os_adapt/fat_shellcmd.c | 121 + fs/fat/os_adapt/fatfs.c | 2419 ++++++++++ fs/fat/virpart/Makefile | 41 + fs/fat/virpart/include/virpart.h | 46 + fs/fat/virpart/include/virpartff.h | 54 + fs/fat/virpart/src/virpart.c | 503 +++ fs/fat/virpart/src/virpartff.c | 872 ++++ fs/include/compiler.h | 1 + fs/include/debug.h | 1 + fs/include/disk.h | 708 +++ fs/include/fs/automount.h | 1 + fs/include/fs/dirent_fs.h | 1 + fs/include/fs/fd_table.h | 80 + fs/include/fs/file.h | 1 + fs/include/fs/fs.h | 1 + fs/include/fs/fs_operation.h | 548 +++ fs/include/inode/inode.h | 1 + fs/include/net/net.h | 1 + fs/include/syslog.h | 1 + fs/include/vfs_config.h | 121 + fs/jffs2/Kconfig | 6 + fs/jffs2/Makefile | 48 + fs/nfs/Kconfig | 7 + fs/nfs/Makefile | 38 + fs/ramfs/Kconfig | 6 + fs/ramfs/Makefile | 38 + fs/vfs/Kconfig | 20 + fs/vfs/Makefile | 116 + fs/vfs/bcache/Makefile | 42 + fs/vfs/bcache/src/bcache.c | 1177 +++++ fs/vfs/bch/Makefile | 42 + fs/vfs/disk/Makefile | 40 + fs/vfs/disk/disk.c | 1638 +++++++ fs/vfs/disk/disk_shellcmd.c | 77 + fs/vfs/include/bcache/bcache.h | 277 ++ fs/vfs/include/disk/disk_pri.h | 69 + fs/vfs/include/driver/blockproxy.h | 53 + fs/vfs/include/driver/driver.h | 106 + fs/vfs/include/driver/mtd_dev.h | 59 + fs/vfs/include/driver/mtd_list.h | 62 + .../include/multi_partition/mtd_partition.h | 158 + fs/vfs/include/operation/fs_file.h | 57 + fs/vfs/include/operation/fs_other.h | 68 + fs/vfs/include/operation/fs_poll_pri.h | 49 + fs/vfs/multi_partition/Makefile | 42 + fs/vfs/multi_partition/src/mtd_partition.c | 478 ++ fs/vfs/multi_partition/src/mtd_shellcmd.c | 88 + fs/vfs/operation/fs_chattr.c | 201 + fs/vfs/operation/fs_check.c | 134 + fs/vfs/operation/fs_fallocate.c | 149 + fs/vfs/operation/fs_fallocate64.c | 152 + fs/vfs/operation/fs_file.c | 300 ++ fs/vfs/operation/fs_file_mapping.c | 314 ++ fs/vfs/operation/fs_getlabel.c | 160 + fs/vfs/operation/fs_init.c | 75 + fs/vfs/operation/fs_other.c | 691 +++ fs/vfs/operation/fs_preadv.c | 50 + fs/vfs/operation/fs_pwritev.c | 50 + fs/vfs/operation/fs_readv.c | 134 + fs/vfs/operation/fs_utime.c | 173 + fs/vfs/operation/fs_virstatfs.c | 153 + fs/vfs/operation/fs_writev.c | 127 + fs/vfs/operation/fullpath.c | 343 ++ fs/vfs/vfs_cmd/vfs_shellcmd.c | 1570 +++++++ kernel/BUILD.gn | 59 + kernel/Kconfig | 120 + kernel/base/BUILD.gn | 82 + kernel/base/Makefile | 54 + kernel/base/core/los_bitmap.c | 148 + kernel/base/core/los_process.c | 2004 +++++++++ kernel/base/core/los_sortlink.c | 244 + kernel/base/core/los_swtmr.c | 543 +++ kernel/base/core/los_sys.c | 82 + kernel/base/core/los_task.c | 2015 +++++++++ kernel/base/core/los_tick.c | 93 + kernel/base/core/los_timeslice.c | 75 + kernel/base/include/los_base_pri.h | 53 + kernel/base/include/los_binarytree_pri.h | 110 + kernel/base/include/los_err_pri.h | 127 + kernel/base/include/los_event_pri.h | 64 + kernel/base/include/los_futex_pri.h | 63 + kernel/base/include/los_heap_pri.h | 253 ++ kernel/base/include/los_ipcdebug_pri.h | 67 + kernel/base/include/los_membox_pri.h | 49 + kernel/base/include/los_memory_pri.h | 72 + kernel/base/include/los_memrecord_pri.h | 84 + kernel/base/include/los_memstat_pri.h | 88 + .../base/include/los_multipledlinkhead_pri.h | 70 + kernel/base/include/los_mux_pri.h | 57 + kernel/base/include/los_oom.h | 70 + kernel/base/include/los_percpu_pri.h | 87 + kernel/base/include/los_pmm.h | 56 + kernel/base/include/los_printf_pri.h | 58 + kernel/base/include/los_priqueue_pri.h | 245 + kernel/base/include/los_process_pri.h | 498 ++ kernel/base/include/los_queue_debug_pri.h | 86 + kernel/base/include/los_queue_pri.h | 207 + kernel/base/include/los_sched_pri.h | 144 + kernel/base/include/los_sem_debug_pri.h | 87 + kernel/base/include/los_sem_pri.h | 120 + kernel/base/include/los_signal.h | 198 + kernel/base/include/los_sortlink_pri.h | 108 + kernel/base/include/los_stackinfo_pri.h | 84 + kernel/base/include/los_stat_pri.h | 59 + kernel/base/include/los_swtmr_pri.h | 114 + kernel/base/include/los_sys_pri.h | 104 + kernel/base/include/los_task_pri.h | 587 +++ kernel/base/include/los_tick_pri.h | 101 + kernel/base/include/los_timeslice_pri.h | 77 + kernel/base/include/los_typedef_pri.h | 37 + kernel/base/include/los_vm_boot.h | 74 + kernel/base/include/los_vm_common.h | 140 + kernel/base/include/los_vm_dump.h | 82 + kernel/base/include/los_vm_fault.h | 67 + kernel/base/include/los_vm_filemap.h | 214 + kernel/base/include/los_vm_iomap.h | 63 + kernel/base/include/los_vm_lock.h | 64 + kernel/base/include/los_vm_map.h | 314 ++ kernel/base/include/los_vm_page.h | 69 + kernel/base/include/los_vm_phys.h | 120 + kernel/base/include/los_vm_shm_pri.h | 54 + kernel/base/include/los_vm_syscall.h | 78 + kernel/base/include/los_vm_zone.h | 89 + kernel/base/ipc/los_event.c | 349 ++ kernel/base/ipc/los_futex.c | 944 ++++ kernel/base/ipc/los_ipcdebug.c | 90 + kernel/base/ipc/los_mux.c | 612 +++ kernel/base/ipc/los_queue.c | 504 +++ kernel/base/ipc/los_queue_debug.c | 208 + kernel/base/ipc/los_sem.c | 298 ++ kernel/base/ipc/los_sem_debug.c | 311 ++ kernel/base/ipc/los_signal.c | 691 +++ kernel/base/mem/bestfit/los_memory.c | 2971 ++++++++++++ .../base/mem/bestfit/los_multipledlinkhead.c | 74 + kernel/base/mem/bestfit_little/los_heap.c | 424 ++ kernel/base/mem/common/los_memstat.c | 126 + .../mem/common/memrecord/los_binarytree.c | 260 ++ .../mem/common/memrecord/los_interto64radix.c | 87 + .../base/mem/common/memrecord/los_memrecord.c | 356 ++ kernel/base/mem/membox/los_membox.c | 237 + kernel/base/misc/kill_shellcmd.c | 93 + kernel/base/misc/los_misc.c | 69 + kernel/base/misc/los_stackinfo.c | 125 + kernel/base/misc/mempt_shellcmd.c | 342 ++ kernel/base/misc/swtmr_shellcmd.c | 147 + kernel/base/misc/sysinfo_shellcmd.c | 170 + kernel/base/misc/task_shellcmd.c | 501 +++ kernel/base/misc/vm_shellcmd.c | 265 ++ kernel/base/mp/los_lockdep.c | 323 ++ kernel/base/mp/los_mp.c | 119 + kernel/base/mp/los_percpu.c | 46 + kernel/base/mp/los_stat.c | 333 ++ kernel/base/om/los_err.c | 61 + kernel/base/sched/sched_sq/los_priqueue.c | 235 + kernel/base/sched/sched_sq/los_sched.c | 176 + kernel/base/vm/los_vm_boot.c | 102 + kernel/base/vm/los_vm_dump.c | 545 +++ kernel/base/vm/los_vm_fault.c | 468 ++ kernel/base/vm/los_vm_filemap.c | 775 ++++ kernel/base/vm/los_vm_iomap.c | 218 + kernel/base/vm/los_vm_map.c | 1209 +++++ kernel/base/vm/los_vm_page.c | 111 + kernel/base/vm/los_vm_phys.c | 585 +++ kernel/base/vm/los_vm_scan.c | 346 ++ kernel/base/vm/los_vm_syscall.c | 439 ++ kernel/base/vm/oom.c | 253 ++ kernel/base/vm/shm.c | 741 +++ kernel/common/Kconfig | 6 + kernel/common/Makefile | 42 + kernel/common/console.c | 1669 +++++++ kernel/common/console.h | 146 + kernel/common/hwi_shell.c | 134 + kernel/common/los_builddef.h | 105 + kernel/common/los_cir_buf.c | 225 + kernel/common/los_cir_buf_pri.h | 87 + kernel/common/los_config.c | 449 ++ kernel/common/los_config.h | 484 ++ kernel/common/los_exc_interaction.c | 133 + kernel/common/los_exc_interaction_pri.h | 53 + kernel/common/los_excinfo.c | 178 + kernel/common/los_excinfo_pri.h | 65 + kernel/common/los_hilog.c | 330 ++ kernel/common/los_hilog.h | 53 + kernel/common/los_magickey.c | 155 + kernel/common/los_magickey.h | 57 + kernel/common/los_printf.c | 270 ++ kernel/common/los_rootfs.c | 504 +++ kernel/common/los_rootfs.h | 69 + kernel/common/los_seq_buf.c | 156 + kernel/common/los_seq_buf.h | 65 + kernel/common/los_timer_pri.h | 50 + kernel/common/sys_config.h | 70 + kernel/common/virtual_serial.c | 316 ++ kernel/common/virtual_serial.h | 75 + kernel/extended/cppsupport/Makefile | 43 + kernel/extended/cppsupport/los_cppsupport.c | 60 + kernel/extended/cpup/Makefile | 41 + kernel/extended/cpup/cpup_shellcmd.c | 149 + kernel/extended/cpup/los_cpup.c | 557 +++ kernel/extended/dynload/Makefile | 41 + .../dynload/include/los_elf_auxvec_pri.h | 70 + .../extended/dynload/include/los_exec_elf.h | 51 + .../extended/dynload/include/los_ld_elf_pri.h | 422 ++ .../extended/dynload/include/los_load_elf.h | 133 + kernel/extended/dynload/src/los_exec_elf.c | 194 + kernel/extended/dynload/src/los_load_elf.c | 1060 +++++ kernel/extended/include/los_cpup_pri.h | 84 + kernel/extended/include/los_tickless_pri.h | 59 + kernel/extended/include/los_trace_pri.h | 57 + kernel/extended/liteipc/Makefile | 37 + kernel/extended/liteipc/hm_liteipc.c | 1321 ++++++ kernel/extended/liteipc/hm_liteipc.h | 233 + kernel/extended/pipe | 1 + kernel/extended/tickless/Makefile | 43 + kernel/extended/tickless/los_tickless.c | 201 + kernel/extended/trace/Makefile | 42 + kernel/extended/trace/los_trace.c | 250 + kernel/extended/vdso/include/los_vdso.h | 56 + .../extended/vdso/include/los_vdso_datapage.h | 63 + kernel/extended/vdso/include/los_vdso_pri.h | 57 + kernel/extended/vdso/src/Makefile | 40 + kernel/extended/vdso/src/los_vdso.c | 127 + kernel/extended/vdso/src/los_vdso_text.S | 34 + kernel/extended/vdso/usr/Makefile | 53 + kernel/extended/vdso/usr/los_vdso.ld | 37 + kernel/extended/vdso/usr/los_vdso_sys.c | 113 + kernel/include/los_base.h | 245 + kernel/include/los_bitmap.h | 221 + kernel/include/los_cppsupport.h | 86 + kernel/include/los_cpup.h | 264 ++ kernel/include/los_err.h | 156 + kernel/include/los_errno.h | 112 + kernel/include/los_event.h | 342 ++ kernel/include/los_ld_elflib.h | 244 + kernel/include/los_list.h | 629 +++ kernel/include/los_lockdep.h | 147 + kernel/include/los_membox.h | 250 + kernel/include/los_memory.h | 837 ++++ kernel/include/los_mp.h | 72 + kernel/include/los_mux.h | 242 + kernel/include/los_printf.h | 119 + kernel/include/los_process.h | 77 + kernel/include/los_queue.h | 735 +++ kernel/include/los_sem.h | 312 ++ kernel/include/los_spinlock.h | 321 ++ kernel/include/los_swtmr.h | 425 ++ kernel/include/los_sys.h | 202 + kernel/include/los_tables.h | 93 + kernel/include/los_task.h | 1038 +++++ kernel/include/los_tick.h | 180 + kernel/include/los_tickless.h | 94 + kernel/include/los_toolchain.h | 148 + kernel/include/los_trace.h | 285 ++ kernel/include/los_typedef.h | 245 + kernel/user/Makefile | 75 + kernel/user/include/los_user_init.h | 70 + kernel/user/src/los_user_init.c | 66 + lib/Kconfig | 15 + lib/libc/Makefile | 50 + lib/libmbedtls/Makefile | 8 + lib/libscrew/Makefile | 15 + lib/libscrew/include/los_crc32.h | 55 + lib/libscrew/include/los_rbtree.h | 142 + lib/libscrew/src/los_crc32.c | 82 + lib/libscrew/src/los_rbtree.c | 775 ++++ lib/libsec/Makefile | 6 + lib/zlib/Makefile | 7 + net/Kconfig | 32 + net/lwip-2.1/Makefile | 51 + net/lwip-2.1/enhancement/include/api_shell.h | 63 + .../enhancement/include/api_shell_fix.h | 161 + net/lwip-2.1/enhancement/include/dhcps.h | 81 + net/lwip-2.1/enhancement/include/dhcps_fix.h | 102 + net/lwip-2.1/enhancement/src/api_shell.c | 4002 +++++++++++++++++ net/lwip-2.1/enhancement/src/api_shell_fix.c | 410 ++ net/lwip-2.1/porting/include/arch/cc.h | 74 + net/lwip-2.1/porting/include/arch/perf.h | 42 + net/lwip-2.1/porting/include/arch/sys_arch.h | 77 + net/lwip-2.1/porting/include/lwip/dhcp.h | 48 + net/lwip-2.1/porting/include/lwip/inet.h | 61 + net/lwip-2.1/porting/include/lwip/lwipopts.h | 221 + net/lwip-2.1/porting/include/lwip/netif.h | 79 + net/lwip-2.1/porting/include/lwip/netifapi.h | 57 + net/lwip-2.1/porting/include/lwip/pbuf.h | 57 + .../porting/include/lwip/priv/api_msg.h | 47 + .../porting/include/lwip/priv/sockets_priv.h | 41 + net/lwip-2.1/porting/include/lwip/sockets.h | 89 + net/lwip-2.1/porting/include/lwipopts.h | 38 + net/lwip-2.1/porting/src/driverif.c | 342 ++ net/lwip-2.1/porting/src/fixme.c | 46 + net/lwip-2.1/porting/src/sockets.c | 1583 +++++++ net/lwip-2.1/porting/src/sys_arch.c | 325 ++ net/mac/los_mac.h | 60 + net/telnet/Kconfig | 6 + net/telnet/Makefile | 36 + net/telnet/include/telnet_dev.h | 87 + net/telnet/include/telnet_loop.h | 59 + net/telnet/include/telnet_pri.h | 56 + net/telnet/src/telnet_dev.c | 417 ++ net/telnet/src/telnet_loop.c | 594 +++ platform/Kconfig | 49 + platform/Makefile | 81 + platform/board.ld.S | 56 + platform/bsp.mk | 90 + platform/hw/arm/interrupt/gic/gic_v2.c | 193 + platform/hw/arm/interrupt/gic/gic_v3.c | 446 ++ .../arm/timer/arm_generic/arm_generic_timer.c | 199 + .../arm/timer/arm_private/arm_private_timer.c | 135 + platform/hw/hisoc/hrtimer/hrtimer.c | 112 + platform/hw/hisoc/timer/timer.c | 408 ++ platform/hw/include/gic_common.h | 123 + platform/hw/include/gic_v3.h | 203 + platform/include/hal_hwi.h | 63 + platform/include/hal_timer.h | 65 + platform/main.c | 186 + platform/uart/amba-pl011-lagacy/uart.c | 304 ++ platform/uart/amba_pl011/amba_pl011.c | 203 + platform/uart/amba_pl011/amba_pl011.h | 68 + platform/uart/dw-3.0.8a/uart.c | 215 + platform/usb/usb3.0_hi3516dv300/usb_board.c | 325 ++ platform/usb/usb3.0_hi3518ev300/usb_board.c | 391 ++ readme.md | 1 + security/Kconfig | 30 + security/Makefile | 48 + security/cap/Makefile | 41 + security/cap/capability.c | 95 + security/cap/capability_api.h | 41 + security/cap/capability_type.h | 69 + security/vid/vid.c | 237 + security/vid/vid_api.h | 48 + security/vid/vid_type.h | 48 + shell/BUILD.gn | 43 + shell/Kconfig | 32 + shell/Makefile | 47 + shell/full/include/dmesg.h | 172 + shell/full/include/dmesg_pri.h | 69 + shell/full/include/shcmd.h | 108 + shell/full/include/shcmdparse.h | 73 + shell/full/include/shell.h | 136 + shell/full/include/shell_lk.h | 119 + shell/full/include/shell_pri.h | 60 + shell/full/include/shmsg.h | 58 + shell/full/include/show.h | 53 + shell/full/src/base/shcmd.c | 877 ++++ shell/full/src/base/shcmdparse.c | 165 + shell/full/src/base/shell_lk.c | 236 + shell/full/src/base/shmsg.c | 473 ++ shell/full/src/base/show.c | 181 + shell/full/src/cmds/date_shell.c | 302 ++ shell/full/src/cmds/dmesg.c | 782 ++++ shell/full/src/cmds/excinfo_shell.c | 71 + shell/full/src/cmds/shell_shellcmd.c | 60 + shell/full/src/cmds/watch_shell.c | 275 ++ syscall/Makefile | 42 + syscall/fs_syscall.c | 1933 ++++++++ syscall/ipc_syscall.c | 295 ++ syscall/los_syscall.c | 148 + syscall/los_syscall.h | 262 ++ syscall/misc_syscall.c | 118 + syscall/net_syscall.c | 632 +++ syscall/process_syscall.c | 1003 +++++ syscall/syscall_lookup.h | 239 + syscall/time_syscall.c | 586 +++ syscall/vm_syscall.c | 125 + tools/.gitignore | 2 + tools/build/config.mk | 60 + tools/build/config/debug/hi3516dv300.config | 190 + .../config/debug/hi3516dv300_clang.config | 190 + tools/build/config/debug/hi3518ev300.config | 183 + .../config/debug/hi3518ev300_clang.config | 183 + .../config/hi3516dv300_clang_release.config | 173 + .../config/hi3516dv300_debug_shell.config | 190 + tools/build/config/hi3516dv300_release.config | 173 + .../config/hi3518ev300_clang_release.config | 166 + .../config/hi3518ev300_debug_shell.config | 183 + tools/build/config/hi3518ev300_release.config | 166 + tools/build/liteos.ld | 150 + tools/build/liteos_llvm.ld | 156 + tools/build/mk/bepbuildtime.conf | 4 + tools/build/mk/dynload.mk | 34 + tools/build/mk/get_llvm_compiler_path.sh | 54 + tools/build/mk/liteos_tables_ldflags.mk | 162 + tools/build/mk/los_config.mk | 718 +++ tools/build/mk/module.mk | 149 + tools/fsimage/MakeVersion.sh | 32 + tools/fsimage/mkfs.jffs2 | Bin 0 -> 56968 bytes tools/fsimage/win-x86/cygz.dll | Bin 0 -> 85011 bytes tools/fsimage/win-x86/doc_loadbios.exe | Bin 0 -> 175488 bytes tools/fsimage/win-x86/docfdisk.exe | Bin 0 -> 180912 bytes tools/fsimage/win-x86/flash_erase.exe | Bin 0 -> 307156 bytes tools/fsimage/win-x86/flash_eraseall | 4 + tools/fsimage/win-x86/flash_lock.exe | Bin 0 -> 177229 bytes tools/fsimage/win-x86/flash_otp_dump.exe | Bin 0 -> 170289 bytes tools/fsimage/win-x86/flash_otp_info.exe | Bin 0 -> 171319 bytes tools/fsimage/win-x86/flash_otp_lock.exe | Bin 0 -> 172723 bytes tools/fsimage/win-x86/flash_otp_write.exe | Bin 0 -> 173747 bytes tools/fsimage/win-x86/flash_unlock.exe | Bin 0 -> 177229 bytes tools/fsimage/win-x86/flashcp.exe | Bin 0 -> 209311 bytes tools/fsimage/win-x86/ftl_check.exe | Bin 0 -> 178518 bytes tools/fsimage/win-x86/ftl_format.exe | Bin 0 -> 185806 bytes tools/fsimage/win-x86/jffs2dump.exe | Bin 0 -> 274938 bytes tools/fsimage/win-x86/jffs2reader.exe | Bin 0 -> 227278 bytes tools/fsimage/win-x86/lsmtd.exe | Bin 0 -> 425385 bytes tools/fsimage/win-x86/mkfs.jffs2.exe | Bin 0 -> 371969 bytes tools/fsimage/win-x86/mtd_debug.exe | Bin 0 -> 188752 bytes tools/fsimage/win-x86/mtdinfo.exe | Bin 0 -> 346944 bytes tools/fsimage/win-x86/mtdpart.exe | Bin 0 -> 178033 bytes tools/fsimage/win-x86/nanddump.exe | Bin 0 -> 319680 bytes tools/fsimage/win-x86/nandtest.exe | Bin 0 -> 185794 bytes tools/fsimage/win-x86/nandwrite.exe | Bin 0 -> 324100 bytes tools/fsimage/win-x86/nftl_format.exe | Bin 0 -> 195394 bytes tools/fsimage/win-x86/nftldump.exe | Bin 0 -> 178670 bytes tools/fsimage/win-x86/recv_image.exe | Bin 0 -> 241942 bytes tools/fsimage/win-x86/rfddump.exe | Bin 0 -> 181454 bytes tools/fsimage/win-x86/rfdformat.exe | Bin 0 -> 173273 bytes tools/fsimage/win-x86/serve_image.exe | Bin 0 -> 224165 bytes tools/fsimage/win-x86/sumtool.exe | Bin 0 -> 243080 bytes tools/fsimage/win-x86/ubiattach.exe | Bin 0 -> 275038 bytes tools/fsimage/win-x86/ubiblock.exe | Bin 0 -> 257551 bytes tools/fsimage/win-x86/ubicrc32.exe | Bin 0 -> 176838 bytes tools/fsimage/win-x86/ubidetach.exe | Bin 0 -> 260561 bytes tools/fsimage/win-x86/ubiformat.exe | Bin 0 -> 474919 bytes tools/fsimage/win-x86/ubimkvol.exe | Bin 0 -> 277086 bytes tools/fsimage/win-x86/ubinfo.exe | Bin 0 -> 285888 bytes tools/fsimage/win-x86/ubinize.exe | Bin 0 -> 289385 bytes tools/fsimage/win-x86/ubirename.exe | Bin 0 -> 256519 bytes tools/fsimage/win-x86/ubirmvol.exe | Bin 0 -> 260968 bytes tools/fsimage/win-x86/ubirsvol.exe | Bin 0 -> 275445 bytes tools/fsimage/win-x86/ubiupdatevol.exe | Bin 0 -> 271187 bytes tools/menuconfig/conf | Bin 0 -> 119040 bytes tools/menuconfig/mconf | Bin 0 -> 164472 bytes tools/scripts/make_rootfs/releaseinfo.sh | 42 + tools/scripts/make_rootfs/rootfs.sh | 39 + tools/scripts/make_rootfs/rootfsdir.sh | 42 + tools/scripts/make_rootfs/rootfsimg.sh | 81 + 736 files changed, 111817 insertions(+) create mode 100755 .gitee/ISSUE_TEMPLATE.zh-CN.md create mode 100755 .gitee/PULL_REQUEST_TEMPLATE.zh-CN.md create mode 100755 .gitignore create mode 100755 BUILD.gn create mode 100755 Kconfig create mode 100755 Makefile create mode 100755 apps/Makefile create mode 100755 apps/config.mk create mode 100755 apps/init/Makefile create mode 100755 apps/init/src/init.c create mode 100755 apps/module.mk create mode 100755 apps/shell/Makefile create mode 100755 apps/shell/builtin/cd.c create mode 100755 apps/shell/include/shcmd.h create mode 100755 apps/shell/include/shcmdparse.h create mode 100755 apps/shell/include/shell.h create mode 100755 apps/shell/include/shell_list.h create mode 100755 apps/shell/include/shell_pri.h create mode 100755 apps/shell/include/sherr.h create mode 100755 apps/shell/include/shmsg.h create mode 100755 apps/shell/include/show.h create mode 100755 apps/shell/src/main.c create mode 100755 apps/shell/src/shcmd.c create mode 100755 apps/shell/src/shcmdparse.c create mode 100755 apps/shell/src/shmsg.c create mode 100755 arch/Kconfig create mode 100755 arch/arm/Kconfig create mode 100755 arch/arm/arm.mk create mode 100755 arch/arm/arm/Makefile create mode 100755 arch/arm/arm/include/arch_config.h create mode 100755 arch/arm/arm/include/arm.h create mode 100755 arch/arm/arm/include/arm_user_copy.h create mode 100755 arch/arm/arm/include/arm_user_get.h create mode 100755 arch/arm/arm/include/arm_user_put.h create mode 100755 arch/arm/arm/include/los_arch_mmu.h create mode 100755 arch/arm/arm/include/los_asid.h create mode 100755 arch/arm/arm/include/los_atomic.h create mode 100755 arch/arm/arm/include/los_hw_cpu.h create mode 100755 arch/arm/arm/include/los_mmu_descriptor_v6.h create mode 100755 arch/arm/arm/include/los_pte_ops.h create mode 100755 arch/arm/arm/include/los_tlb_v6.h create mode 100755 arch/arm/arm/src/armv7a/cache.S create mode 100755 arch/arm/arm/src/hw_user_get.S create mode 100755 arch/arm/arm/src/hw_user_put.S create mode 100755 arch/arm/arm/src/include/asm.h create mode 100755 arch/arm/arm/src/include/los_exc_pri.h create mode 100755 arch/arm/arm/src/include/los_hw_pri.h create mode 100755 arch/arm/arm/src/include/los_hwi_pri.h create mode 100755 arch/arm/arm/src/jmp.S create mode 100755 arch/arm/arm/src/los_arch_mmu.c create mode 100755 arch/arm/arm/src/los_asid.c create mode 100755 arch/arm/arm/src/los_dispatch.S create mode 100755 arch/arm/arm/src/los_exc.c create mode 100755 arch/arm/arm/src/los_hw.c create mode 100755 arch/arm/arm/src/los_hw_exc.S create mode 100755 arch/arm/arm/src/los_hw_runstop.S create mode 100755 arch/arm/arm/src/los_hw_tick.c create mode 100755 arch/arm/arm/src/los_hwi.c create mode 100755 arch/arm/arm/src/startup/reset_vector_mp.S create mode 100755 arch/arm/arm/src/startup/reset_vector_up.S create mode 100755 arch/arm/arm/src/strncpy_from_user.c create mode 100755 arch/arm/arm/src/strnlen_user.c create mode 100755 arch/arm/arm/src/user_copy.c create mode 100755 arch/arm/include/in_cksum.h create mode 100755 arch/arm/include/los_exc.h create mode 100755 arch/arm/include/los_hw.h create mode 100755 arch/arm/include/los_hw_arch.h create mode 100755 arch/arm/include/los_hw_tick_pri.h create mode 100755 arch/arm/include/los_hwi.h create mode 100755 arch/arm/include/los_strncpy_from_user.h create mode 100755 arch/arm/include/los_strnlen_user.h create mode 100755 arch/arm/include/los_sys_stack_pri.h create mode 100755 arch/arm/include/los_user_get.h create mode 100755 arch/arm/include/los_user_put.h create mode 100755 arch/arm/include/user_copy.h create mode 100755 arch/cpu.mk create mode 100755 bsd/Kconfig create mode 100755 bsd/Makefile create mode 120000 bsd/arm/autoconf.c create mode 120000 bsd/arm/hw_user_copy.S create mode 120000 bsd/arm/in_cksum.c create mode 120000 bsd/arm/in_cksum_arm.S create mode 120000 bsd/arm/include/_bus.h create mode 120000 bsd/arm/nexus.c create mode 100755 bsd/compat/linuxkpi/Makefile create mode 120000 bsd/compat/linuxkpi/include/asm/atomic.h create mode 120000 bsd/compat/linuxkpi/include/asm/barrier.h create mode 120000 bsd/compat/linuxkpi/include/asm/io.h create mode 120000 bsd/compat/linuxkpi/include/asm/page.h create mode 120000 bsd/compat/linuxkpi/include/linux/atomic.h create mode 120000 bsd/compat/linuxkpi/include/linux/compat.h create mode 120000 bsd/compat/linuxkpi/include/linux/compiler.h create mode 120000 bsd/compat/linuxkpi/include/linux/completion.h create mode 120000 bsd/compat/linuxkpi/include/linux/ctype.h create mode 120000 bsd/compat/linuxkpi/include/linux/delay.h create mode 120000 bsd/compat/linuxkpi/include/linux/dma-mapping.h create mode 120000 bsd/compat/linuxkpi/include/linux/errno.h create mode 120000 bsd/compat/linuxkpi/include/linux/fcntl.h create mode 120000 bsd/compat/linuxkpi/include/linux/fs.h create mode 120000 bsd/compat/linuxkpi/include/linux/hrtimer.h create mode 120000 bsd/compat/linuxkpi/include/linux/icmp.h create mode 120000 bsd/compat/linuxkpi/include/linux/interrupt.h create mode 120000 bsd/compat/linuxkpi/include/linux/io.h create mode 120000 bsd/compat/linuxkpi/include/linux/ioctl.h create mode 120000 bsd/compat/linuxkpi/include/linux/jiffies.h create mode 120000 bsd/compat/linuxkpi/include/linux/kernel.h create mode 120000 bsd/compat/linuxkpi/include/linux/list.h create mode 120000 bsd/compat/linuxkpi/include/linux/module.h create mode 120000 bsd/compat/linuxkpi/include/linux/moduleparam.h create mode 120000 bsd/compat/linuxkpi/include/linux/mtd/mtd.h create mode 120000 bsd/compat/linuxkpi/include/linux/mtd/mtd_list.h create mode 120000 bsd/compat/linuxkpi/include/linux/pagemap.h create mode 120000 bsd/compat/linuxkpi/include/linux/rbtree.h create mode 120000 bsd/compat/linuxkpi/include/linux/rtc.h create mode 120000 bsd/compat/linuxkpi/include/linux/rwsem.h create mode 120000 bsd/compat/linuxkpi/include/linux/scatterlist.h create mode 120000 bsd/compat/linuxkpi/include/linux/sched.h create mode 120000 bsd/compat/linuxkpi/include/linux/semaphore.h create mode 120000 bsd/compat/linuxkpi/include/linux/slab.h create mode 120000 bsd/compat/linuxkpi/include/linux/spinlock.h create mode 120000 bsd/compat/linuxkpi/include/linux/stat.h create mode 120000 bsd/compat/linuxkpi/include/linux/string.h create mode 120000 bsd/compat/linuxkpi/include/linux/timer.h create mode 120000 bsd/compat/linuxkpi/include/linux/tree.h create mode 120000 bsd/compat/linuxkpi/include/linux/types.h create mode 120000 bsd/compat/linuxkpi/include/linux/wait.h create mode 120000 bsd/compat/linuxkpi/include/linux/wakelock.h create mode 120000 bsd/compat/linuxkpi/include/linux/workqueue.h create mode 120000 bsd/compat/linuxkpi/include/linux/zutil.h create mode 120000 bsd/compat/linuxkpi/include/tzdst.h create mode 120000 bsd/compat/linuxkpi/include/tzdst_pri.h create mode 120000 bsd/compat/linuxkpi/src/adp.c create mode 120000 bsd/compat/linuxkpi/src/linux_completion.c create mode 120000 bsd/compat/linuxkpi/src/linux_hrtimer.c create mode 120000 bsd/compat/linuxkpi/src/linux_interrupt.c create mode 120000 bsd/compat/linuxkpi/src/linux_sched.c create mode 120000 bsd/compat/linuxkpi/src/linux_semaphore.c create mode 120000 bsd/compat/linuxkpi/src/linux_timer.c create mode 120000 bsd/compat/linuxkpi/src/linux_wakelock.c create mode 120000 bsd/compat/linuxkpi/src/linux_workqueue.c create mode 120000 bsd/compat/linuxkpi/src/prctl.c create mode 120000 bsd/compat/linuxkpi/src/tzdst.c create mode 120000 bsd/crypto/rijndael/rijndael-alg-fst.c create mode 120000 bsd/crypto/rijndael/rijndael-api-fst.c create mode 120000 bsd/crypto/rijndael/rijndael-api-fst.h create mode 120000 bsd/crypto/rijndael/rijndael.h create mode 120000 bsd/crypto/rijndael/rijndael_local.h create mode 120000 bsd/crypto/sha2/sha256.h create mode 120000 bsd/crypto/sha2/sha256c.c create mode 120000 bsd/dev/random/hash.c create mode 120000 bsd/dev/random/hash.h create mode 120000 bsd/dev/random/randomdev.h create mode 120000 bsd/dev/random/uint128.h create mode 120000 bsd/dev/random/unit_test.h create mode 120000 bsd/dev/random/yarrow.c create mode 120000 bsd/dev/random/yarrow.h create mode 100755 bsd/dev/usb/Kconfig create mode 100755 bsd/dev/usb/Makefile create mode 120000 bsd/dev/usb/controller/ehci.c create mode 120000 bsd/dev/usb/controller/ehci.h create mode 120000 bsd/dev/usb/controller/ehci_pci.c create mode 120000 bsd/dev/usb/controller/ehcireg.h create mode 120000 bsd/dev/usb/controller/usb_controller.c create mode 120000 bsd/dev/usb/controller/xhci.c create mode 120000 bsd/dev/usb/controller/xhci.h create mode 120000 bsd/dev/usb/controller/xhci_pci.c create mode 120000 bsd/dev/usb/controller/xhcireg.h create mode 120000 bsd/dev/usb/implementation/_macro_ref.h create mode 120000 bsd/dev/usb/implementation/_thread_ref.h create mode 120000 bsd/dev/usb/implementation/_types_ref.h create mode 120000 bsd/dev/usb/implementation/bsd_busspace.c create mode 120000 bsd/dev/usb/implementation/bsd_kernel.c create mode 120000 bsd/dev/usb/implementation/bsd_kernel.h create mode 120000 bsd/dev/usb/implementation/freebsd_sys.h create mode 120000 bsd/dev/usb/implementation/freebsd_usb.h create mode 120000 bsd/dev/usb/implementation/global_implementation.h create mode 120000 bsd/dev/usb/implementation/usb_api_pri.h create mode 120000 bsd/dev/usb/implementation/usb_btree.c create mode 120000 bsd/dev/usb/implementation/usb_btree.h create mode 120000 bsd/dev/usb/implementation/usb_busdma_loader.c create mode 120000 bsd/dev/usb/implementation/usb_init.c create mode 120000 bsd/dev/usb/implementation/usb_init.h create mode 120000 bsd/dev/usb/implementation/usb_version.c create mode 120000 bsd/dev/usb/implementation/usbdevs.h create mode 120000 bsd/dev/usb/input/uhid.c create mode 120000 bsd/dev/usb/input/usb_rdesc.h create mode 120000 bsd/dev/usb/linux_usb.c create mode 120000 bsd/dev/usb/linux_usb.h create mode 120000 bsd/dev/usb/net/if_axe.c create mode 120000 bsd/dev/usb/net/if_axereg.h create mode 120000 bsd/dev/usb/net/if_axge.c create mode 120000 bsd/dev/usb/net/if_axgereg.h create mode 120000 bsd/dev/usb/net/if_cdce.c create mode 120000 bsd/dev/usb/net/if_cdcereg.h create mode 120000 bsd/dev/usb/net/if_urndis.c create mode 120000 bsd/dev/usb/net/if_urndisreg.h create mode 120000 bsd/dev/usb/net/mii.h create mode 120000 bsd/dev/usb/net/usb_eth_drv.c create mode 120000 bsd/dev/usb/net/usb_eth_drv.h create mode 120000 bsd/dev/usb/net/usb_ethernet.c create mode 120000 bsd/dev/usb/net/usb_ethernet.h create mode 120000 bsd/dev/usb/quirk/usb_quirk.c create mode 120000 bsd/dev/usb/quirk/usb_quirk.h create mode 120000 bsd/dev/usb/serial.h create mode 120000 bsd/dev/usb/serial/u3g.c create mode 120000 bsd/dev/usb/serial/usb_serial.c create mode 120000 bsd/dev/usb/serial/usb_serial.h create mode 120000 bsd/dev/usb/storage/scsi.h create mode 120000 bsd/dev/usb/storage/scsi_all.h create mode 120000 bsd/dev/usb/storage/umass.c create mode 120000 bsd/dev/usb/storage/umass_fs.h create mode 120000 bsd/dev/usb/usb.h create mode 120000 bsd/dev/usb/usb_bus.h create mode 120000 bsd/dev/usb/usb_busdma.h create mode 120000 bsd/dev/usb/usb_cdc.h create mode 120000 bsd/dev/usb/usb_controller.h create mode 120000 bsd/dev/usb/usb_core.c create mode 120000 bsd/dev/usb/usb_core.h create mode 120000 bsd/dev/usb/usb_debug.c create mode 120000 bsd/dev/usb/usb_debug.h create mode 120000 bsd/dev/usb/usb_dev.c create mode 120000 bsd/dev/usb/usb_dev.h create mode 120000 bsd/dev/usb/usb_device.c create mode 120000 bsd/dev/usb/usb_device.h create mode 120000 bsd/dev/usb/usb_dynamic.c create mode 120000 bsd/dev/usb/usb_dynamic.h create mode 120000 bsd/dev/usb/usb_endian.h create mode 120000 bsd/dev/usb/usb_error.c create mode 120000 bsd/dev/usb/usb_freebsd_loader.h create mode 120000 bsd/dev/usb/usb_generic.c create mode 120000 bsd/dev/usb/usb_generic.h create mode 120000 bsd/dev/usb/usb_handle_request.c create mode 120000 bsd/dev/usb/usb_hid.c create mode 120000 bsd/dev/usb/usb_hub.c create mode 120000 bsd/dev/usb/usb_hub.h create mode 120000 bsd/dev/usb/usb_if.c create mode 120000 bsd/dev/usb/usb_if.h create mode 120000 bsd/dev/usb/usb_ioctl.h create mode 120000 bsd/dev/usb/usb_lookup.c create mode 120000 bsd/dev/usb/usb_mbuf.c create mode 120000 bsd/dev/usb/usb_mbuf.h create mode 120000 bsd/dev/usb/usb_parse.c create mode 120000 bsd/dev/usb/usb_process.c create mode 120000 bsd/dev/usb/usb_process.h create mode 120000 bsd/dev/usb/usb_request.c create mode 120000 bsd/dev/usb/usb_request.h create mode 120000 bsd/dev/usb/usb_transfer.c create mode 120000 bsd/dev/usb/usb_transfer.h create mode 120000 bsd/dev/usb/usb_util.c create mode 120000 bsd/dev/usb/usb_util.h create mode 120000 bsd/dev/usb/usbdi.h create mode 120000 bsd/dev/usb/usbdi_util.h create mode 120000 bsd/dev/usb/usbhid.h create mode 120000 bsd/kern/bus_if.c create mode 120000 bsd/kern/bus_if.h create mode 120000 bsd/kern/device_if.c create mode 120000 bsd/kern/device_if.h create mode 120000 bsd/kern/kern_condvar.c create mode 120000 bsd/kern/kern_timeout.c create mode 120000 bsd/kern/subr_bus.c create mode 120000 bsd/kern/subr_kobj.c create mode 120000 bsd/libkern/explicit_bzero.c create mode 120000 bsd/net/ppp_defs.h create mode 120000 bsd/sys/_callout.h create mode 120000 bsd/sys/bus.h create mode 120000 bsd/sys/callout.h create mode 120000 bsd/sys/cdefs.h create mode 120000 bsd/sys/condvar.h create mode 120000 bsd/sys/kernel.h create mode 120000 bsd/sys/kobj.h create mode 120000 bsd/sys/linker_set.h create mode 120000 bsd/sys/malloc.h create mode 120000 bsd/sys/module.h create mode 120000 bsd/sys/mutex.h create mode 120000 bsd/sys/priv.h create mode 120000 bsd/sys/queue.h create mode 120000 bsd/sys/sema.h create mode 120000 bsd/sys/sx.h create mode 120000 bsd/sys/systm.h create mode 100755 build.sh create mode 100755 compat/posix/Kconfig create mode 100755 compat/posix/Makefile create mode 100755 compat/posix/include/mqueue.h create mode 100755 compat/posix/include/time_posix.h create mode 100755 compat/posix/src/map_error.c create mode 100755 compat/posix/src/map_error.h create mode 100755 compat/posix/src/misc.c create mode 100755 compat/posix/src/mqueue.c create mode 100755 compat/posix/src/posix_memalign.c create mode 100755 compat/posix/src/pprivate.h create mode 100755 compat/posix/src/pthread.c create mode 100755 compat/posix/src/pthread_attr.c create mode 100755 compat/posix/src/pthread_cond.c create mode 100755 compat/posix/src/pthread_mutex.c create mode 100755 compat/posix/src/sched.c create mode 100755 compat/posix/src/semaphore.c create mode 100755 compat/posix/src/socket.c create mode 100755 compat/posix/src/time.c create mode 100755 config.mk create mode 100755 fs/fat/Kconfig create mode 100755 fs/fat/Makefile create mode 100755 fs/fat/os_adapt/fat_shellcmd.c create mode 100755 fs/fat/os_adapt/fatfs.c create mode 100755 fs/fat/virpart/Makefile create mode 100755 fs/fat/virpart/include/virpart.h create mode 100755 fs/fat/virpart/include/virpartff.h create mode 100755 fs/fat/virpart/src/virpart.c create mode 100755 fs/fat/virpart/src/virpartff.c create mode 120000 fs/include/compiler.h create mode 120000 fs/include/debug.h create mode 100755 fs/include/disk.h create mode 120000 fs/include/fs/automount.h create mode 120000 fs/include/fs/dirent_fs.h create mode 100755 fs/include/fs/fd_table.h create mode 120000 fs/include/fs/file.h create mode 120000 fs/include/fs/fs.h create mode 100755 fs/include/fs/fs_operation.h create mode 120000 fs/include/inode/inode.h create mode 120000 fs/include/net/net.h create mode 120000 fs/include/syslog.h create mode 100755 fs/include/vfs_config.h create mode 100755 fs/jffs2/Kconfig create mode 100755 fs/jffs2/Makefile create mode 100755 fs/nfs/Kconfig create mode 100755 fs/nfs/Makefile create mode 100755 fs/ramfs/Kconfig create mode 100755 fs/ramfs/Makefile create mode 100755 fs/vfs/Kconfig create mode 100755 fs/vfs/Makefile create mode 100755 fs/vfs/bcache/Makefile create mode 100755 fs/vfs/bcache/src/bcache.c create mode 100755 fs/vfs/bch/Makefile create mode 100755 fs/vfs/disk/Makefile create mode 100755 fs/vfs/disk/disk.c create mode 100755 fs/vfs/disk/disk_shellcmd.c create mode 100755 fs/vfs/include/bcache/bcache.h create mode 100755 fs/vfs/include/disk/disk_pri.h create mode 100755 fs/vfs/include/driver/blockproxy.h create mode 100755 fs/vfs/include/driver/driver.h create mode 100755 fs/vfs/include/driver/mtd_dev.h create mode 100755 fs/vfs/include/driver/mtd_list.h create mode 100755 fs/vfs/include/multi_partition/mtd_partition.h create mode 100755 fs/vfs/include/operation/fs_file.h create mode 100755 fs/vfs/include/operation/fs_other.h create mode 100755 fs/vfs/include/operation/fs_poll_pri.h create mode 100755 fs/vfs/multi_partition/Makefile create mode 100755 fs/vfs/multi_partition/src/mtd_partition.c create mode 100755 fs/vfs/multi_partition/src/mtd_shellcmd.c create mode 100755 fs/vfs/operation/fs_chattr.c create mode 100755 fs/vfs/operation/fs_check.c create mode 100755 fs/vfs/operation/fs_fallocate.c create mode 100755 fs/vfs/operation/fs_fallocate64.c create mode 100755 fs/vfs/operation/fs_file.c create mode 100755 fs/vfs/operation/fs_file_mapping.c create mode 100755 fs/vfs/operation/fs_getlabel.c create mode 100755 fs/vfs/operation/fs_init.c create mode 100755 fs/vfs/operation/fs_other.c create mode 100755 fs/vfs/operation/fs_preadv.c create mode 100755 fs/vfs/operation/fs_pwritev.c create mode 100755 fs/vfs/operation/fs_readv.c create mode 100755 fs/vfs/operation/fs_utime.c create mode 100755 fs/vfs/operation/fs_virstatfs.c create mode 100755 fs/vfs/operation/fs_writev.c create mode 100755 fs/vfs/operation/fullpath.c create mode 100755 fs/vfs/vfs_cmd/vfs_shellcmd.c create mode 100755 kernel/BUILD.gn create mode 100755 kernel/Kconfig create mode 100755 kernel/base/BUILD.gn create mode 100755 kernel/base/Makefile create mode 100755 kernel/base/core/los_bitmap.c create mode 100755 kernel/base/core/los_process.c create mode 100755 kernel/base/core/los_sortlink.c create mode 100755 kernel/base/core/los_swtmr.c create mode 100755 kernel/base/core/los_sys.c create mode 100755 kernel/base/core/los_task.c create mode 100755 kernel/base/core/los_tick.c create mode 100755 kernel/base/core/los_timeslice.c create mode 100755 kernel/base/include/los_base_pri.h create mode 100755 kernel/base/include/los_binarytree_pri.h create mode 100755 kernel/base/include/los_err_pri.h create mode 100755 kernel/base/include/los_event_pri.h create mode 100755 kernel/base/include/los_futex_pri.h create mode 100755 kernel/base/include/los_heap_pri.h create mode 100755 kernel/base/include/los_ipcdebug_pri.h create mode 100755 kernel/base/include/los_membox_pri.h create mode 100755 kernel/base/include/los_memory_pri.h create mode 100755 kernel/base/include/los_memrecord_pri.h create mode 100755 kernel/base/include/los_memstat_pri.h create mode 100755 kernel/base/include/los_multipledlinkhead_pri.h create mode 100755 kernel/base/include/los_mux_pri.h create mode 100755 kernel/base/include/los_oom.h create mode 100755 kernel/base/include/los_percpu_pri.h create mode 100755 kernel/base/include/los_pmm.h create mode 100755 kernel/base/include/los_printf_pri.h create mode 100755 kernel/base/include/los_priqueue_pri.h create mode 100755 kernel/base/include/los_process_pri.h create mode 100755 kernel/base/include/los_queue_debug_pri.h create mode 100755 kernel/base/include/los_queue_pri.h create mode 100755 kernel/base/include/los_sched_pri.h create mode 100755 kernel/base/include/los_sem_debug_pri.h create mode 100755 kernel/base/include/los_sem_pri.h create mode 100755 kernel/base/include/los_signal.h create mode 100755 kernel/base/include/los_sortlink_pri.h create mode 100755 kernel/base/include/los_stackinfo_pri.h create mode 100755 kernel/base/include/los_stat_pri.h create mode 100755 kernel/base/include/los_swtmr_pri.h create mode 100755 kernel/base/include/los_sys_pri.h create mode 100755 kernel/base/include/los_task_pri.h create mode 100755 kernel/base/include/los_tick_pri.h create mode 100755 kernel/base/include/los_timeslice_pri.h create mode 100755 kernel/base/include/los_typedef_pri.h create mode 100755 kernel/base/include/los_vm_boot.h create mode 100755 kernel/base/include/los_vm_common.h create mode 100755 kernel/base/include/los_vm_dump.h create mode 100755 kernel/base/include/los_vm_fault.h create mode 100755 kernel/base/include/los_vm_filemap.h create mode 100755 kernel/base/include/los_vm_iomap.h create mode 100755 kernel/base/include/los_vm_lock.h create mode 100755 kernel/base/include/los_vm_map.h create mode 100755 kernel/base/include/los_vm_page.h create mode 100755 kernel/base/include/los_vm_phys.h create mode 100755 kernel/base/include/los_vm_shm_pri.h create mode 100755 kernel/base/include/los_vm_syscall.h create mode 100755 kernel/base/include/los_vm_zone.h create mode 100755 kernel/base/ipc/los_event.c create mode 100755 kernel/base/ipc/los_futex.c create mode 100755 kernel/base/ipc/los_ipcdebug.c create mode 100755 kernel/base/ipc/los_mux.c create mode 100755 kernel/base/ipc/los_queue.c create mode 100755 kernel/base/ipc/los_queue_debug.c create mode 100755 kernel/base/ipc/los_sem.c create mode 100755 kernel/base/ipc/los_sem_debug.c create mode 100755 kernel/base/ipc/los_signal.c create mode 100755 kernel/base/mem/bestfit/los_memory.c create mode 100755 kernel/base/mem/bestfit/los_multipledlinkhead.c create mode 100755 kernel/base/mem/bestfit_little/los_heap.c create mode 100755 kernel/base/mem/common/los_memstat.c create mode 100755 kernel/base/mem/common/memrecord/los_binarytree.c create mode 100755 kernel/base/mem/common/memrecord/los_interto64radix.c create mode 100755 kernel/base/mem/common/memrecord/los_memrecord.c create mode 100755 kernel/base/mem/membox/los_membox.c create mode 100755 kernel/base/misc/kill_shellcmd.c create mode 100755 kernel/base/misc/los_misc.c create mode 100755 kernel/base/misc/los_stackinfo.c create mode 100755 kernel/base/misc/mempt_shellcmd.c create mode 100755 kernel/base/misc/swtmr_shellcmd.c create mode 100755 kernel/base/misc/sysinfo_shellcmd.c create mode 100755 kernel/base/misc/task_shellcmd.c create mode 100755 kernel/base/misc/vm_shellcmd.c create mode 100755 kernel/base/mp/los_lockdep.c create mode 100755 kernel/base/mp/los_mp.c create mode 100755 kernel/base/mp/los_percpu.c create mode 100755 kernel/base/mp/los_stat.c create mode 100755 kernel/base/om/los_err.c create mode 100755 kernel/base/sched/sched_sq/los_priqueue.c create mode 100755 kernel/base/sched/sched_sq/los_sched.c create mode 100755 kernel/base/vm/los_vm_boot.c create mode 100755 kernel/base/vm/los_vm_dump.c create mode 100755 kernel/base/vm/los_vm_fault.c create mode 100755 kernel/base/vm/los_vm_filemap.c create mode 100755 kernel/base/vm/los_vm_iomap.c create mode 100755 kernel/base/vm/los_vm_map.c create mode 100755 kernel/base/vm/los_vm_page.c create mode 100755 kernel/base/vm/los_vm_phys.c create mode 100755 kernel/base/vm/los_vm_scan.c create mode 100755 kernel/base/vm/los_vm_syscall.c create mode 100755 kernel/base/vm/oom.c create mode 100755 kernel/base/vm/shm.c create mode 100755 kernel/common/Kconfig create mode 100755 kernel/common/Makefile create mode 100755 kernel/common/console.c create mode 100755 kernel/common/console.h create mode 100755 kernel/common/hwi_shell.c create mode 100755 kernel/common/los_builddef.h create mode 100755 kernel/common/los_cir_buf.c create mode 100755 kernel/common/los_cir_buf_pri.h create mode 100755 kernel/common/los_config.c create mode 100755 kernel/common/los_config.h create mode 100755 kernel/common/los_exc_interaction.c create mode 100755 kernel/common/los_exc_interaction_pri.h create mode 100755 kernel/common/los_excinfo.c create mode 100755 kernel/common/los_excinfo_pri.h create mode 100755 kernel/common/los_hilog.c create mode 100755 kernel/common/los_hilog.h create mode 100755 kernel/common/los_magickey.c create mode 100755 kernel/common/los_magickey.h create mode 100755 kernel/common/los_printf.c create mode 100755 kernel/common/los_rootfs.c create mode 100755 kernel/common/los_rootfs.h create mode 100755 kernel/common/los_seq_buf.c create mode 100755 kernel/common/los_seq_buf.h create mode 100755 kernel/common/los_timer_pri.h create mode 100755 kernel/common/sys_config.h create mode 100755 kernel/common/virtual_serial.c create mode 100755 kernel/common/virtual_serial.h create mode 100755 kernel/extended/cppsupport/Makefile create mode 100755 kernel/extended/cppsupport/los_cppsupport.c create mode 100755 kernel/extended/cpup/Makefile create mode 100755 kernel/extended/cpup/cpup_shellcmd.c create mode 100755 kernel/extended/cpup/los_cpup.c create mode 100755 kernel/extended/dynload/Makefile create mode 100755 kernel/extended/dynload/include/los_elf_auxvec_pri.h create mode 100755 kernel/extended/dynload/include/los_exec_elf.h create mode 100755 kernel/extended/dynload/include/los_ld_elf_pri.h create mode 100755 kernel/extended/dynload/include/los_load_elf.h create mode 100755 kernel/extended/dynload/src/los_exec_elf.c create mode 100755 kernel/extended/dynload/src/los_load_elf.c create mode 100755 kernel/extended/include/los_cpup_pri.h create mode 100755 kernel/extended/include/los_tickless_pri.h create mode 100755 kernel/extended/include/los_trace_pri.h create mode 100755 kernel/extended/liteipc/Makefile create mode 100755 kernel/extended/liteipc/hm_liteipc.c create mode 100755 kernel/extended/liteipc/hm_liteipc.h create mode 120000 kernel/extended/pipe create mode 100755 kernel/extended/tickless/Makefile create mode 100755 kernel/extended/tickless/los_tickless.c create mode 100755 kernel/extended/trace/Makefile create mode 100755 kernel/extended/trace/los_trace.c create mode 100755 kernel/extended/vdso/include/los_vdso.h create mode 100755 kernel/extended/vdso/include/los_vdso_datapage.h create mode 100755 kernel/extended/vdso/include/los_vdso_pri.h create mode 100755 kernel/extended/vdso/src/Makefile create mode 100755 kernel/extended/vdso/src/los_vdso.c create mode 100755 kernel/extended/vdso/src/los_vdso_text.S create mode 100755 kernel/extended/vdso/usr/Makefile create mode 100755 kernel/extended/vdso/usr/los_vdso.ld create mode 100755 kernel/extended/vdso/usr/los_vdso_sys.c create mode 100755 kernel/include/los_base.h create mode 100755 kernel/include/los_bitmap.h create mode 100755 kernel/include/los_cppsupport.h create mode 100755 kernel/include/los_cpup.h create mode 100755 kernel/include/los_err.h create mode 100755 kernel/include/los_errno.h create mode 100755 kernel/include/los_event.h create mode 100755 kernel/include/los_ld_elflib.h create mode 100755 kernel/include/los_list.h create mode 100755 kernel/include/los_lockdep.h create mode 100755 kernel/include/los_membox.h create mode 100755 kernel/include/los_memory.h create mode 100755 kernel/include/los_mp.h create mode 100755 kernel/include/los_mux.h create mode 100755 kernel/include/los_printf.h create mode 100755 kernel/include/los_process.h create mode 100755 kernel/include/los_queue.h create mode 100755 kernel/include/los_sem.h create mode 100755 kernel/include/los_spinlock.h create mode 100755 kernel/include/los_swtmr.h create mode 100755 kernel/include/los_sys.h create mode 100755 kernel/include/los_tables.h create mode 100755 kernel/include/los_task.h create mode 100755 kernel/include/los_tick.h create mode 100755 kernel/include/los_tickless.h create mode 100755 kernel/include/los_toolchain.h create mode 100755 kernel/include/los_trace.h create mode 100755 kernel/include/los_typedef.h create mode 100755 kernel/user/Makefile create mode 100755 kernel/user/include/los_user_init.h create mode 100755 kernel/user/src/los_user_init.c create mode 100755 lib/Kconfig create mode 100755 lib/libc/Makefile create mode 100755 lib/libmbedtls/Makefile create mode 100755 lib/libscrew/Makefile create mode 100755 lib/libscrew/include/los_crc32.h create mode 100755 lib/libscrew/include/los_rbtree.h create mode 100755 lib/libscrew/src/los_crc32.c create mode 100755 lib/libscrew/src/los_rbtree.c create mode 100755 lib/libsec/Makefile create mode 100755 lib/zlib/Makefile create mode 100755 net/Kconfig create mode 100755 net/lwip-2.1/Makefile create mode 100755 net/lwip-2.1/enhancement/include/api_shell.h create mode 100755 net/lwip-2.1/enhancement/include/api_shell_fix.h create mode 100755 net/lwip-2.1/enhancement/include/dhcps.h create mode 100755 net/lwip-2.1/enhancement/include/dhcps_fix.h create mode 100755 net/lwip-2.1/enhancement/src/api_shell.c create mode 100755 net/lwip-2.1/enhancement/src/api_shell_fix.c create mode 100755 net/lwip-2.1/porting/include/arch/cc.h create mode 100755 net/lwip-2.1/porting/include/arch/perf.h create mode 100755 net/lwip-2.1/porting/include/arch/sys_arch.h create mode 100755 net/lwip-2.1/porting/include/lwip/dhcp.h create mode 100755 net/lwip-2.1/porting/include/lwip/inet.h create mode 100755 net/lwip-2.1/porting/include/lwip/lwipopts.h create mode 100755 net/lwip-2.1/porting/include/lwip/netif.h create mode 100755 net/lwip-2.1/porting/include/lwip/netifapi.h create mode 100755 net/lwip-2.1/porting/include/lwip/pbuf.h create mode 100755 net/lwip-2.1/porting/include/lwip/priv/api_msg.h create mode 100755 net/lwip-2.1/porting/include/lwip/priv/sockets_priv.h create mode 100755 net/lwip-2.1/porting/include/lwip/sockets.h create mode 100755 net/lwip-2.1/porting/include/lwipopts.h create mode 100755 net/lwip-2.1/porting/src/driverif.c create mode 100755 net/lwip-2.1/porting/src/fixme.c create mode 100755 net/lwip-2.1/porting/src/sockets.c create mode 100755 net/lwip-2.1/porting/src/sys_arch.c create mode 100755 net/mac/los_mac.h create mode 100755 net/telnet/Kconfig create mode 100755 net/telnet/Makefile create mode 100755 net/telnet/include/telnet_dev.h create mode 100755 net/telnet/include/telnet_loop.h create mode 100755 net/telnet/include/telnet_pri.h create mode 100755 net/telnet/src/telnet_dev.c create mode 100755 net/telnet/src/telnet_loop.c create mode 100755 platform/Kconfig create mode 100755 platform/Makefile create mode 100755 platform/board.ld.S create mode 100755 platform/bsp.mk create mode 100755 platform/hw/arm/interrupt/gic/gic_v2.c create mode 100755 platform/hw/arm/interrupt/gic/gic_v3.c create mode 100755 platform/hw/arm/timer/arm_generic/arm_generic_timer.c create mode 100755 platform/hw/arm/timer/arm_private/arm_private_timer.c create mode 100755 platform/hw/hisoc/hrtimer/hrtimer.c create mode 100755 platform/hw/hisoc/timer/timer.c create mode 100755 platform/hw/include/gic_common.h create mode 100755 platform/hw/include/gic_v3.h create mode 100755 platform/include/hal_hwi.h create mode 100755 platform/include/hal_timer.h create mode 100755 platform/main.c create mode 100755 platform/uart/amba-pl011-lagacy/uart.c create mode 100755 platform/uart/amba_pl011/amba_pl011.c create mode 100755 platform/uart/amba_pl011/amba_pl011.h create mode 100755 platform/uart/dw-3.0.8a/uart.c create mode 100755 platform/usb/usb3.0_hi3516dv300/usb_board.c create mode 100755 platform/usb/usb3.0_hi3518ev300/usb_board.c create mode 100755 readme.md create mode 100755 security/Kconfig create mode 100755 security/Makefile create mode 100755 security/cap/Makefile create mode 100755 security/cap/capability.c create mode 100755 security/cap/capability_api.h create mode 100755 security/cap/capability_type.h create mode 100755 security/vid/vid.c create mode 100755 security/vid/vid_api.h create mode 100755 security/vid/vid_type.h create mode 100755 shell/BUILD.gn create mode 100755 shell/Kconfig create mode 100755 shell/Makefile create mode 100755 shell/full/include/dmesg.h create mode 100755 shell/full/include/dmesg_pri.h create mode 100755 shell/full/include/shcmd.h create mode 100755 shell/full/include/shcmdparse.h create mode 100755 shell/full/include/shell.h create mode 100755 shell/full/include/shell_lk.h create mode 100755 shell/full/include/shell_pri.h create mode 100755 shell/full/include/shmsg.h create mode 100755 shell/full/include/show.h create mode 100755 shell/full/src/base/shcmd.c create mode 100755 shell/full/src/base/shcmdparse.c create mode 100755 shell/full/src/base/shell_lk.c create mode 100755 shell/full/src/base/shmsg.c create mode 100755 shell/full/src/base/show.c create mode 100755 shell/full/src/cmds/date_shell.c create mode 100755 shell/full/src/cmds/dmesg.c create mode 100755 shell/full/src/cmds/excinfo_shell.c create mode 100755 shell/full/src/cmds/shell_shellcmd.c create mode 100755 shell/full/src/cmds/watch_shell.c create mode 100755 syscall/Makefile create mode 100755 syscall/fs_syscall.c create mode 100755 syscall/ipc_syscall.c create mode 100755 syscall/los_syscall.c create mode 100755 syscall/los_syscall.h create mode 100755 syscall/misc_syscall.c create mode 100755 syscall/net_syscall.c create mode 100755 syscall/process_syscall.c create mode 100755 syscall/syscall_lookup.h create mode 100755 syscall/time_syscall.c create mode 100755 syscall/vm_syscall.c create mode 100755 tools/.gitignore create mode 100755 tools/build/config.mk create mode 100755 tools/build/config/debug/hi3516dv300.config create mode 100755 tools/build/config/debug/hi3516dv300_clang.config create mode 100755 tools/build/config/debug/hi3518ev300.config create mode 100755 tools/build/config/debug/hi3518ev300_clang.config create mode 100755 tools/build/config/hi3516dv300_clang_release.config create mode 100755 tools/build/config/hi3516dv300_debug_shell.config create mode 100755 tools/build/config/hi3516dv300_release.config create mode 100755 tools/build/config/hi3518ev300_clang_release.config create mode 100755 tools/build/config/hi3518ev300_debug_shell.config create mode 100755 tools/build/config/hi3518ev300_release.config create mode 100755 tools/build/liteos.ld create mode 100755 tools/build/liteos_llvm.ld create mode 100755 tools/build/mk/bepbuildtime.conf create mode 100755 tools/build/mk/dynload.mk create mode 100755 tools/build/mk/get_llvm_compiler_path.sh create mode 100755 tools/build/mk/liteos_tables_ldflags.mk create mode 100755 tools/build/mk/los_config.mk create mode 100755 tools/build/mk/module.mk create mode 100755 tools/fsimage/MakeVersion.sh create mode 100755 tools/fsimage/mkfs.jffs2 create mode 100755 tools/fsimage/win-x86/cygz.dll create mode 100755 tools/fsimage/win-x86/doc_loadbios.exe create mode 100755 tools/fsimage/win-x86/docfdisk.exe create mode 100755 tools/fsimage/win-x86/flash_erase.exe create mode 100755 tools/fsimage/win-x86/flash_eraseall create mode 100755 tools/fsimage/win-x86/flash_lock.exe create mode 100755 tools/fsimage/win-x86/flash_otp_dump.exe create mode 100755 tools/fsimage/win-x86/flash_otp_info.exe create mode 100755 tools/fsimage/win-x86/flash_otp_lock.exe create mode 100755 tools/fsimage/win-x86/flash_otp_write.exe create mode 100755 tools/fsimage/win-x86/flash_unlock.exe create mode 100755 tools/fsimage/win-x86/flashcp.exe create mode 100755 tools/fsimage/win-x86/ftl_check.exe create mode 100755 tools/fsimage/win-x86/ftl_format.exe create mode 100755 tools/fsimage/win-x86/jffs2dump.exe create mode 100755 tools/fsimage/win-x86/jffs2reader.exe create mode 100755 tools/fsimage/win-x86/lsmtd.exe create mode 100755 tools/fsimage/win-x86/mkfs.jffs2.exe create mode 100755 tools/fsimage/win-x86/mtd_debug.exe create mode 100755 tools/fsimage/win-x86/mtdinfo.exe create mode 100755 tools/fsimage/win-x86/mtdpart.exe create mode 100755 tools/fsimage/win-x86/nanddump.exe create mode 100755 tools/fsimage/win-x86/nandtest.exe create mode 100755 tools/fsimage/win-x86/nandwrite.exe create mode 100755 tools/fsimage/win-x86/nftl_format.exe create mode 100755 tools/fsimage/win-x86/nftldump.exe create mode 100755 tools/fsimage/win-x86/recv_image.exe create mode 100755 tools/fsimage/win-x86/rfddump.exe create mode 100755 tools/fsimage/win-x86/rfdformat.exe create mode 100755 tools/fsimage/win-x86/serve_image.exe create mode 100755 tools/fsimage/win-x86/sumtool.exe create mode 100755 tools/fsimage/win-x86/ubiattach.exe create mode 100755 tools/fsimage/win-x86/ubiblock.exe create mode 100755 tools/fsimage/win-x86/ubicrc32.exe create mode 100755 tools/fsimage/win-x86/ubidetach.exe create mode 100755 tools/fsimage/win-x86/ubiformat.exe create mode 100755 tools/fsimage/win-x86/ubimkvol.exe create mode 100755 tools/fsimage/win-x86/ubinfo.exe create mode 100755 tools/fsimage/win-x86/ubinize.exe create mode 100755 tools/fsimage/win-x86/ubirename.exe create mode 100755 tools/fsimage/win-x86/ubirmvol.exe create mode 100755 tools/fsimage/win-x86/ubirsvol.exe create mode 100755 tools/fsimage/win-x86/ubiupdatevol.exe create mode 100755 tools/menuconfig/conf create mode 100755 tools/menuconfig/mconf create mode 100755 tools/scripts/make_rootfs/releaseinfo.sh create mode 100755 tools/scripts/make_rootfs/rootfs.sh create mode 100755 tools/scripts/make_rootfs/rootfsdir.sh create mode 100755 tools/scripts/make_rootfs/rootfsimg.sh diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md new file mode 100755 index 00000000..f09d98dd --- /dev/null +++ b/.gitee/ISSUE_TEMPLATE.zh-CN.md @@ -0,0 +1,13 @@ +### 该问题是怎么引起的? + + + +### 重现步骤 + + + +### 报错信息 + + + + diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md new file mode 100755 index 00000000..33948fdc --- /dev/null +++ b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md @@ -0,0 +1,15 @@ +### 相关的Issue + + +### 原因(目的、解决的问题等) + + +### 描述(做了什么,变更了什么) + + +### 测试用例(新增、改动、可能影响的功能) + + + + + diff --git a/.gitignore b/.gitignore new file mode 100755 index 00000000..cf00b530 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +/out +/fs/proc +/test +/include +.config* +cscope* +tags +.vscode +*.o +.idea +*.img +*.swp +*.rej +*.orig +*.a +*.so +.config.cmd +.settings +.cproject +.project +platform/include/menuconfig.h +platform/board.ld +apps/init/init +apps/shell/shell +lib/libc/musl diff --git a/BUILD.gn b/BUILD.gn new file mode 100755 index 00000000..a7e30ac3 --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,68 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//build/lite/config/subsystem/lite_subsystem.gni") + +declare_args() { + enable_ohos_kernel_liteos_a_ext_build = true + LOSCFG_TEST_APPS = false +} + +lite_subsystem("kernel") { + subsystem_components = [] + + if (enable_ohos_kernel_liteos_a_ext_build == false) { + subsystem_components += [ + "//kernel/liteos_a/kernel", + "//kernel/liteos_a/net", + "//kernel/liteos_a/lib", + "//kernel/liteos_a/compat", + "//kernel/liteos_a/fs", + "//kernel/liteos_a/arch:platform_cpu", + ] + if (LOSCFG_SHELL) { + subsystem_components += [ "//kernel/liteos_a/shell" ] + } + } else { + deps = [":make"] + } +} + +action("make") { + script = "//build/lite/build_ext_components.py" + outputs = [ "$target_gen_dir/liteos_a_build_log.txt" ] + exec_path = rebase_path(rebase_path(".", root_build_dir)) + outdir = rebase_path(get_path_info(".", "out_dir")) + command = "make clean OUTDIR=$outdir && make rootfs VERSION=\"${ohos_version}\" -j 16 OUTDIR=$outdir" + args = [ + "--path=$exec_path", + "--prebuilts=sh build.sh ${board_name} ${ohos_build_compiler} ${ohos_build_type}", + "--command=${command}" + ] +} diff --git a/Kconfig b/Kconfig new file mode 100755 index 00000000..522800bd --- /dev/null +++ b/Kconfig @@ -0,0 +1,381 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +# For a description of the syntax of this configuration file, +# see extra/config/Kconfig-language.txt +# +mainmenu "Huawei LiteOS Configuration" + +menu "Compiler" +choice + prompt "LiteOS_Compiler_Type" + default COMPILER_CLANG_LLVM + help + Enable arm-himix100 or aarch64-himix100 or compiler. + +config COMPILER_HIMIX_32 + bool "arm-linux-ohoseabi" + depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 + +config COMPILER_CLANG_LLVM + bool "clang-llvm" + depends on PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300 + +endchoice +endmenu + +menu "Platform" + +######################### config options of bsp ##################### +source "../../kernel/liteos_a/platform/Kconfig" + +######################### config options of cpu arch ################ +source "../../kernel/liteos_a/arch/Kconfig" + +######################### config options of rootfs ##################### +source "../../kernel/liteos_a/kernel/common/Kconfig" +endmenu + +######################### config options of kernel ##################### +source "../../kernel/liteos_a/kernel/Kconfig" +######################### config options of lib ######################## +source "../../kernel/liteos_a/lib/Kconfig" +######################### config options of compatibility ############## +menu "Compat" +source "../../kernel/liteos_a/compat/posix/Kconfig" +source "../../kernel/liteos_a/bsd/Kconfig" +endmenu + +######################### config options of framework ################## +#source "../../frameworks/m2mcomm/Kconfig" + +######################## config options of filesystem ################## +menu "FileSystem" +source "../../kernel/liteos_a/fs/vfs/Kconfig" +source "../../kernel/liteos_a/fs/fat/Kconfig" +source "../../kernel/liteos_a/fs/ramfs/Kconfig" +source "../../kernel/liteos_a/fs/nfs/Kconfig" +source "../../kernel/liteos_a/fs/proc/Kconfig" +source "../../kernel/liteos_a/fs/jffs2/Kconfig" +endmenu + +######################## config options of net ############################ +source "../../kernel/liteos_a/net/Kconfig" + +######################## config options of debug ######################## +menu "Debug" +config COMPILE_DEBUG + bool "Enable GCC -g Option" + default n + help + Answer Y to add -g option in gcc command. But the LiteOS size will be much larger. + +config PLATFORM_ADAPT + bool "Enable Os_adapt" + default y + help + Answer Y to add os_adapt.c to LiteOS. + +config ENABLE_OOM_LOOP_TASK + bool "Enable Oom loop task" + default n + help + Answer Y to enable oom loop kthread to check system out of memory. + +config DO_ALIGN + bool "Enable do align for hi3518e" + default y + depends on PLATFORM_HI3518EV200 + help + Answer Y to enable do align for hi3518e. + + +config ENABLE_MAGICKEY + bool "Enable MAGIC KEY" + default y + help + Answer Y to enable LiteOS Magic key. + ctrl + r : Magic key check switch; + ctrl + z : Show all magic op key; + ctrl + t : Show task information; + ctrl + p : System panic; + ctrl + e : Check system memory pool. + +config THUMB + bool "Enable Thumb" + default n + help + Answer Y to build thumb version. This will make LiteOS smaller. +config PLATFORM_DVFS + bool "Enable Dvfs" + default n + depends on COMPAT_LINUXKPI + help + Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for + low power consumption. + +config DEBUG_VERSION + bool "Enable a Debug Version" + default n + help + If you do not select this option that means you enable a release version for LiteOS. + It also means you do not want to use debug modules, like shell,telnet,tftp, + ,nfs,ramfs proc and memory check. + If you select this option that means you enable a debug version for LiteOS. + That means you want a opposite behaviour compared to release version. + +config DEBUG_KERNEL + bool "Enable Debug LiteOS Kernel Resource" + default n + depends on DEBUG_VERSION + help + If you select this option that means you enable debugging kernel resource. + It also means you want to get queue, mutex, semaphore, memory debug information. + That means you want a opposite behaviour compared to release version. + +config DEBUG_QUEUE + bool "Enable Queue Debugging" + default n + depends on DEBUG_KERNEL + help + Answer Y to enable debug queue. + +config DEBUG_DEADLOCK + bool "Enable Mutex Deadlock Debugging" + default n + depends on DEBUG_KERNEL + help + Answer Y to enable debug mutex deadlock. + +config DEBUG_SEMAPHORE + bool "Enable Semaphore Debugging" + default n + depends on DEBUG_KERNEL + help + Answer Y to enable debug semaphore. + +source "../../kernel/liteos_a/shell/Kconfig" +config NET_LWIP_SACK_TFTP + bool "Enable Tftp" + default y + depends on SHELL && NET_LWIP_SACK && DEBUG_VERSION + help + Answer Y to enable LiteOS support tftp cmd and tftp tool. +source "../../kernel/liteos_a/net/telnet/Kconfig" +config EXC_INTERACTION + bool "Enable exc interaction" + default n + depends on SHELL + help + Answer Y to enable exception interaction for LiteOS, when the system enter exception, user can also interact with system by shell + command like readreg, writereg,task,hwi. + +config USER_INIT_DEBUG + bool "Enable user init Debug" + default n + depends on DEBUG_VERSION + +config SHELL_CMD_DEBUG + bool "Enable shell cmd Debug" + default n + depends on DEBUG_VERSION && SHELL + +config USB_DEBUG + bool "Enable USB Debug" + default n + depends on SHELL && DRIVERS_USB && DEBUG_VERSION + help + Answer Y to enable LiteOS support usb debug. + use shell command to open the specified debug level print. +config MEM_DEBUG + bool "Enable MEM Debug" + default n + depends on DEBUG_VERSION + help + Answer Y to enable LiteOS support mem debug. + +config MEM_MUL_MODULE + bool "Enable Memory module statistics" + default n + depends on MEM_DEBUG + help + Answer Y to enable LiteOS support memory statistics depend on different module +config MEM_MUL_POOL + bool "Enable Memory multi-pool control" + default y + depends on DEBUG_VERSION && MEM_DEBUG + help + Answer Y to enable LiteOS support memory multi-pool control +config MEM_HEAD_BACKUP + bool "Enable Node Head Backup" + default 0 + depends on DEBUG_VERSION && MEM_DEBUG + help + Answer Y to enable node head backup +config MEM_RECORDINFO + bool "Enable Mem Record" + default n + depends on DEBUG_VERSION && MEM_DEBUG + help + Answer Y to enable mem record +config MEM_LEAKCHECK + bool "Enable Function call stack of Mem operation recorded" + default n + depends on DEBUG_VERSION && MEM_DEBUG + help + Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the infomations of mem node. +config BASE_MEM_NODE_INTEGRITY_CHECK + bool "Enable integrity check or not " + default n + depends on DEBUG_VERSION && MEM_DEBUG +config BASE_MEM_NODE_SIZE_CHECK + bool "Enable size check or not" + default n + depends on DEBUG_VERSION && MEM_DEBUG +config SLAB_INFO_STATISTIC + bool "Enable SLAB Statistic" + default n + depends on DEBUG_VERSION && KERNEL_MEM_SLAB && MEM_DEBUG + +config VM_OVERLAP_CHECK + bool "Enable VM overlap check or not" + default n + depends on DEBUG_VERSION && MEM_DEBUG + help + Answer Y to enable vm overlap check. + +config NULL_ADDRESS_PROTECT + bool "Enable NULL Address protect" + default n + depends on (PLATFORM_HI3518EV200 || PLATFORM_HI3516CV300 || PLATFORM_HI3518EV300 || PLATFORM_HI3516DV300) && DEBUG_VERSION + help + Answer Y to set mem address 0~1M prohibit to access, read or write will trigger exception. + +choice + prompt "Enable Uart" + default DRIVERS_HDF_PLATFORM_UART + help + Enable simple uart (without vfs) only for litekernel. + Enable general uart (with vfs) for full code. +source "../../vendor/hisi/hi35xx/platform/uart/Kconfig" +config PLATFORM_UART_WITHOUT_VFS + bool "Simple Uart" +config PLATFORM_NO_UART + bool "NO Uart" + +endchoice +endmenu + +######################## config options os drivers ######################## +menu "Driver" +config DRIVERS + bool "Enable Driver" + default y + help + Answer Y to enable LiteOS support driver. + +source "../../vendor/hisi/hi35xx/platform/hiedmac/Kconfig" +source "../../kernel/liteos_a/bsd/dev/usb/Kconfig" +source "../../drivers/hdf/lite/Kconfig" + +config DRIVERS_NETDEV + bool "Enable Net Device" + default y + depends on DRIVERS && NET_LWIP_SACK + help + Answer Y to enable LiteOS support net device. + +choice + depends on DRIVERS_NETDEV + prompt "MAC" + default n + help + Enable higmac for hi3516a hi3519 hi3559a_cortex-a53_aarch64. + Enable hieth-sf for hi3516cv300 hi3516ev200 and hi3518ev200. +source "../../vendor/hisi/hi35xx/platform/hieth-sf/Kconfig" +endchoice + +source "../../drivers/liteos/mem/Kconfig" +source "../../vendor/hisi/hi35xx/platform/mmc/Kconfig" + + +config DRIVERS_MTD + bool "Enable MTD" + default y + depends on DRIVERS && FS_VFS + help + Answer Y to enable LiteOS support jffs2 multipartion. + +source "../../vendor/hisi/hi35xx/platform/mtd/spi_nor/Kconfig" +source "../../drivers/liteos/random/Kconfig" +source "../../drivers/liteos/tzdriver/Kconfig" +source "../../drivers/liteos/video/Kconfig" +source "../../drivers/liteos/hievent/Kconfig" + +endmenu + +menu "Security" +source "../../kernel/liteos_a/security/Kconfig" +endmenu + +menu "Stack Smashing Protector (SSP) Compiler Feature" + +choice + prompt "Enable stack buffer overflow detection" + default CC_STACKPROTECTOR_STRONG + ---help--- + This option turns on the -fstack-protector GCC feature. This + feature puts, at the beginning of functions, a canary value on + the stack just before the return address, and validates + the value just before actually returning. Stack based buffer + overflows (that need to overwrite this return address) now also + overwrite the canary, which gets detected and the attack is then + neutralized via a kernel panic. + + This feature requires gcc version 4.2 or above, or a distribution + gcc with the feature backported. Older versions are automatically + detected and for those versions, this configuration option is + ignored. (and a warning is printed during bootup) + +config CC_NO_STACKPROTECTOR + bool "-fno-stack-protector" + +config CC_STACKPROTECTOR + bool "-fstack-protector" + +config CC_STACKPROTECTOR_STRONG + bool "-fstack-protector-strong" + +config CC_STACKPROTECTOR_ALL + bool "-fstack-protector-all" + +endchoice + +endmenu diff --git a/Makefile b/Makefile new file mode 100755 index 00000000..673c0988 --- /dev/null +++ b/Makefile @@ -0,0 +1,202 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +LITEOSTOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi) +export OS=$(shell uname -s) +ifneq ($(OS), Linux) +LITEOSTOPDIR := $(shell dirname $(subst \,/,$(LITEOSTOPDIR))/./) +endif + +LITEOSTHIRDPARTY := $(LITEOSTOPDIR)/../../third_party + +export LITEOSTOPDIR +export LITEOSTHIRDPARTY + +-include $(LITEOSTOPDIR)/tools/build/config.mk + +RM = -rm -rf +MAKE = make +__LIBS = libs +APPS = apps +ROOTFSDIR = rootfsdir +ROOTFS = rootfs + +LITEOS_TARGET = liteos +LITEOS_LIBS_TARGET = libs_target +LITEOS_MENUCONFIG_H = $(LITEOSTOPDIR)/include/generated/autoconf.h +LITEOS_PLATFORM_BASE = $(LITEOSTOPDIR)/platform +LITEOS_PLATFORM_MENUCONFIG_H = $(LITEOS_PLATFORM_BASE)/include/menuconfig.h + +ifeq ($(LOSCFG_PLATFORM_HI3518EV300), y) +FSTYPE = jffs2 +endif +ifeq ($(LOSCFG_PLATFORM_HI3516DV300), y) +FSTYPE = vfat +endif +ROOTFS_DIR = $(OUT)/rootfs +ROOTFS_ZIP = $(OUT)/rootfs.zip +VERSION = + +all: $(OUT) $(BUILD) $(LITEOS_TARGET) $(APPS) +lib: $(OUT) $(BUILD) $(LITEOS_LIBS_TARGET) + +help: + $(HIDE)echo "-------------------------------------------------------" + $(HIDE)echo "1.====make help: get help infomation of make" + $(HIDE)echo "2.====make: make a debug version based the .config" + $(HIDE)echo "3.====make debug: make a debug version based the .config" + $(HIDE)echo "4.====make release: make a release version for all platform" + $(HIDE)echo "5.====make release PLATFORM=xxx: make a release version only for platform xxx" + $(HIDE)echo "6.====make rootfsdir: make a original rootfs dir" + $(HIDE)echo "7.====make rootfs FSTYPE=***: make a original rootfs img" + $(HIDE)echo "8.====make test: make the testsuits_app and put it into the rootfs dir" + $(HIDE)echo "9.====make test_apps FSTYPE=***: make a rootfs img with the testsuits_app in it" + $(HIDE)echo "xxx should be one of (hi3516cv300 hi3516ev200 hi3556av100/cortex-a53_aarch32 hi3559av100/cortex-a53_aarch64)" + $(HIDE)echo "*** should be one of (jffs2)" + $(HIDE)echo "-------------------------------------------------------" + +debug: + $(HIDE)echo "=============== make a debug version ===============" + $(HIDE) $(MAKE) all + +release: +ifneq ($(PLATFORM),) + $(HIDE)echo "=============== make a release version for platform $(PLATFORM) ===============" + $(HIDE)$(SCRIPTS_PATH)/mklibversion.sh $(PLATFORM) +else + $(HIDE)echo "================make a release version for all platform ===============" + $(HIDE)$(SCRIPTS_PATH)/mklibversion.sh +endif + +##### make dynload ##### +-include $(LITEOS_MK_PATH)/dynload.mk + +#-----need move when make version-----# +##### make lib ##### +$(__LIBS): $(OUT) $(CXX_INCLUDE) + +$(OUT): $(LITEOS_MENUCONFIG_H) + $(HIDE)mkdir -p $(OUT)/lib + $(HIDE)$(CC) -I$(LITEOS_PLATFORM_BASE)/include -I$(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board \ + -E $(LITEOS_PLATFORM_BASE)/board.ld.S \ + -o $(LITEOS_PLATFORM_BASE)/board.ld -P + +$(BUILD): + $(HIDE)mkdir -p $(BUILD) + +$(LITEOS_LIBS_TARGET): $(__LIBS) + $(HIDE)for dir in $(LIB_SUBDIRS); \ + do $(MAKE) -C $$dir all || exit 1; \ + done + $(HIDE)echo "=============== make lib done ===============" + +##### make menuconfig ##### +export CONFIG_=LOSCFG_ +MENUCONFIG_PATH = $(LITEOSTOPDIR)/tools/menuconfig +KCONFIG_FILE_PATH = $(LITEOSTOPDIR)/Kconfig + +menuconfig:$(MENUCONFIG_PATH)/mconf + $< $(KCONFIG_FILE_PATH) + +genconfig:$(MENUCONFIG_PATH)/conf + $(HIDE)mkdir -p include/config include/generated + $< --silentoldconfig $(KCONFIG_FILE_PATH) + -mv -f $(LITEOS_MENUCONFIG_H) $(LITEOS_PLATFORM_MENUCONFIG_H) +##### menuconfig end ####### + +$(LITEOS_MENUCONFIG_H): +ifneq ($(LITEOS_PLATFORM_MENUCONFIG_H), $(wildcard $(LITEOS_PLATFORM_MENUCONFIG_H))) + $(HIDE)$(MAKE) genconfig +endif +$(LITEOS_TARGET): $(__LIBS) + $(HIDE)touch $(LOSCFG_ENTRY_SRC) + + $(HIDE)for dir in $(LITEOS_SUBDIRS); \ + do $(MAKE) -C $$dir all || exit 1; \ + done + + $(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) $(LITEOS_DYNLDFLAGS) -Map=$(OUT)/$@.map -o $(OUT)/$@ --start-group $(LITEOS_LIBDEP) --end-group +# $(SIZE) -t --common $(OUT)/lib/*.a >$(OUT)/$@.objsize + $(OBJCOPY) -O binary $(OUT)/$@ $(LITEOS_TARGET_DIR)/$@.bin + $(OBJDUMP) -t $(OUT)/$@ |sort >$(OUT)/$@.sym.sorted + $(OBJDUMP) -d $(OUT)/$@ >$(OUT)/$@.asm +# $(NM) -S --size-sort $(OUT)/$@ >$(OUT)/$@.size + +$(APPS): $(LITEOS_TARGET) + $(HIDE)$(MAKE) -C apps all + +prepare: + $(HIDE)mkdir -p $(OUT)/musl +ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) + $(HIDE)cp -f $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/usr/lib/$(LLVM_TARGET)/a7_softfp_neon-vfpv4/libc.so $(OUT)/musl + $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/lib/$(LLVM_TARGET)/c++/a7_softfp_neon-vfpv4/libc++.so $(OUT)/musl +else + $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/target/usr/lib/libc.so $(OUT)/musl + $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libstdc++.so.6 $(OUT)/musl + $(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libgcc_s.so.1 $(OUT)/musl + $(STRIP) $(OUT)/musl/* +endif + +$(ROOTFSDIR): prepare $(APPS) + $(HIDE)$(MAKE) clean -C apps + $(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT)/bin $(OUT)/musl $(ROOTFS_DIR)) +ifneq ($(VERSION),) + $(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR)) +endif + +$(ROOTFS): $(ROOTFSDIR) + $(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE)) + $(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS) +ifneq ($(OUT), $(LITEOS_TARGET_DIR)) + $(HIDE)mv $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)rootfs +endif + +clean: + $(HIDE)for dir in $(LITEOS_SUBDIRS); \ + do $(MAKE) -C $$dir clean|| exit 1; \ + done + $(HIDE)$(MAKE) -C apps clean + $(HIDE)$(RM) $(__OBJS) $(LITEOS_TARGET) $(OUT) $(BUILD) $(LITEOS_MENUCONFIG_H) *.bak *~ + $(HIDE)$(RM) $(LITEOS_PLATFORM_MENUCONFIG_H) + $(HIDE)$(RM) include + $(HIDE)$(MAKE) cleanrootfs + $(HIDE)echo "clean $(LITEOS_PLATFORM) finish" + +cleanall: + $(HIDE)$(RM) $(LITEOSTOPDIR)/out + $(HIDE)find $(LITEOS_PLATFORM_BASE)/ -name board.ld -exec rm -rf {} \; + $(HIDE)cd sample/sample_osdrv;make clean;cd ../..; + $(HIDE)echo "clean all" + +cleanrootfs: + $(HIDE)$(RM) $(OUT)/rootfs + $(HIDE)$(RM) $(OUT)/rootfs.zip + $(HIDE)$(RM) $(OUT)/rootfs.img + +.PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help diff --git a/apps/Makefile b/apps/Makefile new file mode 100755 index 00000000..e5857242 --- /dev/null +++ b/apps/Makefile @@ -0,0 +1,49 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include ../.config +include ./module.mk + +HIDE := @ +APPS := app + +all: $(APPS) + +# Make +$(APPS): +ifneq ($(APP_SUBDIRS), ) + $(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir ; done +endif + +clean: +ifneq ($(APP_SUBDIRS), ) + $(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir clean; done +endif + +.PHONY: all $(APPS) clean diff --git a/apps/config.mk b/apps/config.mk new file mode 100755 index 00000000..8e4c95f9 --- /dev/null +++ b/apps/config.mk @@ -0,0 +1,60 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# common dir config +include $(LITEOSTOPDIR)/config.mk + +# output dir config +OBJOUT := $(APPSTOPDIR)/out +APPSOUT := $(OBJOUT)/apps +LIBSOUT := $(OBJOUT)/libs +IMGOUT := $(OUT) + +# common flags config +BASE_OPTS := -ffunction-sections -fdata-sections -fno-omit-frame-pointer -D_GNU_SOURCE \ + $(LITEOS_SSP) $(LITEOS_CORE_COPTS) $(WARNING_AS_ERROR) $(LLVM_EXTRA_OPTS) $(LITEOS_GCOV_OPTS) + +CFLAGS := -std=c99 -fno-exceptions $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE) +CXXFLAGS := -std=c++11 -fexceptions -fpermissive -frtti $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE) +LDCFLAGS := -lc +ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) +LLVM_SYSROOT := --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/ +LDCXXFLGS := -lc++ -lc++abi -lc +else +BASE_OPTS += -Wl,-z,relro,-z,now +LDCXXFLGS := -lstdc++ -lsupc++ -lc +endif +COMMON_INCLUDE := -I $(LITEOSTHIRDPARTY)/bounds_checking_function/include + +# alias variable config +HIDE := @ +MAKE := make +RM := -rm -rf +CP := -cp -rf +MV := -mv diff --git a/apps/init/Makefile b/apps/init/Makefile new file mode 100755 index 00000000..82017e7e --- /dev/null +++ b/apps/init/Makefile @@ -0,0 +1,63 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +INIT_DIR := $(dir $(shell pwd))/init/ + +ifeq ($(APPSTOPDIR), ) +APPSTOPDIR := $(shell pwd)/../ +LITEOSTOPDIR = $(APPSTOPDIR)/../ +endif +include $(INIT_DIR)/../config.mk + +APPS_OUT := $(OUT)/bin +LOCAL_SRCS := src/init.c +LOCAL_OBJ := src/init.o + +ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) +LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-bitwise-op-parentheses -Wnonnull $(LLVM_SYSROOT) +LDCFLAGS += $(LLVM_EXTRA_LD_OPTS) $(LLVM_SYSROOT) +endif +INITNAME := init + +all: $(INITNAME) + +$(LOCAL_OBJ): %.o : %.c + $(HIDE) $(CC) $(CFLAGS) $(LOCAL_FLAGS) -fPIE $(LOCAL_INCLUDE) -c $< -o $@ + +$(INITNAME):$(LOCAL_OBJ) + $(HIDE) $(CC) -pie -s $(LDPATH) $(BASE_OPTS) -o $(INITNAME) $^ $(LDCFLAGS) + $(HIDE) mkdir -p $(APPS_OUT) + $(HIDE) $(MV) $(INITNAME) $(APPS_OUT) + $(HIDE) $(RM) $(LOCAL_OBJ) + +clean: + $(HIDE) $(RM) $(LOCAL_OBJ) + $(HIDE) $(RM) $(INITNAME) + +.PHONY: all $(INITNAME) clean diff --git a/apps/init/src/init.c b/apps/init/src/init.c new file mode 100755 index 00000000..882219df --- /dev/null +++ b/apps/init/src/init.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +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); + } + }; +} diff --git a/apps/module.mk b/apps/module.mk new file mode 100755 index 00000000..1cd7ae11 --- /dev/null +++ b/apps/module.mk @@ -0,0 +1,40 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +APP_SUBDIRS := + +##compile modules config## + +ifeq ($(LOSCFG_SHELL), y) +APP_SUBDIRS += shell +endif + +ifeq ($(LOSCFG_USER_INIT_DEBUG), y) +APP_SUBDIRS += init +endif diff --git a/apps/shell/Makefile b/apps/shell/Makefile new file mode 100755 index 00000000..857cb136 --- /dev/null +++ b/apps/shell/Makefile @@ -0,0 +1,78 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +SHELL_DIR := $(dir $(shell pwd))/shell/ + +ifeq ($(APPSTOPDIR), ) +APPSTOPDIR := $(shell pwd)/../ +LITEOSTOPDIR = $(APPSTOPDIR)/../ +endif +include $(SHELL_DIR)/../config.mk +APPS_OUT := $(OUT)/bin + +SECUREC_INCLUDE := $(LITEOSTHIRDPARTY)/bounds_checking_function/include + +LOCAL_SRCS = $(wildcard src/main.c)\ + $(wildcard src/shcmd.c)\ + $(wildcard src/shmsg.c)\ + $(wildcard src/shcmdparse.c)\ + $(wildcard builtin/cd.c) +LOCAL_SRCS += $(wildcard $(LITEOSTHIRDPARTY)/bounds_checking_function/src/*.c) +LOCAL_OBJ := $(LOCAL_SRCS:.c=.o) + +LOCAL_INCLUDE := \ + -I $(SHELL_DIR)/include/ \ + -I $(SECUREC_INCLUDE)\ + +LOCAL_FLAGS += $(CFLAGS) + +LDPATH := -L$(SHELL_DIR)/ +ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) +LOCAL_FLAGS += -Wno-shift-op-parentheses -Wno-bitwise-op-parentheses $(LLVM_SYSROOT) +LDCFLAGS += $(LLVM_EXTRA_LD_OPTS) $(LLVM_SYSROOT) +endif + +SHELLNAME := shell + +all: $(SHELLNAME) + +$(LOCAL_OBJ): %.o : %.c + $(HIDE) $(CC) $(LOCAL_FLAGS) -fPIE $(LOCAL_INCLUDE) -c $< -o $@ + +$(SHELLNAME): $(LOCAL_OBJ) + $(HIDE) $(CC) -pie -s $(LDPATH) $(BASE_OPTS) -o $(SHELLNAME) $^ $(LDCFLAGS) + $(HIDE) mkdir -p $(APPS_OUT) + $(HIDE) $(MV) $(SHELLNAME) $(APPS_OUT) + $(HIDE) $(RM) $(LOCAL_OBJ) + +clean: + $(HIDE) $(RM) $(LOCAL_OBJ) + $(HIDE) $(RM) $(SHELLNAME) + +.PHONY: all $(SHELLNAME) clean diff --git a/apps/shell/builtin/cd.c b/apps/shell/builtin/cd.c new file mode 100755 index 00000000..56d6897e --- /dev/null +++ b/apps/shell/builtin/cd.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "unistd.h" +#include "shcmd.h" +#include "sherr.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +int Chdir(const char *tgtDir) +{ + int ret; + + if (!tgtDir) { + return SH_ERROR; + } + + ret = chdir(tgtDir); + if (ret == 0) { + ret = OsShellSetWorkingDirtectory(tgtDir, strlen(tgtDir) + 1); /* 1: the length of '\0' */ + if (ret != SH_NOK) { + return ret; + } + } + + return ret; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif diff --git a/apps/shell/include/shcmd.h b/apps/shell/include/shcmd.h new file mode 100755 index 00000000..d664a4bd --- /dev/null +++ b/apps/shell/include/shcmd.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef _SHCMD_H +#define _SHCMD_H + +#include "string.h" +#include "stdlib.h" +#include "shell_list.h" +#include "shcmdparse.h" +#include "sherr.h" +#include "show.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +typedef struct { + unsigned int count; + SH_List list; + char cmdString[0]; +} CmdKeyLink; + +#define NEED_NEW_LINE(timesPrint, lineCap) ((timesPrint) % (lineCap) == 0) +#define SCREEN_IS_FULL(timesPrint, lineCap) ((timesPrint) >= ((lineCap) * DEFAULT_SCREEN_HEIGNT)) + +extern unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr); +extern unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size); +extern int OsTabCompletion(char *cmdKey, unsigned int *len); +extern void OsShellCmdPush(const char *string, CmdKeyLink *cmdKeyLink); +extern void OsShellHistoryShow(unsigned int value, ShellCB *shellCB); +extern unsigned int OsShellKeyInit(ShellCB *shellCB); +extern void OsShellKeyDeInit(CmdKeyLink *cmdKeyLink); +extern int OsShellSetWorkingDirtectory(const char *dir, size_t len); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif /* _SHCMD_H */ diff --git a/apps/shell/include/shcmdparse.h b/apps/shell/include/shcmdparse.h new file mode 100755 index 00000000..e3206220 --- /dev/null +++ b/apps/shell/include/shcmdparse.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SHCMDPARSE_H +#define _SHCMDPARSE_H + +#include "string.h" +#include "show.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +/* + * Description: the info struct after cmd parser + */ +typedef struct { + unsigned int paramCnt; /* count of para */ + CmdType cmdType; /* cmd type, judge cmd keyword */ + char cmdKeyword[CMD_KEY_LEN]; /* cmd keyword str */ + char *paramArray[CMD_MAX_PARAS]; +} CmdParsed; + +extern unsigned int OsCmdParse(char *cmdStr, CmdParsed *cmdParsed); +extern char *OsCmdParseStrdup(const char *str); +extern unsigned int OsCmdParseOneToken(CmdParsed *cmdParsed, unsigned int index, const char *token); +extern unsigned int OsCmdTokenSplit(char *cmdStr, char split, CmdParsed *cmdParsed); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif + +#endif /* _SHCMDPARSE_H */ diff --git a/apps/shell/include/shell.h b/apps/shell/include/shell.h new file mode 100755 index 00000000..48fa3093 --- /dev/null +++ b/apps/shell/include/shell.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SHELL_H +#define _SHELL_H + +#include "pthread.h" +#include "semaphore.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* Max len of show str */ +#define SHOW_MAX_LEN CMD_MAX_LEN + +#define SHELL_PROCESS_PRIORITY_INIT 15 + +#define PATH_MAX 256 +#define CMD_MAX_PARAS 32 +#define CMD_KEY_LEN 16U +#define CMD_MAX_LEN (256U + CMD_KEY_LEN) +#define CMD_KEY_NUM 32 +#define CMD_HISTORY_LEN 10 +#define CMD_MAX_PATH 256 +#define DEFAULT_SCREEN_WIDTH 80 +#define DEFAULT_SCREEN_HEIGNT 24 + +#define SWITCH_QUOTES_STATUS(qu) do { \ + if ((qu) == TRUE) { \ + (qu) = FALSE; \ + } else { \ + (qu) = TRUE; \ + } \ +} while (0) + +#define QUOTES_STATUS_CLOSE(qu) ((qu) == FALSE) +#define QUOTES_STATUS_OPEN(qu) ((qu) == TRUE) + +typedef size_t bool; + +typedef struct { + unsigned int consoleID; + pthread_t shellTaskHandle; + pthread_t shellEntryHandle; + void *cmdKeyLink; + void *cmdHistoryKeyLink; + void *cmdMaskKeyLink; + unsigned int shellBufOffset; + unsigned int shellKeyType; + sem_t shellSem; + pthread_mutex_t keyMutex; + pthread_mutex_t historyMutex; + char shellBuf[SHOW_MAX_LEN]; + char shellWorkingDirectory[PATH_MAX]; +} ShellCB; + +/* All support cmd types */ +typedef enum { + CMD_TYPE_SHOW = 0, + CMD_TYPE_STD = 1, + CMD_TYPE_EX = 2, + CMD_TYPE_BUTT +} CmdType; + +typedef enum { + CMD_KEY_UP = 0, + CMD_KEY_DOWN = 1, + CMD_KEY_RIGHT = 2, + CMD_KEY_LEFT = 4, + CMD_KEY_BUTT +} CmdKeyDirection; + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _SHELL_H */ diff --git a/apps/shell/include/shell_list.h b/apps/shell/include/shell_list.h new file mode 100755 index 00000000..91b5bbd3 --- /dev/null +++ b/apps/shell/include/shell_list.h @@ -0,0 +1,595 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SHELL_LIST_H +#define _SHELL_LIST_H + +#include "sherr.h" +#include "stdint.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +typedef size_t bool; + +/** + * @ingroup shell_list + * Structure of a node in a doubly linked list. + */ +typedef struct SH_List { + struct SH_List *pstPrev; /**< Current node's pointer to the previous node */ + struct SH_List *pstNext; /**< Current node's pointer to the next node */ +} SH_List; + +/** + * @ingroup shell_list + * + * @par Description: + * This API is used to initialize a doubly linked list. + * @attention + *
    + *
  • The parameter passed in should be ensured to be a legal pointer.
  • + *
+ * + * @param list [IN] Node in a doubly linked list. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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: + *
    + *
  • This API is used to point to the next node pointed to by the current node.
  • + *
+ * @attention + *
    + *
  • None.
  • + *
+ * + * @param object [IN] Node in the doubly linked list. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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: + *
    + *
  • This API is used to point to the previous node pointed to by the current node.
  • + *
+ * @attention + *
    + *
  • None.
  • + *
+ * + * @param object [IN] Node in the doubly linked list. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • The parameters passed in should be ensured to be legal pointers.
  • + *
+ * + * @param list [IN] Doubly linked list where the new node is inserted. + * @param node [IN] New node to be inserted. + * + * @retval None + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • The parameters passed in should be ensured to be legal pointers.
  • + *
+ * + * @param list [IN] Doubly linked list where the new node is inserted. + * @param node [IN] New node to be inserted. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • The parameters passed in should be ensured to be legal pointers.
  • + *
+ * + * @param list [IN] Doubly linked list where the new node is inserted. + * @param node [IN] New node to be inserted. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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: + *
    + *
  • This API is used to delete a specified node from a doubly linked list.
  • + *
+ * @attention + *
    + *
  • The parameter passed in should be ensured to be a legal pointer.
  • + *
+ * + * @param node [IN] Node to be deleted. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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: + *
    + *
  • This API is used to return whether a doubly linked list is empty.
  • + *
+ * @attention + *
    + *
  • The parameter passed in should be ensured to be a legal pointer.
  • + *
+ * + * @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: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • The parameters passed in should be ensured to be legal pointers.
  • + *
+ * + * @param oldList [IN] Doubly linked list where the new list is inserted. + * @param newList [IN] New list to be inserted. + * + * @retval None + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • The parameters passed in should be ensured to be legal pointers.
  • + *
+ * + * @param oldList [IN] Doubly linked list where the new list is inserted. + * @param newList [IN] New list to be inserted. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • The parameters passed in should be ensured to be legal pointers.
  • + *
+ * + * @param oldList [IN] Doubly linked list where the new list is inserted. + * @param newList [IN] New list to be inserted. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • None.
  • + *
+ * + * @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: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • None.
  • + *
+ * + * @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: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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. + *
    + *
  • None.
  • + *
+ * @attention + *
    + *
  • None.
  • + *
+ * + * @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: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • None.
  • + *
+ * + * @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: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • None.
  • + *
+ * + * @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: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • The parameter passed in should be ensured to be s legal pointer.
  • + *
+ * + * @param list [IN] Doubly linked list. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • None.
  • + *
+ * + * @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: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • None.
  • + *
+ * + * @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: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 + *
    + *
  • None.
  • + *
+ * + * @param list [IN] Pointer to the doubly linked list to be traversed. + * + * @retval None. + * @par Dependency: + *
  • shell_list.h: the header file that contains the API declaration.
+ * @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 */ diff --git a/apps/shell/include/shell_pri.h b/apps/shell/include/shell_pri.h new file mode 100755 index 00000000..b8e75c1c --- /dev/null +++ b/apps/shell/include/shell_pri.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SHELL_PRI_H +#define _SHELL_PRI_H + +#include "sys/types.h" +#include "bits/alltypes.h" +#include "shcmd.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +extern void *ShellEntry(void *argv); +extern void *ShellTask(void *argv); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _SHELL_PRI_H */ diff --git a/apps/shell/include/sherr.h b/apps/shell/include/sherr.h new file mode 100755 index 00000000..6122fd2c --- /dev/null +++ b/apps/shell/include/sherr.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SHERR_H +#define _SHERR_H + +#include "sys/types.h" +#include "bits/alltypes.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define SH_ERROR -1 +#define SH_OK 0 +#define SH_NOK -1 + +#ifndef TRUE +# define TRUE 1 +#endif +#ifndef FALSE +# define FALSE 0 +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _SHERR_H */ + diff --git a/apps/shell/include/shmsg.h b/apps/shell/include/shmsg.h new file mode 100755 index 00000000..fb683559 --- /dev/null +++ b/apps/shell/include/shmsg.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SHMSG_H +#define _SHMSG_H + +#include "shell.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define SHELL_ENTRY_STACKSIZE 0x1000 +#define SHELL_TASK_STACKSIZE 0x3000 + +#define SHELL_EXEC_COMMAND "exec " +#define SHELL_EXEC_COMMAND_BYTES 5 + +#define CONSOLE_IOC_MAGIC 'c' +#define CONSOLE_CONTROL_REG_USERTASK _IO(CONSOLE_IOC_MAGIC, 7) + +#define COLOR_NONE "\e[0m" +#define COLOR_RED "\e[0;31m" +#define COLOR_L_RED "\e[1;31m" +#define SHELL_PROMPT COLOR_L_RED"OHOS # "COLOR_NONE + +typedef void (*OutputFunc)(const char *fmt, ...); +extern int ShellTaskInit(ShellCB *shellCB); +extern int ShellEntryInit(ShellCB *shellCB); +extern void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB); +extern int ShellNotify(ShellCB *shellCB); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _SHMSG_H */ diff --git a/apps/shell/include/show.h b/apps/shell/include/show.h new file mode 100755 index 00000000..95c56b12 --- /dev/null +++ b/apps/shell/include/show.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SHOW_H +#define _SHOW_H + +#include "stdarg.h" + +#include "shell.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +extern char *OsShellGetWorkingDirtectory(); +extern unsigned int OsShellInit(); +extern int OsShellDeinit(ShellCB *shellCB); +extern ShellCB *OsGetShellCb(); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _SHOW_H */ diff --git a/apps/shell/src/main.c b/apps/shell/src/main.c new file mode 100755 index 00000000..54c0bf9f --- /dev/null +++ b/apps/shell/src/main.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "show.h" +#include "shmsg.h" +#include "shcmd.h" +#include "semaphore.h" +#include "securec.h" +#include "unistd.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +ShellCB *g_shellCB = NULL; + +ShellCB *OsGetShellCb() +{ + return g_shellCB; +} + +void ShellDeinit(ShellCB *shellCB) +{ + (void)pthread_mutex_destroy(&shellCB->historyMutex); + (void)pthread_mutex_destroy(&shellCB->keyMutex); + OsShellKeyDeInit((CmdKeyLink *)shellCB->cmdKeyLink); + OsShellKeyDeInit((CmdKeyLink *)shellCB->cmdHistoryKeyLink); + (void)free(shellCB); +} + +static int OsShellCreateTask(ShellCB *shellCB) +{ + struct sched_param param = { 0 }; + int ret; + + ret = sched_getparam(getpid(), ¶m); + if (ret != SH_OK) { + goto OUT; + } + + param.sched_priority = SHELL_PROCESS_PRIORITY_INIT; + + ret = sched_setparam(getpid(), ¶m); + if (ret != SH_OK) { + goto OUT; + } + + ret = ShellTaskInit(shellCB); + if (ret != SH_OK) { + goto OUT; + } + + ret = ShellEntryInit(shellCB); + if (ret != SH_OK) { + goto OUT; + } + + (void)pthread_join(shellCB->shellTaskHandle, NULL); + (void)pthread_join(shellCB->shellEntryHandle, NULL); + +OUT: + ShellDeinit(shellCB); + return ret; +} + +int main() +{ + int ret = SH_NOK; + ShellCB *shellCB = NULL; + + shellCB = (ShellCB *)malloc(sizeof(ShellCB)); + if (shellCB == NULL) { + goto ERR_OUT1; + } + ret = memset_s(shellCB, sizeof(ShellCB), 0, sizeof(ShellCB)); + if (ret != SH_OK) { + goto ERR_OUT1; + } + + ret = pthread_mutex_init(&shellCB->keyMutex, NULL); + if (ret != SH_OK) { + goto ERR_OUT1; + } + + ret = pthread_mutex_init(&shellCB->historyMutex, NULL); + if (ret != SH_OK) { + goto ERR_OUT2; + } + + ret = (int)OsShellKeyInit(shellCB); + if (ret != SH_OK) { + goto ERR_OUT3; + } + (void)strncpy_s(shellCB->shellWorkingDirectory, PATH_MAX, "/", 2); /* 2:space for "/" */ + + sem_init(&shellCB->shellSem, 0, 0); + + g_shellCB = shellCB; + return OsShellCreateTask(shellCB); + +ERR_OUT3: + (void)pthread_mutex_destroy(&shellCB->historyMutex); +ERR_OUT2: + (void)pthread_mutex_destroy(&shellCB->keyMutex); +ERR_OUT1: + (void)free(shellCB); + return ret; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif diff --git a/apps/shell/src/shcmd.c b/apps/shell/src/shcmd.c new file mode 100755 index 00000000..06845ac8 --- /dev/null +++ b/apps/shell/src/shcmd.c @@ -0,0 +1,611 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "shcmd.h" +#include "show.h" +#include "stdlib.h" +#include "unistd.h" +#include "dirent.h" +#include "securec.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define SHELL_INIT_MAGIC_FLAG 0xABABABAB +#define CTRL_C 0x03 /* 0x03: ctrl+c ASCII */ + +static void OsFreeCmdPara(CmdParsed *cmdParsed) +{ + unsigned int i; + for (i = 0; i < cmdParsed->paramCnt; i++) { + if ((cmdParsed->paramArray[i]) != NULL) { + free((cmdParsed->paramArray[i])); + cmdParsed->paramArray[i] = NULL; + } + } +} + +static int OsStrSeparateTabStrGet(const char **tabStr, CmdParsed *parsed, unsigned int tabStrLen) +{ + char *shiftStr = NULL; + char *tempStr = (char *)malloc(SHOW_MAX_LEN << 1); + if (tempStr == NULL) { + return (int)SH_ERROR; + } + + (void)memset_s(tempStr, SHOW_MAX_LEN << 1, 0, SHOW_MAX_LEN << 1); + shiftStr = tempStr + SHOW_MAX_LEN; + + if (strncpy_s(tempStr, SHOW_MAX_LEN - 1, *tabStr, tabStrLen)) { + free(tempStr); + return (int)SH_ERROR; + } + + parsed->cmdType = CMD_TYPE_STD; + + /* cut useless or repeat space */ + if (OsCmdKeyShift(tempStr, shiftStr, SHOW_MAX_LEN - 1)) { + free(tempStr); + return (int)SH_ERROR; + } + + /* get exact position of string to complete */ + /* situation different if end space lost or still exist */ + if ((strlen(shiftStr) == 0) || (tempStr[strlen(tempStr) - 1] != shiftStr[strlen(shiftStr) - 1])) { + *tabStr = ""; + } else { + if (OsCmdTokenSplit(shiftStr, ' ', parsed)) { + free(tempStr); + return (int)SH_ERROR; + } + *tabStr = parsed->paramArray[parsed->paramCnt - 1]; + } + + free(tempStr); + return SH_OK; +} + +char *OsShellGetWorkingDirtectory() +{ + return OsGetShellCb()->shellWorkingDirectory; +} + +int OsShellSetWorkingDirtectory(const char *dir, size_t len) +{ + if (dir == NULL) { + return SH_NOK; + } + + int ret = strncpy_s(OsGetShellCb()->shellWorkingDirectory, sizeof(OsGetShellCb()->shellWorkingDirectory), + dir, len); + if (ret != SH_OK) { + return SH_NOK; + } + return SH_OK; +} + +static int OsStrSeparate(const char *tabStr, char *strPath, char *nameLooking, unsigned int tabStrLen) +{ + char *strEnd = NULL; + char *cutPos = NULL; + CmdParsed parsed = {0}; + char *shellWorkingDirectory = OsShellGetWorkingDirtectory(); + int ret; + + ret = OsStrSeparateTabStrGet(&tabStr, &parsed, tabStrLen); + if (ret != SH_OK) { + return ret; + } + + /* get fullpath str */ + if (*tabStr != '/') { + if (strncpy_s(strPath, CMD_MAX_PATH, shellWorkingDirectory, CMD_MAX_PATH - 1)) { + OsFreeCmdPara(&parsed); + return (int)SH_ERROR; + } + if (strcmp(shellWorkingDirectory, "/")) { + if (strncat_s(strPath, CMD_MAX_PATH - 1, "/", CMD_MAX_PATH - strlen(strPath) - 1)) { + OsFreeCmdPara(&parsed); + return (int)SH_ERROR; + } + } + } + + if (strncat_s(strPath, CMD_MAX_PATH - 1, tabStr, CMD_MAX_PATH - strlen(strPath) - 1)) { + OsFreeCmdPara(&parsed); + return (int)SH_ERROR; + } + + /* split str by last '/' */ + strEnd = strrchr(strPath, '/'); + if (strEnd != NULL) { + if (strncpy_s(nameLooking, CMD_MAX_PATH, strEnd + 1, CMD_MAX_PATH - 1)) { /* get cmp str */ + OsFreeCmdPara(&parsed); + return (int)SH_ERROR; + } + } + + cutPos = strrchr(strPath, '/'); + if (cutPos != NULL) { + *(cutPos + 1) = '\0'; + } + + OsFreeCmdPara(&parsed); + return SH_OK; +} + +static int OsShowPageInputControl(void) +{ + char readChar; + + while (1) { + if (read(STDIN_FILENO, &readChar, 1) != 1) { /* get one char from stdin */ + printf("\n"); + return (int)SH_ERROR; + } + if ((readChar == 'q') || (readChar == 'Q') || (readChar == CTRL_C)) { + printf("\n"); + return 0; + } else if (readChar == '\r') { + printf("\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b"); + return 1; + } + } +} + +static int OsShowPageControl(unsigned int timesPrint, unsigned int lineCap, unsigned int count) +{ + if (NEED_NEW_LINE(timesPrint, lineCap)) { + printf("\n"); + if (SCREEN_IS_FULL(timesPrint, lineCap) && (timesPrint < count)) { + printf("--More--"); + return OsShowPageInputControl(); + } + } + return 1; +} + +static int OsSurePrintAll(unsigned int count) +{ + char readChar = 0; + printf("\nDisplay all %u possibilities?(y/n)", count); + while (1) { + if (read(0, &readChar, 1) != 1) { + return (int)SH_ERROR; + } + if ((readChar == 'n') || (readChar == 'N') || (readChar == CTRL_C)) { + printf("\n"); + return 0; + } else if ((readChar == 'y') || (readChar == 'Y') || (readChar == '\r')) { + return 1; + } + } +} + +static int OsPrintMatchList(unsigned int count, const char *strPath, const char *nameLooking, unsigned int printLen) +{ + unsigned int timesPrint = 0; + unsigned int lineCap; + int ret; + DIR *openDir = NULL; + struct dirent *readDir = NULL; + char formatChar[10] = {0}; /* 10:for formatChar length */ + + printLen = (printLen > (DEFAULT_SCREEN_WIDTH - 2)) ? (DEFAULT_SCREEN_WIDTH - 2) : printLen; /* 2:revered 2 bytes */ + lineCap = DEFAULT_SCREEN_WIDTH / (printLen + 2); /* 2:DEFAULT_SCREEN_WIDTH revered 2 bytes */ + if (snprintf_s(formatChar, sizeof(formatChar) - 1, 7, "%%-%us ", printLen) < 0) { /* 7:format-len */ + return (int)SH_ERROR; + } + + if (count > (lineCap * DEFAULT_SCREEN_HEIGNT)) { + ret = OsSurePrintAll(count); + if (ret != 1) { + return ret; + } + } + openDir = opendir(strPath); + if (openDir == NULL) { + return (int)SH_ERROR; + } + + printf("\n"); + for (readDir = readdir(openDir); readDir != NULL; readDir = readdir(openDir)) { + if (strncmp(nameLooking, readDir->d_name, strlen(nameLooking)) != 0) { + continue; + } + printf(formatChar, readDir->d_name); + timesPrint++; + ret = OsShowPageControl(timesPrint, lineCap, count); + if (ret != 1) { + if (closedir(openDir) < 0) { + return (int)SH_ERROR; + } + return ret; + } + } + + printf("\n"); + if (closedir(openDir) < 0) { + return (int)SH_ERROR; + } + + return SH_OK; +} + +static void StrncmpCut(const char *s1, char *s2, size_t n) +{ + if ((n == 0) || (s1 == NULL) || (s2 == NULL)) { + return; + } + do { + if (*s1 && *s2 && (*s1 == *s2)) { + s1++; + s2++; + } else { + break; + } + } while (--n != 0); + if (n > 0) { + /* NULL pad the remaining n-1 bytes */ + while (n-- != 0) { + *s2++ = 0; + } + } + return; +} + +static void OsCompleteStr(char *result, const char *target, char *cmdKey, unsigned int *len) +{ + unsigned int size = strlen(result) - strlen(target); + char *des = cmdKey + *len; + char *src = result + strlen(target); + + while (size-- > 0) { + printf("%c", *src); + if (*len == (SHOW_MAX_LEN - 1)) { + *des = '\0'; + break; + } + *des++ = *src++; + (*len)++; + } +} + +static int OsExecNameMatch(const char *strPath, const char *nameLooking, char *strObj, unsigned int *maxLen) +{ + int count = 0; + DIR *openDir = NULL; + struct dirent *readDir = NULL; + + openDir = opendir(strPath); + if (openDir == NULL) { + return (int)SH_ERROR; + } + + for (readDir = readdir(openDir); readDir != NULL; readDir = readdir(openDir)) { + if (strncmp(nameLooking, readDir->d_name, strlen(nameLooking)) != 0) { + continue; + } + if (count == 0) { + if (strncpy_s(strObj, CMD_MAX_PATH, readDir->d_name, CMD_MAX_PATH - 1)) { + (void)closedir(openDir); + return (int)SH_ERROR; + } + *maxLen = strlen(readDir->d_name); + } else { + /* strncmp&cut the same strings of name matched */ + StrncmpCut(readDir->d_name, strObj, strlen(strObj)); + if (strlen(readDir->d_name) > *maxLen) { + *maxLen = strlen(readDir->d_name); + } + } + count++; + } + + if (closedir(openDir) < 0) { + return (int)SH_ERROR; + } + + return count; +} + +static int OsTabMatchFile(char *cmdKey, unsigned int *len) +{ + unsigned int maxLen = 0; + int count; + char *strOutput = NULL; + char *strCmp = NULL; + char *dirOpen = (char *)malloc(CMD_MAX_PATH * 3); /* 3:dirOpen\strOutput\strCmp */ + if (dirOpen == NULL) { + return (int)SH_ERROR; + } + + (void)memset_s(dirOpen, CMD_MAX_PATH * 3, 0, CMD_MAX_PATH * 3); /* 3:dirOpen\strOutput\strCmp */ + strOutput = dirOpen + CMD_MAX_PATH; + strCmp = strOutput + CMD_MAX_PATH; + + if (OsStrSeparate(cmdKey, dirOpen, strCmp, *len)) { + free(dirOpen); + return (int)SH_ERROR; + } + + count = OsExecNameMatch(dirOpen, strCmp, strOutput, &maxLen); + /* one or more matched */ + if (count >= 1) { + OsCompleteStr(strOutput, strCmp, cmdKey, len); + + if (count == 1) { + free(dirOpen); + return 1; + } + if (OsPrintMatchList((unsigned int)count, dirOpen, strCmp, maxLen) == -1) { + free(dirOpen); + return (int)SH_ERROR; + } + } + + free(dirOpen); + return count; +} + +/* + * Description: Pass in the string and clear useless space ,which inlcude: + * 1) The overmatch space which is not be marked by Quote's area + * Squeeze the overmatch space into one space + * 2) Clear all space before first vaild charatctor + * Input: cmdKey : Pass in the buff string, which is ready to be operated + * cmdOut : Pass out the buffer string ,which has already been operated + * size : cmdKey length + */ +unsigned int OsCmdKeyShift(const char *cmdKey, char *cmdOut, unsigned int size) +{ + char *output = NULL; + char *outputBak = NULL; + unsigned int len; + int ret; + bool quotes = FALSE; + + if ((cmdKey == NULL) || (cmdOut == NULL)) { + return (unsigned int)SH_ERROR; + } + + len = strlen(cmdKey); + if ((*cmdKey == '\n') || (len >= size)) { + return (unsigned int)SH_ERROR; + } + output = (char *)malloc(len + 1); + if (output == NULL) { + printf("malloc failure in %s[%d]", __FUNCTION__, __LINE__); + return (unsigned int)SH_ERROR; + } + + /* Backup the 'output' start address */ + outputBak = output; + /* Scan each charactor in 'cmdKey',and squeeze the overmuch space and ignore invaild charactor */ + for (; *cmdKey != '\0'; cmdKey++) { + /* Detected a Double Quotes, switch the matching status */ + if (*(cmdKey) == '\"') { + SWITCH_QUOTES_STATUS(quotes); + } + /* Ignore the current charactor in following situation */ + /* 1) Quotes matching status is FALSE (which said that the space is not been marked by double quotes) */ + /* 2) Current charactor is a space */ + /* 3) Next charactor is a space too, or the string is been seeked to the end already(\0) */ + /* 4) Invaild charactor, such as single quotes */ + if ((*cmdKey == ' ') && ((*(cmdKey + 1) == ' ') || (*(cmdKey + 1) == '\0')) && QUOTES_STATUS_CLOSE(quotes)) { + continue; + } + if (*cmdKey == '\'') { + continue; + } + *output = *cmdKey; + output++; + } + *output = '\0'; + /* Restore the 'output' start address */ + output = outputBak; + len = strlen(output); + /* Clear the space which is located at the first charactor in buffer */ + if (*output == ' ') { + output++; + len--; + } + /* Copy out the buffer which is been operated already */ + ret = strncpy_s(cmdOut, size, output, len); + if (ret != SH_OK) { + printf("%s,%d strncpy_s failed, err:%d!\n", __FUNCTION__, __LINE__, ret); + free(outputBak); + return SH_ERROR; + } + cmdOut[len] = '\0'; + + free(outputBak); + return SH_OK; +} +int OsTabCompletion(char *cmdKey, unsigned int *len) +{ + int count; + char *cmdMainStr = cmdKey; + + if ((cmdKey == NULL) || (len == NULL)) { + return (int)SH_ERROR; + } + + /* cut left space */ + while (*cmdMainStr == 0x20) { + cmdMainStr++; + } + + count = OsTabMatchFile(cmdKey, len); + + return count; +} + +unsigned int OsShellKeyInit(ShellCB *shellCB) +{ + CmdKeyLink *cmdKeyLink = NULL; + CmdKeyLink *cmdHistoryLink = NULL; + + if (shellCB == NULL) { + return SH_ERROR; + } + + cmdKeyLink = (CmdKeyLink *)malloc(sizeof(CmdKeyLink)); + if (cmdKeyLink == NULL) { + printf("Shell CmdKeyLink memory alloc error!\n"); + return SH_ERROR; + } + cmdHistoryLink = (CmdKeyLink *)malloc(sizeof(CmdKeyLink)); + if (cmdHistoryLink == NULL) { + free(cmdKeyLink); + printf("Shell CmdHistoryLink memory alloc error!\n"); + return SH_ERROR; + } + + cmdKeyLink->count = 0; + SH_ListInit(&(cmdKeyLink->list)); + shellCB->cmdKeyLink = (void *)cmdKeyLink; + + cmdHistoryLink->count = 0; + SH_ListInit(&(cmdHistoryLink->list)); + shellCB->cmdHistoryKeyLink = (void *)cmdHistoryLink; + shellCB->cmdMaskKeyLink = (void *)cmdHistoryLink; + return SH_OK; +} + +void OsShellKeyDeInit(CmdKeyLink *cmdKeyLink) +{ + CmdKeyLink *cmdtmp = NULL; + if (cmdKeyLink == NULL) { + return; + } + + while (!SH_ListEmpty(&(cmdKeyLink->list))) { + cmdtmp = SH_LIST_ENTRY(cmdKeyLink->list.pstNext, CmdKeyLink, list); + SH_ListDelete(&cmdtmp->list); + free(cmdtmp); + } + + cmdKeyLink->count = 0; + free(cmdKeyLink); +} + +void OsShellCmdPush(const char *string, CmdKeyLink *cmdKeyLink) +{ + CmdKeyLink *cmdNewNode = NULL; + unsigned int len; + + if ((string == NULL) || (strlen(string) == 0)) { + return; + } + + len = strlen(string); + cmdNewNode = (CmdKeyLink *)malloc(sizeof(CmdKeyLink) + len + 1); + if (cmdNewNode == NULL) { + return; + } + + (void)memset_s(cmdNewNode, sizeof(CmdKeyLink) + len + 1, 0, sizeof(CmdKeyLink) + len + 1); + if (strncpy_s(cmdNewNode->cmdString, len + 1, string, len)) { + free(cmdNewNode); + return; + } + + SH_ListTailInsert(&(cmdKeyLink->list), &(cmdNewNode->list)); + + return; +} + +void OsShellHistoryShow(unsigned int value, ShellCB *shellCB) +{ + CmdKeyLink *cmdtmp = NULL; + CmdKeyLink *cmdNode = shellCB->cmdHistoryKeyLink; + CmdKeyLink *cmdMask = shellCB->cmdMaskKeyLink; + int ret; + + (void)pthread_mutex_lock(&shellCB->historyMutex); + if (value == CMD_KEY_DOWN) { + if (cmdMask == cmdNode) { + goto END; + } + + cmdtmp = SH_LIST_ENTRY(cmdMask->list.pstNext, CmdKeyLink, list); + if (cmdtmp != cmdNode) { + cmdMask = cmdtmp; + } else { + goto END; + } + } else if (value == CMD_KEY_UP) { + cmdtmp = SH_LIST_ENTRY(cmdMask->list.pstPrev, CmdKeyLink, list); + if (cmdtmp != cmdNode) { + cmdMask = cmdtmp; + } else { + goto END; + } + } + + while (shellCB->shellBufOffset--) { + printf("\b \b"); + } + printf("%s", cmdMask->cmdString); + shellCB->shellBufOffset = strlen(cmdMask->cmdString); + (void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN); + ret = memcpy_s(shellCB->shellBuf, SHOW_MAX_LEN, cmdMask->cmdString, shellCB->shellBufOffset); + if (ret != SH_OK) { + printf("%s, %d memcpy failed!\n", __FUNCTION__, __LINE__); + goto END; + } + shellCB->cmdMaskKeyLink = (void *)cmdMask; + +END: + (void)pthread_mutex_unlock(&shellCB->historyMutex); + return; +} + +unsigned int OsCmdExec(CmdParsed *cmdParsed, char *cmdStr) +{ + /* TODO: complete the usrspace command */ + unsigned int ret = SH_OK; + if (cmdParsed && cmdStr) { + ret = SH_NOK; + } + + return ret; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif diff --git a/apps/shell/src/shcmdparse.c b/apps/shell/src/shcmdparse.c new file mode 100755 index 00000000..1a9bc75e --- /dev/null +++ b/apps/shell/src/shcmdparse.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "shcmd.h" +#include "sherr.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* + * Filter out double quote or single-quoted strings at both ends + */ +char *OsCmdParseStrdup(const char *str) +{ + char *tempStr = NULL; + char *newStr = NULL; + + newStr = (char *)malloc(strlen(str) + 1); + if (newStr == NULL) { + return NULL; + } + + tempStr = newStr; + for (; *str != '\0'; str++) { + if ((*str == '\"') || (*str == '\'')) { + continue; + } + *newStr = *str; + newStr++; + } + *newStr = '\0'; + return tempStr; +} + +unsigned int OsCmdParseParaGet(char **value, const char *paraTokenStr) +{ + if ((paraTokenStr == NULL) || (value == NULL)) { + return (unsigned int)SH_ERROR; + } + *value = OsCmdParseStrdup(paraTokenStr); + if (*value == NULL) { + return SH_NOK; + } + return SH_OK; +} + +unsigned int OsCmdParseOneToken(CmdParsed *cmdParsed, unsigned int index, const char *token) +{ + unsigned int ret = SH_OK; + unsigned int tempLen; + + if (cmdParsed == NULL) { + return (unsigned int)SH_ERROR; + } + + if (index == 0) { + if (cmdParsed->cmdType != CMD_TYPE_STD) { + return ret; + } + } + + if ((token != NULL) && (cmdParsed->paramCnt < CMD_MAX_PARAS)) { + tempLen = cmdParsed->paramCnt; + ret = OsCmdParseParaGet(&(cmdParsed->paramArray[tempLen]), token); + if (ret != SH_OK) { + return ret; + } + cmdParsed->paramCnt++; + } + return ret; +} + +unsigned int OsCmdTokenSplit(char *cmdStr, char split, CmdParsed *cmdParsed) +{ + enum { + STAT_INIT, + STAT_TOKEN_IN, + STAT_TOKEN_OUT + } state = STAT_INIT; + unsigned int count = 0; + char *p = NULL; + char *token = cmdStr; + unsigned int ret = SH_OK; + bool quotes = FALSE; + + if (cmdStr == NULL) { + return (unsigned int)SH_ERROR; + } + + for (p = cmdStr; (*p != '\0') && (ret == SH_OK); p++) { + if (*p == '\"') { + SWITCH_QUOTES_STATUS(quotes); + } + switch (state) { + case STAT_INIT: + case STAT_TOKEN_IN: + if ((*p == split) && QUOTES_STATUS_CLOSE(quotes)) { + *p = '\0'; + ret = OsCmdParseOneToken(cmdParsed, count++, token); + state = STAT_TOKEN_OUT; + } + break; + case STAT_TOKEN_OUT: + if (*p != split) { + token = p; + state = STAT_TOKEN_IN; + } + break; + default: + break; + } + } + + if (((ret == SH_OK) && (state == STAT_TOKEN_IN)) || (state == STAT_INIT)) { + ret = OsCmdParseOneToken(cmdParsed, count, token); + } + + return ret; +} + +unsigned int OsCmdParse(char *cmdStr, CmdParsed *cmdParsed) +{ + if ((cmdStr == NULL) || (cmdParsed == NULL) || (strlen(cmdStr) == 0)) { + return (unsigned int)SH_ERROR; + } + return OsCmdTokenSplit(cmdStr, ' ', cmdParsed); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif diff --git a/apps/shell/src/shmsg.c b/apps/shell/src/shmsg.c new file mode 100755 index 00000000..34b7537b --- /dev/null +++ b/apps/shell/src/shmsg.c @@ -0,0 +1,640 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "stdlib.h" +#include "stdio.h" +#include "unistd.h" +#include "sys/prctl.h" +#include "sys/ioctl.h" +#include "syscall.h" +#include "sys/wait.h" +#include "pthread.h" +#include "securec.h" +#include "shmsg.h" +#include "shell_pri.h" +#include "shcmd.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + + +char *GetCmdline(ShellCB *shellCB) +{ + CmdKeyLink *cmdkey = shellCB->cmdKeyLink; + CmdKeyLink *cmdNode = NULL; + + (void)pthread_mutex_lock(&shellCB->keyMutex); + if ((cmdkey == NULL) || SH_ListEmpty(&cmdkey->list)) { + (void)pthread_mutex_unlock(&shellCB->keyMutex); + return NULL; + } + + cmdNode = SH_LIST_ENTRY(cmdkey->list.pstNext, CmdKeyLink, list); + SH_ListDelete(&(cmdNode->list)); + (void)pthread_mutex_unlock(&shellCB->keyMutex); + + return cmdNode->cmdString; +} + +static void ShellSaveHistoryCmd(char *string, ShellCB *shellCB) +{ + CmdKeyLink *cmdHistory = shellCB->cmdHistoryKeyLink; + CmdKeyLink *cmdkey = SH_LIST_ENTRY(string, CmdKeyLink, cmdString); + CmdKeyLink *cmdNxt = NULL; + + if ((string == NULL) || (*string == '\n') || (strlen(string) == 0)) { + return; + } + + (void)pthread_mutex_lock(&shellCB->historyMutex); + if (cmdHistory->count != 0) { + cmdNxt = SH_LIST_ENTRY(cmdHistory->list.pstPrev, CmdKeyLink, list); + if (strcmp(string, cmdNxt->cmdString) == 0) { + free((void *)cmdkey); + (void)pthread_mutex_unlock(&shellCB->historyMutex); + return; + } + } + + if (cmdHistory->count == CMD_HISTORY_LEN) { + cmdNxt = SH_LIST_ENTRY(cmdHistory->list.pstNext, CmdKeyLink, list); + SH_ListDelete(&(cmdNxt->list)); + SH_ListTailInsert(&(cmdHistory->list), &(cmdkey->list)); + free((void *)cmdNxt); + (void)pthread_mutex_unlock(&shellCB->historyMutex); + return; + } + + SH_ListTailInsert(&(cmdHistory->list), &(cmdkey->list)); + cmdHistory->count++; + + (void)pthread_mutex_unlock(&shellCB->historyMutex); + return; +} + +int ShellPend(ShellCB *shellCB) +{ + if (shellCB == NULL) { + return SH_NOK; + } + + return sem_wait(&shellCB->shellSem); +} + +int ShellNotify(ShellCB *shellCB) +{ + if (shellCB == NULL) { + return SH_NOK; + } + + return sem_post(&shellCB->shellSem); +} + +enum { + STAT_NOMAL_KEY, + STAT_ESC_KEY, + STAT_MULTI_KEY +}; + +static int ShellCmdLineCheckUDRL(const char ch, ShellCB *shellCB) +{ + int ret = SH_OK; + if (ch == 0x1b) { /* 0x1b: ESC */ + shellCB->shellKeyType = STAT_ESC_KEY; + return ret; + } else if (ch == 0x5b) { /* 0x5b: first Key combination */ + if (shellCB->shellKeyType == STAT_ESC_KEY) { + shellCB->shellKeyType = STAT_MULTI_KEY; + return ret; + } + } else if (ch == 0x41) { /* up */ + if (shellCB->shellKeyType == STAT_MULTI_KEY) { + OsShellHistoryShow(CMD_KEY_UP, shellCB); + shellCB->shellKeyType = STAT_NOMAL_KEY; + return ret; + } + } else if (ch == 0x42) { /* down */ + if (shellCB->shellKeyType == STAT_MULTI_KEY) { + shellCB->shellKeyType = STAT_NOMAL_KEY; + OsShellHistoryShow(CMD_KEY_DOWN, shellCB); + return ret; + } + } else if (ch == 0x43) { /* right */ + if (shellCB->shellKeyType == STAT_MULTI_KEY) { + shellCB->shellKeyType = STAT_NOMAL_KEY; + return ret; + } + } else if (ch == 0x44) { /* left */ + if (shellCB->shellKeyType == STAT_MULTI_KEY) { + shellCB->shellKeyType = STAT_NOMAL_KEY; + return ret; + } + } + return SH_NOK; +} + +void ShellTaskNotify(ShellCB *shellCB) +{ + int ret; + + (void)pthread_mutex_lock(&shellCB->keyMutex); + OsShellCmdPush(shellCB->shellBuf, shellCB->cmdKeyLink); + (void)pthread_mutex_unlock(&shellCB->keyMutex); + + ret = ShellNotify(shellCB); + if (ret != SH_OK) { + printf("command execute failed, \"%s\"", shellCB->shellBuf); + } +} + +void ParseEnterKey(OutputFunc outputFunc, ShellCB *shellCB) +{ + if ((shellCB == NULL) || (outputFunc == NULL)) { + return; + } + + if (shellCB->shellBufOffset == 0) { + shellCB->shellBuf[shellCB->shellBufOffset] = '\n'; + shellCB->shellBuf[shellCB->shellBufOffset + 1] = '\0'; + goto NOTIFY; + } + + if (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1)) { + shellCB->shellBuf[shellCB->shellBufOffset] = '\0'; + } +NOTIFY: + outputFunc("\n"); + shellCB->shellBufOffset = 0; + ShellTaskNotify(shellCB); +} + +void ParseDeleteKey(OutputFunc outputFunc, ShellCB *shellCB) +{ + if ((shellCB == NULL) || (outputFunc == NULL)) { + return; + } + + if ((shellCB->shellBufOffset > 0) && (shellCB->shellBufOffset <= (SHOW_MAX_LEN - 1))) { + shellCB->shellBuf[shellCB->shellBufOffset - 1] = '\0'; + shellCB->shellBufOffset--; + outputFunc("\b \b"); + } +} + +void ParseTabKey(OutputFunc outputFunc, ShellCB *shellCB) +{ + int ret; + + if ((shellCB == NULL) || (outputFunc == NULL)) { + return; + } + + if ((shellCB->shellBufOffset > 0) && (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1))) { + ret = OsTabCompletion(shellCB->shellBuf, &shellCB->shellBufOffset); + if (ret > 1) { + outputFunc(SHELL_PROMPT"%s", shellCB->shellBuf); + } + } +} + +void ParseNormalChar(char ch, OutputFunc outputFunc, ShellCB *shellCB) +{ + if ((shellCB == NULL) || (outputFunc == NULL)) { + return; + } + + if ((ch != '\0') && (shellCB->shellBufOffset < (SHOW_MAX_LEN - 1))) { + shellCB->shellBuf[shellCB->shellBufOffset] = ch; + shellCB->shellBufOffset++; + outputFunc("%c", ch); + } + + shellCB->shellKeyType = STAT_NOMAL_KEY; +} + +void ShellCmdLineParse(char c, OutputFunc outputFunc, ShellCB *shellCB) +{ + const char ch = c; + int ret; + + if ((shellCB->shellBufOffset == 0) && (ch != '\n') && (ch != '\0')) { + (void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN); + } + + switch (ch) { + case '\r': + case '\n': /* enter */ + ParseEnterKey(outputFunc, shellCB); + break; + case '\b': /* backspace */ + case 0x7F: /* delete(0x7F) */ + ParseDeleteKey(outputFunc, shellCB); + break; + case '\t': /* tab */ + ParseTabKey(outputFunc, shellCB); + break; + default: + /* parse the up/down/right/left key */ + ret = ShellCmdLineCheckUDRL(ch, shellCB); + if (ret == SH_OK) { + return; + } + ParseNormalChar(ch, outputFunc, shellCB); + break; + } + + return; +} + +unsigned int ShellMsgNameGet(CmdParsed *cmdParsed, const char *cmdType) +{ + (void)cmdParsed; + (void)cmdType; + return SH_ERROR; +} + +char *GetCmdName(const char *cmdline, unsigned int len) +{ + unsigned int loop; + const char *tmpStr = NULL; + bool quotes = FALSE; + char *cmdName = NULL; + if (cmdline == NULL) { + return NULL; + } + + cmdName = (char *)malloc(len + 1); + if (cmdName == NULL) { + printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__); + return NULL; + } + + /* Scan the 'cmdline' string for command */ + /* Notice: Command string must not have any special name */ + for (tmpStr = cmdline, loop = 0; (*tmpStr != '\0') && (loop < len); ) { + /* If reach a double quotes, switch the quotes matching status */ + if (*tmpStr == '\"') { + SWITCH_QUOTES_STATUS(quotes); + /* Ignore the double quote charactor itself */ + tmpStr++; + continue; + } + /* If detected a space which the quotes matching status is false */ + /* which said has detected the first space for seperator, finish this scan operation */ + if ((*tmpStr == ' ') && (QUOTES_STATUS_CLOSE(quotes))) { + break; + } + cmdName[loop] = *tmpStr++; + loop++; + } + cmdName[loop] = '\0'; + + return cmdName; +} + +static void DoCmdExec(const char *cmdName, const char *cmdline, unsigned int len, const CmdParsed *cmdParsed) +{ + int ret; + pid_t forkPid; + + if (strncmp(cmdline, SHELL_EXEC_COMMAND, SHELL_EXEC_COMMAND_BYTES) == 0) { + forkPid = fork(); + if (forkPid < 0) { + printf("Faild to fork from shell\n"); + return; + } else if (forkPid == 0) { + ret = setpgrp(); + if (ret == -1) { + exit(1); + } + + ret = execve((const char *)cmdParsed->paramArray[0], (char * const *)cmdParsed->paramArray, NULL); + if (ret == -1) { + perror("execve"); + exit(-1); + } + } + } else { + (void)syscall(__NR_shellexec, cmdName, cmdline); + } +} + +static void ParseAndExecCmdline(CmdParsed *cmdParsed, const char *cmdline, unsigned int len) +{ + int i; + unsigned int ret; + char shellWorkingDirectory[PATH_MAX + 1] = { 0 }; + char *cmdlineOrigin = NULL; + char *cmdName = NULL; + + cmdlineOrigin = strdup(cmdline); + if (cmdlineOrigin == NULL) { + printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__); + return; + } + + cmdName = GetCmdName(cmdline, len); + if (cmdName == NULL) { + free(cmdlineOrigin); + printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__); + return; + } + + ret = OsCmdParse((char *)cmdline, cmdParsed); + if (ret != SH_OK) { + printf("cmd parse failure in %s[%d]\n", __FUNCTION__, __LINE__); + goto OUT; + } + + DoCmdExec(cmdName, cmdlineOrigin, len, cmdParsed); + + if (getcwd(shellWorkingDirectory, PATH_MAX) != NULL) { + (void)OsShellSetWorkingDirtectory(shellWorkingDirectory, (PATH_MAX + 1)); + } + +OUT: + for (i = 0; i < cmdParsed->paramCnt; i++) { + if (cmdParsed->paramArray[i] != NULL) { + free(cmdParsed->paramArray[i]); + cmdParsed->paramArray[i] = NULL; + } + } + free(cmdName); + free(cmdlineOrigin); +} + +unsigned int PreHandleCmdline(const char *input, char **output, unsigned int *outputlen) +{ + unsigned int shiftLen, execLen, newLen; + unsigned int removeLen = strlen("./"); /* "./" needs to be removed if it exists */ + unsigned int ret; + char *newCmd = NULL; + char *execCmd = SHELL_EXEC_COMMAND; + const char *cmdBuf = input; + unsigned int cmdBufLen = strlen(cmdBuf); + char *shiftStr = (char *)malloc(cmdBufLen + 1); + errno_t err; + + if (shiftStr == NULL) { + printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__); + return SH_NOK; + } + (void)memset_s(shiftStr, cmdBufLen + 1, 0, cmdBufLen + 1); + + /* Call function 'OsCmdKeyShift' to squeeze and clear useless or overmuch space if string buffer */ + ret = OsCmdKeyShift(cmdBuf, shiftStr, cmdBufLen + 1); + shiftLen = strlen(shiftStr); + if ((ret != SH_OK) || (shiftLen == 0)) { + ret = SH_NOK; + goto END_FREE_SHIFTSTR; + } + *output = shiftStr; + *outputlen = shiftLen; + + /* Check and parse "./", located at the first two charaters of the cmd */ + if ((shiftLen > removeLen) && (shiftStr[0] == '.') && (shiftStr[1] == '/')) { + execLen = strlen(execCmd); + newLen = execLen + shiftLen - removeLen; /* i.e., newLen - execLen == shiftLen - removeLen */ + newCmd = (char *)malloc(newLen + 1); + if (newCmd == NULL) { + ret = SH_NOK; + printf("malloc failure in %s[%d]\n", __FUNCTION__, __LINE__); + goto END_FREE_SHIFTSTR; + } + + err = memcpy_s(newCmd, newLen, execCmd, execLen); + if (err != EOK) { + printf("memcpy_s failure in %s[%d]\n", __FUNCTION__, __LINE__); + ret = SH_NOK; + goto END_FREE_NEWCMD; + } + + err = memcpy_s(newCmd + execLen, newLen - execLen, shiftStr + removeLen, shiftLen - removeLen); + if (err != EOK) { + printf("memcpy_s failure in %s[%d]\n", __FUNCTION__, __LINE__); + ret = SH_NOK; + goto END_FREE_NEWCMD; + } + newCmd[newLen] = '\0'; + + *output = newCmd; + *outputlen = newLen; + ret = SH_OK; + goto END_FREE_SHIFTSTR; + } else { + ret = SH_OK; + goto END; + } +END_FREE_NEWCMD: + free(newCmd); +END_FREE_SHIFTSTR: + free(shiftStr); +END: + return ret; +} + +static void ExecCmdline(const char *cmdline) +{ + unsigned int ret; + char *output = NULL; + unsigned int outputlen; + CmdParsed cmdParsed; + + if (cmdline == NULL) { + return; + } + + /* strip out unnecessary characters */ + ret = PreHandleCmdline(cmdline, &output, &outputlen); + if (ret == SH_NOK) { + return; + } + + (void)memset_s(&cmdParsed, sizeof(CmdParsed), 0, sizeof(CmdParsed)); + ParseAndExecCmdline(&cmdParsed, output, outputlen); + free(output); +} + +void RecycleZombieChild(void) +{ + while (waitpid(-1, NULL, WNOHANG) > 0) { + continue; + } +} + +static void ShellCmdProcess(ShellCB *shellCB) +{ + char *buf = NULL; + while (1) { + /* recycle zombine child process */ + RecycleZombieChild(); + buf = GetCmdline(shellCB); + if (buf == NULL) { + break; + } + + ExecCmdline(buf); + ShellSaveHistoryCmd(buf, shellCB); + shellCB->cmdMaskKeyLink = shellCB->cmdHistoryKeyLink; + printf(SHELL_PROMPT); + } +} + +void *ShellTask(void *argv) +{ + int ret; + ShellCB *shellCB = (ShellCB *)argv; + + if (shellCB == NULL) { + return NULL; + } + + ret = prctl(PR_SET_NAME, "ShellTask"); + if (ret != SH_OK) { + return NULL; + } + + printf(SHELL_PROMPT); + while (1) { + ret = ShellPend(shellCB); + if (ret == SH_OK) { + ShellCmdProcess(shellCB); + } else if (ret != SH_OK) { + break; + } + } + + return NULL; +} + +int ShellTaskInit(ShellCB *shellCB) +{ + unsigned int ret; + size_t stackSize = SHELL_TASK_STACKSIZE; + void *arg = NULL; + pthread_attr_t attr; + + if (shellCB == NULL) { + return SH_NOK; + } + + ret = pthread_attr_init(&attr); + if (ret != SH_OK) { + return SH_NOK; + } + + pthread_attr_setstacksize(&attr, stackSize); + arg = (void *)shellCB; + ret = pthread_create(&shellCB->shellTaskHandle, &attr, &ShellTask, arg); + if (ret != SH_OK) { + return SH_NOK; + } + + return ret; +} + +static int ShellKernelReg(unsigned int shellHandle) +{ + return ioctl(0, CONSOLE_CONTROL_REG_USERTASK, shellHandle); +} + +void *ShellEntry(void *argv) +{ + char ch; + int ret; + int n; + pid_t tid = syscall(__NR_gettid); + ShellCB *shellCB = (ShellCB *)argv; + + if (shellCB == NULL) { + return NULL; + } + + (void)memset_s(shellCB->shellBuf, SHOW_MAX_LEN, 0, SHOW_MAX_LEN); + + ret = prctl(PR_SET_NAME, "ShellEntry"); + if (ret != SH_OK) { + return NULL; + } + + ret = ShellKernelReg((int)tid); + if (ret != 0) { + printf("another shell is already running!\n"); + exit(-1); + } + + while (1) { + /* is console ready for shell ? */ + if (ret != SH_OK) + break; + + n = read(0, &ch, 1); + if (n == 1) { + ShellCmdLineParse(ch, (OutputFunc)printf, shellCB); + } + } + return NULL; +} + +int ShellEntryInit(ShellCB *shellCB) +{ + int ret; + size_t stackSize = SHELL_ENTRY_STACKSIZE; + void *arg = NULL; + pthread_attr_t attr; + + if (shellCB == NULL) { + return SH_NOK; + } + + ret = pthread_attr_init(&attr); + if (ret != SH_OK) { + return SH_NOK; + } + + pthread_attr_setstacksize(&attr, stackSize); + arg = (void *)shellCB; + ret = pthread_create(&shellCB->shellEntryHandle, &attr, &ShellEntry, arg); + if (ret != SH_OK) { + return SH_NOK; + } + + return ret; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif diff --git a/arch/Kconfig b/arch/Kconfig new file mode 100755 index 00000000..9e58fe4a --- /dev/null +++ b/arch/Kconfig @@ -0,0 +1,33 @@ +config ARCH_ARM + bool + +source "arch/arm/Kconfig" + +comment "Extra Configurations" + +config ARCH_FPU_DISABLE + bool "Disable Floating Pointer Unit" + default n + help + This option will bypass floating procedure in system. + +config ARCH_SECURE_MONITOR_MODE + bool "Run On Secure Monitor Mode" + default n + depends on ARCH_ARM_AARCH64 + help + This option will make the system run on EL3. + +config ARCH_INTERRUPT_PREEMPTION + bool "Enable Interrupt Preemption" + default n + depends on ARCH_ARM_AARCH64 + help + This option will support high priority interrupt preemption. + +config IRQ_USE_STANDALONE_STACK + bool "Use Interrupt Stack" + default y + depends on ARCH_ARM_AARCH64 || ARCH_ARM_AARCH32 + help + This option will support using standalone interrupt stack. diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig new file mode 100755 index 00000000..59959f81 --- /dev/null +++ b/arch/arm/Kconfig @@ -0,0 +1,77 @@ +# ARM Architecture + +# +# ARM has 32-bit(Aarch32) and 64-bit(Aarch64) implementations +# +config ARCH_ARM_AARCH32 + bool + select ARCH_ARM + help + 32-bit ARM architecture implementations, Except the M-profile. + It is not limited to ARMv7-A but also ARMv7-R, ARMv8-A 32-bit and etc. + +# +# Architecture Versions +# +config ARCH_ARM_V7A + bool + +config ARCH_ARM_VER + string + default "armv7-a" if ARCH_ARM_V7A + +# +# VFP Hardware +# +config ARCH_FPU_VFP_V3 + bool + help + An optional extension to the Arm, Thumb, and ThumbEE instruction sets in the ARMv7-A and ARMv7-R profiles. + VFPv3U is a variant of VFPv3 that supports the trapping of floating-point exceptions to support code. + +config ARCH_FPU_VFP_V4 + bool + help + An optional extension to the Arm, Thumb, and ThumbEE instruction sets in the ARMv7-A and ARMv7-R profiles. + VFPv4U is a variant of VFPv4 that supports the trapping of floating-point exceptions to support code. + VFPv4 and VFPv4U add both the Half-precision Extension and the fused multiply-add instructions to the features of VFPv3. + +config ARCH_FPU_VFP_D16 + bool + depends on ARCH_ARM_AARCH32 + help + VPU implemented with 16 doubleword registers (16 x 64-bit). + +config ARCH_FPU_VFP_D32 + bool + depends on ARCH_ARM_AARCH32 + help + VPU implemented with 32 doubleword registers (32 x 64-bit). + +config ARCH_FPU_VFP_NEON + bool + help + Advanced SIMD extension (NEON) support. + +config ARCH_FPU + string + default "vfpv3" if ARCH_FPU_VFP_V3 && ARCH_FPU_VFP_D32 + default "vfpv3-d16" if ARCH_FPU_VFP_V3 && ARCH_FPU_VFP_D16 + default "neon-vfpv4" if ARCH_FPU_VFP_V4 && ARCH_FPU_VFP_D32 && ARCH_FPU_VFP_NEON + default "vfpv4" if ARCH_FPU_VFP_V4 && ARCH_FPU_VFP_D32 + default "vfpv4-d16" if ARCH_FPU_VFP_V4 && ARCH_FPU_VFP_D16 + +# +# Supported Processor Cores +# +config ARCH_CORTEX_A7 + bool + select ARCH_ARM_V7A + select ARCH_ARM_AARCH32 + select ARCH_FPU_VFP_V4 + select ARCH_FPU_VFP_D32 + select ARCH_FPU_VFP_NEON + +config ARCH_CPU + string + default "cortex-a7" if ARCH_CORTEX_A7 diff --git a/arch/arm/arm.mk b/arch/arm/arm.mk new file mode 100755 index 00000000..923518c9 --- /dev/null +++ b/arch/arm/arm.mk @@ -0,0 +1,99 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# strip quotation mark in configuration + +LOSCFG_ARCH_CPU_STRIP := $(subst $\",,$(LOSCFG_ARCH_CPU)) +LOSCFG_ARCH_CPU = $(LOSCFG_ARCH_CPU_STRIP) + +LOSCFG_ARCH_FPU_STRIP := $(subst $\",,$(LOSCFG_ARCH_FPU)) +LOSCFG_ARCH_FPU = $(LOSCFG_ARCH_FPU_STRIP) + +ifeq ($(LOSCFG_ARCH_ARM_AARCH32), y) +LITEOS_ARCH_ARM := arm +else ifeq ($(LOSCFG_ARCH_ARM_AARCH64), y) +LITEOS_ARCH_ARM := +endif + +LITEOS_BASELIB += -l$(LOSCFG_ARCH_CPU) +LIB_SUBDIRS += arch/arm/$(LITEOS_ARCH_ARM) + +# CPU compile options +ifeq ($(LOSCFG_ARCH_ARM_AARCH64), y) +ifeq ($(LOSCFG_ARCH_FPU_DISABLE), y) +EXTENSION := +nofp +endif +endif +LITEOS_CPU_OPTS := -mcpu=$(LOSCFG_ARCH_CPU)$(EXTENSION) + +# FPU compile options +# -mfloat and -mfpu is ignored with AArch64 targets +ifeq ($(LOSCFG_ARCH_ARM_AARCH32), y) +LITEOS_FLOAT_OPTS := -mfloat-abi=softfp +LITEOS_FPU_OPTS := -mfpu=$(LOSCFG_ARCH_FPU) +# gcc libc folder style is combine with core and fpu +# for example, cortex-a7 with softfp abi and neon vfp4 is: a7_softfp_neon_vfp4 +LITEOS_GCCLIB := $(subst cortex-,,$(LOSCFG_ARCH_CPU))_softfp_$(LOSCFG_ARCH_FPU) +endif + +LITEOS_CORE_COPTS = $(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS) +LITEOS_INTERWORK += $(LITEOS_CORE_COPTS) +LITEOS_NODEBUG += $(LITEOS_CORE_COPTS) +LITEOS_ASOPTS += $(LITEOS_CPU_OPTS) +LITEOS_CXXOPTS_BASE += $(LITEOS_CORE_COPTS) + +ARCH_INCLUDE := -I $(LITEOSTOPDIR)/arch/arm/include \ + -I $(LITEOSTOPDIR)/arch/arm/$(LITEOS_ARCH_ARM)/include \ + -I $(LITEOSTOPDIR)/arch/arm/$(LITEOS_ARCH_ARM)/src/include + +LITEOS_PLATFORM_INCLUDE += $(ARCH_INCLUDE) +LITEOS_CXXINCLUDE += $(ARCH_INCLUDE) + +# expose FPU info to assembly code +ifeq ($(LOSCFG_ARCH_FPU_DISABLE), y) + LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_DISABLE +else ifeq ($(LOSCFG_ARCH_FPU_VFP_D16), y) + LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D16 +else ifeq ($(LOSCFG_ARCH_FPU_VFP_D32), y) + LITEOS_CMACRO += -DLOSCFG_ARCH_FPU_VFP_D32 +endif + +# extra definition for other module +LITEOS_CPU_TYPE = $(LOSCFG_ARCH_CPU) +LITEOS_ARM_ARCH := -march=$(subst $\",,$(LOSCFG_ARCH_ARM_VER)) + +# linux style macros +LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7A) = -D__LINUX_ARM_ARCH__=7 +LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7R) = -D__LINUX_ARM_ARCH__=7 +LINUX_ARCH_$(LOSCFG_ARCH_ARM_V7M) = -D__LINUX_ARM_ARCH__=7 +LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8A) = -D__LINUX_ARM_ARCH__=8 +LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8R) = -D__LINUX_ARM_ARCH__=8 +LINUX_ARCH_$(LOSCFG_ARCH_ARM_V8M) = -D__LINUX_ARM_ARCH__=8 + +AS_OBJS_LIBC_FLAGS += $(LINUX_ARCH_y) diff --git a/arch/arm/arm/Makefile b/arch/arm/arm/Makefile new file mode 100755 index 00000000..24d47056 --- /dev/null +++ b/arch/arm/arm/Makefile @@ -0,0 +1,55 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include $(LITEOSTOPDIR)/config.mk + +MODULE_NAME := $(LOSCFG_ARCH_CPU) + +LOCAL_SRCS := $(wildcard src/*.c) $(wildcard src/*.S) +LOCAL_INCLUDE := \ + -I $(LITEOSTOPDIR)/kernel/base/include \ + -I $(LITEOSTOPDIR)/kernel/extended/include \ + -I $(LITEOSTOPDIR)/arch/arm/arm/include \ + +ifeq ($(LITEOS_ARM_ARCH), -march=armv7-a) +LOCAL_SRCS += $(wildcard src/armv7a/*.S) +endif + +ifeq ($(LOSCFG_KERNEL_SMP), y) +LOCAL_SRCS += src/startup/reset_vector_mp.S +else +LOCAL_SRCS += src/startup/reset_vector_up.S +endif + +LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) + +ifeq ($(LOSCFG_GDB), y) +LOCAL_FLAGS += $(AS_OBJS_LIBC_FLAGS) +endif +include $(MODULE) diff --git a/arch/arm/arm/include/arch_config.h b/arch/arm/arm/include/arch_config.h new file mode 100755 index 00000000..09de16a4 --- /dev/null +++ b/arch/arm/arm/include/arch_config.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#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 diff --git a/arch/arm/arm/include/arm.h b/arch/arm/arm/include/arm.h new file mode 100755 index 00000000..bde38793 --- /dev/null +++ b/arch/arm/arm/include/arm.h @@ -0,0 +1,1135 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#ifndef __LOS_ARM_H__ +#define __LOS_ARM_H__ + +#define CPSR_MODE_USR 0x10 +#define CPSR_MODE_MASK 0x1f + +#define DSB __asm__ volatile("dsb" ::: "memory") +#define ISB __asm__ volatile("isb" ::: "memory") +#define DMB __asm__ volatile("dmb" ::: "memory") + +STATIC INLINE UINT32 OsArmReadSctlr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c1,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteSctlr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c1,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadActlr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c1,c0,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteActlr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c1,c0,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadCpacr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c1,c0,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteCpacr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c1,c0,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTtbr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c2,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTtbr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c2,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTtbr0(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c2,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTtbr0(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c2,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTtbr1(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c2,c0,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTtbr1(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c2,c0,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTtbcr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c2,c0,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTtbcr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c2,c0,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDacr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c3,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDacr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c3,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDfsr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c5,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDfsr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c5,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadIfsr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c5,c0,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteIfsr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c5,c0,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDfar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c6,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDfar(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c6,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadWfar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c6,c0,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteWfar(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c6,c0,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadIfar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c6,c0,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteIfar(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c6,c0,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadFcseidr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c13,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteFcseidr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c13,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadContextidr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c13,c0,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteContextidr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c13,c0,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTpidrurw(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c13,c0,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTpidrurw(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c13,c0,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTpidruro(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c13,c0,3" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTpidruro(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c13,c0,3" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTpidrprw(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c13,c0,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTpidrprw(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c13,c0,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadMidr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c0,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteMidr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c0,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadMpidr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c0,c0,5" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteMpidr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c0,c0,5" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadVbar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c12,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteVbar(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c12,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadCbar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 4, %0, c15,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteCbar(UINT32 val) +{ + __asm__ volatile("mcr p15, 4, %0, c15,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadAts1cpr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c8,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteAts1cpr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c8,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadAts1cpw(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c8,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteAts1cpw(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c8,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadAts1cur(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c8,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteAts1cur(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c8,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadAts1cuw(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c8,3" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteAts1cuw(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c8,3" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadAts12nsopr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c8,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteAts12nsopr(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c8,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadAts12nsopw(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c8,5" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteAts12nsopw(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c8,5" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadAts12nsour(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c8,6" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteAts12nsour(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c8,6" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadAts12nsouw(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c8,7" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteAts12nsouw(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c8,7" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadPar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c4,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWritePar(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c4,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadBpiall(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c5,6" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteBpiall(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c5,6" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadBpimva(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c5,7" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteBpimva(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c5,7" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadBpiallis(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c7,c1,6" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteBpiallis(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c7,c1,6" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTlbiallis(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c3,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTlbiallis(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c3,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTlbimvais(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c3,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTlbimvais(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c3,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTlbiasidis(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c3,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTlbiasidis(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c3,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTlbimvaais(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c3,3" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTlbimvaais(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c3,3" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadItlbiall(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c5,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteItlbiall(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c5,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadItlbimva(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c5,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteItlbimva(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c5,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadItlbiasid(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c5,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteItlbiasid(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c5,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDtlbiall(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c6,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDtlbiall(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c6,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDtlbimva(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c6,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDtlbimva(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c6,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDtlbiasid(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c6,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDtlbiasid(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c6,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTlbiall(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c7,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTlbiall(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c7,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTlbimva(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c7,1" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTlbimva(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c7,1" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTlbiasid(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c7,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTlbiasid(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c7,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadTlbimvaa(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 0, %0, c8,c7,3" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteTlbimvaa(UINT32 val) +{ + __asm__ volatile("mcr p15, 0, %0, c8,c7,3" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadL2ctlr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 1, %0, c9,c0,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteL2ctlr(UINT32 val) +{ + __asm__ volatile("mcr p15, 1, %0, c9,c0,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadL2ectlr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p15, 1, %0, c9,c0,3" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteL2ectlr(UINT32 val) +{ + __asm__ volatile("mcr p15, 1, %0, c9,c0,3" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbddidr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbddidr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdrar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c1,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdrar(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c1,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdsar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c2,c0,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdsar(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c2,c0,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdscr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c1,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdscr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c1,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdtrtxint(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c5,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdtrtxint(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c5,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdtrrxint(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c5,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdtrrxint(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c5,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgwfar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c6,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgwfar(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c6,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgvcr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c7,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgvcr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c7,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgecr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c9,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgecr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c9,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdsccr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c10,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdsccr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c10,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdsmcr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c11,0" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdsmcr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c11,0" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdtrrxext(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c0,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdtrrxext(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c0,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdscrext(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c2,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdscrext(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c2,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdtrtxext(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c3,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdtrtxext(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c3,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdrcr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c4,2" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdrcr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c4,2" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgvr0(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c0,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgvr0(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c0,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgvr1(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c1,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgvr1(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c1,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgvr2(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c2,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgvr2(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c2,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgbcr0(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c0,5" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgbcr0(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c0,5" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgbcr1(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c1,5" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgbcr1(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c1,5" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgbcr2(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c2,5" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgbcr2(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c2,5" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgwvr0(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c0,6" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgwvr0(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c0,6" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgwvr1(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c1,6" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgwvr1(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c1,6" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgwcr0(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c0,7" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgwcr0(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c0,7" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgwcr1(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c0,c1,7" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgwcr1(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c0,c1,7" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgoslar(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c1,c0,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgoslar(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c1,c0,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgoslsr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c1,c1,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgoslsr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c1,c1,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgossrr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c1,c2,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgossrr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c1,c2,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgprcr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c1,c4,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgprcr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c1,c4,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgprsr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c1,c5,4" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgprsr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c1,c5,4" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgclaimset(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c7,c8,6" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgclaimset(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c7,c8,6" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgclaimclr(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c7,c9,6" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgclaimclr(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c7,c9,6" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgauthstatus(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c7,c14,6" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgauthstatus(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c7,c14,6" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +STATIC INLINE UINT32 OsArmReadDbgdevid(VOID) +{ + UINT32 val; + __asm__ volatile("mrc p14, 0, %0, c7,c2,7" : "=r"(val)); + return val; +} + +STATIC INLINE VOID OsArmWriteDbgdevid(UINT32 val) +{ + __asm__ volatile("mcr p14, 0, %0, c7,c2,7" ::"r"(val)); + __asm__ volatile("isb" ::: "memory"); +} + +#endif /* __LOS_ARM_H__ */ diff --git a/arch/arm/arm/include/arm_user_copy.h b/arch/arm/arm/include/arm_user_copy.h new file mode 100755 index 00000000..ac82b958 --- /dev/null +++ b/arch/arm/arm/include/arm_user_copy.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_typedef.h" +#pragma once + +size_t _arm_user_copy(void *dst, const void *src, size_t len); + diff --git a/arch/arm/arm/include/arm_user_get.h b/arch/arm/arm/include/arm_user_get.h new file mode 100755 index 00000000..53532107 --- /dev/null +++ b/arch/arm/arm/include/arm_user_get.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ARM_USER_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 */ diff --git a/arch/arm/arm/include/arm_user_put.h b/arch/arm/arm/include/arm_user_put.h new file mode 100755 index 00000000..cacae1b2 --- /dev/null +++ b/arch/arm/arm/include/arm_user_put.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _ARM_USER_PUT_H +#define _ARM_USER_PUT_H + +#include "los_typedef.h" +#include "securec.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +errno_t _arm_put_user(void *dst, const void *src, size_t dstTypeLen, size_t srcTypeLen); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _ARM_USER_PUT_H */ diff --git a/arch/arm/arm/include/los_arch_mmu.h b/arch/arm/arm/include/los_arch_mmu.h new file mode 100755 index 00000000..c501b219 --- /dev/null +++ b/arch/arm/arm/include/los_arch_mmu.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_arch_mmu architecture mmu + * @ingroup kernel + */ + +#ifndef __LOS_ARCH_MMU_H__ +#define __LOS_ARCH_MMU_H__ + +#include "los_typedef.h" +#include "los_mux.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +typedef struct ArchMmu { + LosMux mtx; /**< arch mmu page table entry modification mutex lock */ + VADDR_T *virtTtb; /**< translation table base virtual addr */ + PADDR_T physTtb; /**< translation table base phys addr */ + UINT32 asid; /**< TLB asid */ + LOS_DL_LIST ptList; /**< page table vm page list */ +} LosArchMmu; + +BOOL OsArchMmuInit(LosArchMmu *archMmu, VADDR_T *virtTtb); +STATUS_T LOS_ArchMmuQuery(const LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T *paddr, UINT32 *flags); +STATUS_T LOS_ArchMmuUnmap(LosArchMmu *archMmu, VADDR_T vaddr, size_t count); +STATUS_T LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_t count, UINT32 flags); +STATUS_T LOS_ArchMmuChangeProt(LosArchMmu *archMmu, VADDR_T vaddr, size_t count, UINT32 flags); +STATUS_T LOS_ArchMmuMove(LosArchMmu *archMmu, VADDR_T oldVaddr, VADDR_T newVaddr, size_t count, UINT32 flags); +VOID LOS_ArchMmuContextSwitch(LosArchMmu *archMmu); +STATUS_T LOS_ArchMmuDestroy(LosArchMmu *archMmu); +VOID OsArchMmuInitPerCPU(VOID); +VADDR_T *OsGFirstTableGet(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* __LOS_VM_PAGE_H__ */ + diff --git a/arch/arm/arm/include/los_asid.h b/arch/arm/arm/include/los_asid.h new file mode 100755 index 00000000..eb343611 --- /dev/null +++ b/arch/arm/arm/include/los_asid.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_asid mmu address space id + * @ingroup kernel + */ + +#ifndef __LOS_ASID_H__ +#define __LOS_ASID_H__ + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define MMU_ARM_ASID_BITS 8 + +/* allocate and free asid */ +STATUS_T OsAllocAsid(UINT32 *asid); +VOID OsFreeAsid(UINT32 asid); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* __LOS_VM_PAGE_H__ */ + diff --git a/arch/arm/arm/include/los_atomic.h b/arch/arm/arm/include/los_atomic.h new file mode 100755 index 00000000..d007b66e --- /dev/null +++ b/arch/arm/arm/include/los_atomic.h @@ -0,0 +1,892 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_atomic Atomic + * @ingroup kernel + */ + +#ifndef __LOS_ATOMIC_H__ +#define __LOS_ATOMIC_H__ + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +typedef volatile INT32 Atomic; +typedef volatile INT64 Atomic64; + +/** + * @ingroup los_atomic + * @brief Atomic read. + * + * @par Description: + * This API is used to implement the atomic read and return the result value of the read. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
+ * + * @param v [IN] The reading pointer. + * + * @retval #INT32 The result value of the read. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT32 LOS_AtomicRead(const Atomic *v) +{ + return *(volatile INT32 *)v; +} + +/** + * @ingroup los_atomic + * @brief Atomic setting. + * + * @par Description: + * This API is used to implement the atomic setting operation. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
+ * + * @param v [IN] The variable pointer to be setting. + * @param setVal [IN] The value to be setting. + * + * @retval none. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE VOID LOS_AtomicSet(Atomic *v, INT32 setVal) +{ + *(volatile INT32 *)v = setVal; +} + +/** + * @ingroup los_atomic + * @brief Atomic addition. + * + * @par Description: + * This API is used to implement the atomic addition and return the result value of the augend. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • If the addtion result is not in the range of representable values for 32-bit signed integer, + * an int integer overflow may occur to the return value
  • + *
+ * + * @param v [IN] The augend pointer. + * @param addVal [IN] The addend. + * + * @retval #INT32 The result value of the augend. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT32 LOS_AtomicAdd(Atomic *v, INT32 addVal) +{ + INT32 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrex %1, [%2]\n" + "add %1, %1, %3\n" + "strex %0, %1, [%2]" + : "=&r"(status), "=&r"(val) + : "r"(v), "r"(addVal) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return val; +} + +/** + * @ingroup los_atomic + * @brief Atomic subtraction. + * + * @par Description: + * This API is used to implement the atomic subtraction and return the result value of the minuend. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • If the subtraction result is not in the range of representable values for 32-bit signed integer, + * an int integer overflow may occur to the return value
  • + *
+ * + * @param v [IN] The minuend pointer. + * @param subVal [IN] The subtrahend. + * + * @retval #INT32 The result value of the minuend. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT32 LOS_AtomicSub(Atomic *v, INT32 subVal) +{ + INT32 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrex %1, [%2]\n" + "sub %1, %1, %3\n" + "strex %0, %1, [%2]" + : "=&r"(status), "=&r"(val) + : "r"(v), "r"(subVal) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return val; +} + +/** + * @ingroup los_atomic + * @brief Atomic addSelf. + * + * @par Description: + * This API is used to implement the atomic addSelf. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • The value which v point to must not be INT_MAX to avoid integer overflow after adding 1.
  • + *
+ * + * @param v [IN] The addSelf variable pointer. + * + * @retval none. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE VOID LOS_AtomicInc(Atomic *v) +{ + INT32 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrex %0, [%3]\n" + "add %0, %0, #1\n" + "strex %1, %0, [%3]" + : "=&r"(val), "=&r"(status), "+m"(*v) + : "r"(v) + : "cc"); + } while (__builtin_expect(status != 0, 0)); +} + +/** + * @ingroup los_atomic + * @brief Atomic addSelf. + * + * @par Description: + * This API is used to implement the atomic addSelf and return the result of addSelf. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • The value which v point to must not be INT_MAX to avoid integer overflow after adding 1.
  • + *
+ * + * @param v [IN] The addSelf variable pointer. + * + * @retval #INT32 The return value of variable addSelf. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT32 LOS_AtomicIncRet(Atomic *v) +{ + INT32 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrex %0, [%3]\n" + "add %0, %0, #1\n" + "strex %1, %0, [%3]" + : "=&r"(val), "=&r"(status), "+m"(*v) + : "r"(v) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return val; +} + +/** + * @ingroup los_atomic + * @brief Atomic auto-decrement. + * + * @par Description: + * This API is used to implementating the atomic auto-decrement. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • The value which v point to must not be INT_MIN to avoid overflow after reducing 1.
  • + *
+ * + * @param v [IN] The auto-decrement variable pointer. + * + * @retval none. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE VOID LOS_AtomicDec(Atomic *v) +{ + INT32 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrex %0, [%3]\n" + "sub %0, %0, #1\n" + "strex %1, %0, [%3]" + : "=&r"(val), "=&r"(status), "+m"(*v) + : "r"(v) + : "cc"); + } while (__builtin_expect(status != 0, 0)); +} + +/** + * @ingroup los_atomic + * @brief Atomic auto-decrement. + * + * @par Description: + * This API is used to implementating the atomic auto-decrement and return the result of auto-decrement. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • The value which v point to must not be INT_MIN to avoid overflow after reducing 1.
  • + *
+ * + * @param v [IN] The auto-decrement variable pointer. + * + * @retval #INT32 The return value of variable auto-decrement. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT32 LOS_AtomicDecRet(Atomic *v) +{ + INT32 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrex %0, [%3]\n" + "sub %0, %0, #1\n" + "strex %1, %0, [%3]" + : "=&r"(val), "=&r"(status), "+m"(*v) + : "r"(v) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return val; +} + +/** + * @ingroup los_atomic + * @brief Atomic64 read. + * + * @par Description: + * This API is used to implement the atomic64 read and return the result value of the read. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
+ * + * @param v [IN] The reading pointer. + * + * @retval #INT64 The result value of the read. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT64 LOS_Atomic64Read(const Atomic64 *v) +{ + INT64 val; + + do { + __asm__ __volatile__("ldrexd %0, %H0, [%1]" + : "=&r"(val) + : "r"(v) + : "cc"); + } while (0); + + return val; +} + +/** + * @ingroup los_atomic + * @brief Atomic64 setting. + * + * @par Description: + * This API is used to implement the atomic64 setting operation. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
+ * + * @param v [IN] The variable pointer to be setting. + * @param setVal [IN] The value to be setting. + * + * @retval none. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE VOID LOS_Atomic64Set(Atomic64 *v, INT64 setVal) +{ + INT64 tmp; + UINT32 status; + + do { + __asm__ __volatile__("ldrexd %1, %H1, [%2]\n" + "strexd %0, %3, %H3, [%2]" + : "=&r"(status), "=&r"(tmp) + : "r"(v), "r"(setVal) + : "cc"); + } while (__builtin_expect(status != 0, 0)); +} + +/** + * @ingroup los_atomic + * @brief Atomic64 addition. + * + * @par Description: + * This API is used to implement the atomic64 addition and return the result value of the augend. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • If the addtion result is not in the range of representable values for 64-bit signed integer, + * an int integer overflow may occur to the return value
  • + *
+ * + * @param v [IN] The augend pointer. + * @param addVal [IN] The addend. + * + * @retval #INT64 The result value of the augend. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT64 LOS_Atomic64Add(Atomic64 *v, INT64 addVal) +{ + INT64 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrexd %1, %H1, [%2]\n" + "adds %Q1, %Q1, %Q3\n" + "adc %R1, %R1, %R3\n" + "strexd %0, %1, %H1, [%2]" + : "=&r"(status), "=&r"(val) + : "r"(v), "r"(addVal) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return val; +} + +/** + * @ingroup los_atomic + * @brief Atomic64 subtraction. + * + * @par Description: + * This API is used to implement the atomic64 subtraction and return the result value of the minuend. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • If the subtraction result is not in the range of representable values for 64-bit signed integer, + * an int integer overflow may occur to the return value
  • + *
+ * + * @param v [IN] The minuend pointer. + * @param subVal [IN] The subtrahend. + * + * @retval #INT64 The result value of the minuend. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT64 LOS_Atomic64Sub(Atomic64 *v, INT64 subVal) +{ + INT64 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrexd %1, %H1, [%2]\n" + "subs %Q1, %Q1, %Q3\n" + "sbc %R1, %R1, %R3\n" + "strexd %0, %1, %H1, [%2]" + : "=&r"(status), "=&r"(val) + : "r"(v), "r"(subVal) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return val; +} + +/** + * @ingroup los_atomic + * @brief Atomic64 addSelf. + * + * @par Description: + * This API is used to implement the atomic64 addSelf . + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • The value which v point to must not be INT64_MAX to avoid integer overflow after adding 1.
  • + *
+ * + * @param v [IN] The addSelf variable pointer. + * + * @retval none. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE VOID LOS_Atomic64Inc(Atomic64 *v) +{ + INT64 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrexd %0, %H0, [%3]\n" + "adds %Q0, %Q0, #1\n" + "adc %R0, %R0, #0\n" + "strexd %1, %0, %H0, [%3]" + : "=&r"(val), "=&r"(status), "+m"(*v) + : "r"(v) + : "cc"); + } while (__builtin_expect(status != 0, 0)); +} + +/** + * @ingroup los_atomic + * @brief Atomic64 addSelf. + * + * @par Description: + * This API is used to implement the atomic64 addSelf and return the result of addSelf. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • The value which v point to must not be INT64_MAX to avoid integer overflow after adding 1.
  • + *
+ * + * @param v [IN] The addSelf variable pointer. + * + * @retval #INT64 The return value of variable addSelf. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT64 LOS_Atomic64IncRet(Atomic64 *v) +{ + INT64 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrexd %0, %H0, [%3]\n" + "adds %Q0, %Q0, #1\n" + "adc %R0, %R0, #0\n" + "strexd %1, %0, %H0, [%3]" + : "=&r"(val), "=&r"(status), "+m"(*v) + : "r"(v) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return val; +} + +/** + * @ingroup los_atomic + * @brief Atomic64 auto-decrement. + * + * @par Description: + * This API is used to implementating the atomic64 auto-decrement. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • The value which v point to must not be INT64_MIN to avoid overflow after reducing 1.
  • + *
+ * + * @param v [IN] The auto-decrement variable pointer. + * + * @retval none. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE VOID LOS_Atomic64Dec(Atomic64 *v) +{ + INT64 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrexd %0, %H0, [%3]\n" + "subs %Q0, %Q0, #1\n" + "sbc %R0, %R0, #0\n" + "strexd %1, %0, %H0, [%3]" + : "=&r"(val), "=&r"(status), "+m"(*v) + : "r"(v) + : "cc"); + } while (__builtin_expect(status != 0, 0)); +} + +/** + * @ingroup los_atomic + * @brief Atomic64 auto-decrement. + * + * @par Description: + * This API is used to implementating the atomic64 auto-decrement and return the result of auto-decrement. + * @attention + *
    + *
  • The pointer v must not be NULL.
  • + *
  • The value which v point to must not be INT64_MIN to avoid overflow after reducing 1.
  • + *
+ * + * @param v [IN] The auto-decrement variable pointer. + * + * @retval #INT64 The return value of variable auto-decrement. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT64 LOS_Atomic64DecRet(Atomic64 *v) +{ + INT64 val; + UINT32 status; + + do { + __asm__ __volatile__("ldrexd %0, %H0, [%3]\n" + "subs %Q0, %Q0, #1\n" + "sbc %R0, %R0, #0\n" + "strexd %1, %0, %H0, [%3]" + : "=&r"(val), "=&r"(status), "+m"(*v) + : "r"(v) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return val; +} + +/** + * @ingroup los_atomic + * @brief Atomic exchange for 8-bit variable. + * + * @par Description: + * This API is used to implement the atomic exchange for 8-bit variable and + * return the previous value of the atomic variable. + * @attention + *
    The pointer v must not be NULL.
+ * + * @param v [IN] The variable pointer. + * @param val [IN] The exchange value. + * + * @retval #INT32 The previous value of the atomic variable + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT32 LOS_AtomicXchgByte(volatile INT8 *v, INT32 val) +{ + INT32 prevVal; + UINT32 status; + + do { + __asm__ __volatile__("ldrexb %0, [%3]\n" + "strexb %1, %4, [%3]" + : "=&r"(prevVal), "=&r"(status), "+m"(*v) + : "r"(v), "r"(val) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return prevVal; +} + +/** + * @ingroup los_atomic + * @brief Atomic exchange for 16-bit variable. + * + * @par Description: + * This API is used to implement the atomic exchange for 16-bit variable and + * return the previous value of the atomic variable. + * @attention + *
    The pointer v must not be NULL.
+ * + * @param v [IN] The variable pointer. + * @param val [IN] The exchange value. + * + * @retval #INT32 The previous value of the atomic variable + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT32 LOS_AtomicXchg16bits(volatile INT16 *v, INT32 val) +{ + INT32 prevVal; + UINT32 status; + + do { + __asm__ __volatile__("ldrexh %0, [%3]\n" + "strexh %1, %4, [%3]" + : "=&r"(prevVal), "=&r"(status), "+m"(*v) + : "r"(v), "r"(val) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return prevVal; +} + +/** + * @ingroup los_atomic + * @brief Atomic exchange for 32-bit variable. + * + * @par Description: + * This API is used to implement the atomic exchange for 32-bit variable + * and return the previous value of the atomic variable. + * @attention + *
    The pointer v must not be NULL.
+ * + * @param v [IN] The variable pointer. + * @param val [IN] The exchange value. + * + * @retval #INT32 The previous value of the atomic variable + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT32 LOS_AtomicXchg32bits(Atomic *v, INT32 val) +{ + INT32 prevVal; + UINT32 status; + + do { + __asm__ __volatile__("ldrex %0, [%3]\n" + "strex %1, %4, [%3]" + : "=&r"(prevVal), "=&r"(status), "+m"(*v) + : "r"(v), "r"(val) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return prevVal; +} + +/** + * @ingroup los_atomic + * @brief Atomic exchange for 64-bit variable. + * + * @par Description: + * This API is used to implement the atomic exchange for 64-bit variable + * and return the previous value of the atomic variable. + * @attention + *
    The pointer v must not be NULL.
+ * + * @param v [IN] The variable pointer. + * @param val [IN] The exchange value. + * + * @retval #INT64 The previous value of the atomic variable + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE INT64 LOS_AtomicXchg64bits(Atomic64 *v, INT64 val) +{ + INT64 prevVal; + UINT32 status; + + do { + __asm__ __volatile__("ldrexd %0, %H0, [%3]\n" + "strexd %1, %4, %H4, [%3]" + : "=&r"(prevVal), "=&r"(status), "+m"(*v) + : "r"(v), "r"(val) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return prevVal; +} + +/** + * @ingroup los_atomic + * @brief Atomic exchange for 8-bit variable with compare. + * + * @par Description: + * This API is used to implement the atomic exchange for 8-bit variable, if the value of variable is equal to oldVal. + * @attention + *
    The pointer v must not be NULL.
+ * + * @param v [IN] The variable pointer. + * @param val [IN] The new value. + * @param oldVal [IN] The old value. + * + * @retval TRUE The previous value of the atomic variable is not equal to oldVal. + * @retval FALSE The previous value of the atomic variable is equal to oldVal. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE BOOL LOS_AtomicCmpXchgByte(volatile INT8 *v, INT32 val, INT32 oldVal) +{ + INT32 prevVal; + UINT32 status; + + do { + __asm__ __volatile__("ldrexb %0, [%3]\n" + "mov %1, #0\n" + "teq %0, %4\n" + "strexbeq %1, %5, [%3]" + : "=&r"(prevVal), "=&r"(status), "+m"(*v) + : "r"(v), "r"(oldVal), "r"(val) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return prevVal != oldVal; +} + +/** + * @ingroup los_atomic + * @brief Atomic exchange for 16-bit variable with compare. + * + * @par Description: + * This API is used to implement the atomic exchange for 16-bit variable, if the value of variable is equal to oldVal. + * @attention + *
    The pointer v must not be NULL.
+ * + * @param v [IN] The variable pointer. + * @param val [IN] The new value. + * @param oldVal [IN] The old value. + * + * @retval TRUE The previous value of the atomic variable is not equal to oldVal. + * @retval FALSE The previous value of the atomic variable is equal to oldVal. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE BOOL LOS_AtomicCmpXchg16bits(volatile INT16 *v, INT32 val, INT32 oldVal) +{ + INT32 prevVal; + UINT32 status; + + do { + __asm__ __volatile__("ldrexh %0, [%3]\n" + "mov %1, #0\n" + "teq %0, %4\n" + "strexheq %1, %5, [%3]" + : "=&r"(prevVal), "=&r"(status), "+m"(*v) + : "r"(v), "r"(oldVal), "r"(val) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return prevVal != oldVal; +} + +/** + * @ingroup los_atomic + * @brief Atomic exchange for 32-bit variable with compare. + * + * @par Description: + * This API is used to implement the atomic exchange for 32-bit variable, if the value of variable is equal to oldVal. + * @attention + *
    The pointer v must not be NULL.
+ * + * @param v [IN] The variable pointer. + * @param val [IN] The new value. + * @param oldVal [IN] The old value. + * + * @retval TRUE The previous value of the atomic variable is not equal to oldVal. + * @retval FALSE The previous value of the atomic variable is equal to oldVal. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE BOOL LOS_AtomicCmpXchg32bits(Atomic *v, INT32 val, INT32 oldVal) +{ + INT32 prevVal; + UINT32 status; + + do { + __asm__ __volatile__("ldrex %0, [%3]\n" + "mov %1, #0\n" + "teq %0, %4\n" + "strexeq %1, %5, [%3]" + : "=&r"(prevVal), "=&r"(status), "+m"(*v) + : "r"(v), "r"(oldVal), "r"(val) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return prevVal != oldVal; +} + +/** + * @ingroup los_atomic + * @brief Atomic exchange for 64-bit variable with compare. + * + * @par Description: + * This API is used to implement the atomic exchange for 64-bit variable, if the value of variable is equal to oldVal. + * @attention + *
    The pointer v must not be NULL.
+ * + * @param v [IN] The variable pointer. + * @param val [IN] The new value. + * @param oldVal [IN] The old value. + * + * @retval TRUE The previous value of the atomic variable is not equal to oldVal. + * @retval FALSE The previous value of the atomic variable is equal to oldVal. + * @par Dependency: + *
  • los_atomic.h: the header file that contains the API declaration.
+ * @see + */ +STATIC INLINE BOOL LOS_AtomicCmpXchg64bits(Atomic64 *v, INT64 val, INT64 oldVal) +{ + INT64 prevVal; + UINT32 status; + + do { + __asm__ __volatile__("ldrexd %0, %H0, [%3]\n" + "mov %1, #0\n" + "teq %0, %4\n" + "teqeq %H0, %H4\n" + "strexdeq %1, %5, %H5, [%3]" + : "=&r"(prevVal), "=&r"(status), "+m"(*v) + : "r"(v), "r"(oldVal), "r"(val) + : "cc"); + } while (__builtin_expect(status != 0, 0)); + + return prevVal != oldVal; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* __LOS_ATOMIC_H__ */ diff --git a/arch/arm/arm/include/los_hw_cpu.h b/arch/arm/arm/include/los_hw_cpu.h new file mode 100755 index 00000000..5585eebc --- /dev/null +++ b/arch/arm/arm/include/los_hw_cpu.h @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_hw Hardware + * @ingroup kernel + */ + +#ifndef _LOS_HW_CPU_H +#define _LOS_HW_CPU_H + +#include "los_typedef.h" +#include "los_toolchain.h" +#include "los_hw_arch.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* ARM System Registers */ +#define DSB __asm__ volatile("dsb" ::: "memory") +#define DMB __asm__ volatile("dmb" ::: "memory") +#define ISB __asm__ volatile("isb" ::: "memory") +#define BARRIER __asm__ volatile("":::"memory") + +#define ARM_SYSREG_READ(REG) \ +({ \ + UINT32 _val; \ + __asm__ volatile("mrc " REG : "=r" (_val)); \ + _val; \ +}) + +#define ARM_SYSREG_WRITE(REG, val) \ +({ \ + __asm__ volatile("mcr " REG :: "r" (val)); \ + ISB; \ +}) + +#define ARM_SYSREG64_READ(REG) \ +({ \ + UINT64 _val; \ + __asm__ volatile("mrrc " REG : "=r" (_val)); \ + _val; \ +}) + +#define ARM_SYSREG64_WRITE(REG, val) \ +({ \ + __asm__ volatile("mcrr " REG :: "r" (val)); \ + ISB; \ +}) + +#define CP14_REG(CRn, Op1, CRm, Op2) "p14, "#Op1", %0, "#CRn","#CRm","#Op2 +#define CP15_REG(CRn, Op1, CRm, Op2) "p15, "#Op1", %0, "#CRn","#CRm","#Op2 +#define CP15_REG64(CRn, Op1) "p15, "#Op1", %0, %H0,"#CRn + +/* + * Identification registers (c0) + */ +#define MIDR CP15_REG(c0, 0, c0, 0) /* Main ID Register */ +#define MPIDR CP15_REG(c0, 0, c0, 5) /* Multiprocessor Affinity Register */ +#define CCSIDR CP15_REG(c0, 1, c0, 0) /* Cache Size ID Registers */ +#define CLIDR CP15_REG(c0, 1, c0, 1) /* Cache Level ID Register */ +#define VPIDR CP15_REG(c0, 4, c0, 0) /* Virtualization Processor ID Register */ +#define VMPIDR CP15_REG(c0, 4, c0, 5) /* Virtualization Multiprocessor ID Register */ + +/* + * System control registers (c1) + */ +#define SCTLR CP15_REG(c1, 0, c0, 0) /* System Control Register */ +#define ACTLR CP15_REG(c1, 0, c0, 1) /* Auxiliary Control Register */ +#define CPACR CP15_REG(c1, 0, c0, 2) /* Coprocessor Access Control Register */ + +/* + * Memory protection and control registers (c2 & c3) + */ +#define TTBR0 CP15_REG(c2, 0, c0, 0) /* Translation Table Base Register 0 */ +#define TTBR1 CP15_REG(c2, 0, c0, 1) /* Translation Table Base Register 1 */ +#define TTBCR CP15_REG(c2, 0, c0, 2) /* Translation Table Base Control Register */ +#define DACR CP15_REG(c3, 0, c0, 0) /* Domain Access Control Register */ + +/* + * Memory system fault registers (c5 & c6) + */ +#define DFSR CP15_REG(c5, 0, c0, 0) /* Data Fault Status Register */ +#define IFSR CP15_REG(c5, 0, c0, 1) /* Instruction Fault Status Register */ +#define DFAR CP15_REG(c6, 0, c0, 0) /* Data Fault Address Register */ +#define IFAR CP15_REG(c6, 0, c0, 2) /* Instruction Fault Address Register */ + +/* + * Process, context and thread ID registers (c13) + */ +#define FCSEIDR CP15_REG(c13, 0, c0, 0) /* FCSE Process ID Register */ +#define CONTEXTIDR CP15_REG(c13, 0, c0, 1) /* Context ID Register */ +#define TPIDRURW CP15_REG(c13, 0, c0, 2) /* User Read/Write Thread ID Register */ +#define TPIDRURO CP15_REG(c13, 0, c0, 3) /* User Read-Only Thread ID Register */ +#define TPIDRPRW CP15_REG(c13, 0, c0, 4) /* PL1 only Thread ID Register */ + +#define MPIDR_CPUID_MASK (0xffU) + +STATIC INLINE VOID *ArchCurrTaskGet(VOID) +{ + return (VOID *)(UINTPTR)ARM_SYSREG_READ(TPIDRPRW); +} + +STATIC INLINE VOID ArchCurrTaskSet(VOID *val) +{ + ARM_SYSREG_WRITE(TPIDRPRW, (UINT32)(UINTPTR)val); +} + +STATIC INLINE VOID ArchCurrUserTaskSet(UINTPTR val) +{ + ARM_SYSREG_WRITE(TPIDRURO, (UINT32)val); +} + +STATIC INLINE UINT32 ArchCurrCpuid(VOID) +{ +#if (LOSCFG_KERNEL_SMP == YES) + return ARM_SYSREG_READ(MPIDR) & MPIDR_CPUID_MASK; +#else + return 0; +#endif +} + +STATIC INLINE UINT64 OsHwIDGet(VOID) +{ + return ARM_SYSREG_READ(MPIDR); +} + +STATIC INLINE UINT32 OsMainIDGet(VOID) +{ + return ARM_SYSREG_READ(MIDR); +} + +/* CPU interrupt mask handle implementation */ +#if LOSCFG_ARM_ARCH >= 6 + +STATIC INLINE UINT32 ArchIntLock(VOID) +{ + UINT32 intSave; + __asm__ __volatile__( + "mrs %0, cpsr \n" + "cpsid if " + : "=r"(intSave) + : + : "memory"); + return intSave; +} + +STATIC INLINE UINT32 ArchIntUnlock(VOID) +{ + UINT32 intSave; + __asm__ __volatile__( + "mrs %0, cpsr \n" + "cpsie if " + : "=r"(intSave) + : + : "memory"); + return intSave; +} + +#else + +STATIC INLINE UINT32 ArchIntLock(VOID) +{ + UINT32 intSave, temp; + __asm__ __volatile__( + "mrs %0, cpsr \n" + "orr %1, %0, #0xc0 \n" + "msr cpsr_c, %1 " + :"=r"(intSave), "=r"(temp) + : :"memory"); + return intSave; +} + +STATIC INLINE UINT32 ArchIntUnlock(VOID) +{ + UINT32 intSave; + __asm__ __volatile__( + "mrs %0, cpsr \n" + "bic %0, %0, #0xc0 \n" + "msr cpsr_c, %0 " + : "=r"(intSave) + : : "memory"); + return intSave; +} + +#endif + +STATIC INLINE VOID ArchIntRestore(UINT32 intSave) +{ + __asm__ __volatile__( + "msr cpsr_c, %0 " + : + : "r"(intSave) + : "memory"); +} + +#define PSR_I_BIT 0x00000080U + +STATIC INLINE UINT32 OsIntLocked(VOID) +{ + UINT32 intSave; + + asm volatile( + "mrs %0, cpsr " + : "=r" (intSave) + : + : "memory", "cc"); + + return intSave & PSR_I_BIT; +} + +STATIC INLINE UINT32 ArchSPGet(VOID) +{ + UINT32 val; + __asm__ __volatile__("mov %0, sp" : "=r"(val)); + return val; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_HW_CPU_H */ diff --git a/arch/arm/arm/include/los_mmu_descriptor_v6.h b/arch/arm/arm/include/los_mmu_descriptor_v6.h new file mode 100755 index 00000000..1eb04229 --- /dev/null +++ b/arch/arm/arm/include/los_mmu_descriptor_v6.h @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_mmu_descriptor_v6 MMU Descriptor v6 + * @ingroup kernel + */ + +#ifndef __LOS_MMU_DESCRIPTOR_V6_H__ +#define __LOS_MMU_DESCRIPTOR_V6_H__ + +#include "los_vm_common.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define __iomem +#ifndef IS_ALIGNED +#define IS_ALIGNED(a, b) (!(((UINTPTR)(a)) & (((UINTPTR)(b))-1))) +#endif + +#define MMU_DESCRIPTOR_TEX_0 0 +#define MMU_DESCRIPTOR_TEX_1 1 +#define MMU_DESCRIPTOR_TEX_2 2 +#define MMU_DESCRIPTOR_TEX_MASK 7 + +#define MMU_DESCRIPTOR_CACHE_BUFFER_SHIFT 2 +#define MMU_DESCRIPTOR_CACHE_BUFFER(x) ((x) << MMU_DESCRIPTOR_CACHE_BUFFER_SHIFT) +#define MMU_DESCRIPTOR_NON_CACHEABLE MMU_DESCRIPTOR_CACHE_BUFFER(0) +#define MMU_DESCRIPTOR_WRITE_BACK_ALLOCATE MMU_DESCRIPTOR_CACHE_BUFFER(1) +#define MMU_DESCRIPTOR_WRITE_THROUGH_NO_ALLOCATE MMU_DESCRIPTOR_CACHE_BUFFER(2) +#define MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE MMU_DESCRIPTOR_CACHE_BUFFER(3) + +/* user space mmu access permission define begin */ +#define MMU_DESCRIPTOR_DOMAIN_MANAGER 0 +#define MMU_DESCRIPTOR_DOMAIN_CLIENT 1 +#define MMU_DESCRIPTOR_DOMAIN_NA 2 + +/* L1 descriptor type */ +#define MMU_DESCRIPTOR_L1_TYPE_INVALID (0x0 << 0) +#define MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE (0x1 << 0) +#define MMU_DESCRIPTOR_L1_TYPE_SECTION (0x2 << 0) +#define MMU_DESCRIPTOR_L1_TYPE_MASK (0x3 << 0) + +/* L2 descriptor type */ +#define MMU_DESCRIPTOR_L2_TYPE_INVALID (0x0 << 0) +#define MMU_DESCRIPTOR_L2_TYPE_LARGE_PAGE (0x1 << 0) +#define MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE (0x2 << 0) +#define MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE_XN (0x3 << 0) +#define MMU_DESCRIPTOR_L2_TYPE_MASK (0x3 << 0) + +#define MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(x) IS_ALIGNED(x, MMU_DESCRIPTOR_L1_SMALL_SIZE) +#define MMU_DESCRIPTOR_L1_SMALL_SIZE 0x100000 +#define MMU_DESCRIPTOR_L1_SMALL_MASK (MMU_DESCRIPTOR_L1_SMALL_SIZE - 1) +#define MMU_DESCRIPTOR_L1_SMALL_FRAME (~MMU_DESCRIPTOR_L1_SMALL_MASK) +#define MMU_DESCRIPTOR_L1_SMALL_SHIFT 20 +#define MMU_DESCRIPTOR_L1_SECTION_ADDR(x) ((x) & MMU_DESCRIPTOR_L1_SMALL_FRAME) +#define MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(x) ((x) & ~((1 << 10)-1)) +#define MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE 4 +#define MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS 0x4000U +#define MMU_DESCRIPTOR_L1_SMALL_DOMAIN_MASK (~(0x0f << 5)) /* 4k page section domain mask */ +#define MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT (MMU_DESCRIPTOR_DOMAIN_CLIENT << 5) + +#define MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE (1 << 3) +#define MMU_DESCRIPTOR_L1_SECTION_NON_SECURE (1 << 19) +#define MMU_DESCRIPTOR_L1_SECTION_SHAREABLE (1 << 16) +#define MMU_DESCRIPTOR_L1_SECTION_NON_GLOBAL (1 << 17) +#define MMU_DESCRIPTOR_L1_SECTION_XN (1 << 4) + +/* TEX CB */ +#define MMU_DESCRIPTOR_L1_TEX_SHIFT 12 /* type extension field shift */ +#define MMU_DESCRIPTOR_L1_TEX(x) \ + ((x) << MMU_DESCRIPTOR_L1_TEX_SHIFT) /* type extension */ +#define MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED \ + (MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_NON_CACHEABLE) +#define MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED \ + (MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_WRITE_BACK_ALLOCATE) +#define MMU_DESCRIPTOR_L1_TYPE_DEVICE_NON_SHARED \ + (MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_2) | MMU_DESCRIPTOR_NON_CACHEABLE) +#define MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE \ + (MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_1) | MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE) +#define MMU_DESCRIPTOR_L1_TEX_TYPE_MASK \ + (MMU_DESCRIPTOR_L1_TEX(MMU_DESCRIPTOR_TEX_MASK) | MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE) + +#define MMU_DESCRIPTOR_L1_AP2_SHIFT 15 +#define MMU_DESCRIPTOR_L1_AP2(x) ((x) << MMU_DESCRIPTOR_L1_AP2_SHIFT) +#define MMU_DESCRIPTOR_L1_AP2_0 (MMU_DESCRIPTOR_L1_AP2(0)) +#define MMU_DESCRIPTOR_L1_AP2_1 (MMU_DESCRIPTOR_L1_AP2(1)) +#define MMU_DESCRIPTOR_L1_AP01_SHIFT 10 +#define MMU_DESCRIPTOR_L1_AP01(x) ((x) << MMU_DESCRIPTOR_L1_AP01_SHIFT) +#define MMU_DESCRIPTOR_L1_AP01_0 (MMU_DESCRIPTOR_L1_AP01(0)) +#define MMU_DESCRIPTOR_L1_AP01_1 (MMU_DESCRIPTOR_L1_AP01(1)) +#define MMU_DESCRIPTOR_L1_AP01_3 (MMU_DESCRIPTOR_L1_AP01(3)) +#define MMU_DESCRIPTOR_L1_AP_P_NA_U_NA (MMU_DESCRIPTOR_L1_AP2_0 | MMU_DESCRIPTOR_L1_AP01_0) +#define MMU_DESCRIPTOR_L1_AP_P_RW_U_RW (MMU_DESCRIPTOR_L1_AP2_0 | MMU_DESCRIPTOR_L1_AP01_3) +#define MMU_DESCRIPTOR_L1_AP_P_RW_U_NA (MMU_DESCRIPTOR_L1_AP2_0 | MMU_DESCRIPTOR_L1_AP01_1) +#define MMU_DESCRIPTOR_L1_AP_P_RO_U_RO (MMU_DESCRIPTOR_L1_AP2_1 | MMU_DESCRIPTOR_L1_AP01_3) +#define MMU_DESCRIPTOR_L1_AP_P_RO_U_NA (MMU_DESCRIPTOR_L1_AP2_1 | MMU_DESCRIPTOR_L1_AP01_1) +#define MMU_DESCRIPTOR_L1_AP_MASK (MMU_DESCRIPTOR_L1_AP2_1 | MMU_DESCRIPTOR_L1_AP01_3) + +#define MMU_DESCRIPTOR_L2_SMALL_SIZE 0x1000 +#define MMU_DESCRIPTOR_L2_SMALL_MASK (MMU_DESCRIPTOR_L2_SMALL_SIZE - 1) +#define MMU_DESCRIPTOR_L2_SMALL_FRAME (~MMU_DESCRIPTOR_L2_SMALL_MASK) +#define MMU_DESCRIPTOR_L2_SMALL_SHIFT 12 +#define MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 \ + (MMU_DESCRIPTOR_L1_SMALL_SIZE >> MMU_DESCRIPTOR_L2_SMALL_SHIFT) +#define MMU_DESCRIPTOR_IS_L2_SIZE_ALIGNED(x) IS_ALIGNED(x, MMU_DESCRIPTOR_L2_SMALL_SIZE) +#define MMU_DESCRIPTOR_L2_TEX_SHIFT 6 /* type extension field shift */ +#define MMU_DESCRIPTOR_L2_TEX(x) \ + ((x) << MMU_DESCRIPTOR_L2_TEX_SHIFT) /* type extension */ +#define MMU_DESCRIPTOR_L2_TYPE_STRONGLY_ORDERED \ + (MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_NON_CACHEABLE) +#define MMU_DESCRIPTOR_L2_TYPE_DEVICE_SHARED \ + (MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_0) | MMU_DESCRIPTOR_WRITE_BACK_ALLOCATE) +#define MMU_DESCRIPTOR_L2_TYPE_DEVICE_NON_SHARED \ + (MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_2) | MMU_DESCRIPTOR_NON_CACHEABLE) +#define MMU_DESCRIPTOR_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE \ + (MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_1) | MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE) +#define MMU_DESCRIPTOR_L2_TEX_TYPE_MASK \ + (MMU_DESCRIPTOR_L2_TEX(MMU_DESCRIPTOR_TEX_MASK) | MMU_DESCRIPTOR_WRITE_BACK_NO_ALLOCATE) +#define MMU_DESCRIPTOR_L2_AP2_SHIFT 9 +#define MMU_DESCRIPTOR_L2_AP2(x) ((x) << MMU_DESCRIPTOR_L2_AP2_SHIFT) +#define MMU_DESCRIPTOR_L2_AP2_0 (MMU_DESCRIPTOR_L2_AP2(0)) +#define MMU_DESCRIPTOR_L2_AP2_1 (MMU_DESCRIPTOR_L2_AP2(1)) +#define MMU_DESCRIPTOR_L2_AP01_SHIFT 4 +#define MMU_DESCRIPTOR_L2_AP01(x) ((x) << MMU_DESCRIPTOR_L2_AP01_SHIFT) +#define MMU_DESCRIPTOR_L2_AP01_0 (MMU_DESCRIPTOR_L2_AP01(0)) +#define MMU_DESCRIPTOR_L2_AP01_1 (MMU_DESCRIPTOR_L2_AP01(1)) +#define MMU_DESCRIPTOR_L2_AP01_3 (MMU_DESCRIPTOR_L2_AP01(3)) +#define MMU_DESCRIPTOR_L2_AP_P_NA_U_NA (MMUDESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_0) +#define MMU_DESCRIPTOR_L2_AP_P_RW_U_RW (MMU_DESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_3) +#define MMU_DESCRIPTOR_L2_AP_P_RW_U_NA (MMU_DESCRIPTOR_L2_AP2_0 | MMU_DESCRIPTOR_L2_AP01_1) +#define MMU_DESCRIPTOR_L2_AP_P_RO_U_RO (MMU_DESCRIPTOR_L2_AP2_1 | MMU_DESCRIPTOR_L2_AP01_3) +#define MMU_DESCRIPTOR_L2_AP_P_RO_U_NA (MMU_DESCRIPTOR_L2_AP2_1 | MMU_DESCRIPTOR_L2_AP01_1) +#define MMU_DESCRIPTOR_L2_AP_MASK (MMU_DESCRIPTOR_L2_AP2_1 | MMU_DESCRIPTOR_L2_AP01_3) + +#define MMU_DESCRIPTOR_L2_SHAREABLE (1 << 10) +#define MMU_DESCRIPTOR_L2_NON_GLOBAL (1 << 11) +#define MMU_DESCRIPTOR_L2_SMALL_PAGE_ADDR(x) ((x) & MMU_DESCRIPTOR_L2_SMALL_FRAME) + +#define MMU_DESCRIPTOR_TTBCR_PD0 (1 << 4) +#define MMU_DESCRIPTOR_TTBR_WRITE_BACK_ALLOCATE 1 +#define MMU_DESCRIPTOR_TTBR_RGN(x) (((x) & 0x3) << 3) +#define MMU_DESCRIPTOR_TTBR_IRGN(x) ((((x) & 0x1) << 6) | ((((x) >> 1) & 0x1) << 0)) +#define MMU_DESCRIPTOR_TTBR_S (1 << 1) +#define MMU_DESCRIPTOR_TTBR_NOS (1 << 5) + +#ifdef LOSCFG_KERNEL_SMP +#define MMU_TTBRx_SHARABLE_FLAGS (MMU_DESCRIPTOR_TTBR_S | MMU_DESCRIPTOR_TTBR_NOS) +#else +#define MMU_TTBRx_SHARABLE_FLAGS 0 +#endif + +#define MMU_TTBRx_FLAGS \ + (MMU_DESCRIPTOR_TTBR_RGN(MMU_DESCRIPTOR_TTBR_WRITE_BACK_ALLOCATE) | \ + MMU_DESCRIPTOR_TTBR_IRGN(MMU_DESCRIPTOR_TTBR_WRITE_BACK_ALLOCATE) | \ + MMU_TTBRx_SHARABLE_FLAGS) + +#ifdef LOSCFG_KERNEL_SMP +#define MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS \ + (MMU_DESCRIPTOR_L1_TYPE_SECTION | \ + MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ + MMU_DESCRIPTOR_L1_AP_P_RW_U_NA | \ + MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \ + MMU_DESCRIPTOR_L1_SECTION_SHAREABLE) +#else +#define MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS \ + (MMU_DESCRIPTOR_L1_TYPE_SECTION | \ + MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \ + MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \ + MMU_DESCRIPTOR_L1_AP_P_RW_U_NA) +#endif + +#define MMU_INITIAL_MAP_STRONGLY_ORDERED \ + (MMU_DESCRIPTOR_L1_TYPE_SECTION | \ + MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED | \ + MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \ + MMU_DESCRIPTOR_L1_AP_P_RW_U_NA) + +#define MMU_INITIAL_MAP_DEVICE \ + (MMU_DESCRIPTOR_L1_TYPE_SECTION | \ + MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED | \ + MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT | \ + MMU_DESCRIPTOR_L1_AP_P_RW_U_NA) + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* __LOS_MMU_DESCRIPTOR_V6_H__ */ + diff --git a/arch/arm/arm/include/los_pte_ops.h b/arch/arm/arm/include/los_pte_ops.h new file mode 100755 index 00000000..5d6c2b74 --- /dev/null +++ b/arch/arm/arm/include/los_pte_ops.h @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_pte_ops page table entry operations + * @ingroup kernel + */ + +#ifndef __LOS_PTE_OPS_H__ +#define __LOS_PTE_OPS_H__ + +#include "los_typedef.h" +#include "arm.h" +#include "los_mmu_descriptor_v6.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +STATIC INLINE VOID OsSavePte1(PTE_T *pte1Ptr, PTE_T pte1) +{ + DMB; + *pte1Ptr = pte1; + DSB; +} + +STATIC INLINE ADDR_T OsTruncPte1(ADDR_T addr) +{ + return MMU_DESCRIPTOR_L1_SECTION_ADDR(addr); +} + +STATIC INLINE UINT32 OsGetPte1Index(vaddr_t va) +{ + return va >> MMU_DESCRIPTOR_L1_SMALL_SHIFT; +} + +STATIC INLINE VOID OsClearPte1(PTE_T *pte1Ptr) +{ + OsSavePte1(pte1Ptr, 0); +} + +STATIC INLINE PTE_T *OsGetPte1Ptr(PTE_T *pte1BasePtr, vaddr_t va) +{ + return (pte1BasePtr + OsGetPte1Index(va)); +} + +STATIC INLINE PTE_T OsGetPte1(PTE_T *pte1BasePtr, vaddr_t va) +{ + return *OsGetPte1Ptr(pte1BasePtr, va); +} + +STATIC INLINE BOOL OsIsPte1PageTable(PTE_T pte1) +{ + return (pte1 & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE; +} + +STATIC INLINE BOOL OsIsPte1Invalid(PTE_T pte1) +{ + return (pte1 & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_INVALID; +} + +STATIC INLINE BOOL OsIsPte1Section(PTE_T pte1) +{ + return (pte1 & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_SECTION; +} + +STATIC INLINE UINT32 OsGetPte2Index(vaddr_t va) +{ + return (va % MMU_DESCRIPTOR_L1_SMALL_SIZE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT; +} + +STATIC INLINE PTE_T *OsGetPte2Ptr(PTE_T *pte2BasePtr, vaddr_t va) +{ + return (pte2BasePtr + OsGetPte2Index(va)); +} + +STATIC INLINE PTE_T OsGetPte2(PTE_T *pte2BasePtr, vaddr_t va) +{ + return *(pte2BasePtr + OsGetPte2Index(va)); +} + +STATIC INLINE VOID OsSavePte2(PTE_T *pte2Ptr, PTE_T pte2) +{ + DMB; + *pte2Ptr = pte2; + DSB; +} + +STATIC INLINE UINT32 OsSavePte2Continuous(PTE_T *pte2BasePtr, UINT32 index, PTE_T pte2, UINT32 count) +{ + UINT32 saveCounts = 0; + if (count == 0) { + return 0; + } + + DMB; + do { + pte2BasePtr[index++] = pte2; + count--; + pte2 += MMU_DESCRIPTOR_L2_SMALL_SIZE; + saveCounts++; + } while ((count != 0) && (index != MMU_DESCRIPTOR_L2_NUMBERS_PER_L1)); + DSB; + + return saveCounts; +} + +STATIC INLINE VOID OsClearPte2Continuous(PTE_T *pte2Ptr, UINT32 count) +{ + UINT32 index = 0; + + DMB; + while (count > 0) { + pte2Ptr[index++] = 0; + count--; + } + DSB; +} + +STATIC INLINE BOOL OsIsPte2SmallPage(PTE_T pte2) +{ + return (pte2 & MMU_DESCRIPTOR_L2_TYPE_MASK) == MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE; +} + +STATIC INLINE BOOL OsIsPte2SmallPageXN(PTE_T pte2) +{ + return (pte2 & MMU_DESCRIPTOR_L2_TYPE_MASK) == MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE_XN; +} + +STATIC INLINE BOOL OsIsPte2LargePage(PTE_T pte2) +{ + return (pte2 & MMU_DESCRIPTOR_L2_TYPE_MASK) == MMU_DESCRIPTOR_L2_TYPE_LARGE_PAGE; +} + +STATIC INLINE BOOL OsIsPte2Invalid(PTE_T pte2) +{ + return (pte2 & MMU_DESCRIPTOR_L2_TYPE_MASK) == MMU_DESCRIPTOR_L2_TYPE_INVALID; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* __LOS_PTE_OPS_H__ */ diff --git a/arch/arm/arm/include/los_tlb_v6.h b/arch/arm/arm/include/los_tlb_v6.h new file mode 100755 index 00000000..5ccacaf5 --- /dev/null +++ b/arch/arm/arm/include/los_tlb_v6.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_tlb_v6 MMU TLB v6 + * @ingroup kernel + */ +#ifndef __LOS_TLB_V6_H__ +#define __LOS_TLB_V6_H__ + +#include "los_typedef.h" +#include "menuconfig.h" +#include "arm.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +STATIC INLINE VOID OsArmInvalidateTlbBarrier(VOID) +{ +#ifdef LOSCFG_KERNEL_SMP + OsArmWriteBpiallis(0); +#else + OsArmWriteBpiall(0); +#endif + DSB; + ISB; +} + +STATIC INLINE VOID OsArmInvalidateTlbMvaNoBarrier(VADDR_T va) +{ +#ifdef LOSCFG_KERNEL_SMP + OsArmWriteTlbimvaais(va & 0xfffff000); +#else + OsArmWriteTlbimvaa(va & 0xfffff000); +#endif +} + +STATIC INLINE VOID OsArmInvalidateTlbMvaRangeNoBarrier(VADDR_T start, UINT32 count) +{ + UINT32 index = 0; + + while (count > 0) { + OsArmInvalidateTlbMvaNoBarrier(start + (index << MMU_DESCRIPTOR_L2_SMALL_SHIFT)); + index++; + count--; + } +} + +STATIC INLINE VOID OsCleanTLB(VOID) +{ + UINT32 val = 0; + __asm volatile("mcr p15, 0, %0, c8, c7, 0" : : "r"(val)); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* __LOS_TLB_V6_H__ */ + diff --git a/arch/arm/arm/src/armv7a/cache.S b/arch/arm/arm/src/armv7a/cache.S new file mode 100755 index 00000000..cdcbee06 --- /dev/null +++ b/arch/arm/arm/src/armv7a/cache.S @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "asm.h" + + .fpu vfpv4 + .arch armv7a +.macro DCACHE_LINE_SIZE, reg, tmp + mrc p15, 0, \tmp, c0, c0, 1 + lsr \tmp, \tmp, #16 + and \tmp, \tmp, #0xf + mov \reg, #4 + mov \reg, \reg, lsl \tmp +.endm + + +FUNCTION(arm_inv_cache_range) + push {r2, r3} + DCACHE_LINE_SIZE r2, r3 + sub r3, r2, #1 + tst r0, r3 + bic r0, r0, r3 + + mcrne p15, 0, r0, c7, c14, 1 + + tst r1, r3 + bic r1, r1, r3 + mcrne p15, 0, r1, c7, c14, 1 +1: + mcr p15, 0, r0, c7, c6, 1 + add r0, r0, r2 + cmp r0, r1 + blo 1b + dsb + pop {r2, r3} + mov pc, lr + +FUNCTION(arm_clean_cache_range) + push {r2, r3} + DCACHE_LINE_SIZE r2, r3 + sub r3, r2, #1 + bic r0, r0, r3 + +1: + mcr p15, 0, r0, c7, c10, 1 + add r0, r0, r2 + cmp r0, r1 + blo 1b + dsb + pop {r2, r3} + mov pc, lr diff --git a/arch/arm/arm/src/hw_user_get.S b/arch/arm/arm/src/hw_user_get.S new file mode 100755 index 00000000..820d48ec --- /dev/null +++ b/arch/arm/arm/src/hw_user_get.S @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "asm.h" + +.syntax unified +.arm + +// errno_t _arm_get_user(void *dst, const void *src, size_t dstTypeLen, size_t srcTypeLen) +FUNCTION(_arm_get_user) + stmdb sp!, {r0, r1, r2, r3, lr} + cmp r2, #0 + beq .Lget_user_return + cmp r2, r3 + bne .Lget_user_err + cmp r2, #1 + bhi .Lget_user_half +.Lget_user_byte: +0: ldrbt r3, [r1], #0 +1: strb r3, [r0], #0 + b .Lget_user_return +.Lget_user_half: + cmp r2, #2 + bhi .Lget_user_word +2: ldrht r3, [r1], #0 +3: strh r3, [r0], #0 + b .Lget_user_return +.Lget_user_word: + cmp r2, #4 + bhi .Lget_user_err +4: ldrt r3, [r1], #0 +5: str r3, [r0], #0 +.Lget_user_return: + ldmia sp!, {r0, r1, r2, r3, lr} + mov r0, 0 + bx lr +.Lget_user_err: + ldmia sp!, {r0, r1, r2, r3, lr} + mov r0, #-14 + bx lr + +.pushsection __exc_table, "a" + .long 0b, .Lget_user_err + .long 1b, .Lget_user_err + .long 2b, .Lget_user_err + .long 3b, .Lget_user_err + .long 4b, .Lget_user_err + .long 5b, .Lget_user_err +.popsection diff --git a/arch/arm/arm/src/hw_user_put.S b/arch/arm/arm/src/hw_user_put.S new file mode 100755 index 00000000..941efe7e --- /dev/null +++ b/arch/arm/arm/src/hw_user_put.S @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "asm.h" + +.syntax unified +.arm + +// errno_t _arm_put_user(void *dst, const void *src, size_t dstTypeLen, size_t srcTypeLen) +FUNCTION(_arm_put_user) + stmdb sp!, {r0, r1, r2, r3, lr} + cmp r2, #0 + beq .Lget_user_return + cmp r2, r3 + bne .Lget_user_err + cmp r2, #1 + bhi .Lget_user_half +.Lget_user_byte: +0: ldrb r3, [r1], #0 +1: strbt r3, [r0], #0 + b .Lget_user_return +.Lget_user_half: + cmp r2, #2 + bhi .Lget_user_word +2: ldrh r3, [r1], #0 +3: strht r3, [r0], #0 + b .Lget_user_return +.Lget_user_word: + cmp r2, #4 + bhi .Lget_user_err +4: ldr r3, [r1], #0 +5: strt r3, [r0], #0 +.Lget_user_return: + ldmia sp!, {r0, r1, r2, r3, lr} + mov r0, 0 + bx lr +.Lget_user_err: + ldmia sp!, {r0, r1, r2, r3, lr} + mov r0, #-14 + bx lr + +.pushsection __exc_table, "a" + .long 0b, .Lget_user_err + .long 1b, .Lget_user_err + .long 2b, .Lget_user_err + .long 3b, .Lget_user_err + .long 4b, .Lget_user_err + .long 5b, .Lget_user_err +.popsection diff --git a/arch/arm/arm/src/include/asm.h b/arch/arm/arm/src/include/asm.h new file mode 100755 index 00000000..796e14c0 --- /dev/null +++ b/arch/arm/arm/src/include/asm.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __ASM_H +#define __ASM_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define FUNCTION(x) .global x; .text; .code 32; x: +#define MPIDR_CPUID_MASK 0xFFU + +/* + * ------------------------------------------ + * stackTop | cpu n | ... | cpu 1 | cpu 0 | stackBottom + * ------------------------------------------ + * | stackSize | ... | stackSize | stackSize | + */ +.macro EXC_SP_SET stackBottom, stackSize, reg0, reg1 + mrc p15, 0, \reg0, c0, c0, 5 + and \reg0, \reg0, #MPIDR_CPUID_MASK /* get cpu id */ + mov \reg1, #\stackSize + mul \reg1, \reg1, \reg0 /* calculate current cpu stack offset */ + ldr \reg0, =\stackBottom + sub \reg0, \reg0, \reg1 /* calculate current cpu stack bottom */ + mov sp, \reg0 /* set sp */ +.endm + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* __ASM_H */ diff --git a/arch/arm/arm/src/include/los_exc_pri.h b/arch/arm/arm/src/include/los_exc_pri.h new file mode 100755 index 00000000..4031217b --- /dev/null +++ b/arch/arm/arm/src/include/los_exc_pri.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_EXC_PRI_H +#define _LOS_EXC_PRI_H + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +STATIC INLINE VOID OsSetCurrCpuSp(UINTPTR regSp) +{ + __asm__ __volatile__("mov sp, %0" :: "r"(regSp)); +} + +#define OS_SYSTEM_NORMAL 0 +#define OS_SYSTEM_EXC_CURR_CPU 1 +#define OS_SYSTEM_EXC_OTHER_CPU 2 + +extern UINT32 OsGetSystemStatus(VOID); +extern VOID BackTraceSub(UINTPTR regFP); +extern VOID OsExcInit(VOID); +extern VOID OsKillUserProcess(UINTPTR sp); +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_EXC_PRI_H */ diff --git a/arch/arm/arm/src/include/los_hw_pri.h b/arch/arm/arm/src/include/los_hw_pri.h new file mode 100755 index 00000000..5d470b34 --- /dev/null +++ b/arch/arm/arm/src/include/los_hw_pri.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_HW_PRI_H +#define _LOS_HW_PRI_H + +#include "los_base.h" +#include "los_hw.h" +#include "los_process_pri.h" +#include "los_signal.h" +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#if defined(LOSCFG_ARCH_FPU_VFP_D16) +#define FP_REGS_NUM 16 +#elif defined (LOSCFG_ARCH_FPU_VFP_D32) +#define FP_REGS_NUM 32 +#endif +#define GEN_REGS_NUM 13 + +/* The size of this structure must be smaller than or equal to the size specified by OS_TSK_STACK_ALIGN (16 bytes). */ +typedef struct { +#if !defined(LOSCFG_ARCH_FPU_DISABLE) + UINT64 D[FP_REGS_NUM]; /* D0-D31 */ + UINT32 regFPSCR; /* FPSCR */ + UINT32 regFPEXC; /* FPEXC */ +#endif + UINT32 resved; /* It's stack 8 aligned */ + UINT32 regPSR; + UINT32 R[GEN_REGS_NUM]; /* R0-R12 */ + UINT32 SP; /* R13 */ + UINT32 LR; /* R14 */ + UINT32 PC; /* R15 */ +} TaskContext; + +typedef struct { +#if !defined(LOSCFG_ARCH_FPU_DISABLE) + UINT64 D[FP_REGS_NUM]; /* D0-D31 */ + UINT32 regFPSCR; /* FPSCR */ + UINT32 regFPEXC; /* FPEXC */ +#endif + UINT32 resved; + TASK_IRQ_CONTEXT +} TaskIrqContext; + +/* + * Description : task stack initialization + * Input : taskID -- task ID + * stackSize -- task stack size + * topStack -- stack top of task (low address) + * Return : pointer to the task context + */ +extern VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag); +extern VOID OsUserCloneParentStack(LosTaskCB *childTaskCB, LosTaskCB *parentTaskCB); +extern VOID OsUserTaskStackInit(TaskContext *context, TSK_ENTRY_FUNC taskEntry, UINTPTR stack); +extern void arm_clean_cache_range(UINTPTR start, UINTPTR end); +extern void arm_inv_cache_range(UINTPTR start, UINTPTR end); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_HW_PRI_H */ diff --git a/arch/arm/arm/src/include/los_hwi_pri.h b/arch/arm/arm/src/include/los_hwi_pri.h new file mode 100755 index 00000000..ea1726b6 --- /dev/null +++ b/arch/arm/arm/src/include/los_hwi_pri.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_HWI_PRI_H +#define _LOS_HWI_PRI_H + +#include "los_hwi.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/** + * @ingroup los_hwi + * The hwi form does not contain exceptions for Aarch32 + */ +#define OS_HWI_FORM_EXC_NUM 0 +#if OS_HWI_FORM_EXC_NUM != 0 +#error "OS_HWI_FORM_EXC_NUM must be zero" +#endif + +#ifdef LOSCFG_NO_SHARED_IRQ +#define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pfnHook != NULL) +#else +#define HWI_IS_REGISTED(num) ((&g_hwiForm[num])->pstNext != NULL) +#endif +extern VOID OsHwiInit(VOID); +extern VOID OsIncHwiFormCnt(UINT32 index); +extern UINT32 OsGetHwiFormCnt(UINT32 index); +extern CHAR *OsGetHwiFormName(UINT32 index); +extern VOID OsInterrupt(UINT32 intNum); +extern VOID SyscallHandleInit(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif /* _LOS_HWI_PRI_H */ diff --git a/arch/arm/arm/src/jmp.S b/arch/arm/arm/src/jmp.S new file mode 100755 index 00000000..209b4e8a --- /dev/null +++ b/arch/arm/arm/src/jmp.S @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "asm.h" + +FUNCTION(longjmp) + ldmfd r0,{r4-r12} + add r0,#(4 * 9) + ldr r13,[r0] + add r0,#4 + ldr r14,[r0] + cmp r1,#0 + moveq r1,#1 + mov r0,r1 + mov pc,lr + +FUNCTION(setjmp) + stmea r0,{r4-r12} + add r0,#(4 * 9) + str r13,[r0] + add r0,#4 + str r14,[r0] + mov r0,#0 + mov pc,lr diff --git a/arch/arm/arm/src/los_arch_mmu.c b/arch/arm/arm/src/los_arch_mmu.c new file mode 100755 index 00000000..7d7cf935 --- /dev/null +++ b/arch/arm/arm/src/los_arch_mmu.c @@ -0,0 +1,882 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_arch_mmu architecture mmu + * @ingroup kernel + */ + +#include "los_arch_mmu.h" +#include "los_asid.h" +#include "los_pte_ops.h" +#include "los_tlb_v6.h" +#include "los_printf.h" +#include "los_vm_phys.h" +#include "los_vm_common.h" +#include "los_vm_map.h" +#include "los_vm_boot.h" +#include "los_mmu_descriptor_v6.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \ + __attribute__((section(".bss.prebss.translation_table"))) UINT8 \ + g_firstPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS]; +#if (LOSCFG_KERNEL_SMP == YES) +__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS))) \ + __attribute__((section(".bss.prebss.translation_table"))) UINT8 \ + g_tempPageTable[MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS]; +UINT8 *g_mmuJumpPageTable = g_tempPageTable; +#else +extern CHAR __mmu_ttlb_begin; /* defined in .ld script */ +UINT8 *g_mmuJumpPageTable = (UINT8 *)&__mmu_ttlb_begin; /* temp page table, this is only used when system power up */ +#endif + +STATIC INLINE PTE_T *OsGetPte2BasePtr(PTE_T pte1) +{ + PADDR_T pa = MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(pte1); + return LOS_PaddrToKVaddr(pa); +} + +STATIC INLINE UINT32 OsUnmapL1Invalid(vaddr_t *vaddr, UINT32 *count) +{ + UINT32 unmapCount; + + unmapCount = MIN2((MMU_DESCRIPTOR_L1_SMALL_SIZE - (*vaddr % MMU_DESCRIPTOR_L1_SMALL_SIZE)) >> + MMU_DESCRIPTOR_L2_SMALL_SHIFT, *count); + *vaddr += unmapCount << MMU_DESCRIPTOR_L2_SMALL_SHIFT; + *count -= unmapCount; + + return unmapCount; +} + +STATIC INT32 OsMapParamCheck(UINT32 flags, VADDR_T vaddr, PADDR_T paddr) +{ +#if !WITH_ARCH_MMU_PICK_SPOT + if (flags & VM_MAP_REGION_FLAG_NS) { + /* WITH_ARCH_MMU_PICK_SPOT is required to support NS memory */ + LOS_Panic("NS mem is not supported\n"); + } +#endif + + if (!(flags & VM_MAP_REGION_FLAG_PERM_READ)) { + VM_ERR("miss read flag"); + return LOS_ERRNO_VM_INVALID_ARGS; + } + + /* paddr and vaddr must be aligned */ + if (!MMU_DESCRIPTOR_IS_L2_SIZE_ALIGNED(vaddr) || !MMU_DESCRIPTOR_IS_L2_SIZE_ALIGNED(paddr)) { + return LOS_ERRNO_VM_INVALID_ARGS; + } + + return 0; +} + +STATIC VOID OsCvtPte2AttsToFlags(PTE_T l1Entry, PTE_T l2Entry, UINT32 *flags) +{ + *flags = 0; + /* NS flag is only present on L1 entry */ + if (l1Entry & MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE) { + *flags |= VM_MAP_REGION_FLAG_NS; + } + + switch (l2Entry & MMU_DESCRIPTOR_L2_TEX_TYPE_MASK) { + case MMU_DESCRIPTOR_L2_TYPE_STRONGLY_ORDERED: + *flags |= VM_MAP_REGION_FLAG_UNCACHED; + break; + case MMU_DESCRIPTOR_L2_TYPE_DEVICE_SHARED: + case MMU_DESCRIPTOR_L2_TYPE_DEVICE_NON_SHARED: + *flags |= VM_MAP_REGION_FLAG_UNCACHED_DEVICE; + break; + default: + break; + } + + *flags |= VM_MAP_REGION_FLAG_PERM_READ; + + switch (l2Entry & MMU_DESCRIPTOR_L2_AP_MASK) { + case MMU_DESCRIPTOR_L2_AP_P_RO_U_NA: + break; + case MMU_DESCRIPTOR_L2_AP_P_RW_U_NA: + *flags |= VM_MAP_REGION_FLAG_PERM_WRITE; + break; + case MMU_DESCRIPTOR_L2_AP_P_RO_U_RO: + *flags |= VM_MAP_REGION_FLAG_PERM_USER; + break; + case MMU_DESCRIPTOR_L2_AP_P_RW_U_RW: + *flags |= VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE; + break; + default: + break; + } + if ((l2Entry & MMU_DESCRIPTOR_L2_TYPE_MASK) != MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE_XN) { + *flags |= VM_MAP_REGION_FLAG_PERM_EXECUTE; + } +} + +STATIC VOID OsPutL2Table(const LosArchMmu *archMmu, UINT32 l1Index, paddr_t l2Paddr) +{ + LosVmPage *vmPage = NULL; + UINT32 index; + PTE_T ttEntry; + /* check if any l1 entry points to this l2 table */ + for (index = 0; index < MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE; index++) { + ttEntry = archMmu->virtTtb[ROUNDDOWN(l1Index, MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE) + index]; + if ((ttEntry & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE) { + return; + } + } + /* we can free this l2 table */ + vmPage = LOS_VmPageGet(l2Paddr); + if (vmPage == NULL) { + LOS_Panic("bad page table paddr %#x\n", l2Paddr); + return; + } + + LOS_ListDelete(&vmPage->node); + LOS_PhysPageFree(vmPage); +} + +STATIC VOID OsTryUnmapL1PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 scanIndex, UINT32 scanCount) +{ + /* + * Check if all pages related to this l1 entry are deallocated. + * We only need to check pages that we did not clear above starting + * from page_idx and wrapped around SECTION. + */ + UINT32 l1Index; + PTE_T l1Entry; + PTE_T *pte2BasePtr = NULL; + + pte2BasePtr = OsGetPte2BasePtr(OsGetPte1(archMmu->virtTtb, vaddr)); + if (pte2BasePtr == NULL) { + VM_ERR("pte2 base ptr is NULL"); + return; + } + + while (scanCount) { + if (scanIndex == MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) { + scanIndex = 0; + } + if (pte2BasePtr[scanIndex++]) { + break; + } + scanCount--; + } + + if (!scanCount) { + l1Index = OsGetPte1Index(vaddr); + l1Entry = archMmu->virtTtb[l1Index]; + /* we can kill l1 entry */ + OsClearPte1(&archMmu->virtTtb[l1Index]); + OsArmInvalidateTlbMvaNoBarrier(l1Index << MMU_DESCRIPTOR_L1_SMALL_SHIFT); + + /* try to free l2 page itself */ + OsPutL2Table(archMmu, l1Index, MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(l1Entry)); + } +} + +/* convert user level mmu flags to L1 descriptors flags */ +STATIC UINT32 OsCvtSecFlagsToAttrs(UINT32 flags) +{ + UINT32 mmuFlags = MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT; + switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) { + case VM_MAP_REGION_FLAG_CACHED: + mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_NORMAL_WRITE_BACK_ALLOCATE; +#if (LOSCFG_KERNEL_SMP == YES) + mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_SHAREABLE; +#endif + break; + case VM_MAP_REGION_FLAG_WRITE_COMBINING: + case VM_MAP_REGION_FLAG_UNCACHED: + mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED; + break; + case VM_MAP_REGION_FLAG_UNCACHED_DEVICE: + mmuFlags |= MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED; + break; + default: + return LOS_ERRNO_VM_INVALID_ARGS; + } + + switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE)) { + case 0: + mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RO_U_NA; + break; + case VM_MAP_REGION_FLAG_PERM_WRITE: + mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RW_U_NA; + break; + case VM_MAP_REGION_FLAG_PERM_USER: + mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RO_U_RO; + break; + case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE: + mmuFlags |= MMU_DESCRIPTOR_L1_AP_P_RW_U_RW; + break; + default: + break; + } + + if (!(flags & VM_MAP_REGION_FLAG_PERM_EXECUTE)) { + mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_XN; + } + + if (flags & VM_MAP_REGION_FLAG_NS) { + mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_NON_SECURE; + } + + if (flags & VM_MAP_REGION_FLAG_PERM_USER) { + mmuFlags |= MMU_DESCRIPTOR_L1_SECTION_NON_GLOBAL; + } + + return mmuFlags; +} + +STATIC VOID OsCvtSecAttsToFlags(PTE_T l1Entry, UINT32 *flags) +{ + *flags = 0; + if (l1Entry & MMU_DESCRIPTOR_L1_SECTION_NON_SECURE) { + *flags |= VM_MAP_REGION_FLAG_NS; + } + + switch (l1Entry & MMU_DESCRIPTOR_L1_TEX_TYPE_MASK) { + case MMU_DESCRIPTOR_L1_TYPE_STRONGLY_ORDERED: + *flags |= VM_MAP_REGION_FLAG_UNCACHED; + break; + case MMU_DESCRIPTOR_L1_TYPE_DEVICE_SHARED: + case MMU_DESCRIPTOR_L1_TYPE_DEVICE_NON_SHARED: + *flags |= VM_MAP_REGION_FLAG_UNCACHED_DEVICE; + break; + default: + break; + } + + *flags |= VM_MAP_REGION_FLAG_PERM_READ; + + switch (l1Entry & MMU_DESCRIPTOR_L1_AP_MASK) { + case MMU_DESCRIPTOR_L1_AP_P_RO_U_NA: + break; + case MMU_DESCRIPTOR_L1_AP_P_RW_U_NA: + *flags |= VM_MAP_REGION_FLAG_PERM_WRITE; + break; + case MMU_DESCRIPTOR_L1_AP_P_RO_U_RO: + *flags |= VM_MAP_REGION_FLAG_PERM_USER; + break; + case MMU_DESCRIPTOR_L1_AP_P_RW_U_RW: + *flags |= VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE; + break; + default: + break; + } + + if (!(l1Entry & MMU_DESCRIPTOR_L1_SECTION_XN)) { + *flags |= VM_MAP_REGION_FLAG_PERM_EXECUTE; + } +} + +STATIC UINT32 OsUnmapL2PTE(const LosArchMmu *archMmu, vaddr_t vaddr, UINT32 *count) +{ + UINT32 unmapCount; + UINT32 pte2Index; + PTE_T *pte2BasePtr = NULL; + + pte2BasePtr = OsGetPte2BasePtr(OsGetPte1((PTE_T *)archMmu->virtTtb, vaddr)); + if (pte2BasePtr == NULL) { + LOS_Panic("%s %d, pte2 base ptr is NULL\n", __FUNCTION__, __LINE__); + } + + pte2Index = OsGetPte2Index(vaddr); + unmapCount = MIN2(MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 - pte2Index, *count); + + /* unmap page run */ + OsClearPte2Continuous(&pte2BasePtr[pte2Index], unmapCount); + + /* invalidate tlb */ + OsArmInvalidateTlbMvaRangeNoBarrier(vaddr, unmapCount); + + *count -= unmapCount; + return unmapCount; +} + +STATIC UINT32 OsUnmapSection(LosArchMmu *archMmu, vaddr_t *vaddr, UINT32 *count) +{ + OsClearPte1(OsGetPte1Ptr((PTE_T *)archMmu->virtTtb, *vaddr)); + OsArmInvalidateTlbMvaNoBarrier(*vaddr); + + *vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE; + *count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1; + + return MMU_DESCRIPTOR_L2_NUMBERS_PER_L1; +} + + +BOOL OsArchMmuInit(LosArchMmu *archMmu, VADDR_T *virtTtb) +{ + if (OsAllocAsid(&archMmu->asid) != LOS_OK) { + VM_ERR("alloc arch mmu asid failed"); + return FALSE; + } + + status_t retval = LOS_MuxInit(&archMmu->mtx, NULL); + if (retval != LOS_OK) { + VM_ERR("Create mutex for arch mmu failed, status: %d", retval); + return FALSE; + } + + LOS_ListInit(&archMmu->ptList); + archMmu->virtTtb = virtTtb; + archMmu->physTtb = (VADDR_T)(UINTPTR)virtTtb - KERNEL_ASPACE_BASE + SYS_MEM_BASE; + return TRUE; +} + +STATUS_T LOS_ArchMmuQuery(const LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T *paddr, UINT32 *flags) +{ + PTE_T l1Entry = OsGetPte1(archMmu->virtTtb, vaddr); + PTE_T l2Entry; + PTE_T* l2Base = NULL; + + if (OsIsPte1Invalid(l1Entry)) { + return LOS_ERRNO_VM_NOT_FOUND; + } else if (OsIsPte1Section(l1Entry)) { + if (paddr != NULL) { + *paddr = MMU_DESCRIPTOR_L1_SECTION_ADDR(l1Entry) + (vaddr & (MMU_DESCRIPTOR_L1_SMALL_SIZE - 1)); + } + + if (flags != NULL) { + OsCvtSecAttsToFlags(l1Entry, flags); + } + } else if (OsIsPte1PageTable(l1Entry)) { + l2Base = OsGetPte2BasePtr(l1Entry); + if (l2Base == NULL) { + return LOS_ERRNO_VM_NOT_FOUND; + } + l2Entry = OsGetPte2(l2Base, vaddr); + if (OsIsPte2SmallPage(l2Entry) || OsIsPte2SmallPageXN(l2Entry)) { + if (paddr != NULL) { + *paddr = MMU_DESCRIPTOR_L2_SMALL_PAGE_ADDR(l2Entry) + (vaddr & (MMU_DESCRIPTOR_L2_SMALL_SIZE - 1)); + } + + if (flags != NULL) { + OsCvtPte2AttsToFlags(l1Entry, l2Entry, flags); + } + } else if (OsIsPte2LargePage(l2Entry)) { + LOS_Panic("%s %d, large page unimplemented\n", __FUNCTION__, __LINE__); + } else { + return LOS_ERRNO_VM_NOT_FOUND; + } + } + + return LOS_OK; +} + +STATUS_T LOS_ArchMmuUnmap(LosArchMmu *archMmu, VADDR_T vaddr, size_t count) +{ + PTE_T l1Entry; + INT32 unmapped = 0; + UINT32 unmapCount = 0; + + while (count > 0) { + l1Entry = OsGetPte1(archMmu->virtTtb, vaddr); + if (OsIsPte1Invalid(l1Entry)) { + unmapCount = OsUnmapL1Invalid(&vaddr, &count); + } else if (OsIsPte1Section(l1Entry)) { + if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(vaddr) && count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) { + unmapCount = OsUnmapSection(archMmu, &vaddr, &count); + } else { + LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__); + } + } else if (OsIsPte1PageTable(l1Entry)) { + unmapCount = OsUnmapL2PTE(archMmu, vaddr, &count); + OsTryUnmapL1PTE(archMmu, vaddr, OsGetPte2Index(vaddr) + unmapCount, + MMU_DESCRIPTOR_L2_NUMBERS_PER_L1 - unmapCount); + vaddr += unmapCount << MMU_DESCRIPTOR_L2_SMALL_SHIFT; + } else { + LOS_Panic("%s %d, unimplemented\n", __FUNCTION__, __LINE__); + } + unmapped += unmapCount; + } + OsArmInvalidateTlbBarrier(); + return unmapped; +} + +STATIC UINT32 OsMapSection(const LosArchMmu *archMmu, UINT32 flags, VADDR_T *vaddr, + PADDR_T *paddr, UINT32 *count) +{ + UINT32 mmuFlags = 0; + + mmuFlags |= OsCvtSecFlagsToAttrs(flags); + OsSavePte1(OsGetPte1Ptr(archMmu->virtTtb, *vaddr), + OsTruncPte1(*paddr) | mmuFlags | MMU_DESCRIPTOR_L1_TYPE_SECTION); + *count -= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1; + *vaddr += MMU_DESCRIPTOR_L1_SMALL_SIZE; + *paddr += MMU_DESCRIPTOR_L1_SMALL_SIZE; + + return MMU_DESCRIPTOR_L2_NUMBERS_PER_L1; +} + +STATIC STATUS_T OsGetL2Table(LosArchMmu *archMmu, UINT32 l1Index, paddr_t *ppa) +{ + UINT32 index; + PTE_T ttEntry; + VADDR_T *kvaddr = NULL; + LosVmPage *vmPage = NULL; + UINT32 l2Offset = (MMU_DESCRIPTOR_L2_SMALL_SIZE / MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE) * + (l1Index & (MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE - 1)); + /* lookup an existing l2 page table */ + for (index = 0; index < MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE; index++) { + ttEntry = archMmu->virtTtb[ROUNDDOWN(l1Index, MMU_DESCRIPTOR_L1_SMALL_L2_TABLES_PER_PAGE) + index]; + if ((ttEntry & MMU_DESCRIPTOR_L1_TYPE_MASK) == MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE) { + *ppa = (PADDR_T)ROUNDDOWN(MMU_DESCRIPTOR_L1_PAGE_TABLE_ADDR(ttEntry), MMU_DESCRIPTOR_L2_SMALL_SIZE) + + l2Offset; + return LOS_OK; + } + } + + /* not found: allocate one (paddr) */ + vmPage = LOS_PhysPageAlloc(); + if (vmPage == NULL) { + VM_ERR("have no memory to save l2 page"); + return LOS_ERRNO_VM_NO_MEMORY; + } + LOS_ListAdd(&archMmu->ptList, &vmPage->node); + kvaddr = OsVmPageToVaddr(vmPage); + (VOID)memset_s(kvaddr, MMU_DESCRIPTOR_L2_SMALL_SIZE, 0, MMU_DESCRIPTOR_L2_SMALL_SIZE); + + /* get physical address */ + *ppa = LOS_PaddrQuery(kvaddr) + l2Offset; + return LOS_OK; +} + +STATIC VOID OsMapL1PTE(LosArchMmu *archMmu, PTE_T *pte1Ptr, vaddr_t vaddr, UINT32 flags) +{ + paddr_t pte2Base = 0; + + if (OsGetL2Table(archMmu, OsGetPte1Index(vaddr), &pte2Base) != LOS_OK) { + LOS_Panic("%s %d, failed to allocate pagetable\n", __FUNCTION__, __LINE__); + } + + *pte1Ptr = pte2Base | MMU_DESCRIPTOR_L1_TYPE_PAGE_TABLE; + if (flags & VM_MAP_REGION_FLAG_NS) { + *pte1Ptr |= MMU_DESCRIPTOR_L1_PAGETABLE_NON_SECURE; + } + *pte1Ptr &= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_MASK; + *pte1Ptr |= MMU_DESCRIPTOR_L1_SMALL_DOMAIN_CLIENT; // use client AP + OsSavePte1(OsGetPte1Ptr(archMmu->virtTtb, vaddr), *pte1Ptr); +} + +/* convert user level mmu flags to L2 descriptors flags */ +STATIC UINT32 OsCvtPte2FlagsToAttrs(uint32_t flags) +{ + UINT32 mmuFlags = 0; + + switch (flags & VM_MAP_REGION_FLAG_CACHE_MASK) { + case VM_MAP_REGION_FLAG_CACHED: +#if (LOSCFG_KERNEL_SMP == YES) + mmuFlags |= MMU_DESCRIPTOR_L2_SHAREABLE; +#endif + mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_NORMAL_WRITE_BACK_ALLOCATE; + break; + case VM_MAP_REGION_FLAG_WRITE_COMBINING: + case VM_MAP_REGION_FLAG_UNCACHED: + mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_STRONGLY_ORDERED; + break; + case VM_MAP_REGION_FLAG_UNCACHED_DEVICE: + mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_DEVICE_SHARED; + break; + default: + return LOS_ERRNO_VM_INVALID_ARGS; + } + + switch (flags & (VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE)) { + case 0: + mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RO_U_NA; + break; + case VM_MAP_REGION_FLAG_PERM_WRITE: + mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RW_U_NA; + break; + case VM_MAP_REGION_FLAG_PERM_USER: + mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RO_U_RO; + break; + case VM_MAP_REGION_FLAG_PERM_USER | VM_MAP_REGION_FLAG_PERM_WRITE: + mmuFlags |= MMU_DESCRIPTOR_L2_AP_P_RW_U_RW; + break; + default: + break; + } + + if (!(flags & VM_MAP_REGION_FLAG_PERM_EXECUTE)) { + mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE_XN; + } else { + mmuFlags |= MMU_DESCRIPTOR_L2_TYPE_SMALL_PAGE; + } + + if (flags & VM_MAP_REGION_FLAG_PERM_USER) { + mmuFlags |= MMU_DESCRIPTOR_L2_NON_GLOBAL; + } + + return mmuFlags; +} + +STATIC UINT32 OsMapL2PageContinous(PTE_T pte1, UINT32 flags, VADDR_T *vaddr, PADDR_T *paddr, UINT32 *count) +{ + PTE_T *pte2BasePtr = NULL; + UINT32 archFlags; + UINT32 saveCounts; + + pte2BasePtr = OsGetPte2BasePtr(pte1); + if (pte2BasePtr == NULL) { + LOS_Panic("%s %d, pte1 %#x error\n", __FUNCTION__, __LINE__, pte1); + } + + /* compute the arch flags for L2 4K pages */ + archFlags = OsCvtPte2FlagsToAttrs(flags); + saveCounts = OsSavePte2Continuous(pte2BasePtr, OsGetPte2Index(*vaddr), *paddr | archFlags, *count); + *paddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT); + *vaddr += (saveCounts << MMU_DESCRIPTOR_L2_SMALL_SHIFT); + *count -= saveCounts; + return saveCounts; +} + +status_t LOS_ArchMmuMap(LosArchMmu *archMmu, VADDR_T vaddr, PADDR_T paddr, size_t count, UINT32 flags) +{ + PTE_T l1Entry; + UINT32 saveCounts = 0; + INT32 mapped = 0; + INT32 checkRst; + + checkRst = OsMapParamCheck(flags, vaddr, paddr); + if (checkRst < 0) { + return checkRst; + } + + /* see what kind of mapping we can use */ + while (count > 0) { + if (MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(vaddr) && + MMU_DESCRIPTOR_IS_L1_SIZE_ALIGNED(paddr) && + count >= MMU_DESCRIPTOR_L2_NUMBERS_PER_L1) { + /* compute the arch flags for L1 sections cache, r ,w ,x, domain and type */ + saveCounts = OsMapSection(archMmu, flags, &vaddr, &paddr, &count); + } else { + /* have to use a L2 mapping, we only allocate 4KB for L1, support 0 ~ 1GB */ + l1Entry = OsGetPte1(archMmu->virtTtb, vaddr); + if (OsIsPte1Invalid(l1Entry)) { + OsMapL1PTE(archMmu, &l1Entry, vaddr, flags); + saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count); + } else if (OsIsPte1PageTable(l1Entry)) { + saveCounts = OsMapL2PageContinous(l1Entry, flags, &vaddr, &paddr, &count); + } else { + LOS_Panic("%s %d, unimplemented tt_entry %x\n", __FUNCTION__, __LINE__, l1Entry); + } + } + mapped += saveCounts; + } + + return mapped; +} + +STATUS_T LOS_ArchMmuChangeProt(LosArchMmu *archMmu, VADDR_T vaddr, size_t count, UINT32 flags) +{ + STATUS_T status; + PADDR_T paddr = 0; + + if ((archMmu == NULL) || (vaddr == 0) || (count == 0)) { + VM_ERR("invalid args: archMmu %p, vaddr %p, count %d", archMmu, vaddr, count); + return LOS_NOK; + } + + while (count > 0) { + count--; + status = LOS_ArchMmuQuery(archMmu, vaddr, &paddr, NULL); + if (status != LOS_OK) { + vaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE; + continue; + } + + status = LOS_ArchMmuUnmap(archMmu, vaddr, 1); + if (status < 0) { + VM_ERR("invalid args:aspace %p, vaddr %p, count %d", + __FUNCTION__, __LINE__, archMmu, vaddr, count); + return LOS_NOK; + } + + status = LOS_ArchMmuMap(archMmu, vaddr, paddr, 1, flags); + if (status < 0) { + VM_ERR("invalid args:aspace %p, vaddr %p, count %d", + archMmu, vaddr, count); + return LOS_NOK; + } + vaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE; + } + return LOS_OK; +} + +STATUS_T LOS_ArchMmuMove(LosArchMmu *archMmu, VADDR_T oldVaddr, VADDR_T newVaddr, size_t count, UINT32 flags) +{ + STATUS_T status; + PADDR_T paddr = 0; + + if ((archMmu == NULL) || (oldVaddr == 0) || (newVaddr == 0) || (count == 0)) { + VM_ERR("invalid args: archMmu %p, oldVaddr %p, newVddr %p, count %d", + archMmu, oldVaddr, newVaddr, count); + return LOS_NOK; + } + + while (count > 0) { + count--; + status = LOS_ArchMmuQuery(archMmu, oldVaddr, &paddr, NULL); + if (status != LOS_OK) { + oldVaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE; + newVaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE; + continue; + } + // we need to clear the mapping here and remain the phy page. + status = LOS_ArchMmuUnmap(archMmu, oldVaddr, 1); + if (status < 0) { + VM_ERR("invalid args: archMmu %p, vaddr %p, count %d", + archMmu, oldVaddr, count); + return LOS_NOK; + } + + status = LOS_ArchMmuMap(archMmu, newVaddr, paddr, 1, flags); + if (status < 0) { + VM_ERR("invalid args:archMmu %p, old_vaddr %p, new_addr %p, count %d", + archMmu, oldVaddr, newVaddr, count); + return LOS_NOK; + } + oldVaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE; + newVaddr += MMU_DESCRIPTOR_L2_SMALL_SIZE; + } + + return LOS_OK; +} + +VOID LOS_ArchMmuContextSwitch(LosArchMmu *archMmu) +{ + UINT32 ttbr; + UINT32 ttbcr = OsArmReadTtbcr(); + if (archMmu) { + ttbr = MMU_TTBRx_FLAGS | (archMmu->physTtb); + /* enable TTBR0 */ + ttbcr &= ~MMU_DESCRIPTOR_TTBCR_PD0; + } else { + ttbr = 0; + /* disable TTBR0 */ + ttbcr |= MMU_DESCRIPTOR_TTBCR_PD0; + } + + /* from armv7a arm B3.10.4, we should do synchronization changes of ASID and TTBR. */ + OsArmWriteContextidr(LOS_GetKVmSpace()->archMmu.asid); + ISB; + OsArmWriteTtbr0(ttbr); + ISB; + OsArmWriteTtbcr(ttbcr); + ISB; + if (archMmu) { + OsArmWriteContextidr(archMmu->asid); + ISB; + } +} + +STATUS_T LOS_ArchMmuDestroy(LosArchMmu *archMmu) +{ + LosVmPage *page = NULL; + /* free all of the pages allocated in archMmu->ptList */ + while ((page = LOS_ListRemoveHeadType(&archMmu->ptList, LosVmPage, node)) != NULL) { + LOS_PhysPageFree(page); + } + + OsArmWriteTlbiasid(archMmu->asid); + OsFreeAsid(archMmu->asid); + (VOID)LOS_MuxDestroy(&archMmu->mtx); + return LOS_OK; +} + +STATIC VOID OsSwitchTmpTTB(VOID) +{ + PTE_T *tmpTtbase = NULL; + errno_t err; + LosVmSpace *kSpace = LOS_GetKVmSpace(); + + /* ttbr address should be 16KByte align */ + tmpTtbase = LOS_MemAllocAlign(m_aucSysMem0, MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS, + MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS); + if (tmpTtbase == NULL) { + VM_ERR("memory alloc failed"); + return; + } + + kSpace->archMmu.virtTtb = tmpTtbase; + err = memcpy_s(kSpace->archMmu.virtTtb, MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS, + g_firstPageTable, MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS); + if (err != EOK) { + (VOID)LOS_MemFree(m_aucSysMem0, tmpTtbase); + kSpace->archMmu.virtTtb = (VADDR_T *)g_firstPageTable; + VM_ERR("memcpy failed, errno: %d", err); + return; + } + kSpace->archMmu.physTtb = LOS_PaddrQuery(kSpace->archMmu.virtTtb); + OsArmWriteTtbr0(kSpace->archMmu.physTtb | MMU_TTBRx_FLAGS); + ISB; +} + +VADDR_T *OsGFirstTableGet() +{ + return (VADDR_T *)g_firstPageTable; +} + +STATIC VOID OsSetKSectionAttr(VOID) +{ + /* every section should be page aligned */ + UINTPTR textStart = (UINTPTR)&__text_start; + UINTPTR textEnd = (UINTPTR)&__text_end; + UINTPTR rodataStart = (UINTPTR)&__rodata_start; + UINTPTR rodataEnd = (UINTPTR)&__rodata_end; + UINTPTR ramDataStart = (UINTPTR)&__ram_data_start; + UINTPTR bssEnd = (UINTPTR)&__bss_end; + UINT32 bssEndBoundary = ROUNDUP(bssEnd, MB); + LosArchMmuInitMapping mmuKernelMappings[] = { + { + .phys = SYS_MEM_BASE + textStart - KERNEL_VMM_BASE, + .virt = textStart, + .size = ROUNDUP(textEnd - textStart, MMU_DESCRIPTOR_L2_SMALL_SIZE), + .flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_EXECUTE, + .name = "kernel_text" + }, + { + .phys = SYS_MEM_BASE + rodataStart - KERNEL_VMM_BASE, + .virt = rodataStart, + .size = ROUNDUP(rodataEnd - rodataStart, MMU_DESCRIPTOR_L2_SMALL_SIZE), + .flags = VM_MAP_REGION_FLAG_PERM_READ, + .name = "kernel_rodata" + }, + { + .phys = SYS_MEM_BASE + ramDataStart - KERNEL_VMM_BASE, + .virt = ramDataStart, + .size = ROUNDUP(bssEndBoundary - ramDataStart, MMU_DESCRIPTOR_L2_SMALL_SIZE), + .flags = VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE, + .name = "kernel_data_bss" + } + }; + LosVmSpace *kSpace = LOS_GetKVmSpace(); + status_t status; + UINT32 length; + paddr_t oldTtPhyBase; + int i; + LosArchMmuInitMapping *kernelMap = NULL; + UINT32 kmallocLength; + + /* use second-level mapping of default READ and WRITE */ + kSpace->archMmu.virtTtb = (PTE_T *)g_firstPageTable; + kSpace->archMmu.physTtb = LOS_PaddrQuery(kSpace->archMmu.virtTtb); + status = LOS_ArchMmuUnmap(&kSpace->archMmu, KERNEL_VMM_BASE, + (bssEndBoundary - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT); + if (status != ((bssEndBoundary - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) { + VM_ERR("unmap failed, status: %d", status); + return; + } + + status = LOS_ArchMmuMap(&kSpace->archMmu, KERNEL_VMM_BASE, SYS_MEM_BASE, + (textStart - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT, + VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE | + VM_MAP_REGION_FLAG_PERM_EXECUTE); + if (status != ((textStart - KERNEL_VMM_BASE) >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) { + VM_ERR("mmap failed, status: %d", status); + return; + } + + length = sizeof(mmuKernelMappings) / sizeof(LosArchMmuInitMapping); + for (i = 0; i < length; i++) { + kernelMap = &mmuKernelMappings[i]; + status = LOS_ArchMmuMap(&kSpace->archMmu, kernelMap->virt, kernelMap->phys, + kernelMap->size >> MMU_DESCRIPTOR_L2_SMALL_SHIFT, kernelMap->flags); + if (status != (kernelMap->size >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) { + VM_ERR("mmap failed, status: %d", status); + return; + } + LOS_VmSpaceReserve(kSpace, kernelMap->size, kernelMap->virt); + } + + kmallocLength = KERNEL_VMM_BASE + SYS_MEM_SIZE_DEFAULT - bssEndBoundary; + status = LOS_ArchMmuMap(&kSpace->archMmu, bssEndBoundary, + SYS_MEM_BASE + bssEndBoundary - KERNEL_VMM_BASE, + kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT, + VM_MAP_REGION_FLAG_PERM_READ | VM_MAP_REGION_FLAG_PERM_WRITE); + if (status != (kmallocLength >> MMU_DESCRIPTOR_L2_SMALL_SHIFT)) { + VM_ERR("unmap failed, status: %d", status); + return; + } + LOS_VmSpaceReserve(kSpace, kmallocLength, bssEndBoundary); + + /* we need free tmp ttbase */ + oldTtPhyBase = OsArmReadTtbr0(); + oldTtPhyBase = oldTtPhyBase & MMU_DESCRIPTOR_L2_SMALL_FRAME; + OsArmWriteTtbr0(kSpace->archMmu.physTtb | MMU_TTBRx_FLAGS); + ISB; + + /* we changed page table entry, so we need to clean TLB here */ + OsCleanTLB(); + + (VOID)LOS_MemFree(m_aucSysMem0, (VOID *)(UINTPTR)(oldTtPhyBase - SYS_MEM_BASE + KERNEL_VMM_BASE)); +} + +/* disable TTBCR0 and set the split between TTBR0 and TTBR1 */ +VOID OsArchMmuInitPerCPU(VOID) +{ + UINT32 n = __builtin_clz(KERNEL_ASPACE_BASE) + 1; + UINT32 ttbcr = MMU_DESCRIPTOR_TTBCR_PD0 | n; + + OsArmWriteTtbr1(OsArmReadTtbr0()); + ISB; + OsArmWriteTtbcr(ttbcr); + ISB; + OsArmWriteTtbr0(0); + ISB; +} + +VOID OsInitMappingStartUp(VOID) +{ + OsArmInvalidateTlbBarrier(); + + OsSwitchTmpTTB(); + + OsSetKSectionAttr(); + + OsArchMmuInitPerCPU(); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + diff --git a/arch/arm/arm/src/los_asid.c b/arch/arm/arm/src/los_asid.c new file mode 100755 index 00000000..72b4d709 --- /dev/null +++ b/arch/arm/arm/src/los_asid.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_asid mmu address space id + * @ingroup kernel + */ + +#include "los_typedef.h" +#include "los_asid.h" +#include "los_spinlock.h" +#include "los_mmu_descriptor_v6.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +STATIC SPIN_LOCK_INIT(g_cpuAsidLock); +STATIC UINTPTR g_asidPool[BITMAP_NUM_WORDS(1UL << MMU_ARM_ASID_BITS)]; + +/* allocate and free asid */ +status_t OsAllocAsid(UINT32 *asid) +{ + UINT32 flags; + LOS_SpinLockSave(&g_cpuAsidLock, &flags); + UINT32 firstZeroBit = LOS_BitmapFfz(g_asidPool, 1UL << MMU_ARM_ASID_BITS); + if (firstZeroBit >= 0 && firstZeroBit < (1UL << MMU_ARM_ASID_BITS)) { + LOS_BitmapSetNBits(g_asidPool, firstZeroBit, 1); + *asid = firstZeroBit; + LOS_SpinUnlockRestore(&g_cpuAsidLock, flags); + return LOS_OK; + } + + LOS_SpinUnlockRestore(&g_cpuAsidLock, flags); + return firstZeroBit; +} + +VOID OsFreeAsid(UINT32 asid) +{ + UINT32 flags; + LOS_SpinLockSave(&g_cpuAsidLock, &flags); + LOS_BitmapClrNBits(g_asidPool, asid, 1); + LOS_SpinUnlockRestore(&g_cpuAsidLock, flags); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/arch/arm/arm/src/los_dispatch.S b/arch/arm/arm/src/los_dispatch.S new file mode 100755 index 00000000..add17d0f --- /dev/null +++ b/arch/arm/arm/src/los_dispatch.S @@ -0,0 +1,313 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "asm.h" +#include "arch_config.h" + +#ifdef LOSCFG_KERNEL_SMP_LOCKDEP + .extern OsLockDepCheckOut +#endif + .extern g_taskSpin + .extern g_percpu + .global OsStartToRun + .global OsTaskSchedule + .global OsIrqHandler + .global ArchSpinUnlock + .global OsSchedToUserSpinUnlock + + .equ OS_TASK_STATUS_RUNNING, 0x0010U + .equ OS_PERCPU_STRUCT_SIZE, 0x28U + .equ OS_PERCPU_TASK_LOCK_OFFSET, 0x14U + .fpu vfpv4 + +/* macros to align and unalign the stack on 8 byte boundary for ABI compliance */ +.macro STACK_ALIGN, reg + MOV \reg, sp + TST SP, #4 + SUBEQ SP, #4 + PUSH { \reg } +.endm + +.macro STACK_RESTORE, reg + POP { \reg } + MOV sp, \reg +.endm + +/* macros to save and restore fpu regs */ +.macro PUSH_FPU_REGS reg1 +#if !defined(LOSCFG_ARCH_FPU_DISABLE) + VMRS \reg1, FPEXC + PUSH {\reg1} + VMRS \reg1, FPSCR + PUSH {\reg1} +#if defined(LOSCFG_ARCH_FPU_VFP_D32) + VPUSH {D16-D31} +#endif + VPUSH {D0-D15} +#endif +.endm + +.macro POP_FPU_REGS reg1 +#if !defined(LOSCFG_ARCH_FPU_DISABLE) + VPOP {D0-D15} +#if defined(LOSCFG_ARCH_FPU_VFP_D32) + VPOP {D16-D31} +#endif + POP {\reg1} + VMSR FPSCR, \reg1 + POP {\reg1} + VMSR FPEXC, \reg1 +#endif +.endm + +/* R0: new task */ +OsStartToRun: + + MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) + + LDRH R1, [R0, #4] + ORR R1, #OS_TASK_STATUS_RUNNING + STRH R1, [R0, #4] + + /* R0 is new task, save it on tpidrprw */ + MCR p15, 0, R0, c13, c0, 4 + ISB + + VPUSH {S0} /* fpu */ + VPOP {S0} + VPUSH {D0} + VPOP {D0} + + B OsTaskContextLoad + +/* + * R0: new task + * R1: run task + */ +OsTaskSchedule: + MRS R2, CPSR + STMFD SP!, {LR} + STMFD SP!, {LR} + /* jump sp */ + SUB SP, SP, #4 + + /* push r0-r12*/ + STMFD SP!, {R0-R12} + STMFD SP!, {R2} + + /* 8 bytes stack align */ + SUB SP, SP, #4 + + /* save fpu registers */ + PUSH_FPU_REGS R2 + + /* store sp on running task */ + STR SP, [R1] + +OsTaskContextLoad: + /* clear the flag of ldrex */ + CLREX + + /* switch to new task's sp */ + LDR SP, [R0] + + /* restore fpu registers */ + POP_FPU_REGS R2 + + /* 8 bytes stack align */ + ADD SP, SP, #4 + + LDMFD SP!, {R0} + MOV R4, R0 + AND R0, R0, #CPSR_MASK_MODE + CMP R0, #CPSR_USER_MODE + BNE OsKernelTaskLoad + +#ifdef LOSCFG_KERNEL_SMP +#ifdef LOSCFG_KERNEL_SMP_LOCKDEP + /* 8 bytes stack align */ + SUB SP, SP, #4 + LDR R0, =g_taskSpin + BL OsLockDepCheckOut + ADD SP, SP, #4 +#endif + /* R0 = &g_taskSpin.rawLock */ + LDR R0, =g_taskSpin + BL ArchSpinUnlock + LDR R2, =g_percpu + MRC P15, 0, R3, C0, C0, 5 + UXTB R3, R3 + MOV R1, #OS_PERCPU_STRUCT_SIZE + MLA R3, R1, R3, R2 + MOV R2, #0 + STR R2, [R3, #OS_PERCPU_TASK_LOCK_OFFSET] +#endif + + MVN R3, #CPSR_INT_DISABLE + AND R4, R4, R3 + MSR SPSR_cxsf, R4 + + /* restore r0-r12, lr */ + LDMFD SP!, {R0-R12} + LDMFD SP, {R13, R14}^ + ADD SP, SP, #(2 * 4) + LDMFD SP!, {PC}^ + +OsKernelTaskLoad: + MSR SPSR_cxsf, R4 + /* restore r0-r12, lr */ + LDMFD SP!, {R0-R12} + ADD SP, SP, #4 + LDMFD SP!, {LR, PC}^ + +OsIrqHandler: + SUB LR, LR, #4 + + /* push r0-r3 to irq stack */ + STMFD SP, {R0-R3} + SUB R0, SP, #(4 * 4) + MRS R1, SPSR + MOV R2, LR + + /* disable irq, switch to svc mode */ + CPSID i, #0x13 + + /* push spsr and pc in svc stack */ + STMFD SP!, {R1, R2} + STMFD SP, {LR} + + AND R3, R1, #CPSR_MASK_MODE + CMP R3, #CPSR_USER_MODE + BNE OsIrqFromKernel + + /* push user sp, lr in svc stack */ + STMFD SP, {R13, R14}^ + +OsIrqFromKernel: + /* from svc not need save sp and lr */ + SUB SP, SP, #(2 * 4) + + /* pop r0-r3 form irq stack*/ + LDMFD R0, {R0-R3} + + /* push caller saved regs as trashed regs in svc stack */ + STMFD SP!, {R0-R3, R12} + + /* 8 bytes stack align */ + SUB SP, SP, #4 + + /* + * save fpu regs in case in case those been + * altered in interrupt handlers. + */ + PUSH_FPU_REGS R0 +#ifdef LOSCFG_IRQ_USE_STANDALONE_STACK + PUSH {R4} + MOV R4, SP + EXC_SP_SET __svc_stack_top, OS_EXC_SVC_STACK_SIZE, R1, R2 +#endif + + BLX HalIrqHandler + +#ifdef LOSCFG_IRQ_USE_STANDALONE_STACK + MOV SP, R4 + POP {R4} +#endif + + /* process pending signals */ + BL OsTaskProcSignal + + /* check if needs to schedule */ + CMP R0, #0 + BLNE OsSchedPreempt + + MOV R0,SP + MOV R1,R7 + BL OsSaveSignalContextIrq + + /* restore fpu regs */ + POP_FPU_REGS R0 + + ADD SP, SP, #4 + +OsIrqContextRestore: + LDR R0, [SP, #(4 * 7)] + MSR SPSR_cxsf, R0 + AND R0, R0, #CPSR_MASK_MODE + CMP R0, #CPSR_USER_MODE + + LDMFD SP!, {R0-R3, R12} + + BNE OsIrqContextRestoreToKernel + + /* load user sp and lr, and jump cpsr */ + LDMFD SP, {R13, R14}^ + ADD SP, SP, #(3 * 4) + + /* return to user mode */ + LDMFD SP!, {PC}^ + +OsIrqContextRestoreToKernel: + /* svc mode not load sp */ + ADD SP, SP, #4 + LDMFD SP!, {LR} + /* jump cpsr and return to svc mode */ + ADD SP, SP, #4 + LDMFD SP!, {PC}^ + +FUNCTION(ArchSpinLock) + mov r1, #1 +1: + ldrex r2, [r0] + cmp r2, #0 + wfene + strexeq r2, r1, [r0] + cmpeq r2, #0 + bne 1b + dmb + bx lr + +FUNCTION(ArchSpinTrylock) + mov r1, #1 + mov r2, r0 + ldrex r0, [r2] + cmp r0, #0 + strexeq r0, r1, [r2] + dmb + bx lr + +FUNCTION(ArchSpinUnlock) + mov r1, #0 + dmb + str r1, [r0] + dsb + sev + bx lr diff --git a/arch/arm/arm/src/los_exc.c b/arch/arm/arm/src/los_exc.c new file mode 100755 index 00000000..989cf2e3 --- /dev/null +++ b/arch/arm/arm/src/los_exc.c @@ -0,0 +1,1065 @@ +/* + * 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_exc.h" +#include "los_memory_pri.h" +#include "los_printf_pri.h" +#include "los_task_pri.h" +#include "los_hw_pri.h" +#ifdef LOSCFG_SHELL_EXCINFO +#include "los_excinfo_pri.h" +#endif +#ifdef LOSCFG_EXC_INTERACTION +#include "los_exc_interaction_pri.h" +#endif +#include "los_sys_stack_pri.h" +#include "los_stackinfo_pri.h" +#ifdef LOSCFG_COREDUMP +#include "los_coredump.h" +#endif +#ifdef LOSCFG_GDB +#include "gdb_int.h" +#endif +#include "los_mp.h" +#include "los_vm_map.h" +#include "los_vm_dump.h" +#include "los_arch_mmu.h" +#include "los_vm_phys.h" +#include "los_vm_fault.h" +#include "los_vm_common.h" +#include "arm.h" +#include "los_bitmap.h" +#include "los_process_pri.h" +#include "los_exc_pri.h" +#ifdef LOSCFG_FS_VFS +#include "console.h" +#endif + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define INVALID_CPUID 0xFFFF +#define OS_EXC_VMM_NO_REGION 0x0U +#define OS_EXC_VMM_ALL_REGION 0x1U + +STATIC UINTPTR g_minAddr; +STATIC UINTPTR g_maxAddr; +STATIC UINT32 g_currHandleExcCpuID = INVALID_CPUID; +VOID OsExcHook(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr); +UINT32 g_curNestCount[LOSCFG_KERNEL_CORE_NUM] = { 0 }; +BOOL g_excFromUserMode[LOSCFG_KERNEL_CORE_NUM]; +STATIC EXC_PROC_FUNC g_excHook = (EXC_PROC_FUNC)OsExcHook; +#if (LOSCFG_KERNEL_SMP == YES) +STATIC SPIN_LOCK_INIT(g_excSerializerSpin); +STATIC UINT32 g_currHandleExcPID = OS_INVALID_VALUE; +STATIC UINT32 g_nextExcWaitCpu = INVALID_CPUID; +#endif + +#define OS_MAX_BACKTRACE 15U +#define DUMPSIZE 128U +#define DUMPREGS 12U +#define INSTR_SET_MASK 0x01000020U +#define THUMB_INSTR_LEN 2U +#define ARM_INSTR_LEN 4U +#define POINTER_SIZE 4U +#define WNR_BIT 11U +#define FSR_FLAG_OFFSET_BIT 10U +#define FSR_BITS_BEGIN_BIT 3U + + +#define GET_FS(fsr) (((fsr) & 0xFU) | (((fsr) & (1U << 10)) >> 6)) +#define GET_WNR(dfsr) ((dfsr) & (1U << 11)) + +#define IS_VALID_ADDR(ptr) (((ptr) >= g_minAddr) && \ + ((ptr) <= g_maxAddr) && \ + (IS_ALIGNED((ptr), sizeof(CHAR *)))) + +STATIC const StackInfo g_excStack[] = { + { &__undef_stack, OS_EXC_UNDEF_STACK_SIZE, "udf_stack" }, + { &__abt_stack, OS_EXC_ABT_STACK_SIZE, "abt_stack" }, + { &__fiq_stack, OS_EXC_FIQ_STACK_SIZE, "fiq_stack" }, + { &__svc_stack, OS_EXC_SVC_STACK_SIZE, "svc_stack" }, + { &__irq_stack, OS_EXC_IRQ_STACK_SIZE, "irq_stack" }, + { &__exc_stack, OS_EXC_STACK_SIZE, "exc_stack" } +}; + +UINT32 OsGetSystemStatus(VOID) +{ + UINT32 flag; + UINT32 cpuID = g_currHandleExcCpuID; + + if (cpuID == INVALID_CPUID) { + flag = OS_SYSTEM_NORMAL; + } else if (cpuID == ArchCurrCpuid()) { + flag = OS_SYSTEM_EXC_CURR_CPU; + } else { + flag = OS_SYSTEM_EXC_OTHER_CPU; + } + + return flag; +} + +STATIC INT32 OsDecodeFS(UINT32 bitsFS) +{ + switch (bitsFS) { + case 0x05: /* 0b00101 */ + case 0x07: /* 0b00111 */ + PrintExcInfo("Translation fault, %s\n", (bitsFS & 0x2) ? "page" : "section"); + break; + case 0x09: /* 0b01001 */ + case 0x0b: /* 0b01011 */ + PrintExcInfo("Domain fault, %s\n", (bitsFS & 0x2) ? "page" : "section"); + break; + case 0x0d: /* 0b01101 */ + case 0x0f: /* 0b01111 */ + PrintExcInfo("Permission fault, %s\n", (bitsFS & 0x2) ? "page" : "section"); + break; + default: + PrintExcInfo("Unknown fault! FS:0x%x. " + "Check IFSR and DFSR in ARM Architecture Reference Manual.\n", + bitsFS); + break; + } + + return LOS_OK; +} + +STATIC INT32 OsDecodeInstructionFSR(UINT32 regIFSR) +{ + INT32 ret; + UINT32 bitsFS = GET_FS(regIFSR); /* FS bits[4]+[3:0] */ + + ret = OsDecodeFS(bitsFS); + return ret; +} + +STATIC INT32 OsDecodeDataFSR(UINT32 regDFSR) +{ + INT32 ret = 0; + UINT32 bitWnR = GET_WNR(regDFSR); /* WnR bit[11] */ + UINT32 bitsFS = GET_FS(regDFSR); /* FS bits[4]+[3:0] */ + + if (bitWnR) { + PrintExcInfo("Abort caused by a write instruction. "); + } else { + PrintExcInfo("Abort caused by a read instruction. "); + } + + if (bitsFS == 0x01) { /* 0b00001 */ + PrintExcInfo("Alignment fault.\n"); + return ret; + } + ret = OsDecodeFS(bitsFS); + return ret; +} + +UINT32 OsArmSharedPageFault(UINT32 excType, ExcContext *frame, UINT32 far, UINT32 fsr) +{ + PRINT_INFO("page fault entry!!!\n"); + BOOL instruction_fault = FALSE; + UINT32 pfFlags = 0; + UINT32 fsrFlag; + BOOL write = FALSE; + + if (OsGetSystemStatus() == OS_SYSTEM_EXC_CURR_CPU) { + return LOS_ERRNO_VM_NOT_FOUND; + } + + if (excType == OS_EXCEPT_PREFETCH_ABORT) { + instruction_fault = TRUE; + } else { + write = !!BIT_GET(fsr, WNR_BIT); + } + + fsrFlag = ((BIT_GET(fsr, FSR_FLAG_OFFSET_BIT) ? 0b10000 : 0) | BITS_GET(fsr, FSR_BITS_BEGIN_BIT, 0)); + switch (fsrFlag) { + case 0b00101: + /* translation fault */ + case 0b00111: + /* translation fault */ + case 0b01101: + /* permission fault */ + case 0b01111: { + /* permission fault */ + BOOL user = (frame->regCPSR & CPSR_MODE_MASK) == CPSR_MODE_USR; + pfFlags |= write ? VM_MAP_PF_FLAG_WRITE : 0; + pfFlags |= user ? VM_MAP_PF_FLAG_USER : 0; + pfFlags |= instruction_fault ? VM_MAP_PF_FLAG_INSTRUCTION : 0; + pfFlags |= VM_MAP_PF_FLAG_NOT_PRESENT; + return OsVmPageFaultHandler(far, pfFlags, frame); + } + default: + return LOS_ERRNO_VM_NOT_FOUND; + } +} + +STATIC VOID OsExcType(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr) +{ + /* undefinited exception handling or software interrupt */ + if ((excType == OS_EXCEPT_UNDEF_INSTR) || (excType == OS_EXCEPT_SWI)) { + if ((excBufAddr->regCPSR & INSTR_SET_MASK) == 0) { /* work status: ARM */ + excBufAddr->PC = excBufAddr->PC - ARM_INSTR_LEN; + } else if ((excBufAddr->regCPSR & INSTR_SET_MASK) == 0x20) { /* work status: Thumb */ + excBufAddr->PC = excBufAddr->PC - THUMB_INSTR_LEN; + } + } + + if (excType == OS_EXCEPT_PREFETCH_ABORT) { + PrintExcInfo("prefetch_abort fault fsr:0x%x, far:0x%0+8x\n", fsr, far); + (VOID)OsDecodeInstructionFSR(fsr); + } else if (excType == OS_EXCEPT_DATA_ABORT) { + PrintExcInfo("data_abort fsr:0x%x, far:0x%0+8x\n", fsr, far); + (VOID)OsDecodeDataFSR(fsr); + } +} + +STATIC const CHAR *g_excTypeString[] = { + "reset", + "undefined instruction", + "software interrupt", + "prefetch abort", + "data abort", + "fiq", + "address abort", + "irq" +}; + +STATIC VOID OsExcSysInfo(UINT32 excType, const ExcContext *excBufAddr) +{ + LosTaskCB *runTask = OsCurrTaskGet(); + LosProcessCB *runProcess = OsCurrProcessGet(); + LosVmMapRegion *region = NULL; + + PrintExcInfo("excType: %s\n" + "processName = %s\n" + "processID = %u\n" + "process aspace = 0x%08x -> 0x%08x\n" + "taskName = %s\n" + "taskID = %u\n", + g_excTypeString[excType], + runProcess->processName, + runProcess->processID, + runProcess->vmSpace->base, + runProcess->vmSpace->base + runProcess->vmSpace->size, + runTask->taskName, + runTask->taskID); + + if (OsProcessIsUserMode(runProcess)) { + PrintExcInfo("task user stack = 0x%08x -> 0x%08x\n", + runTask->userMapBase, runTask->userMapBase + runTask->userMapSize); + } else { + PrintExcInfo("task kernel stack = 0x%08x -> 0x%08x\n", + runTask->topOfStack, runTask->topOfStack + runTask->stackSize); + } + + PrintExcInfo("pc = 0x%x ", excBufAddr->PC); + if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { + if (LOS_IsUserAddress((vaddr_t)excBufAddr->PC)) { + region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)excBufAddr->PC); + if (region != NULL) { + PrintExcInfo("in %s ---> 0x%x", OsGetRegionNameOrFilePath(region), + (VADDR_T)excBufAddr->PC - region->range.base); + } + } + + PrintExcInfo("\nulr = 0x%x ", excBufAddr->ULR); + region = LOS_RegionFind(runProcess->vmSpace, (VADDR_T)excBufAddr->ULR); + if (region != NULL) { + PrintExcInfo("in %s ---> 0x%x", OsGetRegionNameOrFilePath(region), + (VADDR_T)excBufAddr->ULR - region->range.base); + } + PrintExcInfo("\nusp = 0x%x", excBufAddr->USP); + } else { + PrintExcInfo("\nklr = 0x%x\n" + "ksp = 0x%x\n", + excBufAddr->LR, + excBufAddr->SP); + } + + PrintExcInfo("fp = 0x%x\n", excBufAddr->R11); +} + +STATIC VOID OsExcRegsInfo(const ExcContext *excBufAddr) +{ + /* + * Split register information into two parts: + * Ensure printing does not rely on memory modules. + */ + PrintExcInfo("R0 = 0x%x\n" + "R1 = 0x%x\n" + "R2 = 0x%x\n" + "R3 = 0x%x\n" + "R4 = 0x%x\n" + "R5 = 0x%x\n" + "R6 = 0x%x\n", + excBufAddr->R0, excBufAddr->R1, excBufAddr->R2, excBufAddr->R3, + excBufAddr->R4, excBufAddr->R5, excBufAddr->R6); + PrintExcInfo("R7 = 0x%x\n" + "R8 = 0x%x\n" + "R9 = 0x%x\n" + "R10 = 0x%x\n" + "R11 = 0x%x\n" + "R12 = 0x%x\n" + "CPSR = 0x%x\n", + excBufAddr->R7, excBufAddr->R8, excBufAddr->R9, excBufAddr->R10, + excBufAddr->R11, excBufAddr->R12, excBufAddr->regCPSR); +} + +LITE_OS_SEC_TEXT_INIT UINT32 LOS_ExcRegHook(EXC_PROC_FUNC excHook) +{ + UINT32 intSave; + + intSave = LOS_IntLock(); + g_excHook = excHook; + LOS_IntRestore(intSave); + + return LOS_OK; +} + +EXC_PROC_FUNC OsExcRegHookGet(VOID) +{ + return g_excHook; +} + +STATIC VOID OsDumpExcVaddrRegion(LosVmSpace *space, LosVmMapRegion *region) +{ + INT32 i, numPages, pageCount; + paddr_t addr, oldAddr, startVaddr, startPaddr; + vaddr_t pageBase; + BOOL mmuFlag = FALSE; + + numPages = region->range.size >> PAGE_SHIFT; + mmuFlag = TRUE; + for (pageCount = 0, startPaddr = 0, startVaddr = 0, i = 0; i < numPages; i++) { + pageBase = region->range.base + i * PAGE_SIZE; + addr = 0; + if (LOS_ArchMmuQuery(&space->archMmu, pageBase, &addr, NULL) != LOS_OK) { + if (startPaddr == 0) { + continue; + } + } else if (startPaddr == 0) { + startVaddr = pageBase; + startPaddr = addr; + oldAddr = addr; + pageCount++; + if (numPages > 1) { + continue; + } + } else if (addr == (oldAddr + PAGE_SIZE)) { + pageCount++; + oldAddr = addr; + if (i < (numPages - 1)) { + continue; + } + } + if (mmuFlag == TRUE) { + PrintExcInfo(" uvaddr kvaddr mapped size\n"); + mmuFlag = FALSE; + } + PrintExcInfo(" 0x%08x 0x%08x 0x%08x\n", + startVaddr, LOS_PaddrToKVaddr(startPaddr), pageCount << PAGE_SHIFT); + pageCount = 0; + startPaddr = 0; + } +} + +STATIC VOID OsDumpProcessUsedMemRegion(LosProcessCB *runProcess, LosVmSpace *runspace, UINT16 vmmFlags) +{ + LosVmMapRegion *region = NULL; + LosRbNode *pstRbNodeTemp = NULL; + LosRbNode *pstRbNodeNext = NULL; + UINT32 count = 0; + + /* search the region list */ + RB_SCAN_SAFE(&runspace->regionRbTree, pstRbNodeTemp, pstRbNodeNext) + region = (LosVmMapRegion *)pstRbNodeTemp; + PrintExcInfo("%3u -> regionBase: 0x%08x regionSize: 0x%08x\n", count, region->range.base, region->range.size); + if (vmmFlags == OS_EXC_VMM_ALL_REGION) { + OsDumpExcVaddrRegion(runspace, region); + } + count++; + (VOID)OsRegionOverlapCheckUnlock(runspace, region); + RB_SCAN_SAFE_END(&space->regionRbTree, pstRbNodeTemp, pstRbNodeNext) +} + +STATIC VOID OsDumpProcessUsedMemNode(UINT16 vmmFalgs) +{ + LosProcessCB *runProcess = NULL; + LosVmSpace *runspace = NULL; + + runProcess = OsCurrProcessGet(); + if (runProcess == NULL) { + return; + } + + if (!OsProcessIsUserMode(runProcess)) { + return; + } + + PrintExcInfo("\n ******Current process %u vmm regions: ******\n", runProcess->processID); + + runspace = runProcess->vmSpace; + if (!runspace) { + return; + } + + OsDumpProcessUsedMemRegion(runProcess, runspace, vmmFalgs); + return; +} + +VOID OsDumpContextMem(const ExcContext *excBufAddr) +{ + UINT32 count = 0; + const UINT32 *excReg = NULL; + if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { + return; + } + + for (excReg = &(excBufAddr->R0); count <= DUMPREGS; excReg++, count++) { + if (IS_VALID_ADDR(*excReg)) { + PrintExcInfo("\ndump mem around R%u:%p", count, (*excReg)); + OsDumpMemByte(DUMPSIZE, ((*excReg) - (DUMPSIZE >> 1))); + } + } + + if (IS_VALID_ADDR(excBufAddr->SP)) { + PrintExcInfo("\ndump mem around SP:%p", excBufAddr->SP); + OsDumpMemByte(DUMPSIZE, (excBufAddr->SP - (DUMPSIZE >> 1))); + } +} + +STATIC VOID OsExcRestore(UINTPTR taskStackPointer) +{ + UINT32 currCpuID = ArchCurrCpuid(); + + g_excFromUserMode[currCpuID] = FALSE; + g_intCount[currCpuID] = 0; + g_curNestCount[currCpuID] = 0; +#if (LOSCFG_KERNEL_SMP == YES) + OsPercpuGet()->excFlag = CPU_RUNNING; +#endif + OsPercpuGet()->taskLockCnt = 0; + + OsSetCurrCpuSp(taskStackPointer); +} + +STATIC VOID OsUserExcHandle(ExcContext *excBufAddr) +{ + UINT32 currCpu = ArchCurrCpuid(); + LosProcessCB *runProcess = OsCurrProcessGet(); + + if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) { + return; + } + +#if (LOSCFG_KERNEL_SMP == YES) + LOS_SpinLock(&g_excSerializerSpin); + if (g_nextExcWaitCpu != INVALID_CPUID) { + g_currHandleExcCpuID = g_nextExcWaitCpu; + g_nextExcWaitCpu = INVALID_CPUID; + } else { + g_currHandleExcCpuID = INVALID_CPUID; + } + g_currHandleExcPID = OS_INVALID_VALUE; + LOS_SpinUnlock(&g_excSerializerSpin); +#else + g_currHandleExcCpuID = INVALID_CPUID; +#endif + runProcess->processStatus &= ~OS_PROCESS_FLAG_EXIT; + + OsExcRestore(excBufAddr->SP); + +#if (LOSCFG_KERNEL_SMP == YES) +#ifdef LOSCFG_FS_VFS + OsWakeConsoleSendTask(); +#endif +#endif + +#ifdef LOSCFG_SHELL_EXCINFO + OsProcessExitCodeCoreDumpSet(runProcess); +#endif + OsProcessExitCodeSignalSet(runProcess, SIGUSR2); + /* kill user exc process */ + LOS_Exit(OS_PRO_EXIT_OK); + + /* User mode exception handling failed , which normally does not exist */ + g_curNestCount[currCpu]++; + g_intCount[currCpu]++; + PrintExcInfo("User mode exception ends unscheduled!\n"); +} + +/* this function is used to validate fp or validate the checking range start and end. */ +STATIC INLINE BOOL IsValidFP(UINTPTR regFP, UINTPTR start, UINTPTR end, vaddr_t *vaddr) +{ + LosProcessCB *runProcess = NULL; + LosVmSpace *runspace = NULL; + VADDR_T kvaddr = regFP; + PADDR_T paddr; + + if (!((regFP > start) && (regFP < end) && IS_ALIGNED(regFP, sizeof(CHAR *)))) { + return FALSE; + } + + if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { + runProcess = OsCurrProcessGet(); + runspace = runProcess->vmSpace; + if (runspace == NULL) { + return FALSE; + } + + if (LOS_ArchMmuQuery(&runspace->archMmu, regFP, &paddr, NULL) != LOS_OK) { + return FALSE; + } + + kvaddr = (PADDR_T)(UINTPTR)LOS_PaddrToKVaddr(paddr); + } + if (vaddr != NULL) { + *vaddr = kvaddr; + } + + return TRUE; +} + +STATIC INLINE BOOL FindSuitableStack(UINTPTR regFP, UINTPTR *start, UINTPTR *end, vaddr_t *vaddr) +{ + UINT32 index, stackStart, stackEnd; + BOOL found = FALSE; + LosTaskCB *taskCB = NULL; + const StackInfo *stack = NULL; + vaddr_t kvaddr; + + if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { + taskCB = OsCurrTaskGet(); + stackStart = taskCB->userMapBase; + stackEnd = taskCB->userMapBase + taskCB->userMapSize; + if (IsValidFP(regFP, stackStart, stackEnd, &kvaddr) == TRUE) { + found = TRUE; + goto FOUND; + } + return found; + } + + /* Search in the task stacks */ + for (index = 0; index < g_taskMaxNum; index++) { + taskCB = &g_taskCBArray[index]; + if (OsTaskIsUnused(taskCB)) { + continue; + } + + stackStart = taskCB->topOfStack; + stackEnd = taskCB->topOfStack + taskCB->stackSize; + if (IsValidFP(regFP, stackStart, stackEnd, &kvaddr) == TRUE) { + found = TRUE; + goto FOUND; + } + } + + /* Search in the exc stacks */ + for (index = 0; index < sizeof(g_excStack) / sizeof(StackInfo); index++) { + stack = &g_excStack[index]; + stackStart = (UINTPTR)stack->stackTop; + stackEnd = stackStart + LOSCFG_KERNEL_CORE_NUM * stack->stackSize; + if (IsValidFP(regFP, stackStart, stackEnd, &kvaddr) == TRUE) { + found = TRUE; + goto FOUND; + } + } + +FOUND: + if (found == TRUE) { + *start = stackStart; + *end = stackEnd; + *vaddr = kvaddr; + } + + return found; +} + +VOID BackTraceSub(UINTPTR regFP) +{ + UINTPTR tmpFP, backLR; + UINTPTR stackStart, stackEnd; + UINTPTR backFP = regFP; + UINT32 count = 0; + LosVmMapRegion *region = NULL; + VADDR_T kvaddr; + + if (FindSuitableStack(regFP, &stackStart, &stackEnd, &kvaddr) == FALSE) { + PrintExcInfo("traceback error fp = 0x%x\n", regFP); + return; + } + + /* + * Check whether it is the leaf function. + * Generally, the frame pointer points to the address of link register, while in the leaf function, + * there's no function call, and compiler will not store the link register, but the frame pointer + * will still be stored and updated. In that case we needs to find the right position of frame pointer. + */ + tmpFP = *(UINTPTR *)(UINTPTR)kvaddr; + if (IsValidFP(tmpFP, stackStart, stackEnd, NULL) == TRUE) { + backFP = tmpFP; + PrintExcInfo("traceback fp fixed, trace using fp = 0x%x\n", backFP); + } + + while (IsValidFP(backFP, stackStart, stackEnd, &kvaddr) == TRUE) { + tmpFP = backFP; + backLR = *(UINTPTR *)(UINTPTR)kvaddr; + if (IsValidFP(tmpFP - POINTER_SIZE, stackStart, stackEnd, &kvaddr) == FALSE) { + PrintExcInfo("traceback backFP check failed, backFP: 0x%x\n", tmpFP - POINTER_SIZE); + return; + } + backFP = *(UINTPTR *)(UINTPTR)kvaddr; + if (LOS_IsUserAddress((VADDR_T)backLR) == TRUE) { + region = LOS_RegionFind(OsCurrProcessGet()->vmSpace, (VADDR_T)backLR); + } + if (region != NULL) { + PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x lr in %s --> 0x%x\n", count, backLR, backFP, + OsGetRegionNameOrFilePath(region), backLR - region->range.base); + region = NULL; + } else { + PrintExcInfo("traceback %u -- lr = 0x%x fp = 0x%x\n", count, backLR, backFP); + } + count++; + if ((count == OS_MAX_BACKTRACE) || (backFP == tmpFP)) { + break; + } + } +} + +VOID BackTrace(UINT32 regFP) +{ + PrintExcInfo("*******backtrace begin*******\n"); + + BackTraceSub(regFP); +} + +VOID OsExcInit(VOID) +{ + OsExcStackInfoReg(g_excStack, sizeof(g_excStack) / sizeof(g_excStack[0])); +} + +VOID OsExcHook(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr) +{ + OsExcType(excType, excBufAddr, far, fsr); + OsExcSysInfo(excType, excBufAddr); + OsExcRegsInfo(excBufAddr); + + BackTrace(excBufAddr->R11); + + (VOID)OsShellCmdTskInfoGet(OS_ALL_TASK_MASK, NULL, OS_PROCESS_INFO_ALL); + +#ifndef LOSCFG_DEBUG_VERSION + if (g_excFromUserMode[ArchCurrCpuid()] != TRUE) { +#endif + OsDumpProcessUsedMemNode(OS_EXC_VMM_NO_REGION); + + OsExcStackInfo(); +#ifndef LOSCFG_DEBUG_VERSION + } +#endif + + OsDumpContextMem(excBufAddr); + + (VOID)OsShellCmdMemCheck(0, NULL); + +#ifdef LOSCFG_COREDUMP + LOS_CoreDumpV2(excType, excBufAddr); +#endif + + OsUserExcHandle(excBufAddr); +} + +VOID OsCallStackInfo(VOID) +{ + UINT32 count = 0; + LosTaskCB *runTask = OsCurrTaskGet(); + UINTPTR stackBottom = runTask->topOfStack + runTask->stackSize; + UINT32 *stackPointer = (UINT32 *)stackBottom; + + PrintExcInfo("runTask->stackPointer = 0x%x\n" + "runTask->topOfStack = 0x%x\n" + "text_start:0x%x,text_end:0x%x\n", + stackPointer, runTask->topOfStack, &__text_start, &__text_end); + + while ((stackPointer > (UINT32 *)runTask->topOfStack) && (count < OS_MAX_BACKTRACE)) { + if ((*stackPointer > (UINTPTR)(&__text_start)) && + (*stackPointer < (UINTPTR)(&__text_end)) && + IS_ALIGNED((*stackPointer), POINTER_SIZE)) { + if ((*(stackPointer - 1) > (UINT32)runTask->topOfStack) && + (*(stackPointer - 1) < stackBottom) && + IS_ALIGNED((*(stackPointer - 1)), POINTER_SIZE)) { + count++; + PrintExcInfo("traceback %u -- lr = 0x%x\n", count, *stackPointer); + } + } + stackPointer--; + } + PRINTK("\n"); +} + +VOID OsTaskBackTrace(UINT32 taskID) +{ + LosTaskCB *taskCB = NULL; + + if (OS_TID_CHECK_INVALID(taskID)) { + PRINT_ERR("\r\nTask ID is invalid!\n"); + return; + } + taskCB = OS_TCB_FROM_TID(taskID); + if (OsTaskIsUnused(taskCB) || (taskCB->taskEntry == NULL)) { + PRINT_ERR("\r\nThe task is not created!\n"); + return; + } + PRINTK("TaskName = %s\n", taskCB->taskName); + PRINTK("TaskID = 0x%x\n", taskCB->taskID); + BackTrace(((TaskContext *)(taskCB->stackPointer))->R[11]); /* R11 : FP */ +} + +VOID OsBackTrace(VOID) +{ + UINT32 regFP = Get_Fp(); + LosTaskCB *runTask = OsCurrTaskGet(); + PRINTK("OsBackTrace fp = 0x%x\n", regFP); + PRINTK("runTask->taskName = %s\n", runTask->taskName); + PRINTK("runTask->taskID = %u\n", runTask->taskID); + BackTrace(regFP); +} + +#ifdef LOSCFG_GDB +VOID OsUndefIncExcHandleEntry(ExcContext *excBufAddr) +{ + excBufAddr->PC -= 4; /* lr in undef is pc + 4 */ + + if (gdb_undef_hook(excBufAddr, OS_EXCEPT_UNDEF_INSTR)) { + return; + } + + if (g_excHook != NULL) { + /* far, fsr are unused in exc type of OS_EXCEPT_UNDEF_INSTR */ + g_excHook(OS_EXCEPT_UNDEF_INSTR, excBufAddr, 0, 0); + } + while (1) {} +} + +#if __LINUX_ARM_ARCH__ >= 7 +VOID OsPrefetchAbortExcHandleEntry(ExcContext *excBufAddr) +{ + UINT32 far; + UINT32 fsr; + + excBufAddr->PC -= 4; /* lr in prefetch abort is pc + 4 */ + + if (gdbhw_hook(excBufAddr, OS_EXCEPT_PREFETCH_ABORT)) { + return; + } + + if (g_excHook != NULL) { + far = OsArmReadIfar(); + fsr = OsArmReadIfsr(); + g_excHook(OS_EXCEPT_PREFETCH_ABORT, excBufAddr, far, fsr); + } + while (1) {} +} + +VOID OsDataAbortExcHandleEntry(ExcContext *excBufAddr) +{ + UINT32 far; + UINT32 fsr; + + excBufAddr->PC -= 8; /* lr in data abort is pc + 8 */ + + if (gdbhw_hook(excBufAddr, OS_EXCEPT_DATA_ABORT)) { + return; + } + + if (g_excHook != NULL) { + far = OsArmReadDfar(); + fsr = OsArmReadDfsr(); + g_excHook(OS_EXCEPT_DATA_ABORT, excBufAddr, far, fsr); + } + while (1) {} +} +#endif /* __LINUX_ARM_ARCH__ */ +#endif /* LOSCFG_GDB */ + +#if (LOSCFG_KERNEL_SMP == YES) +#define EXC_WAIT_INTER 50U +#define EXC_WAIT_TIME 2000U + +STATIC VOID OsAllCpuStatusOutput(VOID) +{ + UINT32 i; + + for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) { + switch (g_percpu[i].excFlag) { + case CPU_RUNNING: + PrintExcInfo("cpu%u is running.\n", i); + break; + case CPU_HALT: + PrintExcInfo("cpu%u is halted.\n", i); + break; + case CPU_EXC: + PrintExcInfo("cpu%u is in exc.\n", i); + break; + default: + break; + } + } + PrintExcInfo("The current handling the exception is cpu%u !\n", ArchCurrCpuid()); +} + +STATIC VOID WaitAllCpuStop(UINT32 cpuID) +{ + UINT32 i; + UINT32 time = 0; + + while (time < EXC_WAIT_TIME) { + for (i = 0; i < LOSCFG_KERNEL_CORE_NUM; i++) { + if ((i != cpuID) && (g_percpu[i].excFlag != CPU_HALT)) { + LOS_Mdelay(EXC_WAIT_INTER); + time += EXC_WAIT_INTER; + break; + } + } + /* Other CPUs are all haletd or in the exc. */ + if (i == LOSCFG_KERNEL_CORE_NUM) { + break; + } + } + return; +} + +STATIC VOID OsWaitOtherCoresHandleExcEnd(UINT32 currCpuID) +{ + OsProcessSuspendAllTask(); + while (1) { + LOS_SpinLock(&g_excSerializerSpin); + if ((g_currHandleExcCpuID == INVALID_CPUID) || (g_currHandleExcCpuID == currCpuID)) { + g_currHandleExcCpuID = currCpuID; + g_currHandleExcPID = OsCurrProcessGet()->processID; + LOS_SpinUnlock(&g_excSerializerSpin); + break; + } + + if (g_nextExcWaitCpu == INVALID_CPUID) { + g_nextExcWaitCpu = currCpuID; + } + LOS_SpinUnlock(&g_excSerializerSpin); + LOS_Mdelay(EXC_WAIT_INTER); + } +} + +STATIC VOID OsCheckAllCpuStatus(UINTPTR taskStackPointer) +{ + UINT32 currCpuID = ArchCurrCpuid(); + UINT32 ret, target; + + OsPercpuGet()->excFlag = CPU_EXC; + LOCKDEP_CLEAR_LOCKS(); + + LOS_SpinLock(&g_excSerializerSpin); + if (g_currHandleExcCpuID == INVALID_CPUID) { + g_currHandleExcCpuID = currCpuID; + g_currHandleExcPID = OsCurrProcessGet()->processID; + LOS_SpinUnlock(&g_excSerializerSpin); + if (g_excFromUserMode[currCpuID] == FALSE) { + target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID)); + HalIrqSendIpi(target, LOS_MP_IPI_HALT); + } + } else if (g_excFromUserMode[currCpuID] == TRUE) { + if (OsCurrProcessGet()->processID == g_currHandleExcPID) { + LOS_SpinUnlock(&g_excSerializerSpin); + OsExcRestore(taskStackPointer); + while (1) { + ret = LOS_TaskSuspend(OsCurrTaskGet()->taskID); + PrintExcInfo("%s supend task :%u failed: 0x%x\n", __FUNCTION__, OsCurrTaskGet()->taskID, ret); + } + } + LOS_SpinUnlock(&g_excSerializerSpin); + + OsWaitOtherCoresHandleExcEnd(currCpuID); + } else { + if (g_excFromUserMode[g_currHandleExcCpuID] == TRUE) { + g_currHandleExcCpuID = currCpuID; + LOS_SpinUnlock(&g_excSerializerSpin); + target = (UINT32)(OS_MP_CPU_ALL & ~CPUID_TO_AFFI_MASK(currCpuID)); + HalIrqSendIpi(target, LOS_MP_IPI_HALT); + } else { + LOS_SpinUnlock(&g_excSerializerSpin); + while (1) {} + } + } + + /* use halt ipi to stop other active cores */ + if (g_excFromUserMode[ArchCurrCpuid()] == FALSE) { + WaitAllCpuStop(currCpuID); + } +} +#endif + +STATIC VOID OsCheckCpuStatus(UINTPTR taskStackPointer) +{ +#if (LOSCFG_KERNEL_SMP == YES) + OsCheckAllCpuStatus(taskStackPointer); +#else + (VOID)taskStackPointer; + g_currHandleExcCpuID = ArchCurrCpuid(); +#endif +} + +LITE_OS_SEC_TEXT VOID STATIC OsExcPriorDisposal(ExcContext *excBufAddr) +{ +#if (LOSCFG_KERNEL_SMP == YES) + UINT16 runCount; +#endif + + if ((excBufAddr->regCPSR & CPSR_MASK_MODE) == CPSR_USER_MODE) { + g_minAddr = USER_ASPACE_BASE; + g_maxAddr = USER_ASPACE_BASE + USER_ASPACE_SIZE; + g_excFromUserMode[ArchCurrCpuid()] = TRUE; + } else { + g_minAddr = KERNEL_ASPACE_BASE; + g_maxAddr = KERNEL_ASPACE_BASE + KERNEL_ASPACE_SIZE; + g_excFromUserMode[ArchCurrCpuid()] = FALSE; + } + + OsCheckCpuStatus(excBufAddr->SP); + + if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { + while (1) { + OsProcessSuspendAllTask(); +#if (LOSCFG_KERNEL_SMP == YES) + LOS_SpinLock(&g_taskSpin); + runCount = OS_PROCESS_GET_RUNTASK_COUNT(OsCurrProcessGet()->processStatus); + LOS_SpinUnlock(&g_taskSpin); + if (runCount == 1) { + break; + } +#else + break; +#endif + } + } +} + +/* + * Description : EXC handler entry + * Input : excType --- exc type + * excBufAddr --- address of EXC buf + */ +LITE_OS_SEC_TEXT_INIT VOID OsExcHandleEntry(UINT32 excType, ExcContext *excBufAddr, UINT32 far, UINT32 fsr) +{ + /* Task scheduling is not allowed during exception handling */ + OsPercpuGet()->taskLockCnt++; + + g_curNestCount[ArchCurrCpuid()]++; + + OsExcPriorDisposal(excBufAddr); + +#if (LOSCFG_KERNEL_SMP == YES) +#ifdef LOSCFG_FS_VFS + /* Wait for the end of the Console task to avoid multicore printing code */ + OsWaitConsoleSendTaskPend(OsCurrTaskGet()->taskID); +#endif +#endif + + /* You are not allowed to add any other print information before this exception information */ + if (g_excFromUserMode[ArchCurrCpuid()] == TRUE) { + PrintExcInfo("##################excFrom: User!####################\n"); + } else { + PrintExcInfo("##################excFrom: kernel###################!\n"); + } + +#if (LOSCFG_KERNEL_SMP == YES) + OsAllCpuStatusOutput(); +#endif + +#ifdef LOSCFG_SHELL_EXCINFO + log_read_write_fn func = GetExcInfoRW(); +#endif + + if (g_excHook != NULL) { + if (g_curNestCount[ArchCurrCpuid()] == 1) { +#ifdef LOSCFG_SHELL_EXCINFO + if (func != NULL) { + SetExcInfoIndex(0); + g_intCount[ArchCurrCpuid()] = 0; + OsRecordExcInfoTime(); + g_intCount[ArchCurrCpuid()] = 1; + } +#endif + g_excHook(excType, excBufAddr, far, fsr); + } else { + OsCallStackInfo(); + } + +#ifdef LOSCFG_SHELL_EXCINFO + if (func != NULL) { + PrintExcInfo("Be sure flash space bigger than GetExcInfoIndex():0x%x\n", GetExcInfoIndex()); + g_intCount[ArchCurrCpuid()] = 0; + func(GetRecordAddr(), GetRecordSpace(), 0, GetExcInfoBuf()); + g_intCount[ArchCurrCpuid()] = 1; + } +#endif + } +#ifdef LOSCFG_EXC_INTERACTION + OsExcInteractionTaskKeep(); +#endif + while (1) {} +} + +__attribute__((noinline)) VOID LOS_Panic(const CHAR *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + UartVprintf(fmt, ap); + va_end(ap); + __asm__ __volatile__("swi 0"); +} + +/* stack protector */ +UINT32 __stack_chk_guard = 0xd00a0dff; + +VOID __stack_chk_fail(VOID) +{ + /* __builtin_return_address is a builtin function, building in gcc */ + LOS_Panic("stack-protector: Kernel stack is corrupted in: %p\n", + __builtin_return_address(0)); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/arch/arm/arm/src/los_hw.c b/arch/arm/arm/src/los_hw.c new file mode 100755 index 00000000..dbc24d2c --- /dev/null +++ b/arch/arm/arm/src/los_hw.c @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_hw_pri.h" +#include "los_task_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* support cpu vendors */ +CpuVendor g_cpuTable[] = { + /* armv7-a */ + { 0xc07, "Cortex-A7" }, + { 0xc09, "Cortex-A9" }, + { 0, NULL } +}; + +/* logical cpu mapping */ +UINT64 g_cpuMap[LOSCFG_KERNEL_CORE_NUM] = { + [0 ... LOSCFG_KERNEL_CORE_NUM - 1] = (UINT64)(-1) +}; + +/* bit[30] is enable FPU */ +#define FP_EN (1U << 30) +LITE_OS_SEC_TEXT_INIT VOID OsTaskExit(VOID) +{ + __asm__ __volatile__("swi 0"); +} + +#ifdef LOSCFG_GDB +STATIC VOID OsTaskEntrySetupLoopFrame(UINT32) __attribute__((noinline, naked)); +VOID OsTaskEntrySetupLoopFrame(UINT32 arg0) +{ + asm volatile("\tsub fp, sp, #0x4\n" + "\tpush {fp, lr}\n" + "\tadd fp, sp, #0x4\n" + "\tpush {fp, lr}\n" + + "\tadd fp, sp, #0x4\n" + "\tbl OsTaskEntry\n" + + "\tpop {fp, lr}\n" + "\tpop {fp, pc}\n"); +} +#endif + +LITE_OS_SEC_TEXT_INIT VOID *OsTaskStackInit(UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag) +{ + UINT32 index = 1; + TaskContext *taskContext = NULL; + + if (initFlag == TRUE) { + OsStackInit(topStack, stackSize); + } + taskContext = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext)); + + /* initialize the task context */ +#ifdef LOSCFG_GDB + taskContext->PC = (UINTPTR)OsTaskEntrySetupLoopFrame; +#else + taskContext->PC = (UINTPTR)OsTaskEntry; +#endif + taskContext->LR = (UINTPTR)OsTaskExit; /* LR should be kept, to distinguish it's THUMB or ARM instruction */ + taskContext->resved = 0x0; + taskContext->R[0] = taskID; /* R0 */ + taskContext->R[index++] = 0x01010101; /* R1, 0x01010101 : reg initialed magic word */ + for (; index < GEN_REGS_NUM; index++) { + taskContext->R[index] = taskContext->R[index - 1] + taskContext->R[1]; /* R2 - R12 */ + } + +#ifdef LOSCFG_INTERWORK_THUMB + taskContext->regPSR = PSR_MODE_SVC_THUMB; /* CPSR (Enable IRQ and FIQ interrupts, THUMNB-mode) */ +#else + taskContext->regPSR = PSR_MODE_SVC_ARM; /* CPSR (Enable IRQ and FIQ interrupts, ARM-mode) */ +#endif + +#if !defined(LOSCFG_ARCH_FPU_DISABLE) + /* 0xAAA0000000000000LL : float reg initialed magic word */ + for (index = 0; index < FP_REGS_NUM; index++) { + taskContext->D[index] = 0xAAA0000000000000LL + index; /* D0 - D31 */ + } + taskContext->regFPSCR = 0; + taskContext->regFPEXC = FP_EN; +#endif + + return (VOID *)taskContext; +} + +LITE_OS_SEC_TEXT VOID OsUserCloneParentStack(LosTaskCB *childTaskCB, LosTaskCB *parentTaskCB) +{ + TaskContext *context = (TaskContext *)childTaskCB->stackPointer; + VOID *cloneStack = (VOID *)(((UINTPTR)parentTaskCB->topOfStack + parentTaskCB->stackSize) - sizeof(TaskContext)); + + LOS_ASSERT(parentTaskCB->taskStatus & OS_TASK_STATUS_RUNNING); + + (VOID)memcpy_s(childTaskCB->stackPointer, sizeof(TaskContext), cloneStack, sizeof(TaskContext)); + context->R[0] = 0; +} + +LITE_OS_SEC_TEXT_INIT VOID OsUserTaskStackInit(TaskContext *context, TSK_ENTRY_FUNC taskEntry, UINTPTR stack) +{ + LOS_ASSERT(context != NULL); + +#ifdef LOSCFG_INTERWORK_THUMB + context->regPSR = PSR_MODE_USR_THUMB; +#else + context->regPSR = PSR_MODE_USR_ARM; +#endif + context->R[0] = stack; + context->SP = TRUNCATE(stack, LOSCFG_STACK_POINT_ALIGN_SIZE); + context->LR = 0; + context->PC = (UINTPTR)taskEntry; +} + +VOID Sev(VOID) +{ + __asm__ __volatile__ ("sev" : : : "memory"); +} + +VOID Wfe(VOID) +{ + __asm__ __volatile__ ("wfe" : : : "memory"); +} + +VOID Wfi(VOID) +{ + __asm__ __volatile__ ("wfi" : : : "memory"); +} + +VOID Dmb(VOID) +{ + __asm__ __volatile__ ("dmb" : : : "memory"); +} + +VOID Dsb(VOID) +{ + __asm__ __volatile__("dsb" : : : "memory"); +} + +VOID Isb(VOID) +{ + __asm__ __volatile__("isb" : : : "memory"); +} + +VOID FlushICache(VOID) +{ + /* + * Use ICIALLUIS instead of ICIALLU. ICIALLUIS operates on all processors in the Inner + * shareable domain of the processor that performs the operation. + */ + __asm__ __volatile__ ("mcr p15, 0, %0, c7, c1, 0" : : "r" (0) : "memory"); +} + +VOID DCacheFlushRange(UINT32 start, UINT32 end) +{ + arm_clean_cache_range(start, end); +} + +VOID DCacheInvRange(UINT32 start, UINT32 end) +{ + arm_inv_cache_range(start, end); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/arch/arm/arm/src/los_hw_exc.S b/arch/arm/arm/src/los_hw_exc.S new file mode 100755 index 00000000..25d8639c --- /dev/null +++ b/arch/arm/arm/src/los_hw_exc.S @@ -0,0 +1,412 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "asm.h" +#include "arch_config.h" + + .extern g_losTask + .extern g_intCount + .extern g_curNestCount + .extern OsExcHandleEntry + .extern __svc_stack_top + .extern __exc_stack_top + .extern __stack_chk_guard + .extern OsRandomStackGuard +#ifdef LOSCFG_GDB + .extern OsUndefIncExcHandleEntry +#if __LINUX_ARM_ARCH__ >= 7 + .extern OsPrefetchAbortExcHandleEntry + .extern OsDataAbortExcHandleEntry +#endif +#endif + .extern OsArmSharedPageFault + .extern OsArmA32SyscallHandle + .extern LOS_Exit + + .global _osExceptFiqHdl + .global _osExceptAddrAbortHdl + .global _osExceptDataAbortHdl + .global _osExceptPrefetchAbortHdl + .global _osExceptSwiHdl + .global _osExceptUndefInstrHdl + .global __stack_chk_guard_setup + + + .fpu vfpv4 + +.macro PUSH_FPU_REGS reg1 +#if !defined(LOSCFG_ARCH_FPU_DISABLE) + VMRS \reg1, FPEXC + PUSH {\reg1} + VMRS \reg1, FPSCR + PUSH {\reg1} +#if defined(LOSCFG_ARCH_FPU_VFP_D32) + VPUSH {D16-D31} +#endif + VPUSH {D0-D15} +#endif +.endm + +.macro POP_FPU_REGS reg1 +#if !defined(LOSCFG_ARCH_FPU_DISABLE) + VPOP {D0-D15} +#if defined(LOSCFG_ARCH_FPU_VFP_D32) + VPOP {D16-D31} +#endif + POP {\reg1} + VMSR FPSCR, \reg1 + POP {\reg1} + VMSR FPEXC, \reg1 +#endif +.endm + +#ifdef LOSCFG_GDB +.macro GDB_HANDLE fun + SUB SP, SP, #12 + + STMFD SP!, {R0-R12} + MRS R1, SPSR + STMFD SP!, {R1} @save spsr + + ADD R0, SP, #14 * 4 + MOV R3, LR @save pc + + MRS R1, CPSR + MRS R2, SPSR + MOV R4, SP + + ORR R2, R2, #(CPSR_INT_DISABLE) + MSR CPSR_c, R2 + + STR SP, [R0] @SP + STR LR, [R0, #4] @LR + STR R3, [R0, #8] @PC + + ORR R1, R1, #(CPSR_INT_DISABLE) + BIC R1, R1, #OS_PSR_THUMB + MSR CPSR_c, R1 + MOV R0, R4 + + BL \fun + + ADD SP, SP, #4 + LDMFD SP!, {R0-R12} + + MOV R0, SP + ADD SP, SP, #8 + + LDR R1, [R0, #8] @get pc + STMFD SP!, {R1} + + AND R1, R1, #0x03 + CMP R1, #0 + BEQ 1f + LDR R1, [R0, #-14 * 4] + ORR R1, R1, #OS_PSR_THUMB + B 2f +1: + LDR R1, [R0, #-14 * 4] + +2: + MSR SPSR, R1 + + LDR R1, [R0, #-12 * 4] @get R1 + STMFD SP!, {R1} + LDR R1, [R0,#-13 * 4] @get R0 + STMFD SP!, {R1} + + LDMFD SP!, {R0-R1, PC}^ +.endm +#endif + +@ Description: Stack-Protector Init +__stack_chk_guard_setup: + PUSH {FP, LR} + BL OsRandomStackGuard + LDR R1, =__stack_chk_guard + MOV R3, R0 + ORR R2, R3, #0X80000000 + STR R2, [R1] + POP {FP, PC} + +@ Description: Undefined instruction exception handler +_osExceptUndefInstrHdl: +#ifdef LOSCFG_GDB + GDB_HANDLE OsUndefIncExcHandleEntry +#else + @ LR offset to return from this exception: 0. + STMFD SP, {R0-R7} @ Push working registers, but don`t change SP. + + MOV R0, #OS_EXCEPT_UNDEF_INSTR @ Set exception ID to OS_EXCEPT_UNDEF_INSTR. + + B _osExceptDispatch @ Branch to global exception handler. + +#endif + +@ Description: Software interrupt exception handler +_osExceptSwiHdl: + SUB SP, SP, #(4 * 16) + STMIA SP, {R0-R12} + MRS R3, SPSR + MOV R4, LR + + AND R1, R3, #CPSR_MASK_MODE @ Interrupted mode + CMP R1, #CPSR_USER_MODE @ User mode + BNE OsKernelSVCHandler @ Branch if not user mode + + @ we enter from user mode, we need get the values of USER mode r13(sp) and r14(lr). + @ stmia with ^ will return the user mode registers (provided that r15 is not in the register list). + MOV R0, SP + STMFD SP!, {R3} @ Save the CPSR + ADD R3, SP, #(4 * 17) @ Offset to pc/cpsr storage + STMFD R3!, {R4} @ Save the CPSR and r15(pc) + STMFD R3, {R13, R14}^ @ Save user mode r13(sp) and r14(lr) + SUB SP, SP, #4 + PUSH_FPU_REGS R1 + + MOV FP, #0 @ Init frame pointer + CPSIE I + BLX OsArmA32SyscallHandle + CPSID I + + POP_FPU_REGS R1 + ADD SP, SP,#4 + LDMFD SP!, {R3} @ Fetch the return SPSR + MSR SPSR_cxsf, R3 @ Set the return mode SPSR + + @ we are leaving to user mode, we need to restore the values of USER mode r13(sp) and r14(lr). + @ ldmia with ^ will return the user mode registers (provided that r15 is not in the register list) + + LDMFD SP!, {R0-R12} + LDMFD SP, {R13, R14}^ @ Restore user mode R13/R14 + ADD SP, SP, #(2 * 4) + LDMFD SP!, {PC}^ @ Return to user + +OsKernelSVCHandler: + ADD R0, SP, #(4 * 16) + MOV R5, R0 + STMFD R0!, {R4} @ Store PC + STMFD R0!, {R4} + STMFD R0!, {R5} + + STMFD SP!, {R3} @ Push task`s CPSR (i.e. exception SPSR). + SUB SP, SP, #(4 * 2) @ user sp and lr + + MOV R0, #OS_EXCEPT_SWI @ Set exception ID to OS_EXCEPT_SWI. + + B _osExceptionSwi @ Branch to global exception handler. + +@ Description: Prefectch abort exception handler +_osExceptPrefetchAbortHdl: +#ifdef LOSCFG_GDB +#if __LINUX_ARM_ARCH__ >= 7 + GDB_HANDLE OsPrefetchAbortExcHandleEntry +#endif +#else + SUB LR, LR, #4 @ LR offset to return from this exception: -4. + STMFD SP, {R0-R7} @ Push working registers, but don`t change SP. + MOV R5, LR + MRS R1, SPSR + + MOV R0, #OS_EXCEPT_PREFETCH_ABORT @ Set exception ID to OS_EXCEPT_PREFETCH_ABORT. + + AND R4, R1, #CPSR_MASK_MODE @ Interrupted mode + CMP R4, #CPSR_USER_MODE @ User mode + BEQ _osExcPageFault @ Branch if user mode + +_osKernelExceptPrefetchAbortHdl: + MOV LR, R5 + B _osExceptDispatch @ Branch to global exception handler. +#endif + +@ Description: Data abort exception handler +_osExceptDataAbortHdl: +#ifdef LOSCFG_GDB +#if __LINUX_ARM_ARCH__ >= 7 + GDB_HANDLE OsDataAbortExcHandleEntry +#endif +#else + SUB LR, LR, #8 @ LR offset to return from this exception: -8. + STMFD SP, {R0-R7} @ Push working registers, but don`t change SP. + MOV R5, LR + MRS R1, SPSR + + MOV R0, #OS_EXCEPT_DATA_ABORT @ Set exception ID to OS_EXCEPT_DATA_ABORT. + + B _osExcPageFault +#endif + +@ Description: Address abort exception handler +_osExceptAddrAbortHdl: + SUB LR, LR, #8 @ LR offset to return from this exception: -8. + STMFD SP, {R0-R7} @ Push working registers, but don`t change SP. + + MOV R0, #OS_EXCEPT_ADDR_ABORT @ Set exception ID to OS_EXCEPT_ADDR_ABORT. + + B _osExceptDispatch @ Branch to global exception handler. + +@ Description: Fast interrupt request exception handler +_osExceptFiqHdl: + SUB LR, LR, #4 @ LR offset to return from this exception: -4. + STMFD SP, {R0-R7} @ Push working registers. + + MOV R0, #OS_EXCEPT_FIQ @ Set exception ID to OS_EXCEPT_FIQ. + + B _osExceptDispatch @ Branch to global exception handler. + +_osExcPageFault: + SUB R3, SP, #(8 * 4) @ Save the start address of working registers. + MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to SVC mode, and disable all interrupts + MOV R2, SP + STMFD SP!, {R5} @ Push original PC + STMFD SP!, {LR} @ Push original svc LR + STMFD SP!, {R2} @ Push original svc SP + STMFD SP!, {R8-R12} @ Push original R12-R8, + LDMFD R3!, {R4-R11} @ Move original R7-R0 from exception stack to original stack. + STMFD SP!, {R4-R11} + STMFD SP!, {R1} + SUB SP, SP, #8 + STMIA SP, {R13, R14}^ @ Save user mode r13(sp) and r14(lr) + + MOV R4, SP + BIC SP, SP, #7 + PUSH_FPU_REGS R1 + + CMP R0, #OS_EXCEPT_DATA_ABORT + BNE 1f + MRC P15, 0, R2, C6, C0, 0 + MRC P15, 0, R3, C5, C0, 0 + B 2f +1: MRC P15, 0, R2, C6, C0, 2 + MRC P15, 0, R3, C5, C0, 1 + +2: MOV R1, R4 + MOV R5, R0 + MOV R8, R2 + MOV R9, R3 + CPSIE I + BLX OsArmSharedPageFault + CPSID I + + POP_FPU_REGS R1 + MOV SP, R4 + CMP R0, #0 + BEQ _OsExcReturn + + MOV R0, R5 @ exc type + B _osExceptionSwi + +@ Description: Exception handler +@ Parameter : R0 Exception Type +@ Regs Hold : R3 Exception`s CPSR +_osExceptDispatch: + MRS R2, SPSR @ Save CPSR before exception. + MOV R1, LR @ Save PC before exception. + SUB R3, SP, #(8 * 4) @ Save the start address of working registers. + + MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @ Switch to SVC mode, and disable all interrupts + MOV R5, SP + EXC_SP_SET __exc_stack_top, OS_EXC_STACK_SIZE, R6, R7 + + STMFD SP!, {R1} @ Push Exception PC + STMFD SP!, {LR} @ Push SVC LR + STMFD SP!, {R5} @ Push SVC SP + STMFD SP!, {R8-R12} @ Push original R12-R8, + LDMFD R3!, {R4-R11} @ Move original R7-R0 from exception stack to original stack. + STMFD SP!, {R4-R11} + STMFD SP!, {R2} @ Push task`s CPSR (i.e. exception SPSR). + + CMP R0, #OS_EXCEPT_DATA_ABORT + BNE 1f + MRC P15, 0, R8, C6, C0, 0 + MRC P15, 0, R9, C5, C0, 0 + B 3f +1: CMP R0, #OS_EXCEPT_PREFETCH_ABORT + BNE 2f + MRC P15, 0, R8, C6, C0, 2 + MRC P15, 0, R9, C5, C0, 1 + B 3f +2: MOV R8, #0 + MOV R9, #0 + +3: AND R2, R2, #CPSR_MASK_MODE + CMP R2, #CPSR_USER_MODE @ User mode + BNE 4f + STMFD SP, {R13, R14}^ @ save user mode sp and lr +4: + SUB SP, SP, #(4 * 2) + +_osExceptionSwi: + MOV R1, SP @ The second argument to the exception + + MRC P15, 0, R4, C0, C0, 5 + AND R4, R4, #MPIDR_CPUID_MASK @ Get Current cpu id + LSL R2, R4, #2 + LDR R3, =g_curNestCount @ if(g_curNestCount > 0) dump to _osExceptionGetSP + ADD R3, R3, R2 + LDR R4, [R3] + + CMP R4, #0 + BNE _osExceptionGetSP + + LDR R3, =g_intCount @ Judge the exception is occur in task stack or system stack + ADD R3, R3, R2 + LDR R4, [R3] + + CMP R4, #0 @ if (g_intCount[ArchCurrCpuid()] > 0) + BNE _osExceptionGetSP @ can not switch svc stack + + EXC_SP_SET __svc_stack_top, OS_EXC_SVC_STACK_SIZE, R6, R7 @ Switch to unified exception stack. + ADD R4, R4, #1 + STR R4, [R3] + +_osExceptionGetSP: + MOV R2, R8 @ far + MOV R3, R9 @ fsr + LDR R5, =OsExcHandleEntry @ OsExcHandleEntry(UINT32 excType, ExcContext * excBufAddr) + BX R5 + +_OsExcReturn: + LDR R0, [SP, #(2 * 4)] + AND R0, R0, #CPSR_MASK_MODE + CMP R0, #CPSR_USER_MODE @ User mode + BNE _OsExcReturnToKernel + LDMFD SP, {R13, R14}^ @ load user mode sp and lr + +_OsExcReturnToKernel: + ADD SP, SP, #(2 * 4) + LDMFD SP!, {R1} + MSR SPSR_cxsf, R1 @ Set the return mode SPSR + LDMFD SP!, {R0-R12} + ADD SP, SP, #4 + LDMFD SP!, {LR, PC}^ + + .end diff --git a/arch/arm/arm/src/los_hw_runstop.S b/arch/arm/arm/src/los_hw_runstop.S new file mode 100755 index 00000000..032e9af1 --- /dev/null +++ b/arch/arm/arm/src/los_hw_runstop.S @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "arch_config.h" + + .equ MPIDR_CPUID_MASK, 0xffU + + .extern g_saveAR + .extern g_saveSRContext + + .global OsSRSaveRegister + .global OsSRRestoreRegister + + .fpu vfpv4 + @.fpu neon + .arch armv7a + + .text + +OsSRSaveRegister: + PUSH {R2} + LDR R2, =g_saveAR + STR R0, [R2] + STR R1, [R2, #4] + POP {R2} + + MRC P15, 0, R0, c0, c0, 5 + AND R0, R0, #MPIDR_CPUID_MASK + MOV R1, #72 @This number is the total number of bytes in the task context register(R0~R15, SPSR, CPSR). + MUL R1, R1, R0 + + LDR R0, =g_saveSRContext + ADD R0, R0, R1 + ADD R0, R0, #72 + + MOV R1, SP + STMFD R0!, {R1} + + MRS R1, SPSR + STMFD R0!, {R1} + + MOV R1, LR + STMFD R0!, {R1} @PC + STMFD R0!, {R1} @LR + + STMFD R0!, {R12} + + MOV R12, R0 + + LDR R0, =g_saveAR + LDR R0, [R0] + LDR R1, =g_saveAR + LDR R1, [R1, #4] + + STMFD R12!, {R0-R3} + STMFD R12!, {R4-R11} + + MRS R0, CPSR + STMFD R12!, {R0} + + BX LR + +OsSRRestoreRegister: + MRC P15, 0, R0, c0, c0, 5 + AND R0, R0, #MPIDR_CPUID_MASK + MOV R1, #72 @This number is the total number of bytes in the task context register(R0~R15, SPSR, CPSR). + MUL R1, R1, R0 + + LDR R12, =g_saveSRContext + ADD R12, R12, R1 + + LDMFD R12!, {R0} + MSR CPSR_cxsf, R0 + + LDMFD R12!, {R4-R11} + LDMFD R12!, {R0-R3} + + PUSH {R2} + LDR R2, =g_saveAR + STR R0, [R2] + STR R1, [R2, #4] + POP {R2} + + MOV R0, R12 + LDMFD R0!, {R12} + LDMFD R0!, {R1} @LR + LDMFD R0!, {R1} @PC + + MOV LR, R1 + + LDMFD R0!, {R1} + MSR SPSR_cxsf, R1 + + LDMFD R0!, {R1} + MOV SP, R1 + + LDR R0, =g_saveAR + LDR R0, [R0] + LDR R1, =g_saveAR + LDR R1, [R1, #4] + + BX LR + + .end diff --git a/arch/arm/arm/src/los_hw_tick.c b/arch/arm/arm/src/los_hw_tick.c new file mode 100755 index 00000000..b52f346c --- /dev/null +++ b/arch/arm/arm/src/los_hw_tick.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_sys_pri.h" +#include "los_hwi.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +LITE_OS_SEC_TEXT_INIT UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond) +{ + if ((systemClock == 0) || + (tickPerSecond == 0) || + (tickPerSecond > systemClock)) { + return LOS_ERRNO_TICK_CFG_INVALID; + } + HalClockInit(); + + return LOS_OK; +} + +LITE_OS_SEC_TEXT_INIT VOID OsTickStart(VOID) +{ + HalClockStart(); +} + +LITE_OS_SEC_TEXT_MINOR VOID LOS_GetCpuCycle(UINT32 *highCnt, UINT32 *lowCnt) +{ + UINT64 cycle = HalClockGetCycles(); + + *highCnt = cycle >> 32; /* 32: offset 32 bits and retain high bits */ + *lowCnt = cycle & 0xFFFFFFFFU; +} + +LITE_OS_SEC_TEXT_MINOR UINT64 LOS_CurrNanosec(VOID) +{ + DOUBLE nanos; + + nanos = (DOUBLE)HalClockGetCycles() * OS_SYS_NS_PER_SECOND / g_sysClock; + return (UINT64)nanos; +} + +LITE_OS_SEC_TEXT_MINOR VOID LOS_Udelay(UINT32 usecs) +{ + HalDelayUs(usecs); +} + +LITE_OS_SEC_TEXT_MINOR VOID LOS_Mdelay(UINT32 msecs) +{ + HalDelayUs(msecs * 1000); /* 1000 : 1ms = 1000us */ +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/arch/arm/arm/src/los_hwi.c b/arch/arm/arm/src/los_hwi.c new file mode 100755 index 00000000..733fc010 --- /dev/null +++ b/arch/arm/arm/src/los_hwi.c @@ -0,0 +1,351 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_hwi.h" +#include "los_memory.h" +#include "los_tickless_pri.h" +#include "los_spinlock.h" +#ifdef LOSCFG_KERNEL_CPUP +#include "los_cpup_pri.h" +#endif + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* spinlock for hwi module, only available on SMP mode */ +LITE_OS_SEC_BSS SPIN_LOCK_INIT(g_hwiSpin); +#define HWI_LOCK(state) LOS_SpinLockSave(&g_hwiSpin, &(state)) +#define HWI_UNLOCK(state) LOS_SpinUnlockRestore(&g_hwiSpin, (state)) + +size_t g_intCount[LOSCFG_KERNEL_CORE_NUM] = {0}; +HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM]; +STATIC CHAR *g_hwiFormName[OS_HWI_MAX_NUM] = {0}; +STATIC UINT32 g_hwiFormCnt[OS_HWI_MAX_NUM] = {0}; + +VOID OsIncHwiFormCnt(UINT32 index) +{ + g_hwiFormCnt[index]++; +} + +UINT32 OsGetHwiFormCnt(UINT32 index) +{ + return g_hwiFormCnt[index]; +} + +CHAR *OsGetHwiFormName(UINT32 index) +{ + return g_hwiFormName[index]; +} + +typedef VOID (*HWI_PROC_FUNC0)(VOID); +typedef VOID (*HWI_PROC_FUNC2)(INT32, VOID *); +VOID OsInterrupt(UINT32 intNum) +{ + HwiHandleForm *hwiForm = NULL; + UINT32 *intCnt = NULL; + + intCnt = &g_intCount[ArchCurrCpuid()]; + *intCnt = *intCnt + 1; + +#ifdef LOSCFG_CPUP_INCLUDE_IRQ + OsCpupIrqStart(); +#endif + +#ifdef LOSCFG_KERNEL_TICKLESS + OsTicklessUpdate(intNum); +#endif + hwiForm = (&g_hwiForm[intNum]); +#ifndef LOSCFG_NO_SHARED_IRQ + while (hwiForm->pstNext != NULL) { + hwiForm = hwiForm->pstNext; +#endif + if (hwiForm->uwParam) { + HWI_PROC_FUNC2 func = (HWI_PROC_FUNC2)hwiForm->pfnHook; + if (func != NULL) { + UINTPTR *param = (UINTPTR *)(hwiForm->uwParam); + func((INT32)(*param), (VOID *)(*(param + 1))); + } + } else { + HWI_PROC_FUNC0 func = (HWI_PROC_FUNC0)hwiForm->pfnHook; + if (func != NULL) { + func(); + } + } +#ifndef LOSCFG_NO_SHARED_IRQ + } +#endif + ++g_hwiFormCnt[intNum]; + + *intCnt = *intCnt - 1; +#ifdef LOSCFG_CPUP_INCLUDE_IRQ + OsCpupIrqEnd(intNum); +#endif +} + +STATIC HWI_ARG_T OsHwiCpIrqParam(const HwiIrqParam *irqParam) +{ + HwiIrqParam *paramByAlloc = NULL; + + if (irqParam != NULL) { + paramByAlloc = (HwiIrqParam *)LOS_MemAlloc(m_aucSysMem0, sizeof(HwiIrqParam)); + if (paramByAlloc == NULL) { + return LOS_NOK; + } + (VOID)memcpy_s(paramByAlloc, sizeof(HwiIrqParam), irqParam, sizeof(HwiIrqParam)); + } + /* When "irqParam" is NULL, the function return 0(LOS_OK). */ + return (HWI_ARG_T)paramByAlloc; +} + +#ifdef LOSCFG_NO_SHARED_IRQ +STATIC UINT32 OsHwiDelNoShared(HWI_HANDLE_T hwiNum) +{ + UINT32 intSave; + + HWI_LOCK(intSave); + g_hwiForm[hwiNum].pfnHook = NULL; + if (g_hwiForm[hwiNum].uwParam) { + (VOID)LOS_MemFree(m_aucSysMem0, (VOID *)g_hwiForm[hwiNum].uwParam); + } + g_hwiForm[hwiNum].uwParam = 0; + + HWI_UNLOCK(intSave); + return LOS_OK; +} + +STATIC UINT32 OsHwiCreateNoShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode, + HWI_PROC_FUNC hwiHandler, const HwiIrqParam *irqParam) +{ + HWI_ARG_T retParam; + UINT32 intSave; + + HWI_LOCK(intSave); + if (g_hwiForm[hwiNum].pfnHook == NULL) { + g_hwiForm[hwiNum].pfnHook = hwiHandler; + + retParam = OsHwiCpIrqParam(irqParam); + if (retParam == LOS_NOK) { + HWI_UNLOCK(intSave); + return OS_ERRNO_HWI_NO_MEMORY; + } + g_hwiForm[hwiNum].uwParam = retParam; + } else { + HWI_UNLOCK(intSave); + return OS_ERRNO_HWI_ALREADY_CREATED; + } + HWI_UNLOCK(intSave); + return LOS_OK; +} +#else +STATIC UINT32 OsHwiDelShared(HWI_HANDLE_T hwiNum, const HwiIrqParam *irqParam) +{ + HwiHandleForm *hwiForm = NULL; + HwiHandleForm *hwiFormtmp = NULL; + UINT32 hwiValid = FALSE; + UINT32 intSave; + + HWI_LOCK(intSave); + hwiForm = &g_hwiForm[hwiNum]; + hwiFormtmp = hwiForm; + + if ((hwiForm->uwParam & IRQF_SHARED) && ((irqParam == NULL) || (irqParam->pDevId == NULL))) { + HWI_UNLOCK(intSave); + return OS_ERRNO_HWI_SHARED_ERROR; + } + + if ((hwiForm->pstNext != NULL) && !(hwiForm->uwParam & IRQF_SHARED)) { + hwiForm = hwiForm->pstNext; + if (hwiForm->uwParam) { + (VOID)LOS_MemFree(m_aucSysMem0, (VOID *)hwiForm->uwParam); + } + (VOID)LOS_MemFree(m_aucSysMem0, hwiForm); + hwiFormtmp->pstNext = NULL; + + g_hwiFormName[hwiNum] = NULL; + + HWI_UNLOCK(intSave); + return LOS_OK; + } + hwiForm = hwiForm->pstNext; + while (hwiForm != NULL) { + if (((HwiIrqParam *)(hwiForm->uwParam))->pDevId != irqParam->pDevId) { + hwiFormtmp = hwiForm; + hwiForm = hwiForm->pstNext; + } else { + hwiFormtmp->pstNext = hwiForm->pstNext; + (VOID)LOS_MemFree(m_aucSysMem0, (VOID *)hwiForm->uwParam); + (VOID)LOS_MemFree(m_aucSysMem0, hwiForm); + + hwiValid = TRUE; + break; + } + } + + if (hwiValid != TRUE) { + HWI_UNLOCK(intSave); + return OS_ERRNO_HWI_HWINUM_UNCREATE; + } + + if (g_hwiForm[hwiNum].pstNext == NULL) { + g_hwiForm[hwiNum].uwParam = 0; + g_hwiFormName[hwiNum] = NULL; + } + + HWI_UNLOCK(intSave); + return LOS_OK; +} + +STATIC UINT32 OsHwiCreateShared(HWI_HANDLE_T hwiNum, HWI_MODE_T hwiMode, + HWI_PROC_FUNC hwiHandler, const HwiIrqParam *irqParam) +{ + UINT32 intSave; + HwiHandleForm *hwiFormNode = NULL; + HwiHandleForm *hwiForm = NULL; + HwiIrqParam *hwiParam = NULL; + HWI_MODE_T modeResult = hwiMode & IRQF_SHARED; + + if (modeResult && ((irqParam == NULL) || (irqParam->pDevId == NULL))) { + return OS_ERRNO_HWI_SHARED_ERROR; + } + + HWI_LOCK(intSave); + + hwiForm = &g_hwiForm[hwiNum]; + if ((hwiForm->pstNext != NULL) && ((modeResult == 0) || (!(hwiForm->uwParam & IRQF_SHARED)))) { + HWI_UNLOCK(intSave); + return OS_ERRNO_HWI_SHARED_ERROR; + } + + while (hwiForm->pstNext != NULL) { + hwiForm = hwiForm->pstNext; + hwiParam = (HwiIrqParam *)(hwiForm->uwParam); + if (hwiParam->pDevId == irqParam->pDevId) { + HWI_UNLOCK(intSave); + return OS_ERRNO_HWI_ALREADY_CREATED; + } + } + + hwiFormNode = (HwiHandleForm *)LOS_MemAlloc(m_aucSysMem0, sizeof(HwiHandleForm)); + if (hwiFormNode == NULL) { + HWI_UNLOCK(intSave); + return OS_ERRNO_HWI_NO_MEMORY; + } + + hwiFormNode->uwParam = OsHwiCpIrqParam(irqParam); + if (hwiFormNode->uwParam == LOS_NOK) { + HWI_UNLOCK(intSave); + (VOID)LOS_MemFree(m_aucSysMem0, hwiFormNode); + return OS_ERRNO_HWI_NO_MEMORY; + } + + hwiFormNode->pfnHook = hwiHandler; + hwiFormNode->pstNext = (struct tagHwiHandleForm *)NULL; + hwiForm->pstNext = hwiFormNode; + + if ((irqParam != NULL) && (irqParam->pName != NULL)) { + g_hwiFormName[hwiNum] = (CHAR *)irqParam->pName; + } + + g_hwiForm[hwiNum].uwParam = modeResult; + + HWI_UNLOCK(intSave); + return LOS_OK; +} +#endif + +/* + * Description : initialization of the hardware interrupt + */ +LITE_OS_SEC_TEXT_INIT VOID OsHwiInit(VOID) +{ + UINT32 hwiNum; + + for (hwiNum = 0; hwiNum < OS_HWI_MAX_NUM; hwiNum++) { + g_hwiForm[hwiNum].pfnHook = NULL; + g_hwiForm[hwiNum].uwParam = 0; + g_hwiForm[hwiNum].pstNext = NULL; + } + + (VOID)memset_s(g_hwiFormName, (sizeof(CHAR *) * OS_HWI_MAX_NUM), 0, (sizeof(CHAR *) * OS_HWI_MAX_NUM)); + + HalIrqInit(); + + return; +} + +LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, + HWI_PRIOR_T hwiPrio, + HWI_MODE_T hwiMode, + HWI_PROC_FUNC hwiHandler, + HwiIrqParam *irqParam) +{ + UINT32 ret; + + (VOID)hwiPrio; + if (hwiHandler == NULL) { + return OS_ERRNO_HWI_PROC_FUNC_NULL; + } + if ((hwiNum > OS_USER_HWI_MAX) || ((INT32)hwiNum < OS_USER_HWI_MIN)) { + return OS_ERRNO_HWI_NUM_INVALID; + } + +#ifdef LOSCFG_NO_SHARED_IRQ + ret = OsHwiCreateNoShared(hwiNum, hwiMode, hwiHandler, irqParam); +#else + ret = OsHwiCreateShared(hwiNum, hwiMode, hwiHandler, irqParam); +#endif + return ret; +} + +LITE_OS_SEC_TEXT_INIT UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam) +{ + UINT32 ret; + + if ((hwiNum > OS_USER_HWI_MAX) || ((INT32)hwiNum < OS_USER_HWI_MIN)) { + return OS_ERRNO_HWI_NUM_INVALID; + } + +#ifdef LOSCFG_NO_SHARED_IRQ + ret = OsHwiDelNoShared(hwiNum); +#else + ret = OsHwiDelShared(hwiNum, irqParam); +#endif + return ret; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/arch/arm/arm/src/startup/reset_vector_mp.S b/arch/arm/arm/src/startup/reset_vector_mp.S new file mode 100755 index 00000000..dc08b6dc --- /dev/null +++ b/arch/arm/arm/src/startup/reset_vector_mp.S @@ -0,0 +1,505 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#define ASSEMBLY +#include "arch_config.h" +#include "los_vm_boot.h" +#include "los_vm_zone.h" +#include "los_mmu_descriptor_v6.h" +#undef ASSEMBLY + + + .global __exc_stack_top + .global __irq_stack_top + .global __fiq_stack_top + .global __svc_stack_top + .global __abt_stack_top + .global __undef_stack_top + .global __exc_stack + .global __irq_stack + .global __fiq_stack + .global __svc_stack + .global __abt_stack + .global __undef_stack + + .extern __bss_start + .extern __bss_end + .extern hal_clock_initialize_start + .extern los_bss_init + .extern _osExceptFiqHdl + .extern _osExceptAddrAbortHdl + .extern _osExceptDataAbortHdl + .extern _osExceptPrefetchAbortHdl + .extern _osExceptSwiHdl + .extern _osExceptUndefInstrHdl + .extern __stack_chk_guard_setup + .extern g_firstPageTable + .extern g_mmuJumpPageTable + + .equ MPIDR_CPUID_MASK, 0xffU + + .fpu vfpv4 + .arm + +/* param0 is stack bottom, param1 is stack size, r12 hold cpu id */ +.macro EXC_SP_SET param0, param1 + ldr r1, =\param0 + mov r0, \param1 + bl sp_set +.endm + +/* param0 is stack top, param1 is stack size, param2 is magic num */ +.macro STACK_MAGIC_SET param0, param1, param2 + ldr r0, =\param0 + mov r1, \param1 + ldr r2, =\param2 + bl excstack_magic +.endm + +/* param0 is physical address, param1 virtual address, param2 is sizes, param3 is flag */ +.macro PAGE_TABLE_SET param0, param1, param2, param3 + ldr r6, =\param0 + ldr r7, =\param1 + ldr r8, =\param2 + ldr r10, =\param3 + bl page_table_build +.endm + .code 32 + .section ".vectors","ax" + + .global __exception_handlers +__exception_handlers: + /* + *Assumption: ROM code has these vectors at the hardware reset address. + *A simple jump removes any address-space dependencies [i.e. safer] + */ + b reset_vector + b _osExceptUndefInstrHdl + b _osExceptSwiHdl + b _osExceptPrefetchAbortHdl + b _osExceptDataAbortHdl + b _osExceptAddrAbortHdl + b OsIrqHandler + b _osExceptFiqHdl + + /* Startup code which will get the machine into supervisor mode */ + .global reset_vector + .type reset_vector,function +reset_vector: + /* clear register TPIDRPRW */ + mov r0, #0 + mcr p15, 0, r0, c13, c0, 4 + /* do some early cpu setup: i/d cache disable, mmu disabled */ + mrc p15, 0, r0, c1, c0, 0 + bic r0, #(1<<12) + bic r0, #(1<<2 | 1<<0) + mcr p15, 0, r0, c1, c0, 0 + + /* r11: delta of physical address and virtual address */ + adr r11, pa_va_offset + ldr r0, [r11] + sub r11, r11, r0 + + mrc p15, 0, r12, c0, c0, 5 /* r12: get cpuid */ + and r12, r12, #MPIDR_CPUID_MASK + cmp r12, #0 + bne secondary_cpu_init + + /* if we need to relocate to proper location or not */ + adr r4, __exception_handlers /* r4: base of load address */ + ldr r5, =SYS_MEM_BASE /* r5: base of physical address */ + subs r12, r4, r5 /* r12: delta of load address and physical address */ + beq reloc_img_to_bottom_done /* if we load image at the bottom of physical address */ + + /* we need to relocate image at the bottom of physical address */ + ldr r7, =__exception_handlers /* r7: base of linked address (or vm address) */ + ldr r6, =__bss_start /* r6: end of linked address (or vm address) */ + sub r6, r7 /* r6: delta of linked address (or vm address) */ + add r6, r4 /* r6: end of load address */ + +reloc_img_to_bottom_loop: + ldr r7, [r4], #4 + str r7, [r5], #4 + cmp r4, r6 + bne reloc_img_to_bottom_loop + sub pc, r12 + nop + sub r11, r11, r12 /* r11: eventual address offset */ + +reloc_img_to_bottom_done: + ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */ + add r4, r4, r11 + bl page_table_clear + + PAGE_TABLE_SET SYS_MEM_BASE, KERNEL_VMM_BASE, KERNEL_VMM_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS + PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED + PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_DEVICE_BASE, PERIPH_DEVICE_SIZE, MMU_INITIAL_MAP_DEVICE + PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_CACHED_BASE, PERIPH_CACHED_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS + PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_UNCACHED_BASE, PERIPH_UNCACHED_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED + + orr r8, r4, #MMU_TTBRx_FLAGS /* r8 = r4 and set cacheable attributes on translation walk */ + ldr r4, =g_mmuJumpPageTable /* r4: jump pagetable vaddr */ + add r4, r4, r11 + ldr r4, [r4] + add r4, r4, r11 /* r4: jump pagetable paddr */ + bl page_table_clear + + /* build 1M section mapping, in order to jump va during turing on mmu:pa == pa, va == pa */ + mov r6, pc + mov r7, r6 /* r7: pa (MB aligned)*/ + lsr r6, r6, #20 /* r6: va l1 index */ + ldr r10, =MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS + add r12, r10, r6, lsl #20 /* r12: pa |flags */ + str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[paIndex] = pt entry */ + rsb r7, r11, r6, lsl #20 /* r7: va */ + str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[vaIndex] = pt entry */ + + bl _bootaddr_setup + + bl mmu_setup /* set up the mmu */ + + /* clear out the interrupt and exception stack and set magic num to check the overflow */ + ldr r0, =__undef_stack + ldr r1, =__exc_stack_top + bl stack_init + + STACK_MAGIC_SET __undef_stack, #OS_EXC_UNDEF_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __abt_stack, #OS_EXC_ABT_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __irq_stack, #OS_EXC_IRQ_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __fiq_stack, #OS_EXC_FIQ_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __svc_stack, #OS_EXC_SVC_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __exc_stack, #OS_EXC_STACK_SIZE, OS_STACK_MAGIC_WORD + +warm_reset: + /* initialize interrupt/exception environments */ + mov r0, #(CPSR_IRQ_DISABLE |CPSR_FIQ_DISABLE|CPSR_IRQ_MODE) + msr cpsr, r0 + EXC_SP_SET __irq_stack_top, #OS_EXC_IRQ_STACK_SIZE + + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_UNDEF_MODE) + msr cpsr, r0 + EXC_SP_SET __undef_stack_top, #OS_EXC_UNDEF_STACK_SIZE + + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_ABT_MODE) + msr cpsr, r0 + EXC_SP_SET __abt_stack_top, #OS_EXC_ABT_STACK_SIZE + + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_FIQ_MODE) + msr cpsr, r0 + EXC_SP_SET __fiq_stack_top, #OS_EXC_FIQ_STACK_SIZE + + /* initialize CPSR (machine state register) */ + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE) + msr cpsr, r0 + + /* Note: some functions in LIBGCC1 will cause a "restore from SPSR"!! */ + msr spsr, r0 + + /* get cpuid and keep it in r12 */ + mrc p15, 0, r12, c0, c0, 5 + and r12, r12, #MPIDR_CPUID_MASK + + /* set svc stack, every cpu has OS_EXC_SVC_STACK_SIZE stack */ + ldr r0, =__svc_stack_top + mov r2, #OS_EXC_SVC_STACK_SIZE + mul r2, r2, r12 + sub r0, r0, r2 + mov sp, r0 + + /* enable fpu+neon */ +#ifndef LOSCFG_TEE_ENABLE + MRC p15, 0, r0, c1, c1, 2 + ORR r0, r0, #0xC00 + BIC r0, r0, #0xC000 + MCR p15, 0, r0, c1, c1, 2 + + LDR r0, =(0xF << 20) + MCR p15, 0, r0, c1, c0, 2 +#endif + + MOV r3, #0x40000000 + VMSR FPEXC, r3 + + LDR r0, =__exception_handlers + MCR p15, 0, r0, c12, c0, 0 + + cmp r12, #0 + bne cpu_start + +clear_bss: + ldr r1, =__bss_start + ldr r2, =__bss_end + mov r0, #0 + +bss_loop: + cmp r1, r2 + strlo r0, [r1], #4 + blo bss_loop + +#if defined(LOSCFG_CC_STACKPROTECTOR_ALL) || \ + defined(LOSCFG_CC_STACKPROTECTOR_STRONG) || \ + defined(LOSCFG_CC_STACKPROTECTOR) + bl __stack_chk_guard_setup +#endif + +#ifdef LOSCFG_GDB_DEBUG + /* GDB_START - generate a compiled_breadk,This function will get GDB stubs started, with a proper environment */ + bl GDB_START + .word 0xe7ffdeff +#endif + + bl main + +_start_hang: + b _start_hang + +mmu_setup: + mov r12, #0 + mcr p15, 0, r12, c8, c7, 0 /* Set c8 to control the TLB and set the mapping to invalid */ + isb + mcr p15, 0, r12, c2, c0, 2 /* Initialize the c2 register */ + isb + orr r12, r4, #MMU_TTBRx_FLAGS + mcr p15, 0, r12, c2, c0, 0 /* Set attributes and set temp page table */ + isb + mov r12, #0x7 /* 0b0111 */ + mcr p15, 0, r12, c3, c0, 0 /* Set DACR with 0b0111, client and manager domian */ + isb + mrc p15, 0, r12, c1, c0, 1 /* ACTLR, Auxlliary Control Register */ + orr r12, r12, #(1 << 6) /* SMP, Enables coherent requests to the processor. */ + orr r12, r12, #(1 << 2) /* Enable D-side prefetch */ + orr r12, r12, #(1 << 11) /* Global BP Enable bit */ + mcr p15, 0, r12, c1, c0, 1 /* ACTLR, Auxlliary Control Register */ + dsb + mrc p15, 0, r12, c1, c0, 0 + bic r12, #(1 << 29 | 1 << 28) + orr r12, #(1 << 0) + bic r12, #(1 << 1) + orr r12, #(1 << 2) + orr r12, #(1 << 12) + mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */ + isb + ldr pc, =1f /* Convert to VA */ +1: + mcr p15, 0, r8, c2, c0, 0 /* Go to the base address saved in C2: Jump to the page table */ + isb + mov r12, #0 + mcr p15, 0, r12, c8, c7, 0 + isb + sub lr, r11 /* adjust lr with delta of physical address and virtual address */ + bx lr + + .code 32 + + .global reset_platform + .type reset_platform,function +reset_platform: +#ifdef A7SEM_HAL_ROM_MONITOR + /* initialize CPSR (machine state register) */ + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE) + msr cpsr, r0 + b warm_reset +#else + mov r0, #0 + mov pc, r0 // Jump to reset vector +#endif +cpu_start: + ldr r4, =g_firstPageTable /* r4 = physical address of translation table and clear it */ + add r4, r4, r11 + orr r8, r4, #MMU_TTBRx_FLAGS + + ldr r4, =g_mmuJumpPageTable /* r4 = tt_trampoline vaddr */ + add r4, r4, r11 + ldr r4, [r4] + add r4, r4, r11 /* r4 = tt_trampoline paddr */ + + bl mmu_setup + bl secondary_cpu_start + b . + +secondary_cpu_init: +#ifdef LOSCFG_TEE_ENABLE + /* enable fpu+neon */ + ldr r0, =0x60c00 + MCR p15, 0, r0, c1, c1, 2 + + LDR r0, =(0xF << 20) + MCR p15, 0, r0, c1, c0, 2 + cps #0x16 + mov r1, #0x25 + mcr p15, 0, r1, c1, c1, 0 + cps #0x13 +#endif + bl warm_reset + +/* + * set sp for current cpu + * r1 is stack bottom, r0 is stack size, r12 hold cpu id + */ +sp_set: + mrc p15, 0, r12, c0, c0, 5 + and r12, r12, #MPIDR_CPUID_MASK + mul r3, r0, r12 + sub r2, r1, r3 + mov sp, r2 + bx lr /* set sp */ + +/* + * r4: page table base address + * r5 and r6 will be used as variable + */ +page_table_clear: + mov r5, #0 + mov r6, #0 +0: + str r5, [r4, r6, lsl #2] + add r6, #1 + cmp r6, #0x1000 /* r6 < 4096 */ + blt 0b + bx lr + +/* + * r4: page table base address + * r6: physical address + * r7: virtual address + * r8: sizes + * r10: flags + * r9 and r12 will be used as variable + */ +page_table_build: + mov r9, r6 + bfc r9, #20, #12 /* r9: pa % MB */ + add r8, r8, r9 + add r8, r8, #(1 << 20) + sub r8, r8, #1 + lsr r6, #20 /* r6 = physical address / MB */ + lsr r7, #20 /* r7 = virtual address / MB */ + lsr r8, #20 /* r8 = roundup(size, MB) */ + +page_table_build_loop: + orr r12, r10, r6, lsl #20 /* r12: flags | physAddr */ + str r12, [r4, r7, lsl #2] /* gPgTable[l1Index] = physAddr | flags */ + add r6, #1 /* physAddr+ */ + add r7, #1 /* l1Index++ */ + subs r8, #1 /* sizes-- */ + bne page_table_build_loop + bx lr + +/* + * init stack to initial value + * r0 is stack mem start, r1 is stack mem end + */ +stack_init: + ldr r2, =OS_STACK_INIT + ldr r3, =OS_STACK_INIT + /* Main loop sets 32 bytes at a time. */ +stack_init_loop: + .irp offset, #0, #8, #16, #24 + strd r2, r3, [r0, \offset] + .endr + add r0, #32 + cmp r0, r1 + blt stack_init_loop + bx lr + +pa_va_offset: + .word . + +/* + * set magic num to stack top for all cpu + * r0 is stack top, r1 is stack size, r2 is magic num + */ +excstack_magic: + mov r3, #0 +excstack_magic_loop: + str r2, [r0] + add r0, r0, r1 + add r3, r3, #1 + cmp r3, #CORE_NUM + blt excstack_magic_loop + bx lr + +/* + * 0xe51ff004 = "ldr pc, [pc, #-4]" + * next addr value will be the real booting addr + */ +_bootaddr_setup: + mov r0, #0 + ldr r1, =0xe51ff004 + str r1, [r0] + + add r0, r0, #4 + ldr r1, =SYS_MEM_BASE + str r1, [r0] + + dsb + isb + + bx lr + +init_done: + .long 0xDEADB00B + + .code 32 + .data + +init_flag: + .balign 4 + .long 0 + + /* + * Temporary interrupt stack + */ + .section ".int_stack", "wa", %nobits + .align 3 + +__undef_stack: + .space OS_EXC_UNDEF_STACK_SIZE * CORE_NUM +__undef_stack_top: + +__abt_stack: + .space OS_EXC_ABT_STACK_SIZE * CORE_NUM +__abt_stack_top: + +__irq_stack: + .space OS_EXC_IRQ_STACK_SIZE * CORE_NUM +__irq_stack_top: + +__fiq_stack: + .space OS_EXC_FIQ_STACK_SIZE * CORE_NUM +__fiq_stack_top: + +__svc_stack: + .space OS_EXC_SVC_STACK_SIZE * CORE_NUM +__svc_stack_top: + +__exc_stack: + .space OS_EXC_STACK_SIZE * CORE_NUM +__exc_stack_top: diff --git a/arch/arm/arm/src/startup/reset_vector_up.S b/arch/arm/arm/src/startup/reset_vector_up.S new file mode 100755 index 00000000..d7de4777 --- /dev/null +++ b/arch/arm/arm/src/startup/reset_vector_up.S @@ -0,0 +1,473 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define ASSEMBLY +#include "arch_config.h" +#include "los_vm_boot.h" +#include "los_vm_zone.h" +#include "los_mmu_descriptor_v6.h" +#undef ASSEMBLY + + + .global __exc_stack_top + .global __irq_stack_top + .global __fiq_stack_top + .global __svc_stack_top + .global __abt_stack_top + .global __undef_stack_top + .global __exc_stack + .global __irq_stack + .global __fiq_stack + .global __svc_stack + .global __abt_stack + .global __undef_stack + + .extern __bss_start + .extern __bss_end + .extern hal_clock_initialize_start + .extern los_bss_init + .extern _osExceptFiqHdl + .extern _osExceptAddrAbortHdl + .extern _osExceptDataAbortHdl + .extern _osExceptPrefetchAbortHdl + .extern _osExceptSwiHdl + .extern _osExceptUndefInstrHdl + .extern __stack_chk_guard_setup + .extern g_firstPageTable + .extern g_mmuJumpPageTable + + .equ MPIDR_CPUID_MASK, 0xffU + + .fpu vfpv4 + .arm + +/* param0 is stack bottom, param1 is stack size, r11 hold cpu id */ +.macro EXC_SP_SET param0, param1 + ldr r1, =\param0 + mov r0, \param1 + bl sp_set +.endm + +/* param0 is stack top, param1 is stack size, param2 is magic num */ +.macro STACK_MAGIC_SET param0, param1, param2 + ldr r0, =\param0 + mov r1, \param1 + ldr r2, =\param2 + bl excstack_magic +.endm + +/* param0 is physical address, param1 virtual address, param2 is sizes, param3 is flag */ +.macro PAGE_TABLE_SET param0, param1, param2, param3 + ldr r6, =\param0 + ldr r7, =\param1 + ldr r8, =\param2 + ldr r10, =\param3 + bl page_table_build +.endm + .code 32 + .section ".vectors","ax" + +__exception_handlers: + /* + *Assumption: ROM code has these vectors at the hardware reset address. + *A simple jump removes any address-space dependencies [i.e. safer] + */ + b reset_vector + b _osExceptUndefInstrHdl + b _osExceptSwiHdl + b _osExceptPrefetchAbortHdl + b _osExceptDataAbortHdl + b _osExceptAddrAbortHdl + b OsIrqHandler + b _osExceptFiqHdl + + /* Startup code which will get the machine into supervisor mode */ + .global reset_vector + .type reset_vector,function +reset_vector: + /* do some early cpu setup: i/d cache disable, mmu disabled */ + mrc p15, 0, r0, c1, c0, 0 + bic r0, #(1<<12) + bic r0, #(1<<2 | 1<<0) + mcr p15, 0, r0, c1, c0, 0 + + /* r11: delta of physical address and virtual address */ + adr r11, pa_va_offset + ldr r0, [r11] + sub r11, r11, r0 + + /* if we need to relocate to proper location or not */ + adr r4, __exception_handlers /* r4: base of load address */ + ldr r5, =SYS_MEM_BASE /* r5: base of physical address */ + subs r12, r4, r5 /* r12: delta of load address and physical address */ + beq reloc_img_to_bottom_done /* if we load image at the bottom of physical address */ + + /* we need to relocate image at the bottom of physical address */ + ldr r7, =__exception_handlers /* r7: base of linked address (or vm address) */ + ldr r6, =__bss_start /* r6: end of linked address (or vm address) */ + sub r6, r7 /* r6: delta of linked address (or vm address) */ + add r6, r4 /* r6: end of load address */ + +reloc_img_to_bottom_loop: + ldr r7, [r4], #4 + str r7, [r5], #4 + cmp r4, r6 + bne reloc_img_to_bottom_loop + sub pc, r12 + nop + sub r11, r11, r12 /* r11: eventual address offset */ + +reloc_img_to_bottom_done: + ldr r4, =g_firstPageTable /* r4: physical address of translation table and clear it */ + add r4, r4, r11 + bl page_table_clear + + PAGE_TABLE_SET SYS_MEM_BASE, KERNEL_VMM_BASE, KERNEL_VMM_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS + PAGE_TABLE_SET SYS_MEM_BASE, UNCACHED_VMM_BASE, UNCACHED_VMM_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED + PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_DEVICE_BASE, PERIPH_DEVICE_SIZE, MMU_INITIAL_MAP_DEVICE + PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_CACHED_BASE, PERIPH_CACHED_SIZE, MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS + PAGE_TABLE_SET PERIPH_PMM_BASE, PERIPH_UNCACHED_BASE, PERIPH_UNCACHED_SIZE, MMU_INITIAL_MAP_STRONGLY_ORDERED + + orr r8, r4, #MMU_TTBRx_FLAGS /* r8 = r4 and set cacheable attributes on translation walk */ + ldr r4, =g_mmuJumpPageTable /* r4: jump pagetable vaddr */ + add r4, r4, r11 + ldr r4, [r4] + add r4, r4, r11 /* r4: jump pagetable paddr */ + bl page_table_clear + + /* build 1M section mapping, in order to jump va during turing on mmu:pa == pa, va == pa */ + mov r6, pc + mov r7, r6 /* r7: pa (MB aligned)*/ + lsr r6, r6, #20 /* r6: va l1 index */ + ldr r10, =MMU_DESCRIPTOR_KERNEL_L1_PTE_FLAGS + add r12, r10, r6, lsl #20 /* r12: pa |flags */ + str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[paIndex] = pt entry */ + rsb r7, r11, r6, lsl #20 /* r7: va */ + str r12, [r4, r7, lsr #(20 - 2)] /* jumpTable[vaIndex] = pt entry */ + + bl mmu_setup /* set up the mmu */ + + /* get cpuid and keep it in r11 */ + mrc p15, 0, r11, c0, c0, 5 + and r11, r11, #MPIDR_CPUID_MASK + cmp r11, #0 + bne excstatck_loop_done + +excstatck_loop: + /* clear out the interrupt and exception stack and set magic num to check the overflow */ + ldr r0, =__undef_stack + ldr r1, =__exc_stack_top + bl stack_init + + STACK_MAGIC_SET __undef_stack, #OS_EXC_UNDEF_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __abt_stack, #OS_EXC_ABT_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __irq_stack, #OS_EXC_IRQ_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __fiq_stack, #OS_EXC_FIQ_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __svc_stack, #OS_EXC_SVC_STACK_SIZE, OS_STACK_MAGIC_WORD + STACK_MAGIC_SET __exc_stack, #OS_EXC_STACK_SIZE, OS_STACK_MAGIC_WORD + +excstatck_loop_done: +warm_reset: + /* initialize interrupt/exception environments */ + mov r0, #(CPSR_IRQ_DISABLE |CPSR_FIQ_DISABLE|CPSR_IRQ_MODE) + msr cpsr, r0 + EXC_SP_SET __irq_stack_top, #OS_EXC_IRQ_STACK_SIZE + + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_UNDEF_MODE) + msr cpsr, r0 + EXC_SP_SET __undef_stack_top, #OS_EXC_UNDEF_STACK_SIZE + + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_ABT_MODE) + msr cpsr, r0 + EXC_SP_SET __abt_stack_top, #OS_EXC_ABT_STACK_SIZE + + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_FIQ_MODE) + msr cpsr, r0 + EXC_SP_SET __fiq_stack_top, #OS_EXC_FIQ_STACK_SIZE + + /* initialize CPSR (machine state register) */ + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE) + msr cpsr, r0 + + /* Note: some functions in LIBGCC1 will cause a "restore from SPSR"!! */ + msr spsr, r0 + + /* set svc stack, every cpu has OS_EXC_SVC_STACK_SIZE stack */ + ldr r0, =__svc_stack_top + mov r2, #OS_EXC_SVC_STACK_SIZE + mul r2, r2, r11 + sub r0, r0, r2 + mov sp, r0 + + /* enable fpu+neon */ + MRC p15, 0, r0, c1, c1, 2 + ORR r0, r0, #0xC00 + BIC r0, r0, #0xC000 + MCR p15, 0, r0, c1, c1, 2 + + LDR r0, =(0xF << 20) + MCR p15, 0, r0, c1, c0, 2 + + MOV r3, #0x40000000 + VMSR FPEXC, r3 + + LDR r0, =__exception_handlers + MCR p15, 0, r0, c12, c0, 0 + + cmp r11, #0 + bne cpu_start + +clear_bss: + ldr r1, =__bss_start + ldr r2, =__bss_end + mov r0, #0 + +bss_loop: + cmp r1, r2 + strlo r0, [r1], #4 + blo bss_loop + +#if defined(LOSCFG_CC_STACKPROTECTOR_ALL) || \ + defined(LOSCFG_CC_STACKPROTECTOR_STRONG) || \ + defined(LOSCFG_CC_STACKPROTECTOR) + bl __stack_chk_guard_setup +#endif + +#ifdef LOSCFG_GDB_DEBUG + /* GDB_START - generate a compiled_breadk,This function will get GDB stubs started, with a proper environment */ + bl GDB_START + .word 0xe7ffdeff +#endif + + bl main + +_start_hang: + b _start_hang + +mmu_setup: + mov r12, #0 + mcr p15, 0, r12, c8, c7, 0 /* Set c8 to control the TLB and set the mapping to invalid */ + isb + + mcr p15, 0, r12, c2, c0, 2 /* Initialize the c2 register */ + isb + + orr r12, r4, #MMU_TTBRx_FLAGS + mcr p15, 0, r12, c2, c0, 0 /* Set attributes and set temp page table */ + isb + + mov r12, #0x7 /* 0b0111 */ + mcr p15, 0, r12, c3, c0, 0 /* Set DACR with 0b0111, client and manager domian */ + isb + + mrc p15, 0, r12, c1, c0, 0 + bic r12, #(1 << 29 | 1 << 28) + orr r12, #(1 << 0) + bic r12, #(1 << 1) + orr r12, #(1 << 2) + orr r12, #(1 << 12) + mcr p15, 0, r12, c1, c0, 0 /* Set SCTLR with r12: Turn on the MMU, I/D cache Disable TRE/AFE */ + isb + + ldr pc, =1f /* Convert to VA */ +1: + mcr p15, 0, r8, c2, c0, 0 /* Go to the base address saved in C2: Jump to the page table */ + isb + + mov r12, #0 + mcr p15, 0, r12, c8, c7, 0 + isb + + sub lr, r11 /* adjust lr with delta of physical address and virtual address */ + bx lr + + .code 32 + + .global reset_platform + .type reset_platform,function +reset_platform: +#ifdef A7SEM_HAL_ROM_MONITOR + /* initialize CPSR (machine state register) */ + mov r0, #(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SVC_MODE) + msr cpsr, r0 + b warm_reset +#else + mov r0, #0 + mov pc, r0 // Jump to reset vector +#endif +cpu_start: + bl secondary_cpu_start + b . + + + +/* + * set sp for current cpu + * r1 is stack bottom, r0 is stack size, r11 hold cpu id + */ +sp_set: + mul r3, r0, r11 + sub r2, r1, r3 + mov sp, r2 + bx lr /* set sp */ + +/* + * r4: page table base address + * r5 and r6 will be used as variable + */ +page_table_clear: + mov r5, #0 + mov r6, #0 +0: + str r5, [r4, r6, lsl #2] + add r6, #1 + cmp r6, #0x1000 /* r6 < 4096 */ + blt 0b + bx lr + +/* + * r4: page table base address + * r6: physical address + * r7: virtual address + * r8: sizes + * r10: flags + * r9 and r12 will be used as variable + */ +page_table_build: + mov r9, r6 + bfc r9, #20, #12 /* r9: pa % MB */ + add r8, r8, r9 + add r8, r8, #(1 << 20) + sub r8, r8, #1 + lsr r6, #20 /* r6 = physical address / MB */ + lsr r7, #20 /* r7 = virtual address / MB */ + lsr r8, #20 /* r8 = roundup(size, MB) */ + +page_table_build_loop: + orr r12, r10, r6, lsl #20 /* r12: flags | physAddr */ + str r12, [r4, r7, lsl #2] /* gPgTable[l1Index] = physAddr | flags */ + add r6, #1 /* physAddr+ */ + add r7, #1 /* l1Index++ */ + subs r8, #1 /* sizes-- */ + bne page_table_build_loop + bx lr + +/* + * init stack to initial value + * r0 is stack mem start, r1 is stack mem end + */ +stack_init: + ldr r2, =OS_STACK_INIT + ldr r3, =OS_STACK_INIT + /* Main loop sets 32 bytes at a time. */ +stack_init_loop: + .irp offset, #0, #8, #16, #24 + strd r2, r3, [r0, \offset] + .endr + add r0, #32 + cmp r0, r1 + blt stack_init_loop + bx lr + +pa_va_offset: + .word . + +/* + * set magic num to stack top for all cpu + * r0 is stack top, r1 is stack size, r2 is magic num + */ +excstack_magic: + mov r3, #0 +excstack_magic_loop: + str r2, [r0] + add r0, r0, r1 + add r3, r3, #1 + cmp r3, #CORE_NUM + blt excstack_magic_loop + bx lr + +/* + * 0xe51ff004 = "ldr pc, [pc, #-4]" + * next addr value will be the real booting addr + */ +_bootaddr_setup: + mov r0, #0 + ldr r1, =0xe51ff004 + str r1, [r0] + + add r0, r0, #4 + ldr r1, =SYS_MEM_BASE + str r1, [r0] + + dsb + isb + + bx lr + +init_done: + .long 0xDEADB00B + + .code 32 + .data + +init_flag: + .balign 4 + .long 0 + + /* + * Temporary interrupt stack + */ + .section ".int_stack", "wa", %nobits + .align 3 + +__undef_stack: + .space OS_EXC_UNDEF_STACK_SIZE * CORE_NUM +__undef_stack_top: + +__abt_stack: + .space OS_EXC_ABT_STACK_SIZE * CORE_NUM +__abt_stack_top: + +__irq_stack: + .space OS_EXC_IRQ_STACK_SIZE * CORE_NUM +__irq_stack_top: + +__fiq_stack: + .space OS_EXC_FIQ_STACK_SIZE * CORE_NUM +__fiq_stack_top: + +__svc_stack: + .space OS_EXC_SVC_STACK_SIZE * CORE_NUM +__svc_stack_top: + +__exc_stack: + .space OS_EXC_STACK_SIZE * CORE_NUM +__exc_stack_top: diff --git a/arch/arm/arm/src/strncpy_from_user.c b/arch/arm/arm/src/strncpy_from_user.c new file mode 100755 index 00000000..0e307f64 --- /dev/null +++ b/arch/arm/arm/src/strncpy_from_user.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_strncpy_from_user.h" +#include "los_user_get.h" +#include "los_vm_map.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count) +{ + CHAR character; + INT32 i; + INT32 maxCount; + size_t offset = 0; + + if ((!LOS_IsKernelAddress((VADDR_T)(UINTPTR)dst)) || (!LOS_IsUserAddress((VADDR_T)(UINTPTR)src)) || (count <= 0)) { + return -EFAULT; + } + + maxCount = (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, (size_t)count)) ? \ + count : (USER_ASPACE_TOP_MAX - (UINTPTR)src); + + for (i = 0; i < maxCount; ++i) { + if (LOS_GetUser(&character, src + offset) != LOS_OK) { + return -EFAULT; + } + *(CHAR *)(dst + offset) = character; + if (character == '\0') { + return offset; + } + ++offset; + } + + return offset; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/arch/arm/arm/src/strnlen_user.c b/arch/arm/arm/src/strnlen_user.c new file mode 100755 index 00000000..b34d090b --- /dev/null +++ b/arch/arm/arm/src/strnlen_user.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_strnlen_user.h" +#include "los_user_get.h" +#include "los_vm_map.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +INT32 LOS_StrnlenUser(const CHAR *src, INT32 count) +{ + CHAR character; + INT32 maxCount; + INT32 i; + size_t offset = 0; + + if ((!LOS_IsUserAddress((VADDR_T)(UINTPTR)src)) || (count <= 0)) { + return 0; + } + + maxCount = (LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, (size_t)count)) ? \ + count : (USER_ASPACE_TOP_MAX - (UINTPTR)src); + + for (i = 0; i < maxCount; ++i) { + if (LOS_GetUser(&character, src + offset) != LOS_OK) { + return 0; + } + ++offset; + if (character == '\0') { + return offset; + } + } + + return count + 1; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/arch/arm/arm/src/user_copy.c b/arch/arm/arm/src/user_copy.c new file mode 100755 index 00000000..13e23baa --- /dev/null +++ b/arch/arm/arm/src/user_copy.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "user_copy.h" +#include "arm_user_copy.h" +#include "securec.h" +#include "los_memory.h" +#include "los_vm_map.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +size_t arch_copy_from_user(void *dst, const void *src, size_t len) +{ + return LOS_ArchCopyFromUser(dst, src, len); +} + +size_t LOS_ArchCopyFromUser(void *dst, const void *src, size_t len) +{ + if (!LOS_IsUserAddressRange((VADDR_T)(UINTPTR)src, len)) { + return len; + } + + return _arm_user_copy(dst, src, len); +} + +size_t arch_copy_to_user(void *dst, const void *src, size_t len) +{ + return LOS_ArchCopyToUser(dst, src, len); +} + +size_t LOS_ArchCopyToUser(void *dst, const void *src, size_t len) +{ + if (!LOS_IsUserAddressRange((VADDR_T)(UINTPTR)dst, len)) { + return len; + } + + return _arm_user_copy(dst, src, len); +} + +INT32 LOS_CopyFromKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count) +{ + INT32 ret; + + if (!LOS_IsUserAddressRange((VADDR_T)(UINTPTR)dest, count)) { + ret = memcpy_s(dest, max, src, count); + } else { + ret = ((max >= count) ? _arm_user_copy(dest, src, count) : ERANGE_AND_RESET); + } + + return ret; +} + +INT32 LOS_CopyToKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count) +{ + INT32 ret; + + if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)src, count)) { + ret = memcpy_s(dest, max, src, count); + } else { + ret = ((max >= count) ? _arm_user_copy(dest, src, count) : ERANGE_AND_RESET); + } + + return ret; +} + +INT32 LOS_UserMemClear(unsigned char *buf, UINT32 len) +{ + INT32 ret = 0; + if (!LOS_IsUserAddressRange((vaddr_t)(UINTPTR)buf, len)) { + (VOID)memset_s(buf, len, 0, len); + } else { + unsigned char *tmp = (unsigned char *)LOS_MemAlloc(OS_SYS_MEM_ADDR, len); + if (tmp == NULL) { + return -ENOMEM; + } + (VOID)memset_s(tmp, len, 0, len); + if (_arm_user_copy(buf, tmp, len) != 0) { + ret = -EFAULT; + } + LOS_MemFree(OS_SYS_MEM_ADDR, tmp); + } + return ret; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + diff --git a/arch/arm/include/in_cksum.h b/arch/arm/include/in_cksum.h new file mode 100755 index 00000000..8920b1df --- /dev/null +++ b/arch/arm/include/in_cksum.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __LINUX_CHECKSUM_H__ +#define __LINUX_CHECKSUM_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +unsigned int csum_partial(const void *buf, int len, unsigned int wsum); +unsigned int csum_partial_copy_nocheck(const void *src, void *dst, int len, unsigned int wsum); +unsigned short in_cksum(const void *buf, int len); +unsigned short in_cksum_copy(const void *src, void *dst, int len); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/arch/arm/include/los_exc.h b/arch/arm/include/los_exc.h new file mode 100755 index 00000000..62cbe6ff --- /dev/null +++ b/arch/arm/include/los_exc.h @@ -0,0 +1,233 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_exc Exception handling + * @ingroup kernel + */ +#ifndef _LOS_EXC_H +#define _LOS_EXC_H + +#include "los_typedef.h" +#include "arch_config.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/** + * @ingroup los_exc + * Register information structure + * + * Description: register information stored when an exception occurs on an LPC2458 platform. + * + * Note: The following register names without uw are the register names used in the chip manual. + */ +#ifdef LOSCFG_ARCH_ARM_AARCH64 +#define EXC_GEN_REGS_NUM 30 +typedef struct { + UINT64 X[EXC_GEN_REGS_NUM]; /**< Register X0-X29 */ + UINT64 LR; /**< Program returning address. X30 */ + UINT64 SP; + UINT64 regELR; + UINT64 SPSR; +} ExcContext; +#else +typedef struct { + UINT32 USP; /**< User mode stack pointer */ + UINT32 ULR; /**< User mode program returning address */ + UINT32 regCPSR; /**< Current program status register (CPSR) */ + UINT32 R0; /**< Register R0 */ + UINT32 R1; /**< Register R1 */ + UINT32 R2; /**< Register R2 */ + UINT32 R3; /**< Register R3 */ + UINT32 R4; /**< Register R4 */ + UINT32 R5; /**< Register R5 */ + UINT32 R6; /**< Register R6 */ + UINT32 R7; /**< Register R7 */ + UINT32 R8; /**< Register R8 */ + UINT32 R9; /**< Register R9 */ + UINT32 R10; /**< Register R10 */ + UINT32 R11; /**< Register R11 */ + UINT32 R12; /**< Register R12 */ + UINT32 SP; /**< Stack pointer */ + UINT32 LR; /**< Program returning address. */ + UINT32 PC; /**< PC pointer of the exceptional function */ +} ExcContext; +#endif + +/** + * @ingroup los_exc + * Exception information structure + * + * Description: exception information stored when an exception occurs on an LPC2458 platform. + * + */ +typedef struct { + UINT16 phase; /**< Phase in which an exception occurs */ + UINT16 type; /**< Exception type */ + UINT16 nestCnt; /**< Count of nested exception */ + UINT16 reserved; /**< Reserved for alignment */ + ExcContext *context; /**< Hardware context when an exception occurs */ +} ExcInfo; + +/** + * @ingroup los_exc + * @brief Kernel FP Register address obtain function. + * + * @par Description: + * The API is used to obtain the FP Register address. + * @attention None. + * + * @param None. + * + * @retval #UINTPTR The FP Register address. + * + * @par Dependency: + * los_exc.h: the header file that contains the API declaration. + * @see None. + */ +STATIC INLINE UINTPTR Get_Fp(VOID) +{ + UINTPTR regFp; + +#ifdef LOSCFG_ARCH_ARM_AARCH64 + __asm__ __volatile__("mov %0, X29" : "=r"(regFp)); +#else + __asm__ __volatile__("mov %0, fp" : "=r"(regFp)); +#endif + + return regFp; +} + +/** + * @ingroup los_exc + * @brief Define an exception handling function hook. + * + * @par Description: + * This API is used to define the exception handling function hook based on the type of + * the exception handling function and record exceptions. + * @attention None. + * + * @param None. + * + * @retval None. + * + * @par Dependency: + * los_exc.h: the header file that contains the API declaration. + * @see None. + */ +typedef VOID (*EXC_PROC_FUNC)(UINT32, ExcContext *, UINT32, UINT32); + +/** + * @ingroup los_exc + * @brief Register an exception handling hook. + * + * @par Description: + * This API is used to register an exception handling hook. + * @attention If the hook is registered for multiple times, the hook registered at the last time is effective. + * @attention The hook can be registered as NULL, indicating that the hook registration is canceled. + * @param excHook [IN] Type #EXC_PROC_FUNC: hook function. + * + * @retval #LOS_OK The exception handling hook is successfully registered. + * + * @par Dependency: + * los_exc.h: the header file that contains the API declaration. + * @see None. + */ +extern UINT32 LOS_ExcRegHook(EXC_PROC_FUNC excHook); + +/** + * @ingroup los_exc + * @brief Kernel panic function. + * + * @par Description: + * Stack function that prints kernel panics. + * @attention After this function is called and stack information is printed, the system will fail to respond. + * @attention The input parameter can be NULL. + * @param fmt [IN] Type #CHAR* : variadic argument. + * + * @retval #None. + * + * @par Dependency: + * los_exc.h: the header file that contains the API declaration. + * @see None. + */ +VOID LOS_Panic(const CHAR *fmt, ...); + +/** + * @ingroup los_exc + * @brief Kernel backtrace function. + * + * @par Description: + * Backtrace function that prints task call stack information traced from the running task. + * @attention None. + * + * @param None. + * + * @retval #None. + * + * @par Dependency: + * los_exc.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID OsBackTrace(VOID); + +/** + * @ingroup los_exc + * @brief Kernel task backtrace function. + * + * @par Description: + * Backtrace function that prints task call stack information traced from the input task. + * @attention + *
    + *
  • The input taskID should be valid.
  • + *
+ * + * @param taskID [IN] Type #UINT32 Task ID. + * + * @retval #None. + * + * @par Dependency: + * los_exc.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID OsTaskBackTrace(UINT32 taskID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_EXC_H */ diff --git a/arch/arm/include/los_hw.h b/arch/arm/include/los_hw.h new file mode 100755 index 00000000..c9d5825c --- /dev/null +++ b/arch/arm/include/los_hw.h @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_hw Hardware + * @ingroup kernel + */ +#ifndef _LOS_HW_H +#define _LOS_HW_H + +#include "los_typedef.h" +#include "los_hw_cpu.h" +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define OS_SCHEDULE_IN_IRQ 0x0 +#define OS_SCHEDULE_IN_TASK 0x1 + +#define PSR_T_ARM 0x00000000u +#define PSR_T_THUMB 0x00000020u +#define PSR_MODE_SVC 0x00000013u +#define PSR_MODE_SYS 0x0000001Fu +#define PSR_FIQ_DIS 0x00000040u +#define PSR_IRQ_DIS 0x00000080u +#define PSR_MODE_USR 0x00000010u + +#define PSR_MODE_SVC_THUMB (PSR_MODE_SVC | PSR_T_THUMB | PSR_FIQ_DIS | PSR_IRQ_DIS) +#define PSR_MODE_SVC_ARM (PSR_MODE_SVC | PSR_T_ARM | PSR_FIQ_DIS | PSR_IRQ_DIS) + +#define PSR_MODE_SYS_THUMB (PSR_MODE_SYS | PSR_T_THUMB) +#define PSR_MODE_SYS_ARM (PSR_MODE_SYS | PSR_T_ARM) + +#define PSR_MODE_USR_THUMB (PSR_MODE_USR | PSR_T_THUMB) +#define PSR_MODE_USR_ARM (PSR_MODE_USR | PSR_T_ARM) + +#define LOS_CHECK_SCHEDULE ((!OS_INT_ACTIVE) && OsPreemptable()) + +typedef struct { + const UINT32 partNo; + const CHAR *cpuName; +} CpuVendor; + +extern CpuVendor g_cpuTable[]; +extern UINT64 g_cpuMap[]; + +#define CPU_MAP_GET(cpuid) g_cpuMap[(cpuid)] +#define CPU_MAP_SET(cpuid, hwid) g_cpuMap[(cpuid)] = (hwid) + +/** + * @ingroup los_hw + * @brief Set Event. + * + * @par Description: + *
    + *
  • This API is used to send an event to all cores within a muti-processor system.
  • + *
+ * @attention + *
    + *
  • This API is not implemented.
  • + *
+ * + * @param None. + * + * @retval #None. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see wfe. + */ +extern VOID Sev(VOID); + +/** + * @ingroup los_hw + * @brief Wait for event. + * + * @par Description: + *
    + *
  • This API is used to suspend execution until events occurs if the event register is not set.
  • + *
+ * @attention + *
    + *
  • This API is not implemented.
  • + *
+ * + * @param None. + * + * @retval #None. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see sev. + */ +extern VOID Wfe(VOID); + +/** + * @ingroup los_hw + * @brief Wait for interrupt. + * + * @par Description: + *
    + *
  • This API is used to suspend execution until interrupt or a debug request occurs.
  • + *
+ * @attention None. + * + * @param None. + * + * @retval #None. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID Wfi(VOID); + +/** + * @ingroup los_hw + * @brief Data Memory Barrier. + * + * @par Description: + *
    + *
  • This API is used as a memory barrier
  • + *
+ * @attention None. + * + * @param None. + * + * @retval #None. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID Dmb(VOID); + +/** + * @ingroup los_hw + * @brief Data Synchronization Barrier. + * + * @par Description: + *
    + *
  • This API is used as a special kind of memory barrier
  • + *
+ * @attention None. + * + * @param None. + * + * @retval #None. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID Dsb(VOID); + +/** + * @ingroup los_hw + * @brief Instruction Synchronization Barrier. + * + * @par Description: + *
    + *
  • This API is used to flush the pipeline in the processor, + * so that all instructions following the ISB are fetched from cache or memory, + * after the instruction has been completed.
  • + *
+ * @attention None. + * + * @param None. + * + * @retval #None. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID Isb(VOID); + +/** + * @ingroup los_hw + * @brief Invalidate instruction cache. + * + * @par Description: + *
    + *
  • This API is used to invalidate the instruction cache.
  • + *
+ * @attention None. + * + * @param None. + * + * @retval #None. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID FlushICache(VOID); + +/** + * @ingroup los_hw + * @brief Flush data cache. + * + * @par Description: + *
    + *
  • This API is used to flush the data cache to the memory.
  • + *
+ * @attention + *
    + *
  • The input end address must be greater than the input start address.
  • + *
+ * + * @param start [IN] Type #int Flush start address. + * @param end [IN] Type #int Flush end address. + * + * @retval #None. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID DCacheFlushRange(UINTPTR start, UINTPTR end); + +/** + * @ingroup los_hw + * @brief Invalidate data cache. + * + * @par Description: + *
    + *
  • This API is used to Invalidate the data in cache.
  • + *
+ * @attention + *
    + *
  • The input end address must be greater than the input start address.
  • + *
+ * + * @param start [IN] Type #int Invalidate start address. + * @param end [IN] Type #int Invalidate end address . + * + * @retval #None. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see None. + */ +extern VOID DCacheInvRange(UINTPTR start, UINTPTR end); + +/** + * @ingroup los_hw + * @brief Get cpu core name. + * + * @par Description: + *
    + *
  • This API is used to get cpu core name.
  • + *
+ * @attention + *
    + *
  • None.
  • + *
+ * + * @param + * @retval #CHAR * cpu core name. + * + * @par Dependency: + * los_hw.h: the header file that contains the API declaration. + * @see None. + */ +STATIC INLINE const CHAR *LOS_CpuInfo(VOID) +{ + INT32 i; + UINT32 midr = OsMainIDGet(); + /* [15:4] is the primary part number */ + UINT32 partNo = (midr & 0xFFF0) >> 0x4; + + for (i = 0; g_cpuTable[i].partNo != 0; i++) { + if (partNo == g_cpuTable[i].partNo) { + return g_cpuTable[i].cpuName; + } + } + + return "unknown"; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_HW_H */ diff --git a/arch/arm/include/los_hw_arch.h b/arch/arm/include/los_hw_arch.h new file mode 100755 index 00000000..f7bd812a --- /dev/null +++ b/arch/arm/include/los_hw_arch.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_hw Hardware + * @ingroup kernel + */ + +#ifndef _LOS_HW_ARCH_H +#define _LOS_HW_ARCH_H + +# if defined(__GNUC__) +# if defined(__aarch64__) +# define LOSCFG_ARM_AARCH64 1 +# endif +# +# define LOSCFG_ARM_ARCH __ARM_ARCH +# else +# error "unsupported compiler!" +# endif + +#endif diff --git a/arch/arm/include/los_hw_tick_pri.h b/arch/arm/include/los_hw_tick_pri.h new file mode 100755 index 00000000..98a7296b --- /dev/null +++ b/arch/arm/include/los_hw_tick_pri.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_HW_TICK_PRI_H +#define _LOS_HW_TICK_PRI_H + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +extern UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond); +extern VOID OsTickStart(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_HW_TICK_PRI_H */ diff --git a/arch/arm/include/los_hwi.h b/arch/arm/include/los_hwi.h new file mode 100755 index 00000000..b8bcadb9 --- /dev/null +++ b/arch/arm/include/los_hwi.h @@ -0,0 +1,422 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @defgroup los_hwi Hardware interrupt + * @ingroup kernel + */ +#ifndef _LOS_HWI_H +#define _LOS_HWI_H + +#include "los_base.h" +#include "los_hw_cpu.h" +#include "hal_hwi.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/** + * @ingroup los_hwi + * Count of interrupts. + */ +extern size_t g_intCount[]; + +/** + * @ingroup los_hwi + * An interrupt is active. + */ +#define OS_INT_ACTIVE ({ \ + size_t intCount; \ + UINT32 intSave_ = LOS_IntLock(); \ + intCount = g_intCount[ArchCurrCpuid()]; \ + LOS_IntRestore(intSave_); \ + intCount; \ +}) + +/** + * @ingroup los_hwi + * An interrupt is inactive. + */ +#define OS_INT_INACTIVE (!(OS_INT_ACTIVE)) + +/** + * @ingroup los_hwi + * Highest priority of a hardware interrupt. + */ +#define OS_HWI_PRIO_HIGHEST 0 + +/** + * @ingroup los_hwi + * Lowest priority of a hardware interrupt. + */ +#define OS_HWI_PRIO_LOWEST 31 + +/** + * @ingroup los_hwi + * Max name length of a hardware interrupt. + */ +#define OS_HWI_MAX_NAMELEN 10 + +/** + * @ingroup los_hwi + * Hardware interrupt error code: Invalid interrupt number. + * + * Value: 0x02000900 + * + * Solution: Ensure that the interrupt number is valid. + */ +#define OS_ERRNO_HWI_NUM_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x00) + +/** + * @ingroup los_hwi + * Hardware interrupt error code: Null hardware interrupt handling function. + * + * Value: 0x02000901 + * + * Solution: Pass in a valid non-null hardware interrupt handling function. + */ +#define OS_ERRNO_HWI_PROC_FUNC_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x01) + +/** + * @ingroup los_hwi + * Hardware interrupt error code: Insufficient interrupt resources for hardware interrupt creation. + * + * Value: 0x02000902 + * + * Solution: Increase the configured maximum number of supported hardware interrupts. + */ +#define OS_ERRNO_HWI_CB_UNAVAILABLE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x02) + +/** + * @ingroup los_hwi + * Hardware interrupt error code: Insufficient memory for hardware interrupt initialization. + * + * Value: 0x02000903 + * + * Solution: Expand the configured memory. + */ +#define OS_ERRNO_HWI_NO_MEMORY LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x03) + +/** + * @ingroup los_hwi + * Hardware interrupt error code: The interrupt has already been created. + * + * Value: 0x02000904 + * + * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. + */ +#define OS_ERRNO_HWI_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x04) + +/** + * @ingroup los_hwi + * Hardware interrupt error code: Invalid interrupt priority. + * + * Value: 0x02000905 + * + * Solution: Ensure that the interrupt priority is valid. + */ +#define OS_ERRNO_HWI_PRIO_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x05) + +/** + * @ingroup los_hwi + * Hardware interrupt error code: Incorrect interrupt creation mode. + * + * Value: 0x02000906 + * + * Solution: The interrupt creation mode can be only set to OS_HWI_MODE_COMM or OS_HWI_MODE_FAST of + * which the value can be 0 or 1. + */ +#define OS_ERRNO_HWI_MODE_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x06) + +/** + * @ingroup los_hwi + * Hardware interrupt error code: The interrupt has already been created as a fast interrupt. + * + * Value: 0x02000907 + * + * Solution: Check whether the interrupt specified by the passed-in interrupt number has already been created. + */ +#define OS_ERRNO_HWI_FASTMODE_ALREADY_CREATED LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x07) + +/** + * @ingroup los_hwi + * Hardware interrupt error code: The API is called during an interrupt, which is forbidden. + * + * Value: 0x02000908 + * + * * Solution: Do not call the API during an interrupt. + */ +#define OS_ERRNO_HWI_INTERR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x08) + +/** + * @ingroup los_hwi + * Hardware interrupt error code:the hwi support SHARED error. + * + * Value: 0x02000909 + * + * * Solution: Check the input params hwiMode and irqParam of LOS_HwiCreate or + * LOS_HwiDelete whether adapt the current hwi. + */ +#define OS_ERRNO_HWI_SHARED_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x09) + +/** + * @ingroup los_hwi + * Hardware interrupt error code:Invalid interrupt Arg when interrupt mode is IRQF_SHARED. + * + * Value: 0x0200090a + * + * * Solution: Check the interrupt Arg, Arg should not be NULL and pDevId should not be NULL. + */ +#define OS_ERRNO_HWI_ARG_INVALID LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0a) + +/** + * @ingroup los_hwi + * Hardware interrupt error code:The interrupt corresponded to the hwi number or devid has not been created. + * + * Value: 0x0200090b + * + * * Solution: Check the hwi number or devid, make sure the hwi number or devid need to delete. + */ +#define OS_ERRNO_HWI_HWINUM_UNCREATE LOS_ERRNO_OS_ERROR(LOS_MOD_HWI, 0x0b) + +/** + * @ingroup los_hwi + * Define the type of a hardware interrupt number. + */ +typedef UINT32 HWI_HANDLE_T; + +/** + * @ingroup los_hwi + * Define the type of a hardware interrupt priority. + */ +typedef UINT16 HWI_PRIOR_T; + +/** + * @ingroup los_hwi + * Define the type of hardware interrupt mode configurations. + */ +typedef UINT16 HWI_MODE_T; + +/** + * @ingroup los_hwi + * Define the type of the parameter used for the hardware interrupt creation function. + * The function of this parameter varies among platforms. + */ +typedef UINTPTR HWI_ARG_T; + +/** + * @ingroup los_hwi + * Define the type of a hardware interrupt handling function. + */ +typedef VOID (*HWI_PROC_FUNC)(VOID); + +/* + * These flags used only by the kernel as part of the + * irq handling routines. + * + * IRQF_SHARED - allow sharing the irq among several devices + */ +#define IRQF_SHARED 0x8000U + +typedef struct tagHwiHandleForm { + HWI_PROC_FUNC pfnHook; + HWI_ARG_T uwParam; + struct tagHwiHandleForm *pstNext; +} HwiHandleForm; + +typedef struct tagIrqParam { + int swIrq; + VOID *pDevId; + const CHAR *pName; +} HwiIrqParam; + +extern HwiHandleForm g_hwiForm[OS_HWI_MAX_NUM]; + +/** + * @ingroup los_hwi + * @brief Disable all interrupts. + * + * @par Description: + *
    + *
  • This API is used to disable all IRQ and FIQ interrupts in the CPSR.
  • + *
+ * @attention + *
    + *
  • None.
  • + *
+ * + * @param None. + * + * @retval #UINT32 CPSR value obtained before all interrupts are disabled. + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @see LOS_IntRestore + */ +STATIC INLINE UINT32 LOS_IntLock(VOID) +{ + return ArchIntLock(); +} + +/** + * @ingroup los_hwi + * @brief Enable all interrupts. + * + * @par Description: + *
    + *
  • This API is used to enable all IRQ and FIQ interrupts in the CPSR.
  • + *
+ * @attention + *
    + *
  • None.
  • + *
+ * + * @param None. + * + * @retval #UINT32 CPSR value obtained after all interrupts are enabled. + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @see LOS_IntLock + */ +STATIC INLINE UINT32 LOS_IntUnLock(VOID) +{ + return ArchIntUnlock(); +} + +/** + * @ingroup los_hwi + * @brief Restore interrupts. + * + * @par Description: + *
    + *
  • This API is used to restore the CPSR value obtained before all interrupts are disabled.
  • + *
+ * @attention + *
    + *
  • This API can be called only after all interrupts are disabled, and the input parameter value should be + * the value returned by LOS_IntLock.
  • + *
+ * + * @param intSave [IN] Type #UINT32 : CPSR value obtained before all interrupts are disabled. + * + * @retval None. + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @see LOS_IntLock + */ +STATIC INLINE VOID LOS_IntRestore(UINT32 intSave) +{ + ArchIntRestore(intSave); +} + +/** + * @ingroup los_hwi + * @brief Create a hardware interrupt. + * + * @par Description: + * This API is used to configure a hardware interrupt and register a hardware interrupt handling function. + * + * @attention + *
    + *
  • The hardware interrupt module is usable only when the configuration item for + * hardware interrupt tailoring is enabled.
  • + *
  • Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
  • + *
  • OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.
  • + *
  • Before executing an interrupt on a platform, refer to the chip manual of the platform.
  • + *
  • The parameter handler of this interface is a interrupt handler, it should be correct, otherwise, + * the system may be abnormal.
  • + *
  • The input irqParam could be NULL, if not, it should be address which point to a struct HwiIrqParam
  • + *
+ * + * @param hwiNum [IN] Type #HWI_HANDLE_T: hardware interrupt number. + * for an ARM926 platform is [0,31]. + * @param hwiPrio [IN] Type #HWI_PRIOR_T: hardware interrupt priority. The value range is + * [0, GIC_MAX_INTERRUPT_PREEMPTION_LEVEL - 1] << PRIORITY_SHIFT. + * @param hwiMode [IN] Type #HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily. + * @param hwiHandler [IN] Type #HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered. + * @param irqParam [IN] Type #HwiIrqParam: input parameter of the interrupt handler used when + * a hardware interrupt is triggered. + * + * @retval #OS_ERRNO_HWI_PROC_FUNC_NULL Null hardware interrupt handling function. + * @retval #OS_ERRNO_HWI_NUM_INVALID Invalid interrupt number. + * @retval #OS_ERRNO_HWI_NO_MEMORY Insufficient memory for hardware interrupt creation. + * @retval #OS_ERRNO_HWI_ALREADY_CREATED The interrupt handler being created has already been created. + * @retval #LOS_OK The interrupt is successfully created. + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @see None. + */ +extern UINT32 LOS_HwiCreate(HWI_HANDLE_T hwiNum, + HWI_PRIOR_T hwiPrio, + HWI_MODE_T hwiMode, + HWI_PROC_FUNC hwiHandler, + HwiIrqParam *irqParam); + +/** + * @ingroup los_hwi + * @brief delete a hardware interrupt. + * + * @par Description: + * This API is used to delete a hardware interrupt. + * + * @attention + *
    + *
  • The hardware interrupt module is usable only when the configuration item for + * hardware interrupt tailoring is enabled.
  • + *
  • Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX].
  • + *
  • OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.
  • + *
  • Before executing an interrupt on a platform, refer to the chip manual of the platform.
  • + *
+ * + * @param hwiNum [IN] Type #HWI_HANDLE_T: hardware interrupt number. + * @param irqParam [IN] Type #HwiIrqParam *: id of hardware interrupt which will base on + * when delete the hardware interrupt. + * + * @retval #OS_ERRNO_HWI_NUM_INVALID Invalid interrupt number. + * @retval #OS_ERRNO_HWI_SHARED_ERROR Invalid interrupt mode. + * @retval #LOS_OK The interrupt is successfully deleted. + * @retval #LOS_NOK The interrupt is failed deleted based on the pDev_ID. + + * @par Dependency: + *
  • los_hwi.h: the header file that contains the API declaration.
+ * @see None. + */ +extern UINT32 LOS_HwiDelete(HWI_HANDLE_T hwiNum, HwiIrqParam *irqParam); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_HWI_H */ diff --git a/arch/arm/include/los_strncpy_from_user.h b/arch/arm/include/los_strncpy_from_user.h new file mode 100755 index 00000000..764be8a2 --- /dev/null +++ b/arch/arm/include/los_strncpy_from_user.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_STRNCPY_FROM_USER_H +#define _LOS_STRNCPY_FROM_USER_H + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* + * @brief Copy a string end with NULL from userspace to kernelspace + * + * This function validates that usermode has access to src before copying the + * data. + * + * @param dst The destination buffer in kernel space. + * @param src The source buffer in user space. + * @param count Max number of bytes to copy. + * + * @return Return -EFAULT if src is not in user space or count <= 0 or copy out of range. Return the length of + * the string if success, if count is smaller than the length of the string then copy count bytes and return count. + */ +INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_STRNCPY_FROM_USER_H */ diff --git a/arch/arm/include/los_strnlen_user.h b/arch/arm/include/los_strnlen_user.h new file mode 100755 index 00000000..5c90d590 --- /dev/null +++ b/arch/arm/include/los_strnlen_user.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_STRNLEN_USER_H +#define _LOS_STRNLEN_USER_H + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* + * @brief Get the length of string including final NULL. + * + * This function validates that usermode has access to src before measuring the string. + * + * @param src The string in userspace to measure. + * @param count Max count. + * + * @return Return the length of the string including final NULL. Return 0 if src is not in user space or count <= 0 or + * visit the memory out of range. Return a number larger than count if the string is too long, User should handle + * this situation. + */ +INT32 LOS_StrnlenUser(const CHAR *src, INT32 count); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_STRNLEN_USER_H */ diff --git a/arch/arm/include/los_sys_stack_pri.h b/arch/arm/include/los_sys_stack_pri.h new file mode 100755 index 00000000..0dbc46d1 --- /dev/null +++ b/arch/arm/include/los_sys_stack_pri.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_SYS_STACK_H +#define _LOS_SYS_STACK_H + +#include "los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#ifdef LOSCFG_AARCH64 +extern UINTPTR __stack_startup; +extern UINTPTR __stack_startup_top; +#else +extern UINTPTR __fiq_stack_top; +extern UINTPTR __svc_stack_top; +extern UINTPTR __abt_stack_top; +extern UINTPTR __undef_stack_top; +extern UINTPTR __exc_stack_top; +extern UINTPTR __fiq_stack; +extern UINTPTR __svc_stack; +extern UINTPTR __abt_stack; +extern UINTPTR __undef_stack; +extern UINTPTR __exc_stack; +#endif +extern UINTPTR __irq_stack_top; +extern UINTPTR __irq_stack; + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/arch/arm/include/los_user_get.h b/arch/arm/include/los_user_get.h new file mode 100755 index 00000000..883d299e --- /dev/null +++ b/arch/arm/include/los_user_get.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_USER_GET_H +#define _LOS_USER_GET_H + +#include "los_typedef.h" +#include "arm_user_get.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* + * @brief Get data from userspace into kernelspace + * + * This function validates that usermode has access to src before copying the + * data. + * + * @param dst The destination buffer in kernel space. + * @param src The source buffer in user space. + * + * @note The data type is simple such as char, short, int, long in 32bits platform. + * + * @return Return -EFAULT if error. Return 0 if success. + */ +#define LOS_GetUser(dst, src) _arm_get_user((dst), (src), sizeof(*(dst)), sizeof(*(src))) + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_USER_GET_H */ diff --git a/arch/arm/include/los_user_put.h b/arch/arm/include/los_user_put.h new file mode 100755 index 00000000..bec15dae --- /dev/null +++ b/arch/arm/include/los_user_put.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LOS_USER_PUT_H +#define _LOS_USER_PUT_H + +#include "los_typedef.h" +#include "arm_user_put.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* + * @brief put data from kernelspace into userspace + * + * This function validates that usermode has access to dst before copying the + * data. + * + * @param dst The destination buffer in user space. + * @param src The source buffer in kernel space. + * + * @note The data type is simple such as char, short, int, long in 32bits platform. + * + * @return Return -EFAULT if error. Return 0 if success. + */ +#define LOS_PutUser(src, dst) _arm_put_user((dst), (src), sizeof(*(dst)), sizeof(*(src))) + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _LOS_USER_PUT_H */ diff --git a/arch/arm/include/user_copy.h b/arch/arm/include/user_copy.h new file mode 100755 index 00000000..955634ec --- /dev/null +++ b/arch/arm/include/user_copy.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_typedef.h" +#pragma once + +/* + * @brief Copy data from userspace into kernelspace + * + * This function validates that usermode has access to src before copying the + * data. + * + * @param dst The destination buffer. + * @param src The source buffer. + * @param len The number of bytes to copy. + * + * @return bytes not copied + */ +size_t LOS_ArchCopyFromUser(void *dst, const void *src, size_t len); + +/* + * @brief Copy data from kernelspace into userspace + * + * This function validates that usermode has access to dst before copying the + * data. + * + * @param dst The destination buffer. + * @param src The source buffer. + * @param len The number of bytes to copy. + * + * @return bytes not copied + */ +size_t LOS_ArchCopyToUser(void *dst, const void *src, size_t len); + +/* + * @brief Copy data from src to dst + * + * This function will use different copy methods to copy src data to dst, according to + * the different spaces (userspace or kernelspace) of dst data. + * + * @param dst The destination buffer, can be userspace address. + * @param max The maxsimum number of bytes to copy. + * @param src The source buffer. + * @param len The number of bytes to copy. + * + * @return zero on success; non-zero on failure. + */ +INT32 LOS_CopyFromKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count); + +/* + * @brief Copy data from src to dst + * + * This function will use different copy methods to copy src data to dst, according to + * the different spaces (userspace or kernelspace) of src data. + * + * @param dst The destination buffer. + * @param max The maxsimum number of bytes to copy. + * @param src The source buffer, can be userspace address. + * @param len The number of bytes to copy. + * + * @return zero on success; non-zero on failure. + */ +INT32 LOS_CopyToKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count); + +/* + * @brief Clear data in buf + * + * This function will clear buf from buf to buf + len. + * + * @param buf The destination buffer, can be userspace address. + * @param len The number of bytes to clear. + * + * @return zero on success; non-zero on failure. + */ +INT32 LOS_UserMemClear(unsigned char *buf, UINT32 len); diff --git a/arch/cpu.mk b/arch/cpu.mk new file mode 100755 index 00000000..c1af11ac --- /dev/null +++ b/arch/cpu.mk @@ -0,0 +1,32 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +ifeq ($(LOSCFG_ARCH_ARM), y) +-include $(LITEOSTOPDIR)/arch/arm/arm.mk +endif \ No newline at end of file diff --git a/bsd/Kconfig b/bsd/Kconfig new file mode 100755 index 00000000..53c2816a --- /dev/null +++ b/bsd/Kconfig @@ -0,0 +1,6 @@ +config COMPAT_BSD + bool "Enable FreeBSD" + default y + + help + Answer Y to enable LiteOS support FreeBSD. diff --git a/bsd/Makefile b/bsd/Makefile new file mode 100755 index 00000000..9540092d --- /dev/null +++ b/bsd/Makefile @@ -0,0 +1,54 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include $(LITEOSTOPDIR)/config.mk + +MODULE_NAME := $(notdir $(shell pwd)) + +LOCAL_SRCS := $(wildcard kern/*.c) + +LOCAL_SRCS += $(wildcard $(LITEOS_ARCH_ARM)/*.c) +LOCAL_SRCS += $(wildcard $(LITEOS_ARCH_ARM)/*.S) + +ifeq ($(LOSCFG_DRIVERS_RANDOM), y) +LOCAL_SRCS += $(wildcard crypto/rijndael/*.c) \ + $(wildcard crypto/sha2/*.c) \ + $(wildcard dev/random/*.c) \ + $(wildcard libkern/*.c) + +endif + +LOCAL_INCLUDE := \ + -I $(LITEOSTOPDIR)/kernel/base/include \ + -I $(LITEOSTOPDIR)/bsd \ + -I $(LITEOSTOPDIR)/bsd/kern \ + +LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) + +include $(MODULE) diff --git a/bsd/arm/autoconf.c b/bsd/arm/autoconf.c new file mode 120000 index 00000000..f2ba141c --- /dev/null +++ b/bsd/arm/autoconf.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/arm/arm/autoconf.c \ No newline at end of file diff --git a/bsd/arm/hw_user_copy.S b/bsd/arm/hw_user_copy.S new file mode 120000 index 00000000..576e247f --- /dev/null +++ b/bsd/arm/hw_user_copy.S @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/lib/libc/arm/string/hw_user_copy.S \ No newline at end of file diff --git a/bsd/arm/in_cksum.c b/bsd/arm/in_cksum.c new file mode 120000 index 00000000..0adb79c6 --- /dev/null +++ b/bsd/arm/in_cksum.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/arm/arm/in_cksum.c \ No newline at end of file diff --git a/bsd/arm/in_cksum_arm.S b/bsd/arm/in_cksum_arm.S new file mode 120000 index 00000000..daa2408f --- /dev/null +++ b/bsd/arm/in_cksum_arm.S @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/arm/arm/in_cksum_arm.S \ No newline at end of file diff --git a/bsd/arm/include/_bus.h b/bsd/arm/include/_bus.h new file mode 120000 index 00000000..61b5e9b7 --- /dev/null +++ b/bsd/arm/include/_bus.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/arm/include/_bus.h \ No newline at end of file diff --git a/bsd/arm/nexus.c b/bsd/arm/nexus.c new file mode 120000 index 00000000..1e37fd01 --- /dev/null +++ b/bsd/arm/nexus.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/arm/arm/nexus.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/Makefile b/bsd/compat/linuxkpi/Makefile new file mode 100755 index 00000000..5244c469 --- /dev/null +++ b/bsd/compat/linuxkpi/Makefile @@ -0,0 +1,42 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include $(LITEOSTOPDIR)/config.mk + +MODULE_NAME := $(notdir $(shell pwd)) + +LOCAL_SRCS := $(wildcard src/*.c) + +LOCAL_INCLUDE := \ + -I $(LITEOSTOPDIR)/kernel/base/include \ + -I $(LITEOSTOPDIR)/bsd/compat/linuxkpi/include + +LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) + +include $(MODULE) diff --git a/bsd/compat/linuxkpi/include/asm/atomic.h b/bsd/compat/linuxkpi/include/asm/atomic.h new file mode 120000 index 00000000..4abd5f80 --- /dev/null +++ b/bsd/compat/linuxkpi/include/asm/atomic.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/asm/atomic.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/asm/barrier.h b/bsd/compat/linuxkpi/include/asm/barrier.h new file mode 120000 index 00000000..1ba23c96 --- /dev/null +++ b/bsd/compat/linuxkpi/include/asm/barrier.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/asm/barrier.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/asm/io.h b/bsd/compat/linuxkpi/include/asm/io.h new file mode 120000 index 00000000..131e070f --- /dev/null +++ b/bsd/compat/linuxkpi/include/asm/io.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/asm/io.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/asm/page.h b/bsd/compat/linuxkpi/include/asm/page.h new file mode 120000 index 00000000..a0e95fc8 --- /dev/null +++ b/bsd/compat/linuxkpi/include/asm/page.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/asm/page.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/atomic.h b/bsd/compat/linuxkpi/include/linux/atomic.h new file mode 120000 index 00000000..247db5a7 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/atomic.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/atomic.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/compat.h b/bsd/compat/linuxkpi/include/linux/compat.h new file mode 120000 index 00000000..53270094 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/compat.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/compat.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/compiler.h b/bsd/compat/linuxkpi/include/linux/compiler.h new file mode 120000 index 00000000..9f438623 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/compiler.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/compiler.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/completion.h b/bsd/compat/linuxkpi/include/linux/completion.h new file mode 120000 index 00000000..84ca930f --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/completion.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/completion.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/ctype.h b/bsd/compat/linuxkpi/include/linux/ctype.h new file mode 120000 index 00000000..0a07c759 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/ctype.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/ctype.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/delay.h b/bsd/compat/linuxkpi/include/linux/delay.h new file mode 120000 index 00000000..1dc51ca2 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/delay.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/delay.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/dma-mapping.h b/bsd/compat/linuxkpi/include/linux/dma-mapping.h new file mode 120000 index 00000000..67c63612 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/dma-mapping.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/dma-mapping.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/errno.h b/bsd/compat/linuxkpi/include/linux/errno.h new file mode 120000 index 00000000..b4779432 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/errno.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/errno.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/fcntl.h b/bsd/compat/linuxkpi/include/linux/fcntl.h new file mode 120000 index 00000000..7ec7319c --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/fcntl.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/fcntl.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/fs.h b/bsd/compat/linuxkpi/include/linux/fs.h new file mode 120000 index 00000000..2b73fb25 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/fs.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/fs.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/hrtimer.h b/bsd/compat/linuxkpi/include/linux/hrtimer.h new file mode 120000 index 00000000..3ce6c933 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/hrtimer.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/hrtimer.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/icmp.h b/bsd/compat/linuxkpi/include/linux/icmp.h new file mode 120000 index 00000000..368b7911 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/icmp.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/icmp.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/interrupt.h b/bsd/compat/linuxkpi/include/linux/interrupt.h new file mode 120000 index 00000000..533736ef --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/interrupt.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/interrupt.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/io.h b/bsd/compat/linuxkpi/include/linux/io.h new file mode 120000 index 00000000..c64b0af8 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/io.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/io.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/ioctl.h b/bsd/compat/linuxkpi/include/linux/ioctl.h new file mode 120000 index 00000000..3fb3dd8c --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/ioctl.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/ioctl.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/jiffies.h b/bsd/compat/linuxkpi/include/linux/jiffies.h new file mode 120000 index 00000000..6065f203 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/jiffies.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/jiffies.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/kernel.h b/bsd/compat/linuxkpi/include/linux/kernel.h new file mode 120000 index 00000000..ae8eaae0 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/kernel.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/kernel.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/list.h b/bsd/compat/linuxkpi/include/linux/list.h new file mode 120000 index 00000000..4ac90bf0 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/list.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/list.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/module.h b/bsd/compat/linuxkpi/include/linux/module.h new file mode 120000 index 00000000..255944c4 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/module.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/module.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/moduleparam.h b/bsd/compat/linuxkpi/include/linux/moduleparam.h new file mode 120000 index 00000000..b64f6707 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/moduleparam.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/moduleparam.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/mtd/mtd.h b/bsd/compat/linuxkpi/include/linux/mtd/mtd.h new file mode 120000 index 00000000..89878fc8 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/mtd/mtd.h @@ -0,0 +1 @@ +../../../../../../../../third_party/Linux_Kernel/fs/jffs2/mtd.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/mtd/mtd_list.h b/bsd/compat/linuxkpi/include/linux/mtd/mtd_list.h new file mode 120000 index 00000000..d7004259 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/mtd/mtd_list.h @@ -0,0 +1 @@ +../../../../../../../../third_party/Linux_Kernel/fs/jffs2/mtd_list.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/pagemap.h b/bsd/compat/linuxkpi/include/linux/pagemap.h new file mode 120000 index 00000000..4b0d72be --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/pagemap.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/pagemap.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/rbtree.h b/bsd/compat/linuxkpi/include/linux/rbtree.h new file mode 120000 index 00000000..59762226 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/rbtree.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/rbtree.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/rtc.h b/bsd/compat/linuxkpi/include/linux/rtc.h new file mode 120000 index 00000000..8dec352b --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/rtc.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/rtc.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/rwsem.h b/bsd/compat/linuxkpi/include/linux/rwsem.h new file mode 120000 index 00000000..a0c620ef --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/rwsem.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/rwsem.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/scatterlist.h b/bsd/compat/linuxkpi/include/linux/scatterlist.h new file mode 120000 index 00000000..e2bad8d4 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/scatterlist.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/scatterlist.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/sched.h b/bsd/compat/linuxkpi/include/linux/sched.h new file mode 120000 index 00000000..0b5ccb67 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/sched.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/sched.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/semaphore.h b/bsd/compat/linuxkpi/include/linux/semaphore.h new file mode 120000 index 00000000..d870dbcc --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/semaphore.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/semaphore.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/slab.h b/bsd/compat/linuxkpi/include/linux/slab.h new file mode 120000 index 00000000..9351dc8d --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/slab.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/slab.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/spinlock.h b/bsd/compat/linuxkpi/include/linux/spinlock.h new file mode 120000 index 00000000..9cf0152a --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/spinlock.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/spinlock.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/stat.h b/bsd/compat/linuxkpi/include/linux/stat.h new file mode 120000 index 00000000..87229a30 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/stat.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/stat.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/string.h b/bsd/compat/linuxkpi/include/linux/string.h new file mode 120000 index 00000000..c48791d6 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/string.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/string.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/timer.h b/bsd/compat/linuxkpi/include/linux/timer.h new file mode 120000 index 00000000..7ba43e71 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/timer.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/timer.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/tree.h b/bsd/compat/linuxkpi/include/linux/tree.h new file mode 120000 index 00000000..5cc79a5f --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/tree.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/sys/tree.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/types.h b/bsd/compat/linuxkpi/include/linux/types.h new file mode 120000 index 00000000..8f330774 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/types.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/types.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/wait.h b/bsd/compat/linuxkpi/include/linux/wait.h new file mode 120000 index 00000000..e0ce82d7 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/wait.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/wait.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/wakelock.h b/bsd/compat/linuxkpi/include/linux/wakelock.h new file mode 120000 index 00000000..12b2192c --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/wakelock.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/wakelock.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/workqueue.h b/bsd/compat/linuxkpi/include/linux/workqueue.h new file mode 120000 index 00000000..086614c3 --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/workqueue.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/workqueue.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/linux/zutil.h b/bsd/compat/linuxkpi/include/linux/zutil.h new file mode 120000 index 00000000..f481a37b --- /dev/null +++ b/bsd/compat/linuxkpi/include/linux/zutil.h @@ -0,0 +1 @@ +../../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/zutil.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/tzdst.h b/bsd/compat/linuxkpi/include/tzdst.h new file mode 120000 index 00000000..5b435de2 --- /dev/null +++ b/bsd/compat/linuxkpi/include/tzdst.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/tzdst.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/include/tzdst_pri.h b/bsd/compat/linuxkpi/include/tzdst_pri.h new file mode 120000 index 00000000..2b1feb81 --- /dev/null +++ b/bsd/compat/linuxkpi/include/tzdst_pri.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/tzdst_pri.h \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/adp.c b/bsd/compat/linuxkpi/src/adp.c new file mode 120000 index 00000000..a5397f02 --- /dev/null +++ b/bsd/compat/linuxkpi/src/adp.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/adp.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/linux_completion.c b/bsd/compat/linuxkpi/src/linux_completion.c new file mode 120000 index 00000000..a6a575ef --- /dev/null +++ b/bsd/compat/linuxkpi/src/linux_completion.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/linux_completion.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/linux_hrtimer.c b/bsd/compat/linuxkpi/src/linux_hrtimer.c new file mode 120000 index 00000000..32cf1aa1 --- /dev/null +++ b/bsd/compat/linuxkpi/src/linux_hrtimer.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/linux_hrtimer.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/linux_interrupt.c b/bsd/compat/linuxkpi/src/linux_interrupt.c new file mode 120000 index 00000000..758b8b6a --- /dev/null +++ b/bsd/compat/linuxkpi/src/linux_interrupt.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/linux_interrupt.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/linux_sched.c b/bsd/compat/linuxkpi/src/linux_sched.c new file mode 120000 index 00000000..e0cdaf6c --- /dev/null +++ b/bsd/compat/linuxkpi/src/linux_sched.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/linux_sched.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/linux_semaphore.c b/bsd/compat/linuxkpi/src/linux_semaphore.c new file mode 120000 index 00000000..b9035814 --- /dev/null +++ b/bsd/compat/linuxkpi/src/linux_semaphore.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/linux_semaphore.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/linux_timer.c b/bsd/compat/linuxkpi/src/linux_timer.c new file mode 120000 index 00000000..c55e2dc1 --- /dev/null +++ b/bsd/compat/linuxkpi/src/linux_timer.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/linux_timer.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/linux_wakelock.c b/bsd/compat/linuxkpi/src/linux_wakelock.c new file mode 120000 index 00000000..fc48dfca --- /dev/null +++ b/bsd/compat/linuxkpi/src/linux_wakelock.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/linux_wakelock.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/linux_workqueue.c b/bsd/compat/linuxkpi/src/linux_workqueue.c new file mode 120000 index 00000000..de98e3b9 --- /dev/null +++ b/bsd/compat/linuxkpi/src/linux_workqueue.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/linux_workqueue.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/prctl.c b/bsd/compat/linuxkpi/src/prctl.c new file mode 120000 index 00000000..526eb743 --- /dev/null +++ b/bsd/compat/linuxkpi/src/prctl.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/prctl.c \ No newline at end of file diff --git a/bsd/compat/linuxkpi/src/tzdst.c b/bsd/compat/linuxkpi/src/tzdst.c new file mode 120000 index 00000000..8833fbb4 --- /dev/null +++ b/bsd/compat/linuxkpi/src/tzdst.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/tzdst.c \ No newline at end of file diff --git a/bsd/crypto/rijndael/rijndael-alg-fst.c b/bsd/crypto/rijndael/rijndael-alg-fst.c new file mode 120000 index 00000000..eb82dbfd --- /dev/null +++ b/bsd/crypto/rijndael/rijndael-alg-fst.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/crypto/rijndael/rijndael-alg-fst.c \ No newline at end of file diff --git a/bsd/crypto/rijndael/rijndael-api-fst.c b/bsd/crypto/rijndael/rijndael-api-fst.c new file mode 120000 index 00000000..e9f5f2a9 --- /dev/null +++ b/bsd/crypto/rijndael/rijndael-api-fst.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/crypto/rijndael/rijndael-api-fst.c \ No newline at end of file diff --git a/bsd/crypto/rijndael/rijndael-api-fst.h b/bsd/crypto/rijndael/rijndael-api-fst.h new file mode 120000 index 00000000..ec1cf599 --- /dev/null +++ b/bsd/crypto/rijndael/rijndael-api-fst.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/crypto/rijndael/rijndael-api-fst.h \ No newline at end of file diff --git a/bsd/crypto/rijndael/rijndael.h b/bsd/crypto/rijndael/rijndael.h new file mode 120000 index 00000000..f9c3474b --- /dev/null +++ b/bsd/crypto/rijndael/rijndael.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/crypto/rijndael/rijndael.h \ No newline at end of file diff --git a/bsd/crypto/rijndael/rijndael_local.h b/bsd/crypto/rijndael/rijndael_local.h new file mode 120000 index 00000000..9d8a607b --- /dev/null +++ b/bsd/crypto/rijndael/rijndael_local.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/crypto/rijndael/rijndael_local.h \ No newline at end of file diff --git a/bsd/crypto/sha2/sha256.h b/bsd/crypto/sha2/sha256.h new file mode 120000 index 00000000..30c79cf3 --- /dev/null +++ b/bsd/crypto/sha2/sha256.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/crypto/sha2/sha256.h \ No newline at end of file diff --git a/bsd/crypto/sha2/sha256c.c b/bsd/crypto/sha2/sha256c.c new file mode 120000 index 00000000..fd0534e4 --- /dev/null +++ b/bsd/crypto/sha2/sha256c.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/crypto/sha2/sha256c.c \ No newline at end of file diff --git a/bsd/dev/random/hash.c b/bsd/dev/random/hash.c new file mode 120000 index 00000000..529bd599 --- /dev/null +++ b/bsd/dev/random/hash.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/random/hash.c \ No newline at end of file diff --git a/bsd/dev/random/hash.h b/bsd/dev/random/hash.h new file mode 120000 index 00000000..7a93abec --- /dev/null +++ b/bsd/dev/random/hash.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/random/hash.h \ No newline at end of file diff --git a/bsd/dev/random/randomdev.h b/bsd/dev/random/randomdev.h new file mode 120000 index 00000000..c4fb7a8d --- /dev/null +++ b/bsd/dev/random/randomdev.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/random/randomdev.h \ No newline at end of file diff --git a/bsd/dev/random/uint128.h b/bsd/dev/random/uint128.h new file mode 120000 index 00000000..1bb9c89a --- /dev/null +++ b/bsd/dev/random/uint128.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/random/uint128.h \ No newline at end of file diff --git a/bsd/dev/random/unit_test.h b/bsd/dev/random/unit_test.h new file mode 120000 index 00000000..9bf98b1b --- /dev/null +++ b/bsd/dev/random/unit_test.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/random/unit_test.h \ No newline at end of file diff --git a/bsd/dev/random/yarrow.c b/bsd/dev/random/yarrow.c new file mode 120000 index 00000000..192b879c --- /dev/null +++ b/bsd/dev/random/yarrow.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/random/yarrow.c \ No newline at end of file diff --git a/bsd/dev/random/yarrow.h b/bsd/dev/random/yarrow.h new file mode 120000 index 00000000..b2dee7df --- /dev/null +++ b/bsd/dev/random/yarrow.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/random/yarrow.h \ No newline at end of file diff --git a/bsd/dev/usb/Kconfig b/bsd/dev/usb/Kconfig new file mode 100755 index 00000000..2bdac15f --- /dev/null +++ b/bsd/dev/usb/Kconfig @@ -0,0 +1,102 @@ +config DRIVERS_USB + bool "Enable USB" + default y + depends on DRIVERS && COMPAT_BSD + help + Answer Y to enable LiteOS support usb. + +config DRIVERS_USB_HOST_DRIVER + bool "Enable USB HCD" + default y + depends on DRIVERS_USB && DRIVERS + help + Answer Y to enable LiteOS to support usb host controller driver. + +choice + depends on DRIVERS_USB_HOST_DRIVER + prompt "USB HCD" + default y + help + Enable EHCI for USB 2.0. + Enable XHCI for USB 3.0 + +config DRIVERS_USB_HOST_EHCI + bool "Enable EHCI HCD (USB 2.0)" + depends on DRIVERS_USB + +config DRIVERS_USB_HOST_XHCI + bool "Enable XHCI HCD (USB 3.0)" + depends on DRIVERS_USB + +endchoice + +choice + depends on PLATFORM_HI3556AV100 && DRIVERS_USB_HOST_XHCI + prompt "" + default DRIVERS_USB3_HOST_FOR_PORT1 + help + This selects the usb3.0 port or usb2.0 port. + +config DRIVERS_USB3_HOST_FOR_PORT1 + bool "Enable USB3.0 Host Controller For USB3.0 Port1" + +config DRIVERS_USB3_HOST_FOR_PORT2 + bool "Enable USB3.0 Host Controller For USB2.0 Port2" + +endchoice + +config DRIVERS_USB_DEVICE_CLASS_DRIVERS + bool "Enable USB Device Class Drivers" + default y + depends on DRIVERS_USB && DRIVERS && DRIVERS_USB_HOST_DRIVER + help + Answer Y to enable LiteOS to support usb device class drivers. + +menu "USB Device Class Drivers" + depends on DRIVERS_USB_DEVICE_CLASS_DRIVERS +config DRIVERS_USB_MASS_STORAGE + bool "Enable USB Mass Storage Support" + default y + depends on DRIVERS_USB_DEVICE_CLASS_DRIVERS && FS_VFS + help + Say Y here if you want to connect USB mass storage devices to your system's USB port. + +config DRIVERS_USB_RNDIS_HOST + bool "Enable USB Rndis Host Support" + default y + depends on DRIVERS_USB_DEVICE_CLASS_DRIVERS && NET_LWIP_SACK + help + Say Y here if you want to connect USB Rndis Host devices to your system's USB port. + +config DRIVERS_USB_4G_MODEM + bool "Enable USB 4G Modem Support" + default y + depends on DRIVERS_USB_DEVICE_CLASS_DRIVERS && NET_LWIP_SACK + help + Say Y here if you want to connect USB 4G devices to your system's USB port. + +config DRIVERS_USB_SERIAL + bool "Enable USB Serial Converter Support" + default y + depends on DRIVERS_USB_DEVICE_CLASS_DRIVERS + help + Say Y here if you want to connect USB serial devices to your system's USB port. + +config DRIVERS_USB_ETHERNET + bool "Enable USB Ethernet Support" + depends on NET_LWIP_SACK && DRIVERS_USB_DEVICE_CLASS_DRIVERS + help + Say Y here if you want to connect USB ethernet devices to your system's USB port. + +config DRIVERS_USB_WIRELESS + bool "Enable USB Wireless Device Support" + depends on NET_LWIP_SACK && DRIVERS_USB_DEVICE_CLASS_DRIVERS + help + Say Y here if you want to connect usb-wifi devices to your system's USB port. +config DRIVERS_USB_HID_CLASS + bool "Enable USB HID Device Support" + depends on DRIVERS_USB_DEVICE_CLASS_DRIVERS && FS_VFS + help + Say Y here if you want to connect hid devices to your system's USB port. + +endmenu diff --git a/bsd/dev/usb/Makefile b/bsd/dev/usb/Makefile new file mode 100755 index 00000000..5eaa4120 --- /dev/null +++ b/bsd/dev/usb/Makefile @@ -0,0 +1,131 @@ +# 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 := usb_base + +CONTROLLER_HOST_SRC = controller +CORE_SRC = . +IMPLEMENTATION_SRC = implementation +Net_SRC = net +QUIRK_SRC = quirk +SERIAL_SRC = serial +STORAGE_SRC = storage +INPUT_SRC = input +LOCAL_SRCS := $(CORE_SRC)/usb_debug.c \ + $(IMPLEMENTATION_SRC)/bsd_busspace.c \ + $(IMPLEMENTATION_SRC)/usb_busdma_loader.c \ + $(IMPLEMENTATION_SRC)/bsd_kernel.c \ + $(IMPLEMENTATION_SRC)/usb_init.c \ + $(IMPLEMENTATION_SRC)/usb_version.c \ + $(IMPLEMENTATION_SRC)/usb_btree.c + +ifeq ($(LOSCFG_DRIVERS_USB), y) +LOCAL_SRCS += $(CORE_SRC)/usb_dynamic.c \ + $(CORE_SRC)/usb_parse.c \ + $(CORE_SRC)/usb_error.c \ + $(CORE_SRC)/usb_handle_request.c \ + $(CORE_SRC)/usb_util.c \ + $(CORE_SRC)/usb_lookup.c \ + $(CONTROLLER_HOST_SRC)/usb_controller.c \ + $(QUIRK_SRC)/usb_quirk.c \ + $(CORE_SRC)/usb_device.c \ + $(CORE_SRC)/usb_process.c \ + $(CORE_SRC)/usb_hub.c \ + $(CORE_SRC)/usb_request.c \ + $(CORE_SRC)/usb_transfer.c \ + $(CORE_SRC)/usb_dev.c \ + $(CORE_SRC)/usb_mbuf.c \ + $(CORE_SRC)/usb_generic.c \ + $(CORE_SRC)/usb_if.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_4G_MODEM), y) +LOCAL_SRCS += $(Net_SRC)/if_cdce.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_ETHERNET), y) +LOCAL_SRCS += $(Net_SRC)/if_axe.c \ + $(Net_SRC)/if_axge.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_RNDIS_HOST), y) +LOCAL_SRCS += $(Net_SRC)/if_urndis.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_4G_MODEM), y) +LOCAL_SRCS += $(Net_SRC)/usb_eth_drv.c \ + $(Net_SRC)/usb_ethernet.c +else ifeq ($(LOSCFG_DRIVERS_USB_ETHERNET), y) +LOCAL_SRCS += $(Net_SRC)/usb_eth_drv.c \ + $(Net_SRC)/usb_ethernet.c +else ifeq ($(LOSCFG_DRIVERS_USB_RNDIS_HOST), y) +LOCAL_SRCS += $(Net_SRC)/usb_eth_drv.c\ + $(Net_SRC)/usb_ethernet.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_4G_MODEM), y) +LOCAL_SRCS += $(SERIAL_SRC)/usb_serial.c \ + $(SERIAL_SRC)/u3g.c +else ifeq ($(LOSCFG_DRIVERS_USB_SERIAL), y) +LOCAL_SRCS += $(SERIAL_SRC)/usb_serial.c \ + $(SERIAL_SRC)/u3g.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_HOST_EHCI), y) +LOCAL_SRCS += $(CONTROLLER_HOST_SRC)/ehci_pci.c \ + $(CONTROLLER_HOST_SRC)/ehci.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_HOST_XHCI), y) +LOCAL_SRCS += $(CONTROLLER_HOST_SRC)/xhci.c \ + $(CONTROLLER_HOST_SRC)/xhci_pci.c +else ifeq ($(LOSCFG_DRIVERS_USB_HOST_XHCI_FOR_PORT2), y) +LOCAL_SRCS += $(CONTROLLER_HOST_SRC)/xhci.c \ + $(CONTROLLER_HOST_SRC)/xhci_pci.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_WIRELESS), y) +LOCAL_SRCS += $(CORE_SRC)/linux_usb.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_MASS_STORAGE), y) +LOCAL_SRCS += $(STORAGE_SRC)/umass.c +endif + +ifeq ($(LOSCFG_DRIVERS_USB_HID_CLASS), y) +LOCAL_SRCS += $(INPUT_SRC)/uhid.c \ + $(CORE_SRC)/usb_hid.c +endif + +LOCAL_FLAGS += $(LITEOS_GCOV_OPTS) + +include $(MODULE) + diff --git a/bsd/dev/usb/controller/ehci.c b/bsd/dev/usb/controller/ehci.c new file mode 120000 index 00000000..580e5096 --- /dev/null +++ b/bsd/dev/usb/controller/ehci.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/controller/ehci.c \ No newline at end of file diff --git a/bsd/dev/usb/controller/ehci.h b/bsd/dev/usb/controller/ehci.h new file mode 120000 index 00000000..bdbe96c2 --- /dev/null +++ b/bsd/dev/usb/controller/ehci.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/controller/ehci.h \ No newline at end of file diff --git a/bsd/dev/usb/controller/ehci_pci.c b/bsd/dev/usb/controller/ehci_pci.c new file mode 120000 index 00000000..468a4591 --- /dev/null +++ b/bsd/dev/usb/controller/ehci_pci.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/controller/ehci_pci.c \ No newline at end of file diff --git a/bsd/dev/usb/controller/ehcireg.h b/bsd/dev/usb/controller/ehcireg.h new file mode 120000 index 00000000..438e0c5b --- /dev/null +++ b/bsd/dev/usb/controller/ehcireg.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/controller/ehcireg.h \ No newline at end of file diff --git a/bsd/dev/usb/controller/usb_controller.c b/bsd/dev/usb/controller/usb_controller.c new file mode 120000 index 00000000..603ad2dc --- /dev/null +++ b/bsd/dev/usb/controller/usb_controller.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/controller/usb_controller.c \ No newline at end of file diff --git a/bsd/dev/usb/controller/xhci.c b/bsd/dev/usb/controller/xhci.c new file mode 120000 index 00000000..3d3d07d0 --- /dev/null +++ b/bsd/dev/usb/controller/xhci.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/controller/xhci.c \ No newline at end of file diff --git a/bsd/dev/usb/controller/xhci.h b/bsd/dev/usb/controller/xhci.h new file mode 120000 index 00000000..cde351d6 --- /dev/null +++ b/bsd/dev/usb/controller/xhci.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/controller/xhci.h \ No newline at end of file diff --git a/bsd/dev/usb/controller/xhci_pci.c b/bsd/dev/usb/controller/xhci_pci.c new file mode 120000 index 00000000..a1671800 --- /dev/null +++ b/bsd/dev/usb/controller/xhci_pci.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/controller/xhci_pci.c \ No newline at end of file diff --git a/bsd/dev/usb/controller/xhcireg.h b/bsd/dev/usb/controller/xhcireg.h new file mode 120000 index 00000000..ea9f0dc1 --- /dev/null +++ b/bsd/dev/usb/controller/xhcireg.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/controller/xhcireg.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/_macro_ref.h b/bsd/dev/usb/implementation/_macro_ref.h new file mode 120000 index 00000000..0bb8b8ad --- /dev/null +++ b/bsd/dev/usb/implementation/_macro_ref.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/_macro_ref.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/_thread_ref.h b/bsd/dev/usb/implementation/_thread_ref.h new file mode 120000 index 00000000..4abbfd4f --- /dev/null +++ b/bsd/dev/usb/implementation/_thread_ref.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/_thread_ref.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/_types_ref.h b/bsd/dev/usb/implementation/_types_ref.h new file mode 120000 index 00000000..200e9c7e --- /dev/null +++ b/bsd/dev/usb/implementation/_types_ref.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/_types_ref.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/bsd_busspace.c b/bsd/dev/usb/implementation/bsd_busspace.c new file mode 120000 index 00000000..53d8bbf7 --- /dev/null +++ b/bsd/dev/usb/implementation/bsd_busspace.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/stand/kshim/bsd_busspace.c \ No newline at end of file diff --git a/bsd/dev/usb/implementation/bsd_kernel.c b/bsd/dev/usb/implementation/bsd_kernel.c new file mode 120000 index 00000000..32d71825 --- /dev/null +++ b/bsd/dev/usb/implementation/bsd_kernel.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/stand/kshim/bsd_kernel.c \ No newline at end of file diff --git a/bsd/dev/usb/implementation/bsd_kernel.h b/bsd/dev/usb/implementation/bsd_kernel.h new file mode 120000 index 00000000..3b91da37 --- /dev/null +++ b/bsd/dev/usb/implementation/bsd_kernel.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/stand/kshim/bsd_kernel.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/freebsd_sys.h b/bsd/dev/usb/implementation/freebsd_sys.h new file mode 120000 index 00000000..e35723ee --- /dev/null +++ b/bsd/dev/usb/implementation/freebsd_sys.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/freebsd_sys.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/freebsd_usb.h b/bsd/dev/usb/implementation/freebsd_usb.h new file mode 120000 index 00000000..de6fe4d2 --- /dev/null +++ b/bsd/dev/usb/implementation/freebsd_usb.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/freebsd_usb.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/global_implementation.h b/bsd/dev/usb/implementation/global_implementation.h new file mode 120000 index 00000000..2deea9d9 --- /dev/null +++ b/bsd/dev/usb/implementation/global_implementation.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/global_implementation.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/usb_api_pri.h b/bsd/dev/usb/implementation/usb_api_pri.h new file mode 120000 index 00000000..41f4e850 --- /dev/null +++ b/bsd/dev/usb/implementation/usb_api_pri.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/usb_api_pri.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/usb_btree.c b/bsd/dev/usb/implementation/usb_btree.c new file mode 120000 index 00000000..8ea1fd06 --- /dev/null +++ b/bsd/dev/usb/implementation/usb_btree.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/usb_btree.c \ No newline at end of file diff --git a/bsd/dev/usb/implementation/usb_btree.h b/bsd/dev/usb/implementation/usb_btree.h new file mode 120000 index 00000000..6daf0d0b --- /dev/null +++ b/bsd/dev/usb/implementation/usb_btree.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/usb_btree.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/usb_busdma_loader.c b/bsd/dev/usb/implementation/usb_busdma_loader.c new file mode 120000 index 00000000..25fda953 --- /dev/null +++ b/bsd/dev/usb/implementation/usb_busdma_loader.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/stand/usb/usb_busdma_loader.c \ No newline at end of file diff --git a/bsd/dev/usb/implementation/usb_init.c b/bsd/dev/usb/implementation/usb_init.c new file mode 120000 index 00000000..ff702025 --- /dev/null +++ b/bsd/dev/usb/implementation/usb_init.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/usb_init.c \ No newline at end of file diff --git a/bsd/dev/usb/implementation/usb_init.h b/bsd/dev/usb/implementation/usb_init.h new file mode 120000 index 00000000..2294e821 --- /dev/null +++ b/bsd/dev/usb/implementation/usb_init.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/usb_init.h \ No newline at end of file diff --git a/bsd/dev/usb/implementation/usb_version.c b/bsd/dev/usb/implementation/usb_version.c new file mode 120000 index 00000000..98bbe214 --- /dev/null +++ b/bsd/dev/usb/implementation/usb_version.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/usb_version.c \ No newline at end of file diff --git a/bsd/dev/usb/implementation/usbdevs.h b/bsd/dev/usb/implementation/usbdevs.h new file mode 120000 index 00000000..7268cbea --- /dev/null +++ b/bsd/dev/usb/implementation/usbdevs.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/implementation/usbdevs.h \ No newline at end of file diff --git a/bsd/dev/usb/input/uhid.c b/bsd/dev/usb/input/uhid.c new file mode 120000 index 00000000..3b7815ec --- /dev/null +++ b/bsd/dev/usb/input/uhid.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/input/uhid.c \ No newline at end of file diff --git a/bsd/dev/usb/input/usb_rdesc.h b/bsd/dev/usb/input/usb_rdesc.h new file mode 120000 index 00000000..ead4cbdc --- /dev/null +++ b/bsd/dev/usb/input/usb_rdesc.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/input/usb_rdesc.h \ No newline at end of file diff --git a/bsd/dev/usb/linux_usb.c b/bsd/dev/usb/linux_usb.c new file mode 120000 index 00000000..02829ea5 --- /dev/null +++ b/bsd/dev/usb/linux_usb.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/src/linux_usb.c \ No newline at end of file diff --git a/bsd/dev/usb/linux_usb.h b/bsd/dev/usb/linux_usb.h new file mode 120000 index 00000000..09a40781 --- /dev/null +++ b/bsd/dev/usb/linux_usb.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/compat/linuxkpi/common/include/linux/usb.h \ No newline at end of file diff --git a/bsd/dev/usb/net/if_axe.c b/bsd/dev/usb/net/if_axe.c new file mode 120000 index 00000000..5e0cd316 --- /dev/null +++ b/bsd/dev/usb/net/if_axe.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/if_axe.c \ No newline at end of file diff --git a/bsd/dev/usb/net/if_axereg.h b/bsd/dev/usb/net/if_axereg.h new file mode 120000 index 00000000..e5360198 --- /dev/null +++ b/bsd/dev/usb/net/if_axereg.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/if_axereg.h \ No newline at end of file diff --git a/bsd/dev/usb/net/if_axge.c b/bsd/dev/usb/net/if_axge.c new file mode 120000 index 00000000..5b7707c1 --- /dev/null +++ b/bsd/dev/usb/net/if_axge.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/if_axge.c \ No newline at end of file diff --git a/bsd/dev/usb/net/if_axgereg.h b/bsd/dev/usb/net/if_axgereg.h new file mode 120000 index 00000000..92ddbbc0 --- /dev/null +++ b/bsd/dev/usb/net/if_axgereg.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/if_axgereg.h \ No newline at end of file diff --git a/bsd/dev/usb/net/if_cdce.c b/bsd/dev/usb/net/if_cdce.c new file mode 120000 index 00000000..ddce6582 --- /dev/null +++ b/bsd/dev/usb/net/if_cdce.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/if_cdce.c \ No newline at end of file diff --git a/bsd/dev/usb/net/if_cdcereg.h b/bsd/dev/usb/net/if_cdcereg.h new file mode 120000 index 00000000..8c49aa92 --- /dev/null +++ b/bsd/dev/usb/net/if_cdcereg.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/if_cdcereg.h \ No newline at end of file diff --git a/bsd/dev/usb/net/if_urndis.c b/bsd/dev/usb/net/if_urndis.c new file mode 120000 index 00000000..c8e3aa86 --- /dev/null +++ b/bsd/dev/usb/net/if_urndis.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/if_urndis.c \ No newline at end of file diff --git a/bsd/dev/usb/net/if_urndisreg.h b/bsd/dev/usb/net/if_urndisreg.h new file mode 120000 index 00000000..2c301bd0 --- /dev/null +++ b/bsd/dev/usb/net/if_urndisreg.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/if_urndisreg.h \ No newline at end of file diff --git a/bsd/dev/usb/net/mii.h b/bsd/dev/usb/net/mii.h new file mode 120000 index 00000000..31752ff1 --- /dev/null +++ b/bsd/dev/usb/net/mii.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/mii/mii.h \ No newline at end of file diff --git a/bsd/dev/usb/net/usb_eth_drv.c b/bsd/dev/usb/net/usb_eth_drv.c new file mode 120000 index 00000000..9322c742 --- /dev/null +++ b/bsd/dev/usb/net/usb_eth_drv.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/usb_eth_drv.c \ No newline at end of file diff --git a/bsd/dev/usb/net/usb_eth_drv.h b/bsd/dev/usb/net/usb_eth_drv.h new file mode 120000 index 00000000..22d05e55 --- /dev/null +++ b/bsd/dev/usb/net/usb_eth_drv.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/usb_eth_drv.h \ No newline at end of file diff --git a/bsd/dev/usb/net/usb_ethernet.c b/bsd/dev/usb/net/usb_ethernet.c new file mode 120000 index 00000000..f09d6597 --- /dev/null +++ b/bsd/dev/usb/net/usb_ethernet.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/usb_ethernet.c \ No newline at end of file diff --git a/bsd/dev/usb/net/usb_ethernet.h b/bsd/dev/usb/net/usb_ethernet.h new file mode 120000 index 00000000..81a3f57c --- /dev/null +++ b/bsd/dev/usb/net/usb_ethernet.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/net/usb_ethernet.h \ No newline at end of file diff --git a/bsd/dev/usb/quirk/usb_quirk.c b/bsd/dev/usb/quirk/usb_quirk.c new file mode 120000 index 00000000..f4aea237 --- /dev/null +++ b/bsd/dev/usb/quirk/usb_quirk.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/quirk/usb_quirk.c \ No newline at end of file diff --git a/bsd/dev/usb/quirk/usb_quirk.h b/bsd/dev/usb/quirk/usb_quirk.h new file mode 120000 index 00000000..4ed3ea90 --- /dev/null +++ b/bsd/dev/usb/quirk/usb_quirk.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/quirk/usb_quirk.h \ No newline at end of file diff --git a/bsd/dev/usb/serial.h b/bsd/dev/usb/serial.h new file mode 120000 index 00000000..9270f051 --- /dev/null +++ b/bsd/dev/usb/serial.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/sys/serial.h \ No newline at end of file diff --git a/bsd/dev/usb/serial/u3g.c b/bsd/dev/usb/serial/u3g.c new file mode 120000 index 00000000..4294b9df --- /dev/null +++ b/bsd/dev/usb/serial/u3g.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/serial/u3g.c \ No newline at end of file diff --git a/bsd/dev/usb/serial/usb_serial.c b/bsd/dev/usb/serial/usb_serial.c new file mode 120000 index 00000000..5f346935 --- /dev/null +++ b/bsd/dev/usb/serial/usb_serial.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/serial/usb_serial.c \ No newline at end of file diff --git a/bsd/dev/usb/serial/usb_serial.h b/bsd/dev/usb/serial/usb_serial.h new file mode 120000 index 00000000..0a325644 --- /dev/null +++ b/bsd/dev/usb/serial/usb_serial.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/serial/usb_serial.h \ No newline at end of file diff --git a/bsd/dev/usb/storage/scsi.h b/bsd/dev/usb/storage/scsi.h new file mode 120000 index 00000000..2a04e33c --- /dev/null +++ b/bsd/dev/usb/storage/scsi.h @@ -0,0 +1 @@ +../../../../../../third_party/NuttX/include/nuttx/scsi.h \ No newline at end of file diff --git a/bsd/dev/usb/storage/scsi_all.h b/bsd/dev/usb/storage/scsi_all.h new file mode 120000 index 00000000..fc25d9d4 --- /dev/null +++ b/bsd/dev/usb/storage/scsi_all.h @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/cam/scsi/scsi_all.h \ No newline at end of file diff --git a/bsd/dev/usb/storage/umass.c b/bsd/dev/usb/storage/umass.c new file mode 120000 index 00000000..4a961a0d --- /dev/null +++ b/bsd/dev/usb/storage/umass.c @@ -0,0 +1 @@ +../../../../../../third_party/FreeBSD/sys/dev/usb/storage/umass.c \ No newline at end of file diff --git a/bsd/dev/usb/storage/umass_fs.h b/bsd/dev/usb/storage/umass_fs.h new file mode 120000 index 00000000..878547e7 --- /dev/null +++ b/bsd/dev/usb/storage/umass_fs.h @@ -0,0 +1 @@ +../../../../../../third_party/NuttX/include/nuttx/usb/storage.h \ No newline at end of file diff --git a/bsd/dev/usb/usb.h b/bsd/dev/usb/usb.h new file mode 120000 index 00000000..98080d6f --- /dev/null +++ b/bsd/dev/usb/usb.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_bus.h b/bsd/dev/usb/usb_bus.h new file mode 120000 index 00000000..9570cf7b --- /dev/null +++ b/bsd/dev/usb/usb_bus.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_bus.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_busdma.h b/bsd/dev/usb/usb_busdma.h new file mode 120000 index 00000000..79da69fa --- /dev/null +++ b/bsd/dev/usb/usb_busdma.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_busdma.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_cdc.h b/bsd/dev/usb/usb_cdc.h new file mode 120000 index 00000000..ba1456f7 --- /dev/null +++ b/bsd/dev/usb/usb_cdc.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_cdc.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_controller.h b/bsd/dev/usb/usb_controller.h new file mode 120000 index 00000000..7abe004f --- /dev/null +++ b/bsd/dev/usb/usb_controller.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_controller.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_core.c b/bsd/dev/usb/usb_core.c new file mode 120000 index 00000000..d45c5007 --- /dev/null +++ b/bsd/dev/usb/usb_core.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_core.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_core.h b/bsd/dev/usb/usb_core.h new file mode 120000 index 00000000..51169e12 --- /dev/null +++ b/bsd/dev/usb/usb_core.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_core.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_debug.c b/bsd/dev/usb/usb_debug.c new file mode 120000 index 00000000..e715de30 --- /dev/null +++ b/bsd/dev/usb/usb_debug.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_debug.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_debug.h b/bsd/dev/usb/usb_debug.h new file mode 120000 index 00000000..a8afa3ec --- /dev/null +++ b/bsd/dev/usb/usb_debug.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_debug.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_dev.c b/bsd/dev/usb/usb_dev.c new file mode 120000 index 00000000..87796e1b --- /dev/null +++ b/bsd/dev/usb/usb_dev.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_dev.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_dev.h b/bsd/dev/usb/usb_dev.h new file mode 120000 index 00000000..6ef815a9 --- /dev/null +++ b/bsd/dev/usb/usb_dev.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_dev.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_device.c b/bsd/dev/usb/usb_device.c new file mode 120000 index 00000000..fb9877ec --- /dev/null +++ b/bsd/dev/usb/usb_device.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_device.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_device.h b/bsd/dev/usb/usb_device.h new file mode 120000 index 00000000..cc4dc64b --- /dev/null +++ b/bsd/dev/usb/usb_device.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_device.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_dynamic.c b/bsd/dev/usb/usb_dynamic.c new file mode 120000 index 00000000..c574c631 --- /dev/null +++ b/bsd/dev/usb/usb_dynamic.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_dynamic.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_dynamic.h b/bsd/dev/usb/usb_dynamic.h new file mode 120000 index 00000000..61873333 --- /dev/null +++ b/bsd/dev/usb/usb_dynamic.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_dynamic.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_endian.h b/bsd/dev/usb/usb_endian.h new file mode 120000 index 00000000..49970156 --- /dev/null +++ b/bsd/dev/usb/usb_endian.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_endian.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_error.c b/bsd/dev/usb/usb_error.c new file mode 120000 index 00000000..4d5e70df --- /dev/null +++ b/bsd/dev/usb/usb_error.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_error.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_freebsd_loader.h b/bsd/dev/usb/usb_freebsd_loader.h new file mode 120000 index 00000000..5e7aabd7 --- /dev/null +++ b/bsd/dev/usb/usb_freebsd_loader.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_freebsd_loader.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_generic.c b/bsd/dev/usb/usb_generic.c new file mode 120000 index 00000000..fb65b651 --- /dev/null +++ b/bsd/dev/usb/usb_generic.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_generic.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_generic.h b/bsd/dev/usb/usb_generic.h new file mode 120000 index 00000000..8befb6c5 --- /dev/null +++ b/bsd/dev/usb/usb_generic.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_generic.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_handle_request.c b/bsd/dev/usb/usb_handle_request.c new file mode 120000 index 00000000..3fd0764c --- /dev/null +++ b/bsd/dev/usb/usb_handle_request.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_handle_request.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_hid.c b/bsd/dev/usb/usb_hid.c new file mode 120000 index 00000000..55b33ac4 --- /dev/null +++ b/bsd/dev/usb/usb_hid.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_hid.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_hub.c b/bsd/dev/usb/usb_hub.c new file mode 120000 index 00000000..2f4c414e --- /dev/null +++ b/bsd/dev/usb/usb_hub.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_hub.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_hub.h b/bsd/dev/usb/usb_hub.h new file mode 120000 index 00000000..3921270e --- /dev/null +++ b/bsd/dev/usb/usb_hub.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_hub.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_if.c b/bsd/dev/usb/usb_if.c new file mode 120000 index 00000000..c3153d57 --- /dev/null +++ b/bsd/dev/usb/usb_if.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_if.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_if.h b/bsd/dev/usb/usb_if.h new file mode 120000 index 00000000..36f651f7 --- /dev/null +++ b/bsd/dev/usb/usb_if.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_if.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_ioctl.h b/bsd/dev/usb/usb_ioctl.h new file mode 120000 index 00000000..efc78e39 --- /dev/null +++ b/bsd/dev/usb/usb_ioctl.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_ioctl.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_lookup.c b/bsd/dev/usb/usb_lookup.c new file mode 120000 index 00000000..b2250f89 --- /dev/null +++ b/bsd/dev/usb/usb_lookup.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_lookup.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_mbuf.c b/bsd/dev/usb/usb_mbuf.c new file mode 120000 index 00000000..4b6732e8 --- /dev/null +++ b/bsd/dev/usb/usb_mbuf.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_mbuf.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_mbuf.h b/bsd/dev/usb/usb_mbuf.h new file mode 120000 index 00000000..6e4b02e1 --- /dev/null +++ b/bsd/dev/usb/usb_mbuf.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_mbuf.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_parse.c b/bsd/dev/usb/usb_parse.c new file mode 120000 index 00000000..be492026 --- /dev/null +++ b/bsd/dev/usb/usb_parse.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_parse.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_process.c b/bsd/dev/usb/usb_process.c new file mode 120000 index 00000000..9c81bf2c --- /dev/null +++ b/bsd/dev/usb/usb_process.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_process.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_process.h b/bsd/dev/usb/usb_process.h new file mode 120000 index 00000000..c01ef856 --- /dev/null +++ b/bsd/dev/usb/usb_process.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_process.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_request.c b/bsd/dev/usb/usb_request.c new file mode 120000 index 00000000..9fc07786 --- /dev/null +++ b/bsd/dev/usb/usb_request.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_request.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_request.h b/bsd/dev/usb/usb_request.h new file mode 120000 index 00000000..6faf149c --- /dev/null +++ b/bsd/dev/usb/usb_request.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_request.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_transfer.c b/bsd/dev/usb/usb_transfer.c new file mode 120000 index 00000000..14da3d87 --- /dev/null +++ b/bsd/dev/usb/usb_transfer.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_transfer.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_transfer.h b/bsd/dev/usb/usb_transfer.h new file mode 120000 index 00000000..8520c64f --- /dev/null +++ b/bsd/dev/usb/usb_transfer.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_transfer.h \ No newline at end of file diff --git a/bsd/dev/usb/usb_util.c b/bsd/dev/usb/usb_util.c new file mode 120000 index 00000000..d4d290da --- /dev/null +++ b/bsd/dev/usb/usb_util.c @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_util.c \ No newline at end of file diff --git a/bsd/dev/usb/usb_util.h b/bsd/dev/usb/usb_util.h new file mode 120000 index 00000000..0470a037 --- /dev/null +++ b/bsd/dev/usb/usb_util.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usb_util.h \ No newline at end of file diff --git a/bsd/dev/usb/usbdi.h b/bsd/dev/usb/usbdi.h new file mode 120000 index 00000000..3fa51ad3 --- /dev/null +++ b/bsd/dev/usb/usbdi.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usbdi.h \ No newline at end of file diff --git a/bsd/dev/usb/usbdi_util.h b/bsd/dev/usb/usbdi_util.h new file mode 120000 index 00000000..e726cc24 --- /dev/null +++ b/bsd/dev/usb/usbdi_util.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usbdi_util.h \ No newline at end of file diff --git a/bsd/dev/usb/usbhid.h b/bsd/dev/usb/usbhid.h new file mode 120000 index 00000000..410e9d76 --- /dev/null +++ b/bsd/dev/usb/usbhid.h @@ -0,0 +1 @@ +../../../../../third_party/FreeBSD/sys/dev/usb/usbhid.h \ No newline at end of file diff --git a/bsd/kern/bus_if.c b/bsd/kern/bus_if.c new file mode 120000 index 00000000..1561860f --- /dev/null +++ b/bsd/kern/bus_if.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/kern/bus_if.c \ No newline at end of file diff --git a/bsd/kern/bus_if.h b/bsd/kern/bus_if.h new file mode 120000 index 00000000..d8e93ac9 --- /dev/null +++ b/bsd/kern/bus_if.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/kern/bus_if.h \ No newline at end of file diff --git a/bsd/kern/device_if.c b/bsd/kern/device_if.c new file mode 120000 index 00000000..a018079c --- /dev/null +++ b/bsd/kern/device_if.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/kern/device_if.c \ No newline at end of file diff --git a/bsd/kern/device_if.h b/bsd/kern/device_if.h new file mode 120000 index 00000000..47739543 --- /dev/null +++ b/bsd/kern/device_if.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/kern/device_if.h \ No newline at end of file diff --git a/bsd/kern/kern_condvar.c b/bsd/kern/kern_condvar.c new file mode 120000 index 00000000..7352eb86 --- /dev/null +++ b/bsd/kern/kern_condvar.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/kern/kern_condvar.c \ No newline at end of file diff --git a/bsd/kern/kern_timeout.c b/bsd/kern/kern_timeout.c new file mode 120000 index 00000000..24d34da2 --- /dev/null +++ b/bsd/kern/kern_timeout.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/kern/kern_timeout.c \ No newline at end of file diff --git a/bsd/kern/subr_bus.c b/bsd/kern/subr_bus.c new file mode 120000 index 00000000..c003b0c8 --- /dev/null +++ b/bsd/kern/subr_bus.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/kern/subr_bus.c \ No newline at end of file diff --git a/bsd/kern/subr_kobj.c b/bsd/kern/subr_kobj.c new file mode 120000 index 00000000..f339bb21 --- /dev/null +++ b/bsd/kern/subr_kobj.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/kern/subr_kobj.c \ No newline at end of file diff --git a/bsd/libkern/explicit_bzero.c b/bsd/libkern/explicit_bzero.c new file mode 120000 index 00000000..b4d4d101 --- /dev/null +++ b/bsd/libkern/explicit_bzero.c @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/libkern/explicit_bzero.c \ No newline at end of file diff --git a/bsd/net/ppp_defs.h b/bsd/net/ppp_defs.h new file mode 120000 index 00000000..6ac30526 --- /dev/null +++ b/bsd/net/ppp_defs.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/net/ppp_defs.h \ No newline at end of file diff --git a/bsd/sys/_callout.h b/bsd/sys/_callout.h new file mode 120000 index 00000000..513f2665 --- /dev/null +++ b/bsd/sys/_callout.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/_callout.h \ No newline at end of file diff --git a/bsd/sys/bus.h b/bsd/sys/bus.h new file mode 120000 index 00000000..51b415e8 --- /dev/null +++ b/bsd/sys/bus.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/bus.h \ No newline at end of file diff --git a/bsd/sys/callout.h b/bsd/sys/callout.h new file mode 120000 index 00000000..1c5a8ba9 --- /dev/null +++ b/bsd/sys/callout.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/callout.h \ No newline at end of file diff --git a/bsd/sys/cdefs.h b/bsd/sys/cdefs.h new file mode 120000 index 00000000..ca38dcb1 --- /dev/null +++ b/bsd/sys/cdefs.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/cdefs.h \ No newline at end of file diff --git a/bsd/sys/condvar.h b/bsd/sys/condvar.h new file mode 120000 index 00000000..5948c1a2 --- /dev/null +++ b/bsd/sys/condvar.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/condvar.h \ No newline at end of file diff --git a/bsd/sys/kernel.h b/bsd/sys/kernel.h new file mode 120000 index 00000000..a22030ec --- /dev/null +++ b/bsd/sys/kernel.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/kernel.h \ No newline at end of file diff --git a/bsd/sys/kobj.h b/bsd/sys/kobj.h new file mode 120000 index 00000000..465e8619 --- /dev/null +++ b/bsd/sys/kobj.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/kobj.h \ No newline at end of file diff --git a/bsd/sys/linker_set.h b/bsd/sys/linker_set.h new file mode 120000 index 00000000..4b7e6772 --- /dev/null +++ b/bsd/sys/linker_set.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/linker_set.h \ No newline at end of file diff --git a/bsd/sys/malloc.h b/bsd/sys/malloc.h new file mode 120000 index 00000000..73fd4e30 --- /dev/null +++ b/bsd/sys/malloc.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/malloc.h \ No newline at end of file diff --git a/bsd/sys/module.h b/bsd/sys/module.h new file mode 120000 index 00000000..7058563a --- /dev/null +++ b/bsd/sys/module.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/module.h \ No newline at end of file diff --git a/bsd/sys/mutex.h b/bsd/sys/mutex.h new file mode 120000 index 00000000..47606d1b --- /dev/null +++ b/bsd/sys/mutex.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/mutex.h \ No newline at end of file diff --git a/bsd/sys/priv.h b/bsd/sys/priv.h new file mode 120000 index 00000000..5302a516 --- /dev/null +++ b/bsd/sys/priv.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/priv.h \ No newline at end of file diff --git a/bsd/sys/queue.h b/bsd/sys/queue.h new file mode 120000 index 00000000..762e5add --- /dev/null +++ b/bsd/sys/queue.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/queue.h \ No newline at end of file diff --git a/bsd/sys/sema.h b/bsd/sys/sema.h new file mode 120000 index 00000000..ddf8c43b --- /dev/null +++ b/bsd/sys/sema.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/sema.h \ No newline at end of file diff --git a/bsd/sys/sx.h b/bsd/sys/sx.h new file mode 120000 index 00000000..202ca5f0 --- /dev/null +++ b/bsd/sys/sx.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/sx.h \ No newline at end of file diff --git a/bsd/sys/systm.h b/bsd/sys/systm.h new file mode 120000 index 00000000..82118401 --- /dev/null +++ b/bsd/sys/systm.h @@ -0,0 +1 @@ +../../../../third_party/FreeBSD/sys/sys/systm.h \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..bcdf9009 --- /dev/null +++ b/build.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# +# 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. +set -e + +echo "sh param:$1,$2,$3" +source="tools/build/config/$1_release.config" +destination=".config" +if [ "$2" = "clang" ]; then + if [ "$3" = "debug" ]; then + source="tools/build/config/debug/$1_$2.config" + else + source="tools/build/config/$1_$2_release.config" + fi +elif [ "$2" = "gcc" ]; then + if [ "$3" = "debug" ]; then + source="tools/build/config/$1_debug_shell.config" + else + source="tools/build/config/$1_release.config" + fi +fi +if [ -d "./out" ]; then + rm -rf ./out +fi +if [ -f "$destination" ]; then + rm -rf $destination +fi +cp $source $destination diff --git a/compat/posix/Kconfig b/compat/posix/Kconfig new file mode 100755 index 00000000..1d0c733e --- /dev/null +++ b/compat/posix/Kconfig @@ -0,0 +1,6 @@ +config COMPAT_POSIX + bool "Enable Posix" + default y + + help + Answer Y to enable LiteOS support posix interface. \ No newline at end of file diff --git a/compat/posix/Makefile b/compat/posix/Makefile new file mode 100755 index 00000000..02c6cc9f --- /dev/null +++ b/compat/posix/Makefile @@ -0,0 +1,42 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include $(LITEOSTOPDIR)/config.mk + +MODULE_NAME := $(notdir $(shell pwd)) + +LOCAL_SRCS := $(wildcard src/*.c) + +LOCAL_INCLUDE := \ + -I $(LITEOSTOPDIR)/compat/posix/src \ + -I $(LITEOSTOPDIR)/kernel/base/include \ + +LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) + +include $(MODULE) diff --git a/compat/posix/include/mqueue.h b/compat/posix/include/mqueue.h new file mode 100755 index 00000000..c32b158d --- /dev/null +++ b/compat/posix/include/mqueue.h @@ -0,0 +1,409 @@ +/* + * 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 mqueue Message queue + * @ingroup posix + */ + +#ifndef _HWLITEOS_POSIX_MQUEUE_H +#define _HWLITEOS_POSIX_MQUEUE_H + +/* INCLUDES */ +#include "stdarg.h" +#include "stdlib.h" +#include "limits.h" +#include "los_typedef.h" +#include "time.h" + +#include "los_queue_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/** + * @ingroup mqueue + * Maximum number of messages in a message queue + */ +#define MQ_MAX_MSG_NUM 16 + +/** + * @ingroup mqueue + * Maximum size of a single message in a message queue + */ +#define MQ_MAX_MSG_LEN 64 + + +/* CONSTANTS */ + +#define MQ_USE_MAGIC 0x89abcdef +/* not suppurt prio */ +#define MQ_PRIO_MAX 1 + +/* TYPE DEFINITIONS */ +struct mqarray { + UINT32 mq_id : 31; + UINT32 unlinkflag : 1; + char *mq_name; + LosQueueCB *mqcb; + struct mqpersonal *mq_personal; +}; + +struct mqpersonal { + struct mqarray *mq_posixdes; + struct mqpersonal *mq_next; + int mq_flags; + UINT32 mq_status; +}; + +/** + * @ingroup mqueue + * Message queue attribute structure + */ +struct mq_attr { + long mq_flags; /**< Message queue flags */ + long mq_maxmsg; /**< Maximum number of messages */ + long mq_msgsize; /**< Maximum size of a message */ + long mq_curmsgs; /**< Number of messages in the current message queue */ +}; + +/** + * @ingroup mqueue + * Handle type of a message queue + */ +typedef UINTPTR mqd_t; + +/** + * @ingroup mqueue + * + * @par Description: + * This API is used to open an existed message queue that has a specified name or create a new message queue. + * @attention + *
    + *
  • A message queue does not restrict the read and write permissions.
  • + *
  • The length of mqueue name must less than 256.
  • + *
  • This operation and closed mqueue scheduling must be used in coordination to release the resource.
  • + *
  • The parameter "mode" is not supported.
  • + *
  • The "mq_curmsgs" member of the mq_attr structure is not supported.
  • + *
+ * + * @param mqName [IN] Message queue name. + * @param openFlag [IN] Permission attributes of the message queue. The value range is + * [O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_NONBLOCK]. + * @param mode [IN] Message queue mode (variadic argument). When oflag is O_CREAT, it requires + * two additional arguments: mode, which shall be of type mode_t, and attr, + * which shall be a pointer to an mq_attr structure. + * @param attr [IN] Message queue attribute (variadic argument). + * + * @retval mqd_t The message queue is successfully opened or created. + * @retval (mqd_t)-1 The message queue fails to be opened or created, with any of the following error codes in errno. + * + * + * @par Errors + *
    + *
  • ENOENT: O_CREAT flag is not set for oflag, and the message queue specified by name does not exist.
  • + *
  • EEXIST: Both O_CREAT and O_EXCL are set for oflag, but the message queue + * specified by name already exists.
  • + *
  • EINVAL: invalid parameter.
  • + *
  • ENFILE: The number of opened message queues exceeds the maximum limit.
  • + *
  • ENOSPC: insufficient memory.
  • + *
  • ENAMETOOLONG: The message queue name specified by name is too long.
  • + *
+ * + * @par Dependency: + *
  • mqueue.h
+ * @see mq_close + */ +extern mqd_t mq_open(const char *mqName, int openFlag, ...); + +/** + * @ingroup mqueue + * + * @par Description: + * This API is used to close a message queue that has a specified descriptor. + * @attention + *
    + *
  • If the message queue is empty, it will be reclaimed, which is similar to when mq_unlink is called.
  • + *
+ * + * @param personal [IN] Message queue descriptor. + * + * @retval 0 The message queue is successfully closed. + * @retval -1 The message queue fails to be closed, with either of the following error codes in errno. + * + * @par Errors + *
    + *
  • EBADF: Invalid message queue descriptor.
  • + *
  • EAGAIN: Failed to delete the message queue.
  • + *
  • EFAULT: Failed to free the message queue.
  • + *
  • EINVAL: Invalid parameter.
  • + *
+ * + * @par Dependency: + *
  • mqueue.h
+ * @see mq_open + */ +extern int mq_close(mqd_t personal); + +/** + * @ingroup mqueue + * + * @par Description: + * This API is used to remove a message queue that has a specified name. + * @attention + *
    + *
  • If the message queue is empty, it will be reclaimed, which is similar to when mq_close is called.
  • + *
  • The length of mqueue name must less than 256.
  • + *
+ * + * @param mqName [IN] Message queue name. + * + * @retval 0 The message queue is successfully removed. + * @retval -1 The message queue fails to be removed, with any of the following error codes in errno. + * + * @par Errors + *
    + *
  • ENOENT: The message queue specified by name does not exist.
  • + *
  • EAGAIN: Failed to delete the message queue.
  • + *
  • EBUSY: The message queue to be removed is being used.
  • + *
  • EINVAL: Invalid parameter.
  • + *
  • ENAMETOOLONG: The name of mqueue is too long.
  • + *
+ * + * @par Dependency: + *
  • mqueue.h
+ * @see mq_close + */ +extern int mq_unlink(const char *mqName); + +/** + * @ingroup mqueue + * + * @par Description: + * This API is used to put a message with specified message content and length into + * a message queue that has a specified descriptor. + * @attention + *
    + *
  • Priority-based message processing is not supported.
  • + *
  • The msg_len should be same to the length of string which msg_ptr point to.
  • + *
+ * + * @param personal [IN] Message queue descriptor. + * @param msg [IN] Pointer to the message content to be sent. + * @param msgLen [IN] Length of the message to be sent. + * @param msgPrio [IN] Priority of the message to be sent (the value of this parameter must + * be 0 because priority-based message sending is not supported. If the + * value is not 0, this API will cease to work.) + * + * @retval 0 The message is successfully sent. + * @retval -1 The message fails to be sent, with any of the following error codes in errno. + * + * @par Errors + *
    + *
  • EINTR: An interrupt is in progress while the message is being sent.
  • + *
  • EBADF: The message queue is invalid or not writable.
  • + *
  • EAGAIN: The message queue is full.
  • + *
  • EINVAL: Invalid parameter.
  • + *
  • ENOSPC: Insufficient memory.
  • + *
  • EMSGSIZE: The message to be sent is too long.
  • + *
  • EOPNOTSUPP: The operation is not supported.
  • + *
  • ETIMEDOUT: The operation times out.
  • + *
+ * + * @par Dependency: + *
  • mqueue.h
+ * @see mq_receive + */ +extern int mq_send(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio); + +/** + * @ingroup mqueue + * + * @par Description: + * This API is used to remove the oldest message from the message queue that has a specified descriptor, + * and puts it in the buffer pointed to by msg_ptr. + * @attention + *
    + *
  • Priority-based message processing is not supported.
  • + *
  • The msg_len should be same to the length of string which msg_ptr point to.
  • + *
+ * + * @param personal [IN] Message queue descriptor. + * @param msg [IN] Pointer to the message content to be received. + * @param msgLen [IN] Length of the message to be received. + * @param msgPrio [OUT] Priority of the message to be received + * because priority-based message processing is not supported, this parameter is useless). + * + * @retval 0 The message is successfully received. + * @retval -1 The message fails to be received, with any of the following error codes in the errno. + * + * @par Errors + *
    + *
  • EINTR: An interrupt is in progress while the message is being received.
  • + *
  • EBADF: The message queue is invalid or not readable.
  • + *
  • EAGAIN: The message queue is empty.
  • + *
  • EINVAL: invalid parameter.
  • + *
  • EMSGSIZE: The message to be received is too long.
  • + *
  • ETIMEDOUT: The operaton times out.
  • + *
+ * + * @par Dependency: + *
  • mqueue.h
+ * @see mq_send + */ +extern ssize_t mq_receive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio); + +/** + * @ingroup mqueue + * + * @par Description: + * This API is used to obtain or modify attributes of the message queue that has a specified descriptor. + * @attention + *
    + *
  • The mq_maxmsg, mq_msgsize, and mq_curmsgs attributes are not modified + * in the message queue attribute setting.
  • + *
+ * + * @param personal [IN] Message queue descriptor. + * @param mqSetAttr [IN] New attribute of the message queue. + * @param MqOldAttr [OUT] Old attribute of the message queue. + * + * @retval 0 The message queue attributes are successfully set or get. + * @retval -1 The message queue attributes fail to be set or get, + * with either of the following error codes in the errno. + * + * @par Errors + *
    + *
  • EBADF: Invalid message queue.
  • + *
  • EINVAL: Invalid parameter.
  • + *
+ * + * @par Dependency: + *
  • mqueue.h
+ * @see sys_mq_getsetattr + */ +extern int mq_getsetattr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr *MqOldAttr); + +/** + * @ingroup mqueue + * + * @par Description: + * This API is used to put a message with specified message content and length into + * a message queue that has a descriptor at a scheduled time. + * @attention + *
    + *
  • Priority-based message processing is not supported.
  • + *
  • The expiry time must be later than the current time.
  • + *
  • The wait time is a relative time.
  • + *
  • The msg_len should be same to the length of string which msg_ptr point to.
  • + *
+ * + * @param mqdes [IN] Message queue descriptor. + * @param msg [IN] Pointer to the message content to be sent. + * @param msgLen [IN] Length of the message to be sent. + * @param msgPrio [IN] Priority of the message to be sent (the value of this parameter must be 0 + * because priority-based message processing is not supported). + * @param absTimeout [IN] Scheduled time at which the message will be sent. If the value is 0, + * the message is an instant message. + * + * @retval 0 The message is successfully sent. + * @retval -1 The message fails to be sent, with any of the following error codes in errno. + * + * @par Errors + *
    + *
  • EINTR: An interrupt is in progress while the message is being sent.
  • + *
  • EBADF: The message queue is invalid or not writable.
  • + *
  • EAGAIN: The message queue is full.
  • + *
  • EINVAL: Invalid parameter.
  • + *
  • EMSGSIZE: The message to be sent is too long.
  • + *
  • EOPNOTSUPP: The operation is not supported.
  • + *
  • ETIMEDOUT: The operation times out.
  • + *
+ * + * @par Dependency: + *
  • mqueue.h
+ * @see mq_receive + */ +extern int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, + unsigned int msgPrio, const struct timespec *absTimeout); + +/** + * @ingroup mqueue + * + * @par Description: + * This API is used to obtain a message with specified message content and length from + * a message queue message that has a specified descriptor. + * @attention + *
    + *
  • Priority-based message processing is not supported.
  • + *
  • The expiry time must be later than the current time.
  • + *
  • The wait time is a relative time.
  • + *
  • The msg_len should be same to the length of string which msg_ptr point to.
  • + *
+ * + * @param personal [IN] Message queue descriptor. + * @param msg [IN] Pointer to the message content to be received. + * @param msgLen [IN] Length of the message to be received. + * @param msgPrio [OUT] Priority of the message to be received (because priority-based message + * processing is not supported, this parameter is useless ). + * @param absTimeout [IN] Scheduled time at which the messagewill be received. If the value is 0, + * the message is an instant message. + * + * @retval 0 The message is successfully received. + * @retval -1 The message fails to be received, with any of the following error codes in errno. + * + * @par Errors + *
    + *
  • EINTR: An interrupt is in progress while the message is being received.
  • + *
  • EBADF: The message queue is invalid or not readable.
  • + *
  • EAGAIN: The message queue is empty.
  • + *
  • EINVAL: invalid parameter.
  • + *
  • EMSGSIZE: The message to be received is too long.
  • + *
  • ETIMEDOUT: The operation times out.
  • + *
+ * + * @par Dependency: + *
  • mqueue.h
+ * @see mq_send + */ +extern ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, + unsigned int *msgPrio, const struct timespec *absTimeout); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/compat/posix/include/time_posix.h b/compat/posix/include/time_posix.h new file mode 100755 index 00000000..0665d21b --- /dev/null +++ b/compat/posix/include/time_posix.h @@ -0,0 +1,86 @@ +/* + * 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 _TIME_PRI_H +#define _TIME_PRI_H + +#include "time.h" +#include "errno.h" +#include "los_sys_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* internal functions */ +STATIC INLINE BOOL ValidTimeSpec(const struct timespec *tp) +{ + /* Fail a NULL pointer */ + if (tp == NULL) { + return FALSE; + } + + /* Fail illegal nanosecond values */ + if ((tp->tv_nsec < 0) || (tp->tv_nsec >= OS_SYS_NS_PER_SECOND) || (tp->tv_sec < 0)) { + return FALSE; + } + + return TRUE; +} + +STATIC INLINE UINT32 OsTimeSpec2Tick(const struct timespec *tp) +{ + UINT64 tick, ns; + + ns = (UINT64)tp->tv_sec * OS_SYS_NS_PER_SECOND + tp->tv_nsec; + /* Round up for ticks */ + tick = (ns * LOSCFG_BASE_CORE_TICK_PER_SECOND + (OS_SYS_NS_PER_SECOND - 1)) / OS_SYS_NS_PER_SECOND; + if (tick > LOS_WAIT_FOREVER) { + tick = LOS_WAIT_FOREVER; + } + return (UINT32)tick; +} + +STATIC INLINE VOID OsTick2TimeSpec(struct timespec *tp, UINT32 tick) +{ + UINT64 ns = ((UINT64)tick * OS_SYS_NS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND; + tp->tv_sec = (time_t)(ns / OS_SYS_NS_PER_SECOND); + tp->tv_nsec = (long)(ns % OS_SYS_NS_PER_SECOND); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif /* _TIME_PRI_H */ \ No newline at end of file diff --git a/compat/posix/src/map_error.c b/compat/posix/src/map_error.c new file mode 100755 index 00000000..d2cdf013 --- /dev/null +++ b/compat/posix/src/map_error.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "los_mux.h" +#include "los_queue.h" +#include "los_sem.h" +#include "los_task.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +int map_errno(UINT32 err) +{ + if (err == LOS_OK) { + return ENOERR; + } + switch (err) { + case LOS_ERRNO_QUEUE_INVALID: + case LOS_ERRNO_QUEUE_WRITE_PTR_NULL: + case LOS_ERRNO_QUEUE_WRITESIZE_ISZERO: + case LOS_ERRNO_QUEUE_SIZE_TOO_BIG: + case LOS_ERRNO_QUEUE_CREAT_PTR_NULL: + case LOS_ERRNO_QUEUE_PARA_ISZERO: + case LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG: + errno = EINVAL; + break; + case LOS_ERRNO_QUEUE_ISFULL: + case LOS_ERRNO_QUEUE_ISEMPTY: + errno = EAGAIN; + break; + case LOS_ERRNO_QUEUE_CREATE_NO_MEMORY: + errno = ENOSPC; + break; + case LOS_ERRNO_QUEUE_TIMEOUT: + errno = ETIMEDOUT; + break; + case LOS_ERRNO_QUEUE_CB_UNAVAILABLE: + errno = ENFILE; + break; + case LOS_ERRNO_QUEUE_READ_IN_INTERRUPT: + case LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT: + errno = EINTR; + break; + case LOS_ERRNO_TSK_ID_INVALID: + case LOS_ERRNO_TSK_PTR_NULL: + case LOS_ERRNO_TSK_NAME_EMPTY: + case LOS_ERRNO_TSK_ENTRY_NULL: + case LOS_ERRNO_TSK_PRIOR_ERROR: + case LOS_ERRNO_TSK_STKSZ_TOO_LARGE: + case LOS_ERRNO_TSK_STKSZ_TOO_SMALL: + case LOS_ERRNO_TSK_NOT_CREATED: + case LOS_ERRNO_TSK_CPU_AFFINITY_MASK_ERR: + case OS_ERROR: + case LOS_ERRNO_SEM_INVALID: + case LOS_ERRNO_SEM_UNAVAILABLE: + errno = EINVAL; + break; + case LOS_ERRNO_TSK_TCB_UNAVAILABLE: + case LOS_ERRNO_TSK_MP_SYNC_RESOURCE: + case LOS_ERRNO_SEM_ALL_BUSY: + errno = ENOSPC; + break; + case LOS_ERRNO_TSK_NO_MEMORY: + case LOS_ERRNO_SEM_OVERFLOW: + errno = ENOMEM; + break; + case LOS_ERRNO_SEM_PENDED: + case LOS_ERRNO_EVENT_SHOULD_NOT_DESTORY: + errno = EBUSY; + break; + case LOS_ERRNO_SEM_PEND_IN_LOCK: + errno = EPERM; + break; + case LOS_ERRNO_SEM_PEND_INTERR: + errno = EINTR; + break; + case LOS_ERRNO_SEM_TIMEOUT: + errno = ETIMEDOUT; + break; + default: + errno = EINVAL; + break; + } + return errno; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/compat/posix/src/map_error.h b/compat/posix/src/map_error.h new file mode 100755 index 00000000..4731a32c --- /dev/null +++ b/compat/posix/src/map_error.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _HWLITEOS_POSIX_MAP_ERROR_H +#define _HWLITEOS_POSIX_MAP_ERROR_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +int map_errno(unsigned int err); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/compat/posix/src/misc.c b/compat/posix/src/misc.c new file mode 100755 index 00000000..98152931 --- /dev/null +++ b/compat/posix/src/misc.c @@ -0,0 +1,152 @@ +/* + * 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 "sys/types.h" +#include "unistd.h" +#include "stdio.h" +#include "pthread.h" +#include "sys/utsname.h" +#include "mqueue.h" +#include "semaphore.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* + * Supply some suitable values for constants that may not be present + * in all configurations. + */ +#define SC_ENABLE 1 +#define SC_DISABLE (-1) + +#define CONF_CASE_RETURN(name, val) \ + case (name): \ + return (val) + +int uname(struct utsname *name) +{ + INT32 ret; + if (name == NULL) { + return -EFAULT; + } + (VOID)strncpy_s(name->sysname, sizeof(name->sysname), KERNEL_NAME, strlen(KERNEL_NAME) + 1); + (VOID)strncpy_s(name->nodename, sizeof(name->nodename), "hisilicon", strlen("hisilicon") + 1); + ret = snprintf_s(name->version, sizeof(name->version), sizeof(name->version) - 1, "%s %u.%u.%u.%u %s %s\n", + KERNEL_NAME, KERNEL_MAJOR, KERNEL_MINOR, KERNEL_PATCH, KERNEL_ITRE, __DATE__, __TIME__); + if (ret < 0) { + return -EIO; + } + name->machine[0] = '\0'; + name->domainname[0] = '\0'; + return 0; +} + +long sysconf(int name) +{ + switch (name) { + CONF_CASE_RETURN(_SC_AIO_LISTIO_MAX, SC_DISABLE); + CONF_CASE_RETURN(_SC_AIO_MAX, SC_DISABLE); + CONF_CASE_RETURN(_SC_AIO_PRIO_DELTA_MAX, SC_DISABLE); + CONF_CASE_RETURN(_SC_ARG_MAX, ARG_MAX); + CONF_CASE_RETURN(_SC_ASYNCHRONOUS_IO, SC_DISABLE); + CONF_CASE_RETURN(_SC_CHILD_MAX, CHILD_MAX); + CONF_CASE_RETURN(_SC_CLK_TCK, SYS_CLK_TCK); + CONF_CASE_RETURN(_SC_DELAYTIMER_MAX, DELAYTIMER_MAX); + CONF_CASE_RETURN(_SC_FSYNC, SC_DISABLE); + CONF_CASE_RETURN(_SC_GETGR_R_SIZE_MAX, GETGR_R_SIZE_MAX); + CONF_CASE_RETURN(_SC_GETPW_R_SIZE_MAX, GETPW_R_SIZE_MAX); + CONF_CASE_RETURN(_SC_JOB_CONTROL, SC_DISABLE); + CONF_CASE_RETURN(_SC_LOGIN_NAME_MAX, LOGIN_NAME_MAX); + CONF_CASE_RETURN(_SC_MAPPED_FILES, SC_DISABLE); + CONF_CASE_RETURN(_SC_MEMLOCK, SC_DISABLE); + CONF_CASE_RETURN(_SC_MEMLOCK_RANGE, SC_DISABLE); + CONF_CASE_RETURN(_SC_MEMORY_PROTECTION, SC_DISABLE); + CONF_CASE_RETURN(_SC_MESSAGE_PASSING, SC_DISABLE); +#ifdef LOSCFG_BASE_IPC_QUEUE + CONF_CASE_RETURN(_SC_MQ_OPEN_MAX, MQ_OPEN_MAX); + CONF_CASE_RETURN(_SC_MQ_PRIO_MAX, MQ_PRIO_MAX); +#endif + CONF_CASE_RETURN(_SC_NGROUPS_MAX, NGROUPS_MAX); + CONF_CASE_RETURN(_SC_OPEN_MAX, OPEN_MAX); + CONF_CASE_RETURN(_SC_PAGESIZE, 0x1000); + CONF_CASE_RETURN(_SC_PRIORITIZED_IO, SC_DISABLE); + CONF_CASE_RETURN(_SC_PRIORITY_SCHEDULING, SC_DISABLE); + CONF_CASE_RETURN(_SC_REALTIME_SIGNALS, SC_DISABLE); + CONF_CASE_RETURN(_SC_RTSIG_MAX, RTSIG_MAX); + CONF_CASE_RETURN(_SC_SAVED_IDS, SC_DISABLE); + +#ifdef LOSCFG_BASE_IPC_SEM + CONF_CASE_RETURN(_SC_SEMAPHORES, SC_ENABLE); + CONF_CASE_RETURN(_SC_SEM_NSEMS_MAX, SEM_NSEMS_MAX); + CONF_CASE_RETURN(_SC_SEM_VALUE_MAX, SEM_VALUE_MAX); +#endif + + CONF_CASE_RETURN(_SC_SHARED_MEMORY_OBJECTS, SC_DISABLE); + CONF_CASE_RETURN(_SC_SIGQUEUE_MAX, SIGQUEUE_MAX); + CONF_CASE_RETURN(_SC_STREAM_MAX, STREAM_MAX); + CONF_CASE_RETURN(_SC_SYNCHRONIZED_IO, SC_DISABLE); + CONF_CASE_RETURN(_SC_THREADS, SC_ENABLE); + CONF_CASE_RETURN(_SC_THREAD_ATTR_STACKADDR, SC_ENABLE); + CONF_CASE_RETURN(_SC_THREAD_ATTR_STACKSIZE, PTHREAD_ATTR_STACKSIZE); + CONF_CASE_RETURN(_SC_THREAD_DESTRUCTOR_ITERATIONS, PTHREAD_DESTRUCTOR_ITERATIONS); + CONF_CASE_RETURN(_SC_THREAD_KEYS_MAX, PTHREAD_KEYS_MAX); + CONF_CASE_RETURN(_SC_THREAD_PRIO_INHERIT, PTHREAD_PRIO_INHERIT); + CONF_CASE_RETURN(_SC_THREAD_PRIO_PROTECT, PTHREAD_PRIO_PROTECT); + CONF_CASE_RETURN(_SC_THREAD_PRIORITY_SCHEDULING, PTHREAD_PRIORITY_SCHEDULING); + CONF_CASE_RETURN(_SC_THREAD_PROCESS_SHARED, PTHREAD_PROCESS_SHARED); + CONF_CASE_RETURN(_SC_THREAD_SAFE_FUNCTIONS, SC_DISABLE); + CONF_CASE_RETURN(_SC_THREAD_STACK_MIN, PTHREAD_STACK_MIN); + CONF_CASE_RETURN(_SC_THREAD_THREADS_MAX, PTHREAD_THREADS_MAX); + CONF_CASE_RETURN(_SC_TIMERS, TIMERS); + CONF_CASE_RETURN(_SC_TIMER_MAX, TIMER_MAX); + CONF_CASE_RETURN(_SC_TTY_NAME_MAX, TTY_NAME_MAX); + CONF_CASE_RETURN(_SC_TZNAME_MAX, TZNAME_MAX); + CONF_CASE_RETURN(_SC_VERSION, POSIX_VERSION); + + default: + set_errno(EINVAL); + return -1; + } +} + +pid_t getpid(void) +{ + return ((LosTaskCB *)(OsCurrTaskGet()))->taskID; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ \ No newline at end of file diff --git a/compat/posix/src/mqueue.c b/compat/posix/src/mqueue.c new file mode 100755 index 00000000..0aa2705d --- /dev/null +++ b/compat/posix/src/mqueue.c @@ -0,0 +1,610 @@ +/* + * 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 "mqueue.h" +#include "fcntl.h" +#include "pthread.h" +#include "map_error.h" +#include "time_posix.h" +#include "los_memory.h" +#include "los_vm_map.h" +#include "user_copy.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define FNONBLOCK O_NONBLOCK + +/* GLOBALS */ +STATIC struct mqarray g_queueTable[LOSCFG_BASE_IPC_QUEUE_LIMIT]; +STATIC pthread_mutex_t g_mqueueMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; + +/* LOCAL FUNCTIONS */ +STATIC INLINE INT32 MqNameCheck(const CHAR *mqName) +{ + if (mqName == NULL) { + errno = EINVAL; + return -1; + } + + if (strlen(mqName) == 0) { + errno = EINVAL; + return -1; + } + + if (strlen(mqName) > (PATH_MAX - 1)) { + errno = ENAMETOOLONG; + return -1; + } + return 0; +} + +STATIC INLINE UINT32 GetMqueueCBByID(UINT32 queueID, LosQueueCB **queueCB) +{ + LosQueueCB *tmpQueueCB = NULL; + if (queueCB == NULL) { + errno = EINVAL; + return LOS_ERRNO_QUEUE_READ_PTR_NULL; + } + tmpQueueCB = GET_QUEUE_HANDLE(queueID); + if ((GET_QUEUE_INDEX(queueID) >= LOSCFG_BASE_IPC_QUEUE_LIMIT) || (tmpQueueCB->queueID != queueID)) { + return LOS_ERRNO_QUEUE_INVALID; + } + *queueCB = tmpQueueCB; + + return LOS_OK; +} + +STATIC INLINE struct mqarray *GetMqueueCBByName(const CHAR *name) +{ + UINT32 index; + UINT32 mylen = strlen(name); + + for (index = 0; index < LOSCFG_BASE_IPC_QUEUE_LIMIT; index++) { + if ((g_queueTable[index].mq_name == NULL) || (strlen(g_queueTable[index].mq_name) != mylen)) { + continue; + } + + if (strncmp(name, (const CHAR *)(g_queueTable[index].mq_name), mylen) == 0) { + return &(g_queueTable[index]); + } + } + + return NULL; +} + +STATIC INT32 DoMqueueDelete(struct mqarray *mqueueCB) +{ + UINT32 ret; + + if (mqueueCB->mq_name != NULL) { + LOS_MemFree(OS_SYS_MEM_ADDR, mqueueCB->mq_name); + mqueueCB->mq_name = NULL; + } + + mqueueCB->mqcb = NULL; + + ret = LOS_QueueDelete(mqueueCB->mq_id); + switch (ret) { + case LOS_OK: + return 0; + case LOS_ERRNO_QUEUE_NOT_FOUND: + case LOS_ERRNO_QUEUE_NOT_CREATE: + case LOS_ERRNO_QUEUE_IN_TSKUSE: + case LOS_ERRNO_QUEUE_IN_TSKWRITE: + errno = EAGAIN; + return -1; + default: + errno = EINVAL; + return -1; + } +} + +STATIC int SaveMqueueName(const CHAR *mqName, struct mqarray *mqueueCB) +{ + size_t nameLen; + + nameLen = strlen(mqName); /* sys_mq_open has checked name and name length */ + mqueueCB->mq_name = (char *)LOS_MemAlloc(OS_SYS_MEM_ADDR, nameLen + 1); + if (mqueueCB->mq_name == NULL) { + errno = ENOMEM; + return LOS_NOK; + } + + if (strncpy_s(mqueueCB->mq_name, (nameLen + 1), mqName, nameLen) != EOK) { + LOS_MemFree(OS_SYS_MEM_ADDR, mqueueCB->mq_name); + mqueueCB->mq_name = NULL; + errno = EINVAL; + return LOS_NOK; + } + mqueueCB->mq_name[nameLen] = '\0'; + return LOS_OK; +} + +STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR *mqName, INT32 openFlag) +{ + struct mqarray *mqueueCB = NULL; + UINT32 mqueueID; + + UINT32 err = LOS_QueueCreate(NULL, attr->mq_maxmsg, &mqueueID, 0, attr->mq_msgsize); + if (map_errno(err) != ENOERR) { + goto ERROUT; + } + + if (g_queueTable[GET_QUEUE_INDEX(mqueueID)].mqcb == NULL) { + mqueueCB = &(g_queueTable[GET_QUEUE_INDEX(mqueueID)]); + mqueueCB->mq_id = mqueueID; + } + + if (mqueueCB == NULL) { + errno = EINVAL; + goto ERROUT; + } + + if (SaveMqueueName(mqName, mqueueCB) != LOS_OK) { + goto ERROUT; + } + + if (GetMqueueCBByID(mqueueCB->mq_id, &(mqueueCB->mqcb)) != LOS_OK) { + errno = ENOSPC; + goto ERROUT; + } + + mqueueCB->mq_personal = (struct mqpersonal *)LOS_MemAlloc(OS_SYS_MEM_ADDR, sizeof(struct mqpersonal)); + if (mqueueCB->mq_personal == NULL) { + (VOID)LOS_QueueDelete(mqueueCB->mq_id); + mqueueCB->mqcb->queueHandle = NULL; + mqueueCB->mqcb = NULL; + errno = ENOSPC; + goto ERROUT; + } + + mqueueCB->unlinkflag = FALSE; + mqueueCB->mq_personal->mq_status = MQ_USE_MAGIC; + mqueueCB->mq_personal->mq_next = NULL; + mqueueCB->mq_personal->mq_posixdes = mqueueCB; + mqueueCB->mq_personal->mq_flags = (INT32)((UINT32)openFlag | ((UINT32)attr->mq_flags & (UINT32)FNONBLOCK)); + + return mqueueCB->mq_personal; +ERROUT: + + if ((mqueueCB != NULL) && (mqueueCB->mq_name != NULL)) { + LOS_MemFree(OS_SYS_MEM_ADDR, mqueueCB->mq_name); + mqueueCB->mq_name = NULL; + } + return (struct mqpersonal *)-1; +} + +STATIC struct mqpersonal *DoMqueueOpen(struct mqarray *mqueueCB, INT32 openFlag) +{ + struct mqpersonal *privateMqPersonal = NULL; + + /* already have the same name of g_squeuetable */ + if (mqueueCB->unlinkflag == TRUE) { + errno = EINVAL; + goto ERROUT; + } + /* alloc mqprivate and add to mqarray */ + privateMqPersonal = (struct mqpersonal *)LOS_MemAlloc(OS_SYS_MEM_ADDR, sizeof(struct mqpersonal)); + if (privateMqPersonal == NULL) { + errno = ENOSPC; + goto ERROUT; + } + + privateMqPersonal->mq_next = mqueueCB->mq_personal; + mqueueCB->mq_personal = privateMqPersonal; + + privateMqPersonal->mq_posixdes = mqueueCB; + privateMqPersonal->mq_flags = openFlag; + privateMqPersonal->mq_status = MQ_USE_MAGIC; + + return privateMqPersonal; + +ERROUT: + return (struct mqpersonal *)-1; +} + +mqd_t mq_open(const char *mqName, int openFlag, ...) +{ + struct mqarray *mqueueCB = NULL; + struct mqpersonal *privateMqPersonal = (struct mqpersonal *)-1; + struct mq_attr *attr = NULL; + struct mq_attr defaultAttr = { 0, MQ_MAX_MSG_NUM, MQ_MAX_MSG_LEN, 0 }; + int retVal; + va_list ap; + + if (MqNameCheck(mqName) == -1) { + return (mqd_t)-1; + } + + (VOID)pthread_mutex_lock(&g_mqueueMutex); + mqueueCB = GetMqueueCBByName(mqName); + if ((UINT32)openFlag & (UINT32)O_CREAT) { + if (mqueueCB != NULL) { + if (((UINT32)openFlag & (UINT32)O_EXCL)) { + errno = EEXIST; + goto OUT; + } + privateMqPersonal = DoMqueueOpen(mqueueCB, openFlag); + } else { + va_start(ap, openFlag); + (VOID)va_arg(ap, int); + attr = va_arg(ap, struct mq_attr *); + va_end(ap); + + if (attr != NULL) { + retVal = LOS_ArchCopyFromUser(&defaultAttr, attr, sizeof(struct mq_attr)); + if (retVal != 0) { + errno = EFAULT; + goto OUT; + } + if ((defaultAttr.mq_maxmsg < 0) || (defaultAttr.mq_maxmsg > (long int)USHRT_MAX) || + (defaultAttr.mq_msgsize < 0) || (defaultAttr.mq_msgsize > (long int)(USHRT_MAX - sizeof(UINT32)))) { + errno = EINVAL; + goto OUT; + } + } + privateMqPersonal = DoMqueueCreate(&defaultAttr, mqName, openFlag); + } + } else { + if (mqueueCB == NULL) { + errno = ENOENT; + goto OUT; + } + privateMqPersonal = DoMqueueOpen(mqueueCB, openFlag); + } + +OUT: + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + return (mqd_t)privateMqPersonal; +} + +int mq_close(mqd_t personal) +{ + INT32 ret = 0; + struct mqarray *mqueueCB = NULL; + struct mqpersonal *privateMqPersonal = NULL; + struct mqpersonal *tmp = NULL; + + if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) { + errno = EBADF; + return -1; + } + + (VOID)pthread_mutex_lock(&g_mqueueMutex); + privateMqPersonal = (struct mqpersonal *)personal; + if (privateMqPersonal->mq_status != MQ_USE_MAGIC) { + errno = EBADF; + goto OUT_UNLOCK; + } + + mqueueCB = privateMqPersonal->mq_posixdes; + if (mqueueCB->mq_personal == NULL) { + errno = EBADF; + goto OUT_UNLOCK; + } + + /* find the personal and remove */ + if (mqueueCB->mq_personal == privateMqPersonal) { + mqueueCB->mq_personal = privateMqPersonal->mq_next; + } else { + for (tmp = mqueueCB->mq_personal; tmp->mq_next != NULL; tmp = tmp->mq_next) { + if (tmp->mq_next == privateMqPersonal) { + break; + } + } + if (tmp->mq_next == NULL) { + errno = EBADF; + goto OUT_UNLOCK; + } + tmp->mq_next = privateMqPersonal->mq_next; + } + /* flag no use */ + privateMqPersonal->mq_status = 0; + + /* free the personal */ + ret = LOS_MemFree(OS_SYS_MEM_ADDR, privateMqPersonal); + if (ret != LOS_OK) { + errno = EFAULT; + ret = -1; + goto OUT_UNLOCK; + } + + if ((mqueueCB->unlinkflag == TRUE) && (mqueueCB->mq_personal == NULL)) { + ret = DoMqueueDelete(mqueueCB); + } +OUT_UNLOCK: + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + return ret; +} + +int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr) +{ + struct mqarray *mqueueCB = NULL; + struct mqpersonal *privateMqPersonal = NULL; + + if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) { + errno = EBADF; + return -1; + } + + if (mqAttr == NULL) { + errno = EINVAL; + return -1; + } + + (VOID)pthread_mutex_lock(&g_mqueueMutex); + privateMqPersonal = (struct mqpersonal *)personal; + if (privateMqPersonal->mq_status != MQ_USE_MAGIC) { + errno = EBADF; + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + return -1; + } + + mqueueCB = privateMqPersonal->mq_posixdes; + mqAttr->mq_maxmsg = mqueueCB->mqcb->queueLen; + mqAttr->mq_msgsize = mqueueCB->mqcb->queueSize - sizeof(UINT32); + mqAttr->mq_curmsgs = mqueueCB->mqcb->readWriteableCnt[OS_QUEUE_READ]; + mqAttr->mq_flags = privateMqPersonal->mq_flags; + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + return 0; +} + +int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr *mqOldAttr) +{ + struct mqpersonal *privateMqPersonal = NULL; + + if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) { + errno = EBADF; + return -1; + } + + if (mqSetAttr == NULL) { + errno = EINVAL; + return -1; + } + + (VOID)pthread_mutex_lock(&g_mqueueMutex); + privateMqPersonal = (struct mqpersonal *)personal; + if (privateMqPersonal->mq_status != MQ_USE_MAGIC) { + errno = EBADF; + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + return -1; + } + + if (mqOldAttr != NULL) { + (VOID)OsMqGetAttr((mqd_t)privateMqPersonal, mqOldAttr); + } + + privateMqPersonal->mq_flags = (INT32)((UINT32)privateMqPersonal->mq_flags & (UINT32)(~FNONBLOCK)); /* clear */ + if (((UINT32)mqSetAttr->mq_flags & (UINT32)FNONBLOCK) == (UINT32)FNONBLOCK) { + privateMqPersonal->mq_flags = (INT32)((UINT32)privateMqPersonal->mq_flags | (UINT32)FNONBLOCK); + } + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + return 0; +} + +int mq_getsetattr(mqd_t mqd, const struct mq_attr *new, struct mq_attr *old) +{ + if (new == NULL) { + return OsMqGetAttr(mqd, old); + } + return OsMqSetAttr(mqd, new, old); +} + +int mq_unlink(const char *mqName) +{ + INT32 ret = 0; + struct mqarray *mqueueCB = NULL; + + if (MqNameCheck(mqName) == -1) { + return -1; + } + + (VOID)pthread_mutex_lock(&g_mqueueMutex); + mqueueCB = GetMqueueCBByName(mqName); + if (mqueueCB == NULL) { + errno = ENOENT; + goto ERROUT_UNLOCK; + } + + if (mqueueCB->mq_personal != NULL) { + mqueueCB->unlinkflag = TRUE; + } else { + ret = DoMqueueDelete(mqueueCB); + } + + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + return ret; + +ERROUT_UNLOCK: + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + return -1; +} + +STATIC INT32 ConvertTimeout(long flags, const struct timespec *absTimeout, UINT64 *ticks) +{ + if ((UINT32)flags & (UINT32)FNONBLOCK) { + *ticks = LOS_NO_WAIT; + return 0; + } + + if (absTimeout == NULL) { + *ticks = LOS_WAIT_FOREVER; + return 0; + } + + if (!ValidTimeSpec(absTimeout)) { + errno = EINVAL; + return -1; + } + + *ticks = OsTimeSpec2Tick(absTimeout); + return 0; +} + +STATIC INLINE BOOL MqParamCheck(mqd_t personal, const char *msg, size_t msgLen) +{ + if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) { + errno = EBADF; + return FALSE; + } + + if ((msg == NULL) || (msgLen == 0)) { + errno = EINVAL; + return FALSE; + } + return TRUE; +} + +#define OS_MQ_GOTO_ERROUT_UNLOCK_IF(expr, errcode) \ + if (expr) { \ + errno = errcode; \ + goto ERROUT_UNLOCK; \ + } +#define OS_MQ_GOTO_ERROUT_IF(expr, errcode) \ + if (expr) { \ + errno = errcode; \ + goto ERROUT; \ + } +int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int msgPrio, + const struct timespec *absTimeout) +{ + UINT32 mqueueID, err; + UINT64 absTicks; + struct mqarray *mqueueCB = NULL; + struct mqpersonal *privateMqPersonal = NULL; + + OS_MQ_GOTO_ERROUT_IF(!MqParamCheck(personal, msg, msgLen), errno); + + OS_MQ_GOTO_ERROUT_IF(msgPrio > (MQ_PRIO_MAX - 1), EINVAL); + + (VOID)pthread_mutex_lock(&g_mqueueMutex); + privateMqPersonal = (struct mqpersonal *)personal; + OS_MQ_GOTO_ERROUT_UNLOCK_IF(privateMqPersonal->mq_status != MQ_USE_MAGIC, EBADF); + + mqueueCB = privateMqPersonal->mq_posixdes; + OS_MQ_GOTO_ERROUT_UNLOCK_IF(msgLen > (size_t)(mqueueCB->mqcb->queueSize - sizeof(UINT32)), EMSGSIZE); + + OS_MQ_GOTO_ERROUT_UNLOCK_IF((((UINT32)privateMqPersonal->mq_flags & (UINT32)O_WRONLY) != (UINT32)O_WRONLY) && + (((UINT32)privateMqPersonal->mq_flags & (UINT32)O_RDWR) != (UINT32)O_RDWR), + EBADF); + + OS_MQ_GOTO_ERROUT_UNLOCK_IF(ConvertTimeout(privateMqPersonal->mq_flags, absTimeout, &absTicks) == -1, errno); + mqueueID = mqueueCB->mq_id; + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + + err = LOS_QueueWriteCopy(mqueueID, (VOID *)msg, (UINT32)msgLen, (UINT32)absTicks); + if (map_errno(err) != ENOERR) { + goto ERROUT; + } + return 0; +ERROUT_UNLOCK: + (VOID)pthread_mutex_unlock(&g_mqueueMutex); +ERROUT: + return -1; +} + +ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *msgPrio, + const struct timespec *absTimeout) +{ + UINT32 mqueueID, err; + UINT32 receiveLen; + UINT64 absTicks; + struct mqarray *mqueueCB = NULL; + struct mqpersonal *privateMqPersonal = NULL; + + if (!MqParamCheck(personal, msg, msgLen)) { + goto ERROUT; + } + + if (msgPrio != NULL) { + *msgPrio = 0; + } + + (VOID)pthread_mutex_lock(&g_mqueueMutex); + privateMqPersonal = (struct mqpersonal *)personal; + if (privateMqPersonal->mq_status != MQ_USE_MAGIC) { + errno = EBADF; + goto ERROUT_UNLOCK; + } + + mqueueCB = privateMqPersonal->mq_posixdes; + if (msgLen < (size_t)(mqueueCB->mqcb->queueSize - sizeof(UINT32))) { + errno = EMSGSIZE; + goto ERROUT_UNLOCK; + } + + if (((UINT32)privateMqPersonal->mq_flags & (UINT32)O_WRONLY) == (UINT32)O_WRONLY) { + errno = EBADF; + goto ERROUT_UNLOCK; + } + + if (ConvertTimeout(privateMqPersonal->mq_flags, absTimeout, &absTicks) == -1) { + goto ERROUT_UNLOCK; + } + + receiveLen = msgLen; + mqueueID = mqueueCB->mq_id; + (VOID)pthread_mutex_unlock(&g_mqueueMutex); + + err = LOS_QueueReadCopy(mqueueID, (VOID *)msg, &receiveLen, (UINT32)absTicks); + if (map_errno(err) == ENOERR) { + return (ssize_t)receiveLen; + } else { + goto ERROUT; + } + +ERROUT_UNLOCK: + (VOID)pthread_mutex_unlock(&g_mqueueMutex); +ERROUT: + return -1; +} + +/* not support the prio */ +int mq_send(mqd_t personal, const char *msg_ptr, size_t msg_len, unsigned int msg_prio) +{ + return mq_timedsend(personal, msg_ptr, msg_len, msg_prio, NULL); +} + +ssize_t mq_receive(mqd_t personal, char *msg_ptr, size_t msg_len, unsigned int *msg_prio) +{ + return mq_timedreceive(personal, msg_ptr, msg_len, msg_prio, NULL); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/compat/posix/src/posix_memalign.c b/compat/posix/src/posix_memalign.c new file mode 100755 index 00000000..40af37dd --- /dev/null +++ b/compat/posix/src/posix_memalign.c @@ -0,0 +1,59 @@ +/* + * 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" +#include "los_memory.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +int posix_memalign(void **memAddr, size_t alignment, size_t size) +{ + if ((alignment == 0) || ((alignment & (alignment - 1)) != 0) || ((alignment % sizeof(void *)) != 0)) { + return EINVAL; + } + + *memAddr = LOS_MemAllocAlign(OS_SYS_MEM_ADDR, size, alignment); + if (*memAddr == NULL) { + return ENOMEM; + } + + return ENOERR; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ \ No newline at end of file diff --git a/compat/posix/src/pprivate.h b/compat/posix/src/pprivate.h new file mode 100755 index 00000000..e484c81a --- /dev/null +++ b/compat/posix/src/pprivate.h @@ -0,0 +1,87 @@ +/* + * 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 _HWLITEOS_POSIX_PPRIVATE_H +#define _HWLITEOS_POSIX_PPRIVATE_H + +#include "los_process.h" +#include "pthread.h" +#include "sys/types.h" +#include "los_sem_pri.h" +#include "los_task_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define PTHREAD_DATA_NAME_MAX 20 +/* + * Thread control data structure + * Per-thread information needed by POSIX + */ +typedef struct { + pthread_attr_t attr; /* Current thread attributes */ + pthread_t id; /* My thread ID */ + LosTaskCB *task; /* pointer to Huawei LiteOS thread object */ + CHAR name[PTHREAD_DATA_NAME_MAX]; /* name string for debugging */ + UINT8 state; /* Thread state */ + UINT8 cancelstate; /* Cancel state of thread */ + volatile UINT8 canceltype; /* Cancel type of thread */ + volatile UINT8 canceled; /* pending cancel flag */ + struct pthread_cleanup_buffer *cancelbuffer; /* stack of cleanup buffers */ + UINT32 freestack; /* stack malloced, must be freed */ + UINT32 stackmem; /* base of stack memory area only valid if freestack == true */ + VOID **thread_data; /* Per-thread data table pointer */ +} _pthread_data; + +/* + * Values for the state field. These are solely concerned with the + * states visible to POSIX. The thread's run state is stored in the + * struct _pthread_data about thread object. + * Note: numerical order here is important, do not rearrange. + */ +#define PTHREAD_STATE_FREE 0 /* This structure is free for reuse */ +#define PTHREAD_STATE_DETACHED 1 /* The thread is running but detached */ +#define PTHREAD_STATE_RUNNING 2 /* The thread is running and will wait to join when it exits */ +#define PTHREAD_STATE_JOIN 3 /* The thread has exited and is waiting to be joined */ +#define PTHREAD_STATE_EXITED 4 /* The thread has exited and is ready to be reaped */ +#define PTHREAD_STATE_ALRDY_JOIN 5 /* The thread state is in join */ + + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/compat/posix/src/pthread.c b/compat/posix/src/pthread.c new file mode 100755 index 00000000..372fbe56 --- /dev/null +++ b/compat/posix/src/pthread.c @@ -0,0 +1,817 @@ +/* + * 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 "pprivate.h" +#include "pthread.h" +#include "sched.h" + +#include "stdio.h" +#include "map_error.h" +#include "los_process_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* + * Array of pthread control structures. A pthread_t object is + * "just" an index into this array. + */ +STATIC _pthread_data g_pthreadData[LOSCFG_BASE_CORE_TSK_LIMIT + 1]; + +/* Count of number of threads that have exited and not been reaped. */ +STATIC INT32 g_pthreadsExited = 0; + +/* this is to protect the pthread data */ +STATIC pthread_mutex_t g_pthreadsDataMutex = PTHREAD_MUTEX_INITIALIZER; + +/* pointed to by PTHREAD_CANCELED */ +UINTPTR g_pthreadCanceledDummyVar; + +/* + * Private version of pthread_self() that returns a pointer to our internal + * control structure. + */ +_pthread_data *pthread_get_self_data(void) +{ + UINT32 runningTaskPID = ((LosTaskCB *)(OsCurrTaskGet()))->taskID; + _pthread_data *data = &g_pthreadData[runningTaskPID]; + + return data; +} + +_pthread_data *pthread_get_data(pthread_t id) +{ + _pthread_data *data = NULL; + + if (OS_TID_CHECK_INVALID(id)) { + return NULL; + } + + data = &g_pthreadData[id]; + /* Check that this is a valid entry */ + if ((data->state == PTHREAD_STATE_FREE) || (data->state == PTHREAD_STATE_EXITED)) { + return NULL; + } + + /* Check that the entry matches the id */ + if (data->id != id) { + return NULL; + } + + /* Return the pointer */ + return data; +} + +/* + * Check whether there is a cancel pending and if so, whether + * cancellations are enabled. We do it in this order to reduce the + * number of tests in the common case - when no cancellations are + * pending. We make this inline so it can be called directly below for speed + */ +STATIC INT32 CheckForCancel(VOID) +{ + _pthread_data *self = pthread_get_self_data(); + if (self->canceled && (self->cancelstate == PTHREAD_CANCEL_ENABLE)) { + return 1; + } + return 0; +} + +STATIC VOID ProcessUnusedStatusTask(_pthread_data *data) +{ + data->state = PTHREAD_STATE_FREE; + (VOID)memset_s(data, sizeof(_pthread_data), 0, sizeof(_pthread_data)); +} + +/* + * This function is called to tidy up and dispose of any threads that have + * exited. This work must be done from a thread other than the one exiting. + * Note: this function must be called with pthread_mutex locked. + */ +STATIC VOID PthreadReap(VOID) +{ + UINT32 i; + _pthread_data *data = NULL; + /* + * Loop over the thread table looking for exited threads. The + * g_pthreadsExited counter springs us out of this once we have + * found them all (and keeps us out if there are none to do). + */ + for (i = 0; g_pthreadsExited && (i < g_taskMaxNum); i++) { + data = &g_pthreadData[i]; + if (data->state == PTHREAD_STATE_EXITED) { + /* the Huawei LiteOS not delete the dead TCB,so need to delete the TCB */ + (VOID)LOS_TaskDelete(data->task->taskID); + if (data->task->taskStatus & OS_TASK_STATUS_UNUSED) { + ProcessUnusedStatusTask(data); + g_pthreadsExited--; + } + } + } +} + +STATIC VOID SetPthreadAttr(const _pthread_data *self, const pthread_attr_t *attr, pthread_attr_t *outAttr) +{ + /* + * Set use_attr to the set of attributes we are going to + * actually use. Either those passed in, or the default set. + */ + if (attr == NULL) { + (VOID)pthread_attr_init(outAttr); + } else { + (VOID)memcpy_s(outAttr, sizeof(pthread_attr_t), attr, sizeof(pthread_attr_t)); + } + + /* + * If the stack size is not valid, we can assume that it is at + * least PTHREAD_STACK_MIN bytes. + */ + if (!outAttr->stacksize_set) { + outAttr->stacksize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; + } + if (outAttr->inheritsched == PTHREAD_INHERIT_SCHED) { + if (self->task == NULL) { + outAttr->schedparam.sched_priority = ((LosTaskCB *)(OsCurrTaskGet()))->priority; + } else { + outAttr->schedpolicy = self->attr.schedpolicy; + outAttr->schedparam = self->attr.schedparam; + outAttr->scope = self->attr.scope; + } + } +} + +STATIC VOID SetPthreadDataAttr(const pthread_attr_t *userAttr, const pthread_t threadID, + LosTaskCB *taskCB, _pthread_data *created) +{ + created->attr = *userAttr; + created->id = threadID; + created->task = taskCB; + created->state = (userAttr->detachstate == PTHREAD_CREATE_JOINABLE) ? + PTHREAD_STATE_RUNNING : PTHREAD_STATE_DETACHED; + /* need to confirmation */ + created->cancelstate = PTHREAD_CANCEL_ENABLE; + created->canceltype = PTHREAD_CANCEL_DEFERRED; + created->cancelbuffer = NULL; + created->canceled = 0; + created->freestack = 0; /* no use default : 0 */ + created->stackmem = taskCB->topOfStack; + created->thread_data = NULL; +} + +STATIC UINT32 InitPthreadData(pthread_t threadID, pthread_attr_t *userAttr, + const CHAR name[], size_t len) +{ + errno_t err; + UINT32 ret = LOS_OK; + LosTaskCB *taskCB = OS_TCB_FROM_TID(threadID); + _pthread_data *created = &g_pthreadData[threadID]; + + err = strncpy_s(created->name, sizeof(created->name), name, len); + if (err != EOK) { + PRINT_ERR("%s: %d, err: %d\n", __FUNCTION__, __LINE__, err); + return LOS_NOK; + } + userAttr->stacksize = taskCB->stackSize; + err = memcpy_s(taskCB->taskName, OS_TCB_NAME_LEN, created->name, strlen(created->name)); + if (err != EOK) { + PRINT_ERR("%s: %d, err: %d\n", __FUNCTION__, __LINE__, err); + taskCB->taskName[0] = '\0'; + return LOS_NOK; + } +#if (LOSCFG_KERNEL_SMP == YES) + if (userAttr->cpuset.__bits[0] > 0) { + taskCB->cpuAffiMask = (UINT16)userAttr->cpuset.__bits[0]; + } +#endif + + SetPthreadDataAttr(userAttr, threadID, taskCB, created); + return ret; +} + +int pthread_create(pthread_t *thread, const pthread_attr_t *attr, + void *(*startRoutine)(void *), void *arg) +{ + pthread_attr_t userAttr; + UINT32 ret; + CHAR name[PTHREAD_DATA_NAME_MAX]; + STATIC UINT16 pthreadNumber = 1; + TSK_INIT_PARAM_S taskInitParam = {0}; + UINT32 taskHandle; + _pthread_data *self = pthread_get_self_data(); + + if ((thread == NULL) || (startRoutine == NULL)) { + return EINVAL; + } + + SetPthreadAttr(self, attr, &userAttr); + + (VOID)memset_s(name, sizeof(name), 0, sizeof(name)); + (VOID)snprintf_s(name, sizeof(name), sizeof(name) - 1, "pth%02d", pthreadNumber); + pthreadNumber++; + + taskInitParam.pcName = name; + taskInitParam.pfnTaskEntry = (TSK_ENTRY_FUNC)startRoutine; + taskInitParam.auwArgs[0] = (UINTPTR)arg; + taskInitParam.usTaskPrio = (UINT16)userAttr.schedparam.sched_priority; + taskInitParam.uwStackSize = userAttr.stacksize; + if (OsProcessIsUserMode(OsCurrProcessGet())) { + taskInitParam.processID = OsGetKernelInitProcessID(); + } else { + taskInitParam.processID = OsCurrProcessGet()->processID; + } + if (userAttr.detachstate == PTHREAD_CREATE_DETACHED) { + taskInitParam.uwResved = LOS_TASK_STATUS_DETACHED; + } else { + /* Set the pthread default joinable */ + taskInitParam.uwResved = 0; + } + + PthreadReap(); + ret = LOS_TaskCreateOnly(&taskHandle, &taskInitParam); + if (ret == LOS_OK) { + *thread = (pthread_t)taskHandle; + ret = InitPthreadData(*thread, &userAttr, name, PTHREAD_DATA_NAME_MAX); + if (ret != LOS_OK) { + goto ERROR_OUT_WITH_TASK; + } + (VOID)LOS_SetTaskScheduler(taskHandle, SCHED_RR, taskInitParam.usTaskPrio); + } + + if (ret == LOS_OK) { + return ENOERR; + } else { + goto ERROR_OUT; + } + +ERROR_OUT_WITH_TASK: + (VOID)LOS_TaskDelete(taskHandle); +ERROR_OUT: + *thread = (pthread_t)-1; + + return map_errno(ret); +} + +void pthread_exit(void *retVal) +{ + _pthread_data *self = pthread_get_self_data(); + UINT32 intSave; + + if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, (int *)0) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + + if (pthread_mutex_lock(&g_pthreadsDataMutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + + self->task->joinRetval = retVal; + /* + * If we are already detached, go to EXITED state, otherwise + * go into JOIN state. + */ + if (self->state == PTHREAD_STATE_DETACHED) { + self->state = PTHREAD_STATE_EXITED; + g_pthreadsExited++; + } else { + self->state = PTHREAD_STATE_JOIN; + } + + if (pthread_mutex_unlock(&g_pthreadsDataMutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + SCHEDULER_LOCK(intSave); + /* If the thread is the highest thread,it can't schedule in LOS_SemPost. */ + OsTaskJoinPostUnsafe(self->task); + if (self->task->taskStatus & OS_TASK_STATUS_RUNNING) { + OsSchedResched(); + } + SCHEDULER_UNLOCK(intSave); +} + +STATIC INT32 ProcessByJoinState(_pthread_data *joined) +{ + UINT32 intSave; + INT32 err = 0; + UINT32 ret; + switch (joined->state) { + case PTHREAD_STATE_RUNNING: + /* The thread is still running, we must wait for it. */ + SCHEDULER_LOCK(intSave); + ret = OsTaskJoinPendUnsafe(joined->task); + SCHEDULER_UNLOCK(intSave); + if (ret != LOS_OK) { + err = (INT32)ret; + break; + } + + joined->state = PTHREAD_STATE_ALRDY_JOIN; + break; + /* + * The thread has become unjoinable while we waited, so we + * fall through to complain. + */ + case PTHREAD_STATE_FREE: + case PTHREAD_STATE_DETACHED: + case PTHREAD_STATE_EXITED: + /* None of these may be joined. */ + err = EINVAL; + break; + case PTHREAD_STATE_ALRDY_JOIN: + err = EINVAL; + break; + case PTHREAD_STATE_JOIN: + break; + default: + PRINT_ERR("state: %u is not supported\n", (UINT32)joined->state); + break; + } + return err; +} + +int pthread_join(pthread_t thread, void **retVal) +{ + INT32 err; + UINT8 status; + _pthread_data *self = NULL; + _pthread_data *joined = NULL; + + /* Check for cancellation first. */ + pthread_testcancel(); + + /* Dispose of any dead threads */ + (VOID)pthread_mutex_lock(&g_pthreadsDataMutex); + PthreadReap(); + (VOID)pthread_mutex_unlock(&g_pthreadsDataMutex); + + self = pthread_get_self_data(); + joined = pthread_get_data(thread); + if (joined == NULL) { + return ESRCH; + } + status = joined->state; + + if (joined == self) { + return EDEADLK; + } + + err = ProcessByJoinState(joined); + (VOID)pthread_mutex_lock(&g_pthreadsDataMutex); + + if (!err) { + /* + * Here, we know that joinee is a thread that has exited and is + * ready to be joined. + */ + if (retVal != NULL) { + /* Get the retVal */ + *retVal = joined->task->joinRetval; + } + + /* Set state to exited. */ + joined->state = PTHREAD_STATE_EXITED; + g_pthreadsExited++; + + /* Dispose of any dead threads */ + PthreadReap(); + } else { + joined->state = status; + } + + (VOID)pthread_mutex_unlock(&g_pthreadsDataMutex); + /* Check for cancellation before returning */ + pthread_testcancel(); + + return err; +} + +/* + * Set the detachstate of the thread to "detached". The thread then does not + * need to be joined and its resources will be freed when it exits. + */ +int pthread_detach(pthread_t thread) +{ + int ret = 0; + UINT32 intSave; + + _pthread_data *detached = NULL; + + if (pthread_mutex_lock(&g_pthreadsDataMutex) != ENOERR) { + ret = ESRCH; + } + detached = pthread_get_data(thread); + if (detached == NULL) { + ret = ESRCH; /* No such thread */ + } else if (detached->state == PTHREAD_STATE_DETACHED) { + ret = EINVAL; /* Already detached! */ + } else if (detached->state == PTHREAD_STATE_JOIN) { + detached->state = PTHREAD_STATE_EXITED; + g_pthreadsExited++; + } else { + /* Set state to detached and kick any joinees to make them return. */ + SCHEDULER_LOCK(intSave); + if (!(detached->task->taskStatus & OS_TASK_STATUS_EXIT)) { + ret = OsTaskSetDeatchUnsafe(detached->task); + if (ret == ESRCH) { + ret = LOS_OK; + } else if (ret == LOS_OK) { + detached->state = PTHREAD_STATE_DETACHED; + } + } else { + detached->state = PTHREAD_STATE_EXITED; + g_pthreadsExited++; + } + SCHEDULER_UNLOCK(intSave); + } + + /* Dispose of any dead threads */ + PthreadReap(); + if (pthread_mutex_unlock(&g_pthreadsDataMutex) != ENOERR) { + ret = ESRCH; + } + + return ret; +} + +int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param) +{ + _pthread_data *data = NULL; + int ret; + + if ((param == NULL) || (param->sched_priority > OS_TASK_PRIORITY_LOWEST)) { + return EINVAL; + } + + if (policy != SCHED_RR) { + return EINVAL; + } + + /* The parameters seem OK, change the thread. */ + ret = pthread_mutex_lock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + + data = pthread_get_data(thread); + if (data == NULL) { + ret = pthread_mutex_unlock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + return ESRCH; + } + + /* Only support one policy now */ + data->attr.schedpolicy = SCHED_RR; + data->attr.schedparam = *param; + + ret = pthread_mutex_unlock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + (VOID)LOS_TaskPriSet((UINT32)thread, (UINT16)param->sched_priority); + + return ENOERR; +} + +int pthread_getschedparam(pthread_t thread, int *policy, struct sched_param *param) +{ + _pthread_data *data = NULL; + int ret; + + if ((policy == NULL) || (param == NULL)) { + return EINVAL; + } + + ret = pthread_mutex_lock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + + data = pthread_get_data(thread); + if (data == NULL) { + goto ERR_OUT; + } + + *policy = data->attr.schedpolicy; + *param = data->attr.schedparam; + + ret = pthread_mutex_unlock(&g_pthreadsDataMutex); + return ret; +ERR_OUT: + ret = pthread_mutex_unlock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + return ESRCH; +} + +/* Call initRoutine just the once per control variable. */ +int pthread_once(pthread_once_t *onceControl, void (*initRoutine)(void)) +{ + pthread_once_t old; + int ret; + + if ((onceControl == NULL) || (initRoutine == NULL)) { + return EINVAL; + } + + /* Do a test and set on the onceControl object. */ + ret = pthread_mutex_lock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + + old = *onceControl; + *onceControl = 1; + + ret = pthread_mutex_unlock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + /* If the onceControl was zero, call the initRoutine(). */ + if (!old) { + initRoutine(); + } + + return ENOERR; +} + +/* Thread specific data */ +int pthread_key_create(pthread_key_t *key, void (*destructor)(void *)) +{ + (VOID)key; + (VOID)destructor; + PRINT_ERR("[%s] is not support.\n", __FUNCTION__); + return 0; +} + +/* Store the pointer value in the thread-specific data slot addressed by the key. */ +int pthread_setspecific(pthread_key_t key, const void *pointer) +{ + (VOID)key; + (VOID)pointer; + PRINT_ERR("[%s] is not support.\n", __FUNCTION__); + return 0; +} + +/* Retrieve the pointer value in the thread-specific data slot addressed by the key. */ +void *pthread_getspecific(pthread_key_t key) +{ + (VOID)key; + PRINT_ERR("[%s] is not support.\n", __FUNCTION__); + return NULL; +} + +/* + * Set cancel state of current thread to ENABLE or DISABLE. + * Returns old state in *oldState. + */ +int pthread_setcancelstate(int state, int *oldState) +{ + _pthread_data *self = NULL; + int ret; + + if ((state != PTHREAD_CANCEL_ENABLE) && (state != PTHREAD_CANCEL_DISABLE)) { + return EINVAL; + } + + ret = pthread_mutex_lock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + + self = pthread_get_self_data(); + + if (oldState != NULL) { + *oldState = self->cancelstate; + } + + self->cancelstate = (UINT8)state; + + ret = pthread_mutex_unlock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + + return ENOERR; +} + +/* + * Set cancel type of current thread to ASYNCHRONOUS or DEFERRED. + * Returns old type in *oldType. + */ +int pthread_setcanceltype(int type, int *oldType) +{ + _pthread_data *self = NULL; + int ret; + + if ((type != PTHREAD_CANCEL_ASYNCHRONOUS) && (type != PTHREAD_CANCEL_DEFERRED)) { + return EINVAL; + } + + ret = pthread_mutex_lock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + + self = pthread_get_self_data(); + if (oldType != NULL) { + *oldType = self->canceltype; + } + + self->canceltype = (UINT8)type; + + ret = pthread_mutex_unlock(&g_pthreadsDataMutex); + if (ret != ENOERR) { + return ret; + } + + return ENOERR; +} + +STATIC UINT32 DoPthreadCancel(_pthread_data *data) +{ + UINT32 ret = LOS_OK; + UINT32 intSave; + LOS_TaskLock(); + data->canceled = 0; + if ((data->task->taskStatus & OS_TASK_STATUS_EXIT) || (LOS_TaskSuspend(data->task->taskID) != ENOERR)) { + ret = LOS_NOK; + goto OUT; + } + + if (data->task->taskStatus & OS_TASK_FLAG_PTHREAD_JOIN) { + SCHEDULER_LOCK(intSave); + OsTaskJoinPostUnsafe(data->task); + SCHEDULER_UNLOCK(intSave); + g_pthreadCanceledDummyVar = (UINTPTR)PTHREAD_CANCELED; + data->task->joinRetval = (VOID *)g_pthreadCanceledDummyVar; + } else if (data->state && !(data->task->taskStatus & OS_TASK_STATUS_UNUSED)) { + data->state = PTHREAD_STATE_EXITED; + g_pthreadsExited++; + PthreadReap(); + } else { + ret = LOS_NOK; + } +OUT: + LOS_TaskUnlock(); + return ret; +} + +int pthread_cancel(pthread_t thread) +{ + _pthread_data *data = NULL; + + if (pthread_mutex_lock(&g_pthreadsDataMutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + + data = pthread_get_data(thread); + if (data == NULL) { + if (pthread_mutex_unlock(&g_pthreadsDataMutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + return ESRCH; + } + + data->canceled = 1; + + if ((data->cancelstate == PTHREAD_CANCEL_ENABLE) && + (data->canceltype == PTHREAD_CANCEL_ASYNCHRONOUS)) { + /* + * If the thread has cancellation enabled, and it is in + * asynchronous mode, suspend it and set corresponding thread's status. + * We also release the thread out of any current wait to make it wake up. + */ + if (DoPthreadCancel(data) == LOS_NOK) { + goto ERROR_OUT; + } + } + + /* + * Otherwise the thread has cancellation disabled, in which case + * it is up to the thread to enable cancellation + */ + if (pthread_mutex_unlock(&g_pthreadsDataMutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + + return ENOERR; +ERROR_OUT: + if (pthread_mutex_unlock(&g_pthreadsDataMutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + return ESRCH; +} + +/* + * Test for a pending cancellation for the current thread and terminate + * the thread if there is one. + */ +void pthread_testcancel(void) +{ + if (CheckForCancel()) { + /* + * If we have cancellation enabled, and there is a cancellation + * pending, then go ahead and do the deed. + * Exit now with special retVal. pthread_exit() calls the + * cancellation handlers implicitly. + */ + pthread_exit((void *)PTHREAD_CANCELED); + } +} + +/* Get current thread id. */ +pthread_t pthread_self(void) +{ + _pthread_data *data = pthread_get_self_data(); + + return data->id; +} + +/* Compare two thread identifiers. */ +int pthread_equal(pthread_t thread1, pthread_t thread2) +{ + return thread1 == thread2; +} + +void pthread_cleanup_push_inner(struct pthread_cleanup_buffer *buffer, + void (*routine)(void *), void *arg) +{ + (VOID)buffer; + (VOID)routine; + (VOID)arg; + PRINT_ERR("[%s] is not support.\n", __FUNCTION__); + return; +} + +void pthread_cleanup_pop_inner(struct pthread_cleanup_buffer *buffer, int execute) +{ + (VOID)buffer; + (VOID)execute; + PRINT_ERR("[%s] is not support.\n", __FUNCTION__); + return; +} + +/* + * Set the cpu affinity mask for the thread + */ +int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t* cpuset) +{ + INT32 ret = sched_setaffinity(thread, cpusetsize, cpuset); + if (ret == -1) { + return errno; + } else { + return ENOERR; + } +} + +/* + * Get the cpu affinity mask from the thread + */ +int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize, cpu_set_t* cpuset) +{ + INT32 ret = sched_getaffinity(thread, cpusetsize, cpuset); + if (ret == -1) { + return errno; + } else { + return ENOERR; + } +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/compat/posix/src/pthread_attr.c b/compat/posix/src/pthread_attr.c new file mode 100755 index 00000000..ec3764be --- /dev/null +++ b/compat/posix/src/pthread_attr.c @@ -0,0 +1,287 @@ +/* + * 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 "pthread.h" +#include "pprivate.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +int pthread_attr_init(pthread_attr_t *attr) +{ + if (attr == NULL) { + return EINVAL; + } + + attr->detachstate = PTHREAD_CREATE_JOINABLE; + attr->schedpolicy = SCHED_RR; + attr->schedparam.sched_priority = LOSCFG_BASE_CORE_TSK_DEFAULT_PRIO; + attr->inheritsched = PTHREAD_INHERIT_SCHED; + attr->scope = PTHREAD_SCOPE_PROCESS; + attr->stackaddr_set = 0; + attr->stackaddr = NULL; + attr->stacksize_set = 1; + attr->stacksize = LOSCFG_BASE_CORE_TSK_DEFAULT_STACK_SIZE; + +#if (LOSCFG_KERNEL_SMP == YES) + attr->cpuset.__bits[0] = 0; +#endif + + return ENOERR; +} + +int pthread_attr_destroy(pthread_attr_t *attr) +{ + if (attr == NULL) { + return EINVAL; + } + + /* Nothing to do here... */ + return ENOERR; +} + +int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachState) +{ + if ((attr != NULL) && ((detachState == PTHREAD_CREATE_JOINABLE) || (detachState == PTHREAD_CREATE_DETACHED))) { + attr->detachstate = (UINT32)detachState; + return ENOERR; + } + + return EINVAL; +} + +int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachState) +{ + if ((attr == NULL) || (detachState == NULL)) { + return EINVAL; + } + + *detachState = (int)attr->detachstate; + + return ENOERR; +} + +int pthread_attr_setscope(pthread_attr_t *attr, int scope) +{ + if (attr == NULL) { + return EINVAL; + } + + if (scope == PTHREAD_SCOPE_PROCESS) { + attr->scope = (unsigned int)scope; + return ENOERR; + } + + if (scope == PTHREAD_SCOPE_SYSTEM) { + return ENOTSUP; + } + + return EINVAL; +} + +int pthread_attr_getscope(const pthread_attr_t *attr, int *scope) +{ + if ((attr == NULL) || (scope == NULL)) { + return EINVAL; + } + + *scope = (int)attr->scope; + + return ENOERR; +} + +int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit) +{ + if ((attr != NULL) && ((inherit == PTHREAD_INHERIT_SCHED) || (inherit == PTHREAD_EXPLICIT_SCHED))) { + attr->inheritsched = (UINT32)inherit; + return ENOERR; + } + + return EINVAL; +} + +int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inherit) +{ + if ((attr == NULL) || (inherit == NULL)) { + return EINVAL; + } + + *inherit = (int)attr->inheritsched; + + return ENOERR; +} + +int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy) +{ + if ((attr != NULL) && (policy == SCHED_RR)) { + attr->schedpolicy = SCHED_RR; + return ENOERR; + } + + return EINVAL; +} + +int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy) +{ + if ((attr == NULL) || (policy == NULL)) { + return EINVAL; + } + + *policy = (int)attr->schedpolicy; + + return ENOERR; +} + +int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param) +{ + if ((attr == NULL) || (param == NULL)) { + return EINVAL; + } else if ((param->sched_priority < 0) || (param->sched_priority > OS_TASK_PRIORITY_LOWEST)) { + return ENOTSUP; + } + + attr->schedparam = *param; + + return ENOERR; +} + +int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param) +{ + if ((attr == NULL) || (param == NULL)) { + return EINVAL; + } + + *param = attr->schedparam; + + return ENOERR; +} + +/* + * Set starting address of stack. Whether this is at the start or end of + * the memory block allocated for the stack depends on whether the stack + * grows up or down. + */ +int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackAddr) +{ + if (attr == NULL) { + return EINVAL; + } + + attr->stackaddr_set = 1; + attr->stackaddr = stackAddr; + + return ENOERR; +} + +int pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackAddr) +{ + if (((attr != NULL) && (stackAddr != NULL)) && attr->stackaddr_set) { + *stackAddr = attr->stackaddr; + return ENOERR; + } + + return EINVAL; /* Stack address not set, return EINVAL. */ +} + +int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stackSize) +{ + /* Reject inadequate stack sizes */ + if ((attr == NULL) || (stackSize < PTHREAD_STACK_MIN)) { + return EINVAL; + } + + attr->stacksize_set = 1; + attr->stacksize = stackSize; + + return ENOERR; +} + +int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stackSize) +{ + /* Reject attempts to get a stack size when one has not been set. */ + if ((attr == NULL) || (stackSize == NULL) || (!attr->stacksize_set)) { + return EINVAL; + } + + *stackSize = attr->stacksize; + + return ENOERR; +} + +/* + * Set the cpu affinity mask + */ +int pthread_attr_setaffinity_np(pthread_attr_t* attr, size_t cpusetsize, const cpu_set_t* cpuset) +{ +#if (LOSCFG_KERNEL_SMP == YES) + if (attr == NULL) { + return EINVAL; + } + + if ((cpuset == NULL) || (cpusetsize == 0)) { + attr->cpuset.__bits[0] = 0; + return ENOERR; + } + + if ((cpusetsize != sizeof(cpu_set_t)) || (cpuset->__bits[0] > LOSCFG_KERNEL_CPU_MASK)) { + return EINVAL; + } + + attr->cpuset = *cpuset; +#endif + + return ENOERR; +} + +/* + * Get the cpu affinity mask + */ +int pthread_attr_getaffinity_np(const pthread_attr_t* attr, size_t cpusetsize, cpu_set_t* cpuset) +{ +#if (LOSCFG_KERNEL_SMP == YES) + if ((attr == NULL) || (cpuset == NULL) || (cpusetsize != sizeof(cpu_set_t))) { + return EINVAL; + } + + *cpuset = attr->cpuset; +#endif + + return ENOERR; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/compat/posix/src/pthread_cond.c b/compat/posix/src/pthread_cond.c new file mode 100755 index 00000000..0f824902 --- /dev/null +++ b/compat/posix/src/pthread_cond.c @@ -0,0 +1,358 @@ +/* + * 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 "pprivate.h" +#include "pthread.h" +#include "stdlib.h" +#include "time_posix.h" +#include "los_atomic.h" +#include "los_event_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define BROADCAST_EVENT 1 +#define COND_COUNTER_STEP 0x0004U +#define COND_FLAGS_MASK 0x0003U +#define COND_COUNTER_MASK (~COND_FLAGS_MASK) + +STATIC INLINE INT32 CondInitCheck(const pthread_cond_t *cond) +{ + if ((cond->event.stEventList.pstPrev == NULL) && + (cond->event.stEventList.pstNext == NULL)) { + return 1; + } + return 0; +} + +int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *shared) +{ + if ((attr == NULL) || (shared == NULL)) { + return EINVAL; + } + + *shared = PTHREAD_PROCESS_PRIVATE; + + return 0; +} + +int pthread_condattr_setpshared(pthread_condattr_t *attr, int shared) +{ + (VOID)attr; + if ((shared != PTHREAD_PROCESS_PRIVATE) && (shared != PTHREAD_PROCESS_SHARED)) { + return EINVAL; + } + + if (shared != PTHREAD_PROCESS_PRIVATE) { + return ENOSYS; + } + + return 0; +} + +int pthread_condattr_destroy(pthread_condattr_t *attr) +{ + if (attr == NULL) { + return EINVAL; + } + + return 0; +} + +int pthread_condattr_init(pthread_condattr_t *attr) +{ + if (attr == NULL) { + return EINVAL; + } + + return 0; +} + +int pthread_cond_destroy(pthread_cond_t *cond) +{ + if (cond == NULL) { + return EINVAL; + } + + if (CondInitCheck(cond)) { + return ENOERR; + } + + if (LOS_EventDestroy(&cond->event) != LOS_OK) { + return EBUSY; + } + if (pthread_mutex_destroy(cond->mutex) != ENOERR) { + PRINT_ERR("%s mutex destroy fail!\n", __FUNCTION__); + return EINVAL; + } + free(cond->mutex); + cond->mutex = NULL; + return ENOERR; +} + +int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) +{ + int ret = ENOERR; + + if (cond == NULL) { + return EINVAL; + } + (VOID)attr; + (VOID)LOS_EventInit(&(cond->event)); + + cond->mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); + if (cond->mutex == NULL) { + return ENOMEM; + } + + (VOID)pthread_mutex_init(cond->mutex, NULL); + + cond->value = 0; + (VOID)pthread_mutex_lock(cond->mutex); + cond->count = 0; + (VOID)pthread_mutex_unlock(cond->mutex); + + return ret; +} + +STATIC VOID PthreadCondValueModify(pthread_cond_t *cond) +{ + UINT32 flags = ((UINT32)cond->value & COND_FLAGS_MASK); + INT32 oldVal, newVal; + + while (true) { + oldVal = cond->value; + newVal = (INT32)(((UINT32)(oldVal - COND_COUNTER_STEP) & COND_COUNTER_MASK) | flags); + if (LOS_AtomicCmpXchg32bits(&cond->value, newVal, oldVal) == 0) { + break; + } + } +} + +int pthread_cond_broadcast(pthread_cond_t *cond) +{ + int ret = ENOERR; + + if (cond == NULL) { + return EINVAL; + } + + (VOID)pthread_mutex_lock(cond->mutex); + if (cond->count > 0) { + cond->count = 0; + (VOID)pthread_mutex_unlock(cond->mutex); + + PthreadCondValueModify(cond); + + (VOID)LOS_EventWrite(&(cond->event), BROADCAST_EVENT); + return ret; + } + (VOID)pthread_mutex_unlock(cond->mutex); + + return ret; +} + +int pthread_cond_signal(pthread_cond_t *cond) +{ + int ret = ENOERR; + + if (cond == NULL) { + return EINVAL; + } + + (VOID)pthread_mutex_lock(cond->mutex); + if (cond->count > 0) { + cond->count--; + (VOID)pthread_mutex_unlock(cond->mutex); + PthreadCondValueModify(cond); + (VOID)OsEventWriteOnce(&(cond->event), 0x01); + + return ret; + } + (VOID)pthread_mutex_unlock(cond->mutex); + + return ret; +} + +STATIC INT32 PthreadCondWaitSub(pthread_cond_t *cond, INT32 value, UINT32 ticks) +{ + EventCond eventCond = { &cond->value, value, ~0x01U }; + /* + * When the scheduling lock is held: + * (1) value is not equal to cond->value, clear the event message and + * do not block the current thread, because other threads is calling pthread_cond_broadcast or + * pthread_cond_signal to modify cond->value and wake up the current thread, + * and others threads will block on the scheduling lock until the current thread releases + * the scheduling lock. + * (2) value is equal to cond->value, block the current thread + * and wait to be awakened by other threads. + */ + return (int)OsEventReadWithCond(&eventCond, &(cond->event), 0x0fU, + LOS_WAITMODE_OR | LOS_WAITMODE_CLR, ticks); +} +STATIC VOID PthreadCountSub(pthread_cond_t *cond) +{ + (VOID)pthread_mutex_lock(cond->mutex); + if (cond->count > 0) { + cond->count--; + } + (VOID)pthread_mutex_unlock(cond->mutex); +} + +STATIC INT32 ProcessReturnVal(pthread_cond_t *cond, INT32 val) +{ + INT32 ret; + switch (val) { + /* 0: event does not occur */ + case 0: + case BROADCAST_EVENT: + ret = ENOERR; + break; + case LOS_ERRNO_EVENT_READ_TIMEOUT: + PthreadCountSub(cond); + ret = ETIMEDOUT; + break; + default: + PthreadCountSub(cond); + ret = EINVAL; + break; + } + return ret; +} + +int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, + const struct timespec *absTime) +{ + UINT32 absTicks; + INT32 ret; + INT32 oldValue; + + pthread_testcancel(); + if ((cond == NULL) || (mutex == NULL) || (absTime == NULL)) { + return EINVAL; + } + + if (CondInitCheck(cond)) { + ret = pthread_cond_init(cond, NULL); + if (ret != ENOERR) { + return ret; + } + } + oldValue = cond->value; + + (VOID)pthread_mutex_lock(cond->mutex); + cond->count++; + (VOID)pthread_mutex_unlock(cond->mutex); + + if ((absTime->tv_sec == 0) && (absTime->tv_nsec == 0)) { + return ETIMEDOUT; + } + + if (!ValidTimeSpec(absTime)) { + return EINVAL; + } + + absTicks = OsTimeSpec2Tick(absTime); + if (pthread_mutex_unlock(mutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + +#ifndef LOSCFG_ARCH_CORTEX_M7 + ret = PthreadCondWaitSub(cond, oldValue, absTicks); +#else + ret = (INT32)LOS_EventRead(&(cond->event), 0x0f, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, absTicks); +#endif + if (pthread_mutex_lock(mutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + + ret = ProcessReturnVal(cond, ret); + pthread_testcancel(); + return ret; +} + +int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) +{ + int ret; + int oldValue; + + if ((cond == NULL) || (mutex == NULL)) { + return EINVAL; + } + + if (CondInitCheck(cond)) { + ret = pthread_cond_init(cond, NULL); + if (ret != ENOERR) { + return ret; + } + } + oldValue = cond->value; + + (VOID)pthread_mutex_lock(cond->mutex); + cond->count++; + (VOID)pthread_mutex_unlock(cond->mutex); + + if (pthread_mutex_unlock(mutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + +#ifndef LOSCFG_ARCH_CORTEX_M7 + ret = PthreadCondWaitSub(cond, oldValue, LOS_WAIT_FOREVER); +#else + ret = (INT32)LOS_EventRead(&(cond->event), 0x0f, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER); +#endif + if (pthread_mutex_lock(mutex) != ENOERR) { + PRINT_ERR("%s: %d failed\n", __FUNCTION__, __LINE__); + } + + switch (ret) { + /* 0: event does not occur */ + case 0: + case BROADCAST_EVENT: + ret = ENOERR; + break; + default: + PthreadCountSub(cond); + ret = EINVAL; + break; + } + + return ret; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ \ No newline at end of file diff --git a/compat/posix/src/pthread_mutex.c b/compat/posix/src/pthread_mutex.c new file mode 100755 index 00000000..d12a3828 --- /dev/null +++ b/compat/posix/src/pthread_mutex.c @@ -0,0 +1,146 @@ +/* + * 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 "pthread.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +int pthread_mutexattr_init(pthread_mutexattr_t *attr) +{ + unsigned int ret = LOS_MuxAttrInit(attr); + if (ret != LOS_OK) { + return (int)ret; + } + +#if defined POSIX_MUTEX_DEFAULT_INHERIT + attr->protocol = PTHREAD_PRIO_INHERIT; +#elif defined POSIX_MUTEX_DEFAULT_PROTECT + attr->protocol = PTHREAD_PRIO_PROTECT; +#else + attr->protocol = PTHREAD_PRIO_NONE; +#endif + attr->type = PTHREAD_MUTEX_NORMAL; + return LOS_OK; +} + +int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) +{ + return LOS_MuxAttrDestroy(attr); +} + +int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol) +{ + return LOS_MuxAttrSetProtocol(attr, protocol); +} + +int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol) +{ + return LOS_MuxAttrGetProtocol(attr, protocol); +} + +int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling) +{ + return LOS_MuxAttrSetPrioceiling(attr, prioceiling); +} + +int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *attr, int *prioceiling) +{ + return LOS_MuxAttrGetPrioceiling(attr, prioceiling); +} + +int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *oldPrioceiling) +{ + return LOS_MuxSetPrioceiling(mutex, prioceiling, oldPrioceiling); +} + +int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, int *prioceiling) +{ + return LOS_MuxGetPrioceiling(mutex, prioceiling); +} + +int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *outType) +{ + return LOS_MuxAttrGetType(attr, outType); +} + +int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) +{ + return LOS_MuxAttrSetType(attr, type); +} + +/* Initialize mutex. If mutexAttr is NULL, use default attributes. */ +int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexAttr) +{ + unsigned int ret = LOS_MuxInit(mutex, mutexAttr); + if ((ret == LOS_OK) && (mutexAttr == NULL)) { +#if defined POSIX_MUTEX_DEFAULT_INHERIT + mutex->attr.protocol = PTHREAD_PRIO_INHERIT; +#elif defined POSIX_MUTEX_DEFAULT_PROTECT + mutex->attr.protocol = PTHREAD_PRIO_PROTECT; +#else + mutex->attr.protocol = PTHREAD_PRIO_NONE; +#endif + mutex->attr.type = PTHREAD_MUTEX_NORMAL; + } + + return (int)ret; +} + +int pthread_mutex_destroy(pthread_mutex_t *mutex) +{ + return LOS_MuxDestroy(mutex); +} + +/* Lock mutex, waiting for it if necessary. */ +int pthread_mutex_lock(pthread_mutex_t *mutex) +{ + return LOS_MuxLock(mutex, LOS_WAIT_FOREVER); +} + +int pthread_mutex_trylock(pthread_mutex_t *mutex) +{ + return LOS_MuxTrylock(mutex); +} + +int pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + return LOS_MuxUnlock(mutex); +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/compat/posix/src/sched.c b/compat/posix/src/sched.c new file mode 100755 index 00000000..d4841303 --- /dev/null +++ b/compat/posix/src/sched.c @@ -0,0 +1,150 @@ +/* + * 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 "sched.h" +#include "map_error.h" +#include "sys/types.h" +#include "unistd.h" +#include "los_task_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +int sched_get_priority_min(int policy) +{ + if (policy != SCHED_RR) { + errno = EINVAL; + return -1; + } + + return OS_TASK_PRIORITY_HIGHEST; +} + +int sched_get_priority_max(int policy) +{ + if (policy != SCHED_RR) { + errno = EINVAL; + return -1; + } + + return OS_TASK_PRIORITY_LOWEST; +} + +/* + * This API is Linux-specific, not conforming to POSIX. + */ +int sched_setaffinity(pid_t pid, size_t set_size, const cpu_set_t* set) +{ +#if (LOSCFG_KERNEL_SMP == YES) + UINT32 taskID = (UINT32)pid; + UINT32 ret; + + if ((set == NULL) || (set_size != sizeof(cpu_set_t)) || (set->__bits[0] > LOSCFG_KERNEL_CPU_MASK)) { + errno = EINVAL; + return -1; + } + + if (taskID == 0) { + taskID = LOS_CurTaskIDGet(); + if (taskID == LOS_ERRNO_TSK_ID_INVALID) { + errno = EINVAL; + return -1; + } + } + + ret = LOS_TaskCpuAffiSet(taskID, (UINT16)set->__bits[0]); + if (ret != LOS_OK) { + errno = map_errno(ret); + return -1; + } +#endif + + return 0; +} + +/* + * This API is Linux-specific, not conforming to POSIX. + */ +int sched_getaffinity(pid_t pid, size_t set_size, cpu_set_t* set) +{ +#if (LOSCFG_KERNEL_SMP == YES) + UINT32 taskID = (UINT32)pid; + UINT16 cpuAffiMask; + + if ((set == NULL) || (set_size != sizeof(cpu_set_t))) { + errno = EINVAL; + return -1; + } + + if (taskID == 0) { + taskID = LOS_CurTaskIDGet(); + if (taskID == LOS_ERRNO_TSK_ID_INVALID) { + errno = EINVAL; + return -1; + } + } + + cpuAffiMask = LOS_TaskCpuAffiGet(taskID); + if (cpuAffiMask == 0) { + errno = EINVAL; + return -1; + } + + set->__bits[0] = cpuAffiMask; +#endif + + return 0; +} + +int __sched_cpucount(size_t set_size, const cpu_set_t* set) +{ + INT32 count = 0; + UINT32 i; + + if ((set_size != sizeof(cpu_set_t)) || (set == NULL)) { + return 0; + } + + for (i = 0; i < set_size / sizeof(__CPU_BITTYPE); i++) { + count += __builtin_popcountl(set->__bits[i]); + } + + return count; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/compat/posix/src/semaphore.c b/compat/posix/src/semaphore.c new file mode 100755 index 00000000..425259ba --- /dev/null +++ b/compat/posix/src/semaphore.c @@ -0,0 +1,204 @@ +/* + * 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 "semaphore.h" +#include "sys/types.h" +#include "map_error.h" +#include "time_posix.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* Initialize semaphore to value, shared is not supported in Huawei LiteOS. */ +int sem_init(sem_t *sem, int shared, unsigned int value) +{ + UINT32 semHandle = 0; + UINT32 ret; + + (VOID)shared; + if ((sem == NULL) || (value > OS_SEM_COUNT_MAX)) { + errno = EINVAL; + return -1; + } + + ret = LOS_SemCreate(value, &semHandle); + if (map_errno(ret) != ENOERR) { + return -1; + } + + sem->sem = GET_SEM(semHandle); + + return 0; +} + +int sem_destroy(sem_t *sem) +{ + UINT32 ret; + + if ((sem == NULL) || (sem->sem == NULL)) { + errno = EINVAL; + return -1; + } + + ret = LOS_SemDelete(sem->sem->semID); + if (map_errno(ret) != ENOERR) { + return -1; + } + return 0; +} + +/* Decrement value if >0 or wait for a post. */ +int sem_wait(sem_t *sem) +{ + UINT32 ret; + + if ((sem == NULL) || (sem->sem == NULL)) { + errno = EINVAL; + return -1; + } + + ret = LOS_SemPend(sem->sem->semID, LOS_WAIT_FOREVER); + if (map_errno(ret) == ENOERR) { + return 0; + } else { + return -1; + } +} + +/* Decrement value if >0, return -1 if not. */ +int sem_trywait(sem_t *sem) +{ + UINT32 ret; + + if ((sem == NULL) || (sem->sem == NULL)) { + errno = EINVAL; + return -1; + } + + ret = LOS_SemPend(sem->sem->semID, LOS_NO_WAIT); + if (map_errno(ret) == ENOERR) { + return 0; + } else { + if ((errno != EINVAL) || (ret == LOS_ERRNO_SEM_UNAVAILABLE)) { + errno = EAGAIN; + } + return -1; + } +} + +int sem_timedwait(sem_t *sem, const struct timespec *timeout) +{ + UINT32 ret; + UINT32 tickCnt; + + if ((sem == NULL) || (sem->sem == NULL)) { + errno = EINVAL; + return -1; + } + + if (!ValidTimeSpec(timeout)) { + errno = EINVAL; + return -1; + } + + tickCnt = OsTimeSpec2Tick(timeout); + ret = LOS_SemPend(sem->sem->semID, tickCnt); + if (map_errno(ret) == ENOERR) { + return 0; + } else { + return -1; + } +} + +int sem_post(sem_t *sem) +{ + UINT32 ret; + + if ((sem == NULL) || (sem->sem == NULL)) { + errno = EINVAL; + return -1; + } + + ret = LOS_SemPost(sem->sem->semID); + if (map_errno(ret) != ENOERR) { + return -1; + } + + return 0; +} + +int sem_getvalue(sem_t *sem, int *currVal) +{ + INT32 val; + + if ((sem == NULL) || (currVal == NULL)) { + errno = EINVAL; + return -1; + } + val = sem->sem->semCount; + if (val < 0) { + val = 0; + } + + *currVal = val; + return 0; +} + +sem_t *sem_open(const char *name, int openFlag, ...) +{ + (VOID)name; + (VOID)openFlag; + errno = ENOSYS; + return NULL; +} + +int sem_close(sem_t *sem) +{ + (VOID)sem; + errno = ENOSYS; + return -1; +} + +int sem_unlink(const char *name) +{ + (VOID)name; + errno = ENOSYS; + return -1; +} + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/compat/posix/src/socket.c b/compat/posix/src/socket.c new file mode 100755 index 00000000..f29443dc --- /dev/null +++ b/compat/posix/src/socket.c @@ -0,0 +1,188 @@ +/* + * 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 +#include +#include + +#ifdef LOSCFG_NET_LWIP_SACK +#include + +#if !LWIP_COMPAT_SOCKETS + +#define CHECK_NULL_PTR(ptr) do { if (ptr == NULL) { set_errno(EFAULT); return -1; } } while (0) + +int accept(int s, struct sockaddr *addr, socklen_t *addrlen) +{ + return lwip_accept(s, addr, addrlen); +} + +int bind(int s, const struct sockaddr *name, socklen_t namelen) +{ + CHECK_NULL_PTR(name); + if (namelen < sizeof(*name)) { + set_errno(EINVAL); + return -1; + } + return lwip_bind(s, name, namelen); +} + +int shutdown(int s, int how) +{ + return lwip_shutdown(s, how); +} + +int getpeername(int s, struct sockaddr *name, socklen_t *namelen) +{ + CHECK_NULL_PTR(name); + CHECK_NULL_PTR(namelen); + return lwip_getpeername(s, name, namelen); +} + +int getsockname(int s, struct sockaddr *name, socklen_t *namelen) +{ + CHECK_NULL_PTR(name); + CHECK_NULL_PTR(namelen); + return lwip_getsockname(s, name, namelen); +} + +int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) +{ + return lwip_getsockopt(s, level, optname, optval, optlen); +} + +int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) +{ + return lwip_setsockopt(s, level, optname, optval, optlen); +} + +int closesocket(int s) +{ + return lwip_close(s); +} + +int connect(int s, const struct sockaddr *name, socklen_t namelen) +{ + CHECK_NULL_PTR(name); + if (namelen < sizeof(*name)) { + set_errno(EINVAL); + return -1; + } + return lwip_connect(s, name, namelen); +} + +int listen(int s, int backlog) +{ + return lwip_listen(s, backlog); +} + +ssize_t recv(int s, void *mem, size_t len, int flags) +{ + CHECK_NULL_PTR(mem); + return lwip_recv(s, mem, len, flags); +} + +ssize_t recvfrom(int s, void *mem, size_t len, int flags, + struct sockaddr *from, socklen_t *fromlen) +{ + CHECK_NULL_PTR(mem); + return lwip_recvfrom(s, mem, len, flags, from, fromlen); +} + +ssize_t recvmsg(int s, struct msghdr *message, int flags) +{ + CHECK_NULL_PTR(message); + if (message->msg_iovlen) { + CHECK_NULL_PTR(message->msg_iov); + } + return lwip_recvmsg(s, message, flags); +} + +ssize_t send(int s, const void *dataptr, size_t size, int flags) +{ + CHECK_NULL_PTR(dataptr); + return lwip_send(s, dataptr, size, flags); +} + +ssize_t sendmsg(int s, const struct msghdr *message, int flags) +{ + return lwip_sendmsg(s, message, flags); +} + +ssize_t sendto(int s, const void *dataptr, size_t size, int flags, + const struct sockaddr *to, socklen_t tolen) +{ + CHECK_NULL_PTR(dataptr); + if (to && tolen < sizeof(*to)) { + set_errno(EINVAL); + return -1; + } + return lwip_sendto(s, dataptr, size, flags, to, tolen); +} + +int socket(int domain, int type, int protocol) +{ + return lwip_socket(domain, type, protocol); +} + +const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) +{ + return lwip_inet_ntop(af, src, dst, size); +} + +int inet_pton(int af, const char *src, void *dst) +{ + return lwip_inet_pton(af, src, dst); +} + +#ifndef LWIP_INET_ADDR_FUNC +in_addr_t inet_addr(const char* cp) +{ + return ipaddr_addr(cp); +} +#endif + +#ifndef LWIP_INET_ATON_FUNC +int inet_aton(const char* cp, struct in_addr* inp) +{ + return ip4addr_aton(cp, (ip4_addr_t*)inp); +} +#endif + +#ifndef LWIP_INET_NTOA_FUNC +char* inet_ntoa(struct in_addr in) +{ + return ip4addr_ntoa((const ip4_addr_t*)&(in)); +} +#endif + +#endif /* !LWIP_COMPAT_SOCKETS */ +#endif /* LOSCFG_NET_LWIP_SACK */ \ No newline at end of file diff --git a/compat/posix/src/time.c b/compat/posix/src/time.c new file mode 100755 index 00000000..d3a42f4e --- /dev/null +++ b/compat/posix/src/time.c @@ -0,0 +1,984 @@ +/* + * 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 "time.h" +#include "asm/hal_platform_ints.h" +#include "stdint.h" +#include "stdio.h" +#include "sys/times.h" +#include "time_posix.h" +#include "unistd.h" +#ifdef LOSCFG_SECURITY_CAPABILITY +#include "capability_api.h" +#endif +#include "los_signal.h" +#ifdef LOSCFG_KERNEL_VDSO +#include "los_vdso.h" +#endif +#ifdef LOSCFG_SECURITY_VID +#include "vid_api.h" +#endif +#include "user_copy.h" +#include "los_process_pri.h" +#include "los_swtmr_pri.h" +#include "los_sys_pri.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* + * Do a time package defined return. This requires the error code + * to be placed in errno, and if it is non-zero, -1 returned as the + * result of the function. This also gives us a place to put any + * generic tidyup handling needed for things like signal delivery and + * cancellation. + */ +#define TIME_RETURN(err) do { \ + INT32 retVal = 0; \ + if ((err) != 0) { \ + retVal = -1; \ + errno = (err); \ + } \ + return retVal; \ +} while (0) + +#ifdef LOSCFG_AARCH64 +/* + * This two structures originally did't exit, + * they added by liteos to support 64bit interfaces on 32bit platform, + * in 64bit platform, timeval64 define to timeval which is platform adaptive. + */ +#define timeval64 timeval +#define timespec64 timespec +#endif + +STATIC INLINE BOOL ValidTimeval(const struct timeval *tv) +{ + /* Fail a NULL pointer */ + if (tv == NULL) { + return FALSE; + } + + /* Fail illegal microseconds values */ + if ((tv->tv_usec < 0) || (tv->tv_usec >= OS_SYS_US_PER_SECOND) || (tv->tv_sec < 0)) { + return FALSE; + } + + return TRUE; +} + +STATIC INLINE BOOL ValidTimeval64(const struct timeval64 *tv) +{ + /* Fail a NULL pointer */ + if (tv == NULL) { + return FALSE; + } + + /* Fail illegal microseconds values */ + if ((tv->tv_usec < 0) || (tv->tv_usec >= OS_SYS_US_PER_SECOND) || (tv->tv_sec < 0)) { + return FALSE; + } + + return TRUE; +} + +STATIC INLINE BOOL ValidTimerID(UINT16 swtmrID) +{ + /* check timer id */ + if (swtmrID >= OS_SWTMR_MAX_TIMERID) { + return FALSE; + } + + /* check owner of this timer */ + if (OS_SWT_FROM_SID(swtmrID)->uwOwnerPid != LOS_GetCurrProcessID()) { + return FALSE; + } + + return TRUE; +} + +STATIC SPIN_LOCK_INIT(g_timeSpin); +STATIC long long g_adjTimeLeft; /* absolute value of adjtime */ +STATIC INT32 g_adjDirection; /* 1, speed up; 0, slow down; */ + +/* Adjust pacement, nanoseconds per SCHED_CLOCK_INTETRVAL_TICKS ticks */ +STATIC const long long g_adjPacement = (((LOSCFG_BASE_CORE_ADJ_PER_SECOND * SCHED_CLOCK_INTETRVAL_TICKS) / + LOSCFG_BASE_CORE_TICK_PER_SECOND) * OS_SYS_NS_PER_US); + +/* accumulative time delta from continuous modify, such as adjtime */ +STATIC struct timespec64 g_accDeltaFromAdj; +/* accumulative time delta from discontinuous modify, such as settimeofday */ +STATIC struct timespec64 g_accDeltaFromSet; + +VOID OsAdjTime(VOID) +{ + UINT32 intSave; + + LOS_SpinLockSave(&g_timeSpin, &intSave); + if (!g_adjTimeLeft) { + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + return; + } + + if (g_adjTimeLeft > g_adjPacement) { + if (g_adjDirection) { + if ((g_accDeltaFromAdj.tv_nsec + g_adjPacement) >= OS_SYS_NS_PER_SECOND) { + g_accDeltaFromAdj.tv_sec++; + g_accDeltaFromAdj.tv_nsec = (g_accDeltaFromAdj.tv_nsec + g_adjPacement) % OS_SYS_NS_PER_SECOND; + } else { + g_accDeltaFromAdj.tv_nsec = g_accDeltaFromAdj.tv_nsec + g_adjPacement; + } + } else { + if ((g_accDeltaFromAdj.tv_nsec - g_adjPacement) < 0) { + g_accDeltaFromAdj.tv_sec--; + g_accDeltaFromAdj.tv_nsec = g_accDeltaFromAdj.tv_nsec - g_adjPacement + OS_SYS_NS_PER_SECOND; + } else { + g_accDeltaFromAdj.tv_nsec = g_accDeltaFromAdj.tv_nsec - g_adjPacement; + } + } + + g_adjTimeLeft -= g_adjPacement; + } else { + if (g_adjDirection) { + if ((g_accDeltaFromAdj.tv_nsec + g_adjTimeLeft) >= OS_SYS_NS_PER_SECOND) { + g_accDeltaFromAdj.tv_sec++; + g_accDeltaFromAdj.tv_nsec = (g_accDeltaFromAdj.tv_nsec + g_adjTimeLeft) % OS_SYS_NS_PER_SECOND; + } else { + g_accDeltaFromAdj.tv_nsec = g_accDeltaFromAdj.tv_nsec + g_adjTimeLeft; + } + } else { + if ((g_accDeltaFromAdj.tv_nsec - g_adjTimeLeft) < 0) { + g_accDeltaFromAdj.tv_sec--; + g_accDeltaFromAdj.tv_nsec = g_accDeltaFromAdj.tv_nsec - g_adjTimeLeft + OS_SYS_NS_PER_SECOND; + } else { + g_accDeltaFromAdj.tv_nsec = g_accDeltaFromAdj.tv_nsec - g_adjTimeLeft; + } + } + + g_adjTimeLeft = 0; + } + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + return; +} + +/* + * Function: adjtime + * Description: correct the time to synchronize the system clock. + * Input: delta - The amount of time by which the clock is to be adjusted. + * Output: oldDelta - the amount of time remaining from any previous adjustment that has not yet been completed. + * Return: On success, returns 0. On failure, -1 is returned, and errno is set to indicate the error. + */ +int adjtime(const struct timeval *delta, struct timeval *oldDelta) +{ + UINT32 intSave; + LOS_SpinLockSave(&g_timeSpin, &intSave); + /* return the amount of time remaining from any previous adjustment that has not yet been completed. */ + if (oldDelta != NULL) { + if (g_adjDirection == 1) { + oldDelta->tv_sec = g_adjTimeLeft / OS_SYS_NS_PER_SECOND; + oldDelta->tv_usec = (g_adjTimeLeft % OS_SYS_NS_PER_SECOND) / OS_SYS_NS_PER_US; + } else { + oldDelta->tv_sec = -(g_adjTimeLeft / OS_SYS_NS_PER_SECOND); + oldDelta->tv_usec = -((g_adjTimeLeft % OS_SYS_NS_PER_SECOND) / OS_SYS_NS_PER_US); + } + } + + if ((delta == NULL) || ((delta->tv_sec == 0) && (delta->tv_usec == 0))) { + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + return 0; + } + + if ((delta->tv_usec > OS_SYS_US_PER_SECOND) || (delta->tv_usec < -OS_SYS_US_PER_SECOND)) { + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + TIME_RETURN(EINVAL); + } + + /* + * 2: in the glibc implementation, delta must be less than or equal to (INT_MAX / 1000000 - 2) and + * greater than or equal to (INT_MIN / 1000000 + 2) + */ + if ((delta->tv_sec < (INT_MIN / OS_SYS_US_PER_SECOND + 2)) || + (delta->tv_sec > (INT_MAX / OS_SYS_US_PER_SECOND + 2))) { + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + TIME_RETURN(EINVAL); + } + + g_adjTimeLeft = (INT64)delta->tv_sec * OS_SYS_NS_PER_SECOND + delta->tv_usec * OS_SYS_NS_PER_US; + if (g_adjTimeLeft > 0) { + g_adjDirection = 1; + } else { + g_adjDirection = 0; + g_adjTimeLeft = -g_adjTimeLeft; + } + + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + return 0; +} + +STATIC INLINE struct timespec64 OsTimeSpecAdd(const struct timespec64 t1, const struct timespec64 t2) +{ + struct timespec64 ret = {0}; + + ret.tv_sec = t1.tv_sec + t2.tv_sec; + ret.tv_nsec = t1.tv_nsec + t2.tv_nsec; + if (ret.tv_nsec >= OS_SYS_NS_PER_SECOND) { + ret.tv_sec += 1; + ret.tv_nsec -= OS_SYS_NS_PER_SECOND; + } else if (ret.tv_nsec < 0L) { + ret.tv_sec -= 1; + ret.tv_nsec += OS_SYS_NS_PER_SECOND; + } + + return ret; +} + +STATIC INLINE struct timespec64 OsTimeSpecSub(const struct timespec64 t1, const struct timespec64 t2) +{ + struct timespec64 ret = {0}; + + ret.tv_sec = t1.tv_sec - t2.tv_sec; + ret.tv_nsec = t1.tv_nsec - t2.tv_nsec; + if (ret.tv_nsec < 0) { + ret.tv_sec -= 1; + ret.tv_nsec += OS_SYS_NS_PER_SECOND; + } + + return ret; +} + +STATIC VOID OsGetHwTime(struct timespec64 *hwTime) +{ + UINT64 nowNsec; + + nowNsec = hi_sched_clock(); + hwTime->tv_sec = nowNsec / OS_SYS_NS_PER_SECOND; + hwTime->tv_nsec = nowNsec - hwTime->tv_sec * OS_SYS_NS_PER_SECOND; +} + +STATIC INT32 OsSetTimeOfDay(const struct timeval64 *tv, const struct timezone *tz) +{ + UINT32 intSave; + struct timespec64 setTime = {0}; + struct timespec64 hwTime = {0}; + struct timespec64 realTime = {0}; + struct timespec64 tmp = {0}; + +#ifdef LOSCFG_SECURITY_CAPABILITY + if (!IsCapPermit(CAP_SET_TIMEOFDAY)) { + TIME_RETURN(EPERM); + } +#endif + + (VOID)tz; + OsGetHwTime(&hwTime); + setTime.tv_sec = tv->tv_sec; + setTime.tv_nsec = tv->tv_usec * OS_SYS_NS_PER_US; + + LOS_SpinLockSave(&g_timeSpin, &intSave); + /* stop on-going continuous adjusement */ + if (g_adjTimeLeft) { + g_adjTimeLeft = 0; + } + realTime = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj); + realTime = OsTimeSpecAdd(realTime, g_accDeltaFromSet); + + tmp = OsTimeSpecSub(setTime, realTime); + g_accDeltaFromSet = OsTimeSpecAdd(g_accDeltaFromSet, tmp); + + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + + return 0; +} + +int settimeofday(const struct timeval *tv, const struct timezone *tz) +{ + struct timeval64 stTimeVal64 = {0}; + + if (!ValidTimeval(tv)) { + TIME_RETURN(EINVAL); + } + + stTimeVal64.tv_sec = tv->tv_sec; + stTimeVal64.tv_usec = tv->tv_usec; + + return OsSetTimeOfDay(&stTimeVal64, tz); +} + +#ifndef LOSCFG_AARCH64 +int settimeofday64(const struct timeval64 *tv, const struct timezone *tz) +{ + if (!ValidTimeval64(tv)) { + TIME_RETURN(EINVAL); + } + + return OsSetTimeOfDay(tv, tz); +} +#endif + +int setlocalseconds(int seconds) +{ + struct timeval tv = {0}; + + tv.tv_sec = seconds; + tv.tv_usec = 0; + + return settimeofday(&tv, NULL); +} + +STATIC INT32 OsGetTimeOfDay(struct timeval64 *tv, struct timezone *tz) +{ + UINT32 intSave; + + (VOID)tz; + struct timespec64 hwTime = {0}; + struct timespec64 realTime = {0}; + + OsGetHwTime(&hwTime); + + LOS_SpinLockSave(&g_timeSpin, &intSave); + realTime = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj); + realTime = OsTimeSpecAdd(realTime, g_accDeltaFromSet); + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + + tv->tv_sec = realTime.tv_sec; + tv->tv_usec = realTime.tv_nsec / OS_SYS_NS_PER_US; + + if (tv->tv_sec < 0) { + TIME_RETURN(EINVAL); + } + return 0; +} + +#ifndef LOSCFG_AARCH64 +int gettimeofday64(struct timeval64 *tv, struct timezone *tz) +{ + if (tv == NULL) { + TIME_RETURN(EINVAL); + } + + return OsGetTimeOfDay(tv, tz); +} +#endif + +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + struct timeval64 stTimeVal64 = {0}; + + if (tv == NULL) { + TIME_RETURN(EINVAL); + } + + if (OsGetTimeOfDay(&stTimeVal64, tz) == -1) { + return -1; + } + +#ifdef LOSCFG_AARCH64 + tv->tv_sec = stTimeVal64.tv_sec; + tv->tv_usec = stTimeVal64.tv_usec; +#else + if (stTimeVal64.tv_sec > (long long)LONG_MAX) { + return -1; + } + tv->tv_sec = (time_t)stTimeVal64.tv_sec; + tv->tv_usec = (suseconds_t)stTimeVal64.tv_usec; +#endif + + return 0; +} + +int clock_settime(clockid_t clockID, const struct timespec *tp) +{ + struct timeval tv = {0}; + + switch (clockID) { + case CLOCK_REALTIME: + /* we only support the realtime clock currently */ + break; + case CLOCK_MONOTONIC_COARSE: + case CLOCK_REALTIME_COARSE: + case CLOCK_MONOTONIC_RAW: + case CLOCK_PROCESS_CPUTIME_ID: + case CLOCK_BOOTTIME: + case CLOCK_REALTIME_ALARM: + case CLOCK_BOOTTIME_ALARM: + case CLOCK_SGI_CYCLE: + case CLOCK_TAI: + case CLOCK_THREAD_CPUTIME_ID: + TIME_RETURN(ENOTSUP); + case CLOCK_MONOTONIC: + default: + TIME_RETURN(EINVAL); + } + + if (!ValidTimeSpec(tp)) { + TIME_RETURN(EINVAL); + } + +#ifdef LOSCFG_SECURITY_CAPABILITY + if (!IsCapPermit(CAP_CLOCK_SETTIME)) { + TIME_RETURN(EPERM); + } +#endif + + tv.tv_sec = tp->tv_sec; + tv.tv_usec = tp->tv_nsec / OS_SYS_NS_PER_US; + return settimeofday(&tv, NULL); +} + +int clock_gettime(clockid_t clockID, struct timespec *tp) +{ + UINT32 intSave; + struct timespec64 tmp = {0}; + struct timespec64 hwTime = {0}; + + if ((clockID > MAX_CLOCKS) || (clockID < CLOCK_REALTIME)) { + goto ERROUT; + } + + if (tp == NULL) { + goto ERROUT; + } + + OsGetHwTime(&hwTime); + + switch (clockID) { + case CLOCK_MONOTONIC_RAW: + tp->tv_sec = hwTime.tv_sec; + tp->tv_nsec = hwTime.tv_nsec; + break; + case CLOCK_MONOTONIC: + LOS_SpinLockSave(&g_timeSpin, &intSave); + tmp = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj); + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + tp->tv_sec = tmp.tv_sec; + tp->tv_nsec = tmp.tv_nsec; + break; + case CLOCK_REALTIME: + LOS_SpinLockSave(&g_timeSpin, &intSave); + tmp = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj); + tmp = OsTimeSpecAdd(tmp, g_accDeltaFromSet); + LOS_SpinUnlockRestore(&g_timeSpin, intSave); + tp->tv_sec = tmp.tv_sec; + tp->tv_nsec = tmp.tv_nsec; + break; + case CLOCK_MONOTONIC_COARSE: + case CLOCK_REALTIME_COARSE: + case CLOCK_THREAD_CPUTIME_ID: + case CLOCK_PROCESS_CPUTIME_ID: + case CLOCK_BOOTTIME: + case CLOCK_REALTIME_ALARM: + case CLOCK_BOOTTIME_ALARM: + case CLOCK_SGI_CYCLE: + case CLOCK_TAI: + TIME_RETURN(ENOTSUP); + default: + goto ERROUT; + } + + return 0; + +ERROUT: + TIME_RETURN(EINVAL); +} + +int clock_getres(clockid_t clockID, struct timespec *tp) +{ + if (tp == NULL) { + TIME_RETURN(EINVAL); + } + + switch (clockID) { + case CLOCK_MONOTONIC_RAW: + case CLOCK_MONOTONIC: + case CLOCK_REALTIME: + /* the accessable rtc resolution */ + tp->tv_nsec = OS_SYS_NS_PER_US; /* the precision of clock_gettime is 1us */ + tp->tv_sec = 0; + break; + case CLOCK_MONOTONIC_COARSE: + case CLOCK_REALTIME_COARSE: + /* the clock coarse resolution, supported by vdso. + * the precision of clock_gettime is 1tick */ + tp->tv_nsec = OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND; + tp->tv_sec = 0; + break; + case CLOCK_THREAD_CPUTIME_ID: + case CLOCK_PROCESS_CPUTIME_ID: + case CLOCK_BOOTTIME: + case CLOCK_REALTIME_ALARM: + case CLOCK_BOOTTIME_ALARM: + case CLOCK_SGI_CYCLE: + case CLOCK_TAI: + TIME_RETURN(ENOTSUP); + default: + TIME_RETURN(EINVAL); + } + + TIME_RETURN(0); +} + +int clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem) +{ + switch (clk) { + case CLOCK_REALTIME: + if (flags == 0) { + /* we only support the realtime clock currently */ + return nanosleep(req, rem); + } + /* fallthrough */ + case CLOCK_MONOTONIC_COARSE: + case CLOCK_REALTIME_COARSE: + case CLOCK_MONOTONIC_RAW: + case CLOCK_MONOTONIC: + case CLOCK_PROCESS_CPUTIME_ID: + case CLOCK_BOOTTIME: + case CLOCK_REALTIME_ALARM: + case CLOCK_BOOTTIME_ALARM: + case CLOCK_SGI_CYCLE: + case CLOCK_TAI: + if (flags == 0 || flags == TIMER_ABSTIME) { + TIME_RETURN(ENOTSUP); + } + /* fallthrough */ + case CLOCK_THREAD_CPUTIME_ID: + default: + TIME_RETURN(EINVAL); + } + + TIME_RETURN(0); +} + +typedef struct { + int sigev_signo; + UINT32 pid; + union sigval sigev_value; +} swtmr_proc_arg; + +static VOID SwtmrProc(UINTPTR tmrArg) +{ + int sig; + pid_t pid; + siginfo_t info; + swtmr_proc_arg *arg = (swtmr_proc_arg *)tmrArg; + if (arg == NULL) { + return; + } + + sig = arg->sigev_signo + 1; + pid = arg->pid; + /* Make sure that the para is valid */ + if (!GOOD_SIGNO(sig) || pid <= 0) { + return; + } + if (OS_PID_CHECK_INVALID(pid)) { + return; + } + + /* Create the siginfo structure */ + info.si_signo = sig; + info.si_code = SI_TIMER; + info.si_value.sival_ptr = arg->sigev_value.sival_ptr; + + /* Send the signal */ + OsDispatch(pid, &info, OS_USER_KILL_PERMISSION); + return; +} + +int timer_create(clockid_t clockID, struct sigevent *evp, timer_t *timerID) +{ + UINT32 ret; + UINT16 swtmrID; + swtmr_proc_arg *arg = NULL; + int signo; +#ifdef LOSCFG_SECURITY_VID + UINT16 vid; +#endif + + if ((clockID != CLOCK_REALTIME) || (timerID == NULL)) { + errno = EINVAL; + return -1; + } + + signo = evp ? evp->sigev_signo : SIGALRM; + if (signo > SIGRTMAX || signo < 1) { + errno = EINVAL; + return -1; + } + if (evp && (evp->sigev_notify != SIGEV_SIGNAL && evp->sigev_notify != SIGEV_THREAD_ID)) { + errno = ENOTSUP; + return -1; + } + + arg = (swtmr_proc_arg *)malloc(sizeof(swtmr_proc_arg)); + if (arg == NULL) { + errno = ENOMEM; + return -1; + } + arg->sigev_signo = signo - 1; + arg->pid = LOS_GetCurrProcessID(); + arg->sigev_value.sival_ptr = evp ? evp->sigev_value.sival_ptr : NULL; + ret = LOS_SwtmrCreate(1, LOS_SWTMR_MODE_ONCE, SwtmrProc, &swtmrID, (UINTPTR)arg); + if (ret != LOS_OK) { + errno = (ret == LOS_ERRNO_SWTMR_MAXSIZE) ? EAGAIN : EINVAL; + free(arg); + return -1; + } + +#ifdef LOSCFG_SECURITY_VID + vid = AddNodeByRid(swtmrID); + if (vid == MAX_INVALID_TIMER_VID) { + free(arg); + (VOID)LOS_SwtmrDelete(swtmrID); + return -1; + } + swtmrID = vid; +#endif + *timerID = (timer_t)(UINTPTR)swtmrID; + return 0; +} + +int timer_delete(timer_t timerID) +{ + UINT16 swtmrID = (UINT16)(UINTPTR)timerID; + VOID *arg = NULL; + +#ifdef LOSCFG_SECURITY_VID + swtmrID = GetRidByVid(swtmrID); +#endif + if (OS_INT_ACTIVE || !ValidTimerID(swtmrID)) { + goto ERROUT; + } + + arg = (VOID *)OS_SWT_FROM_SID(swtmrID)->uwArg; + if (LOS_SwtmrDelete(swtmrID)) { + goto ERROUT; + } + if (arg != NULL) { + free(arg); + } + +#ifdef LOSCFG_SECURITY_VID + RemoveNodeByVid((UINT16)(UINTPTR)timerID); +#endif + return 0; + +ERROUT: + errno = EINVAL; + return -1; +} + +int timer_settime(timer_t timerID, int flags, + const struct itimerspec *value, /* new value */ + struct itimerspec *oldValue) /* old value to return, always 0 */ +{ + UINT16 swtmrID = (UINT16)(UINTPTR)timerID; + SWTMR_CTRL_S *swtmr = NULL; + UINT32 interval, expiry, ret; + UINT32 intSave; + + if (flags != 0) { + /* flags not supported currently */ + errno = ENOSYS; + return -1; + } + +#ifdef LOSCFG_SECURITY_VID + swtmrID = GetRidByVid(swtmrID); +#endif + if ((value == NULL) || OS_INT_ACTIVE || !ValidTimerID(swtmrID)) { + errno = EINVAL; + return -1; + } + + if (!ValidTimeSpec(&value->it_value) || !ValidTimeSpec(&value->it_interval)) { + errno = EINVAL; + return -1; + } + + if (oldValue) { + (VOID)timer_gettime(timerID, oldValue); + } + + swtmr = OS_SWT_FROM_SID(swtmrID); + ret = LOS_SwtmrStop(swtmr->usTimerID); + if ((ret != LOS_OK) && (ret != LOS_ERRNO_SWTMR_NOT_STARTED)) { + errno = EINVAL; + return -1; + } + + expiry = OsTimeSpec2Tick(&value->it_value); + interval = OsTimeSpec2Tick(&value->it_interval); + + LOS_SpinLockSave(&g_swtmrSpin, &intSave); + swtmr->ucMode = interval ? LOS_SWTMR_MODE_OPP : LOS_SWTMR_MODE_NO_SELFDELETE; + swtmr->uwExpiry = expiry + !!expiry; // PS: skip the first tick because it is NOT a full tick. + swtmr->uwInterval = interval; + swtmr->ucOverrun = 0; + LOS_SpinUnlockRestore(&g_swtmrSpin, intSave); + + if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) { + /* + * 1) when expiry is 0, means timer should be stopped. + * 2) If timer is ticking, stopping timer is already done before. + * 3) If timer is created but not ticking, return 0 as well. + */ + return 0; + } + + if (LOS_SwtmrStart(swtmr->usTimerID)) { + errno = EINVAL; + return -1; + } + + return 0; +} + +int timer_gettime(timer_t timerID, struct itimerspec *value) +{ + UINT32 tick = 0; + SWTMR_CTRL_S *swtmr = NULL; + UINT16 swtmrID = (UINT16)(UINTPTR)timerID; + UINT32 ret; + +#ifdef LOSCFG_SECURITY_VID + swtmrID = GetRidByVid(swtmrID); +#endif + if ((value == NULL) || !ValidTimerID(swtmrID)) { + errno = EINVAL; + return -1; + } + + swtmr = OS_SWT_FROM_SID(swtmrID); + + /* get expire time */ + ret = LOS_SwtmrTimeGet(swtmr->usTimerID, &tick); + if ((ret != LOS_OK) && (ret != LOS_ERRNO_SWTMR_NOT_STARTED)) { + errno = EINVAL; + return -1; + } + + OsTick2TimeSpec(&value->it_value, tick); + OsTick2TimeSpec(&value->it_interval, (swtmr->ucMode == LOS_SWTMR_MODE_ONCE) ? 0 : swtmr->uwInterval); + return 0; +} + +int timer_getoverrun(timer_t timerID) +{ + UINT16 swtmrID = (UINT16)(UINTPTR)timerID; + SWTMR_CTRL_S *swtmr = NULL; + INT32 overRun; + +#ifdef LOSCFG_SECURITY_VID + swtmrID = GetRidByVid(swtmrID); +#endif + if (!ValidTimerID(swtmrID)) { + errno = EINVAL; + return -1; + } + + swtmr = OS_SWT_FROM_SID(swtmrID); + if (swtmr->usTimerID >= OS_SWTMR_MAX_TIMERID) { + errno = EINVAL; + return -1; + } + + overRun = (INT32)(swtmr->ucOverrun); + return (overRun > DELAYTIMER_MAX) ? DELAYTIMER_MAX : overRun; +} + +STATIC INT32 DoNanoSleep(UINT64 nseconds) +{ + UINT64 tick; + UINT32 ret; + const UINT32 nsPerTick = OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND; + + tick = (nseconds + nsPerTick - 1) / nsPerTick; // Round up for ticks + + /* PS: skip the first tick because it is NOT a full tick. */ + ret = LOS_TaskDelay((tick >= UINT32_MAX) ? UINT32_MAX : (tick ? ((UINT32)tick + 1) : 0)); + if (ret == LOS_OK || ret == LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK) { + return 0; + } + return -1; +} + +int usleep(unsigned useconds) +{ + return DoNanoSleep((UINT64)useconds * OS_SYS_NS_PER_US); +} + +int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) +{ + UINT64 nseconds; + INT32 ret = -1; + + (VOID)rmtp; + /* expire time */ + + if (!ValidTimeSpec(rqtp)) { + errno = EINVAL; + return ret; + } + + nseconds = (UINT64)rqtp->tv_sec * OS_SYS_NS_PER_SECOND + rqtp->tv_nsec; + + return DoNanoSleep(nseconds); +} + +unsigned int sleep(unsigned int seconds) +{ + return DoNanoSleep((UINT64)seconds * OS_SYS_NS_PER_SECOND); +} + +double difftime(time_t time2, time_t time1) +{ + return (double)(time2 - time1); +} + +clock_t clock(VOID) +{ + clock_t clockMsec; + UINT64 nowNsec; + + nowNsec = hi_sched_clock(); + clockMsec = (clock_t)(nowNsec / OS_SYS_NS_PER_MS); + + return clockMsec; +} + +clock_t times(struct tms *buf) +{ + clock_t clockTick; + + clockTick = LOS_TickCountGet(); + if (buf != NULL) { + buf->tms_cstime = clockTick; + buf->tms_cutime = clockTick; + buf->tms_stime = clockTick; + buf->tms_utime = clockTick; + } + + return clockTick; +} + +int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue) +{ + LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet()); + LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID); + struct itimerspec spec; + struct itimerspec ospec; + int ret = LOS_OK; + + /* we only support the realtime clock timer currently */ + if (which != ITIMER_REAL || !value) { + set_errno(EINVAL); + return -1; + } + LOS_TaskLock(); + if (processCB->timerID == (timer_t)(UINTPTR)MAX_INVALID_TIMER_VID) { + ret = timer_create(CLOCK_REALTIME, NULL, &processCB->timerID); + if (ret != LOS_OK) { + LOS_TaskUnlock(); + return ret; + } + } + LOS_TaskUnlock(); + TIMEVAL_TO_TIMESPEC(&value->it_value, &spec.it_value); + TIMEVAL_TO_TIMESPEC(&value->it_interval, &spec.it_interval); + + ret = timer_settime(processCB->timerID, 0, &spec, ovalue ? &ospec : NULL); + if (ret == LOS_OK && ovalue) { + TIMESPEC_TO_TIMEVAL(&ovalue->it_value, &ospec.it_value); + TIMESPEC_TO_TIMEVAL(&ovalue->it_interval, &ospec.it_interval); + } + + return ret; +} + +int getitimer(int which, struct itimerval *value) +{ + LosTaskCB *taskCB = OS_TCB_FROM_TID(LOS_CurTaskIDGet()); + LosProcessCB *processCB = OS_PCB_FROM_PID(taskCB->processID); + struct itimerspec spec = {}; + + int ret = LOS_OK; + + /* we only support the realtime clock timer currently */ + if (which != ITIMER_REAL || !value) { + set_errno(EINVAL); + return -1; + } + + if (processCB->timerID != (timer_t)(UINTPTR)MAX_INVALID_TIMER_VID) { + ret = timer_gettime(processCB->timerID, &spec); + } + + if (ret == LOS_OK) { + TIMESPEC_TO_TIMEVAL(&value->it_value, &spec.it_value); + TIMESPEC_TO_TIMEVAL(&value->it_interval, &spec.it_interval); + } + + return ret; +} + +#ifdef LOSCFG_KERNEL_VDSO +VOID OsGetVdsoTime(VdsoDataPage *vdsoDataPage) +{ + UINT32 intSave; + struct timespec64 tmp = {0}; + struct timespec64 hwTime = {0}; + + if (vdsoDataPage == NULL) { + return; + } + + OsGetHwTime(&hwTime); + + LOS_SpinLockSave(&g_timeSpin, &intSave); + tmp = OsTimeSpecAdd(hwTime, g_accDeltaFromAdj); + vdsoDataPage->monoTimeSec = tmp.tv_sec; + vdsoDataPage->monoTimeNsec = tmp.tv_nsec; + + tmp = OsTimeSpecAdd(tmp, g_accDeltaFromSet); + vdsoDataPage->realTimeSec = tmp.tv_sec; + vdsoDataPage->realTimeNsec = tmp.tv_nsec; + LOS_SpinUnlockRestore(&g_timeSpin, intSave); +} +#endif + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/config.mk b/config.mk new file mode 100755 index 00000000..04f95d53 --- /dev/null +++ b/config.mk @@ -0,0 +1,61 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +############### this is a makefile that you can config it ############### +-include $(LITEOSTOPDIR)/tools/build/mk/los_config.mk + +TOP_LD_PATH = $(LITEOSTOPDIR) +SCRIPTS_PATH = $(LITEOS_SCRIPTPATH) +LITEOS_MK_PATH = $(MK_PATH) +LITEOS_SUBDIRS = $(LIB_SUBDIRS) +LIB_BIGODIR = $(LITEOS_LIB_BIGODIR) + +##### liteos tables -u ldflags ##### +-include $(LITEOS_MK_PATH)/liteos_tables_ldflags.mk + + +LITEOS_COPTS := $(LITEOS_COPTS_DEBUG) $(LITEOS_COPTS_BASE) \ + $(LITEOS_COPTS_EXTRA) $(LITEOS_CORE_COPTS) +LITEOS_CXXOPTS := $(LITEOS_CXXOPTS_BASE) +LITEOS_INCLUDE := $(LITEOS_KERNEL_INCLUDE) $(LITEOS_EXTKERNEL_INCLUDE) \ + $(LITEOS_COMPAT_INCLUDE) $(LITEOS_FS_INCLUDE) \ + $(LITEOS_NET_INCLUDE) $(LITEOS_LIB_INCLUDE) \ + $(LITEOS_DRIVERS_INCLUDE) $(LOSCFG_TOOLS_DEBUG_INCLUDE) \ + $(LITEOS_PLATFORM_INCLUDE) $(LITEOS_DFX_INCLUDE) \ + $(LITEOS_SECURITY_INCLUDE) +LITEOS_LIBDEP := $(LITEOS_BASELIB) +LITEOS_ASFLAGS := $(LITEOS_ASOPTS) $(LITEOS_INCLUDE) +LITEOS_CFLAGS := $(LITEOS_COPTS) $(LITEOS_CMACRO) \ + $(LITEOS_CMACRO_TEST) $(LITEOS_IMAGE_MACRO) \ + $(LITEOS_INCLUDE) +LITEOS_CXXFLAGS := $(LITEOS_CXXOPTS) $(LITEOS_CXXMACRO) \ + $(LITEOS_CMACRO) $(LITEOS_CXXINCLUDE) +LITEOS_LDFLAGS := $(LITEOS_LD_OPTS) $(LITEOS_LD_PATH) \ + $(LITEOS_LD_SCRIPT) + diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig new file mode 100755 index 00000000..f2fb077c --- /dev/null +++ b/fs/fat/Kconfig @@ -0,0 +1,43 @@ +config FS_FAT + bool "Enable FAT" + default y + depends on FS_VFS + help + Answer Y to enable LiteOS support fat filesystem. + +config FS_FAT_CACHE + bool "Enable FAT Cache" + default y + depends on FS_FAT + help + Answer Y to enable LiteOS fat filesystem support cache. + +config FS_FAT_CACHE_SYNC_THREAD + bool "Enable FAT Cache Sync Thread" + default n + depends on FS_FAT_CACHE + help + Answer Y to enable LiteOS fat filesystem support cache sync thread. + +config FS_FAT_CHINESE + bool "Enable Chinese" + default y + depends on FS_FAT + help + Answer Y to enable LiteOS fat filesystem support Chinese. + +config FS_FAT_VIRTUAL_PARTITION + bool "Enabel Virtual Partition" + default n + depends on FS_FAT + +config FS_FAT_VOLUMES + int + depends on FS_FAT + default 32 if PLATFORM_HI3731 + default 16 + +config FS_FAT_DISK + bool "Enable partinfo for storage device" + depends on FS_FAT || DRIVERS_MMC || DRIVERS_USB + default y diff --git a/fs/fat/Makefile b/fs/fat/Makefile new file mode 100755 index 00000000..ad65ab6b --- /dev/null +++ b/fs/fat/Makefile @@ -0,0 +1,44 @@ +# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include $(LITEOSTOPDIR)/config.mk + +MODULE_NAME := $(notdir $(shell pwd)) + +LOCAL_SRCS := $(wildcard os_adapt/*.c) +LOCAL_SRCS += $(wildcard $(LITEOSTHIRDPARTY)/FatFs/source/*.c) + +LOCAL_INCLUDE := \ + -I $(LITEOSTHIRDPARTY)/FatFs/source \ + -I $(LITEOSTOPDIR)/fs/fat/virpart/include + +LOCAL_FLAGS := $(LOCAL_INCLUDE) $(LITEOS_GCOV_OPTS) + +include $(MODULE) + diff --git a/fs/fat/os_adapt/fat_shellcmd.c b/fs/fat/os_adapt/fat_shellcmd.c new file mode 100755 index 00000000..2720a2ea --- /dev/null +++ b/fs/fat/os_adapt/fat_shellcmd.c @@ -0,0 +1,121 @@ +/* + * 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_config.h" + +#if defined(LOSCFG_SHELL) && defined(LOSCFG_FS_FAT) +#include "stdlib.h" +#include "stdio.h" +#include "errno.h" +#include "shcmd.h" +#include "shell.h" +#include "fs/fs.h" +#include "fatfs.h" + +int osShellCmdFormat(int argc, char **argv) +{ + if (argc < 3) { /* 3, at least 3 params for this shell command. */ + perror("format error"); + PRINTK("Usage :\n"); + PRINTK(" format