This commit is contained in:
Niklas Gollenstede
2025-10-31 22:37:36 +01:00
commit 174fe17e89
197 changed files with 79558 additions and 0 deletions

23
libsys/Makefile Normal file
View File

@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------
# Files to be compiled (important: defined prior to importing common.mk!)
CC_SOURCES = $(shell find * -name "*.cc")
ASM_SOURCES = $(shell find * -name "*.asm")
# -----------------------------------------------------------------------------
# Include global variables and default targets
include ../tools/common.mk
# --------------------------------------------------------------------------
# Default target
.DEFAULT_GOAL = all
all: $(BUILDDIR)/libsys.a
# --------------------------------------------------------------------------
# Package libsys.a
$(BUILDDIR)/libsys.a: $(ASM_OBJECTS) $(CC_OBJECTS) $(MAKEFILE_LIST)
@echo "AR $@"
@mkdir -p $(@D)
$(VERBOSE) $(AR) rcs $@ $(ASM_OBJECTS) $(CC_OBJECTS)

24
libsys/iostream.h Normal file
View File

@@ -0,0 +1,24 @@
#pragma once
#include "outputstream.h"
#include "stub.h"
class IOStream : public OutputStream {
private:
IOStream(IOStream &copy); // no copy
int fd;
public:
explicit IOStream(int sysfd = 0) : fd(sysfd) {}
~IOStream() {
if (pos > 0) {
sys_write(fd, buffer, pos);
}
}
void flush() override {
sys_write(fd, buffer, pos);
pos = 0;
}
};

1
libsys/libc.cc Symbolic link
View File

@@ -0,0 +1 @@
../kernel/compiler/libc.cc

1
libsys/libc.h Symbolic link
View File

@@ -0,0 +1 @@
../kernel/compiler/libc.h

1
libsys/math.h Symbolic link
View File

@@ -0,0 +1 @@
../kernel/utils/math.h

1
libsys/outputstream.cc Symbolic link
View File

@@ -0,0 +1 @@
../kernel/object/outputstream.cc

1
libsys/outputstream.h Symbolic link
View File

@@ -0,0 +1 @@
../kernel/object/outputstream.h

68
libsys/rand.cc Normal file
View File

@@ -0,0 +1,68 @@
#include "rand.h"
// Mersenne Twister (32 bit pseudorandom number generator)
// https://en.wikipedia.org/wiki/Mersenne_Twister
static const uint32_t N = 624;
static const uint32_t M = 397;
static const uint32_t R = 31;
static const uint32_t A = 0x9908B0DF;
// initialization multiplier
static const uint32_t F = 1812433253;
static const uint32_t U = 11;
static const uint32_t S = 7;
static const uint32_t B = 0x9D2C5680;
static const uint32_t T = 15;
static const uint32_t C = 0xEFC60000;
static const uint32_t L = 18;
static const uint32_t MASK_LOWER = (1ULL << R) - 1;
static const uint32_t MASK_UPPER = (1ULL << R);
static uint32_t mt[N];
static uint16_t index;
void srand(const uint32_t seed) {
mt[0] = seed;
for (uint32_t i = 1; i < N; i++) {
mt[i] = (F * (mt[i - 1] ^ (mt[i - 1] >> 30)) + i);
}
index = N;
}
uint32_t rand() {
uint16_t v = index;
if (index >= N) {
// Twist
for (uint32_t i = 0; i < N; i++) {
uint32_t x = (mt[i] & MASK_UPPER) + (mt[(i + 1) % N] & MASK_LOWER);
uint32_t xA = x >> 1;
if ((x & 0x1) != 0) {
xA ^= A;
}
mt[i] = mt[(i + M) % N] ^ xA;
}
v = index = 0;
}
uint32_t y = mt[v];
index = v + 1;
y ^= (y >> U);
y ^= (y << S) & B;
y ^= (y << T) & C;
y ^= (y >> L);
return y;
}

9
libsys/rand.h Normal file
View File

@@ -0,0 +1,9 @@
#pragma once
#include "types.h"
const uint32_t RAND_MAX = UINT32_MAX;
void srand(uint32_t seed);
uint32_t rand();

1
libsys/string.cc Symbolic link
View File

@@ -0,0 +1 @@
../kernel/utils/string.cc

1
libsys/string.h Symbolic link
View File

@@ -0,0 +1 @@
../kernel/utils/string.h

1
libsys/stringbuffer.cc Symbolic link
View File

@@ -0,0 +1 @@
../kernel/object/stringbuffer.cc

1
libsys/stringbuffer.h Symbolic link
View File

@@ -0,0 +1 @@
../kernel/object/stringbuffer.h

1
libsys/stub.asm Symbolic link
View File

@@ -0,0 +1 @@
../kernel/syscall/stub.asm

1
libsys/stub.h Symbolic link
View File

@@ -0,0 +1 @@
../kernel/syscall/stub.h

1
libsys/types.h Symbolic link
View File

@@ -0,0 +1 @@
../kernel/types.h