refactor: restructure the user space stuff.
authorMinep <lunaixsky@qq.com>
Mon, 17 Jul 2023 17:17:20 +0000 (18:17 +0100)
committerMinep <lunaixsky@qq.com>
Mon, 17 Jul 2023 17:17:20 +0000 (18:17 +0100)
refactor: better isolation between kernel and user header file
refactor: rebuild user space make system

77 files changed:
lunaix-os/.gitignore
lunaix-os/.vscode/c_cpp_properties.json
lunaix-os/config/make-locations [deleted file]
lunaix-os/config/make-os [deleted file]
lunaix-os/includes/lunaix/foptions.h
lunaix-os/includes/lunaix/ioctl.h
lunaix-os/includes/lunaix/mm/mm.h
lunaix-os/includes/lunaix/signal.h
lunaix-os/includes/lunaix/status.h
lunaix-os/includes/lunaix/syscall.h
lunaix-os/includes/lunaix/types.h
lunaix-os/includes/usr/lunaix/dirent_defs.h [moved from lunaix-os/usr/includes/sys/dirent_defs.h with 100% similarity]
lunaix-os/includes/usr/lunaix/fcntl_defs.h [moved from lunaix-os/usr/includes/fcntl_defs.h with 100% similarity]
lunaix-os/includes/usr/lunaix/ioctl_defs.h [moved from lunaix-os/usr/includes/sys/ioctl_defs.h with 100% similarity]
lunaix-os/includes/usr/lunaix/lxdirent.h [moved from lunaix-os/usr/includes/sys/lxdirent.h with 54% similarity]
lunaix-os/includes/usr/lunaix/mann_flags.h [moved from lunaix-os/usr/includes/sys/mann_flags.h with 100% similarity]
lunaix-os/includes/usr/lunaix/signal_defs.h [moved from lunaix-os/usr/includes/signal_defs.h with 100% similarity]
lunaix-os/includes/usr/lunaix/status.h [moved from lunaix-os/usr/includes/errno.h with 64% similarity]
lunaix-os/includes/usr/lunaix/syscallid.h [new file with mode: 0644]
lunaix-os/includes/usr/lunaix/types.h [moved from lunaix-os/usr/includes/sys/types.h with 100% similarity]
lunaix-os/kernel/device/devfs.c
lunaix-os/kernel/fs/iso9660/directory.c
lunaix-os/kernel/fs/vfs.c
lunaix-os/kernel/process/taskfs.c
lunaix-os/makefile.prog [deleted file]
lunaix-os/makefile.usr [deleted file]
lunaix-os/makeinc/os.mkinc [new file with mode: 0644]
lunaix-os/makeinc/qemu.mkinc [moved from lunaix-os/config/make-debug-tool with 100% similarity]
lunaix-os/makeinc/toolchain.mkinc [moved from lunaix-os/config/make-cc with 85% similarity]
lunaix-os/makeinc/utils.mkinc [new file with mode: 0644]
lunaix-os/uprog/includes/ld/elf.h [new file with mode: 0644]
lunaix-os/usr/api/errno.c [deleted file]
lunaix-os/usr/api/ioctl.c [deleted file]
lunaix-os/usr/includes [new symlink]
lunaix-os/usr/includes/string.h [deleted file]
lunaix-os/usr/includes/sys/mann.h [deleted file]
lunaix-os/usr/includes/sys/mount.h [deleted file]
lunaix-os/usr/init/init.c [moved from lunaix-os/uprog/init.c with 96% similarity]
lunaix-os/usr/init/makefile [new file with mode: 0644]
lunaix-os/usr/libc/arch/i386/crt0.S [moved from lunaix-os/usr/uwrap.S with 62% similarity]
lunaix-os/usr/libc/arch/i386/dirent.c [moved from lunaix-os/usr/api/dirent.c with 55% similarity]
lunaix-os/usr/libc/arch/i386/errno.c [new file with mode: 0644]
lunaix-os/usr/libc/arch/i386/fcntl.c [moved from lunaix-os/usr/api/fcntl.c with 73% similarity]
lunaix-os/usr/libc/arch/i386/ioctl.c [new file with mode: 0644]
lunaix-os/usr/libc/arch/i386/lunaix.c [moved from lunaix-os/usr/api/lunaix.c with 83% similarity]
lunaix-os/usr/libc/arch/i386/mann.c [moved from lunaix-os/usr/api/mann.c with 84% similarity]
lunaix-os/usr/libc/arch/i386/mount.c [moved from lunaix-os/usr/api/mount.c with 69% similarity]
lunaix-os/usr/libc/arch/i386/signal.c [moved from lunaix-os/usr/api/signal.c with 86% similarity]
lunaix-os/usr/libc/arch/i386/syscall.h [new file with mode: 0644]
lunaix-os/usr/libc/arch/i386/unistd.c [moved from lunaix-os/usr/api/unistd.c with 97% similarity]
lunaix-os/usr/libc/includes/dirent.h [moved from lunaix-os/usr/includes/dirent.h with 68% similarity]
lunaix-os/usr/libc/includes/errno.h [new file with mode: 0644]
lunaix-os/usr/libc/includes/fcntl.h [moved from lunaix-os/usr/includes/fcntl.h with 64% similarity]
lunaix-os/usr/libc/includes/lunaix/ioctl.h [moved from lunaix-os/usr/includes/sys/ioctl.h with 58% similarity]
lunaix-os/usr/libc/includes/lunaix/lunaix.h [moved from lunaix-os/usr/includes/sys/lunaix.h with 91% similarity]
lunaix-os/usr/libc/includes/lunaix/mann.h [new file with mode: 0644]
lunaix-os/usr/libc/includes/lunaix/mount.h [new file with mode: 0644]
lunaix-os/usr/libc/includes/signal.h [moved from lunaix-os/usr/includes/signal.h with 71% similarity]
lunaix-os/usr/libc/includes/stdio.h [moved from lunaix-os/usr/includes/stdio.h with 93% similarity]
lunaix-os/usr/libc/includes/stdlib.h [moved from lunaix-os/usr/includes/stdlib.h with 62% similarity]
lunaix-os/usr/libc/includes/string.h [new file with mode: 0644]
lunaix-os/usr/libc/includes/unistd.h [moved from lunaix-os/usr/includes/unistd.h with 75% similarity]
lunaix-os/usr/libc/makefile [new file with mode: 0644]
lunaix-os/usr/libc/src/_mystdio.h [moved from lunaix-os/usr/libc/_mystdio.h with 100% similarity]
lunaix-os/usr/libc/src/_vprintf.c [moved from lunaix-os/usr/libc/_vprintf.c with 100% similarity]
lunaix-os/usr/libc/src/itoa.c [moved from lunaix-os/usr/libc/itoa.c with 100% similarity]
lunaix-os/usr/libc/src/printf.c [moved from lunaix-os/usr/libc/printf.c with 100% similarity]
lunaix-os/usr/libc/src/readdir.c [moved from lunaix-os/usr/libc/readdir.c with 96% similarity]
lunaix-os/usr/libc/src/string.c [moved from lunaix-os/usr/libc/string.c with 100% similarity]
lunaix-os/usr/link-usr.ld
lunaix-os/usr/ls/ls.c [moved from lunaix-os/uprog/ls.c with 100% similarity]
lunaix-os/usr/ls/makefile [new file with mode: 0644]
lunaix-os/usr/makefile [new file with mode: 0644]
lunaix-os/usr/sh/makefile [new file with mode: 0644]
lunaix-os/usr/sh/sh.c [moved from lunaix-os/uprog/sh.c with 98% similarity]
lunaix-os/usr/signal_demo/makefile [new file with mode: 0644]
lunaix-os/usr/signal_demo/signal_demo.c [moved from lunaix-os/uprog/signal_demo.c with 98% similarity]

index 251d9927cb8841558c2432105eebace64b26baba..32bb844fc07932810b06e0a973ecc2e6ae08c3f9 100644 (file)
@@ -8,4 +8,6 @@ bx_enh_dbg.ini
 machine/
 draft/
 iso_inspect/
