summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-07-15 14:37:28 (GMT)
committer Hanhui <sylixos@gmail.com>2019-07-15 14:37:28 (GMT)
commit946f661290dede97e5e6008d3c6f42d5a8f20828 (patch)
tree9144922ab7331d435cd44bed508c15f5f6a2916f
parent80679bc07b157813c48c7bb735c4add2ad19ede7 (diff)
parentfeb2f552df2085a6d8b34a63a0f1ca139966ab40 (diff)
downloadAIC-OS-946f661290dede97e5e6008d3c6f42d5a8f20828.zip
Merge branch 'AIC-OS'
-rw-r--r--SylixOS/CHANGELOG3
-rw-r--r--SylixOS/README7
-rw-r--r--SylixOS/arch/arm/arm_support.h3
-rw-r--r--SylixOS/arch/arm/common/armLibAsm.S6
-rw-r--r--SylixOS/arch/arm/common/v7m/armLibV7MAsm.S6
-rw-r--r--SylixOS/arch/arm/dbg/armDbg.c18
-rw-r--r--SylixOS/arch/arm/fpu/armFpu.c3
-rw-r--r--SylixOS/arch/arm/fpu/vfp9/armVfp9Asm.S12
-rw-r--r--SylixOS/arch/arm/fpu/vfpv3/armVfpV3Asm.S11
-rw-r--r--SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S12
-rw-r--r--SylixOS/arch/arm64/arm64_support.h3
-rw-r--r--SylixOS/arch/arm64/common/arm64LibAsm.S9
-rw-r--r--SylixOS/arch/arm64/dbg/arm64Dbg.c18
-rw-r--r--SylixOS/arch/c6x/c6x_support.h1
-rw-r--r--SylixOS/arch/c6x/dbg/c6xDbg.c18
-rw-r--r--SylixOS/arch/csky/backtrace/cskyBacktrace.c26
-rw-r--r--SylixOS/arch/csky/common/ck803/cskyContextCK803.c324
-rw-r--r--SylixOS/arch/csky/common/ck803/cskyContextCK803Asm.S189
-rw-r--r--SylixOS/arch/csky/common/ck803/cskyContextCK803Asm.h68
-rw-r--r--SylixOS/arch/csky/common/ck803/cskyExcCK803.c479
-rw-r--r--SylixOS/arch/csky/common/ck803/cskyExcCK803Asm.S419
-rw-r--r--SylixOS/arch/csky/common/cskyContext.c6
-rw-r--r--SylixOS/arch/csky/common/cskyContextAsm.S4
-rw-r--r--SylixOS/arch/csky/common/cskyExc.c6
-rw-r--r--SylixOS/arch/csky/common/cskyExcAsm.S6
-rw-r--r--SylixOS/arch/csky/common/cskyLibAsm.S14
-rw-r--r--SylixOS/arch/csky/csky_support.h11
-rw-r--r--SylixOS/arch/csky/dbg/cskyDbg.c34
-rw-r--r--SylixOS/arch/csky/fpu/fpu/cskyVfp.c5
-rw-r--r--SylixOS/arch/csky/fpu/fpu/cskyVfpAsm.S103
-rw-r--r--SylixOS/arch/csky/mm/cache/ck803/cskyCacheCK803.c992
-rw-r--r--SylixOS/arch/csky/mm/cache/ck803/cskyCacheCK803.h61
-rw-r--r--SylixOS/arch/csky/mm/cache/cskyCache.c5
-rw-r--r--SylixOS/arch/csky/mm/cache/cskyCacheAsm.S3
-rw-r--r--SylixOS/arch/csky/mm/cskyMpu.c45
-rw-r--r--SylixOS/arch/csky/mm/mmu/cskyMmu.c5
-rw-r--r--SylixOS/arch/csky/mm/mmu/cskyMmuAsm.S3
-rw-r--r--SylixOS/arch/csky/mm/mpu/cskyMpu.c210
-rw-r--r--SylixOS/arch/csky/mm/mpu/cskyMpu.h33
-rw-r--r--SylixOS/arch/mips/common/mipsLibAsm.S6
-rw-r--r--SylixOS/arch/mips/dbg/mipsDbg.c18
-rw-r--r--SylixOS/arch/mips/mips_support.h3
-rw-r--r--SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c2
-rw-r--r--SylixOS/arch/ppc/common/ppcLibAsm.S6
-rw-r--r--SylixOS/arch/ppc/dbg/ppcDbg.c22
-rw-r--r--SylixOS/arch/ppc/ppc_support.h3
-rw-r--r--SylixOS/arch/riscv/common/riscvLibAsm.S6
-rw-r--r--SylixOS/arch/riscv/dbg/riscvDbg.c40
-rw-r--r--SylixOS/arch/riscv/riscv_support.h3
-rw-r--r--SylixOS/arch/sparc/common/sparcLibAsm.S6
-rw-r--r--SylixOS/arch/sparc/dbg/sparcDbg.c18
-rw-r--r--SylixOS/arch/sparc/sparc_support.h3
-rw-r--r--SylixOS/arch/x86/acpi/x86AcpiSylixOS.c1
-rw-r--r--SylixOS/arch/x86/apic/x86IoApic.c23
-rw-r--r--SylixOS/arch/x86/apic/x86LocalApic.c32
-rw-r--r--SylixOS/arch/x86/common/x64/x64LibAsm.S6
-rw-r--r--SylixOS/arch/x86/common/x86CpuId.c140
-rw-r--r--SylixOS/arch/x86/common/x86CpuId.h98
-rw-r--r--SylixOS/arch/x86/common/x86LibAsm.S10
-rw-r--r--SylixOS/arch/x86/dbg/x86Dbg.c34
-rw-r--r--SylixOS/arch/x86/pentium/x86Pentium.c20
-rw-r--r--SylixOS/arch/x86/x86_support.h3
-rw-r--r--SylixOS/config/cpu/cpu_cfg_csky.h11
-rw-r--r--SylixOS/config/cpu/cpu_cfg_x86.h2
-rw-r--r--SylixOS/debug/dtrace/dtrace.c13
-rw-r--r--SylixOS/driver/pci/storage/pciStorageAta.c70
-rw-r--r--SylixOS/driver/pci/storage/pciStorageAta.h2
-rw-r--r--SylixOS/fs/diskCache/diskCache.c6
-rw-r--r--SylixOS/fs/diskPartition/diskPartition.c2
-rw-r--r--SylixOS/fs/iso9660Fs/iso9660_sylixos.c3
-rw-r--r--SylixOS/fs/tpsFs/tpsfs_sylixos.c14
-rw-r--r--SylixOS/include/arch/arch_inc.h1
-rw-r--r--SylixOS/include/arch/csky/arch_def.h2
-rw-r--r--SylixOS/include/arch/csky/arch_float.h21
-rw-r--r--SylixOS/include/arch/csky/arch_mpu.h89
-rw-r--r--SylixOS/include/arch/csky/arch_regs.h14
-rw-r--r--SylixOS/include/arch/csky/asm/archprob.h36
-rw-r--r--SylixOS/include/arch/csky/asm/assembler.h1
-rw-r--r--SylixOS/include/arch/csky/ck803/arch_regs.h92
-rw-r--r--SylixOS/include/arch/csky/inc/cskyregs.h64
-rw-r--r--SylixOS/include/net/if.h28
-rw-r--r--SylixOS/include/net/if_bonding.h4
-rw-r--r--SylixOS/include/net/if_bridge.h2
-rw-r--r--SylixOS/include/netinet/tcp.h41
-rw-r--r--SylixOS/include/network/lwip/sockets.h3
-rw-r--r--SylixOS/include/sys/semfd.h4
-rw-r--r--SylixOS/include/sys/vproc.h3
-rw-r--r--SylixOS/kernel/core/_ThreadSafeLib.c15
-rw-r--r--SylixOS/kernel/include/k_api.h2
-rw-r--r--SylixOS/kernel/include/k_class.h6
-rw-r--r--SylixOS/kernel/include/k_internal.h2
-rw-r--r--SylixOS/kernel/include/k_kernel.h16
-rw-r--r--SylixOS/kernel/interface/InterDefer.c68
-rw-r--r--SylixOS/kernel/interface/SemaphoreMPend.c10
-rw-r--r--SylixOS/kernel/interface/SemaphoreMPost.c8
-rw-r--r--SylixOS/kernel/interface/SemaphoreRWPend.c21
-rw-r--r--SylixOS/kernel/interface/SemaphoreRWPost.c8
-rw-r--r--SylixOS/kernel/interface/ThreadDelete.c2
-rw-r--r--SylixOS/kernel/interface/ThreadDesc.c17
-rw-r--r--SylixOS/kernel/interface/ThreadGetCPUUsage.c12
-rw-r--r--SylixOS/kernel/interface/ThreadSetPriority.c6
-rw-r--r--SylixOS/kernel/show/CPUUsageShow.c17
-rw-r--r--SylixOS/kernel/show/ThreadShow.c45
-rw-r--r--SylixOS/kernel/vmm/vmmMmap.c49
-rw-r--r--SylixOS/kernel/vmm/vmmSwap.h5
-rw-r--r--SylixOS/lib/libc/error/lib_panic.c2
-rw-r--r--SylixOS/lib/libc/stdlib/lib_system.c19
-rw-r--r--SylixOS/loader/include/loader_vppatch.h23
-rw-r--r--SylixOS/loader/src/loader.c14
-rw-r--r--SylixOS/loader/src/loader_malloc.c4
-rw-r--r--SylixOS/loader/src/loader_proc.c69
-rw-r--r--SylixOS/loader/src/loader_shell.c143
-rw-r--r--SylixOS/loader/src/loader_vpdebug.c9
-rw-r--r--SylixOS/loader/src/loader_vppatch.c45
-rw-r--r--SylixOS/loader/src/loader_vpstat.c193
-rw-r--r--SylixOS/loader/src/loader_vpthread.c60
-rw-r--r--SylixOS/loader/src/loader_wait.c8
-rw-r--r--SylixOS/net/lwip/bonding/netbonding.c73
-rw-r--r--SylixOS/net/lwip/bonding/netbonding.h14
-rw-r--r--SylixOS/net/lwip/bridge/netbridge.c56
-rw-r--r--SylixOS/net/lwip/bridge/netbridge.h10
-rw-r--r--SylixOS/net/lwip/lwip_bonding.c38
-rw-r--r--SylixOS/net/lwip/lwip_bridge.c26
-rw-r--r--SylixOS/net/lwip/lwip_ifctl.c72
-rw-r--r--SylixOS/net/lwip/lwip_route.c2
-rw-r--r--SylixOS/net/lwip/lwip_socket.c2
-rw-r--r--SylixOS/net/lwip/route/af_route.c31
-rw-r--r--SylixOS/net/lwip/src/api/api_msg.c4
-rw-r--r--SylixOS/net/lwip/src/api/sockets.c40
-rw-r--r--SylixOS/net/lwip/tools/nat/lwip_natlib.c14
-rw-r--r--SylixOS/net/lwip/tools/npf/lwip_npf.c48
-rw-r--r--SylixOS/posix/aio/aio_lib.c8
-rw-r--r--SylixOS/posix/include/px_mman.h8
-rw-r--r--SylixOS/posix/mman/mman.c4
-rw-r--r--SylixOS/posix/pthread/pthread.c3
-rw-r--r--SylixOS/posix/pthread/pthread_cond.c1
-rw-r--r--SylixOS/posix/pthread/pthread_mutex.c1
-rw-r--r--SylixOS/posix/pthread/pthread_rwlock.c1
-rw-r--r--SylixOS/posix/sched/sched.c98
-rw-r--r--SylixOS/posix/semaphore/semaphore.c1
-rw-r--r--SylixOS/shell/fsLib/ttinyShellFsCmd.c14
-rw-r--r--SylixOS/shell/ttinyShell/ttinyShellLib.c7
-rw-r--r--SylixOS/system/device/can/can.c29
-rw-r--r--SylixOS/system/device/pci/pciLib.c10
-rw-r--r--SylixOS/system/device/pipe/pipeLib.c2
-rw-r--r--SylixOS/system/device/semfd/semfdDev.c10
-rw-r--r--SylixOS/system/device/spipe/spipe.h2
-rw-r--r--SylixOS/system/device/spipe/spipeLib.c51
-rw-r--r--SylixOS/system/include/s_option.h1
-rw-r--r--SylixOS/system/ioLib/ioInterface.c2
-rw-r--r--SylixOS/system/signal/signalLib.c2
-rw-r--r--SylixOS/vpmpdm/dlmalloc/dl_malloc.c23
-rw-r--r--SylixOS/vpmpdm/dlmalloc/dlmalloc.c3
-rw-r--r--SylixOS/vpmpdm/dlmalloc/dlmalloc.h6
-rw-r--r--SylixOS/vpmpdm/vpmpdm.c2
-rw-r--r--libsylixos.mk8
156 files changed, 4899 insertions, 938 deletions
diff --git a/SylixOS/CHANGELOG b/SylixOS/CHANGELOG
index 6673e22..a29e14e 100644
--- a/SylixOS/CHANGELOG
+++ b/SylixOS/CHANGELOG
@@ -4,6 +4,9 @@ HISTORY
++ New features:
+ 2019-07-15: han.hui
+ 加入 mmap 匿名映射的内存预分配机制, 提高 AI 运算效率.
+
2019-03-07: han.hui
加入 ISO9660 光盘文件系统支持.
diff --git a/SylixOS/README b/SylixOS/README
index bcf3cfe..1c10995 100644
--- a/SylixOS/README
+++ b/SylixOS/README
@@ -123,7 +123,12 @@ kernel MUST NOT compiler with VFP instructions!
18:49 2018-01-18
SylixOS 开始支持全功能核心网路由技术, 升级项目代号: Octopus(八爪鱼).
-
+
+----------------------------------------------------------------------------------------------------------------------
+18:49 2019-06-19
+
+ SylixOS 开始面向万物互联时代, 为 EdgerOS 提供完善支撑, 升级项目代号: Tangram(七巧板).
+
----------------------------------------------------------------------------------------------------------------------
23:58 2009-5-12
diff --git a/SylixOS/arch/arm/arm_support.h b/SylixOS/arch/arm/arm_support.h
index 5d39594..3ae0b89 100644
--- a/SylixOS/arch/arm/arm_support.h
+++ b/SylixOS/arch/arm/arm_support.h
@@ -110,6 +110,7 @@ PLW_STACK archCtxStackEnd(const ARCH_REG_CTX *pregctx);
VOID archDbgBpInsert(addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLocal);
VOID archDbgAbInsert(addr_t ulAddr, ULONG *pulIns);
VOID archDbgBpRemove(addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal);
+VOID archDbgApRemove(addr_t ulAddr, ULONG ulIns);
VOID archDbgBpPrefetch(addr_t ulAddr);
UINT archDbgTrapType(addr_t ulAddr, PVOID pvArch);
VOID archDbgBpAdjust(PVOID pvDtrace, PVOID pvtm);
@@ -179,7 +180,7 @@ INTREG archGetCpsr(VOID);
VOID archBogoMipsLoop(ULONG ulLoop);
#define __ARCH_BOGOMIPS_LOOP archBogoMipsLoop
-#define __ARCH_BOGOMIPS_INS_PER_LOOP 2
+#define __ARCH_BOGOMIPS_INS_PER_LOOP 8
/*********************************************************************************************************
ARM CP15 基本功能
diff --git a/SylixOS/arch/arm/common/armLibAsm.S b/SylixOS/arch/arm/common/armLibAsm.S
index 9307366..8c2e70c 100644
--- a/SylixOS/arch/arm/common/armLibAsm.S
+++ b/SylixOS/arch/arm/common/armLibAsm.S
@@ -306,6 +306,12 @@ FUNC_DEF(archReboot)
FUNC_DEF(archBogoMipsLoop)
1:
+ MOV R1 , #1
+ MOV R2 , #2
+ MOV R3 , #3
+ MOV R1 , #1
+ MOV R2 , #2
+ MOV R3 , #3
SUBS R0 , R0 , #1
BNE 1b
BX LR
diff --git a/SylixOS/arch/arm/common/v7m/armLibV7MAsm.S b/SylixOS/arch/arm/common/v7m/armLibV7MAsm.S
index 2474a37..bfe98a7 100644
--- a/SylixOS/arch/arm/common/v7m/armLibV7MAsm.S
+++ b/SylixOS/arch/arm/common/v7m/armLibV7MAsm.S
@@ -253,6 +253,12 @@ FUNC_DEF(archReboot)
FUNC_DEF(archBogoMipsLoop)
1:
+ MOV R1 , #1
+ MOV R2 , #2
+ MOV R3 , #3
+ MOV R1 , #1
+ MOV R2 , #2
+ MOV R3 , #3
SUBS R0 , R0 , #1
BNE 1b
BX LR
diff --git a/SylixOS/arch/arm/dbg/armDbg.c b/SylixOS/arch/arm/dbg/armDbg.c
index 9bf20f9..28a94e8 100644
--- a/SylixOS/arch/arm/dbg/armDbg.c
+++ b/SylixOS/arch/arm/dbg/armDbg.c
@@ -115,6 +115,24 @@ VOID archDbgBpRemove (addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal
#endif /* LW_CFG_CACHE_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: archDbgApRemove
+** 功能描述: 删除一个终止点.
+** 输 入 : ulAddr 终止点地址
+** pulIns 返回的之前的指令
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDbgApRemove (addr_t ulAddr, ULONG ulIns)
+{
+ lib_memcpy((PCHAR)ulAddr, (PCHAR)&ulIns, sizeof(ULONG));
+ KN_SMP_MB();
+
+#if LW_CFG_CACHE_EN > 0
+ API_CacheTextUpdate((PVOID)ulAddr, sizeof(ULONG));
+#endif /* LW_CFG_CACHE_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: archDbgBpPrefetch
** 功能描述: 预取一个指令.
当指令处于 MMU 共享物理段时, 指令空间为物理只读, 这里需要产生一次缺页中断, 克隆一个物理页面.
diff --git a/SylixOS/arch/arm/fpu/armFpu.c b/SylixOS/arch/arm/fpu/armFpu.c
index 16f445d..a495ddb 100644
--- a/SylixOS/arch/arm/fpu/armFpu.c
+++ b/SylixOS/arch/arm/fpu/armFpu.c
@@ -103,8 +103,7 @@ VOID archFpuPrimaryInit (CPCHAR pcMachineName, CPCHAR pcFpuName)
_G_fpuCtxInit.FPUCTX_fpuctxContext.FPUCTX_uiFpsid = (UINT32)ARM_VFP_HW_SID(_G_pfpuop);
ARM_VFP_SAVE(_G_pfpuop, (PVOID)&_G_fpuCtxInit);
-
- _G_fpuCtxInit.FPUCTX_fpuctxContext.FPUCTX_uiFpexc = 0x00000000; /* disable VFP */
+
_G_fpuCtxInit.FPUCTX_fpuctxContext.FPUCTX_uiFpscr = 0x01000000; /* Set FZ bit in VFP */
/* Do not enable FPU */
ARM_VFP_DISABLE(_G_pfpuop);
diff --git a/SylixOS/arch/arm/fpu/vfp9/armVfp9Asm.S b/SylixOS/arch/arm/fpu/vfp9/armVfp9Asm.S
index 2a589e7..b15b131 100644
--- a/SylixOS/arch/arm/fpu/vfp9/armVfp9Asm.S
+++ b/SylixOS/arch/arm/fpu/vfp9/armVfp9Asm.S
@@ -50,7 +50,7 @@ FUNC_DEF(armVfp9Sid)
FUNC_END()
FUNC_DEF(armVfp9Enable)
- MOV R1, #0x40000000 ;/* Set Neon/VFP Enable bit */
+ MOV R1, #(1 << 30) ;/* Set Neon/VFP Enable bit */
FMXR FPEXC, R1 ;/* FPEXC, clear others. */
BX LR
FUNC_END()
@@ -100,12 +100,15 @@ FUNC_DEF(armVfp9IsEnable)
;*********************************************************************************************************/
MACRO_DEF(VFP9_SAVE_CTRL)
- FMRX R1, FPSCR
- STR R1, [R0, #VFP_FPSCR]
-
FMRX R1, FPEXC
+ ORR R1, R1, #(1 << 30)
+ FMXR FPEXC, R1
+
STR R1, [R0, #VFP_FPEXC]
+ FMRX R2, FPSCR
+ STR R2, [R0, #VFP_FPSCR]
+
FMRX R2, FPINST
STR R2, [R0, #VFP_FPINST]
@@ -125,6 +128,7 @@ MACRO_DEF(VFP9_SAVE_CTRL)
MACRO_DEF(VFP9_RESTORE_CTRL)
LDR R1, [R0, #VFP_FPEXC]
+ ORR R1, R1, #(1 << 30)
FMXR FPEXC, R1
LDR R2, [R0, #VFP_FPINST]
diff --git a/SylixOS/arch/arm/fpu/vfpv3/armVfpV3Asm.S b/SylixOS/arch/arm/fpu/vfpv3/armVfpV3Asm.S
index 6386973..d220583 100644
--- a/SylixOS/arch/arm/fpu/vfpv3/armVfpV3Asm.S
+++ b/SylixOS/arch/arm/fpu/vfpv3/armVfpV3Asm.S
@@ -71,12 +71,15 @@
;*********************************************************************************************************/
MACRO_DEF(VFPv3_SAVE_CTRL)
- FMRX R1, FPSCR
- STR R1, [R0, #VFP_FPSCR] ;/* 保存 FPSCR */
-
FMRX R1, FPEXC
+ ORR R1, R1, #(1 << 30)
+ FMXR FPEXC, R1
+
STR R1, [R0, #VFP_FPEXC] ;/* 保存 FPEXC */
+ FMRX R2, FPSCR
+ STR R2, [R0, #VFP_FPSCR] ;/* 保存 FPSCR */
+
ORR R1, R1, #((1 << 28) | (1 << 31))
FMXR FPEXC, R1 ;/* Set FPEXC.EX=1 and FPEXC.FP2V=1 */
@@ -102,7 +105,7 @@ MACRO_DEF(VFPv3_SAVE_CTRL)
MACRO_DEF(VFPv3_RESTORE_CTRL)
FMRX R1, FPEXC
- ORR R1, R1, #((1 << 28) | (1 << 31))
+ ORR R1, R1, #((1 << 28) | (1 << 30) | (1 << 31))
FMXR FPEXC, R1 ;/* Set FPEXC.EX=1 and FPEXC.FP2V=1 */
FMRX R1, FPEXC ;/* Read back the FPEXC register */
diff --git a/SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S b/SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S
index d169c49..19f60c3 100644
--- a/SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S
+++ b/SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S
@@ -189,9 +189,17 @@ FUNC_DEF(armDCacheInvalidate)
;/*********************************************************************************************************
; 将指定虚拟地址的 DCACHE 回写 R0=void *start; R1=void *end; R2=cache line size
+; MMU 初始化写页表映射关系时也会调用此函数, 此时 CACHE 并未使能, ARM1176 会卡死, 所以这里加入使能判断.
;*********************************************************************************************************/
FUNC_DEF(armDCacheFlush)
+#if __SYLIXOS_ARM_ARCH__ == 6
+ MRC p15, 0, R3, c1, c0, 0
+ AND R3, R3, #P15_R1_C
+ CMP R3, #0
+ BEQ dcache_not_en
+#endif
+
ARM_DSB()
ARM_ISB()
1:
@@ -201,6 +209,10 @@ FUNC_DEF(armDCacheFlush)
BCC 1b
ARM_DSB()
ARM_ISB()
+
+#if __SYLIXOS_ARM_ARCH__ == 6
+LINE_LABEL(dcache_not_en)
+#endif
BX LR
FUNC_END()
diff --git a/SylixOS/arch/arm64/arm64_support.h b/SylixOS/arch/arm64/arm64_support.h
index 518cc66..7ab89dc 100644
--- a/SylixOS/arch/arm64/arm64_support.h
+++ b/SylixOS/arch/arm64/arm64_support.h
@@ -100,6 +100,7 @@ PLW_STACK archCtxStackEnd(const ARCH_REG_CTX *pregctx);
VOID archDbgBpInsert(addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLocal);
VOID archDbgAbInsert(addr_t ulAddr, ULONG *pulIns);
VOID archDbgBpRemove(addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal);
+VOID archDbgApRemove(addr_t ulAddr, ULONG ulIns);
VOID archDbgBpPrefetch(addr_t ulAddr);
UINT archDbgTrapType(addr_t ulAddr, PVOID pvArch);
VOID archDbgBpAdjust(PVOID pvDtrace, PVOID pvtm);
@@ -151,7 +152,7 @@ VOID arm64WaitForInterrupt(VOID);
VOID archBogoMipsLoop(ULONG ulLoop);
#define __ARCH_BOGOMIPS_LOOP archBogoMipsLoop
-#define __ARCH_BOGOMIPS_INS_PER_LOOP 2
+#define __ARCH_BOGOMIPS_INS_PER_LOOP 8
/*********************************************************************************************************
ARM64 处理器 CACHE 操作
diff --git a/SylixOS/arch/arm64/common/arm64LibAsm.S b/SylixOS/arch/arm64/common/arm64LibAsm.S
index a7ef998..1aa3bfb 100644
--- a/SylixOS/arch/arm64/common/arm64LibAsm.S
+++ b/SylixOS/arch/arm64/common/arm64LibAsm.S
@@ -323,8 +323,15 @@ FUNC_DEF(archReboot)
;*********************************************************************************************************/
FUNC_DEF(archBogoMipsLoop)
+1:
+ MOV X1 , #1
+ MOV X2 , #2
+ MOV X3 , #3
+ MOV X1 , #1
+ MOV X2 , #2
+ MOV X3 , #3
SUBS X0 , X0 , #1
- BNE archBogoMipsLoop
+ BNE 1b
RET
FUNC_END()
diff --git a/SylixOS/arch/arm64/dbg/arm64Dbg.c b/SylixOS/arch/arm64/dbg/arm64Dbg.c
index 7b7a6c6..19df355 100644
--- a/SylixOS/arch/arm64/dbg/arm64Dbg.c
+++ b/SylixOS/arch/arm64/dbg/arm64Dbg.c
@@ -107,6 +107,24 @@ VOID archDbgBpRemove (addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal
#endif /* LW_CFG_CACHE_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: archDbgApRemove
+** 功能描述: 删除一个终止点.
+** 输 入 : ulAddr 终止点地址
+** pulIns 返回的之前的指令
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDbgApRemove (addr_t ulAddr, ULONG ulIns)
+{
+ lib_memcpy((PCHAR)ulAddr, (PCHAR)&ulIns, sizeof(ARM64_INSTRUCTION));
+ KN_SMP_MB();
+
+#if LW_CFG_CACHE_EN > 0
+ API_CacheTextUpdate((PVOID)ulAddr, sizeof(ARM64_INSTRUCTION));
+#endif /* LW_CFG_CACHE_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: archDbgBpPrefetch
** 功能描述: 预取一个指令.
当指令处于 MMU 共享物理段时, 指令空间为物理只读, 这里需要产生一次缺页中断, 克隆一个物理页面.
diff --git a/SylixOS/arch/c6x/c6x_support.h b/SylixOS/arch/c6x/c6x_support.h
index 935bca3..5e2ade3 100644
--- a/SylixOS/arch/c6x/c6x_support.h
+++ b/SylixOS/arch/c6x/c6x_support.h
@@ -98,6 +98,7 @@ PLW_STACK archCtxStackEnd(const ARCH_REG_CTX *pregctx);
VOID archDbgBpInsert(addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLocal);
VOID archDbgAbInsert(addr_t ulAddr, ULONG *pulIns);
VOID archDbgBpRemove(addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal);
+VOID archDbgApRemove(addr_t ulAddr, ULONG ulIns);
VOID archDbgBpPrefetch(addr_t ulAddr);
UINT archDbgTrapType(addr_t ulAddr, PVOID pvArch);
VOID archDbgBpAdjust(PVOID pvDtrace, PVOID pvtm);
diff --git a/SylixOS/arch/c6x/dbg/c6xDbg.c b/SylixOS/arch/c6x/dbg/c6xDbg.c
index 3e02e3c..9481c91 100644
--- a/SylixOS/arch/c6x/dbg/c6xDbg.c
+++ b/SylixOS/arch/c6x/dbg/c6xDbg.c
@@ -111,6 +111,24 @@ VOID archDbgBpRemove (addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLoca
#endif /* LW_CFG_CACHE_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: archDbgApRemove
+** 功能描述: 删除一个终止点.
+** 输 入 : ulAddr 终止点地址
+** pulIns 返回的之前的指令
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDbgApRemove (addr_t ulAddr, ULONG ulIns)
+{
+ lib_memcpy((PCHAR)ulAddr, (PCHAR)&ulIns, sizeof(ULONG));
+ KN_SMP_MB();
+
+#if LW_CFG_CACHE_EN > 0
+ API_CacheTextUpdate((PVOID)ulAddr, sizeof(ULONG));
+#endif /* LW_CFG_CACHE_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: archDbgBpPrefetch
** 功能描述: 预取一个指令.
当指令处于 MMU 共享物理段时, 指令空间为物理只读, 这里需要产生一次缺页中断, 克隆一个物理页面.
diff --git a/SylixOS/arch/csky/backtrace/cskyBacktrace.c b/SylixOS/arch/csky/backtrace/cskyBacktrace.c
index 9f862b7..c0b7e4c 100644
--- a/SylixOS/arch/csky/backtrace/cskyBacktrace.c
+++ b/SylixOS/arch/csky/backtrace/cskyBacktrace.c
@@ -63,19 +63,19 @@ static int csky_get_insn (unsigned long addr, unsigned int *insn)
return (2);
}
}
- /********************************************************************************************************
- ** 函数名称: csky_analyze_prologue
- ** 功能描述: 分析堆栈
- ** 输 入 : start_pc 起始地址
- ** limit_pc 结束地址
- ** r15_offset r15 偏移
- ** r8_offset r8 偏移
- ** subi_len sp 移动大小
- ** subi2_len sp 第二次移动大小
- ** 输 出 : NONE
- ** 全局变量:
- ** 调用模块:
- ********************************************************************************************************/
+/*********************************************************************************************************
+** 函数名称: csky_analyze_prologue
+** 功能描述: 分析堆栈
+** 输 入 : start_pc 起始地址
+** limit_pc 结束地址
+** r15_offset r15 偏移
+** r8_offset r8 偏移
+** subi_len sp 移动大小
+** subi2_len sp 第二次移动大小
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
static void csky_analyze_prologue (unsigned long start_pc, unsigned long limit_pc,
unsigned long *r15_offset, unsigned long *r8_offset,
unsigned long *subi_len, unsigned long *subi2_len)
diff --git a/SylixOS/arch/csky/common/ck803/cskyContextCK803.c b/SylixOS/arch/csky/common/ck803/cskyContextCK803.c
new file mode 100644
index 0000000..e030e46
--- /dev/null
+++ b/SylixOS/arch/csky/common/ck803/cskyContextCK803.c
@@ -0,0 +1,324 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: cskyContextCK803.c
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2018 年 11 月 12 日
+**
+** 描 述: C-SKY CK803 体系架构上下文处理.
+*********************************************************************************************************/
+#define __SYLIXOS_STDIO
+#define __SYLIXOS_KERNEL
+#include "SylixOS.h"
+/*********************************************************************************************************
+ C-SKY 体系架构
+*********************************************************************************************************/
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+/*********************************************************************************************************
+** 函数名称: archTaskCtxCreate
+** 功能描述: 创建任务上下文
+** 输 入 : pregctx 寄存器上下文
+** pfuncTask 任务入口
+** pvArg 入口参数
+** ptcb 任务控制块
+** pstkTop 初始化堆栈起点
+** ulOpt 任务创建选项
+** 输 出 : 初始化堆栈结束点
+** 全局变量:
+** 调用模块:
+** 注 意 : 堆栈从高地址向低地址增长.
+*********************************************************************************************************/
+PLW_STACK archTaskCtxCreate (ARCH_REG_CTX *pregctx,
+ PTHREAD_START_ROUTINE pfuncTask,
+ PVOID pvArg,
+ PLW_CLASS_TCB ptcb,
+ PLW_STACK pstkTop,
+ ULONG ulOpt)
+{
+ ARCH_FP_CTX *pfpctx;
+ ARCH_REG_T ulPsr;
+ INT i;
+
+ pstkTop = (PLW_STACK)ROUND_DOWN(pstkTop, ARCH_STK_ALIGN_SIZE); /* 保证出栈后 SP 8 字节对齐 */
+
+ pfpctx = (ARCH_FP_CTX *)((PCHAR)pstkTop - sizeof(ARCH_FP_CTX));
+
+ /*
+ * 初始化寄存器上下文
+ */
+ for (i = 0; i < ARCH_GREG_NR; i++) {
+ pregctx->REG_ulReg[i] = i;
+ }
+
+ ulPsr = archGetPSR(); /* 获得当前的 PSR 寄存器 */
+ ulPsr |= bspIntInitEnableStatus() | M_PSR_IE | M_PSR_EE; /* 使能中断和异常 */
+
+ pregctx->REG_ulReg[REG_A0] = (ARCH_REG_T)pvArg;
+ pregctx->REG_ulReg[REG_RA] = (ARCH_REG_T)0x0;
+ pregctx->REG_ulReg[REG_SP] = (ARCH_REG_T)pfpctx;
+
+ pregctx->REG_ulPsr = (ARCH_REG_T)ulPsr;
+ pregctx->REG_ulPc = (ARCH_REG_T)pfuncTask;
+
+ return ((PLW_STACK)pfpctx);
+}
+/*********************************************************************************************************
+** 函数名称: archTaskCtxSetFp
+** 功能描述: 设置任务上下文栈帧 (用于 backtrace 回溯, 详情请见 backtrace 相关文件)
+** 输 入 : pstkDest 目的 stack frame
+** pregctxDest 目的寄存器上下文
+** pregctxSrc 源寄存器上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archTaskCtxSetFp (PLW_STACK pstkDest,
+ ARCH_REG_CTX *pregctxDest,
+ const ARCH_REG_CTX *pregctxSrc)
+{
+ pregctxDest->REG_ulReg[REG_FP] = (ARCH_REG_T)pregctxSrc->REG_ulReg[REG_SP];
+ pregctxDest->REG_ulReg[REG_RA] = (ARCH_REG_T)pregctxSrc->REG_ulPc;
+}
+/*********************************************************************************************************
+** 函数名称: archTaskRegsGet
+** 功能描述: 获取寄存器上下文
+** 输 入 : pregctx 寄存器上下文
+** pregSp SP 指针
+** 输 出 : 寄存器上下文
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+ARCH_REG_CTX *archTaskRegsGet (ARCH_REG_CTX *pregctx, ARCH_REG_T *pregSp)
+{
+ *pregSp = pregctx->REG_ulReg[REG_SP];
+
+ return (pregctx);
+}
+/*********************************************************************************************************
+** 函数名称: archTaskRegsSet
+** 功能描述: 设置寄存器上下文
+** 输 入 : pregctxDest 目的寄存器上下文
+** pregctxSrc 源寄存器上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archTaskRegsSet (ARCH_REG_CTX *pregctxDest, const ARCH_REG_CTX *pregctxSrc)
+{
+ pregctxDest->REG_ulReg[0] = pregctxSrc->REG_ulReg[0]; /* SP 不设置, 保持原值 */
+ pregctxDest->REG_ulReg[1] = pregctxSrc->REG_ulReg[1];
+ pregctxDest->REG_ulReg[2] = pregctxSrc->REG_ulReg[2];
+ pregctxDest->REG_ulReg[3] = pregctxSrc->REG_ulReg[3];
+ pregctxDest->REG_ulReg[4] = pregctxSrc->REG_ulReg[4];
+ pregctxDest->REG_ulReg[5] = pregctxSrc->REG_ulReg[5];
+ pregctxDest->REG_ulReg[6] = pregctxSrc->REG_ulReg[6];
+ pregctxDest->REG_ulReg[7] = pregctxSrc->REG_ulReg[7];
+ pregctxDest->REG_ulReg[8] = pregctxSrc->REG_ulReg[8];
+ pregctxDest->REG_ulReg[9] = pregctxSrc->REG_ulReg[9];
+ pregctxDest->REG_ulReg[10] = pregctxSrc->REG_ulReg[10];
+ pregctxDest->REG_ulReg[11] = pregctxSrc->REG_ulReg[11];
+ pregctxDest->REG_ulReg[12] = pregctxSrc->REG_ulReg[12];
+ pregctxDest->REG_ulReg[13] = pregctxSrc->REG_ulReg[13];
+ pregctxDest->REG_ulReg[14] = pregctxSrc->REG_ulReg[14];
+ pregctxDest->REG_ulReg[15] = pregctxSrc->REG_ulReg[15];
+ pregctxDest->REG_ulReg[16] = pregctxSrc->REG_ulReg[16]; /* R28 通用目的寄存器 */
+
+ pregctxDest->REG_ulPsr = pregctxSrc->REG_ulPsr; /* SPR 寄存器 */
+ pregctxDest->REG_ulPc = pregctxSrc->REG_ulPc; /* 程序计数器寄存器 */
+}
+/*********************************************************************************************************
+** 函数名称: archTaskCtxShow
+** 功能描述: 打印任务上下文
+** 输 入 : iFd 文件描述符
+ pregctx 寄存器上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+#if LW_CFG_DEVICE_EN > 0
+
+VOID archTaskCtxShow (INT iFd, const ARCH_REG_CTX *pregctx)
+{
+ ARCH_REG_T ulPsr = pregctx->REG_ulPsr;
+
+ if (iFd >= 0) {
+#define LX_FMT "0x%08x"
+
+ fdprintf(iFd, "\n");
+
+ fdprintf(iFd, "PC = "LX_FMT"\n", pregctx->REG_ulPc);
+
+ fdprintf(iFd, "R0(A0) = "LX_FMT"\n", pregctx->REG_ulReg[0]);
+ fdprintf(iFd, "R1(A1) = "LX_FMT"\n", pregctx->REG_ulReg[1]);
+ fdprintf(iFd, "R2(A2) = "LX_FMT"\n", pregctx->REG_ulReg[2]);
+ fdprintf(iFd, "R3(A3) = "LX_FMT"\n", pregctx->REG_ulReg[3]);
+ fdprintf(iFd, "R4 = "LX_FMT"\n", pregctx->REG_ulReg[4]);
+ fdprintf(iFd, "R5 = "LX_FMT"\n", pregctx->REG_ulReg[5]);
+ fdprintf(iFd, "R6 = "LX_FMT"\n", pregctx->REG_ulReg[6]);
+ fdprintf(iFd, "R7 = "LX_FMT"\n", pregctx->REG_ulReg[7]);
+ fdprintf(iFd, "R8 = "LX_FMT"\n", pregctx->REG_ulReg[8]);
+ fdprintf(iFd, "R9 = "LX_FMT"\n", pregctx->REG_ulReg[9]);
+ fdprintf(iFd, "R10 = "LX_FMT"\n", pregctx->REG_ulReg[10]);
+ fdprintf(iFd, "R11 = "LX_FMT"\n", pregctx->REG_ulReg[11]);
+ fdprintf(iFd, "R12 = "LX_FMT"\n", pregctx->REG_ulReg[12]);
+ fdprintf(iFd, "R13 = "LX_FMT"\n", pregctx->REG_ulReg[13]);
+ fdprintf(iFd, "R14(SP) = "LX_FMT"\n", pregctx->REG_ulReg[14]);
+ fdprintf(iFd, "R15 = "LX_FMT"\n", pregctx->REG_ulReg[15]);
+ fdprintf(iFd, "R28 = "LX_FMT"\n", pregctx->REG_ulReg[16]);
+
+ fdprintf(iFd, "PSR Status Register:\n");
+ fdprintf(iFd, "S = %d ", (ulPsr & M_PSR_S) >> S_PSR_S);
+ fdprintf(iFd, "MM = %d ", (ulPsr & M_PSR_MM) >> S_PSR_MM);
+ fdprintf(iFd, "EE = %d\n", (ulPsr & M_PSR_EE) >> S_PSR_EE);
+ fdprintf(iFd, "IC = %d ", (ulPsr & M_PSR_IC) >> S_PSR_IC);
+ fdprintf(iFd, "IE = %d\n", (ulPsr & M_PSR_IE) >> S_PSR_IE);
+ fdprintf(iFd, "C = %d\n", (ulPsr & M_PSR_C) >> S_PSR_C);
+
+#undef LX_FMT
+ } else {
+ archTaskCtxPrint(LW_NULL, 0, pregctx);
+ }
+}
+
+#endif /* LW_CFG_DEVICE_EN > 0 */
+/*********************************************************************************************************
+** 函数名称: archTaskCtxPrint
+** 功能描述: 直接打印任务上下文
+** 输 入 : pvBuffer 内存缓冲区 (NULL, 表示直接打印)
+** stSize 缓冲大小
+** pregctx 寄存器上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archTaskCtxPrint (PVOID pvBuffer, size_t stSize, const ARCH_REG_CTX *pregctx)
+{
+ ARCH_REG_T ulPsr = pregctx->REG_ulPsr;
+
+ if (pvBuffer && stSize) {
+#define LX_FMT "0x%08x"
+
+ size_t stOft = 0;
+
+ stOft = bnprintf(pvBuffer, stSize, stOft, "PC = "LX_FMT"\n", pregctx->REG_ulPc);
+
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R0(A0) = "LX_FMT"\n", pregctx->REG_ulReg[0]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R1(A1) = "LX_FMT"\n", pregctx->REG_ulReg[1]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R2(A2) = "LX_FMT"\n", pregctx->REG_ulReg[2]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R3(A3) = "LX_FMT"\n", pregctx->REG_ulReg[3]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R4 = "LX_FMT"\n", pregctx->REG_ulReg[4]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R5 = "LX_FMT"\n", pregctx->REG_ulReg[5]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R6 = "LX_FMT"\n", pregctx->REG_ulReg[6]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R7 = "LX_FMT"\n", pregctx->REG_ulReg[7]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R8 = "LX_FMT"\n", pregctx->REG_ulReg[8]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R9 = "LX_FMT"\n", pregctx->REG_ulReg[9]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R10 = "LX_FMT"\n", pregctx->REG_ulReg[10]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R11 = "LX_FMT"\n", pregctx->REG_ulReg[11]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R12 = "LX_FMT"\n", pregctx->REG_ulReg[12]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R13 = "LX_FMT"\n", pregctx->REG_ulReg[13]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R14(SP) = "LX_FMT"\n", pregctx->REG_ulReg[14]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R15 = "LX_FMT"\n", pregctx->REG_ulReg[15]);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "R28 = "LX_FMT"\n", pregctx->REG_ulReg[16]);
+
+ stOft = bnprintf(pvBuffer, stSize, stOft, "PSR Status Register:\n");
+ stOft = bnprintf(pvBuffer, stSize, stOft, "S = %d ", (ulPsr & M_PSR_S) >> S_PSR_S);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "MM = %d ", (ulPsr & M_PSR_MM) >> S_PSR_MM);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "EE = %d\n", (ulPsr & M_PSR_EE) >> S_PSR_EE);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "IC = %d ", (ulPsr & M_PSR_IC) >> S_PSR_IC);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "IE = %d\n", (ulPsr & M_PSR_IE) >> S_PSR_IE);
+ stOft = bnprintf(pvBuffer, stSize, stOft, "C = %d\n", (ulPsr & M_PSR_C) >> S_PSR_C);
+
+#undef LX_FMT
+ } else {
+#define LX_FMT "0x%08x"
+
+ _PrintFormat("\r\n");
+
+ _PrintFormat("PC = "LX_FMT"\r\n", pregctx->REG_ulPc);
+
+ _PrintFormat("R0(A0) = "LX_FMT"\r\n", pregctx->REG_ulReg[0]);
+ _PrintFormat("R1(A1) = "LX_FMT"\r\n", pregctx->REG_ulReg[1]);
+ _PrintFormat("R2(A2) = "LX_FMT"\r\n", pregctx->REG_ulReg[2]);
+ _PrintFormat("R3(A3) = "LX_FMT"\r\n", pregctx->REG_ulReg[3]);
+ _PrintFormat("R4 = "LX_FMT"\r\n", pregctx->REG_ulReg[4]);
+ _PrintFormat("R5 = "LX_FMT"\r\n", pregctx->REG_ulReg[5]);
+ _PrintFormat("R6 = "LX_FMT"\r\n", pregctx->REG_ulReg[6]);
+ _PrintFormat("R7 = "LX_FMT"\r\n", pregctx->REG_ulReg[7]);
+ _PrintFormat("R8 = "LX_FMT"\r\n", pregctx->REG_ulReg[8]);
+ _PrintFormat("R9 = "LX_FMT"\r\n", pregctx->REG_ulReg[9]);
+ _PrintFormat("R10 = "LX_FMT"\r\n", pregctx->REG_ulReg[10]);
+ _PrintFormat("R11 = "LX_FMT"\r\n", pregctx->REG_ulReg[11]);
+ _PrintFormat("R12 = "LX_FMT"\r\n", pregctx->REG_ulReg[12]);
+ _PrintFormat("R13 = "LX_FMT"\r\n", pregctx->REG_ulReg[13]);
+ _PrintFormat("R14(SP) = "LX_FMT"\r\n", pregctx->REG_ulReg[14]);
+ _PrintFormat("R15 = "LX_FMT"\r\n", pregctx->REG_ulReg[15]);
+ _PrintFormat("R28 = "LX_FMT"\r\n", pregctx->REG_ulReg[16]);
+
+ _PrintFormat("PSR Status Register:\r\n");
+ _PrintFormat("S = %d ", (ulPsr & M_PSR_S) >> S_PSR_S);
+ _PrintFormat("MM = %d ", (ulPsr & M_PSR_MM) >> S_PSR_MM);
+ _PrintFormat("EE = %d\r\n", (ulPsr & M_PSR_EE) >> S_PSR_EE);
+ _PrintFormat("IC = %d ", (ulPsr & M_PSR_IC) >> S_PSR_IC);
+ _PrintFormat("IE = %d\r\n", (ulPsr & M_PSR_IE) >> S_PSR_IE);
+ _PrintFormat("C = %d\r\n", (ulPsr & M_PSR_C) >> S_PSR_C);
+
+#undef LX_FMT
+ }
+}
+/*********************************************************************************************************
+** 函数名称: archIntCtxSaveReg
+** 功能描述: 中断保存寄存器
+** 输 入 : pcpu CPU 结构
+** reg0 寄存器 0
+** reg1 寄存器 1
+** reg2 寄存器 2
+** reg3 寄存器 3
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archIntCtxSaveReg (PLW_CLASS_CPU pcpu,
+ ARCH_REG_T reg0,
+ ARCH_REG_T reg1,
+ ARCH_REG_T reg2,
+ ARCH_REG_T reg3)
+{
+ ARCH_REG_CTX *pregctx;
+
+ if (pcpu->CPU_ulInterNesting == 1) {
+ pregctx = &pcpu->CPU_ptcbTCBCur->TCB_archRegCtx;
+
+ } else {
+ pregctx = (ARCH_REG_CTX *)(((ARCH_REG_CTX *)reg0)->REG_ulReg[REG_SP] - ARCH_REG_CTX_SIZE);
+ }
+
+ archTaskCtxCopy(pregctx, (ARCH_REG_CTX *)reg0);
+}
+/*********************************************************************************************************
+** 函数名称: archCtxStackEnd
+** 功能描述: 根据寄存器上下文获得栈结束地址
+** 输 入 : pregctx 寄存器上下文
+** 输 出 : 栈结束地址
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+PLW_STACK archCtxStackEnd (const ARCH_REG_CTX *pregctx)
+{
+ return ((PLW_STACK)pregctx->REG_ulReg[REG_SP]);
+}
+
+#endif /* __SYLIXOS_CSKY_ARCH_CK803__ */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/ck803/cskyContextCK803Asm.S b/SylixOS/arch/csky/common/ck803/cskyContextCK803Asm.S
new file mode 100644
index 0000000..1af3f59
--- /dev/null
+++ b/SylixOS/arch/csky/common/ck803/cskyContextCK803Asm.S
@@ -0,0 +1,189 @@
+;/*********************************************************************************************************
+;**
+;** 中国软件开源组织
+;**
+;** 嵌入式实时操作系统
+;**
+;** SylixOS(TM)
+;**
+;** Copyright All Rights Reserved
+;**
+;**--------------文件信息--------------------------------------------------------------------------------
+;**
+;** 文 件 名: cskyContextCK803Asm.S
+;**
+;** 创 建 人: Wang.Xuan (王翾)
+;**
+;** 文件创建日期: 2019 年 04 月 26 日
+;**
+;** 描 述: C-SKY CK803 体系架构上下文切换.
+;*********************************************************************************************************/
+
+#ifndef ASSEMBLY
+#define ASSEMBLY 1
+#endif
+
+#include <arch/assembler.h>
+#include <config/kernel/kernel_cfg.h>
+#include <config/mp/mp_cfg.h>
+
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
+#include "cskyContextCK803Asm.h"
+
+ FILE_BEGIN()
+
+ IMPORT_LABEL(_SchedSwp)
+#if LW_CFG_SMP_EN > 0
+ IMPORT_LABEL(_SchedSafeStack)
+#endif
+#if LW_CFG_COROUTINE_EN > 0
+ IMPORT_LABEL(_SchedCrSwp)
+#endif
+
+ EXPORT_LABEL(archTaskCtxStart)
+ EXPORT_LABEL(archTaskCtxSwitch)
+ EXPORT_LABEL(archTaskCtxCopy)
+#if LW_CFG_COROUTINE_EN > 0
+ EXPORT_LABEL(archCrtCtxSwitch)
+#endif
+ EXPORT_LABEL(archIntCtxLoad)
+ EXPORT_LABEL(archSigCtxLoad)
+ EXPORT_LABEL(archExcOldStack)
+ EXPORT_LABEL(archExcIrqStack)
+
+;/*********************************************************************************************************
+; 异常栈
+;*********************************************************************************************************/
+
+ .balign ARCH_STK_ALIGN_SIZE
+LINE_LABEL(archExcOldStack)
+ .long archExcOldStack
+
+LINE_LABEL(archExcIrqStack)
+ .long archExcIrqStack
+
+;/*********************************************************************************************************
+; 当前 CPU 开始运行多任务执行
+; 参数为当前 CPU 控制块, 即 A0 为当前 CPU 控制块指针
+;*********************************************************************************************************/
+
+FUNC_DEF(archTaskCtxStart)
+ SUBI SP , 1024 ;/* 在启动栈开辟异常临时栈 */
+ ANDNI SP , SP , 0x7 ;/* SP 向下 8 字节对齐 */
+ LRW A1 , archExcIrqStack
+ ST.W SP , (A1)
+
+ LD.W A1 , (A0 , 0) ;/* 获取当前 TCB 的 REG_CTX 地址*/
+
+ RESTORE_REGS ;/* 恢复寄存器 */
+ FUNC_END(archTaskCtxStart)
+
+;/*********************************************************************************************************
+; 线程切换
+; 参数为当前 CPU 控制块, 即 A0 为当前 CPU 控制块指针
+;*********************************************************************************************************/
+
+FUNC_DEF(archTaskCtxSwitch)
+ LD.W A1 , (A0 , 0) ;/* 获取当前 TCB 的 REG_CTX 地址*/
+
+ SAVE_REGS ;/* 保存任务寄存器 */
+
+ MOV S0 , A0 ;/* S0 暂存 A0 */
+
+#if LW_CFG_SMP_EN > 0
+ JSRI _SchedSafeStack ;/* _SchedSafeStack(); */
+ MOV SP , A0
+ MOV A0 , S0 ;/* 恢复 A0 */
+#endif
+
+ JSRI _SchedSwp ;/* _SchedSwp(); */
+
+ LD.W A1 , (S0 , 0) ;/* 获取当前 TCB 的 REG_CTX 地址*/
+
+ RESTORE_REGS ;/* 恢复任务寄存器 */
+ FUNC_END(archTaskCtxSwitch)
+
+;/*********************************************************************************************************
+; 协程切换
+; 参数为当前 CPU 控制块, 即 A0 为当前 CPU 控制块指针
+;*********************************************************************************************************/
+
+#if LW_CFG_COROUTINE_EN > 0
+FUNC_DEF(archCrtCtxSwitch)
+ LD.W A1 , (A0 , (2 * PTRSIZE)) ;/* 当前 CCB 的 REG_CTX 地址 */
+
+ SAVE_REGS ;/* 保存协程寄存器 */
+
+ MOV S0 , A0 ;/* S0 暂存 A0 */
+
+ JSRI _SchedCrSwp ;/* _SchedCrSwp(); */
+
+ LD.W A1 , (S0 , (2 * PTRSIZE)) ;/* 当前 CCB 的 REG_CTX 地址 */
+
+ RESTORE_REGS ;/* 恢复协程寄存器 */
+ FUNC_END(archCrtCtxSwitch)
+#endif
+
+;/*********************************************************************************************************
+; 中断返回时, 线程装载
+; 参数为当前 CPU 控制块, 即 A0 为当前 CPU 控制块指针
+;*********************************************************************************************************/
+
+FUNC_DEF(archIntCtxLoad)
+ LD.W A1 , (A0 , 0) ;/* 获取当前 TCB 的 REG_CTX 地址*/
+
+ RESTORE_REGS ;/* 恢复任务寄存器 */
+ FUNC_END(archIntCtxLoad)
+
+;/*********************************************************************************************************
+; 信号上下文返回
+; 参数为 ARCH_REG_CTX 指针, 即 A0 为 ARCH_REG_CTX 指针
+;*********************************************************************************************************/
+
+FUNC_DEF(archSigCtxLoad)
+ MOV A1 , A0
+
+ RESTORE_REGS ;/* 恢复任务寄存器 */
+ FUNC_END(archSigCtxLoad)
+
+;/*********************************************************************************************************
+; 拷贝任务上下文
+; 参数 A0 为目的 ARCH_REG_CTX 指针, A1 为源 ARCH_REG_CTX 指针
+;*********************************************************************************************************/
+
+FUNC_DEF(archTaskCtxCopy)
+ PUSH R4-R8
+
+ LDM R4-R8 , (A1)
+ STM R4-R8 , (A0)
+ ADDI A0 , (5 * ARCH_REG_SIZE)
+ ADDI A1 , (5 * ARCH_REG_SIZE)
+
+ LDM R4-R8 , (A1)
+ STM R4-R8 , (A0)
+ ADDI A0 , (5 * ARCH_REG_SIZE)
+ ADDI A1 , (5 * ARCH_REG_SIZE)
+
+ LDM R4-R8 , (A1)
+ STM R4-R8 , (A0)
+ ADDI A0 , (5 * ARCH_REG_SIZE)
+ ADDI A1 , (5 * ARCH_REG_SIZE)
+
+ LDM R4-R8 , (A1)
+ STM R4-R8 , (A0)
+ ADDI A0 , (5 * ARCH_REG_SIZE)
+ ADDI A1 , (5 * ARCH_REG_SIZE)
+
+ LDM R4-R8 , (SP)
+ ADDI SP , (5 * ARCH_REG_SIZE)
+
+ RTS
+ FUNC_END(archTaskCtxCopy)
+
+ FILE_END()
+
+#endif
+;/*********************************************************************************************************
+; END
+;*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/ck803/cskyContextCK803Asm.h b/SylixOS/arch/csky/common/ck803/cskyContextCK803Asm.h
new file mode 100644
index 0000000..b637bf3
--- /dev/null
+++ b/SylixOS/arch/csky/common/ck803/cskyContextCK803Asm.h
@@ -0,0 +1,68 @@
+;/*********************************************************************************************************
+;**
+;** 中国软件开源组织
+;**
+;** 嵌入式实时操作系统
+;**
+;** SylixOS(TM)
+;**
+;** Copyright All Rights Reserved
+;**
+;**--------------文件信息--------------------------------------------------------------------------------
+;**
+;** 文 件 名: cskyContextCK803Asm.h
+;**
+;** 创 建 人: Wang.Xuan (王翾)
+;**
+;** 文件创建日期: 2018 年 11 月 12 日
+;**
+;** 描 述: C-SKY CK803 体系架构上下文处理.
+;*********************************************************************************************************/
+
+#ifndef __ARCH_CSKYCONTEXTCK803ASM_H
+#define __ARCH_CSKYCONTEXTCK803ASM_H
+
+#include "arch/csky/arch_regs.h"
+
+;/*********************************************************************************************************
+; 保存寄存器(参数 A1: ARCH_REG_CTX 地址)
+;*********************************************************************************************************/
+
+MACRO_DEF(SAVE_REGS)
+ STM R0-R15 , (A1)
+
+ ST.W R28, (A1 , XGREG28)
+
+ ST.W RA , (A1 , XPC) ;/* RA 代替 PC 保存 */
+
+ MFCR A2 , PSR
+ ST.W A2 , (A1 , XPSR) ;/* 保存 PSR 寄存器 */
+ MACRO_END()
+
+;/*********************************************************************************************************
+; 恢复寄存器(参数 A1: ARCH_REG_CTX 地址)
+;*********************************************************************************************************/
+
+MACRO_DEF(RESTORE_REGS)
+ LD.W A0 , (A1 , XPSR) ;/* 恢复 PSR 寄存器 */
+ MTCR A0 , EPSR
+
+ LD.W A0 , (A1 , XPC) ;/* 恢复 PC 寄存器 */
+ MTCR A0 , EPC
+
+ LD.W R28, (A1 , XGREG28)
+
+ LD.W R0 , (A1 , XGREG(0))
+
+ ADDI A1 , (2 * ARCH_REG_SIZE)
+ LDM R2-R15 , (A1)
+ SUBI A1 , (2 * ARCH_REG_SIZE)
+ LD.W A1 , (A1 , XGREG(1))
+
+ RTE
+ MACRO_END()
+
+#endif
+;/*********************************************************************************************************
+; END
+;*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/ck803/cskyExcCK803.c b/SylixOS/arch/csky/common/ck803/cskyExcCK803.c
new file mode 100644
index 0000000..3cd1616
--- /dev/null
+++ b/SylixOS/arch/csky/common/ck803/cskyExcCK803.c
@@ -0,0 +1,479 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: cskyExcCK803.c
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2018 年 11 月 12 日
+**
+** 描 述: C-SKY CK803 体系架构异常处理.
+*********************************************************************************************************/
+#define __SYLIXOS_STDIO
+#define __SYLIXOS_KERNEL
+#include "SylixOS.h"
+#include "dtrace.h"
+#include "arch/csky/common/unaligned/cskyUnaligned.h"
+#if LW_CFG_CPU_FPU_EN > 0
+#include "arch/csky/fpu/fpu/cskyVfp.h"
+#endif
+#include "arch/csky/param/cskyParam.h"
+#include "arch/csky/inc/cskyregs.h"
+/*********************************************************************************************************
+ C-SKY 体系架构
+*********************************************************************************************************/
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+/*********************************************************************************************************
+ 向量使能与禁能锁
+*********************************************************************************************************/
+#if LW_CFG_SMP_EN > 0
+#define VECTOR_OP_LOCK() LW_SPIN_LOCK_IGNIRQ(&_K_slcaVectorTable.SLCA_sl)
+#define VECTOR_OP_UNLOCK() LW_SPIN_UNLOCK_IGNIRQ(&_K_slcaVectorTable.SLCA_sl)
+#else
+#define VECTOR_OP_LOCK()
+#define VECTOR_OP_UNLOCK()
+#endif
+/*********************************************************************************************************
+** 函数名称: archIntHandle
+** 功能描述: bspIntHandle 需要调用此函数处理中断 (关闭中断情况被调用)
+** 输 入 : ulVector 中断向量
+** bPreemptive 中断是否可抢占
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+** 注 意 : 此函数退出时必须为中断关闭状态.
+*********************************************************************************************************/
+LW_WEAK VOID archIntHandle (ULONG ulVector, BOOL bPreemptive)
+{
+ REGISTER irqreturn_t irqret;
+
+ if (_Inter_Vector_Invalid(ulVector)) {
+ return; /* 向量号不正确 */
+ }
+
+ if (LW_IVEC_GET_FLAG(ulVector) & LW_IRQ_FLAG_PREEMPTIVE) {
+ bPreemptive = LW_TRUE;
+ }
+
+ if (bPreemptive) {
+ VECTOR_OP_LOCK();
+ __ARCH_INT_VECTOR_DISABLE(ulVector); /* 屏蔽 vector 中断 */
+ VECTOR_OP_UNLOCK();
+ KN_INT_ENABLE_FORCE(); /* 允许中断 */
+ }
+
+ irqret = API_InterVectorIsr(ulVector); /* 调用中断服务程序 */
+
+ KN_INT_DISABLE(); /* 禁能中断 */
+
+ if (bPreemptive) {
+ if (irqret != LW_IRQ_HANDLED_DISV) {
+ VECTOR_OP_LOCK();
+ __ARCH_INT_VECTOR_ENABLE(ulVector); /* 允许 vector 中断 */
+ VECTOR_OP_UNLOCK();
+ }
+
+ } else if (irqret == LW_IRQ_HANDLED_DISV) {
+ VECTOR_OP_LOCK();
+ __ARCH_INT_VECTOR_DISABLE(ulVector); /* 屏蔽 vector 中断 */
+ VECTOR_OP_UNLOCK();
+ }
+}
+/*********************************************************************************************************
+** 函数名称: archAutoIntHandle
+** 功能描述: 普通中断
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archAutoIntHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ bspIntHandle(ulVector);
+}
+/*********************************************************************************************************
+** 函数名称: archTrapExceptHandle
+** 功能描述: 跟踪异常
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archTrapExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiMethod = LW_VMM_ABORT_METHOD_EXEC;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_SYS;
+
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
+** 函数名称: archTrap0ExceptHandle
+** 功能描述: 陷阱指令异常 0
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archTrap0ExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ archTrapExceptHandle(ulVector, pregctx);
+}
+/*********************************************************************************************************
+** 函数名称: archTrap1ExceptHandle
+** 功能描述: 陷阱指令异常 1
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archTrap1ExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ archTrapExceptHandle(ulVector, pregctx);
+}
+/*********************************************************************************************************
+** 函数名称: archTrap2ExceptHandle
+** 功能描述: 陷阱指令异常 2
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archTrap2ExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ archTrapExceptHandle(ulVector, pregctx);
+}
+/*********************************************************************************************************
+** 函数名称: archTrap3ExceptHandle
+** 功能描述: 陷阱指令异常 3
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archTrap3ExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ archTrapExceptHandle(ulVector, pregctx);
+}
+/*********************************************************************************************************
+** 函数名称: archReservedExceptHandle
+** 功能描述: Reserved 中断
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archReservedExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ LW_VMM_ABORT abtInfo;
+ PLW_CLASS_TCB ptcbCur;
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiMethod = 0;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_FATAL_ERROR;
+
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
+** 函数名称: archTspendIntHandle
+** 功能描述: TSPEND 中断
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archTspendIntHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ bspIntHandle(ulVector);
+}
+/*********************************************************************************************************
+** 函数名称: archFpuExceptHandle
+** 功能描述: 浮点异常
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archFpuExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+#if LW_CFG_CPU_FPU_EN > 0
+ UINT32 uiFESR;
+#endif /* LW_CFG_CPU_FPU_EN > 0 */
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_FPE; /* 终止类型默认为浮点异常 */
+
+#if LW_CFG_CPU_FPU_EN > 0
+ uiFESR = cskyVfpGetFESR();
+ if (uiFESR & FESR_ILLE) { /* 非法指令 */
+ abtInfo.VMABT_uiMethod = ILL_ILLOPC;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_UNDEF;
+
+ } else if (uiFESR & FESR_IDC) { /* 非规格数输入 */
+ abtInfo.VMABT_uiMethod = ILL_ILLOPN;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_UNDEF;
+
+ } else if (uiFESR & FESR_FEC) {
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_FPE;
+
+ if (uiFESR & FESR_IOC) {
+ abtInfo.VMABT_uiMethod = FPE_FLTINV; /* 非法操作异常 */
+
+ } else if (uiFESR & FESR_DZC) {
+ abtInfo.VMABT_uiMethod = FPE_FLTDIV; /* 除零异常 */
+
+ } else if (uiFESR & FESR_UFC) {
+ abtInfo.VMABT_uiMethod = FPE_FLTUND; /* 下溢异常 */
+
+ } else if (uiFESR & FESR_OFC) {
+ abtInfo.VMABT_uiMethod = FPE_FLTOVF; /* 上溢异常 */
+
+ } else if (uiFESR & FESR_IXC) {
+ abtInfo.VMABT_uiMethod = FPE_FLTRES; /* 不精确异常 */
+
+ } else {
+ abtInfo.VMABT_uiMethod = 0;
+ }
+
+ } else {
+ abtInfo.VMABT_uiMethod = 0;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_FATAL_ERROR;
+ }
+#endif /* LW_CFG_CPU_FPU_EN > 0 */
+
+ if (abtInfo.VMABT_uiType) {
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+ }
+}
+/*********************************************************************************************************
+** 函数名称: archIdlyExceptHandle
+** 功能描述: Idly 异常
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archIdlyExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiMethod = 0;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_FATAL_ERROR;
+
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
+** 函数名称: archFatalErrExceptHandle
+** 功能描述: 不可恢复错误异常
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archFatalErrExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiMethod = 0;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_FATAL_ERROR;
+
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
+** 函数名称: archBreakPointExceptHandle
+** 功能描述: 断点异常
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archBreakPointExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+#if LW_CFG_GDB_EN > 0
+ UINT uiBpType;
+#endif /* LW_CFG_GDB_EN > 0 */
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+#if LW_CFG_GDB_EN > 0
+ uiBpType = archDbgTrapType(pregctx->REG_ulPc, LW_NULL); /* 断点指令探测 */
+ if (uiBpType) {
+ if (API_DtraceBreakTrap(pregctx->REG_ulPc, uiBpType) == ERROR_NONE) {
+ return; /* 进入调试接口断点处理 */
+ }
+ }
+#endif /* LW_CFG_GDB_EN > 0 */
+
+ abtInfo.VMABT_uiMethod = LW_VMM_ABORT_METHOD_EXEC;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_BREAK;
+
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
+** 函数名称: archPrivilegeExceptHandle
+** 功能描述: 特权违反异常
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archPrivilegeExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiMethod = LW_VMM_ABORT_METHOD_EXEC;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_PERM;
+
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
+** 函数名称: archIllegalInstExceptHandle
+** 功能描述: 非法指令异常
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archIllegalInstExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiMethod = LW_VMM_ABORT_METHOD_EXEC;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_UNDEF;
+
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
+** 函数名称: archDivideZeroExceptHandle
+** 功能描述: 除以零异常
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDivideZeroExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiMethod = LW_VMM_ABORT_METHOD_EXEC;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_TERMINAL;
+
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
+** 函数名称: archAccessExceptHandle
+** 功能描述: 访问错误异常
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archAccessExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiMethod = 0;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_BUS;
+
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
+** 函数名称: archUnalignedHandle
+** 功能描述: 非对齐内存访问异常处理
+** 输 入 : pabtctx abort 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID archUnalignedHandle (PLW_VMM_ABORT_CTX pabtctx)
+{
+ cskyUnalignedHandle(&pabtctx->ABTCTX_archRegCtx,
+ &pabtctx->ABTCTX_abtInfo);
+
+ API_VmmAbortReturn(pabtctx);
+}
+/*********************************************************************************************************
+** 函数名称: archUnalignedExceptHandle
+** 功能描述: 未对齐访问异常处理
+** 输 入 : ulVector 中断向量
+** pregctx 上下文
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archUnalignedExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+ CSKY_PARAM *param = archKernelParamGet();
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_BUS;
+ abtInfo.VMABT_uiMethod = BUS_ADRALN;
+
+ if (param->CP_bUnalign) {
+ API_VmmAbortIsrEx(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur, archUnalignedHandle);
+
+ } else {
+ API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
+ }
+}
+
+#endif /* __SYLIXOS_CSKY_ARCH_CK803__ */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/ck803/cskyExcCK803Asm.S b/SylixOS/arch/csky/common/ck803/cskyExcCK803Asm.S
new file mode 100644
index 0000000..d19a4b4
--- /dev/null
+++ b/SylixOS/arch/csky/common/ck803/cskyExcCK803Asm.S
@@ -0,0 +1,419 @@
+;/*********************************************************************************************************
+;**
+;** 中国软件开源组织
+;**
+;** 嵌入式实时操作系统
+;**
+;** SylixOS(TM)
+;**
+;** Copyright All Rights Reserved
+;**
+;**--------------文件信息--------------------------------------------------------------------------------
+;**
+;** 文 件 名: cskyExcCK803Asm.S
+;**
+;** 创 建 人: Wang.Xuan (王翾)
+;**
+;** 文件创建日期: 2018 年 11 月 12 日
+;**
+;** 描 述: C-SKY CK803 体系架构异常处理.
+;*********************************************************************************************************/
+
+#ifndef ASSEMBLY
+#define ASSEMBLY 1
+#endif
+
+#include <arch/assembler.h>
+#include <config/kernel/kernel_cfg.h>
+#include <config/mp/mp_cfg.h>
+
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
+#include "cskyContextCK803Asm.h"
+
+ FILE_BEGIN()
+
+ IMPORT_LABEL(API_ThreadTcbInter)
+ IMPORT_LABEL(API_InterStackBaseGet)
+ IMPORT_LABEL(API_InterEnter)
+ IMPORT_LABEL(API_InterExit)
+ IMPORT_LABEL(bspIntHandle)
+
+ IMPORT_LABEL(archResetHandle)
+ IMPORT_LABEL(archUnalignedExceptHandle)
+ IMPORT_LABEL(archAccessExceptHandle)
+ IMPORT_LABEL(archDivideZeroExceptHandle)
+ IMPORT_LABEL(archIllegalInstExceptHandle)
+ IMPORT_LABEL(archPrivilegeExceptHandle)
+ IMPORT_LABEL(archTrapExceptHandle)
+ IMPORT_LABEL(archBreakPointExceptHandle)
+ IMPORT_LABEL(archFatalErrExceptHandle)
+ IMPORT_LABEL(archIdlyExceptHandle)
+ IMPORT_LABEL(archAutoIntHandle)
+ IMPORT_LABEL(archReservedExceptHandle)
+ IMPORT_LABEL(archTrap0ExceptHandle)
+ IMPORT_LABEL(archTrap1ExceptHandle)
+ IMPORT_LABEL(archTrap2ExceptHandle)
+ IMPORT_LABEL(archTrap3ExceptHandle)
+ IMPORT_LABEL(archTspendIntHandle)
+ IMPORT_LABEL(archFpuExceptHandle)
+ IMPORT_LABEL(archExcOldStack)
+ IMPORT_LABEL(archExcIrqStack)
+
+ EXPORT_LABEL(archUnalignedExceptEntry)
+ EXPORT_LABEL(archAccessExceptEntry)
+ EXPORT_LABEL(archDivideZeroExceptEntry)
+ EXPORT_LABEL(archIllegalInstExceptEntry)
+ EXPORT_LABEL(archPrivilegeExceptEntry)
+ EXPORT_LABEL(archTrapExceptEntry)
+ EXPORT_LABEL(archBreakPointExceptEntry)
+ EXPORT_LABEL(archFatalErrExceptEntry)
+ EXPORT_LABEL(archIdlyExceptEntry)
+ EXPORT_LABEL(archAutoIntEntry)
+ EXPORT_LABEL(archReservedExceptEntry)
+ EXPORT_LABEL(archTrap0ExceptEntry)
+ EXPORT_LABEL(archTrap1ExceptEntry)
+ EXPORT_LABEL(archTrap2ExceptEntry)
+ EXPORT_LABEL(archTrap3ExceptEntry)
+ EXPORT_LABEL(archTspendIntEntry)
+ EXPORT_LABEL(archFpuExceptEntry)
+
+ EXPORT_LABEL(vector)
+
+;/*********************************************************************************************************
+; 这里的异常向量表 vector 声明为弱符号, BSP 可以重新实现异常向量表
+;*********************************************************************************************************/
+
+ WEAK(vector)
+
+;/*********************************************************************************************************
+; 异常/中断入口宏
+;*********************************************************************************************************/
+
+ SECTION(.text)
+
+MACRO_DEF(IRQ_ENTRY irq handle)
+ ;/*
+ ; * 使用异常临时栈, 并在异常临时栈开辟临时上下文保存区, 将寄存器保存到临时上下文保存区
+ ; */
+ PUSH R4 , R5 ;/* 先将 R4, R5 入栈 */
+ LRW R4 , archExcOldStack ;/* 获取存储异常前 SP 的位置 */
+ ADDI R5 , SP , 2 * ARCH_REG_SIZE ;/* 获取异常前 SP 指针 */
+ ST.W R5 , (R4) ;/* 将异常前 SP 存入对应位置 */
+ LD.W R4 , (SP) ;/* 不能使用 POP 指令 */
+ LD.W R5 , (SP, ARCH_REG_SIZE) ;/* POP 指令会同时改变 PC */
+
+ LRW SP , archExcIrqStack ;/* 获取异常临时栈 SP 的位置 */
+ LD.W SP , (SP) ;/* 得到异常栈指针 */
+ SUBI SP , ARCH_REG_CTX_SIZE ;/* 在临时堆栈开辟上下文保存区 */
+
+ STM R0-R15 , (SP)
+ ST.W R28 , (SP , XGREG28)
+
+ MFCR R0 , EPC ;/* EPC 代替 PC 保存 */
+ STW R0 , (SP , XPC)
+
+ MFCR R0 , EPSR ;/* 保存 PSR 寄存器 */
+ ST.W R0 , (SP , XPSR)
+
+ LRW R0 , archExcOldStack ;/* 读出异常前 SP */
+ LD.W R0 , (R0)
+ ST.W R0 , (SP , XGREG(14)) ;/* 保存异常前 SP */
+
+ ;/*
+ ; * API_InterEnter(寄存器上下文)
+ ; */
+ MOV A0 , SP
+ JSRI API_InterEnter
+
+ CMPNEI A0 , 1
+ BT 3f
+
+ ;/*
+ ; * 第一次进入中断: 获得当前 CPU 中断堆栈栈顶, 并设置 SP
+ ; */
+ JSRI API_InterStackBaseGet
+ MOV SP , A0
+
+ ;/*
+ ; * 获得当前任务 TCB 的 ARCH_REG_CTX 地址
+ ; */
+ JSRI API_ThreadTcbInter
+ MOV A1 , A0
+
+2:
+ PSRSET EE
+
+ ;/*
+ ; * handle(vector, 寄存器上下文)
+ ; */
+ MOVI A0 , \irq
+
+ JSRI \handle
+
+ ;/*
+ ; * API_InterExit()
+ ; * 如果没有发生中断嵌套, 则 API_InterExit 会调用 archIntCtxLoad 函数
+ ; */
+ JSRI API_InterExit
+
+ ;/*
+ ; * 来到这里, 说明发生了中断嵌套
+ ; */
+ MOV A1 , SP
+ RESTORE_REGS
+
+3:
+ ;/*
+ ; * 不是第一次进入中断
+ ; */
+ LRW SP , archExcOldStack
+ LD.W SP , (SP) ;/* 获取异常前 SP 的位置 */
+ SUBI SP , ARCH_REG_CTX_SIZE
+ MOV A1 , SP
+ BR 2b
+ MACRO_END()
+
+;/*********************************************************************************************************
+; 未对齐访问异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archUnalignedExceptEntry)
+ IRQ_ENTRY 1 archUnalignedExceptHandle
+ FUNC_END(archUnalignedExceptEntry)
+
+;/*********************************************************************************************************
+; 访问错误异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archAccessExceptEntry)
+ IRQ_ENTRY 2 archAccessExceptHandle
+ FUNC_END(archAccessExceptEntry)
+
+;/*********************************************************************************************************
+; 除零异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archDivideZeroExceptEntry)
+ IRQ_ENTRY 3 archDivideZeroExceptHandle
+ FUNC_END(archDivideZeroExceptEntry)
+
+;/*********************************************************************************************************
+; 非法指令异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archIllegalInstExceptEntry)
+ IRQ_ENTRY 4 archIllegalInstExceptHandle
+ FUNC_END(archIllegalInstExceptEntry)
+
+;/*********************************************************************************************************
+; 特权违反异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archPrivilegeExceptEntry)
+ IRQ_ENTRY 5 archPrivilegeExceptHandle
+ FUNC_END(archPrivilegeExceptEntry)
+
+;/*********************************************************************************************************
+; 跟踪异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archTrapExceptEntry)
+ IRQ_ENTRY 6 archTrapExceptHandle
+ FUNC_END(archTrapExceptEntry)
+
+;/*********************************************************************************************************
+; 断点异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archBreakPointExceptEntry)
+ IRQ_ENTRY 7 archBreakPointExceptHandle
+ FUNC_END(archBreakPointExceptEntry)
+
+;/*********************************************************************************************************
+; 不可恢复错误异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archFatalErrExceptEntry)
+ IRQ_ENTRY 8 archFatalErrExceptHandle
+ FUNC_END(archFatalErrExceptEntry)
+
+;/*********************************************************************************************************
+; Idly 异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archIdlyExceptEntry)
+ IRQ_ENTRY 9 archIdlyExceptHandle
+ FUNC_END(archIdlyExceptEntry)
+
+;/*********************************************************************************************************
+; 普通中断入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archAutoIntEntry)
+ IRQ_ENTRY 10 archAutoIntHandle
+ FUNC_END(archAutoIntEntry)
+
+;/*********************************************************************************************************
+; Reserved 异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archReservedExceptEntry)
+ IRQ_ENTRY 12 archReservedExceptHandle
+ FUNC_END(archReservedExceptEntry)
+
+;/*********************************************************************************************************
+; 陷阱指令异常 0 入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archTrap0ExceptEntry)
+ IRQ_ENTRY 16 archTrap0ExceptHandle
+ FUNC_END(archTrap0ExceptEntry)
+
+;/*********************************************************************************************************
+; 陷阱指令异常 1 入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archTrap1ExceptEntry)
+ IRQ_ENTRY 17 archTrap1ExceptHandle
+ FUNC_END(archTrap1ExceptEntry)
+
+;/*********************************************************************************************************
+; 陷阱指令异常 2 入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archTrap2ExceptEntry)
+ IRQ_ENTRY 18 archTrap2ExceptHandle
+ FUNC_END(archTrap2ExceptEntry)
+
+;/*********************************************************************************************************
+; 陷阱指令异常 3 入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archTrap3ExceptEntry)
+ IRQ_ENTRY 19 archTrap3ExceptHandle
+ FUNC_END(archTrap3ExceptEntry)
+
+;/*********************************************************************************************************
+; TSPEND 中断入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archTspendIntEntry)
+ IRQ_ENTRY 22 archTspendIntHandle
+ FUNC_END(archTspendIntEntry)
+
+;/*********************************************************************************************************
+; 浮点运算异常入口函数
+;*********************************************************************************************************/
+
+FUNC_DEF(archFpuExceptEntry)
+ IRQ_ENTRY 30 archFpuExceptHandle
+ FUNC_END(archFpuExceptEntry)
+
+;/*********************************************************************************************************
+; 32 ~ 255 号中断入口函数
+;*********************************************************************************************************/
+
+ .irp Id, \
+ 32, 33, 34, 35, 36, 37, 38, 39, \
+ 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, \
+ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, \
+ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, \
+ 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, \
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, \
+ 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, \
+ 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, \
+ 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, \
+ 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, \
+ 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, \
+ 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, \
+ 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, \
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, \
+ 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, \
+ 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, \
+ 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, \
+ 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, \
+ 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, \
+ 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, \
+ 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, \
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, \
+ 250, 251, 252, 253, 254, 255
+ EXPORT_LABEL(archIntEntry\Id)
+FUNC_DEF(archIntEntry\Id)
+ IRQ_ENTRY \Id bspIntHandle
+ FUNC_END(archIntEntry\Id)
+ .endr
+
+;/*********************************************************************************************************
+; 异常向量表
+;*********************************************************************************************************/
+
+ .align 10
+FUNC_DEF(vector)
+ .long archResetEntry ;/* 0 - Reset */
+ .long archUnalignedExceptEntry ;/* 1 - Unaligned */
+ .long archAccessExceptEntry ;/* 2 - Access */
+ .long archDivideZeroExceptEntry ;/* 3 - Divide By Zero */
+ .long archIllegalInstExceptEntry ;/* 4 - Illegal Instruction */
+ .long archPrivilegeExceptEntry ;/* 5 - Privilege */
+ .long archTrapExceptEntry ;/* 6 - Trap */
+ .long archBreakPointExceptEntry ;/* 7 - BreakPoint */
+ .long archFatalErrExceptEntry ;/* 8 - Fatal Err */
+ .long archIdlyExceptEntry ;/* 9 - Idly */
+ .long archAutoIntEntry ;/* 10 - Auto */
+ .long archReservedExceptEntry ;/* 11 - Reserved */
+ .long archReservedExceptEntry ;/* 12 - Reserved */
+ .long archReservedExceptEntry ;/* 13 - Reserved */
+ .long archReservedExceptEntry ;/* 14 - Reserved */
+ .long archReservedExceptEntry ;/* 15 - Reserved */
+ .long archTrap0ExceptEntry ;/* 16 - Trap0 */
+ .long archTrap1ExceptEntry ;/* 17 - Trap1 */
+ .long archTrap2ExceptEntry ;/* 18 - Trap2 */
+ .long archTrap3ExceptEntry ;/* 19 - Trap3 */
+ .long archReservedExceptEntry ;/* 20 - Reserved */
+ .long archReservedExceptEntry ;/* 21 - Reserved */
+ .long archTspendIntEntry ;/* 22 - TSPEND */
+ .long archReservedExceptEntry ;/* 23 - Reserved */
+ .long archReservedExceptEntry ;/* 24 - Reserved */
+ .long archReservedExceptEntry ;/* 25 - Reserved */
+ .long archReservedExceptEntry ;/* 26 - Reserved */
+ .long archReservedExceptEntry ;/* 27 - Reserved */
+ .long archReservedExceptEntry ;/* 28 - Reserved */
+ .long archReservedExceptEntry ;/* 29 - Reserved */
+ .long archFpuExceptEntry ;/* 30 - FPU */
+ .long archReservedExceptEntry ;/* 31 - Reserved */
+
+ .irp Id, \
+ 32, 33, 34, 35, 36, 37, 38, 39, \
+ 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, \
+ 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, \
+ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, \
+ 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, \
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, \
+ 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, \
+ 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, \
+ 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, \
+ 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, \
+ 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, \
+ 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, \
+ 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, \
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, \
+ 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, \
+ 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, \
+ 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, \
+ 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, \
+ 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, \
+ 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, \
+ 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, \
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, \
+ 250, 251, 252, 253, 254, 255
+ .long archIntEntry\Id
+ .endr
+ FUNC_END(vector)
+
+ FILE_END()
+
+#endif
+;/*********************************************************************************************************
+; END
+;*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/cskyContext.c b/SylixOS/arch/csky/common/cskyContext.c
index 03d446a..efff6bf 100644
--- a/SylixOS/arch/csky/common/cskyContext.c
+++ b/SylixOS/arch/csky/common/cskyContext.c
@@ -22,6 +22,10 @@
#define __SYLIXOS_KERNEL
#include "SylixOS.h"
/*********************************************************************************************************
+ C-SKY 体系架构
+*********************************************************************************************************/
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
+/*********************************************************************************************************
** 函数名称: archTaskCtxCreate
** 功能描述: 创建任务上下文
** 输 入 : pregctx 寄存器上下文
@@ -459,6 +463,8 @@ PLW_STACK archCtxStackEnd (const ARCH_REG_CTX *pregctx)
{
return ((PLW_STACK)pregctx->REG_ulReg[REG_SP]);
}
+
+#endif /* !__SYLIXOS_CSKY_ARCH_CK803__*/
/*********************************************************************************************************
END
*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/cskyContextAsm.S b/SylixOS/arch/csky/common/cskyContextAsm.S
index 147b1d2..eb32923 100644
--- a/SylixOS/arch/csky/common/cskyContextAsm.S
+++ b/SylixOS/arch/csky/common/cskyContextAsm.S
@@ -26,6 +26,9 @@
#include <arch/assembler.h>
#include <config/kernel/kernel_cfg.h>
#include <config/mp/mp_cfg.h>
+
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
#include "cskyContextAsm.h"
FILE_BEGIN()
@@ -163,6 +166,7 @@ FUNC_DEF(archTaskCtxCopy)
FILE_END()
+#endif
;/*********************************************************************************************************
; END
;*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/cskyExc.c b/SylixOS/arch/csky/common/cskyExc.c
index a655eaa..9471bc2 100644
--- a/SylixOS/arch/csky/common/cskyExc.c
+++ b/SylixOS/arch/csky/common/cskyExc.c
@@ -28,6 +28,10 @@
#endif
#include "arch/csky/param/cskyParam.h"
/*********************************************************************************************************
+ C-SKY 体系架构
+*********************************************************************************************************/
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
+/*********************************************************************************************************
向量使能与禁能锁
*********************************************************************************************************/
#if LW_CFG_SMP_EN > 0
@@ -531,6 +535,8 @@ VOID archUnalignedExceptHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
API_VmmAbortIsr(pregctx->REG_ulPc, pregctx->REG_ulPc, &abtInfo, ptcbCur);
}
}
+
+#endif /* !__SYLIXOS_CSKY_ARCH_CK803__*/
/*********************************************************************************************************
END
*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/cskyExcAsm.S b/SylixOS/arch/csky/common/cskyExcAsm.S
index 773aafa..beb1bb7 100644
--- a/SylixOS/arch/csky/common/cskyExcAsm.S
+++ b/SylixOS/arch/csky/common/cskyExcAsm.S
@@ -26,6 +26,9 @@
#include <arch/assembler.h>
#include <config/kernel/kernel_cfg.h>
#include <config/mp/mp_cfg.h>
+
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
#include "cskyContextAsm.h"
FILE_BEGIN()
@@ -107,7 +110,7 @@ MACRO_DEF(IRQ_ENTRY irq handle)
MTCR SP , SS1 ;/* SS1 暂存异常前 SP */
MFCR SP , SS0 ;/* SP = 异常临时栈 */
- SUBI SP , ARCH_REG_CTX_SIZE ;/* 在临时堆栈开辟上下文保存区 */
+ SUBI SP , ARCH_REG_CTX_SIZE ;/* 在临时堆栈开辟上下文保存区 */
STM R0-R31 , (SP)
@@ -464,6 +467,7 @@ FUNC_DEF(vector)
FILE_END()
+#endif
;/*********************************************************************************************************
; END
;*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/cskyLibAsm.S b/SylixOS/arch/csky/common/cskyLibAsm.S
index e9073cc..8f673a2 100644
--- a/SylixOS/arch/csky/common/cskyLibAsm.S
+++ b/SylixOS/arch/csky/common/cskyLibAsm.S
@@ -147,6 +147,7 @@ MACRO_DEF(SAVE_NON_VOLATILE_REG)
ST.W R11 , (A0 , XGREG(11))
ST.W R14 , (A0 , XGREG(14))
ST.W R15 , (A0 , XGREG(15))
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
ST.W R16 , (A0 , XGREG(16))
ST.W R17 , (A0 , XGREG(17))
ST.W R26 , (A0 , XGREG(26))
@@ -155,6 +156,9 @@ MACRO_DEF(SAVE_NON_VOLATILE_REG)
ST.W R29 , (A0 , XGREG(29))
ST.W R30 , (A0 , XGREG(30))
ST.W R31 , (A0 , XGREG(31))
+#else
+ ST.W R28 , (A0 , XGREG28)
+#endif
MACRO_END()
;/*********************************************************************************************************
@@ -173,6 +177,7 @@ MACRO_DEF(RESTORE_NON_VOLATILE_REG)
LD.W R11 , (A0 , XGREG(11))
LD.W R14 , (A0 , XGREG(14))
LD.W R15 , (A0 , XGREG(15))
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
LD.W R16 , (A0 , XGREG(16))
LD.W R17 , (A0 , XGREG(17))
LD.W R26 , (A0 , XGREG(26))
@@ -181,6 +186,9 @@ MACRO_DEF(RESTORE_NON_VOLATILE_REG)
LD.W R29 , (A0 , XGREG(29))
LD.W R30 , (A0 , XGREG(30))
LD.W R31 , (A0 , XGREG(31))
+#else
+ LD.W R28 , (A0 , XGREG28)
+#endif
MACRO_END()
;/*********************************************************************************************************
@@ -256,6 +264,12 @@ FUNC_DEF(archReboot)
;*********************************************************************************************************/
FUNC_DEF(archBogoMipsLoop)
+ MOVI A1 , 1
+ MOVI A2 , 2
+ MOVI A3 , 3
+ MOVI A1 , 1
+ MOVI A2 , 2
+ MOVI A3 , 3
SUBI A0 , 1
BNEZ A0 , archBogoMipsLoop
RTS
diff --git a/SylixOS/arch/csky/csky_support.h b/SylixOS/arch/csky/csky_support.h
index 9d45c33..ff92f1a 100644
--- a/SylixOS/arch/csky/csky_support.h
+++ b/SylixOS/arch/csky/csky_support.h
@@ -100,6 +100,7 @@ PLW_STACK archCtxStackEnd(const ARCH_REG_CTX *pregctx);
VOID archDbgBpInsert(addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLocal);
VOID archDbgAbInsert(addr_t ulAddr, ULONG *pulIns);
VOID archDbgBpRemove(addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal);
+VOID archDbgApRemove(addr_t ulAddr, ULONG ulIns);
VOID archDbgBpPrefetch(addr_t ulAddr);
UINT archDbgTrapType(addr_t ulAddr, PVOID pvArch);
VOID archDbgBpAdjust(PVOID pvDtrace, PVOID pvtm);
@@ -144,7 +145,7 @@ VOID archReboot(INT iRebootType, addr_t ulStartAddress);
VOID archBogoMipsLoop(ULONG ulLoop);
#define __ARCH_BOGOMIPS_LOOP archBogoMipsLoop
-#define __ARCH_BOGOMIPS_INS_PER_LOOP 2
+#define __ARCH_BOGOMIPS_INS_PER_LOOP 8
/*********************************************************************************************************
C-SKY 处理器 CACHE 操作
@@ -178,6 +179,14 @@ VOID archMmuInit(CPCHAR pcMachineName);
#endif /* LW_CFG_VMM_EN > 0 */
/*********************************************************************************************************
+ C-SKY 处理器 MPU 操作 (bsp 初始化阶段直接调用下面函数初始化 MPU)
+*********************************************************************************************************/
+
+#if (LW_CFG_VMM_EN == 0) && (LW_CFG_CSKY_MPU > 0)
+VOID archMpuInit(CPCHAR pcMachineName, const CSKY_MPU_REGION mpuregion[]);
+#endif
+
+/*********************************************************************************************************
C-SKY 处理器多核自旋锁操作
*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/dbg/cskyDbg.c b/SylixOS/arch/csky/dbg/cskyDbg.c
index b9de814..13e3adf 100644
--- a/SylixOS/arch/csky/dbg/cskyDbg.c
+++ b/SylixOS/arch/csky/dbg/cskyDbg.c
@@ -107,6 +107,24 @@ VOID archDbgBpRemove (addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal
#endif /* LW_CFG_CACHE_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: archDbgApRemove
+** 功能描述: 删除一个终止点.
+** 输 入 : ulAddr 终止点地址
+** pulIns 返回的之前的指令
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDbgApRemove (addr_t ulAddr, ULONG ulIns)
+{
+ lib_memcpy((PCHAR)ulAddr, (PCHAR)&ulIns, sizeof(CSKY_INSTRUCTION));
+ KN_SMP_MB();
+
+#if LW_CFG_CACHE_EN > 0
+ API_CacheTextUpdate((PVOID)ulAddr, sizeof(CSKY_INSTRUCTION));
+#endif /* LW_CFG_CACHE_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: archDbgBpPrefetch
** 功能描述: 预取一个指令.
当指令处于 MMU 共享物理段时, 指令空间为物理只读, 这里需要产生一次缺页中断, 克隆一个物理页面.
@@ -132,21 +150,23 @@ VOID archDbgBpPrefetch (addr_t ulAddr)
*********************************************************************************************************/
UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
{
+ PLW_CLASS_TCB ptcbCur;
#if (LW_CFG_SMP_EN > 0) && (LW_CFG_CACHE_EN > 0) && (LW_CFG_GDB_SMP_TU_LAZY > 0)
- ULONG ulCPUId;
+ ULONG ulCPUId;
#endif /* LW_CFG_SMP_EN > 0 */
if (API_DtraceIsValid() == LW_FALSE) { /* 不存在调试节点 */
return (LW_TRAP_INVAL);
}
- switch (*(CSKY_INSTRUCTION *)ulAddr) {
-
- case CSKY_BREAKPOINT_INS:
- return (LW_TRAP_BRKPT);
+ if (*(CSKY_INSTRUCTION *)ulAddr == CSKY_BREAKPOINT_INS) {
+ LW_TCB_GET_CUR_SAFE(ptcbCur);
- default:
- break;
+ if (ptcbCur->TCB_ulAbortPointAddr == ulAddr) {
+ return (LW_TRAP_ABORT);
+ } else {
+ return (LW_TRAP_BRKPT);
+ }
}
#if (LW_CFG_SMP_EN > 0) && (LW_CFG_CACHE_EN > 0) && (LW_CFG_GDB_SMP_TU_LAZY > 0)
diff --git a/SylixOS/arch/csky/fpu/fpu/cskyVfp.c b/SylixOS/arch/csky/fpu/fpu/cskyVfp.c
index c6687c5..235b47c 100644
--- a/SylixOS/arch/csky/fpu/fpu/cskyVfp.c
+++ b/SylixOS/arch/csky/fpu/fpu/cskyVfp.c
@@ -59,9 +59,14 @@ static VOID cskyVfpCtxShow (INT iFd, PVOID pvFpuCtx)
fdprintf(iFd, "FESR = 0x%08x\n", pcpufpuCtx->FPUCTX_uiFpesr);
for (i = 0; i < FPU_REG_NR; i++) {
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+ fdprintf(iFd, "FP%02d = 0x%08x\n", i,
+ pcpufpuCtx->FPUCTX_uiDreg[i].val32[0]);
+#else
fdprintf(iFd, "FP%02d = 0x%08x0x%08x\n", i,
pcpufpuCtx->FPUCTX_uiDreg[i].val32[0],
pcpufpuCtx->FPUCTX_uiDreg[i].val32[1]);
+#endif /* __SYLIXOS_CSKY_ARCH_CK803__ */
}
#endif
}
diff --git a/SylixOS/arch/csky/fpu/fpu/cskyVfpAsm.S b/SylixOS/arch/csky/fpu/fpu/cskyVfpAsm.S
index de6d1d2..b156c28 100644
--- a/SylixOS/arch/csky/fpu/fpu/cskyVfpAsm.S
+++ b/SylixOS/arch/csky/fpu/fpu/cskyVfpAsm.S
@@ -42,7 +42,19 @@
; 宏定义
;*********************************************************************************************************/
-#define FCR_ENABLE (IDE_STAT | UFE_STAT | OFE_STAT | DZE_STAT | IOE_STAT)
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
+MACRO_DEF(FPU_REG_RESTORE fr, tmp, base, offset)
+ LD.W \tmp , (\base , \offset)
+ FMTVRL \fr , \tmp
+ MACRO_END()
+
+MACRO_DEF(FPU_REG_SAVE fr, tmp, base, offset)
+ FMFVRL \tmp , \fr
+ ST.W \tmp , (\base , \offset)
+ MACRO_END()
+
+#else
MACRO_DEF(FPU_REG_RESTORE fr, tmp, base, offsetl, offseth)
LD.W \tmp , (\base , \offsetl)
@@ -58,6 +70,8 @@ MACRO_DEF(FPU_REG_SAVE fr, tmp, base, offsetl, offseth)
ST.W \tmp , (\base , \offseth)
MACRO_END()
+#endif
+
;/*********************************************************************************************************
; 使能 FPU
;*********************************************************************************************************/
@@ -80,39 +94,43 @@ FUNC_DEF(cskyVfpInit)
MOVI A0 , 0
FMTVRL FR0 , A0 ;/* 清零 FPU 寄存器 */
- FMTVRH FR0 , A0
FMTVRL FR1 , A0
- FMTVRH FR1 , A0
FMTVRL FR2 , A0
- FMTVRH FR2 , A0
FMTVRL FR3 , A0
- FMTVRH FR3 , A0
FMTVRL FR4 , A0
- FMTVRH FR4 , A0
FMTVRL FR5 , A0
- FMTVRH FR5 , A0
FMTVRL FR6 , A0
- FMTVRH FR6 , A0
FMTVRL FR7 , A0
- FMTVRH FR7 , A0
FMTVRL FR8 , A0
- FMTVRH FR8 , A0
FMTVRL FR9 , A0
- FMTVRH FR9 , A0
FMTVRL FR10, A0
- FMTVRH FR10, A0
FMTVRL FR11, A0
- FMTVRH FR11, A0
FMTVRL FR12, A0
- FMTVRH FR12, A0
FMTVRL FR13, A0
- FMTVRH FR13, A0
FMTVRL FR14, A0
- FMTVRH FR14, A0
FMTVRL FR15, A0
+
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
+ FMTVRH FR0 , A0
+ FMTVRH FR1 , A0
+ FMTVRH FR2 , A0
+ FMTVRH FR3 , A0
+ FMTVRH FR4 , A0
+ FMTVRH FR5 , A0
+ FMTVRH FR6 , A0
+ FMTVRH FR7 , A0
+ FMTVRH FR8 , A0
+ FMTVRH FR9 , A0
+ FMTVRH FR10, A0
+ FMTVRH FR11, A0
+ FMTVRH FR12, A0
+ FMTVRH FR13, A0
+ FMTVRH FR14, A0
FMTVRH FR15, A0
-
- MTCR A1 , CR<1, 2> ;/* 恢复原 FPU 开关状态 */
+
+#endif
+
RTS
FUNC_END(cskyVfpInit)
@@ -156,8 +174,27 @@ FUNC_DEF(cskyVfpIsEnable)
;*********************************************************************************************************/
FUNC_DEF(cskyVfpSave)
- ENABLE_FPU ;/* 使能 FPU */
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
+ FPU_REG_SAVE FR0 , A1, A0, FPU_OFFSET_REG(0)
+ FPU_REG_SAVE FR1 , A1, A0, FPU_OFFSET_REG(1)
+ FPU_REG_SAVE FR2 , A1, A0, FPU_OFFSET_REG(2)
+ FPU_REG_SAVE FR3 , A1, A0, FPU_OFFSET_REG(3)
+ FPU_REG_SAVE FR4 , A1, A0, FPU_OFFSET_REG(4)
+ FPU_REG_SAVE FR5 , A1, A0, FPU_OFFSET_REG(5)
+ FPU_REG_SAVE FR6 , A1, A0, FPU_OFFSET_REG(6)
+ FPU_REG_SAVE FR7 , A1, A0, FPU_OFFSET_REG(7)
+ FPU_REG_SAVE FR8 , A1, A0, FPU_OFFSET_REG(8)
+ FPU_REG_SAVE FR9 , A1, A0, FPU_OFFSET_REG(9)
+ FPU_REG_SAVE FR10, A1, A0, FPU_OFFSET_REG(10)
+ FPU_REG_SAVE FR11, A1, A0, FPU_OFFSET_REG(11)
+ FPU_REG_SAVE FR12, A1, A0, FPU_OFFSET_REG(12)
+ FPU_REG_SAVE FR13, A1, A0, FPU_OFFSET_REG(13)
+ FPU_REG_SAVE FR14, A1, A0, FPU_OFFSET_REG(14)
+ FPU_REG_SAVE FR15, A1, A0, FPU_OFFSET_REG(15)
+
+#else
FPU_REG_SAVE FR0 , A1, A0, FPU_OFFSET_REG_LO(0), FPU_OFFSET_REG_HI(0)
FPU_REG_SAVE FR1 , A1, A0, FPU_OFFSET_REG_LO(1), FPU_OFFSET_REG_HI(1)
FPU_REG_SAVE FR2 , A1, A0, FPU_OFFSET_REG_LO(2), FPU_OFFSET_REG_HI(2)
@@ -175,6 +212,8 @@ FUNC_DEF(cskyVfpSave)
FPU_REG_SAVE FR14, A1, A0, FPU_OFFSET_REG_LO(14), FPU_OFFSET_REG_HI(14)
FPU_REG_SAVE FR15, A1, A0, FPU_OFFSET_REG_LO(15), FPU_OFFSET_REG_HI(15)
+#endif
+
MFCR A1 , CR<1, 2>
ST.W A1 , (A0 , FPU_OFFSET_FCR) ;/* 保存 FCR 状态寄存器 */
@@ -193,7 +232,28 @@ FUNC_DEF(cskyVfpRestore)
LD.W A1 , (A0 , FPU_OFFSET_FESR) ;/* 恢复 FECR 状态寄存器 */
MTCR A1 , CR<2, 2>
-
+
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
+ FPU_REG_RESTORE FR0 , A1, A0, FPU_OFFSET_REG(0)
+ FPU_REG_RESTORE FR1 , A1, A0, FPU_OFFSET_REG(1)
+ FPU_REG_RESTORE FR2 , A1, A0, FPU_OFFSET_REG(2)
+ FPU_REG_RESTORE FR3 , A1, A0, FPU_OFFSET_REG(3)
+ FPU_REG_RESTORE FR4 , A1, A0, FPU_OFFSET_REG(4)
+ FPU_REG_RESTORE FR5 , A1, A0, FPU_OFFSET_REG(5)
+ FPU_REG_RESTORE FR6 , A1, A0, FPU_OFFSET_REG(6)
+ FPU_REG_RESTORE FR7 , A1, A0, FPU_OFFSET_REG(7)
+ FPU_REG_RESTORE FR8 , A1, A0, FPU_OFFSET_REG(8)
+ FPU_REG_RESTORE FR9 , A1, A0, FPU_OFFSET_REG(9)
+ FPU_REG_RESTORE FR10, A1, A0, FPU_OFFSET_REG(10)
+ FPU_REG_RESTORE FR11, A1, A0, FPU_OFFSET_REG(11)
+ FPU_REG_RESTORE FR12, A1, A0, FPU_OFFSET_REG(12)
+ FPU_REG_RESTORE FR13, A1, A0, FPU_OFFSET_REG(13)
+ FPU_REG_RESTORE FR14, A1, A0, FPU_OFFSET_REG(14)
+ FPU_REG_RESTORE FR15, A1, A0, FPU_OFFSET_REG(15)
+
+#else
+
FPU_REG_RESTORE FR0 , A1, A0, FPU_OFFSET_REG_LO(0), FPU_OFFSET_REG_HI(0)
FPU_REG_RESTORE FR1 , A1, A0, FPU_OFFSET_REG_LO(1), FPU_OFFSET_REG_HI(1)
FPU_REG_RESTORE FR2 , A1, A0, FPU_OFFSET_REG_LO(2), FPU_OFFSET_REG_HI(2)
@@ -210,7 +270,8 @@ FUNC_DEF(cskyVfpRestore)
FPU_REG_RESTORE FR13, A1, A0, FPU_OFFSET_REG_LO(13), FPU_OFFSET_REG_HI(13)
FPU_REG_RESTORE FR14, A1, A0, FPU_OFFSET_REG_LO(14), FPU_OFFSET_REG_HI(14)
FPU_REG_RESTORE FR15, A1, A0, FPU_OFFSET_REG_LO(15), FPU_OFFSET_REG_HI(15)
-
+#endif
+
LD.W A1 , (A0 , FPU_OFFSET_FCR) ;/* 恢复 FCR 状态寄存器 */
MTCR A1 , CR<1, 2>
diff --git a/SylixOS/arch/csky/mm/cache/ck803/cskyCacheCK803.c b/SylixOS/arch/csky/mm/cache/ck803/cskyCacheCK803.c
new file mode 100644
index 0000000..1ec1941
--- /dev/null
+++ b/SylixOS/arch/csky/mm/cache/ck803/cskyCacheCK803.c
@@ -0,0 +1,992 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM)
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: cskyCacheCK803.c
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2018 年 11 月 12 日
+**
+** 描 述: C-SKY CK803 体系架构 CACHE 驱动.
+*********************************************************************************************************/
+#define __SYLIXOS_KERNEL
+#include "SylixOS.h"
+/*********************************************************************************************************
+ C-SKY 体系架构
+*********************************************************************************************************/
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+/*********************************************************************************************************
+ 裁剪支持
+*********************************************************************************************************/
+#if LW_CFG_CACHE_EN > 0
+#include "../../mpu/cskyMpu.h"
+/*********************************************************************************************************
+ L2 CACHE 支持
+*********************************************************************************************************/
+#if LW_CFG_CSKY_CACHE_L2 > 0
+#include "../l2/cskyL2.h"
+/*********************************************************************************************************
+ L1 CACHE 状态
+*********************************************************************************************************/
+#define L1_CACHE_I_EN 0x01
+#define L1_CACHE_D_EN 0x02
+#define L1_CACHE_EN (L1_CACHE_I_EN | L1_CACHE_D_EN)
+#define L1_CACHE_DIS 0x00
+
+static INT iCacheStatus = L1_CACHE_DIS;
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+/*********************************************************************************************************
+ CACHE 参数
+*********************************************************************************************************/
+typedef struct {
+ UINT32 CACHE_uiSize; /* CACHE 大小 */
+ UINT32 CACHE_uiLineSize; /* CACHE 行大小 */
+ UINT32 CACHE_uiWaySize; /* 路大小 */
+} CSKY_CACHE;
+
+static CSKY_CACHE _G_ICacheInfo = {
+ 4 * LW_CFG_KB_SIZE, /* 4KB 的四路组相联 ICACHE */
+ 16,
+ 1 * LW_CFG_KB_SIZE
+};
+
+static CSKY_CACHE _G_DCacheInfo = {
+ 4 * LW_CFG_KB_SIZE, /* 4KB 的四路组相联 DCACHE */
+ 16,
+ 1 * LW_CFG_KB_SIZE
+};
+
+#define CSKY_ICACHE_SIZE _G_ICacheInfo.CACHE_uiSize
+#define CSKY_DCACHE_SIZE _G_DCacheInfo.CACHE_uiSize
+
+#define CSKY_ICACHE_LINE_SIZE _G_ICacheInfo.CACHE_uiLineSize
+#define CSKY_DCACHE_LINE_SIZE _G_DCacheInfo.CACHE_uiLineSize
+
+#define CSKY_ICACHE_WAY_SIZE _G_ICacheInfo.CACHE_uiWaySize
+#define CSKY_DCACHE_WAY_SIZE _G_DCacheInfo.CACHE_uiWaySize
+
+#define CSKY_L1_CACHE_LOOP_OP_MAX_SIZE (CSKY_DCACHE_SIZE >> 1)
+/*********************************************************************************************************
+ CACHE 获得 pvAdrs 与 pvEnd 位置
+*********************************************************************************************************/
+#define CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, uiLineSize) \
+ do { \
+ ulEnd = (addr_t)((size_t)pvAdrs + stBytes); \
+ pvAdrs = (PVOID)((addr_t)pvAdrs & ~((addr_t)uiLineSize - 1)); \
+ } while (0)
+/*********************************************************************************************************
+ On chip cache structure.
+*********************************************************************************************************/
+typedef struct
+{
+ volatile UINT32 CER; /* Cache enable register */
+ volatile UINT32 CIR; /* Cache invalid register */
+ volatile UINT32 CRCR[4U]; /* Cache Configuration register */
+ volatile UINT32 RSERVED0[1015U];
+ volatile UINT32 CPFCR; /* Cache performance analisis control register */
+ volatile UINT32 CPFATR; /* Cache access times register */
+ volatile UINT32 CPFMTR; /* Cache missing times register */
+} CACHE_Type;
+/*********************************************************************************************************
+ Memory mapping of CK803 Hardware
+*********************************************************************************************************/
+#define TCIP_BASE (0xe000e000ul) /* Titly Coupled IP Base Addr */
+#define CACHE_BASE (TCIP_BASE + 0x1000ul) /* CACHE Base Address */
+
+#define CACHE ((CACHE_Type *)CACHE_BASE) /* cache configuration struct */
+/*********************************************************************************************************
+ CACHE Register Definitions
+*********************************************************************************************************/
+#define CACHE_CER_EN_Pos 0u /* CACHE CER: EN Position */
+#define CACHE_CER_EN_Msk (0x1ul << CACHE_CER_EN_Pos)
+
+#define CACHE_CER_CFIG_Pos 1u /* CACHE CER: CFIG Position */
+#define CACHE_CER_CFIG_Msk (0x1ul << CACHE_CER_CFIG_Pos)
+
+#define CACHE_CER_WB_Pos 2u /* CACHE CER: WB Position */
+#define CACHE_CER_WB_Msk (0x1ul << CACHE_CER_WB_Pos)
+
+#define CACHE_CER_WCFIG_Pos 3u /* CACHE CER: WCFIG Position */
+#define CACHE_CER_WCFIG_Msk (0x1ul << CACHE_CER_WCFIG_Pos)
+
+#define CACHE_CER_DCW_Pos 4u /* CACHE CER: DCW Position */
+#define CACHE_CER_DCW_Msk (0x1ul << CACHE_CER_DCW_Pos)
+
+#define CACHE_CER_WA_Pos 5u /* CACHE CER: WA Position */
+#define CACHE_CER_WA_Msk (0x1ul << CACHE_CER_WA_Pos)
+
+#define CACHE_CIR_INV_ALL_Pos 0u /* CACHE CIR: INV_ALL Position */
+#define CACHE_CIR_INV_ALL_Msk (0x1ul << CACHE_CIR_INV_ALL_Pos)
+
+#define CACHE_CIR_INV_ONE_Pos 1u /* CACHE CIR: INV_ONE Position */
+#define CACHE_CIR_INV_ONE_Msk (0x1ul << CACHE_CIR_INV_ONE_Pos)
+
+#define CACHE_CIR_CLR_ALL_Pos 2u /* CACHE CIR: CLR_ALL Position */
+#define CACHE_CIR_CLR_ALL_Msk (0x1ul << CACHE_CIR_CLR_ALL_Pos)
+
+#define CACHE_CIR_CLR_ONE_Pos 3u /* CACHE CIR: CLR_ONE Position */
+#define CACHE_CIR_CLR_ONE_Msk (0x1ul << CACHE_CIR_CLR_ONE_Pos)
+
+#define CACHE_CIR_INV_ADDR_Pos 4u /* CACHE CIR: INV_ADDR Position*/
+#define CACHE_CIR_INV_ADDR_Msk (0xffffffful << CACHE_CIR_INV_ADDR_Pos)
+
+#define CACHE_CRCR_EN_Pos 0u /* CACHE CRCR: EN Position */
+#define CACHE_CRCR_EN_Msk (0x1ul << CACHE_CRCR_EN_Pos)
+
+#define CACHE_CRCR_SIZE_Pos 1u /* CACHE CRCR: Size Position */
+#define CACHE_CRCR_SIZE_Msk (0x1ful << CACHE_CRCR_SIZE_Pos)
+
+#define CACHE_CRCR_BASE_ADDR_Pos 10u /* CACHE CRCR: base addr Pos */
+#define CACHE_CRCR_BASE_ADDR_Msk (0x3ffffful << CACHE_CRCR_BASE_ADDR_Pos)
+
+#define CACHE_CPFCR_PFEN_Pos 0u /* CACHE CPFCR: PFEN Position */
+#define CACHE_CPFCR_PFEN_Msk (0x1ul << CACHE_CPFCR_PFEN_Pos)
+
+#define CACHE_CPFCR_PFRST_Pos 1U /* CACHE CPFCR: PFRST Position */
+#define CACHE_CPFCR_PFRST_Msk (0x1ul << CACHE_CPFCR_PFRST_Pos)
+/*********************************************************************************************************
+ Mask and shift operation.
+*********************************************************************************************************/
+#define _VAL2FLD(field, value) ((value << field ## _Pos) & field ## _Msk)
+#define _FLD2VAL(field, value) ((value & field ## _Msk) >> field ## _Pos)
+/*********************************************************************************************************
+** 函数名称: cskyICacheCK803Enable
+** 功能描述: 使能 ICACHE
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyICacheCK803Enable (VOID)
+{
+ CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
+ CACHE->CER |= (UINT32)(CACHE_CER_EN_Msk | CACHE_CER_CFIG_Msk); /* enable all Cache */
+}
+/*********************************************************************************************************
+** 函数名称: cskyDCacheCK803Enable
+** 功能描述: 使能 DCACHE
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyDCacheCK803Enable (VOID)
+{
+ CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
+ CACHE->CER = (UINT32)(CACHE_CER_EN_Msk | CACHE_CER_WB_Msk | CACHE_CER_DCW_Msk);
+ /* enable all Cache */
+}
+/*********************************************************************************************************
+** 函数名称: cskyICacheCK803Disable
+** 功能描述: 禁能 ICACHE
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyICacheCK803Disable (VOID)
+{
+ CACHE->CER &= ~(UINT32)(CACHE_CER_EN_Msk | CACHE_CER_CFIG_Msk); /* disable all Cache */
+ CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
+}
+/*********************************************************************************************************
+** 函数名称: cskyDCacheCK803Disable
+** 功能描述: 禁能 DCACHE
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyDCacheCK803Disable (VOID)
+{
+ CACHE->CER &= ~(UINT32)CACHE_CER_EN_Msk; /* disable all Cache */
+ CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
+}
+/*********************************************************************************************************
+** 函数名称: cskyICacheCK803InvalidateAll
+** 功能描述: 无效所有 ICACHE
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyICacheCK803InvalidateAll (VOID)
+{
+ CACHE->CIR = CACHE_CIR_INV_ALL_Msk; /* invalidate all Cache */
+}
+/*********************************************************************************************************
+** 函数名称: cskyDCacheCK803FlushAll
+** 功能描述: 回写所有 DCACHE
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyDCacheCK803FlushAll (VOID)
+{
+ CACHE->CIR = _VAL2FLD(CACHE_CIR_CLR_ALL, 1); /* clean all Cache */
+}
+/*********************************************************************************************************
+** 函数名称: cskyDCacheCK803ClearAll
+** 功能描述: 回写并无效所有 DCACHE
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyDCacheCK803ClearAll (VOID)
+{
+ CACHE->CIR = _VAL2FLD(CACHE_CIR_INV_ALL, 1) | _VAL2FLD(CACHE_CIR_CLR_ALL, 1);
+ /* clean and inv all Cache */
+}
+/*********************************************************************************************************
+** 函数名称: cskyICacheCK803Invalidate
+** 功能描述: 无效指定区间的 ICACHE
+** 输 入 : pvStart 起始地址
+** pvEnd 结束地址
+** uiStep 步进
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyICacheCK803Invalidate (PVOID pvStart, PVOID pvEnd, UINT32 uiStep)
+{
+ UINT32 uiOpAddr = (UINT32)pvStart & CACHE_CIR_INV_ADDR_Msk;
+ UINT32 uiLineSize = 16;
+ INT32 iOpSize = (UINT32)pvEnd - (UINT32)pvStart;
+
+ uiOpAddr |= _VAL2FLD(CACHE_CIR_INV_ONE, 1);
+
+ while (iOpSize >= 128) {
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+
+ iOpSize -= 128;
+ }
+
+ while (iOpSize > 0) {
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ iOpSize -= uiLineSize;
+ }
+}
+/*********************************************************************************************************
+** 函数名称: cskyDCacheCK803Invalidate
+** 功能描述: 无效指定区间的 DCACHE
+** 输 入 : pvStart 起始地址
+** pvEnd 结束地址
+** uiStep 步进
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyDCacheCK803Invalidate (PVOID pvStart, PVOID pvEnd, UINT32 uiStep)
+{
+ UINT32 uiOpAddr = (UINT32)pvStart & CACHE_CIR_INV_ADDR_Msk;
+ UINT32 uiLineSize = 16;
+ INT32 iOpSize = (UINT32)pvEnd - (UINT32)pvStart;
+
+ if (iOpSize == 0) {
+ iOpSize = uiLineSize;
+ }
+
+ uiOpAddr |= _VAL2FLD(CACHE_CIR_INV_ONE, 1);
+
+ while (iOpSize >= 128) {
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+
+ iOpSize -= 128;
+ }
+
+ while (iOpSize > 0) {
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ iOpSize -= uiLineSize;
+ }
+}
+/*********************************************************************************************************
+** 函数名称: cskyDCacheCK803Flush
+** 功能描述: 回写指定区间的 DCACHE
+** 输 入 : pvStart 起始地址
+** pvEnd 结束地址
+** uiStep 步进
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyDCacheCK803Flush (PVOID pvStart, PVOID pvEnd, UINT32 uiStep)
+{
+ UINT32 uiOpAddr = (UINT32)pvStart & CACHE_CIR_INV_ADDR_Msk;
+ UINT32 uiLineSize = 16;
+ INT32 iOpSize = (UINT32)pvEnd - (UINT32)pvStart;
+
+ if (iOpSize == 0) {
+ iOpSize = uiLineSize;
+ }
+
+ uiOpAddr |= _VAL2FLD(CACHE_CIR_CLR_ONE, 1);
+
+ while (iOpSize >= 128) {
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+
+ iOpSize -= 128;
+ }
+
+ while (iOpSize > 0) {
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ iOpSize -= uiLineSize;
+ }
+}
+/*********************************************************************************************************
+** 函数名称: cskyDCacheCK803Clear
+** 功能描述: 回写并无效指定区间的 DCACHE
+** 输 入 : pvStart 起始地址
+** pvEnd 结束地址
+** uiStep 步进
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyDCacheCK803Clear (PVOID pvStart, PVOID pvEnd, UINT32 uiStep)
+{
+ UINT32 uiOpAddr = (UINT32)pvStart & CACHE_CIR_INV_ADDR_Msk;
+ UINT32 uiLineSize = 16;
+ INT32 iOpSize = (UINT32)pvEnd - (UINT32)pvStart;
+
+ if (iOpSize == 0) {
+ iOpSize = uiLineSize;
+ }
+
+ uiOpAddr |= _VAL2FLD(CACHE_CIR_INV_ONE, 1) | _VAL2FLD(CACHE_CIR_CLR_ONE, 1);
+
+ while (iOpSize >= 128) {
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+
+ iOpSize -= 128;
+ }
+
+ while (iOpSize > 0) {
+ CACHE->CIR = uiOpAddr;
+ uiOpAddr += uiLineSize;
+ iOpSize -= uiLineSize;
+ }
+}
+/*********************************************************************************************************
+** 函数名称: cskyBranchPredictorCK803Invalidate
+** 功能描述: 无效分支预测
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyBranchPredictorCK803Invalidate (VOID)
+{
+}
+/*********************************************************************************************************
+** 函数名称: cskyBranchPredictionCK803Disable
+** 功能描述: 禁能分支预测
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyBranchPredictionCK803Disable (VOID)
+{
+}
+/*********************************************************************************************************
+** 函数名称: cskyBranchPredictionCK803Enable
+** 功能描述: 使能分支预测
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyBranchPredictionCK803Enable (VOID)
+{
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803Enable
+** 功能描述: 使能 CACHE
+** 输 入 : cachetype INSTRUCTION_CACHE / DATA_CACHE
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803Enable (LW_CACHE_TYPE cachetype)
+{
+ if (cachetype == INSTRUCTION_CACHE) {
+ cskyICacheCK803Enable();
+#if LW_CFG_CSKY_CACHE_L2 > 0
+ if (LW_CPU_GET_CUR_ID() == 0) {
+ iCacheStatus |= L1_CACHE_I_EN;
+ }
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+ cskyBranchPredictionCK803Enable();
+
+ } else {
+ cskyDCacheCK803Enable();
+#if LW_CFG_CSKY_CACHE_L2 > 0
+ if (LW_CPU_GET_CUR_ID() == 0) {
+ iCacheStatus |= L1_CACHE_D_EN;
+ }
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+ }
+
+#if LW_CFG_CSKY_CACHE_L2 > 0
+ if ((LW_CPU_GET_CUR_ID() == 0) &&
+ (iCacheStatus == L1_CACHE_EN)) {
+ cskyL2CK803Enable();
+ }
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803Disable
+** 功能描述: 禁能 CACHE
+** 输 入 : cachetype INSTRUCTION_CACHE / DATA_CACHE
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803Disable (LW_CACHE_TYPE cachetype)
+{
+ if (cachetype == INSTRUCTION_CACHE) {
+ cskyICacheCK803Disable();
+#if LW_CFG_ARM_CACHE_L2 > 0
+ if (LW_CPU_GET_CUR_ID() == 0) {
+ iCacheStatus &= ~L1_CACHE_I_EN;
+ }
+#endif /* LW_CFG_ARM_CACHE_L2 > 0 */
+ cskyBranchPredictionCK803Disable();
+
+ } else {
+ cskyDCacheCK803Disable();
+#if LW_CFG_ARM_CACHE_L2 > 0
+ if (LW_CPU_GET_CUR_ID() == 0) {
+ iCacheStatus &= ~L1_CACHE_D_EN;
+ }
+#endif /* LW_CFG_ARM_CACHE_L2 > 0 */
+ }
+
+#if LW_CFG_ARM_CACHE_L2 > 0
+ if ((LW_CPU_GET_CUR_ID() == 0) &&
+ (iCacheStatus == L1_CACHE_DIS)) {
+ cskyL2CK803Disable();
+ }
+#endif /* LW_CFG_ARM_CACHE_L2 > 0 */
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803Flush
+** 功能描述: CACHE 脏数据回写
+** 输 入 : cachetype CACHE 类型
+** pvAdrs 虚拟地址
+** stBytes 长度
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803Flush (LW_CACHE_TYPE cachetype, PVOID pvAdrs, size_t stBytes)
+{
+ addr_t ulEnd;
+
+ if (cachetype == DATA_CACHE) {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyDCacheCK803FlushAll(); /* 全部回写 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_DCACHE_LINE_SIZE);
+ cskyDCacheCK803Flush(pvAdrs, (PVOID)ulEnd,
+ CSKY_DCACHE_LINE_SIZE); /* 部分回写 */
+ }
+
+#if LW_CFG_CSKY_CACHE_L2 > 0
+ cskyL2CK803FlushAll();
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803FlushPage
+** 功能描述: CACHE 脏数据回写
+** 输 入 : cachetype CACHE 类型
+** pvAdrs 虚拟地址
+** pvPdrs 物理地址
+** stBytes 长度
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803FlushPage (LW_CACHE_TYPE cachetype, PVOID pvAdrs, PVOID pvPdrs, size_t stBytes)
+{
+ addr_t ulEnd;
+
+ if (cachetype == DATA_CACHE) {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyDCacheCK803FlushAll(); /* 全部回写 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_DCACHE_LINE_SIZE);
+ cskyDCacheCK803Flush(pvAdrs, (PVOID)ulEnd,
+ CSKY_DCACHE_LINE_SIZE); /* 部分回写 */
+ }
+
+#if LW_CFG_CSKY_CACHE_L2 > 0
+ cskyL2CK803Flush(pvPdrs, stBytes);
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803Invalidate
+** 功能描述: 指定类型的 CACHE 使部分无效(访问不命中)
+** 输 入 : cachetype CACHE 类型
+** pvAdrs 虚拟地址
+** stBytes 长度
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803Invalidate (LW_CACHE_TYPE cachetype, PVOID pvAdrs, size_t stBytes)
+{
+ addr_t ulEnd;
+
+ if (cachetype == INSTRUCTION_CACHE) {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyICacheCK803InvalidateAll(); /* ICACHE 全部无效 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_ICACHE_LINE_SIZE);
+ cskyICacheCK803Invalidate(pvAdrs, (PVOID)ulEnd, CSKY_ICACHE_LINE_SIZE);
+ }
+
+ } else {
+ if (stBytes > 0) { /* 必须 > 0 */
+ addr_t ulStart = (addr_t)pvAdrs;
+ ulEnd = ulStart + stBytes;
+
+ if (ulStart & ((addr_t)CSKY_DCACHE_LINE_SIZE - 1)) { /* 起始地址非 cache line 对齐 */
+ ulStart &= ~((addr_t)CSKY_DCACHE_LINE_SIZE - 1);
+ cskyDCacheCK803Clear((PVOID)ulStart, (PVOID)ulStart, CSKY_DCACHE_LINE_SIZE);
+ ulStart += CSKY_DCACHE_LINE_SIZE;
+ }
+
+ if (ulEnd & ((addr_t)CSKY_DCACHE_LINE_SIZE - 1)) { /* 结束地址非 cache line 对齐 */
+ ulEnd &= ~((addr_t)CSKY_DCACHE_LINE_SIZE - 1);
+ cskyDCacheCK803Clear((PVOID)ulEnd, (PVOID)ulEnd, CSKY_DCACHE_LINE_SIZE);
+ }
+
+ if (ulStart < ulEnd) { /* 仅无效对齐部分 */
+ cskyDCacheCK803Invalidate((PVOID)ulStart, (PVOID)ulEnd, CSKY_DCACHE_LINE_SIZE);
+ }
+
+#if LW_CFG_CSKY_CACHE_L2 > 0
+ cskyL2CK803Invalidate(pvAdrs, stBytes); /* 虚拟与物理地址必须相同 */
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+ } else {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "stBytes == 0.\r\n");
+ }
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803InvalidatePage
+** 功能描述: 指定类型的 CACHE 使部分无效(访问不命中)
+** 输 入 : cachetype CACHE 类型
+** pvAdrs 虚拟地址
+** pvPdrs 物理地址
+** stBytes 长度
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803InvalidatePage (LW_CACHE_TYPE cachetype, PVOID pvAdrs, PVOID pvPdrs, size_t stBytes)
+{
+ addr_t ulEnd;
+
+ if (cachetype == INSTRUCTION_CACHE) {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyICacheCK803InvalidateAll(); /* ICACHE 全部无效 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_ICACHE_LINE_SIZE);
+ cskyICacheCK803Invalidate(pvAdrs, (PVOID)ulEnd, CSKY_ICACHE_LINE_SIZE);
+ }
+
+ } else {
+ if (stBytes > 0) { /* 必须 > 0 */
+ addr_t ulStart = (addr_t)pvAdrs;
+ ulEnd = ulStart + stBytes;
+
+ if (ulStart & ((addr_t)CSKY_DCACHE_LINE_SIZE - 1)) { /* 起始地址非 cache line 对齐 */
+ ulStart &= ~((addr_t)CSKY_DCACHE_LINE_SIZE - 1);
+ cskyDCacheCK803Clear((PVOID)ulStart, (PVOID)ulStart, CSKY_DCACHE_LINE_SIZE);
+ ulStart += CSKY_DCACHE_LINE_SIZE;
+ }
+
+ if (ulEnd & ((addr_t)CSKY_DCACHE_LINE_SIZE - 1)) { /* 结束地址非 cache line 对齐 */
+ ulEnd &= ~((addr_t)CSKY_DCACHE_LINE_SIZE - 1);
+ cskyDCacheCK803Clear((PVOID)ulEnd, (PVOID)ulEnd, CSKY_DCACHE_LINE_SIZE);
+ }
+
+ if (ulStart < ulEnd) { /* 仅无效对齐部分 */
+ cskyDCacheCK803Invalidate((PVOID)ulStart, (PVOID)ulEnd, CSKY_DCACHE_LINE_SIZE);
+ }
+
+#if LW_CFG_CSKY_CACHE_L2 > 0
+ cskyL2CK803Invalidate(pvPdrs, stBytes); /* 虚拟与物理地址必须相同 */
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+ } else {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "stBytes == 0.\r\n");
+ }
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803Clear
+** 功能描述: 指定类型的 CACHE 使部分或全部清空(回写内存)并无效(访问不命中)
+** 输 入 : cachetype CACHE 类型
+** pvAdrs 虚拟地址
+** stBytes 长度
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803Clear (LW_CACHE_TYPE cachetype, PVOID pvAdrs, size_t stBytes)
+{
+ addr_t ulEnd;
+
+ if (cachetype == INSTRUCTION_CACHE) {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyICacheCK803InvalidateAll(); /* ICACHE 全部无效 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_ICACHE_LINE_SIZE);
+ cskyICacheCK803Invalidate(pvAdrs, (PVOID)ulEnd, CSKY_ICACHE_LINE_SIZE);
+ }
+
+ } else {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyDCacheCK803ClearAll(); /* 全部回写并无效 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_DCACHE_LINE_SIZE);
+ cskyDCacheCK803Clear(pvAdrs, (PVOID)ulEnd,
+ CSKY_DCACHE_LINE_SIZE); /* 部分回写并无效 */
+ }
+
+#if LW_CFG_CSKY_CACHE_L2 > 0
+ cskyL2CK803ClearAll();
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803ClearPage
+** 功能描述: 指定类型的 CACHE 使部分或全部清空(回写内存)并无效(访问不命中)
+** 输 入 : cachetype CACHE 类型
+** pvAdrs 虚拟地址
+** pvPdrs 物理地址
+** stBytes 长度
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803ClearPage (LW_CACHE_TYPE cachetype, PVOID pvAdrs, PVOID pvPdrs, size_t stBytes)
+{
+ addr_t ulEnd;
+
+ if (cachetype == INSTRUCTION_CACHE) {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyICacheCK803InvalidateAll(); /* ICACHE 全部无效 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_ICACHE_LINE_SIZE);
+ cskyICacheCK803Invalidate(pvAdrs, (PVOID)ulEnd, CSKY_ICACHE_LINE_SIZE);
+ }
+
+ } else {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyDCacheCK803ClearAll(); /* 全部回写并无效 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_DCACHE_LINE_SIZE);
+ cskyDCacheCK803Clear(pvAdrs, (PVOID)ulEnd,
+ CSKY_DCACHE_LINE_SIZE); /* 部分回写并无效 */
+ }
+
+#if LW_CFG_CSKY_CACHE_L2 > 0
+ cskyL2CK803Clear(pvPdrs, stBytes);
+#endif /* LW_CFG_CSKY_CACHE_L2 > 0 */
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803Lock
+** 功能描述: 锁定指定类型的 CACHE
+** 输 入 : cachetype CACHE 类型
+** pvAdrs 虚拟地址
+** stBytes 长度
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803Lock (LW_CACHE_TYPE cachetype, PVOID pvAdrs, size_t stBytes)
+{
+ _ErrorHandle(ENOSYS);
+ return (PX_ERROR);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803Unlock
+** 功能描述: 解锁指定类型的 CACHE
+** 输 入 : cachetype CACHE 类型
+** pvAdrs 虚拟地址
+** stBytes 长度
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT cskyCacheCK803Unlock (LW_CACHE_TYPE cachetype, PVOID pvAdrs, size_t stBytes)
+{
+ _ErrorHandle(ENOSYS);
+ return (PX_ERROR);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803TextUpdate
+** 功能描述: 清空(回写内存) D CACHE 无效(访问不命中) I CACHE
+** 输 入 : pvAdrs 虚拟地址
+** stBytes 长度
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+** 注 意 : L2 cache 为统一 CACHE 所以 text update 不需要操作 L2 cache.
+*********************************************************************************************************/
+static INT cskyCacheCK803TextUpdate (PVOID pvAdrs, size_t stBytes)
+{
+ addr_t ulEnd;
+
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyDCacheCK803ClearAll(); /* DCACHE 全部回写 */
+ cskyICacheCK803InvalidateAll(); /* ICACHE 全部无效 */
+
+ } else {
+ PVOID pvAdrsBak = pvAdrs;
+
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_DCACHE_LINE_SIZE);
+ cskyDCacheCK803Flush(pvAdrs, (PVOID)ulEnd, CSKY_DCACHE_LINE_SIZE);
+
+ CSKY_CACHE_GET_END(pvAdrsBak, stBytes, ulEnd, CSKY_ICACHE_LINE_SIZE);
+ cskyICacheCK803Invalidate(pvAdrsBak, (PVOID)ulEnd, CSKY_ICACHE_LINE_SIZE);
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803DataUpdate
+** 功能描述: 回写 D CACHE (仅回写 CPU 独享级 CACHE)
+** 输 入 : pvAdrs 虚拟地址
+** stBytes 长度
+** bInv 是否为回写无效
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+** 注 意 : L2 cache 为统一 CACHE 所以 data update 不需要操作 L2 cache.
+*********************************************************************************************************/
+static INT cskyCacheCK803DataUpdate (PVOID pvAdrs, size_t stBytes, BOOL bInv)
+{
+ addr_t ulEnd;
+
+ if (bInv == LW_FALSE) {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyDCacheCK803FlushAll(); /* 全部回写 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_DCACHE_LINE_SIZE);
+ cskyDCacheCK803Flush(pvAdrs, (PVOID)ulEnd,
+ CSKY_DCACHE_LINE_SIZE); /* 部分回写 */
+ }
+
+ } else {
+ if (stBytes >= CSKY_L1_CACHE_LOOP_OP_MAX_SIZE) {
+ cskyDCacheCK803ClearAll(); /* 全部回写 */
+
+ } else {
+ CSKY_CACHE_GET_END(pvAdrs, stBytes, ulEnd, CSKY_DCACHE_LINE_SIZE);
+ cskyDCacheCK803Clear(pvAdrs, (PVOID)ulEnd,
+ CSKY_DCACHE_LINE_SIZE); /* 部分回写 */
+ }
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheCK803RangeSet
+** 功能描述: CACHE 区域设置
+** 输 入 : uiIndex 存储 CACHE 配置的 CRCR 下标
+** ulBase 区域基地址
+** uiSize 区域大小
+** uiEnable 是否使能 CACHE 属性
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyCacheCK803RangeSet (UINT32 uiIndex, ULONG ulBase, UINT32 uiSize, UINT32 uiEnable)
+{
+ CACHE->CRCR[uiIndex] = ((ulBase & CACHE_CRCR_BASE_ADDR_Msk) |
+ (_VAL2FLD(CACHE_CRCR_SIZE, uiSize)) |
+ (_VAL2FLD(CACHE_CRCR_EN, uiEnable)));
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheInit
+** 功能描述: 初始化 CACHE
+** 输 入 : pcacheop CACHE 操作函数集
+** uiInstruction 指令 CACHE 参数
+** uiData 数据 CACHE 参数
+** pcMachineName 机器名称
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyCacheInit (LW_CACHE_OP *pcacheop,
+ CACHE_MODE uiInstruction,
+ CACHE_MODE uiData,
+ CPCHAR pcMachineName)
+{
+ if (lib_strcmp(pcMachineName, CSKY_MACHINE_803) != 0) {
+ return;
+ }
+
+ pcacheop->CACHEOP_ulOption = 0ul;
+
+ pcacheop->CACHEOP_iILoc = CACHE_LOCATION_PIPT;
+ pcacheop->CACHEOP_iDLoc = CACHE_LOCATION_PIPT;
+
+ pcacheop->CACHEOP_iICacheLine = CSKY_ICACHE_LINE_SIZE;
+ pcacheop->CACHEOP_iDCacheLine = CSKY_DCACHE_LINE_SIZE;
+
+ pcacheop->CACHEOP_iICacheWaySize = CSKY_ICACHE_WAY_SIZE;
+ pcacheop->CACHEOP_iDCacheWaySize = CSKY_ICACHE_WAY_SIZE;
+
+ pcacheop->CACHEOP_pfuncEnable = cskyCacheCK803Enable;
+ pcacheop->CACHEOP_pfuncDisable = cskyCacheCK803Disable;
+
+ pcacheop->CACHEOP_pfuncLock = cskyCacheCK803Lock; /* 暂时不支持锁定操作 */
+ pcacheop->CACHEOP_pfuncUnlock = cskyCacheCK803Unlock;
+
+ pcacheop->CACHEOP_pfuncFlush = cskyCacheCK803Flush;
+ pcacheop->CACHEOP_pfuncFlushPage = cskyCacheCK803FlushPage;
+ pcacheop->CACHEOP_pfuncInvalidate = cskyCacheCK803Invalidate;
+ pcacheop->CACHEOP_pfuncInvalidatePage = cskyCacheCK803InvalidatePage;
+ pcacheop->CACHEOP_pfuncClear = cskyCacheCK803Clear;
+ pcacheop->CACHEOP_pfuncClearPage = cskyCacheCK803ClearPage;
+ pcacheop->CACHEOP_pfuncTextUpdate = cskyCacheCK803TextUpdate;
+ pcacheop->CACHEOP_pfuncDataUpdate = cskyCacheCK803DataUpdate;
+
+#if (LW_CFG_VMM_EN == 0) && (LW_CFG_ARM_MPU > 0)
+ pcacheop->CACHEOP_pfuncDmaMalloc = cskyMpuDmaAlloc;
+ pcacheop->CACHEOP_pfuncDmaMallocAlign = cskyMpuDmaAllocAlign;
+ pcacheop->CACHEOP_pfuncDmaFree = cskyMpuDmaFree;
+#endif /* LW_CFG_ARM_MPU > 0 */
+}
+/*********************************************************************************************************
+** 函数名称: cskyCacheReset
+** 功能描述: 复位 CACHE
+** 输 入 : pcMachineName 机器名称
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+LW_WEAK VOID cskyCacheReset (CPCHAR pcMachineName)
+{
+ if (lib_strcmp(pcMachineName, CSKY_MACHINE_803) != 0) {
+ return;
+ }
+
+ cskyICacheCK803InvalidateAll();
+ cskyDCacheCK803Disable();
+ cskyICacheCK803Disable();
+ cskyBranchPredictorCK803Invalidate();
+}
+
+#endif /* LW_CFG_CACHE_EN > 0 */
+#endif /* __SYLIXOS_CSKY_ARCH_CK803__ */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/mm/cache/ck803/cskyCacheCK803.h b/SylixOS/arch/csky/mm/cache/ck803/cskyCacheCK803.h
new file mode 100644
index 0000000..f7e7b0b
--- /dev/null
+++ b/SylixOS/arch/csky/mm/cache/ck803/cskyCacheCK803.h
@@ -0,0 +1,61 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM)
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: cskyCacheCK803.h
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2019 年 05 月 09 日
+**
+** 描 述: C-SKY CK803 体系架构 CACHE 驱动.
+*********************************************************************************************************/
+
+#ifndef __ARCH_CSKYCACHECK803_H
+#define __ARCH_CSKYCACHECK803_H
+
+/*********************************************************************************************************
+ CK803 处理器 CACHE 区域大小
+*********************************************************************************************************/
+
+#define CACHE_CRCR_4K 0xb
+#define CACHE_CRCR_8K 0xc
+#define CACHE_CRCR_16K 0xd
+#define CACHE_CRCR_32K 0xe
+#define CACHE_CRCR_64K 0xf
+#define CACHE_CRCR_128K 0x10
+#define CACHE_CRCR_256K 0x11
+#define CACHE_CRCR_512K 0x12
+#define CACHE_CRCR_1M 0x13
+#define CACHE_CRCR_2M 0x14
+#define CACHE_CRCR_4M 0x15
+#define CACHE_CRCR_8M 0x16
+#define CACHE_CRCR_16M 0x17
+#define CACHE_CRCR_32M 0x18
+#define CACHE_CRCR_64M 0x19
+#define CACHE_CRCR_128M 0x1a
+#define CACHE_CRCR_256M 0x1b
+#define CACHE_CRCR_512M 0x1c
+#define CACHE_CRCR_1G 0x1d
+#define CACHE_CRCR_2G 0x1e
+#define CACHE_CRCR_4G 0x1f
+
+VOID cskyDCacheCK803Disable(VOID);
+VOID cskyICacheCK803Disable(VOID);
+VOID cskyICacheCK803InvalidateAll(VOID);
+VOID cskyDCacheCK803FlushAll(VOID);
+VOID cskyDCacheCK803ClearAll(VOID);
+VOID cskyCacheCK803RangeSet(UINT32 uiIndex, ULONG ulBase, UINT32 uiSize, UINT32 uiEnable);
+
+#endif /* __ARCH_CSKYCACHECK803_H */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/mm/cache/cskyCache.c b/SylixOS/arch/csky/mm/cache/cskyCache.c
index 9d37170..38749c1 100644
--- a/SylixOS/arch/csky/mm/cache/cskyCache.c
+++ b/SylixOS/arch/csky/mm/cache/cskyCache.c
@@ -21,6 +21,10 @@
#define __SYLIXOS_KERNEL
#include "SylixOS.h"
/*********************************************************************************************************
+ C-SKY 体系架构
+*********************************************************************************************************/
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
+/*********************************************************************************************************
裁剪支持
*********************************************************************************************************/
#if LW_CFG_CACHE_EN > 0
@@ -730,6 +734,7 @@ VOID cskyCacheReset (CPCHAR pcMachineName)
}
#endif /* LW_CFG_CACHE_EN > 0 */
+#endif /* !__SYLIXOS_CSKY_ARCH_CK803__*/
/*********************************************************************************************************
END
*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/mm/cache/cskyCacheAsm.S b/SylixOS/arch/csky/mm/cache/cskyCacheAsm.S
index ca0e379..ec7be93 100644
--- a/SylixOS/arch/csky/mm/cache/cskyCacheAsm.S
+++ b/SylixOS/arch/csky/mm/cache/cskyCacheAsm.S
@@ -28,6 +28,8 @@
#include <config/kernel/cache_cfg.h>
#include <config/cpu/cpu_cfg_csky.h>
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
#if LW_CFG_CACHE_EN > 0
EXPORT_LABEL(cskyICacheInvalidateAll)
@@ -196,6 +198,7 @@ FUNC_DEF(cskyBranchPredictionDisable)
FILE_END()
#endif
+#endif
;/*********************************************************************************************************
; END
;*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/mm/cskyMpu.c b/SylixOS/arch/csky/mm/cskyMpu.c
new file mode 100644
index 0000000..7553dfe
--- /dev/null
+++ b/SylixOS/arch/csky/mm/cskyMpu.c
@@ -0,0 +1,45 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM)
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: cskyMpu.c
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2018 年 11 月 12 日
+**
+** 描 述: C-SKY 体系架构 MPU 驱动.
+*********************************************************************************************************/
+#define __SYLIXOS_KERNEL
+#include "SylixOS.h"
+/*********************************************************************************************************
+ 裁剪支持
+*********************************************************************************************************/
+#if (LW_CFG_VMM_EN == 0) && (LW_CFG_CSKY_MPU > 0)
+#include "mpu/cskyMpu.h"
+/*********************************************************************************************************
+** 函数名称: archMpuInit
+** 功能描述: 初始化 MPU
+** 输 入 : pcMachineName 机器名称
+** pmpuregion 内存分区信息
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archMpuInit (CPCHAR pcMachineName, const CSKY_MPU_REGION mpuregion[])
+{
+ cskyMpuInit(pcMachineName, mpuregion);
+}
+
+#endif /* LW_CFG_CSKY_MPU > 0 */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/mm/mmu/cskyMmu.c b/SylixOS/arch/csky/mm/mmu/cskyMmu.c
index 1129c04..ef26de1 100644
--- a/SylixOS/arch/csky/mm/mmu/cskyMmu.c
+++ b/SylixOS/arch/csky/mm/mmu/cskyMmu.c
@@ -21,6 +21,10 @@
#define __SYLIXOS_KERNEL
#include "SylixOS.h"
/*********************************************************************************************************
+ C-SKY 体系架构
+*********************************************************************************************************/
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
+/*********************************************************************************************************
裁剪支持
*********************************************************************************************************/
#if LW_CFG_VMM_EN > 0
@@ -711,6 +715,7 @@ VOID cskyMmuInit (LW_MMU_OP *pmmuop, CPCHAR pcMachineName)
}
#endif /* LW_CFG_VMM_EN > 0 */
+#endif /* !__SYLIXOS_CSKY_ARCH_CK803__*/
/*********************************************************************************************************
END
*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/mm/mmu/cskyMmuAsm.S b/SylixOS/arch/csky/mm/mmu/cskyMmuAsm.S
index 80fed9f..a96c298 100644
--- a/SylixOS/arch/csky/mm/mmu/cskyMmuAsm.S
+++ b/SylixOS/arch/csky/mm/mmu/cskyMmuAsm.S
@@ -27,6 +27,8 @@
#include <config/kernel/vmm_cfg.h>
#include <config/kernel/memory_cfg.h>
+#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
#if LW_CFG_VMM_EN > 0
#include "arch/csky/arch_mmu.h"
#include "arch/csky/inc/cskyregs.h"
@@ -269,6 +271,7 @@ LINE_LABEL(__tlbinv_handle)
FILE_END()
#endif
+#endif
;/*********************************************************************************************************
; END
;*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/mm/mpu/cskyMpu.c b/SylixOS/arch/csky/mm/mpu/cskyMpu.c
new file mode 100644
index 0000000..b076b8f
--- /dev/null
+++ b/SylixOS/arch/csky/mm/mpu/cskyMpu.c
@@ -0,0 +1,210 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM)
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: cskyMpu.c
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2018 年 11 月 12 日
+**
+** 描 述: C-SKY 体系架构 MPU 驱动.
+*********************************************************************************************************/
+#define __SYLIXOS_KERNEL
+#include "SylixOS.h"
+/*********************************************************************************************************
+ C-SKY 体系架构
+*********************************************************************************************************/
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+/*********************************************************************************************************
+ 裁剪支持
+*********************************************************************************************************/
+#if (LW_CFG_VMM_EN == 0) && (LW_CFG_CSKY_MPU > 0)
+#include "arch/csky/inc/cskyregs.h"
+/*********************************************************************************************************
+ 可高缓区配置寄存器地址
+*********************************************************************************************************/
+#define CSKY_CACHE_CRCR(n) (*(volatile UINT32 *)(0xe000f008 + 0x4 * (n)))
+/*********************************************************************************************************
+ CRCR 寄存器定义
+*********************************************************************************************************/
+#define CSKY_CACHE_CRCR_OFF_EN 0
+#define CSKY_CACHE_CRCR_MASK_EN (0x1 << CSKY_CACHE_CRCR_OFF_EN)
+
+#define CSKY_CACHE_CRCR_OFF_SIZE 1
+#define CSKY_CACHE_CRCR_MASK_SIZE (0x1f << CSKY_CACHE_CRCR_OFF_SIZE)
+
+#define CSKY_CACHE_CRCR_OFF_BASE_ADDR 10
+#define CSKY_CACHE_CRCR_MASK_BASE_ADDR (0x3fffff << CSKY_CACHE_CRCR_OFF_BASE_ADDR)
+/*********************************************************************************************************
+ CAPR 寄存器定义
+*********************************************************************************************************/
+#define CSKY_MPU_CAPR_OFF_NX 0
+#define CSKY_MPU_CAPR_OFF_AP 8
+#define CSKY_MPU_CAPR_OFF_S 24
+/*********************************************************************************************************
+ PACR 寄存器定义
+*********************************************************************************************************/
+#define CSKY_MPU_PACR_OFF_E 0
+#define CSKY_MPU_PACR_MASK_E (0x1 << CSKY_MPU_PACR_OFF_E)
+
+#define CSKY_MPU_PACR_OFF_SIZE 1
+#define CSKY_MPU_PACR_MASK_SIZE (0x1f << CSKY_MPU_PACR_OFF_SIZE)
+
+#define CSKY_MPU_PACR_OFF_BASE_ADDR 12
+#define CSKY_MPU_PACR_MASK_BASE_ADDR (0xfffff << CSKY_MPU_PACR_OFF_BASE_ADDR)
+/*********************************************************************************************************
+ PRSR 寄存器定义
+*********************************************************************************************************/
+#define CSKY_MPU_PRSR_OFF_RID 0
+#define CSKY_MPU_PRSR_MASK_RID (0x7 << CSKY_MPU_PRSR_OFF_RID)
+/*********************************************************************************************************
+ DMA Pool
+*********************************************************************************************************/
+static LW_CLASS_HEAP _G_heapDmaPool;
+/*********************************************************************************************************
+** 函数名称: cskyMpuInit
+** 功能描述: 初始化 MPU
+** 输 入 : pcMachineName 机器名称
+** mpuregion 内存属性与布局表
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID cskyMpuInit (CPCHAR pcMachineName, const CSKY_MPU_REGION mpuregion[])
+{
+ PCSKY_MPU_REGION pmpuregion;
+ UINT32 uiCAPR;
+ UINT32 uiPACR;
+ UINT32 uiCRCR;
+ size_t stSize;
+
+ if (mpuregion == LW_NULL) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "MPU mpuregion[] invalid.\r\n");
+ return;
+ }
+
+ cskyMpuSetCCR(cskyMpuGetCCR() & ~1); /* 禁能 MPU */
+
+ for (pmpuregion = (PCSKY_MPU_REGION)mpuregion;
+ (pmpuregion->MPUD_ucSize != CSKY_MPU_REGION_SIZE_END) &&
+ (pmpuregion->MPUD_ucMpuNumber < LW_CFG_MPU_REGION_NUM);
+ pmpuregion++) {
+
+ cskyMpuSetPRSR((UINT32)pmpuregion->MPUD_ucMpuNumber); /* 选择保护区 */
+
+ if (pmpuregion->MPUD_bEnable) {
+ uiCAPR = cskyMpuGetCAPR();
+
+ uiPACR = cskyMpuGetPACR() & ~CSKY_MPU_PACR_MASK_BASE_ADDR; /* 设置基地址 */
+ uiPACR |= pmpuregion->MPUD_uiAddr & CSKY_MPU_PACR_MASK_BASE_ADDR;
+
+ if (pmpuregion->MPUD_ucSize != CSKY_MPU_REGION_SIZE_4KB) {
+ uiPACR &= ~(((1u << (pmpuregion->MPUD_ucSize - 11)) - 1) << 12);
+ }
+
+ uiPACR |= ((UINT32)(pmpuregion->MPUD_ucSize) << CSKY_MPU_PACR_OFF_SIZE) & CSKY_MPU_PACR_MASK_SIZE;
+ uiPACR |= (1 << CSKY_MPU_PACR_OFF_E);
+
+ uiCAPR &= ~((0x1 << pmpuregion->MPUD_ucMpuNumber) |
+ (0x3 << (pmpuregion->MPUD_ucMpuNumber * 2 + CSKY_MPU_CAPR_OFF_AP)) |
+ (0x1 << (pmpuregion->MPUD_ucMpuNumber + CSKY_MPU_CAPR_OFF_S)));
+ uiCAPR |= (((pmpuregion->MPUD_uiAttr & CSKY_MPU_ATTR_NX) >>
+ CSKY_MPU_ATTR_NX_POS) << pmpuregion->MPUD_ucMpuNumber) |
+ (((pmpuregion->MPUD_uiAttr & CSKY_MPU_ATTR_AP) >>
+ CSKY_MPU_ATTR_AP_POS) << (pmpuregion->MPUD_ucMpuNumber * 2 + CSKY_MPU_CAPR_OFF_AP)) |
+ (((pmpuregion->MPUD_uiAttr & CSKY_MPU_ATTR_S) >>
+ CSKY_MPU_ATTR_S_POS) << (pmpuregion->MPUD_ucMpuNumber + CSKY_MPU_CAPR_OFF_AP));
+
+ cskyMpuSetCAPR(uiCAPR);
+ cskyMpuSetPACR(uiPACR);
+
+ if (pmpuregion->MPUD_bDmaPool) {
+ stSize = ((size_t)2 << pmpuregion->MPUD_ucSize);
+ if (!_G_heapDmaPool.HEAP_stTotalByteSize) {
+ _HeapCtor(&_G_heapDmaPool,
+ (PVOID)pmpuregion->MPUD_uiAddr, stSize);
+
+ } else {
+ _HeapAddMemory(&_G_heapDmaPool, (PVOID)pmpuregion->MPUD_uiAddr, stSize);
+ }
+
+ } else {
+ uiCRCR = pmpuregion->MPUD_uiAddr & CSKY_CACHE_CRCR_MASK_BASE_ADDR;
+ uiCRCR |= (pmpuregion->MPUD_ucSize << CSKY_CACHE_CRCR_OFF_SIZE) &
+ CSKY_CACHE_CRCR_MASK_SIZE;
+ uiCRCR |= (1 << CSKY_CACHE_CRCR_OFF_EN);
+
+ CSKY_CACHE_CRCR(pmpuregion->MPUD_ucMpuNumber) = uiCRCR;
+ }
+
+ } else {
+ cskyMpuSetPACR(0);
+ }
+ }
+
+ cskyMpuSetCCR(cskyMpuGetCCR() | 1); /* 使能 MPU */
+}
+/*********************************************************************************************************
+** 函数名称: cskyMpuDmaAlloc
+** 功能描述: 从 DMA 内存池中分配内存
+** 输 入 : stSize 需要的内存大小
+** 输 出 : 内存首地址
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+PVOID cskyMpuDmaAlloc (size_t stSize)
+{
+ if (_G_heapDmaPool.HEAP_stTotalByteSize) {
+ return (_HeapAllocate(&_G_heapDmaPool, stSize, __func__));
+
+ } else {
+ return (LW_NULL);
+ }
+}
+/*********************************************************************************************************
+** 函数名称: cskyMpuDmaAllocAlign
+** 功能描述: 从 DMA 内存池中分配内存
+** 输 入 : stSize 需要的内存大小
+** stAlign 对齐要求
+** 输 出 : 内存首地址
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+PVOID cskyMpuDmaAllocAlign (size_t stSize, size_t stAlign)
+{
+ if (_G_heapDmaPool.HEAP_stTotalByteSize) {
+ return (_HeapAllocateAlign(&_G_heapDmaPool, stSize, stAlign, __func__));
+
+ } else {
+ return (LW_NULL);
+ }
+}
+/*********************************************************************************************************
+** 函数名称: cskyMpuDmaFree
+** 功能描述: 释放从 DMA 内存池中分配的内存
+** 输 入 : pvDmaMem 内存首地址
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID cskyMpuDmaFree (PVOID pvDmaMem)
+{
+ if (_G_heapDmaPool.HEAP_stTotalByteSize) {
+ _HeapFree(&_G_heapDmaPool, pvDmaMem, LW_FALSE, __func__);
+ }
+}
+
+#endif /* LW_CFG_CSKY_MPU > 0 */
+#endif /* __SYLIXOS_CSKY_ARCH_CK803__ */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/mm/mpu/cskyMpu.h b/SylixOS/arch/csky/mm/mpu/cskyMpu.h
new file mode 100644
index 0000000..0ab47e7
--- /dev/null
+++ b/SylixOS/arch/csky/mm/mpu/cskyMpu.h
@@ -0,0 +1,33 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM)
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: cskyMpu.h
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2018 年 11 月 12 日
+**
+** 描 述: C-SKY 体系架构 MPU 驱动.
+*********************************************************************************************************/
+
+#ifndef __CSKYMPU_H
+#define __CSKYMPU_H
+
+VOID cskyMpuInit(CPCHAR pcMachineName, const CSKY_MPU_REGION mpuregion[]);
+PVOID cskyMpuDmaAlloc(size_t stSize);
+PVOID cskyMpuDmaAllocAlign(size_t stSize, size_t stAlign);
+VOID cskyMpuDmaFree(PVOID pvDmaMem);
+
+#endif /* __CSKYMPU_H */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/arch/mips/common/mipsLibAsm.S b/SylixOS/arch/mips/common/mipsLibAsm.S
index 32fec95..1159413 100644
--- a/SylixOS/arch/mips/common/mipsLibAsm.S
+++ b/SylixOS/arch/mips/common/mipsLibAsm.S
@@ -300,6 +300,12 @@ FUNC_DEF(archReboot)
FUNC_DEF(archBogoMipsLoop)
1:
+ LI T1 , 1
+ LI T2 , 2
+ LI T3 , 3
+ LI T1 , 1
+ LI T2 , 2
+ LI T3 , 3
BNE A0 , ZERO , 1b
REG_SUBU A0 , 1
JR RA
diff --git a/SylixOS/arch/mips/dbg/mipsDbg.c b/SylixOS/arch/mips/dbg/mipsDbg.c
index 2223979..9a88f55 100644
--- a/SylixOS/arch/mips/dbg/mipsDbg.c
+++ b/SylixOS/arch/mips/dbg/mipsDbg.c
@@ -108,6 +108,24 @@ VOID archDbgBpRemove (addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal
#endif /* LW_CFG_CACHE_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: archDbgApRemove
+** 功能描述: 删除一个终止点.
+** 输 入 : ulAddr 终止点地址
+** pulIns 返回的之前的指令
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDbgApRemove (addr_t ulAddr, ULONG ulIns)
+{
+ lib_memcpy((PCHAR)ulAddr, (PCHAR)&ulIns, sizeof(MIPS_INSTRUCTION));
+ KN_SMP_MB();
+
+#if LW_CFG_CACHE_EN > 0
+ API_CacheTextUpdate((PVOID)ulAddr, sizeof(MIPS_INSTRUCTION));
+#endif /* LW_CFG_CACHE_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: archDbgBpPrefetch
** 功能描述: 预取一个指令.
当指令处于 MMU 共享物理段时, 指令空间为物理只读, 这里需要产生一次缺页中断, 克隆一个物理页面.
diff --git a/SylixOS/arch/mips/mips_support.h b/SylixOS/arch/mips/mips_support.h
index b79dc5a..ac2da34 100644
--- a/SylixOS/arch/mips/mips_support.h
+++ b/SylixOS/arch/mips/mips_support.h
@@ -110,6 +110,7 @@ VOIDFUNCPTR mipsIdleHookGet(CPCHAR pcMachineName);
VOID archDbgBpInsert(addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLocal);
VOID archDbgAbInsert(addr_t ulAddr, ULONG *pulIns);
VOID archDbgBpRemove(addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal);
+VOID archDbgApRemove(addr_t ulAddr, ULONG ulIns);
VOID archDbgBpPrefetch(addr_t ulAddr);
UINT archDbgTrapType(addr_t ulAddr, PVOID pvArch);
VOID archDbgBpAdjust(PVOID pvDtrace, PVOID pvtm);
@@ -153,7 +154,7 @@ VOID archReboot(INT iRebootType, addr_t ulStartAddress);
VOID archBogoMipsLoop(ULONG ulLoop);
#define __ARCH_BOGOMIPS_LOOP archBogoMipsLoop
-#define __ARCH_BOGOMIPS_INS_PER_LOOP 2
+#define __ARCH_BOGOMIPS_INS_PER_LOOP 8
/*********************************************************************************************************
MIPS 处理器 CACHE 操作
diff --git a/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c b/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c
index 49a0e79..c78fa5f 100644
--- a/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c
+++ b/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c
@@ -183,7 +183,7 @@ VOID mipsMmuDumpTLB (VOID)
ulEntryHi = mipsCp0EntryHiRead();
ulPageMask = mipsCp0PageMaskRead();
- _PrintFormat("TLB[%02d]: EntryLo0="LX_FMT", EntryLo1=0x%"LX_FMT", "
+ _PrintFormat("TLB[%02d]: EntryLo0="LX_FMT", EntryLo1="LX_FMT", "
"EntryHi="LX_FMT", PageMask="LX_FMT"\r\n",
i, ulEntryLo0, ulEntryLo1, ulEntryHi, ulPageMask);
}
diff --git a/SylixOS/arch/ppc/common/ppcLibAsm.S b/SylixOS/arch/ppc/common/ppcLibAsm.S
index a77a50d..633164f 100644
--- a/SylixOS/arch/ppc/common/ppcLibAsm.S
+++ b/SylixOS/arch/ppc/common/ppcLibAsm.S
@@ -275,6 +275,12 @@ FUNC_DEF(archReboot)
FUNC_DEF(archBogoMipsLoop)
1:
+ LI R4 , 4
+ LI R5 , 5
+ LI R6 , 6
+ LI R4 , 4
+ LI R5 , 5
+ LI R6 , 6
SUBI R3 , R3 , 1
CMPWI CR0, R3 , 0
BNE CR0, 1b
diff --git a/SylixOS/arch/ppc/dbg/ppcDbg.c b/SylixOS/arch/ppc/dbg/ppcDbg.c
index 3f6ce3b..47df447 100644
--- a/SylixOS/arch/ppc/dbg/ppcDbg.c
+++ b/SylixOS/arch/ppc/dbg/ppcDbg.c
@@ -122,6 +122,28 @@ VOID archDbgBpRemove (addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLoca
#endif /* LW_CFG_CACHE_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: archDbgApRemove
+** 功能描述: 删除一个终止点.
+** 输 入 : ulAddr 终止点地址
+** pulIns 返回的之前的指令
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDbgApRemove (addr_t ulAddr, ULONG ulIns)
+{
+#if LW_CFG_VMM_EN > 0
+ archMmuDataTlbPreLoad(ulAddr);
+#endif
+
+ lib_memcpy((PCHAR)ulAddr, (PCHAR)&ulIns, sizeof(ULONG));
+ KN_SMP_MB();
+
+#if LW_CFG_CACHE_EN > 0
+ API_CacheTextUpdate((PVOID)ulAddr, sizeof(ULONG));
+#endif /* LW_CFG_CACHE_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: archDbgBpPrefetch
** 功能描述: 预取一个指令.
当指令处于 MMU 共享物理段时, 指令空间为物理只读, 这里需要产生一次缺页中断, 克隆一个物理页面.
diff --git a/SylixOS/arch/ppc/ppc_support.h b/SylixOS/arch/ppc/ppc_support.h
index 0c24b4d..0657111 100644
--- a/SylixOS/arch/ppc/ppc_support.h
+++ b/SylixOS/arch/ppc/ppc_support.h
@@ -102,6 +102,7 @@ PLW_STACK archCtxStackEnd(const ARCH_REG_CTX *pregctx);
VOID archDbgBpInsert(addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLocal);
VOID archDbgAbInsert(addr_t ulAddr, ULONG *pulIns);
VOID archDbgBpRemove(addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal);
+VOID archDbgApRemove(addr_t ulAddr, ULONG ulIns);
VOID archDbgBpPrefetch(addr_t ulAddr);
UINT archDbgTrapType(addr_t ulAddr, PVOID pvArch);
VOID archDbgBpAdjust(PVOID pvDtrace, PVOID pvtm);
@@ -145,7 +146,7 @@ VOID archReboot(INT iRebootType, addr_t ulStartAddress);
VOID archBogoMipsLoop(ULONG ulLoop);
#define __ARCH_BOGOMIPS_LOOP archBogoMipsLoop
-#define __ARCH_BOGOMIPS_INS_PER_LOOP 3
+#define __ARCH_BOGOMIPS_INS_PER_LOOP 9
/*********************************************************************************************************
PowerPC 处理器定义
diff --git a/SylixOS/arch/riscv/common/riscvLibAsm.S b/SylixOS/arch/riscv/common/riscvLibAsm.S
index 0637a87..5081d65 100644
--- a/SylixOS/arch/riscv/common/riscvLibAsm.S
+++ b/SylixOS/arch/riscv/common/riscvLibAsm.S
@@ -235,6 +235,12 @@ FUNC_DEF(archReboot)
FUNC_DEF(archBogoMipsLoop)
LI T0 , 1
LINE_LABEL(again)
+ LI T1 , 1
+ LI T2 , 2
+ LI T3 , 3
+ LI T1 , 1
+ LI T2 , 2
+ LI T3 , 3
SUB A0 , A0 , T0
BNEZ A0 , again
RET
diff --git a/SylixOS/arch/riscv/dbg/riscvDbg.c b/SylixOS/arch/riscv/dbg/riscvDbg.c
index 8e7b394..01ab183 100644
--- a/SylixOS/arch/riscv/dbg/riscvDbg.c
+++ b/SylixOS/arch/riscv/dbg/riscvDbg.c
@@ -29,7 +29,6 @@
RISC-V 断点指令 (必须支持压缩指令)
*********************************************************************************************************/
#define RISCV_BREAKPOINT_INS 0x9002
-#define RISCV_ABORTPOINT_INS 0x9003 /* TODO */
/*********************************************************************************************************
SMP
*********************************************************************************************************/
@@ -76,7 +75,7 @@ VOID archDbgBpInsert (addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLoc
VOID archDbgAbInsert (addr_t ulAddr, ULONG *pulIns)
{
*pulIns = *(ULONG *)ulAddr;
- *(UINT16 *)ulAddr = RISCV_ABORTPOINT_INS;
+ *(UINT16 *)ulAddr = RISCV_BREAKPOINT_INS;
KN_SMP_MB();
#if LW_CFG_CACHE_EN > 0
@@ -108,6 +107,24 @@ VOID archDbgBpRemove (addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal
#endif /* LW_CFG_CACHE_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: archDbgApRemove
+** 功能描述: 删除一个终止点.
+** 输 入 : ulAddr 终止点地址
+** pulIns 返回的之前的指令
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDbgApRemove (addr_t ulAddr, ULONG ulIns)
+{
+ lib_memcpy((PCHAR)ulAddr, (PCHAR)&ulIns, sizeof(UINT16));
+ KN_SMP_MB();
+
+#if LW_CFG_CACHE_EN > 0
+ API_CacheTextUpdate((PVOID)ulAddr, sizeof(UINT16));
+#endif /* LW_CFG_CACHE_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: archDbgBpPrefetch
** 功能描述: 预取一个指令.
当指令处于 MMU 共享物理段时, 指令空间为物理只读, 这里需要产生一次缺页中断, 克隆一个物理页面.
@@ -133,24 +150,23 @@ VOID archDbgBpPrefetch (addr_t ulAddr)
*********************************************************************************************************/
UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
{
+ PLW_CLASS_TCB ptcbCur;
#if (LW_CFG_SMP_EN > 0) && (LW_CFG_CACHE_EN > 0) && (LW_CFG_GDB_SMP_TU_LAZY > 0)
- ULONG ulCPUId;
+ ULONG ulCPUId;
#endif /* LW_CFG_SMP_EN > 0 */
if (API_DtraceIsValid() == LW_FALSE) { /* 不存在调试节点 */
return (LW_TRAP_INVAL);
}
- switch (*(UINT16 *)ulAddr) {
-
- case RISCV_BREAKPOINT_INS:
- return (LW_TRAP_BRKPT);
+ if (*(UINT16 *)ulAddr == RISCV_BREAKPOINT_INS) {
+ LW_TCB_GET_CUR_SAFE(ptcbCur);
- case RISCV_ABORTPOINT_INS:
- return (LW_TRAP_ABORT);
-
- default:
- break;
+ if (ptcbCur->TCB_ulAbortPointAddr == ulAddr) {
+ return (LW_TRAP_ABORT);
+ } else {
+ return (LW_TRAP_BRKPT);
+ }
}
#if (LW_CFG_SMP_EN > 0) && (LW_CFG_CACHE_EN > 0) && (LW_CFG_GDB_SMP_TU_LAZY > 0)
diff --git a/SylixOS/arch/riscv/riscv_support.h b/SylixOS/arch/riscv/riscv_support.h
index 577a0c6..fb1b3a3 100644
--- a/SylixOS/arch/riscv/riscv_support.h
+++ b/SylixOS/arch/riscv/riscv_support.h
@@ -104,6 +104,7 @@ PLW_STACK archCtxStackEnd(const ARCH_REG_CTX *pregctx);
VOID archDbgBpInsert(addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLocal);
VOID archDbgAbInsert(addr_t ulAddr, ULONG *pulIns);
VOID archDbgBpRemove(addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal);
+VOID archDbgApRemove(addr_t ulAddr, ULONG ulIns);
VOID archDbgBpPrefetch(addr_t ulAddr);
UINT archDbgTrapType(addr_t ulAddr, PVOID pvArch);
VOID archDbgBpAdjust(PVOID pvDtrace, PVOID pvtm);
@@ -148,7 +149,7 @@ VOID archReboot(INT iRebootType, addr_t ulStartAddress);
VOID archBogoMipsLoop(ULONG ulLoop);
#define __ARCH_BOGOMIPS_LOOP archBogoMipsLoop
-#define __ARCH_BOGOMIPS_INS_PER_LOOP 2
+#define __ARCH_BOGOMIPS_INS_PER_LOOP 8
/*********************************************************************************************************
RISC-V 处理器 CACHE 操作
diff --git a/SylixOS/arch/sparc/common/sparcLibAsm.S b/SylixOS/arch/sparc/common/sparcLibAsm.S
index 332e8ff..026f138 100644
--- a/SylixOS/arch/sparc/common/sparcLibAsm.S
+++ b/SylixOS/arch/sparc/common/sparcLibAsm.S
@@ -286,6 +286,12 @@ FUNC_END(archReboot)
FUNC_DEF(archBogoMipsLoop)
LINE_LABEL(bogo_loop)
+ MOV 1 , %o1
+ MOV 2 , %o2
+ MOV 3 , %o3
+ MOV 1 , %o1
+ MOV 2 , %o2
+ MOV 3 , %o3
SUBCC %o0 , 0x1 , %o0
BNE bogo_loop
NOP
diff --git a/SylixOS/arch/sparc/dbg/sparcDbg.c b/SylixOS/arch/sparc/dbg/sparcDbg.c
index 9308e4d..1eeeca3 100644
--- a/SylixOS/arch/sparc/dbg/sparcDbg.c
+++ b/SylixOS/arch/sparc/dbg/sparcDbg.c
@@ -108,6 +108,24 @@ VOID archDbgBpRemove (addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal
#endif /* LW_CFG_CACHE_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: archDbgApRemove
+** 功能描述: 删除一个终止点.
+** 输 入 : ulAddr 终止点地址
+** pulIns 返回的之前的指令
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDbgApRemove (addr_t ulAddr, ULONG ulIns)
+{
+ lib_memcpy((PCHAR)ulAddr, (PCHAR)&ulIns, sizeof(ULONG));
+ KN_SMP_MB();
+
+#if LW_CFG_CACHE_EN > 0
+ API_CacheTextUpdate((PVOID)ulAddr, sizeof(ULONG));
+#endif /* LW_CFG_CACHE_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: archDbgBpPrefetch
** 功能描述: 预取一个指令.
当指令处于 MMU 共享物理段时, 指令空间为物理只读, 这里需要产生一次缺页中断, 克隆一个物理页面.
diff --git a/SylixOS/arch/sparc/sparc_support.h b/SylixOS/arch/sparc/sparc_support.h
index fab1b83..f528547 100644
--- a/SylixOS/arch/sparc/sparc_support.h
+++ b/SylixOS/arch/sparc/sparc_support.h
@@ -102,6 +102,7 @@ PLW_STACK archCtxStackEnd(const ARCH_REG_CTX *pregctx);
VOID archDbgBpInsert(addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLocal);
VOID archDbgAbInsert(addr_t ulAddr, ULONG *pulIns);
VOID archDbgBpRemove(addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal);
+VOID archDbgApRemove(addr_t ulAddr, ULONG ulIns);
VOID archDbgBpPrefetch(addr_t ulAddr);
UINT archDbgTrapType(addr_t ulAddr, PVOID pvArch);
VOID archDbgBpAdjust(PVOID pvDtrace, PVOID pvtm);
@@ -146,7 +147,7 @@ VOID archReboot(INT iRebootType, addr_t ulStartAddress);
VOID archBogoMipsLoop(ULONG ulLoop);
#define __ARCH_BOGOMIPS_LOOP archBogoMipsLoop
-#define __ARCH_BOGOMIPS_INS_PER_LOOP 3
+#define __ARCH_BOGOMIPS_INS_PER_LOOP 9
/*********************************************************************************************************
SPARC 处理器定义
diff --git a/SylixOS/arch/x86/acpi/x86AcpiSylixOS.c b/SylixOS/arch/x86/acpi/x86AcpiSylixOS.c
index b721fc1..0a3e084 100644
--- a/SylixOS/arch/x86/acpi/x86AcpiSylixOS.c
+++ b/SylixOS/arch/x86/acpi/x86AcpiSylixOS.c
@@ -846,6 +846,7 @@ ACPI_STATUS AcpiOsExecute (ACPI_EXECUTE_TYPE Type,
if (LW_SYS_STATUS_IS_RUNNING()) {
LW_CLASS_THREADATTR threadattr = API_ThreadAttrGetDefault();
+ threadattr.THREADATTR_ulOption |= LW_OPTION_OBJECT_GLOBAL;
threadattr.THREADATTR_pvArg = Context;
API_ThreadCreate("t_acpi", (PTHREAD_START_ROUTINE)Function, &threadattr, LW_NULL);
diff --git a/SylixOS/arch/x86/apic/x86IoApic.c b/SylixOS/arch/x86/apic/x86IoApic.c
index d2a689d..beff441 100644
--- a/SylixOS/arch/x86/apic/x86IoApic.c
+++ b/SylixOS/arch/x86/apic/x86IoApic.c
@@ -496,18 +496,17 @@ static INT __x86IoApicInit (PX86_IOAPIC_INTR pIoApicIntr)
* hardwired to FSB delivery.
*/
if (((pIoApicIntr->IOAPIC_uiVersion & IOAPIC_VERSION_MASK) >= 0x20)) {
- if (X86_FEATURE_PROCESSOR_FAMILY >= X86_FAMILY_PENTIUM4) {
- /*
- * Pentium4 and later use FSB for interrupt delivery
- */
- __x86IoApicRegSet(pIoApicIntr, IOAPIC_BOOT, IOAPIC_DT_FS);
-
- } else {
- /*
- * Pentium up to and including P6 use APIC bus
- */
- __x86IoApicRegSet(pIoApicIntr, IOAPIC_BOOT, IOAPIC_DT_APIC);
- }
+#if LW_CFG_CPU_X86_APIC_BUS_INT > 0
+ /*
+ * Pentium up to and including P6 use APIC bus
+ */
+ __x86IoApicRegSet(pIoApicIntr, IOAPIC_BOOT, IOAPIC_DT_APIC);
+#else
+ /*
+ * Pentium4 and later use FSB for interrupt delivery
+ */
+ __x86IoApicRegSet(pIoApicIntr, IOAPIC_BOOT, IOAPIC_DT_FS);
+#endif /* X86_APIC_BUS_INT > 0 */
}
uiRteValue = IOAPIC_EDGE | /* 边沿信号触发 */
diff --git a/SylixOS/arch/x86/apic/x86LocalApic.c b/SylixOS/arch/x86/apic/x86LocalApic.c
index 9c559e5..56c4f43 100644
--- a/SylixOS/arch/x86/apic/x86LocalApic.c
+++ b/SylixOS/arch/x86/apic/x86LocalApic.c
@@ -317,43 +317,11 @@ static VOID __x86LocalApicEnable (PX86_LOAPIC_INTR pLoApicIntr, BOOL bEnable)
INT x86LocalApicInit (UINT *puiLocalApicIntNr)
{
PX86_LOAPIC_INTR pLoApicIntr = &_G_x86LocalApicIntrs[LW_CPU_GET_CUR_ID()];
- UINT64 ui64ApicBase;
INT iCoreNum;
pLoApicIntr->LOAPIC_pcBase = (CHAR *)LOCAL_APIC_BASE;
pLoApicIntr->LOAPIC_uiIntMask = 0;
- if (X86_FEATURE_HAS_APIC && (X86_FEATURE_PROCESSOR_FAMILY != X86_FAMILY_PENTIUM)) {
- CHAR *pcMpApicLoBase;
- INT i;
-
- x86PentiumMsrGet(X86_MSR_APICBASE, (UINT64 *)&ui64ApicBase);
- pcMpApicLoBase = (CHAR *)((ULONG)ui64ApicBase & LOAPIC_BASE_MASK);
-
- if (pLoApicIntr->LOAPIC_pcBase != pcMpApicLoBase) {
- ui64ApicBase &= ~LOAPIC_BASE_MASK;
- ui64ApicBase |= LOCAL_APIC_BASE;
- }
-
- /*
- * Enable the Local APIC explicitly by making sure
- * it is disabled first. A toggle will make sure
- * interrupts are cleared.
- */
- ui64ApicBase &= ~(LOAPIC_GLOBAL_ENABLE); /* Clear Enable bit */
- x86PentiumMsrSet(X86_MSR_APICBASE, &ui64ApicBase);
-
- /*
- * Delays 50usec
- */
- for (i = 0; i < 70; i++) { /* 70*720 ~= 50.4usec */
- bspDelay720Ns(); /* 720ns */
- }
-
- ui64ApicBase |= LOAPIC_GLOBAL_ENABLE; /* Set Enable bit */
- x86PentiumMsrSet(X86_MSR_APICBASE, &ui64ApicBase);
- }
-
/*
* Remember the original state: SVR, LINT0, LINT1 for now
*/
diff --git a/SylixOS/arch/x86/common/x64/x64LibAsm.S b/SylixOS/arch/x86/common/x64/x64LibAsm.S
index d3e4aea..e7b6898 100644
--- a/SylixOS/arch/x86/common/x64/x64LibAsm.S
+++ b/SylixOS/arch/x86/common/x64/x64LibAsm.S
@@ -293,6 +293,12 @@ FUNC_DEF(archReboot)
FUNC_DEF(archBogoMipsLoop)
1:
+ MOV $1 , X86_64_ARG1
+ MOV $2 , X86_64_ARG2
+ MOV $3 , X86_64_ARG3
+ MOV $1 , X86_64_ARG1
+ MOV $2 , X86_64_ARG2
+ MOV $3 , X86_64_ARG3
DEC X86_64_ARG0
JNS 1b
RET
diff --git a/SylixOS/arch/x86/common/x86CpuId.c b/SylixOS/arch/x86/common/x86CpuId.c
index 50799e4..239fb48 100644
--- a/SylixOS/arch/x86/common/x86CpuId.c
+++ b/SylixOS/arch/x86/common/x86CpuId.c
@@ -52,63 +52,6 @@
*********************************************************************************************************/
static UINT64 _G_ui64X86CpuIdFreq = 1000000000ULL; /* CPU 主频, 缺省为 1GHz */
-static X86_CPUID_ENTRY _G_x86CpuIdTable[] = { /* CPUID 条目表 */
- {X86_CPUID_PENTIUM, X86_FAMILY_PENTIUM},
- {X86_CPUID_PENTIUM4, X86_FAMILY_PENTIUM4},
- {X86_CPUID_CORE, X86_FAMILY_CORE},
- {X86_CPUID_CORE2, X86_FAMILY_CORE},
- {X86_CPUID_CORE2_DUO, X86_FAMILY_CORE},
- {X86_CPUID_XEON_5400, X86_FAMILY_NEHALEM},
- {X86_CPUID_XEON_7400, X86_FAMILY_NEHALEM},
- {X86_CPUID_XEON_5500, X86_FAMILY_NEHALEM},
- {X86_CPUID_XEON_C5500, X86_FAMILY_NEHALEM},
- {X86_CPUID_XEON_5600, X86_FAMILY_NEHALEM},
- {X86_CPUID_XEON_7500, X86_FAMILY_NEHALEM},
- {X86_CPUID_COREI5_I7M, X86_FAMILY_NEHALEM},
- {X86_CPUID_XEON_32NM, X86_FAMILY_NEHALEM},
- {X86_CPUID_ATOM, X86_FAMILY_ATOM},
- {X86_CPUID_SANDYBRIDGE, X86_FAMILY_SANDYBRIDGE},
- {X86_CPUID_CEDARVIEW, X86_FAMILY_ATOM},
- {X86_CPUID_SILVERMONT, X86_FAMILY_ATOM},
-
- {X86_CPUID_HASWELL_CLIENT, X86_FAMILY_HASWELL},
- {X86_CPUID_HASWELL_SERVER, X86_FAMILY_HASWELL},
- {X86_CPUID_HASWELL_ULT, X86_FAMILY_HASWELL},
- {X86_CPUID_CRYSTAL_WELL, X86_FAMILY_HASWELL},
-
- {X86_CPUID_MINUTEIA, X86_FAMILY_MINUTEIA},
-
- {X86_CPUID_DUMMY, X86_CPUID_DUMMY},
- {X86_CPUID_DUMMY, X86_CPUID_DUMMY},
- {X86_CPUID_DUMMY, X86_CPUID_DUMMY},
- {X86_CPUID_DUMMY, X86_CPUID_DUMMY},
- {X86_CPUID_DUMMY, X86_CPUID_DUMMY},
- {X86_CPUID_DUMMY, X86_CPUID_DUMMY},
- {X86_CPUID_DUMMY, X86_CPUID_DUMMY},
- {X86_CPUID_DUMMY, X86_CPUID_DUMMY},
- {X86_CPUID_DUMMY, X86_CPUID_DUMMY}};
-
-static INT _G_iX86CpuEntriesNr = \
- sizeof(_G_x86CpuIdTable) / sizeof(X86_CPUID_ENTRY); /* CPUID 条目数 */
-
-const static CHAR *_G_pcX86CpuFamilyNames[] = { /* CPU 家族名字表 */
- "Not Supported", /* 0 */
- "Not Supported", /* 1 */
- "Pentium", /* 2 */
- "Not Supported", /* 3 */
- "Not Supported", /* 4 */
- "Pentium 4", /* 5 */
- "Core", /* 6 */
- "Atom", /* 7 */
- "Nehalem", /* 8 */
- "Sandy Bridge", /* 9 */
- "Haswell", /* 10 */
- "Quark" /* 11 */
-};
-
-const static INT _G_iCpuFamilyNr = \
- sizeof(_G_pcX86CpuFamilyNames) / sizeof(CHAR *); /* CPU 家族名字数 */
-
const static CHAR *_G_pcX86CacheTypes[] = { /* CACHE 类型表 */
"Null", /* 0 */
"Data", /* 1 */
@@ -153,7 +96,6 @@ X86_CPU_FEATURE _G_x86CpuFeature = { /* 全局
.CPUF_stCacheFlushBytes = X86_CLFLUSH_DEF_BYTES, /* CLFLUSH 字节数 */
.CPUF_bHasCLFlush = LW_FALSE, /* Has CLFLUSH inst? */
.CPUF_bHasAPIC = LW_FALSE, /* Has APIC on chip? */
- .CPUF_uiProcessorFamily = X86_FAMILY_UNSUPPORTED, /* Processor Family */
.CPUF_bHasX87FPU = LW_FALSE, /* Has X87 FPU? */
.CPUF_bHasSSE = LW_FALSE, /* Has SSE? */
.CPUF_bHasSSE2 = LW_FALSE, /* Has SSE? */
@@ -257,32 +199,6 @@ X86_CPUID *x86CpuIdGet (VOID)
return (&_G_x86CpuId);
}
/*********************************************************************************************************
-** 函数名称: x86CpuIdAdd
-** 功能描述: 增加一个新的 X86_CPUID_ENTRY 到支持的 CPUID 条目表
-** 输 入 : pentry CPUID 条目
-** 输 出 : ERROR CODE
-** 全局变量:
-** 调用模块:
-*********************************************************************************************************/
-INT x86CpuIdAdd (X86_CPUID_ENTRY *pentry)
-{
- X86_CPUID_ENTRY *pcur = LW_NULL;
- INT i;
- INT iError = PX_ERROR;
-
- for (i = 0; i < _G_iX86CpuEntriesNr; i++) {
- pcur = &_G_x86CpuIdTable[i];
- if (pcur->signature == X86_CPUID_DUMMY) {
- pcur->signature = pentry->signature;
- pcur->family = pentry->family;
- iError = ERROR_NONE;
- break;
- }
- }
-
- return (iError);
-}
-/*********************************************************************************************************
** 函数名称: x86CpuIdOverride
** 功能描述: 覆盖 CPU 特性
** 输 入 : pentries 覆盖的 CPUID 条目
@@ -343,7 +259,6 @@ VOID x86CpuIdProbe (VOID)
X86_CPUID_ECX_CACHE_PARAMS cacheEcx[4];
X86_CPUID_EDX_FEATURES features;
X86_CPUID_ECX_FEATURES extendedFeatures;
- UINT uiCpuId;
CHAR *pcLine;
INT i;
CHAR cTemp[256];
@@ -354,22 +269,6 @@ VOID x86CpuIdProbe (VOID)
extendedFeatures.value = pcpuid->std.featuresEcx;
/*
- * 识别 Intel 处理器家族类型码
- */
- uiCpuId = pcpuid->std.signature & (X86_CPUID_FAMILY | X86_CPUID_MODEL | X86_CPUID_EXT_MODEL);
-
- for (i = 0; i < _G_iX86CpuEntriesNr; i++) {
- if (_G_x86CpuIdTable[i].signature == uiCpuId) {
- pcpufeature->CPUF_uiProcessorFamily = _G_x86CpuIdTable[i].family;
- break;
- }
- }
-
- if (pcpufeature->CPUF_uiProcessorFamily == X86_FAMILY_UNSUPPORTED) {
- pcpufeature->CPUF_uiProcessorFamily = X86_FAMILY_PENTIUM;
- }
-
- /*
* 识别 CPU 名字
*/
if (pcpuid->ext.highestExtValue >= 0x80000002) {
@@ -471,7 +370,6 @@ VOID x86CpuIdProbe (VOID)
VOID x86CpuIdShow (VOID)
{
X86_CPUID *pcpuid = &_G_x86CpuId;
- X86_CPUID_ENTRY *pentry;
X86_CPUID_INFO info;
X86_CPUID_VERSION version;
X86_CPUID_EDX_FEATURES features;
@@ -512,11 +410,8 @@ VOID x86CpuIdShow (VOID)
X86_CPUID_EAX_VPADRSIZES_PARAMS vpadrEax;
UINT64 ulCpuSerial;
- CHAR *pcCpuTypeName = LW_NULL;
CHAR *pcLine;
- UINT uiX86Processor = X86_FAMILY_UNSUPPORTED;
- INT i, iCpuIdMask;
-
+ INT i;
lib_bzero((VOID *)cacheEax, 4 * sizeof(X86_CPUID_EAX_CACHE_PARAMS));
lib_bzero((VOID *)cacheEbx, 4 * sizeof(X86_CPUID_EAX_CACHE_PARAMS));
@@ -566,39 +461,6 @@ VOID x86CpuIdShow (VOID)
version.field.stepid,
version.field.family, version.field.familyExt);
- switch ((INT)version.field.type) {
-
- case X86_CPUID_ORIG:
- pcCpuTypeName = "original OEM";
- break;
-
- case X86_CPUID_OVERD:
- pcCpuTypeName = "overdrive";
- break;
-
- case X86_CPUID_DUAL:
- pcCpuTypeName = "dual";
- break;
-
- default:
- pcCpuTypeName = "<unknown>";
- break;
- }
-
- iCpuIdMask = X86_CPUID_FAMILY | X86_CPUID_MODEL | X86_CPUID_EXT_MODEL;
- for (i = 0; i < _G_iX86CpuEntriesNr; i++) {
- pentry = &_G_x86CpuIdTable[i];
- if ((pentry->signature & iCpuIdMask) == (pcpuid->std.signature & iCpuIdMask)) {
- uiX86Processor = pentry->family;
- break;
- }
- }
-
- printf(" x86 processor architecture is %s, type %s\n",
- ((uiX86Processor <= _G_iCpuFamilyNr) && (uiX86Processor != X86_FAMILY_UNSUPPORTED)) ?
- _G_pcX86CpuFamilyNames[uiX86Processor] : "unsupported",
- pcCpuTypeName);
-
if (features.field.psnum) {
ulCpuSerial = (UINT64)pcpuid->std.serialNo64[0] << 32 | pcpuid->std.serialNo64[1];
printf(" CPU serial number: %lld\n", ulCpuSerial);
diff --git a/SylixOS/arch/x86/common/x86CpuId.h b/SylixOS/arch/x86/common/x86CpuId.h
index 06d0ef7..aac4b66 100644
--- a/SylixOS/arch/x86/common/x86CpuId.h
+++ b/SylixOS/arch/x86/common/x86CpuId.h
@@ -188,92 +188,6 @@
#define X86_CPUID_EXT_MODEL_SANDYBRIDGE 0x00020000
/*********************************************************************************************************
- CPU TYPE
-*********************************************************************************************************/
-
-#define X86_CPUID_ORIG 0x00000000 /* Type: original OEM */
-#define X86_CPUID_OVERD 0x00001000 /* Type: overdrive */
-#define X86_CPUID_DUAL 0x00002000 /* Type: dual */
-
-/*********************************************************************************************************
- CPUID definitions
-*********************************************************************************************************/
-
-#define X86_CPUID_UNSUPPORTED 0xffffffff /* Family: not supported */
-
-/*********************************************************************************************************
- Pentium microarchitecture CPUIDs
-*********************************************************************************************************/
-
-#define X86_CPUID_PENTIUM 0x00000500 /* Family: Pentium */
-#define X86_CPUID_MINUTEIA 0x00000590 /* Family: MinuteIA/Quark */
-#define X86_CPUID_PENTIUM4 0x00000000 /* Extended family: PENTIUM4 */
-
-/*********************************************************************************************************
- Core microarchitecture CPUIDs
-*********************************************************************************************************/
-
-#define X86_CPUID_CORE 0x000006e0 /* Core Solo/Duo */
-#define X86_CPUID_CORE2 0x000006f0 /* Core2 */
-#define X86_CPUID_CORE2_DUO 0x00010670 /* Core2 Duo */
-#define X86_CPUID_XEON_5400 0x00010670 /* Xeon 52xx/54xx */
-#define X86_CPUID_XEON_7400 0x000106d0 /* Xeon 74xx Core2 */
-
-/*********************************************************************************************************
- Nehalem microarchitecture CPUIDs
-*********************************************************************************************************/
-
-#define X86_CPUID_XEON_5500 0x000106a0 /* Xeon 55xx */
-#define X86_CPUID_XEON_C5500 0x000106e0 /* Xeon C35xx/C55xx */
-#define X86_CPUID_XEON_5600 0x000206c0 /* Xeon 56xx */
-#define X86_CPUID_XEON_7500 0x000206e0 /* Xeon 65xx/75xx */
-#define X86_CPUID_XEON_32NM 0x000206f0 /* Xeon 65xx/75xx 32 NM */
-#define X86_CPUID_COREI5_I7M 0x00020650 /* Arrandale i3 or i5/i7 Mobile 6xx/5xx */
-
-/*********************************************************************************************************
- Atom microarchitecture CPUIDs
-*********************************************************************************************************/
-
-#define X86_CPUID_ATOM 0x000106c0 /* Atom */
-#define X86_CPUID_CEDARVIEW 0x00030660 /* Atom CedarView CPU N2800 */
-#define X86_CPUID_SILVERMONT 0x00030672 /* Atom Silvermont CPU */
-
-/*********************************************************************************************************
- Sandy Bridge microarchitecture CPUIDs
-*********************************************************************************************************/
-
-#define X86_CPUID_SANDYBRIDGE 0x000206a0 /* SandyBridge */
-
-/*********************************************************************************************************
- Haswell microarchitecture CPUIDs
-*********************************************************************************************************/
-
-#define X86_CPUID_HASWELL_CLIENT 0x000306c0 /* Haswell Client */
-#define X86_CPUID_HASWELL_SERVER 0x000306f0 /* Haswell Server */
-#define X86_CPUID_HASWELL_ULT 0x00040650 /* Haswell ULT */
-#define X86_CPUID_CRYSTAL_WELL 0x00040660 /* Crystal Well */
-
-/*********************************************************************************************************
- Dummy entry
-*********************************************************************************************************/
-
-#define X86_CPUID_DUMMY 0 /* Dummy CPUID entry */
-
-/*********************************************************************************************************
- CPU FAMILY
-*********************************************************************************************************/
-
-#define X86_FAMILY_UNSUPPORTED 0 /* CPU FAMILY: Not supported */
-#define X86_FAMILY_PENTIUM 2 /* CPU FAMILY: Pentium/P5 */
-#define X86_FAMILY_PENTIUM4 5 /* CPU FAMILY: Pentium4/P7 */
-#define X86_FAMILY_CORE 6 /* CPU FAMILY: Core/Core2 */
-#define X86_FAMILY_ATOM 7 /* CPU FAMILY: Atom */
-#define X86_FAMILY_NEHALEM 8 /* CPU FAMILY: Nehalem */
-#define X86_FAMILY_SANDYBRIDGE 9 /* CPU FAMILY: Sandy Bridge */
-#define X86_FAMILY_HASWELL 10 /* CPU FAMILY: Haswell */
-#define X86_FAMILY_MINUTEIA 11 /* CPU FAMILY: MinuteIA/Quark */
-
-/*********************************************************************************************************
CPU feature override flags
*********************************************************************************************************/
@@ -319,15 +233,6 @@ typedef struct {
} X86_CPUID_OVERRIDE;
/*********************************************************************************************************
- CPUID signature table entry structure
-*********************************************************************************************************/
-
-typedef struct {
- UINT32 signature;
- UINT32 family;
-} X86_CPUID_ENTRY;
-
-/*********************************************************************************************************
CPUID standard features
*********************************************************************************************************/
@@ -872,7 +777,6 @@ typedef struct {
INT CPUF_iDCacheWaySize; /* I-Cache way size */
BOOL CPUF_bHasCLFlush; /* Has CLFLUSH inst? */
BOOL CPUF_bHasAPIC; /* Has APIC on chip? */
- UINT CPUF_uiProcessorFamily; /* Processor Family */
BOOL CPUF_bHasX87FPU; /* Has X87 FPU? */
BOOL CPUF_bHasSSE; /* Has SSE? */
BOOL CPUF_bHasSSE2; /* Has SSE? */
@@ -895,7 +799,6 @@ extern X86_CPU_FEATURE _G_x86CpuFeature;
#define X86_FEATURE_DCACHE_WAY_SIZE _G_x86CpuFeature.CPUF_iDCacheWaySize
#define X86_FEATURE_HAS_CLFLUSH _G_x86CpuFeature.CPUF_bHasCLFlush
#define X86_FEATURE_HAS_APIC _G_x86CpuFeature.CPUF_bHasAPIC
-#define X86_FEATURE_PROCESSOR_FAMILY _G_x86CpuFeature.CPUF_uiProcessorFamily
#define X86_FEATURE_HAS_X87FPU _G_x86CpuFeature.CPUF_bHasX87FPU
#define X86_FEATURE_HAS_SSE _G_x86CpuFeature.CPUF_bHasSSE
#define X86_FEATURE_HAS_SSE2 _G_x86CpuFeature.CPUF_bHasSSE2
@@ -917,7 +820,6 @@ extern X86_CPUID *x86CpuIdGet(VOID);
extern VOID x86CpuIdProbe(VOID);
extern VOID x86CpuIdShow(VOID);
-extern INT x86CpuIdAdd(X86_CPUID_ENTRY *pentry);
extern INT x86CpuIdOverride(X86_CPUID_OVERRIDE *pentries, INT iCount);
extern UINT8 x86CpuIdBitField(UINT8 ucFullId, UINT8 ucMaxSubIdValue, UINT8 ucShiftCount);
diff --git a/SylixOS/arch/x86/common/x86LibAsm.S b/SylixOS/arch/x86/common/x86LibAsm.S
index 6a8b9ec..7cb139c 100644
--- a/SylixOS/arch/x86/common/x86LibAsm.S
+++ b/SylixOS/arch/x86/common/x86LibAsm.S
@@ -274,9 +274,15 @@ FUNC_DEF(archReboot)
;*********************************************************************************************************/
FUNC_DEF(archBogoMipsLoop)
- MOVL X86_SP_ARG1(%ESP) , %EAX
+ MOVL X86_SP_ARG1(%ESP) , %ECX
1:
- DEC %EAX
+ MOVL $1 , %EAX
+ MOVL $2 , %EDX
+ MOVL $1 , %EAX
+ MOVL $2 , %EDX
+ MOVL $1 , %EAX
+ MOVL $2 , %EDX
+ DEC %ECX
JNS 1b
RET
FUNC_END(archBogoMipsLoop)
diff --git a/SylixOS/arch/x86/dbg/x86Dbg.c b/SylixOS/arch/x86/dbg/x86Dbg.c
index b44187a..897505f 100644
--- a/SylixOS/arch/x86/dbg/x86Dbg.c
+++ b/SylixOS/arch/x86/dbg/x86Dbg.c
@@ -104,6 +104,24 @@ VOID archDbgBpRemove (addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLoca
#endif /* LW_CFG_CACHE_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: archDbgApRemove
+** 功能描述: 删除一个终止点.
+** 输 入 : ulAddr 终止点地址
+** pulIns 返回的之前的指令
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archDbgApRemove (addr_t ulAddr, ULONG ulIns)
+{
+ *(UINT8 *)ulAddr = (UINT8)ulIns;
+ KN_SMP_MB();
+
+#if LW_CFG_CACHE_EN > 0
+ API_CacheTextUpdate((PVOID)ulAddr, sizeof(UINT8));
+#endif /* LW_CFG_CACHE_EN > 0 */
+}
+/*********************************************************************************************************
** 函数名称: archDbgBpPrefetch
** 功能描述: 预取一个指令.
当指令处于 MMU 共享物理段时, 指令空间为物理只读, 这里需要产生一次缺页中断, 克隆一个物理页面.
@@ -129,8 +147,9 @@ VOID archDbgBpPrefetch (addr_t ulAddr)
*********************************************************************************************************/
UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
{
+ PLW_CLASS_TCB ptcbCur;
#if (LW_CFG_SMP_EN > 0) && (LW_CFG_CACHE_EN > 0) && (LW_CFG_GDB_SMP_TU_LAZY > 0)
- ULONG ulCPUId;
+ ULONG ulCPUId;
#endif /* LW_CFG_SMP_EN > 0 */
if (API_DtraceIsValid() == LW_FALSE) { /* 不存在调试节点 */
@@ -141,13 +160,14 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
return (LW_TRAP_ISTEP);
}
- switch (*(UINT8 *)ulAddr) {
+ if (*(UINT8 *)ulAddr == X86_BREAKPOINT_INS) {
+ LW_TCB_GET_CUR_SAFE(ptcbCur);
- case X86_BREAKPOINT_INS:
- return (LW_TRAP_BRKPT);
-
- default:
- break;
+ if (ptcbCur->TCB_ulAbortPointAddr == ulAddr) {
+ return (LW_TRAP_ABORT);
+ } else {
+ return (LW_TRAP_BRKPT);
+ }
}
#if (LW_CFG_SMP_EN > 0) && (LW_CFG_CACHE_EN > 0) && (LW_CFG_GDB_SMP_TU_LAZY > 0)
diff --git a/SylixOS/arch/x86/pentium/x86Pentium.c b/SylixOS/arch/x86/pentium/x86Pentium.c
index 13550f3..5493830 100644
--- a/SylixOS/arch/x86/pentium/x86Pentium.c
+++ b/SylixOS/arch/x86/pentium/x86Pentium.c
@@ -53,10 +53,7 @@ VOID x86PentiumMtrrEnable (VOID)
X86_CR_REG uiOldCr4;
#if LW_CFG_CPU_WORD_LENGHT == 32
- /*
- * Not available for MinuteIA
- */
- if (X86_FEATURE_PROCESSOR_FAMILY == X86_FAMILY_MINUTEIA) {
+ if (!X86_FEATURE_HAS_MTRR) {
return;
}
#endif /* LW_CFG_CPU_WORD_LENGHT == 32*/
@@ -100,10 +97,7 @@ VOID x86PentiumMtrrDisable (VOID)
X86_CR_REG uiOldCr4;
#if LW_CFG_CPU_WORD_LENGHT == 32
- /*
- * Not available for MinuteIA
- */
- if (X86_FEATURE_PROCESSOR_FAMILY == X86_FAMILY_MINUTEIA) {
+ if (!X86_FEATURE_HAS_MTRR) {
return;
}
#endif /* LW_CFG_CPU_WORD_LENGHT == 32*/
@@ -149,10 +143,7 @@ INT x86PentiumMtrrGet (PX86_MTRR pMtrr)
INTREG iregInterLevel;
#if LW_CFG_CPU_WORD_LENGHT == 32
- /*
- * Not available for MinuteIA
- */
- if (X86_FEATURE_PROCESSOR_FAMILY == X86_FAMILY_MINUTEIA) {
+ if (!X86_FEATURE_HAS_MTRR) {
return (PX_ERROR);
}
#endif /* LW_CFG_CPU_WORD_LENGHT == 32*/
@@ -206,10 +197,7 @@ INT x86PentiumMtrrSet (PX86_MTRR pMtrr)
INTREG iregInterLevel;
#if LW_CFG_CPU_WORD_LENGHT == 32
- /*
- * Not available for MinuteIA
- */
- if (X86_FEATURE_PROCESSOR_FAMILY == X86_FAMILY_MINUTEIA) {
+ if (!X86_FEATURE_HAS_MTRR) {
return (PX_ERROR);
}
#endif /* LW_CFG_CPU_WORD_LENGHT == 32*/
diff --git a/SylixOS/arch/x86/x86_support.h b/SylixOS/arch/x86/x86_support.h
index cbd4df1..8886ea8 100644
--- a/SylixOS/arch/x86/x86_support.h
+++ b/SylixOS/arch/x86/x86_support.h
@@ -105,6 +105,7 @@ PLW_STACK archCtxStackEnd(const ARCH_REG_CTX *pregctx);
VOID archDbgBpInsert(addr_t ulAddr, size_t stSize, ULONG *pulIns, BOOL bLocal);
VOID archDbgAbInsert(addr_t ulAddr, ULONG *pulIns);
VOID archDbgBpRemove(addr_t ulAddr, size_t stSize, ULONG ulIns, BOOL bLocal);
+VOID archDbgApRemove(addr_t ulAddr, ULONG ulIns);
VOID archDbgBpPrefetch(addr_t ulAddr);
UINT archDbgTrapType(addr_t ulAddr, PVOID pvArch);
VOID archDbgBpAdjust(PVOID pvDtrace, PVOID pvtm);
@@ -149,7 +150,7 @@ VOID archReboot(INT iRebootType, addr_t ulStartAddress);
VOID archBogoMipsLoop(ULONG ulLoop);
#define __ARCH_BOGOMIPS_LOOP archBogoMipsLoop
-#define __ARCH_BOGOMIPS_INS_PER_LOOP 2
+#define __ARCH_BOGOMIPS_INS_PER_LOOP 8
/*********************************************************************************************************
x86 处理器 CACHE 操作
diff --git a/SylixOS/config/cpu/cpu_cfg_csky.h b/SylixOS/config/cpu/cpu_cfg_csky.h
index c8fb33c..4dc4611 100644
--- a/SylixOS/config/cpu/cpu_cfg_csky.h
+++ b/SylixOS/config/cpu/cpu_cfg_csky.h
@@ -59,6 +59,17 @@
#define LW_CFG_CPU_PHYS_ADDR_64BIT 0 /* 物理地址 64bit 宽度 */
/*********************************************************************************************************
+ C-SKY MPU 配置
+*********************************************************************************************************/
+
+#if defined(__CK803__) || defined(__CK803S__)
+#define LW_CFG_CSKY_MPU 1
+#define LW_CFG_MPU_REGION_NUM 8
+#else
+#define LW_CFG_CSKY_MPU 0
+#endif /* __CK803__ || __CK803S__ */
+
+/*********************************************************************************************************
C-SKY MMU 配置
LW_CFG_CSKY_PAGE_SHIFT 可配置的值有如下:
diff --git a/SylixOS/config/cpu/cpu_cfg_x86.h b/SylixOS/config/cpu/cpu_cfg_x86.h
index ddd532b..f54f698 100644
--- a/SylixOS/config/cpu/cpu_cfg_x86.h
+++ b/SylixOS/config/cpu/cpu_cfg_x86.h
@@ -53,6 +53,8 @@
/* 老式奔腾处理器 (1, 2, 3, 4) */
#define LW_CFG_CPU_X86_NO_PAUSE 0 /* 不支持 PAUSE 指令 */
#define LW_CFG_CPU_X86_NO_HLT 0 /* 不支持 HLT 指令 */
+#define LW_CFG_CPU_X86_APIC_BUS_INT 0 /* 使用 APIC BUS 而不是前端总线*/
+ /* 投递中断(老式奔腾 1, 2, 3) */
/*********************************************************************************************************
CPU 字长与整型大小端定义
diff --git a/SylixOS/debug/dtrace/dtrace.c b/SylixOS/debug/dtrace/dtrace.c
index a71655c..5cca0ec 100644
--- a/SylixOS/debug/dtrace/dtrace.c
+++ b/SylixOS/debug/dtrace/dtrace.c
@@ -266,6 +266,12 @@ INT API_DtraceBreakTrap (addr_t ulAddr, UINT uiBpType)
}
#endif /* LW_CFG_SMP_EN > 0 */
+ if (uiBpType == LW_TRAP_ABORT) { /* 恢复终止点指令 */
+ archDbgApRemove(ulAddr, ptcbCur->TCB_ulAbortPointInst);
+ ptcbCur->TCB_ulAbortPointInst = 0;
+ ptcbCur->TCB_ulAbortPointAddr = 0;
+ }
+
dtm.DTM_ulAddr = ulAddr;
dtm.DTM_uiType = uiBpType; /* 获得 trap 类型 */
dtm.DTM_ulThread = ptcbCur->TCB_ulId;
@@ -330,7 +336,6 @@ LW_API
INT API_DtraceAbortTrap (addr_t ulAddr)
{
#if LW_CFG_MODULELOADER_EN > 0
- ULONG ulIns;
PLW_LIST_LINE plineTemp;
LW_LD_VPROC *pvproc;
PLW_CLASS_TCB ptcbCur;
@@ -344,7 +349,8 @@ INT API_DtraceAbortTrap (addr_t ulAddr)
}
if (pvproc->VP_iDbgFlags & LW_VPROC_DEBUG_TRAP) { /* 需要停止下来 */
- archDbgAbInsert(ulAddr, &ulIns); /* 建立一个断点 */
+ ptcbCur->TCB_ulAbortPointAddr = ulAddr;
+ archDbgAbInsert(ulAddr, &ptcbCur->TCB_ulAbortPointInst); /* 建立一个终止点 */
vprocDebugStop(pvproc, ptcbCur); /* 需要停止进程内其他线程 */
return (ERROR_NONE);
}
@@ -364,7 +370,8 @@ INT API_DtraceAbortTrap (addr_t ulAddr)
return (PX_ERROR);
} else {
- archDbgAbInsert(ulAddr, &ulIns); /* 建立一个断点 */
+ ptcbCur->TCB_ulAbortPointAddr = ulAddr;
+ archDbgAbInsert(ulAddr, &ptcbCur->TCB_ulAbortPointInst); /* 建立一个终止点 */
return (ERROR_NONE);
}
#else
diff --git a/SylixOS/driver/pci/storage/pciStorageAta.c b/SylixOS/driver/pci/storage/pciStorageAta.c
index 0a94fd5..91bf222 100644
--- a/SylixOS/driver/pci/storage/pciStorageAta.c
+++ b/SylixOS/driver/pci/storage/pciStorageAta.c
@@ -17,6 +17,9 @@
** 文件创建日期: 2018 年 09 月 04 日
**
** 描 述: ATA/IDE 驱动.
+
+** BUG:
+** 2019.07.02 增加 INTEL ICH4 IDE 控制器延时的特殊处理, 否则会出现控制器复位失败.
*********************************************************************************************************/
#define __SYLIXOS_PCI_DRV
#define __SYLIXOS_ATA_DRV
@@ -30,6 +33,7 @@
#if (LW_CFG_DEVICE_EN > 0) && (LW_CFG_PCI_EN > 0) && (LW_CFG_ATA_EN > 0) && (LW_CFG_DRV_ATA_IDE > 0)
#include "pci_ids.h"
#include "pciStorageAta.h"
+#include "../SylixOS/system/device/ata/ataLib.h"
/*********************************************************************************************************
板载类型.
*********************************************************************************************************/
@@ -203,6 +207,68 @@ typedef struct ata_pci_dma_ctrl {
typedef ATA_PCI_DMA_CTRL_CB *ATA_PCI_DMA_CTRL_HANDLE;
/*********************************************************************************************************
+** 函数名称: pciStorageAtaCtrlIch4Delay
+** 功能描述: ICH4 控制器延时处理
+** 输 入 : hCtrl 控制器句柄
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID pciStorageAtaCtrlIch4Delay (ATA_CTRL_HANDLE hCtrl)
+{
+ UINT8 ucReg;
+
+ ATA_IO_BYTES_READ(hCtrl, ATA_A_STATUS_ADDR(hCtrl), &ucReg, 1);
+ ATA_IO_BYTES_READ(hCtrl, ATA_A_STATUS_ADDR(hCtrl), &ucReg, 1);
+ ATA_IO_BYTES_READ(hCtrl, ATA_A_STATUS_ADDR(hCtrl), &ucReg, 1);
+ ATA_IO_BYTES_READ(hCtrl, ATA_A_STATUS_ADDR(hCtrl), &ucReg, 1);
+ ATA_IO_BYTES_READ(hCtrl, ATA_A_STATUS_ADDR(hCtrl), &ucReg, 1);
+ ATA_IO_BYTES_READ(hCtrl, ATA_A_STATUS_ADDR(hCtrl), &ucReg, 1);
+
+ ATA_IO_BYTES_READ(hCtrl, ATA_A_STATUS_ADDR(hCtrl), &ucReg, 1);
+ ATA_IO_BYTES_READ(hCtrl, ATA_A_STATUS_ADDR(hCtrl), &ucReg, 1);
+ ATA_IO_BYTES_READ(hCtrl, ATA_A_STATUS_ADDR(hCtrl), &ucReg, 1);
+}
+/*********************************************************************************************************
+** 函数名称: pciStorageAtaCtrlQuirk
+** 功能描述: 控制器的特殊处理
+** 输 入 : hPciDev PCI 设备句柄
+** hDrv 驱动句柄
+** hCtrlCfg 控制器配置句柄
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT pciStorageAtaCtrlQuirk (PCI_DEV_HANDLE hPciDev,
+ ATA_DRV_HANDLE hDrv,
+ ATA_CTRL_CFG_HANDLE hCtrlCfg)
+{
+ UINT16 usVendorId;
+ UINT16 usDeviceId;
+
+ if ((!hPciDev) || (!hDrv) || (!hCtrlCfg)) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ usVendorId = PCI_DEV_VENDOR_ID(hPciDev);
+ usDeviceId = PCI_DEV_DEVICE_ID(hPciDev);
+
+ switch (usVendorId) {
+
+ case PCI_VENDOR_ID_INTEL:
+ if (usDeviceId == PCI_DEVICE_ID_INTEL_82801DB_11) {
+ hCtrlCfg->ATACTRLCFG_pfuncDelay = (FUNCPTR)pciStorageAtaCtrlIch4Delay;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
** 函数名称: pciStorageAtaDevIdTblGet
** 功能描述: 获取设备列表
** 输 入 : phPciDevId 设备 ID 列表句柄缓冲区
@@ -989,6 +1055,8 @@ static INT pciStorageAtaDevProbe (PCI_DEV_HANDLE hPciDev, const PCI_DEV_ID_HAN
}
hCtrlCfg->ATACTRLCFG_pfuncDelay = (FUNCPTR)LW_NULL;
+ pciStorageAtaCtrlQuirk(hPciDev, hDrv, hCtrlCfg);
+
hCtrlCfg = &hDrv->ATADRV_tCtrlCfg[1];
if (ucReg & ATA_SEC_NATIVE_EN) {
hResource = API_PciDevResourceGet(hPciDev, PCI_IORESOURCE_IRQ, 0);
@@ -1028,6 +1096,8 @@ static INT pciStorageAtaDevProbe (PCI_DEV_HANDLE hPciDev, const PCI_DEV_ID_HAN
}
hCtrlCfg->ATACTRLCFG_pfuncDelay = (FUNCPTR)LW_NULL;
+ pciStorageAtaCtrlQuirk(hPciDev, hDrv, hCtrlCfg);
+
/*
* 驱动 IO 操作初始化
*/
diff --git a/SylixOS/driver/pci/storage/pciStorageAta.h b/SylixOS/driver/pci/storage/pciStorageAta.h
index e9d1d39..64ed9f3 100644
--- a/SylixOS/driver/pci/storage/pciStorageAta.h
+++ b/SylixOS/driver/pci/storage/pciStorageAta.h
@@ -26,7 +26,7 @@
驱动名称
*********************************************************************************************************/
#define ATA_PCI_DRV_NAME "ata_pci" /* PCI 类型 */
-#define ATA_PCI_DRV_VER_NUM 0x02000000 /* 驱动版本数值 */
+#define ATA_PCI_DRV_VER_NUM 0x02000100 /* 驱动版本数值 */
/*********************************************************************************************************
函数声明
diff --git a/SylixOS/fs/diskCache/diskCache.c b/SylixOS/fs/diskCache/diskCache.c
index 7d70e17..a46ae01 100644
--- a/SylixOS/fs/diskCache/diskCache.c
+++ b/SylixOS/fs/diskCache/diskCache.c
@@ -464,6 +464,8 @@ ULONG API_DiskCacheCreate (PLW_BLK_DEV pblkdDisk,
diskCacheDelete(pblkdCfCache);
cfDiskCreate(pblkdCf);
+** 注 意 : 必须先 ListDel 在 DISKCACHE_LOCK 防止死锁.
+
API 函数
*********************************************************************************************************/
LW_API
@@ -472,11 +474,11 @@ INT API_DiskCacheDelete (PLW_BLK_DEV pblkdDiskCache)
REGISTER PLW_DISKCACHE_CB pdiskcDiskCache = (PLW_DISKCACHE_CB)pblkdDiskCache;
if (pblkdDiskCache) {
+ __diskCacheListDel(pdiskcDiskCache); /* 退出背景线程 */
+
__LW_DISKCACHE_LOCK(pdiskcDiskCache); /* 等待使用权 */
-
__diskCacheWpSync(&pdiskcDiskCache->DISKC_wpWrite);
__diskCacheWpDelete(&pdiskcDiskCache->DISKC_wpWrite);
- __diskCacheListDel(pdiskcDiskCache); /* 退出背景线程 */
API_SemaphoreMDelete(&pdiskcDiskCache->DISKC_hDiskCacheLock);
__SHEAP_FREE(pdiskcDiskCache->DISKC_pcCacheNodeMem);
diff --git a/SylixOS/fs/diskPartition/diskPartition.c b/SylixOS/fs/diskPartition/diskPartition.c
index 244e532..28d686f 100644
--- a/SylixOS/fs/diskPartition/diskPartition.c
+++ b/SylixOS/fs/diskPartition/diskPartition.c
@@ -256,7 +256,7 @@ static INT __diskPartitionScan (PLW_BLK_DEV pblkd,
ULONG ulExtStartSector)
{
#ifndef MBR_Table
-#define MBR_Table 446 /* MBR: Partition table offset */
+#define MBR_Table 446 /* MBR: Partition table offset */
#endif
INT i;
diff --git a/SylixOS/fs/iso9660Fs/iso9660_sylixos.c b/SylixOS/fs/iso9660Fs/iso9660_sylixos.c
index 9b0bd7b..5347146 100644
--- a/SylixOS/fs/iso9660Fs/iso9660_sylixos.c
+++ b/SylixOS/fs/iso9660Fs/iso9660_sylixos.c
@@ -688,7 +688,6 @@ ssize_t __iso9660FsRead (PLW_FD_ENTRY pfdentry,
__ISO_FILE_UNLOCK(pisofile);
- _ErrorHandle(ERROR_NONE);
return ((ssize_t)uiReadNum);
}
/*********************************************************************************************************
@@ -755,7 +754,6 @@ ssize_t __iso9660FsPRead (PLW_FD_ENTRY pfdentry,
__ISO_FILE_UNLOCK(pisofile);
- _ErrorHandle(ERROR_NONE);
return ((ssize_t)uiReadNum);
}
/*********************************************************************************************************
@@ -1161,7 +1159,6 @@ static INT __iso9660FsReadDir (PLW_FD_ENTRY pfdentry, DIR *dir)
__ISO_FILE_UNLOCK(pisofile);
- _ErrorHandle(ERROR_NONE);
return (ERROR_NONE);
}
/*********************************************************************************************************
diff --git a/SylixOS/fs/tpsFs/tpsfs_sylixos.c b/SylixOS/fs/tpsFs/tpsfs_sylixos.c
index 934500c..48bd8f8 100644
--- a/SylixOS/fs/tpsFs/tpsfs_sylixos.c
+++ b/SylixOS/fs/tpsFs/tpsfs_sylixos.c
@@ -1164,11 +1164,12 @@ static ssize_t __tpsFsWrite (PLW_FD_ENTRY pfdentry,
break;
}
}
-
__SHEAP_FREE(pucZoreBuf);
- if (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < pfdentry->FDENTRY_oftPtr) {
+
+ pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
+ if (pfdnode->FDNODE_oftSize < pfdentry->FDENTRY_oftPtr) {
__TPS_FILE_UNLOCK(ptpsfile);
- _ErrorHandle(EFBIG);
+ _ErrorHandle(ENOSPC);
return (PX_ERROR);
}
}
@@ -1244,11 +1245,12 @@ static ssize_t __tpsFsPWrite (PLW_FD_ENTRY pfdentry,
break;
}
}
-
__SHEAP_FREE(pucZoreBuf);
- if (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < oftPos) {
+
+ pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
+ if (pfdnode->FDNODE_oftSize < oftPos) {
__TPS_FILE_UNLOCK(ptpsfile);
- _ErrorHandle(EFBIG);
+ _ErrorHandle(ENOSPC);
return (PX_ERROR);
}
}
diff --git a/SylixOS/include/arch/arch_inc.h b/SylixOS/include/arch/arch_inc.h
index b35d3df..7966a24 100644
--- a/SylixOS/include/arch/arch_inc.h
+++ b/SylixOS/include/arch/arch_inc.h
@@ -106,6 +106,7 @@
#include "csky/arch_limits.h"
#include "csky/arch_regs.h"
#include "csky/arch_mmu.h"
+#include "csky/arch_mpu.h"
#endif /* LW_CFG_CPU_ARCH_ARM */
#endif /* __ARCH_INC_H */
diff --git a/SylixOS/include/arch/csky/arch_def.h b/SylixOS/include/arch/csky/arch_def.h
index 7b42160..47405ee 100644
--- a/SylixOS/include/arch/csky/arch_def.h
+++ b/SylixOS/include/arch/csky/arch_def.h
@@ -22,6 +22,8 @@
#ifndef __CSKY_ARCH_DEF_H
#define __CSKY_ARCH_DEF_H
+#include "asm/archprob.h"
+
/*********************************************************************************************************
SSEG0 SSEG1 地址转换
*********************************************************************************************************/
diff --git a/SylixOS/include/arch/csky/arch_float.h b/SylixOS/include/arch/csky/arch_float.h
index 620c4a3..dfe37f8 100644
--- a/SylixOS/include/arch/csky/arch_float.h
+++ b/SylixOS/include/arch/csky/arch_float.h
@@ -22,18 +22,29 @@
#ifndef __CSKY_ARCH_FLOAT_H
#define __CSKY_ARCH_FLOAT_H
+#include "asm/archprob.h"
+
/*********************************************************************************************************
FPU 浮点数据寄存器的相关定义
*********************************************************************************************************/
#if defined(__SYLIXOS_KERNEL) || defined(__ASSEMBLY__) || defined(ASSEMBLY)
#define FPU_REG_NR 16 /* FPU 通用寄存器数量 */
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+#define FPU_REG_WIDTH 32 /* 浮点数据寄存器的位宽 */
+#else
#define FPU_REG_WIDTH 64 /* 浮点数据寄存器的位宽 */
+#endif /* __SYLIXOS_CSKY_ARCH_CK803__ */
#define FPU_REG_SIZE (FPU_REG_WIDTH / 8) /* 浮点数据寄存器的大小 */
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+#define FPU_OFFSET_REG(n) ((n) * FPU_REG_SIZE) /* 浮点数据寄存器偏移 */
+#define FPU_OFFSET_FCR (FPU_OFFSET_REG(FPU_REG_NR)) /* FCR 偏移 */
+#else
#define FPU_OFFSET_REG_HI(n) ((n) * FPU_REG_SIZE) /* 浮点数据寄存器偏移 */
#define FPU_OFFSET_REG_LO(n) ((n) * FPU_REG_SIZE + FPU_REG_SIZE >> 1)/* 浮点数据寄存器偏移 */
#define FPU_OFFSET_FCR (FPU_OFFSET_REG_HI(FPU_REG_NR)) /* FCR 偏移 */
+#endif /* __SYLIXOS_CSKY_ARCH_CK803__ */
#define FPU_OFFSET_FESR (FPU_OFFSET_FCR + 4) /* FESR 偏移 */
/*********************************************************************************************************
@@ -43,18 +54,18 @@
#if !defined(__ASSEMBLY__) && !defined(ASSEMBLY)
/*********************************************************************************************************
- FPU 访问时需要高 32 位和低 32位分开访问
+ FPU 访问时需要高 32 位和低 32 位分开访问
*********************************************************************************************************/
typedef struct fpureg { /* FPU 寄存器类型 */
UINT32 val32[FPU_REG_WIDTH / 32];
} ARCH_FPU_REG;
-#define ARCH_FPU_CTX_ALIGN 8 /* FPU CTX align size */
+#define ARCH_FPU_CTX_ALIGN 8 /* FPU CTX align size */
struct arch_fpu_ctx {
- ARCH_FPU_REG FPUCTX_uiDreg[FPU_REG_NR]; /* FPU 通用寄存器 */
- UINT32 FPUCTX_uiFpcr; /* FPU 控制寄存器 */
- UINT32 FPUCTX_uiFpesr; /* FPU 异常寄存器 */
+ ARCH_FPU_REG FPUCTX_uiDreg[FPU_REG_NR]; /* FPU 通用寄存器 */
+ UINT32 FPUCTX_uiFpcr; /* FPU 控制寄存器 */
+ UINT32 FPUCTX_uiFpesr; /* FPU 异常寄存器 */
} __attribute__ ((aligned(ARCH_FPU_CTX_ALIGN)));
diff --git a/SylixOS/include/arch/csky/arch_mpu.h b/SylixOS/include/arch/csky/arch_mpu.h
new file mode 100644
index 0000000..e7e5af6
--- /dev/null
+++ b/SylixOS/include/arch/csky/arch_mpu.h
@@ -0,0 +1,89 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: arch_mpu.h
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2018 年 11 月 12 日
+**
+** 描 述: C-SKY MPU 管理相关.
+*********************************************************************************************************/
+
+#ifndef __CSKY_ARCH_MPU_H
+#define __CSKY_ARCH_MPU_H
+
+#if (LW_CFG_VMM_EN == 0) && (LW_CFG_CSKY_MPU > 0)
+/*********************************************************************************************************
+ 映射描述符
+*********************************************************************************************************/
+#ifdef __SYLIXOS_KERNEL
+
+typedef struct {
+ BOOL MPUD_bEnable; /* Enable */
+ BOOL MPUD_bDmaPool; /* DMA buffer pool */
+
+ UINT32 MPUD_uiAddr; /* Start address */
+ UINT8 MPUD_ucSize; /* Region size */
+#define CSKY_MPU_REGION_SIZE_END ((UINT8)0x00) /* The last one */
+#define CSKY_MPU_REGION_SIZE_4KB ((UINT8)0x0b)
+#define CSKY_MPU_REGION_SIZE_8KB ((UINT8)0x0c)
+#define CSKY_MPU_REGION_SIZE_16KB ((UINT8)0x0d)
+#define CSKY_MPU_REGION_SIZE_32KB ((UINT8)0x0e)
+#define CSKY_MPU_REGION_SIZE_64KB ((UINT8)0x0f)
+#define CSKY_MPU_REGION_SIZE_128KB ((UINT8)0x10)
+#define CSKY_MPU_REGION_SIZE_256KB ((UINT8)0x11)
+#define CSKY_MPU_REGION_SIZE_512KB ((UINT8)0x12)
+#define CSKY_MPU_REGION_SIZE_1MB ((UINT8)0x13)
+#define CSKY_MPU_REGION_SIZE_2MB ((UINT8)0x14)
+#define CSKY_MPU_REGION_SIZE_4MB ((UINT8)0x15)
+#define CSKY_MPU_REGION_SIZE_8MB ((UINT8)0x16)
+#define CSKY_MPU_REGION_SIZE_16MB ((UINT8)0x17)
+#define CSKY_MPU_REGION_SIZE_32MB ((UINT8)0x18)
+#define CSKY_MPU_REGION_SIZE_64MB ((UINT8)0x19)
+#define CSKY_MPU_REGION_SIZE_128MB ((UINT8)0x1a)
+#define CSKY_MPU_REGION_SIZE_256MB ((UINT8)0x1b)
+#define CSKY_MPU_REGION_SIZE_512MB ((UINT8)0x1c)
+#define CSKY_MPU_REGION_SIZE_1GB ((UINT8)0x1d)
+#define CSKY_MPU_REGION_SIZE_2GB ((UINT8)0x1e)
+#define CSKY_MPU_REGION_SIZE_4GB ((UINT8)0x1f)
+
+ UINT8 MPUD_ucMpuNumber; /* Mpu Region Number */
+
+ UINT32 MPUD_uiAttr; /* Access permission */
+#define CSKY_MPU_ATTR_NX_POS 0
+#define CSKY_MPU_ATTR_NX (1 << CSKY_MPU_ATTR_NX_POS)
+ /* Instruction Fetched Execution */
+
+#define CSKY_MPU_ATTR_AP_POS 1
+#define CSKY_MPU_ATTR_AP_BOTH_INACCESS (0 << CSKY_MPU_ATTR_AP_POS)
+ /* Both Inaccessible */
+#define CSKY_MPU_ATTR_AP_S_RW_U_INACCESS (1 << CSKY_MPU_ATTR_AP_POS)
+ /* Super: Read Write/User: Inaccessible*/
+#define CSKY_MPU_ATTR_AP_S_RW_U_RO (2 << CSKY_MPU_ATTR_AP_POS)
+ /* Super: Read Write/User: Read Only */
+#define CSKY_MPU_ATTR_AP_BOTH_RW (3 << CSKY_MPU_ATTR_AP_POS)
+ /* Both Read Write */
+#define CSKY_MPU_ATTR_AP (3 << CSKY_MPU_ATTR_AP_POS)
+
+#define CSKY_MPU_ATTR_S_POS 3
+#define CSKY_MPU_ATTR_S (1 << CSKY_MPU_ATTR_S_POS)
+ /* Security */
+} CSKY_MPU_REGION;
+typedef CSKY_MPU_REGION *PCSKY_MPU_REGION;
+
+#endif /* __SYLIXOS_KERNEL */
+#endif /* LW_CFG_CSKY_MPU > 0 */
+#endif /* __CSKY_ARCH_MPU_H */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/include/arch/csky/arch_regs.h b/SylixOS/include/arch/csky/arch_regs.h
index 92c6b84..6d6f49b 100644
--- a/SylixOS/include/arch/csky/arch_regs.h
+++ b/SylixOS/include/arch/csky/arch_regs.h
@@ -22,6 +22,19 @@
#ifndef __CSKY_ARCH_REGS_H
#define __CSKY_ARCH_REGS_H
+#include "asm/archprob.h"
+
+/*********************************************************************************************************
+ C-SKY CK803 体系架构
+*********************************************************************************************************/
+#if defined(__SYLIXOS_CSKY_ARCH_CK803__)
+
+#include "./ck803/arch_regs.h"
+
+#else
+/*********************************************************************************************************
+ C-SKY 通用体系架构
+*********************************************************************************************************/
/*********************************************************************************************************
定义
*********************************************************************************************************/
@@ -121,6 +134,7 @@ typedef struct {
#define ARCH_REG_CTX_GET_PC(ctx) ((void *)(ctx).REG_ulPc)
#endif /* !defined(__ASSEMBLY__) */
+#endif /* __SYLIXOS_CSKY_ARCH_CK803__ */
#endif /* __CSKY_ARCH_REGS_H */
/*********************************************************************************************************
END
diff --git a/SylixOS/include/arch/csky/asm/archprob.h b/SylixOS/include/arch/csky/asm/archprob.h
new file mode 100644
index 0000000..a48c868
--- /dev/null
+++ b/SylixOS/include/arch/csky/asm/archprob.h
@@ -0,0 +1,36 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: archprob.h
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2019 年 07 月 15 日
+**
+** 描 述: 平台编译探测.
+*********************************************************************************************************/
+
+#ifndef __ARCHPROB_H
+#define __ARCHPROB_H
+
+/*********************************************************************************************************
+ C-SKY architecture detect
+*********************************************************************************************************/
+
+#if defined(__CK803__) || defined(__CK803S__)
+#define __SYLIXOS_CSKY_ARCH_CK803__
+#endif
+
+#endif /* __ARCHPROB_H */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/include/arch/csky/asm/assembler.h b/SylixOS/include/arch/csky/asm/assembler.h
index 84b5544..f631dec 100644
--- a/SylixOS/include/arch/csky/asm/assembler.h
+++ b/SylixOS/include/arch/csky/asm/assembler.h
@@ -22,6 +22,7 @@
#ifndef __ASMCSKY_ASSEMBLER_H
#define __ASMCSKY_ASSEMBLER_H
+#include "archprob.h"
#include "arch/csky/arch_def.h"
/*********************************************************************************************************
diff --git a/SylixOS/include/arch/csky/ck803/arch_regs.h b/SylixOS/include/arch/csky/ck803/arch_regs.h
new file mode 100644
index 0000000..971d439
--- /dev/null
+++ b/SylixOS/include/arch/csky/ck803/arch_regs.h
@@ -0,0 +1,92 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: arch_regs.h
+**
+** 创 建 人: Wang.Xuan (王翾)
+**
+** 文件创建日期: 2018 年 11 月 12 日
+**
+** 描 述: CK803 体系架构寄存器相关.
+*********************************************************************************************************/
+
+#ifndef __CSKYCK803_ARCH_REGS_H
+#define __CSKYCK803_ARCH_REGS_H
+
+/*********************************************************************************************************
+ 定义
+*********************************************************************************************************/
+
+#define ARCH_GREG_NR 17 /* 通用寄存器数目 */
+
+#define ARCH_REG_CTX_WORD_SIZE 20 /* 寄存器上下文字数 */
+#define ARCH_STK_MIN_WORD_SIZE 256 /* 堆栈最小字数 */
+
+#define ARCH_REG_SIZE 4 /* 寄存器大小 */
+#define ARCH_REG_CTX_SIZE (ARCH_REG_CTX_WORD_SIZE * ARCH_REG_SIZE)/* 寄存器上下文大小 */
+
+#define ARCH_STK_ALIGN_SIZE 8 /* 堆栈对齐要求 */
+
+#define ARCH_JMP_BUF_WORD_SIZE 20 /* 跳转缓冲字数(向后兼容) */
+
+/*********************************************************************************************************
+ 寄存器在 ARCH_REG_CTX 中的偏移量
+*********************************************************************************************************/
+
+#define XGREG(n) ((n) * ARCH_REG_SIZE)
+#define XGREG28 ((16) * ARCH_REG_SIZE)
+#define XPC ((ARCH_GREG_NR + 0) * ARCH_REG_SIZE)
+#define XPSR ((ARCH_GREG_NR + 1) * ARCH_REG_SIZE)
+
+/*********************************************************************************************************
+ 寄存器表
+*********************************************************************************************************/
+
+#if (!defined(__ASSEMBLY__)) && (!defined(ASSEMBLY))
+
+typedef UINT32 ARCH_REG_T;
+
+typedef struct {
+ ARCH_REG_T REG_ulReg[ARCH_GREG_NR]; /* 17 个通用目的寄存器 */
+ ARCH_REG_T REG_ulPc; /* 程序计数器寄存器 */
+ ARCH_REG_T REG_ulPsr; /* 处理器状态寄存器 */
+ ARCH_REG_T REG_ulPad;
+
+#define REG_A0 0 /* 第一个参数 */
+#define REG_A1 1 /* 第二个参数 */
+#define REG_A2 2 /* 第三个参数 */
+#define REG_A3 3 /* 第四个参数 */
+#define REG_SP 14 /* 堆栈指针 */
+#define REG_FP 8 /* FP */
+#define REG_RA 15 /* 链接寄存器 */
+} ARCH_REG_CTX;
+
+/*********************************************************************************************************
+ 调用回溯堆栈表
+*********************************************************************************************************/
+
+typedef struct {
+ ARCH_REG_T FP_uiFp;
+ ARCH_REG_T FP_uiLr;
+} ARCH_FP_CTX;
+
+/*********************************************************************************************************
+ 从上下文中获取信息
+*********************************************************************************************************/
+
+#define ARCH_REG_CTX_GET_PC(ctx) ((void *)(ctx).REG_ulPc)
+
+#endif /* !defined(__ASSEMBLY__) */
+#endif /* __CSKYCK803_ARCH_REGS_H */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/include/arch/csky/inc/cskyregs.h b/SylixOS/include/arch/csky/inc/cskyregs.h
index bc1bc9c..39283e4 100644
--- a/SylixOS/include/arch/csky/inc/cskyregs.h
+++ b/SylixOS/include/arch/csky/inc/cskyregs.h
@@ -182,6 +182,70 @@ static inline void cskyTlbInvalidIndexed(void)
: :"r" (value));
}
+static inline uint32_t cskyMpuGetCCR(void)
+{
+ register uint32_t result;
+
+ __asm__ __volatile__("mfcr %0, cr<18, 0>\n"
+ : "=r"(result));
+
+ return (result);
+}
+
+static inline void cskyMpuSetCCR(uint32_t ccr)
+{
+ __asm__ __volatile__("mtcr %0, cr<18, 0>\n"
+ : : "r"(ccr));
+}
+
+static inline uint32_t cskyMpuGetCAPR(void)
+{
+ register uint32_t result;
+
+ __asm__ __volatile__("mfcr %0, cr<19, 0>\n"
+ : "=r"(result));
+
+ return (result);
+}
+
+static inline void cskyMpuSetCAPR(uint32_t capr)
+{
+ __asm__ __volatile__("mtcr %0, cr<19, 0>\n"
+ : : "r"(capr));
+}
+
+static inline void cskyMpuSetPACR(uint32_t pacr)
+{
+ __asm__ __volatile__("mtcr %0, cr<20, 0>\n"
+ : : "r"(pacr));
+}
+
+static inline uint32_t cskyMpuGetPACR(void)
+{
+ uint32_t result;
+
+ __asm__ __volatile__("mfcr %0, cr<20, 0>"
+ : "=r"(result));
+
+ return (result);
+}
+
+static inline void cskyMpuSetPRSR(uint32_t prsr)
+{
+ __asm__ __volatile__("mtcr %0, cr<21, 0>\n"
+ : : "r"(prsr));
+}
+
+static inline uint32_t cskyMpuGetPRSR(void)
+{
+ uint32_t result;
+
+ __asm__ __volatile__("mfcr %0, cr<21, 0>"
+ : "=r"(result));
+
+ return (result);
+}
+
#endif /* !__ASSEMBLY__ */
#define CSKY_FPUID_IMPLEMENT (1 << 31)
diff --git a/SylixOS/include/net/if.h b/SylixOS/include/net/if.h
index 091292f..9b43cd9 100644
--- a/SylixOS/include/net/if.h
+++ b/SylixOS/include/net/if.h
@@ -249,6 +249,34 @@ struct in6_ifreq {
#define SIOCDIFADDR6 _IOW('i', 35, struct in6_ifreq)
/*********************************************************************************************************
+ sylixos if statistics
+*********************************************************************************************************/
+
+struct ifstatreq {
+ char ifrs_name[IFNAMSIZ]; /* if name, e.g. "en1" */
+ u_long ifrs_mtu; /* maximum transmission unit */
+ u_long ifrs_collisions; /* collisions on csma interfaces */
+ uint64_t ifrs_baudrate; /* linespeed */
+ uint64_t ifrs_ipackets; /* packets received on interface */
+ uint64_t ifrs_ierrors; /* input errors on interface */
+ uint64_t ifrs_opackets; /* packets sent on interface */
+ uint64_t ifrs_oerrors; /* output errors on interface */
+ uint64_t ifrs_ibytes; /* total number of octets received */
+ uint64_t ifrs_obytes; /* total number of octets sent */
+ uint64_t ifrs_imcasts; /* packets received via multicast */
+ uint64_t ifrs_omcasts; /* packets sent via multicast */
+ uint64_t ifrs_iqdrops; /* dropped on input, this interface */
+ uint64_t ifrs_noproto; /* destined for unsupported protocol */
+ uint64_t ifrs_reserved[8];
+};
+
+/*********************************************************************************************************
+ sylixos if statistics ioctl
+*********************************************************************************************************/
+
+#define SIOCGIFSTATS _IOWR('i', 80, struct ifstatreq)
+
+/*********************************************************************************************************
6lowpan IEEE802.15.4
*********************************************************************************************************/
diff --git a/SylixOS/include/net/if_bonding.h b/SylixOS/include/net/if_bonding.h
index e19d96d..af77df8 100644
--- a/SylixOS/include/net/if_bonding.h
+++ b/SylixOS/include/net/if_bonding.h
@@ -45,7 +45,7 @@ extern "C" {
bd_interval 只针对 NETBD_MON_MODE_ARP 监控模式有效.
*********************************************************************************************************/
struct net_bonding_ctl {
- int bd_index; /* Only for NETBD_CTL_ADD return */
+ int bd_index; /* NETBD_CTL_ADD return */
int bd_mode; /* Only for NETBD_CTL_ADD set */
int bd_mon_mode; /* Only for NETBD_CTL_ADD set */
int bd_interval; /* ARP detect period (milliseconds) mode 1 */
@@ -72,6 +72,7 @@ struct net_bonding_ctl {
Bonding 网络设置 MASTER 网卡. (NETBD_MODE_ACTIVE_BACKUP mode only!)
*********************************************************************************************************/
struct net_bonding_device {
+ int bd_index;
char bd_dev[IFNAMSIZ]; /* Bonding device name */
char eth_dev[IFNAMSIZ]; /* Sub ethernet device name */
};
@@ -83,6 +84,7 @@ struct net_bonding_device {
Bonding 网络监控目标. (NETBD_MODE_ACTIVE_BACKUP mode only!)
*********************************************************************************************************/
struct net_bonding_arp {
+ int bd_index;
char bd_dev[IFNAMSIZ]; /* Bonding device name */
char arp_ip_target[64];
};
diff --git a/SylixOS/include/net/if_bridge.h b/SylixOS/include/net/if_bridge.h
index 6924b88..a474434 100644
--- a/SylixOS/include/net/if_bridge.h
+++ b/SylixOS/include/net/if_bridge.h
@@ -40,7 +40,7 @@ extern "C" {
网桥控制参数.
*********************************************************************************************************/
struct net_bridge_ctl {
- int br_index; /* Only for NETBR_CTL_ADD return */
+ int br_index; /* NETBR_CTL_ADD return */
char br_dev[IFNAMSIZ]; /* Bridge device name */
char eth_dev[IFNAMSIZ]; /* Sub ethernet device name */
};
diff --git a/SylixOS/include/netinet/tcp.h b/SylixOS/include/netinet/tcp.h
index afa2232..91bc32e 100644
--- a/SylixOS/include/netinet/tcp.h
+++ b/SylixOS/include/netinet/tcp.h
@@ -64,6 +64,47 @@ struct tcphdr {
u_short th_urp; /* urgent pointer */
} __packed;
+/*********************************************************************************************************
+ TCP describe.
+*********************************************************************************************************/
+
+#define TCP_STATE_CLOSED 0
+#define TCP_STATE_LISTEN 1
+#define TCP_STATE_SYN_SENT 2
+#define TCP_STATE_SYN_RCVD 3
+#define TCP_STATE_ESTABLISHED 4
+#define TCP_STATE_FIN_WAIT_1 5
+#define TCP_STATE_FIN_WAIT_2 6
+#define TCP_STATE_CLOSE_WAIT 7
+#define TCP_STATE_CLOSING 8
+#define TCP_STATE_LAST_ACK 9
+#define TCP_STATE_TIME_WAIT 10
+
+struct tcp_desc {
+ u_char tcp_state;
+ u_char tcp_backlog;
+ u_char tcp_accpend;
+ u_char tcp_rcv_scale;
+ u_char tcp_snd_scale;
+ u_char tcp_pad1[3];
+ u_int tcp_rcv_nxt;
+ u_int tcp_rcv_wnd;
+ u_int tcp_snd_nxt;
+ u_int tcp_snd_wnd;
+ u_int tcp_snd_buf;
+ u_int tcp_cwnd;
+ u_int tcp_ssthresh;
+ u_int tcp_rtime;
+ u_int tcp_mss;
+ u_int tcp_flags;
+ u_int tcp_rcv_ts;
+ u_int tcp_snd_ts;
+ u_int tcp_keep_idle;
+ u_int tcp_keep_intvl;
+ u_int tcp_keep_cnt;
+ u_int tcp_pad2[16];
+};
+
#endif /* __NETINET_TCP_H */
/*********************************************************************************************************
END
diff --git a/SylixOS/include/network/lwip/sockets.h b/SylixOS/include/network/lwip/sockets.h
index b99c61b..9643f41 100644
--- a/SylixOS/include/network/lwip/sockets.h
+++ b/SylixOS/include/network/lwip/sockets.h
@@ -320,6 +320,9 @@ struct linger {
#define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
#define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
#define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
+#ifdef SYLIXOS /* SylixOS Add TCP_DESC Support */
+#define TCP_DESC 0x80
+#endif /* SYLIXOS */
/* SylixOS Add TCP MD5 SIG Support */
#ifdef SYLIXOS
diff --git a/SylixOS/include/sys/semfd.h b/SylixOS/include/sys/semfd.h
index 70a94c3..f6ba6c6 100644
--- a/SylixOS/include/sys/semfd.h
+++ b/SylixOS/include/sys/semfd.h
@@ -43,13 +43,13 @@ typedef enum {
#define SEMFD_OPT_DELETE_SAFE LW_OPTION_DELETE_SAFE /* Only for mutex */
/*********************************************************************************************************
- set/get parameter
+ set/get parameter (Initial value and Max value <= INT32_MAX)
*********************************************************************************************************/
struct semfd_param {
semfd_type sem_type; /* Type */
UINT32 sem_opts; /* Options */
- UINT32 sem_value; /* Initialize value */
+ UINT32 sem_value; /* Initial value */
UINT32 sem_max; /* Max value */
UINT32 auto_unlink; /* unlink on last close */
UINT32 reserved[3];
diff --git a/SylixOS/include/sys/vproc.h b/SylixOS/include/sys/vproc.h
index 56ebf01..c824695 100644
--- a/SylixOS/include/sys/vproc.h
+++ b/SylixOS/include/sys/vproc.h
@@ -53,6 +53,9 @@ LW_API INT vprocDebugFlagsGet(pid_t pid, INT *piFlags);
LW_API INT vprocDebugFlagsSet(pid_t pid, INT piFlags);
#endif /* LW_CFG_GDB_EN > 0 */
+LW_API INT vprocListGet(pid_t pidTable[], UINT uiMaxCnt);
+LW_API INT vprocMemInfo(pid_t pid, size_t *pstStatic, size_t *pstHeap, size_t *pstMmap);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/SylixOS/kernel/core/_ThreadSafeLib.c b/SylixOS/kernel/core/_ThreadSafeLib.c
index 69ae3ac..18671de 100644
--- a/SylixOS/kernel/core/_ThreadSafeLib.c
+++ b/SylixOS/kernel/core/_ThreadSafeLib.c
@@ -101,6 +101,21 @@ VOID _ThreadSafeInternal (VOID)
ptcbCur->TCB_ulId, ptcbCur->TCB_ulThreadSafeCounter, LW_NULL);
}
/*********************************************************************************************************
+** 函数名称: _ThreadSafeInKern
+** 功能描述: 在内核模式指定线程进入安全模式 (内核锁定状态被调用)
+** 输 入 : ptcbDes 目标线程
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID _ThreadSafeInKern (PLW_CLASS_TCB ptcbDes)
+{
+ ptcbDes->TCB_ulThreadSafeCounter++;
+
+ MONITOR_EVT_LONG2(MONITOR_EVENT_ID_THREAD, MONITOR_EVENT_THREAD_SAFE,
+ ptcbDes->TCB_ulId, ptcbDes->TCB_ulThreadSafeCounter, LW_NULL);
+}
+/*********************************************************************************************************
** 函数名称: _ThreadUnsafeInternal
** 功能描述: 当前线程进入安全模式
** 输 入 : NONE
diff --git a/SylixOS/kernel/include/k_api.h b/SylixOS/kernel/include/k_api.h
index 3d05280..b7074e8 100644
--- a/SylixOS/kernel/include/k_api.h
+++ b/SylixOS/kernel/include/k_api.h
@@ -1109,6 +1109,8 @@ LW_API VOID API_InterVectorIpiEx(ULONG ulCPUId,
#if LW_CFG_ISR_DEFER_EN > 0
LW_API PLW_JOB_QUEUE API_InterDeferGet(ULONG ulCPUId); /* 获得对应 CPU 的中断延迟队列 */
+LW_API INT API_InterDeferContext(VOID); /* 是否在中断或 defer 上下文 */
+
LW_API ULONG API_InterDeferJobAdd(PLW_JOB_QUEUE pjobq, VOIDFUNCPTR pfunc, PVOID pvArg);
/* 向中断延迟处理队列加入任务 */
LW_API ULONG API_InterDeferJobDelete(PLW_JOB_QUEUE pjobq, BOOL bMatchArg,
diff --git a/SylixOS/kernel/include/k_class.h b/SylixOS/kernel/include/k_class.h
index e1aebac..03c9966 100644
--- a/SylixOS/kernel/include/k_class.h
+++ b/SylixOS/kernel/include/k_class.h
@@ -697,6 +697,8 @@ typedef struct __lw_tcb {
addr_t TCB_ulStepAddr; /* 单步地址,-1 表示非单步模式 */
ULONG TCB_ulStepInst; /* 单步地址指令备份 */
BOOL TCB_bStepClear; /* 单步断点是否被清除 */
+ addr_t TCB_ulAbortPointAddr; /* 终止点地址 */
+ ULONG TCB_ulAbortPointInst; /* 终止点地址指令备份 */
#endif
/*********************************************************************************************************
@@ -805,11 +807,9 @@ typedef struct __lw_tcb_desc {
ULONG TCBD_ulThreadSafeCounter; /* 线程安全模式标志 */
UINT8 TCBD_ucStackAutoAllocFlag; /* 堆栈是否有系统在堆中开辟 */
-
CHAR TCBD_cThreadName[LW_CFG_OBJECT_NAME_SIZE]; /* 线程名 */
- PVOID TCBD_pvVProcessContext; /* 进程上下文 */
-
+ LONG TCBD_lPid; /* PID */
INT64 TCBD_i64PageFailCounter; /* 缺页中断次数 */
uid_t TCBD_uid; /* 用户 */
diff --git a/SylixOS/kernel/include/k_internal.h b/SylixOS/kernel/include/k_internal.h
index 6a2a374..cec6154 100644
--- a/SylixOS/kernel/include/k_internal.h
+++ b/SylixOS/kernel/include/k_internal.h
@@ -501,10 +501,12 @@ VOID _ThreadUnlock(VOID);
VOID _ThreadSafeSuspend(PLW_CLASS_TCB ptcbCur);
VOID _ThreadSafeResume(PLW_CLASS_TCB ptcb);
VOID _ThreadSafeInternal(VOID);
+VOID _ThreadSafeInKern(PLW_CLASS_TCB ptcbDes);
VOID _ThreadUnsafeInternal(VOID);
VOID _ThreadUnsafeInternalEx(PLW_CLASS_TCB ptcbDes);
#define LW_THREAD_SAFE() _ThreadSafeInternal()
+#define LW_THREAD_SAFE_INKERN(ptcb) _ThreadSafeInKern(ptcb)
#define LW_THREAD_UNSAFE() _ThreadUnsafeInternal()
#define LW_THREAD_UNSAFE_EX(ptcb) _ThreadUnsafeInternalEx(ptcb)
diff --git a/SylixOS/kernel/include/k_kernel.h b/SylixOS/kernel/include/k_kernel.h
index 29b4bfe..ed44732 100644
--- a/SylixOS/kernel/include/k_kernel.h
+++ b/SylixOS/kernel/include/k_kernel.h
@@ -31,6 +31,7 @@
2015.11.20 修改项目代号为: NeZha(哪吒).
2016.10.08 修改项目代号为: LongYuan(龙渊).
2018.01.18 修改项目代号为: Octopus(八爪鱼).
+2019.06.19 修改项目代号为: Tangram(七巧板).
*********************************************************************************************************/
#ifndef __K_KERNEL_H
@@ -49,9 +50,9 @@
*********************************************************************************************************/
#define __SYLIXOS_MAJOR_VER 1
-#define __SYLIXOS_MINOR_VER 9
-#define __SYLIXOS_PATCH_VER 9
-#define __SYLIXOS_PATCH_PAD 9
+#define __SYLIXOS_MINOR_VER 10
+#define __SYLIXOS_PATCH_VER 2
+#define __SYLIXOS_PATCH_PAD 0
/*********************************************************************************************************
版本格式
@@ -80,10 +81,11 @@
__SYLIXOS_PATCH_VER, \
__SYLIXOS_PATCH_PAD)
-#define __SYLIXOS_VERINFO "AIC-OS kernel version: " \
- __SYLIXOS_VERSTR \
- " Code name: " __SYLIXOS_RELSTR
-#define __SYLIXOS_LICENSE "SylixOS license: Commercial & GPL."
+#define __SYLIXOS_RELSTR "Tangram"
+#define __SYLIXOS_VERINFO "SylixOS kernel version: " \
+ __SYLIXOS_VERSTR \
+ " Code name: " __SYLIXOS_RELSTR
+#define __SYLIXOS_LICENSE "SylixOS license: Commercial & GPL."
/*********************************************************************************************************
版本匹配弱符号 (__sylixos_version 版本信息将保留在使用此版本头文件编译的库中)
diff --git a/SylixOS/kernel/interface/InterDefer.c b/SylixOS/kernel/interface/InterDefer.c
index 36c868d..a2c63bc 100644
--- a/SylixOS/kernel/interface/InterDefer.c
+++ b/SylixOS/kernel/interface/InterDefer.c
@@ -28,9 +28,11 @@
每一个 CPU 的 DEFER ISR QUEUE
*********************************************************************************************************/
#if (LW_CFG_SMP_EN > 0) && (LW_CFG_ISR_DEFER_PER_CPU > 0)
+static LW_OBJECT_HANDLE _K_ulIsrDefer[LW_CFG_MAX_PROCESSORS];
static LW_JOB_QUEUE _K_jobqIsrDefer[LW_CFG_MAX_PROCESSORS];
static LW_JOB_MSG _K_jobmsgIsrDefer[LW_CFG_MAX_PROCESSORS][LW_CFG_ISR_DEFER_SIZE];
#else
+static LW_OBJECT_HANDLE _K_ulIsrDefer[1];
static LW_JOB_QUEUE _K_jobqIsrDefer[1];
static LW_JOB_MSG _K_jobmsgIsrDefer[LW_CFG_ISR_DEFER_SIZE];
#endif /* LW_CFG_SMP_EN > 0 */
@@ -66,7 +68,6 @@ VOID _interDeferInit (VOID)
{
CHAR cDefer[LW_CFG_OBJECT_NAME_SIZE] = "t_isrdefer";
LW_CLASS_THREADATTR threadattr;
- LW_OBJECT_HANDLE ulId;
#if (LW_CFG_SMP_EN > 0) && (LW_CFG_ISR_DEFER_PER_CPU > 0)
INT i;
@@ -94,17 +95,17 @@ VOID _interDeferInit (VOID)
lib_itoa(i, &cDefer[10], 10);
API_ThreadAttrSetArg(&threadattr, &_K_jobqIsrDefer[i]);
- ulId = API_ThreadInit(cDefer, _interDeferTask, &threadattr, LW_NULL);
- if (ulId == LW_OBJECT_HANDLE_INVALID) {
+ _K_ulIsrDefer[i] = API_ThreadInit(cDefer, _interDeferTask, &threadattr, LW_NULL);
+ if (_K_ulIsrDefer[i] == LW_OBJECT_HANDLE_INVALID) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "can not create ISR defer task.\r\n");
return;
}
- LW_CPU_SET(i, &cpuset);
- API_ThreadSetAffinity(ulId, sizeof(LW_CLASS_CPUSET), &cpuset); /* 锁定到指定 CPU */
+ LW_CPU_SET(i, &cpuset); /* 锁定到指定 CPU */
+ API_ThreadSetAffinity(_K_ulIsrDefer[i], sizeof(LW_CLASS_CPUSET), &cpuset);
LW_CPU_CLR(i, &cpuset);
- API_ThreadStart(ulId);
+ API_ThreadStart(_K_ulIsrDefer[i]);
}
#else
@@ -125,13 +126,13 @@ VOID _interDeferInit (VOID)
LW_OPTION_THREAD_AFFINITY_ALWAYS),
&_K_jobqIsrDefer[0]);
- ulId = API_ThreadInit(cDefer, _interDeferTask, &threadattr, LW_NULL);
- if (ulId == LW_OBJECT_HANDLE_INVALID) {
+ _K_ulIsrDefer[0] = API_ThreadInit(cDefer, _interDeferTask, &threadattr, LW_NULL);
+ if (_K_ulIsrDefer[0] == LW_OBJECT_HANDLE_INVALID) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "can not create ISR defer task.\r\n");
return;
}
- API_ThreadStart(ulId);
+ API_ThreadStart(_K_ulIsrDefer[0]);
#endif /* LW_CFG_SMP_EN > 0 */
} /* LW_CFG_ISR_DEFER_PER_CPU */
/*********************************************************************************************************
@@ -158,6 +159,55 @@ PLW_JOB_QUEUE API_InterDeferGet (ULONG ulCPUId)
#endif /* LW_CFG_SMP_EN > 0 */
} /* LW_CFG_ISR_DEFER_PER_CPU */
/*********************************************************************************************************
+** 函数名称: API_InterDeferContext
+** 功能描述: 是否在中断延迟队列任务上下文
+** 输 入 : NONE
+** 输 出 : 0: 不在中断上下文也不在中断延迟队列任务上下文
+** 1: 在中断上下文
+** 2: 中断延迟队列任务上下文
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+INT API_InterDeferContext (VOID)
+{
+ INTREG iregInterLevel;
+ ULONG ulNesting;
+ PLW_CLASS_TCB ptcbCur;
+
+ iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
+
+ ulNesting = LW_CPU_GET_CUR()->CPU_ulInterNesting;
+ if (ulNesting) {
+ KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
+ return (1);
+ }
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
+
+#if (LW_CFG_SMP_EN > 0) && (LW_CFG_ISR_DEFER_PER_CPU > 0)
+ {
+ INT i;
+
+ LW_CPU_FOREACH_ACTIVE (i) {
+ if (_K_ulIsrDefer[i] == ptcbCur->TCB_ulId) {
+ return (2);
+ }
+ }
+ }
+
+#else
+ if (_K_ulIsrDefer[0] == ptcbCur->TCB_ulId) {
+ return (2);
+ }
+#endif /* LW_CFG_SMP_EN > 0 */
+
+ return (0);
+}
+/*********************************************************************************************************
** 函数名称: API_InterDeferJobAdd
** 功能描述: 向中断延迟处理队列加入一个任务
** 输 入 : pjobq 队列
diff --git a/SylixOS/kernel/interface/SemaphoreMPend.c b/SylixOS/kernel/interface/SemaphoreMPend.c
index 1412e31..84d9826 100644
--- a/SylixOS/kernel/interface/SemaphoreMPend.c
+++ b/SylixOS/kernel/interface/SemaphoreMPend.c
@@ -42,6 +42,7 @@
2013.07.18 使用新的获取 TCB 的方法, 确保 SMP 系统安全.
2013.12.11 系统没有启动时 pend 操作不工作.
2014.05.29 修复超时后瞬间激活时没有设置任务安全属性错误.
+2019.05.10 安全模式设置必须与获取处于同一原子状态.
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
@@ -132,10 +133,10 @@ __wait_again:
pevent->EVENT_ulCounter = LW_FALSE;
pevent->EVENT_ulMaxCounter = (ULONG)ptcbCur->TCB_ucPriority;
pevent->EVENT_pvTcbOwn = (PVOID)ptcbCur; /* 保存线程信息 */
- __KERNEL_EXIT(); /* 退出内核 */
if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
+ LW_THREAD_SAFE_INKERN(ptcbCur);
}
+ __KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
}
@@ -213,10 +214,7 @@ __wait_again:
} else {
if (ptcbCur->TCB_ucIsEventDelete == LW_EVENT_EXIST) { /* 事件是否存在 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
- }
- return (ERROR_NONE);
+ return (ERROR_NONE); /* 释放操作已将此任务设为安全 */
} else {
_ErrorHandle(ERROR_EVENT_WAS_DELETED); /* 已经被删除 */
diff --git a/SylixOS/kernel/interface/SemaphoreMPost.c b/SylixOS/kernel/interface/SemaphoreMPost.c
index 0fe86c1..4f7ba41 100644
--- a/SylixOS/kernel/interface/SemaphoreMPost.c
+++ b/SylixOS/kernel/interface/SemaphoreMPost.c
@@ -130,12 +130,16 @@ ULONG API_SemaphoreMPost (LW_OBJECT_HANDLE ulId)
_EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) {
+ LW_THREAD_SAFE_INKERN(ptcb); /* 将激活任务设置为安全 */
+ }
+
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMM, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
__KERNEL_EXIT(); /* 退出内核 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 退出安全模式 */
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 本任务退出安全模式 */
LW_THREAD_UNSAFE();
}
return (ERROR_NONE);
@@ -151,7 +155,7 @@ ULONG API_SemaphoreMPost (LW_OBJECT_HANDLE ulId)
__KERNEL_EXIT(); /* 退出内核 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 退出安全模式 */
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 本任务退出安全模式 */
LW_THREAD_UNSAFE();
}
return (ERROR_NONE);
diff --git a/SylixOS/kernel/interface/SemaphoreRWPend.c b/SylixOS/kernel/interface/SemaphoreRWPend.c
index 76d1d37..d619ba9 100644
--- a/SylixOS/kernel/interface/SemaphoreRWPend.c
+++ b/SylixOS/kernel/interface/SemaphoreRWPend.c
@@ -17,6 +17,9 @@
** 文件创建日期: 2016 年 07 月 20 日
**
** 描 述: 等待读写信号量.
+**
+** BUG
+2019.05.10 安全模式设置必须与获取处于同一原子状态.
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
@@ -98,10 +101,10 @@ __wait_again:
if ((pevent->EVENT_iStatus == EVENT_RW_STATUS_R) &&
(_EventWaitNum(EVENT_RW_Q_W, pevent) == 0)) { /* 当前为读状态并且没有写请求 */
pevent->EVENT_ulCounter++; /* 操作数++ */
- __KERNEL_EXIT(); /* 退出内核 */
if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
+ LW_THREAD_SAFE_INKERN(ptcbCur);
}
+ __KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
}
@@ -163,10 +166,7 @@ __wait_again:
} else {
if (ptcbCur->TCB_ucIsEventDelete == LW_EVENT_EXIST) { /* 事件是否存在 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
- }
- return (ERROR_NONE);
+ return (ERROR_NONE); /* 释放操作已将此任务设为安全 */
} else {
_ErrorHandle(ERROR_EVENT_WAS_DELETED); /* 已经被删除 */
@@ -243,10 +243,10 @@ __wait_again:
pevent->EVENT_ulCounter++;
pevent->EVENT_iStatus = EVENT_RW_STATUS_W;
pevent->EVENT_pvTcbOwn = (PVOID)ptcbCur; /* 保存线程信息 */
- __KERNEL_EXIT(); /* 退出内核 */
if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
+ LW_THREAD_SAFE_INKERN(ptcbCur);
}
+ __KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
}
@@ -314,10 +314,7 @@ __wait_again:
} else {
if (ptcbCur->TCB_ucIsEventDelete == LW_EVENT_EXIST) { /* 事件是否存在 */
- if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 安全模式设定 */
- LW_THREAD_SAFE();
- }
- return (ERROR_NONE);
+ return (ERROR_NONE); /* 释放操作已将此任务设为安全 */
} else {
_ErrorHandle(ERROR_EVENT_WAS_DELETED); /* 已经被删除 */
diff --git a/SylixOS/kernel/interface/SemaphoreRWPost.c b/SylixOS/kernel/interface/SemaphoreRWPost.c
index e02e8ee..c1ef8bd 100644
--- a/SylixOS/kernel/interface/SemaphoreRWPost.c
+++ b/SylixOS/kernel/interface/SemaphoreRWPost.c
@@ -136,6 +136,10 @@ __release_pend:
pevent->EVENT_pvTcbOwn = (PVOID)ptcb;
pevent->EVENT_iStatus = EVENT_RW_STATUS_W;
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 将激活任务设置为安全 */
+ LW_THREAD_SAFE_INKERN(ptcb);
+ }
+
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMRW, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
@@ -164,6 +168,10 @@ __release_pend:
KN_INT_ENABLE(iregInterLevel); /* 打开中断 */
_EventReadyHighLevel(ptcb, LW_THREAD_STATUS_SEM); /* 处理 TCB */
+ if (pevent->EVENT_ulOption & LW_OPTION_DELETE_SAFE) { /* 将激活任务设置为安全 */
+ LW_THREAD_SAFE_INKERN(ptcb);
+ }
+
MONITOR_EVT_LONG2(MONITOR_EVENT_ID_SEMRW, MONITOR_EVENT_SEM_POST,
ulId, ptcb->TCB_ulId, LW_NULL);
diff --git a/SylixOS/kernel/interface/ThreadDelete.c b/SylixOS/kernel/interface/ThreadDelete.c
index fbd7d9d..7c473ca 100644
--- a/SylixOS/kernel/interface/ThreadDelete.c
+++ b/SylixOS/kernel/interface/ThreadDelete.c
@@ -360,6 +360,8 @@ ULONG API_ThreadDelete (LW_OBJECT_HANDLE *pulId, PVOID pvRetVal)
ptcbCur->TCB_ulThreadSafeCounter++; /* LW_THREAD_SAFE(); */
+ __KERNEL_SPACE_SET2(ptcbDel, 0); /* 目标任务退出内核环境 */
+
__KERNEL_EXIT(); /* 退出内核 */
if (ptcbDel == ptcbCur) {
diff --git a/SylixOS/kernel/interface/ThreadDesc.c b/SylixOS/kernel/interface/ThreadDesc.c
index 8cf5a71..21fac4d 100644
--- a/SylixOS/kernel/interface/ThreadDesc.c
+++ b/SylixOS/kernel/interface/ThreadDesc.c
@@ -21,6 +21,12 @@
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
/*********************************************************************************************************
+ 进程相关
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_EN > 0
+#include "../SylixOS/loader/include/loader_vppatch.h"
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+/*********************************************************************************************************
** 函数名称: API_ThreadDesc
** 功能描述: 获得线程基本信息
** 输 入 : ulId 线程句柄
@@ -37,6 +43,10 @@ ULONG API_ThreadDesc (LW_OBJECT_HANDLE ulId, PLW_CLASS_TCB_DESC ptcbdesc)
REGISTER UINT16 usIndex;
REGISTER PLW_CLASS_TCB ptcb;
INT i;
+
+#if LW_CFG_MODULELOADER_EN > 0
+ LW_LD_VPROC *pvproc;
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
usIndex = _ObjectGetIndex(ulId);
@@ -144,7 +154,12 @@ ULONG API_ThreadDesc (LW_OBJECT_HANDLE ulId, PLW_CLASS_TCB_DESC ptcbdesc)
lib_strcpy(ptcbdesc->TCBD_cThreadName, ptcb->TCB_cThreadName);
- ptcbdesc->TCBD_pvVProcessContext = ptcb->TCB_pvVProcessContext;
+#if LW_CFG_MODULELOADER_EN > 0
+ pvproc = __LW_VP_GET_TCB_PROC(ptcb);
+ ptcbdesc->TCBD_lPid = (LONG)((pvproc) ? pvproc->VP_pid : 0);
+#else
+ ptcbdesc->TCBD_lPid = 0;
+#endif
ptcbdesc->TCBD_i64PageFailCounter = ptcb->TCB_i64PageFailCounter;
diff --git a/SylixOS/kernel/interface/ThreadGetCPUUsage.c b/SylixOS/kernel/interface/ThreadGetCPUUsage.c
index 0c696f9..4ea2516 100644
--- a/SylixOS/kernel/interface/ThreadGetCPUUsage.c
+++ b/SylixOS/kernel/interface/ThreadGetCPUUsage.c
@@ -215,9 +215,15 @@ INT API_ThreadGetCPUUsageAll (LW_OBJECT_HANDLE ulId[],
uiUsageKernel = (uiUsageKernel / 10); /* 四舍 */
}
- ulId[iIndex] = ptcb->TCB_ulId;
- uiThreadUsage[iIndex] = uiUsage;
- uiKernelUsage[iIndex] = uiUsageKernel;
+ if (ulId) {
+ ulId[iIndex] = ptcb->TCB_ulId;
+ }
+ if (uiThreadUsage) {
+ uiThreadUsage[iIndex] = uiUsage;
+ }
+ if (uiKernelUsage) {
+ uiKernelUsage[iIndex] = uiUsageKernel;
+ }
iIndex++;
if (iIndex >= iSize) {
diff --git a/SylixOS/kernel/interface/ThreadSetPriority.c b/SylixOS/kernel/interface/ThreadSetPriority.c
index a254bed..8c78905 100644
--- a/SylixOS/kernel/interface/ThreadSetPriority.c
+++ b/SylixOS/kernel/interface/ThreadSetPriority.c
@@ -84,6 +84,12 @@ ULONG API_ThreadSetPriority (LW_OBJECT_HANDLE ulId, UINT8 ucPriority)
ptcb = _K_ptcbTCBIdTable[usIndex];
+ if (ptcb->TCB_iDeleteProcStatus) {
+ __KERNEL_EXIT(); /* 退出内核 */
+ _ErrorHandle(ERROR_THREAD_OTHER_DELETE);
+ return (ERROR_THREAD_OTHER_DELETE);
+ }
+
if (LW_PRIO_IS_EQU(ptcb->TCB_ucPriority, ucPriority)) {
__KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
diff --git a/SylixOS/kernel/show/CPUUsageShow.c b/SylixOS/kernel/show/CPUUsageShow.c
index f4cd803..05814be 100644
--- a/SylixOS/kernel/show/CPUUsageShow.c
+++ b/SylixOS/kernel/show/CPUUsageShow.c
@@ -36,12 +36,6 @@
#if LW_CFG_FIO_LIB_EN > 0 && LW_CFG_THREAD_CPU_USAGE_CHK_EN > 0
#include "../SylixOS/shell/include/ttiny_shell.h"
/*********************************************************************************************************
- 进程相关
-*********************************************************************************************************/
-#if LW_CFG_MODULELOADER_EN > 0
-#include "../SylixOS/loader/include/loader_vppatch.h"
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
-/*********************************************************************************************************
全局变量
*********************************************************************************************************/
static const CHAR _G_cCPUUsageInfoHdr[] = "\n\
@@ -80,7 +74,6 @@ VOID API_CPUUsageShow (INT iWaitSec, INT iTimes)
INT iOption;
LW_CLASS_TCB_DESC tcbdesc;
- pid_t pidGet;
if (LW_CPU_GET_CUR_NESTING()) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
@@ -136,16 +129,10 @@ VOID API_CPUUsageShow (INT iWaitSec, INT iTimes)
} else if (uiThreadUsage[i] > ulLitePercent) {
API_TShellColorStart2(LW_TSHELL_COLOR_GREEN, STD_OUT);
}
-
-#if LW_CFG_MODULELOADER_EN > 0
- pidGet = vprocGetPidByTcbdesc(&tcbdesc);
-#else
- pidGet = 0;
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
- printf("%-16s %7lx %5d %3d %3d.%d%% %3d.%d%%\n",
+ printf("%-16s %7lx %5ld %3d %3d.%d%% %3d.%d%%\n",
tcbdesc.TCBD_cThreadName, ulId[i],
- pidGet, tcbdesc.TCBD_ucPriority,
+ tcbdesc.TCBD_lPid, tcbdesc.TCBD_ucPriority,
uiThreadUsage[i] / 10, uiThreadUsage[i] % 10,
uiThreadKernel[i] / 10, uiThreadKernel[i] % 10);
diff --git a/SylixOS/kernel/show/ThreadShow.c b/SylixOS/kernel/show/ThreadShow.c
index 7994676..d9143bf 100644
--- a/SylixOS/kernel/show/ThreadShow.c
+++ b/SylixOS/kernel/show/ThreadShow.c
@@ -84,7 +84,6 @@ VOID API_ThreadShowEx (pid_t pid)
PCHAR pcPendType = LW_NULL;
PCHAR pcFpu = LW_NULL;
- pid_t pidGet;
if (LW_CPU_GET_CUR_NESTING()) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
@@ -105,22 +104,13 @@ VOID API_ThreadShowEx (pid_t pid)
continue;
}
-#if LW_CFG_MODULELOADER_EN > 0
- pidGet = vprocGetPidByTcbdesc(&tcbdesc);
-#else
- pidGet = 0;
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
-
- if ((pidGet != pid) && (pid != -1)) {
+ if (((pid_t)tcbdesc.TCBD_lPid != pid) && (pid != -1)) {
continue;
}
-#if LW_CFG_CPU_WORD_LENGHT == 64
- if (tcbdesc.TCBD_ulWakeupLeft > 999999999l) {
+ if (tcbdesc.TCBD_ulWakeupLeft > INT_MAX) {
lib_strcpy(cWakeupLeft, "--");
- } else
-#endif
- {
+ } else {
lib_itoa((int)tcbdesc.TCBD_ulWakeupLeft, cWakeupLeft, 10);
}
@@ -167,10 +157,10 @@ VOID API_ThreadShowEx (pid_t pid)
pcFpu = "";
}
- printf("%-16s %7lx %5d %3d %-4s %4ld %-4s %10s %9llu %-3s %3ld\n",
+ printf("%-16s %7lx %5ld %3d %-4s %4ld %-4s %10s %9llu %-3s %3ld\n",
tcbdesc.TCBD_cThreadName, /* 线程名 */
tcbdesc.TCBD_ulId, /* ID 号 */
- pidGet, /* 所属进程 ID */
+ tcbdesc.TCBD_lPid, /* 所属进程 ID */
tcbdesc.TCBD_ucPriority, /* 优先级 */
pcPendType, /* 状态 */
tcbdesc.TCBD_ulThreadLockCounter, /* 线程锁 */
@@ -213,7 +203,6 @@ VOID API_ThreadPendShowEx (pid_t pid)
/* (LW_CFG_MAX_EVENTSETS > 0) */
CHAR cWakeupLeft[11];
PCHAR pcPendType = LW_NULL;
- pid_t pidGet;
CHAR cEventName[LW_CFG_OBJECT_NAME_SIZE + 2];
LW_OBJECT_HANDLE ulEvent;
LW_OBJECT_HANDLE ulOwner;
@@ -324,22 +313,13 @@ VOID API_ThreadPendShowEx (pid_t pid)
continue;
}
-#if LW_CFG_MODULELOADER_EN > 0
- pidGet = vprocGetPidByTcbdesc(&tcbdesc);
-#else
- pidGet = 0;
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
-
- if ((pidGet != pid) && (pid != -1)) {
+ if (((pid_t)tcbdesc.TCBD_lPid != pid) && (pid != -1)) {
continue;
}
-#if LW_CFG_CPU_WORD_LENGHT == 64
- if (tcbdesc.TCBD_ulWakeupLeft > 9999999999l) {
+ if (tcbdesc.TCBD_ulWakeupLeft > INT_MAX) {
lib_strcpy(cWakeupLeft, "--");
- } else
-#endif
- {
+ } else {
lib_itoa((int)tcbdesc.TCBD_ulWakeupLeft, cWakeupLeft, 10);
}
@@ -381,20 +361,20 @@ VOID API_ThreadPendShowEx (pid_t pid)
}
if (ulOwner) {
- printf("%-16s %7lx %5d %-4s %10s %8lx:%-14s %7lx\n",
+ printf("%-16s %7lx %5ld %-4s %10s %8lx:%-14s %7lx\n",
tcbdesc.TCBD_cThreadName, /* 线程名 */
tcbdesc.TCBD_ulId, /* ID 号 */
- pidGet, /* 所属进程 ID */
+ tcbdesc.TCBD_lPid, /* 所属进程 ID */
pcPendType, /* 状态 */
cWakeupLeft, /* 等待计数器 */
ulEvent,
cEventName,
ulOwner);
} else {
- printf("%-16s %7lx %5d %-4s %10s %8lx:%-14s\n",
+ printf("%-16s %7lx %5ld %-4s %10s %8lx:%-14s\n",
tcbdesc.TCBD_cThreadName, /* 线程名 */
tcbdesc.TCBD_ulId, /* ID 号 */
- pidGet, /* 所属进程 ID */
+ tcbdesc.TCBD_lPid, /* 所属进程 ID */
pcPendType, /* 状态 */
cWakeupLeft, /* 等待计数器 */
ulEvent,
@@ -492,7 +472,6 @@ VOID API_ThreadPendShow (VOID)
{
API_ThreadPendShowEx(PX_ERROR); /* 显示所有线程 */
}
-
/*********************************************************************************************************
** 函数名称: API_ThreadWjShow
** 功能描述: 显示已经删除但未被 join 的线程信息
diff --git a/SylixOS/kernel/vmm/vmmMmap.c b/SylixOS/kernel/vmm/vmmMmap.c
index 57f4755..45572be 100644
--- a/SylixOS/kernel/vmm/vmmMmap.c
+++ b/SylixOS/kernel/vmm/vmmMmap.c
@@ -245,7 +245,7 @@ __full_with_zero:
** 功能描述: 分配虚拟空间
** 输 入 : pmapn mmap node
** stLen 内存大小
-** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE
+** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE / LW_VMM_PHY_PREALLOC
** ulFlag 虚拟空间内存属性
** 输 出 : 内存地址
** 全局变量:
@@ -255,9 +255,14 @@ static PVOID __vmmMapnMalloc (PLW_VMM_MAP_NODE pmapn, size_t stLen, INT iFla
{
REGISTER PVOID pvMem;
- pvMem = API_VmmMallocAreaEx(stLen, __vmmMapnFill, pmapn, iFlags, ulFlag);
- if (pvMem) {
- API_VmmSetFindShare(pvMem, __vmmMapnFindShare, pmapn);
+ if (iFlags & LW_VMM_PHY_PREALLOC) {
+ pvMem = API_VmmMallocEx(stLen, ulFlag);
+
+ } else {
+ pvMem = API_VmmMallocAreaEx(stLen, __vmmMapnFill, pmapn, iFlags, ulFlag);
+ if (pvMem) {
+ API_VmmSetFindShare(pvMem, __vmmMapnFindShare, pmapn);
+ }
}
return (pvMem);
@@ -353,7 +358,7 @@ static VOID __vmmMapnReclaim (PLW_VMM_MAP_NODE pmapn, LW_LD_VPROC *pvproc)
** 函数名称: __vmmMmapNew
** 功能描述: 分配一段新的虚拟内存
** 输 入 : stLen 映射长度
-** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE
+** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE / LW_VMM_PHY_PREALLOC
** ulFlag LW_VMM_FLAG_READ | LW_VMM_FLAG_RDWR | LW_VMM_FLAG_EXEC
** iFd 文件描述符
** off 文件偏移量
@@ -379,10 +384,10 @@ static PVOID __vmmMmapNew (size_t stLen, INT iFlags, ULONG ulFlag, int iFd,
if (iosFdGetFlag(iFd, &iFileFlag) < 0) { /* 获得文件权限 */
_ErrorHandle(EBADF);
return (LW_VMM_MAP_FAILED);
- }
+ }
iFileFlag &= O_ACCMODE;
- if (iFlags == LW_VMM_SHARED_CHANGE) {
+ if (iFlags & LW_VMM_SHARED_CHANGE) {
if ((ulFlag & LW_VMM_FLAG_WRITABLE) &&
(iFileFlag == O_RDONLY)) { /* 带有写权限映射只读文件 */
_ErrorHandle(EACCES);
@@ -532,6 +537,12 @@ static PVOID __vmmMmapChange (PVOID pvAddr, size_t stLen, INT iFlags,
return (LW_VMM_MAP_FAILED);
}
+ if ((iFlags & LW_VMM_PHY_PREALLOC) ||
+ (pmapn->MAPN_iFlags & LW_VMM_PHY_PREALLOC)) { /* 预分配型内存不允许更改 */
+ _ErrorHandle(ENOTSUP);
+ return (LW_VMM_MAP_FAILED);
+ }
+
if ((pmapn->MAPN_iFd != iFd) ||
(pmapn->MAPN_off != off) ||
(pmapn->MAPN_iFlags != iFlags) ||
@@ -719,7 +730,7 @@ static VOID __vmmMmapMerge (PLW_VMM_MAP_NODE pmapnL, PLW_VMM_MAP_NODE pmapnR)
** 功能描述: 内存文件映射.
** 输 入 : pvAddr 虚拟地址
** stLen 映射长度
-** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE
+** iFlags LW_VMM_SHARED_CHANGE / LW_VMM_PRIVATE_CHANGE / LW_VMM_PHY_PREALLOC
** ulFlag LW_VMM_FLAG_READ | LW_VMM_FLAG_RDWR | LW_VMM_FLAG_EXEC
** iFd 文件描述符
** off 文件偏移量
@@ -733,8 +744,8 @@ PVOID API_VmmMmap (PVOID pvAddr, size_t stLen, INT iFlags, ULONG ulFlag, IN
{
PVOID pvRet;
- if ((iFlags != LW_VMM_SHARED_CHANGE) &&
- (iFlags != LW_VMM_PRIVATE_CHANGE)) {
+ if ((iFlags & LW_VMM_SHARED_CHANGE) &&
+ (iFlags & LW_VMM_PRIVATE_CHANGE)) { /* 不允许同时出现两个 */
_ErrorHandle(EINVAL);
return (LW_VMM_MAP_FAILED);
}
@@ -747,7 +758,7 @@ PVOID API_VmmMmap (PVOID pvAddr, size_t stLen, INT iFlags, ULONG ulFlag, IN
stLen = ROUND_UP(stLen, LW_CFG_VMM_PAGE_SIZE); /* 变成页面对齐大小 */
#if LW_CFG_CACHE_EN > 0
- if (iFlags == LW_VMM_SHARED_CHANGE) {
+ if (iFlags & LW_VMM_SHARED_CHANGE) {
if (API_CacheAliasProb()) { /* 如果有 CACHE 别名可能 */
ulFlag &= ~(LW_VMM_FLAG_CACHEABLE | LW_VMM_FLAG_WRITETHROUGH);
} /* 共享内存不允许任何形式 CACHE*/
@@ -799,6 +810,11 @@ PVOID API_VmmMremap (PVOID pvAddr, size_t stOldSize, size_t stNewSize, INT iM
return (LW_VMM_MAP_FAILED);
}
+ if (pmapn->MAPN_iFlags & LW_VMM_PHY_PREALLOC) { /* 预分配型内存不允许更改 */
+ _ErrorHandle(ENOTSUP);
+ return (LW_VMM_MAP_FAILED);
+ }
+
if ((pmapn->MAPN_pvAddr != pvAddr) ||
(pmapn->MAPN_stLen != stOldSize)) { /* 只支持完整空间操作 */
__VMM_MMAP_UNLOCK();
@@ -860,6 +876,13 @@ __goon:
return (PX_ERROR);
}
+ if ((pmapn->MAPN_iFlags & LW_VMM_PHY_PREALLOC) &&
+ ((pmapn->MAPN_pvAddr != pvAddr) || (pmapn->MAPN_stLen != stLen))) {
+ __VMM_MMAP_UNLOCK(); /* 预分配型内存不允许更改 */
+ _ErrorHandle(ENOTSUP);
+ return (PX_ERROR);
+ }
+
pmapnL = LW_NULL;
if (pmapn->MAPN_pvAddr != pvAddr) { /* 将左侧分段隔开 */
@@ -1027,7 +1050,7 @@ INT API_VmmMsync (PVOID pvAddr, size_t stLen, INT iInval)
if (iInval) {
API_VmmInvalidateArea(pmapn->MAPN_pvAddr, pvAddr, stLen); /* 释放对应的物理内存 */
- } else if (pmapn->MAPN_iFlags == LW_VMM_SHARED_CHANGE) { /* SHARED 类型可以回写文件 */
+ } else if (pmapn->MAPN_iFlags & LW_VMM_SHARED_CHANGE) { /* SHARED 类型可以回写文件 */
INT i;
ULONG ulPageNum;
size_t stExcess;
@@ -1116,7 +1139,7 @@ VOID API_VmmMmapShow (VOID)
pcWrite = "false";
}
- if (pmapn->MAPN_iFlags == LW_VMM_SHARED_CHANGE) {
+ if (pmapn->MAPN_iFlags & LW_VMM_SHARED_CHANGE) {
pcShare = "true ";
} else {
pcShare = "false";
diff --git a/SylixOS/kernel/vmm/vmmSwap.h b/SylixOS/kernel/vmm/vmmSwap.h
index e3887b6..ddf5e85 100644
--- a/SylixOS/kernel/vmm/vmmSwap.h
+++ b/SylixOS/kernel/vmm/vmmSwap.h
@@ -56,8 +56,9 @@ typedef struct {
LW_LIST_LINE PAGEP_lineManage; /* area 链表 */
PLW_VMM_PAGE PAGEP_pvmpageVirtual; /* 回指虚拟页面控制块 */
-#define LW_VMM_SHARED_CHANGE 1
-#define LW_VMM_PRIVATE_CHANGE 2
+#define LW_VMM_SHARED_CHANGE 0x1 /* 共享更改 */
+#define LW_VMM_PRIVATE_CHANGE 0x2 /* 写时拷贝 */
+#define LW_VMM_PHY_PREALLOC 0x4 /* 物理内存预分配 */
INT PAGEP_iFlags; /* like mmap flags */
FUNCPTR PAGEP_pfuncFiller; /* 页面填充器 */
diff --git a/SylixOS/lib/libc/error/lib_panic.c b/SylixOS/lib/libc/error/lib_panic.c
index f87f632..146db8e 100644
--- a/SylixOS/lib/libc/error/lib_panic.c
+++ b/SylixOS/lib/libc/error/lib_panic.c
@@ -49,7 +49,7 @@ void panic (const char *pcFormat, ...)
/* (LW_CFG_FIO_LIB_EN > 0) */
if (getpid() > 0) { /* 进程内 panic */
#if LW_CFG_SIGNAL_EN > 0
- kill(getpid(), SIGABRT);
+ kill(getpid(), SIGKILL);
#endif /* LW_CFG_SIGNAL_EN > 0 */
API_ThreadForceDelete(&ulMe, (PVOID)EXIT_FAILURE);
diff --git a/SylixOS/lib/libc/stdlib/lib_system.c b/SylixOS/lib/libc/stdlib/lib_system.c
index a586a90..3600f4b 100644
--- a/SylixOS/lib/libc/stdlib/lib_system.c
+++ b/SylixOS/lib/libc/stdlib/lib_system.c
@@ -34,16 +34,29 @@
*********************************************************************************************************/
VOID lib_abort (VOID)
{
- LW_OBJECT_HANDLE ulMe = API_ThreadIdSelf();
+ LW_OBJECT_HANDLE ulMe;
#if LW_CFG_SIGNAL_EN > 0
- if (getpid() > 0) {
- kill(getpid(), SIGABRT);
+ pid_t pidMe;
+
+ pidMe = getpid();
+ if (pidMe > 0) {
+ kill(pidMe, SIGABRT);
+ } else {
+ raise(SIGABRT);
+ }
+
+ sleep(1);
+ signal(SIGABRT, SIG_DFL);
+
+ if (pidMe > 0) {
+ kill(pidMe, SIGABRT);
} else {
raise(SIGABRT);
}
#endif /* LW_CFG_SIGNAL_EN > 0 */
+ ulMe = API_ThreadIdSelf();
API_ThreadForceDelete(&ulMe, (PVOID)EXIT_FAILURE);
}
/*********************************************************************************************************
diff --git a/SylixOS/loader/include/loader_vppatch.h b/SylixOS/loader/include/loader_vppatch.h
index 8af3e69..16a7840 100644
--- a/SylixOS/loader/include/loader_vppatch.h
+++ b/SylixOS/loader/include/loader_vppatch.h
@@ -84,8 +84,8 @@ typedef struct lw_ld_vproc {
#define __LW_VP_INIT 0
#define __LW_VP_RUN 1
-#define __LW_VP_EXIT 2
-#define __LW_VP_STOP 3
+#define __LW_VP_STOP 2
+#define __LW_VP_EXIT 3
INT VP_iStatus; /* 当前进程状态 */
INT VP_iExitCode; /* 结束代码 */
INT VP_iSigCode; /* iSigCode */
@@ -163,7 +163,6 @@ LW_LD_VPROC *vprocGetCur(VOID);
VOID vprocSetCur(LW_LD_VPROC *pvproc);
pid_t vprocGetPidByTcb(PLW_CLASS_TCB ptcb);
pid_t vprocGetPidByTcbNoLock(PLW_CLASS_TCB ptcb);
-pid_t vprocGetPidByTcbdesc(PLW_CLASS_TCB_DESC ptcbdesc);
pid_t vprocGetPidByThread(LW_OBJECT_HANDLE ulId);
VOID vprocKillPrepare(pid_t pid, LW_OBJECT_HANDLE ulId);
LW_OBJECT_HANDLE vprocMainThread(pid_t pid);
@@ -195,14 +194,30 @@ ssize_t vprocGetModsSvr4Info(pid_t pid, PCHAR pcBuff, size_t stMax
#endif /* LW_CFG_GDB_EN > 0 */
/*********************************************************************************************************
+ 进程内存信息
+*********************************************************************************************************/
+
+INT vprocMemInfoNoLock(LW_LD_VPROC *pvproc,
+ size_t *pstStatic, size_t *pstHeap, size_t *pstMmap);
+
+/*********************************************************************************************************
进程内部线程操作
*********************************************************************************************************/
VOID vprocThreadAdd(PVOID pvVProc, PLW_CLASS_TCB ptcb);
VOID vprocThreadDelete(PVOID pvVProc, PLW_CLASS_TCB ptcb);
-INT vprocThreadNum(pid_t pid, ULONG *pulNum);
VOID vprocThreadKill(PVOID pvVProc, PLW_CLASS_TCB ptcbExcp);
+INT vprocThreadNum(pid_t pid, ULONG *pulNum);
+INT vprocThreadTraversal(pid_t pid,
+ VOIDFUNCPTR pfunc,
+ PVOID pvArg0,
+ PVOID pvArg1,
+ PVOID pvArg2,
+ PVOID pvArg3,
+ PVOID pvArg4,
+ PVOID pvArg5);
+
#if LW_CFG_SIGNAL_EN > 0
INT vprocThreadSigaction(PVOID pvVProc, VOIDFUNCPTR pfunc, INT iSigIndex,
const struct sigaction *psigactionNew);
diff --git a/SylixOS/loader/src/loader.c b/SylixOS/loader/src/loader.c
index e8a2c32..5bd95ce 100644
--- a/SylixOS/loader/src/loader.c
+++ b/SylixOS/loader/src/loader.c
@@ -64,6 +64,12 @@
#include "../elf/elf_arch.h"
#endif /* defined(LW_CFG_CPU_ARCH_C6X)*/
/*********************************************************************************************************
+ POSIX
+*********************************************************************************************************/
+#if LW_CFG_POSIX_EN > 0
+VOID _PthreadKeyCleanup(PLW_CLASS_TCB ptcbDel);
+#endif /* LW_CFG_POSIX_EN > 0 */
+/*********************************************************************************************************
模块进程模型
SylixOS 使用一个虚拟地址空间映射关系, 所以这里面的进程只能称为一个没有独立寻址空间的进程框架, 主要是为了
@@ -1036,6 +1042,9 @@ INT API_ModuleFinish (PVOID pvVProc)
{
LW_LD_VPROC *pvproc = (LW_LD_VPROC *)pvVProc;
LW_LD_EXEC_MODULE *pmodule;
+#if LW_CFG_POSIX_EN > 0
+ PLW_CLASS_TCB ptcbCur;
+#endif /* LW_CFG_POSIX_EN > 0 */
if (pvproc == LW_NULL) {
_ErrorHandle(ERROR_LOADER_PARAM_NULL);
@@ -1052,6 +1061,11 @@ INT API_ModuleFinish (PVOID pvVProc)
finiArrayCall(pmodule, !pvproc->VP_bImmediatelyTerm); /* 调用c++析构函数代码 */
+#if LW_CFG_POSIX_EN > 0
+ LW_TCB_GET_CUR_SAFE(ptcbCur);
+ _PthreadKeyCleanup(ptcbCur); /* 提前执行 key cleanup 操作 */
+#endif /* LW_CFG_POSIX_EN > 0 */
+
__moduleVpPatchFini(pmodule);
return (ERROR_NONE);
diff --git a/SylixOS/loader/src/loader_malloc.c b/SylixOS/loader/src/loader_malloc.c
index 89f86a8..0cb8e84 100644
--- a/SylixOS/loader/src/loader_malloc.c
+++ b/SylixOS/loader/src/loader_malloc.c
@@ -354,7 +354,7 @@ PVOID __ldMallocAreaAlign (size_t stLen, size_t stAlign)
LW_VMM_FLAG_EXEC | LW_VMM_FLAG_RDWR));
#else
-#ifdef defined(LW_CFG_CPU_ARCH_C6X) && (LW_CFG_C6X_CUSTOM_MEM > 0)
+#if defined(LW_CFG_CPU_ARCH_C6X) && (LW_CFG_C6X_CUSTOM_MEM > 0)
if (__ldUseBspCustomMem()) {
PVOID pvAddr = bspLibMemCustomAllocAlign(stLen, stAlign);
if (pvAddr != LW_NULL) {
@@ -389,7 +389,7 @@ VOID __ldFreeArea (PVOID pvAddr)
API_VmmFreeArea(pvAddr);
#else
-#ifdef defined(LW_CFG_CPU_ARCH_C6X) && (LW_CFG_C6X_CUSTOM_MEM > 0)
+#if defined(LW_CFG_CPU_ARCH_C6X) && (LW_CFG_C6X_CUSTOM_MEM > 0)
if (bspLibIsInMemCustom(pvAddr)) {
bspLibMemCustomFree(pvAddr);
return;
diff --git a/SylixOS/loader/src/loader_proc.c b/SylixOS/loader/src/loader_proc.c
index 2e26c3d..616869c 100644
--- a/SylixOS/loader/src/loader_proc.c
+++ b/SylixOS/loader/src/loader_proc.c
@@ -31,7 +31,6 @@
*********************************************************************************************************/
#if (LW_CFG_MODULELOADER_EN > 0) && (LW_CFG_PROCFS_EN > 0)
#include "../include/loader_lib.h"
-#include "../include/loader_symbol.h"
/*********************************************************************************************************
对应文件信息
*********************************************************************************************************/
@@ -188,21 +187,9 @@ static ssize_t __procFsProcMemRead (PLW_PROCFS_NODE p_pfsn,
stRealSize = API_ProcFsNodeGetRealFileSize(p_pfsn);
if (stRealSize == 0) { /* 需要生成文件 */
- INT i, iNum;
- ULONG ulPages;
- size_t stTotalMem;
- size_t stMmapSize = 0;
size_t stStatic;
- BOOL bStart;
-
- LW_LIST_RING *pringTemp;
- LW_LD_EXEC_MODULE *pmodTemp;
-
-#if LW_CFG_VMM_EN == 0
- PLW_CLASS_HEAP pheapVpPatch;
-#endif /* LW_CFG_VMM_EN == 0 */
-
- PVOID pvVmem[LW_LD_VMEM_MAX];
+ size_t stHeapMem;
+ size_t stMmap;
LW_LD_LOCK();
pvproc = (LW_LD_VPROC *)p_pfsn->PFSN_pvValue;
@@ -211,53 +198,7 @@ static ssize_t __procFsProcMemRead (PLW_PROCFS_NODE p_pfsn,
return (PX_ERROR);
}
- LW_VP_LOCK(pvproc);
- stTotalMem = 0;
- for (pringTemp = pvproc->VP_ringModules, bStart = LW_TRUE;
- pringTemp && (pringTemp != pvproc->VP_ringModules || bStart);
- pringTemp = _list_ring_get_next(pringTemp), bStart = LW_FALSE) {
-
- pmodTemp = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
-
-#if LW_CFG_VMM_EN > 0
- ulPages = 0;
- if (API_VmmPCountInArea(pmodTemp->EMOD_pvBaseAddr, &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
- }
-#else
- stTotalMem += pmodTemp->EMOD_stLen;
-#endif /* LW_CFG_VMM_EN > 0 */
- stTotalMem += __moduleSymbolBufferSize(pmodTemp);
- }
- stStatic = stTotalMem;
-
- if (stTotalMem) { /* 至少存在一个模块 */
- pmodTemp = _LIST_ENTRY(pvproc->VP_ringModules, LW_LD_EXEC_MODULE, EMOD_ringModules);
- ulPages = 0;
-
-#if LW_CFG_VMM_EN > 0
- iNum = __moduleVpPatchVmem(pmodTemp, pvVmem, LW_LD_VMEM_MAX);
- if (iNum > 0) {
- for (i = 0; i < iNum; i++) {
- if (API_VmmPCountInArea(pvVmem[i],
- &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages
- << LW_CFG_VMM_PAGE_SHIFT);
- }
- }
- }
-#else
- pheapVpPatch = (PLW_CLASS_HEAP)__moduleVpPatchHeap(pmodTemp);
- if (pheapVpPatch) { /* 获得 vp 进程私有 heap */
- stTotalMem += (size_t)(pheapVpPatch->HEAP_stTotalByteSize);
- }
-#endif /* LW_CFG_VMM_EN > 0 */
- }
- LW_VP_UNLOCK(pvproc);
-
-#if LW_CFG_VMM_EN > 0
- API_VmmMmapPCount(pvproc->VP_pid, &stMmapSize); /* 计算 mmap 内存实际消耗量 */
-#endif /* LW_CFG_VMM_EN > 0 */
+ vprocMemInfoNoLock(pvproc, &stStatic, &stHeapMem, &stMmap);
LW_LD_UNLOCK();
stRealSize = bnprintf(pcFileBuffer,
@@ -266,8 +207,8 @@ static ssize_t __procFsProcMemRead (PLW_PROCFS_NODE p_pfsn,
"heap memory : %zu Bytes\n"
"mmap memory : %zu Bytes\n"
"total memory : %zu Bytes",
- stStatic, (stTotalMem - stStatic),
- stMmapSize, (stTotalMem + stMmapSize));
+ stStatic, stHeapMem, stMmap,
+ stStatic + stHeapMem + stMmap);
API_ProcFsNodeSetRealFileSize(p_pfsn, stRealSize);
}
diff --git a/SylixOS/loader/src/loader_shell.c b/SylixOS/loader/src/loader_shell.c
index 773e52d..2f5400b 100644
--- a/SylixOS/loader/src/loader_shell.c
+++ b/SylixOS/loader/src/loader_shell.c
@@ -62,7 +62,6 @@
#if LW_CFG_MODULELOADER_EN > 0
#include "pwd.h"
#include "../include/loader_lib.h"
-#include "../include/loader_symbol.h"
/*********************************************************************************************************
进程列表
*********************************************************************************************************/
@@ -720,17 +719,12 @@ static INT __tshellModuleShow (INT iArgC, PCHAR *ppcArgV)
LW_LD_VPROC *pvproc;
LW_LD_EXEC_MODULE *pmodTemp;
-#if LW_CFG_VMM_EN == 0
- PLW_CLASS_HEAP pheapVpPatch;
-#endif /* LW_CFG_VMM_EN == 0 */
-
+ size_t stStatic;
+ size_t stHeapMem;
+ size_t stMmapMem;
+
CHAR cVpVersion[128] = "";
- INT i, iNum;
- ULONG ulPages;
- size_t stTotalMem;
- PVOID pvVmem[LW_LD_VMEM_MAX];
-
if (iArgC < 2) {
pcFileName = LW_NULL;
} else {
@@ -753,66 +747,12 @@ static INT __tshellModuleShow (INT iArgC, PCHAR *ppcArgV)
}
}
- /*
- * 计算 vp 进程总内存消耗.
- */
- LW_VP_LOCK(pvproc);
- stTotalMem = 0;
- for (pringTemp = pvproc->VP_ringModules, bStart = LW_TRUE;
- pringTemp && (pringTemp != pvproc->VP_ringModules || bStart);
- pringTemp = _list_ring_get_next(pringTemp), bStart = LW_FALSE) {
-
- pmodTemp = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
-
-#if LW_CFG_VMM_EN > 0
- ulPages = 0;
- if (API_VmmPCountInArea(pmodTemp->EMOD_pvBaseAddr, &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
- }
-#else
- stTotalMem += pmodTemp->EMOD_stLen;
-#endif /* LW_CFG_VMM_EN > 0 */
- stTotalMem += __moduleSymbolBufferSize(pmodTemp);
- }
-
- if (stTotalMem) { /* 至少存在一个模块 */
- pmodTemp = _LIST_ENTRY(pvproc->VP_ringModules, LW_LD_EXEC_MODULE, EMOD_ringModules);
- ulPages = 0;
-
-#if LW_CFG_VMM_EN > 0
- iNum = __moduleVpPatchVmem(pmodTemp, pvVmem, LW_LD_VMEM_MAX);
- if (iNum > 0) {
- for (i = 0; i < iNum; i++) {
- if (API_VmmPCountInArea(pvVmem[i],
- &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages
- << LW_CFG_VMM_PAGE_SHIFT);
- }
- }
- lib_strlcpy(cVpVersion, __moduleVpPatchVersion(pmodTemp), sizeof(cVpVersion));
- }
-#else
- pheapVpPatch = (PLW_CLASS_HEAP)__moduleVpPatchHeap(pmodTemp);
- if (pheapVpPatch) { /* 获得 vp 进程私有 heap */
- stTotalMem += (size_t)(pheapVpPatch->HEAP_stTotalByteSize);
- lib_strlcpy(cVpVersion, __moduleVpPatchVersion(pmodTemp), sizeof(cVpVersion));
- }
-#endif /* LW_CFG_VMM_EN > 0 */
- }
- LW_VP_UNLOCK(pvproc);
-
-#if LW_CFG_VMM_EN > 0
- {
- size_t stMmapSize = 0;
- API_VmmMmapPCount(pvproc->VP_pid, &stMmapSize); /* 计算 mmap 内存实际消耗量 */
- stTotalMem += stMmapSize;
- }
-#endif /* LW_CFG_VMM_EN > 0 */
+ vprocMemInfoNoLock(pvproc, &stStatic, &stHeapMem, &stMmapMem);
printf("VPROC: %-18s pid:%4d TOTAL MEM: %zu ",
pcProcessName,
pvproc->VP_pid,
- stTotalMem);
+ stStatic + stHeapMem + stMmapMem);
if (cVpVersion[0] != PX_EOS) {
printf("<vp ver:%s>\n", cVpVersion);
@@ -870,23 +810,14 @@ static INT __tshellVProcShow (INT iArgC, PCHAR *ppcArgV)
INT iCnt = 0;
PCHAR pcProcessName;
PCHAR pcFatherName;
- BOOL bStart;
-
CHAR cVprocStat; /* 进程状态 */
LW_LIST_LINE *plineTemp;
- LW_LIST_RING *pringTemp;
LW_LD_VPROC *pvproc;
- LW_LD_EXEC_MODULE *pmodTemp;
-
-#if LW_CFG_VMM_EN == 0
- PLW_CLASS_HEAP pheapVpPatch;
-#endif /* LW_CFG_VMM_EN == 0 */
- INT i, iNum;
- ULONG ulPages;
- size_t stTotalMem;
- PVOID pvVmem[LW_LD_VMEM_MAX];
+ size_t stStatic;
+ size_t stHeapMem;
+ size_t stMmapMem;
struct passwd passwd;
struct passwd *ppasswd = LW_NULL;
@@ -939,60 +870,8 @@ static INT __tshellVProcShow (INT iArgC, PCHAR *ppcArgV)
cVprocStat = 'R';
}
}
-
- /*
- * 计算 vp 进程总内存消耗.
- */
- LW_VP_LOCK(pvproc);
- stTotalMem = 0;
- for (pringTemp = pvproc->VP_ringModules, bStart = LW_TRUE;
- pringTemp && (pringTemp != pvproc->VP_ringModules || bStart);
- pringTemp = _list_ring_get_next(pringTemp), bStart = LW_FALSE) {
-
- pmodTemp = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
-
-#if LW_CFG_VMM_EN > 0
- ulPages = 0;
- if (API_VmmPCountInArea(pmodTemp->EMOD_pvBaseAddr, &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
- }
-#else
- stTotalMem += pmodTemp->EMOD_stLen;
-#endif /* LW_CFG_VMM_EN > 0 */
- stTotalMem += __moduleSymbolBufferSize(pmodTemp);
- }
-
- if (stTotalMem) { /* 至少存在一个模块 */
- pmodTemp = _LIST_ENTRY(pvproc->VP_ringModules, LW_LD_EXEC_MODULE, EMOD_ringModules);
- ulPages = 0;
-
-#if LW_CFG_VMM_EN > 0
- iNum = __moduleVpPatchVmem(pmodTemp, pvVmem, LW_LD_VMEM_MAX);
- if (iNum > 0) {
- for (i = 0; i < iNum; i++) {
- if (API_VmmPCountInArea(pvVmem[i],
- &ulPages) == ERROR_NONE) {
- stTotalMem += (size_t)(ulPages
- << LW_CFG_VMM_PAGE_SHIFT);
- }
- }
- }
-#else
- pheapVpPatch = (PLW_CLASS_HEAP)__moduleVpPatchHeap(pmodTemp);
- if (pheapVpPatch) { /* 获得 vp 进程私有 heap */
- stTotalMem += (size_t)(pheapVpPatch->HEAP_stTotalByteSize);
- }
-#endif /* LW_CFG_VMM_EN > 0 */
- }
- LW_VP_UNLOCK(pvproc);
-#if LW_CFG_VMM_EN > 0
- {
- size_t stMmapSize = 0;
- API_VmmMmapPCount(pvproc->VP_pid, &stMmapSize); /* 计算 mmap 内存实际消耗量 */
- stTotalMem += stMmapSize;
- }
-#endif /* LW_CFG_VMM_EN > 0 */
+ vprocMemInfoNoLock(pvproc, &stStatic, &stHeapMem, &stMmapMem);
uid = 0;
gid = 0;
@@ -1009,7 +888,7 @@ static INT __tshellVProcShow (INT iArgC, PCHAR *ppcArgV)
printf("%-16s %-16s %-4c %5d %5d %8zuKB %5d %5d %s\n",
pcProcessName, pcFatherName, cVprocStat, pvproc->VP_pid, pvproc->VP_pidGroup,
- stTotalMem / LW_CFG_KB_SIZE, uid, gid, pcUser);
+ (stStatic + stHeapMem + stMmapMem) / LW_CFG_KB_SIZE, uid, gid, pcUser);
iCnt++;
}
diff --git a/SylixOS/loader/src/loader_vpdebug.c b/SylixOS/loader/src/loader_vpdebug.c
index 3309927..12489a3 100644
--- a/SylixOS/loader/src/loader_vpdebug.c
+++ b/SylixOS/loader/src/loader_vpdebug.c
@@ -92,6 +92,9 @@ VOID vprocDebugStop (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb == ptcbExcp) {
continue; /* 不停止此任务 */
}
@@ -129,6 +132,9 @@ VOID vprocDebugContinue (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb == ptcbExcp) {
continue; /* 不启动此任务 */
}
@@ -271,6 +277,9 @@ UINT vprocDebugThreadGet (PVOID pvVProc, LW_OBJECT_HANDLE ulId[], UINT uiTa
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (uiNum < uiTableNum) {
ulId[uiNum] = ptcb->TCB_ulId;
uiNum++;
diff --git a/SylixOS/loader/src/loader_vppatch.c b/SylixOS/loader/src/loader_vppatch.c
index 82690d8..d3a74ae 100644
--- a/SylixOS/loader/src/loader_vppatch.c
+++ b/SylixOS/loader/src/loader_vppatch.c
@@ -82,7 +82,7 @@
LW_LIST_LINE_HEADER _G_plineVProcHeader = LW_NULL;
LW_OBJECT_HANDLE _G_ulVProcMutex = LW_OBJECT_HANDLE_INVALID;
/*********************************************************************************************************
- 内核进程控制卡
+ 进程控制块
*********************************************************************************************************/
LW_LD_VPROC _G_vprocKernel;
LW_LD_VPROC *_G_pvprocTable[LW_CFG_MAX_THREADS];
@@ -103,12 +103,6 @@ INT vprocProcAdd(LW_LD_VPROC *pvproc);
INT vprocProcDelete(LW_LD_VPROC *pvproc);
#endif /* LW_CFG_PROCFS_EN > 0 */
/*********************************************************************************************************
- POSIX
-*********************************************************************************************************/
-#if LW_CFG_POSIX_EN > 0
-VOID _PthreadKeyCleanup(PLW_CLASS_TCB ptcbDel);
-#endif /* LW_CFG_POSIX_EN > 0 */
-/*********************************************************************************************************
** 函数名称: __moduleVpPatchVersion
** 功能描述: vp 补丁版本
** 输 入 : pmodule 进程主模块句柄
@@ -704,30 +698,6 @@ pid_t vprocGetPidByTcbNoLock (PLW_CLASS_TCB ptcb)
return (pid);
}
/*********************************************************************************************************
-** 函数名称: vprocGetPidByTcbdesc
-** 功能描述: 通过 tcbdesc 获得进程 id
-** 输 入 : ptcbdesc 任务信息描述
-** 输 出 : 进程 pid
-** 全局变量:
-** 调用模块:
-*********************************************************************************************************/
-pid_t vprocGetPidByTcbdesc (PLW_CLASS_TCB_DESC ptcbdesc)
-{
- pid_t pid = 0;
- LW_LD_VPROC *pvproc;
-
- if (ptcbdesc) {
- LW_LD_LOCK();
- pvproc = (LW_LD_VPROC *)ptcbdesc->TCBD_pvVProcessContext;
- if (pvproc) {
- pid = pvproc->VP_pid;
- }
- LW_LD_UNLOCK();
- }
-
- return (pid);
-}
-/*********************************************************************************************************
** 函数名称: vprocGetPidByThread
** 功能描述: 通过线程 ID 获得进程 id
** 输 入 : ulId 线程 ID
@@ -801,6 +771,9 @@ VOID vprocKillPrepare (pid_t pid, LW_OBJECT_HANDLE ulId)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb->TCB_ulId == ulId) {
continue; /* 不停止主任务 */
}
@@ -841,6 +814,9 @@ static VOID vprocKillRelease (PLW_CLASS_TCB ptcbCur)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb == ptcbCur) {
continue;
}
@@ -1097,14 +1073,12 @@ VOID vprocExit (LW_LD_VPROC *pvproc, LW_OBJECT_HANDLE ulId, INT iCode)
LW_TCB_GET_CUR_SAFE(ptcbCur);
+ __KERNEL_SPACE_SET2(ptcbCur, 0); /* 当前任务退出内核环境 */
+
__recheck:
#if LW_CFG_THREAD_EXT_EN > 0
_TCBCleanupPopExt(ptcbCur); /* 提前执行 cleanup pop 操作 */
#endif /* LW_CFG_THREAD_EXT_EN > 0 */
-
-#if LW_CFG_POSIX_EN > 0
- _PthreadKeyCleanup(ptcbCur); /* 提前执行 key cleanup 操作 */
-#endif /* LW_CFG_POSIX_EN > 0 */
if (pvproc->VP_iExitMode == LW_VPROC_EXIT_FORCE) { /* 强制退出删除除主线程外的线程*/
vprocThreadKill(pvproc, ptcbCur);
@@ -1135,7 +1109,6 @@ __recheck:
LW_LD_VPROC *pvprocChild = _LIST_ENTRY(plineList, LW_LD_VPROC, VP_lineBrother);
pvprocChild->VP_pvprocFather = LW_NULL; /* 子进程设为孤儿进程 */
-
if (pvprocChild->VP_iStatus == __LW_VP_EXIT) { /* 子进程为僵尸进程 */
__resReclaimReq((PVOID)pvprocChild); /* 请求释放进程资源 */
}
diff --git a/SylixOS/loader/src/loader_vpstat.c b/SylixOS/loader/src/loader_vpstat.c
new file mode 100644
index 0000000..0d05136
--- /dev/null
+++ b/SylixOS/loader/src/loader_vpstat.c
@@ -0,0 +1,193 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: loader_vpstat.c
+**
+** 创 建 人: Han.hui (韩辉)
+**
+** 文件创建日期: 2019 年 06 月 03 日
+**
+** 描 述: 进程数据统计.
+*********************************************************************************************************/
+#define __SYLIXOS_KERNEL
+#include "SylixOS.h"
+/*********************************************************************************************************
+ 裁剪支持
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_EN > 0
+#include "../include/loader_lib.h"
+#include "../include/loader_symbol.h"
+/*********************************************************************************************************
+ 进程控制块
+*********************************************************************************************************/
+extern LW_LD_VPROC *_G_pvprocTable[LW_CFG_MAX_THREADS];
+/*********************************************************************************************************
+** 函数名称: vprocMemInfo
+** 功能描述: 获得进程内存使用情况
+** 输 入 : pid 进程号
+** pstStatic 静态内存大小
+** pstHeap 内存堆消耗
+** pstMmap mmap 大小
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT vprocMemInfoNoLock (LW_LD_VPROC *pvproc, size_t *pstStatic, size_t *pstHeap, size_t *pstMmap)
+{
+ size_t stStatic = 0;
+ size_t stHeap = 0;
+ size_t stMmap = 0;
+
+ INT i, iNum;
+ ULONG ulPages;
+ BOOL bStart;
+ LW_LIST_RING *pringTemp;
+ LW_LD_EXEC_MODULE *pmodTemp;
+ PVOID pvVmem[LW_LD_VMEM_MAX];
+
+#if LW_CFG_VMM_EN == 0
+ PLW_CLASS_HEAP pheapVpPatch;
+#endif /* LW_CFG_VMM_EN == 0 */
+
+ if (!pvproc) {
+ _ErrorHandle(ESRCH);
+ return (PX_ERROR);
+ }
+
+ LW_VP_LOCK(pvproc);
+ for (pringTemp = pvproc->VP_ringModules, bStart = LW_TRUE;
+ pringTemp && (pringTemp != pvproc->VP_ringModules || bStart);
+ pringTemp = _list_ring_get_next(pringTemp), bStart = LW_FALSE) {
+
+ pmodTemp = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
+
+#if LW_CFG_VMM_EN > 0
+ ulPages = 0;
+ if (API_VmmPCountInArea(pmodTemp->EMOD_pvBaseAddr, &ulPages) == ERROR_NONE) {
+ stStatic += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
+ }
+#else
+ stStatic += pmodTemp->EMOD_stLen;
+#endif /* LW_CFG_VMM_EN > 0 */
+ stStatic += __moduleSymbolBufferSize(pmodTemp);
+ }
+
+ if (stStatic) { /* 至少存在一个模块 */
+ pmodTemp = _LIST_ENTRY(pvproc->VP_ringModules, LW_LD_EXEC_MODULE, EMOD_ringModules);
+ ulPages = 0;
+
+#if LW_CFG_VMM_EN > 0
+ iNum = __moduleVpPatchVmem(pmodTemp, pvVmem, LW_LD_VMEM_MAX);
+ if (iNum > 0) {
+ for (i = 0; i < iNum; i++) {
+ if (API_VmmPCountInArea(pvVmem[i],
+ &ulPages) == ERROR_NONE) {
+ stHeap += (size_t)(ulPages << LW_CFG_VMM_PAGE_SHIFT);
+ }
+ }
+ }
+#else
+ pheapVpPatch = (PLW_CLASS_HEAP)__moduleVpPatchHeap(pmodTemp);
+ if (pheapVpPatch) { /* 获得 vp 进程私有 heap */
+ stHeap += (size_t)(pheapVpPatch->HEAP_stTotalByteSize);
+ }
+#endif /* LW_CFG_VMM_EN > 0 */
+ }
+ LW_VP_UNLOCK(pvproc);
+
+#if LW_CFG_VMM_EN > 0
+ API_VmmMmapPCount(pvproc->VP_pid, &stMmap); /* 计算 mmap 内存实际消耗量 */
+#endif /* LW_CFG_VMM_EN > 0 */
+
+ if (pstStatic) {
+ *pstStatic = stStatic;
+ }
+
+ if (pstHeap) {
+ *pstHeap = stHeap;
+ }
+
+ if (pstMmap) {
+ *pstMmap = stMmap;
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: vprocMemInfo
+** 功能描述: 获得进程内存使用情况
+** 输 入 : pid 进程号
+** pstStatic 静态内存大小
+** pstHeap 内存堆消耗
+** pstMmap mmap 大小
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+INT vprocMemInfo (pid_t pid, size_t *pstStatic, size_t *pstHeap, size_t *pstMmap)
+{
+ INT iRet;
+ LW_LD_VPROC *pvproc;
+
+ LW_LD_LOCK();
+ pvproc = vprocGet(pid);
+ if (!pvproc) {
+ LW_LD_UNLOCK();
+ return (PX_ERROR);
+ }
+
+ iRet = vprocMemInfoNoLock(pvproc, pstStatic, pstHeap, pstMmap);
+ LW_LD_UNLOCK();
+
+ return (iRet);
+}
+/*********************************************************************************************************
+** 函数名称: vprocListGet
+** 功能描述: 获得进程列表
+** 输 入 : pidTable 进程号表
+** uiMaxCnt 缓存个数
+** 输 出 : 获取的进程个数
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+INT vprocListGet (pid_t pidTable[], UINT uiMaxCnt)
+{
+ INT i, iNum = 0;
+
+ if (!pidTable || !uiMaxCnt) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ LW_LD_LOCK();
+ for (i = 0; i < LW_CFG_MAX_THREADS; i++) {
+ if (_G_pvprocTable[i]) {
+ pidTable[iNum] = _G_pvprocTable[i]->VP_pid;
+ iNum++;
+ if (iNum >= uiMaxCnt) {
+ break;
+ }
+ }
+ }
+ LW_LD_UNLOCK();
+
+ return (iNum);
+}
+
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/loader/src/loader_vpthread.c b/SylixOS/loader/src/loader_vpthread.c
index e48a7b4..cbf8026 100644
--- a/SylixOS/loader/src/loader_vpthread.c
+++ b/SylixOS/loader/src/loader_vpthread.c
@@ -83,6 +83,7 @@ INT vprocThreadNum (pid_t pid, ULONG *pulNum)
{
LW_LD_VPROC *pvproc;
PLW_LIST_LINE plineTemp;
+ PLW_CLASS_TCB ptcb;
if (!pulNum) {
_ErrorHandle(EINVAL);
@@ -98,6 +99,11 @@ INT vprocThreadNum (pid_t pid, ULONG *pulNum)
for (plineTemp = pvproc->VP_plineThread;
plineTemp != LW_NULL;
plineTemp = _list_line_get_next(plineTemp)) {
+
+ ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
(*pulNum)++;
}
__KERNEL_EXIT(); /* 退出内核 */
@@ -126,6 +132,9 @@ VOID vprocThreadKill (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb != ptcbExcp) { /* ptcbCur 为主线程 */
_excJobAdd((VOIDFUNCPTR)kill, (PVOID)ptcb->TCB_ulId, (PVOID)SIGKILL, 0, 0, 0, 0);
}
@@ -133,6 +142,50 @@ VOID vprocThreadKill (PVOID pvVProc, PLW_CLASS_TCB ptcbExcp)
LW_VP_UNLOCK(pvproc); /* 解锁当前进程 */
}
/*********************************************************************************************************
+** 函数名称: vprocThreadTraversal
+** 功能描述: 遍历进程内的所有线程 (为了提高效率此函数会锁定 KERNEL)
+** 输 入 : pid 进程 id
+** pfunc 回调函数
+** pvArg[0 ~ 5] 遍历函数参数
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT vprocThreadTraversal (pid_t pid,
+ VOIDFUNCPTR pfunc,
+ PVOID pvArg0,
+ PVOID pvArg1,
+ PVOID pvArg2,
+ PVOID pvArg3,
+ PVOID pvArg4,
+ PVOID pvArg5)
+{
+ LW_LD_VPROC *pvproc;
+ PLW_LIST_LINE plineTemp;
+ PLW_CLASS_TCB ptcb;
+
+ __KERNEL_ENTER(); /* 进入内核 */
+ pvproc = vprocGet(pid);
+ if (!pvproc) {
+ __KERNEL_EXIT(); /* 退出内核 */
+ return (PX_ERROR);
+ }
+
+ for (plineTemp = pvproc->VP_plineThread;
+ plineTemp != LW_NULL;
+ plineTemp = _list_line_get_next(plineTemp)) {
+
+ ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
+ pfunc(ptcb, pvArg0, pvArg1, pvArg2, pvArg3, pvArg4, pvArg5);
+ }
+ __KERNEL_EXIT(); /* 退出内核 */
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
** 函数名称: vprocThreadSigaction
** 功能描述: 设置进程内所有任务的 sigaction
** 输 入 : pvVProc 进程控制块指针
@@ -166,6 +219,9 @@ INT vprocThreadSigaction (PVOID pvVProc, VOIDFUNCPTR pfunc, INT iSigIndex,
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
if (ptcb != ptcbCur) {
pfunc(ptcb, iSigIndex, psigactionNew);
}
@@ -208,6 +264,10 @@ INT vprocThreadAffinity (PVOID pvVProc, size_t stSize, const PLW_CLASS_CPUSET
plineTemp = _list_line_get_next(plineTemp)) {
ptcb = _LIST_ENTRY(plineTemp, LW_CLASS_TCB, TCB_lineProcess);
+ if (ptcb->TCB_iDeleteProcStatus) {
+ continue; /* 已经在删除过程中 */
+ }
+
if (ptcb == ptcbCur) {
if (!__THREAD_LOCK_GET(ptcb)) { /* 外部没有锁定此任务 */
__KERNEL_ENTER(); /* 进入内核 */
diff --git a/SylixOS/loader/src/loader_wait.c b/SylixOS/loader/src/loader_wait.c
index 256a14e..c87e936 100644
--- a/SylixOS/loader/src/loader_wait.c
+++ b/SylixOS/loader/src/loader_wait.c
@@ -249,6 +249,9 @@ static BOOL __haveThisChild (LW_LD_VPROC *pvproc, pid_t pidChild)
pidChild == 0 子进程中组 ID 相同的
pidChild == -1 任何子进程
pidChild < -1 子进程中组 ID 为 pid 绝对值的
+
+ 此函数为信号响应函数, 可能之前已占用有关资源锁, 如果在这里回收子进程资源, 可能造成死锁,
+ 所以这里在获取到进程返回信息后, 通知内核回收线程去回收资源.
*********************************************************************************************************/
static INT __reclaimAChild (LW_LD_VPROC *pvproc,
pid_t pidChild,
@@ -304,6 +307,9 @@ static INT __reclaimAChild (LW_LD_VPROC *pvproc,
if (stat_loc) {
*stat_loc = SET_EXITSTATUS(pvprocChild->VP_iExitCode); /* 子进程正常退出 */
}
+ pvprocChild->VP_pvprocFather = LW_NULL;
+ _List_Line_Del(&pvprocChild->VP_lineBrother,
+ &pvproc->VP_plineChild); /* 将子进程从链表中退出 */
bHasEvent = LW_TRUE;
bNeedReclaim = LW_TRUE;
break;
@@ -339,7 +345,7 @@ static INT __reclaimAChild (LW_LD_VPROC *pvproc,
__tickToTimeval(pvprocChild->VP_clockSystem, &prusage->ru_stime);
}
if (bNeedReclaim) {
- vprocReclaim(pvprocChild, LW_TRUE); /* 回收子进程资源 */
+ __resReclaimReq((PVOID)pvprocChild); /* 请求内核释放进程资源 */
}
return (1);
diff --git a/SylixOS/net/lwip/bonding/netbonding.c b/SylixOS/net/lwip/bonding/netbonding.c
index 089a7ea..84175cd 100644
--- a/SylixOS/net/lwip/bonding/netbonding.c
+++ b/SylixOS/net/lwip/bonding/netbonding.c
@@ -462,7 +462,7 @@ static void netbd_proc (void *arg)
'subdev' sub ethernet device name
sub_is_ifname == 0: dev name
sub_is_ifname == 1: if name */
-int netbd_add_dev (const char *bddev, const char *sub, int sub_is_ifname)
+int netbd_add_dev (const char *bddev, int bdindex, const char *sub, int sub_is_ifname)
{
int found, flags, need_up = 0;
struct netif *netif;
@@ -473,14 +473,18 @@ int netbd_add_dev (const char *bddev, const char *sub, int sub_is_ifname)
netdev_t *netdev;
struct ifreq ifreq;
- if (!bddev || !sub) {
+ if (!sub) {
errno = EINVAL;
return (-1);
}
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_bd = netdev_find_by_devname(bddev);
+ if (bddev && bddev[0]) {
+ netdev_bd = netdev_find_by_devname(bddev);
+ } else {
+ netdev_bd = netdev_find_by_index(bdindex);
+ }
if (netdev_bd && (netdev_bd->drv->transmit == netbd_transmit)) {
netbd = (netbd_t *)netdev_bd->priv;
if (netbd && netbd->magic_no == NETBONDING_MAGIC) {
@@ -608,7 +612,7 @@ int netbd_add_dev (const char *bddev, const char *sub, int sub_is_ifname)
'subdev' sub ethernet device name
sub_is_ifname == 0: dev name
sub_is_ifname == 1: if name */
-int netbd_delete_dev (const char *bddev, const char *sub, int sub_is_ifname)
+int netbd_delete_dev (const char *bddev, int bdindex, const char *sub, int sub_is_ifname)
{
int i, found, flags;
char subif[IFNAMSIZ];
@@ -619,14 +623,18 @@ int netbd_delete_dev (const char *bddev, const char *sub, int sub_is_ifname)
netdev_t *netdev;
struct ifreq ifreq;
- if (!bddev || !sub) {
+ if (!sub) {
errno = EINVAL;
return (-1);
}
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_bd = netdev_find_by_devname(bddev);
+ if (bddev && bddev[0]) {
+ netdev_bd = netdev_find_by_devname(bddev);
+ } else {
+ netdev_bd = netdev_find_by_index(bdindex);
+ }
if (netdev_bd && (netdev_bd->drv->transmit == netbd_transmit)) {
netbd = (netbd_t *)netdev_bd->priv;
if (netbd && netbd->magic_no == NETBONDING_MAGIC) {
@@ -733,7 +741,7 @@ int netbd_delete_dev (const char *bddev, const char *sub, int sub_is_ifname)
}
/* net bonding set master device */
-int netbd_master_dev (const char *bddev, const char *sub, int sub_is_ifname)
+int netbd_master_dev (const char *bddev, int bdindex, const char *sub, int sub_is_ifname)
{
int i, found;
char subif[IFNAMSIZ];
@@ -742,14 +750,18 @@ int netbd_master_dev (const char *bddev, const char *sub, int sub_is_ifname)
netdev_t *netdev_bd;
netdev_t *netdev;
- if (!bddev || !sub) {
+ if (!sub) {
errno = EINVAL;
return (-1);
}
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_bd = netdev_find_by_devname(bddev);
+ if (bddev && bddev[0]) {
+ netdev_bd = netdev_find_by_devname(bddev);
+ } else {
+ netdev_bd = netdev_find_by_index(bdindex);
+ }
if (netdev_bd && (netdev_bd->drv->transmit == netbd_transmit)) {
netbd = (netbd_t *)netdev_bd->priv;
if (netbd && netbd->magic_no == NETBONDING_MAGIC) {
@@ -796,7 +808,7 @@ int netbd_master_dev (const char *bddev, const char *sub, int sub_is_ifname)
}
/* add a arp detect target to net bonding virtual device */
-int netbd_add_arp (const char *bddev, const char *ip)
+int netbd_add_arp (const char *bddev, int bdindex, const char *ip)
{
int found;
netbd_t *netbd;
@@ -804,7 +816,7 @@ int netbd_add_arp (const char *bddev, const char *ip)
netbd_arp_t *netbd_arp;
ip4_addr_t ipaddr;
- if (!bddev || !ip) {
+ if (!ip) {
errno = EINVAL;
return (-1);
}
@@ -816,7 +828,11 @@ int netbd_add_arp (const char *bddev, const char *ip)
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_bd = netdev_find_by_devname(bddev);
+ if (bddev && bddev[0]) {
+ netdev_bd = netdev_find_by_devname(bddev);
+ } else {
+ netdev_bd = netdev_find_by_index(bdindex);
+ }
if (netdev_bd && (netdev_bd->drv->transmit == netbd_transmit)) {
netbd = (netbd_t *)netdev_bd->priv;
if (netbd && netbd->magic_no == NETBONDING_MAGIC) {
@@ -847,7 +863,7 @@ int netbd_add_arp (const char *bddev, const char *ip)
}
/* delete a arp detect target to net bonding virtual device */
-int netbd_delete_arp (const char *bddev, const char *ip)
+int netbd_delete_arp (const char *bddev, int bdindex, const char *ip)
{
int found;
netbd_t *netbd;
@@ -856,7 +872,7 @@ int netbd_delete_arp (const char *bddev, const char *ip)
ip4_addr_t ipaddr;
LW_LIST_LINE *pline;
- if (!bddev || !ip) {
+ if (!ip) {
errno = EINVAL;
return (-1);
}
@@ -868,7 +884,11 @@ int netbd_delete_arp (const char *bddev, const char *ip)
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_bd = netdev_find_by_devname(bddev);
+ if (bddev && bddev[0]) {
+ netdev_bd = netdev_find_by_devname(bddev);
+ } else {
+ netdev_bd = netdev_find_by_index(bdindex);
+ }
if (netdev_bd && (netdev_bd->drv->transmit == netbd_transmit)) {
netbd = (netbd_t *)netdev_bd->priv;
if (netbd && netbd->magic_no == NETBONDING_MAGIC) {
@@ -1024,7 +1044,7 @@ int netbd_add (const char *bddev, const char *ip,
/* delete net bonding
'bddev' bonding device name (not ifname) */
-int netbd_delete (const char *bddev)
+int netbd_delete (const char *bddev, int bdindex)
{
int found, flags;
struct netif *netif;
@@ -1034,14 +1054,13 @@ int netbd_delete (const char *bddev)
netdev_t *netdev;
struct ifreq ifreq;
- if (!bddev) {
- errno = EINVAL;
- return (-1);
- }
-
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_bd = netdev_find_by_devname(bddev);
+ if (bddev && bddev[0]) {
+ netdev_bd = netdev_find_by_devname(bddev);
+ } else {
+ netdev_bd = netdev_find_by_index(bdindex);
+ }
if (netdev_bd && (netdev_bd->drv->transmit == netbd_transmit)) {
netbd = (netbd_t *)netdev_bd->priv;
if (netbd && netbd->magic_no == NETBONDING_MAGIC) {
@@ -1206,7 +1225,7 @@ void netbd_sub_delete_hook (netdev_t *netdev)
}
/* net bonding show all device in bonding virtual device */
-int netbd_show_dev (const char *bddev, int fd)
+int netbd_show_dev (const char *bddev, int bdindex, int fd)
{
#define NETBD_ARP_BUF_MAX 16
int found;
@@ -1222,14 +1241,18 @@ int netbd_show_dev (const char *bddev, int fd)
char ifname[NETIF_NAMESIZE];
LW_LIST_LINE *pline;
- if (!bddev || (fd < 0)) {
+ if (fd < 0) {
errno = EINVAL;
return (-1);
}
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_bd = netdev_find_by_devname(bddev);
+ if (bddev && bddev[0]) {
+ netdev_bd = netdev_find_by_devname(bddev);
+ } else {
+ netdev_bd = netdev_find_by_index(bdindex);
+ }
if (netdev_bd && (netdev_bd->drv->transmit == netbd_transmit)) {
netbd = (netbd_t *)netdev_bd->priv;
if (netbd && netbd->magic_no == NETBONDING_MAGIC) {
diff --git a/SylixOS/net/lwip/bonding/netbonding.h b/SylixOS/net/lwip/bonding/netbonding.h
index cbb67f8..53028c0 100644
--- a/SylixOS/net/lwip/bonding/netbonding.h
+++ b/SylixOS/net/lwip/bonding/netbonding.h
@@ -50,21 +50,21 @@ int netbd_add(const char *bddev, const char *ip,
const char *netmask, const char *gw,
int mode, int mon_mode, int interval,
int alive, int *index);
-int netbd_delete(const char *bddev);
+int netbd_delete(const char *bddev, int bdindex);
/* add or delete a net device to net bonding virtual device */
-int netbd_add_dev(const char *bddev, const char *sub, int sub_is_ifname);
-int netbd_delete_dev(const char *bddev, const char *sub, int sub_is_ifname);
+int netbd_add_dev(const char *bddev, int bdindex, const char *sub, int sub_is_ifname);
+int netbd_delete_dev(const char *bddev, int bdindex, const char *sub, int sub_is_ifname);
/* net bonding set master device */
-int netbd_master_dev(const char *bddev, const char *sub, int sub_is_ifname);
+int netbd_master_dev(const char *bddev, int bdindex, const char *sub, int sub_is_ifname);
/* add or delete a arp detect target to net bonding virtual device */
-int netbd_add_arp(const char *bddev, const char *ip);
-int netbd_delete_arp(const char *bddev, const char *ip);
+int netbd_add_arp(const char *bddev, int bdindex, const char *ip);
+int netbd_delete_arp(const char *bddev, int bdindex, const char *ip);
/* net bonding show all device in bonding virtual device */
-int netbd_show_dev(const char *bddev, int fd);
+int netbd_show_dev(const char *bddev, int bdindex, int fd);
#endif /* LW_CFG_NET_DEV_BONDING_EN */
#endif /* __NETBONDING_H */
diff --git a/SylixOS/net/lwip/bridge/netbridge.c b/SylixOS/net/lwip/bridge/netbridge.c
index 51388fb..5420675 100644
--- a/SylixOS/net/lwip/bridge/netbridge.c
+++ b/SylixOS/net/lwip/bridge/netbridge.c
@@ -342,7 +342,7 @@ static void netbr_wd (netdev_t *netdev_br)
'subdev' sub ethernet device name
sub_is_ifname == 0: dev name
sub_is_ifname == 1: if name */
-int netbr_add_dev (const char *brdev, const char *sub, int sub_is_ifname)
+int netbr_add_dev (const char *brdev, int brindex, const char *sub, int sub_is_ifname)
{
int found, flags, need_up = 0;
struct netif *netif;
@@ -353,14 +353,18 @@ int netbr_add_dev (const char *brdev, const char *sub, int sub_is_ifname)
netdev_t *netdev;
struct ifreq ifreq;
- if (!brdev || !sub) {
+ if (!sub) {
errno = EINVAL;
return (-1);
}
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_br = netdev_find_by_devname(brdev);
+ if (brdev && brdev[0]) {
+ netdev_br = netdev_find_by_devname(brdev);
+ } else {
+ netdev_br = netdev_find_by_index(brindex);
+ }
if (netdev_br && (netdev_br->drv->transmit == netbr_transmit)) {
netbr = (netbr_t *)netdev_br->priv;
if (netbr && netbr->magic_no == NETBRIDGE_MAGIC) {
@@ -468,7 +472,7 @@ int netbr_add_dev (const char *brdev, const char *sub, int sub_is_ifname)
'subdev' sub ethernet device name
sub_is_ifname == 0: dev name
sub_is_ifname == 1: if name */
-int netbr_delete_dev (const char *brdev, const char *sub, int sub_is_ifname)
+int netbr_delete_dev (const char *brdev, int brindex, const char *sub, int sub_is_ifname)
{
int found, flags;
char subif[IFNAMSIZ];
@@ -480,14 +484,18 @@ int netbr_delete_dev (const char *brdev, const char *sub, int sub_is_ifname)
LW_LIST_LINE *pline;
struct ifreq ifreq;
- if (!brdev || !sub) {
+ if (!sub) {
errno = EINVAL;
return (-1);
}
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_br = netdev_find_by_devname(brdev);
+ if (brdev && brdev[0]) {
+ netdev_br = netdev_find_by_devname(brdev);
+ } else {
+ netdev_br = netdev_find_by_index(brindex);
+ }
if (netdev_br && (netdev_br->drv->transmit == netbr_transmit)) {
netbr = (netbr_t *)netdev_br->priv;
if (netbr && netbr->magic_no == NETBRIDGE_MAGIC) {
@@ -649,7 +657,7 @@ int netbr_add (const char *brdev, const char *ip,
/* delete net bridge
'brdev' bridge device name (not ifname) */
-int netbr_delete (const char *brdev)
+int netbr_delete (const char *brdev, int brindex)
{
int found, flags;
struct netif *netif;
@@ -659,14 +667,13 @@ int netbr_delete (const char *brdev)
netdev_t *netdev;
struct ifreq ifreq;
- if (!brdev) {
- errno = EINVAL;
- return (-1);
- }
-
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_br = netdev_find_by_devname(brdev);
+ if (brdev && brdev[0]) {
+ netdev_br = netdev_find_by_devname(brdev);
+ } else {
+ netdev_br = netdev_find_by_index(brindex);
+ }
if (netdev_br && (netdev_br->drv->transmit == netbr_transmit)) {
netbr = (netbr_t *)netdev_br->priv;
if (netbr && netbr->magic_no == NETBRIDGE_MAGIC) {
@@ -746,7 +753,7 @@ int netbr_delete (const char *brdev)
/* net bridge mac cache flush
'brdev' bridge device name (not ifname) */
-int netbr_flush_cache (const char *brdev)
+int netbr_flush_cache (const char *brdev, int brindex)
{
int found;
netbr_t *netbr;
@@ -755,14 +762,13 @@ int netbr_flush_cache (const char *brdev)
LW_LIST_LINE *pline;
int i;
- if (!brdev) {
- errno = EINVAL;
- return (-1);
- }
-
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_br = netdev_find_by_devname(brdev);
+ if (brdev && brdev[0]) {
+ netdev_br = netdev_find_by_devname(brdev);
+ } else {
+ netdev_br = netdev_find_by_index(brindex);
+ }
if (netdev_br && (netdev_br->drv->transmit == netbr_transmit)) {
netbr = (netbr_t *)netdev_br->priv;
if (netbr && netbr->magic_no == NETBRIDGE_MAGIC) {
@@ -845,7 +851,7 @@ void netbr_sub_delete_hook (netdev_t *netdev)
}
/* net bridge show all device in bridge */
-int netbr_show_dev (const char *brdev, int fd)
+int netbr_show_dev (const char *brdev, int brindex, int fd)
{
int found;
int i = 0, j;
@@ -858,14 +864,18 @@ int netbr_show_dev (const char *brdev, int fd)
char ifname[NETIF_NAMESIZE];
LW_LIST_LINE *pline;
- if (!brdev || (fd < 0)) {
+ if (fd < 0) {
errno = EINVAL;
return (-1);
}
LWIP_IF_LIST_LOCK(FALSE);
found = 0;
- netdev_br = netdev_find_by_devname(brdev);
+ if (brdev && brdev[0]) {
+ netdev_br = netdev_find_by_devname(brdev);
+ } else {
+ netdev_br = netdev_find_by_index(brindex);
+ }
if (netdev_br && (netdev_br->drv->transmit == netbr_transmit)) {
netbr = (netbr_t *)netdev_br->priv;
if (netbr && netbr->magic_no == NETBRIDGE_MAGIC) {
diff --git a/SylixOS/net/lwip/bridge/netbridge.h b/SylixOS/net/lwip/bridge/netbridge.h
index 1aadbce..b9eff08 100644
--- a/SylixOS/net/lwip/bridge/netbridge.h
+++ b/SylixOS/net/lwip/bridge/netbridge.h
@@ -48,17 +48,17 @@
/* add and delete net bridge */
int netbr_add(const char *brdev, const char *ip,
const char *netmask, const char *gw, int *index);
-int netbr_delete(const char *brdev);
+int netbr_delete(const char *brdev, int brindex);
/* add or delete a net device to net bridge */
-int netbr_add_dev(const char *brdev, const char *sub, int sub_is_ifname);
-int netbr_delete_dev(const char *brdev, const char *sub, int sub_is_ifname);
+int netbr_add_dev(const char *brdev, int brindex, const char *sub, int sub_is_ifname);
+int netbr_delete_dev(const char *brdev, int brindex, const char *sub, int sub_is_ifname);
/* net bridge mac cache flush */
-int netbr_flush_cache(const char *brdev);
+int netbr_flush_cache(const char *brdev, int brindex);
/* net bridge show all device in bridge */
-int netbr_show_dev(const char *brdev, int fd);
+int netbr_show_dev(const char *brdev, int brindex, int fd);
#endif /* LW_CFG_NET_DEV_BRIDGE_EN */
#endif /* __NETBRIDGE_H */
diff --git a/SylixOS/net/lwip/lwip_bonding.c b/SylixOS/net/lwip/lwip_bonding.c
index 1b1f13b..1ef4842 100644
--- a/SylixOS/net/lwip/lwip_bonding.c
+++ b/SylixOS/net/lwip/lwip_bonding.c
@@ -110,63 +110,63 @@ static INT _netbdIoctl (PLW_DEV_HDR pdevhdr,
case NETBD_CTL_DELETE:
pnetbdcrl = (struct net_bonding_ctl *)lArg;
if (pnetbdcrl) {
- iRet = netbd_delete(pnetbdcrl->bd_dev);
+ iRet = netbd_delete(pnetbdcrl->bd_dev, pnetbdcrl->bd_index);
}
return (iRet);
case NETBD_CTL_ADD_DEV:
pnetbdcrl = (struct net_bonding_ctl *)lArg;
if (pnetbdcrl) {
- iRet = netbd_add_dev(pnetbdcrl->bd_dev, pnetbdcrl->eth_dev, 0);
+ iRet = netbd_add_dev(pnetbdcrl->bd_dev, pnetbdcrl->bd_index, pnetbdcrl->eth_dev, 0);
}
return (iRet);
case NETBD_CTL_DELETE_DEV:
pnetbdcrl = (struct net_bonding_ctl *)lArg;
if (pnetbdcrl) {
- iRet = netbd_delete_dev(pnetbdcrl->bd_dev, pnetbdcrl->eth_dev, 0);
+ iRet = netbd_delete_dev(pnetbdcrl->bd_dev, pnetbdcrl->bd_index, pnetbdcrl->eth_dev, 0);
}
return (iRet);
case NETBD_CTL_ADD_IF:
pnetbdcrl = (struct net_bonding_ctl *)lArg;
if (pnetbdcrl) {
- iRet = netbd_add_dev(pnetbdcrl->bd_dev, pnetbdcrl->eth_dev, 1);
+ iRet = netbd_add_dev(pnetbdcrl->bd_dev, pnetbdcrl->bd_index, pnetbdcrl->eth_dev, 1);
}
return (iRet);
case NETBD_CTL_DELETE_IF:
pnetbdcrl = (struct net_bonding_ctl *)lArg;
if (pnetbdcrl) {
- iRet = netbd_delete_dev(pnetbdcrl->bd_dev, pnetbdcrl->eth_dev, 1);
+ iRet = netbd_delete_dev(pnetbdcrl->bd_dev, pnetbdcrl->bd_index, pnetbdcrl->eth_dev, 1);
}
return (iRet);
case NETBD_CTL_MASTER_DEV:
pnetbddev = (struct net_bonding_device *)lArg;
if (pnetbddev) {
- iRet = netbd_master_dev(pnetbddev->bd_dev, pnetbddev->eth_dev, 0);
+ iRet = netbd_master_dev(pnetbddev->bd_dev, pnetbddev->bd_index, pnetbddev->eth_dev, 0);
}
return (iRet);
case NETBD_CTL_MASTER_IF:
pnetbddev = (struct net_bonding_device *)lArg;
if (pnetbddev) {
- iRet = netbd_master_dev(pnetbddev->bd_dev, pnetbddev->eth_dev, 1);
+ iRet = netbd_master_dev(pnetbddev->bd_dev, pnetbddev->bd_index, pnetbddev->eth_dev, 1);
}
return (iRet);
case NETBD_CTL_ARP_ADD:
pnetbdarp = (struct net_bonding_arp *)lArg;
if (pnetbdarp) {
- iRet = netbd_add_arp(pnetbdarp->bd_dev, pnetbdarp->arp_ip_target);
+ iRet = netbd_add_arp(pnetbdarp->bd_dev, pnetbdarp->bd_index, pnetbdarp->arp_ip_target);
}
return (iRet);
case NETBD_CTL_ARP_DELETE:
pnetbdarp = (struct net_bonding_arp *)lArg;
if (pnetbdarp) {
- iRet = netbd_delete_arp(pnetbdarp->bd_dev, pnetbdarp->arp_ip_target);
+ iRet = netbd_delete_arp(pnetbdarp->bd_dev, pnetbdarp->bd_index, pnetbdarp->arp_ip_target);
}
return (iRet);
@@ -306,7 +306,7 @@ static INT __tshellNetbd (INT iArgC, PCHAR *ppcArgV)
} else {
if (iArgC == 3) {
if (lib_strcmp(ppcArgV[1], "delbd") == 0) {
- iRet = netbd_delete(ppcArgV[2]);
+ iRet = netbd_delete(ppcArgV[2], 0);
if (iRet) {
fprintf(stderr, "can not delete net bonding device: %s!\n", lib_strerror(errno));
} else {
@@ -314,7 +314,7 @@ static INT __tshellNetbd (INT iArgC, PCHAR *ppcArgV)
}
} else if (lib_strcmp(ppcArgV[1], "show") == 0) {
- iRet = netbd_show_dev(ppcArgV[2], STD_OUT);
+ iRet = netbd_show_dev(ppcArgV[2], 0, STD_OUT);
if (iRet) {
fprintf(stderr, "can not show net bonding device: %s!\n", lib_strerror(errno));
}
@@ -325,49 +325,49 @@ static INT __tshellNetbd (INT iArgC, PCHAR *ppcArgV)
} else if (iArgC == 4) {
if (lib_strcmp(ppcArgV[1], "adddev") == 0) {
- iRet = netbd_add_dev(ppcArgV[2], ppcArgV[3], 0);
+ iRet = netbd_add_dev(ppcArgV[2], 0, ppcArgV[3], 0);
if (iRet) {
fprintf(stderr, "can not add device '%s' to bonding '%s'!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "deldev") == 0) {
- iRet = netbd_delete_dev(ppcArgV[2], ppcArgV[3], 0);
+ iRet = netbd_delete_dev(ppcArgV[2], 0, ppcArgV[3], 0);
if (iRet) {
fprintf(stderr, "can not delete device '%s' from bonding '%s'!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "addif") == 0) {
- iRet = netbd_add_dev(ppcArgV[2], ppcArgV[3], 1);
+ iRet = netbd_add_dev(ppcArgV[2], 0, ppcArgV[3], 1);
if (iRet) {
fprintf(stderr, "can not add if '%s' to bonding '%s'!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "delif") == 0) {
- iRet = netbd_delete_dev(ppcArgV[2], ppcArgV[3], 1);
+ iRet = netbd_delete_dev(ppcArgV[2], 0, ppcArgV[3], 1);
if (iRet) {
fprintf(stderr, "can not delete if '%s' from bonding '%s'!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "masterdev") == 0) {
- iRet = netbd_master_dev(ppcArgV[2], ppcArgV[3], 0);
+ iRet = netbd_master_dev(ppcArgV[2], 0, ppcArgV[3], 0);
if (iRet) {
fprintf(stderr, "can not set device '%s' to bonding '%s' MASTER device!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "masterif") == 0) {
- iRet = netbd_master_dev(ppcArgV[2], ppcArgV[3], 1);
+ iRet = netbd_master_dev(ppcArgV[2], 0, ppcArgV[3], 1);
if (iRet) {
fprintf(stderr, "can not set if '%s' to bonding '%s' MASTER device!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "addarp") == 0) {
- iRet = netbd_add_arp(ppcArgV[2], ppcArgV[3]);
+ iRet = netbd_add_arp(ppcArgV[2], 0, ppcArgV[3]);
if (iRet) {
fprintf(stderr, "can not add ip '%s' to bonding '%s' ARP detect target!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "delarp") == 0) {
- iRet = netbd_delete_arp(ppcArgV[2], ppcArgV[3]);
+ iRet = netbd_delete_arp(ppcArgV[2], 0, ppcArgV[3]);
if (iRet) {
fprintf(stderr, "can not delete ip '%s' from bonding '%s' ARP detect target!\n", ppcArgV[3], ppcArgV[2]);
}
diff --git a/SylixOS/net/lwip/lwip_bridge.c b/SylixOS/net/lwip/lwip_bridge.c
index 62a0c4b..7c1a7b1 100644
--- a/SylixOS/net/lwip/lwip_bridge.c
+++ b/SylixOS/net/lwip/lwip_bridge.c
@@ -105,42 +105,42 @@ static INT _netbrIoctl (PLW_DEV_HDR pdevhdr,
case NETBR_CTL_DELETE:
pnetbrcrl = (struct net_bridge_ctl *)lArg;
if (pnetbrcrl) {
- iRet = netbr_delete(pnetbrcrl->br_dev);
+ iRet = netbr_delete(pnetbrcrl->br_dev, pnetbrcrl->br_index);
}
return (iRet);
case NETBR_CTL_ADD_DEV:
pnetbrcrl = (struct net_bridge_ctl *)lArg;
if (pnetbrcrl) {
- iRet = netbr_add_dev(pnetbrcrl->br_dev, pnetbrcrl->eth_dev, 0);
+ iRet = netbr_add_dev(pnetbrcrl->br_dev, pnetbrcrl->br_index, pnetbrcrl->eth_dev, 0);
}
return (iRet);
case NETBR_CTL_DELETE_DEV:
pnetbrcrl = (struct net_bridge_ctl *)lArg;
if (pnetbrcrl) {
- iRet = netbr_delete_dev(pnetbrcrl->br_dev, pnetbrcrl->eth_dev, 0);
+ iRet = netbr_delete_dev(pnetbrcrl->br_dev, pnetbrcrl->br_index, pnetbrcrl->eth_dev, 0);
}
return (iRet);
case NETBR_CTL_ADD_IF:
pnetbrcrl = (struct net_bridge_ctl *)lArg;
if (pnetbrcrl) {
- iRet = netbr_add_dev(pnetbrcrl->br_dev, pnetbrcrl->eth_dev, 1);
+ iRet = netbr_add_dev(pnetbrcrl->br_dev, pnetbrcrl->br_index, pnetbrcrl->eth_dev, 1);
}
return (iRet);
case NETBR_CTL_DELETE_IF:
pnetbrcrl = (struct net_bridge_ctl *)lArg;
if (pnetbrcrl) {
- iRet = netbr_delete_dev(pnetbrcrl->br_dev, pnetbrcrl->eth_dev, 1);
+ iRet = netbr_delete_dev(pnetbrcrl->br_dev, pnetbrcrl->br_index, pnetbrcrl->eth_dev, 1);
}
return (iRet);
case NETBR_CTL_CACHE_FLUSH:
pnetbrcrl = (struct net_bridge_ctl *)lArg;
if (pnetbrcrl) {
- iRet = netbr_flush_cache(pnetbrcrl->br_dev);
+ iRet = netbr_flush_cache(pnetbrcrl->br_dev, pnetbrcrl->br_index);
}
return (iRet);
@@ -244,7 +244,7 @@ static INT __tshellNetbr (INT iArgC, PCHAR *ppcArgV)
}
} else if (lib_strcmp(ppcArgV[1], "delbr") == 0) {
- iRet = netbr_delete(ppcArgV[2]);
+ iRet = netbr_delete(ppcArgV[2], 0);
if (iRet) {
fprintf(stderr, "can not delete net bridge device: %s!\n", lib_strerror(errno));
} else {
@@ -252,13 +252,13 @@ static INT __tshellNetbr (INT iArgC, PCHAR *ppcArgV)
}
} else if (lib_strcmp(ppcArgV[1], "flush") == 0) {
- iRet = netbr_flush_cache(ppcArgV[2]);
+ iRet = netbr_flush_cache(ppcArgV[2], 0);
if (iRet) {
fprintf(stderr, "can not flush net bridge device: %s!\n", lib_strerror(errno));
}
} else if (lib_strcmp(ppcArgV[1], "show") == 0) {
- iRet = netbr_show_dev(ppcArgV[2], STD_OUT);
+ iRet = netbr_show_dev(ppcArgV[2], 0, STD_OUT);
if (iRet) {
fprintf(stderr, "can not show net bridge device: %s!\n", lib_strerror(errno));
}
@@ -269,25 +269,25 @@ static INT __tshellNetbr (INT iArgC, PCHAR *ppcArgV)
} else if (iArgC == 4) {
if (lib_strcmp(ppcArgV[1], "adddev") == 0) {
- iRet = netbr_add_dev(ppcArgV[2], ppcArgV[3], 0);
+ iRet = netbr_add_dev(ppcArgV[2], 0, ppcArgV[3], 0);
if (iRet) {
fprintf(stderr, "can not add device '%s' to bridge '%s'!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "deldev") == 0) {
- iRet = netbr_delete_dev(ppcArgV[2], ppcArgV[3], 0);
+ iRet = netbr_delete_dev(ppcArgV[2], 0, ppcArgV[3], 0);
if (iRet) {
fprintf(stderr, "can not delete device '%s' from bridge '%s'!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "addif") == 0) {
- iRet = netbr_add_dev(ppcArgV[2], ppcArgV[3], 1);
+ iRet = netbr_add_dev(ppcArgV[2], 0, ppcArgV[3], 1);
if (iRet) {
fprintf(stderr, "can not add if '%s' to bridge '%s'!\n", ppcArgV[3], ppcArgV[2]);
}
} else if (lib_strcmp(ppcArgV[1], "delif") == 0) {
- iRet = netbr_delete_dev(ppcArgV[2], ppcArgV[3], 1);
+ iRet = netbr_delete_dev(ppcArgV[2], 0, ppcArgV[3], 1);
if (iRet) {
fprintf(stderr, "can not delete if '%s' from bridge '%s'!\n", ppcArgV[3], ppcArgV[2]);
}
diff --git a/SylixOS/net/lwip/lwip_ifctl.c b/SylixOS/net/lwip/lwip_ifctl.c
index abf938b..cd09880 100644
--- a/SylixOS/net/lwip/lwip_ifctl.c
+++ b/SylixOS/net/lwip/lwip_ifctl.c
@@ -642,6 +642,66 @@ static INT __ifSubIoctl6 (INT iCmd, PVOID pvArg)
#endif /* LWIP_IPV6 */
/*********************************************************************************************************
+** 函数名称: __ifSubIoctlStats
+** 功能描述: INET 网络统计接口 ioctl 操作
+** 输 入 : iCmd 命令
+** pvArg 参数
+** 输 出 : 处理结果
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT __ifSubIoctlStats (INT iCmd, PVOID pvArg)
+{
+#define MIB2_NETIF(netif) (&((netif)->mib2_counters))
+
+ INT iRet = PX_ERROR;
+ struct ifstatreq *pifstat;
+ struct netif *pnetif;
+ struct netdev *pnetdev;
+
+ pifstat = (struct ifstatreq *)pvArg;
+
+ pnetif = netif_find(pifstat->ifrs_name);
+ if (pnetif == LW_NULL) {
+ _ErrorHandle(EADDRNOTAVAIL); /* 未找到指定的网络接口 */
+ return (iRet);
+ }
+
+ if (netif_is_mipif(pnetif)) {
+ pnetif = netif_get_masterif(pnetif);
+ if (pnetif == LW_NULL) {
+ _ErrorHandle(EADDRNOTAVAIL); /* 未找到指定的网络接口 */
+ return (iRet);
+ }
+ }
+
+ switch (iCmd) {
+
+ case SIOCGIFSTATS:
+ pifstat->ifrs_mtu = pnetif->mtu;
+ pifstat->ifrs_collisions = MIB2_NETIF(pnetif)->ifcollisions;
+ pifstat->ifrs_baudrate = pnetif->link_speed;
+ pifstat->ifrs_ipackets = MIB2_NETIF(pnetif)->ifinucastpkts + MIB2_NETIF(pnetif)->ifinnucastpkts;
+ pifstat->ifrs_ierrors = MIB2_NETIF(pnetif)->ifinerrors;
+ pifstat->ifrs_opackets = MIB2_NETIF(pnetif)->ifoutucastpkts + MIB2_NETIF(pnetif)->ifoutnucastpkts;
+ pifstat->ifrs_oerrors = MIB2_NETIF(pnetif)->ifouterrors;
+ pifstat->ifrs_ibytes = MIB2_NETIF(pnetif)->ifinoctets;
+ pifstat->ifrs_obytes = MIB2_NETIF(pnetif)->ifoutoctets;
+ pifstat->ifrs_imcasts = MIB2_NETIF(pnetif)->ifinnucastpkts;
+ pifstat->ifrs_omcasts = MIB2_NETIF(pnetif)->ifoutnucastpkts;
+ pifstat->ifrs_iqdrops = MIB2_NETIF(pnetif)->ifindiscards;
+ pifstat->ifrs_noproto = MIB2_NETIF(pnetif)->ifinunknownprotos;
+ pnetdev = (netdev_t *)(pnetif->state);
+ if (pnetdev && (pnetdev->magic_no == NETDEV_MAGIC)) {
+ pifstat->ifrs_baudrate = pnetdev->speed;
+ }
+ iRet = ERROR_NONE;
+ break;
+ }
+
+ return (iRet);
+}
+/*********************************************************************************************************
** 函数名称: __ifSubIoctlCommon
** 功能描述: 通用网络接口 ioctl 操作
** 输 入 : iCmd 命令
@@ -791,6 +851,12 @@ INT __ifIoctlInet (INT iCmd, PVOID pvArg)
break;
#endif /* LWIP_IPV6 */
+ case SIOCGIFSTATS: /* 网络统计 */
+ LWIP_IF_LIST_LOCK(LW_FALSE); /* 进入临界区 */
+ iRet = __ifSubIoctlStats(iCmd, pvArg);
+ LWIP_IF_LIST_UNLOCK(); /* 退出临界区 */
+ break;
+
default:
_ErrorHandle(ENOSYS);
break;
@@ -883,6 +949,12 @@ INT __ifIoctlPacket (INT iCmd, PVOID pvArg)
LWIP_IF_LIST_UNLOCK(); /* 退出临界区 */
break;
+ case SIOCGIFSTATS: /* 网络统计 */
+ LWIP_IF_LIST_LOCK(LW_FALSE); /* 进入临界区 */
+ iRet = __ifSubIoctlStats(iCmd, pvArg);
+ LWIP_IF_LIST_UNLOCK(); /* 退出临界区 */
+ break;
+
default:
_ErrorHandle(ENOSYS);
break;
diff --git a/SylixOS/net/lwip/lwip_route.c b/SylixOS/net/lwip/lwip_route.c
index 925730b..af849b9 100644
--- a/SylixOS/net/lwip/lwip_route.c
+++ b/SylixOS/net/lwip/lwip_route.c
@@ -106,6 +106,7 @@ static VOID __route_show_ipv4 (VOID)
iRet = ioctl(iSock, SIOCLSTRT, &rtentrylist);
if (iRet < 0) {
fprintf(stderr, "command 'SIOCLSTRT' error: %s!\n", lib_strerror(errno));
+ __SHEAP_FREE(rtentrylist.rtl_buf);
close(iSock);
return;
}
@@ -201,6 +202,7 @@ static VOID __route_show_ipv6 (VOID)
iRet = ioctl(iSock, SIOCLSTRT, &rtentrylist);
if (iRet < 0) {
fprintf(stderr, "command 'SIOCLSTRT' error: %s!\n", lib_strerror(errno));
+ __SHEAP_FREE(rtentrylist.rtl_buf);
close(iSock);
return;
}
diff --git a/SylixOS/net/lwip/lwip_socket.c b/SylixOS/net/lwip/lwip_socket.c
index 3151f89..4e14444 100644
--- a/SylixOS/net/lwip/lwip_socket.c
+++ b/SylixOS/net/lwip/lwip_socket.c
@@ -552,6 +552,7 @@ static INT __socketIoctl (SOCKET_T *psock, INT iCmd, PVOID pvArg)
case SIOCSIFHWADDR:
case SIOCGIFPFLAGS:
case SIOCSIFPFLAGS:
+ case SIOCGIFSTATS:
iRet = __ifIoctlPacket(iCmd, pvArg);
break;
@@ -663,6 +664,7 @@ static INT __socketIoctl (SOCKET_T *psock, INT iCmd, PVOID pvArg)
case SIOCGIFNETMASK6:
case SIOCGIFDSTADDR6:
case SIOCDIFADDR6:
+ case SIOCGIFSTATS:
iRet = __ifIoctlInet(iCmd, pvArg);
break;
diff --git a/SylixOS/net/lwip/route/af_route.c b/SylixOS/net/lwip/route/af_route.c
index 278c41a..9370c86 100644
--- a/SylixOS/net/lwip/route/af_route.c
+++ b/SylixOS/net/lwip/route/af_route.c
@@ -34,6 +34,7 @@
#include "lwip/mem.h"
#include "lwip/netif.h"
#include "lwip/tcpip.h"
+#include "netdev.h"
#include "af_route.h"
/*********************************************************************************************************
函数声明
@@ -1389,6 +1390,7 @@ VOID route_hook_netif_updown (struct netif *pnetif)
#define MIB2_NETIF(netif) (&((netif)->mib2_counters))
size_t stMsgLen;
+ struct netdev *pnetdev;
struct if_msghdr *pmsghdr;
struct sockaddr_dl *psockaddrdl;
struct if_data *pifdata;
@@ -1448,17 +1450,24 @@ VOID route_hook_netif_updown (struct netif *pnetif)
pifdata->ifi_type = IFT_OTHER;
}
- pifdata->ifi_baudrate = pnetif->link_speed;
- pifdata->ifi_ipackets = MIB2_NETIF(pnetif)->ifinucastpkts + MIB2_NETIF(pnetif)->ifinnucastpkts;
- pifdata->ifi_ierrors = MIB2_NETIF(pnetif)->ifinerrors;
- pifdata->ifi_opackets = MIB2_NETIF(pnetif)->ifoutucastpkts + MIB2_NETIF(pnetif)->ifoutnucastpkts;
- pifdata->ifi_oerrors = MIB2_NETIF(pnetif)->ifouterrors;
- pifdata->ifi_ibytes = (u_long)MIB2_NETIF(pnetif)->ifinoctets;
- pifdata->ifi_obytes = (u_long)MIB2_NETIF(pnetif)->ifoutoctets;
- pifdata->ifi_imcasts = MIB2_NETIF(pnetif)->ifinnucastpkts;
- pifdata->ifi_omcasts = MIB2_NETIF(pnetif)->ifoutnucastpkts;
- pifdata->ifi_iqdrops = MIB2_NETIF(pnetif)->ifindiscards;
- pifdata->ifi_noproto = MIB2_NETIF(pnetif)->ifinunknownprotos;
+ pnetdev = (netdev_t *)(pnetif->state);
+ if (pnetdev && (pnetdev->magic_no == NETDEV_MAGIC)) {
+ pifdata->ifi_baudrate = pnetdev->speed;
+ } else {
+ pifdata->ifi_baudrate = pnetif->link_speed;
+ }
+
+ pifdata->ifi_ipackets = MIB2_NETIF(pnetif)->ifinucastpkts + MIB2_NETIF(pnetif)->ifinnucastpkts;
+ pifdata->ifi_ierrors = MIB2_NETIF(pnetif)->ifinerrors;
+ pifdata->ifi_opackets = MIB2_NETIF(pnetif)->ifoutucastpkts + MIB2_NETIF(pnetif)->ifoutnucastpkts;
+ pifdata->ifi_oerrors = MIB2_NETIF(pnetif)->ifouterrors;
+ pifdata->ifi_collisions = MIB2_NETIF(pnetif)->ifcollisions;
+ pifdata->ifi_ibytes = (u_long)MIB2_NETIF(pnetif)->ifinoctets;
+ pifdata->ifi_obytes = (u_long)MIB2_NETIF(pnetif)->ifoutoctets;
+ pifdata->ifi_imcasts = MIB2_NETIF(pnetif)->ifinnucastpkts;
+ pifdata->ifi_omcasts = MIB2_NETIF(pnetif)->ifoutnucastpkts;
+ pifdata->ifi_iqdrops = MIB2_NETIF(pnetif)->ifindiscards;
+ pifdata->ifi_noproto = MIB2_NETIF(pnetif)->ifinunknownprotos;
lib_clock_gettime(CLOCK_REALTIME, &ts);
pifdata->ifi_lastchange.tv_sec = ts.tv_sec;
diff --git a/SylixOS/net/lwip/src/api/api_msg.c b/SylixOS/net/lwip/src/api/api_msg.c
index bf94be4..233cc05 100644
--- a/SylixOS/net/lwip/src/api/api_msg.c
+++ b/SylixOS/net/lwip/src/api/api_msg.c
@@ -1019,7 +1019,9 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
/* check linger possibilites before calling tcp_close */
err = ERR_OK;
/* linger enabled/required at all? (i.e. is there untransmitted data left?) */
- if ((conn->linger >= 0) && (conn->pcb.tcp->unsent || conn->pcb.tcp->unacked)) {
+ /* SylixOS Fixed listen conn do not need check linger */
+ if ((conn->state != NETCONN_LISTEN) &&
+ (conn->linger >= 0) && (conn->pcb.tcp->unsent || conn->pcb.tcp->unacked)) {
if ((conn->linger == 0)) {
/* data left but linger prevents waiting */
tcp_abort(tpcb);
diff --git a/SylixOS/net/lwip/src/api/sockets.c b/SylixOS/net/lwip/src/api/sockets.c
index 8cc7054..4647741 100644
--- a/SylixOS/net/lwip/src/api/sockets.c
+++ b/SylixOS/net/lwip/src/api/sockets.c
@@ -69,6 +69,10 @@
#include LWIP_HOOK_FILENAME
#endif
+#ifdef SYLIXOS /* SylixOS Need TCP_STATE */
+#include <netinet/tcp.h>
+#endif
+
/* If the netconn API is not required publicly, then we include the necessary
files here to get the implementation */
#if !LWIP_NETCONN
@@ -3383,6 +3387,42 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt
#if LWIP_TCP
/* Level: IPPROTO_TCP */
case IPPROTO_TCP:
+#ifdef SYLIXOS /* SylixOS Add TCP_DESC */
+ if (optname == TCP_DESC) {
+ LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, sizeof(struct tcp_desc), NETCONN_TCP);
+ struct tcp_desc *desc = (struct tcp_desc *)optval;
+ if (sock->conn->pcb.tcp->state == LISTEN) {
+ struct tcp_pcb_listen *lpcb = (struct tcp_pcb_listen *)lpcb;
+ lib_bzero(desc, sizeof(struct tcp_desc));
+ desc->tcp_state = LISTEN;
+ desc->tcp_backlog = lpcb->backlog;
+ desc->tcp_accpend = lpcb->accepts_pending;
+ } else {
+ struct tcp_pcb *pcb = sock->conn->pcb.tcp;
+ desc->tcp_state = pcb->state;
+ desc->tcp_backlog = 0;
+ desc->tcp_accpend = 0;
+ desc->tcp_rcv_scale = pcb->rcv_scale;
+ desc->tcp_snd_scale = pcb->snd_scale;
+ desc->tcp_rcv_nxt = pcb->rcv_nxt;
+ desc->tcp_rcv_wnd = pcb->rcv_wnd;
+ desc->tcp_snd_nxt = pcb->snd_nxt;
+ desc->tcp_snd_wnd = pcb->snd_wnd;
+ desc->tcp_snd_buf = pcb->snd_buf;
+ desc->tcp_cwnd = pcb->cwnd;
+ desc->tcp_ssthresh = pcb->ssthresh;
+ desc->tcp_rtime = pcb->rtime;
+ desc->tcp_mss = pcb->mss;
+ desc->tcp_flags = pcb->flags;
+ desc->tcp_rcv_ts = pcb->ts_recent;
+ desc->tcp_snd_ts = pcb->ts_lastacksent;
+ desc->tcp_keep_idle = pcb->keep_idle;
+ desc->tcp_keep_intvl = pcb->keep_intvl;
+ desc->tcp_keep_cnt = pcb->keep_cnt;
+ }
+ break;
+ }
+#endif /* SYLIXOS */
/* Special case: all IPPROTO_TCP option take an int */
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, int, NETCONN_TCP);
if (sock->conn->pcb.tcp->state == LISTEN) {
diff --git a/SylixOS/net/lwip/tools/nat/lwip_natlib.c b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
index 6f2f1a6..ef03ca3 100644
--- a/SylixOS/net/lwip/tools/nat/lwip_natlib.c
+++ b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
@@ -39,6 +39,7 @@
2018.04.06 NAT 支持提前分片重组.
2019.02.15 本地 TCP SYN, CLOSING 仅保持 1 分钟.
2019.04.09 NAT AP 端口支持主机安全隔离.
+2019.05.20 MAP 0.0.0.0 作为本机映射.
*********************************************************************************************************/
#define __SYLIXOS_STDIO
#define __SYLIXOS_KERNEL
@@ -768,11 +769,16 @@ static INT __natApInput (struct pbuf *p, struct netif *netifIn)
}
}
if (plineTemp == LW_NULL) {
- u32_t uiHost;
+ if (pnatmap->NATM_ipaddrLocalIp.addr == IPADDR_ANY) {
+ ipaddr.addr = netif_ip4_addr(netifIn)->addr; /* 本机映射 */
- uiHost = (u32_t)PP_NTOHL(pnatmap->NATM_ipaddrLocalIp.addr);
- uiHost += usSrcHash; /* 根据源地址散列做均衡 */
- ipaddr.addr = (u32_t)PP_HTONL(uiHost);
+ } else {
+ u32_t uiHost;
+
+ uiHost = (u32_t)PP_NTOHL(pnatmap->NATM_ipaddrLocalIp.addr);
+ uiHost += usSrcHash; /* 根据源地址散列做均衡 */
+ ipaddr.addr = (u32_t)PP_HTONL(uiHost);
+ }
pnatcb = __natNew(&ipaddr, /* 新建控制块 */
pnatmap->NATM_usLocalPort, ucProto);
diff --git a/SylixOS/net/lwip/tools/npf/lwip_npf.c b/SylixOS/net/lwip/tools/npf/lwip_npf.c
index 3278988..ede62b3 100644
--- a/SylixOS/net/lwip/tools/npf/lwip_npf.c
+++ b/SylixOS/net/lwip/tools/npf/lwip_npf.c
@@ -356,12 +356,18 @@ static BOOL __npfIpRuleCheck (__PNPF_NETIF_CB pnpfni, BOOL bIn, struct ip_hdr
while (plineTemp) {
pnpfri = _LIST_ENTRY(plineTemp, __NPF_RULE_IP, NPFRI_lineManage);
- if ((ipaddrHbo.addr >= pnpfri->NPFRI_ipaddrHboS.addr) &&
- (ipaddrHbo.addr <= pnpfri->NPFRI_ipaddrHboE.addr)) {
- if (pnpfri->NPFRI_bAllow) {
+ if (pnpfri->NPFRI_bAllow) {
+ if ((ipaddrHbo.addr >= pnpfri->NPFRI_ipaddrHboS.addr) &&
+ (ipaddrHbo.addr <= pnpfri->NPFRI_ipaddrHboE.addr)) {
return (LW_TRUE); /* 白名单, 立即放行 */
}
bAllow = LW_FALSE; /* 禁止通过 */
+
+ } else {
+ if ((ipaddrHbo.addr >= pnpfri->NPFRI_ipaddrHboS.addr) &&
+ (ipaddrHbo.addr <= pnpfri->NPFRI_ipaddrHboE.addr)) {
+ bAllow = LW_FALSE; /* 禁止通过 */
+ }
}
plineTemp = _list_line_get_next(plineTemp);
}
@@ -401,14 +407,22 @@ static BOOL __npfUdpRuleCheck (__PNPF_NETIF_CB pnpfni, BOOL bIn,
while (plineTemp) {
pnpfru = _LIST_ENTRY(plineTemp, __NPF_RULE_UDP, NPFRU_lineManage);
- if ((ipaddrHbo.addr >= pnpfru->NPFRU_ipaddrHboS.addr) &&
- (ipaddrHbo.addr <= pnpfru->NPFRU_ipaddrHboE.addr) &&
- (usPortHbo >= pnpfru->NPFRU_usPortHboS) &&
- (usPortHbo <= pnpfru->NPFRU_usPortHboE)) {
- if (pnpfru->NPFRU_bAllow) {
+ if (pnpfru->NPFRU_bAllow) {
+ if ((ipaddrHbo.addr >= pnpfru->NPFRU_ipaddrHboS.addr) &&
+ (ipaddrHbo.addr <= pnpfru->NPFRU_ipaddrHboE.addr) &&
+ (usPortHbo >= pnpfru->NPFRU_usPortHboS) &&
+ (usPortHbo <= pnpfru->NPFRU_usPortHboE)) {
return (LW_TRUE); /* 白名单, 立即放行 */
}
bAllow = LW_FALSE; /* 禁止通过 */
+
+ } else {
+ if ((ipaddrHbo.addr >= pnpfru->NPFRU_ipaddrHboS.addr) &&
+ (ipaddrHbo.addr <= pnpfru->NPFRU_ipaddrHboE.addr) &&
+ (usPortHbo >= pnpfru->NPFRU_usPortHboS) &&
+ (usPortHbo <= pnpfru->NPFRU_usPortHboE)) {
+ bAllow = LW_FALSE; /* 禁止通过 */
+ }
}
plineTemp = _list_line_get_next(plineTemp);
}
@@ -447,14 +461,22 @@ static BOOL __npfTcpRuleCheck (__PNPF_NETIF_CB pnpfni, BOOL bIn,
while (plineTemp) {
pnpfrt = _LIST_ENTRY(plineTemp, __NPF_RULE_TCP, NPFRT_lineManage);
- if ((ipaddrHbo.addr >= pnpfrt->NPFRT_ipaddrHboS.addr) &&
- (ipaddrHbo.addr <= pnpfrt->NPFRT_ipaddrHboE.addr) &&
- (usPortHbo >= pnpfrt->NPFRT_usPortHboS) &&
- (usPortHbo <= pnpfrt->NPFRT_usPortHboE)) {
- if (pnpfrt->NPFRT_bAllow) {
+ if (pnpfrt->NPFRT_bAllow) {
+ if ((ipaddrHbo.addr >= pnpfrt->NPFRT_ipaddrHboS.addr) &&
+ (ipaddrHbo.addr <= pnpfrt->NPFRT_ipaddrHboE.addr) &&
+ (usPortHbo >= pnpfrt->NPFRT_usPortHboS) &&
+ (usPortHbo <= pnpfrt->NPFRT_usPortHboE)) {
return (LW_TRUE); /* 白名单, 立即放行 */
}
bAllow = LW_FALSE; /* 禁止通过 */
+
+ } else {
+ if ((ipaddrHbo.addr >= pnpfrt->NPFRT_ipaddrHboS.addr) &&
+ (ipaddrHbo.addr <= pnpfrt->NPFRT_ipaddrHboE.addr) &&
+ (usPortHbo >= pnpfrt->NPFRT_usPortHboS) &&
+ (usPortHbo <= pnpfrt->NPFRT_usPortHboE)) {
+ bAllow = LW_FALSE; /* 禁止通过 */
+ }
}
plineTemp = _list_line_get_next(plineTemp);
}
diff --git a/SylixOS/posix/aio/aio_lib.c b/SylixOS/posix/aio/aio_lib.c
index 9343874..b3c6281 100644
--- a/SylixOS/posix/aio/aio_lib.c
+++ b/SylixOS/posix/aio/aio_lib.c
@@ -733,6 +733,14 @@ static PVOID __aioThread (PVOID pvArg)
API_SemaphoreMPend(paiorc->aiorc_mutex, LW_OPTION_WAIT_INFINITE);
+ if (paiorc->aiorc_iscancel) {
+ paioreq->aioreq_return = PX_ERROR;
+ paioreq->aioreq_error = ECANCELED;
+ paioreq->aioreq_flags &= ~AIO_REQ_BUSY; /* 清除忙标志 */
+ API_SemaphoreMPost(paiorc->aiorc_mutex);
+ continue;
+ }
+
_List_Line_Del(paiorc->aiorc_plineaiocb,
&paiorc->aiorc_plineaiocb); /* 将处理节点从 paiorc 中删除 */
diff --git a/SylixOS/posix/include/px_mman.h b/SylixOS/posix/include/px_mman.h
index 993210f..c01dba5 100644
--- a/SylixOS/posix/include/px_mman.h
+++ b/SylixOS/posix/include/px_mman.h
@@ -60,6 +60,14 @@ extern "C" {
#endif
/*********************************************************************************************************
+ extends flag
+*********************************************************************************************************/
+
+#if defined(__SYLIXOS_EXTEND) || defined(__SYLIXOS_KERNEL)
+#define MAP_PREALLOC 0x8000 /* MAP_ANON pre alloc memory */
+#endif
+
+/*********************************************************************************************************
msync() flag
*********************************************************************************************************/
diff --git a/SylixOS/posix/mman/mman.c b/SylixOS/posix/mman/mman.c
index 55c374e..ce46df8 100644
--- a/SylixOS/posix/mman/mman.c
+++ b/SylixOS/posix/mman/mman.c
@@ -231,6 +231,10 @@ void *mmap (void *pvAddr, size_t stLen, int iProt, int iFlag, int iFd, off
return (MAP_FAILED);
}
+ if ((iFlag & MAP_ANONYMOUS) && (iFlag & MAP_PREALLOC) && (pvAddr == LW_NULL)) {
+ iFlags |= LW_VMM_PHY_PREALLOC; /* 内存管理预分配 */
+ }
+
pvRet = API_VmmMmap(pvAddr, stLen, iFlags, ulFlag, iFd, off);
return ((pvRet != LW_VMM_MAP_FAILED) ? pvRet : MAP_FAILED);
diff --git a/SylixOS/posix/pthread/pthread.c b/SylixOS/posix/pthread/pthread.c
index 0f1e7e3..15da09e 100644
--- a/SylixOS/posix/pthread/pthread.c
+++ b/SylixOS/posix/pthread/pthread.c
@@ -51,7 +51,6 @@
#if LW_CFG_POSIX_EN > 0
#if (LW_CFG_GJB7714_EN > 0) && (LW_CFG_MODULELOADER_EN > 0)
#include "unistd.h"
-#include "../SylixOS/loader/include/loader_vppatch.h"
#endif
/*********************************************************************************************************
** 函数名称: pthread_atfork
@@ -1052,7 +1051,7 @@ int pthread_getid (const char *name, pthread_t *pthread)
}
#if LW_CFG_MODULELOADER_EN > 0
- if (pid != vprocGetPidByTcbdesc(&tcbdesc)) {
+ if (pid != (pid_t)tcbdesc.TCBD_lPid) {
continue;
}
#endif /* LW_CFG_MODULELOADER_EN > 0 */
diff --git a/SylixOS/posix/pthread/pthread_cond.c b/SylixOS/posix/pthread/pthread_cond.c
index e2673b0..3cc1092 100644
--- a/SylixOS/posix/pthread/pthread_cond.c
+++ b/SylixOS/posix/pthread/pthread_cond.c
@@ -54,6 +54,7 @@ VOID _posixPCondInit (VOID)
_G_ulPCondInitLock = API_SemaphoreMCreate("pcondinit", LW_PRIO_DEF_CEILING,
LW_OPTION_INHERIT_PRIORITY |
LW_OPTION_WAIT_PRIORITY |
+ LW_OPTION_OBJECT_GLOBAL |
LW_OPTION_DELETE_SAFE, LW_NULL);
}
/*********************************************************************************************************
diff --git a/SylixOS/posix/pthread/pthread_mutex.c b/SylixOS/posix/pthread/pthread_mutex.c
index 1b9cc12..d0e9e8f 100644
--- a/SylixOS/posix/pthread/pthread_mutex.c
+++ b/SylixOS/posix/pthread/pthread_mutex.c
@@ -62,6 +62,7 @@ VOID _posixPMutexInit (VOID)
_G_ulPMutexInitLock = API_SemaphoreMCreate("pmutexinit", LW_PRIO_DEF_CEILING,
LW_OPTION_INHERIT_PRIORITY |
LW_OPTION_WAIT_PRIORITY |
+ LW_OPTION_OBJECT_GLOBAL |
LW_OPTION_DELETE_SAFE, LW_NULL);
}
}
diff --git a/SylixOS/posix/pthread/pthread_rwlock.c b/SylixOS/posix/pthread/pthread_rwlock.c
index b340826..4af4fbe 100644
--- a/SylixOS/posix/pthread/pthread_rwlock.c
+++ b/SylixOS/posix/pthread/pthread_rwlock.c
@@ -56,6 +56,7 @@ VOID _posixPRWLockInit (VOID)
_G_ulPRWLockInitLock = API_SemaphoreMCreate("prwinit", LW_PRIO_DEF_CEILING,
LW_OPTION_INHERIT_PRIORITY |
LW_OPTION_WAIT_PRIORITY |
+ LW_OPTION_OBJECT_GLOBAL |
LW_OPTION_DELETE_SAFE, LW_NULL);
}
/*********************************************************************************************************
diff --git a/SylixOS/posix/sched/sched.c b/SylixOS/posix/sched/sched.c
index 49e6d10..8d7f331 100644
--- a/SylixOS/posix/sched/sched.c
+++ b/SylixOS/posix/sched/sched.c
@@ -90,6 +90,38 @@ int sched_yield (void)
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: __sched_set
+** 功能描述: 设置指定任务调度器参数 (进入内核后被调用)
+** 输 入 : ptcb 任务控制块
+** pucPolicy 调度策略
+** pucPriority 优先级
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_EN > 0
+
+static VOID __sched_set (PLW_CLASS_TCB ptcb, UINT8 *pucPolicy, UINT8 *pucPriority)
+{
+ if (LW_LIKELY(ptcb)) {
+ if (pucPriority) {
+ if (!LW_PRIO_IS_EQU(ptcb->TCB_ucPriority, *pucPriority)) {
+ _SchedSetPrio(ptcb, *pucPriority);
+ }
+ }
+
+ if (pucPolicy) {
+ ptcb->TCB_ucSchedPolicy = *pucPolicy;
+ if (*pucPolicy == LW_OPTION_SCHED_FIFO) {
+ ptcb->TCB_usSchedCounter = ptcb->TCB_usSchedSlice; /* 不为零 */
+ }
+ }
+ }
+}
+
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+/*********************************************************************************************************
** 函数名称: sched_setparam
** 功能描述: 设置指定任务调度器参数
** 输 入 : pid 进程 / 线程 ID
@@ -102,9 +134,7 @@ int sched_yield (void)
LW_API
int sched_setparam (pid_t pid, const struct sched_param *pschedparam)
{
- UINT8 ucPriority;
- ULONG ulError;
- LW_OBJECT_HANDLE ulThread;
+ UINT8 ucPriority;
if (pschedparam == LW_NULL) {
errno = EINVAL;
@@ -120,29 +150,29 @@ int sched_setparam (pid_t pid, const struct sched_param *pschedparam)
#if LW_CFG_MODULELOADER_EN > 0
if (pid == 0) {
- pid = getpid();
+ pid = getpid();
}
if (pid == 0) {
- ulThread = API_ThreadIdSelf();
- } else {
- ulThread = vprocMainThread(pid);
+ errno = ESRCH;
+ return (PX_ERROR);
}
- if (ulThread == LW_OBJECT_HANDLE_INVALID) {
+
+ if (vprocThreadTraversal(pid, __sched_set, LW_NULL, &ucPriority,
+ LW_NULL, LW_NULL, LW_NULL, LW_NULL)) {
errno = ESRCH;
return (PX_ERROR);
}
#else
- ulThread = (LW_OBJECT_HANDLE)pid;
+ LW_OBJECT_HANDLE ulThread = (LW_OBJECT_HANDLE)pid;
PX_ID_VERIFY(ulThread, LW_OBJECT_HANDLE);
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
- ulError = API_ThreadSetPriority(ulThread, ucPriority);
- if (ulError) {
+ if (API_ThreadSetPriority(ulThread, ucPriority)) {
errno = ESRCH;
return (PX_ERROR);
- } else {
- return (ERROR_NONE);
}
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+
+ return (ERROR_NONE);
}
/*********************************************************************************************************
** 函数名称: sched_getparam
@@ -209,9 +239,7 @@ int sched_setscheduler (pid_t pid,
int iPolicy,
const struct sched_param *pschedparam)
{
- UINT8 ucPriority;
- UINT8 ucActivatedMode;
- LW_OBJECT_HANDLE ulThread;
+ UINT8 ucPriority;
if (pschedparam == LW_NULL) {
errno = EINVAL;
@@ -234,21 +262,22 @@ int sched_setscheduler (pid_t pid,
#if LW_CFG_MODULELOADER_EN > 0
if (pid == 0) {
- pid = getpid();
+ pid = getpid();
}
if (pid == 0) {
- ulThread = API_ThreadIdSelf();
- } else {
- ulThread = vprocMainThread(pid);
+ errno = ESRCH;
+ return (PX_ERROR);
}
- if (ulThread == LW_OBJECT_HANDLE_INVALID) {
+
+ if (vprocThreadTraversal(pid, __sched_set, &iPolicy, &ucPriority,
+ LW_NULL, LW_NULL, LW_NULL, LW_NULL)) {
errno = ESRCH;
return (PX_ERROR);
}
#else
- ulThread = (LW_OBJECT_HANDLE)pid;
+ UINT8 ucActivatedMode;
+ LW_OBJECT_HANDLE ulThread = (LW_OBJECT_HANDLE)pid;
PX_ID_VERIFY(ulThread, LW_OBJECT_HANDLE);
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
if (API_ThreadGetSchedParam(ulThread,
LW_NULL,
@@ -256,15 +285,16 @@ int sched_setscheduler (pid_t pid,
errno = ESRCH;
return (PX_ERROR);
}
-
+
API_ThreadSetSchedParam(ulThread, (UINT8)iPolicy, ucActivatedMode);
-
+
if (API_ThreadSetPriority(ulThread, ucPriority)) {
errno = ESRCH;
return (PX_ERROR);
- } else {
- return (ERROR_NONE);
}
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+
+ return (ERROR_NONE);
}
/*********************************************************************************************************
** 函数名称: sched_getscheduler
@@ -387,10 +417,16 @@ int sched_setaffinity (pid_t pid, size_t setsize, const cpu_set_t *set)
errno = EINVAL;
return (PX_ERROR);
}
+
+#if LW_CFG_MODULELOADER_EN > 0
if (vprocSetAffinity(pid, setsize, (PLW_CLASS_CPUSET)set)) {
errno = ESRCH;
return (PX_ERROR);
}
+#else
+ errno = ESRCH;
+ return (PX_ERROR);
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
#endif /* LW_CFG_SMP_EN > 0 */
return (ERROR_NONE);
@@ -414,10 +450,16 @@ int sched_getaffinity (pid_t pid, size_t setsize, cpu_set_t *set)
errno = EINVAL;
return (PX_ERROR);
}
+
+#if LW_CFG_MODULELOADER_EN > 0
if (vprocGetAffinity(pid, setsize, set)) {
errno = ESRCH;
return (PX_ERROR);
}
+#else
+ errno = ESRCH;
+ return (PX_ERROR);
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
#endif /* LW_CFG_SMP_EN > 0 */
return (ERROR_NONE);
diff --git a/SylixOS/posix/semaphore/semaphore.c b/SylixOS/posix/semaphore/semaphore.c
index feeaa4f..39d6a2f 100644
--- a/SylixOS/posix/semaphore/semaphore.c
+++ b/SylixOS/posix/semaphore/semaphore.c
@@ -78,6 +78,7 @@ VOID _posixPSemInit (VOID)
_G_ulPSemInitLock = API_SemaphoreMCreate("pseminit", LW_PRIO_DEF_CEILING,
LW_OPTION_INHERIT_PRIORITY |
LW_OPTION_WAIT_PRIORITY |
+ LW_OPTION_OBJECT_GLOBAL |
LW_OPTION_DELETE_SAFE, LW_NULL);
}
/*********************************************************************************************************
diff --git a/SylixOS/shell/fsLib/ttinyShellFsCmd.c b/SylixOS/shell/fsLib/ttinyShellFsCmd.c
index 9987f76..f29a65a 100644
--- a/SylixOS/shell/fsLib/ttinyShellFsCmd.c
+++ b/SylixOS/shell/fsLib/ttinyShellFsCmd.c
@@ -343,9 +343,10 @@ static INT __tshellFsCmdRm (INT iArgC, PCHAR ppcArgV[])
*********************************************************************************************************/
static INT __tshellFsCmdMv (INT iArgC, PCHAR ppcArgV[])
{
- REGISTER INT iError = PX_ERROR;
- REGISTER INT iFd;
- CHAR cTemp[16];
+ REGISTER INT iError = PX_ERROR;
+ REGISTER INT iFd;
+ CHAR cTemp[16];
+ struct stat statGet;
if (iArgC != 3) {
fprintf(stderr, "arguments error!\n");
@@ -368,6 +369,13 @@ __re_select:
goto __error_handle;
} else if ((cTemp[0] == 'Y') ||
(cTemp[0] == 'y')) { /* 覆盖 */
+ if (stat(ppcArgV[2], &statGet)) {
+ goto __error_handle;
+ }
+ if (S_ISDIR(statGet.st_mode)) { /* 不允许覆盖目录 */
+ fprintf(stderr, "Error: %s is an existing directory!\n", ppcArgV[2]);
+ goto __error_handle;
+ }
if (unlink(ppcArgV[2]) != ERROR_NONE) {
goto __error_handle;
}
diff --git a/SylixOS/shell/ttinyShell/ttinyShellLib.c b/SylixOS/shell/ttinyShell/ttinyShellLib.c
index 9999986..00f2216 100644
--- a/SylixOS/shell/ttinyShell/ttinyShellLib.c
+++ b/SylixOS/shell/ttinyShell/ttinyShellLib.c
@@ -806,7 +806,12 @@ INT __tshellRestartEx (LW_OBJECT_HANDLE ulThread, BOOL bNeedAuthen)
INT iMsg;
UINT16 usIndex;
- if (LW_CPU_GET_CUR_NESTING()) {
+#if LW_CFG_ISR_DEFER_EN > 0
+ if (API_InterDeferContext())
+#else
+ if (LW_CPU_GET_CUR_NESTING())
+#endif
+ {
return (_excJobAdd((VOIDFUNCPTR)__tshellRestartEx,
(PVOID)ulThread, (PVOID)bNeedAuthen, 0, 0, 0, 0));
}
diff --git a/SylixOS/system/device/can/can.c b/SylixOS/system/device/can/can.c
index 6636b7d..44d6a8f 100644
--- a/SylixOS/system/device/can/can.c
+++ b/SylixOS/system/device/can/can.c
@@ -33,6 +33,7 @@
pend(..., LW_OPTION_NOT_WAIT) 改为 clear() 操作.
2012.10.31 修正一些不合理的命名.
2017.03.13 支持 CAN FD 标准与发送完成同步.
+2019.05.20 总线异常唤醒读写阻塞线程.
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#include "../SylixOS/kernel/include/k_kernel.h"
@@ -536,9 +537,12 @@ static VOID __canSetBusState (__CAN_DEV *pcanDev, INT iState)
LW_SPIN_UNLOCK_QUICK(&pcanport->CANPORT_can.CAN_slLock, iregInterLevel);
if (pcanDev->CAN_uiBusState != CAN_DEV_BUS_ERROR_NONE) { /* 总线异常 */
- API_SemaphoreBFlush(pcanDev->CAN_ulSendSemB, LW_NULL); /* 激活写等待任务 */
- API_SemaphoreBFlush(pcanDev->CAN_ulRcvSemB, LW_NULL); /* 激活读等待任务 */
- SEL_WAKE_UP_ALL(&pcanDev->CAN_selwulList, SELEXCEPT); /* select() 激活 */
+ API_SemaphoreBPost(pcanDev->CAN_ulSendSemB); /* 激活写等待任务 */
+ API_SemaphoreBPost(pcanDev->CAN_ulRcvSemB); /* 激活读等待任务 */
+ SEL_WAKE_UP_ALL_BY_FLAGS(&pcanDev->CAN_selwulList,
+ LW_SEL_TYPE_FLAG_READ |
+ LW_SEL_TYPE_FLAG_WRITE |
+ LW_SEL_TYPE_FLAG_EXCEPT); /* select() 激活 */
}
}
/*********************************************************************************************************
@@ -967,6 +971,11 @@ static ssize_t __canWrite (__CAN_DEV *pcanDev, PVOID pvCanFrame, size_t stNBy
stNumber = stNBytes / stUnit; /* 转换为数据包个数 */
+ if (pcanDev->CAN_uiBusState != CAN_DEV_BUS_ERROR_NONE) { /* 总线错误 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
while (stNumber > 0) {
ulError = API_SemaphoreBPend(pcanDev->CAN_ulSendSemB,
pcanDev->CAN_ulSendTimeout);
@@ -978,12 +987,20 @@ static ssize_t __canWrite (__CAN_DEV *pcanDev, PVOID pvCanFrame, size_t stNBy
CANDEV_LOCK(pcanDev); /* 等待设备使用权 */
LW_SPIN_LOCK_QUICK(&pcanDev->CAN_slLock, &iregInterLevel);
+
if (pcanDev->CAN_uiBusState != CAN_DEV_BUS_ERROR_NONE) { /* 总线错误 */
LW_SPIN_UNLOCK_QUICK(&pcanDev->CAN_slLock, iregInterLevel);
CANDEV_UNLOCK(pcanDev);
_ErrorHandle(EIO);
return ((ssize_t)(i * stUnit));
}
+
+ if (__canQFreeNum(pcanDev->CAN_pcanqSendQueue) <= 0) { /* 发送队列是否有空闲空间 */
+ LW_SPIN_UNLOCK_QUICK(&pcanDev->CAN_slLock, iregInterLevel);
+ CANDEV_UNLOCK(pcanDev);
+ continue;
+ }
+
LW_SPIN_UNLOCK_QUICK(&pcanDev->CAN_slLock, iregInterLevel);
iFrameput = __canWriteQueue(pcanDev,
@@ -1053,6 +1070,11 @@ static ssize_t __canRead (__CAN_DEV *pcanDev, PVOID pvCanFrame, size_t stNByt
stNumber = stNBytes / stUnit; /* 转换为数据包个数 */
+ if (pcanDev->CAN_uiBusState != CAN_DEV_BUS_ERROR_NONE) { /* 总线错误 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
for (;;) {
ulError = API_SemaphoreBPend(pcanDev->CAN_ulRcvSemB,
pcanDev->CAN_ulRecvTimeout);
@@ -1076,6 +1098,7 @@ static ssize_t __canRead (__CAN_DEV *pcanDev, PVOID pvCanFrame, size_t stNByt
return (0);
}
}
+
LW_SPIN_UNLOCK_QUICK(&pcanDev->CAN_slLock, iregInterLevel);
/* 打开中断 */
CANDEV_UNLOCK(pcanDev); /* 释放设备使用权 */
diff --git a/SylixOS/system/device/pci/pciLib.c b/SylixOS/system/device/pci/pciLib.c
index 5375b94..4cb57ac 100644
--- a/SylixOS/system/device/pci/pciLib.c
+++ b/SylixOS/system/device/pci/pciLib.c
@@ -216,6 +216,8 @@ pci_size_t API_PciSizeNumGet (pci_size_t stSize)
LW_API
PCI_CTRL_HANDLE API_PciCtrlCreate (PCI_CTRL_HANDLE hCtrl)
{
+ PCI_AUTO_HANDLE hPciAuto; /* 自动配置控制句柄 */
+
if (PCI_CTRL == LW_NULL) {
PCI_CTRL = hCtrl;
@@ -227,8 +229,16 @@ PCI_CTRL_HANDLE API_PciCtrlCreate (PCI_CTRL_HANDLE hCtrl)
/*
* 需要在设备列表创建完成之后再进行自动配置
* 因为部分平台配置寄存器的读写需要依赖父节点的索引参数
+ *
+ * 需要在自动配置后重新更新设备列表
+ * 因为部分主控器会修改枚举设备树型结构
*/
API_PciAutoScan(hCtrl, (UINT32 *)&hCtrl->PCI_iBusMax);
+ hPciAuto = &hCtrl->PCI_tAutoConfig;
+ if (hPciAuto->PCIAUTO_iConfigEn) { /* 自动配置使能 */
+ API_PciDevDelete(LW_NULL);
+ API_PciDevListCreate();
+ }
#if LW_CFG_PROCFS_EN > 0
__procFsPciInit();
diff --git a/SylixOS/system/device/pipe/pipeLib.c b/SylixOS/system/device/pipe/pipeLib.c
index 5edf25c..9f0f7c7 100644
--- a/SylixOS/system/device/pipe/pipeLib.c
+++ b/SylixOS/system/device/pipe/pipeLib.c
@@ -64,7 +64,7 @@ LONG _PipeOpen (PLW_PIPE_DEV p_pipedev,
return (PX_ERROR);
} else {
- if (iFlags & O_CREAT) {
+ if ((iFlags & O_CREAT) && (iFlags & O_EXCL)) {
_ErrorHandle(ERROR_IO_FILE_EXIST); /* 不能重复创建 */
return (PX_ERROR);
}
diff --git a/SylixOS/system/device/semfd/semfdDev.c b/SylixOS/system/device/semfd/semfdDev.c
index e984c86..c8fcc5f 100644
--- a/SylixOS/system/device/semfd/semfdDev.c
+++ b/SylixOS/system/device/semfd/semfdDev.c
@@ -229,6 +229,12 @@ static INT _semfdSetInode (PLW_SEMFD_INODE psemfdinode, struct semfd_param *pa
return (PX_ERROR);
}
+ if ((param->sem_value > INT32_MAX) ||
+ (param->sem_max > INT32_MAX)) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
ulOpt |= param->sem_opts;
switch (param->sem_type) {
@@ -697,7 +703,7 @@ static INT _semfdNFreeFnode (PLW_SEMFD_FILE psemfdfil, INT *piNFree)
case _OBJECT_SEM_C:
API_SemaphoreCStatusEx(psemfdfil->SEMFDF_pinode->SEMFDI_ulSem, &ulValue, LW_NULL, LW_NULL, &ulMaxValue);
if (ulValue < ulMaxValue) {
- *piNFree = 1;
+ *piNFree = (INT)(ulMaxValue - ulValue);
}
break;
@@ -758,7 +764,7 @@ static INT _semfdNReadFnode (PLW_SEMFD_FILE psemfdfil, INT *piNRead)
case _OBJECT_SEM_C:
API_SemaphoreCStatus(psemfdfil->SEMFDF_pinode->SEMFDI_ulSem, &ulValue, LW_NULL, LW_NULL);
if (ulValue) {
- *piNRead = 1;
+ *piNRead = (INT)ulValue;
}
break;
diff --git a/SylixOS/system/device/spipe/spipe.h b/SylixOS/system/device/spipe/spipe.h
index 92ccb1c..c69e353 100644
--- a/SylixOS/system/device/spipe/spipe.h
+++ b/SylixOS/system/device/spipe/spipe.h
@@ -76,9 +76,9 @@ typedef LW_SPIPE_DEV *PLW_SPIPE_DEV;
typedef struct {
PLW_SPIPE_DEV SPIPEFIL_pspipedev;
-
INT SPIPEFIL_iFlags; /* 建立属性 */
INT SPIPEFIL_iMode; /* 操作方式 */
+ INT SPIPEFIL_iExtMode;
} LW_SPIPE_FILE;
typedef LW_SPIPE_FILE *PLW_SPIPE_FILE;
diff --git a/SylixOS/system/device/spipe/spipeLib.c b/SylixOS/system/device/spipe/spipeLib.c
index 4d4cb10..a7372af 100644
--- a/SylixOS/system/device/spipe/spipeLib.c
+++ b/SylixOS/system/device/spipe/spipeLib.c
@@ -49,6 +49,10 @@
#include "../SylixOS/system/include/s_system.h"
#include "limits.h"
/*********************************************************************************************************
+ EXT MODE
+*********************************************************************************************************/
+#define LW_SPIPE_EXT_MODE_NOSIG 0x1
+/*********************************************************************************************************
共享锁操作
*********************************************************************************************************/
#define LW_SPIPE_LOCK(pspipedev, code) \
@@ -177,7 +181,7 @@ LONG _SpipeOpen (PLW_SPIPE_DEV pspipedev,
return (PX_ERROR);
} else {
- if (iFlags & O_CREAT) {
+ if ((iFlags & O_CREAT) && (iFlags & O_EXCL)) {
_ErrorHandle(ERROR_IO_FILE_EXIST); /* 不能重复创建 */
return (PX_ERROR);
}
@@ -208,6 +212,7 @@ LONG _SpipeOpen (PLW_SPIPE_DEV pspipedev,
pspipefil->SPIPEFIL_iFlags = iFlags;
pspipefil->SPIPEFIL_iMode = iMode;
+ pspipefil->SPIPEFIL_iExtMode = 0;
pspipefil->SPIPEFIL_pspipedev = pspipedev;
if (!(iFlags & O_PEEKONLY)) {
@@ -364,14 +369,14 @@ ssize_t _SpipeRead (PLW_SPIPE_FILE pspipefil,
PLW_SPIPE_DEV pspipedev = pspipefil->SPIPEFIL_pspipedev;
- if (!pcBuffer) {
- _ErrorHandle(EINVAL);
- return (PX_ERROR);
- }
+ if (!pcBuffer) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
- if (!stMaxBytes) {
- return (0);
- }
+ if (!stMaxBytes) {
+ return (0);
+ }
if (LW_CPU_GET_CUR_NESTING()) { /* 是否在中断中调用 */
_DebugHandle(__ERRORMESSAGE_LEVEL, "called from ISR.\r\n");
@@ -383,7 +388,9 @@ ssize_t _SpipeRead (PLW_SPIPE_FILE pspipefil,
if (pspipedev->SPIPEDEV_uiWriteCnt == 0) { /* 没有写端且没有数据 */
if (pspipedev->SPIPEDEV_ringbufferBuffer.RINGBUFFER_stMsgBytes == 0) {
- return (0);
+ if (!(pspipefil->SPIPEFIL_iExtMode & LW_SPIPE_EXT_MODE_NOSIG)) {
+ return (0);
+ }
}
}
@@ -534,13 +541,14 @@ __continue_write:
if (pspipedev->SPIPEDEV_uiReadCnt == 0) { /* 没有读端 */
#if LW_CFG_SIGNAL_EN > 0
- sigevent_t sigeventPipe;
-
- sigeventPipe.sigev_signo = SIGPIPE;
- sigeventPipe.sigev_value.sival_ptr = LW_NULL;
- sigeventPipe.sigev_notify = SIGEV_SIGNAL;
-
- _doSigEvent(API_ThreadIdSelf(), &sigeventPipe, SI_MESGQ); /* 产生 SIGPIPE 信号 */
+ if (!(pspipefil->SPIPEFIL_iExtMode & LW_SPIPE_EXT_MODE_NOSIG)) {
+ sigevent_t sigeventPipe;
+
+ sigeventPipe.sigev_signo = SIGPIPE;
+ sigeventPipe.sigev_value.sival_ptr = LW_NULL;
+ sigeventPipe.sigev_notify = SIGEV_SIGNAL;
+ _doSigEvent(API_ThreadIdSelf(), &sigeventPipe, SI_MESGQ); /* 产生 SIGPIPE 信号 */
+ }
#endif /* LW_CFG_SIGNAL_EN > 0 */
_ErrorHandle(EPIPE);
return (PX_ERROR);
@@ -549,6 +557,7 @@ __continue_write:
if (pspipefil->SPIPEFIL_iFlags & O_NONBLOCK) { /* 非阻塞 IO */
ulTimeout = LW_OPTION_NOT_WAIT;
bNonblock = LW_TRUE;
+
} else {
ulTimeout = pspipedev->SPIPEDEV_ulWTimeout;
bNonblock = LW_FALSE;
@@ -849,6 +858,16 @@ INT _SpipeIoctl (PLW_SPIPE_FILE pspipefil,
LW_SPIPE_UNLOCK(pspipedev);
break;
+ case FIOPIPENOSIG: /* 不需要信号 */
+ LW_SPIPE_LOCK(pspipedev, return (PX_ERROR));
+ if ((INT)piArgPtr) {
+ pspipefil->SPIPEFIL_iExtMode |= LW_SPIPE_EXT_MODE_NOSIG;
+ } else {
+ pspipefil->SPIPEFIL_iExtMode &= ~LW_SPIPE_EXT_MODE_NOSIG;
+ }
+ LW_SPIPE_UNLOCK(pspipedev);
+ break;
+
default:
iErrCode = PX_ERROR;
_ErrorHandle(ERROR_IO_UNKNOWN_REQUEST);
diff --git a/SylixOS/system/include/s_option.h b/SylixOS/system/include/s_option.h
index fc9d68b..0b4b0a8 100644
--- a/SylixOS/system/include/s_option.h
+++ b/SylixOS/system/include/s_option.h
@@ -98,6 +98,7 @@
#ifdef __SYLIXOS_KERNEL /* ONLY pipe() can use this! */
#define FIOPIPEBLOCK LW_OSIO( 'f', 15) /* block until events happen */
#define FIOPIPERDONLY LW_OSIO( 'f', 18) /* make pipe rdwr fd to rdonly */
+#define FIOPIPENOSIG LW_OSIOD('f', 40, INT) /* no write broken pipe raise signal */
#endif
#define FIOGETOPTIONS LW_OSIOR('f', 19, INT) /* get options */
diff --git a/SylixOS/system/ioLib/ioInterface.c b/SylixOS/system/ioLib/ioInterface.c
index 4dae6d9..f5b2948 100644
--- a/SylixOS/system/ioLib/ioInterface.c
+++ b/SylixOS/system/ioLib/ioInterface.c
@@ -276,7 +276,7 @@ __error_handle:
** 函数名称: mknod
** 功能描述: create a new file named by the pathname to which the argument path points.
** 输 入 : pcFifoName 目录名
-** mode 方式 (目前未使用)
+** mode 类型
** dev 目前未使用
** 输 出 : ERROR_NONE 没有错误
** 其他值表示错误
diff --git a/SylixOS/system/signal/signalLib.c b/SylixOS/system/signal/signalLib.c
index 1e010fb..38d4d3e 100644
--- a/SylixOS/system/signal/signalLib.c
+++ b/SylixOS/system/signal/signalLib.c
@@ -170,11 +170,13 @@ static VOID __signalExitHandle (PLW_CLASS_TCB ptcbCur, INT iSigNo, struct sig
#endif /* LW_CFG_MODULELOADER_EN > 0 */
_exit(psiginfo->si_int);
+#if LW_CFG_MODULELOADER_EN > 0
} else if (iSigNo != SIGTERM) { /* 仅删除当前线程 */
if (pid > 0 && vprocIsMainThread()) {
vprocExitModeSet(pid, LW_VPROC_EXIT_FORCE); /* 强制进程退出 */
vprocSetImmediatelyTerm(pid); /* 立即退出模式 */
}
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
}
/* 删除自己 */
API_ThreadDelete(&ulId, (PVOID)psiginfo->si_int); /* 如果在安全模式, 则退出安全 */
diff --git a/SylixOS/vpmpdm/dlmalloc/dl_malloc.c b/SylixOS/vpmpdm/dlmalloc/dl_malloc.c
index a8fbb9e..3f8944d 100644
--- a/SylixOS/vpmpdm/dlmalloc/dl_malloc.c
+++ b/SylixOS/vpmpdm/dlmalloc/dl_malloc.c
@@ -83,10 +83,15 @@ void *dlmalloc_mmap (size_t stLen)
{
void *mem;
+#ifdef MAP_PREALLOC
+ mem = mmap(NULL, stLen, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_PREALLOC, -1, 0);
+
+#else
mem = mmap(NULL, stLen, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (mem != MAP_FAILED) {
__vp_pre_alloc_phy(mem, stLen, 1);
}
+#endif
return (mem);
}
@@ -97,7 +102,12 @@ void *dlmalloc_mmap (size_t stLen)
void *dlmalloc_mremap (void *pvAddr, size_t stOldSize, size_t stNewSize, int mv)
{
void *mem;
- int flag = 0;
+
+#ifdef MAP_PREALLOC
+ mem = MAP_FAILED;
+
+#else
+ int flag = 0;
if (mv) {
flag = MREMAP_MAYMOVE;
@@ -107,10 +117,21 @@ void *dlmalloc_mremap (void *pvAddr, size_t stOldSize, size_t stNewSize, int mv
if (mem != MAP_FAILED) {
__vp_pre_alloc_phy(mem, stNewSize, 1);
}
+#endif
return (mem);
}
/*
+ * dlmalloc_abort
+ */
+void dlmalloc_abort (void)
+{
+ fprintf(stderr, "dlmalloc abort!\n");
+ API_BacktraceShow(STD_ERR, 100);
+ lib_abort();
+}
+
+/*
* end
*/
diff --git a/SylixOS/vpmpdm/dlmalloc/dlmalloc.c b/SylixOS/vpmpdm/dlmalloc/dlmalloc.c
index 38084c0..9fcba24 100644
--- a/SylixOS/vpmpdm/dlmalloc/dlmalloc.c
+++ b/SylixOS/vpmpdm/dlmalloc/dlmalloc.c
@@ -521,6 +521,7 @@ MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP
improvement at the expense of carrying around more memory.
*/
+#define __SYLIXOS_EXTEND
#include "dlmalloc.h"
/* Version identifier to allow people to support multiple versions */
@@ -1644,7 +1645,7 @@ unsigned char _BitScanReverse(unsigned long *index, unsigned long mask);
#define MAP_ANONYMOUS MAP_ANON
#endif /* MAP_ANON */
#ifdef MAP_ANONYMOUS
-#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS)
+#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS|MAP_PREALLOC) /* SylixOS Add 'MAP_PREALLOC' */
#define MMAP_DEFAULT(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0)
#else /* MAP_ANONYMOUS */
/*
diff --git a/SylixOS/vpmpdm/dlmalloc/dlmalloc.h b/SylixOS/vpmpdm/dlmalloc/dlmalloc.h
index 2b34896..012f880 100644
--- a/SylixOS/vpmpdm/dlmalloc/dlmalloc.h
+++ b/SylixOS/vpmpdm/dlmalloc/dlmalloc.h
@@ -36,6 +36,7 @@
void *dlmalloc_sbrk(int size);
void *dlmalloc_mmap(size_t stLen);
void *dlmalloc_mremap(void *pvAddr, size_t stOldSize, size_t stNewSize, int mv);
+void dlmalloc_abort(void);
/* use dl prefix */
#define USE_DL_PREFIX 1
@@ -58,9 +59,12 @@ void *dlmalloc_mremap(void *pvAddr, size_t stOldSize, size_t stNewSize, int mv);
#define DIRECT_MMAP dlmalloc_mmap
#define MREMAP dlmalloc_mremap
-#define DEFAULT_MMAP_THRESHOLD (256 * 1024) /* 256K */
+#define DEFAULT_MMAP_THRESHOLD (128 * 1024) /* 128K */
#endif /* LW_CFG_VMM_EN > 0 */
+/* Abort */
+#define ABORT dlmalloc_abort()
+
/* Use some mutex locks */
#define USE_LOCKS 1
#define USE_SPIN_LOCKS 0
diff --git a/SylixOS/vpmpdm/vpmpdm.c b/SylixOS/vpmpdm/vpmpdm.c
index 33993da..82fd5c9 100644
--- a/SylixOS/vpmpdm/vpmpdm.c
+++ b/SylixOS/vpmpdm/vpmpdm.c
@@ -58,7 +58,7 @@
#include "./loader/include/loader_lib.h" /* need __eabi */
#endif /* LW_CFG_CPU_ARCH_PPC */
-#define __VP_PATCH_VERSION "2.1.3" /* vp patch version */
+#define __VP_PATCH_VERSION "2.1.5" /* vp patch version */
/*
* fixed gcc old version.
diff --git a/libsylixos.mk b/libsylixos.mk
index df073a5..026c5cf 100644
--- a/libsylixos.mk
+++ b/libsylixos.mk
@@ -632,6 +632,10 @@ SylixOS/arch/csky/common/cskyExcAsm.S \
SylixOS/arch/csky/common/cskyIo.c \
SylixOS/arch/csky/common/cskyLib.c \
SylixOS/arch/csky/common/cskyLibAsm.S \
+SylixOS/arch/csky/common/ck803/cskyContextCK803.c \
+SylixOS/arch/csky/common/ck803/cskyContextCK803Asm.S \
+SylixOS/arch/csky/common/ck803/cskyExcCK803.c \
+SylixOS/arch/csky/common/ck803/cskyExcCK803Asm.S \
SylixOS/arch/csky/common/unaligned/cskyUnaligned.c \
SylixOS/arch/csky/dbg/cskyDbg.c \
SylixOS/arch/csky/dbg/cskyGdb.c \
@@ -643,9 +647,12 @@ SylixOS/arch/csky/fpu/vfpnone/cskyVfpNone.c \
SylixOS/arch/csky/mm/cskyCache.c \
SylixOS/arch/csky/mm/cache/cskyCache.c \
SylixOS/arch/csky/mm/cache/cskyCacheAsm.S \
+SylixOS/arch/csky/mm/cache/ck803/cskyCacheCK803.c \
SylixOS/arch/csky/mm/cskyMmu.c \
SylixOS/arch/csky/mm/mmu/cskyMmu.c \
SylixOS/arch/csky/mm/mmu/cskyMmuAsm.S \
+SylixOS/arch/csky/mm/cskyMpu.c \
+SylixOS/arch/csky/mm/mpu/cskyMpu.c \
SylixOS/arch/csky/mpcore/cskyMpCoreAsm.S \
SylixOS/arch/csky/mpcore/cskySpinlock.c \
SylixOS/arch/csky/param/cskyParam.c
@@ -1388,6 +1395,7 @@ SylixOS/loader/src/loader_symbol.c \
SylixOS/loader/src/loader_vpdebug.c \
SylixOS/loader/src/loader_vppatch.c \
SylixOS/loader/src/loader_vpstack.c \
+SylixOS/loader/src/loader_vpstat.c \
SylixOS/loader/src/loader_vpthread.c \
SylixOS/loader/src/loader_vptimer.c \
SylixOS/loader/src/loader_wait.c