Updated userspace

This commit is contained in:
Alex
2022-12-24 09:18:45 +02:00
parent 0ce6433311
commit 40410cba41
25 changed files with 472 additions and 36 deletions

53
libc/Interpreter/Makefile Normal file
View File

@ -0,0 +1,53 @@
# Config file
include ../../../Makefile.conf
NAME=ld
OBJECT_NAME=$(NAME).so
SO_NAME=$(OBJECT_NAME)
OUTPUT_DIR=../../out/system/
SYSROOT = --sysroot=../../out/system/
CC = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)gcc
AS = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)as
AR = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)ar
OBJDUMP = ../../../$(TC_COMPILER_PATH)/$(TC_COMPILER_ARCH)objdump
NASM = /usr/bin/nasm
C_SOURCES = $(shell find ./ -type f -name '*.c')
CPP_SOURCES = $(shell find ./ -type f -name '*.cpp')
S_SOURCES = $(shell find ./ -type f -name '*.S')
ASM_SOURCES = $(shell find ./ -type f -name '*.asm')
OBJ = ${C_SOURCES:.c=.o} ${CPP_SOURCES:.cpp=.o} ${ASM_SOURCES:.asm=.o} ${S_SOURCES:.S=.o}
INCLUDE = ../include
ifeq ($(OSARCH), amd64)
ASM_ARCH := elf64
else ifeq ($(OSARCH), i686)
ASM_ARCH := elf32
endif
CFLAGS := -fPIC -I$(INCLUDE)
build: $(OBJECT_NAME)
$(OBJECT_NAME): $(OBJ)
$(CC) -nostdlib -static -fPIC -fPIE -Wl,-soname,$(SO_NAME) $(SYSROOT) $(OBJ) -o $(OUTPUT_DIR)$@
$(OBJDUMP) -d $(OUTPUT_DIR)$@ > file_dump.map
%.o: %.c
$(CC) $(CFLAGS) -std=c17 -c $< -o $@
%.o: %.cpp
$(CC) $(CFLAGS) -std=c++20 -c $< -o $@
%.o: %.S
$(AS) -c $< -o $@
%.o: %.asm
$(NASM) $< -f $(ASM_ARCH) -o $@
clean:
rm -f file_dump.map $(OBJ)

14
libc/Interpreter/hash.c Normal file
View File

@ -0,0 +1,14 @@
#include "ld.h"
uint32_t ElfHash(const unsigned char *Name)
{
uint32_t i = 0, j;
while (*Name)
{
i = (i << 4) + *Name++;
if ((j = i & 0xF0000000) != 0)
i ^= j >> 24;
i &= ~j;
}
return i;
}

12
libc/Interpreter/ld.c Normal file
View File

@ -0,0 +1,12 @@
#include "ld.h"
int main(int argc, char *argv[], char *envp[])
{
if (argc < 2)
return -1;
int envc = 0;
while (envp[envc] != NULL)
envc++;
return -0xD0D0;
}

8
libc/Interpreter/ld.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef __FENNIX_LIBC_LD_H__
#define __FENNIX_LIBC_LD_H__
#include <types.h>
uint32_t ElfHash(const unsigned char *Name);
#endif // !__FENNIX_LIBC_LD_H__

View File

@ -3,7 +3,9 @@ build:
cp ../../Kernel/syscalls.h ../out/system/include/sys
make --quiet -C runtime build
make --quiet -C src build
make --quiet -C Interpreter build
clean:
make -C runtime clean
make -C src clean
make -C Interpreter clean

View File

@ -12,6 +12,7 @@ extern "C"
void *memset(void *, int, size_t);
char *strcpy(char *, const char *);
size_t strlen(const char *);
int strncmp(const char *s1, const char *s2, size_t n);
#ifdef __cplusplus
}

View File

@ -3,4 +3,4 @@
typedef int pid_t;
#endif
#endif

View File

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "../mem/liballoc_1_1.h"
@ -37,10 +38,20 @@ int atoi(const char *nptr)
return OutBuffer;
}
char **environ = NULL;
char *getenv(const char *name)
{
static char *env = "PATH=/bin";
return env;
char **env = environ;
if (env == NULL)
return NULL;
size_t len = strlen(name);
while (*env != NULL)
{
if ((strncmp(*env, name, len) == 0) && ((*env)[len] == '='))
return &(*env)[len + 1];
++env;
}
}
void *malloc(size_t Size) { return PREFIX(malloc)(Size); }

14
libc/src/string.c Normal file
View File

@ -0,0 +1,14 @@
#include <string.h>
int strncmp(const char *s1, const char *s2, size_t n)
{
for (size_t i = 0; i < n; i++)
{
char c1 = s1[i], c2 = s2[i];
if (c1 != c2)
return c1 - c2;
if (!c1)
return 0;
}
return 0;
}