summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2021-08-13 07:35:34 (GMT)
committer Hanhui <hanhui@acoinfo.com>2021-08-13 07:35:34 (GMT)
commit6d34953aa6bd99aba841e826daedcd36a92207e8 (patch)
tree0af6907f5f240a5f81d78b24ad72c67985a40a50
parent5fd9d4140b9dca60d95ef1249c4f562a5541ce8e (diff)
downloadlibsylixos-6d34953aa6bd99aba841e826daedcd36a92207e8.zip
libsylixos-6d34953aa6bd99aba841e826daedcd36a92207e8.tar.gz
libsylixos-6d34953aa6bd99aba841e826daedcd36a92207e8.tar.bz2
Add GPT partition management support and improve the safety and efficiency of SD bus framework.
-rw-r--r--SylixOS/arch/arm64/common/arm64Exc.c6
-rw-r--r--SylixOS/arch/arm64/mm/cache/arm64Cache.c2
-rw-r--r--SylixOS/arch/arm64/mm/mmu/arm64Mmu64K.c40
-rw-r--r--SylixOS/arch/csky/common/cskyContextAsm.S14
-rw-r--r--SylixOS/arch/csky/common/cskyExc.c87
-rw-r--r--SylixOS/arch/csky/common/cskyExcAsm.S96
-rw-r--r--SylixOS/arch/csky/common/cskyLibAsm.S20
-rw-r--r--SylixOS/arch/csky/csky_io.h86
-rw-r--r--SylixOS/arch/csky/csky_support.h17
-rw-r--r--SylixOS/arch/csky/param/cskyParam.c9
-rw-r--r--SylixOS/arch/csky/param/cskyParam.h1
-rw-r--r--SylixOS/arch/mips/common/mipsCpuProbe.c8
-rw-r--r--SylixOS/arch/mips/common/mipsIo32.c22
-rw-r--r--SylixOS/arch/mips/common/mipsIo64.c22
-rw-r--r--SylixOS/arch/mips/mips_io.h2
-rw-r--r--SylixOS/arch/mips/mips_support.h4
-rw-r--r--SylixOS/arch/mips/mm/cache/mipsCacheCommon.c42
-rw-r--r--SylixOS/arch/mips/mm/cache/r4k/mipsCacheR4k.c47
-rw-r--r--SylixOS/arch/mips/mm/mipsCache.c8
-rw-r--r--SylixOS/arch/mips/mm/mmu/mips32/mips32Mmu.c2
-rw-r--r--SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c16
-rw-r--r--SylixOS/arch/x86/bsp/bspLib.c2
-rw-r--r--SylixOS/arch/x86/common/x64/x64Context.c2
-rw-r--r--SylixOS/arch/x86/common/x64/x64IoAsm.S8
-rw-r--r--SylixOS/arch/x86/common/x86Gdt.c10
-rw-r--r--SylixOS/config/system/system_cfg.h2
-rw-r--r--SylixOS/debug/dtrace/dtrace.c4
-rw-r--r--SylixOS/devtree/devtree.h2
-rw-r--r--SylixOS/devtree/devtreeDev.c27
-rw-r--r--SylixOS/driver/can/sja1000.c3
-rw-r--r--SylixOS/driver/sio/16c550.c17
-rw-r--r--SylixOS/fs/diskCache/diskCache.c2
-rw-r--r--SylixOS/fs/diskPartition/diskPartition.c81
-rw-r--r--SylixOS/fs/diskPartition/diskPartition.h1
-rw-r--r--SylixOS/fs/diskPartition/gptPartition.c655
-rw-r--r--SylixOS/fs/diskPartition/gptPartition.h115
-rw-r--r--SylixOS/fs/fatFs/fatFs.c15
-rw-r--r--SylixOS/fs/include/fs_fs.h3
-rw-r--r--SylixOS/fs/oemDisk/oemDisk.c3
-rw-r--r--SylixOS/fs/oemDisk/oemFdisk.c241
-rw-r--r--SylixOS/fs/oemDisk/oemFdisk.h8
-rw-r--r--SylixOS/fs/rootFs/rootFsLib.c2
-rw-r--r--SylixOS/fs/tpsFs/tpsfs.c2
-rw-r--r--SylixOS/fs/tpsFs/tpsfs_sylixos.c220
-rw-r--r--SylixOS/include/arch/mips/inc/cpu.h5
-rw-r--r--SylixOS/kernel/cache/cache.c2
-rw-r--r--SylixOS/kernel/core/_CandTable.c2
-rw-r--r--SylixOS/kernel/core/_EventQueue.c2
-rw-r--r--SylixOS/kernel/core/_HeapLib.c4
-rw-r--r--SylixOS/kernel/core/_KernelHighLevelInit.c18
-rw-r--r--SylixOS/kernel/core/_Object.c2
-rw-r--r--SylixOS/kernel/core/_ThreadInit.c8
-rw-r--r--SylixOS/kernel/core/_WakeupLine.c2
-rw-r--r--SylixOS/kernel/include/k_class.h24
-rw-r--r--SylixOS/kernel/include/k_cpu.h12
-rw-r--r--SylixOS/kernel/include/k_globalvar.h9
-rw-r--r--SylixOS/kernel/include/k_kernel.h4
-rw-r--r--SylixOS/kernel/include/k_timecvt.h2
-rw-r--r--SylixOS/kernel/inline/inlObject.h2
-rw-r--r--SylixOS/kernel/interface/InterEnterExit.c62
-rw-r--r--SylixOS/kernel/interface/KernelDsp.c14
-rw-r--r--SylixOS/kernel/interface/KernelFpu.c16
-rw-r--r--SylixOS/kernel/interface/TimeSleep.c13
-rw-r--r--SylixOS/kernel/interface/TimerCancel.c2
-rw-r--r--SylixOS/kernel/resource/resourceLib.c2
-rw-r--r--SylixOS/kernel/vmm/pageTable.h16
-rw-r--r--SylixOS/kernel/vmm/phyPage.c2
-rw-r--r--SylixOS/kernel/vmm/vmmAbort.c2
-rw-r--r--SylixOS/kernel/vmm/vmmMalloc.c6
-rw-r--r--SylixOS/kernel/vmm/vmmMmap.c6
-rw-r--r--SylixOS/kernel/vmm/vmmStack.c2
-rw-r--r--SylixOS/lib/libc/stdio/popen.c15
-rw-r--r--SylixOS/lib/libc/time/lib_clock.c16
-rw-r--r--SylixOS/loader/src/loader_vppatch.c18
-rw-r--r--SylixOS/mktemp/mkdemo/bsp/SylixOS/bsp/bspLib.c2
-rw-r--r--SylixOS/net/lwip/tools/hosttable/lwip_hosttable.c4
-rw-r--r--SylixOS/posix/mman/mman.c22
-rw-r--r--SylixOS/posix/pthread/pthread_attr.c6
-rw-r--r--SylixOS/posix/resource/resource.c2
-rw-r--r--SylixOS/posix/sched/sched.c2
-rw-r--r--SylixOS/posix/spawn/spawn.c2
-rw-r--r--SylixOS/posix/sysconf/sysconf.c2
-rw-r--r--SylixOS/posix/syslog/syslog.c12
-rw-r--r--SylixOS/shell/fsLib/ttinyShellFsCmd.c61
-rw-r--r--SylixOS/shell/heapLib/ttinyShellHeapCmd.c10
-rw-r--r--SylixOS/shell/ttinyShell/ttinyShell.c4
-rw-r--r--SylixOS/shell/ttinyShell/ttinyShellSysCmd.c4
-rw-r--r--SylixOS/system/device/ahci/ahci.c4
-rw-r--r--SylixOS/system/device/sdcard/client/sdiobaseDrv.c72
-rw-r--r--SylixOS/system/device/sdcard/client/sdmemory.c62
-rw-r--r--SylixOS/system/device/sdcard/core/sdcore.h5
-rw-r--r--SylixOS/system/device/sdcard/core/sdcoreLib.c15
-rw-r--r--SylixOS/system/device/sdcard/core/sddrvm.c32
-rw-r--r--SylixOS/system/device/sdcard/core/sddrvm.h1
-rw-r--r--SylixOS/system/device/sdcard/host/sdhci.c425
-rw-r--r--SylixOS/system/device/sdcard/host/sdhci.h71
-rw-r--r--SylixOS/system/device/shm/shm.c35
-rw-r--r--SylixOS/system/device/spipe/spipeLib.c5
-rw-r--r--SylixOS/system/device/ty/tyLib.c5
-rw-r--r--SylixOS/system/ioLib/ioInterface.c1
-rw-r--r--SylixOS/system/ioLib/ioPath.c8
-rw-r--r--SylixOS/system/ptimer/ptimer.c14
-rw-r--r--SylixOS/system/select/select.h4
-rw-r--r--SylixOS/system/signal/signal.c8
-rw-r--r--SylixOS/system/signal/signalLib.c4
-rw-r--r--SylixOS/vpmpdm/vpmpdm_start.c1
-rw-r--r--libsylixos.mk1
107 files changed, 2502 insertions, 670 deletions
diff --git a/SylixOS/arch/arm64/common/arm64Exc.c b/SylixOS/arch/arm64/common/arm64Exc.c
index bfc8839..6865a9c 100644
--- a/SylixOS/arch/arm64/common/arm64Exc.c
+++ b/SylixOS/arch/arm64/common/arm64Exc.c
@@ -217,9 +217,9 @@ VOID archSyncExcHandle (ARCH_REG_CTX *pregctx, UINT32 uiExcType)
case EXC_SVC_AARCH64:
case EXC_HVC_AARCH64:
case EXC_SMC_AARCH64:
- abtInfo.VMABT_uiMethod = LW_VMM_ABORT_METHOD_EXEC;
- abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_SYS; /* 系统调用错误 */
- break;
+ abtInfo.VMABT_uiMethod = LW_VMM_ABORT_METHOD_EXEC;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_SYS; /* 系统调用错误 */
+ break;
case EXC_INSTRUCTION_ABORT_LO:
case EXC_INSTRUCTION_ABORT:
diff --git a/SylixOS/arch/arm64/mm/cache/arm64Cache.c b/SylixOS/arch/arm64/mm/cache/arm64Cache.c
index ea905da..fa758df 100644
--- a/SylixOS/arch/arm64/mm/cache/arm64Cache.c
+++ b/SylixOS/arch/arm64/mm/cache/arm64Cache.c
@@ -519,7 +519,7 @@ VOID arm64CacheInit (LW_CACHE_OP *pcacheop,
#endif /* LW_CFG_VMM_EN > 0 */
}
/*********************************************************************************************************
-** 函数名称: archCacheV8Reset
+** 函数名称: arm64CacheReset
** 功能描述: 复位 CACHE
** 输 入 : pcMachineName 机器名称
** 输 出 : NONE
diff --git a/SylixOS/arch/arm64/mm/mmu/arm64Mmu64K.c b/SylixOS/arch/arm64/mm/mmu/arm64Mmu64K.c
index 74f583c..75ff035 100644
--- a/SylixOS/arch/arm64/mm/mmu/arm64Mmu64K.c
+++ b/SylixOS/arch/arm64/mm/mmu/arm64Mmu64K.c
@@ -770,27 +770,27 @@ static ULONG arm64MmuFlagGet (PLW_MMU_CONTEXT pmmuctx, addr_t ulAddr)
LW_PMD_TRANSENTRY *p_pmdentry = arm64MmuPmdOffset((LW_PMD_TRANSENTRY *)p_pgdentry,
ulAddr); /* 获取二级描述符 */
if (arm64MmuPmdIsOk(*p_pmdentry)) {
- LW_PTE_TRANSENTRY *p_pteentry = arm64MmuPteOffset((LW_PTE_TRANSENTRY *)p_pmdentry,
- ulAddr);
+ LW_PTE_TRANSENTRY *p_pteentry = arm64MmuPteOffset((LW_PTE_TRANSENTRY *)p_pmdentry,
+ ulAddr);
/* 获取三级描述符 */
- if (arm64MmuPteIsOk(*p_pteentry)) {
- UINT64 u64Descriptor = (UINT64)(*p_pteentry);
-
- ucGuard = (UINT8)((u64Descriptor & ARM64_PTE_GUARD_MASK) >> ARM64_PTE_GUARD_SHIFT);
- ucXN = (UINT8)((u64Descriptor & ARM64_PTE_UXN_MASK) >> ARM64_PTE_UXN_SHIFT);
- ucPXN = (UINT8)((u64Descriptor & ARM64_PTE_PXN_MASK) >> ARM64_PTE_PXN_SHIFT);
- ucCon = (UINT8)((u64Descriptor & ARM64_PTE_CONT_MASK) >> ARM64_PTE_CONT_SHIFT);
- ucnG = (UINT8)((u64Descriptor & ARM64_PTE_NG_MASK) >> ARM64_PTE_NG_SHIFT);
- ucAF = (UINT8)((u64Descriptor & ARM64_PTE_AF_MASK) >> ARM64_PTE_AF_SHIFT);
- ucSH = (UINT8)((u64Descriptor & ARM64_PTE_SH_MASK) >> ARM64_PTE_SH_SHIFT);
- ucAP = (UINT8)((u64Descriptor & ARM64_PTE_AP_MASK) >> ARM64_PTE_AP_SHIFT);
- ucNS = (UINT8)((u64Descriptor & ARM64_PTE_NS_MASK) >> ARM64_PTE_NS_SHIFT);
- ucAIn = (UINT8)((u64Descriptor & ARM64_PTE_AIN_MASK) >> ARM64_PTE_AIN_SHIFT);
-
- arm64MmuAttr2Flags(ucGuard, ucXN, ucPXN, ucCon, ucnG,
- ucAF, ucSH, ucAP, ucNS, ucAIn, &ulFlag);
-
- return (ulFlag);
+ if (arm64MmuPteIsOk(*p_pteentry)) {
+ UINT64 u64Descriptor = (UINT64)(*p_pteentry);
+
+ ucGuard = (UINT8)((u64Descriptor & ARM64_PTE_GUARD_MASK) >> ARM64_PTE_GUARD_SHIFT);
+ ucXN = (UINT8)((u64Descriptor & ARM64_PTE_UXN_MASK) >> ARM64_PTE_UXN_SHIFT);
+ ucPXN = (UINT8)((u64Descriptor & ARM64_PTE_PXN_MASK) >> ARM64_PTE_PXN_SHIFT);
+ ucCon = (UINT8)((u64Descriptor & ARM64_PTE_CONT_MASK) >> ARM64_PTE_CONT_SHIFT);
+ ucnG = (UINT8)((u64Descriptor & ARM64_PTE_NG_MASK) >> ARM64_PTE_NG_SHIFT);
+ ucAF = (UINT8)((u64Descriptor & ARM64_PTE_AF_MASK) >> ARM64_PTE_AF_SHIFT);
+ ucSH = (UINT8)((u64Descriptor & ARM64_PTE_SH_MASK) >> ARM64_PTE_SH_SHIFT);
+ ucAP = (UINT8)((u64Descriptor & ARM64_PTE_AP_MASK) >> ARM64_PTE_AP_SHIFT);
+ ucNS = (UINT8)((u64Descriptor & ARM64_PTE_NS_MASK) >> ARM64_PTE_NS_SHIFT);
+ ucAIn = (UINT8)((u64Descriptor & ARM64_PTE_AIN_MASK) >> ARM64_PTE_AIN_SHIFT);
+
+ arm64MmuAttr2Flags(ucGuard, ucXN, ucPXN, ucCon, ucnG,
+ ucAF, ucSH, ucAP, ucNS, ucAIn, &ulFlag);
+
+ return (ulFlag);
}
}
}
diff --git a/SylixOS/arch/csky/common/cskyContextAsm.S b/SylixOS/arch/csky/common/cskyContextAsm.S
index 1a5e9a4..0c5abbf 100644
--- a/SylixOS/arch/csky/common/cskyContextAsm.S
+++ b/SylixOS/arch/csky/common/cskyContextAsm.S
@@ -48,7 +48,6 @@
EXPORT_LABEL(archCrtCtxSwitch)
#endif
EXPORT_LABEL(archIntCtxLoad)
- EXPORT_LABEL(archFastIntCtxLoad)
EXPORT_LABEL(archSigCtxLoad)
;/*********************************************************************************************************
@@ -57,7 +56,7 @@
;*********************************************************************************************************/
FUNC_DEF(archTaskCtxStart)
- SUBI SP , 1024 ;/* 在启动栈开辟异常临时栈 */
+ SUBI SP , 2048 ;/* 在启动栈开辟异常临时栈 */
ANDNI SP , SP , 0x7 ;/* SP 向下 8 字节对齐 */
MTCR SP , SS0 ;/* 设置异常临时栈(使用启动栈) */
@@ -124,17 +123,6 @@ FUNC_DEF(archIntCtxLoad)
FUNC_END(archIntCtxLoad)
;/*********************************************************************************************************
-; 快速中断返回时, 线程装载
-; 参数为当前 CPU 控制块, 即 A0 为当前 CPU 控制块指针
-;*********************************************************************************************************/
-
-FUNC_DEF(archFastIntCtxLoad)
- LD.W A1 , (A0 , 0) ;/* 获取当前 TCB 的 REG_CTX 地址*/
-
- RESTORE_REGS_FAST_INT ;/* 恢复任务寄存器 */
- FUNC_END(archFastIntCtxLoad)
-
-;/*********************************************************************************************************
; 信号上下文返回
; 参数为 ARCH_REG_CTX 指针, 即 A0 为 ARCH_REG_CTX 指针
;*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/common/cskyExc.c b/SylixOS/arch/csky/common/cskyExc.c
index 82234e7..3358e83 100644
--- a/SylixOS/arch/csky/common/cskyExc.c
+++ b/SylixOS/arch/csky/common/cskyExc.c
@@ -32,6 +32,10 @@
#include "arch/csky/fpu/fpu/cskyVfp.h"
#endif
/*********************************************************************************************************
+ 异常向量表
+*********************************************************************************************************/
+extern ULONG vector[];
+/*********************************************************************************************************
C-SKY 体系架构
*********************************************************************************************************/
#if !defined(__SYLIXOS_CSKY_ARCH_CK803__)
@@ -103,17 +107,55 @@ LW_WEAK VOID bspFastIntHandle (ULONG ulVector)
{
}
/*********************************************************************************************************
+** 函数名称: archFastVectorIntHandle
+** 功能描述: 快速向量中断
+** 输 入 : ulVector 中断向量
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archFastVectorIntHandle (ULONG ulVector)
+{
+ PLW_CLASS_CPU pcpu;
+
+ pcpu = LW_CPU_GET_CUR();
+ pcpu->CPU_ulInterNesting++;
+
+ bspFastIntHandle(ulVector);
+
+ pcpu->CPU_ulInterNesting--;
+}
+/*********************************************************************************************************
** 函数名称: archFastAutoIntHandle
-** 功能描述: 快速中断
+** 功能描述: 快速自动中断
+** 输 入 : ulVector 中断向量
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archFastAutoIntHandle (ULONG ulVector)
+{
+ PLW_CLASS_CPU pcpu;
+
+ pcpu = LW_CPU_GET_CUR();
+ pcpu->CPU_ulInterNesting++;
+
+ bspFastIntHandle(VEC_FAUTOVEC);
+
+ pcpu->CPU_ulInterNesting--;
+}
+/*********************************************************************************************************
+** 函数名称: archVectorIntHandle
+** 功能描述: 普通向量中断
** 输 入 : ulVector 中断向量
** pregctx 上下文
** 输 出 : NONE
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-VOID archFastAutoIntHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
+VOID archVectorIntHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
{
- bspFastIntHandle(ulVector);
+ bspIntHandle(ulVector);
}
/*********************************************************************************************************
** 函数名称: archAutoIntHandle
@@ -126,7 +168,44 @@ VOID archFastAutoIntHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
*********************************************************************************************************/
VOID archAutoIntHandle (ULONG ulVector, ARCH_REG_CTX *pregctx)
{
- bspIntHandle(ulVector);
+ bspIntHandle(VEC_AUTOVEC);
+}
+/*********************************************************************************************************
+** 函数名称: archFastVectorIntClaim
+** 功能描述: 设置中断向量为快速中断
+** 快速中断向量号由硬件决定,当外设使用向量化的中断时,需调用此函数将目标中断向量声明为快速中断
+** 输 入 : ulVector 中断向量号
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT archFastVectorIntClaim (ULONG ulVector)
+{
+ CSKY_PARAM *param = archKernelParamGet();
+
+ if ((ulVector < VEC_USER) || (ulVector > VEC_MAX)) {
+ return (PX_ERROR);
+ }
+
+ if (param->CP_bAPGR) {
+ vector[ulVector] = ((ULONG)archFastVectorIntRawEntry) | 1;
+ } else {
+ vector[ulVector] = ((ULONG)archFastVectorIntEntry);
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: archFastAutoIntEntrySet
+** 功能描述: 设置系统快速自动中断处理服务函数
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID archFastAutoIntEntrySet (VOID)
+{
+ vector[VEC_FAUTOVEC] = ((ULONG)archFastAutoIntEntry);
}
/*********************************************************************************************************
** 函数名称: archTlbLoadExceptHandle
diff --git a/SylixOS/arch/csky/common/cskyExcAsm.S b/SylixOS/arch/csky/common/cskyExcAsm.S
index f6fd095..870c484 100644
--- a/SylixOS/arch/csky/common/cskyExcAsm.S
+++ b/SylixOS/arch/csky/common/cskyExcAsm.S
@@ -50,7 +50,9 @@
IMPORT_LABEL(archFatalErrExceptHandle)
IMPORT_LABEL(archIdlyExceptHandle)
IMPORT_LABEL(archAutoIntHandle)
+ IMPORT_LABEL(archVectorIntHandle)
IMPORT_LABEL(archFastAutoIntHandle)
+ IMPORT_LABEL(archFastVectorIntHandle)
IMPORT_LABEL(archReservedExceptHandle)
IMPORT_LABEL(archTlbFatalExceptHandle)
IMPORT_LABEL(archTlbModExceptHandle)
@@ -78,7 +80,10 @@
EXPORT_LABEL(archFatalErrExceptEntry)
EXPORT_LABEL(archIdlyExceptEntry)
EXPORT_LABEL(archAutoIntEntry)
+ EXPORT_LABEL(archFastAutoIntRawEntry)
EXPORT_LABEL(archFastAutoIntEntry)
+ EXPORT_LABEL(archFastVectorIntRawEntry)
+ EXPORT_LABEL(archFastVectorIntEntry)
EXPORT_LABEL(archReservedExceptEntry)
EXPORT_LABEL(archTlbFatalExceptEntry)
EXPORT_LABEL(archTlbModExceptEntry)
@@ -104,6 +109,8 @@
SECTION(.text)
MACRO_DEF(IRQ_ENTRY irq handle)
+ PSRCLR FE ;/* 防止在保存 SP 时被 FIQ 打断 */
+
;/*
; * 使用异常临时栈, 并在异常临时栈开辟临时上下文保存区, 将寄存器保存到临时上下文保存区
; */
@@ -142,6 +149,8 @@ MACRO_DEF(IRQ_ENTRY irq handle)
MOV A0 , SP
JSRI API_InterEnter
+ PSRSET FE ;/* 使能 FIQ */
+
CMPNEI A0 , 1
BT 3f
@@ -195,6 +204,7 @@ MACRO_DEF(IRQ_ENTRY irq handle)
MACRO_DEF(FAST_INT_ENTRY handle)
MTCR SP , SS1 ;/* SS1 暂存异常前 SP */
MFCR SP , SS0 ;/* SP = 异常临时栈 */
+ ADDI SP , 1024 ;/* SP = FIQ 临时栈 */
SUBI SP , ARCH_REG_CTX_SIZE ;/* 在临时堆栈开辟上下文保存区 */
@@ -222,53 +232,18 @@ MACRO_DEF(FAST_INT_ENTRY handle)
ST.W R18 , (SP , XGREG(0))
#endif
- ;/*
- ; * API_InterEnter(寄存器上下文)
- ; */
- MOV A0 , SP
- JSRI API_InterEnter
-
- CMPNEI A0 , 1
- BT 3f
+ MFCR R0 , PSR
+ LSRI R0 , 16
+ SEXTB R0 ;/* R0 = 异常向量号 */
;/*
- ; * 第一次进入中断: 获得当前 CPU 中断堆栈栈顶, 并设置 SP
- ; */
- JSRI API_InterStackBaseGet
- MOV SP , A0
-
- ;/*
- ; * 获得当前任务 TCB 的 ARCH_REG_CTX 地址
- ; */
- JSRI API_ThreadTcbInter
- MOV A1 , A0
-
-2:
- PSRCLR FE
- ;/*
; * handle(vector, 寄存器上下文)
; */
JSRI \handle
- ;/*
- ; * API_InterExitFastInt()
- ; * 如果没有发生中断嵌套, 则 API_InterExitFastInt 会调用 archFiqCtxLoad 函数
- ; */
- JSRI API_InterExitFastInt
- ;/*
- ; * 来到这里, 说明发生了中断嵌套
- ; */
MOV A1 , SP
RESTORE_REGS_FAST_INT
-3:
- ;/*
- ; * 不是第一次进入中断
- ; */
- MFCR SP , SS1 ;/* 异常前 SP */
- SUBI SP , ARCH_REG_CTX_SIZE
- MOV A1 , SP
- BR 2b
MACRO_END()
;/*********************************************************************************************************
@@ -344,7 +319,7 @@ FUNC_DEF(archIdlyExceptEntry)
FUNC_END(archIdlyExceptEntry)
;/*********************************************************************************************************
-; 普通中断入口函数
+; 普通自动中断入口函数
;*********************************************************************************************************/
FUNC_DEF(archAutoIntEntry)
@@ -352,7 +327,16 @@ FUNC_DEF(archAutoIntEntry)
FUNC_END(archAutoIntEntry)
;/*********************************************************************************************************
-; 快速中断入口函数
+; 快速自动中断入口函数(硬件存在可选通用寄存器, 不需要保存上下文)
+;*********************************************************************************************************/
+
+FUNC_DEF(archFastAutoIntRawEntry)
+ JSRI archFastAutoIntHandle
+ RFI
+ FUNC_END(archFastAutoIntRawEntry)
+
+;/*********************************************************************************************************
+; 快速自动中断入口函数(硬件不存在可选通用寄存器, 需要保存上下文)
;*********************************************************************************************************/
FUNC_DEF(archFastAutoIntEntry)
@@ -442,7 +426,27 @@ FUNC_DEF(archTlbStoreExceptEntry)
FUNC_END(archTlbStoreExceptEntry)
;/*********************************************************************************************************
-; 32 ~ 255 号中断入口函数
+; 快速向量中断处理入口函数(硬件存在可选通用寄存器, 不需要保存上下文)
+;*********************************************************************************************************/
+
+FUNC_DEF(archFastVectorIntRawEntry)
+ MFCR R0 , PSR
+ LSRI R0 , 16
+ SEXTB R0
+ JSRI archFastVectorIntHandle
+ RFI
+ FUNC_END(archFastVectorIntRawEntry)
+
+;/*********************************************************************************************************
+; 快速向量中断处理入口函数(硬件不存在可选通用寄存器, 需要保存上下文)
+;*********************************************************************************************************/
+
+FUNC_DEF(archFastVectorIntEntry)
+ FAST_INT_ENTRY archFastVectorIntHandle
+ FUNC_END(archFastVectorIntEntry)
+
+;/*********************************************************************************************************
+; 32 ~ 255 号普通向量中断入口函数
;*********************************************************************************************************/
.irp Id, \
@@ -471,7 +475,7 @@ FUNC_DEF(archTlbStoreExceptEntry)
250, 251, 252, 253, 254, 255
EXPORT_LABEL(archIntEntry\Id)
FUNC_DEF(archIntEntry\Id)
- IRQ_ENTRY \Id bspIntHandle
+ IRQ_ENTRY \Id archVectorIntHandle
FUNC_END(archIntEntry\Id)
.endr
@@ -479,8 +483,10 @@ FUNC_DEF(archIntEntry\Id)
; 异常向量表
;*********************************************************************************************************/
+ SECTION(.data)
+
.align 10
-FUNC_DEF(vector)
+LINE_LABEL(vector)
.long archResetEntry ;/* 0 - Reset */
.long archUnalignedExceptEntry ;/* 1 - Unaligned */
.long archAccessExceptEntry ;/* 2 - Access */
@@ -492,7 +498,7 @@ FUNC_DEF(vector)
.long archFatalErrExceptEntry ;/* 8 - Fatal Err */
.long archIdlyExceptEntry ;/* 9 - Idly */
.long archAutoIntEntry ;/* 10 - Auto */
- .long archFastAutoIntEntry + 0x1 ;/* 11 - Fast Auto */
+ .long archFastAutoIntRawEntry + 0x1 ;/* 11 - Fast Auto */
.long archReservedExceptEntry ;/* 12 - Reserved */
.long archTlbFatalExceptEntry ;/* 13 - TLB Fatal */
#if LW_CFG_VMM_EN > 0
@@ -544,8 +550,6 @@ FUNC_DEF(vector)
250, 251, 252, 253, 254, 255
.long archIntEntry\Id
.endr
- FUNC_END(vector)
-
FILE_END()
#endif
diff --git a/SylixOS/arch/csky/common/cskyLibAsm.S b/SylixOS/arch/csky/common/cskyLibAsm.S
index 8f673a2..38172a8 100644
--- a/SylixOS/arch/csky/common/cskyLibAsm.S
+++ b/SylixOS/arch/csky/common/cskyLibAsm.S
@@ -51,6 +51,8 @@
WEAK(archIntDisable)
WEAK(archIntEnable)
WEAK(archIntEnableForce)
+ WEAK(archFastIntDisable)
+ WEAK(archFastIntEnable)
;/*********************************************************************************************************
; C-SKY 获取处理器状态寄存器
@@ -93,6 +95,24 @@ FUNC_DEF(archIntEnableForce)
FUNC_END(archIntEnableForce)
;/*********************************************************************************************************
+; C-SKY 关闭快速中断
+;*********************************************************************************************************/
+
+FUNC_DEF(archFastIntDisable)
+ PSRCLR FE
+ RTS
+ FUNC_END(archFastIntDisable)
+
+;/*********************************************************************************************************
+; C-SKY 强制打开快速中断
+;*********************************************************************************************************/
+
+FUNC_DEF(archFastIntEnable)
+ PSRSET FE
+ RTS
+ FUNC_END(archFastIntEnable)
+
+;/*********************************************************************************************************
; C-SKY 前导零运算
;*********************************************************************************************************/
diff --git a/SylixOS/arch/csky/csky_io.h b/SylixOS/arch/csky/csky_io.h
index 39d3e61..95c15ec 100644
--- a/SylixOS/arch/csky/csky_io.h
+++ b/SylixOS/arch/csky/csky_io.h
@@ -77,66 +77,58 @@
#define writes64(a, b, c) writes64_raw(a, b, c)
/*********************************************************************************************************
- C-SKY 处理器 I/O 端口读
+ C-SKY 处理器 I/O 端口操作 (C-SKY 处理器没有独立 I/O 端口, 处理方法与 I/O 内存相同)
*********************************************************************************************************/
-#define in8(addr) read8(addr)
-#define in16(addr) read16(addr)
-#define in32(addr) read32(addr)
-#define in64(addr) read64(addr)
-/*********************************************************************************************************
- C-SKY 处理器 I/O 端口读 (大小端相关)
-*********************************************************************************************************/
-
-#define in8_le(a) in8(a)
-#define in16_le(a) le16toh(in16(a))
-#define in32_le(a) le32toh(in32(a))
-#define in64_le(a) le64toh(in64(a))
-
-#define in8_be(a) in8(a)
-#define in16_be(a) be16toh(in16(a))
-#define in32_be(a) be32toh(in32(a))
-#define in64_be(a) be64toh(in64(a))
+extern ioaddr_t __IO_BASE__;
/*********************************************************************************************************
- C-SKY 处理器 I/O 端口写
+ in IOPORT
*********************************************************************************************************/
-#define out8(x, addr) write8(x, addr)
-#define out16(x, addr) write16(x, addr)
-#define out32(x, addr) write32(x, addr)
-#define out64(x, addr) write64(x, addr)
-/*********************************************************************************************************
- C-SKY 处理器 I/O 端口写 (大小端相关)
-*********************************************************************************************************/
-
-#define out8_le(v, a) out8(v, a)
-#define out16_le(v, a) out16(htole16(v), a)
-#define out32_le(v, a) out32(htole32(v), a)
-#define out64_le(v, a) out64(htole64(v), a)
+#define in8(a) read8(__IO_BASE__ + a)
+#define in16(a) read16(__IO_BASE__ + a)
+#define in32(a) read32(__IO_BASE__ + a)
+#define in64(a) read64(__IO_BASE__ + a)
-#define out8_be(v, a) out8(v, a)
-#define out16_be(v, a) out16(htobe16(v), a)
-#define out32_be(v, a) out32(htobe32(v), a)
-#define out64_be(v, a) out64(htobe64(v), a)
+#define in8_le(a) read8_le(__IO_BASE__ + a)
+#define in16_le(a) read16_le(__IO_BASE__ + a)
+#define in32_le(a) read32_le(__IO_BASE__ + a)
+#define in64_le(a) read64_le(__IO_BASE__ + a)
-/*********************************************************************************************************
- C-SKY 处理器 I/O 端口连续读 (数据来自单个地址)
-*********************************************************************************************************/
+#define in8_be(a) read8_be(__IO_BASE__ + a)
+#define in16_be(a) read16_be(__IO_BASE__ + a)
+#define in32_be(a) read32_be(__IO_BASE__ + a)
+#define in64_be(a) read64_be(__IO_BASE__ + a)
-#define ins8(a, b, c) reads8(a, b, c)
-#define ins16(a, b, c) reads16(a, b, c)
-#define ins32(a, b, c) reads32(a, b, c)
-#define ins64(a, b, c) reads64(a, b, c)
+#define ins8(a, b, c) reads8(__IO_BASE__ + a, b, c)
+#define ins16(a, b, c) reads16(__IO_BASE__ + a, b, c)
+#define ins32(a, b, c) reads32(__IO_BASE__ + a, b, c)
+#define ins64(a, b, c) reads64(__IO_BASE__ + a, b, c)
/*********************************************************************************************************
- C-SKY 处理器 I/O 端口连续写 (数据写入单个地址)
+ out IOPORT
*********************************************************************************************************/
-#define outs8(a, b, c) writes8(a, b, c)
-#define outs16(a, b, c) writes16(a, b, c)
-#define outs32(a, b, c) writes32(a, b, c)
-#define outs64(a, b, c) writes64(a, b, c)
+#define out8(d, a) write8(d, __IO_BASE__ + a)
+#define out16(d, a) write16(d, __IO_BASE__ + a)
+#define out32(d, a) write32(d, __IO_BASE__ + a)
+#define out64(d, a) write64(d, __IO_BASE__ + a)
+
+#define out8_le(d, a) write8_le(d, __IO_BASE__ + a)
+#define out16_le(d, a) write16_le(d, __IO_BASE__ + a)
+#define out32_le(d, a) write32_le(d, __IO_BASE__ + a)
+#define out64_le(d, a) write64_le(d, __IO_BASE__ + a)
+
+#define out8_be(d, a) write8_be(d, __IO_BASE__ + a)
+#define out16_be(d, a) write16_be(d, __IO_BASE__ + a)
+#define out32_be(d, a) write32_be(d, __IO_BASE__ + a)
+#define out64_be(d, a) write64_be(d, __IO_BASE__ + a)
+
+#define outs8(a, b, c) writes8(__IO_BASE__ + a, b, c)
+#define outs16(a, b, c) writes16(__IO_BASE__ + a, b, c)
+#define outs32(a, b, c) writes32(__IO_BASE__ + a, b, c)
+#define outs64(a, b, c) writes64(__IO_BASE__ + a, b, c)
#endif /* __ARCH_CSKY_IO_H */
/*********************************************************************************************************
diff --git a/SylixOS/arch/csky/csky_support.h b/SylixOS/arch/csky/csky_support.h
index e0df10a..6f161de 100644
--- a/SylixOS/arch/csky/csky_support.h
+++ b/SylixOS/arch/csky/csky_support.h
@@ -88,7 +88,6 @@ VOID archCrtCtxSwitch(PLW_CLASS_CPU pcpuSw);
#endif /* LW_CFG_COROUTINE_EN > 0 */
VOID archIntCtxLoad(PLW_CLASS_CPU pcpuSw);
-VOID archFastIntCtxLoad(PLW_CLASS_CPU pcpuSw);
VOID archSigCtxLoad(const ARCH_REG_CTX *pregctx);
VOID archIntCtxSaveReg(PLW_CLASS_CPU pcpu,
@@ -139,6 +138,22 @@ INTREG archIntDisable(VOID);
VOID archIntEnable(INTREG iregInterLevel);
VOID archIntEnableForce(VOID);
+#define KN_FIQ_DISABLE() archFastIntDisable()
+#define KN_FIQ_ENABLE() archFastIntEnable()
+#define KN_FIQ_AUTO_ENTRY_SET() archFastAutoIntEntrySet()
+#define KN_FIQ_VECTOR_CLAIM(vector) archFastVectorIntClaim(vector)
+
+VOID archFastIntDisable(VOID);
+VOID archFastIntEnable(VOID);
+
+VOID archFastAutoIntEntry(VOID);
+VOID archFastAutoIntRawEntry(VOID);
+VOID archFastAutoIntEntrySet(VOID);
+
+VOID archFastVectorIntEntry(VOID);
+VOID archFastVectorIntRawEntry(VOID);
+INT archFastVectorIntClaim(ULONG ulVector);
+
VOID archPageCopy(PVOID pvTo, PVOID pvFrom);
#define KN_COPY_PAGE(to, from) archPageCopy(to, from)
diff --git a/SylixOS/arch/csky/param/cskyParam.c b/SylixOS/arch/csky/param/cskyParam.c
index 77734e7..85f9e5c 100644
--- a/SylixOS/arch/csky/param/cskyParam.c
+++ b/SylixOS/arch/csky/param/cskyParam.c
@@ -24,7 +24,7 @@
/*********************************************************************************************************
启动参数
*********************************************************************************************************/
-static CSKY_PARAM cskyParam = { LW_TRUE, LW_TRUE , LW_TRUE };
+static CSKY_PARAM cskyParam = { LW_TRUE, LW_TRUE, LW_TRUE, LW_TRUE };
/*********************************************************************************************************
** 函数名称: archKernelParam
** 功能描述: C-SKY 体系架构启动参数设置.
@@ -58,6 +58,13 @@ VOID archKernelParam (CPCHAR pcParam)
__ARCH_SPIN_BYPASS();
}
#endif /* LW_CFG_SMP_EN > 0 */
+ } else if (lib_strncmp(pcParam, "agpr=", 5) == 0) { /* 硬件是否存在可选通用寄存器 */
+ if (pcParam[5] == 'n') {
+ cskyParam.CP_bAPGR = LW_FALSE;
+ KN_FIQ_AUTO_ENTRY_SET();
+ } else {
+ cskyParam.CP_bAPGR = LW_TRUE;
+ }
}
}
/*********************************************************************************************************
diff --git a/SylixOS/arch/csky/param/cskyParam.h b/SylixOS/arch/csky/param/cskyParam.h
index ad81cbc..9e63612 100644
--- a/SylixOS/arch/csky/param/cskyParam.h
+++ b/SylixOS/arch/csky/param/cskyParam.h
@@ -30,6 +30,7 @@ typedef struct {
BOOL CP_bUnalign; /* 是否支持非对齐访问 */
BOOL CP_bMmuEnByBoot; /* BOOT 是否已经启动了 MMU */
BOOL CP_bSLDepCache; /* 自旋锁是否依赖 CACHE */
+ BOOL CP_bAPGR; /* 硬件是否存在可选通用寄存器 */
} CSKY_PARAM;
/*********************************************************************************************************
diff --git a/SylixOS/arch/mips/common/mipsCpuProbe.c b/SylixOS/arch/mips/common/mipsCpuProbe.c
index 0b1f4d0..4a3b7c6 100644
--- a/SylixOS/arch/mips/common/mipsCpuProbe.c
+++ b/SylixOS/arch/mips/common/mipsCpuProbe.c
@@ -106,6 +106,7 @@ static VOID mispCpuProbeIngenic (VOID)
switch (_G_uiMipsPridImp) {
case PRID_IMP_JZRISC:
+ case PRID_IMP_XBURST2:
_G_uiMipsCpuType = CPU_JZRISC;
break;
@@ -169,6 +170,12 @@ VOID mipsCpuProbe (CPCHAR pcMachineName)
} else if ((lib_strcmp(pcMachineName, MIPS_MACHINE_HR2) == 0)) {
_G_uiMipsMachineType = MIPS_MACHINE_TYPE_HR2;
+
+ } else if ((lib_strcmp(pcMachineName, MIPS_MACHINE_X1000) == 0)) {
+ _G_uiMipsMachineType = MIPS_MACHINE_TYPE_X1000;
+
+ } else if ((lib_strcmp(pcMachineName, MIPS_MACHINE_X2000) == 0)) {
+ _G_uiMipsMachineType = MIPS_MACHINE_TYPE_X2000;
}
_G_uiMipsProcessorId = mipsCp0PRIdRead();
@@ -192,6 +199,7 @@ VOID mipsCpuProbe (CPCHAR pcMachineName)
case PRID_COMP_INGENIC_D0:
case PRID_COMP_INGENIC_D1:
case PRID_COMP_INGENIC_E1:
+ case PRID_COMP_INGENIC_13:
mispCpuProbeIngenic();
break;
}
diff --git a/SylixOS/arch/mips/common/mipsIo32.c b/SylixOS/arch/mips/common/mipsIo32.c
index 9ccfdcb..517c3a2 100644
--- a/SylixOS/arch/mips/common/mipsIo32.c
+++ b/SylixOS/arch/mips/common/mipsIo32.c
@@ -30,9 +30,9 @@
*********************************************************************************************************/
#define __32BIT_SPACE (4ULL * LW_CFG_GB_SIZE) /* 32 位空间 */
/*********************************************************************************************************
- 全局变量
+ IO 基地址定义
*********************************************************************************************************/
-static UINT64 _G_ui64MipsIoPortBase = 0ULL; /* MIPS I/O 端口基地址 */
+LW_WEAK UINT64 __IO_BASE__ = (UINT64)0ul;
/*********************************************************************************************************
** 函数名称: archSetIoPortBase
** 功能描述: 设置 I/O 端口基地址
@@ -43,7 +43,7 @@ static UINT64 _G_ui64MipsIoPortBase = 0ULL; /* MIPS
*********************************************************************************************************/
VOID archSetIoPortBase (UINT64 ui64IoPortBase)
{
- _G_ui64MipsIoPortBase = ui64IoPortBase;
+ __IO_BASE__ = ui64IoPortBase;
}
/*********************************************************************************************************
MIPS 处理器 I/O 端口读
@@ -58,7 +58,7 @@ VOID archSetIoPortBase (UINT64 ui64IoPortBase)
*********************************************************************************************************/
UINT8 in8 (addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
UINT8 ucVal;
if (ui64Addr < __32BIT_SPACE) {
@@ -80,7 +80,7 @@ UINT8 in8 (addr_t ulAddr)
*********************************************************************************************************/
UINT16 in16 (addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
UINT16 usVal;
if (ui64Addr < __32BIT_SPACE) {
@@ -102,7 +102,7 @@ UINT16 in16 (addr_t ulAddr)
*********************************************************************************************************/
UINT32 in32 (addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
UINT32 uiVal;
if (ui64Addr < __32BIT_SPACE) {
@@ -124,7 +124,7 @@ UINT32 in32 (addr_t ulAddr)
*********************************************************************************************************/
UINT64 in64 (addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
UINT64 ui64Val;
if (ui64Addr < __32BIT_SPACE) {
@@ -150,7 +150,7 @@ UINT64 in64 (addr_t ulAddr)
*********************************************************************************************************/
VOID out8 (UINT8 ucData, addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
KN_IO_WMB();
if (ui64Addr < __32BIT_SPACE) {
@@ -170,7 +170,7 @@ VOID out8 (UINT8 ucData, addr_t ulAddr)
*********************************************************************************************************/
VOID out16 (UINT16 usData, addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
KN_IO_WMB();
if (ui64Addr < __32BIT_SPACE) {
@@ -190,7 +190,7 @@ VOID out16 (UINT16 usData, addr_t ulAddr)
*********************************************************************************************************/
VOID out32 (UINT32 uiData, addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
KN_IO_WMB();
if (ui64Addr < __32BIT_SPACE) {
@@ -210,7 +210,7 @@ VOID out32 (UINT32 uiData, addr_t ulAddr)
*********************************************************************************************************/
VOID out64 (UINT64 u64Data, addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
KN_IO_WMB();
if (ui64Addr < __32BIT_SPACE) {
diff --git a/SylixOS/arch/mips/common/mipsIo64.c b/SylixOS/arch/mips/common/mipsIo64.c
index 1eb6822..400e366 100644
--- a/SylixOS/arch/mips/common/mipsIo64.c
+++ b/SylixOS/arch/mips/common/mipsIo64.c
@@ -25,9 +25,9 @@
*********************************************************************************************************/
#if LW_CFG_CPU_WORD_LENGHT == 64
/*********************************************************************************************************
- 全局变量
+ IO 基地址定义
*********************************************************************************************************/
-static UINT64 _G_ui64MipsIoPortBase = 0ULL; /* MIPS I/O 端口基地址 */
+LW_WEAK UINT64 __IO_BASE__ = (UINT64)0ul;
/*********************************************************************************************************
** 函数名称: archSetIoPortBase
** 功能描述: 设置 I/O 端口基地址
@@ -38,7 +38,7 @@ static UINT64 _G_ui64MipsIoPortBase = 0ULL; /* MIPS
*********************************************************************************************************/
VOID archSetIoPortBase (UINT64 ui64IoPortBase)
{
- _G_ui64MipsIoPortBase = ui64IoPortBase;
+ __IO_BASE__ = ui64IoPortBase;
}
/*********************************************************************************************************
MIPS 处理器 I/O 端口读
@@ -53,7 +53,7 @@ VOID archSetIoPortBase (UINT64 ui64IoPortBase)
*********************************************************************************************************/
UINT8 in8 (addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
UINT8 ucVal;
ucVal = *(volatile UINT8 *)(addr_t)ui64Addr;
@@ -70,7 +70,7 @@ UINT8 in8 (addr_t ulAddr)
*********************************************************************************************************/
UINT16 in16 (addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
UINT16 usVal;
usVal = *(volatile UINT16 *)(addr_t)ui64Addr;
@@ -87,7 +87,7 @@ UINT16 in16 (addr_t ulAddr)
*********************************************************************************************************/
UINT32 in32 (addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
UINT32 uiVal;
uiVal = *(volatile UINT32 *)(addr_t)ui64Addr;
@@ -104,7 +104,7 @@ UINT32 in32 (addr_t ulAddr)
*********************************************************************************************************/
UINT64 in64 (addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
UINT64 ui64Val;
ui64Val = *(volatile UINT64 *)(addr_t)ui64Addr;
@@ -125,7 +125,7 @@ UINT64 in64 (addr_t ulAddr)
*********************************************************************************************************/
VOID out8 (UINT8 ucData, addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
KN_IO_WMB();
*(volatile UINT8 *)ui64Addr = ucData;
@@ -141,7 +141,7 @@ VOID out8 (UINT8 ucData, addr_t ulAddr)
*********************************************************************************************************/
VOID out16 (UINT16 usData, addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
KN_IO_WMB();
*(volatile UINT16 *)ui64Addr = usData;
@@ -157,7 +157,7 @@ VOID out16 (UINT16 usData, addr_t ulAddr)
*********************************************************************************************************/
VOID out32 (UINT32 uiData, addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
KN_IO_WMB();
*(volatile UINT32 *)ui64Addr = uiData;
@@ -173,7 +173,7 @@ VOID out32 (UINT32 uiData, addr_t ulAddr)
*********************************************************************************************************/
VOID out64 (UINT64 u64Data, addr_t ulAddr)
{
- UINT64 ui64Addr = _G_ui64MipsIoPortBase + ulAddr;
+ UINT64 ui64Addr = __IO_BASE__ + ulAddr;
KN_IO_WMB();
*(volatile UINT64 *)ui64Addr = u64Data;
diff --git a/SylixOS/arch/mips/mips_io.h b/SylixOS/arch/mips/mips_io.h
index 14af771..cd15a2d 100644
--- a/SylixOS/arch/mips/mips_io.h
+++ b/SylixOS/arch/mips/mips_io.h
@@ -83,6 +83,8 @@
MIPS 处理器设置 I/O 端口基地址
*********************************************************************************************************/
+extern UINT64 __IO_BASE__;
+
VOID archSetIoPortBase(UINT64 ui64IoPortBase);
/*********************************************************************************************************
diff --git a/SylixOS/arch/mips/mips_support.h b/SylixOS/arch/mips/mips_support.h
index ac2da34..9536dfc 100644
--- a/SylixOS/arch/mips/mips_support.h
+++ b/SylixOS/arch/mips/mips_support.h
@@ -169,6 +169,8 @@ VOID archBogoMipsLoop(ULONG ulLoop);
#define MIPS_MACHINE_LS2X "loongson2x"
#define MIPS_MACHINE_LS3X "loongson3x"
#define MIPS_MACHINE_JZ47XX "jz47xx"
+#define MIPS_MACHINE_X1000 "x1000"
+#define MIPS_MACHINE_X2000 "x2000"
#define MIPS_MACHINE_HR2 "hr2"
#define MIPS_MACHINE_TYPE_24KF 0
@@ -176,6 +178,8 @@ VOID archBogoMipsLoop(ULONG ulLoop);
#define MIPS_MACHINE_TYPE_LS2X 20
#define MIPS_MACHINE_TYPE_LS3X 30
#define MIPS_MACHINE_TYPE_JZ47XX 40
+#define MIPS_MACHINE_TYPE_X1000 41
+#define MIPS_MACHINE_TYPE_X2000 42
#define MIPS_MACHINE_TYPE_HR2 50
#if LW_CFG_CACHE_EN > 0
diff --git a/SylixOS/arch/mips/mm/cache/mipsCacheCommon.c b/SylixOS/arch/mips/mm/cache/mipsCacheCommon.c
index da7dfe0..cbc06df 100644
--- a/SylixOS/arch/mips/mm/cache/mipsCacheCommon.c
+++ b/SylixOS/arch/mips/mm/cache/mipsCacheCommon.c
@@ -291,6 +291,36 @@ static VOID loongson3SCacheInit (VOID)
}
}
/*********************************************************************************************************
+** 函数名称: jzriscSCacheInit
+** 功能描述: JZRISC SCACHE init
+** 输 入 : NONE
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID jzriscSCacheInit (VOID)
+{
+ UINT32 uiConfig2;
+ UINT32 uiTemp;
+
+ uiConfig2 = mipsCp0Config2Read(); /* 读 Config2 */
+
+ uiTemp = (uiConfig2 >> 4) & 0x0f;
+ _G_SCache.CACHE_uiLineSize = 2 << uiTemp;
+
+ uiTemp = (uiConfig2 >> 8) & 0x0f;
+ _G_SCache.CACHE_uiSetNr = 64 << uiTemp;
+
+ uiTemp = (uiConfig2 >> 0) & 0x0f;
+ _G_SCache.CACHE_uiWayNr = uiTemp + 1;
+
+ _G_SCache.CACHE_uiWaySize = _G_SCache.CACHE_uiSetNr * _G_SCache.CACHE_uiLineSize;
+ _G_SCache.CACHE_uiWayBit = lib_ffs(_G_SCache.CACHE_uiWaySize) - 1;
+ _G_SCache.CACHE_uiSize = _G_SCache.CACHE_uiSetNr * _G_SCache.CACHE_uiWayNr *
+ _G_SCache.CACHE_uiLineSize;
+ _G_SCache.CACHE_bPresent = LW_TRUE;
+}
+/*********************************************************************************************************
** 函数名称: mipsSCacheInit
** 功能描述: MIPS SCACHE init
** 输 入 : NONE
@@ -366,6 +396,10 @@ static VOID mipsSCacheSetup (VOID)
loongson3SCacheInit();
break;
+ case CPU_JZRISC:
+ jzriscSCacheInit();
+ break;
+
default:
mipsSCacheInit();
break;
@@ -466,9 +500,13 @@ VOID mipsCacheProbe (CPCHAR pcMachineName)
case CPU_JZRISC: /* 君正 CPU */
_G_bHaveTagHi = LW_FALSE;
- _G_bHaveECC = LW_TRUE;
- _G_uiEccValue = 0; /* 操作 L1C 的指令不影响 L2C */
+ if (_G_uiMipsPridImp == PRID_IMP_XBURST2) {
+ _G_bHaveECC = LW_FALSE;
+ } else {
+ _G_bHaveECC = LW_TRUE;
+ }
_G_bHaveFillI = LW_TRUE;
+ _G_uiEccValue = 0; /* 操作 L1C 的指令不影响 L2C */
_G_bHaveHitWritebackD = LW_TRUE;
/*
* TODO: _G_bHaveHitWritebackS ??
diff --git a/SylixOS/arch/mips/mm/cache/r4k/mipsCacheR4k.c b/SylixOS/arch/mips/mm/cache/r4k/mipsCacheR4k.c
index 746df69..f58233f 100644
--- a/SylixOS/arch/mips/mm/cache/r4k/mipsCacheR4k.c
+++ b/SylixOS/arch/mips/mm/cache/r4k/mipsCacheR4k.c
@@ -337,6 +337,30 @@ static INT mipsCacheR4kDisable (LW_CACHE_TYPE cachetype)
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: mipsCacheX2kEnable
+** 功能描述: 使能 CACHE
+** 输 入 : cachetype INSTRUCTION_CACHE / DATA_CACHE
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT mipsCacheX2kEnable (LW_CACHE_TYPE cachetype)
+{
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: mipsCacheX2kDisable
+** 功能描述: 禁能 CACHE
+** 输 入 : cachetype INSTRUCTION_CACHE / DATA_CACHE
+** 输 出 : ERROR or OK
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT mipsCacheX2kDisable (LW_CACHE_TYPE cachetype)
+{
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
** 函数名称: mipsCacheR4kFlush
** 功能描述: CACHE 脏数据回写
** 输 入 : cachetype CACHE 类型
@@ -829,9 +853,11 @@ VOID mipsCacheR4kInit (LW_CACHE_OP *pcacheop,
{
mipsCacheProbe(pcMachineName); /* CACHE 探测 */
mipsCacheInfoShow(); /* 打印 CACHE 信息 */
- mipsCacheR4kDisableHw(); /* 关闭 CACHE */
- mipsBranchPredictorInvalidate(); /* 无效分支预测 */
- mipsCacheR4kInitHw(); /* 初始化 CACHE */
+ if (!((_G_uiMipsCpuType == CPU_JZRISC) && (_G_uiMipsPridImp == PRID_IMP_XBURST2))) {
+ mipsCacheR4kDisableHw(); /* 关闭 CACHE */
+ mipsBranchPredictorInvalidate(); /* 无效分支预测 */
+ mipsCacheR4kInitHw(); /* 初始化 CACHE */
+ }
#if LW_CFG_SMP_EN > 0
pcacheop->CACHEOP_ulOption = CACHE_TEXT_UPDATE_MP;
@@ -848,8 +874,13 @@ VOID mipsCacheR4kInit (LW_CACHE_OP *pcacheop,
pcacheop->CACHEOP_iICacheWaySize = _G_ICache.CACHE_uiWaySize;
pcacheop->CACHEOP_iDCacheWaySize = _G_DCache.CACHE_uiWaySize;
- pcacheop->CACHEOP_pfuncEnable = mipsCacheR4kEnable;
- pcacheop->CACHEOP_pfuncDisable = mipsCacheR4kDisable;
+ if ((_G_uiMipsCpuType == CPU_JZRISC) && (_G_uiMipsPridImp == PRID_IMP_XBURST2)) {
+ pcacheop->CACHEOP_pfuncEnable = mipsCacheX2kEnable;
+ pcacheop->CACHEOP_pfuncDisable = mipsCacheX2kDisable;
+ } else {
+ pcacheop->CACHEOP_pfuncEnable = mipsCacheR4kEnable;
+ pcacheop->CACHEOP_pfuncDisable = mipsCacheR4kDisable;
+ }
pcacheop->CACHEOP_pfuncLock = mipsCacheR4kLock; /* 暂时不支持锁定操作 */
pcacheop->CACHEOP_pfuncUnlock = mipsCacheR4kUnlock;
@@ -881,8 +912,10 @@ VOID mipsCacheR4kInit (LW_CACHE_OP *pcacheop,
VOID mipsCacheR4kReset (CPCHAR pcMachineName)
{
mipsCacheProbe(pcMachineName); /* CACHE 探测 */
- mipsCacheR4kDisableHw(); /* 关闭 CACHE */
- mipsBranchPredictorInvalidate(); /* 无效分支预测 */
+ if (!((_G_uiMipsCpuType == CPU_JZRISC) && (_G_uiMipsPridImp == PRID_IMP_XBURST2))) {
+ mipsCacheR4kDisableHw(); /* 关闭 CACHE */
+ mipsBranchPredictorInvalidate(); /* 无效分支预测 */
+ }
}
#endif /* LW_CFG_CACHE_EN > 0 */
diff --git a/SylixOS/arch/mips/mm/mipsCache.c b/SylixOS/arch/mips/mm/mipsCache.c
index c8e310a..fe6a2eb 100644
--- a/SylixOS/arch/mips/mm/mipsCache.c
+++ b/SylixOS/arch/mips/mm/mipsCache.c
@@ -58,7 +58,9 @@ VOID archCacheInit (CACHE_MODE uiInstruction, CACHE_MODE uiData, CPCHAR pcMa
} else if ((lib_strcmp(pcMachineName, MIPS_MACHINE_LS1X) == 0) ||
(lib_strcmp(pcMachineName, MIPS_MACHINE_LS2X) == 0) || /* Loongson-2E/2F */
(lib_strcmp(pcMachineName, MIPS_MACHINE_24KF) == 0) ||
- (lib_strcmp(pcMachineName, MIPS_MACHINE_JZ47XX) == 0)) {
+ (lib_strcmp(pcMachineName, MIPS_MACHINE_JZ47XX) == 0) ||
+ (lib_strcmp(pcMachineName, MIPS_MACHINE_X1000) == 0) ||
+ (lib_strcmp(pcMachineName, MIPS_MACHINE_X2000) == 0)) {
mipsCacheR4kInit(pcacheop, uiInstruction, uiData, pcMachineName);
} else {
@@ -88,7 +90,9 @@ VOID archCacheReset (CPCHAR pcMachineName)
} else if ((lib_strcmp(pcMachineName, MIPS_MACHINE_LS1X) == 0) ||
(lib_strcmp(pcMachineName, MIPS_MACHINE_LS2X) == 0) || /* Loongson-2E/2F */
(lib_strcmp(pcMachineName, MIPS_MACHINE_24KF) == 0) ||
- (lib_strcmp(pcMachineName, MIPS_MACHINE_JZ47XX) == 0)) {
+ (lib_strcmp(pcMachineName, MIPS_MACHINE_JZ47XX) == 0) ||
+ (lib_strcmp(pcMachineName, MIPS_MACHINE_X1000) == 0) ||
+ (lib_strcmp(pcMachineName, MIPS_MACHINE_X2000) == 0)) {
mipsCacheR4kReset(pcMachineName);
} else {
diff --git a/SylixOS/arch/mips/mm/mmu/mips32/mips32Mmu.c b/SylixOS/arch/mips/mm/mmu/mips32/mips32Mmu.c
index 078ed69..b307563 100644
--- a/SylixOS/arch/mips/mm/mmu/mips32/mips32Mmu.c
+++ b/SylixOS/arch/mips/mm/mmu/mips32/mips32Mmu.c
@@ -533,7 +533,7 @@ VOID mips32MmuInit (LW_MMU_OP *pmmuop, CPCHAR pcMachineName)
pmmuop->MMUOP_pfuncMakeCurCtx = mips32MmuMakeCurCtx;
}
-#endif /* LW_CFG_CPU_WORD_LENGHT == 64*/
+#endif /* LW_CFG_CPU_WORD_LENGHT == 32*/
#endif /* LW_CFG_VMM_EN > 0 */
/*********************************************************************************************************
END
diff --git a/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c b/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c
index 05d3273..484ab81 100644
--- a/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c
+++ b/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c
@@ -31,6 +31,15 @@
#include "mips32/mips32Mmu.h"
#include "mips64/mips64Mmu.h"
/*********************************************************************************************************
+ 君正 x1000 TLB 需要的特殊处理
+*********************************************************************************************************/
+#if LW_CFG_CPU_WORD_LENGHT == 32
+#define MIPS32_INGENIC_X1000_TLB_FIX __asm__ __volatile__ ("li $2, 0xa9000000 \n\t" \
+ "mtc0 $2, $5, 4 \n\t" \
+ "nop \n\t" \
+ ::"r"(2))
+#endif /* LW_CFG_CPU_WORD_LENGHT == 32*/
+/*********************************************************************************************************
UNIQUE ENTRYHI(按 512KB 步进, 提升兼容性, TLB 数目最多 256 个, 不会上溢到 CKSEG1, CKSEG0 空间有 512MB)
*********************************************************************************************************/
#define MIPS_UNIQUE_ENTRYHI(idx) (CKSEG0 + ((idx) << (18 + 1)))
@@ -389,6 +398,13 @@ VOID mipsMmuInit (LW_MMU_OP *pmmuop, CPCHAR pcMachineName)
* 5: Cacheable, coherent, write-back, write-allocate, read misses request Shared
*/
_G_uiMmuEntryLoCache = 0x5; /* 一致性高速缓存 */
+
+#if LW_CFG_CPU_WORD_LENGHT == 32
+ if (_G_uiMipsMachineType == MIPS_MACHINE_TYPE_X1000) { /* 针对 x1000 TLB 特殊初始化 */
+ MIPS32_INGENIC_X1000_TLB_FIX;
+ }
+#endif /* LW_CFG_CPU_WORD_LENGHT == 32*/
+
break;
case CPU_CETC_HR2: /* CETC-HR2 */
diff --git a/SylixOS/arch/x86/bsp/bspLib.c b/SylixOS/arch/x86/bsp/bspLib.c
index 91ac294..53b2a52 100644
--- a/SylixOS/arch/x86/bsp/bspLib.c
+++ b/SylixOS/arch/x86/bsp/bspLib.c
@@ -131,7 +131,7 @@ LW_WEAK ULONG bspMmuPtsMaxNum (VOID)
#endif /* LW_CFG_CPU_WORD_LENGHT == 64*/
/*********************************************************************************************************
-** 函数名称: bspMmuPgdMaxNum
+** 函数名称: bspMmuPteMaxNum
** 功能描述: 获得 PTE 池的数量
** 输 入 : NONE
** 输 出 : PTE 池的数量 (映射 4GB 空间, 需要 1024 个 PTE 池)
diff --git a/SylixOS/arch/x86/common/x64/x64Context.c b/SylixOS/arch/x86/common/x64/x64Context.c
index ee125fc..00ffcf7 100644
--- a/SylixOS/arch/x86/common/x64/x64Context.c
+++ b/SylixOS/arch/x86/common/x64/x64Context.c
@@ -242,7 +242,7 @@ VOID archTaskCtxPrint (PVOID pvBuffer, size_t stSize, const ARCH_REG_CTX *pr
_PrintFormat("\r\n");
_PrintFormat("RFLAGS = 0x%016qx\r\n", pregctx->REG_ulRFLAGS);
- _PrintFormat("RIP = 0x%016qx\r\n", pregctx->REG_ulRIP);
+ _PrintFormat("RIP = 0x%016qx\r\n", pregctx->REG_ulRIP);
_PrintFormat("SS = 0x%016qx ", pregctx->REG_ulSS);
_PrintFormat("CS = 0x%016qx\r\n", pregctx->REG_ulCS);
diff --git a/SylixOS/arch/x86/common/x64/x64IoAsm.S b/SylixOS/arch/x86/common/x64/x64IoAsm.S
index 902f239..b6f9027 100644
--- a/SylixOS/arch/x86/common/x64/x64IoAsm.S
+++ b/SylixOS/arch/x86/common/x64/x64IoAsm.S
@@ -68,7 +68,7 @@
FUNC_DEF(in8)
MOV X86_64_ARG0 , %RDX
- MOV $0 , %RAX
+ MOV $0 , %RAX
INB %DX , %AL
RET
FUNC_END(in8)
@@ -79,7 +79,7 @@ FUNC_DEF(in8)
FUNC_DEF(in16)
MOV X86_64_ARG0 , %RDX
- MOV $0 , %RAX
+ MOV $0 , %RAX
INW %DX , %AX
RET
FUNC_END(in16)
@@ -90,7 +90,7 @@ FUNC_DEF(in16)
FUNC_DEF(in32)
MOV X86_64_ARG0 , %RDX
- MOV $0 , %RAX
+ MOV $0 , %RAX
INL %DX , %EAX
RET
FUNC_END(in32)
@@ -169,7 +169,7 @@ FUNC_DEF(ins32)
MOV X86_64_ARG1 , %RDI ;/* %RDI = pvBuffer */
CLD
REP
- INSL %DX , (%RDI)
+ INSL %DX , (%RDI)
RET
FUNC_END(ins32)
diff --git a/SylixOS/arch/x86/common/x86Gdt.c b/SylixOS/arch/x86/common/x86Gdt.c
index da566f5..3dc046b 100644
--- a/SylixOS/arch/x86/common/x86Gdt.c
+++ b/SylixOS/arch/x86/common/x86Gdt.c
@@ -262,11 +262,11 @@ static INT __x86GdtInit (ULONG ulCPUId)
{
X86_GDT_REG gdtr;
- _G_x86GDT[ulCPUId][X86_SEG_NULL] = (X86_SEG_DESC){ 0, };
- _G_x86GDT[ulCPUId][X86_SEG_KCODE] = BUILD_GDTE(0, 1);
- _G_x86GDT[ulCPUId][X86_SEG_KDATA] = BUILD_GDTE(0, 0);
- _G_x86GDT[ulCPUId][X86_SEG_UCODE] = BUILD_GDTE(3, 1);
- _G_x86GDT[ulCPUId][X86_SEG_UDATA] = BUILD_GDTE(3, 0);
+ _G_x86GDT[ulCPUId][X86_SEG_NULL] = (X86_SEG_DESC){ 0, };
+ _G_x86GDT[ulCPUId][X86_SEG_KCODE] = BUILD_GDTE(0, 1);
+ _G_x86GDT[ulCPUId][X86_SEG_KDATA] = BUILD_GDTE(0, 0);
+ _G_x86GDT[ulCPUId][X86_SEG_UCODE] = BUILD_GDTE(3, 1);
+ _G_x86GDT[ulCPUId][X86_SEG_UDATA] = BUILD_GDTE(3, 0);
_G_x86GDT[ulCPUId][X86_SEG_KERNEL_TSS] = (X86_SEG_DESC){ 0, };
/*
diff --git a/SylixOS/config/system/system_cfg.h b/SylixOS/config/system/system_cfg.h
index f060b34..e1ec411 100644
--- a/SylixOS/config/system/system_cfg.h
+++ b/SylixOS/config/system/system_cfg.h
@@ -66,7 +66,7 @@
#define LW_CFG_SIGNAL_EN 1 /* 是否允许系统使用信号 */
/*********************************************************************************************************
-* POSIX 定时器及其附件配置, 如果需要 BSD Net/3 网络支持则需要同时开通信号服务和posix 定时器服务
+* POSIX 定时器及其附件配置, 如果需要 BSD Net/3 网络支持则需要同时开通信号服务和 posix 定时器服务
*
* 依存关系: 1: 信号服务
2: 内核定时器服务
diff --git a/SylixOS/debug/dtrace/dtrace.c b/SylixOS/debug/dtrace/dtrace.c
index 3a7aa78..681ca3a 100644
--- a/SylixOS/debug/dtrace/dtrace.c
+++ b/SylixOS/debug/dtrace/dtrace.c
@@ -308,8 +308,8 @@ INT API_DtraceBreakTrap (addr_t ulAddr, UINT uiBpType)
#if LW_CFG_SMP_EN > 0 && !defined(LW_DTRACE_HW_ISTEP)
if (ulAddr == ptcbCur->TCB_ulStepAddr) {
- archDbgBpRemove(ptcbCur->TCB_ulStepAddr, sizeof(addr_t),
- ptcbCur->TCB_ulStepInst, LW_FALSE);
+ archDbgBpRemove(ptcbCur->TCB_ulStepAddr, sizeof(addr_t),
+ ptcbCur->TCB_ulStepInst, LW_FALSE);
ptcbCur->TCB_bStepClear = LW_TRUE; /* 断点被移除 */
}
#endif /* LW_CFG_SMP_EN > 0 */
diff --git a/SylixOS/devtree/devtree.h b/SylixOS/devtree/devtree.h
index 440160e..fea885d 100644
--- a/SylixOS/devtree/devtree.h
+++ b/SylixOS/devtree/devtree.h
@@ -303,6 +303,8 @@ LW_API INT API_DeviceTreeDevEarlyInit(PLW_DEVTREE_TABLE pdttM
LW_API INT API_DeviceTreeIsCompatible(PLW_DEVTREE_NODE pdtnDev,
PCHAR pcCompat);
+LW_API PVOID API_DeviceTreeDevGetMatchData(PLW_DEV_INSTANCE pdevinstance);
+
/*********************************************************************************************************
中断相关接口
*********************************************************************************************************/
diff --git a/SylixOS/devtree/devtreeDev.c b/SylixOS/devtree/devtreeDev.c
index e0e335b..4ed3a8c 100644
--- a/SylixOS/devtree/devtreeDev.c
+++ b/SylixOS/devtree/devtreeDev.c
@@ -354,6 +354,33 @@ INT API_DeviceTreeIsCompatible (PLW_DEVTREE_NODE pdtnDev,
return (__deviceTreeIsCompatible(pdtnDev, pcCompat, LW_NULL, LW_NULL));
}
+/*********************************************************************************************************
+** 函数名称: API_DeviceTreeDevGetMatchData
+** 功能描述: 设备树设备节点获取匹配表数据
+** 输 入 : pdevInstance 设备节点
+** 输 出 : 匹配表数据
+** 全局变量:
+** 调用模块:
+** API 函数
+*********************************************************************************************************/
+LW_API
+PVOID API_DeviceTreeDevGetMatchData (PLW_DEV_INSTANCE pdevInstance)
+{
+ PLW_DEVTREE_TABLE pdttMatch;
+
+ if (!pdevInstance) {
+ _ErrorHandle(EINVAL);
+ return (LW_NULL);
+ }
+
+ pdttMatch = __deviceTreeNodeMatch(pdevInstance->DEVHD_pdtnDev,
+ pdevInstance->DEVHD_pdrvinstance->DRVHD_pMatchTable);
+ if (!pdttMatch) {
+ return (LW_NULL);
+ }
+
+ return ((PVOID)pdttMatch->DTITEM_pvData);
+}
#endif /* LW_CFG_DEVTREE_EN > 0 */
/*********************************************************************************************************
diff --git a/SylixOS/driver/can/sja1000.c b/SylixOS/driver/can/sja1000.c
index 55b4d09..2c710de 100644
--- a/SylixOS/driver/can/sja1000.c
+++ b/SylixOS/driver/can/sja1000.c
@@ -264,7 +264,8 @@ static INT sja1000SetBaud (SJA1000_CHAN *pcanchan, ULONG baudvalue)
** 函数名称: sja1000SetDiv
** 功能描述: 设置 SJA1000 DIV
** 输 入 : pcanchan CAN CHAN
-** baudvalue 波特率码
+** rxinten rx 中断使能状态
+** cbp 时钟分频
** 输 出 : ERROR or OK
** 全局变量:
** 调用模块:
diff --git a/SylixOS/driver/sio/16c550.c b/SylixOS/driver/sio/16c550.c
index 45dfd69..a527aa1 100644
--- a/SylixOS/driver/sio/16c550.c
+++ b/SylixOS/driver/sio/16c550.c
@@ -17,6 +17,8 @@
** 文件创建日期: 2015 年 08 月 27 日
**
** 描 述: 16c550 兼容串口驱动支持.
+** BUG:
+** 2021.08.05 修复接收中断使用工作队列多收数据和少发数据
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#include "SylixOS.h"
@@ -367,11 +369,18 @@ static INT sio16c550SetHighBaud (SIO16C550_CHAN *psiochan, ULONG baud)
INT base_port;
size_t i = 0;
+#if defined(LW_CFG_CPU_ARCH_X86)
if (psiochan->iobase == 0) {
_ErrorHandle(ENODEV);
return (PX_ERROR);
}
-
+#else
+ if ((psiochan->iobase == 0) && (__IO_BASE__ == 0)) {
+ _ErrorHandle(ENODEV);
+ return (PX_ERROR);
+ }
+#endif /* LW_CFG_CPU_ARCH_X86 */
+
base_port = sio16c550GetBasePort(psiochan->iobase, &key, &index);
if (base_port < 0) {
_ErrorHandle(ENODEV);
@@ -1022,7 +1031,7 @@ VOID sio16c550TxIsr (SIO16C550_CHAN *psiochan)
psiochan->bdefer = LW_FALSE;
- lsr = psiochan->lsr; /* first use save lsr value */
+ lsr = GET_REG(psiochan, LSR);
if (lsr & LSR_THRE) {
for (i = 0; i < psiochan->fifo_len; i++) {
@@ -1057,7 +1066,7 @@ VOID sio16c550RxIsr (SIO16C550_CHAN *psiochan)
LW_SPIN_LOCK_QUICK(&psiochan->slock, &intreg);
- lsr = psiochan->lsr; /* first use save lsr value */
+ lsr = GET_REG(psiochan, LSR);
do {
if (lsr & (LSR_BI | LSR_FE | LSR_PE | LSR_OE)) {
@@ -1120,7 +1129,6 @@ VOID sio16c550Isr (SIO16C550_CHAN *psiochan)
psiochan->ier &= (~RxFIFO_BIT);
SET_REG(psiochan, IER, psiochan->ier); /* disable Rx Int */
- psiochan->lsr = lsr; /* save lsr */
LW_SPIN_UNLOCK_QUICK(&psiochan->slock, intreg);
#if LW_CFG_ISR_DEFER_EN > 0
@@ -1145,7 +1153,6 @@ VOID sio16c550Isr (SIO16C550_CHAN *psiochan)
if (psiochan->bdefer == LW_FALSE) { /* not in queue */
psiochan->bdefer = LW_TRUE;
- psiochan->lsr = lsr; /* save lsr */
LW_SPIN_UNLOCK_QUICK(&psiochan->slock, intreg);
#if LW_CFG_ISR_DEFER_EN > 0
diff --git a/SylixOS/fs/diskCache/diskCache.c b/SylixOS/fs/diskCache/diskCache.c
index fa23cf4..dcba65a 100644
--- a/SylixOS/fs/diskCache/diskCache.c
+++ b/SylixOS/fs/diskCache/diskCache.c
@@ -270,7 +270,7 @@ ULONG API_DiskCacheCreateEx2 (PLW_BLK_DEV pblkdDisk,
pdiskcDiskCache->DISKC_ulBytesPerSector = ulBytesPerSector;
pdiskcDiskCache->DISKC_iMaxRBurstSector = pdcattrl->DCATTR_iMaxRBurstSector;
pdiskcDiskCache->DISKC_iMaxWBurstSector = pdcattrl->DCATTR_iMaxWBurstSector;
-
+
if (pdcattrl->DCATTR_iBurstOpt & LW_DCATTR_BOPT_META_ONE_BURST) {
pdiskcDiskCache->DISKC_iMetaBurstSector = 1;
} else {
diff --git a/SylixOS/fs/diskPartition/diskPartition.c b/SylixOS/fs/diskPartition/diskPartition.c
index f3ac310..abab077 100644
--- a/SylixOS/fs/diskPartition/diskPartition.c
+++ b/SylixOS/fs/diskPartition/diskPartition.c
@@ -41,6 +41,9 @@
*********************************************************************************************************/
#if (LW_CFG_MAX_VOLUMES > 0) && (LW_CFG_DISKPART_EN > 0)
#include "diskPartition.h"
+#if LW_CFG_CPU_WORD_LENGHT > 32
+#include "gptPartition.h"
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
/*********************************************************************************************************
一个物理磁盘带有五个逻辑分区的 BLK_DEV 文件系统示例结构:
@@ -399,6 +402,72 @@ static INT __diskPartitionScan (PLW_BLK_DEV pblkd,
}
}
/*********************************************************************************************************
+** 函数名称: __diskGptPartitionScan
+** 功能描述: 扫描 GPT 分区信息
+** 输 入 : pblkd 块设备
+** ulBytesPerSector 扇区大小
+** pdpt GPT 分区表结构
+** 输 出 : > 0 分区数量
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+#if LW_CFG_CPU_WORD_LENGHT > 32
+
+static INT __diskGptPartitionScan (PLW_BLK_DEV pblkd,
+ ULONG ulBytesPerSector,
+ PLW_DISKPART_TABLE pdpt)
+{
+ UINT64 ui64PStartSec;
+ UINT64 ui64lPNSec;
+ BYTE ucPartType;
+ INT i;
+
+ LW_DISKPART_OPERAT *pdoLogic;
+ GPT_TABLE *pgpt;
+
+ pgpt = API_GptCreateAndInit(ulBytesPerSector, 0);
+ if (!pgpt) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
+ return (PX_ERROR);
+ }
+
+ if (API_GptPartitionBlkLoad(pblkd, pgpt) != ERROR_NONE) { /* 从块设备加载 GPT 分区表 */
+ API_GptDestroy(pgpt);
+ return (PX_ERROR);
+ }
+
+ for (i = 0;
+ (i < pgpt->GPT_header.HDR_uiEntriesCount) && (i < LW_CFG_MAX_DISKPARTS);
+ i++) { /* 遍历分区表 */
+ pdoLogic = &pdpt->DPT_dpoLogic[i]; /* 逻辑分区信息 */
+ if (API_GptGetEntry(pgpt, i, &ui64PStartSec, &ui64lPNSec, &ucPartType) != ERROR_NONE) {
+ API_GptDestroy(pgpt);
+ return (PX_ERROR);
+ }
+
+ pdoLogic->DPO_dpnEntry.DPN_bIsActive = LW_TRUE;
+ pdoLogic->DPO_dpnEntry.DPN_ulStartSector = ui64PStartSec;
+ pdoLogic->DPO_dpnEntry.DPN_ulNSector = ui64lPNSec;
+ pdoLogic->DPO_dpnEntry.DPN_ucPartType = ucPartType;
+ pdoLogic->DPT_pblkdDisk = pblkd;
+
+ __logicDiskInit(&pdoLogic->DPO_blkdLogic,
+ pdoLogic->DPT_pblkdDisk,
+ pdoLogic->DPO_dpnEntry.DPN_ulNSector); /* 初始化逻辑设备控制块 */
+
+ if (!LW_DISK_PART_IS_VALID(ucPartType)) { /* 对未知分区类型尝试枚举 */
+ pdoLogic->DPO_dpnEntry.DPN_ucPartType = __fsPartitionProb(&pdoLogic->DPO_blkdLogic);
+ }
+ }
+
+ API_GptDestroy(pgpt);
+
+ return (i);
+}
+
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
+/*********************************************************************************************************
** 函数名称: __diskPartitionProb
** 功能描述: 分区表探测处理
** 输 入 : pblkd 块设备
@@ -473,9 +542,15 @@ INT API_DiskPartitionScan (PLW_BLK_DEV pblkd, PLW_DISKPART_TABLE pdptDisk)
return (iError);
}
}
-
- iError = __diskPartitionScan(pblkd, ulBytesPerSector,
- pdptDisk, 0, 0, 0); /* 分析磁盘分区表 */
+
+#if LW_CFG_CPU_WORD_LENGHT > 32
+ iError = __diskGptPartitionScan(pblkd, ulBytesPerSector, pdptDisk); /* 首先尝试 GPT 分区格式扫描 */
+ if (iError < 0)
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
+ {
+ iError = __diskPartitionScan(pblkd, ulBytesPerSector,
+ pdptDisk, 0, 0, 0); /* 分析磁盘分区表 */
+ }
if (iError >= 0) {
pdptDisk->DPT_ulNPart = (ULONG)iError; /* 记录分区数量 */
diff --git a/SylixOS/fs/diskPartition/diskPartition.h b/SylixOS/fs/diskPartition/diskPartition.h
index 5b0c773..42e50f5 100644
--- a/SylixOS/fs/diskPartition/diskPartition.h
+++ b/SylixOS/fs/diskPartition/diskPartition.h
@@ -83,6 +83,7 @@
#define LW_DISK_PART_TYPE_QNX6_3 0xb3
#define LW_DISK_PART_TYPE_ISO9660 0x96
#define LW_DISK_PART_TYPE_TPS 0x9c
+#define LW_DISK_PART_TYPE_EFI 0x9d
#define LW_DISK_PART_TYPE_RESERVED 0xbf
/*********************************************************************************************************
分区类型 (扩展分区)
diff --git a/SylixOS/fs/diskPartition/gptPartition.c b/SylixOS/fs/diskPartition/gptPartition.c
new file mode 100644
index 0000000..72682fa
--- /dev/null
+++ b/SylixOS/fs/diskPartition/gptPartition.c
@@ -0,0 +1,655 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: gptPartition.c
+**
+** 创 建 人: Jiang.Taijin (蒋太金)
+**
+** 文件创建日期: 2021 年 06 月 19 日
+**
+** 描 述: GPT 分区表分析.
+*********************************************************************************************************/
+#define __SYLIXOS_KERNEL
+#include "../SylixOS/kernel/include/k_kernel.h"
+#include "../SylixOS/system/include/s_system.h"
+#include "../SylixOS/fs/include/fs_internal.h"
+#include "../SylixOS/fs/fsCommon/fsCommon.h"
+/*********************************************************************************************************
+ 裁剪宏
+*********************************************************************************************************/
+#if (LW_CFG_MAX_VOLUMES > 0) && (LW_CFG_DISKPART_EN > 0) && (LW_CFG_CPU_WORD_LENGHT > 32)
+#include "sys/uuid.h"
+#include "endian.h"
+#include "gptPartition.h"
+/*********************************************************************************************************
+ 分区类型数组在 GPT 头逻辑块中的偏移,分区类型数组是为实现 SylixOS 自动挂载功能所添加的数据
+*********************************************************************************************************/
+#define GPT_PART_TYPE_OFF 128
+/*********************************************************************************************************
+ GPT 分区名前缀
+*********************************************************************************************************/
+static const CHAR _G_acGptPartName[] = "SylixOSPart";
+/*********************************************************************************************************
+ 分区类型 UUID,Windows 数据分区
+*********************************************************************************************************/
+static const UINT8 _G_ucGptPartTypeData[16] = {
+ 0xa2, 0xa0, 0xd0, 0xeb, 0xe5, 0xb9, 0x33, 0x44,
+ 0x87, 0xc0, 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7,
+};
+/*********************************************************************************************************
+ 分区类型 EFI,UEFI引导分区
+*********************************************************************************************************/
+static const UINT8 _G_ucGptPartTypeEfi[16] = {
+ 0x28, 0x73, 0x2a, 0xc1, 0x1f, 0xf8, 0xd2, 0x11,
+ 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b,
+};
+/*********************************************************************************************************
+** 函数名称: __gptCrcReflect
+** 功能描述: 高低位对换(i.e. 10101000 <--> 00010101),用于 crc32 计算
+** 输 入 : iData 待计算数据
+** iLen 数据为宽
+** 输 出 : 计算结果
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __gptCrcReflect (INT iData, INT iLen)
+{
+ INT iRef = 0;
+ INT i;
+
+ for (i = 0; i < iLen; i++) {
+ if (iData & 0x1) {
+ iRef |= (1 << ((iLen - 1) - i));
+ }
+ iData = (iData >> 1);
+ }
+
+ return (iRef);
+}
+/*********************************************************************************************************
+** 函数名称: __gptCrc32
+** 功能描述: 计算 crc
+** 输 入 : pucBuffer 数据缓冲区
+** iLen 数据长度
+** 输 出 : crc32 值
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static UINT32 __gptCrc32 (UINT8 *pucBuffer, INT iLen)
+{
+ INT iByteLen = 8;
+ INT iMsb = 0;
+ INT iPolynomial = 0x04c11db7; /* IEEE 32bit polynomial */
+ UINT uiRegs = 0xffffffff;
+ INT iRegsMask = 0xffffffff;
+ INT iRegsMsb = 0;
+ UINT uiReflectedRegs;
+ INT iDataByte;
+ INT i;
+ INT j;
+
+ for (i = 0; i < iLen; i++) {
+ iDataByte = pucBuffer[i];
+ iDataByte = __gptCrcReflect(iDataByte, 8);
+
+ for (j = 0; j < iByteLen; j++) {
+ iMsb = iDataByte >> (iByteLen - 1); /* get MSB */
+ iMsb &= 1; /* ensure just 1 bit */
+ iRegsMsb = (uiRegs >> 31) & 1; /* MSB of regs */
+ uiRegs = uiRegs << 1; /* shift regs for CRC-CCITT */
+ if (iRegsMsb ^ iMsb) { /* MSB is a 1 */
+ uiRegs = uiRegs ^ iPolynomial; /* XOR with generator poly */
+ }
+
+ uiRegs = uiRegs & iRegsMask; /* Mask off excess upper bits */
+ iDataByte <<= 1; /* get to next bit */
+ }
+ }
+ uiRegs = uiRegs & iRegsMask;
+ uiReflectedRegs = __gptCrcReflect(uiRegs, 32) ^ 0xffffffff;
+
+ return (uiReflectedRegs);
+}
+/*********************************************************************************************************
+** 函数名称: __gptInitMbr
+** 功能描述: 初始化 MBR
+** 输 入 : ucMbr MBR 数据缓冲区
+** ui64LbaCnt 块设备逻辑块数量
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __gptInitMbr (UINT8 *ucMbr, UINT64 ui64LbaCnt)
+{
+ ucMbr[0x1be] = 0x00;
+ ucMbr[0x1bf] = 0x00;
+ ucMbr[0x1c0] = 0x01;
+ ucMbr[0x1c1] = 0x00;
+
+ ucMbr[0x1c2] = 0xee;
+ ucMbr[0x1c3] = 0xfe;
+ ucMbr[0x1c4] = 0xff;
+ ucMbr[0x1c5] = 0xff;
+
+ ucMbr[0x1c6] = 0x01;
+ ucMbr[0x1c7] = 0x00;
+ ucMbr[0x1c8] = 0x00;
+ ucMbr[0x1c9] = 0x00;
+
+ ucMbr[0x1ca] = (ui64LbaCnt & 0xff);
+ ucMbr[0x1cb] = ((ui64LbaCnt >> 8) & 0xff);
+ ucMbr[0x1cc] = ((ui64LbaCnt >> 16) & 0xff);
+ ucMbr[0x1cd] = ((ui64LbaCnt >> 24) & 0xff);
+
+ ucMbr[0x1fe] = 0x55;
+ ucMbr[0x1ff] = 0xaa;
+}
+/*********************************************************************************************************
+** 函数名称: API_GptCreateAndInit
+** 功能描述: 分配和初始化 GPT 内存结构
+** 输 入 : ulSecSize 扇区大小
+** ui64SecCnt 块设备扇区数量,为 0 则只分配内存不初始化结构
+** 输 出 : GPT 内存结构
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+GPT_TABLE *API_GptCreateAndInit (UINT ulSecSize, UINT64 ui64SecCnt)
+{
+ GPT_TABLE *pgpt;
+ GPT_HEADER *pgpthdr;
+
+ pgpt = (GPT_TABLE *)__SHEAP_ALLOC(sizeof(GPT_TABLE));
+ if (!pgpt) {
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY); /* 内存不足 */
+ return (LW_NULL);
+ }
+
+ if (ulSecSize > GPT_MAX_SECSIZE) {
+ _ErrorHandle(EINVAL);
+ return (LW_NULL);
+ }
+
+ lib_bzero((PVOID)pgpt, sizeof(GPT_TABLE));
+
+ pgpt->GPT_uiSecSize = ulSecSize;
+
+ if (ui64SecCnt == 0) { /* 无需初始化 */
+ return (pgpt);
+ }
+
+ __gptInitMbr(pgpt->GPT_ucMbr, ui64SecCnt); /* 初始化 MBR */
+
+ /*
+ * 初始化 GPT 表头
+ */
+ pgpthdr = &pgpt->GPT_header;
+ lib_memcpy(pgpthdr->HDR_ucMagic, GPT_MAGIC, sizeof(GPT_HEADER));
+ pgpthdr->HDR_uiVersion = GPT_VERSION;
+ pgpthdr->HDR_uiHeadSz = sizeof(GPT_HEADER);
+ pgpthdr->HDR_uiCrc32 = 0;
+ pgpthdr->HDR_uiReserved = 0;
+
+ pgpthdr->HDR_ui64HeaderLba = GPT_HEAD_LBA;
+ pgpthdr->HDR_ui64BackupLba = ui64SecCnt - GPT_HEAD_LBA_CNT;
+ pgpthdr->HDR_ui64FirstLba = GPT_DATA_LBA;
+ pgpthdr->HDR_ui64LastLba = ui64SecCnt - GPT_HEAD_LBA_CNT - GPT_ENT_LBA_CNT;
+
+ uuidgen((uuid_t *)pgpthdr->HDR_ucVolumeUuid, 1);
+
+ pgpthdr->HDR_ui64Entrieslba = 2;
+ pgpthdr->HDR_uiEntriesCount = 0;
+ pgpthdr->HDR_uiEntriesSize = sizeof(GPT_ENTRY);
+ pgpthdr->HDR_uiEntriesCrc32 = 0;
+
+ return (pgpt);
+}
+/*********************************************************************************************************
+** 函数名称: API_GptDestroy
+** 功能描述: 销毁 GPT 内存结构
+** 输 入 : pgpt GPT 内存结构指针
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID API_GptDestroy (GPT_TABLE *pgpt)
+{
+ if (!pgpt) {
+ _ErrorHandle(EINVAL);
+ }
+
+ __SHEAP_FREE(pgpt);
+}
+/*********************************************************************************************************
+** 函数名称: API_GptAddEntry
+** 功能描述: 添加分区表项
+** 输 入 : pgpt GPT 内存结构指针
+** ui64LbaNum 分区起始逻辑块号
+** ui64LbaCnt 分区逻辑块数量
+** ucPartType 分区类型
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT API_GptAddEntry (GPT_TABLE *pgpt, UINT64 ui64LbaNum, UINT64 ui64LbaCnt, UINT8 ucPartType)
+{
+ INT iIndex;
+ INT i;
+
+ if (!pgpt || (pgpt->GPT_header.HDR_uiVersion == 0)) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ iIndex = pgpt->GPT_header.HDR_uiEntriesCount;
+
+ if (ucPartType == LW_DISK_PART_TYPE_EFI) {
+ lib_memcpy(pgpt->GPT_entry[iIndex].ENT_ucTypeUuid,
+ _G_ucGptPartTypeEfi, sizeof(_G_ucGptPartTypeEfi)); /* EFI分区 */
+
+ } else {
+ lib_memcpy(pgpt->GPT_entry[iIndex].ENT_ucTypeUuid,
+ _G_ucGptPartTypeData, sizeof(_G_ucGptPartTypeData)); /* 数据分区 */
+ }
+
+ uuidgen((uuid_t *)pgpt->GPT_entry[iIndex].ENT_ucUniqUuid, 1);
+ pgpt->GPT_entry[iIndex].ENT_ui64FirstLba = ui64LbaNum;
+ pgpt->GPT_entry[iIndex].ENT_ui64LastLba = ui64LbaNum + ui64LbaCnt - 1;
+ pgpt->GPT_entry[iIndex].ENT_ui64Attr = 0;
+
+ /*
+ * 分区名称 SylixOSPart*
+ */
+ for (i = 0; i < lib_strlen(_G_acGptPartName); i++) {
+ pgpt->GPT_entry[iIndex].ENT_usName[i] = _G_acGptPartName[i];
+ }
+ pgpt->GPT_entry[iIndex].ENT_usName[i] = iIndex;
+
+ /*
+ * 将分区类型保存在 GPT 分区头扇区的空闲字节中
+ */
+ if ((GPT_PART_TYPE_OFF + iIndex) >= pgpt->GPT_uiSecSize) {
+ return (PX_ERROR);
+ }
+
+ pgpt->GPT_ucBlock[GPT_PART_TYPE_OFF + iIndex] = ucPartType;
+
+ pgpt->GPT_header.HDR_uiEntriesCount++;
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: API_GptGetEntry
+** 功能描述: 获取分区表项
+** 输 入 : pgpt GPT 内存结构指针
+** iIndex 分区索引
+** pui64LbaNum 输出分区起始逻辑块号
+** pui64LbaCnt 输出分区逻辑块数量
+** pucPartType 输出分区类型
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT API_GptGetEntry (GPT_TABLE *pgpt,
+ INT iIndex,
+ UINT64 *pui64LbaNum,
+ UINT64 *pui64LbaCnt,
+ UINT8 *pucPartType)
+{
+ GPT_ENTRY *pentry;
+
+ if (!pgpt || (pgpt->GPT_header.HDR_uiVersion == 0)) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ if (iIndex >= pgpt->GPT_header.HDR_uiEntriesCount) {
+ return (PX_ERROR);
+ }
+
+ pentry = &pgpt->GPT_entry[iIndex];
+ *pui64LbaNum = pentry->ENT_ui64FirstLba;
+ *pui64LbaCnt = pentry->ENT_ui64LastLba - pentry->ENT_ui64FirstLba + 1;
+ *pucPartType = pgpt->GPT_ucBlock[GPT_PART_TYPE_OFF + iIndex];
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: __gptSerial
+** 功能描述: 序列化分区表
+** 输 入 : pgpt GPT 内存结构指针
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __gptSerial (GPT_TABLE *pgpt)
+{
+ GPT_HEADER *pgpthdr = &pgpt->GPT_header;
+ GPT_ENTRY *pentry = pgpt->GPT_entry;
+ INT i;
+ INT j;
+
+ /*
+ * 先序列化分区表项,以便计算分区表crc
+ */
+ pgpthdr->HDR_uiEntriesCount = GPT_MAX_ENTRIES; /* Windows 需设置项数为最大值 */
+ for (i = 0; i < pgpthdr->HDR_uiEntriesCount; i++, pentry++) {
+ pentry->ENT_ui64FirstLba = htole64(pentry->ENT_ui64FirstLba);
+ pentry->ENT_ui64LastLba = htole64(pentry->ENT_ui64LastLba);
+ pentry->ENT_ui64Attr = htole64(pentry->ENT_ui64Attr);
+
+ for (j = 0; j < GPT_MAX_NAMELEN; j++) {
+ pentry->ENT_usName[j] = htole16(pentry->ENT_usName[j]);
+ }
+ }
+
+ pgpthdr->HDR_uiCrc32 = 0; /* 计算前初始化 crc 为 0 */
+ pgpthdr->HDR_uiVersion = htole32(pgpthdr->HDR_uiVersion);
+ pgpthdr->HDR_uiHeadSz = htole32(pgpthdr->HDR_uiHeadSz);
+ pgpthdr->HDR_uiReserved = htole32(pgpthdr->HDR_uiReserved);
+ pgpthdr->HDR_ui64HeaderLba = htole64(pgpthdr->HDR_ui64HeaderLba);
+ pgpthdr->HDR_ui64BackupLba = htole64(pgpthdr->HDR_ui64BackupLba);
+ pgpthdr->HDR_ui64FirstLba = htole64(pgpthdr->HDR_ui64FirstLba);
+ pgpthdr->HDR_ui64LastLba = htole64(pgpthdr->HDR_ui64LastLba);
+ pgpthdr->HDR_ui64Entrieslba = htole64(pgpthdr->HDR_ui64Entrieslba);
+ pgpthdr->HDR_uiEntriesCount = htole32(pgpthdr->HDR_uiEntriesCount);
+ pgpthdr->HDR_uiEntriesSize = htole32(pgpthdr->HDR_uiEntriesSize);
+ pgpthdr->HDR_uiEntriesCrc32 = __gptCrc32((UINT8 *)pgpt->GPT_entry,
+ pgpthdr->HDR_uiEntriesCount * sizeof(GPT_ENTRY));
+
+ pgpthdr->HDR_uiCrc32 = __gptCrc32((UINT8 *)pgpthdr, sizeof(GPT_HEADER));
+}
+/*********************************************************************************************************
+** 函数名称: __gptUnserial
+** 功能描述: 逆序列化分区表
+** 输 入 : pgpt GPT 内存结构指针
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __gptUnserial (GPT_TABLE *pgpt)
+{
+ GPT_HEADER *pgpthdr = &pgpt->GPT_header;
+ GPT_ENTRY *pentry = pgpt->GPT_entry;
+ INT i;
+ INT j;
+
+ pgpthdr->HDR_uiCrc32 = 0;
+ pgpthdr->HDR_uiVersion = le32toh(pgpthdr->HDR_uiVersion);
+ pgpthdr->HDR_uiHeadSz = le32toh(pgpthdr->HDR_uiHeadSz);
+ pgpthdr->HDR_uiReserved = le32toh(pgpthdr->HDR_uiReserved);
+ pgpthdr->HDR_ui64HeaderLba = le64toh(pgpthdr->HDR_ui64HeaderLba);
+ pgpthdr->HDR_ui64BackupLba = le64toh(pgpthdr->HDR_ui64BackupLba);
+ pgpthdr->HDR_ui64FirstLba = le64toh(pgpthdr->HDR_ui64FirstLba);
+ pgpthdr->HDR_ui64LastLba = le64toh(pgpthdr->HDR_ui64LastLba);
+ pgpthdr->HDR_ui64Entrieslba = le64toh(pgpthdr->HDR_ui64Entrieslba);
+ pgpthdr->HDR_uiEntriesCount = le32toh(pgpthdr->HDR_uiEntriesCount);
+ pgpthdr->HDR_uiEntriesSize = le32toh(pgpthdr->HDR_uiEntriesSize);
+
+ for (i = 0; i < pgpthdr->HDR_uiEntriesCount; i++, pentry++) { /* 遍历分区表直至非法表项 */
+ pentry->ENT_ui64FirstLba = le64toh(pentry->ENT_ui64FirstLba);
+ pentry->ENT_ui64LastLba = le64toh(pentry->ENT_ui64LastLba);
+ pentry->ENT_ui64Attr = le64toh(pentry->ENT_ui64Attr);
+
+ for (j = 0; j < GPT_MAX_NAMELEN; j++) {
+ pentry->ENT_usName[j] = le16toh(pentry->ENT_usName[j]);
+ }
+
+ if (pentry->ENT_ui64FirstLba == 0) {
+ break;
+ }
+ }
+
+ pgpthdr->HDR_uiEntriesCount = i; /* 设置分区表项数为有效项数 */
+}
+/*********************************************************************************************************
+** 函数名称: __gptVerify
+** 功能描述: 校验 GPT crc
+** 输 入 : pgpt GPT 内存结构指针
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __gptVerify (GPT_TABLE *pgpt)
+{
+ GPT_HEADER *pgpthdr = &pgpt->GPT_header;
+ UINT32 uiCrc;
+ UINT32 uiCrcCalc;
+ UINT32 uiCrcEntries;
+ UINT32 uiEntriesCount;
+
+ uiCrc = pgpthdr->HDR_uiCrc32; /* 备份 crc */
+ pgpthdr->HDR_uiCrc32 = 0; /* 计算前需将表头 crc 置0 */
+
+ uiCrcCalc = __gptCrc32((UINT8 *)pgpthdr, sizeof(GPT_HEADER)); /* 比较表头 crc */
+ if (uiCrc != uiCrcCalc) {
+ _DebugFormat(__ERRORMESSAGE_LEVEL, "Gpt header crc error : %08x %08x\n",
+ uiCrc, uiCrcCalc);
+ return (PX_ERROR);
+ }
+
+ uiEntriesCount = le32toh(pgpthdr->HDR_uiEntriesCount); /* 获取分区表项数用于计算大小 */
+ uiCrcEntries = __gptCrc32((UINT8 *)pgpt->GPT_entry, uiEntriesCount * sizeof(GPT_ENTRY));
+ if (pgpthdr->HDR_uiEntriesCrc32 != uiCrcEntries) {
+ _DebugFormat(__ERRORMESSAGE_LEVEL, "Gpt entries crc error : %08x %08x\n",
+ pgpthdr->HDR_uiEntriesCrc32, uiCrcEntries);
+ return (PX_ERROR);
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: API_GptPartitionSave
+** 功能描述: 保存 GPT 表到块设备
+** 输 入 : iBlkFd 块设备文件描述符
+** pgpt GPT 内存结构指针
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT API_GptPartitionSave (INT iBlkFd, GPT_TABLE *pgpt)
+{
+ GPT_HEADER gpthdrBakup;
+ GPT_HEADER *pgpthdr;
+
+ if (!pgpt || (pgpt->GPT_header.HDR_uiVersion == 0)) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ pgpthdr = &pgpt->GPT_header;
+ gpthdrBakup = (*pgpthdr);
+
+ __gptSerial(pgpt); /* 序列化分区表结构 */
+
+ if (pwrite(iBlkFd, pgpt->GPT_ucMbr,
+ pgpt->GPT_uiSecSize, 0) != pgpt->GPT_uiSecSize) { /* 写入 MBR */
+ _ErrorHandle(EIO);
+ __gptUnserial(pgpt);
+ return (PX_ERROR);
+ }
+
+ if (pwrite(iBlkFd, pgpt->GPT_ucBlock, pgpt->GPT_uiSecSize,
+ (gpthdrBakup.HDR_ui64HeaderLba * pgpt->GPT_uiSecSize)) != pgpt->GPT_uiSecSize) {
+ /* 写入 GPT 分区表头 */
+ _ErrorHandle(EIO);
+ __gptUnserial(pgpt);
+ return (PX_ERROR);
+ }
+
+ if (pwrite(iBlkFd, pgpt->GPT_ucBlock, pgpt->GPT_uiSecSize,
+ (gpthdrBakup.HDR_ui64BackupLba * pgpt->GPT_uiSecSize)) != pgpt->GPT_uiSecSize) {
+ /* 写入 GPT 备份分区表头 */
+ _ErrorHandle(EIO);
+ __gptUnserial(pgpt);
+ return (PX_ERROR);
+ }
+
+ if (pwrite(iBlkFd, pgpt->GPT_entry, sizeof(pgpt->GPT_entry),
+ (gpthdrBakup.HDR_ui64Entrieslba * pgpt->GPT_uiSecSize)) != sizeof(pgpt->GPT_entry)) {
+ /* 写入 GPT 分区表项 */
+ _ErrorHandle(EIO);
+ __gptUnserial(pgpt);
+ return (PX_ERROR);
+ }
+
+ if (pwrite(iBlkFd, pgpt->GPT_entry, sizeof(pgpt->GPT_entry),
+ (gpthdrBakup.HDR_ui64LastLba * pgpt->GPT_uiSecSize)) != sizeof(pgpt->GPT_entry)) {
+ /* 写入 GPT 备份分区表头 */
+ _ErrorHandle(EIO);
+ __gptUnserial(pgpt);
+ return (PX_ERROR);
+ }
+
+ /*
+ * 一般情况下 GPT 内存结构在保存后会被销毁,为防万一,这里逆序列化 GPT 内存结构,以便后续使用
+ */
+ __gptUnserial(pgpt);
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: API_GptPartitionLoad
+** 功能描述: 通过块设备文件句柄加载 GPT 表到块设备
+** 输 入 : iBlkFd 块设备文件描述符
+** pgpt GPT 内存结构指针
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT API_GptPartitionLoad (INT iBlkFd, GPT_TABLE *pgpt)
+{
+ if (!pgpt) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ if (pread(iBlkFd, pgpt->GPT_ucMbr,
+ pgpt->GPT_uiSecSize, 0) != pgpt->GPT_uiSecSize) { /* 读取 MBR */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (pgpt->GPT_ucMbr[0x1c2] != 0xee) { /* 类型标识错误 */
+ return (PX_ERROR);
+ }
+
+ if (pread(iBlkFd, pgpt->GPT_ucBlock, pgpt->GPT_uiSecSize,
+ (1 * pgpt->GPT_uiSecSize)) != pgpt->GPT_uiSecSize) { /* 读取 GPT 分区表头 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (pread(iBlkFd, (UINT8 *)pgpt->GPT_entry, sizeof(pgpt->GPT_entry),
+ (2 * pgpt->GPT_uiSecSize)) != sizeof(pgpt->GPT_entry)) { /* 读取分区表项 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (__gptVerify(pgpt) != ERROR_NONE) { /* fdisk 命令不做恢复 */
+ return (PX_ERROR);
+ }
+
+ __gptUnserial(pgpt);
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
+** 函数名称: API_GptPartitionLoad
+** 功能描述: 通过块设备文件句柄加载 GPT 表到块设备
+** 输 入 : pblkd 块设备指针
+** pgpt GPT 内存结构指针
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+INT API_GptPartitionBlkLoad (PLW_BLK_DEV pblkd, GPT_TABLE *pgpt)
+{
+ if (!pgpt) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ if (pblkd->BLKD_pfuncBlkRd(pblkd, pgpt->GPT_ucMbr,
+ 0, 1) != ERROR_NONE) { /* 读取 MBR */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (pgpt->GPT_ucMbr[0x1c2] != 0xee) { /* 类型标识错误 */
+ return (PX_ERROR);
+ }
+
+ if (pblkd->BLKD_pfuncBlkRd(pblkd, pgpt->GPT_ucBlock,
+ GPT_HEAD_LBA, GPT_HEAD_LBA_CNT) != ERROR_NONE) {
+ /* 读取 GPT 分区表头 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (pblkd->BLKD_pfuncBlkRd(pblkd, (UINT8 *)pgpt->GPT_entry,
+ GPT_ENT_LBA, GPT_ENT_LBA_CNT) != ERROR_NONE) {
+ /* 读取分区表项 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (__gptVerify(pgpt) != ERROR_NONE) {
+ /*
+ * 从备份数据区读取并恢复 GPT 分区表信息
+ */
+ if (pblkd->BLKD_pfuncBlkRd(pblkd,
+ pgpt->GPT_ucBlock,
+ (pblkd->BLKD_ulNSector - GPT_HEAD_LBA_CNT),
+ GPT_HEAD_LBA_CNT) != ERROR_NONE) { /* 读取 GPT 备份分区表头 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (pblkd->BLKD_pfuncBlkWrt(pblkd, pgpt->GPT_ucBlock,
+ GPT_HEAD_LBA, GPT_HEAD_LBA_CNT) != ERROR_NONE) {
+ /* 恢复 GPT 分区表头 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (pblkd->BLKD_pfuncBlkRd(pblkd,
+ (UINT8 *)pgpt->GPT_entry,
+ (pblkd->BLKD_ulNSector - GPT_ENT_LBA_CNT - GPT_ENT_LBA_CNT),
+ GPT_ENT_LBA_CNT) != ERROR_NONE) { /* 读取备份分区表项 */
+
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (pblkd->BLKD_pfuncBlkWrt(pblkd, (UINT8 *)pgpt->GPT_entry,
+ GPT_ENT_LBA, GPT_ENT_LBA_CNT) != ERROR_NONE) {
+ /* 恢复分区表项 */
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+
+ if (__gptVerify(pgpt) != ERROR_NONE) {
+ _ErrorHandle(EIO);
+ return (PX_ERROR);
+ }
+ }
+
+ __gptUnserial(pgpt);
+
+ return (ERROR_NONE);
+}
+
+#endif /* (LW_CFG_MAX_VOLUMES > 0) */
+ /* (LW_CFG_DISKPART_EN > 0) */
+ /* LW_CFG_CPU_WORD_LENGHT > 32 */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/fs/diskPartition/gptPartition.h b/SylixOS/fs/diskPartition/gptPartition.h
new file mode 100644
index 0000000..21c5e8b
--- /dev/null
+++ b/SylixOS/fs/diskPartition/gptPartition.h
@@ -0,0 +1,115 @@
+/*********************************************************************************************************
+**
+** 中国软件开源组织
+**
+** 嵌入式实时操作系统
+**
+** SylixOS(TM) LW : long wing
+**
+** Copyright All Rights Reserved
+**
+**--------------文件信息--------------------------------------------------------------------------------
+**
+** 文 件 名: gptPartition.h
+**
+** 创 建 人: Jiang.Taijin (蒋太金)
+**
+** 文件创建日期: 2021 年 06 月 19 日
+**
+** 描 述: GPT 分区表分析.
+*********************************************************************************************************/
+
+#ifndef __GPTPARTITION_H
+#define __GPTPARTITION_H
+
+/*********************************************************************************************************
+ 裁剪宏
+*********************************************************************************************************/
+#if (LW_CFG_MAX_VOLUMES > 0) && (LW_CFG_DISKPART_EN > 0) && (LW_CFG_CPU_WORD_LENGHT > 32)
+/*********************************************************************************************************
+ GPT 分区相关宏定义
+*********************************************************************************************************/
+#define GPT_VERSION 0x00010000 /* GPT 表版本号 */
+#define GPT_MAGIC "EFI PART" /* GPT 表标识 */
+#define GPT_MAX_ENTRIES 128 /* 最大分区数 */
+#define GPT_MAX_NAMELEN 36 /* 最大分区名长度 */
+#define GPT_MAX_SECSIZE 4096 /* 支持的最大逻辑块大小 */
+#define GPT_DATA_LBA 34 /* 数据起始逻辑块 */
+#define GPT_HEAD_LBA 1 /* GPT 头逻辑块号 */
+#define GPT_HEAD_LBA_CNT 1 /* GPT 头占用的逻辑块数量 */
+#define GPT_ENT_LBA 2 /* GPT 分区表起始逻辑块 */
+#define GPT_ENT_LBA_CNT 32 /* GPT 分区表逻辑块数量 */
+/*********************************************************************************************************
+ GPT 分区表头
+*********************************************************************************************************/
+LW_STRUCT_PACK_BEGIN
+typedef struct {
+ LW_STRUCT_PACK_FIELD(UINT8 HDR_ucMagic[8]); /* GPT 表标识 */
+ LW_STRUCT_PACK_FIELD(UINT32 HDR_uiVersion); /* GPT 表版本号 */
+ LW_STRUCT_PACK_FIELD(UINT32 HDR_uiHeadSz); /* GPT 表头大小 */
+ LW_STRUCT_PACK_FIELD(UINT32 HDR_uiCrc32); /* GPT 表头 crc */
+ LW_STRUCT_PACK_FIELD(UINT32 HDR_uiReserved); /* 保留字段 */
+
+ LW_STRUCT_PACK_FIELD(UINT64 HDR_ui64HeaderLba); /* GPT 表头逻辑块号 */
+ LW_STRUCT_PACK_FIELD(UINT64 HDR_ui64BackupLba); /* GPT 备份表头逻辑块号 */
+ LW_STRUCT_PACK_FIELD(UINT64 HDR_ui64FirstLba); /* GPT 数据区起始块 */
+ LW_STRUCT_PACK_FIELD(UINT64 HDR_ui64LastLba); /* GPT 数据区结束块 */
+
+ LW_STRUCT_PACK_FIELD(UINT8 HDR_ucVolumeUuid[16]); /* 块设备 UUID */
+
+ LW_STRUCT_PACK_FIELD(UINT64 HDR_ui64Entrieslba); /* GPT 分区表起始逻辑块 */
+ LW_STRUCT_PACK_FIELD(UINT32 HDR_uiEntriesCount); /* GPT 分区表项数 */
+ LW_STRUCT_PACK_FIELD(UINT32 HDR_uiEntriesSize); /* GPT 分区表项大小 */
+ LW_STRUCT_PACK_FIELD(UINT32 HDR_uiEntriesCrc32); /* GPT 分区表CRC */
+} LW_STRUCT_PACK_STRUCT GPT_HEADER;
+LW_STRUCT_PACK_END
+/*********************************************************************************************************
+ GPT 分区表项
+*********************************************************************************************************/
+LW_STRUCT_PACK_BEGIN
+typedef struct {
+ LW_STRUCT_PACK_FIELD(UINT8 ENT_ucTypeUuid[16]); /* 分区类型 UUID */
+ LW_STRUCT_PACK_FIELD(UINT8 ENT_ucUniqUuid[16]); /* 分区标识 UUID */
+ LW_STRUCT_PACK_FIELD(UINT64 ENT_ui64FirstLba); /* 分区起始逻辑块号 */
+ LW_STRUCT_PACK_FIELD(UINT64 ENT_ui64LastLba); /* 分区结束逻辑块号 */
+ LW_STRUCT_PACK_FIELD(UINT64 ENT_ui64Attr); /* 分区属性 */
+ LW_STRUCT_PACK_FIELD(UINT16 ENT_usName[GPT_MAX_NAMELEN]); /* 分区名称 */
+} LW_STRUCT_PACK_STRUCT GPT_ENTRY;
+LW_STRUCT_PACK_END
+/*********************************************************************************************************
+ GPT 内存结构
+*********************************************************************************************************/
+
+typedef struct {
+ UINT GPT_uiSecSize; /* 扇区大小 */
+ UINT8 GPT_ucMbr[GPT_MAX_SECSIZE]; /* MBR 信息 */
+ union {
+ GPT_HEADER GPT_header; /* GPT 表头 */
+ UINT8 GPT_ucBlock[GPT_MAX_SECSIZE]; /* GPT 表头对应扇区数据 */
+ };
+ GPT_ENTRY GPT_entry[GPT_MAX_ENTRIES]; /* GPT 分区表项数组 */
+} GPT_TABLE;
+
+GPT_TABLE *API_GptCreateAndInit(UINT ulSecSize, UINT64 uiSecCnt); /* 分配和初始化 GPT 内存结构 */
+
+VOID API_GptDestroy(GPT_TABLE *pgpt); /* 销毁 GPT 内存结构 */
+
+INT API_GptAddEntry(GPT_TABLE *pgpt, UINT64 ui64LbaNum,
+ UINT64 ui64LbaCnt, UINT8 ucPartType); /* 添加 GPT 表项 */
+
+INT API_GptGetEntry(GPT_TABLE *pgpt, INT iIndex, UINT64 *ui64LbaNum,
+ UINT64 *pui64LbaCnt, UINT8 *pucPartType); /* 获取 GPT 表项 */
+
+INT API_GptPartitionSave(INT iBlkFd, GPT_TABLE *pgpt); /* 保存 GPT 表到块设备 */
+
+INT API_GptPartitionLoad(INT iBlkFd, GPT_TABLE *pgpt); /* 从块设备加载 GPT 表 */
+
+INT API_GptPartitionBlkLoad(PLW_BLK_DEV pblkd, GPT_TABLE *pgpt); /* 从块设备加载 GPT 表 */
+
+#endif /* (LW_CFG_MAX_VOLUMES > 0) */
+ /* (LW_CFG_DISKPART_EN > 0) */
+ /* LW_CFG_CPU_WORD_LENGHT > 32 */
+#endif /* __GPTPARTITION_H */
+/*********************************************************************************************************
+ END
+*********************************************************************************************************/
diff --git a/SylixOS/fs/fatFs/fatFs.c b/SylixOS/fs/fatFs/fatFs.c
index 011cf56..94d8241 100644
--- a/SylixOS/fs/fatFs/fatFs.c
+++ b/SylixOS/fs/fatFs/fatFs.c
@@ -1452,7 +1452,16 @@ static INT __fatFsClusterSizeCal (PFAT_FILE pfatfile, ULONG *pulClusterSize)
return (PX_ERROR);
}
- if (ulSecNum >= 0x800000) { /* 4 GB 以上磁盘 */
+ if (ulSecNum >= 0x4000000) { /* 32 GB 以上磁盘 */
+ *pulClusterSize = 64 * __FAT_CLUSTER_CAL_BASE(ulSecSize);
+
+ } else if (ulSecNum >= 0x2000000) { /* 16 GB 以上磁盘 */
+ *pulClusterSize = 32 * __FAT_CLUSTER_CAL_BASE(ulSecSize);
+
+ } else if (ulSecNum >= 0x1000000) { /* 8 GB 以上磁盘 */
+ *pulClusterSize = 16 * __FAT_CLUSTER_CAL_BASE(ulSecSize);
+
+ } else if (ulSecNum >= 0x800000) { /* 4 GB 以上磁盘 */
*pulClusterSize = 8 * __FAT_CLUSTER_CAL_BASE(ulSecSize);
} else if (ulSecNum >= 0x200000) { /* 1 GB 以上磁盘 */
@@ -1531,12 +1540,12 @@ static INT __fatFsFormat (PLW_FD_ENTRY pfdentry, LONG lArg)
if (__blockIoDevIsLogic(pfatfile->FATFIL_pfatvol->FATVOL_iDrv)) {
fresError = f_mkfs((BYTE)pfatfile->FATFIL_pfatvol->FATVOL_iDrv,
(BYTE)(FM_SFD | FM_FAT | FM_FAT32),
- (UINT16)ulClusterSize,
+ (UINT32)ulClusterSize,
pvWork, _MAX_SS); /* 此磁盘为逻辑磁盘不需要分区表*/
} else {
fresError = f_mkfs((BYTE)pfatfile->FATFIL_pfatvol->FATVOL_iDrv,
(BYTE)(FM_FAT | FM_FAT32),
- (UINT16)ulClusterSize,
+ (UINT32)ulClusterSize,
pvWork, _MAX_SS); /* 格式化带有分区表 */
}
diff --git a/SylixOS/fs/include/fs_fs.h b/SylixOS/fs/include/fs_fs.h
index ccc1d3c..1a669d2 100644
--- a/SylixOS/fs/include/fs_fs.h
+++ b/SylixOS/fs/include/fs_fs.h
@@ -79,6 +79,9 @@
DISK PARTITION
*********************************************************************************************************/
#include "../SylixOS/fs/diskPartition/diskPartition.h" /* 磁盘分区表 */
+#if LW_CFG_CPU_WORD_LENGHT > 32 /* 64 位 CPU 使能 GPT 分区 */
+#include "../SylixOS/fs/diskPartition/gptPartition.h" /* GPT 分区表 */
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
/*********************************************************************************************************
BLOCK DISK CACHE
*********************************************************************************************************/
diff --git a/SylixOS/fs/oemDisk/oemDisk.c b/SylixOS/fs/oemDisk/oemDisk.c
index 1d21398..6a69c8f 100644
--- a/SylixOS/fs/oemDisk/oemDisk.c
+++ b/SylixOS/fs/oemDisk/oemDisk.c
@@ -415,6 +415,7 @@ __refined_seq:
case LW_DISK_PART_TYPE_WIN95_FAT32:
case LW_DISK_PART_TYPE_WIN95_FAT32LBA:
case LW_DISK_PART_TYPE_WIN95_FAT16LBA:
+ case LW_DISK_PART_TYPE_EFI:
if (bForceFsType) { /* 是否强制指定文件系统类型 */
pfuncFsCreate = __fsCreateFuncGet(pcFsName,
poemd->OEMDISK_pblkdPart[i],
@@ -726,6 +727,7 @@ __refined_seq:
case LW_DISK_PART_TYPE_WIN95_FAT32:
case LW_DISK_PART_TYPE_WIN95_FAT32LBA:
case LW_DISK_PART_TYPE_WIN95_FAT16LBA:
+ case LW_DISK_PART_TYPE_EFI:
pfuncFsCreate = __fsCreateFuncGet("vfat", /* 查询 VFAT 文件系统装载函数 */
poemd->OEMDISK_pblkdPart[i],
dptPart.DPT_dpoLogic[i].DPO_dpnEntry.DPN_ucPartType);
@@ -1049,6 +1051,7 @@ __refined_seq:
case LW_DISK_PART_TYPE_WIN95_FAT32:
case LW_DISK_PART_TYPE_WIN95_FAT32LBA:
case LW_DISK_PART_TYPE_WIN95_FAT16LBA:
+ case LW_DISK_PART_TYPE_EFI:
pfuncFsCreate = __fsCreateFuncGet("vfat", /* 查询 VFAT 文件系统装载函数 */
poemd->OEMDISK_pblkdPart[i],
dptPart.DPT_dpoLogic[i].DPO_dpnEntry.DPN_ucPartType);
diff --git a/SylixOS/fs/oemDisk/oemFdisk.c b/SylixOS/fs/oemDisk/oemFdisk.c
index d66e519..9b54244 100644
--- a/SylixOS/fs/oemDisk/oemFdisk.c
+++ b/SylixOS/fs/oemDisk/oemFdisk.c
@@ -189,19 +189,114 @@ static INT __oemFdisk (INT iBlkFd,
return ((INT)i);
}
/*********************************************************************************************************
-** 函数名称: API_OemFdisk
+** 函数名称: __oemGptFdisk
+** 功能描述: 对 OEM 磁盘设备进行 GPT 分区操作
+** 输 入 : iBlkFd 块设备文件描述符
+** ulSecSize 扇区大小
+** ulTotalSec 扇区总数
+** fdpPart 分区信息
+** uiNPart 分区个数
+** stAlign 分区对齐 (例如: SSD 需要 4K 对齐)
+** 输 出 : 分区个数
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+#if LW_CFG_CPU_WORD_LENGHT > 32
+
+static INT __oemGptFdisk (INT iBlkFd,
+ ULONG ulSecSize,
+ ULONG ulTotalSec,
+ const LW_OEMFDISK_PART fdpPart[],
+ UINT uiNPart,
+ size_t stAlign)
+{
+ UINT64 ui64PSecNext;
+ UINT64 ui64PStartSec;
+ UINT64 ui64lPNSec;
+ UINT64 ui64LeftSec;
+ INT i;
+ ULONG ulNSecPerMB = LW_CFG_MB_SIZE / ulSecSize;
+
+ GPT_TABLE *pgpt;
+
+ pgpt = API_GptCreateAndInit(ulSecSize, ulTotalSec);
+ if (!pgpt) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
+ return (PX_ERROR);
+ }
+
+ ui64PSecNext = pgpt->GPT_header.HDR_ui64FirstLba;
+ ui64LeftSec = pgpt->GPT_header.HDR_ui64LastLba - pgpt->GPT_header.HDR_ui64FirstLba;
+
+ for (i = 0; i < uiNPart; i++) { /* 确定分区 LBA 信息 */
+ ui64PStartSec = ui64PSecNext;
+ if (ui64PStartSec > pgpt->GPT_header.HDR_ui64LastLba) {
+ API_GptDestroy(pgpt);
+ return (PX_ERROR);
+ }
+
+ if (fdpPart[i].FDP_ucSzPct == 0) { /* 剩下所有 */
+ ui64lPNSec = ui64LeftSec;
+
+ } else if (fdpPart[i].FDP_ucSzPct > 100) { /* 按容量信息分配 */
+ ui64lPNSec = fdpPart[i].FDP_ulMBytes * ulNSecPerMB;
+
+ } else { /* 按百分比分配 */
+ ui64lPNSec = ulTotalSec;
+ ui64lPNSec = (ui64lPNSec * fdpPart[i].FDP_ucSzPct) / 100;
+ }
+
+ if ((ui64PStartSec + ui64lPNSec) > pgpt->GPT_header.HDR_ui64LastLba) {
+ ui64lPNSec = pgpt->GPT_header.HDR_ui64LastLba - ui64PStartSec;
+ }
+
+ ui64lPNSec = ROUND_DOWN(ui64lPNSec, (stAlign / ulSecSize)); /* 对齐的扇区个数 */
+ ui64LeftSec -= ui64lPNSec;
+ ui64PSecNext += ui64lPNSec;
+
+ if (API_GptAddEntry(pgpt, ui64PStartSec, ui64lPNSec,
+ fdpPart[i].FDP_ucPartType) != ERROR_NONE) { /* 添加到 GPT 分区表 */
+ API_GptDestroy(pgpt);
+ return (PX_ERROR);
+ }
+
+ if (fdpPart[i].FDP_ucSzPct == 0) {
+ i++;
+ break;
+ }
+ }
+
+ if (API_GptPartitionSave(iBlkFd, pgpt) != ERROR_NONE) { /* 写入分区表到块设备 */
+ API_GptDestroy(pgpt);
+ return (PX_ERROR);
+ }
+
+ API_GptDestroy(pgpt);
+
+ return ((INT)i);
+}
+
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
+/*********************************************************************************************************
+** 函数名称: API_OemFdiskEx
** 功能描述: 对 OEM 磁盘设备进行分区操作
** 输 入 : pcBlkDev 块设备文件 例如: /dev/blk/sata0
** fdpPart 分区参数
** uiNPart 分区参数个数
** stAlign 分区对齐 (例如: SSD 需要 4K 对齐)
+** bGpt 是否 GPT 分区
** 输 出 : 产生的分区个数, PX_ERROR 表示错误.
** 全局变量:
** 调用模块:
API 函数
*********************************************************************************************************/
LW_API
-INT API_OemFdisk (CPCHAR pcBlkDev, const LW_OEMFDISK_PART fdpPart[], UINT uiNPart, size_t stAlign)
+INT API_OemFdiskEx (CPCHAR pcBlkDev,
+ const LW_OEMFDISK_PART fdpPart[],
+ UINT uiNPart,
+ size_t stAlign,
+ BOOL bGpt)
{
INT i;
INT iBlkFd;
@@ -210,11 +305,24 @@ INT API_OemFdisk (CPCHAR pcBlkDev, const LW_OEMFDISK_PART fdpPart[], UINT ui
ULONG ulSecSize;
ULONG ulTotalSec;
- if (!pcBlkDev || !fdpPart || !uiNPart || (uiNPart > 4)) {
+ if (!pcBlkDev || !fdpPart || !uiNPart) {
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+
+ if (!bGpt && (uiNPart > 4)) {
_ErrorHandle(EINVAL);
return (PX_ERROR);
}
+#if LW_CFG_CPU_WORD_LENGHT == 32
+ if (bGpt) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "32bits CPU no support GPT partition.\r\n");
+ _ErrorHandle(EINVAL);
+ return (PX_ERROR);
+ }
+#endif /* LW_CFG_CPU_WORD_LENGHT == 32*/
+
if ((stAlign < 4096) || (stAlign & (stAlign - 1))) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "stAlign error.\r\n");
_ErrorHandle(EINVAL);
@@ -244,7 +352,7 @@ INT API_OemFdisk (CPCHAR pcBlkDev, const LW_OEMFDISK_PART fdpPart[], UINT ui
return (PX_ERROR);
}
- if (ulTotalSec < __DISK_PART_MINSEC) {
+ if (!bGpt && (ulTotalSec < __DISK_PART_OFFSEC)) {
close(iBlkFd);
_ErrorHandle(ENOSPC);
return (PX_ERROR);
@@ -267,7 +375,14 @@ INT API_OemFdisk (CPCHAR pcBlkDev, const LW_OEMFDISK_PART fdpPart[], UINT ui
}
uiNPart = i;
- iNCnt = __oemFdisk(iBlkFd, ulSecSize, ulTotalSec, fdpPart, uiNPart, stAlign);
+#if LW_CFG_CPU_WORD_LENGHT > 32
+ if (bGpt) { /* 以 GPT 格式对块设备分区 */
+ iNCnt = __oemGptFdisk(iBlkFd, ulSecSize, ulTotalSec, fdpPart, uiNPart, stAlign);
+ } else
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
+ {
+ iNCnt = __oemFdisk(iBlkFd, ulSecSize, ulTotalSec, fdpPart, uiNPart, stAlign);
+ }
if (iNCnt > 0) {
fsync(iBlkFd);
}
@@ -276,6 +391,26 @@ INT API_OemFdisk (CPCHAR pcBlkDev, const LW_OEMFDISK_PART fdpPart[], UINT ui
return (iNCnt);
}
/*********************************************************************************************************
+** 函数名称: API_OemFdisk
+** 功能描述: 对 OEM 磁盘设备进行分区操作
+** 输 入 : pcBlkDev 块设备文件 例如: /dev/blk/sata0
+** fdpPart 分区参数
+** uiNPart 分区参数个数
+** stAlign 分区对齐 (例如: SSD 需要 4K 对齐)
+** 输 出 : 产生的分区个数, PX_ERROR 表示错误.
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+INT API_OemFdisk (CPCHAR pcBlkDev,
+ const LW_OEMFDISK_PART fdpPart[],
+ UINT uiNPart,
+ size_t stAlign)
+{
+ return (API_OemFdiskEx(pcBlkDev, fdpPart, uiNPart, stAlign, LW_FALSE));
+}
+/*********************************************************************************************************
** 函数名称: __oemFdiskGet
** 功能描述: 获取 OEM 磁盘设备分区情况
** 输 入 : iBlkFd 块设备文件描述符
@@ -383,18 +518,73 @@ static INT __oemFdiskGet (INT iBlkFd,
}
}
/*********************************************************************************************************
+** 函数名称: __oemGptFdiskGet
+** 功能描述: 获取 OEM 磁盘设备 GPT 分区情况
+** 输 入 : iBlkFd 块设备文件描述符
+** fdpInfo 获取信息缓冲
+** uiNPart 缓冲区可保存分区信息个数
+** ulSecSize 扇区大小
+** 输 出 : 获取的分区个数
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+#if LW_CFG_CPU_WORD_LENGHT > 32
+
+static INT __oemGptFdiskGet (INT iBlkFd,
+ LW_OEMFDISK_PINFO fdpInfo[],
+ UINT uiNPart,
+ ULONG ulSecSize)
+{
+ UINT64 ui64PStartSec;
+ UINT64 ui64lPNSec;
+ INT i;
+
+ GPT_TABLE *pgpt;
+
+ pgpt = API_GptCreateAndInit(ulSecSize, 0);
+ if (!pgpt) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
+ return (PX_ERROR);
+ }
+
+ if (API_GptPartitionLoad(iBlkFd, pgpt) != ERROR_NONE) { /* 加载 GPT 分区信息 */
+ API_GptDestroy(pgpt);
+ return (PX_ERROR);
+ }
+
+ for (i = 0; i < pgpt->GPT_header.HDR_uiEntriesCount; i++) { /* 转换分区表 */
+ if (API_GptGetEntry(pgpt, i, &ui64PStartSec,
+ &ui64lPNSec, &fdpInfo[i].FDP_ucPartType) != ERROR_NONE) {
+ API_GptDestroy(pgpt);
+ return (PX_ERROR);
+ }
+
+ fdpInfo[i].FDP_bIsActive = LW_TRUE;
+ fdpInfo[i].FDP_u64Size = ((UINT64)ui64lPNSec * ulSecSize);
+ fdpInfo[i].FDP_u64Oft = ((UINT64)ui64PStartSec * ulSecSize);
+ }
+
+ API_GptDestroy(pgpt);
+
+ return (i);
+}
+
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
+/*********************************************************************************************************
** 函数名称: API_OemFdiskGet
** 功能描述: 获取 OEM 磁盘设备分区情况
** 输 入 : pcBlkDev 块设备文件 例如: /dev/blk/sata0
** fdpInfo 获取信息缓冲
** uiNPart 缓冲区可保存分区信息个数
+** pbGpt 返回是否 GPT 分区
** 输 出 : 获取的分区个数, PX_ERROR 表示错误.
** 全局变量:
** 调用模块:
API 函数
*********************************************************************************************************/
LW_API
-INT API_OemFdiskGet (CPCHAR pcBlkDev, LW_OEMFDISK_PINFO fdpInfo[], UINT uiNPart)
+INT API_OemFdiskGetEx (CPCHAR pcBlkDev, LW_OEMFDISK_PINFO fdpInfo[], UINT uiNPart, BOOL *pbGpt)
{
INT iBlkFd;
INT iNCnt;
@@ -422,12 +612,43 @@ INT API_OemFdiskGet (CPCHAR pcBlkDev, LW_OEMFDISK_PINFO fdpInfo[], UINT uiNP
ulSecSize = 512;
}
- iNCnt = __oemFdiskGet(iBlkFd, 0, 0, ulSecSize, 0, fdpInfo, uiNPart);
+#if LW_CFG_CPU_WORD_LENGHT > 32
+ iNCnt = __oemGptFdiskGet(iBlkFd, fdpInfo, uiNPart, ulSecSize); /* 首先尝试 GPT 分区格式扫描 */
+ if (iNCnt < 0) {
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
+ iNCnt = __oemFdiskGet(iBlkFd, 0, 0, ulSecSize, 0, fdpInfo, uiNPart);
+ if (pbGpt) {
+ *pbGpt = LW_FALSE;
+ }
+#if LW_CFG_CPU_WORD_LENGHT > 32
+ } else {
+ if (pbGpt) {
+ *pbGpt = LW_TRUE;
+ }
+ }
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
+
close(iBlkFd);
return (iNCnt);
}
/*********************************************************************************************************
+** 函数名称: API_OemFdiskGet
+** 功能描述: 获取 OEM 磁盘设备分区情况
+** 输 入 : pcBlkDev 块设备文件 例如: /dev/blk/sata0
+** fdpInfo 获取信息缓冲
+** uiNPart 缓冲区可保存分区信息个数
+** 输 出 : 获取的分区个数, PX_ERROR 表示错误.
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+LW_API
+INT API_OemFdiskGet (CPCHAR pcBlkDev, LW_OEMFDISK_PINFO fdpInfo[], UINT uiNPart)
+{
+ return (API_OemFdiskGetEx(pcBlkDev, fdpInfo, uiNPart, LW_NULL));
+}
+/*********************************************************************************************************
** 函数名称: __oemFdiskGetType
** 功能描述: 获得磁盘分区类型字段
** 输 入 : ucType 分区类型
@@ -496,6 +717,7 @@ static CPCHAR __oemFdiskGetType (UINT8 ucType)
case 0x94: return ("Amoeba bad block table Partition");
case 0x96: return ("ISO-9660 file system");
case 0x9c: return ("SylixOS True Power Safe Partition");
+ case 0x9d: return ("EFI Partition");
case 0xa0: return ("IBM Thinkpad hibernation Partition");
case 0xa5: return ("BSD/386 Partition");
case 0xa7: return ("NeXTSTEP 486 Partition");
@@ -549,6 +771,7 @@ INT API_OemFdiskShow (CPCHAR pcBlkDev)
INT i, iBlkFd;
PCHAR pcAct;
CPCHAR pcType;
+ BOOL bGpt;
fdpInfo = (PLW_OEMFDISK_PINFO)__SHEAP_ALLOC(sizeof(LW_OEMFDISK_PINFO) *
LW_CFG_MAX_DISKPARTS);
@@ -612,7 +835,7 @@ INT API_OemFdiskShow (CPCHAR pcBlkDev)
printf("block product : %s\n", blkinfo.BLKI_cProduct);
printf("block media : %s\n", blkinfo.BLKI_cMedia);
- iRet = API_OemFdiskGet(pcBlkDev, fdpInfo, LW_CFG_MAX_DISKPARTS);
+ iRet = API_OemFdiskGetEx(pcBlkDev, fdpInfo, LW_CFG_MAX_DISKPARTS, &bGpt);
if (iRet < ERROR_NONE) {
fprintf(stderr, "\ncan not analysis partition table: %s\n", lib_strerror(errno));
__SHEAP_FREE(fdpInfo);
@@ -624,7 +847,7 @@ INT API_OemFdiskShow (CPCHAR pcBlkDev)
return (iRet);
}
- printf("\npartition >>\n%s", pcPartInfo);
+ printf("\n%s partition >>\n%s", (bGpt ? "GPT" : "MBR"), pcPartInfo);
for (i = 0; i < iRet; i++) {
pcAct = (fdpInfo[i].FDP_bIsActive) ? "*" : "";
pcType = __oemFdiskGetType(fdpInfo[i].FDP_ucPartType);
diff --git a/SylixOS/fs/oemDisk/oemFdisk.h b/SylixOS/fs/oemDisk/oemFdisk.h
index e94448c..dc92e91 100644
--- a/SylixOS/fs/oemDisk/oemFdisk.h
+++ b/SylixOS/fs/oemDisk/oemFdisk.h
@@ -54,12 +54,18 @@ typedef LW_OEMFDISK_PINFO *PLW_OEMFDISK_PINFO;
API
*********************************************************************************************************/
-LW_API INT API_OemFdisk(CPCHAR pcBlkDev, const LW_OEMFDISK_PART fdpInfo[], UINT uiNPart, size_t stAlign);
+LW_API INT API_OemFdisk(CPCHAR pcBlkDev, const LW_OEMFDISK_PART fdpInfo[],
+ UINT uiNPart, size_t stAlign);
+LW_API INT API_OemFdiskEx(CPCHAR pcBlkDev, const LW_OEMFDISK_PART fdpInfo[],
+ UINT uiNPart, size_t stAlign, BOOL bGpt);
LW_API INT API_OemFdiskGet(CPCHAR pcBlkDev, LW_OEMFDISK_PINFO fdpInfo[], UINT uiNPart);
+LW_API INT API_OemFdiskGetEx(CPCHAR pcBlkDev, LW_OEMFDISK_PINFO fdpInfo[], UINT uiNPart, BOOL *pbGpt);
LW_API INT API_OemFdiskShow(CPCHAR pcBlkDev);
#define oemFdisk API_OemFdisk
+#define oemFdiskEx API_OemFdiskEx
#define oemFdiskGet API_OemFdiskGet
+#define oemFdiskGetEx API_OemFdiskGetEx
#define oemFdiskShow API_OemFdiskShow
#endif /* __OEMFDISK_H */
diff --git a/SylixOS/fs/rootFs/rootFsLib.c b/SylixOS/fs/rootFs/rootFsLib.c
index 301a47a..f46107c 100644
--- a/SylixOS/fs/rootFs/rootFsLib.c
+++ b/SylixOS/fs/rootFs/rootFsLib.c
@@ -436,7 +436,7 @@ INT API_RootFsMakeNode (CPCHAR pcName, INT iNodeType, INT iNodeOpt, INT iMo
}
} else if ((iNodeType == LW_ROOTFS_NODE_TYPE_SOCK) ||
- (iNodeType == LW_ROOTFS_NODE_TYPE_REG)) { /* socket or reg file */
+ (iNodeType == LW_ROOTFS_NODE_TYPE_REG)) { /* socket or reg file */
/*
* AF_UNIX 文件
*/
diff --git a/SylixOS/fs/tpsFs/tpsfs.c b/SylixOS/fs/tpsFs/tpsfs.c
index 8df9a17..70a2551 100644
--- a/SylixOS/fs/tpsFs/tpsfs.c
+++ b/SylixOS/fs/tpsFs/tpsfs.c
@@ -1387,7 +1387,7 @@ errno_t tpsFsChtime (PTPS_INODE pinode, struct utimbuf *utim)
errno_t tpsFsFlushInodes (PTPS_SUPER_BLOCK psb)
{
PTPS_INODE pinode = LW_NULL;
- INT iErr = ERROR_NONE;
+ errno_t iErr = ERROR_NONE;
if (LW_NULL == psb) {
return (EINVAL);
diff --git a/SylixOS/fs/tpsFs/tpsfs_sylixos.c b/SylixOS/fs/tpsFs/tpsfs_sylixos.c
index be304e0..75c07b4 100644
--- a/SylixOS/fs/tpsFs/tpsfs_sylixos.c
+++ b/SylixOS/fs/tpsFs/tpsfs_sylixos.c
@@ -55,6 +55,7 @@ typedef struct {
INT TPSVOL_iFlag; /* O_RDONLY or O_RDWR */
LW_HANDLE TPSVOL_hThreadFlush; /* 回写线程句柄 */
BOOL TPSVOL_bNeedExit; /* 是否需要退出线程 */
+ PUCHAR TPSVOL_pucZoreBuf; /* 清零缓冲区,用于文件扩充 */
} TPS_VOLUME;
typedef TPS_VOLUME *PTPS_VOLUME;
@@ -74,6 +75,10 @@ static INT _G_iTpsDrvNum = PX_ERROR;
*********************************************************************************************************/
#define __TPS_INODE_FLUSH_INTERVAL 2000
/*********************************************************************************************************
+ 16K 大小的清零缓冲区,用于扩充文件
+*********************************************************************************************************/
+#define __TPS_ZERO_BUFF_SIZE (1024 << 4)
+/*********************************************************************************************************
文件类型
*********************************************************************************************************/
#define __TPS_FILE_TYPE_NODE 0 /* open 打开文件 */
@@ -351,7 +356,13 @@ static INT __tpsFsDiskWrMeta (PTPS_DEV pdev, PUCHAR pucBuf, UINT64 ui64StartSec
blkrange.BLKM_ulSectorCnt = (ULONG)(uiSectorCnt);
blkrange.BLKM_pucBuf = pucBuf;
- return (__blockIoDevIoctl((INT)iDrv, FIOWRMETA, (LONG)&blkrange));
+ if (__blockIoDevIoctl((INT)iDrv, FIOWRMETA,
+ (LONG)&blkrange) != ERROR_NONE) { /* 兼容diskcache被禁用的情况 */
+ return (__tpsFsDiskWrite(pdev, pucBuf, ui64StartSector,
+ uiSectorCnt, LW_TRUE));
+ }
+
+ return (ERROR_NONE);
}
/*********************************************************************************************************
** 函数名称: __tpsFsDiskRdMeta
@@ -373,7 +384,13 @@ static INT __tpsFsDiskRdMeta (PTPS_DEV pdev, PUCHAR pucBuf, UINT64 ui64StartSec
blkrange.BLKM_ulSectorCnt = (ULONG)(uiSectorCnt);
blkrange.BLKM_pucBuf = pucBuf;
- return (__blockIoDevIoctl((INT)iDrv, FIORDMETA, (LONG)&blkrange));
+ if (__blockIoDevIoctl((INT)iDrv, FIORDMETA,
+ (LONG)&blkrange) != ERROR_NONE) { /* 兼容diskcache被禁用的情况 */
+ return (__tpsFsDiskRead(pdev, pucBuf,
+ ui64StartSector, uiSectorCnt));
+ }
+
+ return (ERROR_NONE);
}
/*********************************************************************************************************
** 函数名称: API_TpsFsDrvInstall
@@ -540,7 +557,8 @@ INT API_TpsFsDevCreate (PCHAR pcName, PLW_BLK_DEV pblkd)
(PTHREAD_START_ROUTINE)__tpsFsFlushThread,
&threadattr, LW_NULL);
/* 创建背景更新线程 */
- ptpsvol->TPSVOL_iFlag = pblkd->BLKD_iFlag;
+ ptpsvol->TPSVOL_iFlag = pblkd->BLKD_iFlag;
+ ptpsvol->TPSVOL_pucZoreBuf = LW_NULL;
if (iosDevAddEx(&ptpsvol->TPSVOL_devhdrHdr, pcName, _G_iTpsDrvNum, DT_DIR)
!= ERROR_NONE) { /* 安装文件系统设备 */
@@ -575,6 +593,10 @@ __error_handle:
__blockIoDevDelete(iBlkdIndex);
}
+ if (ptpsvol->TPSVOL_pucZoreBuf) {
+ __SHEAP_FREE(ptpsvol->TPSVOL_pucZoreBuf);
+ ptpsvol->TPSVOL_pucZoreBuf = LW_NULL;
+ }
__SHEAP_FREE(ptpsvol);
_ErrorHandle(iErr);
@@ -894,6 +916,10 @@ __re_umount_vol:
API_SemaphoreMDelete(&ptpsvol->TPSVOL_hVolLock); /* 删除卷锁 */
+ if (ptpsvol->TPSVOL_pucZoreBuf) {
+ __SHEAP_FREE(ptpsvol->TPSVOL_pucZoreBuf);
+ ptpsvol->TPSVOL_pucZoreBuf = LW_NULL;
+ }
__SHEAP_FREE(ptpsvol); /* 释放卷控制块 */
_DebugHandle(__LOGMESSAGE_LEVEL, "disk unmount ok.\r\n");
@@ -1153,6 +1179,88 @@ static ssize_t __tpsFsPRead (PLW_FD_ENTRY pfdentry,
return ((ssize_t)szReadNum);
}
/*********************************************************************************************************
+** 函数名称: __tpsFsExtendFile
+** 功能描述: 扩充文件长度,只能在 __TPS_FILE_LOCK 状态下调用
+** 输 入 : pfdentry 文件控制块
+** oftPos 目标长度
+** 输 出 : ERROR
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static INT __tpsFsExtendFile (PLW_FD_ENTRY pfdentry,
+ off_t oftPos)
+{
+ PLW_FD_NODE pfdnode = (PLW_FD_NODE)pfdentry->FDENTRY_pfdnode;
+ PTPS_FILE ptpsfile = (PTPS_FILE)pfdnode->FDNODE_pvFile;
+ PTPS_VOLUME ptpsvol = ptpsfile->TPSFIL_ptpsvol;
+ ino64_t inode64 = pfdnode->FDNODE_inode64;
+ size_t szWrite;
+ TPS_SIZE_T szWriteNum = 0;
+ struct statfs statfs;
+ size_t szExtend = oftPos - tpsFsGetSize(ptpsfile->TPSFIL_pinode);
+
+ tpsFsStatfs(ptpsfile->TPSFIL_pinode->IND_psb, &statfs);
+ if ((szExtend / statfs.f_bsize) > statfs.f_bfree) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "no space for extending file.\r\n");
+ _ErrorHandle(ENOSPC);
+ return (PX_ERROR);
+ }
+
+ while (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < oftPos) {
+ if (!ptpsvol->TPSVOL_pucZoreBuf) { /* 防止其它线程释放清零缓冲 */
+ ptpsvol->TPSVOL_pucZoreBuf = (PUCHAR)__SHEAP_ALLOC(__TPS_ZERO_BUFF_SIZE);
+ if (!ptpsvol->TPSVOL_pucZoreBuf) {
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
+ _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
+ return (PX_ERROR);
+ }
+ lib_bzero(ptpsvol->TPSVOL_pucZoreBuf, __TPS_ZERO_BUFF_SIZE);
+ }
+
+ szWrite = (size_t)min(__TPS_ZERO_BUFF_SIZE,
+ oftPos - tpsFsGetSize(ptpsfile->TPSFIL_pinode));
+ if (tpsFsWrite(ptpsfile->TPSFIL_pinode, ptpsvol->TPSVOL_pucZoreBuf,
+ tpsFsGetSize(ptpsfile->TPSFIL_pinode),
+ szWrite, &szWriteNum) != ERROR_NONE) {
+ break;
+ }
+
+ /*
+ * 释放锁再加锁,当扩展文件长度耗时很长时,给系统 kill 线程和 shell 运行的机会
+ * 此处需要使用 ptpsvol 加锁和解锁,因为 ptpsfile 可能在解锁过程中被删除
+ */
+ __TPS_VOL_UNLOCK(ptpsvol);
+ __TPS_VOL_LOCK(ptpsvol);
+
+ /*
+ * TODO: 这里可能发生卷被移除的情况, 暂时未处理.
+ */
+ if (API_IosFdNodeFind(ptpsvol->TPSVOL_plineFdNodeHeader,
+ LW_DEV_MAKE_STDEV(&ptpsvol->TPSVOL_devhdrHdr),
+ inode64) != pfdnode) { /* 文件在解锁期间被关闭 */
+ _DebugHandle(__ERRORMESSAGE_LEVEL, "file closed.\r\n");
+ _ErrorHandle(ERROR_IOS_INVALID_FILE_DESCRIPTOR);
+ __SHEAP_FREE(ptpsvol->TPSVOL_pucZoreBuf);
+ ptpsvol->TPSVOL_pucZoreBuf = LW_NULL;
+ return (PX_ERROR);
+ }
+ }
+
+ /*
+ * 释放内存,如果线程在上述解锁过程被杀死,则清零缓冲将被保持到下次调用本函数
+ */
+ __SHEAP_FREE(ptpsvol->TPSVOL_pucZoreBuf);
+ ptpsvol->TPSVOL_pucZoreBuf = LW_NULL;
+
+ pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
+ if (pfdnode->FDNODE_oftSize < oftPos) {
+ _ErrorHandle(ENOSPC);
+ return (PX_ERROR);
+ }
+
+ return (ERROR_NONE);
+}
+/*********************************************************************************************************
** 函数名称: __tpsFsWrite
** 功能描述: TPS FS write 操作
** 输 入 : pfdentry 文件控制块
@@ -1168,8 +1276,10 @@ static ssize_t __tpsFsWrite (PLW_FD_ENTRY pfdentry,
{
PLW_FD_NODE pfdnode = (PLW_FD_NODE)pfdentry->FDENTRY_pfdnode;
PTPS_FILE ptpsfile = (PTPS_FILE)pfdnode->FDNODE_pvFile;
+ PTPS_VOLUME ptpsvol = ptpsfile->TPSFIL_ptpsvol;
TPS_SIZE_T szWriteNum = 0;
errno_t iErr = ERROR_NONE;
+ off_t oftPos;
if (!pcBuffer) {
_ErrorHandle(EINVAL);
@@ -1190,43 +1300,24 @@ static ssize_t __tpsFsWrite (PLW_FD_ENTRY pfdentry,
if (pfdentry->FDENTRY_iFlag & O_APPEND) { /* 追加模式 */
pfdentry->FDENTRY_oftPtr = pfdnode->FDNODE_oftSize; /* 移动读写指针到末尾 */
}
+ oftPos = pfdentry->FDENTRY_oftPtr;
if (stNBytes) { /* 自动扩展文件 */
- if (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < pfdentry->FDENTRY_oftPtr) {
- UINT uiBufSize = ptpsfile->TPSFIL_pinode->IND_psb->SB_uiBlkSize;
- size_t szWrite;
- PUCHAR pucZoreBuf = (PUCHAR)__SHEAP_ALLOC(uiBufSize);
- if (pucZoreBuf == LW_NULL) {
- __TPS_FILE_UNLOCK(ptpsfile);
- _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
- _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
- return (PX_ERROR);
- }
-
- lib_bzero(pucZoreBuf, uiBufSize);
- while (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < pfdentry->FDENTRY_oftPtr) {
- szWrite = (size_t)min(uiBufSize, pfdentry->FDENTRY_oftPtr - tpsFsGetSize(ptpsfile->TPSFIL_pinode));
- if (tpsFsWrite(ptpsfile->TPSFIL_pinode, pucZoreBuf,
- tpsFsGetSize(ptpsfile->TPSFIL_pinode),
- szWrite, &szWriteNum) != ERROR_NONE) {
- break;
- }
- }
- __SHEAP_FREE(pucZoreBuf);
-
- pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
- if (pfdnode->FDNODE_oftSize < pfdentry->FDENTRY_oftPtr) {
- __TPS_FILE_UNLOCK(ptpsfile);
- _ErrorHandle(ENOSPC);
+ if (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < oftPos) {
+ if (__tpsFsExtendFile(pfdentry, oftPos) != ERROR_NONE) {
+ /*
+ * 需要使用 ptpsvol 释放锁,因为 ptpsfile 可能被删除
+ */
+ __TPS_VOL_UNLOCK(ptpsvol);
return (PX_ERROR);
}
}
iErr = tpsFsWrite(ptpsfile->TPSFIL_pinode, (PUCHAR)pcBuffer,
- pfdentry->FDENTRY_oftPtr, stNBytes, &szWriteNum);
+ oftPos, stNBytes, &szWriteNum);
if ((iErr == ERROR_NONE) && (szWriteNum > 0)) {
- pfdentry->FDENTRY_oftPtr += (off_t)szWriteNum; /* 更新文件指针 */
- pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
+ pfdentry->FDENTRY_oftPtr = oftPos + (off_t)szWriteNum; /* 更新文件指针 */
+ pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
}
}
@@ -1253,6 +1344,7 @@ static ssize_t __tpsFsPWrite (PLW_FD_ENTRY pfdentry,
{
PLW_FD_NODE pfdnode = (PLW_FD_NODE)pfdentry->FDENTRY_pfdnode;
PTPS_FILE ptpsfile = (PTPS_FILE)pfdnode->FDNODE_pvFile;
+ PTPS_VOLUME ptpsvol = ptpsfile->TPSFIL_ptpsvol;
TPS_SIZE_T szWriteNum = 0;
errno_t iErr = ERROR_NONE;
@@ -1274,31 +1366,11 @@ static ssize_t __tpsFsPWrite (PLW_FD_ENTRY pfdentry,
if (stNBytes) {
if (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < oftPos) { /* 自动扩展文件 */
- UINT uiBufSize = ptpsfile->TPSFIL_pinode->IND_psb->SB_uiBlkSize;
- size_t szWrite;
- PUCHAR pucZoreBuf = (PUCHAR)__SHEAP_ALLOC(uiBufSize);
- if (pucZoreBuf == LW_NULL) {
- __TPS_FILE_UNLOCK(ptpsfile);
- _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
- _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
- return (PX_ERROR);
- }
-
- lib_bzero(pucZoreBuf, uiBufSize);
- while (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < oftPos) {
- szWrite = (size_t)min(uiBufSize, oftPos - tpsFsGetSize(ptpsfile->TPSFIL_pinode));
- if (tpsFsWrite(ptpsfile->TPSFIL_pinode, pucZoreBuf,
- tpsFsGetSize(ptpsfile->TPSFIL_pinode),
- szWrite, &szWriteNum) != ERROR_NONE) {
- break;
- }
- }
- __SHEAP_FREE(pucZoreBuf);
-
- pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
- if (pfdnode->FDNODE_oftSize < oftPos) {
- __TPS_FILE_UNLOCK(ptpsfile);
- _ErrorHandle(ENOSPC);
+ if (__tpsFsExtendFile(pfdentry, oftPos) != ERROR_NONE) {
+ /*
+ * 需要使用 ptpsvol 释放锁,因为 ptpsfile 可能被删除
+ */
+ __TPS_VOL_UNLOCK(ptpsvol);
return (PX_ERROR);
}
}
@@ -1810,6 +1882,7 @@ static INT __tpsFsTruncate (PLW_FD_ENTRY pfdentry, off_t oftSize)
{
PLW_FD_NODE pfdnode = (PLW_FD_NODE)pfdentry->FDENTRY_pfdnode;
PTPS_FILE ptpsfile = (PTPS_FILE)pfdnode->FDNODE_pvFile;
+ PTPS_VOLUME ptpsvol = ptpsfile->TPSFIL_ptpsvol;
INT iError = ERROR_NONE;
errno_t iErr = ERROR_NONE;
@@ -1825,34 +1898,11 @@ static INT __tpsFsTruncate (PLW_FD_ENTRY pfdentry, off_t oftSize)
if (ptpsfile->TPSFIL_iFileType == __TPS_FILE_TYPE_NODE) {
if (oftSize > tpsFsGetSize(ptpsfile->TPSFIL_pinode)) { /* 自动扩展文件 */
- UINT uiBufSize = ptpsfile->TPSFIL_pinode->IND_psb->SB_uiBlkSize;
- size_t szWrite;
- TPS_SIZE_T szWriteNum;
- PUCHAR pucZoreBuf = (PUCHAR)__SHEAP_ALLOC(uiBufSize);
-
- if (pucZoreBuf == LW_NULL) {
- __TPS_FILE_UNLOCK(ptpsfile);
- _DebugHandle(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
- _ErrorHandle(ERROR_SYSTEM_LOW_MEMORY);
- return (PX_ERROR);
- }
-
- while (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < oftSize) {
- szWrite = (size_t)min(uiBufSize, oftSize -
- tpsFsGetSize(ptpsfile->TPSFIL_pinode));
- if (tpsFsWrite(ptpsfile->TPSFIL_pinode, pucZoreBuf,
- tpsFsGetSize(ptpsfile->TPSFIL_pinode),
- szWrite, &szWriteNum) != ERROR_NONE) {
- break;
- }
- }
-
- pfdnode->FDNODE_oftSize = tpsFsGetSize(ptpsfile->TPSFIL_pinode);
-
- __SHEAP_FREE(pucZoreBuf);
- if (tpsFsGetSize(ptpsfile->TPSFIL_pinode) < oftSize) {
- __TPS_FILE_UNLOCK(ptpsfile);
- _ErrorHandle(EFBIG);
+ if (__tpsFsExtendFile(pfdentry, oftSize) != ERROR_NONE) {
+ /*
+ * 需要使用 ptpsvol 释放锁,因为 ptpsfile 可能被删除
+ */
+ __TPS_VOL_UNLOCK(ptpsvol);
return (PX_ERROR);
}
diff --git a/SylixOS/include/arch/mips/inc/cpu.h b/SylixOS/include/arch/mips/inc/cpu.h
index c208e36..c8d2776 100644
--- a/SylixOS/include/arch/mips/inc/cpu.h
+++ b/SylixOS/include/arch/mips/inc/cpu.h
@@ -54,8 +54,9 @@
#define PRID_COMP_CAVIUM 0x0d0000
#define PRID_COMP_LOONGSON 0x140000
#define PRID_COMP_INGENIC_D0 0xd00000 /* JZ4740, JZ4750 */
-#define PRID_COMP_INGENIC_D1 0xd10000 /* JZ4770, JZ4775 */
+#define PRID_COMP_INGENIC_D1 0xd10000 /* JZ4770, JZ4775, X1000 */
#define PRID_COMP_INGENIC_E1 0xe10000 /* JZ4780 */
+#define PRID_COMP_INGENIC_13 0x130000 /* X2000 */
#define PRID_COMP_CETC 0xff0000
/*********************************************************************************************************
Assigned Processor ID (implementation) values for bits 15:8 of the PRId
@@ -132,6 +133,8 @@
These are the PRID's for when 23:16 == PRID_COMP_INGENIC
*********************************************************************************************************/
#define PRID_IMP_JZRISC 0x0200
+#define PRID_IMP_XBURST PRID_IMP_JZRISC
+#define PRID_IMP_XBURST2 0x2000
/*********************************************************************************************************
Particular Revision values for bits 7:0 of the PRId register.
*********************************************************************************************************/
diff --git a/SylixOS/kernel/cache/cache.c b/SylixOS/kernel/cache/cache.c
index 786a402..7d18dcf 100644
--- a/SylixOS/kernel/cache/cache.c
+++ b/SylixOS/kernel/cache/cache.c
@@ -146,7 +146,7 @@ extern VOID __ARCH_CACHE_INIT(CACHE_MODE uiInstruction, CACHE_MODE uiData, C
API 函数
*********************************************************************************************************/
LW_API
-LW_CACHE_OP *API_CacheGetLibBlock (VOID)
+LW_CACHE_OP *API_CacheGetLibBlock (VOID)
{
return (&_G_cacheopLib);
}
diff --git a/SylixOS/kernel/core/_CandTable.c b/SylixOS/kernel/core/_CandTable.c
index b0d048c..a3d3709 100644
--- a/SylixOS/kernel/core/_CandTable.c
+++ b/SylixOS/kernel/core/_CandTable.c
@@ -331,7 +331,7 @@ __can_not_cand:
}
/*********************************************************************************************************
** 函数名称: _CandTableTryDel
-** 功能描述: 试图从将一个不再就绪的候选线程从候选表中退出
+** 功能描述: 试图将一个不再就绪的候选线程从候选表中退出
** 输 入 : ptcb 就绪的线程
** ppcb 对应的优先级控制块
** 输 出 : NONE
diff --git a/SylixOS/kernel/core/_EventQueue.c b/SylixOS/kernel/core/_EventQueue.c
index e1c3ab7..583a4f2 100644
--- a/SylixOS/kernel/core/_EventQueue.c
+++ b/SylixOS/kernel/core/_EventQueue.c
@@ -111,7 +111,7 @@ VOID _AddTCBToEventPriority (PLW_CLASS_TCB ptcb,
}
/*********************************************************************************************************
** 函数名称: _DelTCBFromEventPriority
-** 功能描述: 从FIFO事件等待队列中删除一个线程
+** 功能描述: 从 PRIORITY 事件等待队列中删除一个线程
** 输 入 : ptcb 任务控制块
** pevent 事件控制块
** ppringList 等待队列
diff --git a/SylixOS/kernel/core/_HeapLib.c b/SylixOS/kernel/core/_HeapLib.c
index 33380ba..56a0764 100644
--- a/SylixOS/kernel/core/_HeapLib.c
+++ b/SylixOS/kernel/core/_HeapLib.c
@@ -281,7 +281,7 @@ VOID _HeapTraceFree (PLW_CLASS_HEAP pheap, PVOID pvMem)
__HEAP_TRACE_FREE(pheap, pvMem);
}
/*********************************************************************************************************
-** 函数名称: _HeapCtor
+** 函数名称: _HeapCtorEx
** 功能描述: 构造一个内存堆
** 输 入 : pheapToBuild 需要创建的堆
** pvStartAddress 起始内存地址
@@ -304,7 +304,7 @@ PLW_CLASS_HEAP _HeapCtorEx (PLW_CLASS_HEAP pheapToBuild,
stByteSize -= (size_t)(ulStartAlign - ulStart); /* 去掉前面的不对齐长度 */
}
- stByteSize = ROUND_DOWN(stByteSize, LW_CFG_HEAP_ALIGNMENT); /* 分段大小对其 */
+ stByteSize = ROUND_DOWN(stByteSize, LW_CFG_HEAP_ALIGNMENT); /* 分段大小对齐 */
psegment = (PLW_CLASS_SEGMENT)ulStartAlign; /* 第一个分段起始地址 */
_LIST_LINE_INIT_IN_CODE(psegment->SEGMENT_lineManage); /* 初始化第一个分段 */
diff --git a/SylixOS/kernel/core/_KernelHighLevelInit.c b/SylixOS/kernel/core/_KernelHighLevelInit.c
index f11c378..b3c6154 100644
--- a/SylixOS/kernel/core/_KernelHighLevelInit.c
+++ b/SylixOS/kernel/core/_KernelHighLevelInit.c
@@ -41,7 +41,7 @@ extern VOID _mpiInit(VOID); /* MPI
#endif /* LW_CFG_MPI_EN */
/*********************************************************************************************************
** 函数名称: _CreateIdleThread
-** 功能描述: 内核高层初始化
+** 功能描述: 建立空闲任务
** 输 入 : NONE
** 输 出 : NONE
** 全局变量:
@@ -51,13 +51,13 @@ extern VOID _mpiInit(VOID); /* MPI
static VOID _CreateIdleThread (VOID)
{
#if LW_CFG_SMP_EN > 0
- REGISTER INT i;
- LW_CLASS_CPUSET cpuset;
+ REGISTER INT i;
+ LW_CLASS_CPUSET cpuset;
#endif
- LW_CLASS_THREADATTR threadattr;
+ LW_CLASS_THREADATTR threadattr;
- threadattr.THREADATTR_pstkLowAddr = LW_NULL; /* 系统自行分配堆栈 */
+ threadattr.THREADATTR_pstkLowAddr = LW_NULL; /* 系统自行分配堆栈 */
threadattr.THREADATTR_stGuardSize = LW_CFG_THREAD_DEFAULT_GUARD_SIZE;
threadattr.THREADATTR_stStackByteSize = LW_CFG_THREAD_IDLE_STK_SIZE;
threadattr.THREADATTR_ucPriority = LW_PRIO_IDLE;
@@ -79,7 +79,7 @@ static VOID _CreateIdleThread (VOID)
API_ThreadAttrSetArg(&threadattr, (PVOID)(ULONG)i);
_K_ulIdleId[i] = API_ThreadInit(cIdle, _IdleThread, &threadattr, LW_NULL);
_K_ptcbIdle[i] = _K_ptcbTCBIdTable[_ObjectGetIndex(_K_ulIdleId[i])];
- _K_ptcbIdle[i]->TCB_ucSchedPolicy = LW_OPTION_SCHED_FIFO; /* idle 必须是 FIFO 调度器 */
+ _K_ptcbIdle[i]->TCB_ucSchedPolicy = LW_OPTION_SCHED_FIFO; /* idle 必须是 FIFO 调度器 */
LW_CPU_SET(i, &cpuset); /* 锁定到指定 CPU */
_ThreadSetAffinity(_K_ptcbIdle[i], sizeof(LW_CLASS_CPUSET), &cpuset);
@@ -91,13 +91,13 @@ static VOID _CreateIdleThread (VOID)
#else
_K_ulIdleId[0] = API_ThreadInit("t_idle", _IdleThread, &threadattr, LW_NULL);
_K_ptcbIdle[0] = _K_ptcbTCBIdTable[_ObjectGetIndex(_K_ulIdleId[0])];
- _K_ptcbIdle[0]->TCB_ucSchedPolicy = LW_OPTION_SCHED_FIFO; /* idle 必须是 FIFO 调度器 */
+ _K_ptcbIdle[0]->TCB_ucSchedPolicy = LW_OPTION_SCHED_FIFO; /* idle 必须是 FIFO 调度器 */
API_ThreadStart(_K_ulIdleId[0]);
-#endif /* LW_CFG_SMP_EN > 0 */
+#endif /* LW_CFG_SMP_EN > 0 */
}
/*********************************************************************************************************
** 函数名称: _CreateITimerThread
-** 功能描述: 内核高层初始化
+** 功能描述: 建立 ITIMER 任务
** 输 入 : NONE
** 输 出 : NONE
** 全局变量:
diff --git a/SylixOS/kernel/core/_Object.c b/SylixOS/kernel/core/_Object.c
index 0e20389..bbcc69c 100644
--- a/SylixOS/kernel/core/_Object.c
+++ b/SylixOS/kernel/core/_Object.c
@@ -35,7 +35,7 @@
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-LW_OBJECT_ID _MakeObjectId (UINT8 ucCls, UINT16 usNode, UINT16 usIndex)
+LW_OBJECT_ID _MakeObjectId (UINT8 ucCls, UINT16 usNode, UINT16 usIndex)
{
REGISTER ULONG ulId;
diff --git a/SylixOS/kernel/core/_ThreadInit.c b/SylixOS/kernel/core/_ThreadInit.c
index 6a07087..cdeba9e 100644
--- a/SylixOS/kernel/core/_ThreadInit.c
+++ b/SylixOS/kernel/core/_ThreadInit.c
@@ -364,12 +364,16 @@ VOID _TCBBuild (UINT8 ucPriority,
#if LW_CFG_CPU_FPU_EN > 0
ptcb->TCB_pvStackFP = &ptcb->TCB_fpuctxContext;
- __ARCH_FPU_CTX_INIT(ptcb->TCB_pvStackFP); /* 初始化当前任务 FPU 上下文 */
+ if (LW_CPU_FPU_IS_INITED()) {
+ __ARCH_FPU_CTX_INIT(ptcb->TCB_pvStackFP); /* 初始化当前任务 FPU 上下文 */
+ }
#endif /* LW_CFG_CPU_FPU_EN > 0 */
#if LW_CFG_CPU_DSP_EN > 0
ptcb->TCB_pvStackDSP = &ptcb->TCB_dspctxContext;
- __ARCH_DSP_CTX_INIT(ptcb->TCB_pvStackDSP); /* 初始化当前任务 DSP 上下文 */
+ if (LW_CPU_DSP_IS_INITED()) {
+ __ARCH_DSP_CTX_INIT(ptcb->TCB_pvStackDSP); /* 初始化当前任务 DSP 上下文 */
+ }
#endif /* LW_CFG_CPU_DSP_EN > 0 */
#if LW_CFG_NET_EN > 0 && LW_CFG_NET_SAFE > 0
diff --git a/SylixOS/kernel/core/_WakeupLine.c b/SylixOS/kernel/core/_WakeupLine.c
index 06c2b27..fa94eae 100644
--- a/SylixOS/kernel/core/_WakeupLine.c
+++ b/SylixOS/kernel/core/_WakeupLine.c
@@ -68,7 +68,7 @@ VOID _WakeupAdd (PLW_CLASS_WAKEUP pwu, PLW_CLASS_WAKEUP_NODE pwun, BOOL bPro
} else {
_List_Line_Add_Left(&pwun->WUN_lineManage, plineTemp); /* 不是表头则插在左边 */
}
- pwunTemp->WUN_ulCounter -= pwun->WUN_ulCounter; /* 右侧的点从新就算计数器 */
+ pwunTemp->WUN_ulCounter -= pwun->WUN_ulCounter; /* 右侧的点重新计算计数器 */
break;
}
}
diff --git a/SylixOS/kernel/include/k_class.h b/SylixOS/kernel/include/k_class.h
index d078d65..9fa38c3 100644
--- a/SylixOS/kernel/include/k_class.h
+++ b/SylixOS/kernel/include/k_class.h
@@ -260,7 +260,7 @@ typedef struct {
PVOID EVENT_pvTcbOwn; /* 占有资源的TCB指针 */
/* 可以在加入死锁检测机制 */
ULONG EVENT_ulCounter; /* 计数器值 */
- ULONG EVENT_ulMaxCounter; /* 最大技术值 */
+ ULONG EVENT_ulMaxCounter; /* 最大计数值 */
INT EVENT_iStatus;
#define EVENT_RW_STATUS_R 0
@@ -361,12 +361,12 @@ typedef LW_CLASS_NOTEPAD *PLW_CLASS_NOTEPAD;
*********************************************************************************************************/
typedef struct {
- LW_LIST_LINE PRIVATEVAR_lineVarList; /* 双向线表 */
- LW_LIST_MONO PRIVATEVAR_monoResrcList; /* 空闲资源表 */
+ LW_LIST_LINE PRIVATEVAR_lineVarList; /* 双向线表 */
+ LW_LIST_MONO PRIVATEVAR_monoResrcList; /* 空闲资源表 */
/* 为了快速计算 将 LW_LIST_LINE*/
/* 放在 0 偏移量上 */
- ULONG *PRIVATEVAR_pulAddress; /* 4/8 BYTE 私有化变量地址 */
- ULONG PRIVATEVAR_ulValueSave; /* 保存的变量的值 */
+ ULONG *PRIVATEVAR_pulAddress; /* 4/8 BYTE 私有化变量地址 */
+ ULONG PRIVATEVAR_ulValueSave; /* 保存的变量的值 */
} LW_CLASS_THREADVAR;
typedef LW_CLASS_THREADVAR *PLW_CLASS_THREADVAR;
@@ -376,13 +376,13 @@ typedef LW_CLASS_THREADVAR *PLW_CLASS_THREADVAR;
*********************************************************************************************************/
typedef struct {
- PLW_STACK THREADATTR_pstkLowAddr; /* 全部堆栈区低内存起始地址 */
- size_t THREADATTR_stGuardSize; /* 堆栈警戒区大小 */
- size_t THREADATTR_stStackByteSize; /* 全部堆栈区大小(字节) */
- UINT8 THREADATTR_ucPriority; /* 线程优先级 */
- ULONG THREADATTR_ulOption; /* 任务选项 */
- PVOID THREADATTR_pvArg; /* 线程参数 */
- PVOID THREADATTR_pvExt; /* 扩展数据段指针 */
+ PLW_STACK THREADATTR_pstkLowAddr; /* 全部堆栈区低内存起始地址 */
+ size_t THREADATTR_stGuardSize; /* 堆栈警戒区大小 */
+ size_t THREADATTR_stStackByteSize; /* 全部堆栈区大小(字节) */
+ UINT8 THREADATTR_ucPriority; /* 线程优先级 */
+ ULONG THREADATTR_ulOption; /* 任务选项 */
+ PVOID THREADATTR_pvArg; /* 线程参数 */
+ PVOID THREADATTR_pvExt; /* 扩展数据段指针 */
} LW_CLASS_THREADATTR;
typedef LW_CLASS_THREADATTR *PLW_CLASS_THREADATTR;
diff --git a/SylixOS/kernel/include/k_cpu.h b/SylixOS/kernel/include/k_cpu.h
index d52567f..6268acb 100644
--- a/SylixOS/kernel/include/k_cpu.h
+++ b/SylixOS/kernel/include/k_cpu.h
@@ -380,6 +380,18 @@ ULONG _CpuGetMaxNesting(VOID);
PLW_CLASS_CPU _CpuGetCur(VOID);
#endif /* __SYLIXOS_ARM_ARCH_M__ */
+/*********************************************************************************************************
+ FPU 与 DSP 初始化状态
+*********************************************************************************************************/
+
+#define LW_CPU_FPU_INITED() (_K_bFpuInited = LW_TRUE)
+#define LW_CPU_FPU_IS_INITED() (_K_bFpuInited)
+
+#if LW_CFG_CPU_DSP_EN > 0
+#define LW_CPU_DSP_INITED() (_K_bDspInited = LW_TRUE)
+#define LW_CPU_DSP_IS_INITED() (_K_bDspInited)
+#endif /* LW_CFG_CPU_DSP_EN > 0 */
+
#endif /* __SYLIXOS_KERNEL */
#endif /* __K_CPU_H */
/*********************************************************************************************************
diff --git a/SylixOS/kernel/include/k_globalvar.h b/SylixOS/kernel/include/k_globalvar.h
index 4718985..493e56b 100644
--- a/SylixOS/kernel/include/k_globalvar.h
+++ b/SylixOS/kernel/include/k_globalvar.h
@@ -282,6 +282,15 @@ __KERNEL_EXT LW_SPINLOCK_CA_DECLARE (_K_slcaAtomic); /* 原子
*********************************************************************************************************/
__KERNEL_EXT LW_CLASS_TCB _K_tcbDummy[LW_CFG_MAX_PROCESSORS];
/*********************************************************************************************************
+ FPU、DSP 是否已经初始化的标记
+*********************************************************************************************************/
+#if LW_CFG_CPU_FPU_EN > 0
+__KERNEL_EXT BOOL _K_bFpuInited; /* FPU 已经初始化 */
+#endif /* LW_CFG_CPU_FPU_EN > 0 */
+#if LW_CFG_CPU_DSP_EN > 0
+__KERNEL_EXT BOOL _K_bDspInited; /* DSP 已经初始化 */
+#endif /* LW_CFG_CPU_DSP_EN > 0 */
+/*********************************************************************************************************
系统 LOGO
*********************************************************************************************************/
#if LW_CFG_KERNEL_LOGO > 0
diff --git a/SylixOS/kernel/include/k_kernel.h b/SylixOS/kernel/include/k_kernel.h
index fa224af..ace44f9 100644
--- a/SylixOS/kernel/include/k_kernel.h
+++ b/SylixOS/kernel/include/k_kernel.h
@@ -52,8 +52,8 @@
*********************************************************************************************************/
#define __SYLIXOS_MAJOR_VER 2
-#define __SYLIXOS_MINOR_VER 1
-#define __SYLIXOS_PATCH_VER 6
+#define __SYLIXOS_MINOR_VER 2
+#define __SYLIXOS_PATCH_VER 0
#define __SYLIXOS_PATCH_PAD 0
/*********************************************************************************************************
diff --git a/SylixOS/kernel/include/k_timecvt.h b/SylixOS/kernel/include/k_timecvt.h
index 23faa34..71591f6 100644
--- a/SylixOS/kernel/include/k_timecvt.h
+++ b/SylixOS/kernel/include/k_timecvt.h
@@ -23,7 +23,7 @@
#define __K_TIMECVT_H
/*********************************************************************************************************
- time invald
+ time invalid
*********************************************************************************************************/
#define LW_NSEC_INVALD(nsec) (((nsec) < 0) || ((nsec) >= __TIMEVAL_NSEC_MAX))
diff --git a/SylixOS/kernel/inline/inlObject.h b/SylixOS/kernel/inline/inlObject.h
index 564c702..0fdc674 100644
--- a/SylixOS/kernel/inline/inlObject.h
+++ b/SylixOS/kernel/inline/inlObject.h
@@ -42,7 +42,7 @@ static LW_INLINE UINT16 _ObjectGetIndex (LW_OBJECT_ID ulId)
static LW_INLINE ULONG _ObjectGetNode (LW_OBJECT_ID ulId)
{
- return ((ULONG)((ulId >> 16) & 0x03ff));
+ return ((ULONG)((ulId >> 16) & 0x03ff));
}
/*********************************************************************************************************
diff --git a/SylixOS/kernel/interface/InterEnterExit.c b/SylixOS/kernel/interface/InterEnterExit.c
index 03e061b..4977c73 100644
--- a/SylixOS/kernel/interface/InterEnterExit.c
+++ b/SylixOS/kernel/interface/InterEnterExit.c
@@ -258,68 +258,6 @@ VOID API_InterExit (VOID)
#endif
}
/*********************************************************************************************************
-** 函数名称: API_InterExitFastInt
-** 功能描述: 内核 FIQ 中断出口函数 (在关中断的情况下被调用)
-** 输 入 : NONE
-** 输 出 : NONE
-** 全局变量:
-** 调用模块:
- API 函数
-*********************************************************************************************************/
-#if defined(LW_CFG_CPU_ARCH_CSKY)
-
-LW_API
-VOID API_InterExitFastInt (VOID)
-{
- PLW_CLASS_CPU pcpu;
-
- pcpu = LW_CPU_GET_CUR();
-
-#if LW_CFG_INTER_INFO > 0
- if (pcpu->CPU_ulInterNestingMax < pcpu->CPU_ulInterNesting) {
- pcpu->CPU_ulInterNestingMax = pcpu->CPU_ulInterNesting;
- }
-#endif /* LW_CFG_INTER_INFO > 0 */
-
- if (pcpu->CPU_ulInterNesting) { /* 系统中断嵌套层数-- */
- pcpu->CPU_ulInterNesting--;
- }
-
- if (pcpu->CPU_ulInterNesting) { /* 查看系统是否在中断嵌套中 */
-#if (LW_CFG_CPU_FPU_EN > 0) && (LW_CFG_INTER_FPU > 0) /* 恢复上一等级中断 FPU CTX */
- if (LW_KERN_FPU_EN_GET()) {
- __fpuInterExit(pcpu);
- }
-#endif /* LW_CFG_CPU_FPU_EN > 0 */
- /* LW_CFG_INTER_FPU > 0 */
-#if (LW_CFG_CPU_DSP_EN > 0) && (LW_CFG_INTER_DSP > 0) /* 恢复上一等级中断 DSP CTX */
- if (LW_KERN_DSP_EN_GET()) {
- __dspInterExit(pcpu);
- }
-#endif /* LW_CFG_CPU_DSP_EN > 0 */
- return; /* LW_CFG_INTER_DSP > 0 */
- }
-
- __KERNEL_SCHED_INT(pcpu); /* 中断中的调度 */
-
-#if (LW_CFG_CPU_FPU_EN > 0) && (LW_CFG_INTER_FPU > 0)
- if (LW_KERN_FPU_EN_GET()) {
- __fpuInterExit(pcpu);
- }
-#endif /* LW_CFG_CPU_FPU_EN > 0 */
- /* LW_CFG_INTER_FPU > 0 */
-#if (LW_CFG_CPU_DSP_EN > 0) && (LW_CFG_INTER_DSP > 0)
- if (LW_KERN_DSP_EN_GET()) {
- __dspInterExit(pcpu);
- }
-#endif /* LW_CFG_CPU_DSP_EN > 0 */
- /* LW_CFG_INTER_DSP > 0 */
-
- archFastIntCtxLoad(pcpu); /* 中断返回 (当前任务 CTX 加载)*/
-}
-
-#endif /* LW_CFG_CPU_ARCH_CSKY */
-/*********************************************************************************************************
** 函数名称: API_InterExitNoSched
** 功能描述: 内核中断出口函数 (在关中断的情况下被调用), 不进行任务调度, 供 ARMv7M 使用
** 输 入 : NONE
diff --git a/SylixOS/kernel/interface/KernelDsp.c b/SylixOS/kernel/interface/KernelDsp.c
index 0eed3dd..96a77b5 100644
--- a/SylixOS/kernel/interface/KernelDsp.c
+++ b/SylixOS/kernel/interface/KernelDsp.c
@@ -35,8 +35,10 @@
LW_API
VOID API_KernelDspPrimaryInit (CPCHAR pcMachineName, CPCHAR pcDspName)
{
+ REGISTER PLW_CLASS_TCB ptcb;
+ PLW_LIST_LINE plineList;
#if LW_CFG_INTER_DSP > 0
- INT i, j;
+ INT i, j;
#endif /* LW_CFG_INTER_DSP > 0 */
if (LW_SYS_STATUS_GET()) {
@@ -46,6 +48,16 @@ VOID API_KernelDspPrimaryInit (CPCHAR pcMachineName, CPCHAR pcDspName)
archDspPrimaryInit(pcMachineName, pcDspName); /* 初始化 DSP 单元 */
+ LW_CPU_DSP_INITED(); /* 标记 DSP 已经初始化 */
+
+ for (plineList = _K_plineTCBHeader;
+ plineList != LW_NULL;
+ plineList = _list_line_get_next(plineList)) {
+
+ ptcb = _LIST_ENTRY(plineList, LW_CLASS_TCB, TCB_lineManage);
+ __ARCH_DSP_CTX_INIT(ptcb->TCB_pvStackDSP); /* 初始化该任务 DSP 上下文 */
+ }
+
#if LW_CFG_INTER_DSP > 0
if (LW_KERN_DSP_EN_GET()) { /* 中断状态允许使用 DSP */
__ARCH_DSP_ENABLE(); /* 这里需要在当前 DSP 上下文中 */
diff --git a/SylixOS/kernel/interface/KernelFpu.c b/SylixOS/kernel/interface/KernelFpu.c
index 50d873b..a7149ea 100644
--- a/SylixOS/kernel/interface/KernelFpu.c
+++ b/SylixOS/kernel/interface/KernelFpu.c
@@ -35,8 +35,10 @@
LW_API
VOID API_KernelFpuPrimaryInit (CPCHAR pcMachineName, CPCHAR pcFpuName)
{
+ REGISTER PLW_CLASS_TCB ptcb;
+ PLW_LIST_LINE plineList;
#if LW_CFG_INTER_FPU > 0
- INT i, j;
+ INT i, j;
#endif /* LW_CFG_INTER_FPU > 0 */
if (LW_SYS_STATUS_GET()) {
@@ -45,7 +47,17 @@ VOID API_KernelFpuPrimaryInit (CPCHAR pcMachineName, CPCHAR pcFpuName)
}
archFpuPrimaryInit(pcMachineName, pcFpuName); /* 初始化 FPU 单元 */
-
+
+ LW_CPU_FPU_INITED(); /* 标记 FPU 已经初始化 */
+
+ for (plineList = _K_plineTCBHeader;
+ plineList != LW_NULL;
+ plineList = _list_line_get_next(plineList)) {
+
+ ptcb = _LIST_ENTRY(plineList, LW_CLASS_TCB, TCB_lineManage);
+ __ARCH_FPU_CTX_INIT(ptcb->TCB_pvStackFP); /* 初始化该任务 FPU 上下文 */
+ }
+
#if LW_CFG_INTER_FPU > 0
if (LW_KERN_FPU_EN_GET()) { /* 中断状态允许使用 FPU */
__ARCH_FPU_ENABLE(); /* 这里需要在当前 FPU 上下文中 */
diff --git a/SylixOS/kernel/interface/TimeSleep.c b/SylixOS/kernel/interface/TimeSleep.c
index 8bb85fb..3c2a4f2 100644
--- a/SylixOS/kernel/interface/TimeSleep.c
+++ b/SylixOS/kernel/interface/TimeSleep.c
@@ -333,11 +333,11 @@ INT nanosleep (const struct timespec *rqtp, struct timespec *rmtp)
PLW_CLASS_TCB ptcbCur;
REGISTER PLW_CLASS_PCB ppcb;
- REGISTER ULONG ulKernelTime;
- REGISTER INT iRetVal;
- INT iSchedRet;
-
- REGISTER ULONG ulError;
+ REGISTER ULONG ulKernelTime;
+ REGISTER INT iRetVal;
+ INT iSchedRet;
+
+ REGISTER ULONG ulError;
ULONG ulTick;
struct timespec tvStart;
@@ -496,11 +496,14 @@ UINT sleep (UINT uiSeconds)
if (tsEnd.tv_sec >= tsStart.tv_sec) {
uiPass = (UINT)(tsEnd.tv_sec - tsStart.tv_sec);
if (uiPass < uiSeconds) {
+ __THREAD_CANCEL_POINT(); /* 测试取消点 */
return (uiSeconds - uiPass);
}
}
}
+ __THREAD_CANCEL_POINT(); /* 测试取消点 */
+
return (0);
}
/*********************************************************************************************************
diff --git a/SylixOS/kernel/interface/TimerCancel.c b/SylixOS/kernel/interface/TimerCancel.c
index b950e4f..e47cb44 100644
--- a/SylixOS/kernel/interface/TimerCancel.c
+++ b/SylixOS/kernel/interface/TimerCancel.c
@@ -68,7 +68,7 @@ ULONG API_TimerCancel (LW_OBJECT_HANDLE ulId)
}
ptmr = &_K_tmrBuffer[usIndex];
-
+
iregInterLevel = KN_INT_DISABLE(); /* 关闭中断 */
if (ptmr->TIMER_ucStatus == LW_TIMER_STATUS_STOP) { /* 没有工作 */
diff --git a/SylixOS/kernel/resource/resourceLib.c b/SylixOS/kernel/resource/resourceLib.c
index c861c98..f655e5d 100644
--- a/SylixOS/kernel/resource/resourceLib.c
+++ b/SylixOS/kernel/resource/resourceLib.c
@@ -348,7 +348,7 @@ INT __resPidReclaim (pid_t pid)
}
#endif
-#if ((LW_CFG_HTIMER_EN > 0) || (LW_CFG_ITIMER_EN > 0)) && (LW_CFG_MAX_TIMERS > 0)
+#if ((LW_CFG_HTIMER_EN > 0) || (LW_CFG_ITIMER_EN > 0)) && (LW_CFG_MAX_TIMERS > 0)
for (i = 0; i < LW_CFG_MAX_TIMERS; i++) { /* 处理定时器 */
presh = &_G_reshTimerBuffer[i];
if ((presh->RESH_pid == pid) && !presh->RESH_bIsGlobal) {
diff --git a/SylixOS/kernel/vmm/pageTable.h b/SylixOS/kernel/vmm/pageTable.h
index 1077b0a..4bf3f4d 100644
--- a/SylixOS/kernel/vmm/pageTable.h
+++ b/SylixOS/kernel/vmm/pageTable.h
@@ -387,8 +387,8 @@ static LW_INLINE VOID __vmm_pgd_free (LW_PGD_TRANSENTRY *p_pgdentry)
}
static LW_INLINE LW_PMD_TRANSENTRY *__vmm_pmd_alloc (PLW_MMU_CONTEXT pmmuctx,
- LW_PGD_TRANSENTRY *p_pgdentry,
- addr_t ulAddr)
+ LW_PGD_TRANSENTRY *p_pgdentry,
+ addr_t ulAddr)
{
if (__VMM_MMU_PGD_NONE(*p_pgdentry)) {
return (__VMM_MMU_PMD_ALLOC(pmmuctx, p_pgdentry, ulAddr));
@@ -404,8 +404,8 @@ static LW_INLINE VOID __vmm_pmd_free (LW_PMD_TRANSENTRY *p_pmdentry)
#if LW_CFG_VMM_PAGE_4L_EN > 0 /* LW_CFG_VMM_PAGE_4L_EN > 0 */
static LW_INLINE LW_PTS_TRANSENTRY *__vmm_pts_alloc (PLW_MMU_CONTEXT pmmuctx,
- LW_PMD_TRANSENTRY *p_pmdentry,
- addr_t ulAddr)
+ LW_PMD_TRANSENTRY *p_pmdentry,
+ addr_t ulAddr)
{
if (__VMM_MMU_PMD_NONE(*p_pmdentry)) {
return (__VMM_MMU_PTS_ALLOC(pmmuctx, p_pmdentry, ulAddr));
@@ -420,8 +420,8 @@ static LW_INLINE VOID __vmm_pts_free (LW_PTS_TRANSENTRY *p_ptsentry)
}
static LW_INLINE LW_PTE_TRANSENTRY *__vmm_pte_alloc (PLW_MMU_CONTEXT pmmuctx,
- LW_PTS_TRANSENTRY *p_ptsentry,
- addr_t ulAddr)
+ LW_PTS_TRANSENTRY *p_ptsentry,
+ addr_t ulAddr)
{
if (__VMM_MMU_PTS_NONE(*p_ptsentry)) {
return (__VMM_MMU_PTE_ALLOC(pmmuctx, p_ptsentry, ulAddr));
@@ -432,8 +432,8 @@ static LW_INLINE LW_PTE_TRANSENTRY *__vmm_pte_alloc (PLW_MMU_CONTEXT pmmuct
#else /* !LW_CFG_VMM_PAGE_4L_EN > 0 */
static LW_INLINE LW_PTE_TRANSENTRY *__vmm_pte_alloc (PLW_MMU_CONTEXT pmmuctx,
- LW_PMD_TRANSENTRY *p_pmdentry,
- addr_t ulAddr)
+ LW_PMD_TRANSENTRY *p_pmdentry,
+ addr_t ulAddr)
{
if (__VMM_MMU_PMD_NONE(*p_pmdentry)) {
return (__VMM_MMU_PTE_ALLOC(pmmuctx, p_pmdentry, ulAddr));
diff --git a/SylixOS/kernel/vmm/phyPage.c b/SylixOS/kernel/vmm/phyPage.c
index dbe0b8f..8da1917 100644
--- a/SylixOS/kernel/vmm/phyPage.c
+++ b/SylixOS/kernel/vmm/phyPage.c
@@ -634,7 +634,7 @@ ULONG __vmmPhysicalPageGetMinContinue (ULONG *pulZoneIndex, UINT uiAttr)
return (ulMin);
}
/*********************************************************************************************************
-** 函数名称: __vmmPhysicalCreate
+** 函数名称: __vmmPhysicalPageFaultLimit
** 功能描述: 设置缺页中断物理内存限制.
** 输 入 : pvpflNew 新的设置
** pvpflOld 之前的设置
diff --git a/SylixOS/kernel/vmm/vmmAbort.c b/SylixOS/kernel/vmm/vmmAbort.c
index 9e6949b..fcecdc4 100644
--- a/SylixOS/kernel/vmm/vmmAbort.c
+++ b/SylixOS/kernel/vmm/vmmAbort.c
@@ -446,7 +446,7 @@ static PLW_VMM_PAGE __vmmAbortNewPage (ULONG ulAllocPageNum,
pvmpagePhysical = __vmmPhysicalPageAlloc(ulAllocPageNum,
LW_ZONE_ATTR_NONE,
&ulZoneIndex); /* 分配物理内存(1个页面) */
- if (pvmpagePhysical == LW_NULL) { /* 如果分配失败择交换出一个页面*/
+ if (pvmpagePhysical == LW_NULL) { /* 如果分配失败则交换出一个页面*/
_K_vmmStatus.VMMS_i64PageLackCounter++;
pvmpagePhysical = __vmmPageSwapSwitch(__PAGEFAIL_CUR_PID,
ulAllocPageNum,
diff --git a/SylixOS/kernel/vmm/vmmMalloc.c b/SylixOS/kernel/vmm/vmmMalloc.c
index ba6e234..1c78946 100644
--- a/SylixOS/kernel/vmm/vmmMalloc.c
+++ b/SylixOS/kernel/vmm/vmmMalloc.c
@@ -299,7 +299,7 @@ PVOID API_VmmMallocAlign (size_t stSize, size_t stAlign, ULONG ulFlag)
}
pvmpagePhysical->PAGE_ulMapPageAddr = ulVirtualAddr;
- pvmpagePhysical->PAGE_ulFlags = ulFlag;
+ pvmpagePhysical->PAGE_ulFlags = ulFlag;
__pageLink(pvmpageVirtual, pvmpagePhysical); /* 将物理页面连接入虚拟空间 */
@@ -330,7 +330,7 @@ PVOID API_VmmMallocAlign (size_t stSize, size_t stAlign, ULONG ulFlag)
}
pvmpagePhysical->PAGE_ulMapPageAddr = ulVirtualAddr;
- pvmpagePhysical->PAGE_ulFlags = ulFlag;
+ pvmpagePhysical->PAGE_ulFlags = ulFlag;
__pageLink(pvmpageVirtual, pvmpagePhysical); /* 将物理页面连接入虚拟空间 */
@@ -752,7 +752,7 @@ ULONG API_VmmMergeArea (PVOID pvVirtualMem1, PVOID pvVirtualMem2)
return (ERROR_VMM_VIRTUAL_PAGE);
}
- if ((pvmpageVirtualL->PAGE_ulPageAddr + pvmpageVirtualL->PAGE_ulCount) !=
+ if ((pvmpageVirtualL->PAGE_ulPageAddr + (pvmpageVirtualL->PAGE_ulCount << LW_CFG_VMM_PAGE_SHIFT)) !=
pvmpageVirtualR->PAGE_ulPageAddr) { /* 非连续页面不能进行合并 */
__VMM_UNLOCK();
_ErrorHandle(ERROR_VMM_VIRTUAL_ADDR);
diff --git a/SylixOS/kernel/vmm/vmmMmap.c b/SylixOS/kernel/vmm/vmmMmap.c
index 43407eb..2987274 100644
--- a/SylixOS/kernel/vmm/vmmMmap.c
+++ b/SylixOS/kernel/vmm/vmmMmap.c
@@ -263,7 +263,7 @@ static PVOID __vmmMapnMalloc (PLW_VMM_MAP_NODE pmapn, size_t stLen,
if (iFlags & LW_VMM_PHY_PREALLOC) {
LW_TCB_GET_CUR_SAFE(ptcbCur);
- bNoLimit = __vmmPhysicalPageFaultCheck(1, ptcbCur, pulGuarder); /* 检查物理内存是否超限 */
+ bNoLimit = __vmmPhysicalPageFaultCheck(1, ptcbCur, pulGuarder); /* 检查物理内存是否超限 */
if (bNoLimit) {
pvMem = API_VmmMallocEx(stLen, ulFlag);
} else {
@@ -1171,7 +1171,11 @@ VOID API_VmmMmapShow (VOID)
pcShare = "false";
}
+#if LW_CFG_CPU_WORD_LENGHT == 64
+ printf("%016lx %16lx %16llx %s %s %5d %4d\n",
+#else
printf("%08lx %8lx %16llx %s %s %5d %4d\n",
+#endif /* LW_CFG_CPU_WORD_LENGHT adj */
(addr_t)pmapn->MAPN_pvAddr,
(ULONG)pmapn->MAPN_stLen,
pmapn->MAPN_off,
diff --git a/SylixOS/kernel/vmm/vmmStack.c b/SylixOS/kernel/vmm/vmmStack.c
index 9102d80..aa1422e 100644
--- a/SylixOS/kernel/vmm/vmmStack.c
+++ b/SylixOS/kernel/vmm/vmmStack.c
@@ -111,7 +111,7 @@ PVOID API_VmmStackAlloc (size_t stSize)
}
pvmpagePhysical->PAGE_ulMapPageAddr = ulVirtualAddr;
- pvmpagePhysical->PAGE_ulFlags = LW_VMM_FLAG_RDWR;
+ pvmpagePhysical->PAGE_ulFlags = LW_VMM_FLAG_RDWR;
__pageLink(pvmpageVirtual, pvmpagePhysical); /* 将物理页面连接入虚拟空间 */
diff --git a/SylixOS/lib/libc/stdio/popen.c b/SylixOS/lib/libc/stdio/popen.c
index 5af2468..76e4d34 100644
--- a/SylixOS/lib/libc/stdio/popen.c
+++ b/SylixOS/lib/libc/stdio/popen.c
@@ -38,6 +38,7 @@
#define __SYLIXOS_KERNEL
#include "stdio.h"
#include "unistd.h"
+#include "loader/include/loader_vppatch.h"
#if (LW_CFG_DEVICE_EN > 0) && (LW_CFG_FIO_LIB_EN > 0) && (LW_CFG_SHELL_EN > 0)
@@ -139,14 +140,20 @@ int pclose (FILE *fp)
return (PX_ERROR);
}
- fclose(fp);
-
/*
* 注意, 这里没有使用 waitpid 因为无法确定 popen 是否执行的是进程,
- * 如果执行的是进程, 如果是进程, 则必须等到当前进程结束时, 子进程资源才能被回收器回收.
+ * 如果执行的是进程, 则必须等到当前进程结束时, 子进程资源才能被回收器回收.
* 这是一个折中方案, 目前没有好的解决方法.
*/
- API_ThreadJoin(childsh, (void **)&status);
+#if LW_CFG_MODULELOADER_EN > 0
+ if (!vprocGetPidByThread(API_ThreadIdSelf()) &&
+ !vprocGetPidByThread(childsh)) {
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
+ API_ThreadJoin(childsh, (void **)&status);
+ fclose(fp);
+#if LW_CFG_MODULELOADER_EN > 0
+ }
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
return ((int)status);
}
diff --git a/SylixOS/lib/libc/time/lib_clock.c b/SylixOS/lib/libc/time/lib_clock.c
index ebe5c72..054c233 100644
--- a/SylixOS/lib/libc/time/lib_clock.c
+++ b/SylixOS/lib/libc/time/lib_clock.c
@@ -80,16 +80,9 @@ clock_t lib_clock (VOID)
INT lib_clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
{
#if LW_CFG_MODULELOADER_EN > 0
- if (!vprocGet(pid)) {
+ if (pid && !vprocGet(pid)) {
return (PX_ERROR);
}
-
-#else
- if (pid) {
- _ErrorHandle(ESRCH);
- return (PX_ERROR);
- }
-#endif /* LW_CFG_MODULELOADER_EN > 0 */
if (!clock_id) {
_ErrorHandle(EINVAL);
@@ -99,6 +92,10 @@ INT lib_clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
*clock_id = CLOCK_PROCESS_CPUTIME_ID;
return (ERROR_NONE);
+#else
+ _ErrorHandle(ESRCH);
+ return (PX_ERROR);
+#endif /* LW_CFG_MODULELOADER_EN > 0 */
}
/*********************************************************************************************************
** 函数名称: lib_clock_getres
@@ -205,7 +202,8 @@ INT lib_clock_settime (clockid_t clockid, const struct timespec *tv)
{
INTREG iregInterLevel;
- if (tv == LW_NULL) {
+ if ((tv == LW_NULL) ||
+ LW_NSEC_INVALD(tv->tv_nsec)) {
_ErrorHandle(EINVAL);
return (PX_ERROR);
}
diff --git a/SylixOS/loader/src/loader_vppatch.c b/SylixOS/loader/src/loader_vppatch.c
index a80dd45..9d545bd 100644
--- a/SylixOS/loader/src/loader_vppatch.c
+++ b/SylixOS/loader/src/loader_vppatch.c
@@ -400,7 +400,7 @@ INT vprocDetach (pid_t pid)
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-LW_LD_VPROC *vprocCreate (CPCHAR pcFile, ULONG ulExts)
+LW_LD_VPROC *vprocCreate (CPCHAR pcFile, ULONG ulExts)
{
static UINT uiIndex = 0;
CHAR cVarValue[2];
@@ -1456,7 +1456,7 @@ static INT vprocPatchVerCheck (LW_LD_VPROC *pvproc)
_PathLastName(pmodTemp->EMOD_pcModulePath, &pcModuleName);
if (lib_strcmp(pcModuleName, "libvpmpdm.so") == 0) {
pmodule = pmodTemp;
- break;
+ break;
}
}
LW_VP_UNLOCK(pvproc);
@@ -1555,11 +1555,11 @@ FUNCPTR vprocGetMain (VOID)
}
/*********************************************************************************************************
** 函数名称: vprocRun
-** 功能描述: 加载并执行elf文件.
+** 功能描述: 加载并执行 elf 文件.
** 输 入 : pvproc 进程控制块
** pvpstop 是否等待调试器继续执行信号才能执行
** pcFile 文件路径
-** pcEntry 入口函数名,如果为LW_NULL,表示不需要条用初始化函数
+** pcEntry 入口函数名,如果为 LW_NULL,表示不需要条用初始化函数
** piRet 进程返回值
** iArgC 程序参数个数
** ppcArgV 程序参数数组
@@ -1611,11 +1611,11 @@ INT vprocRun (LW_LD_VPROC *pvproc,
* 找不到入口函数"_start",因此需要手动加载libvpmpdm.so
*/
if (LW_NULL == pfunEntry) {
- API_ModuleLoadEx("libvpmpdm.so", LW_OPTION_LOADER_SYM_GLOBAL,
- LW_NULL, LW_NULL,
- pcEntry, LW_NULL,
- pvproc);
- pfunEntry = vprocGetEntry(pvproc);
+ API_ModuleLoadEx("libvpmpdm.so", LW_OPTION_LOADER_SYM_GLOBAL,
+ LW_NULL, LW_NULL,
+ pcEntry, LW_NULL,
+ pvproc);
+ pfunEntry = vprocGetEntry(pvproc);
}
#endif
diff --git a/SylixOS/mktemp/mkdemo/bsp/SylixOS/bsp/bspLib.c b/SylixOS/mktemp/mkdemo/bsp/SylixOS/bsp/bspLib.c
index 3c9d91e..58bce7e 100644
--- a/SylixOS/mktemp/mkdemo/bsp/SylixOS/bsp/bspLib.c
+++ b/SylixOS/mktemp/mkdemo/bsp/SylixOS/bsp/bspLib.c
@@ -534,7 +534,7 @@ ULONG bspMmuPgdMaxNum (VOID)
return (1);
}
/*********************************************************************************************************
-** 函数名称: bspMmuPgdMaxNum
+** 函数名称: bspMmuPteMaxNum
** 功能描述: 获得 PTE 池的数量
** 输 入 : NONE
** 输 出 : PTE 池的数量 (映射 4GB 空间, 需要 4096 个 PTE 池)
diff --git a/SylixOS/net/lwip/tools/hosttable/lwip_hosttable.c b/SylixOS/net/lwip/tools/hosttable/lwip_hosttable.c
index 3431d68..3a0ec2b 100644
--- a/SylixOS/net/lwip/tools/hosttable/lwip_hosttable.c
+++ b/SylixOS/net/lwip/tools/hosttable/lwip_hosttable.c
@@ -37,6 +37,7 @@
宏定义
*********************************************************************************************************/
#define __LW_HOSTTABLE_HASH_SIZE 17 /* hash 表大小 */
+#define __LW_HOSTTABLE_BUFFER_SIZE 1024 /* host buffer 大小 */
/*********************************************************************************************************
hash 函数声明
*********************************************************************************************************/
@@ -69,7 +70,6 @@ static INT __tshellHostTable(INT iArgC, PCHAR *ppcArgV);
*********************************************************************************************************/
VOID __inetHostTableInit (VOID)
{
-
_G_ulHostTableLock = API_SemaphoreBCreate("hosttable_lock", LW_TRUE,
LW_OPTION_OBJECT_GLOBAL, LW_NULL);
@@ -98,7 +98,7 @@ INT __inetHostTableGetItem (CPCHAR pcHost, size_t stLen, PVOID pvAddr, UINT8
ip_addr_t *addr = (ip_addr_t *)pvAddr;
u32_t uiAddr = INADDR_NONE;
CHAR cHostName[HOST_NAME_MAX + 1];
- CHAR cHostsBuffer[MAX_FILENAME_LENGTH];
+ CHAR cHostsBuffer[__LW_HOSTTABLE_BUFFER_SIZE];
struct hostent *phostent;
FILE *fpHosts;
BOOL bHostsFund = LW_FALSE;
diff --git a/SylixOS/posix/mman/mman.c b/SylixOS/posix/mman/mman.c
index 76747fd..9a34a16 100644
--- a/SylixOS/posix/mman/mman.c
+++ b/SylixOS/posix/mman/mman.c
@@ -218,6 +218,10 @@ void *mmap (void *pvAddr, size_t stLen, int iProt, int iFlag, int iFd, off
}
if (iFlag & MAP_ANONYMOUS) {
iFd = PX_ERROR;
+
+ } else if (iFd < 0) {
+ errno = EBADF;
+ return (MAP_FAILED);
}
if ((iFlag & MAP_SHARED) && ((iFlag & MAP_PRIVATE) == 0)) {
@@ -234,10 +238,10 @@ void *mmap (void *pvAddr, size_t stLen, int iProt, int iFlag, int iFd, off
if ((iFlag & MAP_ANONYMOUS) && (pvAddr == LW_NULL)) {
if (iFlag & MAP_CONTIG) {
iFlags |= LW_VMM_PHY_PREALLOC;
- ulFlag |= LW_VMM_FLAG_PHY_CONTINUOUS; /* 物理内存连续 */
+ ulFlag |= LW_VMM_FLAG_PHY_CONTINUOUS; /* 物理内存连续 */
} else if (iFlag & MAP_PREALLOC) {
- iFlags |= LW_VMM_PHY_PREALLOC; /* 内存管理预分配 */
+ iFlags |= LW_VMM_PHY_PREALLOC; /* 内存管理预分配 */
}
}
@@ -347,7 +351,7 @@ int msync (void *pvAddr, size_t stLen, int iFlag)
#endif /* LW_CFG_VMM_EN > 0 */
}
/*********************************************************************************************************
-** 函数名称: shm_open
+** 函数名称: posix_madvise
** 功能描述: The posix_madvise() function shall advise the implementation on the expected behavior of the
application with respect to the data in the memory starting at address addr, and continuing
for len bytes. The implementation may use this information to optimize handling of the
@@ -387,13 +391,18 @@ int shm_open (const char *name, int oflag, mode_t mode)
return (PX_ERROR);
}
+ if (lib_strnlen(name, NAME_MAX) >= NAME_MAX) {
+ errno = ENAMETOOLONG;
+ return (PX_ERROR);
+ }
+
if (name[0] == PX_ROOT) {
lib_strlcat(cFullName, &name[1], MAX_FILENAME_LENGTH);
} else {
lib_strlcat(cFullName, name, MAX_FILENAME_LENGTH);
}
- return (open(cFullName, oflag, mode));
+ return (open(cFullName, oflag | O_CLOEXEC, mode));
}
/*********************************************************************************************************
** 函数名称: shm_unlink
@@ -414,6 +423,11 @@ int shm_unlink (const char *name)
return (PX_ERROR);
}
+ if (lib_strnlen(name, NAME_MAX) >= NAME_MAX) {
+ errno = ENAMETOOLONG;
+ return (PX_ERROR);
+ }
+
if (name[0] == PX_ROOT) {
lib_strlcat(cFullName, &name[1], MAX_FILENAME_LENGTH);
} else {
diff --git a/SylixOS/posix/pthread/pthread_attr.c b/SylixOS/posix/pthread/pthread_attr.c
index ccccd07..025a75f 100644
--- a/SylixOS/posix/pthread/pthread_attr.c
+++ b/SylixOS/posix/pthread/pthread_attr.c
@@ -409,6 +409,12 @@ int pthread_attr_setschedparam (pthread_attr_t *pattr,
return (EINVAL);
}
+ if ((pschedparam->sched_priority < __PX_PRIORITY_MIN) ||
+ (pschedparam->sched_priority > __PX_PRIORITY_MAX)) {
+ errno = EINVAL;
+ return (EINVAL);
+ }
+
pattr->PTHREADATTR_schedparam = *pschedparam;
return (ERROR_NONE);
diff --git a/SylixOS/posix/resource/resource.c b/SylixOS/posix/resource/resource.c
index d8566b7..5d00bd8 100644
--- a/SylixOS/posix/resource/resource.c
+++ b/SylixOS/posix/resource/resource.c
@@ -140,7 +140,7 @@ int setrlimit (int resource, const struct rlimit *rlp)
INT iRet = PX_ERROR;
LW_LD_VPROC *pvproc;
- if (!rlp || (rlp->rlim_max > rlp->rlim_cur)) {
+ if (!rlp || (rlp->rlim_cur > rlp->rlim_max)) {
errno = EINVAL;
return (PX_ERROR);
}
diff --git a/SylixOS/posix/sched/sched.c b/SylixOS/posix/sched/sched.c
index 8d7f331..c3e93b8 100644
--- a/SylixOS/posix/sched/sched.c
+++ b/SylixOS/posix/sched/sched.c
@@ -146,7 +146,7 @@ int sched_setparam (pid_t pid, const struct sched_param *pschedparam)
return (PX_ERROR);
}
- ucPriority= (UINT8)PX_PRIORITY_CONVERT(pschedparam->sched_priority);
+ ucPriority = (UINT8)PX_PRIORITY_CONVERT(pschedparam->sched_priority);
#if LW_CFG_MODULELOADER_EN > 0
if (pid == 0) {
diff --git a/SylixOS/posix/spawn/spawn.c b/SylixOS/posix/spawn/spawn.c
index 66c7de3..97b7249 100644
--- a/SylixOS/posix/spawn/spawn.c
+++ b/SylixOS/posix/spawn/spawn.c
@@ -889,7 +889,7 @@ int posix_spawn_file_actions_destroy (posix_spawn_file_actions_t *file_actions
*********************************************************************************************************/
LW_API
int posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
- int fd, const char *path, int oflag, mode_t mode)
+ int fd, const char *path, int oflag, mode_t mode)
{
__spawn_action *pspawnactNew;
size_t stPathLen;
diff --git a/SylixOS/posix/sysconf/sysconf.c b/SylixOS/posix/sysconf/sysconf.c
index cb4e8ee..0a8c8e4 100644
--- a/SylixOS/posix/sysconf/sysconf.c
+++ b/SylixOS/posix/sysconf/sysconf.c
@@ -111,7 +111,7 @@ long sysconf (int name)
return (1);
case _SC_SIGQUEUE_MAX:
- return (LW_CFG_MAX_MSGQUEUES);
+ return (LW_CFG_MAX_SIGQUEUE_NODES);
case _SC_TIMER_MAX:
return (LW_CFG_MAX_TIMERS);
diff --git a/SylixOS/posix/syslog/syslog.c b/SylixOS/posix/syslog/syslog.c
index 07cc37b..5d8e1fd 100644
--- a/SylixOS/posix/syslog/syslog.c
+++ b/SylixOS/posix/syslog/syslog.c
@@ -291,7 +291,7 @@ void syslog (int priority, const char *message, ...)
CHAR cBuffer[LOG_DEFAULT_SIZE];
size_t stLen;
- time_t time;
+ time_t timeNow;
struct tm tmBuf;
va_list valist;
@@ -311,8 +311,8 @@ void syslog (int priority, const char *message, ...)
priority |= _G_iSyslogFaci;
}
- time = lib_time(LW_NULL);
- lib_localtime_r(&time, &tmBuf); /* RFC3164 is the local time */
+ timeNow = lib_time(LW_NULL);
+ lib_localtime_r(&timeNow, &tmBuf); /* RFC3164 is the local time */
stLen = bnprintf(cBuffer, sizeof(cBuffer), 0, "<%d>", priority); /* 打印 priority */
stLen = bnprintf(cBuffer, sizeof(cBuffer), stLen,
@@ -390,7 +390,7 @@ void syslog_r (int priority, struct syslog_data *data, const char *message, ...
CHAR cBuffer[LOG_DEFAULT_SIZE];
size_t stLen;
- time_t time;
+ time_t timeNow;
struct tm tmBuf;
va_list valist;
@@ -415,8 +415,8 @@ void syslog_r (int priority, struct syslog_data *data, const char *message, ...
priority |= data->log_fac;
}
- time = lib_time(LW_NULL);
- lib_localtime_r(&time, &tmBuf); /* RFC3164 is the local time */
+ timeNow = lib_time(LW_NULL);
+ lib_localtime_r(&timeNow, &tmBuf); /* RFC3164 is the local time */
stLen = bnprintf(cBuffer, sizeof(cBuffer), 0, "<%d>", priority); /* 打印 priority */
stLen = bnprintf(cBuffer, sizeof(cBuffer), stLen,
diff --git a/SylixOS/shell/fsLib/ttinyShellFsCmd.c b/SylixOS/shell/fsLib/ttinyShellFsCmd.c
index a44292b..1bd5ca2 100644
--- a/SylixOS/shell/fsLib/ttinyShellFsCmd.c
+++ b/SylixOS/shell/fsLib/ttinyShellFsCmd.c
@@ -2020,14 +2020,15 @@ static INT __tshellFsCmdDosfslabel (INT iArgC, PCHAR ppcArgV[])
static INT __tshellFsCmdFdisk (INT iArgC, PCHAR ppcArgV[])
{
CHAR cInput[512];
- LW_OEMFDISK_PART fdpInfo[4];
- UINT uiNPart;
+ LW_OEMFDISK_PART fdpInfo[LW_CFG_MAX_DISKPARTS];
+ UINT uiNPart, uiMaxPart;
size_t stAlign, stNum;
struct stat statGet;
PCHAR pcBlkFile;
UINT i, uiPct, uiTotalPct = 0;
CHAR cActive, cChar, *pcStr;
INT iCnt, iType;
+ BOOL bGpt;
if (iArgC < 2) {
fprintf(stderr, "too few arguments!\n");
@@ -2037,7 +2038,15 @@ static INT __tshellFsCmdFdisk (INT iArgC, PCHAR ppcArgV[])
return (oemFdiskShow(ppcArgV[1]));
} else {
- if (lib_strcmp(ppcArgV[1], "-f")) {
+ if (lib_strcmp(ppcArgV[1], "-f") == 0) {
+ bGpt = LW_FALSE;
+
+#if LW_CFG_CPU_WORD_LENGHT > 32
+ } else if (lib_strcmp(ppcArgV[1], "-fgpt") == 0) {
+ bGpt = LW_TRUE;
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
+
+ } else {
fprintf(stderr, "you must use '-f' to make disk partition!\n");
return (-ERROR_TSHELL_EPARAM);
}
@@ -2055,20 +2064,29 @@ static INT __tshellFsCmdFdisk (INT iArgC, PCHAR ppcArgV[])
return (-ERROR_TSHELL_EPARAM);
}
- printf("block device %s total size: %llu (MB), reserved: %lu (KB)\n",
- pcBlkFile, (statGet.st_size >> 20),
- statGet.st_blksize * 2048 / 1024); /* 保留了 2048 个扇区 */
+#if LW_CFG_CPU_WORD_LENGHT > 32
+ if (bGpt) {
+ uiMaxPart = LW_CFG_MAX_DISKPARTS;
+ printf("block device %s total size: %llu (MB)\n", pcBlkFile, (statGet.st_size >> 20));
+ } else
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
+ {
+ uiMaxPart = LW_CFG_MAX_DISKPARTS > 4 ? 4 : LW_CFG_MAX_DISKPARTS;
+ printf("block device %s total size: %llu (MB), reserved: %lu (KB)\n",
+ pcBlkFile, (statGet.st_size >> 20),
+ statGet.st_blksize * 2048 / 1024); /* 保留了 2048 个扇区 */
+ }
__input_num:
- printf("please input how many partition(s) you want to make (1 ~ 4) : ");
+ printf("please input how many partition(s) you want to make (1 ~ %d) : ", uiMaxPart);
fflush(stdout);
fpurge(stdin);
if (scanf("%d", &uiNPart) != 1) {
goto __input_num;
}
- if ((uiNPart < 1) || (uiNPart > 4)) {
- printf("the number must be 1 ~ 4\n");
+ if ((uiNPart < 1) || (uiNPart > uiMaxPart)) {
+ printf("the number must be 1 ~ %d\n", uiMaxPart);
goto __input_num;
}
@@ -2155,12 +2173,21 @@ __input_active:
__input_type:
printf("please input the file system type\n");
+#if LW_CFG_CPU_WORD_LENGHT > 32
+ printf("1: FAT 2: TPSFS 3: LINUX 4: RESERVED 5:EFI\n");
+ fpurge(stdin);
+ if ((scanf("%d", &iType) != 1) || ((iType < 1) || (iType > 5))) {
+ printf("please use 1 2 3 4 or 5\n");
+ goto __input_type;
+ }
+#else
printf("1: FAT 2: TPSFS 3: LINUX 4: RESERVED\n");
fpurge(stdin);
if ((scanf("%d", &iType) != 1) || ((iType < 1) || (iType > 4))) {
printf("please use 1 2 3 or 4\n");
goto __input_type;
}
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
switch (iType) {
@@ -2179,6 +2206,12 @@ __input_type:
case 4:
fdpInfo[i].FDP_ucPartType = LW_DISK_PART_TYPE_RESERVED;
break;
+
+#if LW_CFG_CPU_WORD_LENGHT > 32
+ case 5:
+ fdpInfo[i].FDP_ucPartType = LW_DISK_PART_TYPE_EFI;
+ break;
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
default:
fdpInfo[i].FDP_ucPartType = LW_DISK_PART_TYPE_TPS;
@@ -2187,7 +2220,7 @@ __input_type:
}
printf("making partition...\n");
- iCnt = oemFdisk(pcBlkFile, fdpInfo, uiNPart, stAlign);
+ iCnt = oemFdiskEx(pcBlkFile, fdpInfo, uiNPart, stAlign, bGpt);
if (iCnt <= ERROR_NONE) {
fprintf(stderr, "make partition error: %s\n", lib_strerror(errno));
return (PX_ERROR);
@@ -2442,10 +2475,18 @@ VOID __tshellFsCmdInit (VOID)
#if LW_CFG_OEMDISK_EN > 0
API_TShellKeywordAdd("fdisk", __tshellFsCmdFdisk);
+#if LW_CFG_CPU_WORD_LENGHT > 32
+ API_TShellFormatAdd("fdisk", " [-f] [-fgpt] [block I/O device]");
+ API_TShellHelpAdd("fdisk", "show or make disk partition table\n"
+ "eg. fdisk /dev/blk/udisk0\n"
+ " fdisk -f /dev/blk/sata0\n"
+ " fdisk -fgpt /dev/blk/sata0\n");
+#else
API_TShellFormatAdd("fdisk", " [-f] [block I/O device]");
API_TShellHelpAdd("fdisk", "show or make disk partition table\n"
"eg. fdisk /dev/blk/udisk0\n"
" fdisk -f /dev/blk/sata0\n");
+#endif /* LW_CFG_CPU_WORD_LENGHT > 32 */
API_TShellKeywordAdd("clrgpt", __tshellFsCmdClrGpt);
API_TShellFormatAdd("clrgpt", " [-s [sector size]] [block I/O device]");
diff --git a/SylixOS/shell/heapLib/ttinyShellHeapCmd.c b/SylixOS/shell/heapLib/ttinyShellHeapCmd.c
index 233d615..d2b2938 100644
--- a/SylixOS/shell/heapLib/ttinyShellHeapCmd.c
+++ b/SylixOS/shell/heapLib/ttinyShellHeapCmd.c
@@ -102,7 +102,7 @@ static VOID __heapAllocPrint (PLW_CLASS_HEAP pheap,
return;
}
- } else if (_G_pidTraceProcess > 0) { /* 进跟踪指定进程 */
+ } else if (_G_pidTraceProcess > 0) { /* 仅跟踪指定进程 */
if (_G_pidTraceProcess != __PROC_GET_PID_CUR()) {
return;
}
@@ -139,10 +139,10 @@ static VOID __heapAllocPrint (PLW_CLASS_HEAP pheap,
*********************************************************************************************************/
static VOID __heapFreePrint (PLW_CLASS_HEAP pheap, PVOID pvAddr)
{
- BOOL bPut = LW_FALSE;
- PLW_LIST_LINE plineTemp;
- __PHEAP_TRACE_NODE phtn = LW_NULL;
- REGISTER PCHAR pcAddr = (PCHAR)pvAddr;
+ BOOL bPut = LW_FALSE;
+ PLW_LIST_LINE plineTemp;
+ __PHEAP_TRACE_NODE phtn = LW_NULL;
+ REGISTER PCHAR pcAddr = (PCHAR)pvAddr;
if (!pvAddr) {
return;
diff --git a/SylixOS/shell/ttinyShell/ttinyShell.c b/SylixOS/shell/ttinyShell/ttinyShell.c
index cfed66a..c4baf64 100644
--- a/SylixOS/shell/ttinyShell/ttinyShell.c
+++ b/SylixOS/shell/ttinyShell/ttinyShell.c
@@ -848,14 +848,14 @@ INT API_TShellExec (CPCHAR pcCommandExec)
*********************************************************************************************************/
LW_API
INT API_TShellExecBg (CPCHAR pcCommandExec, INT iFd[3], BOOL bClosed[3],
- BOOL bIsJoin, LW_OBJECT_HANDLE *pulSh)
+ BOOL bIsJoin, LW_OBJECT_HANDLE *pulSh)
{
INT iRet;
INT iError;
INT iFdArray[3];
BOOL bClosedArray[3];
CHAR cKeyword[LW_CFG_SHELL_MAX_KEYWORDLEN + 1]; /* 关键字 */
- PCHAR pcParam = LW_NULL; /* 指向第一个参数的指针 */
+ PCHAR pcParam = LW_NULL; /* 指向第一个参数的指针 */
__PTSHELL_KEYWORD pskwNode = LW_NULL;
CHAR cCommand[LW_CFG_SHELL_MAX_COMMANDLEN + 1];
diff --git a/SylixOS/shell/ttinyShell/ttinyShellSysCmd.c b/SylixOS/shell/ttinyShell/ttinyShellSysCmd.c
index 5903c6f..5c1e95f 100644
--- a/SylixOS/shell/ttinyShell/ttinyShellSysCmd.c
+++ b/SylixOS/shell/ttinyShell/ttinyShellSysCmd.c
@@ -956,7 +956,7 @@ static INT __tshellSysCmdSigqueue (INT iArgC, PCHAR ppcArgV[])
INT iSigNum = SIGKILL;
union sigval sigvalue;
- sigvalue.sival_int = 0;
+ sigvalue.sival_int = 1;
if (iArgC == 2) {
if (ppcArgV[1][0] < '0' ||
@@ -980,7 +980,7 @@ static INT __tshellSysCmdSigqueue (INT iArgC, PCHAR ppcArgV[])
sscanf(ppcArgV[2], "%d", &iSigNum);
sscanf(ppcArgV[3], "%lx", &ulId);
if (API_ObjectGetClass(ulId) != _OBJECT_THREAD) {
- sscanf(ppcArgV[1], "%ld", &ulId); /* 进程 id */
+ sscanf(ppcArgV[3], "%ld", &ulId); /* 进程 id */
}
return (sigqueue(ulId, iSigNum, sigvalue));
diff --git a/SylixOS/system/device/ahci/ahci.c b/SylixOS/system/device/ahci/ahci.c
index 8d6e731..1be4851 100644
--- a/SylixOS/system/device/ahci/ahci.c
+++ b/SylixOS/system/device/ahci/ahci.c
@@ -3172,8 +3172,8 @@ static INT __ahciDiskDriveInit (AHCI_CTRL_HANDLE hCtrl, UINT uiDrive)
hCtrl->AHCICTRL_ullLba48TotalSecs[uiDrive] =
(UINT64)((((UINT64)((hParam->AHCIPARAM_usLba48Size[0]) & 0x0000ffff)) << 0) |
(((UINT64)((hParam->AHCIPARAM_usLba48Size[1]) & 0x0000ffff)) << 16) |
- (((UINT64)((hParam->AHCIPARAM_usLba48Size[2]) & 0x0000ffff)) << 24) |
- (((UINT64)((hParam->AHCIPARAM_usLba48Size[3]) & 0x0000ffff)) << 32));
+ (((UINT64)((hParam->AHCIPARAM_usLba48Size[2]) & 0x0000ffff)) << 32) |
+ (((UINT64)((hParam->AHCIPARAM_usLba48Size[3]) & 0x0000ffff)) << 48));
hDrive->AHCIDRIVE_ulSectorMax = AHCI_MAX_RW_48LBA_SECTORS;
} else {
diff --git a/SylixOS/system/device/sdcard/client/sdiobaseDrv.c b/SylixOS/system/device/sdcard/client/sdiobaseDrv.c
index d75a4e7..6afa4e9 100644
--- a/SylixOS/system/device/sdcard/client/sdiobaseDrv.c
+++ b/SylixOS/system/device/sdcard/client/sdiobaseDrv.c
@@ -40,6 +40,7 @@ struct __sdm_sdio_base {
SDIO_INIT_DATA SDMIOBASE_initdata;
SDIO_DRV *SDMIOBASE_psdiodrv;
VOID *SDMIOBASE_pvDevPriv;
+ BOOL SDMIOBASE_bCustomSdio;
};
typedef struct __sdm_sdio_base __SDM_SDIO_BASE;
/*********************************************************************************************************
@@ -100,6 +101,8 @@ static INT __sdiobaseDevCreate (SD_DRV *psddrv, PLW_SDCORE_DEVICE psdcoredev,
SDIO_INIT_DATA *psdioinitdata;
SDIO_DRV *psdiodrv;
PLW_LIST_LINE plineTmp;
+ BOOL bCustomSdio;
+ LONG lHostCfg;
INT iRet;
psdiobase= (__SDM_SDIO_BASE *)__SHEAP_ALLOC(sizeof(__SDM_SDIO_BASE));
@@ -108,16 +111,32 @@ static INT __sdiobaseDevCreate (SD_DRV *psddrv, PLW_SDCORE_DEVICE psdcoredev,
return (PX_ERROR);
}
+ lib_memset(psdiobase, 0, sizeof(__SDM_SDIO_BASE));
+
+ API_SdmHostExtOptGet(psdcoredev, SDHOST_EXTOPT_CONFIG_FLAG_GET, (LONG)&lHostCfg);
+ if (lHostCfg & SDHOST_EXTOPT_CONFIG_CUSTOM_SDIO) {
+ bCustomSdio = LW_TRUE;
+ } else {
+ bCustomSdio = LW_FALSE;
+ }
+
+ psdiobase->SDMIOBASE_bCustomSdio = bCustomSdio;
+
psdioinitdata = &psdiobase->SDMIOBASE_initdata;
*ppvDevPriv = (VOID *)psdiobase;
- iRet = __sdiobasePreInit(psdioinitdata, psdcoredev);
- if (iRet != ERROR_NONE) {
- /*
- * 如果预初始化失败, 说明不是一个 SDIO 设备, 无需进行
- * 下面的 SDIO 设备驱动匹配工作
- */
- goto __err;
+ if (!bCustomSdio) {
+ iRet = __sdiobasePreInit(psdioinitdata, psdcoredev);
+ if (iRet != ERROR_NONE) {
+ /*
+ * 如果预初始化失败, 说明不是一个 SDIO 设备, 无需进行
+ * 下面的 SDIO 设备驱动匹配工作
+ */
+ goto __err;
+ }
+
+ } else {
+ psdioinitdata->INIT_psdcoredev = psdcoredev;
}
__sdmSdioDrvAccessRequest();
@@ -126,20 +145,23 @@ static INT __sdiobaseDevCreate (SD_DRV *psddrv, PLW_SDCORE_DEVICE psdcoredev,
plineTmp = _list_line_get_next(plineTmp)) {
psdiodrv = _LIST_ENTRY(plineTmp, SDIO_DRV, SDIODRV_lineManage);
- iRet = __sdiobaseDrvMatch(&psdioinitdata->INIT_psdiofuncTbl[0],
- psdioinitdata->INIT_iFuncCnt + 1,
- psdiodrv);
- if (iRet != ERROR_NONE) {
- /*
- * 当前驱动匹配失败,匹配下一个
- */
- continue;
- }
- __sdiobaseMatchFuncIdSet(psdioinitdata,
- &psdioinitdata->INIT_psdiofuncTbl[0],
- psdioinitdata->INIT_iFuncCnt + 1,
- psdiodrv);
+ if (!bCustomSdio) {
+ iRet = __sdiobaseDrvMatch(&psdioinitdata->INIT_psdiofuncTbl[0],
+ psdioinitdata->INIT_iFuncCnt + 1,
+ psdiodrv);
+ if (iRet != ERROR_NONE) {
+ /*
+ * 当前驱动匹配失败,匹配下一个
+ */
+ continue;
+ }
+
+ __sdiobaseMatchFuncIdSet(psdioinitdata,
+ &psdioinitdata->INIT_psdiofuncTbl[0],
+ psdioinitdata->INIT_iFuncCnt + 1,
+ psdiodrv);
+ }
/*
* 因为在接下来的具体驱动设备创建过程中可能会产生中断事件
@@ -194,10 +216,12 @@ static INT __sdiobaseDevDelete (SD_DRV *psddrv, VOID *pvDevPriv)
psdioDrv = psdiobase->SDMIOBASE_psdiodrv;
psdioDrv->SDIODRV_pfuncDevDelete(psdioDrv, psdiobase->SDMIOBASE_pvDevPriv);
- psdiofunc = &psdiobase->SDMIOBASE_initdata.INIT_psdiofuncTbl[0];
- for (i = 0; i < (psdiobase->SDMIOBASE_initdata.INIT_iFuncCnt + 1); i++) {
- API_SdioCoreDevFuncClean(psdiofunc);
- psdiofunc++;
+ if (!psdiobase->SDMIOBASE_bCustomSdio) {
+ psdiofunc = &psdiobase->SDMIOBASE_initdata.INIT_psdiofuncTbl[0];
+ for (i = 0; i < (psdiobase->SDMIOBASE_initdata.INIT_iFuncCnt + 1); i++) {
+ API_SdioCoreDevFuncClean(psdiofunc);
+ psdiofunc++;
+ }
}
__SHEAP_FREE(psdiobase);
diff --git a/SylixOS/system/device/sdcard/client/sdmemory.c b/SylixOS/system/device/sdcard/client/sdmemory.c
index 674b033..ec80db6 100644
--- a/SylixOS/system/device/sdcard/client/sdmemory.c
+++ b/SylixOS/system/device/sdcard/client/sdmemory.c
@@ -150,6 +150,8 @@ static INT __sdMemSwitchWait(PLW_SDCORE_DEVICE psdcoredevice,
static CPCHAR __sdMemProtVsnStr(UINT8 ucType, UINT8 ucVsn);
static ULONG __sdMemBlkLogic2Phy(ULONG ulLogic, UINT8 ucBlkLenBits);
static ULONG __sdMemBlkPhy2Logic(ULONG ulPhy, UINT8 ucBlkLenBits);
+static VOID *__sdMemExtBufAlloc(VOID);
+static VOID __sdMemExtBufFree(VOID *pvExtBuf);
/*********************************************************************************************************
** 函数名称: API_SdMemDevCreate
** 功能描述: 创建一个SD记忆卡设备
@@ -206,6 +208,16 @@ LW_API PLW_BLK_DEV API_SdMemDevCreate (INT iAdapterType,
return (LW_NULL);
}
+ psdcoredevice->COREDEV_pucExtBuf = __sdMemExtBufAlloc();
+ if (!psdcoredevice->COREDEV_pucExtBuf) {
+ SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "alloc ext buffer failed.\r\n");
+
+ if (bCoreDevSelf) {
+ API_SdCoreDevDelete(psdcoredevice);
+ }
+ return (LW_NULL);
+ }
+
/*
* 初始化这个设备(针对记忆卡)
*/
@@ -213,6 +225,7 @@ LW_API PLW_BLK_DEV API_SdMemDevCreate (INT iAdapterType,
if (iError != ERROR_NONE) {
SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "do memory initialize failed.\r\n");
+ __sdMemExtBufFree(psdcoredevice->COREDEV_pucExtBuf);
if (bCoreDevSelf) {
API_SdCoreDevDelete(psdcoredevice);
}
@@ -222,6 +235,7 @@ LW_API PLW_BLK_DEV API_SdMemDevCreate (INT iAdapterType,
psdblkdevice = (__PSD_BLK_DEV)__SHEAP_ALLOC(sizeof(__SD_BLK_DEV));
if (!psdblkdevice) {
+ __sdMemExtBufFree(psdcoredevice->COREDEV_pucExtBuf);
if (bCoreDevSelf) {
API_SdCoreDevDelete(psdcoredevice);
}
@@ -239,6 +253,7 @@ LW_API PLW_BLK_DEV API_SdMemDevCreate (INT iAdapterType,
SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "view csd of device failed.\r\n");
__SHEAP_FREE(psdblkdevice);
+ __sdMemExtBufFree(psdcoredevice->COREDEV_pucExtBuf);
if (bCoreDevSelf) {
API_SdCoreDevDelete(psdcoredevice);
}
@@ -251,6 +266,7 @@ LW_API PLW_BLK_DEV API_SdMemDevCreate (INT iAdapterType,
SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "unkonwn address access way.\r\n");
__SHEAP_FREE(psdblkdevice);
+ __sdMemExtBufFree(psdcoredevice->COREDEV_pucExtBuf);
if (bCoreDevSelf) {
API_SdCoreDevDelete(psdcoredevice);
}
@@ -364,6 +380,10 @@ LW_API INT API_SdMemDevDelete (PLW_BLK_DEV pblkdevice)
psdblkdevice = (__PSD_BLK_DEV)pblkdevice;
psdcoredevice = psdblkdevice->SDBLKDEV_pcoreDev;
+ if (psdcoredevice) {
+ __sdMemExtBufFree(psdcoredevice->COREDEV_pucExtBuf);
+ }
+
if (psdcoredevice && psdblkdevice->SDBLKDEV_bCoreDevSelf) {
iError = API_SdCoreDevDelete(psdcoredevice); /* 先删除core设备 */
if (iError != ERROR_NONE) {
@@ -1588,6 +1608,36 @@ static ULONG __sdMemBlkPhy2Logic (ULONG ulPhy, UINT8 ucBlkLenBits)
return (ulPhy);
}
/*********************************************************************************************************
+** 函数名称: __sdMemExtBufAlloc
+** 功能描述: 分配初始化使用的扩展缓冲区
+** 输 入: NONE
+** 输 出: NONE
+** 返 回: 缓冲区指针
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID *__sdMemExtBufAlloc (VOID)
+{
+ VOID *pvExtBuf;
+
+ pvExtBuf = API_CacheDmaMallocAlign(1024, 4);
+
+ return (pvExtBuf);
+}
+/*********************************************************************************************************
+** 函数名称: __sdMemExtBufFree
+** 功能描述: 释放扩展缓冲区
+** 输 入: pvExtBuf 缓冲区指针
+** 输 出: NONE
+** 返 回: NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __sdMemExtBufFree (VOID *pvExtBuf)
+{
+ API_CacheDmaFree(pvExtBuf);
+}
+/*********************************************************************************************************
** 函数名称: __sdMemSdSwCapGet
** 功能描述: 获得SD卡的SWITCH功能信息
** 输 入: psdcoredevice 核心设备对象
@@ -1604,7 +1654,7 @@ static INT __sdMemSdSwCapGet (PLW_SDCORE_DEVICE psdcoredevice,
LW_SDDEV_CSD *psdcsd,
LW_SDDEV_SW_CAP *psdswcap)
{
- UINT8 ucSwCap[64];
+ UINT8 *pucSwCap = psdcoredevice->COREDEV_pucExtBuf;
INT iRet;
lib_bzero(psdswcap, sizeof(LW_SDDEV_SW_CAP));
@@ -1617,13 +1667,13 @@ static INT __sdMemSdSwCapGet (PLW_SDCORE_DEVICE psdcoredevice,
return (PX_ERROR);
}
- iRet = API_SdCoreDevSwitchEx(psdcoredevice, 0, 0, 0, ucSwCap);
+ iRet = API_SdCoreDevSwitchEx(psdcoredevice, 0, 0, 0, pucSwCap);
if (iRet != ERROR_NONE) {
SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "get sd switch information error.\r\n");
return (PX_ERROR);
}
- if (ucSwCap[13] & SD_SW_MODE_HIGH_SPEED) {
+ if (pucSwCap[13] & SD_SW_MODE_HIGH_SPEED) {
psdswcap->DEVSWCAP_uiHsMaxDtr = 50000000;
}
@@ -1642,18 +1692,18 @@ static INT __sdMemSdSwCapGet (PLW_SDCORE_DEVICE psdcoredevice,
static INT __sdMemSdHsSwitch (PLW_SDCORE_DEVICE psdcoredevice, LW_SDDEV_SW_CAP *psdswcap)
{
INT iRet;
- UINT8 ucStatus[64];
+ UINT8 *pucStatus = psdcoredevice->COREDEV_pucExtBuf;
if (!psdswcap->DEVSWCAP_uiHsMaxDtr) {
return (PX_ERROR);
}
- iRet = API_SdCoreDevSwitchEx(psdcoredevice, 1, 0, 1, ucStatus);
+ iRet = API_SdCoreDevSwitchEx(psdcoredevice, 1, 0, 1, pucStatus);
if (iRet != ERROR_NONE) {
return (PX_ERROR);
}
- if ((ucStatus[16] & 0xF) != 1) {
+ if ((pucStatus[16] & 0xF) != 1) {
return (PX_ERROR);
}
diff --git a/SylixOS/system/device/sdcard/core/sdcore.h b/SylixOS/system/device/sdcard/core/sdcore.h
index 579536b..8562cb2 100644
--- a/SylixOS/system/device/sdcard/core/sdcore.h
+++ b/SylixOS/system/device/sdcard/core/sdcore.h
@@ -21,9 +21,10 @@
** BUG:
2011.01.12 增加对 SPI 的支持(SPI 下的特殊工具函数).
2011.02.21 增加 API_SdCoreSpiSendIfCond 函数.该函数只能用于 SPI 模式下.
-2011.02.21 增 SPI 下设备寄存器的读取函数: API_SdCoreSpiRegisterRead().
+2011.02.21 增加 SPI 下设备寄存器的读取函数: API_SdCoreSpiRegisterRead().
2011.03.25 修改 API_SdCoreDevCreate(), 用于底层驱动安装上层的回调.
2015.09.15 修改 SD_OPCOND_DELAY_CONTS 由100改为5000, 使卡识别阶段具有更好的兼容性.
+2021.07.22 修正 设备初始化时涉及数据传输的缓冲区不能直接来源于栈上空间.
*********************************************************************************************************/
#ifndef __SDCORE_H
@@ -67,6 +68,8 @@ typedef struct lw_sdcore_device {
INT (*COREDEV_pfuncCoreDevXfer)(PVOID pvDevHandle, PLW_SD_MESSAGE psdmsg, INT iNum);
INT (*COREDEV_pfuncCoreDevCtl)(PVOID pvDevHandle, INT iCmd, LONG lArg);
INT (*COREDEV_pfuncCoreDevDelet)(PVOID pvDevHandle);
+
+ UINT8 *COREDEV_pucExtBuf; /* 初始化使用的数据缓冲 */
} LW_SDCORE_DEVICE, *PLW_SDCORE_DEVICE;
/*********************************************************************************************************
diff --git a/SylixOS/system/device/sdcard/core/sdcoreLib.c b/SylixOS/system/device/sdcard/core/sdcoreLib.c
index 6a2e9c0..1009f1c 100644
--- a/SylixOS/system/device/sdcard/core/sdcoreLib.c
+++ b/SylixOS/system/device/sdcard/core/sdcoreLib.c
@@ -299,7 +299,7 @@ INT API_SdCoreDecodeExtCSD (PLW_SDCORE_DEVICE psdcoredevice,
LW_SDDEV_EXT_CSD *psdextcsd)
{
UINT uiExtCsdRev;
- UINT8 pucExtCsd[512];
+ UINT8 *pucExtCsd = psdcoredevice->COREDEV_pucExtBuf;
INT iError;
@@ -1194,19 +1194,20 @@ static INT __sdCoreSendScr (PLW_SDCORE_DEVICE psdcoredevice, UINT32 *puiScr)
*********************************************************************************************************/
INT API_SdCoreDevSendAllSCR (PLW_SDCORE_DEVICE psdcoredevice, LW_SDDEV_SCR *psdscr)
{
- UINT32 uiScr[4];
+ UINT32 *puiScr = (UINT32 *)psdcoredevice->COREDEV_pucExtBuf;
INT iRet;
- uiScr[0] = 0;
- uiScr[1] = 0;
- iRet = __sdCoreSendScr(psdcoredevice, uiScr + 2);
+ puiScr[0] = 0;
+ puiScr[1] = 0;
+
+ iRet = __sdCoreSendScr(psdcoredevice, puiScr + 2);
if (iRet != ERROR_NONE) {
SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "send scr error.\r\n");
return (PX_ERROR);
}
- psdscr->DEVSCR_ucSdaVsn = __getBits(uiScr, 56, 4);
- psdscr->DEVSCR_ucBusWidth = __getBits(uiScr, 48, 4);
+ psdscr->DEVSCR_ucSdaVsn = __getBits(puiScr, 56, 4);
+ psdscr->DEVSCR_ucBusWidth = __getBits(puiScr, 48, 4);
return (ERROR_NONE);
}
diff --git a/SylixOS/system/device/sdcard/core/sddrvm.c b/SylixOS/system/device/sdcard/core/sddrvm.c
index 5509b56..9db86cc 100644
--- a/SylixOS/system/device/sdcard/core/sddrvm.c
+++ b/SylixOS/system/device/sdcard/core/sddrvm.c
@@ -851,21 +851,27 @@ static INT __sdmSdioIntHandle (__SDM_HOST *psdmhost)
return (PX_ERROR);
}
- /*
- * Host 控制器可能传来假的 SDIO 中断
- * 或者是不支持硬件 SDIO 中断的 HOST进行的一次查询请求
- */
- iRet = API_SdioCoreDevReadByte(psdmdev->SDMDEV_psdcoredev,
- SDIO_CCCR_CCCR,
- SDIO_CCCR_INTX,
- &ucIntFlag);
- if (iRet != ERROR_NONE) {
- return (PX_ERROR);
- }
-
- if (ucIntFlag) {
+ if (psdmhost->SDMHOST_lCfgFlag & SDHOST_EXTOPT_CONFIG_CUSTOM_SDIO) {
__sdiobaseDevIrqHandle(psdmdev->SDMDEV_psddrv, psdmdev->SDMDEV_pvDevPriv);
return (ERROR_NONE);
+
+ } else {
+ /*
+ * Host 控制器可能传来假的 SDIO 中断
+ * 或者是不支持硬件 SDIO 中断的 HOST进行的一次查询请求
+ */
+ iRet = API_SdioCoreDevReadByte(psdmdev->SDMDEV_psdcoredev,
+ SDIO_CCCR_CCCR,
+ SDIO_CCCR_INTX,
+ &ucIntFlag);
+ if (iRet != ERROR_NONE) {
+ return (PX_ERROR);
+ }
+
+ if (ucIntFlag) {
+ __sdiobaseDevIrqHandle(psdmdev->SDMDEV_psddrv, psdmdev->SDMDEV_pvDevPriv);
+ return (ERROR_NONE);
+ }
}
#endif /* LW_CFG_SDCARD_SDIO_EN > 0 */
diff --git a/SylixOS/system/device/sdcard/core/sddrvm.h b/SylixOS/system/device/sdcard/core/sddrvm.h
index b19af1d..f6f3349 100644
--- a/SylixOS/system/device/sdcard/core/sddrvm.h
+++ b/SylixOS/system/device/sdcard/core/sddrvm.h
@@ -164,6 +164,7 @@ struct sd_host {
#define SDHOST_EXTOPT_CONFIG_RESELECT_SDIO (1 << 1) /* SDIO 每一次传输都重新选择卡 */
#define SDHOST_EXTOPT_CONFIG_SKIP_SDMEM (1 << 2) /* 跳过 SDMEM 驱动探测 */
#define SDHOST_EXTOPT_CONFIG_SKIP_SDIO (1 << 3) /* 跳过 SDIO 驱动探测 */
+#define SDHOST_EXTOPT_CONFIG_CUSTOM_SDIO (1 << 4) /* 自定义 SDIO (将不做标准初始化) */
/*********************************************************************************************************
API
diff --git a/SylixOS/system/device/sdcard/host/sdhci.c b/SylixOS/system/device/sdcard/host/sdhci.c
index c4760bd..26e5671 100644
--- a/SylixOS/system/device/sdcard/host/sdhci.c
+++ b/SylixOS/system/device/sdcard/host/sdhci.c
@@ -36,6 +36,7 @@
2016.12.16 修正 在传输过程中可能产生死锁的问题.
2017.03.15 修正 使用查询 SDIO 中断情况下, 应用线程禁止中断可能造成死锁的问题.
2017.07.10 修正 带忙应答的命令处理应考虑数据完成中断和命令完成中断的先后顺序.
+2021.07.20 增加 传输性能以及实时性等性能优化配置.
*********************************************************************************************************/
#define __SYLIXOS_KERNEL
#define __SYLIXOS_IO
@@ -86,8 +87,11 @@
/*********************************************************************************************************
传输事务线操作宏定义
*********************************************************************************************************/
-#define __SDHCI_TRANS_LOCK(pt) LW_SPIN_LOCK(&pt->SDHCITS_slLock)
-#define __SDHCI_TRANS_UNLOCK(pt) LW_SPIN_UNLOCK(&pt->SDHCITS_slLock)
+#define __SDHCI_TRANS_PREP() INTREG iregInterLevel
+#define __SDHCI_TRANS_LOCK(pt) LW_SPIN_LOCK_QUICK(&pt->SDHCITS_slLock, &iregInterLevel)
+#define __SDHCI_TRANS_UNLOCK(pt) LW_SPIN_UNLOCK_QUICK(&pt->SDHCITS_slLock, iregInterLevel)
+
+#define __SDHCI_ISRDEFER_EN(t) (t)->SDHCITS_pjobqueue
/*********************************************************************************************************
适用于控制器能发出 SDIO 硬件中断的情况
*********************************************************************************************************/
@@ -148,9 +152,7 @@ typedef struct __sdhci_capab {
*********************************************************************************************************/
struct __sdhci_trans {
__PSDHCI_HOST SDHCITS_psdhcihost;
-#if LW_CFG_VMM_EN > 0
UINT8 *SDHCITS_pucDmaBuffer;
-#endif
LW_OBJECT_HANDLE SDHCITS_hFinishSync; /* 传输事务完成同步信号 */
BOOL SDHCITS_bCmdFinish;
@@ -176,10 +178,13 @@ struct __sdhci_trans {
INT SDHCITS_iStage;
#define __SDHCI_TRANS_STAGE_START 0
#define __SDHCI_TRANS_STAGE_STOP 1
+
LW_SD_COMMAND *SDHCITS_psdcmd;
LW_SD_COMMAND *SDHCITS_psdcmdStop;
LW_SD_DATA *SDHCITS_psddat; /* 对用户请求的引用 */
+ PLW_JOB_QUEUE SDHCITS_pjobqueue;
+
LW_SPINLOCK_DEFINE (SDHCITS_slLock);
};
/*********************************************************************************************************
@@ -324,6 +329,7 @@ static INT __sdhciTransClean(__SDHCI_TRANS *psdhcitrans);
static irqreturn_t __sdhciTransIrq(VOID *pvArg, ULONG ulVector);
static PVOID __sdhciSdioIntSvr(VOID *pvArg);
+static VOID __sdhciTransHandle(__SDHCI_TRANS *psdhcitrans);
static INT __sdhciTransCmdHandle(__SDHCI_TRANS *psdhcitrans, UINT32 uiIntSta);
static INT __sdhciTransDatHandle(__SDHCI_TRANS *psdhcitrans, UINT32 uiIntSta);
@@ -332,6 +338,12 @@ static INT __sdhciTransDatFinish(__SDHCI_TRANS *psdhcitrans);
static INT __sdhciDataReadNorm(__PSDHCI_TRANS psdhcitrans);
static INT __sdhciDataWriteNorm(__PSDHCI_TRANS psdhcitrans);
+
+static VOID __sdhciTransDmaSync(__PSDHCI_TRANS psdhcitrans,
+ VOID *pvRaw,
+ VOID *pvDma,
+ UINT32 uiSize,
+ INT iSyncStage);
/*********************************************************************************************************
FOR IO ACCESS DRV
*********************************************************************************************************/
@@ -351,6 +363,7 @@ static VOID __sdhciMemWriteW(PLW_SDHCI_HOST_ATTR psdhcihostattr, ULONG ulAdd
static VOID __sdhciMemWriteB(PLW_SDHCI_HOST_ATTR psdhcihostattr, ULONG ulAddr, UINT8 ucByte);
static INT __sdhciRegAccessDrvInit(PLW_SDHCI_HOST_ATTR psdhcihostattr);
+static VOID __sdhciPerfCfgInit(SDHCI_PERF_CFG *psdhciperfcfg);
/*********************************************************************************************************
FOR DEBUG
*********************************************************************************************************/
@@ -476,6 +489,8 @@ LW_API PVOID API_SdhciHostCreate (CPCHAR pcAdapterName,
return ((PVOID)LW_NULL);
}
+ __sdhciPerfCfgInit(&psdhcihostattr->SDHCIHOST_perfcfg);
+
psdhcihost = (__PSDHCI_HOST)__SHEAP_ALLOC(sizeof(__SDHCI_HOST)); /* 分配HOST */
if (!psdhcihost) {
SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
@@ -504,8 +519,12 @@ LW_API PVOID API_SdhciHostCreate (CPCHAR pcAdapterName,
psdhcihost->SDHCIHS_psdadapter = psdadapter;
psdhcihost->SDHCIHS_atomicDevCnt.counter = 0; /* 初始设备数为0 */
- psdhcihost->SDHCIHS_pfuncMasterXfer = __sdhciTransferNorm;
- psdhcihost->SDHCIHS_ucTransferMod = SDHCIHOST_TMOD_SET_NORMAL;
+
+ psdhcihost->SDHCIHS_pfuncMasterXfer = __sdhciTransferNorm;
+ psdhcihost->SDHCIHS_ucTransferMod = SDHCIHOST_TMOD_SET_NORMAL; /* 预设模式 */
+
+ API_SdhciHostTransferModSet(psdhcihost, psdhcihostattr->SDHCIHOST_perfcfg.SDHCIPERF_iXferMode);
+
lib_memcpy(&psdhcihost->SDHCIHS_sdhcihostattr,
psdhcihostattr, sizeof(LW_SDHCI_HOST_ATTR));
/* 保存属性域 */
@@ -915,15 +934,11 @@ static INT __sdhciTransferNorm (__PSDHCI_HOST psdhcihost,
psdhcitrans = psdhcihost->SDHCIHS_psdhcitrans;
while ((i < iNum) && (psdmsg != LW_NULL)) {
- __SDHCI_TRANS_LOCK(psdhcitrans); /* 锁定传输 */
iError = __sdhciTransPrepare(psdhcitrans, psdmsg, __SDHIC_TRANS_NORMAL);
if (iError != ERROR_NONE) {
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
return (PX_ERROR);
}
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
-
iError = __sdhciTransStart(psdhcitrans);
if (iError != ERROR_NONE) {
return (PX_ERROR);
@@ -934,18 +949,14 @@ static INT __sdhciTransferNorm (__PSDHCI_HOST psdhcihost,
return (PX_ERROR);
}
- __SDHCI_TRANS_LOCK(psdhcitrans); /* 锁定传输 */
__sdhciTransClean(psdhcitrans); /* 清理本次传输 */
if (psdhcitrans->SDHCITS_iCmdError != ERROR_NONE) {
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
return (PX_ERROR);
}
if (psdhcitrans->SDHCITS_iDatError != ERROR_NONE) {
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
return (PX_ERROR);
}
- __SDHCI_TRANS_UNLOCK(psdhcitrans); /* 解锁传输 */
i++;
psdmsg++;
@@ -976,36 +987,28 @@ static INT __sdhciTransferSdma (__PSDHCI_HOST psdhcihost,
psdhcitrans = psdhcihost->SDHCIHS_psdhcitrans;
while ((i < iNum) && (psdmsg != LW_NULL)) {
- __SDHCI_TRANS_LOCK(psdhcitrans); /* 锁定传输 */
iError = __sdhciTransPrepare(psdhcitrans, psdmsg, __SDHIC_TRANS_SDMA);
if (iError != ERROR_NONE) {
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
return (PX_ERROR);
}
iError = __sdhciTransStart(psdhcitrans);
if (iError != ERROR_NONE) {
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
return (PX_ERROR);
}
- __SDHCI_TRANS_UNLOCK(psdhcitrans); /* 解锁传输 */
iError = __sdhciTransFinishWait(psdhcitrans); /* 等待本次传输完成 */
if (iError != ERROR_NONE) {
return (PX_ERROR);
}
- __SDHCI_TRANS_LOCK(psdhcitrans); /* 锁定传输 */
__sdhciTransClean(psdhcitrans); /* 清理本次传输 */
if (psdhcitrans->SDHCITS_iCmdError != ERROR_NONE) {
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
return (PX_ERROR);
}
if (psdhcitrans->SDHCITS_iDatError != ERROR_NONE) {
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
return (PX_ERROR);
}
- __SDHCI_TRANS_UNLOCK(psdhcitrans); /* 解锁传输 */
i++;
psdmsg++;
@@ -1086,8 +1089,11 @@ static INT __sdhciIoCtl (PLW_SD_ADAPTER psdadapter,
INT iCmd,
LONG lArg)
{
- __PSDHCI_HOST psdhcihost = LW_NULL;
- INT iError = ERROR_NONE;
+ __PSDHCI_HOST psdhcihost;
+ PLW_SDHCI_HOST_ATTR psdhcihostattr;
+ SDHCI_QUIRK_OP *psdhciquirkop;
+
+ INT iError = ERROR_NONE;
if (!psdadapter) {
_ErrorHandle(EINVAL);
@@ -1100,6 +1106,16 @@ static INT __sdhciIoCtl (PLW_SD_ADAPTER psdadapter,
return (PX_ERROR);
}
+ psdhcihostattr = &psdhcihost->SDHCIHS_sdhcihostattr;
+ psdhciquirkop = psdhcihostattr->SDHCIHOST_pquirkop;
+
+ if (psdhciquirkop && psdhciquirkop->SDHCIQOP_pfuncCustomIoCtl) {
+ iError = psdhciquirkop->SDHCIQOP_pfuncCustomIoCtl(psdhcihostattr, iCmd, lArg);
+ if (iError != -ENOSYS) {
+ return (iError);
+ }
+ }
+
switch (iCmd) {
case SDBUS_CTRL_POWEROFF:
@@ -1844,6 +1860,8 @@ static INT __sdhciCmdSend (__PSDHCI_HOST psdhcihost,
struct timespec tvOld;
struct timespec tvNow;
+ __SDHCI_TRANS_PREP();
+
if (!SDHCI_QUIRK_FLG(psdhcihostattr, SDHCI_QUIRK_FLG_DONOT_CHECK_BUSY_BEFORE_CMD_SEND)) {
uiMask = SDHCI_PSTA_CMD_INHIBIT;
if (psddat || SD_CMD_TEST_RSP(psdcmd, SD_RSP_BUSY)) {
@@ -1927,9 +1945,11 @@ static INT __sdhciCmdSend (__PSDHCI_HOST psdhcihost,
}
}
+ __SDHCI_TRANS_LOCK(psdhcitrans);
SDHCI_WRITEW(psdhcihostattr, SDHCI_COMMAND, SDHCI_MAKE_CMD(psdcmd->SDCMD_uiOpcode, iCmdFlg));
-
KN_IO_MB();
+ __SDHCI_TRANS_UNLOCK(psdhcitrans);
+
return (ERROR_NONE);
__timeout:
@@ -2020,25 +2040,42 @@ static VOID __sdhciDataPrepareNorm (__PSDHCI_HOST psdhcihost)
*********************************************************************************************************/
static VOID __sdhciDataPrepareSdma (__PSDHCI_HOST psdhcihost)
{
- __PSDHCI_TRANS psdhcitrans = psdhcihost->SDHCIHS_psdhcitrans;
- UINT8 *pucBuf = psdhcitrans->SDHCITS_pucDatBuffCurr;
+ __PSDHCI_TRANS psdhcitrans;
+ PLW_SDHCI_HOST_ATTR psdhcihostattr;
+ SDHCI_PERF_CFG *psdhciperfcfg;
+ UINT8 *pucRaw;
+ UINT8 *pucDma;
+ INT iSyncStage;
- if (!pucBuf) {
+ psdhcitrans = psdhcihost->SDHCIHS_psdhcitrans;
+ psdhcihostattr = &psdhcitrans->SDHCITS_psdhcihost->SDHCIHS_sdhcihostattr;
+ psdhciperfcfg = &psdhcihostattr->SDHCIHOST_perfcfg;
+ pucRaw = psdhcitrans->SDHCITS_pucDatBuffCurr;
+
+ if (!pucRaw) {
return;
}
-#if LW_CFG_VMM_EN > 0
- pucBuf = psdhcitrans->SDHCITS_pucDmaBuffer;
- if (!psdhcitrans->SDHCITS_bIsRead) {
- lib_memcpy(psdhcitrans->SDHCITS_pucDmaBuffer,
- psdhcitrans->SDHCITS_pucDatBuffCurr,
- psdhcitrans->SDHCITS_uiBlkCntRemain * psdhcitrans->SDHCITS_uiBlkSize);
+ if (psdhcitrans->SDHCITS_bIsRead) {
+ iSyncStage = SDHCI_DMASS_BEFORE_READ;
+ } else {
+ iSyncStage = SDHCI_DMASS_BEFORE_WRITE;
}
-#else
- pucBuf = psdhcitrans->SDHCITS_pucDatBuffCurr;
-#endif
- __sdhciSdmaAddrUpdate(psdhcihost, (LONG)pucBuf); /* 写入 DMA 系统地址寄存器 */
+ if (psdhciperfcfg->SDHCIPERF_uiDmaBuffAttr &
+ (SDHCI_DMABUF_CACHE_COHERENCE | SDHCI_DMABUF_USR_DIRECT)) {
+ pucDma = psdhcitrans->SDHCITS_pucDatBuffCurr;
+ } else {
+ pucDma = psdhcitrans->SDHCITS_pucDmaBuffer;
+ }
+
+ __sdhciTransDmaSync(psdhcitrans,
+ pucRaw,
+ pucDma,
+ psdhcitrans->SDHCITS_uiBlkCntRemain * psdhcitrans->SDHCITS_uiBlkSize,
+ iSyncStage);
+
+ __sdhciSdmaAddrUpdate(psdhcihost, (LONG)pucDma); /* 写入 DMA 系统地址寄存器 */
/* 命令发送后才会启动 DMA 传输 */
__sdhciDataPrepareNorm(psdhcihost);
__sdhciDmaSelect(psdhcihost, SDHCI_HCTRL_SDMA);
@@ -2179,6 +2216,63 @@ static INT __sdhciDataWriteNorm (__PSDHCI_TRANS psdhcitrans)
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: __sdhciTransDmaSync
+** 功能描述: DMA 传输数据同步
+** 输 入: psdhcitrans 传输控制块
+** pvRaw 原始数据地址
+** pvDma DMA 缓冲数据地址
+** uiSize 数据大小
+** iSyncStage 数据同步阶段标志
+** 输 出: NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __sdhciTransDmaSync (__PSDHCI_TRANS psdhcitrans,
+ VOID *pvRaw,
+ VOID *pvDma,
+ UINT32 uiSize,
+ INT iSyncStage)
+{
+ PLW_SDHCI_HOST_ATTR psdhcihostattr;
+ SDHCI_PERF_CFG *psdhciperfcfg;
+
+ psdhcihostattr = &psdhcitrans->SDHCITS_psdhcihost->SDHCIHS_sdhcihostattr;
+ psdhciperfcfg = &psdhcihostattr->SDHCIHOST_perfcfg;
+
+ if (psdhciperfcfg->SDHCIPERF_uiDmaBuffAttr & SDHCI_DMABUF_CACHE_COHERENCE) {
+ return;
+ }
+
+ if (psdhciperfcfg->SDHCIPERF_pfuncDmaSync) {
+ psdhciperfcfg->SDHCIPERF_pfuncDmaSync(pvRaw, pvDma, uiSize, iSyncStage);
+ return;
+ }
+
+ if (psdhciperfcfg->SDHCIPERF_uiDmaBuffAttr & SDHCI_DMABUF_USR_DIRECT) {
+ return;
+ }
+
+ switch (iSyncStage) {
+
+ case SDHCI_DMASS_BEFORE_READ:
+ break;
+
+ case SDHCI_DMASS_AFTER_READ:
+ lib_memcpy(pvRaw, pvDma, uiSize);
+ break;
+
+ case SDHCI_DMASS_BEFORE_WRITE:
+ lib_memcpy(pvDma, pvRaw, uiSize);
+ break;
+
+ case SDHCI_DMASS_AFTER_WRITE:
+ break;
+
+ default:
+ break;
+ }
+}
+/*********************************************************************************************************
** 函数名称: __sdhciTransferIntSet
** 功能描述: 数据传输中断设置
** 输 入: psdhcihost SDHCI HOST 结构指针
@@ -2283,11 +2377,8 @@ static __SDHCI_TRANS *__sdhciTransNew (__PSDHCI_HOST psdhcihost)
{
__SDHCI_TRANS *psdhcitrans;
LW_OBJECT_HANDLE hSync;
- INT iError;
-
-#if LW_CFG_VMM_EN > 0
VOID *pvDmaBuf;
-#endif
+ INT iError;
if (!psdhcihost) {
return (LW_NULL);
@@ -2300,14 +2391,12 @@ static __SDHCI_TRANS *__sdhciTransNew (__PSDHCI_HOST psdhcihost)
}
lib_bzero(psdhcitrans, sizeof(__SDHCI_TRANS));
-#if LW_CFG_VMM_EN > 0
- pvDmaBuf = API_VmmDmaAllocAlign(__SDHCI_DMA_BOUND_LEN, 4);
+ pvDmaBuf = API_CacheDmaMallocAlign(__SDHCI_DMA_BOUND_LEN, 4);
if (!pvDmaBuf) {
SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "system low memory.\r\n");
goto __err0;
}
psdhcitrans->SDHCITS_pucDmaBuffer = (UINT8 *)pvDmaBuf;
-#endif
hSync = API_SemaphoreBCreate("sdhcits_sync", LW_FALSE, LW_OPTION_OBJECT_GLOBAL, LW_NULL);
if (hSync == LW_OBJECT_HANDLE_INVALID) {
@@ -2316,9 +2405,6 @@ static __SDHCI_TRANS *__sdhciTransNew (__PSDHCI_HOST psdhcihost)
LW_SPIN_INIT(&psdhcitrans->SDHCITS_slLock);
-#if LW_CFG_VMM_EN > 0
- psdhcitrans->SDHCITS_pucDmaBuffer = pvDmaBuf;
-#endif
psdhcitrans->SDHCITS_hFinishSync = hSync;
psdhcitrans->SDHCITS_psdhcihost = psdhcihost;
psdhcihost->SDHCIHS_psdhcitrans = psdhcitrans;
@@ -2340,11 +2426,9 @@ __err2:
API_SemaphoreBDelete(&hSync);
__err1:
-#if LW_CFG_VMM_EN > 0
- API_VmmDmaFree(pvDmaBuf);
+ API_CacheDmaFree(pvDmaBuf);
__err0:
-#endif
__SHEAP_FREE(psdhcitrans);
return (LW_NULL);
@@ -2359,12 +2443,15 @@ __err0:
*********************************************************************************************************/
static INT __sdhciTransTaskInit (__SDHCI_TRANS *psdhcitrans)
{
- LW_OBJECT_HANDLE hSdioIntSem;
- LW_OBJECT_HANDLE hSdioIntThread;
- LW_CLASS_THREADATTR threadattr;
- LW_SDHCI_HOST_ATTR *psdhcihostattr;
+ LW_OBJECT_HANDLE hSdioIntSem;
+ LW_OBJECT_HANDLE hSdioIntThread;
+ LW_CLASS_THREADATTR threadattr;
+ LW_SDHCI_HOST_ATTR *psdhcihostattr;
+ SDHCI_PERF_CFG *psdhciperfcfg;
psdhcihostattr = &psdhcitrans->SDHCITS_psdhcihost->SDHCIHS_sdhcihostattr;
+ psdhciperfcfg = &psdhcihostattr->SDHCIHOST_perfcfg;
+
if (SDHCI_QUIRK_FLG(psdhcihostattr, SDHCI_QUIRK_FLG_SDIO_INT_OOB)) {
return (ERROR_NONE);
}
@@ -2390,7 +2477,7 @@ static INT __sdhciTransTaskInit (__SDHCI_TRANS *psdhcitrans)
threadattr = API_ThreadAttrGetDefault();
threadattr.THREADATTR_pvArg = (PVOID)psdhcitrans;
- threadattr.THREADATTR_ucPriority = __SDHCI_SDIOINTSVR_PRIO;
+ threadattr.THREADATTR_ucPriority = psdhciperfcfg->SDHCIPERF_iSdioSvrPrio;
threadattr.THREADATTR_stStackByteSize = __SDHCI_SDIOINTSVR_STKSZ;
threadattr.THREADATTR_ulOption |= LW_OPTION_OBJECT_GLOBAL;
hSdioIntThread = API_ThreadCreate("t_sdhcisdio",
@@ -2401,6 +2488,10 @@ static INT __sdhciTransTaskInit (__SDHCI_TRANS *psdhcitrans)
goto __err;
}
psdhcitrans->SDHCITS_hSdioIntThread = hSdioIntThread;
+
+ if (psdhciperfcfg->SDHCIPERF_iIsrDeferNum >= 0) {
+ psdhcitrans->SDHCITS_pjobqueue = API_InterDeferGet((ULONG)psdhciperfcfg->SDHCIPERF_iIsrDeferNum);
+ }
return (ERROR_NONE);
@@ -2453,11 +2544,7 @@ static VOID __sdhciTransDel (__SDHCI_TRANS *psdhcitrans)
API_InterVectorDisconnect(ulVector, __sdhciTransIrq, (VOID *)psdhcitrans);
__sdhciTransTaskDeInit(psdhcitrans);
-
-#if LW_CFG_VMM_EN > 0
- API_VmmDmaFree(psdhcitrans->SDHCITS_pucDmaBuffer);
-#endif
-
+ API_CacheDmaFree(psdhcitrans->SDHCITS_pucDmaBuffer);
API_SemaphoreBDelete(&psdhcitrans->SDHCITS_hFinishSync);
__SHEAP_FREE(psdhcitrans);
}
@@ -2554,7 +2641,6 @@ static INT __sdhciTransStart (__SDHCI_TRANS *psdhcitrans)
__sdhciHostReset(psdhcitrans->SDHCITS_psdhcihost, SDHCI_SFRST_DATA | SDHCI_SFRST_CMD);
}
-
if (SDHCI_QUIRK_FLG(&psdhcitrans->SDHCITS_psdhcihost->SDHCIHS_sdhcihostattr,
SDHCI_QUIRK_FLG_REENABLE_INTS_ON_EVERY_TRANSACTION)) {
__sdhciIntClear(psdhcitrans->SDHCITS_psdhcihost);
@@ -2572,14 +2658,12 @@ static INT __sdhciTransStart (__SDHCI_TRANS *psdhcitrans)
}
psdhcitrans->SDHCITS_iStage = __SDHCI_TRANS_STAGE_START;
+
+ API_SemaphoreBClear(psdhcitrans->SDHCITS_hFinishSync);
iRet = __sdhciCmdSend(psdhcitrans->SDHCITS_psdhcihost,
psdhcitrans->SDHCITS_psdcmd,
psdhcitrans->SDHCITS_psddat);
- if (iRet != ERROR_NONE) {
- API_SemaphoreBClear(psdhcitrans->SDHCITS_hFinishSync);
- }
-
return (iRet);
}
/*********************************************************************************************************
@@ -2618,19 +2702,24 @@ static VOID __sdhciTransFinish (__SDHCI_TRANS *psdhcitrans)
*********************************************************************************************************/
static INT __sdhciTransClean (__SDHCI_TRANS *psdhcitrans)
{
+ __SDHCI_TRANS_PREP();
+
if (!psdhcitrans) {
return (PX_ERROR);
}
- psdhcitrans->SDHCITS_psdcmd = LW_NULL;
- psdhcitrans->SDHCITS_psdcmdStop = LW_NULL;
- psdhcitrans->SDHCITS_psddat = LW_NULL;
+ __SDHCI_TRANS_LOCK(psdhcitrans);
+ psdhcitrans->SDHCITS_psdcmd = LW_NULL;
+ psdhcitrans->SDHCITS_psdcmdStop = LW_NULL;
+ psdhcitrans->SDHCITS_psddat = LW_NULL;
+ psdhcitrans->SDHCITS_pucDatBuffCurr = LW_NULL;
if (SDHCI_QUIRK_FLG(&psdhcitrans->SDHCITS_psdhcihost->SDHCIHS_sdhcihostattr,
SDHCI_QUIRK_FLG_REENABLE_INTS_ON_EVERY_TRANSACTION)) {
__sdhciIntDisAndEn(psdhcitrans->SDHCITS_psdhcihost, SDHCI_INT_ALL_MASK, 0);
__sdhciIntClear(psdhcitrans->SDHCITS_psdhcihost);
}
+ __SDHCI_TRANS_UNLOCK(psdhcitrans);
API_SemaphoreBClear(psdhcitrans->SDHCITS_hFinishSync);
@@ -2650,31 +2739,82 @@ static irqreturn_t __sdhciTransIrq (VOID *pvArg, ULONG ulVector)
__SDHCI_TRANS *psdhcitrans = (__SDHCI_TRANS *)pvArg;
__SDHCI_HOST *psdhcihost = psdhcitrans->SDHCITS_psdhcihost;
LW_SDHCI_HOST_ATTR *psdhcihostattr = &psdhcihost->SDHCIHS_sdhcihostattr;
- BOOL bSdioInt = LW_FALSE;
-
+ ULONG ulIntFlag = 0;
+ irqreturn_t irqret = LW_IRQ_HANDLED;
UINT32 uiIntSta;
- irqreturn_t irqret;
+
+ __SDHCI_TRANS_PREP();
if (psdhcihostattr->SDHCIHOST_pquirkop &&
psdhcihostattr->SDHCIHOST_pquirkop->SDHCIQOP_pfuncIsrEnterHook) {
psdhcihostattr->SDHCIHOST_pquirkop->SDHCIQOP_pfuncIsrEnterHook(psdhcihostattr);
}
+__redo:
+ __SDHCI_TRANS_LOCK(psdhcitrans);
uiIntSta = SDHCI_READL(psdhcihostattr, SDHCI_INT_STATUS);
+ psdhcitrans->SDHCITS_uiIntSta = uiIntSta;
+ SDHCI_WRITEL(psdhcihostattr, SDHCI_INT_STATUS, uiIntSta);
+ __SDHCI_TRANS_UNLOCK(psdhcitrans);
-__redo:
if (!uiIntSta || uiIntSta == 0xffffffff) {
SDHCI_WRITEL(psdhcihostattr, SDHCI_INT_STATUS, uiIntSta);
SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "unknown int signals\r\n");
- irqret = LW_IRQ_NONE;
- goto __end; /* 无效或未知的中断 */
+
+ API_InterVectorGetFlag(ulVector, &ulIntFlag);
+ if (ulIntFlag & LW_IRQ_FLAG_QUEUE) {
+ irqret = LW_IRQ_NONE;
+ }
+
+ goto __end;
}
- SDHCI_WRITEL(psdhcihostattr, SDHCI_INT_STATUS, uiIntSta);
+ if (__SDHCI_ISRDEFER_EN(psdhcitrans)) {
+ API_InterVectorDisable(ulVector);
+ API_InterDeferJobAdd(psdhcitrans->SDHCITS_pjobqueue,
+ (VOIDFUNCPTR)__sdhciTransHandle,
+ (PVOID)psdhcitrans);
+ } else {
+ __sdhciTransHandle(psdhcitrans);
+ }
- __SDHCI_TRANS_LOCK(psdhcitrans);
+ /*
+ * 有的控制器在处理完当前的中断后, 可能会再次产生新的中断状态,
+ * 该状态不一定能在之后以硬件中断的方式通知 CPU,
+ * 该情况下需要再次查询直到处理完成.
+ */
+ if (SDHCI_QUIRK_FLG(psdhcihostattr, SDHCI_QUIRK_FLG_RECHECK_INTS_AFTER_ISR)) {
+ goto __redo;
+ }
- psdhcitrans->SDHCITS_uiIntSta = uiIntSta;
+__end:
+ if (psdhcihostattr->SDHCIHOST_pquirkop &&
+ psdhcihostattr->SDHCIHOST_pquirkop->SDHCIQOP_pfuncIsrExitHook) {
+ psdhcihostattr->SDHCIHOST_pquirkop->SDHCIQOP_pfuncIsrExitHook(psdhcihostattr);
+ }
+
+ return (irqret);
+}
+/*********************************************************************************************************
+** 函数名称: __sdhciTransHandle
+** 功能描述: SDHCI 传输处理程序
+** 输 入: psdhcitrans 传输控制块
+** 输 出: NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __sdhciTransHandle (__SDHCI_TRANS *psdhcitrans)
+{
+ __SDHCI_HOST *psdhcihost = psdhcitrans->SDHCITS_psdhcihost;
+ LW_SDHCI_HOST_ATTR *psdhcihostattr = &psdhcihost->SDHCIHS_sdhcihostattr;
+ BOOL bSdioInt = LW_FALSE;
+ UINT32 uiIntSta;
+
+ __SDHCI_TRANS_PREP();
+
+ __SDHCI_TRANS_LOCK(psdhcitrans);
+ uiIntSta = psdhcitrans->SDHCITS_uiIntSta;
+ __SDHCI_TRANS_UNLOCK(psdhcitrans);
if (uiIntSta & SDHCI_INT_CMD_MASK) {
SDHCI_WRITEL(psdhcihostattr, SDHCI_INT_STATUS, uiIntSta & SDHCI_INT_CMD_MASK);
@@ -2718,8 +2858,6 @@ __redo:
SDHCI_WRITEL(psdhcihostattr, SDHCI_INT_STATUS, uiIntSta);
}
- irqret = LW_IRQ_HANDLED;
-
KN_IO_MB();
if (!SDHCI_QUIRK_FLG(psdhcihostattr, SDHCI_QUIRK_FLG_CANNOT_SDIO_INT) &&
@@ -2729,29 +2867,9 @@ __redo:
__SDHCI_SDIO_NOTIFY(psdhcitrans);
}
- /*
- * 有的控制器在处理完当前的中断后, 可能会再次产生新的中断状态,
- * 该状态不一定能在之后以硬件中断的方式通知 CPU,
- * 该情况下需要再次查询直到处理完成.
- */
- if (SDHCI_QUIRK_FLG(psdhcihostattr, SDHCI_QUIRK_FLG_RECHECK_INTS_AFTER_ISR)) {
- uiIntSta = SDHCI_READL(psdhcihostattr, SDHCI_INT_STATUS);
- if (uiIntSta) {
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
- bSdioInt = LW_FALSE;
- goto __redo;
- }
+ if (__SDHCI_ISRDEFER_EN(psdhcitrans)) {
+ API_InterVectorEnable(psdhcihostattr->SDHCIHOST_ulIntVector);
}
-
- __SDHCI_TRANS_UNLOCK(psdhcitrans);
-
-__end:
- if (psdhcihostattr->SDHCIHOST_pquirkop &&
- psdhcihostattr->SDHCIHOST_pquirkop->SDHCIQOP_pfuncIsrExitHook) {
- psdhcihostattr->SDHCIHOST_pquirkop->SDHCIQOP_pfuncIsrExitHook(psdhcihostattr);
- }
-
- return (irqret);
}
/*********************************************************************************************************
** 函数名称: __sdhciSdioIntSvr
@@ -2896,13 +3014,23 @@ static INT __sdhciTransDatHandle (__SDHCI_TRANS *psdhcitrans, UINT32 uiIntSta)
{
LW_SDHCI_HOST_ATTR *psdhcihostattr = &psdhcitrans->SDHCITS_psdhcihost->SDHCIHS_sdhcihostattr;
SDHCI_QUIRK_OP *psdhciquirkop = psdhcihostattr->SDHCIHOST_pquirkop;
+ LW_SD_COMMAND *psdcmd;
+ BOOL bStop;
/*
* 当没有数据传输时, 如果命令包含了 忙等待信号, 则也会产生数据完成中断
* 详见 SDHCI 规范 2.2.17(page64)
*/
- if (!psdhcitrans->SDHCITS_pucDatBuffCurr) {
- if (SD_CMD_TEST_RSP(psdhcitrans->SDHCITS_psdcmd, SD_RSP_BUSY)) {
+ if (psdhcitrans->SDHCITS_iStage == __SDHCI_TRANS_STAGE_START) {
+ psdcmd = psdhcitrans->SDHCITS_psdcmd;
+ bStop = LW_FALSE;
+ } else {
+ psdcmd = psdhcitrans->SDHCITS_psdcmdStop;
+ bStop = LW_TRUE;
+ }
+
+ if (bStop || !psdhcitrans->SDHCITS_pucDatBuffCurr) {
+ if (psdcmd && SD_CMD_TEST_RSP(psdcmd, SD_RSP_BUSY)) {
if (uiIntSta & SDHCI_INT_DATA_TIMEOUT) {
psdhcitrans->SDHCITS_iDatError = PX_ERROR;
SDCARD_DEBUG_MSG(__ERRORMESSAGE_LEVEL, "timeout on busy irq.\r\n");
@@ -3114,17 +3242,35 @@ static INT __sdhciTransDatFinish (__SDHCI_TRANS *psdhcitrans)
{
LW_SDHCI_HOST_ATTR *psdhcihostattr = &psdhcitrans->SDHCITS_psdhcihost->SDHCIHS_sdhcihostattr;
-#if LW_CFG_VMM_EN > 0
- if (psdhcitrans->SDHCITS_iDatError == ERROR_NONE) {
- if (psdhcitrans->SDHCITS_bIsRead &&
- (psdhcitrans->SDHCITS_iTransType != __SDHIC_TRANS_NORMAL)) {
+ if ((psdhcitrans->SDHCITS_iDatError == ERROR_NONE) &&
+ (psdhcitrans->SDHCITS_iTransType != __SDHIC_TRANS_NORMAL)) {
+ SDHCI_PERF_CFG *psdhciperfcfg;
+ UINT8 *pucRaw;
+ UINT8 *pucDma;
+ INT iSyncStage;
+
+ psdhciperfcfg = &psdhcihostattr->SDHCIHOST_perfcfg;
+ pucRaw = psdhcitrans->SDHCITS_pucDatBuffCurr;
+
+ if (psdhcitrans->SDHCITS_bIsRead) {
+ iSyncStage = SDHCI_DMASS_AFTER_READ;
+ } else {
+ iSyncStage = SDHCI_DMASS_AFTER_WRITE;
+ }
- lib_memcpy(psdhcitrans->SDHCITS_pucDatBuffCurr,
- psdhcitrans->SDHCITS_pucDmaBuffer,
- psdhcitrans->SDHCITS_uiBlkSize * psdhcitrans->SDHCITS_uiBlkCntRemain);
+ if (psdhciperfcfg->SDHCIPERF_uiDmaBuffAttr &
+ (SDHCI_DMABUF_CACHE_COHERENCE | SDHCI_DMABUF_USR_DIRECT)) {
+ pucDma = psdhcitrans->SDHCITS_pucDatBuffCurr;
+ } else {
+ pucDma = psdhcitrans->SDHCITS_pucDmaBuffer;
}
+
+ __sdhciTransDmaSync(psdhcitrans,
+ pucRaw,
+ pucDma,
+ psdhcitrans->SDHCITS_uiBlkCntRemain * psdhcitrans->SDHCITS_uiBlkSize,
+ iSyncStage);
}
-#endif
if (SDHCI_QUIRK_FLG(psdhcihostattr, SDHCI_QUIRK_FLG_DONOT_USE_ACMD12)) {
if (psdhcitrans->SDHCITS_psdcmdStop) {
@@ -3182,14 +3328,67 @@ static INT __sdhciRegAccessDrvInit (PLW_SDHCI_HOST_ATTR psdhcihostattr)
/*
* 如果提供了自己的寄存器访问驱动则不使用默认的方法
+ * 且允许部分重构驱动方法
*/
- if (!psdhcihostattr->SDHCIHOST_pdrvfuncs) {
+ if (psdhcihostattr->SDHCIHOST_pdrvfuncs) {
+ if ((iType != SDHCI_REGACCESS_TYPE_IO) &&
+ (iType != SDHCI_REGACCESS_TYPE_MEM)) {
+ SDCARD_DEBUG_MSG(__PRINTMESSAGE_LEVEL, "warning: sdhci io access type not valid, "
+ "default to memory access type.\r\n");
+ iType = SDHCI_REGACCESS_TYPE_MEM;
+ }
+
+#define __SDHCI_DRV_COMPLETE(op) \
+ if (!psdhcihostattr->SDHCIHOST_pdrvfuncs->op) { \
+ psdhcihostattr->SDHCIHOST_pdrvfuncs->op = \
+ _G_sdhcidrvfuncTbl[iType].op; \
+ }
+
+ __SDHCI_DRV_COMPLETE(sdhciReadB);
+ __SDHCI_DRV_COMPLETE(sdhciReadW);
+ __SDHCI_DRV_COMPLETE(sdhciReadL);
+ __SDHCI_DRV_COMPLETE(sdhciWriteB);
+ __SDHCI_DRV_COMPLETE(sdhciWriteW);
+ __SDHCI_DRV_COMPLETE(sdhciWriteL);
+#undef __SDHCI_DRV_OVERWRITE
+
+ } else {
psdhcihostattr->SDHCIHOST_pdrvfuncs = &_G_sdhcidrvfuncTbl[iType];
}
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: __sdhciPerfCfgInit
+** 功能描述: 性能配置参数初始化
+** 输 入: psdhciperfcfg 性能配置对象
+** 输 出: NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID __sdhciPerfCfgInit (SDHCI_PERF_CFG *psdhciperfcfg)
+{
+ if (psdhciperfcfg->SDHCIPERF_uiValidMagic != SDHCI_PERF_MAGIC) {
+ psdhciperfcfg->SDHCIPERF_iIsrDeferNum = 0;
+ psdhciperfcfg->SDHCIPERF_iSdioSvrPrio = __SDHCI_SDIOINTSVR_PRIO;
+ psdhciperfcfg->SDHCIPERF_iXferMode = SDHCIHOST_TMOD_SET_NORMAL;
+ psdhciperfcfg->SDHCIPERF_uiDmaBuffAttr = 0;
+ psdhciperfcfg->SDHCIPERF_pfuncDmaSync = LW_NULL;
+ }
+
+ if (psdhciperfcfg->SDHCIPERF_iXferMode == SDHCIHOST_TMOD_SET_ADMA) {
+ psdhciperfcfg->SDHCIPERF_iXferMode = SDHCIHOST_TMOD_SET_SDMA;
+ }
+
+ if (psdhciperfcfg->SDHCIPERF_iSdioSvrPrio < 0) {
+ psdhciperfcfg->SDHCIPERF_iSdioSvrPrio = __SDHCI_SDIOINTSVR_PRIO;
+ }
+
+ if (psdhciperfcfg->SDHCIPERF_iSdioSvrPrio > LW_PRIO_LOWEST) {
+ psdhciperfcfg->SDHCIPERF_iSdioSvrPrio = LW_PRIO_LOWEST;
+ }
+}
+/*********************************************************************************************************
** 函数名称: __sdhciIoReadL
** 功能描述: IO 空间读取32位长度的数据
** 输 入: uiAddr IO 空间地址
diff --git a/SylixOS/system/device/sdcard/host/sdhci.h b/SylixOS/system/device/sdcard/host/sdhci.h
index 0d07168..6b43cc6 100644
--- a/SylixOS/system/device/sdcard/host/sdhci.h
+++ b/SylixOS/system/device/sdcard/host/sdhci.h
@@ -32,7 +32,8 @@
2015.12.17 增加对 MMC/eMMC 总线位宽的兼容性处理.
2017.02.28 增加 SDIO 外设额外电源设置和带外 SDIO 中断的 Quirk 操作.
2018.05.22 增加 SD 卡仅能使用1位模式的处理.
- 增加 PIO 模式平台相关延时处理.
+ 增加 PIO 模式平台相关延时处理.
+2021.07.20 增加 传输性能以及实时性等性能优化配置.
*********************************************************************************************************/
#ifndef __SDHCI_H
@@ -461,6 +462,62 @@
#define SDHCIHOST_TMOD_CAN_ADMA (1 << 2)
/*********************************************************************************************************
+ SD 标准主控性能相关配置
+
+ SDHCIPERF_iIsrDeferNum
+ < 0 : 则不使用中断底半部处理
+ > 0 : 代表中断底半部分处理绑定的CPU核心号(依赖LW_CFG_ISR_DEFER_EN/LW_CFG_ISR_DEFER_PER_CPU 配置)
+
+ SDHCIPERF_iSdioSvrPrio
+ sdio 服务线程优先级. 如果小于0, 则使用默认值
+
+ SDHCIPERF_iXferMode
+ 可选择: SDHCIHOST_TMOD_SET_XXXX. 可不再使用: API_SdhciHostTransferModSet()
+
+ SDHCIPERF_iDmaBuffAttr
+ 用于指明使用 DMA 传输时, DMA缓冲区的属性
+ SDHCI_DMABUF_CACHE_COHERENCE :
+ 如果确保传输的缓冲区是cache一致性的,则设置此标志指示内部不进行数据同步
+
+ SDHCI_DMABUF_USR_DIRECT :
+ 该标志指示直接使用上层提供的缓冲区用于DMA传输, 且同步方式由驱动决定
+
+ 注: 以上两种标志不允许同时使用
+
+ SDHCIPERF_pfuncDmaSync
+ 仅在使用 DMA 传输的时候使用, 驱动可根据当前的平台特性进行优化(如使用cache操作, 优化的内存拷贝等)
+ 参数 iSyncStage 为: SDHCI_DMASS_BEFORE_XXXX
+ 如果为 LW_NULL, 则默认使用 memcpy() 操作
+
+ 特别注意: 如果使用了SIMD指令的拷贝函数,则必须使能中断底半部功能
+*********************************************************************************************************/
+
+#define SDHCI_PERF_MAGIC 0xabcd4321
+
+#define SDHCI_DMASS_BEFORE_READ 0
+#define SDHCI_DMASS_AFTER_READ 1
+#define SDHCI_DMASS_BEFORE_WRITE 2
+#define SDHCI_DMASS_AFTER_WRITE 3
+
+typedef struct _sdhci_perf_cfg {
+ UINT32 SDHCIPERF_uiValidMagic;
+ INT SDHCIPERF_iIsrDeferNum;
+ INT SDHCIPERF_iSdioSvrPrio;
+
+ INT SDHCIPERF_iXferMode;
+ UINT32 SDHCIPERF_uiDmaBuffAttr;
+#define SDHCI_DMABUF_CACHE_COHERENCE (1 << 0)
+#define SDHCI_DMABUF_USR_DIRECT (1 << 1)
+
+ VOID (*SDHCIPERF_pfuncDmaSync)(VOID *pvRaw,
+ VOID *pvDma,
+ UINT32 uiSize,
+ INT iSyncStage);
+
+ ULONG SDHCIPERF_ulReserved[8];
+} SDHCI_PERF_CFG;
+
+/*********************************************************************************************************
SD 标准主控制器属性结构
*********************************************************************************************************/
@@ -528,6 +585,10 @@ typedef struct lw_sdhci_host_attr {
#define SDHCI_QUIRK_FLG_SD_FORCE_1BIT (1 << 18) /* SD 卡强制使用1位总线 */
VOID *SDHCIHOST_pvUsrSpec; /* 用户驱动特殊数据 */
+
+ SDHCI_PERF_CFG SDHCIHOST_perfcfg; /* 性能相关配置 */
+ ULONG SDHCIHOST_ulReserved[12];
+
} LW_SDHCI_HOST_ATTR, *PLW_SDHCI_HOST_ATTR;
#define SDHCI_QUIRK_FLG(pattr, flg) ((pattr)->SDHCIHOST_uiQuirkFlag & (flg))
@@ -657,6 +718,14 @@ struct _sdhci_quirk_op {
PLW_SDHCI_HOST_ATTR psdhcihostattr,
BOOL bIsRead
);
+ INT (*SDHCIQOP_pfuncCustomIoCtl) /* 自定义总线控制操作 */
+ ( /* 如果返回值为-ENOSYS */
+ PLW_SDHCI_HOST_ATTR psdhcihostattr, /* 则使用默认操作 */
+ INT iCmd,
+ LONG lArg
+ );
+
+ ULONG ulReserved[12];
};
/*********************************************************************************************************
diff --git a/SylixOS/system/device/shm/shm.c b/SylixOS/system/device/shm/shm.c
index 319ad1b..acb9de9 100644
--- a/SylixOS/system/device/shm/shm.c
+++ b/SylixOS/system/device/shm/shm.c
@@ -47,13 +47,14 @@ typedef struct lw_shm_node {
#define SHMN_pvLink SHMN_pvPhyMem
ULONG SHMN_ulMapCnt; /* 映射计数器 */
mode_t SHMN_mode; /* 节点类型 */
+ INT SHMN_iFlag; /* 文件标志 */
time_t SHMN_time; /* 节点时间, 一般为当前时间 */
uid_t SHMN_uid;
gid_t SHMN_gid;
} LW_SHM_NODE;
typedef LW_SHM_NODE *PLW_SHM_NODE;
/*********************************************************************************************************
- shm根
+ shm 根
*********************************************************************************************************/
typedef struct lw_shm_root {
PLW_LIST_LINE SHMR_plineSon; /* 指向第一个儿子 */
@@ -85,6 +86,7 @@ static INT _G_iShmDrvNum = PX_ERROR;
*********************************************************************************************************/
static INT __shmPhymemAlloc(PLW_SHM_NODE pshmn);
static INT __shmPhymemFree(PLW_SHM_NODE pshmn);
+static INT __shmTruncate(PLW_SHM_NODE pshmn, off_t oftSize);
/*********************************************************************************************************
** 函数名称: __shmFindNode
** 功能描述: 共享内存设备查找一个节点
@@ -304,6 +306,7 @@ static INT __shmMakeNode (CPCHAR pcName, INT iFlags, INT iMode, CPCHAR pcLi
pshmnNew->SHMN_oftSize = 0;
pshmnNew->SHMN_ulMapCnt = 0; /* 没有映射 */
pshmnNew->SHMN_mode = iMode;
+ pshmnNew->SHMN_iFlag = iFlags;
pshmnNew->SHMN_time = lib_time(LW_NULL); /* 以 UTC 时间作为时间基准 */
pshmnNew->SHMN_uid = getuid();
pshmnNew->SHMN_gid = getgid();
@@ -489,6 +492,12 @@ static LONG __shmOpen (LW_DEV_HDR *pdevhdr,
LW_DEV_INC_USE_COUNT(&_G_devhdrShm); /* 更新计数器 */
return ((LONG)LW_NULL);
}
+
+ if ((iFlags & O_TRUNC) &&
+ ((iFlags & O_ACCMODE) == O_RDONLY)) { /* 需要截断但为只读 */
+ _ErrorHandle(EACCES);
+ return ((LONG)LW_NULL);
+ }
if (iFlags & O_CREAT) { /* 这里不过滤 socket 文件 */
if (__fsCheckFileName(pcName)) {
@@ -501,15 +510,8 @@ static LONG __shmOpen (LW_DEV_HDR *pdevhdr,
_ErrorHandle(ERROR_IO_DISK_NOT_PRESENT); /* 不支持以上这些格式 */
return (PX_ERROR);
}
- }
-
- if (iFlags & O_TRUNC) { /* 不允许打开截断 */
- _ErrorHandle(ENOSYS);
- return (PX_ERROR);
- }
-
- if (iFlags & O_CREAT) { /* 创建目录或文件 */
- iError = __shmMakeNode(pcName, iFlags, iMode, LW_NULL);
+
+ iError = __shmMakeNode(pcName, iFlags, iMode, LW_NULL); /* 创建目录或文件 */
if ((iError != ERROR_NONE) && (iFlags & O_EXCL)) {
return (PX_ERROR); /* 无法创建 */
}
@@ -522,10 +524,16 @@ static LONG __shmOpen (LW_DEV_HDR *pdevhdr,
if (!S_ISLNK(pshmn->SHMN_mode)) { /* 不是链接文件 */
__LW_SHM_UNLOCK(); /* 解锁共享内存设备 */
LW_DEV_INC_USE_COUNT(&_G_devhdrShm); /* 更新计数器 */
+
+ if (iFlags & O_TRUNC) { /* 需要截断 */
+ __shmTruncate(pshmn, 0);
+ }
+
return ((LONG)pshmn);
}
} else {
__LW_SHM_UNLOCK(); /* 解锁共享内存设备 */
+ _ErrorHandle(ENOENT);
return (PX_ERROR);
}
__LW_SHM_UNLOCK(); /* 解锁共享内存设备 */
@@ -953,6 +961,11 @@ static INT __shmTruncate (PLW_SHM_NODE pshmn, off_t oftSize)
_ErrorHandle(EINVAL);
return (PX_ERROR);
}
+ if ((pshmn->SHMN_iFlag & O_ACCMODE) == O_RDONLY) { /* 权限不足 */
+ __LW_SHM_UNLOCK(); /* 解锁共享内存设备 */
+ _ErrorHandle(EACCES);
+ return (PX_ERROR);
+ }
if (pshmn->SHMN_oftSize == oftSize) {
__LW_SHM_UNLOCK(); /* 解锁共享内存设备 */
return (ERROR_NONE);
@@ -1006,7 +1019,7 @@ static INT __shmMmap (PLW_SHM_NODE pshmn, PLW_DEV_MMAP_AREA pdmap)
pshmn->SHMN_ulMapCnt++; /* mmap 计数++ */
ulPhysical = (addr_t)pshmn->SHMN_pvPhyMem;
- ulPhysical += (addr_t)(pdmap->DMAP_offPages << LW_CFG_VMM_PAGE_SHIFT);
+ ulPhysical += (addr_t)(pdmap->DMAP_offPages << LW_CFG_VMM_PAGE_SHIFT);
if (API_VmmRemapArea(pdmap->DMAP_pvAddr, (PVOID)ulPhysical,
pdmap->DMAP_stLen, pdmap->DMAP_ulFlag, /* 直接使用 mmap 指定的 flag */
diff --git a/SylixOS/system/device/spipe/spipeLib.c b/SylixOS/system/device/spipe/spipeLib.c
index 3763899..211032e 100644
--- a/SylixOS/system/device/spipe/spipeLib.c
+++ b/SylixOS/system/device/spipe/spipeLib.c
@@ -871,6 +871,11 @@ INT _SpipeIoctl (PLW_SPIPE_FILE pspipefil,
LW_SPIPE_UNLOCK(pspipedev);
break;
+ case FIOSYNC: /* 不能进行同步操作 */
+ iErrCode = PX_ERROR;
+ _ErrorHandle(EINVAL);
+ break;
+
default:
iErrCode = PX_ERROR;
_ErrorHandle(ERROR_IO_UNKNOWN_REQUEST);
diff --git a/SylixOS/system/device/ty/tyLib.c b/SylixOS/system/device/ty/tyLib.c
index 9ce21b3..f91fd13 100644
--- a/SylixOS/system/device/ty/tyLib.c
+++ b/SylixOS/system/device/ty/tyLib.c
@@ -886,7 +886,10 @@ ssize_t _TyWrite (TY_DEV_ID ptyDev,
LW_SPIN_LOCK_QUICK(&ptyDev->TYDEV_slLock, &iregInterLevel); /* 锁定 spinlock 并关闭中断 */
if (rngFreeBytes(ptyDev->TYDEV_vxringidWrBuf) > 0) {
LW_SPIN_UNLOCK_QUICK(&ptyDev->TYDEV_slLock, iregInterLevel);/* 解锁 spinlock 打开中断 */
- API_SemaphoreBPost(ptyDev->TYDEV_hWrtSyncSemB); /* 缓冲区还有空间 */
+ ulError = API_SemaphoreBPost(ptyDev->TYDEV_hWrtSyncSemB); /* 缓冲区还有空间 */
+ if (ulError == ERROR_EVENT_FULL) {
+ errno = ERROR_NONE; /* 错误码清零 */
+ }
} else {
LW_SPIN_UNLOCK_QUICK(&ptyDev->TYDEV_slLock, iregInterLevel);/* 解锁 spinlock 打开中断 */
diff --git a/SylixOS/system/ioLib/ioInterface.c b/SylixOS/system/ioLib/ioInterface.c
index 7c1960d..1ad66db 100644
--- a/SylixOS/system/ioLib/ioInterface.c
+++ b/SylixOS/system/ioLib/ioInterface.c
@@ -105,6 +105,7 @@ static INT _G_iIoStdFd[3] = {PX_ERROR, PX_ERROR, PX_ERROR}; /* 全局
** 输 入 : pcName 文件名
** iFlag 方式 O_RDONLY O_WRONLY O_RDWR O_CREAT
** iMode UNIX MODE
+** bCreate 是否只调用创建接口
** 输 出 : 文件描述符
** 全局变量:
** 调用模块:
diff --git a/SylixOS/system/ioLib/ioPath.c b/SylixOS/system/ioLib/ioPath.c
index 9740708..53173f6 100644
--- a/SylixOS/system/ioLib/ioPath.c
+++ b/SylixOS/system/ioLib/ioPath.c
@@ -103,14 +103,16 @@ VOID _PathCondense (PCHAR pcPathName)
*pcTemp = PX_DIVIDER; /* 转换分隔符 */
if (iDotNum > 1) { /* 双点, 将忽略上一级目录 */
- /*
- * XXX 起始字符必须为 / 否则这里的后退会多出一个字符!
- */
__LW_PATH_PUTBACK(pcNode, pcTail); /* 退回到上一级目录 */
+ if (!__LW_PATH_IS_DIVIDER(*pcNode)) {
+ bNotInc = LW_FALSE; /* 清除掉不包含 */
+ }
+
} else if (iDotNum == 1) { /* 单点 */
/*
* 什么也不处理, 直接忽略此目录.
*/
+
} else {
/*
* 这里直接拷贝分隔符但不改变保存指针.
diff --git a/SylixOS/system/ptimer/ptimer.c b/SylixOS/system/ptimer/ptimer.c
index e892cc2..0a03e23 100644
--- a/SylixOS/system/ptimer/ptimer.c
+++ b/SylixOS/system/ptimer/ptimer.c
@@ -86,7 +86,7 @@ static VOID __ptimerHookInstall (VOID)
(不得在中断中调用)
*********************************************************************************************************/
LW_API
-INT timer_create (clockid_t clockid, struct sigevent *sigeventT, timer_t *ptimer)
+INT timer_create (clockid_t clockid, struct sigevent *sigeventT, timer_t *ptimer)
{
return (timer_create_internal(clockid, sigeventT, ptimer, LW_OPTION_NONE));
}
@@ -101,8 +101,10 @@ INT timer_create (clockid_t clockid, struct sigevent *sigeventT, timer_t *ptim
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-INT timer_create_internal (clockid_t clockid, struct sigevent *sigeventT,
- timer_t *ptimer, ULONG ulOption)
+INT timer_create_internal (clockid_t clockid,
+ struct sigevent *sigeventT,
+ timer_t *ptimer,
+ ULONG ulOption)
{
#if LW_CFG_PTIMER_AUTO_DEL_EN > 0
static INT iIsInstallHook = 0;
@@ -629,7 +631,7 @@ INT setitimer (INT iWhich,
return (iError);
}
/*********************************************************************************************************
-** 函数名称: setitimer
+** 函数名称: getitimer
** 功能描述: 获取内部定时器
** 输 入 : iWhich 类型, 仅支持 ITIMER_REAL
** pitValue 获取当前定时信息
@@ -641,7 +643,7 @@ INT setitimer (INT iWhich,
(不得在中断中调用)
*********************************************************************************************************/
LW_API
-INT getitimer (INT iWhich, struct itimerval *pitValue)
+INT getitimer (INT iWhich, struct itimerval *pitValue)
{
ULONG ulGetCounter;
ULONG ulGetInterval;
@@ -702,7 +704,7 @@ UINT alarm (UINT uiSeconds)
(不得在中断中调用)
*********************************************************************************************************/
LW_API
-useconds_t ualarm (useconds_t usec, useconds_t usecInterval)
+useconds_t ualarm (useconds_t usec, useconds_t usecInterval)
{
struct itimerval tvValue, tvOld;
diff --git a/SylixOS/system/select/select.h b/SylixOS/system/select/select.h
index 6bb7e02..24d8fea 100644
--- a/SylixOS/system/select/select.h
+++ b/SylixOS/system/select/select.h
@@ -87,7 +87,7 @@ LW_API INT select(INT iWidth,
fd_set *pfdsetWrite,
fd_set *pfdsetExcept,
struct timeval *ptmvalTO); /* BSD 标准 select() */
-
+
LW_API INT pselect(INT iWidth,
fd_set *pfdsetRead,
fd_set *pfdsetWrite,
@@ -101,7 +101,7 @@ LW_API INT waitread(INT iFd, struct timeval *ptmvalTO); /* 等待
LW_API INT waitwrite(INT iFd, struct timeval *ptmvalTO); /* 等待单个文件可写 */
LW_API INT waitexcept(INT iFd, struct timeval *ptmvalTO); /* 等待单个文件可异常 */
-#endif /* __SYLIXOS_EXTEND */
+#endif /* __SYLIXOS_EXTEND */
#endif /* (LW_CFG_DEVICE_EN > 0) && */
/* (LW_CFG_SELECT_EN > 0) */
diff --git a/SylixOS/system/signal/signal.c b/SylixOS/system/signal/signal.c
index 607a163..91a0639 100644
--- a/SylixOS/system/signal/signal.c
+++ b/SylixOS/system/signal/signal.c
@@ -537,7 +537,7 @@ INT sigsetmask (INT iMask)
return (iMaskOld);
}
/*********************************************************************************************************
-** 函数名称: sigsetblock
+** 函数名称: sigblock
** 功能描述: 将新的需要阻塞的信号添加到当前线程 (BSD 兼容)
** 输 入 : iBlock 新的阻塞信号掩码
** 输 出 : 先早的掩码
@@ -710,7 +710,7 @@ INT siginterrupt (INT iSigNo, INT iFlag)
API 函数
*********************************************************************************************************/
LW_API
-INT sigstack (struct sigstack *ss, struct sigstack *oss)
+INT sigstack (struct sigstack *ss, struct sigstack *oss)
{
stack_t stackNew, stackOld;
@@ -754,7 +754,7 @@ INT sigstack (struct sigstack *ss, struct sigstack *oss)
API 函数
*********************************************************************************************************/
LW_API
-INT sigaltstack (const stack_t *ss, stack_t *oss)
+INT sigaltstack (const stack_t *ss, stack_t *oss)
{
PLW_CLASS_TCB ptcbCur;
PLW_CLASS_SIGCONTEXT psigctx;
@@ -1097,7 +1097,7 @@ INT sigqueue (LW_OBJECT_HANDLE ulId, INT iSigNo, const union sigval sigvalu
return (__sigqueue(ulId, iSigNo, sigvalue.sival_ptr));
}
/*********************************************************************************************************
-** 函数名称: sigTrap
+** 函数名称: __sig_trap
** 功能描述: 向指定任务发送信号, 同时停止自己. (本程序在异常上下文中执行)
** 输 入 : ulIdSig 线程 id (不允许为进程号)
** ulIdStop 需要等待结束的线程
diff --git a/SylixOS/system/signal/signalLib.c b/SylixOS/system/signal/signalLib.c
index 79d17ff..58bf9e8 100644
--- a/SylixOS/system/signal/signalLib.c
+++ b/SylixOS/system/signal/signalLib.c
@@ -290,7 +290,7 @@ static VOID __signalStkShowHandle (PLW_CLASS_TCB ptcbCur, PLW_CLASS_SIGCTLMSG
*********************************************************************************************************/
static VOID __sigTaskCreateHook (LW_OBJECT_HANDLE ulId)
{
- PLW_CLASS_TCB ptcb = __GET_TCB_FROM_INDEX(_ObjectGetIndex(ulId));
+ PLW_CLASS_TCB ptcb = __GET_TCB_FROM_INDEX(_ObjectGetIndex(ulId));
PLW_CLASS_SIGCONTEXT psigctx = _signalGetCtx(ptcb);
#if LW_CFG_MODULELOADER_EN > 0
@@ -993,7 +993,7 @@ INT _sigPendGet (PLW_CLASS_SIGCONTEXT psigctx, const sigset_t *psigset, struc
** 调用模块:
** 注 意 :
*********************************************************************************************************/
-static BOOL _sigPendRunSelf (VOID)
+static BOOL _sigPendRunSelf (VOID)
{
PLW_CLASS_TCB ptcbCur;
PLW_CLASS_SIGCONTEXT psigctx;
diff --git a/SylixOS/vpmpdm/vpmpdm_start.c b/SylixOS/vpmpdm/vpmpdm_start.c
index a3ede0b..f370487 100644
--- a/SylixOS/vpmpdm/vpmpdm_start.c
+++ b/SylixOS/vpmpdm/vpmpdm_start.c
@@ -303,6 +303,7 @@ int setenv (const char *name, const char *value, int rewrite)
if ((saveenv = malloc(size)) == NULL)
goto bad;
(void)memcpy(saveenv, environ, cnt * sizeof(char *));
+ free(environ);
}
environ = saveenv;
environ[cnt + 1] = NULL;
diff --git a/libsylixos.mk b/libsylixos.mk
index 25f16a5..19bdd43 100644
--- a/libsylixos.mk
+++ b/libsylixos.mk
@@ -811,6 +811,7 @@ SylixOS/fs/diskCache/diskCachePipeline.c \
SylixOS/fs/diskCache/diskCacheProc.c \
SylixOS/fs/diskCache/diskCacheSync.c \
SylixOS/fs/diskPartition/diskPartition.c \
+SylixOS/fs/diskPartition/gptPartition.c \
SylixOS/fs/diskRaid/diskRaid0.c \
SylixOS/fs/diskRaid/diskRaid1.c \
SylixOS/fs/diskRaid/diskRaidLib.c \