Index: asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/Debug/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/Debug/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/Debug/Makefile	(revision 387)
@@ -204,6 +204,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 APPLDIRS := $(APPLDIRS) ../../ntshell/lcd
 APPL_COBJS := $(APPL_COBJS) draw_font.o shnm12_font.o
Index: asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/DebugEnbt/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/DebugEnbt/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/DebugEnbt/Makefile	(revision 387)
@@ -204,6 +204,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 APPLDIRS := $(APPLDIRS) ../../ntshell/lcd
 APPL_COBJS := $(APPL_COBJS) draw_font.o shnm12_font.o
Index: asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/DebugEther/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/DebugEther/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/DebugEther/Makefile	(revision 387)
@@ -204,6 +204,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 APPLDIRS := $(APPLDIRS) ../../ntshell/lcd
 APPL_COBJS := $(APPL_COBJS) draw_font.o shnm12_font.o
Index: asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/src/main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/src/main.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/src/main.c	(revision 387)
@@ -66,10 +66,6 @@
 #include "ffarch.h"
 #include "ff.h"
-#include "core/ntshell.h"
-#include "core/ntlibc.h"
 #include <stdio.h>
 #include "usrcmd.h"
-#include "util/ntopt.h"
-#include "socket_stub.h"
 #include "gpio_api.h"
 #include "usb_hbth.h"
Index: asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/src/main.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/src/main.cdl	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app1_usb_watt_meter/src/main.cdl	(revision 387)
@@ -22,5 +22,5 @@
  *  ターゲット依存部の取り込み
  */
-import("target.cdl");
+import("ntshell.cdl");
 
 /*
Index: asp3_tinet_ecnl_arm/trunk/app2_light/Debug/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app2_light/Debug/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app2_light/Debug/Makefile	(revision 387)
@@ -189,6 +189,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 
 #
Index: asp3_tinet_ecnl_arm/trunk/app2_light/DebugEther/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app2_light/DebugEther/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app2_light/DebugEther/Makefile	(revision 387)
@@ -187,6 +187,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 
 #
Index: asp3_tinet_ecnl_arm/trunk/app2_light/src/main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app2_light/src/main.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app2_light/src/main.c	(revision 387)
@@ -65,10 +65,6 @@
 #include "ffarch.h"
 #include "ff.h"
-#include "core/ntshell.h"
-#include "core/ntlibc.h"
 #include <stdio.h>
 #include "usrcmd.h"
-#include "util/ntopt.h"
-#include "socket_stub.h"
 #include "gpio_api.h"
 #include "usb_hbth.h"
Index: asp3_tinet_ecnl_arm/trunk/app2_light/src/main.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app2_light/src/main.cdl	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app2_light/src/main.cdl	(revision 387)
@@ -22,5 +22,5 @@
  *  ターゲット依存部の取り込み
  */
-import("target.cdl");
+import("ntshell.cdl");
 
 /*
Index: asp3_tinet_ecnl_arm/trunk/app3_human_detec/Debug/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app3_human_detec/Debug/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app3_human_detec/Debug/Makefile	(revision 387)
@@ -189,6 +189,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 
 #
Index: asp3_tinet_ecnl_arm/trunk/app3_human_detec/DebugEther/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app3_human_detec/DebugEther/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app3_human_detec/DebugEther/Makefile	(revision 387)
@@ -187,6 +187,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 
 #
Index: asp3_tinet_ecnl_arm/trunk/app3_human_detec/src/main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app3_human_detec/src/main.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app3_human_detec/src/main.c	(revision 387)
@@ -65,10 +65,6 @@
 #include "ffarch.h"
 #include "ff.h"
-#include "core/ntshell.h"
-#include "core/ntlibc.h"
 #include <stdio.h>
 #include "usrcmd.h"
-#include "util/ntopt.h"
-#include "socket_stub.h"
 #include "gpio_api.h"
 #include "usb_hbth.h"
Index: asp3_tinet_ecnl_arm/trunk/app3_human_detec/src/main.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app3_human_detec/src/main.cdl	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app3_human_detec/src/main.cdl	(revision 387)
@@ -22,5 +22,5 @@
  *  ターゲット依存部の取り込み
  */
-import("target.cdl");
+import("ntshell.cdl");
 
 /*
Index: asp3_tinet_ecnl_arm/trunk/app4_aircon/Debug/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app4_aircon/Debug/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app4_aircon/Debug/Makefile	(revision 387)
@@ -195,6 +195,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 APPLDIRS := $(APPLDIRS) ../../ntshell/lcd
 APPL_COBJS := $(APPL_COBJS) draw_font.o shnm12_font.o
Index: asp3_tinet_ecnl_arm/trunk/app4_aircon/DebugEther/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app4_aircon/DebugEther/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app4_aircon/DebugEther/Makefile	(revision 387)
@@ -193,6 +193,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 APPLDIRS := $(APPLDIRS) ../../ntshell/lcd
 APPL_COBJS := $(APPL_COBJS) draw_font.o shnm12_font.o
Index: asp3_tinet_ecnl_arm/trunk/app4_aircon/src/main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app4_aircon/src/main.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app4_aircon/src/main.c	(revision 387)
@@ -65,10 +65,6 @@
 #include "ffarch.h"
 #include "ff.h"
-#include "core/ntshell.h"
-#include "core/ntlibc.h"
 #include <stdio.h>
 #include "usrcmd.h"
-#include "util/ntopt.h"
-#include "socket_stub.h"
 #include "gpio_api.h"
 #include "usb_hbth.h"
Index: asp3_tinet_ecnl_arm/trunk/app4_aircon/src/main.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app4_aircon/src/main.cdl	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app4_aircon/src/main.cdl	(revision 387)
@@ -22,5 +22,5 @@
  *  ターゲット依存部の取り込み
  */
-import("target.cdl");
+import("ntshell.cdl");
 
 /*
Index: asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/Debug/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/Debug/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/Debug/Makefile	(revision 387)
@@ -195,6 +195,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 APPLDIRS := $(APPLDIRS) ../../ntshell/lcd
 APPL_COBJS := $(APPL_COBJS) draw_font.o shnm12_font.o
Index: asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/DebugEther/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/DebugEther/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/DebugEther/Makefile	(revision 387)
@@ -193,6 +193,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 APPLDIRS := $(APPLDIRS) ../../ntshell/lcd
 APPL_COBJS := $(APPL_COBJS) draw_font.o shnm12_font.o
Index: asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.c	(revision 387)
@@ -65,10 +65,6 @@
 #include "ffarch.h"
 #include "ff.h"
-#include "core/ntshell.h"
-#include "core/ntlibc.h"
 #include <stdio.h>
 #include "usrcmd.h"
-#include "util/ntopt.h"
-#include "socket_stub.h"
 #include "gpio_api.h"
 #include "usb_hbth.h"
Index: asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.cdl	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.cdl	(revision 387)
@@ -22,5 +22,5 @@
  *  ターゲット依存部の取り込み
  */
-import("target.cdl");
+import("ntshell.cdl");
 
 /*
Index: asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/Debug/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/Debug/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/Debug/Makefile	(revision 387)
@@ -189,6 +189,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 
 #
Index: asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/DebugEther/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/DebugEther/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/DebugEther/Makefile	(revision 387)
@@ -187,6 +187,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 
 #
Index: asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/src/main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/src/main.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/src/main.c	(revision 387)
@@ -65,10 +65,6 @@
 #include "ffarch.h"
 #include "ff.h"
-#include "core/ntshell.h"
-#include "core/ntlibc.h"
 #include <stdio.h>
 #include "usrcmd.h"
-#include "util/ntopt.h"
-#include "socket_stub.h"
 #include "gpio_api.h"
 #include "usb_hbth.h"
Index: asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/src/main.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/src/main.cdl	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app6_hot_water_pot/src/main.cdl	(revision 387)
@@ -22,5 +22,5 @@
  *  ターゲット依存部の取り込み
  */
-import("target.cdl");
+import("ntshell.cdl");
 
 /*
Index: asp3_tinet_ecnl_arm/trunk/app7_buzzer/Debug/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app7_buzzer/Debug/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app7_buzzer/Debug/Makefile	(revision 387)
@@ -189,6 +189,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 
 #
Index: asp3_tinet_ecnl_arm/trunk/app7_buzzer/DebugEther/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app7_buzzer/DebugEther/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app7_buzzer/DebugEther/Makefile	(revision 387)
@@ -187,6 +187,6 @@
 APPLDIRS := $(APPLDIRS) $(SRCDIR)/$(TINETDIR)/netapp
 APPL_COBJS := $(APPL_COBJS) ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o
-APPLDIRS := $(APPLDIRS) ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
-APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPLDIRS := $(APPLDIRS) ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src
+APPL_COBJS := $(APPL_COBJS) netcmd.o fdtable.o stdio_stub.o io_stub.o socket_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 
 #
Index: asp3_tinet_ecnl_arm/trunk/app7_buzzer/src/main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app7_buzzer/src/main.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app7_buzzer/src/main.c	(revision 387)
@@ -65,10 +65,6 @@
 #include "ffarch.h"
 #include "ff.h"
-#include "core/ntshell.h"
-#include "core/ntlibc.h"
 #include <stdio.h>
 #include "usrcmd.h"
-#include "util/ntopt.h"
-#include "socket_stub.h"
 #include "gpio_api.h"
 #include "usb_hbth.h"
Index: asp3_tinet_ecnl_arm/trunk/app7_buzzer/src/main.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app7_buzzer/src/main.cdl	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/app7_buzzer/src/main.cdl	(revision 387)
@@ -22,5 +22,5 @@
  *  ターゲット依存部の取り込み
  */
