From 6a5543bb8f1f535ca49737bcd7be0cafca3b2a08 Mon Sep 17 00:00:00 2001 From: hachem Date: Mon, 12 Oct 2026 23:08:48 +0200 Subject: feat: lib sea --- sysroot/usr/include/fcntl.h | 12 ++++++++++++ sysroot/usr/include/stddef.h | 9 +++++++++ sysroot/usr/include/stdint.h | 10 ++++++++++ sysroot/usr/include/stdio.h | 15 +++++++++++++++ sysroot/usr/include/stdlib.h | 17 +++++++++++++++++ sysroot/usr/include/string.h | 17 +++++++++++++++++ sysroot/usr/include/sys/syscall.h | 34 ++++++++++++++++++++++++++++++++++ sysroot/usr/include/unistd.h | 18 ++++++++++++++++++ 8 files changed, 132 insertions(+) create mode 100644 sysroot/usr/include/fcntl.h create mode 100644 sysroot/usr/include/stddef.h create mode 100644 sysroot/usr/include/stdint.h create mode 100644 sysroot/usr/include/stdio.h create mode 100644 sysroot/usr/include/stdlib.h create mode 100644 sysroot/usr/include/string.h create mode 100644 sysroot/usr/include/sys/syscall.h create mode 100644 sysroot/usr/include/unistd.h (limited to 'sysroot/usr/include') diff --git a/sysroot/usr/include/fcntl.h b/sysroot/usr/include/fcntl.h new file mode 100644 index 0000000..4c9dc07 --- /dev/null +++ b/sysroot/usr/include/fcntl.h @@ -0,0 +1,12 @@ +#ifndef _FCNTL_H +#define _FCNTL_H + +#define O_RDONLY 0 +#define O_WRONLY 1 +#define O_CREAT 0x40 +#define O_TRUNC 0x200 +#define O_APPEND 0x400 + +int open(const char* path, int flags); + +#endif diff --git a/sysroot/usr/include/stddef.h b/sysroot/usr/include/stddef.h new file mode 100644 index 0000000..0fe5f56 --- /dev/null +++ b/sysroot/usr/include/stddef.h @@ -0,0 +1,9 @@ +#ifndef _STDDEF_H +#define _STDDEF_H + +typedef unsigned long size_t; +typedef long ptrdiff_t; + +#define NULL ((void*)0) + +#endif diff --git a/sysroot/usr/include/stdint.h b/sysroot/usr/include/stdint.h new file mode 100644 index 0000000..d3da3d2 --- /dev/null +++ b/sysroot/usr/include/stdint.h @@ -0,0 +1,10 @@ +#ifndef _STDINT_H +#define _STDINT_H + +typedef unsigned char uint8_t; typedef signed char int8_t; +typedef unsigned short uint16_t; typedef short int16_t; +typedef unsigned int uint32_t; typedef int int32_t; +typedef unsigned long uint64_t; typedef long int64_t; +typedef unsigned long uintptr_t; typedef long intptr_t; + +#endif diff --git a/sysroot/usr/include/stdio.h b/sysroot/usr/include/stdio.h new file mode 100644 index 0000000..9f6929e --- /dev/null +++ b/sysroot/usr/include/stdio.h @@ -0,0 +1,15 @@ +#ifndef _STDIO_H +#define _STDIO_H + +#define EOF (-1) + +int putchar(int character); +int getchar(void); +int puts(const char* string); +int printf(const char* format, ...); + +// revel only, not part of stdc +// read a line from stdin -> returns length +int readline(char* buffer, int max_length); + +#endif diff --git a/sysroot/usr/include/stdlib.h b/sysroot/usr/include/stdlib.h new file mode 100644 index 0000000..7950258 --- /dev/null +++ b/sysroot/usr/include/stdlib.h @@ -0,0 +1,17 @@ +#ifndef _STDLIB_H +#define _STDLIB_H + +#include + +void* malloc(size_t length); +void free(void* pointer); +void* calloc(size_t count, size_t size); +void* realloc(void* pointer, size_t length); + +void exit(int code) __attribute__((noreturn)); + +int atoi(const char* string); +long atol(const char* string); +int abs(int value); + +#endif diff --git a/sysroot/usr/include/string.h b/sysroot/usr/include/string.h new file mode 100644 index 0000000..2177ad6 --- /dev/null +++ b/sysroot/usr/include/string.h @@ -0,0 +1,17 @@ +#ifndef _STRING_H +#define _STRING_H + +#include + +size_t strlen(const char* string); +int strcmp(const char* a, const char* b); +int strncmp(const char* a, const char* b, size_t length); +char* strcpy(char* destination, const char* source); +char* strncpy(char* destination, const char* source, size_t length); + +void* memcpy(void* destination, const void* source, size_t length); +void* memmove(void* destination, const void* source, size_t length); +void* memset(void* destination, int value, size_t length); +int memcmp(const void* a, const void* b, size_t length); + +#endif diff --git a/sysroot/usr/include/sys/syscall.h b/sysroot/usr/include/sys/syscall.h new file mode 100644 index 0000000..4a23a53 --- /dev/null +++ b/sysroot/usr/include/sys/syscall.h @@ -0,0 +1,34 @@ +#ifndef _SYS_SYSCALL_H +#define _SYS_SYSCALL_H + +#define SYS_exit 0 +#define SYS_write 1 +#define SYS_read 2 +#define SYS_open 7 +#define SYS_close 8 +#define SYS_lseek 9 +#define SYS_brk 10 +#define SYS_sbrk 11 + +static inline long __syscall1(long number, long a1) +{ + long result; + __asm__ volatile("int $0x80" : "=a"(result) : "a"(number), "D"(a1) : "memory"); + return result; +} + +static inline long __syscall2(long number, long a1, long a2) +{ + long result; + __asm__ volatile("int $0x80" : "=a"(result) : "a"(number), "D"(a1), "S"(a2) : "memory"); + return result; +} + +static inline long __syscall3(long number, long a1, long a2, long a3) +{ + long result; + __asm__ volatile("int $0x80" : "=a"(result) : "a"(number), "D"(a1), "S"(a2), "d"(a3) : "memory"); + return result; +} + +#endif diff --git a/sysroot/usr/include/unistd.h b/sysroot/usr/include/unistd.h new file mode 100644 index 0000000..f5a67ab --- /dev/null +++ b/sysroot/usr/include/unistd.h @@ -0,0 +1,18 @@ +#ifndef _UNISTD_H +#define _UNISTD_H + +#include + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 + +long read(int fd, void* buffer, size_t length); +long write(int fd, const void* buffer, size_t length); +int close(int fd); +long lseek(int fd, long offset, int whence); + +void* sbrk(long increment); +int brk(void* address); + +#endif -- cgit v1.3