-unused/
\ No newline at end of file
+unused/
+
+**.o
\ No newline at end of file
index 0fdf9959bb64051d315742a6b29720a0728ec772..f91b0507f97eb1855d756cdfd72730099f83092c 100644 (file)
@@ -4,6 +4,7 @@
             "name": "OS-DEV",
             "includePath": [
                 "${workspaceFolder}/includes",
+                "${workspaceFolder}/includes/usr",
                 "${workspaceFolder}/usr/includes"
             ],
             "compilerArgs": [
diff --git a/lunaix-os/config/make-locations b/lunaix-os/config/make-locations
deleted file mode 100644 (file)
index 093f7ba..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-BUILD_DIR := build
-KERNEL_DIR := kernel
-OBJECT_DIR := $(BUILD_DIR)/obj
-BIN_DIR := $(BUILD_DIR)/bin
-ISO_DIR := $(BUILD_DIR)/iso
-USR_DIR := $(BUILD_DIR)/usr
-ISO_BOOT_DIR := $(ISO_DIR)/boot
-ISO_GRUB_DIR := $(ISO_BOOT_DIR)/grub
-
-INCLUDES := -Iincludes -Iusr/includes
\ No newline at end of file
diff --git a/lunaix-os/config/make-os b/lunaix-os/config/make-os
deleted file mode 100644 (file)
index fd4908e..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-OS_ARCH := x86
-OS_NAME := lunaix
-OS_ID := LunaixOS
-OS_VER := dev$(shell date +%Y%m%d)
-OS_BIN := $(OS_NAME).bin
-OS_ISO := $(OS_NAME).iso
-
-USR_LIB := liblxusrt.a
index 625c0b22074f045ba2273c06bb923bb1e2c9603a..38b055a9d18dd1b3a73ed6e7cccf02b3bb38361a 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef __LUNAIX_FOPTIONS_H
 #define __LUNAIX_FOPTIONS_H
 
-#include <fcntl_defs.h>
+#include <usr/lunaix/fcntl_defs.h>
 
 #endif /* __LUNAIX_FOPTIONS_H */
index 6dcd83c0ceefc3d67a848174a24f6f6e61a66cdd..ed7c4f7316e7a82265506f7c3aecbd03b1e0a76f 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef __LUNAIX_IOCTL_H
 #define __LUNAIX_IOCTL_H
 
-#include <sys/ioctl_defs.h>
+#include <usr/lunaix/ioctl_defs.h>
 
 #endif /* __LUNAIX_IOCTL_H */
index 24ced3cc9dcce584558e48e74c463c985242f49b..433ecfc7f50d8542efc6ed136d8b35356908db5d 100644 (file)
@@ -6,7 +6,7 @@
 #include <lunaix/fs.h>
 #include <lunaix/types.h>
 
-#include <sys/mann_flags.h>
+#include <usr/lunaix/mann_flags.h>
 
 /**
  * @brief 私有区域,该区域中的页无法进行任何形式的共享。
index 16ec0336cb5024fb22d495cff475103a1455e999..dbe9ce5c9c212af1d28fe167558615b65049743b 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_SIGNAL_H
 #define __LUNAIX_SIGNAL_H
 
-#include <signal_defs.h>
+#include <usr/lunaix/signal_defs.h>
 
 #define _SIG_NUM 16
 
index ffaacf51ce091b959e3462636f120f6c2233a08e..9b057472812215f80779e3f61be9e5c1b0ca2739 100644 (file)
@@ -1,37 +1 @@
-#ifndef __LUNAIX_CODE_H
-#define __LUNAIX_CODE_H
-
-#define LXPROCFULL -(1)
-#define LXHEAPFULL -(2)
-#define LXINVLDPTR -(2)
-#define LXOUTOFMEM -(3)
-#define LXSEGFAULT -(5)
-#define EINVAL -(6)
-
-#define EINTR -(7)
-
-#define EMFILE -8
-#define ENOENT -9
-#define ENAMETOOLONG -10
-#define ENOTDIR -11
-#define EEXIST -12
-#define EBADF -13
-#define ENOTSUP -14
-#define EIO -15
-#define ELOOP -16
-#define ENOTEMPTY -17
-#define EROFS -18
-#define EISDIR -19
-#define EBUSY -20
-#define EXDEV -21
-#define ENODEV -22
-#define ERANGE -23
-#define ENOMEM LXOUTOFMEM
-#define ENOTDEV -24
-#define EOVERFLOW -25
-#define ENOTBLK -26
-#define ENOEXEC -27
-#define E2BIG -28
-#define ELIBBAD -29
-
-#endif /* __LUNAIX_CODE_H */
+#include <usr/lunaix/status.h>
\ No newline at end of file
index a512bd7b8a48cb21aafd6bd3d48c59dbbca54534..4a101fa73c280f31c47a369149b927c4b092fb4e 100644 (file)
@@ -2,70 +2,7 @@
 #define __LUNAIX_SYSCALL_H
 
 #include <arch/x86/vectors.h>
-
-#define __SYSCALL_fork 1
-#define __SYSCALL_yield 2
-#define __SYSCALL_sbrk 3
-#define __SYSCALL_brk 4
-#define __SYSCALL_getpid 5
-#define __SYSCALL_getppid 6
-#define __SYSCALL_sleep 7
-#define __SYSCALL__exit 8
-#define __SYSCALL_wait 9
-#define __SYSCALL_waitpid 10
-
-#define __SYSCALL_sigreturn 11
-#define __SYSCALL_sigprocmask 12
-#define __SYSCALL_signal 13
-#define __SYSCALL_pause 14
-#define __SYSCALL_kill 15
-#define __SYSCALL_alarm 16
-#define __SYSCALL_sigpending 17
-#define __SYSCALL_sigsuspend 18
-#define __SYSCALL_open 19
-#define __SYSCALL_close 20
-
-#define __SYSCALL_read 21
-#define __SYSCALL_write 22
-#define __SYSCALL_sys_readdir 23
-#define __SYSCALL_mkdir 24
-#define __SYSCALL_lseek 25
-#define __SYSCALL_geterrno 26
-#define __SYSCALL_readlink 27
-#define __SYSCALL_readlinkat 28
-#define __SYSCALL_rmdir 29
-
-#define __SYSCALL_unlink 30
-#define __SYSCALL_unlinkat 31
-#define __SYSCALL_link 32
-#define __SYSCALL_fsync 33
-#define __SYSCALL_dup 34
-#define __SYSCALL_dup2 35
-#define __SYSCALL_realpathat 36
-#define __SYSCALL_symlink 37
-#define __SYSCALL_chdir 38
-#define __SYSCALL_fchdir 39
-#define __SYSCALL_getcwd 40
-#define __SYSCALL_rename 41
-#define __SYSCALL_mount 42
-#define __SYSCALL_unmount 43
-#define __SYSCALL_getxattr 44
-#define __SYSCALL_setxattr 45
-#define __SYSCALL_fgetxattr 46
-#define __SYSCALL_fsetxattr 47
-
-#define __SYSCALL_ioctl 48
-#define __SYSCALL_getpgid 49
-#define __SYSCALL_setpgid 50
-
-#define __SYSCALL_syslog 51
-
-#define __SYSCALL_sys_mmap 52
-#define __SYSCALL_munmap 53
-
-#define __SYSCALL_execve 54
-
-#define __SYSCALL_MAX 0x100
+#include <usr/lunaix/syscallid.h>
 
 #ifndef __ASM__
 
@@ -107,61 +44,5 @@ syscall_install();
     asm("sti");                                                                \
     { code };                                                                  \
     asm("cli");
-
-#define ___DOINT33(callcode, rettype)                                          \
-    int v;                                                                     \
-    asm volatile("int %1\n" : "=a"(v) : "i"(LUNAIX_SYS_CALL), "a"(callcode));  \
-    return (rettype)v;
-
-#define __LXSYSCALL(rettype, name)                                             \
-    rettype name()                                                             \
-    {                                                                          \
-        ___DOINT33(__SYSCALL_##name, rettype)                                  \
-    }
-
-#define __LXSYSCALL1(rettype, name, t1, p1)                                    \
-    rettype name(__PARAM_MAP1(t1, p1))                                         \
-    {                                                                          \
-        asm("" ::"b"(p1));                                                     \
-        ___DOINT33(__SYSCALL_##name, rettype)                                  \
-    }
-
-#define __LXSYSCALL2(rettype, name, t1, p1, t2, p2)                            \
-    rettype name(__PARAM_MAP2(t1, p1, t2, p2))                                 \
-    {                                                                          \
-        asm("\n" ::"b"(p1), "c"(p2));                                          \
-        ___DOINT33(__SYSCALL_##name, rettype)                                  \
-    }
-
-#define __LXSYSCALL3(rettype, name, t1, p1, t2, p2, t3, p3)                    \
-    rettype name(__PARAM_MAP3(t1, p1, t2, p2, t3, p3))                         \
-    {                                                                          \
-        asm("\n" ::"b"(p1), "c"(p2), "d"(p3));                                 \
-        ___DOINT33(__SYSCALL_##name, rettype)                                  \
-    }
-
-#define __LXSYSCALL4(rettype, name, t1, p1, t2, p2, t3, p3, t4, p4)            \
-    rettype name(__PARAM_MAP4(t1, p1, t2, p2, t3, p3, t4, p4))                 \
-    {                                                                          \
-        asm("\n" ::"b"(p1), "c"(p2), "d"(p3), "D"(p4));                        \
-        ___DOINT33(__SYSCALL_##name, rettype)                                  \
-    }
-
-#define __LXSYSCALL5(rettype, name, t1, p1, t2, p2, t3, p3, t4, p4, t5, p5)    \
-    rettype name(__PARAM_MAP5(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5))         \
-    {                                                                          \
-        asm("" ::"r"(p5), "b"(p1), "c"(p2), "d"(p3), "D"(p4), "S"(p5));        \
-        ___DOINT33(__SYSCALL_##name, rettype)                                  \
-    }
-
-#define __LXSYSCALL2_VARG(rettype, name, t1, p1, t2, p2)                       \
-    __attribute__((noinline)) rettype name(__PARAM_MAP2(t1, p1, t2, p2), ...)  \
-    {                                                                          \
-        /* No inlining! This depends on the call frame assumption */           \
-        void* _last = (void*)&p2 + sizeof(void*);                              \
-        asm("\n" ::"b"(p1), "c"(p2), "d"(_last));                              \
-        ___DOINT33(__SYSCALL_##name, rettype)                                  \
-    }
-
 #endif
 #endif /* __LUNAIX_SYSCALL_H */
index 5a6fb9095839576578065c623d6d164c6c0600a7..fc0ef1ceeedce13b2a66702ba2ae9ffa1877da58 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <stdarg.h>
 #include <stddef.h>
-#include <sys/types.h>
+#include <usr/lunaix/types.h>
 
 #define PACKED __attribute__((packed))
 
similarity index 54%
rename from lunaix-os/usr/includes/sys/lxdirent.h
rename to lunaix-os/includes/usr/lunaix/lxdirent.h
index e616180a5fc9b1d4b68845480fec8be9331964bb..6793d9968589c34a8816969eeba57b8e746056c0 100644 (file)
@@ -1,9 +1,8 @@
 #ifndef __LUNAIX_SYS_LXDIRENT_H
 #define __LUNAIX_SYS_LXDIRENT_H
 
-#include <sys/dirent_defs.h>
+#include <lunaix/dirent_defs.h>
 
-int
-sys_readdir(int fd, struct lx_dirent* dirent);
+int sys_readdir(int fd, struct lx_dirent* dirent);
 
 #endif /* __LUNAIX_DIRENT_H */
similarity index 64%
rename from lunaix-os/usr/includes/errno.h
rename to lunaix-os/includes/usr/lunaix/status.h
index f3c5347f87666e9e6c55f3ccf5e34bc6b8fc617e..504584beef027ba40ca285d3b3c26be14b112141 100644 (file)
@@ -1,8 +1,15 @@
-#ifndef __LUNAIX_SYS_ERRNO_H
-#define __LUNAIX_SYS_ERRNO_H
+#ifndef __LUNAIX_STATUS_H
+#define __LUNAIX_STATUS_H
 
+#define LXPROCFULL -(1)
+#define LXHEAPFULL -(2)
+#define LXINVLDPTR -(2)
+#define LXOUTOFMEM -(3)
+#define LXSEGFAULT -(5)
 #define EINVAL -(6)
+
 #define EINTR -(7)
+
 #define EMFILE -8
 #define ENOENT -9
 #define ENAMETOOLONG -10
 #define EXDEV -21
 #define ENODEV -22
 #define ERANGE -23
-#define ENOMEM -(3)
+#define ENOMEM LXOUTOFMEM
 #define ENOTDEV -24
 #define EOVERFLOW -25
 #define ENOTBLK -26
 #define ENOEXEC -27
 #define E2BIG -28
+#define ELIBBAD -29
 
-int
-geterrno();
-
-#define errno (geterrno())
-
-#endif /* __LUNAIX_ERRNO_H */
+#endif /* __LUNAIX_STATUS_H */
diff --git a/lunaix-os/includes/usr/lunaix/syscallid.h b/lunaix-os/includes/usr/lunaix/syscallid.h
new file mode 100644 (file)
index 0000000..cc7ac7a
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef __LUNAIX_SYSCALLID_H
+#define __LUNAIX_SYSCALLID_H
+
+#define __SYSCALL_fork 1
+#define __SYSCALL_yield 2
+#define __SYSCALL_sbrk 3
+#define __SYSCALL_brk 4
+#define __SYSCALL_getpid 5
+#define __SYSCALL_getppid 6
+#define __SYSCALL_sleep 7
+#define __SYSCALL__exit 8
+#define __SYSCALL_wait 9
+#define __SYSCALL_waitpid 10
+
+#define __SYSCALL_sigreturn 11
+#define __SYSCALL_sigprocmask 12
+#define __SYSCALL_signal 13
+#define __SYSCALL_pause 14
+#define __SYSCALL_kill 15
+#define __SYSCALL_alarm 16
+#define __SYSCALL_sigpending 17
+#define __SYSCALL_sigsuspend 18
+#define __SYSCALL_open 19
+#define __SYSCALL_close 20
+
+#define __SYSCALL_read 21
+#define __SYSCALL_write 22
+#define __SYSCALL_sys_readdir 23
+#define __SYSCALL_mkdir 24
+#define __SYSCALL_lseek 25
+#define __SYSCALL_geterrno 26
+#define __SYSCALL_readlink 27
+#define __SYSCALL_readlinkat 28
+#define __SYSCALL_rmdir 29
+
+#define __SYSCALL_unlink 30
+#define __SYSCALL_unlinkat 31
+#define __SYSCALL_link 32
+#define __SYSCALL_fsync 33
+#define __SYSCALL_dup 34
+#define __SYSCALL_dup2 35
+#define __SYSCALL_realpathat 36
+#define __SYSCALL_symlink 37
+#define __SYSCALL_chdir 38
+#define __SYSCALL_fchdir 39
+#define __SYSCALL_getcwd 40
+#define __SYSCALL_rename 41
+#define __SYSCALL_mount 42
+#define __SYSCALL_unmount 43
+#define __SYSCALL_getxattr 44
+#define __SYSCALL_setxattr 45
+#define __SYSCALL_fgetxattr 46
+#define __SYSCALL_fsetxattr 47
+
+#define __SYSCALL_ioctl 48
+#define __SYSCALL_getpgid 49
+#define __SYSCALL_setpgid 50
+
+#define __SYSCALL_syslog 51
+
+#define __SYSCALL_sys_mmap 52
+#define __SYSCALL_munmap 53
+
+#define __SYSCALL_execve 54
+
+#define __SYSCALL_MAX 0x100
+
+#endif /* __LUNAIX_SYSCALLID_H */
index 867f93d1ca76891deb65d24f33b1c65fe6fea7d4..fdb8b4720d9b705282954e4003b653d6ce0c92a3 100644 (file)
@@ -3,7 +3,7 @@
 #include <lunaix/fs/devfs.h>
 #include <lunaix/spike.h>
 
-#include <sys/dirent_defs.h>
+#include <usr/lunaix/dirent_defs.h>
 
 extern struct v_inode_ops devfs_inode_ops;
 extern struct v_file_ops devfs_file_ops;
index 76262d2f5a5a53d64ec4542c1dca1340d51e00cf..5a06fc8b39eab5308d975ee4565359e0d0a6e530 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <klibc/string.h>
 
-#include <sys/dirent_defs.h>
+#include <usr/lunaix/dirent_defs.h>
 
 extern struct cake_pile* drec_cache_pile;
 
index 988be639b242c4e048948c96fb4e3a5436baa20c..3197a5b05a4476e39066ec1c24bdf5f6b9d13cd2 100644 (file)
@@ -56,7 +56,7 @@
 
 #include <lunaix/fs/twifs.h>
 
-#include <sys/dirent_defs.h>
+#include <usr/lunaix/dirent_defs.h>
 
 static struct cake_pile* dnode_pile;
 static struct cake_pile* inode_pile;
index ca7f61e13c8dfabeb62af094b8cc9fa371068e2f..6ecdc8f5d1db17e95bf6d3899a4b9ef984cca22a 100644 (file)
@@ -7,7 +7,7 @@
 #include <klibc/stdio.h>
 #include <klibc/string.h>
 
-#include <sys/dirent_defs.h>
+#include <usr/lunaix/dirent_defs.h>
 
 #define COUNTER_MASK ((1 << 16) - 1)
 
diff --git a/lunaix-os/makefile.prog b/lunaix-os/makefile.prog
deleted file mode 100644 (file)
index 2c8b8e7..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-include config/make-locations
-include config/make-os
-include config/make-cc
-
-SRC_FILES := $(wildcard uprog/*.c)
-PROGRAMES := $(patsubst uprog/%.c, $(USR_DIR)/%, $(SRC_FILES))
-
-$(USR_DIR)/%:
-       @echo "  BUILD   $(*F)"
-       @$(CC) -T usr/link-usr.ld $(INCLUDES) $(CFLAGS) -g $(LDFLAGS) uprog/$(*F).c $(BIN_DIR)/$(USR_LIB) -o $@
-
-all: $(PROGRAMES)
\ No newline at end of file
diff --git a/lunaix-os/makefile.usr b/lunaix-os/makefile.usr
deleted file mode 100644 (file)
index 7cbec35..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-include config/make-cc
-include config/make-os
-include config/make-locations
-
-SRC_DIRS := usr
-
-SRC_FILES := $(foreach f, $(SRC_DIRS), $(shell find $(f) -name "*.[cS]"))
-
-OBJS := $(foreach f, $(SRC_FILES), $(OBJECT_DIR)/$(f).o)
-
-$(OBJECT_DIR)/%.S.o: %.S
-       @mkdir -p $(@D)
-       @echo "  CC    $<"
-       @$(CC) $(INCLUDES) -c $< -o $@
-
-$(OBJECT_DIR)/%.c.o: %.c 
-       @mkdir -p $(@D)
-       @echo "  CC    $<"
-       @$(CC) $(INCLUDES) $(CFLAGS) -g -c $< -o $@ 
-
-$(BIN_DIR)/$(USR_LIB): $(OBJS)
-       @echo "  AR    $@"
-       @$(AR) rcs $@ $^
-
-usr-runtime: $(BIN_DIR)/$(USR_LIB)
-
-usr-runtime-debug: O := -Og
-usr-runtime-debug: CFLAGS := -g -std=gnu99 -ffreestanding $(O) $(W) $(ARCH_OPT) -D__LUNAIXOS_DEBUG__
-usr-runtime-debug: LDFLAGS := -g -ffreestanding $(O) -nostdlib -lgcc
-usr-runtime-debug: usr-runtime
-
-usr-objs: $(OBJS)
\ No newline at end of file
diff --git a/lunaix-os/makeinc/os.mkinc b/lunaix-os/makeinc/os.mkinc
new file mode 100644 (file)
index 0000000..1a8ac15
--- /dev/null
@@ -0,0 +1,18 @@
+OS_ARCH := x86
+OS_NAME := lunaix
+OS_ID := LunaixOS
+OS_VER := dev$(shell date +%Y%m%d)
+OS_BIN := $(OS_NAME).bin
+OS_ISO := $(OS_NAME).iso
+
+USR_LIB := liblxusrt.a
+
+BUILD_DIR := build
+KERNEL_DIR := kernel
+OBJECT_DIR := $(BUILD_DIR)/obj
+BIN_DIR := $(BUILD_DIR)/bin
+ISO_DIR := $(BUILD_DIR)/iso
+ISO_BOOT_DIR := $(ISO_DIR)/boot
+ISO_GRUB_DIR := $(ISO_BOOT_DIR)/grub
+
+INCLUDES := -Iincludes -Iincludes/usr
\ No newline at end of file
similarity index 85%
rename from lunaix-os/config/make-cc
rename to lunaix-os/makeinc/toolchain.mkinc
index 75b37f887688cc41a429f1ea525355c5aecc925e..42fae9fa3dfc36c517946950fd5b0cb259dcb9b4 100644 (file)
@@ -3,7 +3,7 @@ AS := i686-elf-as
 AR := i686-elf-ar
 
 
-ARCH_OPT := -D__ARCH_IA32 -include flags.h
+ARCH_OPT := -D__ARCH_IA32
 O := -O2
 W := -Wall -Wextra -Wno-unknown-pragmas \
                -Wno-unused-function \
@@ -24,4 +24,6 @@ OFLAGS := -fno-gcse\
                  -fno-indirect-inlining
 
 CFLAGS := -std=gnu99 -ffreestanding $(O) $(OFLAGS) $(W) $(ARCH_OPT)
-LDFLAGS := -ffreestanding $(O) -nostdlib -lgcc
\ No newline at end of file
+LDFLAGS := -ffreestanding $(O) -nostdlib -lgcc
+
+MKFLAGS := --no-print-directory
\ No newline at end of file
diff --git a/lunaix-os/makeinc/utils.mkinc b/lunaix-os/makeinc/utils.mkinc
new file mode 100644 (file)
index 0000000..3975605
--- /dev/null
@@ -0,0 +1,4 @@
+status = @printf "  %-8s %s\n" $(1) $(2)
+status_ := @printf "  %-8s %s\n" $$(1) $$(2)
+
+export status_
diff --git a/lunaix-os/uprog/includes/ld/elf.h b/lunaix-os/uprog/includes/ld/elf.h
new file mode 100644 (file)
index 0000000..c699605
--- /dev/null
@@ -0,0 +1,67 @@
+#ifndef __LUNAIX_LD_ELF_H
+#define __LUNAIX_LD_ELF_H
+
+typedef unsigned int elf32_ptr_t;
+typedef unsigned short elf32_hlf_t;
+typedef unsigned int elf32_off_t;
+typedef unsigned int elf32_swd_t;
+typedef unsigned int elf32_wrd_t;
+
+#define ET_NONE 0
+#define ET_EXEC 2
+#define ET_DYN 3
+
+#define PT_LOAD 1
+#define PT_DYNAMIC 2
+#define PT_INTERP 3
+
+#define PF_X 0x1
+#define PF_W 0x2
+#define PF_R 0x4
+
+#define EM_NONE 0
+#define EM_386 3
+
+#define EV_CURRENT 1
+
+// [0x7f, 'E', 'L', 'F']
+#define ELFMAGIC 0x464c457fU
+#define ELFCLASS32 1
+#define ELFCLASS64 2
+#define ELFDATA2LSB 1
+#define ELFDATA2MSB 2
+
+#define EI_CLASS 4
+#define EI_DATA 5
+
+struct elf32_ehdr
+{
+  unsigned char e_ident[16];
+  elf32_hlf_t e_type;
+  elf32_hlf_t e_machine;
+  elf32_wrd_t e_version;
+  elf32_ptr_t e_entry;
+  elf32_off_t e_phoff;
+  elf32_off_t e_shoff;
+  elf32_wrd_t e_flags;
+  elf32_hlf_t e_ehsize;
+  elf32_hlf_t e_phentsize;
+  elf32_hlf_t e_phnum;
+  elf32_hlf_t e_shentsize;
+  elf32_hlf_t e_shnum;
+  elf32_hlf_t e_shstrndx;
+};
+
+struct elf32_phdr
+{
+  elf32_wrd_t p_type;
+  elf32_off_t p_offset;
+  elf32_ptr_t p_va;
+  elf32_ptr_t p_pa;
+  elf32_wrd_t p_filesz;
+  elf32_wrd_t p_memsz;
+  elf32_wrd_t p_flags;
+  elf32_wrd_t p_align;
+};
+
+#endif /* __LUNAIX_ELF_H */
diff --git a/lunaix-os/usr/api/errno.c b/lunaix-os/usr/api/errno.c
deleted file mode 100644 (file)
index ac0d004..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#include <lunaix/syscall.h>
-#include <errno.h>
-
-__LXSYSCALL(int, geterrno);
\ No newline at end of file
diff --git a/lunaix-os/usr/api/ioctl.c b/lunaix-os/usr/api/ioctl.c
deleted file mode 100644 (file)
index bb2126a..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#include <lunaix/syscall.h>
-#include <sys/ioctl.h>
-
-__LXSYSCALL2_VARG(int, ioctl, int, fd, int, req);
\ No newline at end of file
diff --git a/lunaix-os/usr/includes b/lunaix-os/usr/includes
new file mode 120000 (symlink)
index 0000000..6e4b52e
--- /dev/null
@@ -0,0 +1 @@
+../includes/usr
\ No newline at end of file
diff --git a/lunaix-os/usr/includes/string.h b/lunaix-os/usr/includes/string.h
deleted file mode 100644 (file)
index 7383a0f..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef __LUNAIX_STRING_H
-#define __LUNAIX_STRING_H
-
-#include <stddef.h>
-
-size_t
-strlen(const char* str);
-
-size_t
-strnlen(const char* str, size_t max_len);
-
-char*
-strncpy(char* dest, const char* src, size_t n);
-
-const char*
-strchr(const char* str, int character);
-
-char*
-strcpy(char* dest, const char* src);
-
-int
-strcmp(const char* s1, const char* s2);
-
-#endif /* __LUNAIX_STRING_H */
diff --git a/lunaix-os/usr/includes/sys/mann.h b/lunaix-os/usr/includes/sys/mann.h
deleted file mode 100644 (file)
index 0e424d4..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef __LUNAIX_SYS_MANN_H
-#define __LUNAIX_SYS_MANN_H
-
-#include <sys/mann_flags.h>
-#include <sys/types.h>
-
-void*
-mmap(void* addr, size_t length, int proct, int flags, int fd, off_t offset);
-
-void
-munmap(void* addr, size_t length);
-
-#endif /* __LUNAIX_MANN_H */
diff --git a/lunaix-os/usr/includes/sys/mount.h b/lunaix-os/usr/includes/sys/mount.h
deleted file mode 100644 (file)
index 5d12df8..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef __LUNAIX_SYS_MOUNT_H
-#define __LUNAIX_SYS_MOUNT_H
-
-#include <sys/types.h>
-
-int
-mount(const char* source, const char* target, const char* fstype, int flags);
-
-int
-unmount(const char* target);
-
-static inline int
-umount(const char* target)
-{
-    return unmount(target);
-}
-#endif /* __LUNAIX_MOUNT_H */
similarity index 96%
rename from lunaix-os/uprog/init.c
rename to lunaix-os/usr/init/init.c
index b78cd3b360c293a055fbb4db217da3ff2eacfb29..7e1785a4948f985740f6de49ae832c16464fa95d 100644 (file)
@@ -1,7 +1,7 @@
 #include <errno.h>
 #include <fcntl.h>
+#include <lunaix/lunaix.h>
 #include <stdio.h>
-#include <sys/lunaix.h>
 #include <unistd.h>
 
 int
diff --git a/lunaix-os/usr/init/makefile b/lunaix-os/usr/init/makefile
new file mode 100644 (file)
index 0000000..e087160
--- /dev/null
@@ -0,0 +1,21 @@
+define src_files
+       init.c
+endef
+
+obj_files := $(addsuffix .o,$(src_files))
+include_opt := $(addprefix -I,$(INCLUDES))
+
+out := $(BUILD_DIR)/bin
+
+%.c.o: %.c
+       $(call status_,CC,$<)
+       @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
+
+$(out)/$(BUILD_NAME): $(obj_files)
+       $(call status_,LD,$(@F))
+       @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
+
+all: $(out)/$(BUILD_NAME)
+
+clean:
+       @rm -f $(obj_files)
\ No newline at end of file
similarity index 62%
rename from lunaix-os/usr/uwrap.S
rename to lunaix-os/usr/libc/arch/i386/crt0.S
index 84fe24ec0183eda8dde63fbe8a4f60da8275c4c2..28aa6ba05374b96898124bb6e5e09c5d13189fa8 100644 (file)
@@ -1,5 +1,5 @@
 #define __ASM__
-#include <lunaix/syscall.h>
+#include <lunaix/syscallid.h>
 
 .section .data
     .global environ
@@ -7,14 +7,14 @@
         .long 0
 
 .section .text
-    .global _u_start
-    _u_start:        
+    .global _start
+    _start:        
         xorl %eax, %eax
         call main
         
     1:
         movl %eax, %ebx
         movl $__SYSCALL__exit, %eax
-        int $LUNAIX_SYS_CALL
+        int $33
 
         ud2 // should not reach
\ No newline at end of file
similarity index 55%
rename from lunaix-os/usr/api/dirent.c
rename to lunaix-os/usr/libc/arch/i386/dirent.c
index e309582a15448924ae7b17dcf0ada7f51a0467ca..1c45242dcbff34ba28e7cf5de47ced2fd2b1bd74 100644 (file)
@@ -1,4 +1,4 @@
-#include <lunaix/syscall.h>
-#include <sys/lxdirent.h>
+#include "syscall.h"
+#include <lunaix/dirent_defs.h>
 
 __LXSYSCALL2(int, sys_readdir, int, fd, struct lx_dirent*, dent)
diff --git a/lunaix-os/usr/libc/arch/i386/errno.c b/lunaix-os/usr/libc/arch/i386/errno.c
new file mode 100644 (file)
index 0000000..3ad6d52
--- /dev/null
@@ -0,0 +1,4 @@
+#include "syscall.h"
+#include <errno.h>
+
+__LXSYSCALL(int, geterrno);
\ No newline at end of file
similarity index 73%
rename from lunaix-os/usr/api/fcntl.c
rename to lunaix-os/usr/libc/arch/i386/fcntl.c
index 92e2fa3960ea6781898e6bcfc5d68445686d7a13..5f28766c2663455c6dd65341dfaaf70a68f1c71c 100644 (file)
@@ -1,4 +1,4 @@
-#include <lunaix/syscall.h>
+#include "syscall.h"
 #include <fcntl.h>
 
 __LXSYSCALL2(int, open, const char*, path, int, options)
diff --git a/lunaix-os/usr/libc/arch/i386/ioctl.c b/lunaix-os/usr/libc/arch/i386/ioctl.c
new file mode 100644 (file)
index 0000000..8675d22
--- /dev/null
@@ -0,0 +1,4 @@
+#include "syscall.h"
+#include <lunaix/ioctl.h>
+
+__LXSYSCALL2_VARG(int, ioctl, int, fd, int, req);
\ No newline at end of file
similarity index 83%
rename from lunaix-os/usr/api/lunaix.c
rename to lunaix-os/usr/libc/arch/i386/lunaix.c
index 59fe79a2beb9e5b3598bb69b21c010c8257d4989..87f30bb02c6c5a4a18536bbe4e86f309a6fed0f3 100644 (file)
@@ -1,5 +1,5 @@
-#include <lunaix/syscall.h>
-#include <sys/lunaix.h>
+#include "syscall.h"
+#include <lunaix/types.h>
 
 __LXSYSCALL(void, yield);
 
similarity index 84%
rename from lunaix-os/usr/api/mann.c
rename to lunaix-os/usr/libc/arch/i386/mann.c
index e211cad43557c682ef7f51023a77a6d3d4ee9fe4..b21ea3fd9b06fe6f4c659535de267649c0db01b1 100644 (file)
@@ -1,5 +1,5 @@
-#include <lunaix/syscall.h>
-#include <sys/mann.h>
+#include "syscall.h"
+#include <lunaix/types.h>
 
 __LXSYSCALL2_VARG(void*, sys_mmap, void*, addr, size_t, length);
 
similarity index 69%
rename from lunaix-os/usr/api/mount.c
rename to lunaix-os/usr/libc/arch/i386/mount.c
index 854c96be46c6def80877a78e828f5f75ef46dd4b..637f451ce8eeaf7cf1b63b2cbfa36f57520e54d9 100644 (file)
@@ -1,5 +1,4 @@
-#include <lunaix/syscall.h>
-#include <sys/mount.h>
+#include "syscall.h"
 
 __LXSYSCALL4(int,
              mount,
similarity index 86%
rename from lunaix-os/usr/api/signal.c
rename to lunaix-os/usr/libc/arch/i386/signal.c
index 191e8d868220c00300cafff7faa8512c2fc69959..681f193100c42dc7d8d817cbf1a631bca37b19bb 100644 (file)
@@ -1,5 +1,5 @@
-#include <lunaix/syscall.h>
-#include <signal.h>
+#include "syscall.h"
+#include <lunaix/signal_defs.h>
 
 __LXSYSCALL2(int, signal, int, signum, sighandler_t, handler);
 
diff --git a/lunaix-os/usr/libc/arch/i386/syscall.h b/lunaix-os/usr/libc/arch/i386/syscall.h
new file mode 100644 (file)
index 0000000..4747678
--- /dev/null
@@ -0,0 +1,69 @@
+#ifndef __LUNAIX_SYSCALL_H
+#define __LUNAIX_SYSCALL_H
+#include <lunaix/syscallid.h>
+
+#define asmlinkage __attribute__((regparm(0)))
+
+#define __PARAM_MAP1(t1, p1) t1 p1
+#define __PARAM_MAP2(t1, p1, ...) t1 p1, __PARAM_MAP1(__VA_ARGS__)
+#define __PARAM_MAP3(t1, p1, ...) t1 p1, __PARAM_MAP2(__VA_ARGS__)
+#define __PARAM_MAP4(t1, p1, ...) t1 p1, __PARAM_MAP3(__VA_ARGS__)
+#define __PARAM_MAP5(t1, p1, ...) t1 p1, __PARAM_MAP4(__VA_ARGS__)
+#define __PARAM_MAP6(t1, p1, ...) t1 p1, __PARAM_MAP5(__VA_ARGS__)
+
+#define ___DOINT33(callcode, rettype)                                          \
+    int v;                                                                     \
+    asm volatile("int %1\n" : "=a"(v) : "i"(33), "a"(callcode));               \
+    return (rettype)v;
+
+#define __LXSYSCALL(rettype, name)                                             \
+    rettype name()                                                             \
+    {                                                                          \
+        ___DOINT33(__SYSCALL_##name, rettype)                                  \
+    }
+
+#define __LXSYSCALL1(rettype, name, t1, p1)                                    \
+    rettype name(__PARAM_MAP1(t1, p1))                                         \
+    {                                                                          \
+        asm("" ::"b"(p1));                                                     \
+        ___DOINT33(__SYSCALL_##name, rettype)                                  \
+    }
+
+#define __LXSYSCALL2(rettype, name, t1, p1, t2, p2)                            \
+    rettype name(__PARAM_MAP2(t1, p1, t2, p2))                                 \
+    {                                                                          \
+        asm("\n" ::"b"(p1), "c"(p2));                                          \
+        ___DOINT33(__SYSCALL_##name, rettype)                                  \
+    }
+
+#define __LXSYSCALL3(rettype, name, t1, p1, t2, p2, t3, p3)                    \
+    rettype name(__PARAM_MAP3(t1, p1, t2, p2, t3, p3))                         \
+    {                                                                          \
+        asm("\n" ::"b"(p1), "c"(p2), "d"(p3));                                 \
+        ___DOINT33(__SYSCALL_##name, rettype)                                  \
+    }
+
+#define __LXSYSCALL4(rettype, name, t1, p1, t2, p2, t3, p3, t4, p4)            \
+    rettype name(__PARAM_MAP4(t1, p1, t2, p2, t3, p3, t4, p4))                 \
+    {                                                                          \
+        asm("\n" ::"b"(p1), "c"(p2), "d"(p3), "D"(p4));                        \
+        ___DOINT33(__SYSCALL_##name, rettype)                                  \
+    }
+
+#define __LXSYSCALL5(rettype, name, t1, p1, t2, p2, t3, p3, t4, p4, t5, p5)    \
+    rettype name(__PARAM_MAP5(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5))         \
+    {                                                                          \
+        asm("" ::"r"(p5), "b"(p1), "c"(p2), "d"(p3), "D"(p4), "S"(p5));        \
+        ___DOINT33(__SYSCALL_##name, rettype)                                  \
+    }
+
+#define __LXSYSCALL2_VARG(rettype, name, t1, p1, t2, p2)                       \
+    __attribute__((noinline)) rettype name(__PARAM_MAP2(t1, p1, t2, p2), ...)  \
+    {                                                                          \
+        /* No inlining! This depends on the call frame assumption */           \
+        void* _last = (void*)&p2 + sizeof(void*);                              \
+        asm("\n" ::"b"(p1), "c"(p2), "d"(_last));                              \
+        ___DOINT33(__SYSCALL_##name, rettype)                                  \
+    }
+
+#endif /* __LUNAIX_SYSCALL_H */
similarity index 97%
rename from lunaix-os/usr/api/unistd.c
rename to lunaix-os/usr/libc/arch/i386/unistd.c
index 088c33582b78da9602279980b25847d3a2c780eb..9790cb188f8ab37b424bd0e5f6939ed5ec00b96f 100644 (file)
@@ -1,5 +1,5 @@
-#include <lunaix/syscall.h>
-#include <unistd.h>
+#include "syscall.h"
+#include <lunaix/types.h>
 
 __LXSYSCALL(pid_t, fork)
 
similarity index 68%
rename from lunaix-os/usr/includes/dirent.h
rename to lunaix-os/usr/libc/includes/dirent.h
index 78d57e3bb3835b36309e52d3a7676b88aff68110..9748c8c90d3206bed5e1de29028f006e02c2b657 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_SYS_DIRENT_H
 #define __LUNAIX_SYS_DIRENT_H
 
-#include <sys/dirent_defs.h>
+#include <lunaix/dirent_defs.h>
 
 typedef struct
 {
@@ -15,13 +15,16 @@ struct dirent
     char d_name[256];
 };
 
-DIR*
+extern DIR*
 opendir(const char* dirp);
 
-int
+extern int
 closedir(DIR* dirp);
 
-struct dirent*
+extern struct dirent*
 readdir(DIR* dir);
 
+extern int
+sys_readdir(int fd, struct lx_dirent* dirent);
+
 #endif /* __LUNAIX_DIRENT_H */
diff --git a/lunaix-os/usr/libc/includes/errno.h b/lunaix-os/usr/libc/includes/errno.h
new file mode 100644 (file)
index 0000000..4377190
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __LUNAIX_SYS_ERRNO_H
+#define __LUNAIX_SYS_ERRNO_H
+
+#include <lunaix/status.h>
+
+extern int geterrno();
+
+#define errno (geterrno())
+
+#endif /* __LUNAIX_ERRNO_H */
similarity index 64%
rename from lunaix-os/usr/includes/fcntl.h
rename to lunaix-os/usr/libc/includes/fcntl.h
index 0ce31d8115fb685d006fe394557b117fe349dd78..b013d70d9f0c1a602ef671024d997cd0559ae6b7 100644 (file)
@@ -1,10 +1,10 @@
 #ifndef __LUNAIX_SYS_FCNTL_H
 #define __LUNAIX_SYS_FCNTL_H
 
-#include <fcntl_defs.h>
-#include <sys/types.h>
+#include <lunaix/fcntl_defs.h>
+#include <lunaix/types.h>
 
-int
+extern int
 open(const char* path, int flags);
 
 #endif /* __LUNAIX_FCNTL_H */
similarity index 58%
rename from lunaix-os/usr/includes/sys/ioctl.h
rename to lunaix-os/usr/libc/includes/lunaix/ioctl.h
index 58c681a9720b42bf4cde63b9b6d0d60fd65d05dd..b185ac27d301590e098dce00f3f2cfa8c2ebce04 100644 (file)
@@ -1,9 +1,8 @@
 #ifndef __LUNAIX_SYS_IOCTL_H
 #define __LUNAIX_SYS_IOCTL_H
 
-#include <sys/ioctl_defs.h>
+#include <lunaix/ioctl_defs.h>
 
-int
-ioctl(int fd, int req, ...);
+int ioctl(int fd, int req, ...);
 
 #endif /* __LUNAIX_IOCTL_H */
similarity index 91%
rename from lunaix-os/usr/includes/sys/lunaix.h
rename to lunaix-os/usr/libc/includes/lunaix/lunaix.h
index febcb59c3c8f355ad6c76b71a1b2475182101eb4..172056cf4b3900d0a7876a9af62ffd29141e18dd 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __LUNAIX_SYS_LUNAIX_H
 #define __LUNAIX_SYS_LUNAIX_H
 
-#include <sys/types.h>
+#include <lunaix/types.h>
 
 void
 yield();
diff --git a/lunaix-os/usr/libc/includes/lunaix/mann.h b/lunaix-os/usr/libc/includes/lunaix/mann.h
new file mode 100644 (file)
index 0000000..1e79912
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __LUNAIX_SYS_MANN_H
+#define __LUNAIX_SYS_MANN_H
+
+#include <lunaix/mann_flags.h>
+#include <lunaix/types.h>
+
+extern void* mmap(void* addr, size_t length, int proct, int flags, int fd, off_t offset);
+
+extern void munmap(void* addr, size_t length);
+
+#endif /* __LUNAIX_MANN_H */
diff --git a/lunaix-os/usr/libc/includes/lunaix/mount.h b/lunaix-os/usr/libc/includes/lunaix/mount.h
new file mode 100644 (file)
index 0000000..4f41c70
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __LUNAIX_SYS_MOUNT_H
+#define __LUNAIX_SYS_MOUNT_H
+
+#include <lunaix/types.h>
+
+extern int mount(const char* source, const char* target, const char* fstype, int flags);
+
+extern int unmount(const char* target);
+
+static inline int umount(const char* target)
+{
+  return unmount(target);
+}
+#endif /* __LUNAIX_MOUNT_H */
similarity index 71%
rename from lunaix-os/usr/includes/signal.h
rename to lunaix-os/usr/libc/includes/signal.h
index 56da91e9a9bd3f322044176d8d9b5811c346400a..0e6cce2b31b10e32dcbeb6d055553ace470e187a 100644 (file)
@@ -1,19 +1,19 @@
 #ifndef __LUNAIX_SYS_SIGNAL_H
 #define __LUNAIX_SYS_SIGNAL_H
 
-#include <signal_defs.h>
-#include <sys/types.h>
+#include <lunaix/signal_defs.h>
+#include <lunaix/types.h>
 
-int
+extern int
 signal(int signum, sighandler_t handler);
 
-int
+extern int
 sigpending(sigset_t* set);
 
-int
+extern int
 sigsuspend(const sigset_t* mask);
 
-int
+extern int
 sigprocmask(int how, const sigset_t* set, sigset_t* oldset);
 
 #endif /* __LUNAIX_SIGNAL_H */
similarity index 93%
rename from lunaix-os/usr/includes/stdio.h
rename to lunaix-os/usr/libc/includes/stdio.h
index 0ef2e146fa2211b1a2fee357c7cb9e2271ea4e6e..26c9b56ba1836245ff40a3c534dc11828dea345b 100644 (file)
@@ -4,7 +4,7 @@
 #define stdout 0
 #define stdin 1
 
-int
+extern int
 printf(const char* fmt, ...);
 
 #endif /* __LUNAIX_USTDIO_H */
similarity index 62%
rename from lunaix-os/usr/includes/stdlib.h
rename to lunaix-os/usr/libc/includes/stdlib.h
index 0e38fb52fa0df9830fbc5775680817005f7f0259..72bd6636d079f81511cf0175e531eeb52cb517ff 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef __LUNAIX_STDLIB_H
 #define __LUNAIX_STDLIB_H
 
-char*
-itoa(int value, char* str, int base);
+extern char* itoa(int value, char* str, int base);
 
 #endif /* __LUNAIX_STDLIB_H */
diff --git a/lunaix-os/usr/libc/includes/string.h b/lunaix-os/usr/libc/includes/string.h
new file mode 100644 (file)
index 0000000..e9313b7
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef __LUNAIX_STRING_H
+#define __LUNAIX_STRING_H
+
+#include <stddef.h>
+
+extern size_t strlen(const char* str);
+
+extern size_t strnlen(const char* str, size_t max_len);
+
+extern char* strncpy(char* dest, const char* src, size_t n);
+
+extern const char* strchr(const char* str, int character);
+
+extern char* strcpy(char* dest, const char* src);
+
+extern int strcmp(const char* s1, const char* s2);
+
+#endif /* __LUNAIX_STRING_H */
similarity index 75%
rename from lunaix-os/usr/includes/unistd.h
rename to lunaix-os/usr/libc/includes/unistd.h
index 8420ffac3954cc93443eaf37f67e03e4510149c1..24e519f9757d4b37444c13f78868a3f60e8cd226 100644 (file)
 #ifndef __LUNAIX_SYS_UNISTD_H
 #define __LUNAIX_SYS_UNISTD_H
 
-#include <sys/types.h>
+#include <lunaix/types.h>
 
 extern const char** environ;
 
-pid_t
+extern pid_t
 fork();
 
-pid_t
+extern pid_t
 getpid();
 
-pid_t
+extern pid_t
 getppid();
 
-pid_t
+extern pid_t
 getpgid();
 
-pid_t
+extern pid_t
 setpgid(pid_t pid, pid_t pgid);
 
-int
+extern int
 brk(void* addr);
 
-void*
+extern void*
 sbrk(ssize_t size);
 
-void
+extern void
 _exit(int status);
 
-unsigned int
+extern unsigned int
 sleep(unsigned int);
 
-int
+extern int
 pause();
 
-int
+extern int
 kill(pid_t pid, int signum);
 
-unsigned int
+extern unsigned int
 alarm(unsigned int seconds);
 
-int
+extern int
 link(const char* oldpath, const char* newpath);
 
-int
+extern int
 rmdir(const char* pathname);
 
-int
+extern int
 read(int fd, void* buf, size_t size);
 
-int
+extern int
 write(int fd, void* buf, size_t size);
 
-int
+extern int
 readlink(const char* path, char* buffer, size_t size);
 
-int
+extern int
 readlinkat(int dirfd, const char* pathname, char* buffer, size_t size);
 
-int
+extern int
 lseek(int fd, off_t offset, int mode);
 
-int
+extern int
 unlink(const char* pathname);
 
-int
+extern int
 unlinat(int fd, const char* pathname);
 
-int
+extern int
 mkdir(const char* path);
 
-int
+extern int
 close(int fd);
 
-int
+extern int
 dup2(int oldfd, int newfd);
 
-int
+extern int
 dup(int oldfd);
 
-int
+extern int
 fsync(int fd);
 
-int
+extern int
 symlink(const char* pathname, const char* linktarget);
 
-int
+extern int
 chdir(const char* path);
 
-int
+extern int
 fchdir(int fd);
 
-char*
+extern char*
 getcwd(char* buf, size_t size);
 
-int
+extern int
 rename(const char* oldpath, const char* newpath);
 
-int
+extern int
 getxattr(const char* path, const char* name, void* value, size_t len);
 
-int
+extern int
 setxattr(const char* path, const char* name, void* value, size_t len);
 
-int
+extern int
 fgetxattr(int fd, const char* name, void* value, size_t len);
 
-int
+extern int
 fsetxattr(int fd, const char* name, void* value, size_t len);
 
-int
+extern int
 execve(const char* filename, const char* argv[], const char* envp[]);
 
 #endif /* __LUNAIX_UNISTD_H */
diff --git a/lunaix-os/usr/libc/makefile b/lunaix-os/usr/libc/makefile
new file mode 100644 (file)
index 0000000..3d976cb
--- /dev/null
@@ -0,0 +1,50 @@
+libc_include := $(CURDIR)/includes
+
+ARCH ?= i386
+BUILD_DIR ?= bin
+BUILD_NAME ?= liblunac
+
+src_dirs := src
+src_dirs += arch/$(ARCH)
+
+src_files := $(foreach f, $(src_dirs), $(shell find $(f) -name "*.[cS]"))
+obj_files := $(addsuffix .o, $(src_files))
+
+build_lib := $(BUILD_DIR)/lib
+build_include := $(BUILD_DIR)/includes
+
+libc_include_opt = $(addprefix -I, $(libc_include))
+global_include_opt = $(addprefix -I, $(INCLUDES))
+
+check_folders := $(src_dirs)
+check_folders += $(build_lib) $(build_include)
+
+$(BUILD_DIR):
+       @mkdir -p bin
+
+%.check:
+       @if [ ! -d "$*" ]; then \
+               echo "'$*' is not exists" && exit 1;\
+       fi
+
+%.c.o: %.c
+       @$(call status_,CC,$@)
+       @$(CC) $(CFLAGS) $(libc_include_opt) $(global_include_opt) -c $< -o $@
+
+%.S.o: %.S
+       @$(call status_,CC,$@)
+       @$(CC) $(libc_include_opt) $(global_include_opt) -c $< -o $@
+
+$(build_lib)/$(BUILD_NAME): $(obj_files)
+       @$(call status_,AR,$(*F))
+       @$(AR) rcs $@ $^
+
+clean:
+       @rm -f $(obj_files)
+
+headers: $(libc_include)
+       @$(call status_,INSTALL,$(<F))
+       @cp -r $(libc_include)/* $(build_include)/
+
+all: $(addsuffix .check, $(check_folders)) $(build_lib)/$(BUILD_NAME) headers
+       @cp arch/$(ARCH)/crt0.S.o $(build_lib)/crt0.o
\ No newline at end of file
similarity index 96%
rename from lunaix-os/usr/libc/readdir.c
rename to lunaix-os/usr/libc/src/readdir.c
index f8285b88d2293ab5b70fa392ed13101c3f23a58d..d70f22525e13b8ef3c56b2294353ac77906a3cc5 100644 (file)
@@ -1,7 +1,6 @@
 #include <dirent.h>
 #include <fcntl.h>
 #include <string.h>
-#include <sys/lxdirent.h>
 #include <unistd.h>
 
 DIR*
index 49fb4c9b4b38066ffb3796bd55f2d58b420b25b2..c0699391d79cb6558e47b64e1e76f7d016c30c84 100644 (file)
@@ -1,4 +1,4 @@
-ENTRY(_u_start)
+ENTRY(_start)
 
 SECTIONS {
     . = 0x400000;
similarity index 100%
rename from lunaix-os/uprog/ls.c
rename to lunaix-os/usr/ls/ls.c
diff --git a/lunaix-os/usr/ls/makefile b/lunaix-os/usr/ls/makefile
new file mode 100644 (file)
index 0000000..5351d43
--- /dev/null
@@ -0,0 +1,21 @@
+define src_files
+       ls.c
+endef
+
+obj_files := $(addsuffix .o,$(src_files))
+include_opt := $(addprefix -I,$(INCLUDES))
+
+out := $(BUILD_DIR)/bin
+
+%.c.o: %.c
+       $(call status_,CC,$<)
+       @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
+
+$(out)/$(BUILD_NAME): $(obj_files)
+       $(call status_,LD,$(@F))
+       @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
+
+all: $(out)/$(BUILD_NAME)
+
+clean:
+       @rm -f $(obj_files)
\ No newline at end of file
diff --git a/lunaix-os/usr/makefile b/lunaix-os/usr/makefile
new file mode 100644 (file)
index 0000000..942a5e6
--- /dev/null
@@ -0,0 +1,54 @@
+include utils.mkinc
+include toolchain.mkinc
+
+task := all
+
+sys_include := $(CURDIR)/includes
+build_dir := $(CURDIR)/build
+libc_name := liblunac
+libc_files := $(libc_name).a
+
+common_param :=        CC AR INCLUDES BUILD_DIR BUILD_NAME CFLAGS LDFLAGS
+
+INCLUDES := $(sys_include)
+BUILD_DIR := $(build_dir)
+BUILD_NAME := $(libc_name).a
+
+$(build_dir)/bin:
+       @mkdir -p $(build_dir)/bin
+
+$(build_dir)/lib:
+       @mkdir -p $(build_dir)/lib
+
+$(build_dir)/includes:
+       @mkdir -p $(build_dir)/includes
+
+export $(common_param)
+$(build_dir)/$(libc_name).a: $(build_dir)/bin $(build_dir)/lib $(build_dir)/includes
+       $(call status,TASK,$(BUILD_NAME))
+       @$(MAKE) $(MKFLAGS) -C libc/ $(task)
+
+app-list := ls
+app-list += init
+app-list += signal_demo
+app-list += sh
+
+mkapp-list := $(addprefix app-, $(app-list))
+
+export LD_SCRIPT := $(CURDIR)/link-usr.ld
+export LIBC := $(addprefix $(build_dir)/lib/,$(libc_files))
+app-%:
+       $(call status,TASK,$*)
+       @$(MAKE) $(MKFLAGS) -C $* $(task) BUILD_NAME="$*"
+
+app: task := all
+app: INCLUDES += $(build_dir)/includes
+app: $(mkapp-list)
+
+clean: task := clean
+clean: $(mkapp-list)
+       @rm -rf $(build_dir)
+       @$(MAKE) $(MKFLAGS) -C libc/ $(task)
+
+all: task := all
+all: $(build_dir)/$(libc_name).a app
\ No newline at end of file
diff --git a/lunaix-os/usr/sh/makefile b/lunaix-os/usr/sh/makefile
new file mode 100644 (file)
index 0000000..bc10a4d
--- /dev/null
@@ -0,0 +1,21 @@
+define src_files
+       sh.c
+endef
+
+obj_files := $(addsuffix .o,$(src_files))
+include_opt := $(addprefix -I,$(INCLUDES))
+
+out := $(BUILD_DIR)/bin
+
+%.c.o: %.c
+       $(call status_,CC,$<)
+       @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
+
+$(out)/$(BUILD_NAME): $(obj_files)
+       $(call status_,LD,$(@F))
+       @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
+
+all: $(out)/$(BUILD_NAME)
+
+clean:
+       @rm -f $(obj_files)
\ No newline at end of file
similarity index 98%
rename from lunaix-os/uprog/sh.c
rename to lunaix-os/usr/sh/sh.c
index 616fa672ebf65a5797930e05f22a4e49b9a70cc0..8ce8617dfd271f4e6d96ebc749405968cf907408 100644 (file)
@@ -1,9 +1,9 @@
 #include <errno.h>
+#include <lunaix/ioctl.h>
+#include <lunaix/lunaix.h>
 #include <signal.h>
 #include <stdio.h>
 #include <string.h>
-#include <sys/ioctl.h>
-#include <sys/lunaix.h>
 #include <unistd.h>
 
 char pwd[512];
diff --git a/lunaix-os/usr/signal_demo/makefile b/lunaix-os/usr/signal_demo/makefile
new file mode 100644 (file)
index 0000000..1bb1248
--- /dev/null
@@ -0,0 +1,21 @@
+define src_files
+       signal_demo.c
+endef
+
+obj_files := $(addsuffix .o,$(src_files))
+include_opt := $(addprefix -I,$(INCLUDES))
+
+out := $(BUILD_DIR)/bin
+
+%.c.o: %.c
+       $(call status_,CC,$<)
+       @$(CC) $(CFLAGS) $(include_opt) -c $< -o $@
+
+$(out)/$(BUILD_NAME): $(obj_files)
+       $(call status_,LD,$(@F))
+       @$(CC) -T $(LD_SCRIPT) -o $@ $< $(LIBC) $(LDFLAGS)
+
+all: $(out)/$(BUILD_NAME)
+
+clean:
+       @rm -f $(obj_files)
\ No newline at end of file
similarity index 98%
rename from lunaix-os/uprog/signal_demo.c
rename to lunaix-os/usr/signal_demo/signal_demo.c
index 8a9bdc6587bd7a3bd29b462d9adda43db6acf4fc..612e132a6d4aaf2b226b97f6c864f09dc1f6c56a 100644 (file)
@@ -1,6 +1,6 @@
+#include <lunaix/lunaix.h>
 #include <signal.h>
 #include <stdio.h>
-#include <sys/lunaix.h>
 #include <unistd.h>
 
 void