summaryrefslogtreecommitdiffstatsabout
path: root/SylixOS
diff options
context:
space:
mode:
authorHanhui <hanhui@acoinfo.com>2020-07-22 14:47:01 (GMT)
committer Hanhui <hanhui@acoinfo.com>2020-07-22 14:47:01 (GMT)
commitb4279ee1b1591c21f9f452c8d4271c0336704a1a (patch)
tree433325ef699ce5af1d8b488a7c7c61646fbdb565 /SylixOS
parenta1485a81a25651e8e8ba16627bc36222ad72d8cb (diff)
downloadlibsylixos-b4279ee1b1591c21f9f452c8d4271c0336704a1a.zip
libsylixos-b4279ee1b1591c21f9f452c8d4271c0336704a1a.tar.gz
libsylixos-b4279ee1b1591c21f9f452c8d4271c0336704a1a.tar.bz2
Fixed FPU enable without initialize context error.
Diffstat (limited to 'SylixOS')
-rw-r--r--SylixOS/arch/arm/fpu/armFpu.c6
-rw-r--r--SylixOS/arch/arm64/fpu/arm64Fpu.c6
-rw-r--r--SylixOS/arch/csky/fpu/cskyFpu.c6
-rw-r--r--SylixOS/arch/mips/dsp/mipsDsp.c6
-rw-r--r--SylixOS/arch/mips/fpu/mipsFpu.c6
-rw-r--r--SylixOS/arch/ppc/dsp/ppcDsp.c6
-rw-r--r--SylixOS/arch/ppc/fpu/ppcFpu.c6
-rw-r--r--SylixOS/arch/riscv/fpu/riscvFpu.c6
-rw-r--r--SylixOS/arch/sparc/fpu/sparcFpu.c6
-rw-r--r--SylixOS/arch/x86/fpu/x86Fpu.c8
-rw-r--r--SylixOS/kernel/interface/InterEnterExit.c4
-rw-r--r--SylixOS/net/lwip/tools/nat/lwip_natlib.c23
12 files changed, 73 insertions, 16 deletions
diff --git a/SylixOS/arch/arm/fpu/armFpu.c b/SylixOS/arch/arm/fpu/armFpu.c
index 1340562..9748efd 100644
--- a/SylixOS/arch/arm/fpu/armFpu.c
+++ b/SylixOS/arch/arm/fpu/armFpu.c
@@ -243,12 +243,16 @@ VOID archFpuCtxShow (INT iFd, PVOID pvFpuCtx)
*********************************************************************************************************/
INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
{
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (ptcbCur->TCB_ulOption & LW_OPTION_THREAD_USED_FP) {
return (PX_ERROR);
}
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_FP;
- ARM_VFP_ENABLE(_G_pfpuop); /* 使能 FPU */
+ ARM_VFP_RESTORE(_G_pfpuop, ptcbCur->TCB_pvStackFP); /* 使能 FPU, 初始化 FPU 寄存器 */
return (ERROR_NONE);
}
diff --git a/SylixOS/arch/arm64/fpu/arm64Fpu.c b/SylixOS/arch/arm64/fpu/arm64Fpu.c
index c54da81..6e51065 100644
--- a/SylixOS/arch/arm64/fpu/arm64Fpu.c
+++ b/SylixOS/arch/arm64/fpu/arm64Fpu.c
@@ -190,12 +190,16 @@ VOID archFpuCtxShow (INT iFd, PVOID pvFpuCtx)
*********************************************************************************************************/
INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
{
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (ptcbCur->TCB_ulOption & LW_OPTION_THREAD_USED_FP) {
return (PX_ERROR);
}
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_FP;
- ARM64_VFP_ENABLE(_G_pfpuop); /* 使能 FPU */
+ ARM64_VFP_RESTORE(_G_pfpuop, ptcbCur->TCB_pvStackFP); /* 使能 FPU, 初始化 FPU 寄存器 */
return (ERROR_NONE);
}
diff --git a/SylixOS/arch/csky/fpu/cskyFpu.c b/SylixOS/arch/csky/fpu/cskyFpu.c
index ef0d333..8fe00c5 100644
--- a/SylixOS/arch/csky/fpu/cskyFpu.c
+++ b/SylixOS/arch/csky/fpu/cskyFpu.c
@@ -188,12 +188,16 @@ VOID archFpuCtxShow (INT iFd, PVOID pvFpuCtx)
*********************************************************************************************************/
INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
{
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (ptcbCur->TCB_ulOption & LW_OPTION_THREAD_USED_FP) {
return (PX_ERROR);
}
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_FP;
- CSKY_VFP_ENABLE(_G_pfpuop); /* 使能 FPU */
+ CSKY_VFP_RESTORE(_G_pfpuop, ptcbCur->TCB_pvStackFP); /* 使能 FPU, 初始化 FPU 寄存器 */
return (ERROR_NONE);
}
diff --git a/SylixOS/arch/mips/dsp/mipsDsp.c b/SylixOS/arch/mips/dsp/mipsDsp.c
index c8ddae1..a6a9c5b 100644
--- a/SylixOS/arch/mips/dsp/mipsDsp.c
+++ b/SylixOS/arch/mips/dsp/mipsDsp.c
@@ -201,6 +201,10 @@ VOID archDspCtxShow (INT iFd, PVOID pvDspCtx)
*********************************************************************************************************/
INT archDspUndHandle (PLW_CLASS_TCB ptcbCur)
{
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (MIPS_DSP_ISENABLE(_G_pdspop)) { /* 如果当前上下文 DSP 使能 */
return (PX_ERROR); /* 此未定义指令与 DSP 无关 */
}
@@ -208,7 +212,7 @@ INT archDspUndHandle (PLW_CLASS_TCB ptcbCur)
MIPS_DSP_ENABLE_TASK(_G_pdspop, ptcbCur); /* 任务使能 DSP */
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_DSP;
- MIPS_DSP_ENABLE(_G_pdspop); /* 使能 DSP */
+ MIPS_DSP_RESTORE(_G_pdspop, ptcbCur->TCB_pvStackDSP); /* 使能 DSP, 初始化 DSP 寄存器 */
return (ERROR_NONE);
}
diff --git a/SylixOS/arch/mips/fpu/mipsFpu.c b/SylixOS/arch/mips/fpu/mipsFpu.c
index ba192f6..041ef7b 100644
--- a/SylixOS/arch/mips/fpu/mipsFpu.c
+++ b/SylixOS/arch/mips/fpu/mipsFpu.c
@@ -260,6 +260,10 @@ INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
{
UINT32 uiConfig1;
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (ptcbCur->TCB_ulOption & LW_OPTION_THREAD_USED_FP) {
return (PX_ERROR);
}
@@ -273,7 +277,7 @@ INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
}
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_FP;
- MIPS_VFP_ENABLE(_G_pfpuop); /* 使能 FPU */
+ MIPS_VFP_RESTORE(_G_pfpuop, ptcbCur->TCB_pvStackFP); /* 使能 FPU, 初始化 FPU 寄存器 */
return (ERROR_NONE);
}
diff --git a/SylixOS/arch/ppc/dsp/ppcDsp.c b/SylixOS/arch/ppc/dsp/ppcDsp.c
index 0b0b591..fc34130 100644
--- a/SylixOS/arch/ppc/dsp/ppcDsp.c
+++ b/SylixOS/arch/ppc/dsp/ppcDsp.c
@@ -185,6 +185,10 @@ VOID archDspCtxShow (INT iFd, PVOID pvDspCtx)
*********************************************************************************************************/
INT archDspUndHandle (PLW_CLASS_TCB ptcbCur)
{
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (PPC_DSP_ISENABLE(_G_pdspop)) { /* 如果当前上下文 DSP 使能 */
return (PX_ERROR); /* 此未定义指令与 DSP 无关 */
}
@@ -192,7 +196,7 @@ INT archDspUndHandle (PLW_CLASS_TCB ptcbCur)
PPC_DSP_ENABLE_TASK(_G_pdspop, ptcbCur); /* 任务使能 DSP */
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_DSP;
- PPC_DSP_ENABLE(_G_pdspop); /* 使能 DSP */
+ PPC_DSP_RESTORE(_G_pdspop, ptcbCur->TCB_pvStackDSP); /* 使能 DSP, 初始化 DSP 寄存器 */
return (ERROR_NONE);
}
diff --git a/SylixOS/arch/ppc/fpu/ppcFpu.c b/SylixOS/arch/ppc/fpu/ppcFpu.c
index ca61593..57f5678 100644
--- a/SylixOS/arch/ppc/fpu/ppcFpu.c
+++ b/SylixOS/arch/ppc/fpu/ppcFpu.c
@@ -206,6 +206,10 @@ VOID archFpuCtxShow (INT iFd, PVOID pvFpuCtx)
*********************************************************************************************************/
INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
{
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (ptcbCur->TCB_ulOption & LW_OPTION_THREAD_USED_FP) {
return (PX_ERROR);
}
@@ -213,7 +217,7 @@ INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
PPC_VFP_ENABLE_TASK(_G_pfpuop, ptcbCur); /* 任务使能 FPU */
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_FP;
- PPC_VFP_ENABLE(_G_pfpuop); /* 使能 FPU */
+ PPC_VFP_RESTORE(_G_pfpuop, ptcbCur->TCB_pvStackFP); /* 使能 FPU, 初始化 FPU 寄存器 */
return (ERROR_NONE);
}
diff --git a/SylixOS/arch/riscv/fpu/riscvFpu.c b/SylixOS/arch/riscv/fpu/riscvFpu.c
index 771a0dd..ddc026d 100644
--- a/SylixOS/arch/riscv/fpu/riscvFpu.c
+++ b/SylixOS/arch/riscv/fpu/riscvFpu.c
@@ -187,6 +187,10 @@ VOID archFpuCtxShow (INT iFd, PVOID pvFpuCtx)
*********************************************************************************************************/
INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
{
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (ptcbCur->TCB_ulOption & LW_OPTION_THREAD_USED_FP) {
return (PX_ERROR);
}
@@ -194,7 +198,7 @@ INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
RISCV_VFP_ENABLE_TASK(_G_pfpuop, ptcbCur); /* 任务使能 FPU */
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_FP;
- RISCV_VFP_ENABLE(_G_pfpuop); /* 使能 FPU */
+ RISCV_VFP_RESTORE(_G_pfpuop, ptcbCur->TCB_pvStackFP); /* 使能 FPU, 初始化 FPU 寄存器 */
return (ERROR_NONE);
}
diff --git a/SylixOS/arch/sparc/fpu/sparcFpu.c b/SylixOS/arch/sparc/fpu/sparcFpu.c
index b857c98..92fc6f3 100644
--- a/SylixOS/arch/sparc/fpu/sparcFpu.c
+++ b/SylixOS/arch/sparc/fpu/sparcFpu.c
@@ -183,6 +183,10 @@ VOID archFpuCtxShow (INT iFd, PVOID pvFpuCtx)
*********************************************************************************************************/
INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
{
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (ptcbCur->TCB_ulOption & LW_OPTION_THREAD_USED_FP) {
return (PX_ERROR);
}
@@ -190,7 +194,7 @@ INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
SPARC_VFP_ENABLE_TASK(_G_pfpuop, ptcbCur); /* 任务使能 FPU */
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_FP;
- SPARC_VFP_ENABLE(_G_pfpuop); /* 使能 FPU */
+ SPARC_VFP_RESTORE(_G_pfpuop, ptcbCur->TCB_pvStackFP); /* 使能 FPU, 初始化 FPU 寄存器 */
return (ERROR_NONE);
}
diff --git a/SylixOS/arch/x86/fpu/x86Fpu.c b/SylixOS/arch/x86/fpu/x86Fpu.c
index 587be78..fca26e9 100644
--- a/SylixOS/arch/x86/fpu/x86Fpu.c
+++ b/SylixOS/arch/x86/fpu/x86Fpu.c
@@ -178,6 +178,10 @@ VOID archFpuCtxShow (INT iFd, PVOID pvFpuCtx)
*********************************************************************************************************/
INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
{
+ if (LW_CPU_GET_CUR_NESTING() > 1) { /* 中断中发生异常, 返回出错 */
+ return (PX_ERROR);
+ }
+
if (ptcbCur->TCB_ulOption & LW_OPTION_THREAD_USED_FP) {
return (PX_ERROR);
}
@@ -185,8 +189,8 @@ INT archFpuUndHandle (PLW_CLASS_TCB ptcbCur)
X86_FPU_ENABLE_TASK(_G_pfpuop, ptcbCur); /* 任务使能 FPU */
ptcbCur->TCB_ulOption |= LW_OPTION_THREAD_USED_FP;
- X86_FPU_ENABLE(_G_pfpuop); /* 使能 FPU */
-
+ X86_FPU_RESTORE(_G_pfpuop, ptcbCur->TCB_pvStackFP); /* 使能 FPU, 初始化 FPU 寄存器 */
+
return (ERROR_NONE);
}
diff --git a/SylixOS/kernel/interface/InterEnterExit.c b/SylixOS/kernel/interface/InterEnterExit.c
index 199b840..4977c73 100644
--- a/SylixOS/kernel/interface/InterEnterExit.c
+++ b/SylixOS/kernel/interface/InterEnterExit.c
@@ -64,7 +64,7 @@ static VOID __fpuInterEnter (PLW_CLASS_CPU pcpu)
__ARCH_FPU_SAVE(ptcbCur->TCB_pvStackFP); /* 保存当前被中断线程 FPU CTX */
} else {
- __ARCH_FPU_ENABLE(); /* 使能当前中断下 FPU */
+ __ARCH_FPU_RESTORE(__INTER_FPU_CTX(ulInterNesting - 1)); /* 使能当前中断下 FPU */
}
} else {
@@ -122,7 +122,7 @@ static VOID __dspInterEnter (PLW_CLASS_CPU pcpu)
__ARCH_DSP_SAVE(ptcbCur->TCB_pvStackDSP); /* 保存当前被中断线程 DSP CTX */
} else {
- __ARCH_DSP_ENABLE(); /* 使能当前中断下 DSP */
+ __ARCH_DSP_RESTORE(__INTER_DSP_CTX(ulInterNesting - 1)); /* 使能当前中断下 DSP */
}
} else {
diff --git a/SylixOS/net/lwip/tools/nat/lwip_natlib.c b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
index 91cddd6..a845226 100644
--- a/SylixOS/net/lwip/tools/nat/lwip_natlib.c
+++ b/SylixOS/net/lwip/tools/nat/lwip_natlib.c
@@ -42,6 +42,7 @@
2019.05.20 MAP 0.0.0.0 作为本机映射.
2020.02.25 三大协议皆使用 Hash 表, 提高转发查找速度.
2020.06.30 增加网络接口退出 NAT 功能.
+2020.07.22 不拦截本机 DHCP 端口.
*********************************************************************************************************/
#define __SYLIXOS_STDIO
#define __SYLIXOS_KERNEL
@@ -59,6 +60,7 @@
#include "lwip/ip.h"
#include "lwip/ip4_frag.h"
#include "lwip/tcp.h"
+#include "lwip/prot/iana.h"
#include "lwip/priv/tcp_priv.h"
#include "lwip/udp.h"
#include "lwip/icmp.h"
@@ -888,6 +890,13 @@ static INT __natApInput (struct pbuf *p, struct netif *netifIn)
if ((ucProto != IP_PROTO_ICMP) &&
((PP_NTOHS(usDestPort) < LW_CFG_NET_NAT_MIN_PORT) ||
(PP_NTOHS(usDestPort) > LW_CFG_NET_NAT_MAX_PORT))) { /* 目标端口不在代理端口之间 */
+
+ if ((ucProto == IP_PROTO_UDP) &&
+ (udphdr->src == PP_HTONS(LWIP_IANA_PORT_DHCP_SERVER)) &&
+ (udphdr->dest == PP_HTONS(LWIP_IANA_PORT_DHCP_CLIENT))) { /* 本机为 DHCP 客户端 */
+ return (0); /* 直接放行 */
+ }
+
for (plineTemp = _G_plineNatmap;
plineTemp != LW_NULL;
plineTemp = _list_line_get_next(plineTemp)) {
@@ -1134,6 +1143,12 @@ static INT __natApOutput (struct pbuf *p, struct netif *pnetifIn, struct netif
return (1); /* 不能处理的协议 */
}
+ if (!pnetifIn && (ucProto == IP_PROTO_UDP) &&
+ (udphdr->src == PP_HTONS(LWIP_IANA_PORT_DHCP_CLIENT)) &&
+ (udphdr->dest == PP_HTONS(LWIP_IANA_PORT_DHCP_SERVER))) { /* 本机为 DHCP 客户端 */
+ return (0); /* 直接放行 */
+ }
+
for (plineTemp = plineHeader;
plineTemp != LW_NULL;
plineTemp = _list_line_get_next(plineTemp)) {
@@ -1257,11 +1272,13 @@ static INT __natApOutput (struct pbuf *p, struct netif *pnetifIn, struct netif
static struct pbuf *__natIpInput (struct pbuf *p, struct netif *pnetifIn, struct netif *pnetifOut)
{
struct ip_hdr *iphdr;
+ const ip4_addr_t *ipaddr;
- iphdr = (struct ip_hdr *)p->payload;
+ iphdr = (struct ip_hdr *)p->payload;
+ ipaddr = netif_ip4_addr(pnetifIn);
- if (!ip4_addr_cmp(&iphdr->dest, netif_ip4_addr(pnetifIn))) { /* 只允许发送至本机 */
- pbuf_free(p);
+ if ((ipaddr->addr != IPADDR_ANY) && !ip4_addr_cmp(&iphdr->dest, ipaddr)) {
+ pbuf_free(p); /* 只允许发送至本机 */
return (LW_NULL);
}