diff --git a/userland/init_service/init.bin b/userland/init_service/init.bin index b7557ef..1d54a3b 100755 Binary files a/userland/init_service/init.bin and b/userland/init_service/init.bin differ diff --git a/userland/init_service/server.c b/userland/init_service/server.c index 914ee90..0a13072 100644 --- a/userland/init_service/server.c +++ b/userland/init_service/server.c @@ -33,14 +33,6 @@ static int64_t allocate_user_stack(int slave_vspace, uint64_t stack_top, uint64_ return stack_top; } -void *memcpy(void *dst, const void *src, uint64_t n) { - uint8_t *d = (uint8_t *)dst; - const uint8_t *s = (const uint8_t *)src; - while (n--) - *d++ = *s++; - return dst; -} - __attribute__((noreturn, section(".text._start"))) void _start(BootInfo_t* boot_info) { int64_t ret; @@ -181,4 +173,4 @@ void _start(BootInfo_t* boot_info) { printf("Slave process started, init going idle\n"); for (;;) { spin_pause(); } -} \ No newline at end of file +} diff --git a/userland/libOs/shared.h b/userland/libOs/shared.h index 05be5c0..354879c 100644 --- a/userland/libOs/shared.h +++ b/userland/libOs/shared.h @@ -1,12 +1,13 @@ #pragma once -#include "types.h" -#include "syscalls.h" -#include "stdlib.h" -#include "stdio.h" #include "ipc.h" #include "memory.h" +#include "stdio.h" +#include "stdlib.h" +#include "string.h" +#include "syscalls.h" #include "tcb.h" +#include "types.h" #define SYS_CAP_COPY 0x80 diff --git a/userland/libOs/string.h b/userland/libOs/string.h new file mode 100644 index 0000000..6a0bacb --- /dev/null +++ b/userland/libOs/string.h @@ -0,0 +1,71 @@ +#pragma once + +#include "types.h" + +static inline int memcmp(const char *s1, const char *s2, size_t n) { + unsigned char u1, u2; + + for (; n--; s1++, s2++){ + u1 = *(unsigned char *)s1; + u2 = *(unsigned char *)s2; + + if (u1 != u2){ + return (u1 - u2); + } + } + + return 0; +} + +static inline void* memcpy(void *restrict destination, const void *restrict source, size_t n) { + size_t *tmp_dest = (size_t *)destination; + size_t *tmp_src = (size_t *)source; + size_t len = n / sizeof(size_t); + size_t i = 0; + size_t tail = n & (sizeof(size_t) - 1); + + for (; i < len; i++) { + *tmp_dest++ = *tmp_src++; + } + + if(tail) { + char *dest = (char *)destination; + const char *src = (const char *)source; + + for(i = n - tail; i < n; i++) { + dest[i] = src[i]; + } + } + + return destination; +} + +static inline void* memset(void* ptr, int value, size_t num) { + uint8_t* bytes = ptr; + + while(num--) { + *bytes++ = (uint8_t)value; + } +} + +static inline void* memmove(void *dest, void *src, size_t count) { + void* ret = dest; + + if (dest <= src || (char*)dest >= ((char*)src + count)) { + while (count--) { + *(char*)dest = *(char*)src; + dest = (char*)dest + 1; + src = (char*)src + 1; + } + } else { + dest = (char*)dest + count - 1; + src = (char*)src + count - 1; + while (count--) { + *(char*)dest = *(char*)src; + dest = (char*)dest - 1; + src = (char*)src - 1; + } + } + + return ret; +} \ No newline at end of file diff --git a/userland/libOs/syscalls.h b/userland/libOs/syscalls.h index 8402b81..046874e 100644 --- a/userland/libOs/syscalls.h +++ b/userland/libOs/syscalls.h @@ -1,5 +1,7 @@ #pragma once +#include "types.h" + static inline int64_t syscall0(uint64_t number) { int64_t ret; __asm__ volatile ( diff --git a/userland/libOs/types.h b/userland/libOs/types.h index 5fc1e01..5da9f2c 100644 --- a/userland/libOs/types.h +++ b/userland/libOs/types.h @@ -4,10 +4,21 @@ typedef unsigned char __uint8_t; typedef unsigned short int __uint16_t; typedef unsigned int __uint32_t; typedef unsigned long int __uint64_t; + +typedef signed char __int8_t; +typedef signed short int __int16_t; +typedef signed int __int32_t; typedef signed long int __int64_t; typedef __uint8_t uint8_t; typedef __uint16_t uint16_t; typedef __uint32_t uint32_t; typedef __uint64_t uint64_t; + +typedef __int8_t int8_t; +typedef __int16_t int16_t; +typedef __int32_t int32_t; typedef __int64_t int64_t; + +typedef __SIZE_TYPE__ size_t; +typedef int64_t ssize_t; \ No newline at end of file