mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-02 10:59:15 +00:00
userspace: Rewrite everything
Everything. Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
@ -1,33 +0,0 @@
|
||||
# Config file
|
||||
include ../../../config.mk
|
||||
|
||||
cwd := $(CURDIR)
|
||||
CACHE_DIR := $(cwd)/../../cache
|
||||
PREFIX := $(cwd)/../../out/
|
||||
TARGET := x86_64-fennix
|
||||
|
||||
export CC := $(cwd)/../../../tools/cross/bin/$(TARGET)-gcc
|
||||
export LD := $(cwd)/../../../tools/cross/bin/$(TARGET)-ld
|
||||
export AR := $(cwd)/../../../tools/cross/bin/$(TARGET)-ar
|
||||
export STRIP := $(cwd)/../../../tools/cross/bin/$(TARGET)-strip
|
||||
export RANLIB := $(cwd)/../../../tools/cross/bin/$(TARGET)-ranlib
|
||||
export LD_LIBRARY_PATH := $(cwd)/../../out/lib/
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
export CFLAGS := --sysroot=$(cwd)/../../out/ -I$(cwd)/../../out/include/ -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
export LDFLAGS := -ggdb3 -O0
|
||||
else
|
||||
export CFLAGS := --sysroot=$(cwd)/../../out/ -I$(cwd)/../../out/include/
|
||||
endif
|
||||
|
||||
build:
|
||||
make -C utest build
|
||||
make -C cross_test build
|
||||
make -C echo build
|
||||
make -C fsh build
|
||||
|
||||
clean:
|
||||
make -C utest clean
|
||||
make -C cross_test clean
|
||||
make -C echo clean
|
||||
make -C fsh clean
|
@ -1,16 +0,0 @@
|
||||
WORKSPACE := ../../../
|
||||
|
||||
# Config file
|
||||
include ../$(WORKSPACE)config.mk
|
||||
|
||||
FILENAME = utest_
|
||||
|
||||
CFLAGS = -static -g -ggdb3 -O0
|
||||
|
||||
build:
|
||||
$(info Compiling $(FILENAME)linux)
|
||||
gcc linux_glibc.c $(CFLAGS) -o $(WORKSPACE)out/bin/$(FILENAME)linux
|
||||
$(info Compiling $(FILENAME)win)
|
||||
x86_64-w64-mingw32-gcc win_mingw.c $(CFLAGS) -o $(WORKSPACE)out/bin/$(FILENAME)win.exe
|
||||
|
||||
clean:
|
@ -1,22 +0,0 @@
|
||||
$ setarch `uname -m` -R strace ./utest_linux
|
||||
|
||||
execve("./utest_linux", ["./utest_linux"], 0x7fffffffdec0 /* 56 vars */) = 0
|
||||
arch_prctl(0x3001 /* ARCH_??? */, 0x7fffffffde40) = -1 EINVAL (Invalid argument)
|
||||
brk(NULL) = 0x4cd000
|
||||
brk(0x4cddc0) = 0x4cddc0
|
||||
arch_prctl(ARCH_SET_FS, 0x4cd3c0) = 0
|
||||
set_tid_address(0x4cd690) = 68565
|
||||
set_robust_list(0x4cd6a0, 24) = 0
|
||||
rseq(0x4cdd60, 0x20, 0, 0x53053053) = 0
|
||||
uname({sysname="Fennix", nodename="fennix", ...}) = 0
|
||||
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
|
||||
readlink("/proc/self/exe", "/bin/utest_linux"..., 4096) = 50
|
||||
getrandom("\x1e\x3c\x20\xdd\x09\xe8\x46\x0d", 8, GRND_NONBLOCK) = 8
|
||||
brk(0x4eedc0) = 0x4eedc0
|
||||
brk(0x4ef000) = 0x4ef000
|
||||
mprotect(0x4c1000, 16384, PROT_READ) = 0
|
||||
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0x1), ...}, AT_EMPTY_PATH) = 0
|
||||
write(1, "Hello, World!\n", 14Hello, World!
|
||||
) = 14
|
||||
exit_group(0) = ?
|
||||
+++ exited with 0 +++
|
@ -1,66 +0,0 @@
|
||||
WORKSPACE := ../../../
|
||||
|
||||
# Config file
|
||||
include ../$(WORKSPACE)config.mk
|
||||
|
||||
CC = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
|
||||
CPP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)g++
|
||||
LD = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)ld
|
||||
AS = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)as
|
||||
OBJDUMP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)objdump
|
||||
|
||||
GIT_COMMIT = $(shell git rev-parse HEAD)
|
||||
GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD)
|
||||
|
||||
ifeq ($(OSARCH), amd64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), i386)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), aarch64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
endif
|
||||
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
|
||||
|
||||
SYSROOT = --sysroot=$(WORKSPACE)out/
|
||||
FILENAME = echo
|
||||
|
||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
|
||||
|
||||
LDFLAGS =
|
||||
CFLAGS = -I$(WORKSPACE)out/include \
|
||||
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
|
||||
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
endif
|
||||
|
||||
build: $(FILENAME)
|
||||
mv $(FILENAME) $(WORKSPACE)out/bin/$(FILENAME)
|
||||
|
||||
$(FILENAME): $(OBJ)
|
||||
$(info Linking $@)
|
||||
$(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -o $@
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.cpp $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
@ -1,59 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int enableEscapes = 0;
|
||||
int disableNewline = 0;
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "neE")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'n':
|
||||
disableNewline = 1;
|
||||
break;
|
||||
case 'e':
|
||||
enableEscapes = 1;
|
||||
break;
|
||||
case 'E':
|
||||
enableEscapes = 0;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
(void)enableEscapes;
|
||||
|
||||
size_t totalLength = 0;
|
||||
for (int i = optind; i < argc; ++i)
|
||||
totalLength += strlen(argv[i]) + 1;
|
||||
|
||||
char *result = (char *)malloc(totalLength);
|
||||
if (!result)
|
||||
{
|
||||
perror("Memory allocation error");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
result[0] = '\0';
|
||||
|
||||
for (int i = optind; i < argc; ++i)
|
||||
{
|
||||
strcat(result, argv[i]);
|
||||
if (i < argc - 1)
|
||||
strcat(result, " ");
|
||||
}
|
||||
|
||||
printf("%s", result);
|
||||
|
||||
if (!disableNewline)
|
||||
printf("\n");
|
||||
|
||||
free(result);
|
||||
return 0;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
WORKSPACE := ../../../
|
||||
|
||||
# Config file
|
||||
include ../$(WORKSPACE)config.mk
|
||||
|
||||
CC = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
|
||||
CPP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)g++
|
||||
LD = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)ld
|
||||
AS = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)as
|
||||
OBJDUMP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)objdump
|
||||
|
||||
GIT_COMMIT = $(shell git rev-parse HEAD)
|
||||
GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD)
|
||||
|
||||
ifeq ($(OSARCH), amd64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), i386)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), aarch64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
endif
|
||||
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
|
||||
|
||||
SYSROOT = --sysroot=$(WORKSPACE)out/
|
||||
FILENAME = sh
|
||||
|
||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
|
||||
|
||||
LDFLAGS =
|
||||
CFLAGS = -I$(WORKSPACE)out/include \
|
||||
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
|
||||
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
endif
|
||||
|
||||
build: $(FILENAME)
|
||||
mv $(FILENAME) $(WORKSPACE)out/bin/$(FILENAME)
|
||||
|
||||
$(FILENAME): $(OBJ)
|
||||
$(info Linking $@)
|
||||
$(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -o $@
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.cpp $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
@ -1,160 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#define _GNU_SOURCE
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#define _POSIX_SOURCE
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_COMMAND_LENGTH 1024
|
||||
#define MAX_ARGS 10
|
||||
|
||||
void DisableInputBuffering()
|
||||
{
|
||||
struct termios tty_attr;
|
||||
tcgetattr(STDIN_FILENO, &tty_attr);
|
||||
tty_attr.c_lflag &= ~(ICANON | ECHO);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty_attr);
|
||||
}
|
||||
|
||||
void EnableInputBuffering()
|
||||
{
|
||||
struct termios tty_attr;
|
||||
tcgetattr(STDIN_FILENO, &tty_attr);
|
||||
tty_attr.c_lflag |= ICANON | ECHO;
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &tty_attr);
|
||||
}
|
||||
|
||||
void ReadLine(char *Buffer, size_t BufferSize)
|
||||
{
|
||||
size_t index = 0;
|
||||
int c;
|
||||
while (1)
|
||||
{
|
||||
c = getchar();
|
||||
if (c == EOF || c == '\n')
|
||||
{
|
||||
Buffer[index] = '\0';
|
||||
break;
|
||||
}
|
||||
else if (c == 127 || c == 8) // Backspace
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
printf("\b \b");
|
||||
index--;
|
||||
}
|
||||
}
|
||||
else if (c == 4) // Ctrl + D
|
||||
{
|
||||
if (index == 0)
|
||||
kill(getpid(), SIGQUIT);
|
||||
else
|
||||
putchar('\a');
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index < BufferSize - 1)
|
||||
{
|
||||
putchar(c);
|
||||
Buffer[index] = (char)c;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExecuteCommand(char *command)
|
||||
{
|
||||
char *args[MAX_ARGS];
|
||||
int i = 0;
|
||||
|
||||
char *token = strtok(command, " ");
|
||||
while (token != NULL && i < MAX_ARGS - 1)
|
||||
{
|
||||
args[i++] = token;
|
||||
token = strtok(NULL, " ");
|
||||
}
|
||||
args[i] = NULL;
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid == 0)
|
||||
{
|
||||
execvp(args[0], args);
|
||||
perror("execvp");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else if (pid > 0)
|
||||
wait(NULL);
|
||||
else
|
||||
{
|
||||
perror("fork");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleSignal(int signal)
|
||||
{
|
||||
if (signal == SIGQUIT)
|
||||
{
|
||||
EnableInputBuffering();
|
||||
printf("\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
else if (signal == SIGINT)
|
||||
{
|
||||
putchar('\n');
|
||||
}
|
||||
else if (signal == SIGHUP)
|
||||
{
|
||||
EnableInputBuffering();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
else if (signal == SIGCHLD)
|
||||
wait(NULL);
|
||||
else if (signal == SIGSEGV)
|
||||
{
|
||||
printf("Segmentation fault\n");
|
||||
while (1)
|
||||
sleep(1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Signal %s(%d) received\n",
|
||||
strsignal(signal), signal);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
char command[MAX_COMMAND_LENGTH];
|
||||
for (int i = 0; i < NSIG; ++i)
|
||||
signal(i, HandleSignal);
|
||||
|
||||
char hostname[256];
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("\033[1;32m");
|
||||
printf("┌──(%s@%s)-[%s]\n", getenv("USER"), hostname, getenv("PWD"));
|
||||
printf("└$ ");
|
||||
printf("\033[0m");
|
||||
|
||||
DisableInputBuffering();
|
||||
ReadLine(command, sizeof(command));
|
||||
EnableInputBuffering();
|
||||
putchar('\n');
|
||||
|
||||
if (strcmp(command, "exit") == 0)
|
||||
break;
|
||||
|
||||
ExecuteCommand(command);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
WORKSPACE := ../../../
|
||||
|
||||
# Config file
|
||||
include ../$(WORKSPACE)config.mk
|
||||
|
||||
CC = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
|
||||
CPP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)g++
|
||||
LD = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)ld
|
||||
AS = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)as
|
||||
OBJDUMP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)objdump
|
||||
|
||||
GIT_COMMIT = $(shell git rev-parse HEAD)
|
||||
GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD)
|
||||
|
||||
ifeq ($(OSARCH), amd64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), i386)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), aarch64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
endif
|
||||
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
|
||||
|
||||
SYSROOT = --sysroot=$(WORKSPACE)out/
|
||||
FILENAME = utest
|
||||
|
||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
|
||||
|
||||
LDFLAGS = -static
|
||||
CFLAGS = -I$(WORKSPACE)out/include \
|
||||
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
|
||||
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"' -static
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
endif
|
||||
|
||||
build: $(FILENAME)
|
||||
mv $(FILENAME) $(WORKSPACE)out/bin/$(FILENAME)
|
||||
|
||||
$(FILENAME): $(OBJ)
|
||||
$(info Linking $@)
|
||||
$(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -o $@
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.cpp $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
9
Userspace/apps/sys/Makefile
Normal file
9
Userspace/apps/sys/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
MAKE_TARGETS := build clean
|
||||
DIRECTORIES := $(sort $(dir $(wildcard ./*/)))
|
||||
|
||||
.PHONY: $(MAKE_TARGETS) $(DIRECTORIES)
|
||||
|
||||
$(MAKE_TARGETS): $(DIRECTORIES)
|
||||
|
||||
$(DIRECTORIES):
|
||||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
1
Userspace/apps/sys/init/.gitignore
vendored
Normal file
1
Userspace/apps/sys/init/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
init
|
33
Userspace/apps/sys/init/Makefile
Normal file
33
Userspace/apps/sys/init/Makefile
Normal file
@ -0,0 +1,33 @@
|
||||
default:
|
||||
$(error Do not run this Makefile directly!)
|
||||
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S')
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c')
|
||||
CXX_SOURCES = $(shell find ./ -type f -name '*.cpp')
|
||||
|
||||
OBJ = $(S_SOURCES:.S=.o) $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o)
|
||||
|
||||
FILENAME = $(notdir $(shell pwd))
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
||||
build: $(FILENAME)
|
||||
cp $(FILENAME) $(WORKSPACE_DIR)/out/bin/$(FILENAME)
|
||||
|
||||
$(FILENAME): $(OBJ)
|
||||
$(info Linking $@)
|
||||
$(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -o $@
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.cpp $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CXX) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(FILENAME)
|
27
Userspace/apps/sys/init/init.c
Normal file
27
Userspace/apps/sys/init/init.c
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
This file is part of Fennix C Library.
|
||||
|
||||
Fennix C Library is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int, char *[], char *[])
|
||||
{
|
||||
printf("Hello, World!\n");
|
||||
return 0;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
build:
|
||||
make -C init build
|
||||
|
||||
clean:
|
||||
make -C init clean
|
@ -1,70 +0,0 @@
|
||||
WORKSPACE := ../../../
|
||||
|
||||
# Config file
|
||||
include ../$(WORKSPACE)config.mk
|
||||
|
||||
CC = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)gcc
|
||||
CPP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)g++
|
||||
LD = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)ld
|
||||
AS = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)as
|
||||
OBJDUMP = ../$(WORKSPACE)$(COMPILER_PATH)/$(COMPILER_ARCH)objdump
|
||||
|
||||
GIT_COMMIT = $(shell git rev-parse HEAD)
|
||||
GIT_COMMIT_SHORT = $(shell git rev-parse --short HEAD)
|
||||
|
||||
ifeq ($(OSARCH), amd64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/i386/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), i386)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/aarch64/*")
|
||||
else ifeq ($(OSARCH), aarch64)
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp' -not -path "./arch/amd64/*" -not -path "./arch/i386/*")
|
||||
endif
|
||||
OBJ = $(C_SOURCES:.c=.o) $(CPP_SOURCES:.cpp=.o) $(ASM_SOURCES:.asm=.o) $(S_SOURCES:.S=.o) $(PSF_SOURCES:.psf=.o) $(BMP_SOURCES:.bmp=.o)
|
||||
|
||||
SYSROOT = --sysroot=$(WORKSPACE)out/
|
||||
FILENAME = init
|
||||
|
||||
HEADERS = $(sort $(dir $(wildcard $(WORKSPACE)out/include/*)))
|
||||
|
||||
LDFLAGS =
|
||||
CFLAGS = -I$(WORKSPACE)out/include \
|
||||
-DGIT_COMMIT='"$(GIT_COMMIT)"' \
|
||||
-DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"'
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
||||
ifneq ($(OSARCH), aarch64)
|
||||
# CFLAGS += -fstack-protector-all -fstack-clash-protection
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
CFLAGS += -DDEBUG -ggdb3 -O0 -fdiagnostics-color=always -fverbose-asm
|
||||
LDFLAGS += -ggdb3 -O0
|
||||
endif
|
||||
|
||||
build: $(FILENAME)
|
||||
mv $(FILENAME) $(WORKSPACE)out/bin/$(FILENAME)
|
||||
|
||||
$(FILENAME): $(OBJ)
|
||||
$(info Linking $@)
|
||||
$(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -o $@
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.cpp $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
@ -1,6 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int, char *[], char *[])
|
||||
{
|
||||
return 0;
|
||||
}
|
9
Userspace/apps/test/Makefile
Normal file
9
Userspace/apps/test/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
MAKE_TARGETS := build clean
|
||||
DIRECTORIES := $(sort $(dir $(wildcard ./*/)))
|
||||
|
||||
.PHONY: $(MAKE_TARGETS) $(DIRECTORIES)
|
||||
|
||||
$(MAKE_TARGETS): $(DIRECTORIES)
|
||||
|
||||
$(DIRECTORIES):
|
||||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
2
Userspace/apps/test/cross_test/.gitignore
vendored
Normal file
2
Userspace/apps/test/cross_test/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
utest_linux
|
||||
utest_win.exe
|
30
Userspace/apps/test/cross_test/Makefile
Normal file
30
Userspace/apps/test/cross_test/Makefile
Normal file
@ -0,0 +1,30 @@
|
||||
default:
|
||||
$(error Do not run this Makefile directly!)
|
||||
|
||||
FILENAME = utest_
|
||||
|
||||
CFLAGS = -static -g -ggdb3 -O0 -w
|
||||
UNAME_OS := $(shell uname -s)
|
||||
|
||||
$(FILENAME)linux:
|
||||
ifneq ($(shell uname -s), Linux)
|
||||
$(info Only Linux is supported)
|
||||
exit 0
|
||||
endif
|
||||
$(info Compiling $(FILENAME)linux)
|
||||
gcc linux_glibc.c $(CFLAGS) -o $(FILENAME)linux
|
||||
cp $(FILENAME)linux $(WORKSPACE_DIR)/out/bin/$(FILENAME)linux
|
||||
|
||||
$(FILENAME)win.exe:
|
||||
ifneq ($(shell uname -s), Linux)
|
||||
$(info Only Linux is supported)
|
||||
exit 0
|
||||
endif
|
||||
$(info Compiling $(FILENAME)win)
|
||||
x86_64-w64-mingw32-gcc win_mingw.c $(CFLAGS) -o $(FILENAME)win.exe
|
||||
cp $(FILENAME)win.exe $(WORKSPACE_DIR)/out/bin/$(FILENAME)win.exe
|
||||
|
||||
build: $(FILENAME)linux $(FILENAME)win.exe
|
||||
|
||||
clean:
|
||||
rm -f $(FILENAME)linux $(FILENAME)win.exe
|
1
Userspace/apps/test/utest/.gitignore
vendored
Normal file
1
Userspace/apps/test/utest/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
utest
|
36
Userspace/apps/test/utest/Makefile
Normal file
36
Userspace/apps/test/utest/Makefile
Normal file
@ -0,0 +1,36 @@
|
||||
default:
|
||||
$(error Do not run this Makefile directly!)
|
||||
|
||||
S_SOURCES = $(shell find ./ -type f -name '*.S')
|
||||
C_SOURCES = $(shell find ./ -type f -name '*.c')
|
||||
CXX_SOURCES = $(shell find ./ -type f -name '*.cpp')
|
||||
|
||||
OBJ = $(S_SOURCES:.S=.o) $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o)
|
||||
|
||||
FILENAME = $(notdir $(shell pwd))
|
||||
WARNCFLAG = -Wall -Wextra
|
||||
|
||||
build: $(FILENAME)
|
||||
# cp $(FILENAME) $(WORKSPACE_DIR)/out/bin/$(FILENAME)
|
||||
|
||||
# Use static linking
|
||||
LDFLAGS += -static -fno-pic -fno-pie -Wl,-static
|
||||
|
||||
$(FILENAME): $(OBJ)
|
||||
$(info Linking $@)
|
||||
# $(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -o $@
|
||||
|
||||
%.o: %.c $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@
|
||||
|
||||
%.o: %.cpp $(HEADERS)
|
||||
$(info Compiling $<)
|
||||
$(CXX) $(CFLAGS) $(WARNCFLAG) -std=c++20 -fexceptions -c $< -o $@ -fno-rtti
|
||||
|
||||
%.o: %.S
|
||||
$(info Compiling $<)
|
||||
$(AS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(FILENAME)
|
@ -7,15 +7,11 @@
|
||||
#include <sys/wait.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <fcntl.h>
|
||||
#include <pty.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/reboot.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <pwd.h>
|
||||
@ -141,10 +137,10 @@ void test_passwd()
|
||||
else
|
||||
{
|
||||
printf("name: %s\n", p->pw_name);
|
||||
printf("passwd: %s\n", p->pw_passwd);
|
||||
// printf("passwd: %s\n", p->pw_passwd);
|
||||
printf("uid: %d\n", p->pw_uid);
|
||||
printf("gid: %d\n", p->pw_gid);
|
||||
printf("gecos: %s\n", p->pw_gecos);
|
||||
// printf("gecos: %s\n", p->pw_gecos);
|
||||
printf("dir: %s\n", p->pw_dir);
|
||||
printf("shell: %s\n", p->pw_shell);
|
||||
}
|
||||
@ -251,7 +247,9 @@ void test_time()
|
||||
|
||||
time_t t = mktime(&time);
|
||||
if (t != (time_t)-1)
|
||||
stime(&t);
|
||||
{
|
||||
// stime(&t);
|
||||
}
|
||||
else
|
||||
{
|
||||
perror("mktime");
|
||||
@ -401,29 +399,29 @@ void test_stat()
|
||||
|
||||
void test_ptmx()
|
||||
{
|
||||
printf("- Testing PTMX\n");
|
||||
// printf("- Testing PTMX\n");
|
||||
|
||||
int master, slave;
|
||||
char buffer[256];
|
||||
// int master, slave;
|
||||
// char buffer[256];
|
||||
|
||||
if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
|
||||
{
|
||||
perror("openpty");
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
return;
|
||||
}
|
||||
// if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
|
||||
// {
|
||||
// perror("openpty");
|
||||
// fflush(stdout);
|
||||
// fflush(stderr);
|
||||
// return;
|
||||
// }
|
||||
|
||||
write(master, "Hello, pty!\n", 12);
|
||||
ssize_t bytesRead = read(slave, buffer, sizeof(buffer));
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
buffer[bytesRead] = '\0';
|
||||
printf("Received from pty: %s", buffer);
|
||||
}
|
||||
// write(master, "Hello, pty!\n", 12);
|
||||
// ssize_t bytesRead = read(slave, buffer, sizeof(buffer));
|
||||
// if (bytesRead > 0)
|
||||
// {
|
||||
// buffer[bytesRead] = '\0';
|
||||
// printf("Received from pty: %s", buffer);
|
||||
// }
|
||||
|
||||
close(master);
|
||||
close(slave);
|
||||
// close(master);
|
||||
// close(slave);
|
||||
}
|
||||
|
||||
void test_system()
|
||||
@ -654,6 +652,7 @@ char *create_directory()
|
||||
return path;
|
||||
}
|
||||
|
||||
#ifndef __fennix__
|
||||
void test_watch_file()
|
||||
{
|
||||
printf("- Testing file watching\n");
|
||||
@ -788,6 +787,7 @@ void reboot_linux()
|
||||
sync();
|
||||
reboot(RB_AUTOBOOT);
|
||||
}
|
||||
#endif // __fennix__
|
||||
|
||||
void test_stdin()
|
||||
{
|
||||
@ -892,10 +892,12 @@ int main(int argc, char *argv[], char *envp[])
|
||||
test_stat();
|
||||
test_dirent();
|
||||
test_execve_fork();
|
||||
#ifndef __fennix__
|
||||
test_watch_file();
|
||||
test_watch_directory();
|
||||
// shutdown_linux();
|
||||
// reboot_linux();
|
||||
shutdown_linux();
|
||||
reboot_linux();
|
||||
#endif
|
||||
|
||||
int status = 0;
|
||||
pid_t wpid;
|
@ -1,5 +0,0 @@
|
||||
build:
|
||||
make -C games build
|
||||
|
||||
clean:
|
||||
make -C games clean
|
@ -1,5 +0,0 @@
|
||||
build:
|
||||
# make -C doomgeneric build
|
||||
|
||||
clean:
|
||||
# make -C doomgeneric clean
|
Reference in New Issue
Block a user