Stub shell

This commit is contained in:
Alex 2023-05-03 06:39:20 +03:00
parent 2523ad0911
commit 5a017b6626
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
3 changed files with 89 additions and 0 deletions

View File

@ -1,5 +1,7 @@
build:
make -C init build
make -C sh build
clean:
make -C init clean
make -C sh clean

78
apps/system/sh/Makefile Normal file
View File

@ -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)

9
apps/system/sh/sh.c Normal file
View File

@ -0,0 +1,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <aux.h>
int main(int argc, char *argv[], char *envp[])
{
printf("Hello, world!\n");
return 0;
}