Berry failed port attempt leftovers :(
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m9s

This commit is contained in:
2026-03-08 23:35:41 +01:00
parent ed4db21cf2
commit bea4ddd2c8
22 changed files with 218 additions and 26 deletions

View File

@@ -13,3 +13,4 @@ include make/libkb.mk
include make/libaux.mk
include make/libarena.mk
include make/libioutil.mk
include make/libmath.mk

View File

@@ -12,3 +12,4 @@ make -B all_compiledb_libkb
make -B all_compiledb_libaux
make -B all_compiledb_libarena
make -B all_compiledb_libioutil
make -B all_compiledb_libmath

View File

@@ -19,6 +19,7 @@ make -B all_libkb "$bt"
make -B all_libaux "$bt"
make -B all_libarena "$bt"
make -B all_libioutil "$bt"
make -B all_libmath "$bt"
make -B all_apps "$bt"
make -B all_dist
./aux/limine_iso_amd64.sh

View File

@@ -13,5 +13,6 @@ make -B docs_libkb
make -B docs_libaux
make -B docs_libarena
make -B docs_libioutil
make -B docs_libmath
mkdocs build

View File

@@ -12,4 +12,5 @@ make -B format_libkb
make -B format_libaux
make -B format_libarena
make -B format_libioutil
make -B format_libmath
make -B format_apps

1
libaux/amd64/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.o

34
libaux/amd64/setjmp.c Normal file
View File

@@ -0,0 +1,34 @@
#include <setjmp.h>
/* https://nullprogram.com/blog/2023/02/12 */
__attribute__ ((naked, returns_twice)) int setjmp (jmp_buf buf) {
__asm__ volatile ("mov (%rsp), %rax\n"
"mov %rax, 0(%rcx)\n"
"lea 8(%rsp), %rax\n"
"mov %rax, 8(%rcx)\n"
"mov %rbp, 16(%rcx)\n"
"mov %rbx, 24(%rcx)\n"
"mov %rdi, 32(%rcx)\n"
"mov %rsi, 40(%rcx)\n"
"mov %r12, 48(%rcx)\n"
"mov %r13, 56(%rcx)\n"
"mov %r14, 64(%rcx)\n"
"mov %r15, 72(%rcx)\n"
"xor %eax, %eax\n"
"ret\n");
}
__attribute__ ((naked, noreturn)) void longjmp (jmp_buf buf, int ret) {
__asm__ volatile ("mov 72(%rcx), %r15\n"
"mov 64(%rcx), %r14\n"
"mov 56(%rcx), %r13\n"
"mov 48(%rcx), %r12\n"
"mov 40(%rcx), %rsi\n"
"mov 32(%rcx), %rdi\n"
"mov 24(%rcx), %rbx\n"
"mov 16(%rcx), %rbp\n"
"mov 8(%rcx), %rsp\n"
"mov %edx, %eax\n"
"jmp *0(%rcx)\n");
}

3
libaux/amd64/src.mk Normal file
View File

@@ -0,0 +1,3 @@
c += amd64/setjmp.c
o += amd64/setjmp.o

12
libaux/assert.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef _LIBAUX_ASSERT_H
#define _LIBAUX_ASSERT_H
#include <system.h>
#define assert(x) \
do { \
if (!!(x)) \
quit (); \
} while (0)
#endif // _LIBAUX_ASSERT_H

12
libaux/setjmp.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef _LIBAUX_SETJMP_H
#define _LIBAUX_SETJMP_H
#if defined(__x86_64__)
typedef void* jmp_buf[10];
#endif
__attribute__ ((naked, returns_twice)) int setjmp (jmp_buf buf);
__attribute__ ((naked, noreturn)) void longjmp (jmp_buf buf, int ret);
#endif // _LIBAUX_SETJMP_H

View File

@@ -1,3 +1,5 @@
include $(platform)/src.mk
c += printf.c \
path.c

4
libmath/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.o
*.json
docs/
.cache/

5
libmath/Makefile Normal file
View File

@@ -0,0 +1,5 @@
include ../make/ufuncs.mk
libname := libmath
include ../make/lib.mk

1
libmath/build/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*.a

5
libmath/math.c Normal file
View File

@@ -0,0 +1,5 @@
#include <math.h>
double fmod (double a, double b) { return a - ((double)((long long)(a / b))) * b; }
float fmodf (float a, float b) { return a - ((float)((long)(a / b))) * b; }

8
libmath/math.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef _LIBMATH_MATH_H
#define _LIBMATH_MATH_H
double fmod (double a, double b);
float fmodf (float a, float b);
#endif // _LIBMATH_MATH_H

3
libmath/src.mk Normal file
View File

@@ -0,0 +1,3 @@
c += math.c
o += math.o

View File

@@ -132,33 +132,59 @@ char* strcat (char* dest, const char* src) {
return rdest;
}
int isalnum (int c) { return isalpha (c) || isdigit (c); }
int isalpha (int c) { return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); }
int iscntrl (int c) { return (c >= 0 && c <= 32) || (c == 127); }
int isdigit (int c) { return (c >= '0' && c <= '9'); }
int isgraph (int c) { return (c > 32 && c <= 126); }
int islower (int c) { return (c >= 'A' && c <= 'z'); }
int isprint (int c) { return (c >= 32 && c <= 126); }
int ispunct (int c) { return isgraph (c) && !isalnum (c); }
int isspace (int c) {
return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v');
int strncmp (const char* s1, const char* s2, size_t n) {
while (n && *s1 && (*s1 == *s2)) {
++s1;
++s2;
--n;
}
if (n == 0) {
return 0;
} else {
return (*(unsigned char*)s1 - *(unsigned char*)s2);
}
}
int isupper (int c) { return (c >= 'A' && c <= 'Z'); }
/* https://stackoverflow.com/questions/49131175/recreate-the-strstr-function */
char* strstr (const char* str, const char* substring) {
const char* a;
const char* b;
int isxdigit (int c) { return isdigit (c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); }
b = substring;
int isascii (int c) { return (c >= 0 && c <= 127); }
if (*b == 0) {
return (char*)str;
}
int isblank (int c) { return (c == ' ' || c == '\t'); }
for (; *str != 0; str += 1) {
if (*str != *b) {
continue;
}
a = str;
while (1) {
if (*b == 0) {
return (char*)str;
}
if (*a++ != *b++) {
break;
}
}
b = substring;
}
return NULL;
}
/* https://github.com/gcc-mirror/gcc/blob/master/libiberty/strchr.c */
char* strchr (register const char* s, int c) {
do {
if (*s == c) {
return (char*)s;
}
} while (*s++);
return (0);
}
/* SOURCE: https://aticleworld.com/memmove-function-implementation-in-c/ */
void* memmove (void* dest, const void* src, unsigned int n) {
@@ -194,3 +220,43 @@ char* strncat (char* dest, const char* src, size_t n) {
*ptr = '\0';
return dest;
}
/* https://stackoverflow.com/questions/14476627/strcpy-implementation-in-c */
char* strcpy (char* strDest, const char* strSrc) {
char* temp = strDest;
while ((*strDest++ = *strSrc++))
;
return temp;
}
int isalnum (int c) { return isalpha (c) || isdigit (c); }
int isalpha (int c) { return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); }
int iscntrl (int c) { return (c >= 0 && c <= 32) || (c == 127); }
int isdigit (int c) { return (c >= '0' && c <= '9'); }
int isgraph (int c) { return (c > 32 && c <= 126); }
int islower (int c) { return (c >= 'A' && c <= 'z'); }
int isprint (int c) { return (c >= 32 && c <= 126); }
int ispunct (int c) { return isgraph (c) && !isalnum (c); }
int isspace (int c) {
return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v');
}
int isupper (int c) { return (c >= 'A' && c <= 'Z'); }
int isxdigit (int c) { return isdigit (c) || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); }
int isascii (int c) { return (c >= 0 && c <= 127); }
int isblank (int c) { return (c == ' ' || c == '\t'); }
int tolower (int chr) { return (chr >= 'A' && chr <= 'Z') ? (chr + 32) : (chr); }
int toupper (int chr) { return (chr >= 'a' && chr <= 'z') ? (chr - 32) : (chr); }

