diff options
Diffstat (limited to 'src/library/std')
-rw-r--r-- | src/library/std/mutex.c | 22 | ||||
-rw-r--r-- | src/library/std/stdio.c | 51 | ||||
-rw-r--r-- | src/library/std/string.c | 79 |
3 files changed, 0 insertions, 152 deletions
diff --git a/src/library/std/mutex.c b/src/library/std/mutex.c deleted file mode 100644 index ac0ee8f..0000000 --- a/src/library/std/mutex.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <mutex.h> - -static uint32_t atomic_exchange(uint32_t* ptr, uint32_t newval) { - uint32_t r; - asm volatile("xchg (%%ecx), %%eax" : "=a"(r) : "c"(ptr), "a"(newval)); - return r; -} - -void mutex_lock(uint32_t* mutex) { - while (atomic_exchange(mutex, MUTEX_LOCKED) == MUTEX_LOCKED) { - thread_sleep(1); - } -} - -int mutex_lockE(uint32_t* mutex) { - if (atomic_exchange(mutex, MUTEX_LOCKED) == MUTEX_LOCKED) return 0; - return 1; -} - -void mutex_unlock(uint32_t* mutex) { - *mutex = MUTEX_UNLOCKED; -} diff --git a/src/library/std/stdio.c b/src/library/std/stdio.c deleted file mode 100644 index 3b24da1..0000000 --- a/src/library/std/stdio.c +++ /dev/null @@ -1,51 +0,0 @@ -#include <stdlib.h> - -void printk_int(int number) { - if (number == 0) { - printk("0"); - return; - } - int negative = 0; - if (number < 0) { - negative = 1; - number = 0 - number; - } - int order = 0, temp = number, i; - char numbers[] = "0123456789"; - while (temp > 0) { - order++; - temp /= 10; - } - - char *s, *r; - s = malloc(order + (negative ? 2 : 1)); - if (negative) { - s[0] = '-'; - r = s + 1; - } else { - r = s; - } - - for (i = order; i > 0; i--) { - r[i - 1] = numbers[number % 10]; - number /= 10; - } - r[order] = 0; - printk(s); - free(s); -} - -void printk_hex(unsigned v) { - char s[11] = {'0', 'x', 0}; - - int i; - - char hexdigits[] = "0123456789ABCDEF"; - - for (i = 0; i < 8; i++) { - s[i + 2] = (hexdigits[v >> 28]); - v = v << 4; - } - s[11] = 0; - printk(s); -} diff --git a/src/library/std/string.c b/src/library/std/string.c deleted file mode 100644 index 4c374ad..0000000 --- a/src/library/std/string.c +++ /dev/null @@ -1,79 +0,0 @@ -#include <string.h> - -int strlen(const char *str) { - int i = 0; - while (str[i++]); - return i; -} - -char *strchr(const char *str, char c) { - while (*str) { - if (*str == c) return (char*)str; - str++; - } - return NULL; -} - -char *strcpy(char *dest, const char *src) { - memcpy(dest, src, strlen(src) + 1); - return (char*)src; -} - -char *strdup(const char *src) { - char* ret = malloc(strlen(src) + 1); - if (ret == NULL) return ret; - strcpy(ret, src); - return ret; -} - -char *strcat(char *dest, const char *src) { - char *dest2 = dest; - dest2 += strlen(dest) - 1; - while (*src) { - *dest2 = *src; - src++; - dest2++; - } - *dest2 = 0; - return dest; -} - -int strcmp(const char *s1, const char *s2) { - while ((*s1) && (*s1 == *s2)) { - s1++; - s2++; - } - return (* (unsigned char*)s1 - *(unsigned char*)s2); -} - -void *memcpy(void *vd, const void *vs, int count) { - uint8_t *dest = (uint8_t*)vd, *src = (uint8_t*)vs; - uint32_t f = count % 4, n = count / 4, i; - const uint32_t* s = (uint32_t*)src; - uint32_t* d = (uint32_t*)dest; - for (i = 0; i < n; i++) { - d[i] = s[i]; - } - if (f != 0) { - for (i = count - f; i < count; i++) { - dest[i] = src[i]; - } - } - return vd; -} - -uint8_t *memset(uint8_t *dest, uint8_t val, int count) { - int i; - for (i = 0; i < count; i++) { - dest[i] = val; - } - return dest; -} - -uint16_t *memsetw(uint16_t *dest, uint16_t val, int count) { - int i; - for (i = 0; i < count; i++) { - dest[i] = val; - } - return dest; -} |