-import("target.cdl");
+import("ntshell.cdl");
 
 /*
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/gdic/adafruit_ssd1306/Makefile.config
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/gdic/adafruit_ssd1306/Makefile.config	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/gdic/adafruit_ssd1306/Makefile.config	(revision 387)
@@ -39,5 +39,5 @@
 #  @(#) $Id$
 #
- 
+
 #
 #  Makefile のプロセッサ依存 (adafruit ssd1306:OLED用)
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/mbed_stub.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/mbed_stub.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/mbed_stub.c	(revision 387)
@@ -66,4 +66,6 @@
 #include "t_syslog.h"
 
+extern void musl_start(const char *const args);
+
 int main()
 {
@@ -182,6 +184,5 @@
 }
 
-__attribute__((weak))
-void *SYS_brk(void *addr)
+void *shell_brk(void *addr)
 {
 	if (addr == 0) {
@@ -194,6 +195,5 @@
 }
 
-__attribute__((weak))
-void *SYS_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
+void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
 {
 	if (fd != -1)
@@ -206,6 +206,5 @@
 }
 
-__attribute__((weak))
-int SYS_mprotect(void *addr, size_t len, int prot)
+int shell_mprotect(void *addr, size_t len, int prot)
 {
 	//if ((addr >= (void *)&__HeapBase) && (addr + len < (void *)&__HeapLimit)) {
@@ -216,4 +215,19 @@
 
 __attribute__((weak))
+long SYS_brk(long a) {
+	return (long)shell_brk((void *)a);
+}
+
+__attribute__((weak))
+long SYS_mmap2(long a, long b, long c, long d, long e, long f, long g) {
+	return (int)shell_mmap2((void *)a, (size_t)b, (int)c, (int)d, (int)e, ((off_t)f << 32) | (off_t)g);
+}
+
+__attribute__((weak))
+long SYS_mprotect(long a, long b, long c) {
+	return shell_mprotect((void *)a, (size_t)b, (int)c);
+}
+
+__attribute__((weak))
 long SYS_madvise()
 {
@@ -235,4 +249,5 @@
 int malloc_lock_sem_count[TNUM_TSKID];
 
+__attribute__((weak))
 void __malloc_lock(struct _reent *_r)
 {
@@ -261,4 +276,5 @@
 }
 
+__attribute__((weak))
 void __malloc_unlock(struct _reent *_r)
 {
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/tMbedSerial.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/tMbedSerial.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/tMbedSerial.c	(revision 387)
@@ -130,7 +130,5 @@
 
 	if (serial_readable(obj)) {
-		if (c = serial_getc(obj)) {
-			return((int_t) c);
-		}
+		return serial_getc(obj);
 	}
 	return(-1);
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/targets/TARGET_RENESAS/TARGET_RZA1XX/serial_api.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/targets/TARGET_RENESAS/TARGET_RZA1XX/serial_api.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/mbed/targets/TARGET_RENESAS/TARGET_RZA1XX/serial_api.c	(revision 387)
@@ -344,5 +344,5 @@
         }
     }
-    
+
     if (uart_data[index].irq_handler != NULL)
         uart_data[index].irq_handler(uart_data[index].serial_irq_id, TxIrq);
@@ -409,5 +409,5 @@
         }
     }
-    
+
     if (uart_data[index].irq_handler != NULL)
         uart_data[index].irq_handler(uart_data[index].serial_irq_id, RxIrq);
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/siofd.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/siofd.c	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/siofd.c	(revision 387)
@@ -0,0 +1,110 @@
+/*
+ *  TOPPERS ECHONET Lite Communication Middleware
+ * 
+ *  Copyright (C) 2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+
+/*
+ *	シリアルインタフェースドライバのファイルディスクリプタ実装部
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <termios.h>
+#include "target_serial.h"
+#include "siofd.h"
+#include "serial_api.h"
+
+extern serial_t log_serial;
+
+__attribute__((weak))
+int siofd_open(const char *path, int flags, ...)
+{
+	return -1;
+}
+
+__attribute__((weak))
+int siofd_close(int fd)
+{
+	return -1;
+}
+
+__attribute__((weak))
+ssize_t siofd_read(int fd, void *data, size_t len)
+{
+	char *pos, *end;
+
+	if (fd != STDIN_FILENO)
+		return -1;
+
+	for (pos = (char *)data, *end = &pos[len]; pos < end; pos++) {
+		*pos = serial_getc(&log_serial);
+	}
+
+	return pos - (char *)data;
+}
+
+__attribute__((weak))
+ssize_t siofd_write(int fd, const void *data, size_t len)
+{
+	const char *pos, *end;
+
+	if (fd != STDOUT_FILENO)
+		return -1;
+
+	for (pos = (const char *)data, end = &pos[len]; pos < end; pos++) {
+		serial_putc(&log_serial, *pos);
+	}
+
+	return pos - (char *)data;
+}
+
+__attribute__((weak))
+int siofd_tcsetattr(int fd, int act, const struct termios *tio)
+{
+	return 0;
+}
+
+__attribute__((weak))
+int siofd_tcgetattr(int fd, struct termios *tio)
+{
+	return 0;
+}
+
+__attribute__((weak))
+int siofd_fcntl(int fd, int cmd, ...)
+{
+	return 0;
+}
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/siofd.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/siofd.h	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/siofd.h	(revision 387)
@@ -0,0 +1,55 @@
+/*
+ *  TOPPERS ECHONET Lite Communication Middleware
+ * 
+ *  Copyright (C) 2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+
+/*
+ *	シリアルインタフェースドライバのファイルディスクリプタ実装部
+ */
+
+int siofd_open(const char *path, int flags, ...);
+
+int siofd_close(int fd);
+
+ssize_t siofd_read(int fd, void *data, size_t len);
+
+ssize_t siofd_write(int fd, const void *data, size_t len);
+
+int siofd_tcsetattr(int fd, int act, const struct termios *tio);
+
+int siofd_tcgetattr(int fd, struct termios *tio);
+
+int siofd_fcntl(int fd, int cmd, ...);
+
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tPutLogSIOPort.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tPutLogSIOPort.c	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tPutLogSIOPort.c	(revision 387)
@@ -0,0 +1,70 @@
+/*
+ *  TOPPERS Software
+ *      Toyohashi Open Platform for Embedded Real-Time Systems
+ * 
+ *  Copyright (C) 2007-2018 by Embedded and Real-Time Systems Laboratory
+ *              Graduate School of Information Science, Nagoya Univ., JAPAN
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  $Id$
+ */
+
+/*
+ *		SIOドライバによるシステムログの低レベル出力
+ */
+
+#include "tPutLogSIOPort_tecsgen.h"
+
+/*
+ *  システムログの低レベル出力のための初期化
+ *
+ *  初期化ルーチンを呼び出すより前に初期化するために，カーネルのターゲッ
+ *  ト依存部から直接呼び出すための関数．
+ */
+void
+tPutLogSIOPort_initialize(void)
+{
+	cSIOPort_open();
+}
+
+/*
+ *  システムログの低レベル出力のための文字出力（受け口関数）
+ *
+ *  SIOポートに文字が送信できるまでポーリングする．
+ */
+void
+ePutLog_putChar(char c)
+{
+	if(c == '\n'){
+		while (!cSIOPort_putChar('\r'));
+	}
+	while (!cSIOPort_putChar(c));
+}
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tPutLogSIOPort.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tPutLogSIOPort.cdl	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tPutLogSIOPort.cdl	(revision 387)
@@ -0,0 +1,54 @@
+/*
+ *  TOPPERS Software
+ *      Toyohashi Open Platform for Embedded Real-Time Systems
+ * 
+ *  Copyright (C) 2015 by Ushio Laboratory
+ *              Graduate School of Engineering Science, Osaka Univ., JAPAN
+ *  Copyright (C) 2015-2018 by Embedded and Real-Time Systems Laboratory
+ *              Graduate School of Information Science, Nagoya Univ., JAPAN
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  $Id$
+ */
+
+/*
+ *		SIOドライバによるシステムログの低レベル出力のコンポーネント記述
+ *		ファイル
+ */
+
+/*
+ *  システムログの低レベル出力のセルタイプ
+ */
+[singleton]
+celltype tPutLogSIOPort {
+	entry	sPutLog		ePutLog;
+	call	sSIOPort	cSIOPort;
+};
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tlsf/README.md
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tlsf/README.md	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tlsf/README.md	(revision 387)
@@ -0,0 +1,92 @@
+# tlsf
+Two-Level Segregated Fit memory allocator implementation.
+Written by Matthew Conte (matt@baisoku.org).
+Released under the BSD license.
+
+Features
+--------
+  * O(1) cost for malloc, free, realloc, memalign
+  * Extremely low overhead per allocation (4 bytes)
+  * Low overhead per TLSF management of pools (~3kB)
+  * Low fragmentation
+  * Compiles to only a few kB of code and data
+  * Support for adding and removing memory pool regions on the fly
+
+Caveats
+-------
+  * Currently, assumes architecture can make 4-byte aligned accesses
+  * Not designed to be thread safe; the user must provide this
+
+Notes
+-----
+This code was based on the TLSF 1.4 spec and documentation found at:
+
+	http://www.gii.upv.es/tlsf/main/docs
+
+It also leverages the TLSF 2.0 improvement to shrink the per-block overhead from 8 to 4 bytes.
+
+History
+-------
+2016/04/10 - v3.1
+  * Code moved to github
+  * tlsfbits.h rolled into tlsf.c
+  * License changed to BSD
+
+2014/02/08 - v3.0
+  * This version is based on improvements from 3DInteractive GmbH
+  * Interface changed to allow more than one memory pool
+  * Separated pool handling from control structure (adding, removing, debugging)
+  * Control structure and pools can still be constructed in the same memory block
+  * Memory blocks for control structure and pools are checked for alignment
+  * Added functions to retrieve control structure size, alignment size, min and max block size, overhead of pool structure, and overhead of a single allocation
+  * Minimal Pool size is tlsf_block_size_min() + tlsf_pool_overhead()
+  * Pool must be empty when it is removed, in order to allow O(1) removal
+
+2011/10/20 - v2.0
+  * 64-bit support
+  * More compiler intrinsics for ffs/fls
+  * ffs/fls verification during TLSF creation in debug builds
+
+2008/04/04 - v1.9
+  * Add tlsf_heap_check, a heap integrity check
+  * Support a predefined tlsf_assert macro
+  * Fix realloc case where block should shrink; if adjacent block is in use, execution would go down the slow path
+
+2007/02/08 - v1.8
+  * Fix for unnecessary reallocation in tlsf_realloc
+
+2007/02/03 - v1.7
+  * tlsf_heap_walk takes a callback
+  * tlsf_realloc now returns NULL on failure
+  * tlsf_memalign optimization for 4-byte alignment
+  * Usage of size_t where appropriate
+
+2006/11/21 - v1.6
+  * ffs/fls broken out into tlsfbits.h
+  * tlsf_overhead queries per-pool overhead
+
+2006/11/07 - v1.5
+  * Smart realloc implementation
+  * Smart memalign implementation
+
+2006/10/11 - v1.4
+  * Add some ffs/fls implementations
+  * Minor code footprint reduction
+
+2006/09/14 - v1.3
+  * Profiling indicates heavy use of blocks of size 1-128, so implement small block handling
+  * Reduce pool overhead by about 1kb
+  * Reduce minimum block size from 32 to 12 bytes
+  * Realloc bug fix
+
+2006/09/09 - v1.2
+  * Add tlsf_block_size
+  * Static assertion mechanism for invariants
+  * Minor bugfixes 
+
+2006/09/01 - v1.1
+  * Add tlsf_realloc
+  * Add tlsf_walk_heap
+
+2006/08/25 - v1.0
+  * First release
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tlsf/tlsf.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tlsf/tlsf.c	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tlsf/tlsf.c	(revision 387)
@@ -0,0 +1,1252 @@
+#include <assert.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "tlsf.h"
+
+#undef _MSC_VER
+
+#if defined(__cplusplus)
+#define tlsf_decl inline
+#else
+#define tlsf_decl static
+#endif
+
+/*
+** Architecture-specific bit manipulation routines.
+**
+** TLSF achieves O(1) cost for malloc and free operations by limiting
+** the search for a free block to a free list of guaranteed size
+** adequate to fulfill the request, combined with efficient free list
+** queries using bitmasks and architecture-specific bit-manipulation
+** routines.
+**
+** Most modern processors provide instructions to count leading zeroes
+** in a word, find the lowest and highest set bit, etc. These
+** specific implementations will be used when available, falling back
+** to a reasonably efficient generic implementation.
+**
+** NOTE: TLSF spec relies on ffs/fls returning value 0..31.
+** ffs/fls return 1-32 by default, returning 0 for error.
+*/
+
+/*
+** Detect whether or not we are building for a 32- or 64-bit (LP/LLP)
+** architecture. There is no reliable portable method at compile-time.
+*/
+#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) \
+	|| defined (_WIN64) || defined (__LP64__) || defined (__LLP64__)
+#define TLSF_64BIT
+#endif
+
+/*
+** gcc 3.4 and above have builtin support, specialized for architecture.
+** Some compilers masquerade as gcc; patchlevel test filters them out.
+*/
+#if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \
+	&& defined (__GNUC_PATCHLEVEL__)
+
+#if defined (__SNC__)
+/* SNC for Playstation 3. */
+
+tlsf_decl int tlsf_ffs(unsigned int word)
+{
+	const unsigned int reverse = word & (~word + 1);
+	const int bit = 32 - __builtin_clz(reverse);
+	return bit - 1;
+}
+
+#else
+
+tlsf_decl int tlsf_ffs(unsigned int word)
+{
+	return __builtin_ffs(word) - 1;
+}
+
+#endif
+
+tlsf_decl int tlsf_fls(unsigned int word)
+{
+	const int bit = word ? 32 - __builtin_clz(word) : 0;
+	return bit - 1;
+}
+
+#elif defined (_MSC_VER) && (_MSC_VER >= 1400) && (defined (_M_IX86) || defined (_M_X64))
+/* Microsoft Visual C++ support on x86/X64 architectures. */
+
+#include <intrin.h>
+
+#pragma intrinsic(_BitScanReverse)
+#pragma intrinsic(_BitScanForward)
+
+tlsf_decl int tlsf_fls(unsigned int word)
+{
+	unsigned long index;
+	return _BitScanReverse(&index, word) ? index : -1;
+}
+
+tlsf_decl int tlsf_ffs(unsigned int word)
+{
+	unsigned long index;
+	return _BitScanForward(&index, word) ? index : -1;
+}
+
+#elif defined (_MSC_VER) && defined (_M_PPC)
+/* Microsoft Visual C++ support on PowerPC architectures. */
+
+#include <ppcintrinsics.h>
+
+tlsf_decl int tlsf_fls(unsigned int word)
+{
+	const int bit = 32 - _CountLeadingZeros(word);
+	return bit - 1;
+}
+
+tlsf_decl int tlsf_ffs(unsigned int word)
+{
+	const unsigned int reverse = word & (~word + 1);
+	const int bit = 32 - _CountLeadingZeros(reverse);
+	return bit - 1;
+}
+
+#elif defined (__ARMCC_VERSION)
+/* RealView Compilation Tools for ARM */
+
+tlsf_decl int tlsf_ffs(unsigned int word)
+{
+	const unsigned int reverse = word & (~word + 1);
+	const int bit = 32 - __clz(reverse);
+	return bit - 1;
+}
+
+tlsf_decl int tlsf_fls(unsigned int word)
+{
+	const int bit = word ? 32 - __clz(word) : 0;
+	return bit - 1;
+}
+
+#elif defined (__ghs__)
+/* Green Hills support for PowerPC */
+
+#include <ppc_ghs.h>
+
+tlsf_decl int tlsf_ffs(unsigned int word)
+{
+	const unsigned int reverse = word & (~word + 1);
+	const int bit = 32 - __CLZ32(reverse);
+	return bit - 1;
+}
+
+tlsf_decl int tlsf_fls(unsigned int word)
+{
+	const int bit = word ? 32 - __CLZ32(word) : 0;
+	return bit - 1;
+}
+
+#else
+/* Fall back to generic implementation. */
+
+tlsf_decl int tlsf_fls_generic(unsigned int word)
+{
+	int bit = 32;
+
+	if (!word) bit -= 1;
+	if (!(word & 0xffff0000)) { word <<= 16; bit -= 16; }
+	if (!(word & 0xff000000)) { word <<= 8; bit -= 8; }
+	if (!(word & 0xf0000000)) { word <<= 4; bit -= 4; }
+	if (!(word & 0xc0000000)) { word <<= 2; bit -= 2; }
+	if (!(word & 0x80000000)) { word <<= 1; bit -= 1; }
+
+	return bit;
+}
+
+/* Implement ffs in terms of fls. */
+tlsf_decl int tlsf_ffs(unsigned int word)
+{
+	return tlsf_fls_generic(word & (~word + 1)) - 1;
+}
+
+tlsf_decl int tlsf_fls(unsigned int word)
+{
+	return tlsf_fls_generic(word) - 1;
+}
+
+#endif
+
+/* Possibly 64-bit version of tlsf_fls. */
+#if defined (TLSF_64BIT)
+tlsf_decl int tlsf_fls_sizet(size_t size)
+{
+	int high = (int)(size >> 32);
+	int bits = 0;
+	if (high)
+	{
+		bits = 32 + tlsf_fls(high);
+	}
+	else
+	{
+		bits = tlsf_fls((int)size & 0xffffffff);
+
+	}
+	return bits;
+}
+#else
+#define tlsf_fls_sizet tlsf_fls
+#endif
+
+#undef tlsf_decl
+
+/*
+** Constants.
+*/
+
+/* Public constants: may be modified. */
+enum tlsf_public
+{
+	/* log2 of number of linear subdivisions of block sizes. Larger
+	** values require more memory in the control structure. Values of
+	** 4 or 5 are typical.
+	*/
+	SL_INDEX_COUNT_LOG2 = 5,
+};
+
+/* Private constants: do not modify. */
+enum tlsf_private
+{
+#if defined (TLSF_64BIT)
+	/* All allocation sizes and addresses are aligned to 8 bytes. */
+	ALIGN_SIZE_LOG2 = 3,
+#else
+	/* All allocation sizes and addresses are aligned to 4 bytes. */
+	ALIGN_SIZE_LOG2 = 2,
+#endif
+	ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2),
+
+	/*
+	** We support allocations of sizes up to (1 << FL_INDEX_MAX) bits.
+	** However, because we linearly subdivide the second-level lists, and
+	** our minimum size granularity is 4 bytes, it doesn't make sense to
+	** create first-level lists for sizes smaller than SL_INDEX_COUNT * 4,
+	** or (1 << (SL_INDEX_COUNT_LOG2 + 2)) bytes, as there we will be
+	** trying to split size ranges into more slots than we have available.
+	** Instead, we calculate the minimum threshold size, and place all
+	** blocks below that size into the 0th first-level list.
+	*/
+
+#if defined (TLSF_64BIT)
+	/*
+	** TODO: We can increase this to support larger sizes, at the expense
+	** of more overhead in the TLSF structure.
+	*/
+	FL_INDEX_MAX = 32,
+#else
+	FL_INDEX_MAX = 30,
+#endif
+	SL_INDEX_COUNT = (1 << SL_INDEX_COUNT_LOG2),
+	FL_INDEX_SHIFT = (SL_INDEX_COUNT_LOG2 + ALIGN_SIZE_LOG2),
+	FL_INDEX_COUNT = (FL_INDEX_MAX - FL_INDEX_SHIFT + 1),
+
+	SMALL_BLOCK_SIZE = (1 << FL_INDEX_SHIFT),
+};
+
+/*
+** Cast and min/max macros.
+*/
+
+#define tlsf_cast(t, exp)	((t) (exp))
+#define tlsf_min(a, b)		((a) < (b) ? (a) : (b))
+#define tlsf_max(a, b)		((a) > (b) ? (a) : (b))
+
+/*
+** Set assert macro, if it has not been provided by the user.
+*/
+#if !defined (tlsf_assert)
+#define tlsf_assert assert
+#endif
+
+/*
+** Static assertion mechanism.
+*/
+
+#define _tlsf_glue2(x, y) x ## y
+#define _tlsf_glue(x, y) _tlsf_glue2(x, y)
+#define tlsf_static_assert(exp) \
+	typedef char _tlsf_glue(static_assert, __LINE__) [(exp) ? 1 : -1]
+
+/* This code has been tested on 32- and 64-bit (LP/LLP) architectures. */
+tlsf_static_assert(sizeof(int) * CHAR_BIT == 32);
+tlsf_static_assert(sizeof(size_t) * CHAR_BIT >= 32);
+tlsf_static_assert(sizeof(size_t) * CHAR_BIT <= 64);
+
+/* SL_INDEX_COUNT must be <= number of bits in sl_bitmap's storage type. */
+tlsf_static_assert(sizeof(unsigned int) * CHAR_BIT >= SL_INDEX_COUNT);
+
+/* Ensure we've properly tuned our sizes. */
+tlsf_static_assert(ALIGN_SIZE == SMALL_BLOCK_SIZE / SL_INDEX_COUNT);
+
+/*
+** Data structures and associated constants.
+*/
+
+/*
+** Block header structure.
+**
+** There are several implementation subtleties involved:
+** - The prev_phys_block field is only valid if the previous block is free.
+** - The prev_phys_block field is actually stored at the end of the
+**   previous block. It appears at the beginning of this structure only to
+**   simplify the implementation.
+** - The next_free / prev_free fields are only valid if the block is free.
+*/
+typedef struct block_header_t
+{
+	/* Points to the previous physical block. */
+	struct block_header_t* prev_phys_block;
+
+	/* The size of this block, excluding the block header. */
+	size_t size;
+
+	/* Next and previous free blocks. */
+	struct block_header_t* next_free;
+	struct block_header_t* prev_free;
+} block_header_t;
+
+/*
+** Since block sizes are always at least a multiple of 4, the two least
+** significant bits of the size field are used to store the block status:
+** - bit 0: whether block is busy or free
+** - bit 1: whether previous block is busy or free
+*/
+static const size_t block_header_free_bit = 1 << 0;
+static const size_t block_header_prev_free_bit = 1 << 1;
+
+/*
+** The size of the block header exposed to used blocks is the size field.
+** The prev_phys_block field is stored *inside* the previous free block.
+*/
+static const size_t block_header_overhead = sizeof(size_t);
+
+/* User data starts directly after the size field in a used block. */
+static const size_t block_start_offset =
+	offsetof(block_header_t, size) + sizeof(size_t);
+
+/*
+** A free block must be large enough to store its header minus the size of
+** the prev_phys_block field, and no larger than the number of addressable
+** bits for FL_INDEX.
+*/
+static const size_t block_size_min = 
+	sizeof(block_header_t) - sizeof(block_header_t*);
+static const size_t block_size_max = tlsf_cast(size_t, 1) << FL_INDEX_MAX;
+
+
+/* The TLSF control structure. */
+typedef struct control_t
+{
+	/* Empty lists point at this block to indicate they are free. */
+	block_header_t block_null;
+
+	/* Bitmaps for free lists. */
+	unsigned int fl_bitmap;
+	unsigned int sl_bitmap[FL_INDEX_COUNT];
+
+	/* Head of free lists. */
+	block_header_t* blocks[FL_INDEX_COUNT][SL_INDEX_COUNT];
+} control_t;
+
+/* A type used for casting when doing pointer arithmetic. */
+typedef ptrdiff_t tlsfptr_t;
+
+/*
+** block_header_t member functions.
+*/
+
+static size_t block_size(const block_header_t* block)
+{
+	return block->size & ~(block_header_free_bit | block_header_prev_free_bit);
+}
+
+static void block_set_size(block_header_t* block, size_t size)
+{
+	const size_t oldsize = block->size;
+	block->size = size | (oldsize & (block_header_free_bit | block_header_prev_free_bit));
+}
+
+static int block_is_last(const block_header_t* block)
+{
+	return block_size(block) == 0;
+}
+
+static int block_is_free(const block_header_t* block)
+{
+	return tlsf_cast(int, block->size & block_header_free_bit);
+}
+
+static void block_set_free(block_header_t* block)
+{
+	block->size |= block_header_free_bit;
+}
+
+static void block_set_used(block_header_t* block)
+{
+	block->size &= ~block_header_free_bit;
+}
+
+static int block_is_prev_free(const block_header_t* block)
+{
+	return tlsf_cast(int, block->size & block_header_prev_free_bit);
+}
+
+static void block_set_prev_free(block_header_t* block)
+{
+	block->size |= block_header_prev_free_bit;
+}
+
+static void block_set_prev_used(block_header_t* block)
+{
+	block->size &= ~block_header_prev_free_bit;
+}
+
+static block_header_t* block_from_ptr(const void* ptr)
+{
+	return tlsf_cast(block_header_t*,
+		tlsf_cast(unsigned char*, ptr) - block_start_offset);
+}
+
+static void* block_to_ptr(const block_header_t* block)
+{
+	return tlsf_cast(void*,
+		tlsf_cast(unsigned char*, block) + block_start_offset);
+}
+
+/* Return location of next block after block of given size. */
+static block_header_t* offset_to_block(const void* ptr, size_t size)
+{
+	return tlsf_cast(block_header_t*, tlsf_cast(tlsfptr_t, ptr) + size);
+}
+
+/* Return location of previous block. */
+static block_header_t* block_prev(const block_header_t* block)
+{
+	tlsf_assert(block_is_prev_free(block) && "previous block must be free");
+	return block->prev_phys_block;
+}
+
+/* Return location of next existing block. */
+static block_header_t* block_next(const block_header_t* block)
+{
+	block_header_t* next = offset_to_block(block_to_ptr(block),
+		block_size(block) - block_header_overhead);
+	tlsf_assert(!block_is_last(block));
+	return next;
+}
+
+/* Link a new block with its physical neighbor, return the neighbor. */
+static block_header_t* block_link_next(block_header_t* block)
+{
+	block_header_t* next = block_next(block);
+	next->prev_phys_block = block;
+	return next;
+}
+
+static void block_mark_as_free(block_header_t* block)
+{
+	/* Link the block to the next block, first. */
+	block_header_t* next = block_link_next(block);
+	block_set_prev_free(next);
+	block_set_free(block);
+}
+
+static void block_mark_as_used(block_header_t* block)
+{
+	block_header_t* next = block_next(block);
+	block_set_prev_used(next);
+	block_set_used(block);
+}
+
+static size_t align_up(size_t x, size_t align)
+{
+	tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two");
+	return (x + (align - 1)) & ~(align - 1);
+}
+
+static size_t align_down(size_t x, size_t align)
+{
+	tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two");
+	return x - (x & (align - 1));
+}
+
+static void* align_ptr(const void* ptr, size_t align)
+{
+	const tlsfptr_t aligned =
+		(tlsf_cast(tlsfptr_t, ptr) + (align - 1)) & ~(align - 1);
+	tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two");
+	return tlsf_cast(void*, aligned);
+}
+
+/*
+** Adjust an allocation size to be aligned to word size, and no smaller
+** than internal minimum.
+*/
+static size_t adjust_request_size(size_t size, size_t align)
+{
+	size_t adjust = 0;
+	if (size && size < block_size_max)
+	{
+		const size_t aligned = align_up(size, align);
+		adjust = tlsf_max(aligned, block_size_min);
+	}
+	return adjust;
+}
+
+/*
+** TLSF utility functions. In most cases, these are direct translations of
+** the documentation found in the white paper.
+*/
+
+static void mapping_insert(size_t size, int* fli, int* sli)
+{
+	int fl, sl;
+	if (size < SMALL_BLOCK_SIZE)
+	{
+		/* Store small blocks in first list. */
+		fl = 0;
+		sl = tlsf_cast(int, size) / (SMALL_BLOCK_SIZE / SL_INDEX_COUNT);
+	}
+	else
+	{
+		fl = tlsf_fls_sizet(size);
+		sl = tlsf_cast(int, size >> (fl - SL_INDEX_COUNT_LOG2)) ^ (1 << SL_INDEX_COUNT_LOG2);
+		fl -= (FL_INDEX_SHIFT - 1);
+	}
+	*fli = fl;
+	*sli = sl;
+}
+
+/* This version rounds up to the next block size (for allocations) */
+static void mapping_search(size_t size, int* fli, int* sli)
+{
+	if (size >= SMALL_BLOCK_SIZE)
+	{
+		const size_t round = (1 << (tlsf_fls_sizet(size) - SL_INDEX_COUNT_LOG2)) - 1;
+		size += round;
+	}
+	mapping_insert(size, fli, sli);
+}
+
+static block_header_t* search_suitable_block(control_t* control, int* fli, int* sli)
+{
+	int fl = *fli;
+	int sl = *sli;
+
+	/*
+	** First, search for a block in the list associated with the given
+	** fl/sl index.
+	*/
+	unsigned int sl_map = control->sl_bitmap[fl] & (~0U << sl);
+	if (!sl_map)
+	{
+		/* No block exists. Search in the next largest first-level list. */
+		const unsigned int fl_map = control->fl_bitmap & (~0U << (fl + 1));
+		if (!fl_map)
+		{
+			/* No free blocks available, memory has been exhausted. */
+			return 0;
+		}
+
+		fl = tlsf_ffs(fl_map);
+		*fli = fl;
+		sl_map = control->sl_bitmap[fl];
+	}
+	tlsf_assert(sl_map && "internal error - second level bitmap is null");
+	sl = tlsf_ffs(sl_map);
+	*sli = sl;
+
+	/* Return the first block in the free list. */
+	return control->blocks[fl][sl];
+}
+
+/* Remove a free block from the free list.*/
+static void remove_free_block(control_t* control, block_header_t* block, int fl, int sl)
+{
+	block_header_t* prev = block->prev_free;
+	block_header_t* next = block->next_free;
+	tlsf_assert(prev && "prev_free field can not be null");
+	tlsf_assert(next && "next_free field can not be null");
+	next->prev_free = prev;
+	prev->next_free = next;
+
+	/* If this block is the head of the free list, set new head. */
+	if (control->blocks[fl][sl] == block)
+	{
+		control->blocks[fl][sl] = next;
+
+		/* If the new head is null, clear the bitmap. */
+		if (next == &control->block_null)
+		{
+			control->sl_bitmap[fl] &= ~(1 << sl);
+
+			/* If the second bitmap is now empty, clear the fl bitmap. */
+			if (!control->sl_bitmap[fl])
+			{
+				control->fl_bitmap &= ~(1 << fl);
+			}
+		}
+	}
+}
+
+/* Insert a free block into the free block list. */
+static void insert_free_block(control_t* control, block_header_t* block, int fl, int sl)
+{
+	block_header_t* current = control->blocks[fl][sl];
+	tlsf_assert(current && "free list cannot have a null entry");
+	tlsf_assert(block && "cannot insert a null entry into the free list");
+	block->next_free = current;
+	block->prev_free = &control->block_null;
+	current->prev_free = block;
+
+	tlsf_assert(block_to_ptr(block) == align_ptr(block_to_ptr(block), ALIGN_SIZE)
+		&& "block not aligned properly");
+	/*
+	** Insert the new block at the head of the list, and mark the first-
+	** and second-level bitmaps appropriately.
+	*/
+	control->blocks[fl][sl] = block;
+	control->fl_bitmap |= (1 << fl);
+	control->sl_bitmap[fl] |= (1 << sl);
+}
+
+/* Remove a given block from the free list. */
+static void block_remove(control_t* control, block_header_t* block)
+{
+	int fl, sl;
+	mapping_insert(block_size(block), &fl, &sl);
+	remove_free_block(control, block, fl, sl);
+}
+
+/* Insert a given block into the free list. */
+static void block_insert(control_t* control, block_header_t* block)
+{
+	int fl, sl;
+	mapping_insert(block_size(block), &fl, &sl);
+	insert_free_block(control, block, fl, sl);
+}
+
+static int block_can_split(block_header_t* block, size_t size)
+{
+	return block_size(block) >= sizeof(block_header_t) + size;
+}
+
+/* Split a block into two, the second of which is free. */
+static block_header_t* block_split(block_header_t* block, size_t size)
+{
+	/* Calculate the amount of space left in the remaining block. */
+	block_header_t* remaining =
+		offset_to_block(block_to_ptr(block), size - block_header_overhead);
+
+	const size_t remain_size = block_size(block) - (size + block_header_overhead);
+
+	tlsf_assert(block_to_ptr(remaining) == align_ptr(block_to_ptr(remaining), ALIGN_SIZE)
+		&& "remaining block not aligned properly");
+
+	tlsf_assert(block_size(block) == remain_size + size + block_header_overhead);
+	block_set_size(remaining, remain_size);
+	tlsf_assert(block_size(remaining) >= block_size_min && "block split with invalid size");
+
+	block_set_size(block, size);
+	block_mark_as_free(remaining);
+
+	return remaining;
+}
+
+/* Absorb a free block's storage into an adjacent previous free block. */
+static block_header_t* block_absorb(block_header_t* prev, block_header_t* block)
+{
+	tlsf_assert(!block_is_last(prev) && "previous block can't be last");
+	/* Note: Leaves flags untouched. */
+	prev->size += block_size(block) + block_header_overhead;
+	block_link_next(prev);
+	return prev;
+}
+
+/* Merge a just-freed block with an adjacent previous free block. */
+static block_header_t* block_merge_prev(control_t* control, block_header_t* block)
+{
+	if (block_is_prev_free(block))
+	{
+		block_header_t* prev = block_prev(block);
+		tlsf_assert(prev && "prev physical block can't be null");
+		tlsf_assert(block_is_free(prev) && "prev block is not free though marked as such");
+		block_remove(control, prev);
+		block = block_absorb(prev, block);
+	}
+
+	return block;
+}
+
+/* Merge a just-freed block with an adjacent free block. */
+static block_header_t* block_merge_next(control_t* control, block_header_t* block)
+{
+	block_header_t* next = block_next(block);
+	tlsf_assert(next && "next physical block can't be null");
+
+	if (block_is_free(next))
+	{
+		tlsf_assert(!block_is_last(block) && "previous block can't be last");
+		block_remove(control, next);
+		block = block_absorb(block, next);
+	}
+
+	return block;
+}
+
+/* Trim any trailing block space off the end of a block, return to pool. */
+static void block_trim_free(control_t* control, block_header_t* block, size_t size)
+{
+	tlsf_assert(block_is_free(block) && "block must be free");
+	if (block_can_split(block, size))
+	{
+		block_header_t* remaining_block = block_split(block, size);
+		block_link_next(block);
+		block_set_prev_free(remaining_block);
+		block_insert(control, remaining_block);
+	}
+}
+
+/* Trim any trailing block space off the end of a used block, return to pool. */
+static void block_trim_used(control_t* control, block_header_t* block, size_t size)
+{
+	tlsf_assert(!block_is_free(block) && "block must be used");
+	if (block_can_split(block, size))
+	{
+		/* If the next block is free, we must coalesce. */
+		block_header_t* remaining_block = block_split(block, size);
+		block_set_prev_used(remaining_block);
+
+		remaining_block = block_merge_next(control, remaining_block);
+		block_insert(control, remaining_block);
+	}
+}
+
+static block_header_t* block_trim_free_leading(control_t* control, block_header_t* block, size_t size)
+{
+	block_header_t* remaining_block = block;
+	if (block_can_split(block, size))
+	{
+		/* We want the 2nd block. */
+		remaining_block = block_split(block, size - block_header_overhead);
+		block_set_prev_free(remaining_block);
+
+		block_link_next(block);
+		block_insert(control, block);
+	}
+
+	return remaining_block;
+}
+
+static block_header_t* block_locate_free(control_t* control, size_t size)
+{
+	int fl = 0, sl = 0;
+	block_header_t* block = 0;
+
+	if (size)
+	{
+		mapping_search(size, &fl, &sl);
+		block = search_suitable_block(control, &fl, &sl);
+	}
+
+	if (block)
+	{
+		tlsf_assert(block_size(block) >= size);
+		remove_free_block(control, block, fl, sl);
+	}
+
+	return block;
+}
+
+static void* block_prepare_used(control_t* control, block_header_t* block, size_t size)
+{
+	void* p = 0;
+	if (block)
+	{
+		tlsf_assert(size && "size must be non-zero");
+		block_trim_free(control, block, size);
+		block_mark_as_used(block);
+		p = block_to_ptr(block);
+	}
+	return p;
+}
+
+/* Clear structure and point all empty lists at the null block. */
+static void control_construct(control_t* control)
+{
+	int i, j;
+
+	control->block_null.next_free = &control->block_null;
+	control->block_null.prev_free = &control->block_null;
+
+	control->fl_bitmap = 0;
+	for (i = 0; i < FL_INDEX_COUNT; ++i)
+	{
+		control->sl_bitmap[i] = 0;
+		for (j = 0; j < SL_INDEX_COUNT; ++j)
+		{
+			control->blocks[i][j] = &control->block_null;
+		}
+	}
+}
+
+/*
+** Debugging utilities.
+*/
+
+typedef struct integrity_t
+{
+	int prev_status;
+	int status;
+} integrity_t;
+
+#define tlsf_insist(x) { tlsf_assert(x); if (!(x)) { status--; } }
+
+static void integrity_walker(void* ptr, size_t size, int used, void* user)
+{
+	block_header_t* block = block_from_ptr(ptr);
+	integrity_t* integ = tlsf_cast(integrity_t*, user);
+	const int this_prev_status = block_is_prev_free(block) ? 1 : 0;
+	const int this_status = block_is_free(block) ? 1 : 0;
+	const size_t this_block_size = block_size(block);
+
+	int status = 0;
+	(void)used;
+	tlsf_insist(integ->prev_status == this_prev_status && "prev status incorrect");
+	tlsf_insist(size == this_block_size && "block size incorrect");
+
+	integ->prev_status = this_status;
+	integ->status += status;
+}
+
+int tlsf_check(tlsf_t tlsf)
+{
+	int i, j;
+
+	control_t* control = tlsf_cast(control_t*, tlsf);
+	int status = 0;
+
+	/* Check that the free lists and bitmaps are accurate. */
+	for (i = 0; i < FL_INDEX_COUNT; ++i)
+	{
+		for (j = 0; j < SL_INDEX_COUNT; ++j)
+		{
+			const int fl_map = control->fl_bitmap & (1 << i);
+			const int sl_list = control->sl_bitmap[i];
+			const int sl_map = sl_list & (1 << j);
+			const block_header_t* block = control->blocks[i][j];
+
+			/* Check that first- and second-level lists agree. */
+			if (!fl_map)
+			{
+				tlsf_insist(!sl_map && "second-level map must be null");
+			}
+
+			if (!sl_map)
+			{
+				tlsf_insist(block == &control->block_null && "block list must be null");
+				continue;
+			}
+
+			/* Check that there is at least one free block. */
+			tlsf_insist(sl_list && "no free blocks in second-level map");
+			tlsf_insist(block != &control->block_null && "block should not be null");
+
+			while (block != &control->block_null)
+			{
+				int fli, sli;
+				tlsf_insist(block_is_free(block) && "block should be free");
+				tlsf_insist(!block_is_prev_free(block) && "blocks should have coalesced");
+				tlsf_insist(!block_is_free(block_next(block)) && "blocks should have coalesced");
+				tlsf_insist(block_is_prev_free(block_next(block)) && "block should be free");
+				tlsf_insist(block_size(block) >= block_size_min && "block not minimum size");
+
+				mapping_insert(block_size(block), &fli, &sli);
+				tlsf_insist(fli == i && sli == j && "block size indexed in wrong list");
+				block = block->next_free;
+			}
+		}
+	}
+
+	return status;
+}
+
+#undef tlsf_insist
+
+static void default_walker(void* ptr, size_t size, int used, void* user)
+{
+	(void)user;
+	printf("\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, block_from_ptr(ptr));
+}
+
+void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user)
+{
+	tlsf_walker pool_walker = walker ? walker : default_walker;
+	block_header_t* block =
+		offset_to_block(pool, -(int)block_header_overhead);
+
+	while (block && !block_is_last(block))
+	{
+		pool_walker(
+			block_to_ptr(block),
+			block_size(block),
+			!block_is_free(block),
+			user);
+		block = block_next(block);
+	}
+}
+
+size_t tlsf_block_size(void* ptr)
+{
+	size_t size = 0;
+	if (ptr)
+	{
+		const block_header_t* block = block_from_ptr(ptr);
+		size = block_size(block);
+	}
+	return size;
+}
+
+int tlsf_check_pool(pool_t pool)
+{
+	/* Check that the blocks are physically correct. */
+	integrity_t integ = { 0, 0 };
+	tlsf_walk_pool(pool, integrity_walker, &integ);
+
+	return integ.status;
+}
+
+/*
+** Size of the TLSF structures in a given memory block passed to
+** tlsf_create, equal to the size of a control_t
+*/
+size_t tlsf_size(void)
+{
+	return sizeof(control_t);
+}
+
+size_t tlsf_align_size(void)
+{
+	return ALIGN_SIZE;
+}
+
+size_t tlsf_block_size_min(void)
+{
+	return block_size_min;
+}
+
+size_t tlsf_block_size_max(void)
+{
+	return block_size_max;
+}
+
+/*
+** Overhead of the TLSF structures in a given memory block passed to
+** tlsf_add_pool, equal to the overhead of a free block and the
+** sentinel block.
+*/
+size_t tlsf_pool_overhead(void)
+{
+	return 2 * block_header_overhead;
+}
+
+size_t tlsf_alloc_overhead(void)
+{
+	return block_header_overhead;
+}
+
+pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
+{
+	block_header_t* block;
+	block_header_t* next;
+
+	const size_t pool_overhead = tlsf_pool_overhead();
+	const size_t pool_bytes = align_down(bytes - pool_overhead, ALIGN_SIZE);
+
+	if (((ptrdiff_t)mem % ALIGN_SIZE) != 0)
+	{
+		printf("tlsf_add_pool: Memory must be aligned by %u bytes.\n",
+			(unsigned int)ALIGN_SIZE);
+		return 0;
+	}
+
+	if (pool_bytes < block_size_min || pool_bytes > block_size_max)
+	{
+#if defined (TLSF_64BIT)
+		printf("tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n", 
+			(unsigned int)(pool_overhead + block_size_min),
+			(unsigned int)((pool_overhead + block_size_max) / 256));
+#else
+		printf("tlsf_add_pool: Memory size must be between %u and %u bytes.\n", 
+			(unsigned int)(pool_overhead + block_size_min),
+			(unsigned int)(pool_overhead + block_size_max));
+#endif
+		return 0;
+	}
+
+	/*
+	** Create the main free block. Offset the start of the block slightly
+	** so that the prev_phys_block field falls outside of the pool -
+	** it will never be used.
+	*/
+	block = offset_to_block(mem, -(tlsfptr_t)block_header_overhead);
+	block_set_size(block, pool_bytes);
+	block_set_free(block);
+	block_set_prev_used(block);
+	block_insert(tlsf_cast(control_t*, tlsf), block);
+
+	/* Split the block to create a zero-size sentinel block. */
+	next = block_link_next(block);
+	block_set_size(next, 0);
+	block_set_used(next);
+	block_set_prev_free(next);
+
+	return mem;
+}
+
+void tlsf_remove_pool(tlsf_t tlsf, pool_t pool)
+{
+	control_t* control = tlsf_cast(control_t*, tlsf);
+	block_header_t* block = offset_to_block(pool, -(int)block_header_overhead);
+
+	int fl = 0, sl = 0;
+
+	tlsf_assert(block_is_free(block) && "block should be free");
+	tlsf_assert(!block_is_free(block_next(block)) && "next block should not be free");
+	tlsf_assert(block_size(block_next(block)) == 0 && "next block size should be zero");
+
+	mapping_insert(block_size(block), &fl, &sl);
+	remove_free_block(control, block, fl, sl);
+}
+
+/*
+** TLSF main interface.
+*/
+
+#if _DEBUG
+int test_ffs_fls()
+{
+	/* Verify ffs/fls work properly. */
+	int rv = 0;
+	rv += (tlsf_ffs(0) == -1) ? 0 : 0x1;
+	rv += (tlsf_fls(0) == -1) ? 0 : 0x2;
+	rv += (tlsf_ffs(1) == 0) ? 0 : 0x4;
+	rv += (tlsf_fls(1) == 0) ? 0 : 0x8;
+	rv += (tlsf_ffs(0x80000000) == 31) ? 0 : 0x10;
+	rv += (tlsf_ffs(0x80008000) == 15) ? 0 : 0x20;
+	rv += (tlsf_fls(0x80000008) == 31) ? 0 : 0x40;
+	rv += (tlsf_fls(0x7FFFFFFF) == 30) ? 0 : 0x80;
+
+#if defined (TLSF_64BIT)
+	rv += (tlsf_fls_sizet(0x80000000) == 31) ? 0 : 0x100;
+	rv += (tlsf_fls_sizet(0x100000000) == 32) ? 0 : 0x200;
+	rv += (tlsf_fls_sizet(0xffffffffffffffff) == 63) ? 0 : 0x400;
+#endif
+
+	if (rv)
+	{
+		printf("test_ffs_fls: %x ffs/fls tests failed.\n", rv);
+	}
+	return rv;
+}
+#endif
+
+tlsf_t tlsf_create(void* mem)
+{
+#if _DEBUG
+	if (test_ffs_fls())
+	{
+		return 0;
+	}
+#endif
+
+	if (((tlsfptr_t)mem % ALIGN_SIZE) != 0)
+	{
+		printf("tlsf_create: Memory must be aligned to %u bytes.\n",
+			(unsigned int)ALIGN_SIZE);
+		return 0;
+	}
+
+	control_construct(tlsf_cast(control_t*, mem));
+
+	return tlsf_cast(tlsf_t, mem);
+}
+
+tlsf_t tlsf_create_with_pool(void* mem, size_t bytes)
+{
+	tlsf_t tlsf = tlsf_create(mem);
+	tlsf_add_pool(tlsf, (char*)mem + tlsf_size(), bytes - tlsf_size());
+	return tlsf;
+}
+
+void tlsf_destroy(tlsf_t tlsf)
+{
+	/* Nothing to do. */
+	(void)tlsf;
+}
+
+pool_t tlsf_get_pool(tlsf_t tlsf)
+{
+	return tlsf_cast(pool_t, (char*)tlsf + tlsf_size());
+}
+
+void* tlsf_malloc(tlsf_t tlsf, size_t size)
+{
+	control_t* control = tlsf_cast(control_t*, tlsf);
+	const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
+	block_header_t* block = block_locate_free(control, adjust);
+	return block_prepare_used(control, block, adjust);
+}
+
+void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size)
+{
+	control_t* control = tlsf_cast(control_t*, tlsf);
+	const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
+
+	/*
+	** We must allocate an additional minimum block size bytes so that if
+	** our free block will leave an alignment gap which is smaller, we can
+	** trim a leading free block and release it back to the pool. We must
+	** do this because the previous physical block is in use, therefore
+	** the prev_phys_block field is not valid, and we can't simply adjust
+	** the size of that block.
+	*/
+	const size_t gap_minimum = sizeof(block_header_t);
+	const size_t size_with_gap = adjust_request_size(adjust + align + gap_minimum, align);
+
+	/*
+	** If alignment is less than or equals base alignment, we're done.
+	** If we requested 0 bytes, return null, as tlsf_malloc(0) does.
+	*/
+	const size_t aligned_size = (adjust && align > ALIGN_SIZE) ? size_with_gap : adjust;
+
+	block_header_t* block = block_locate_free(control, aligned_size);
+
+	/* This can't be a static assert. */
+	tlsf_assert(sizeof(block_header_t) == block_size_min + block_header_overhead);
+
+	if (block)
+	{
+		void* ptr = block_to_ptr(block);
+		void* aligned = align_ptr(ptr, align);
+		size_t gap = tlsf_cast(size_t,
+			tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr));
+
+		/* If gap size is too small, offset to next aligned boundary. */
+		if (gap && gap < gap_minimum)
+		{
+			const size_t gap_remain = gap_minimum - gap;
+			const size_t offset = tlsf_max(gap_remain, align);
+			const void* next_aligned = tlsf_cast(void*,
+				tlsf_cast(tlsfptr_t, aligned) + offset);
+
+			aligned = align_ptr(next_aligned, align);
+			gap = tlsf_cast(size_t,
+				tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr));
+		}
+
+		if (gap)
+		{
+			tlsf_assert(gap >= gap_minimum && "gap size too small");
+			block = block_trim_free_leading(control, block, gap);
+		}
+	}
+
+	return block_prepare_used(control, block, adjust);
+}
+
+void tlsf_free(tlsf_t tlsf, void* ptr)
+{
+	/* Don't attempt to free a NULL pointer. */
+	if (ptr)
+	{
+		control_t* control = tlsf_cast(control_t*, tlsf);
+		block_header_t* block = block_from_ptr(ptr);
+		tlsf_assert(!block_is_free(block) && "block already marked as free");
+		block_mark_as_free(block);
+		block = block_merge_prev(control, block);
+		block = block_merge_next(control, block);
+		block_insert(control, block);
+	}
+}
+
+/*
+** The TLSF block information provides us with enough information to
+** provide a reasonably intelligent implementation of realloc, growing or
+** shrinking the currently allocated block as required.
+**
+** This routine handles the somewhat esoteric edge cases of realloc:
+** - a non-zero size with a null pointer will behave like malloc
+** - a zero size with a non-null pointer will behave like free
+** - a request that cannot be satisfied will leave the original buffer
+**   untouched
+** - an extended buffer size will leave the newly-allocated area with
+**   contents undefined
+*/
+void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size)
+{
+	control_t* control = tlsf_cast(control_t*, tlsf);
+	void* p = 0;
+
+	/* Zero-size requests are treated as free. */
+	if (ptr && size == 0)
+	{
+		tlsf_free(tlsf, ptr);
+	}
+	/* Requests with NULL pointers are treated as malloc. */
+	else if (!ptr)
+	{
+		p = tlsf_malloc(tlsf, size);
+	}
+	else
+	{
+		block_header_t* block = block_from_ptr(ptr);
+		block_header_t* next = block_next(block);
+
+		const size_t cursize = block_size(block);
+		const size_t combined = cursize + block_size(next) + block_header_overhead;
+		const size_t adjust = adjust_request_size(size, ALIGN_SIZE);
+
+		tlsf_assert(!block_is_free(block) && "block already marked as free");
+
+		/*
+		** If the next block is used, or when combined with the current
+		** block, does not offer enough space, we must reallocate and copy.
+		*/
+		if (adjust > cursize && (!block_is_free(next) || adjust > combined))
+		{
+			p = tlsf_malloc(tlsf, size);
+			if (p)
+			{
+				const size_t minsize = tlsf_min(cursize, size);
+				memcpy(p, ptr, minsize);
+				tlsf_free(tlsf, ptr);
+			}
+		}
+		else
+		{
+			/* Do we need to expand to the next block? */
+			if (adjust > cursize)
+			{
+				block_merge_next(control, block);
+				block_mark_as_used(block);
+			}
+
+			/* Trim the resulting block and return the original pointer. */
+			block_trim_used(control, block, adjust);
+			p = ptr;
+		}
+	}
+
+	return p;
+}
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tlsf/tlsf.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tlsf/tlsf.h	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/syssvc/tlsf/tlsf.h	(revision 387)
@@ -0,0 +1,90 @@
+#ifndef INCLUDED_tlsf
+#define INCLUDED_tlsf
+
+/*
+** Two Level Segregated Fit memory allocator, version 3.1.
+** Written by Matthew Conte
+**	http://tlsf.baisoku.org
+**
+** Based on the original documentation by Miguel Masmano:
+**	http://www.gii.upv.es/tlsf/main/docs
+**
+** This implementation was written to the specification
+** of the document, therefore no GPL restrictions apply.
+** 
+** Copyright (c) 2006-2016, Matthew Conte
+** All rights reserved.
+** 
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are met:
+**     * Redistributions of source code must retain the above copyright
+**       notice, this list of conditions and the following disclaimer.
+**     * Redistributions in binary form must reproduce the above copyright
+**       notice, this list of conditions and the following disclaimer in the
+**       documentation and/or other materials provided with the distribution.
+**     * Neither the name of the copyright holder nor the
+**       names of its contributors may be used to endorse or promote products
+**       derived from this software without specific prior written permission.
+** 
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
+** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <stddef.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
+/* pool_t: a block of memory that TLSF can manage. */
+typedef void* tlsf_t;
+typedef void* pool_t;
+
+/* Create/destroy a memory pool. */
+tlsf_t tlsf_create(void* mem);
+tlsf_t tlsf_create_with_pool(void* mem, size_t bytes);
+void tlsf_destroy(tlsf_t tlsf);
+pool_t tlsf_get_pool(tlsf_t tlsf);
+
+/* Add/remove memory pools. */
+pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
+void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
+
+/* malloc/memalign/realloc/free replacements. */
+void* tlsf_malloc(tlsf_t tlsf, size_t bytes);
+void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes);
+void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size);
+void tlsf_free(tlsf_t tlsf, void* ptr);
+
+/* Returns internal block size, not original request size */
+size_t tlsf_block_size(void* ptr);
+
+/* Overheads/limits of internal structures. */
+size_t tlsf_size(void);
+size_t tlsf_align_size(void);
+size_t tlsf_block_size_min(void);
+size_t tlsf_block_size_max(void);
+size_t tlsf_pool_overhead(void);
+size_t tlsf_alloc_overhead(void);
+
+/* Debugging. */
+typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
+void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
+/* Returns nonzero if any internal consistency check fails. */
+int tlsf_check(tlsf_t tlsf);
+int tlsf_check_pool(pool_t pool);
+
+#if defined(__cplusplus)
+};
+#endif
+
+#endif
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/target/gr_peach_gcc/gr_peach.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/target/gr_peach_gcc/gr_peach.h	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/target/gr_peach_gcc/gr_peach.h	(revision 387)
@@ -58,4 +58,9 @@
 
 /*
+ *  ボーレート設定
+ */
+#define UART_BAUDRATE		115200
+
+/*
  *  LEDの点灯／消灯
  */
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/target/gr_peach_gcc/target.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/target/gr_peach_gcc/target.cdl	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/target/gr_peach_gcc/target.cdl	(revision 387)
@@ -60,5 +60,5 @@
  *  ターゲット依存のセルタイプの定義
  */
