diff --git a/Makefile b/Makefile index 58c6db472b5f6a2c79cbd5dfab47afeabc1af8fe..4d86f76347ef97ed538f5563520738e629c1473d 100644 --- a/Makefile +++ b/Makefile @@ -12,14 +12,15 @@ MAKE :=make CP :=cp -SDK_DIR := ./sdk +SDK_DIR := ../sdk SDK_INC_DIR := $(SDK_DIR)/include SDK_LIB_DIR := $(SDK_DIR)/lib -LIBNXBASE_NAME := libnxbase.a -LIBNXBASE_DIR := ../nxos-baselib -LIBNXBASE_LIB_DIR := $(LIBNXBASE_DIR)/build/ -LIBNXBASE_INC_DIR := $(LIBNXBASE_DIR)/src/include +LIBXLIBC_NAME := libxlibc.a +LIBXLIBC_LIB_DIR := ./build/ +LIBXLIBC_INC_DIR := ./src/include +LIBXLIBC_ARCH_INC_DIR := ./src/arch/$(ARCH)/include +LIBXLIBC_GENERIC_INC_DIR := ./src/arch/generic # # Cmds @@ -32,8 +33,8 @@ all: clean: @$(MAKE) -s -C src clean O=../build -# update lib -ulib: - @$(CP) $(LIBNXBASE_LIB_DIR)/$(LIBNXBASE_NAME) $(SDK_LIB_DIR) - @$(CP) -r $(LIBNXBASE_INC_DIR)/* $(SDK_INC_DIR) - @echo copy user lib done. +install: + @$(CP) $(LIBXLIBC_LIB_DIR)/$(LIBXLIBC_NAME) $(SDK_LIB_DIR) + @$(CP) -r $(LIBXLIBC_INC_DIR)/* $(SDK_INC_DIR) + @$(CP) -r $(LIBXLIBC_ARCH_INC_DIR)/* $(SDK_INC_DIR) + @$(CP) -r $(LIBXLIBC_GENERIC_INC_DIR)/* $(SDK_INC_DIR) diff --git a/README.md b/README.md index da67ba77483bb05220bff31a320f12c3a1b06bf0..8d440cce494960552e973254dd64ee44f79e1e77 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ setup.bat # windows环境,默认x86 source setup.sh # linux环境 setup.bat riscv64 # windows环境 source setup.sh riscv64 # linux环境 -# 2. 更新nxbase基础库 -make ulib -# 3. 编译库 +# 2. 编译库 make +# 3. 安装库 +make install ``` diff --git a/setup.bat b/setup.bat index fa897742657695888809fb96fb00c9154f2b8b55..4a8b671e0e9dc3aba753568ae13e9954480abaf9 100644 --- a/setup.bat +++ b/setup.bat @@ -37,7 +37,7 @@ if "%def_arch%" == "x86" ( echo Set environment for xlibc. echo [CROSS COMPILE ] %CROSS_COMPILE% echo [ARCH ] %def_arch% -echo [NXBASE ARCH ] %ARCH% +echo [NXOS ARCH ] %ARCH% :end @echo on diff --git a/setup.sh b/setup.sh index 9ddea27b695b2a21c2f297f89f20901babc4fb02..719693f86062f564ed3380f6a00485a64603145d 100755 --- a/setup.sh +++ b/setup.sh @@ -15,29 +15,9 @@ # source setup.sh [arch] # example: source setup.sh # x86 # example: source setup.sh riscv64 # riscv64 - -# supported targe list -supported_arch="x86 riscv64" - -def_arch="unknown" - -# find arch in arch list -if [ -z $1 ] -then - def_arch="x86" # default arch is x86 -else - for arch in $supported_arch - do - if [ $arch = $1 ] - then - def_arch=$arch - break - fi - done -fi - # set env -case $def_arch in +arch=$1 +case $arch in "x86") export CROSS_COMPILE= export ARCH=x86 @@ -46,11 +26,14 @@ case $def_arch in export CROSS_COMPILE=riscv64-unknown-elf- export ARCH=riscv64 ;; - *) echo "unknown arch! " $def_arch + "qemu_riscv64") + export CROSS_COMPILE=riscv64-unknown-elf- + export ARCH=riscv64 + ;; + *) echo "unknown arch! " $arch return 1 esac -echo "Set environment for for xlibc." -echo [CROSS COMPILE ] $CROSS_COMPILE -echo [ARCH ] $def_arch -echo [NXBASE ARCH ] $ARCH +echo "Set environment for nxos-user." +echo "[CROSS COMPILE ] $CROSS_COMPILE" +echo "[ARCH ] $arch" \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index 2e78b0427b168a71a86b11ace5e0b020fe026df9..b34a71a92207fa291ccce0762e184120047eef12 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,7 @@ sinclude ../scripts/xbuild/env.mk # we have build dir, so need double last level LINK_ROOT_PATH := ../.. -COMPILE_ROOT_PATH := .. +COMPILE_ROOT_PATH := ../.. ARCH ?= x86 @@ -33,15 +33,12 @@ X_LDFLAGS += -T $(LINK_ROOT_PATH)/ldscripts/$(ARCH).ld LINK_SDK_DIR := $(LINK_ROOT_PATH)/sdk COMPILE_SDK_DIR := $(COMPILE_ROOT_PATH)/sdk -LIBS_DIR := $(LINK_SDK_DIR)/lib - X_INCDIRS := include arch/$(ARCH)/include $(COMPILE_SDK_DIR)/include internal X_INCDIRS += arch/generic +X_LIBDIRS := $(LINK_SDK_DIR)/lib -X_LIBDIRS := $(LIBS_DIR) - -# we must link nxbase lib. -X_LIBS += libnxbase.a +# we must link nxos lib. +X_LIBS += libnxos.a SRC += multibyte/ SRC += time/ diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c index 236e4eb4ea523f448c80225a49304e1a72641d2c..216e9df3fbba53f38b69ba60479dfcd56a445d18 100644 --- a/src/env/__libc_start_main.c +++ b/src/env/__libc_start_main.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include "stdio_impl.h" diff --git a/src/errno/errno.c b/src/errno/errno.c index 3cbea15c1cd329e725c2a29fa0ab25504d2b4826..934ddd1a6ea52290f808f1f9d744b2a2eaf3468f 100644 --- a/src/errno/errno.c +++ b/src/errno/errno.c @@ -1,5 +1,5 @@ #include -#include +#include int *__errno_location(void) { diff --git a/src/exit/_Exit.c b/src/exit/_Exit.c index a01c356e0011b0e96a6eb5c2b9916826ce16588a..96f02bfbcd31c7639c7a88ca9032f2c6c3091bc9 100644 --- a/src/exit/_Exit.c +++ b/src/exit/_Exit.c @@ -1,5 +1,5 @@ #include -#include +#include _Noreturn void _Exit(int ec) { diff --git a/src/exit/abort.c b/src/exit/abort.c index 1ad35664a2b08957ac09a28d2a683e4fcdc649a8..9ef2b7fb6ec9c5521298f3fec4f1478fc0c6fdb8 100644 --- a/src/exit/abort.c +++ b/src/exit/abort.c @@ -1,5 +1,5 @@ #include -#include +#include _Noreturn void abort(void) { diff --git a/src/exit/assert.c b/src/exit/assert.c index 79d4495578fdeced7f694b8206b496d0f738cd7e..94edd8272792e79fb0e2079142342c518e22fbfe 100644 --- a/src/exit/assert.c +++ b/src/exit/assert.c @@ -3,6 +3,6 @@ _Noreturn void __assert_fail(const char *expr, const char *file, int line, const char *func) { - // fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line); + fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line); abort(); } diff --git a/src/include/signal.h b/src/include/signal.h index bb372b06d05723fbcb8fbcc00ded61ef6f24d1b9..d086e5814a41d1b70d622e32fbb19b642dadfea9 100644 --- a/src/include/signal.h +++ b/src/include/signal.h @@ -1,7 +1,7 @@ #ifndef _SIGNAL_H #define _SIGNAL_H -#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/include/stdio.h b/src/include/stdio.h index abdf89354fc3347948931a5552dced5dc4b88838..d320daabd4c4c5e566841bf5a5e9728fafc218d2 100644 --- a/src/include/stdio.h +++ b/src/include/stdio.h @@ -14,11 +14,13 @@ extern "C" { #define __NEED_struct__IO_FILE #endif +#ifndef NULL #ifdef __cplusplus -#define NULL 0L +#define NULL 0 #else -#define NULL ((void*)0) +#define NULL ((void *)0) #endif +#endif /* NULL */ #undef EOF #define EOF (-1) diff --git a/src/internal/locale_impl.h b/src/internal/locale_impl.h index b0371853a4825c45490ac63683eb844d94cc85b4..1a3dabf6e35719becb7bbc592616befc4dd4f7a3 100644 --- a/src/internal/locale_impl.h +++ b/src/internal/locale_impl.h @@ -4,7 +4,7 @@ #include #include #include "libc.h" -#include +#include #define LOCALE_NAME_MAX 23 diff --git a/src/process/system.c b/src/process/system.c index f2e39b09aa928d788327d977a276e42c9bdcb7bb..4d2e4436a41a49ed52076413046e1d4fa8553f66 100644 --- a/src/process/system.c +++ b/src/process/system.c @@ -1,12 +1,12 @@ #include #include -#include +#include #include "libc.h" int system(const char *cmd) { - NX_Error err; - char appPath[NX_VFS_MAX_NAME] = {0}; + NX_Solt solt; + char appPath[NX_FILE_MAX_NAME] = {0}; char *spacePos; char * cmdline = (char *)cmd; NX_U32 exitCode; @@ -32,8 +32,8 @@ int system(const char *cmd) NX_StrCopyN(appPath, cmdline, spacePos - cmdline + 1); } - err = NX_ProcessLaunch(appPath, NX_PROC_FLAG_WAIT, &exitCode, cmdline, libc.envline); - if (err != NX_EOK) + solt = NX_ProcessLaunch(appPath, NX_THREAD_CREATE_WAIT, &exitCode, cmdline, libc.envline); + if (solt == NX_SOLT_INVALID_VALUE) { return -1; } diff --git a/src/stdio/__fmodeflags.c b/src/stdio/__fmodeflags.c index 3832dc6115a97e4a2c0db9d74bd126eed1644a38..8117a5f1678ed009b1efe385d1d4a95ffa5494bb 100644 --- a/src/stdio/__fmodeflags.c +++ b/src/stdio/__fmodeflags.c @@ -1,16 +1,16 @@ -#include +#include #include int __fmodeflags(const char *mode) { int flags; - if (strchr(mode, '+')) flags = NX_VFS_O_RDWR; - else if (*mode == 'r') flags = NX_VFS_O_RDONLY; - else flags = NX_VFS_O_WRONLY; - if (strchr(mode, 'x')) flags |= NX_VFS_O_EXCL; - //FIXME: if (strchr(mode, 'e')) flags |= NX_VFS_O_CLOEXEC; - if (*mode != 'r') flags |= NX_VFS_O_CREAT; - if (*mode == 'w') flags |= NX_VFS_O_TRUNC; - if (*mode == 'a') flags |= NX_VFS_O_APPEND; + if (strchr(mode, '+')) flags = NX_FILE_RDWR; + else if (*mode == 'r') flags = NX_FILE_RDONLY; + else flags = NX_FILE_WRONLY; + if (strchr(mode, 'x')) flags |= NX_FILE_EXCL; + //FIXME: if (strchr(mode, 'e')) flags |= NX_FILE_CLOEXEC; + if (*mode != 'r') flags |= NX_FILE_CREAT; + if (*mode == 'w') flags |= NX_FILE_TRUNC; + if (*mode == 'a') flags |= NX_FILE_APPEND; return flags; } diff --git a/src/stdio/__fopen_rb_ca.c b/src/stdio/__fopen_rb_ca.c index 6075abdf7a440fc37598c1763a6a3e87a001f06a..81f6b49839d282f7f519323729af0da100a625a0 100644 --- a/src/stdio/__fopen_rb_ca.c +++ b/src/stdio/__fopen_rb_ca.c @@ -1,12 +1,12 @@ #include "stdio_impl.h" #include -#include +#include FILE *__fopen_rb_ca(const char *filename, FILE *f, unsigned char *buf, size_t len) { memset(f, 0, sizeof *f); - f->fd = NX_FileOpen(filename, NX_VFS_O_RDONLY, 0666); + f->fd = NX_FileOpen(filename, NX_FILE_RDONLY, 0); if (f->fd < 0) return 0; f->flags = F_NOWR | F_PERM; diff --git a/src/stdio/__init_stdio.c b/src/stdio/__init_stdio.c index 18918bfe1d4674283a3cf23a47c009ed03debffc..8a2c35b04ac202e5855911f58d115cb265ab9036 100644 --- a/src/stdio/__init_stdio.c +++ b/src/stdio/__init_stdio.c @@ -1,16 +1,16 @@ -#include +#include #include #include "stdio_impl.h" void __init_stdio(void) { /* open stdio device */ - stdin->fd = NX_FileOpen("/dev/console", NX_VFS_O_RDONLY, 0666); + stdin->fd = NX_FileOpen("/System/Device/console", NX_FILE_RDONLY, 0); assert(stdin->fd >= 0); - stdout->fd = NX_FileOpen("/dev/console", NX_VFS_O_WRONLY, 0666); + stdout->fd = NX_FileOpen("/System/Device/console", NX_FILE_WRONLY, 0); assert(stdout->fd >= 0); - stderr->fd = NX_FileOpen("/dev/console", NX_VFS_O_WRONLY, 0666); + stderr->fd = NX_FileOpen("/System/Device/console", NX_FILE_WRONLY, 0); assert(stderr->fd >= 0); /* no buffer for stdin & stdout */ diff --git a/src/stdio/__stdio_close.c b/src/stdio/__stdio_close.c index 44502b87ee3bcb1b575db330bc74ac100a58348c..58e2ae2a9bf2e7bcb8f7b50b36319fdf32e2bad3 100644 --- a/src/stdio/__stdio_close.c +++ b/src/stdio/__stdio_close.c @@ -1,5 +1,5 @@ #include "stdio_impl.h" -#include +#include static int dummy(int fd) { diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c index 62da92149423219f46a44bb9cb741b893a54c7ec..5954c123bfdaf6dd40ef5db5581df6e112b59fa3 100644 --- a/src/stdio/__stdio_read.c +++ b/src/stdio/__stdio_read.c @@ -1,5 +1,5 @@ #include "stdio_impl.h" -#include +#include struct iovec { void *iov_base; /* starting address of buffer */ diff --git a/src/stdio/__stdio_seek.c b/src/stdio/__stdio_seek.c index 00f8dc11935781d0f424dcea70ec804939cbe460..eecd42fad7af4a3a00b5018116a70bb77a5c8d45 100644 --- a/src/stdio/__stdio_seek.c +++ b/src/stdio/__stdio_seek.c @@ -1,7 +1,7 @@ #include "stdio_impl.h" -#include +#include off_t __stdio_seek(FILE *f, off_t off, int whence) { - return NX_FileSeek(f->fd, off, whence); + return NX_FileSetPointer(f->fd, off, whence); } diff --git a/src/stdio/__stdio_write.c b/src/stdio/__stdio_write.c index f9fa660cba97de2115a9cb02fb97560249627282..05f598c379ef5abd6c393c3fdd8874e28e14a60a 100644 --- a/src/stdio/__stdio_write.c +++ b/src/stdio/__stdio_write.c @@ -1,5 +1,5 @@ #include "stdio_impl.h" -#include +#include struct iovec { void *iov_base; /* starting address of buffer */ diff --git a/src/stdio/__towrite.c b/src/stdio/__towrite.c index d2931a04e09df698b0127e35ec18a9c6affa534b..23ba3fd715d432de1e6b896b2eda37809d931ad0 100644 --- a/src/stdio/__towrite.c +++ b/src/stdio/__towrite.c @@ -1,5 +1,5 @@ #include "stdio_impl.h" -#include +#include int __towrite(FILE *f) { diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c index a6154a8a01bd37c7047aa56046ee81f82254eae6..53471626e24c0cc6c1c8ecd508c8a90f5bb90e64 100644 --- a/src/stdio/fopen.c +++ b/src/stdio/fopen.c @@ -1,6 +1,7 @@ #include "stdio_impl.h" #include #include +#include FILE *fopen(const char *restrict filename, const char *restrict mode) { @@ -17,7 +18,7 @@ FILE *fopen(const char *restrict filename, const char *restrict mode) /* Compute the flags to pass to open() */ flags = __fmodeflags(mode); - fd = NX_FileOpen(filename, flags, 0666); + fd = NX_FileOpen(filename, flags, NX_FILE_MODE_READ | NX_FILE_MODE_WRITE); if (fd < 0) return 0; f = __fdopen(fd, mode); diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c index 11b8faf2ea9bd3a25ea29bd12adce47733fd612e..1b079dd1df22537f27f4759ecb8899716084b3b7 100644 --- a/src/stdio/freopen.c +++ b/src/stdio/freopen.c @@ -1,5 +1,5 @@ #include "stdio_impl.h" -#include +#include /* The basic idea of this implementation is to open a new FILE, * hack the necessary parts of the new FILE into the old one, then @@ -19,7 +19,7 @@ FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *re fflush(f); if (!filename) { - fl &= ~(NX_VFS_O_CREAT|NX_VFS_O_EXCL); + fl &= ~(NX_FILE_CREAT|NX_FILE_EXCL); } else { f2 = fopen(filename, mode); if (!f2) goto fail; diff --git a/src/stdio/remove.c b/src/stdio/remove.c index 4580575470a063b21de3b05e4957eabe177e3a81..1fa7dbcecf4a4788b4ac78c20fa6233aa223ea4b 100644 --- a/src/stdio/remove.c +++ b/src/stdio/remove.c @@ -1,8 +1,8 @@ #include #include -#include +#include int remove(const char *path) { - return NX_PathUnlink(path) == NX_EOK ? 0 : -1; + return NX_FileDelete(path) == NX_EOK ? 0 : -1; } diff --git a/src/stdio/rename.c b/src/stdio/rename.c index 14a0a48fa39a647042402e11b7aaeff8c9cec571..5e1bfecf14b9604c130eb5ffce02073469383fc6 100644 --- a/src/stdio/rename.c +++ b/src/stdio/rename.c @@ -1,7 +1,7 @@ #include -#include +#include int rename(const char *old, const char *new) { - return NX_PathRename(old, new) == NX_EOK ? 0 : -1; + return NX_FileRename(old, new) == NX_EOK ? 0 : -1; } diff --git a/src/stdio/tmpfile.c b/src/stdio/tmpfile.c index 73d40207102a43e1aec42a76680e2239ea838751..beeca4d85fc5afc5fce6ba38c24225f5505728a5 100644 --- a/src/stdio/tmpfile.c +++ b/src/stdio/tmpfile.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include "stdio_impl.h" @@ -13,9 +13,9 @@ FILE *tmpfile(void) int try; for (try=0; try= 0) { - NX_PathUnlink(s); + NX_FileDelete(s); f = __fdopen(fd, "w+"); if (!f) NX_FileClose(fd); return f; diff --git a/src/stdio/tmpnam.c b/src/stdio/tmpnam.c index f7724663507fd39c64ddc846244ecd9babda00af..123c6d65a1c8beb9f5a8a026bebb0388d8d38731 100644 --- a/src/stdio/tmpnam.c +++ b/src/stdio/tmpnam.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #define MAXTRIES 100 @@ -15,8 +15,8 @@ char *tmpnam(char *buf) for (try=0; try -#include +#include void* malloc( size_t size ) { diff --git a/src/temp/__randname.c b/src/temp/__randname.c index a719fec9bc5b2d765a7b5717f67a47f13f049afb..4ba333ee12ec5d75a7b579d5b525f408cf6ef62c 100644 --- a/src/temp/__randname.c +++ b/src/temp/__randname.c @@ -1,5 +1,5 @@ #include -#include +#include /* This assumes that a check for the template size has already been made */ diff --git a/src/time/clock.c b/src/time/clock.c index 90c9cbf9f5cd419e7884b19674d58c584c6126e8..774cd2a3aeb1754e4f9f8465d498106b2258ce50 100644 --- a/src/time/clock.c +++ b/src/time/clock.c @@ -1,6 +1,6 @@ #include #include -#include +#include clock_t clock(void) { diff --git a/src/time/time.c b/src/time/time.c index 98bd1e59cf73fe26d4d321638d3a2d786765d42e..d1b1a81c99b1563fa67ed731a641c4cc7bb15b98 100644 --- a/src/time/time.c +++ b/src/time/time.c @@ -3,7 +3,7 @@ */ #include -#include +#include #include "time_impl.h" time_t time(time_t * t) @@ -13,8 +13,8 @@ time_t time(time_t * t) NX_Time nxtm; NX_TimeGet(&nxtm); - tm.tm_year = nxtm.year - 1900; /* start from */ - tm.tm_mon = nxtm.month - 1; + tm.tm_year = nxtm.year; + tm.tm_mon = nxtm.month; tm.tm_mday = nxtm.day; tm.tm_hour = nxtm.hour; tm.tm_min = nxtm.minute; diff --git a/src/time/timespec_get.c b/src/time/timespec_get.c index 04768773fd1c91f641dea78fe4a2614b30cf02b4..a09a10ee3b0b6feae486259feeee08a8fecc630c 100644 --- a/src/time/timespec_get.c +++ b/src/time/timespec_get.c @@ -1,5 +1,5 @@ #include -#include +#include /* There is no other implemented value than TIME_UTC; all other values * are considered erroneous. */