diff --git a/Makefile b/Makefile index 928c492..3bd5aea 100644 --- a/Makefile +++ b/Makefile @@ -59,8 +59,7 @@ KERNEL_OBJ := \ kern/libkern/memory.o \ kern/libkern/spinlock.o \ kern/libkern/mini-printf.o \ - kern/libkern/stdio.o \ - kern/libkern/badrand.o + kern/libkern/stdio.o kern/kernel.elf: $(KERNEL_OBJ) @echo LD $@ @@ -102,24 +101,19 @@ QEMU_ALIAS := qemu GCC_ALIAS := gcc $(TOOLCHAIN_DIR): - @mkdir -p $@ + mkdir -p $@ $(QEMU_TARPATH): $(TOOLCHAIN_DIR) - @echo "Fetching qemu-riscv-xpack: v$(QEMU_VER)" - @curl -# -L -o $@ $(QEMU_URL) + curl -# -L -o $@ $(QEMU_URL) $(GCC_TARPATH): $(TOOLCHAIN_DIR) - @echo "Fetching riscv-none-elf-gcc-xpack: v$(GCC_VER)" - @curl -# -L -o $@ $(GCC_URL) + curl -# -L -o $@ $(GCC_URL) get_toolchain: $(TOOLCHAIN_DIR) $(GCC_TARPATH) $(QEMU_TARPATH) - @echo "Unpacking qemu..." - @cd toolchain && tar xf $(QEMU_TARBALL) - @echo "Unpacking gcc..." - @cd toolchain && tar xf $(GCC_TARBALL) - @cd $(TOOLCHAIN_DIR) && ln -sfn $(QEMU_SYM_DIR) $(QEMU_ALIAS) - @cd $(TOOLCHAIN_DIR) && ln -sfn $(GCC_SYM_DIR) $(GCC_ALIAS) - @echo "Toolchain in place, ready to make!" + cd toolchain && tar xf $(QEMU_TARBALL) + cd toolchain && tar xf $(GCC_TARBALL) + cd $(TOOLCHAIN_DIR) && ln -sfn $(QEMU_SYM_DIR) $(QEMU_ALIAS) + cd $(TOOLCHAIN_DIR) && ln -sfn $(GCC_SYM_DIR) $(GCC_ALIAS) distclean: clean rm -rf $(TOOLCHAIN_DIR) diff --git a/README.md b/README.md index 52fd5e1..177f304 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,6 @@ root ### Quick Start -On a linux machine, make sure that you have `make` and `curl` in path. The rest -of the tooling (gcc, qemu) will be handled by the build system. - ```sh make get_toolchain # Dont worry, is will land locally inside project directory make -j$(nproc) diff --git a/kern/libkern/badrand.c b/kern/libkern/badrand.c deleted file mode 100644 index 48df698..0000000 --- a/kern/libkern/badrand.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "badrand.h" -#include - -#define PRAND_BUILD_SEED \ - ((uint64_t)(__TIME__[0]) * (uint64_t)(__TIME__[1]) * (uint64_t)(__TIME__[3]) * (uint64_t)(__TIME__[4]) * \ - (uint64_t)(__TIME__[6]) * (uint64_t)(__TIME__[7])) - -static uint64_t seed = PRAND_BUILD_SEED * 6364136223846793005ULL + 1; - -uint64_t badrand() { - seed = seed * 6364136223846793005ULL + 1; - return seed; -} - -uint64_t badrand_range(uint64_t min, uint64_t max) { - uint64_t range = max - min + 1; - uint64_t x; - uint64_t limit = UINT64_MAX - (UINT64_MAX % range); - - do { - x = badrand(); - } while (x > limit); - - return min + (x % range); -} - -void sbadprand(uint64_t s) { - if (s) { - seed ^= (s * 0x9e3779b97f4a7c15ULL) + (seed << 6) + (seed >> 2); - } else { - seed ^= PRAND_BUILD_SEED; - } -} - -#undef PRAND_BUILD_SEED diff --git a/kern/libkern/badrand.h b/kern/libkern/badrand.h deleted file mode 100644 index 8a0ab9c..0000000 --- a/kern/libkern/badrand.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef BADRAND_H -#define BADRAND_H - -#include - -/* - * This is a PRNG for non-cryptographic use. - * - * See: - * https://en.wikipedia.org/wiki/Linear_congruential_generator - */ - -/** - * @brief Sets the seed for the PRNG. - * - * @param s The specific seed value or zero. If zero is passed, it will call - * rand_reseed(). - */ -void sbadrand(uint64_t s); - -/** - * @brief Generates a pseudo-random 64-bit number. - * - * Uses a simple Linear Congruential Generator (LCG) to produce - * a sequence of pseudo-random numbers. - * - * @return A pseudo-random 64-bit unsigned integer. - */ -uint64_t badrand(); - -/** - * @brief Generates a random number within a specified range. - * - * Produces a random number in the inclusive range [min, max]. - * Ensures uniform distribution by applying a modulo operation. - * - * @param min The lower bound of the range (inclusive). - * @param max The upper bound of the range (inclusive). - * @return A random number between min and max. - */ -uint64_t badrand_range(uint64_t min, uint64_t max); - -#endif // BADRAND_H diff --git a/kern/libkern/stdint.h b/kern/libkern/stdint.h index 095e598..0ce4c00 100644 --- a/kern/libkern/stdint.h +++ b/kern/libkern/stdint.h @@ -12,18 +12,3 @@ typedef unsigned long uint64_t; typedef uint64_t size_t; typedef uint64_t uintptr_t; - -#define INT8_MIN (-128) -#define INT16_MIN (-32767 - 1) -#define INT32_MIN (-2147483647 - 1) -#define INT64_MIN (-__INT64_C(9223372036854775807) - 1) - -#define INT8_MAX (127) -#define INT16_MAX (32767) -#define INT32_MAX (2147483647) -#define INT64_MAX (__INT64_C(9223372036854775807)) - -#define UINT8_MAX (255) -#define UINT16_MAX (65535) -#define UINT32_MAX (4294967295U) -#define UINT64_MAX (__UINT64_C(18446744073709551615))