-import("tPutLogGRPeach.cdl");
+import("syssvc/tPutLogSIOPort.cdl");
 import("tSIOPortGRPeach.cdl");
 
@@ -72,5 +72,5 @@
  *  低レベル出力の組み上げ記述
  */
-cell tPutLogGRPeach PutLogTarget {
+cell tPutLogSIOPort PutLogTarget {
 	/* SIOドライバとの結合 */
 	cSIOPort = SIOPortTarget1.eSIOPort;
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/target/gr_peach_gcc/target_kernel_impl.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/target/gr_peach_gcc/target_kernel_impl.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/target/gr_peach_gcc/target_kernel_impl.c	(revision 387)
@@ -264,5 +264,5 @@
 	 */
 #ifndef TOPPERS_OMIT_TECS
-	tPutLogGRPeach_initialize();
+	tPutLogSIOPort_initialize();
 #endif /* TOPPERS_OMIT_TECS */
 }
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netapp/Makefile.netapp
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netapp/Makefile.netapp	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netapp/Makefile.netapp	(revision 387)
@@ -183,5 +183,5 @@
 		NETAPP_COBJS := $(NETAPP_COBJS) udp6_echo_cli.o
 		NETAPP_KERNEL_CFG := $(NETAPP_KERNEL_CFG) $(NETAPP_DIRS)/udp6_echo_cli.cfg
-	
+
 		ifeq ($(SUPPORT_INET4),true)
 			ifeq ($(USE_UDP4_ECHO_CLI),true)
@@ -191,5 +191,5 @@
 			endif
 		endif
-        else
+		else
 		ifeq ($(SUPPORT_INET4),true)
 			SUPPORT_UDP = true
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/in_itron.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/in_itron.h	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/in_itron.h	(revision 387)
@@ -131,4 +131,5 @@
 extern ER_UINT	udp6_snd_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout);
 extern ER_UINT	udp6_rcv_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout);
+extern ER	udp6_can_cep(ID cepid, FN fncd);
 
 /* 【拡張機能】 */
@@ -139,4 +140,7 @@
 extern ER	udp_cre_cep (ID cepid, T_UDP_CCEP *pk_ccep);
 
+extern ER	udp6_del_cep(ID cepid);
+extern ER	udp6_set_opt(ID cepid, int_t optname, void *optval, int_t optlen);
+extern ER	udp6_get_opt(ID cepid, int_t optname, void *optval, int_t optlen);
 extern ER	udp6_cre_cep (ID cepid, T_UDP6_CCEP *pk_ccep);
 
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/tcp_input.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/tcp_input.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/tcp_input.c	(revision 387)
@@ -521,5 +521,19 @@
 
 				/* 相手のアドレスをコピーする。*/
+
+#if defined(_IP6_CFG) && defined(_IP4_CFG)
+
+				if (cep->flags & TCP_CEP_FLG_IPV4) {
+					(*cep->p_dstaddr4).ipaddr = ntohl(cep->dstaddr.ipaddr.s6_addr32[3]);
+					(*cep->p_dstaddr4).portno = cep->dstaddr.portno;
+					}
+				else
+					*cep->p_dstaddr = cep->dstaddr;
+
+#else	/* of #if defined(_IP6_CFG) && defined(_IP4_CFG) */
+
 				*cep->p_dstaddr = cep->dstaddr;