View File

@@ -39,6 +39,14 @@ void* memchr (const void* s, unsigned char c, size_t n);
void str_split_lines (const char* str, size_t total_len, void* ctx, strtokenize_cb_func_t cb);
char* strcpy (char* strDest, const char* strSrc);
int strncmp (const char* s1, const char* s2, size_t n);
char* strstr (const char* str, const char* substring);
char* strchr (register const char* s, int c);
int isalnum (int c);
int isalpha (int c);
@@ -65,4 +73,8 @@ int isascii (int c);
int isblank (int c);
int tolower (int chr);
int toupper (int chr);
#endif // _LIBSTRING_STRING_H

View File

@@ -1,7 +1,7 @@
apps := \
init \
spin \
ce
ce \
all_apps:
@for d in $(apps); do make -C $$d platform=$(platform) all; done

16
make/libmath.mk Normal file
View File

@@ -0,0 +1,16 @@
all_libmath:
make -C libmath platform=$(platform) all
all_compiledb_libmath:
bear --output libmath/compile_commands.json -- make -C libmath platform=$(platform) all
clean_libmath:
make -C libmath platform=$(platform) clean
format_libmath:
make -C libmath platform=$(platform) format
docs_libmath:
make -C libmath platform=$(platform) docs
.PHONY: all_libmath clean_libmath format_libmath docs_libmath all_compiledb_libmath

View File

@@ -4,16 +4,19 @@ o :=
c :=
ldflags += -L ../libsystem/build -l:libsystem.a -L ../liballoc/build -l:liballoc.a
cflags += -isystem ../libsystem -isystem ../liballoc
extra_deps +=
include src.mk
include app.mk
include ../generic/flags.mk
include ../$(platform)/flags.mk
FORMAT ?= clang-format -i $$(git ls-files '*.c' '*.h')
all: $(app)
$(app): $(o)
$(ld) -o $@ $(ldflags) -T ../$(platform)/link.ld $^
$(app): $(extra_deps) $(o)
$(ld) -o $@ $(ldflags) -T ../$(platform)/link.ld $(o)
%.o: %.c
$(cc) -c -o $@ $(cflags) $<
@@ -25,6 +28,6 @@ clean:
rm -f $(o) $(app)
format:
clang-format -i $$(git ls-files '*.c' '*.h')
$(FORMAT)
.PHONY: all clean format