Compare commits
No commits in common. "59fda90b89e1f785b26afda9890dd68d641d30c1" and "f654aeb0381a16ef53a7ef1538e7ca5262e27c45" have entirely different histories.
59fda90b89
...
f654aeb038
5 changed files with 8 additions and 110 deletions
22
Makefile
22
Makefile
|
|
@ -59,8 +59,7 @@ KERNEL_OBJ := \
|
||||||
kern/libkern/memory.o \
|
kern/libkern/memory.o \
|
||||||
kern/libkern/spinlock.o \
|
kern/libkern/spinlock.o \
|
||||||
kern/libkern/mini-printf.o \
|
kern/libkern/mini-printf.o \
|
||||||
kern/libkern/stdio.o \
|
kern/libkern/stdio.o
|
||||||
kern/libkern/badrand.o
|
|
||||||
|
|
||||||
kern/kernel.elf: $(KERNEL_OBJ)
|
kern/kernel.elf: $(KERNEL_OBJ)
|
||||||
@echo LD $@
|
@echo LD $@
|
||||||
|
|
@ -102,24 +101,19 @@ QEMU_ALIAS := qemu
|
||||||
GCC_ALIAS := gcc
|
GCC_ALIAS := gcc
|
||||||
|
|
||||||
$(TOOLCHAIN_DIR):
|
$(TOOLCHAIN_DIR):
|
||||||
@mkdir -p $@
|
mkdir -p $@
|
||||||
|
|
||||||
$(QEMU_TARPATH): $(TOOLCHAIN_DIR)
|
$(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)
|
$(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)
|
get_toolchain: $(TOOLCHAIN_DIR) $(GCC_TARPATH) $(QEMU_TARPATH)
|
||||||
@echo "Unpacking qemu..."
|
cd toolchain && tar xf $(QEMU_TARBALL)
|
||||||
@cd toolchain && tar xf $(QEMU_TARBALL)
|
cd toolchain && tar xf $(GCC_TARBALL)
|
||||||
@echo "Unpacking gcc..."
|
cd $(TOOLCHAIN_DIR) && ln -sfn $(QEMU_SYM_DIR) $(QEMU_ALIAS)
|
||||||
@cd toolchain && tar xf $(GCC_TARBALL)
|
cd $(TOOLCHAIN_DIR) && ln -sfn $(GCC_SYM_DIR) $(GCC_ALIAS)
|
||||||
@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!"
|
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
rm -rf $(TOOLCHAIN_DIR)
|
rm -rf $(TOOLCHAIN_DIR)
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,6 @@ root
|
||||||
|
|
||||||
### Quick Start
|
### 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
|
```sh
|
||||||
make get_toolchain # Dont worry, is will land locally inside project directory
|
make get_toolchain # Dont worry, is will land locally inside project directory
|
||||||
make -j$(nproc)
|
make -j$(nproc)
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
#include "badrand.h"
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
#ifndef BADRAND_H
|
|
||||||
#define BADRAND_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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
|
|
||||||
|
|
@ -12,18 +12,3 @@ typedef unsigned long uint64_t;
|
||||||
typedef uint64_t size_t;
|
typedef uint64_t size_t;
|
||||||
|
|
||||||
typedef uint64_t uintptr_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))
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue