machine/
draft/
iso_inspect/
-unused/
\ No newline at end of file
+unused/
+
+**.o
\ No newline at end of file
"name": "OS-DEV",
"includePath": [
"${workspaceFolder}/includes",
+ "${workspaceFolder}/includes/usr",
"${workspaceFolder}/usr/includes"
],
"compilerArgs": [
+++ /dev/null
-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
+++ /dev/null
-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
#ifndef __LUNAIX_FOPTIONS_H
#define __LUNAIX_FOPTIONS_H
-#include <fcntl_defs.h>
+#include <usr/lunaix/fcntl_defs.h>
#endif /* __LUNAIX_FOPTIONS_H */
#ifndef __LUNAIX_IOCTL_H
#define __LUNAIX_IOCTL_H
-#include <sys/ioctl_defs.h>
+#include <usr/lunaix/ioctl_defs.h>
#endif /* __LUNAIX_IOCTL_H */
#include <lunaix/fs.h>
#include <lunaix/types.h>
-#include <sys/mann_flags.h>
+#include <usr/lunaix/mann_flags.h>
/**
* @brief 私有区域,该区域中的页无法进行任何形式的共享。
#ifndef __LUNAIX_SIGNAL_H
#define __LUNAIX_SIGNAL_H
-#include <signal_defs.h>
+#include <usr/lunaix/signal_defs.h>
#define _SIG_NUM 16
-#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
#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__
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 */
#include <stdarg.h>
#include <stddef.h>
-#include <sys/types.h>
+#include <usr/lunaix/types.h>
#define PACKED __attribute__((packed))
#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 */
-#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 */
--- /dev/null
+#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 */
#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;
#include <klibc/string.h>
-#include <sys/dirent_defs.h>
+#include <usr/lunaix/dirent_defs.h>
extern struct cake_pile* drec_cache_pile;
#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;
#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)
+++ /dev/null
-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
+++ /dev/null
-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
--- /dev/null
+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
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 \
-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
--- /dev/null
+status = @printf " %-8s %s\n" $(1) $(2)
+status_ := @printf " %-8s %s\n" $$(1) $$(2)
+
+export status_
--- /dev/null
+#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 */
+++ /dev/null
-#include <lunaix/syscall.h>
-#include <errno.h>
-
-__LXSYSCALL(int, geterrno);
\ No newline at end of file
+++ /dev/null
-#include <lunaix/syscall.h>
-#include <sys/ioctl.h>
-
-__LXSYSCALL2_VARG(int, ioctl, int, fd, int, req);
\ No newline at end of file
--- /dev/null
+../includes/usr
\ No newline at end of file
+++ /dev/null
-#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 */
+++ /dev/null
-#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 */
+++ /dev/null
-#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 */
#include <errno.h>
#include <fcntl.h>
+#include <lunaix/lunaix.h>
#include <stdio.h>
-#include <sys/lunaix.h>
#include <unistd.h>
int
--- /dev/null
+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
#define __ASM__
-#include <lunaix/syscall.h>
+#include <lunaix/syscallid.h>
.section .data
.global environ
.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
-#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)
--- /dev/null
+#include "syscall.h"
+#include <errno.h>
+
+__LXSYSCALL(int, geterrno);
\ No newline at end of file
-#include <lunaix/syscall.h>
+#include "syscall.h"
#include <fcntl.h>
__LXSYSCALL2(int, open, const char*, path, int, options)
--- /dev/null
+#include "syscall.h"
+#include <lunaix/ioctl.h>
+
+__LXSYSCALL2_VARG(int, ioctl, int, fd, int, req);
\ No newline at end of file
-#include <lunaix/syscall.h>
-#include <sys/lunaix.h>
+#include "syscall.h"
+#include <lunaix/types.h>
__LXSYSCALL(void, yield);
-#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);
-#include <lunaix/syscall.h>
-#include <sys/mount.h>
+#include "syscall.h"
__LXSYSCALL4(int,
mount,
-#include <lunaix/syscall.h>
-#include <signal.h>
+#include "syscall.h"
+#include <lunaix/signal_defs.h>
__LXSYSCALL2(int, signal, int, signum, sighandler_t, handler);
--- /dev/null
+#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 */
-#include <lunaix/syscall.h>
-#include <unistd.h>
+#include "syscall.h"
+#include <lunaix/types.h>
__LXSYSCALL(pid_t, fork)
#ifndef __LUNAIX_SYS_DIRENT_H
#define __LUNAIX_SYS_DIRENT_H
-#include <sys/dirent_defs.h>
+#include <lunaix/dirent_defs.h>
typedef struct
{
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 */
--- /dev/null
+#ifndef __LUNAIX_SYS_ERRNO_H
+#define __LUNAIX_SYS_ERRNO_H
+
+#include <lunaix/status.h>
+
+extern int geterrno();
+
+#define errno (geterrno())
+
+#endif /* __LUNAIX_ERRNO_H */
#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 */
#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 */
#ifndef __LUNAIX_SYS_LUNAIX_H
#define __LUNAIX_SYS_LUNAIX_H
-#include <sys/types.h>
+#include <lunaix/types.h>
void
yield();
--- /dev/null
+#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 */
--- /dev/null
+#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 */
#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 */
#define stdout 0
#define stdin 1
-int
+extern int
printf(const char* fmt, ...);
#endif /* __LUNAIX_USTDIO_H */
#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 */
--- /dev/null
+#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 */
#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 */
--- /dev/null
+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
#include <dirent.h>
#include <fcntl.h>
#include <string.h>
-#include <sys/lxdirent.h>
#include <unistd.h>
DIR*
-ENTRY(_u_start)
+ENTRY(_start)
SECTIONS {
. = 0x400000;
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
#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];
--- /dev/null
+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
+#include <lunaix/lunaix.h>
#include <signal.h>
#include <stdio.h>
-#include <sys/lunaix.h>
#include <unistd.h>
void