kernel: Rewrite from scratch since the current thing is held by duct tape (lmao)
This commit is contained in:
parent
d017412af5
commit
a1e27c2730
117 changed files with 285 additions and 13622 deletions
|
@ -1,18 +0,0 @@
|
|||
#include <stdint.h>
|
||||
/*int __eqdf2(double a, double b) {
|
||||
union { double f; uint64_t i; } ua = { a }, ub = { b };
|
||||
return ua.i == ub.i;
|
||||
}
|
||||
int __ltdf2(double a, double b) {
|
||||
if (a < b) return -1;
|
||||
if (a > b) return 1;
|
||||
return 0;
|
||||
}
|
||||
double __truncxfdf2(double x) {
|
||||
return (double)x;
|
||||
}
|
||||
int __gtdf2(double a, double b) {
|
||||
if (a > b) return 1;
|
||||
if (a < b) return -1;
|
||||
return 0;
|
||||
}**/
|
|
@ -1,31 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct spinlock {
|
||||
volatile int locked;
|
||||
} spinlock_t;
|
||||
|
||||
static inline void spinlock_acquire(spinlock_t *lock) {
|
||||
// uint64_t timeout = 1000000; // Adjust this value based on your needs
|
||||
|
||||
for (;;) {
|
||||
if (__atomic_exchange_n(&lock->locked, 1, __ATOMIC_ACQUIRE) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (__atomic_load_n(&lock->locked, __ATOMIC_RELAXED)) {
|
||||
/**if (--timeout == 0) {
|
||||
// Force unlock after too many attempts
|
||||
__atomic_store_n(&lock->locked, 0, __ATOMIC_RELEASE);
|
||||
continue;
|
||||
}**/
|
||||
__asm__ volatile("pause" ::: "memory");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void spinlock_release(spinlock_t *lock) {
|
||||
__atomic_store_n(&lock->locked, 0, __ATOMIC_RELEASE);
|
||||
}
|
|
@ -1,134 +1,8 @@
|
|||
#include <lib/string.h>
|
||||
#include <mm/liballoc/liballoc.h>
|
||||
#include <mm/memop.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static char *olds;
|
||||
|
||||
int strlen(const char *str) {
|
||||
int len = 0;
|
||||
while (str[len])
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
|
||||
int strcmp(const char *s1, const char *s2) {
|
||||
while (*s1 && *s1 == *s2) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return *s1 - *s2;
|
||||
}
|
||||
|
||||
char *strcpy(char *dest, const char *src) {
|
||||
if (dest == NULL || src == NULL)
|
||||
return NULL;
|
||||
|
||||
char *temp = dest;
|
||||
while ((*dest++ = *src++) != '\0')
|
||||
;
|
||||
return temp;
|
||||
}
|
||||
|
||||
char *strchr(const char *s, int c) {
|
||||
while (*s++) {
|
||||
if (*s == c)
|
||||
return (char *)s;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *strrchr(const char *s, int c) {
|
||||
const char *p = NULL;
|
||||
|
||||
for (;;) {
|
||||
if (*s == (char)c)
|
||||
p = s;
|
||||
if (*s++ == '\0')
|
||||
return (char *)p;
|
||||
}
|
||||
}
|
||||
|
||||
int oct2bin(unsigned char *str, int size) {
|
||||
int n = 0;
|
||||
unsigned char *c = str;
|
||||
while (size-- > 0) {
|
||||
n *= 8;
|
||||
n += *c - '0';
|
||||
c++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
char *strdup(const char *str) {
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
|
||||
int len = strlen(str);
|
||||
char *dup = (char *)malloc(len + 1);
|
||||
if (dup == NULL)
|
||||
return NULL;
|
||||
|
||||
strcpy(dup, str);
|
||||
return dup;
|
||||
}
|
||||
|
||||
char *strncpy(char *dest, const char *src, size_t n) {
|
||||
size_t i;
|
||||
for (i = 0; i < n && src[i] != '\0'; i++)
|
||||
dest[i] = src[i];
|
||||
for (; i < n; i++)
|
||||
dest[i] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
#define DICT_LEN 256
|
||||
|
||||
static int *create_delim_dict(char *delim) {
|
||||
int *d = (int *)malloc(sizeof(int) * DICT_LEN);
|
||||
memset((void *)d, 0, sizeof(int) * DICT_LEN);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < strlen(delim); i++) {
|
||||
d[delim[i]] = 1;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
char *strtok(char *str, char *delim) {
|
||||
|
||||
static char *last, *to_free;
|
||||
int *deli_dict = create_delim_dict(delim);
|
||||
|
||||
if (!deli_dict) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (str) {
|
||||
last = (char *)malloc(strlen(str) + 1);
|
||||
if (!last) {
|
||||
free(deli_dict);
|
||||
}
|
||||
to_free = last;
|
||||
strcpy(last, str);
|
||||
}
|
||||
|
||||
while (deli_dict[*last] && *last != '\0') {
|
||||
last++;
|
||||
}
|
||||
str = last;
|
||||
if (*last == '\0') {
|
||||
free(deli_dict);
|
||||
free(to_free);
|
||||
return NULL;
|
||||
}
|
||||
while (*last != '\0' && !deli_dict[*last]) {
|
||||
last++;
|
||||
}
|
||||
|
||||
*last = '\0';
|
||||
last++;
|
||||
|
||||
free(deli_dict);
|
||||
return str;
|
||||
}
|
||||
size_t strlen(char *str) {
|
||||
size_t i = 0;
|
||||
while (str[i] != '\0')
|
||||
i++;
|
||||
return i;
|
||||
}
|
|
@ -1,12 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
int strlen(const char *str);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
char *strchr(const char *s, int c);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strrchr(const char *s, int c);
|
||||
int oct2bin(unsigned char *str, int size);
|
||||
char *strdup(const char *str);
|
||||
char *strncpy(char *dest, const char *src, size_t n);
|
||||
char *strtok(char *str, char *delim);
|
||||
size_t strlen(char *str);
|
Loading…
Add table
Add a link
Reference in a new issue