+
+#endif	/* of #if defined(_IP6_CFG) && defined(_IP4_CFG) */
 
 				if (IS_PTR_DEFINED(cep->callback)) {
@@ -847,5 +861,19 @@
 
 				/* 相手のアドレスをコピーする。*/
+
+#if defined(_IP6_CFG) && defined(_IP4_CFG)
+
+				if (cep->flags & TCP_CEP_FLG_IPV4) {
+					(*cep->p_dstaddr4).ipaddr = ntohl(cep->dstaddr.ipaddr.s6_addr32[3]);
+					(*cep->p_dstaddr4).portno = cep->dstaddr.portno;
+					}
+				else
+					*cep->p_dstaddr = cep->dstaddr;
+
+#else	/* of #if defined(_IP6_CFG) && defined(_IP4_CFG) */
+
 				*cep->p_dstaddr = cep->dstaddr;
+
+#endif	/* of #if defined(_IP6_CFG) && defined(_IP4_CFG) */
 
 				if (IS_PTR_DEFINED(cep->callback)) {
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/tcpn_usrreq.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/tcpn_usrreq.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/tcpn_usrreq.c	(revision 387)
@@ -671,10 +671,10 @@
 		cep->p_myaddr4    = p_myaddr;
 		cep->p_dstaddr    = NULL;
-		cep->p_myaddr     = NULL;
+		cep->p_myaddr     = NADR;
 
 #else	/* of #if API_PROTO == API_PROTO_IPV4 */
 
 		cep->p_dstaddr4   = NULL;
-		cep->p_myaddr4    = NULL;
+		cep->p_myaddr4    = NADR;
 		cep->p_dstaddr    = p_dstaddr;
 		cep->p_myaddr     = p_myaddr;
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udp_output.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udp_output.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udp_output.c	(revision 387)
@@ -182,5 +182,5 @@
 #if defined(_IP6_CFG) && TNUM_UDP6_CEPID > 0
 
-		for (ix = tmax_udp6_cepid; ix -- > 0; ) {
+		for (ix = TNUM_UDP6_CEPID - 1; ix -- > 0; ) {
 
 			if (udp6_cep[ix].flags & UDP_CEP_FLG_POST_OUTPUT) {
@@ -194,5 +194,5 @@
 #if defined(_IP4_CFG) && TNUM_UDP4_CEPID > 0
 
-		for (ix = tmax_udp4_cepid; ix -- > 0; ) {
+		for (ix = TNUM_UDP4_CEPID - 1; ix -- > 0; ) {
 
 			if (udp4_cep[ix].flags & UDP_CEP_FLG_POST_OUTPUT) {
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udp_subr.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udp_subr.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udp_subr.c	(revision 387)
@@ -146,5 +146,5 @@
 #define UDP_FIND_CEP		udp6_find_cep
 #define UDP_NOTIFY		udp6_notify
-#define TMAX_UDP_CEPID		tmax_udp6_cepid
+#define TMAX_UDP_CEPID		(TNUM_UDP6_CEPID - 1)
 #define UDP_CEP			udp6_cep
 #define T_UDP_CEP		T_UDP6_CEP
@@ -183,5 +183,5 @@
 #define UDP_FIND_CEP		udp4_find_cep
 #define UDP_NOTIFY		udp4_notify
-#define TMAX_UDP_CEPID		tmax_udp4_cepid
+#define TMAX_UDP_CEPID		(TNUM_UDP4_CEPID - 1)
 #define T_UDP_CEP		T_UDP4_CEP
 #define UDP_CEP			udp4_cep
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udpn_usrreq.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udpn_usrreq.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet/udpn_usrreq.c	(revision 387)
@@ -308,16 +308,15 @@
 		else 
 			error = UDP_ALLOC_PORT(cep, pk_ccep->myaddr.portno);
-		
-                if (error == E_OK) {
-
-			/* UDP 通信端点生成情報をコピーする。*/
-			cep->cepatr        = pk_ccep->cepatr;			/* 通信端点属性		*/
-			cep->myaddr.ipaddr = pk_ccep->myaddr.ipaddr;		/* 自分のアドレス	*/
-			cep->callback      = (void*)pk_ccep->callback;		/* コールバック		*/
-
-			/* UDP 通信端点を生成済みにする。*/
-			cep->flags |= UDP_CEP_FLG_VALID;
-			}
-		}
+
+			if (error == E_OK) {
+				/* UDP 通信端点生成情報をコピーする。*/
+				cep->cepatr        = pk_ccep->cepatr;			/* 通信端点属性		*/
+				cep->myaddr.ipaddr = pk_ccep->myaddr.ipaddr;		/* 自分のアドレス	*/
+				cep->callback      = (void*)pk_ccep->callback;		/* コールバック		*/
+
+				/* UDP 通信端点を生成済みにする。*/
+				cep->flags |= UDP_CEP_FLG_VALID;
+				}
+			}
 
 	/* 通信端点のロックを解除する。*/
Index: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet6/nd6_rtr.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet6/nd6_rtr.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netinet6/nd6_rtr.c	(revision 387)
@@ -999,9 +999,9 @@
 		return;
 
- 	/* ルータ要請ヘッダを設定する。*/
- 	rsh = GET_ROUTER_SOLICIT_HDR(output, IF_IP6_ROUTER_SOLICIT_HDR_OFFSET);
- 	rsh->hdr.type       = ND_ROUTER_SOLICIT;
- 	rsh->hdr.code       = 0;
- 	rsh->nd_rs_reserved = 0;
+	/* ルータ要請ヘッダを設定する。*/
+	rsh = GET_ROUTER_SOLICIT_HDR(output, IF_IP6_ROUTER_SOLICIT_HDR_OFFSET);
+	rsh->hdr.type       = ND_ROUTER_SOLICIT;
+	rsh->hdr.code       = 0;
+	rsh->nd_rs_reserved = 0;
 
 	/* チェックサムを計算する。*/
Index: asp3_tinet_ecnl_arm/trunk/bnep_bridge/Debug/Makefile
===================================================================
--- asp3_tinet_ecnl_arm/trunk/bnep_bridge/Debug/Makefile	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/bnep_bridge/Debug/Makefile	(revision 387)
@@ -58,5 +58,6 @@
 	LIBS = $(SRCDIR)/../musl-1.1.18/Debug/libmusl.a \
 		$(SRCDIR)/../btstack/Debug/libbtstack.a \
-		$(SRCDIR)/../usbhost/Debug/libusbhost.a
+		$(SRCDIR)/../usbhost/Debug/libusbhost.a \
+		$(SRCDIR)/../zlib-1.2.11/Debug/libzlib.a
 endif
 ifeq ($(SRCLANG),c++)
@@ -189,9 +190,9 @@
 #
 APPLNAME = bnep_bridge
-APPLDIRS = ../src ../../ntshell/tlsf ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src $(SRCDIR)/$(TINETDIR)/netapp
+APPLDIRS = ../src ../../ntshell/fatfs ../../ntshell/ntshell ../../ntshell/ntshell/core ../../ntshell/ntshell/util ../../ntshell/src $(SRCDIR)/$(TINETDIR)/netapp
 APPL_CFG = main.cfg
 APPL_CDL = main.cdl
 
-APPL_COBJS := $(APPL_COBJS) ntshell_main.o fdtable.o io_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o tlsf.o
+APPL_COBJS := $(APPL_COBJS) ntshell_main.o fdtable.o stdio_stub.o io_stub.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o
 
 APPL_DIRS := $(APPLDIRS) $(SRCDIR)/library
Index: asp3_tinet_ecnl_arm/trunk/bnep_bridge/src/main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/bnep_bridge/src/main.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/bnep_bridge/src/main.c	(revision 387)
@@ -54,9 +54,6 @@
 #include "ffarch.h"
 #include "ff.h"
-#include "core/ntshell.h"
-#include "core/ntlibc.h"
 #include <stdio.h>
 #include "usrcmd.h"
-#include "util/ntopt.h"
 #include "gpio_api.h"
 #include "usb_hbth.h"
Index: asp3_tinet_ecnl_arm/trunk/bnep_bridge/src/main.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/bnep_bridge/src/main.cdl	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/bnep_bridge/src/main.cdl	(revision 387)
@@ -22,5 +22,5 @@
  *  ターゲット依存部の取り込み
  */
-import("target.cdl");
+import("ntshell.cdl");
 
 /*
Index: asp3_tinet_ecnl_arm/trunk/btstack/include/btstack/hci_cmds.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/btstack/include/btstack/hci_cmds.h	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/btstack/include/btstack/hci_cmds.h	(revision 387)
@@ -422,5 +422,5 @@
  * @param attribute_value
  */
-#define SDP_EVENT_QUERY_ATTRIBUTE_VALUE                          0x93
+#define SDP_EVENT_QUERY_ATTRIBUTE_VALUE                    0x93
 
 // not provided by daemon, only used for internal testing
Index: asp3_tinet_ecnl_arm/trunk/btstack/src/bnep.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/btstack/src/bnep.h	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/btstack/src/bnep.h	(revision 387)
@@ -72,7 +72,7 @@
 
 /* BNEP UUIDs */
-#define BLUETOOTH_SERVICE_CLASS_PANU                                  0x1115
-#define BLUETOOTH_SERVICE_CLASS_NAP                                   0x1116
-#define BLUETOOTH_SERVICE_CLASS_GN                                    0x1117
+#define BLUETOOTH_SERVICE_CLASS_PANU                    0x1115
+#define BLUETOOTH_SERVICE_CLASS_NAP                     0x1116
+#define BLUETOOTH_SERVICE_CLASS_GN                      0x1117
     
 /* BNEP packet types */    
Index: asp3_tinet_ecnl_arm/trunk/curl-7.57.0/lib/easy.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/curl-7.57.0/lib/easy.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/curl-7.57.0/lib/easy.c	(revision 387)
@@ -166,11 +166,4 @@
 #endif
 
-#ifdef __c2__
-#define malloc musl_malloc
-#define free musl_free
-#define realloc musl_realloc
-#define calloc musl_calloc
-#endif
-
 #ifndef __SYMBIAN32__
 /*
Index: asp3_tinet_ecnl_arm/trunk/curl-7.57.0/lib/security.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/curl-7.57.0/lib/security.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/curl-7.57.0/lib/security.c	(revision 387)
@@ -8,5 +8,5 @@
  * below.
  *
- * Copyright (c) 1998, 1999, 2017 Kungliga Tekniska H旦gskolan
+ * Copyright (c) 1998, 1999, 2017 Kungliga Tekniska Hogskolan
  * (Royal Institute of Technology, Stockholm, Sweden).
  *
Index: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/include/bits/alltypes.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/musl-1.1.18/include/bits/alltypes.h	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/musl-1.1.18/include/bits/alltypes.h	(revision 387)
@@ -1,34 +1,2 @@
-#if defined(_MSC_VER) || defined(__c2__)
-#define close musl_close
-#define execvp musl_execvp
-#define fclose musl_fclose
-#define fdopen musl_fdopen
-#define fflush musl_fflush
-#define fopen musl_fopen
-#define free musl_free
-#define fwrite musl_fwrite
-#define getcwd musl_getcwd
-#define localtime musl_localtime
-#define lseek musl_lseek
-#define open musl_open
-#define read musl_read
-#define malloc musl_malloc
-#define calloc musl_calloc
-#define realloc musl_realloc
-#define time musl_time
-#define unlink musl_unlink
-#define perror musl_perror
-#define strnlen musl_strnlen
-#define strftime musl_strftime
-#define asctime musl_asctime
-#define tzset musl_tzset
-#define clock musl_clock
-#endif
-#ifdef _MSC_VER
-#define __builtin_va_list char *
-#define __NEED_va_list
-#define restrict __restrict
-#endif
-
 #define _Addr int
 #define _Int64 long long
Index: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/include/stddef.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/musl-1.1.18/include/stddef.h	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/musl-1.1.18/include/stddef.h	(revision 387)
@@ -11,5 +11,5 @@
 #define __NEED_size_t
 #define __NEED_wchar_t
-#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L
+#if __STDC_VERSION__ >= 201112L || (defined(__cplusplus) && __cplusplus >= 201103L)
 #define __NEED_max_align_t
 #endif
Index: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/__lctrans.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/__lctrans.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/__lctrans.c	(revision 387)
@@ -8,7 +8,5 @@
 }
 
-#ifndef __c2__
 weak_alias(dummy, __lctrans_impl);
-#endif
 
 const char *__lctrans(const char *msg, const struct __locale_map *lm)
Index: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/__mo_lookup.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/__mo_lookup.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/__mo_lookup.c	(revision 387)
@@ -4,5 +4,5 @@
 static inline uint32_t swapc(uint32_t x, int c)
 {
-	return c ? x>>24 | x>>8&0xff00 | x<<8&0xff0000 | x<<24 : x;
+	return c ? (x>>24) | (x>>8&0xff00) | (x<<8&0xff0000) | (x<<24) : x;
 }
 
Index: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/iconv.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/iconv.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/iconv.c	(revision 387)
@@ -136,5 +136,5 @@
 {
 	e &= 3;
-	return s[e]+0U<<24 | s[e^1]<<16 | s[e^2]<<8 | s[e^3];
+	return (s[e]+0U)<<24 | s[e^1]<<16 | s[e^2]<<8 | s[e^3];
 }
 
@@ -156,5 +156,5 @@
 	unsigned x = c - 128 - map[-1];
 	x = legacy_chars[ map[x*5/4]>>2*x%8 |
-		map[x*5/4+1]<<8-2*x%8 & 1023 ];
+		(map[x*5/4+1]<<(8-2*x%8) & 1023) ];
 	return x ? x : c;
 }
@@ -348,5 +348,5 @@
 				c += (0xa1-0x81);
 				d += 0xa1;
-				if (c >= 93 || c>=0xc6-0x81 && d>0x52)
+				if (c >= 93 || (c>=0xc6-0x81 && d>0x52))
 					goto ilseq;
 				if (d-'A'<26) d = d-'A';
Index: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/locale_map.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/locale_map.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/locale/locale_map.c	(revision 387)
@@ -36,7 +36,7 @@
 
 	if (!*val) {
-		(val = getenv("LC_ALL")) && *val ||
-		(val = getenv(envvars[cat])) && *val ||
-		(val = getenv("LANG")) && *val ||
+		((val = getenv("LC_ALL")) && *val) ||
+		((val = getenv(envvars[cat])) && *val) ||
+		((val = getenv("LANG")) && *val) ||
 		(val = "C.UTF-8");
 	}
Index: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/malloc/memalign.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/malloc/memalign.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/malloc/memalign.c	(revision 387)
@@ -46,8 +46,8 @@
 	footer = ((size_t *)end)[-2];
 
-	((size_t *)mem)[-1] = header&7 | new-mem;
-	((size_t *)new)[-2] = footer&7 | new-mem;
-	((size_t *)new)[-1] = header&7 | end-new;
-	((size_t *)end)[-2] = footer&7 | end-new;
+	((size_t *)mem)[-1] = (header&7) | new-mem;
+	((size_t *)new)[-2] = (footer&7) | new-mem;
+	((size_t *)new)[-1] = (header&7) | end-new;
+	((size_t *)end)[-2] = (footer&7) | end-new;
 
 	free(mem);
Index: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/math/fma.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/math/fma.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/math/fma.c	(revision 387)
@@ -70,5 +70,5 @@
 		if (d < 64) {
 			zlo = nz.m<<d;
-			zhi = nz.m>>64-d;
+			zhi = nz.m>>(64-d);
 		} else {
 			zlo = 0;
@@ -78,5 +78,5 @@
 			if (d == 0) {
 			} else if (d < 64) {
-				rlo = rhi<<64-d | rlo>>d | !!(rlo<<64-d);
+				rlo = rhi<<(64-d) | rlo>>d | !!(rlo<<(64-d));
 				rhi = rhi>>d;
 			} else {
@@ -91,5 +91,5 @@
 			zlo = nz.m;
 		} else if (d < 64) {
-			zlo = nz.m>>d | !!(nz.m<<64-d);
+			zlo = nz.m>>d | !!(nz.m<<(64-d));
 		} else {
 			zlo = 1;
@@ -123,5 +123,5 @@
 		d = a_clz_64(rhi)-1;
 		/* note: d > 0 */
-		rhi = rhi<<d | rlo>>64-d | !!(rlo<<d);
+		rhi = rhi<<d | rlo>>(64-d) | !!(rlo<<d);
 	} else if (rlo) {
 		d = a_clz_64(rlo)-1;
@@ -174,5 +174,5 @@
 			/* only round once when scaled */
 			d = 10;
-			i = ( rhi>>d | !!(rhi<<64-d) ) << d;
+			i = ( rhi>>d | !!(rhi<<(64-d)) ) << d;
 			if (sign)
 				i = -i;
Index: asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/network/lookup_name.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/network/lookup_name.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/musl-1.1.18/src/network/lookup_name.c	(revision 387)
@@ -11,4 +11,5 @@
 #include <pthread.h>
 #include <errno.h>
+#include <resolv.h>
 #include "lookup.h"
 #include "stdio_impl.h"
@@ -185,4 +186,8 @@
 	if (dots >= conf.ndots || name[l-1]=='.') *search = 0;
 
+	/* Strip final dot for canon, fail if multiple trailing dots. */
+	if (name[l-1]=='.') l--;
+	if (!l || name[l-1]=='.') return EAI_NONAME;
+
 	/* This can never happen; the caller already checked length. */
 	if (l >= 256) return EAI_NONAME;
@@ -311,5 +316,5 @@
 	if (!cnt && !(flags & AI_NUMERICHOST)) {
 		cnt = name_from_hosts(buf, canon, name, family);
-		if (!cnt) cnt = name_from_dns_search(buf, canon, name, family);
+		if (cnt<=0) cnt = name_from_dns_search(buf, canon, name, family);
 	}
 	if (cnt<=0) return cnt ? cnt : EAI_NONAME;
@@ -352,34 +357,51 @@
 	 * So far the label/precedence table cannot be customized. */
 	for (i=0; i<cnt; i++) {
+		int family = buf[i].family;
 		int key = 0;
-		struct sockaddr_in6 sa, da = {
+		struct sockaddr_in6 sa6 = { 0 }, da6 = {
 			.sin6_family = AF_INET6,
 			.sin6_scope_id = buf[i].scopeid,
 			.sin6_port = 65535
 		};
-		if (buf[i].family == AF_INET6) {
-			memcpy(da.sin6_addr.s6_addr, buf[i].addr, 16);
+		struct sockaddr_in sa4 = { 0 }, da4 = {
+			.sin_family = AF_INET,
+			.sin_port = 65535
+		};
+		void *sa, *da;
+		socklen_t salen, dalen;
+		if (family == AF_INET6) {
+			memcpy(da6.sin6_addr.s6_addr, buf[i].addr, 16);
+			da = &da6; dalen = sizeof da6;
+			sa = &sa6; salen = sizeof sa6;
 		} else {
-			memcpy(da.sin6_addr.s6_addr,
+			memcpy(sa6.sin6_addr.s6_addr,
 				"\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
-			memcpy(da.sin6_addr.s6_addr+12, buf[i].addr, 4);
-		}
-		const struct policy *dpolicy = policyof(&da.sin6_addr);
-		int dscope = scopeof(&da.sin6_addr);
+			memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4);
+			memcpy(da6.sin6_addr.s6_addr,
+				"\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
+			memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4);
+			memcpy(&da4.sin_addr, buf[i].addr, 4);
+			da = &da4; dalen = sizeof da4;
+			sa = &sa4; salen = sizeof sa4;
+		}
+		const struct policy *dpolicy = policyof(&da6.sin6_addr);
+		int dscope = scopeof(&da6.sin6_addr);
 		int dlabel = dpolicy->label;
 		int dprec = dpolicy->prec;
 		int prefixlen = 0;
-		int fd = socket(AF_INET6, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP);
+		int fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP);
 		if (fd >= 0) {
-			if (!connect(fd, (void *)&da, sizeof da)) {
+			if (!connect(fd, da, dalen)) {
 				key |= DAS_USABLE;
-				if (!getsockname(fd, (void *)&sa,
-				    &(socklen_t){sizeof sa})) {
-					if (dscope == scopeof(&sa.sin6_addr))
+				if (!getsockname(fd, sa, &salen)) {
+					if (family == AF_INET) memcpy(
+						sa6.sin6_addr.s6_addr+12,
+						&sa4.sin_addr, 4);
+					if (dscope == scopeof(&sa6.sin6_addr))
 						key |= DAS_MATCHINGSCOPE;
-					if (dlabel == labelof(&sa.sin6_addr))
+					if (dlabel == labelof(&sa6.sin6_addr))
 						key |= DAS_MATCHINGLABEL;
-					prefixlen = prefixmatch(&sa.sin6_addr,
-						&da.sin6_addr);
+					prefixlen = prefixmatch(&sa6.sin6_addr,
+						&da6.sin6_addr);
 				}
 			}
Index: asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/fatfs/ffarch.c	(revision 387)
@@ -80,5 +80,5 @@
 	ret2 = get_tim(&now);
 	if (ret2 != E_OK){
-		printf("[ffarch] get_tim error: %s",
+		syslog(LOG_NOTICE, "[ffarch] get_tim error: %s",
 			itron_strerror(ret2));
 		return;
@@ -94,5 +94,5 @@
 		ret = tslp_tsk(timer);
 		if ((ret != E_OK) && (ret != E_TMOUT)) {
-			printf("[ffarch] tslp_tsk error: %s %d",
+			syslog(LOG_NOTICE, "[ffarch] tslp_tsk error: %s %d",
 				itron_strerror(ret), timer);
 			break;
@@ -101,5 +101,5 @@
 		ret2 = get_tim(&now);
 		if (ret2 != E_OK) {
-			printf("[ffarch] get_tim error: %s",
+			syslog(LOG_NOTICE, "[ffarch] get_tim error: %s",
 				itron_strerror(ret2));
 			break;
@@ -131,5 +131,5 @@
 bool_t SD_begin();
 
-void ffarch_init()
+void ffarch_init(void)
 {
 	/* SD_CD */
@@ -150,8 +150,8 @@
 
 	if (romdisk_init()) {
-		printf("ROM disk (0:) OK!\n");
+		syslog(LOG_NOTICE, "ROM disk (0:) OK!");
 	}
 	else {
-		printf("ROM disk (0:) NG!\n");
+		syslog(LOG_NOTICE, "ROM disk (0:) NG!");
 	}
 }
@@ -352,5 +352,5 @@
 }
 
-int ffarch_get_timer()
+int ffarch_get_timer(void)
 {
 	return ffarch_timer;
@@ -367,5 +367,5 @@
 }
 
-void ffarch_timeout()
+void ffarch_timeout(void)
 {
 	if (ffarch_timer != 0)
@@ -375,5 +375,5 @@
 	case FFS_RETRY_WAIT:
 		if (ffarch_retry_count == 0) {
-			printf("SD card (1:) initialize tired...\n");
+			syslog(LOG_NOTICE, "SD card (1:) initialize tired...");
 
 			ffarch_state = FFS_IDLE;
@@ -388,8 +388,8 @@
  		if ((sdfs._is_initialized & STA_NOINIT)
  			|| (((sdfs_prev_status & STA_NODISK) != 0) && ((sdfs_new_status & STA_NODISK) == 0))) {
-			printf("SD card initializing ...\n");
+			syslog(LOG_NOTICE, "SD card initializing ...");
 
 			if (SD_begin()) {
-				printf("SD card (1:) OK!\n");
+				syslog(LOG_NOTICE, "SD card (1:) OK!");
 
 				/* uploadディレクトリを作成しておく */
@@ -401,5 +401,5 @@
 			}
 			else {
-				printf("SD card (1:) NG!\n");
+				syslog(LOG_NOTICE, "SD card (1:) NG!");
 				ffarch_state = FFS_RETRY_WAIT;
 				ffarch_timer = 1000 * 1000;
@@ -408,5 +408,5 @@
 		/* SDカードが抜かれた場合 */
 		else if (((sdfs_prev_status & STA_NODISK) == 0) && ((sdfs_new_status & STA_NODISK) != 0)) {
-			printf("SD card unmount\n");
+			syslog(LOG_NOTICE, "SD card unmount");
 
 			f_mount(&Sd.FatFs, "1:", 0);
Index: asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.c	(revision 387)
@@ -224,6 +224,4 @@
 	handle->xi = xi;
 	handle->xo = xo;
-	handle->outptr = 0;
-	handle->len = 0;
 	handle->pos = 0;
 	handle->option = option;
@@ -232,12 +230,4 @@
 static void _putc(ntstdio_t *handle, char c)
 {
-	if (handle->outptr) {
-		if ((handle->pos + 1) >= handle->len)
-			return;
-		handle->outptr[handle->pos] = (unsigned char)c;
-		handle->pos++;
-		return;
-	}
-
 	if (handle->xo) {
 		handle->xo(handle, (unsigned char)c);
@@ -291,14 +281,32 @@
 }
 
+struct put_buf_t {
+	char *outptr;
+	int len;
+};
+
+static void put_buf(struct ntstdio_t *handle, unsigned char c)
+{
+	struct put_buf_t *put_buf = (struct put_buf_t *)handle->exinf;
+	if ((handle->pos + 1) >= put_buf->len)
+		return;
+	put_buf->outptr[handle->pos] = (char)c;
+	handle->pos++;
+}
+
 int ntstdio_snprintf(char *buf, int len, const char *fmt, ...)
 {
 	int result;
 	ntstdio_t handle;
+	struct put_buf_t exinf;
 	va_list arp;
 	/* Switch destination for memory */
+	handle.xo = put_buf;
 	handle.option = 0;
-	handle.outptr = buf;
-	handle.len = len;
 	handle.pos = 0;
+	handle.exinf = &exinf;
+	exinf.outptr = buf;
+	exinf.len = len;
+
 	va_start(arp, fmt);
 	result = xvprintf(&handle, fmt, arp);
@@ -306,5 +314,5 @@
 
 	/* Terminate output string with a \0 */
-	handle.outptr[handle.pos] = '\0';
+	buf[handle.pos] = '\0';
 	return result;
 }
Index: asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.h	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/ntshell/util/ntstdio.h	(revision 387)
@@ -74,6 +74,4 @@
 	NTSTDIO_XI xi;
 	NTSTDIO_XO xo;
-	char *outptr;
-	int len;
 	int pos;
 	unsigned int option;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.c	(revision 387)
@@ -44,26 +44,5 @@
 #include "syssvc/syslog.h"
 #include "target_syssvc.h"
-#ifndef NTSHELL_NO_SOCKET
-#include <tinet_defs.h>
-#include <tinet_config.h>
-#include <net/net.h>
-#include <net/net_endian.h>
-#include <netinet/in.h>
-#include <netinet/in_itron.h>
-#include <tinet_nic_defs.h>
-#include <tinet_cfg.h>
-#include <netinet/in_var.h>
-#include <net/ethernet.h>
-#include <net/if6_var.h>
-#include <net/net.h>
-#include <net/if_var.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
-#include <netinet/tcp.h>
-#include <netinet/tcp_var.h>
-#include <net/net_buf.h>
-#endif
-#include "ff.h"
-#include "socket_stub.h"
+#include "fdtable.h"
 #include "kernel_cfg.h"
 #include <string.h>
@@ -75,147 +54,14 @@
 #endif
 
-static int stdio_close(struct SHELL_FILE *fp);
-static size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
-static size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
-static size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
-static size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
-static size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
-static void stdio_delete(struct SHELL_FILE *fp);
-
-static int sio_close(struct SHELL_FILE *fp);
-static size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
-static size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
-static off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org);
-static int sio_ioctl(struct SHELL_FILE *fp, int req, void *arg);
-static bool_t sio_readable(struct SHELL_FILE *fp);
-static void sio_delete(struct SHELL_FILE *fp);
-
-IO_TYPE IO_TYPE_STDIN = { stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
-IO_TYPE IO_TYPE_STDOUT = { stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
-IO_TYPE IO_TYPE_STDERR = { stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl, sio_readable, stdio_delete };
-IO_TYPE IO_TYPE_SIO = { sio_close, sio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_delete };
-ntstdio_t ntstdio;
+extern IO_TYPE IO_TYPE_STDIN;
+extern IO_TYPE IO_TYPE_STDOUT;
+extern IO_TYPE IO_TYPE_STDERR;
 
 static struct SHELL_FILE fd_table[8 * sizeof(FLGPTN)] = {
-	{ 0, &IO_TYPE_STDIN, 0, .exinf = &ntstdio },
-	{ 1, &IO_TYPE_STDOUT, 0, .exinf = &ntstdio },
-	{ 2, &IO_TYPE_STDERR, 0,.exinf = &ntstdio },
+	{ STDIN_FILENO, &IO_TYPE_STDIN, 0 },
+	{ STDOUT_FILENO, &IO_TYPE_STDOUT, 0 },
+	{ STDERR_FILENO, &IO_TYPE_STDERR, 0 },
 };
 #define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0]))
-
-extern ntstdio_t ntstdio;
-extern serial_t stdio_uart;
-
-unsigned char ntstdio_xi(struct ntstdio_t *handle)
-{
-	return serial_getc((serial_t *)handle->exinf);
-}
-
-void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
-{
-	serial_putc((serial_t *)handle->exinf, c);
-}
-
-void sys_init(intptr_t exinf)
-{
-	ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
-	ntstdio.exinf = (void *)&stdio_uart;
-}
-
-int stdio_close(struct SHELL_FILE *fp)
-{
-	return -EPERM;
-}
-
-size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t stdin_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
-{
-	int i = 0;
-	while (i < len) {
-		int c = ntstdio_getc((struct ntstdio_t *)fp->exinf);
-		data[i++] = c;
-		if ((c == EOF) || (c == '\n'))
-			break;
-	}
-	return i;
-}
-
-size_t stdout_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
-{
-	for (int i = 0; i < len; i++) {
-		ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
-	}
-	return len;
-}
-
-size_t stderr_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
-{
-	for (int i = 0; i < len; i++) {
-		ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
-	}
-	return len;
-}
-
-void stdio_delete(struct SHELL_FILE *fp)
-{
-}
-
-int sio_close(struct SHELL_FILE *fp)
-{
-	return -EPERM;
-}
-
-size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org)
-{
-	return -EPERM;
-}
-
-int sio_ioctl(struct SHELL_FILE *fp, int request, void *arg)
-{
-	switch (request) {
-	case TIOCGWINSZ:
-		return 0;
-	case TCGETS:
-		return sio_tcgetattr(fp->fd, (struct termios *)arg);
-	case TCSETS + TCSANOW:
-	case TCSETS + TCSADRAIN:
-	case TCSETS + TCSAFLUSH:
-		return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
-	}
-
-	return -EINVAL;
-}
-
-bool_t sio_readable(struct SHELL_FILE *fp)
-{
-	return fp->readevt_w != fp->readevt_r;
-}
-
-void sio_delete(struct SHELL_FILE *fp)
-{
-	free((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf);
-	((struct ntstdio_t *)fp->exinf)->exinf = NULL;
-	free((struct ntstdio_t *)fp->exinf);
-	fp->exinf = NULL;
-}
 
 struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable)
@@ -245,4 +91,15 @@
 	if (ret < 0) {
 		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
+
+	if (fp != NULL) {
+		FLGPTN flgptn = 0;
+
+		FD_SET(fp->fd, (fd_set *)&flgptn);
+
+		ret = clr_flg(FLG_SELECT_WAIT, ~flgptn);
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "clr_flg => %d", ret);
+		}
 	}
 
@@ -440,50 +297,9 @@
 }
 
-/* TODO:コールバック化したい */
-void stdio_update_evts()
-{
-	int fd = STDIN_FILENO;
-	struct SHELL_FILE *fp = &fd_table[fd];
-	FLGPTN flgptn = 0;
-
-	if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		FD_SET(fd, (fd_set *)&flgptn);
-	}
-	if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		FD_SET(fd, (fd_set *)&flgptn);
-	}
-
-	if (flgptn != 0) {
-		set_flg(FLG_SELECT_WAIT, flgptn);
-	}
-}
-
-/* TODO:コールバック化したい */
-void stdio_flgptn(FLGPTN *flgptn)
-{
-	int fd = STDIN_FILENO;
-	struct SHELL_FILE *fp = &fd_table[fd];
-	*flgptn = 0;
-
-	if (serial_readable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		FD_SET(fd, (fd_set *)flgptn);
-	}
-	if (serial_writable((serial_t *)((struct ntstdio_t *)fp->exinf)->exinf)) {
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		FD_SET(fd, (fd_set *)flgptn);
-	}
-}
-
 ER shell_get_evts(struct fd_events *evts, TMO tmout)
 {
 	int count = 0;
 	SYSTIM prev, now;
+	FLGPTN flgptn;
 
 	get_tim(&prev);
@@ -491,8 +307,6 @@
 	for (;;) {
 		ER ret;
-		FLGPTN waitptn, flgptn, readfds = 0, writefds = 0;
+		FLGPTN waitptn, readfds = 0, writefds = 0;
 		struct SHELL_FILE *fp = NULL;
-
-		stdio_update_evts();
 
 #ifndef NTSHELL_NO_SOCKET
@@ -504,5 +318,4 @@
 			fp = &fd_table[fd];
 
-#ifndef NTSHELL_NO_SOCKET
 			if (FD_ISSET(fd, &evts->readfds)) {
 				if (fp->type->readable(fp)) {
@@ -515,7 +328,7 @@
 				}
 			}
-#endif
+
 			if (FD_ISSET(fd, &evts->writefds)) {
-				if (fp->writeevt_w == fp->writeevt_r) {
+				if (fp->type->writable(fp)) {
 					FD_SET(fd, (fd_set *)&writefds);
 					count++;
@@ -547,46 +360,41 @@
 				return ret;
 			}
-
-			stdio_flgptn(&flgptn);
-
-			if (flgptn == 0)
-				return E_TMOUT;
-		}
-		flgptn &= waitptn;
-
-		/* 受け取ったフラグのみクリア */
-		ret = clr_flg(FLG_SELECT_WAIT, ~flgptn);
-		if (ret != E_OK) {
-			syslog(LOG_ERROR, "clr_flg => %d", ret);
+		}
+
+		if (flgptn != 0) {
+			flgptn &= waitptn;
+
+			/* 受け取ったフラグのみクリア */
+			ret = clr_flg(FLG_SELECT_WAIT, ~flgptn);
+			if (ret != E_OK) {
+				syslog(LOG_ERROR, "clr_flg => %d", ret);
+			}
 		}
 
 		count = 0;
 		for (int fd = 0; fd < fd_table_count; fd++) {
-			if (!FD_ISSET(fd, (fd_set *)&waitptn))
-				continue;
-
 			fp = &fd_table[fd];
 
 			if (fp->readevt_w != fp->readevt_r) {
 				fp->readevt_r++;
-				FD_SET(fd, &evts->readfds);
+				if (FD_ISSET(fd, (fd_set *)&waitptn))
+					FD_SET(fd, &evts->readfds);
 				count++;
 			}
 			if (fp->writeevt_w != fp->writeevt_r) {
 				fp->writeevt_r++;
-				fp->writable = 1;
-			}
-			if (fp->writable) {
-				FD_SET(fd, &evts->writefds);
+				if (FD_ISSET(fd, (fd_set *)&waitptn))
+					FD_SET(fd, &evts->writefds);
 				count++;
 			}
 			if (fp->errorevt_w != fp->errorevt_r) {
 				fp->errorevt_r++;
-				FD_SET(fd, &evts->errorfds);
+				if (FD_ISSET(fd, (fd_set *)&waitptn))
+					FD_SET(fd, &evts->errorfds);
 				count++;
 			}
 		}
 
-		if (count > 0)
+		if ((flgptn == 0) || (count > 0))
 			break;
 
@@ -594,6 +402,8 @@
 
 		SYSTIM elapse = now - prev;
-		if (elapse > tmout)
-			return E_TMOUT;
+		if (elapse > tmout) {
+			flgptn = 0;
+			break;
+		}
 
 		prev = now;
@@ -603,5 +413,5 @@
 	evts->count = count;
 
-	return E_OK;
+	return (flgptn == 0) ? E_TMOUT : E_OK;
 }
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.h	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/fdtable.h	(revision 387)
@@ -0,0 +1,85 @@
+/*
+ *  TOPPERS ECHONET Lite Communication Middleware
+ * 
+ *  Copyright (C) 2017 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+#ifndef SOCKET_STUB_H
+#define SOCKET_STUB_H
+
+typedef const struct io_type_s IO_TYPE;
+
+struct SHELL_FILE {
+	int fd;
+	IO_TYPE *type;
+	int handle;
+	int readevt_r;
+	int readevt_w;
+	int writeevt_r;
+	int writeevt_w;
+	int writable;
+	int errorevt_r;
+	int errorevt_w;
+	void *exinf;
+};
+
+struct io_type_s {
+	int (*close)(struct SHELL_FILE *);
+	size_t (*read)(struct SHELL_FILE *, unsigned char *, size_t);
+	size_t (*write)(struct SHELL_FILE *, const unsigned char *, size_t);
+	off_t (*seek)(struct SHELL_FILE *, off_t, int);
+	int (*ioctl)(struct SHELL_FILE *, int, void *);
+	bool_t (*readable)(struct SHELL_FILE *);
+	bool_t (*writable)(struct SHELL_FILE *);
+	void (*delete)(struct SHELL_FILE *);
+};
+
+#ifndef bool
+#define bool int
+#endif
+#ifndef true
+#define true 1
+#endif
+#ifndef false
+#define false 0
+#endif
+
+struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable);
+int delete_fd_by_id(IO_TYPE *type, int id);
+struct SHELL_FILE *fd_to_fp(int fd);
+struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id);
+
+int delete_fp(struct SHELL_FILE *fp);
+void clean_fd();
+
+#endif // !SOCKET_STUB_H
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/io_stub.c	(revision 387)
@@ -45,5 +45,5 @@
 #include "syssvc/serial.h"
 #include "syssvc/syslog.h"
-#include "socket_stub.h"
+#include "fdtable.h"
 #include "util/ntstdio.h"
 #include "usrcmd.h"
@@ -51,4 +51,9 @@
 #include "kernel_cfg.h"
 #include "target_syssvc.h"
+
+struct SHELL_DIR {
+	FATFS_DIR dir;
+	struct dirent dirent;
+};
 
 int fresult2errno(FRESULT res)
@@ -85,4 +90,5 @@
 static int file_ioctl(struct SHELL_FILE *fp, int req, void *arg);
 static bool_t file_readable(struct SHELL_FILE *fp);
+static bool_t file_writable(struct SHELL_FILE *fp);
 static void file_delete(struct SHELL_FILE *fp);
 
@@ -93,8 +99,9 @@
 static int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg);
 static bool_t dir_readable(struct SHELL_FILE *fp);
+static bool_t dir_writable(struct SHELL_FILE *fp);
 static void dir_delete(struct SHELL_FILE *fp);
 
-IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_delete };
-IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_delete };
+IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_writable, file_delete };
+IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_writable, dir_delete };
 
 int shell_open(const char *path, int flags, void *arg)
@@ -114,4 +121,5 @@
 		FRESULT res;
 		if ((res = f_opendir(dir, path)) != FR_OK) {
+			delete_fp(fp);
 			return fresult2errno(res);
 		}
@@ -165,4 +173,5 @@
 	}
 
+	delete_fp(fp);
 	return fresult2errno(res);
 }
@@ -239,4 +248,9 @@
 }
 
+bool_t file_writable(struct SHELL_FILE *fp)
+{
+	return fp->writable && (fp->writeevt_w == fp->writeevt_r);
+}
+
 void file_delete(struct SHELL_FILE *fp)
 {
@@ -356,84 +370,4 @@
 {
 	return shell_ioctl(fd, cmd, arg);
-}
-
-extern IO_TYPE IO_TYPE_SIO;
-
-int sio_tcgetattr(int fd, struct termios *termios)
-{
-	struct SHELL_FILE *fp = fd_to_fp(fd);
-	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))
-		return -EBADF;
-
-	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
-
-	memset(termios, 0, sizeof(*termios));
-
-	if (ntstdio->option & NTSTDIO_OPTION_LINE_ECHO) {
-		termios->c_lflag |= ECHO;
-	}
-	else {
-		termios->c_lflag &= ~ECHO;
-	}
-	if (ntstdio->option & NTSTDIO_OPTION_CANON) {
-		termios->c_lflag |= ICANON;
-	}
-	else {
-		termios->c_lflag &= ~ICANON;
-	}
-	if (ntstdio->option & NTSTDIO_OPTION_LF_CR) {
-		termios->c_iflag |= INLCR;
-	}
-	else {
-		termios->c_iflag &= ~INLCR;
-	}
-	if (ntstdio->option & NTSTDIO_OPTION_LF_CRLF) {
-		termios->c_oflag |= ONLCR;
-	}
-	else {
-		termios->c_oflag &= ~ONLCR;
-	}
-
-	return 0;
-}
-
-int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)
-{
-	struct SHELL_FILE *fp = fd_to_fp(fd);
-	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))
-		return -EBADF;
-
-	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
-
-	if (optional_actions == TCSANOW) {
-		if (termios->c_lflag & ECHO) {
-			ntstdio->option |= NTSTDIO_OPTION_LINE_ECHO;
-		}
-		else {
-			ntstdio->option &= ~NTSTDIO_OPTION_LINE_ECHO;
-		}
-		if (termios->c_lflag & ICANON) {
-			ntstdio->option |= NTSTDIO_OPTION_CANON;
-		}
-		else {
-			ntstdio->option &= ~NTSTDIO_OPTION_CANON;
-		}
-		if (termios->c_iflag & INLCR) {
-			ntstdio->option |= NTSTDIO_OPTION_LF_CR;
-		}
-		else {
-			ntstdio->option &= ~NTSTDIO_OPTION_LF_CR;
-		}
-		if (termios->c_oflag & ONLCR) {
-			ntstdio->option |= NTSTDIO_OPTION_LF_CRLF;
-		}
-		else {
-			ntstdio->option &= ~NTSTDIO_OPTION_LF_CRLF;
-		}
-		return 0;
-	}
-
-	shell_abort();
-	return 0;
 }
 
@@ -688,4 +622,9 @@
 }
 
+bool_t dir_writable(struct SHELL_FILE *fp)
+{
+	return false;
+}
+
 void dir_delete(struct SHELL_FILE *fp)
 {
@@ -710,40 +649,2 @@
 	return 0;
 }
-
-#ifndef _MSC_VER
-extern uint32_t __HeapBase;
-extern uint32_t __HeapLimit;
-#else
-uint8_t __HeapBase[14 * 4096];
-#define __HeapLimit __HeapBase[sizeof(__HeapBase)]
-#endif
-
-void *shell_brk(void *addr)
-{
-	if (addr == 0) {
-		return (void *)(&__HeapBase);
-	}
-	if ((addr >= (void *)&__HeapBase) && (addr < (void *)&__HeapLimit)) {
-		return addr;
-	}
-	return (void *)-1;
-}
-
-void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
-{
-	if (fd != -1)
-		return (void *)-EINVAL;
-
-	if ((length >= 0) && (length <= sizeof(&__HeapBase))) {
-		return &__HeapBase;
-	}
-	return (void *)-1;
-}
-
-int shell_mprotect(void *addr, size_t len, int prot)
-{
-	//if ((addr >= (void *)&__HeapBase) && (addr + len < (void *)&__HeapLimit)) {
-	return 0;
-//}
-//return -1;
-}
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/net_misc.c	(revision 387)
@@ -95,5 +95,5 @@
 
 	get_tid(&nc->tskid);
-	printf("[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);
+	syslog(LOG_NOTICE, "[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);
 
 	/* 初期化 */
@@ -103,5 +103,5 @@
 	ret = get_tim(&time);
 	if (ret != E_OK) {
-		printf("[NET MISC,%d] get_tim error: %7lu,%s",
+		syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %7lu,%s",
 			nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
 		return;
@@ -117,5 +117,5 @@
 		error = tslp_tsk(timer);
 		if ((error != E_OK) && (error != E_TMOUT)) {
-			printf("[NET MISC,%d] tslp_tsk error: %s %d",
+			syslog(LOG_NOTICE, "[NET MISC,%d] tslp_tsk error: %s %d",
 				nc->cepid, itron_strerror(error), timer);
 			break;
@@ -124,5 +124,5 @@
 		ret = get_tim(&time);
 		if (ret != E_OK) {
-			printf("[NET MISC,%d] get_tim error: %s",
+			syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %s",
 				nc->cepid, itron_strerror(ret));
 			break;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntp_cli.c	(revision 387)
@@ -277,5 +277,5 @@
 	}
 
-	printf("[NTP CLI,%d] recv time: %s .%09u\n",
+	syslog(LOG_NOTICE, "[NTP CLI,%d] recv time: %s .%09u",
 		nc->cepid, nc->buf, tp.tv_nsec);
 }
@@ -309,5 +309,5 @@
 		line = lookup_ipaddr(&nc->ipaddr6, NTP_SRV_URL, API_PROTO_IPV4);
 		if (line == NULL || !in6_is_addr_ipv4mapped(&nc->ipaddr6)) {
-			printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
+			syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
 				nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
 			nc->timer = SLP_ITV;
@@ -317,5 +317,5 @@
 #else	/* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
 		if ((line = lookup_ipaddr(&nc->snd_rmt.ipaddr, NTP_SRV_URL, DEFAULT_API_PROTO)) == NULL) {
-			printf("[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
+			syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
 				nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
 			nc->timer = SLP_ITV;
@@ -421,10 +421,10 @@
 
 	if ((error = udp_snd_dat(nc->cepid, &nc->snd_rmt, ntp, len, TMO_NBLK)) != E_WBLK) {
-		printf("[NTP CLI,%d] udp_snd_dat error: %s",
+		syslog(LOG_NOTICE, "[NTP CLI,%d] udp_snd_dat error: %s",
 			nc->cepid, itron_strerror(error));
 		return error;
 	}
 	else
-		syslog(LOG_DEBUG, "[NTP CLI,%d] udp_snd_dat: to: %s.%d\n",
+		syslog(LOG_DEBUG, "[NTP CLI,%d] udp_snd_dat: to: %s.%d",
 			nc->cepid, ip2str(NULL, &nc->snd_rmt.ipaddr), nc->snd_rmt.portno);
 
@@ -439,5 +439,5 @@
 	ret = get_tim(&time);
 	if (ret != E_OK) {
-		printf("[NTP CLI,%d] get_tim error: %s",
+		syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s",
 			nc->cepid, itron_strerror(ret));
 		tp->tv_sec = 0;
@@ -459,5 +459,5 @@
 	ret = set_tim(time);
 	if (ret != E_OK) {
-		printf("[NTP CLI,%d] set_tim error: %s",
+		syslog(LOG_NOTICE, "[NTP CLI,%d] set_tim error: %s",
 			nc->cepid, itron_strerror(ret));
 	}
@@ -477,5 +477,5 @@
 	if (len < 0 && len != E_RLWAI) {
 		/* E_RLWAI 以外で、0 以下の場合は、エラーを意味している。*/
-		printf("[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,
+		syslog(LOG_NOTICE, "[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,
 			itron_strerror(len), in_strtfn(fncd));
 	}
@@ -484,5 +484,5 @@
 			if ((len = udp_rcv_dat(nc->cepid, &nc->rcv_rmt, &nc->ntp_msg, len, TMO_POL)) < 0)
 			{
-				printf("[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,
+				syslog(LOG_NOTICE, "[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,
 					itron_strerror(len));
 			}
@@ -516,5 +516,5 @@
 
 	get_tid(&nc->tskid);
-	printf("[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);
+	syslog(LOG_NOTICE, "[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);
 
 	/* 初期化 */
@@ -523,5 +523,5 @@
 	ret = get_tim(&time);
 	if (ret != E_OK) {
-		printf("[NTP CLI,%d] get_tim error: %7lu,%s",
+		syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %7lu,%s",
 			nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
 		return;
@@ -537,5 +537,5 @@
 		error = tslp_tsk(timer);
 		if ((error != E_OK) && (error != E_TMOUT)) {
-			printf("[NTP CLI,%d] tslp_tsk error: %s %d",
+			syslog(LOG_NOTICE, "[NTP CLI,%d] tslp_tsk error: %s %d",
 				nc->cepid, itron_strerror(error), timer);
 			break;
@@ -544,5 +544,5 @@
 		ret = get_tim(&time);
 		if (ret != E_OK) {
-			printf("[NTP CLI,%d] get_tim error: %s",
+			syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s",
 				nc->cepid, itron_strerror(ret));
 			break;
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell.cdl	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell.cdl	(revision 387)
@@ -0,0 +1,79 @@
+/*
+ *  TOPPERS/ASP Kernel
+ *      Toyohashi Open Platform for Embedded Real-Time Systems/
+ *      Advanced Standard Profile Kernel
+ * 
+ *  Copyright (C) 2015 by Ushio Laboratory
+ *              Graduate School of Engineering Science, Osaka Univ., JAPAN
+ *  Copyright (C) 2015,2016 by Embedded and Real-Time Systems Laboratory
+ *              Graduate School of Information Science, Nagoya Univ., JAPAN
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  $Id$
+ */
+
+import_C("target_syssvc.h");
+
+/*
+ *  タスクのスタックサイズのデフォルト
+ */
+const size_t DefaultTaskStackSize = 1024;		/* スタックサイズ（1KB）*/
+
+/*
+ *  システムログタスクのスタックサイズの定義
+ */
+const size_t LogTaskStackSize = DefaultTaskStackSize;
+
+/*
+ *  カーネル起動メッセージに関する定義
+ */
+const char *const BannerTargetName = C_EXP("TARGET_NAME");		/* ターゲット名 */
+const char *const BannerCopyrightNotice = "";			/* 著作権表示 */
+
+/*
+ *  ターゲット依存のセルタイプの定義
+ */
+import("syssvc/tPutLogSIOPort.cdl");
+import("tSIOPortNTShell.cdl");
+
+/*
+ *  シリアルインタフェースドライバのターゲット依存部の組み上げ記述
+ */
+cell tSIOPortNTShell SIOPortTarget1 {
+};
+
+/*
+ *  低レベル出力の組み上げ記述
+ */
+cell tPutLogSIOPort PutLogTarget {
+	/* SIOドライバとの結合 */
+	cSIOPort = SIOPortTarget1.eSIOPort;
+};
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/ntshell_main.c	(revision 387)
@@ -58,5 +58,5 @@
 #include "util/ntopt.h"
 #include "ntshell_main.h"
-#include "socket_stub.h"
+#include "fdtable.h"
 
 char command[NTOPT_TEXT_MAXLEN];
@@ -78,4 +78,5 @@
 }
 
+void stdio_open(ID portid);
 static int usrcmd_ntopt_callback(long *args, void *extobj);
 
@@ -86,5 +87,5 @@
 void ntshell_task_init(ID portid)
 {
-	serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
+	stdio_open(portid);
 }
 
@@ -95,5 +96,12 @@
 {
 	ntshell_state = 1;
-	ntshell_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL);
+
+	if (setjmp(process_exit) == 0) {
+		ntshell_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL);
+	}
+
+	fflush(stdout);
+	clean_fd();
+
 	ntshell_state = 2;
 }
@@ -139,6 +147,4 @@
 		printf("Unknown command found.\n");
 
-	clean_fd();
-
 	return result;
 }
@@ -285,9 +291,18 @@
 }
 
-struct sigaction sigtable[7];
-
-int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
-{
-	struct sigaction *sat;
+// musl-1.1.18\src\internal\ksigaction.h
+struct k_sigaction {
+	void(*handler)(int);
+	unsigned long flags;
+	void(*restorer)(void);
+	unsigned mask[2];
+};
+
+struct k_sigaction sigtable[7];
+
+int shell_sigaction(int sig, const struct k_sigaction *__restrict sa,
+	struct k_sigaction *__restrict old, size_t size)
+{
+	struct k_sigaction *sat;
 
 	switch(sig){
@@ -318,7 +333,7 @@
 
 	if (old != NULL)
-		memcpy(old, sat, sizeof(struct sigaction));
-
-	memcpy(sat, sa, sizeof(struct sigaction));
+		memcpy(old, sat, offsetof(struct k_sigaction, mask) + size);
+
+	memcpy(sat, sa, offsetof(struct k_sigaction, mask) + size);
 
 	return 0;
@@ -368,2 +383,34 @@
 }
 
+int shell_nanosleep(const struct timespec *req, struct timespec *rem)
+{
+	ER ret;
+	TMO tmo;
+	SYSTIM prev, now, diff;
+
+	if ((req == NULL) || (req->tv_nsec < 0) || (req->tv_nsec >= 1000000000))
+		return -EINVAL;
+
+	get_tim(&prev);
+
+	tmo = req->tv_sec * 1000000 + req->tv_nsec / 1000;
+	ret = tslp_tsk(tmo);
+	if (ret == E_OK) {
+		if (rem != NULL) {
+			get_tim(&now);
+			diff = now - prev;
+			rem->tv_sec = diff / 1000000ll;
+			rem->tv_nsec = (diff - (rem->tv_sec * 1000000ll)) * 1000ll;
+		}
+		return 0;
+	}
+	else if (ret == E_TMOUT) {
+		if (rem != NULL) {
+			rem->tv_sec = 0;
+			rem->tv_nsec = 0;
+		}
+		return 0;
+	}
+
+	return -EFAULT;
+}
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/shellif.h	(revision 387)
@@ -74,7 +74,7 @@
 #define NCCS 32
 
-#include <bits/fcntl.h>
-#include <bits/termios.h>
-#include <bits/stat.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <sys/stat.h>
 #include <sys/select.h>
 #include <time.h>
@@ -85,6 +85,6 @@
 #include <sys/utsname.h>
 #include <dirent.h>
-#include <bits/ioctl.h>
-#include <bits/errno.h>
+#include <sys/ioctl.h>
+#include <errno.h>
 #include <sys/socket.h>
 #else
@@ -132,4 +132,5 @@
 // time.h
 #define CLOCK_REALTIME 0
+int shell_nanosleep(const struct timespec *req, struct timespec *rem);
 
 // dirent.h
@@ -177,5 +178,7 @@
 // signal.h
 int shell_sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict old);
-int shell_sigaction(int sig, const struct sigaction *__restrict sa, struct sigaction *__restrict old);
+struct k_sigaction;
+int shell_sigaction(int sig, const struct k_sigaction *__restrict sa,
+	struct k_sigaction *__restrict old, size_t size);
 // socket.h
 int shell_socket(int, int, int);
@@ -197,7 +200,4 @@
 // syslog.h
 void vsyslog (int, const char *, va_list);
-// termios.h
-int sio_tcgetattr (int, struct termios *);
-int sio_tcsetattr(int, int, const struct termios *);
 // fcntl.h
 int shell_open(const char *, int, void *arg);
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.c	(revision 387)
@@ -62,10 +62,77 @@
 #include <netinet/tcp_var.h>
 #include <netapp/resolver.h>
-extern const ID tmax_tcp_cepid;
-#include "ff.h"
-#include "socket_stub.h"
+#include "fdtable.h"
 #include "kernel_cfg.h"
 
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
+
 #define SOCKET_TIMEOUT 2000000
+
+struct addrinfo {
+	int ai_flags;
+	int ai_family;
+	int ai_socktype;
+	int ai_protocol;
+	socklen_t ai_addrlen;
+	struct sockaddr *ai_addr;
+	char *ai_canonname;
+	struct addrinfo *ai_next;
+};
+
+typedef uint16_t in_port_t;
+typedef uint32_t in_addr_t;
+struct in_addr { in_addr_t s_addr; };
+
+struct sockaddr_in {
+	sa_family_t sin_family;
+	in_port_t sin_port;
+	struct in_addr sin_addr;
+	uint8_t sin_zero[8];
+};
+
+struct in6_addr
+{
+	union {
+		uint8_t __s6_addr[16];
+		uint16_t __s6_addr16[8];
+		uint32_t __s6_addr32[4];
+	} __in6_union;
+};
+//#define s6_addr __in6_union.__s6_addr
+//#define s6_addr16 __in6_union.__s6_addr16
+//#define s6_addr32 __in6_union.__s6_addr32
+
+struct sockaddr_in6
+{
+	sa_family_t     sin6_family;
+	in_port_t       sin6_port;
+	uint32_t        sin6_flowinfo;
+	struct in6_addr sin6_addr;
+	uint32_t        sin6_scope_id;
+};
+
+typedef struct socket_t {
+	int family;
+	int type;
+	int protocol;
+	int cepid;
+	int repid;
+	int backlog;
+	unsigned int flags;
+	union {
+		struct sockaddr_in laddr4;
+		struct sockaddr_in6 laddr6;
+	};
+	union {
+		struct sockaddr_in raddr4;
+		struct sockaddr_in6 raddr6;
+	};
+	int buf_size;
+	unsigned char *buf;
+	void *input;
+	int len;
+} socket_t;
 
 #define tcp6_cre_cep tcp_cre_cep
@@ -82,8 +149,4 @@
 #define tcp6_set_opt tcp_set_opt
 
-#define udp6_del_cep udp_del_cep
-#define udp6_get_opt udp_get_opt
-#define udp6_set_opt udp_set_opt
-
 #ifndef SUPPORT_INET6
 
@@ -93,6 +156,9 @@
 
 ER	udp6_cre_cep (ID cepid, T_UDP6_CCEP *pk_ccep) { return E_SYS; }
+ER	udp6_del_cep (ID cepid) { return E_SYS; }
 ER_UINT	udp6_snd_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout) { return E_SYS; }
 ER_UINT	udp6_rcv_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout) { return E_SYS; }
+ER	udp6_set_opt (ID cepid, int_t optname, void *optval, int_t optlen) { return E_SYS; }
+ER	udp6_get_opt (ID cepid, int_t optname, void *optval, int_t optlen) { return E_SYS; }
 
 const T_IN6_ADDR *in6_get_ifaddr (int_t index) { return NULL; }
@@ -111,4 +177,5 @@
 static int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
 static bool_t tcp_fd_readable(struct SHELL_FILE *fp);
+static bool_t tcp_fd_writable(struct SHELL_FILE *fp);
 static void tcp_fd_delete(struct SHELL_FILE *fp);
 
@@ -119,8 +186,9 @@
 static int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
 static bool_t udp_fd_readable(struct SHELL_FILE *fp);
+static bool_t udp_fd_writable(struct SHELL_FILE *fp);
 static void udp_fd_delete(struct SHELL_FILE *fp);
 
-IO_TYPE IO_TYPE_TCP = { tcp_fd_close, tcp_fd_read, tcp_fd_write, tcp_fd_seek, tcp_fd_ioctl, tcp_fd_readable, tcp_fd_delete };
-IO_TYPE IO_TYPE_UDP = { udp_fd_close, udp_fd_read, udp_fd_write, udp_fd_seek, udp_fd_ioctl, udp_fd_readable, udp_fd_delete };
+IO_TYPE IO_TYPE_TCP = { tcp_fd_close, tcp_fd_read, tcp_fd_write, tcp_fd_seek, tcp_fd_ioctl, tcp_fd_readable, tcp_fd_writable, tcp_fd_delete };
+IO_TYPE IO_TYPE_UDP = { udp_fd_close, udp_fd_read, udp_fd_write, udp_fd_seek, udp_fd_ioctl, udp_fd_readable, udp_fd_writable, udp_fd_delete };
 
 typedef struct id_table_t {
@@ -185,4 +253,15 @@
 
 #endif
+
+void addrcpy(void *_dst, const void *_src, int len)
+{
+#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
+	memcpy(_dst, _src, len);
+#else
+	uint8_t *dst = (uint8_t *)_dst, *src = &((uint8_t *)_src)[len];
+	while (src != _src)
+		*dst++ = *--src;
+#endif
+}
 
 ID new_id(id_table_t *table, int count)
@@ -347,12 +426,12 @@
 		}
 		case SOCK_DGRAM: {
-			ID cepid = new_id(udp_cepid_table, udp_cepid_table_count);
+			ID cepid = new_id(udp6_cepid_table, udp6_cepid_table_count);
 			if (cepid < 0)
 				return -ENOMEM;
 
-			T_UDP6_CCEP ccep = { 0, {ntohl(addr_in6->sin6_addr.__in6_union.__s6_addr), ntohs(addr_in6->sin6_port)}, (FP)socket_udp6_callback };
+			T_UDP6_CCEP ccep = { 0, { { ntohl(addr_in6->sin6_addr.__in6_union.__s6_addr) }, ntohs(addr_in6->sin6_port)}, (FP)socket_udp6_callback };
 			ret = udp6_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
-				delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
+				delete_id(udp6_cepid_table, udp6_cepid_table_count, cepid);
 				return -ENOMEM;
 			}
@@ -407,5 +486,5 @@
 
 		struct sockaddr_in6 *laddr = &socket->laddr6;
-		T_TCP6_CREP crep = { 0, {ntohl(laddr->sin6_addr.__in6_union.__s6_addr), ntohs(laddr->sin6_port)} };
+		T_TCP6_CREP crep = { 0, { { ntohl(laddr->sin6_addr.__in6_union.__s6_addr) }, ntohs(laddr->sin6_port)} };
 		ret = tcp6_cre_rep(repid, &crep);
 		if (ret != E_OK) {
@@ -423,5 +502,5 @@
 }
 
-int shell_connect(int fd, const struct sockaddr *addr, socklen_t len)
+int shell_connect(int fd, const struct sockaddr *addr, socklen_t alen)
 {
 	SOCKET *fp = fd_to_fp(fd);
@@ -435,5 +514,5 @@
 	switch (socket->family) {
 	case AF_INET: {
-		if (len < 8) {
+		if (alen < sizeof(struct sockaddr_in)) {
 			return -EINVAL;
 		}
@@ -455,14 +534,17 @@
 			}
 			fp->handle = cepid;
+			fp->writable = 1;
 			socket->cepid = cepid;
 		}
 		struct sockaddr_in *laddr = &socket->laddr4;
 		struct sockaddr_in *raddr = &socket->raddr4;
-		memset(raddr, 0, sizeof(*raddr));
-		memcpy(raddr, addr, len);
+		memcpy(raddr, addr, sizeof(struct sockaddr_in));
 		T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) };
 		T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
 		ret = tcp_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT);
-		if (ret < 0) {
+		if (ret == E_TMOUT) {
+			return -ETIMEDOUT;
+		}
+		else if (ret < 0) {
 			return -EHOSTUNREACH;
 		}
@@ -470,5 +552,5 @@
 	}
 	case AF_INET6: {
-		if (len < 20) {
+		if (alen < sizeof(struct sockaddr_in6)) {
 			return -EINVAL;
 		}
@@ -490,14 +572,21 @@
 			}
 			fp->handle = cepid;
+			fp->writable = 1;
 			socket->cepid = cepid;
 		}
 		struct sockaddr_in6 *laddr = &socket->laddr6;
 		struct sockaddr_in6 *raddr = &socket->raddr6;
-		memset(raddr, 0, sizeof(*raddr));
-		memcpy(raddr, addr, len);
-		T_IPV6EP lep = { ntohl(laddr->sin6_addr.__in6_union.__s6_addr), ntohs(laddr->sin6_port) };
-		T_IPV6EP rep = { ntohl(raddr->sin6_addr.__in6_union.__s6_addr), ntohs(raddr->sin6_port) };
+		memcpy(raddr, addr, sizeof(struct sockaddr_in6));
+		T_IPV6EP lep;
+		addrcpy(&lep.ipaddr, &laddr->sin6_addr, 16);
+		lep.portno = ntohs(laddr->sin6_port);
+		T_IPV6EP rep;
+		addrcpy(&rep.ipaddr, &raddr->sin6_addr, 16);
+		rep.portno = ntohs(raddr->sin6_port);
 		ret = tcp6_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT);
-		if (ret < 0) {
+		if (ret == E_TMOUT) {
+			return -ETIMEDOUT;
+		}
+		else if (ret < 0) {
 			return -EHOSTUNREACH;
 		}
@@ -508,8 +597,10 @@
 	}
 
+	if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++;
+
 	return 0;
 }
 
-int shell_accept(int fd, struct sockaddr *__restrict addr, socklen_t *__restrict len)
+int shell_accept(int fd, struct sockaddr *__restrict addr, socklen_t *__restrict alen)
 {
 	SOCKET *lfp = fd_to_fp(fd);
@@ -550,4 +641,5 @@
 			}
 			fp->handle = cepid;
+			fp->writable = 1;
 			socket->cepid = cepid;
 		}
@@ -555,4 +647,5 @@
 			cepid = ((socket_t *)lfp->exinf)->cepid;
 			fp->handle = cepid;
+			fp->writable = 1;
 			lfp->handle = tmax_tcp_cepid + ((socket_t *)lfp->exinf)->repid;
 			((socket_t *)lfp->exinf)->cepid = 0;
@@ -566,19 +659,19 @@
 		}
 		struct sockaddr_in *raddr = &socket->raddr4;
-		memset(raddr, 0, sizeof(*raddr));
+		memset(raddr, 0, sizeof(struct sockaddr_in));
 		raddr->sin_family = AF_INET;
 		raddr->sin_port = htons(rep.portno);
 		raddr->sin_addr.s_addr = htonl(rep.ipaddr);
 
-		if (addr != NULL && len != NULL) {
-			int sz = *len;
-			if (sz < 8) {
+		if (addr != NULL && alen != NULL) {
+			int sz = *alen;
+			if (sz < sizeof(struct sockaddr_in)) {
 				return -EINVAL;
 			}
 			struct sockaddr_in *raddr = &socket->raddr4;
-			if (sz > sizeof(*raddr))
-				sz = sizeof(*raddr);
+			if (sz > sizeof(struct sockaddr_in))
+				sz = sizeof(struct sockaddr_in);
 			memcpy(addr, raddr, sz);
-			*len = sizeof(*raddr);
+			*alen = sz;
 		}
 		break;
@@ -603,4 +696,5 @@
 			}
 			fp->handle = cepid;
+			fp->writable = 1;
 			socket->cepid = cepid;
 		}
@@ -608,4 +702,5 @@
 			cepid = ((socket_t *)lfp->exinf)->cepid;
 			fp->handle = cepid;
+			fp->writable = 1;
 			lfp->handle = tmax_tcp6_cepid + ((socket_t *)lfp->exinf)->repid;
 			((socket_t *)lfp->exinf)->cepid = 0;
@@ -613,5 +708,5 @@
 			((socket_t *)lfp->exinf)->buf = 0;
 		}
-		T_IPV6EP rep = { 0, 0 };
+		T_IPV6EP rep = { { 0 }, 0 };
 		ret = tcp6_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR);
 		if (ret < 0) {
@@ -619,24 +714,19 @@
 		}
 		struct sockaddr_in6 *raddr = &socket->raddr6;
-		memset(raddr, 0, sizeof(*raddr));
+		memset(raddr, 0, sizeof(struct sockaddr_in6));
 		raddr->sin6_family = AF_INET;
 		raddr->sin6_port = htons(rep.portno);
-#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
-		memcpy(raddr->sin6_addr.__in6_union.__s6_addr, rep.ipaddr.__u6_addr.__u6_addr8, 16);
-#else
-		for (int i = 0; i < 16; i++)
-			raddr->sin6_addr.__in6_union.__s6_addr[i] = rep.ipaddr.__u6_addr.__u6_addr8[i];
-#endif
-
-		if (addr != NULL && len != NULL) {
-			int sz = *len;
-			if (sz < 8) {
+		addrcpy(&raddr->sin6_addr, &rep.ipaddr, 16);
+
+		if (addr != NULL && alen != NULL) {
+			int sz = *alen;
+			if (sz < sizeof(struct sockaddr_in6)) {
 				return -EINVAL;
 			}
 			struct sockaddr_in6 *raddr = &socket->raddr6;
-			if (sz > sizeof(*raddr))
-				sz = sizeof(*raddr);
+			if (sz > sizeof(struct sockaddr_in6))
+				sz = sizeof(struct sockaddr_in6);
 			memcpy(addr, raddr, sz);
-			*len = sizeof(*raddr);
+			*alen = sz;
 		}
 		break;
@@ -645,4 +735,6 @@
 		return -ENOPROTOOPT;
 	}
+
+	if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++;
 
 	return fp->fd;
@@ -673,10 +765,9 @@
 			}
 			else {
+				int temp = len;
 				for (;;) {
 					ret = tcp_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
 					if (ret < 0) {
-						if (ret == E_TMOUT)
-							return -ETIME;
-						return -ECOMM;
+						return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
 					}
 					len -= ret;
@@ -685,20 +776,19 @@
 					buf = (const void *)&((uint8_t *)buf)[ret];
 				} 
+				ret = temp;
 			}
 			break;
 		}
 		case SOCK_DGRAM: {
-			int sz = alen;
-			if ((addr == NULL) || (sz < 8)) {
+			if ((addr == NULL) || (alen < sizeof(struct sockaddr_in))) {
 				return -EINVAL;
 			}
 			struct sockaddr_in *raddr = &socket->raddr4;
-			memset(raddr, 0, sizeof(*raddr));
-			memcpy(raddr, addr, sz);
+			memcpy(raddr, addr, sizeof(struct sockaddr_in));
 			T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
 			ret = udp_snd_dat(socket->cepid, &rep, (void *)buf, len,
 				(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
 			if (ret < 0) {
-				return (ret == E_TMOUT) ? -ETIME : -ECOMM;
+				return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
 			}
 			break;
@@ -721,10 +811,9 @@
 			}
 			else {
+				int temp = len;
 				for (;;) {
 					ret = tcp6_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
 					if (ret < 0) {
-						if (ret == E_TMOUT)
-							return -ETIME;
-						return -ECOMM;
+						return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
 					}
 					len -= ret;
@@ -732,21 +821,22 @@
 						break;
 					buf = (const void *)&((uint8_t *)buf)[ret];
-				} 
+				}
+				ret = temp;
 			}
 			break;
 		}
 		case SOCK_DGRAM: {
-			int sz = alen;
-			if ((addr == NULL) || (sz < 8)) {
+			if ((addr == NULL) || (alen < sizeof(struct sockaddr_in6))) {
 				return -EINVAL;
 			}
 			struct sockaddr_in6 *raddr = &socket->raddr6;
-			memset(raddr, 0, sizeof(*raddr));
-			memcpy(raddr, addr, sz);
-			T_IPV6EP rep = { ntohl(raddr->sin6_addr.__in6_union.__s6_addr), ntohs(raddr->sin6_port) };
+			memcpy(raddr, addr, sizeof(struct sockaddr_in6));
+			T_IPV6EP rep;
+			addrcpy(&rep.ipaddr, &raddr->sin6_addr, 16);
+			rep.portno = ntohs(raddr->sin6_port);
 			ret = udp6_snd_dat(socket->cepid, &rep, (void *)buf, len,
 				(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
 			if (ret < 0) {
-				return (ret == E_TMOUT) ? -ETIME : -ECOMM;
+				return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
 			}
 			break;
@@ -758,4 +848,6 @@
 		return -ENOPROTOOPT;
 	}
+
+	if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++;
 
 	return ret;
@@ -800,8 +892,10 @@
 						syslog(LOG_ERROR, "sig_sem => %d", ret);
 					}
-					ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_FEVR);
+					ret = tcp_rcv_buf(socket->cepid, &socket->input,
+						(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
 					if (ret < 0) {
-						syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
-						return -ECOMM;
+						if ((socket->flags & O_NONBLOCK) == 0)
+							syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
+						return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
 					}
 					rsz = ret;
@@ -858,5 +952,5 @@
 					if ((socket->flags & O_NONBLOCK) == 0)
 						syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
-					return (ret == E_TMOUT) ? -ETIME : -ECOMM;
+					return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
 				}
 				rsz = ret;
@@ -867,10 +961,10 @@
 					}
 					int sz = *alen;
-					memset(raddr, 0, sizeof(socket->raddr4));
+					memset(raddr, 0, sizeof(struct sockaddr_in));
 					raddr->sin_family = AF_INET;
 					raddr->sin_port = htons(rep.portno);
 					raddr->sin_addr.s_addr = htonl(rep.ipaddr);
-					if (sz > sizeof(socket->raddr4))
-						sz = sizeof(socket->raddr4);
+					if (sz > sizeof(struct sockaddr_in))
+						sz = sizeof(struct sockaddr_in);
 					memcpy(addr, raddr, sz);
 					*alen = sz;
@@ -889,6 +983,6 @@
 				if ((addr != NULL) && (alen != NULL)) {
 					int sz = *alen;
-					if (sz > sizeof(socket->raddr4))
-						sz = sizeof(socket->raddr4);
+					if (sz > sizeof(struct sockaddr_in))
+						sz = sizeof(struct sockaddr_in);
 					memcpy(addr, raddr, sz);
 					*alen = sz;
@@ -934,8 +1028,10 @@
 						syslog(LOG_ERROR, "sig_sem => %d", ret);
 					}
-					ret = tcp6_rcv_buf(socket->cepid, &socket->input, TMO_FEVR);
+					ret = tcp6_rcv_buf(socket->cepid, &socket->input,
+						(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
 					if (ret < 0) {
-						syslog(LOG_ERROR, "tcp6_rcv_buf => %d", ret);
-						return -ECOMM;
+						if ((socket->flags & O_NONBLOCK) == 0)
+							syslog(LOG_ERROR, "tcp6_rcv_buf => %d", ret);
+						return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
 					}
 					rsz = ret;
@@ -986,5 +1082,5 @@
 				}
 
-				T_IPV6EP rep = { 0, 0 };
+				T_IPV6EP rep = { { 0 }, 0 };
 				ret = udp6_rcv_dat(socket->cepid, &rep, buf, len,
 					(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
@@ -992,5 +1088,5 @@
 					if ((socket->flags & O_NONBLOCK) == 0)
 						syslog(LOG_ERROR, "udp6_rcv_buf => %d", ret);
-					return (ret == E_TMOUT) ? -ETIME : -ECOMM;
+					return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
 				}
 				rsz = ret;
@@ -1001,15 +1097,10 @@
 					}
 					int sz = *alen;
-					memset(raddr, 0, sizeof(socket->raddr6));
+					memset(raddr, 0, sizeof(struct sockaddr_in6));
 					raddr->sin6_family = AF_INET;
 					raddr->sin6_port = htons(rep.portno);
-#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
-					memcpy(raddr->sin6_addr.__in6_union.__s6_addr, rep.ipaddr.__u6_addr.__u6_addr8, 16);
-#else
-					for (int i = 0; i < 16; i++)
-						raddr->sin6_addr.__in6_union.__s6_addr[i] = rep.ipaddr.__u6_addr.__u6_addr8[i];
-#endif
-					if (sz > sizeof(socket->raddr6))
-						sz = sizeof(socket->raddr6);
+					addrcpy(&raddr->sin6_addr, &rep.ipaddr, 16);
+					if (sz > sizeof(struct sockaddr_in6))
+						sz = sizeof(struct sockaddr_in6);
 					memcpy(addr, raddr, sz);
 					*alen = sz;
@@ -1028,6 +1119,6 @@
 				if ((addr != NULL) && (alen != NULL)) {
 					int sz = *alen;
-					if (sz > sizeof(socket->raddr6))
-						sz = sizeof(socket->raddr6);
+					if (sz > sizeof(struct sockaddr_in6))
+						sz = sizeof(struct sockaddr_in6);
 					memcpy(addr, raddr, sz);
 					*alen = sz;
@@ -1054,4 +1145,6 @@
 		return -ENOPROTOOPT;
 	}
+
+	if (fp->readevt_w != fp->readevt_r) fp->readevt_r++;
 
 	return ret;
@@ -1427,10 +1520,5 @@
 		struct sockaddr_in6 laddr;
 		laddr.sin6_family = AF_INET;
-#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
-		memcpy(laddr.sin6_addr.__in6_union.__s6_addr, laddr6->__u6_addr.__u6_addr8, 16);
-#else
-		for (int i = 0; i < 16; i++)
-			laddr.sin6_addr.__in6_union.__s6_addr[i] = laddr6->__u6_addr.__u6_addr8[i];
-#endif
+		addrcpy(&laddr.sin6_addr, laddr6, 16);
 		laddr.sin6_port = socket->laddr6.sin6_port;
 		*len = sizeof(struct sockaddr_in6);
@@ -1465,5 +1553,5 @@
 			delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
 			if ((ret < 0) || (ret2 < 0)) {
-				return (ret == E_TMOUT) ? -ETIME : -EINVAL;
+				return (ret == E_TMOUT) ? -ETIMEDOUT : -EIO;
 			}
 		}
@@ -1494,5 +1582,5 @@
 			delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid);
 			if ((ret < 0) || (ret2 < 0)) {
-				return (ret == E_TMOUT) ? -ETIME : -EINVAL;
+				return (ret == E_TMOUT) ? -ETIMEDOUT : -EIO;
 			}
 		}
@@ -1535,4 +1623,14 @@
 int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
+	socket_t *socket = (socket_t *)fp->exinf;
+
+	switch (req) {
+	case F_GETFL:
+		return socket->flags;
+	case F_SETFL:
+		socket->flags = (unsigned int)arg;
+		return 0;
+	}
+
 	return -EINVAL;
 }
@@ -1571,4 +1669,11 @@
 }
 
+bool_t tcp_fd_writable(struct SHELL_FILE *fp)
+{
+	//socket_t *socket = (socket_t *)fp->exinf;
+
+	return /*fp->writable &&*/ (fp->writeevt_w == fp->writeevt_r);
+}
+
 void tcp_fd_delete(struct SHELL_FILE *fp)
 {
@@ -1590,4 +1695,5 @@
 		return E_PAR;
 
+	socket_t *socket = (socket_t *)fp->exinf;
 	int fd = fp->fd;
 	FD_SET(fd, (fd_set *)&flgptn);
@@ -1603,5 +1709,4 @@
 			syslog(LOG_ERROR, "wai_sem => %d", ret);
 		}
-		socket_t *socket = (socket_t *)fp->exinf;
 		socket->len += len;
 		ret = sig_sem(SEM_FILEDESC);
@@ -1670,4 +1775,5 @@
 		return E_PAR;
 
+	socket_t *socket = (socket_t *)fp->exinf;
 	int fd = fp->fd;
 	FD_SET(fd, (fd_set *)&flgptn);
@@ -1683,5 +1789,4 @@
 			syslog(LOG_ERROR, "wai_sem => %d", ret);
 		}
-		socket_t *socket = (socket_t *)fp->exinf;
 		socket->len += len;
 		ret = sig_sem(SEM_FILEDESC);
@@ -1806,4 +1911,11 @@
 }
 
+bool_t udp_fd_writable(struct SHELL_FILE *fp)
+{
+	//socket_t *socket = (socket_t *)fp->exinf;
+
+	return fp->writable && (fp->writeevt_w == fp->writeevt_r);
+}
+
 void udp_fd_delete(struct SHELL_FILE *fp)
 {
@@ -1849,5 +1961,5 @@
 		socket->input = udppara->input;
 		socket->buf = GET_UDP_SDU(udppara->input, udppara->off);
-		memset(&socket->raddr4, 0, sizeof(socket->raddr4));
+		memset(&socket->raddr4, 0, sizeof(struct sockaddr_in));
 		socket->raddr4.sin_family = AF_INET;
 		socket->raddr4.sin_port = htons(udppara->rep4.portno);
@@ -1932,13 +2044,8 @@
 		socket->input = udppara->input;
 		socket->buf = GET_UDP_SDU(udppara->input, udppara->off);
-		memset(&socket->raddr6, 0, sizeof(socket->raddr6));
+		memset(&socket->raddr6, 0, sizeof(struct sockaddr_in6));
 		socket->raddr6.sin6_family = AF_INET;
 		socket->raddr6.sin6_port = htons(udppara->rep6.portno);
-#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
-		memcpy(socket->raddr6.sin6_addr.__in6_union.__s6_addr, udppara->rep6.ipaddr.__u6_addr.__u6_addr8, 16);
-#else
-		for (int i = 0; i < 16; i++)
-			socket->raddr6.sin6_addr.__in6_union.__s6_addr[i] = udppara->rep6.ipaddr.__u6_addr.__u6_addr8[i];
-#endif
+		addrcpy(&socket->raddr6.sin6_addr, &udppara->rep6.ipaddr, 16);
 		udppara->input->flags |= NB_FLG_NOREL_IFOUT;
 		ret = sig_sem(SEM_FILEDESC);
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/socket_stub.h	(revision 380)
+++ 	(revision )
@@ -1,154 +1,0 @@
-/*
- *  TOPPERS ECHONET Lite Communication Middleware
- * 
- *  Copyright (C) 2017 Cores Co., Ltd. Japan
- * 
- *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
- *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
- *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
- *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
- *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
- *      スコード中に含まれていること．
- *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
- *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
- *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
- *      の無保証規定を掲載すること．
- *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
- *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
- *      と．
- *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
- *        作権表示，この利用条件および下記の無保証規定を掲載すること．
- *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
- *        報告すること．
- *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
- *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
- *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
- *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
- *      免責すること．
- * 
- *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
- *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
- *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
- *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
- *  の責任を負わない．
- * 
- *  @(#) $Id$
- */
-#ifndef SOCKET_STUB_H
-#define SOCKET_STUB_H
-
-struct addrinfo {
-	int ai_flags;
-	int ai_family;
-	int ai_socktype;
-	int ai_protocol;
-	socklen_t ai_addrlen;
-	struct sockaddr *ai_addr;
-	char *ai_canonname;
-	struct addrinfo *ai_next;
-};
-
-typedef uint16_t in_port_t;
-typedef uint32_t in_addr_t;
-struct in_addr { in_addr_t s_addr; };
-
-struct sockaddr_in {
-	sa_family_t sin_family;
-	in_port_t sin_port;
-	struct in_addr sin_addr;
-	uint8_t sin_zero[8];
-};
-
-struct in6_addr
-{
-	union {
-		uint8_t __s6_addr[16];
-		uint16_t __s6_addr16[8];
-		uint32_t __s6_addr32[4];
-	} __in6_union;
-};
-//#define s6_addr __in6_union.__s6_addr
-//#define s6_addr16 __in6_union.__s6_addr16
-//#define s6_addr32 __in6_union.__s6_addr32
-
-struct sockaddr_in6
-{
-	sa_family_t     sin6_family;
-	in_port_t       sin6_port;
-	uint32_t        sin6_flowinfo;
-	struct in6_addr sin6_addr;
-	uint32_t        sin6_scope_id;
-};
-
-typedef struct socket_t {
-	int family;
-	int type;
-	int protocol;
-	int cepid;
-	int repid;
-	int backlog;
-	unsigned int flags;
-	union {
-		struct sockaddr_in laddr4;
-		struct sockaddr_in6 laddr6;
-	};
-	union {
-		struct sockaddr_in raddr4;
-		struct sockaddr_in6 raddr6;
-	};
-	int buf_size;
-	unsigned char *buf;
-	void *input;
-	int len;
-} socket_t;
-
-struct SHELL_DIR {
-	FATFS_DIR dir;
-	struct dirent dirent;
-};
-
-typedef const struct io_type_s IO_TYPE;
-
-struct SHELL_FILE {
-	int fd;
-	IO_TYPE *type;
-	int handle;
-	int readevt_r;
-	int readevt_w;
-	int writeevt_r;
-	int writeevt_w;
-	int writable;
-	int errorevt_r;
-	int errorevt_w;
-	void *exinf;
-};
-
-struct io_type_s {
-	int (*close)(struct SHELL_FILE *);
-	size_t (*read)(struct SHELL_FILE *, unsigned char *, size_t);
-	size_t (*write)(struct SHELL_FILE *, const unsigned char *, size_t);
-	off_t (*seek)(struct SHELL_FILE *, off_t, int);
-	int (*ioctl)(struct SHELL_FILE *, int, void *);
-	bool_t (*readable)(struct SHELL_FILE *);
-	void (*delete)(struct SHELL_FILE *);
-};
-
-#ifndef bool
-#define bool int
-#endif
-#ifndef true
-#define true 1
-#endif
-#ifndef false
-#define false 0
-#endif
-
-struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable);
-int delete_fd_by_id(IO_TYPE *type, int id);
-struct SHELL_FILE *fd_to_fp(int fd);
-struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id);
-
-int delete_fp(struct SHELL_FILE *fp);
-void clean_fd();
-
-#endif // !SOCKET_STUB_H
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/stdio_stub.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/stdio_stub.c	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/stdio_stub.c	(revision 387)
@@ -0,0 +1,631 @@
+/*
+ *  TOPPERS ECHONET Lite Communication Middleware
+ * 
+ *  Copyright (C) 2017-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+#include "shellif.h"
+#include <stdint.h>
+#include <kernel.h>
+#include <t_syslog.h>
+#include <t_stdlib.h>
+#include <sil.h>
+#include "syssvc/serial.h"
+#include "syssvc/syslog.h"
+#include "target_syssvc.h"
+#ifdef TOPPERS_OMIT_TECS
+#include "target_serial.h"
+#endif // TOPPERS_OMIT_TECS
+#include "fdtable.h"
+#include "kernel_cfg.h"
+#include <string.h>
+#include <errno.h>
+#include "util/ntstdio.h"
+#include "hal/serial_api.h"
+#include "target_rename.h"
+#include "target_kernel_impl.h"
+#include "syssvc/siofd.h"
+
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
+
+static unsigned char stdio_xi(struct ntstdio_t *handle);
+static void stdio_xo(struct ntstdio_t *handle, unsigned char c);
+static void stdio_serial_irq_handler(uint32_t id, SerialIrq event);
+
+static int stdio_close(struct SHELL_FILE *fp);
+static size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static void stdio_delete(struct SHELL_FILE *fp);
+
+static unsigned char sio_xi(struct ntstdio_t *handle);
+static void sio_xo(struct ntstdio_t *handle, unsigned char c);
+static void sio_serial_irq_handler(uint32_t id, SerialIrq event);
+
+static int sio_close(struct SHELL_FILE *fp);
+static size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int sio_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t sio_readable(struct SHELL_FILE *fp);
+static bool_t sio_writable(struct SHELL_FILE *fp);
+static void sio_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_STDIN = { stdio_close, sio_read, stdio_write, sio_seek, sio_ioctl, sio_readable, sio_writable, stdio_delete };
+IO_TYPE IO_TYPE_STDOUT = { stdio_close, stdio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_writable, stdio_delete };
+IO_TYPE IO_TYPE_STDERR = { stdio_close, stdio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_writable, stdio_delete };
+IO_TYPE IO_TYPE_SIO = { sio_close, sio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_writable, sio_delete };
+
+#define STDIO_UART_BUF_SZ 256
+
+typedef struct stdio_sio_t {
+	serial_t serial;
+	ntstdio_t ntstdio;
+	struct SHELL_FILE *fp;
+	unsigned char tx_buf[STDIO_UART_BUF_SZ];
+	int tx_pos_w;
+	int tx_pos_r;
+	unsigned char rx_buf[STDIO_UART_BUF_SZ];
+	int rx_pos_w;
+	int rx_pos_r;
+} stdio_sio_t;
+
+stdio_sio_t stdio_sio;
+
+void sys_init(intptr_t exinf)
+{
+	serial_t *serial = &stdio_sio.serial;
+	ntstdio_t *ntstdio = &stdio_sio.ntstdio;
+
+	serial_init(serial, STDIO_UART_TX, STDIO_UART_RX);
+	serial_baud(serial, UART_BAUDRATE);
+	serial_format(serial, 8, ParityNone, 1);
+
+	ntstdio_init(ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, stdio_xi, stdio_xo);
+	ntstdio->exinf = (void *)&stdio_sio;
+
+	struct SHELL_FILE *fp;
+
+	fp = fd_to_fp(STDIN_FILENO);
+	fp->handle = SIO_PORTID;
+	fp->exinf = (void *)ntstdio;
+
+	fp = fd_to_fp(STDOUT_FILENO);
+	fp->handle = SIO_PORTID;
+	fp->exinf = (void *)ntstdio;
+
+	fp = fd_to_fp(STDERR_FILENO);
+	fp->handle = SIO_PORTID;
+	fp->exinf = (void *)ntstdio;
+
+	serial_irq_handler(&stdio_sio.serial, stdio_serial_irq_handler, 0);
+
+	serial_irq_set(serial, RxIrq, true);
+}
+
+ID serial_portid;
+
+void stdio_open(ID portid)
+{
+	struct SHELL_FILE *fp;
+
+	serial_portid = portid;
+	serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
+
+	fp = fd_to_fp(STDIN_FILENO);
+	fp->handle = portid;
+
+	fp = fd_to_fp(STDOUT_FILENO);
+	fp->handle = portid;
+
+	fp = fd_to_fp(STDERR_FILENO);
+	fp->handle = portid;
+}
+
+int stdio_close(struct SHELL_FILE *fp)
+{
+	return -EPERM;
+}
+
+size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+void stdio_delete(struct SHELL_FILE *fp)
+{
+}
+
+int sio_close(struct SHELL_FILE *fp)
+{
+	return -EPERM;
+}
+
+size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	int i = 0;
+	while (i < len) {
+		int c = ntstdio_getc((struct ntstdio_t *)fp->exinf);
+		data[i++] = c;
+		if ((c == EOF) || (c == '\n'))
+			break;
+	}
+	return i;
+}
+
+size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	for (int i = 0; i < len; i++) {
+		ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
+	}
+	return len;
+}
+
+off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org)
+{
+	return -EPERM;
+}
+
+int sio_tcgetattr(struct SHELL_FILE *fp, struct termios *termios)
+{
+	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
+
+	memset(termios, 0, sizeof(*termios));
+
+	if (ntstdio->option & NTSTDIO_OPTION_LINE_ECHO) {
+		termios->c_lflag |= ECHO;
+	}
+	else {
+		termios->c_lflag &= ~ECHO;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_CANON) {
+		termios->c_lflag |= ICANON;
+	}
+	else {
+		termios->c_lflag &= ~ICANON;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_LF_CR) {
+		termios->c_iflag |= INLCR;
+	}
+	else {
+		termios->c_iflag &= ~INLCR;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_LF_CRLF) {
+		termios->c_oflag |= ONLCR;
+	}
+	else {
+		termios->c_oflag &= ~ONLCR;
+	}
+
+	return 0;
+}
+
+int sio_tcsetattr(struct SHELL_FILE *fp, int optional_actions, const struct termios *termios)
+{
+	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
+
+	if (optional_actions == TCSANOW) {
+		if (termios->c_lflag & ECHO) {
+			ntstdio->option |= NTSTDIO_OPTION_LINE_ECHO;
+		}
+		else {
+			ntstdio->option &= ~NTSTDIO_OPTION_LINE_ECHO;
+		}
+		if (termios->c_lflag & ICANON) {
+			ntstdio->option |= NTSTDIO_OPTION_CANON;
+		}
+		else {
+			ntstdio->option &= ~NTSTDIO_OPTION_CANON;
+		}
+		if (termios->c_iflag & INLCR) {
+			ntstdio->option |= NTSTDIO_OPTION_LF_CR;
+		}
+		else {
+			ntstdio->option &= ~NTSTDIO_OPTION_LF_CR;
+		}
+		if (termios->c_oflag & ONLCR) {
+			ntstdio->option |= NTSTDIO_OPTION_LF_CRLF;
+		}
+		else {
+			ntstdio->option &= ~NTSTDIO_OPTION_LF_CRLF;
+		}
+		return 0;
+	}
+
+	//shell_abort();
+	return 0;
+}
+
+int sio_ioctl(struct SHELL_FILE *fp, int request, void *arg)
+{
+	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))
+		return -EBADF;
+
+	switch (request) {
+	case TIOCGWINSZ:
+		return 0;
+	case TCGETS:
+		return sio_tcgetattr(fp, (struct termios *)arg);
+	case TCSETS + TCSANOW:
+	case TCSETS + TCSADRAIN:
+	case TCSETS + TCSAFLUSH:
+		return sio_tcsetattr(fp, request - TCSETS, (const struct termios *)arg);
+	}
+
+	return -EINVAL;
+}
+
+bool_t sio_readable(struct SHELL_FILE *fp)
+{
+	return fp->readevt_w != fp->readevt_r;
+}
+
+bool_t sio_writable(struct SHELL_FILE *fp)
+{
+	return fp->writable && (fp->writeevt_w == fp->writeevt_r);
+}
+
+void sio_delete(struct SHELL_FILE *fp)
+{
+	free((stdio_sio_t *)((struct ntstdio_t *)fp->exinf)->exinf);
+	((struct ntstdio_t *)fp->exinf)->exinf = NULL;
+	free((struct ntstdio_t *)fp->exinf);
+	fp->exinf = NULL;
+}
+
+static unsigned char ntstdio_xi(struct ntstdio_t *handle, struct SHELL_FILE *fp)
+{
+	stdio_sio_t *uart = (stdio_sio_t *)handle->exinf;
+	ER ret;
+	unsigned char c;
+
+	bool_t lock = sense_lock();
+	if (lock)
+		unl_cpu();
+
+	while (uart->rx_pos_w == uart->rx_pos_r) {
+		FLGPTN flgptn = 0, waitptn = 0;
+		FD_SET(fp->fd, (fd_set *)&waitptn);
+
+		ret = wai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn);
+		if (ret != E_OK) {
+			if (lock)
+				loc_cpu();
+			syslog(LOG_ERROR, "wai_flg => %d", ret);
+			return 0;
+		}
+
+		ret = clr_flg(FLG_SELECT_WAIT, ~(flgptn & waitptn));
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "clr_flg => %d", ret);
+		}
+	}
+
+	if (lock)
+		unl_cpu();
+
+	if (fp->readevt_w != fp->readevt_r) fp->readevt_r++;
+
+	c = uart->rx_buf[uart->rx_pos_r++];
+	if (uart->rx_pos_r >= sizeof(uart->rx_buf))
+		uart->rx_pos_r = 0;
+
+	return c;
+}
+
+extern volatile int ntshell_state;
+extern ID serial_portid;
+
+static void serial_rx_irq_handler(int fd)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	stdio_sio_t *uart = (stdio_sio_t *)((struct ntstdio_t *)fp->exinf)->exinf;
+	serial_t *serial = (serial_t *)&uart->serial;
+
+	if (serial_readable(serial)) {
+		unsigned char c = (unsigned char)serial_getc(serial);
+
+		if (ntshell_state == 1) {
+			ER ret;
+			FLGPTN flgptn = 0;
+
+			uart->rx_buf[uart->rx_pos_w++] = c;
+			if (uart->rx_pos_w >= sizeof(uart->rx_buf))
+				uart->rx_pos_w = 0;
+
+			if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+			FD_SET(fd, (fd_set *)&flgptn);
+
+			ret = set_flg(FLG_SELECT_WAIT, flgptn);
+			if (ret != E_OK) {
+				syslog(LOG_ERROR, "set_flg => %d", ret);
+			}
+		}
+		else
+			sio_isr_rcv(fp->handle, c);
+	}
+}
+
+static void ntstdio_xo(struct ntstdio_t *handle, struct SHELL_FILE *fp, unsigned char c)
+{
+	stdio_sio_t *uart = (stdio_sio_t *)handle->exinf;
+	serial_t *serial = (serial_t *)&uart->serial;
+	ER ret;
+
+	// タスクコンテキストでない場合
+	if (sense_context()) {
+		// 送信可能になるまで待ち
+		while (!serial_writable(serial));
+		// 送信する
+		serial_putc(serial, c);
+		return;
+	}
+
+	// 送信バッファが空で
+	if (uart->tx_pos_w == uart->tx_pos_r) {
+		// 送信可能なら
+		if (serial_writable(serial)) {
+			// 送信する
+			serial_putc(serial, c);
+			return;
+		}
+	}
+
+	// 送信バッファに追加する
+	uart->tx_buf[uart->tx_pos_w++] = c;
+	if (uart->tx_pos_w >= sizeof(uart->tx_buf))
+		uart->tx_pos_w = 0;
+
+	// 送信可能になったら割り込みをもらうよう設定
+	serial_irq_set(serial, TxIrq, true);
+
+	bool_t lock = sense_lock();
+	if (lock)
+		unl_cpu();
+
+	do {
+		FLGPTN flgptn = 0, waitptn = 0;
+		FD_SET(fp->fd, (fd_set *)&waitptn);
+
+		ret = wai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn);
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "wai_flg => %d", ret);
+			break;
+		}
+
+		ret = clr_flg(FLG_SELECT_WAIT, ~(flgptn & waitptn));
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "clr_flg => %d", ret);
+		}
+	} while (fp->writeevt_w == fp->writeevt_r);
+
+	fp->writeevt_r++;
+
+	if (lock)
+		loc_cpu();
+}
+
+static void serial_tx_irq_handler(int fd)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	stdio_sio_t *uart = (stdio_sio_t *)((struct ntstdio_t *)fp->exinf)->exinf;
+	serial_t *serial = (serial_t *)&uart->serial;
+	ER ret;
+	unsigned char c;
+
+	if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+	FLGPTN flgptn = 0;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	ret = set_flg(FLG_SELECT_WAIT, flgptn);
+	if (ret != E_OK) {
+		syslog(LOG_ERROR, "set_flg => %d", ret);
+	}
+
+	// 送信バッファが空なら
+	if (uart->tx_pos_w == uart->tx_pos_r) {
+		// SIOドライバの送信
+		sio_isr_snd(fp->handle);
+		// やっぱり送信バッファが空なら
+		if (uart->tx_pos_w == uart->tx_pos_r) {
+			// 送信割り込み停止
+			serial_irq_set(serial, TxIrq, false);
+			return;
+		}
+	}
+
+	c = uart->tx_buf[uart->tx_pos_r++];
+	if (uart->tx_pos_r >= sizeof(uart->tx_buf))
+		uart->tx_pos_r = 0;
+
+	// 送信する
+	serial_putc(serial, c);
+}
+
+void stdio_serial_irq_handler(uint32_t id, SerialIrq event)
+{
+	switch (event) {
+	case RxIrq:
+		serial_rx_irq_handler(STDIN_FILENO);
+		break;
+	case TxIrq:
+		serial_tx_irq_handler(STDOUT_FILENO);
+		break;
+	}
+}
+
+void sio_serial_irq_handler(uint32_t id, SerialIrq event)
+{
+	struct SHELL_FILE *fp = fd_to_fp(id);
+	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))
+		return;
+
+	switch (event) {
+	case RxIrq:
+		serial_rx_irq_handler(id);
+		break;
+	case TxIrq:
+		serial_tx_irq_handler(id);
+		break;
+	}
+}
+
+unsigned char stdio_xi(struct ntstdio_t *handle)
+{
+	return ntstdio_xi(handle, fd_to_fp(STDIN_FILENO));
+}
+
+void stdio_xo(struct ntstdio_t *handle, unsigned char c)
+{
+	ntstdio_xo(handle, fd_to_fp(STDOUT_FILENO), c);
+}
+
+unsigned char sio_xi(struct ntstdio_t *handle)
+{
+	return ntstdio_xi(handle, ((stdio_sio_t *)handle->exinf)->fp);
+}
+
+void sio_xo(struct ntstdio_t *handle, unsigned char c)
+{
+	ntstdio_xo(handle, ((stdio_sio_t *)handle->exinf)->fp, c);
+}
+
+int siofd_open(const char *path, int flags, ...)
+{
+	return -1;
+}
+
+int siofd_close(int fd)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO)) {
+		errno = EBADF;
+		return -1;
+	}
+
+	errno = sio_close(fp);
+	if (errno != 0)
+		return 1;
+	return 0;
+}
+
+ssize_t siofd_read(int fd, void *data, size_t len)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_SIO))) {
+		errno = EBADF;
+		return -1;
+	}
+	char *pos, *end;
+
+	for (pos = (char *)data, end = &pos[len]; pos < end; pos++) {
+		*pos = ntstdio_xi((struct ntstdio_t *)fp->exinf, fp);
+	}
+
+	return pos - (char *)data;
+}
+
+ssize_t siofd_write(int fd, const void *data, size_t len)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDOUT) && (fp->type != &IO_TYPE_STDERR)
+		&& (fp->type != &IO_TYPE_SIO))) {
+		errno = EBADF;
+		return -1;
+	}
+	const char *pos, *end;
+
+	for (pos = (const char *)data, end = &pos[len]; pos < end; pos++) {
+		ntstdio_xo((struct ntstdio_t *)fp->exinf, fp, *pos);
+	}
+
+	return pos - (char *)data;
+}
+
+int siofd_tcsetattr(int fd, int act, const struct termios *tio)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_STDOUT)
+		&& (fp->type != &IO_TYPE_STDERR) && (fp->type != &IO_TYPE_SIO))) {
+		errno = EBADF;
+		return -1;
+	}
+
+	errno = sio_tcsetattr(fp, act, tio);
+	if (errno != 0)
+		return 1;
+	return 0;
+}
+
+int siofd_tcgetattr(int fd, struct termios *tio)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_STDOUT)
+		&& (fp->type != &IO_TYPE_STDERR) && (fp->type != &IO_TYPE_SIO))) {
+		errno = EBADF;
+		return -1;
+	}
+
+	errno = sio_tcgetattr(fp, tio);
+	if (errno != 0)
+		return 1;
+	return 0;
+}
+
+int siofd_fcntl(int fd, int cmd, ...)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_STDOUT)
+		&& (fp->type != &IO_TYPE_STDERR) && (fp->type != &IO_TYPE_SIO))) {
+		errno = EBADF;
+		return -1;
+	}
+	void *arg;
+	va_list ap;
+	va_start(ap, cmd);
+	arg = va_arg(ap, void *);
+	va_end(ap);
+
+	errno = sio_ioctl(fp, cmd, arg);
+	if (errno != 0)
+		return 1;
+	return 0;
+}
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c	(revision 380)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/syscall.c	(revision 387)
@@ -336,6 +336,6 @@
 }
 
-long SYS_rt_sigaction(long a, long b, long c) {
-	return shell_sigaction((int)a, (const struct sigaction *)b, (struct sigaction *)c);
+long SYS_rt_sigaction(long a, long b, long c, long d) {
+	return shell_sigaction((int)a, (const struct k_sigaction *)b, (struct k_sigaction *)c, (size_t)d);
 }
 
@@ -429,4 +429,9 @@
 }
 
+long SYS_nanosleep(long a, long b)
+{
+	return shell_nanosleep((const struct timespec *)a, (struct timespec *)b);
+}
+
 long SYS_dup(long a) {
 	//int dup(int fd)
@@ -532,9 +537,4 @@
 {
 	return no_implement("tgkill\n");
-}
-
-long SYS_nanosleep(long a, long b) {
-	//int nanosleep(const struct timespec *req, struct timespec *rem)
-	return no_implement("nanosleep\n");
 }
 
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/tSIOPortNTShell.cdl
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/tSIOPortNTShell.cdl	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/tSIOPortNTShell.cdl	(revision 387)
@@ -0,0 +1,119 @@
+/*
+ *  TOPPERS/ASP Kernel
+ *      Toyohashi Open Platform for Embedded Real-Time Systems/
+ *      Advanced Standard Profile Kernel
+ * 
+ *  Copyright (C) 2015 by Ushio Laboratory
+ *              Graduate School of Engineering Science, Osaka Univ., JAPAN
+ *  Copyright (C) 2015,2016 by Embedded and Real-Time Systems Laboratory
+ *              Graduate School of Information Science, Nagoya Univ., JAPAN
+ * 
+ *  上記著作権者は，以下の(1)〜(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  $Id$
+ */
+
+/*
+ *		シリアルインタフェースドライバのターゲット依存部（NTShell用）
+ *		のコンポーネント記述
+ */
+
+/*
+ *  NTShell に関する定義
+ */
+import_C("termios.h");
+
+/*
+ *  SIOドライバの本体のセルタイプ
+ */
+celltype tSIOPortNTShellMain {
+	/*
+	 *  シリアルインタフェースドライバとの結合
+	 */
+	entry				sSIOPort		eSIOPort;
+	[optional] call		siSIOCBR		ciSIOCBR;
+
+	/*
+	 *  終了処理ルーチン
+	 */
+	entry	sRoutineBody	eTerminate;
+
+	attr {
+		const char	*path;				/* パス名 */
+	};
+
+	var {
+		bool_t			opened = false;	/* オープン済みフラグ */
+		struct termios	saved_term;		/* 元の端末制御情報 */
+		int_t			read_fd;		/* 読出し用ファイルディスクリプタ */
+		bool_t			rcv_flag;		/* 受信文字バッファ有効フラグ */
+		char			rcv_buf;		/* 受信文字バッファ */
+		bool_t			rcv_rdy;		/* 受信通知コールバック許可フラグ */
+		int_t			write_fd;		/* 書込み用ファイルディスクリプタ */
+		bool_t			snd_flag;		/* 送信文字バッファ有効フラグ */
+		char			snd_buf;		/* 送信文字バッファ */
+		bool_t			snd_rdy;		/* 送信通知コールバック許可フラグ */
+	};
+};
+
+/*
+ *  SIOドライバ（複合コンポーネント）のセルタイプ
+ */
+[active]
+composite tSIOPortNTShell {
+	/*
+	 *  シリアルインタフェースドライバとの結合
+	 */
+	entry				sSIOPort	eSIOPort;
+	[optional] call		siSIOCBR	ciSIOCBR;
+
+	/*
+	 *  属性の定義
+	 */
+	attr {
+		const char	*path = C_EXP("NULL");		/* パス名 */
+	};
+
+	/*
+	 *  SIOドライバの本体
+	 */
+	cell tSIOPortNTShellMain SIOPortMain {
+		path     = composite.path;
+		ciSIOCBR => composite.ciSIOCBR;
+	};
+	composite.eSIOPort => SIOPortMain.eSIOPort;
+
+	/*
+	 *  SIOドライバの終了処理ルーチン
+	 */
+	cell tTerminateRoutine TerminateSIO {
+		cTerminateRoutineBody = SIOPortMain.eTerminate;
+	};
+};
Index: asp3_tinet_ecnl_arm/trunk/ntshell/src/tSIOPortNTShellMain.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/ntshell/src/tSIOPortNTShellMain.c	(revision 387)
+++ asp3_tinet_ecnl_arm/trunk/ntshell/src/tSIOPortNTShellMain.c	(revision 387)
@@ -0,0 +1,255 @@
+/*
+ *  TOPPERS/ASP Kernel
+ *      Toyohashi Open Platform for Embedded Real-Time Systems/
+ *      Advanced Standard Profile Kernel
+ * 
+ *  Copyright (C) 2006-2018 by Embedded and Real-Time Systems Laboratory
+ *              Graduate School of Information Science, Nagoya Univ., JAPAN
+ * 
+ *  上記著作権者は，以下の(1)〜(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  $Id$
+ */
+
+/*
+ *		シリアルインタフェースドライバのターゲット依存部（NTShell用）
+ */
+
+#include <t_stddef.h>
+#include <t_syslog.h>
+#include <errno.h> 
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include "tSIOPortNTShellMain_tecsgen.h"
+#include "syssvc/siofd.h"
+ 
+/*
+ *  SIOポートのオープン
+ */
+void
+eSIOPort_open(CELLIDX idx)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	int_t	fd;
+	struct	termios term;
+
+	if (!VAR_opened) {
+		/*
+		 *  既にオープンしている場合は、二重にオープンしない．
+		 */
+		if (ATTR_path != NULL) {
+			fd = siofd_open(ATTR_path, O_RDWR, 0777);
+			assert(fd >= 0);
+			VAR_read_fd = fd;
+			VAR_write_fd = fd;
+		}
+		else {
+			fd = STDIN_FILENO;				/* 標準入出力を使う */
+			VAR_read_fd = STDIN_FILENO;
+			VAR_write_fd = STDOUT_FILENO;
+		}
+		siofd_fcntl(fd, F_SETOWN, getpid());
+		siofd_fcntl(fd, F_SETFL, (O_NONBLOCK | O_ASYNC));
+
+		siofd_tcgetattr(fd, &VAR_saved_term);
+		term = VAR_saved_term;
+		term.c_lflag &= ~(ECHO | ICANON);
+		siofd_tcsetattr(fd, TCSAFLUSH, &term);
+
+		VAR_rcv_flag = false;
+		VAR_rcv_rdy = false;
+		VAR_snd_flag = false;
+		VAR_snd_rdy = false;
+		VAR_opened = true;
+	}
+}
+
+/*
+ *  SIOポートのクローズ
+ */
+void
+eSIOPort_close(CELLIDX idx)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	int_t	fd;
+
+	if (VAR_opened) {
+		fd = VAR_read_fd;
+		siofd_tcsetattr(fd, TCSAFLUSH, &VAR_saved_term);
+		siofd_fcntl(fd, F_SETFL, 0);
+
+		if (ATTR_path != NULL) {
+			siofd_close(VAR_read_fd);
+		}
+		VAR_opened = false;
+	}
+}
+
+/*
+ *  SIOポートへの文字送信
+ */
+bool_t
+eSIOPort_putChar(CELLIDX idx, char c)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	int_t	n;
+
+	if (!VAR_snd_flag) {
+		if ((n = siofd_write(VAR_write_fd, &c, 1)) > 0) {
+			return(true);
+		}
+		else {
+			assert(n < 0 && errno == EAGAIN);
+			VAR_snd_flag = true;
+			VAR_snd_buf = c;
+			return(true);
+		}
+	}
+	else {
+		return(false);
+	}
+}
+
+/*
+ *  SIOポートからの文字受信
+ */
+int_t
+eSIOPort_getChar(CELLIDX idx)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	char	c;
+	int_t	n;
+
+	if (VAR_rcv_flag) {
+		VAR_rcv_flag = false;
+		return((int_t)(uint8_t)(VAR_rcv_buf));
+	}
+	else if ((n = siofd_read(VAR_read_fd, &c, 1)) > 0) {
+		return((int_t)(uint8_t) c);
+	}
+	else {
+		assert(n < 0 && errno == EAGAIN);
+		return(-1);
+	}
+}
+
+/*
+ *  SIOポートからのコールバックの許可
+ */
+void
+eSIOPort_enableCBR(CELLIDX idx, uint_t cbrtn)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+
+	switch (cbrtn) {
+	case SIOSendReady:
+		VAR_snd_rdy = true;
+		break;
+	case SIOReceiveReady:
+		VAR_rcv_rdy = true;
+		break;
+	}
+}
+
+/*
+ *  SIOポートからのコールバックの禁止
+ */
+void
+eSIOPort_disableCBR(CELLIDX idx, uint_t cbrtn)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+
+	switch (cbrtn) {
+	case SIOSendReady:
+		VAR_snd_rdy = false;
+		break;
+	case SIOReceiveReady:
+		VAR_rcv_rdy = false;
+		break;
+	}
+}
+
+/*
+ *  SIOの割込みサービスルーチン
+ */
+bool_t
+sio_isr_snd(ID siopid)
+{
+	if (!(1 <= siopid && siopid <= tSIOPortNTShellMain_N_CELL))
+		return false;
+	CELLIDX idx = &tSIOPortNTShellMain_CB_tab[siopid - 1];
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	int_t	n;
+
+	if (VAR_snd_flag) {
+		if ((n = siofd_write(VAR_write_fd, &(VAR_snd_buf), 1)) > 0) {
+			VAR_snd_flag = false;
+			if (VAR_snd_rdy) {
+				ciSIOCBR_readySend();
+				return VAR_snd_rdy;
+			}
+		}
+	}
+
+	return false;
+}
+
+/*
+ *  SIOの割込みサービスルーチン
+ */
+bool_t
+sio_isr_rcv(ID siopid, char c)
+{
+	if (!(1 <= siopid && siopid <= tSIOPortNTShellMain_N_CELL))
+		return false;
+	CELLIDX idx = &tSIOPortNTShellMain_CB_tab[siopid - 1];
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+
+	if (!VAR_rcv_flag) {
+		VAR_rcv_buf = c;
+		VAR_rcv_flag = true;
+		if (VAR_rcv_rdy) {
+			ciSIOCBR_readyReceive();
+			return VAR_rcv_rdy;
+		}
+	}
+
+	return false;
+}
+
+/*
+ *  SIOドライバの終了処理
+ */
+void
+eTerminate_main(CELLIDX idx)
+{
+	eSIOPort_close(idx);
+}
