From 5a017b662662725fea487867e60a7e68df6cbdfe Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 3 May 2023 06:39:20 +0300 Subject: [PATCH] Stub shell --- apps/system/Makefile | 2 ++ apps/system/sh/Makefile | 78 +++++++++++++++++++++++++++++++++++++++++ apps/system/sh/sh.c | 9 +++++ 3 files changed, 89 insertions(+) create mode 100644 apps/system/sh/Makefile create mode 100644 apps/system/sh/sh.c diff --git a/apps/system/Makefile b/apps/system/Makefile index d3cd073..ce3ca0d 100644 --- a/apps/system/Makefile +++ b/apps/system/Makefile @@ -1,5 +1,7 @@ build: make -C init build + make -C sh build clean: make -C init clean + make -C sh clean diff --git a/apps/system/sh/Makefile b/apps/system/sh/Makefile new file mode 100644 index 0000000..e5c720d --- /dev/null +++ b/apps/system/sh/Makefile @@ -0,0 +1,78 @@ +# Config file +include ../../../../Makefile.conf + +FILENAME = sh.elf + +SYSROOT = --sysroot=../../../out/system/ + +CC = ../../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)gcc +CPP = ../../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)g++ +LD = ../../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)ld +AS = ../../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)as +OBJDUMP = ../../../../$(TC_COMPILER_PATH)/$(TC_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 +HEADERS = $(sort $(dir $(wildcard ../../../out/system/include/*))) +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) +INCLUDE_DIR = ../../../out/system/include + +LDFLAGS := -Wl,-Map file.map + +WARNCFLAG = -Wall -Wextra -Wno-main + +CFLAGS := \ + -I$(INCLUDE_DIR) \ + -DGIT_COMMIT='"$(GIT_COMMIT)"' \ + -DGIT_COMMIT_SHORT='"$(GIT_COMMIT_SHORT)"' + +ifeq ($(OSARCH), amd64) +CFLAGS += -march=x86-64 -fstack-protector-all -fstack-clash-protection +else ifeq ($(OSARCH), i386) +CFLAGS += -march=i386 +else ifeq ($(OSARCH), aarch64) +CFLAGS += -pipe +endif + +build: $(FILENAME) + $(OBJDUMP) -d $(FILENAME) > file_dump.map + mv $(FILENAME) ../../../out/system/bin/$(FILENAME) + +$(FILENAME): $(OBJ) + $(info Linking $@) + $(CC) $(LDFLAGS) $(SYSROOT) $(OBJ) -lssp -linit -o $@ + +%.o: %.c $(HEADERS) + $(info Compiling $<) + $(CC) $(CFLAGS) $(WARNCFLAG) -std=c17 -c $< -o $@ + +%.o: %.cpp $(HEADERS) + $(info Compiling $<) + $(CPP) $(CFLAGS) $(WARNCFLAG) -std=c++20 -c $< -o $@ + +%.o: %.S + $(info Compiling $<) +ifeq ($(OSARCH), amd64) + $(AS) -o $@ $< +else ifeq ($(OSARCH), i386) + $(AS) -o $@ $< +else ifeq ($(OSARCH), aarch64) + $(AS) -o $@ $< +endif + +clean: + rm -f *.o file.map file_dump.map $(OBJ) diff --git a/apps/system/sh/sh.c b/apps/system/sh/sh.c new file mode 100644 index 0000000..8704da6 --- /dev/null +++ b/apps/system/sh/sh.c @@ -0,0 +1,9 @@ +#include +#include +#include + +int main(int argc, char *argv[], char *envp[]) +{ + printf("Hello, world!\n"); + return 0; +}