diff options
Diffstat (limited to 'src/userspace/libc')
39 files changed, 0 insertions, 784 deletions
diff --git a/src/userspace/libc/assert.h b/src/userspace/libc/assert.h deleted file mode 100644 index 5ff70ab..0000000 --- a/src/userspace/libc/assert.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef MELVIX_ASSERT_H -#define MELVIX_ASSERT_H - -#define __FILENAME__ \ - (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) -#define assert(exp) (exp) ? 0 : _assert(__FILENAME__, __LINE__, __func__, #exp) - -#endif
\ No newline at end of file diff --git a/src/userspace/libc/assert/assert.c b/src/userspace/libc/assert/assert.c deleted file mode 100644 index efd9083..0000000 --- a/src/userspace/libc/assert/assert.c +++ /dev/null @@ -1,8 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -void _assert(const char *file, int line, const char *func, const char *exp) -{ - printf("%s:%d: %s: Assertion '%s' failed", file, line, func, exp); - exit(1); -}
\ No newline at end of file diff --git a/src/userspace/libc/math.h b/src/userspace/libc/math.h deleted file mode 100644 index 0ecde4e..0000000 --- a/src/userspace/libc/math.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MELVIX_MATH_H -#define MELVIX_MATH_H - -// Trigonometric - -// Hyperbolic - -// Exponential and logarithmic - -// Power -int pow(int base, int exp); - -// Error and gamma - -// Rounding and remainder - -// Floating point manipulation - -// Minimum, maximum, difference - -#endif
\ No newline at end of file diff --git a/src/userspace/libc/math/pow.c b/src/userspace/libc/math/pow.c deleted file mode 100644 index 5cdcfa5..0000000 --- a/src/userspace/libc/math/pow.c +++ /dev/null @@ -1,13 +0,0 @@ -int pow(int base, int exp) -{ - if (exp < 0) - return 0; - - if (!exp) - return 1; - - int ret = base; - for (int i = 1; i < exp; i++) - ret *= base; - return ret; -}
\ No newline at end of file diff --git a/src/userspace/libc/stdio.h b/src/userspace/libc/stdio.h deleted file mode 100644 index d6779dd..0000000 --- a/src/userspace/libc/stdio.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MELVIX_STDIO_H -#define MELVIX_STDIO_H - -#include <stdarg.h> - -// File operations - -// Character input/output -char getch(); -void putch(char ch); -void puts(char *data); - -void printf(char *fmt, ...); -void vprintf(char *fmt, va_list args); - -#endif
\ No newline at end of file diff --git a/src/userspace/libc/stdio/getch.c b/src/userspace/libc/stdio/getch.c deleted file mode 100644 index 5f9655a..0000000 --- a/src/userspace/libc/stdio/getch.c +++ /dev/null @@ -1,75 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -// TODO: Move keymaps somewhere more appropriate -char keymap[128] = { - 0 /*E*/, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', - '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', - '\n', 17 /*C*/, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', - 14 /*LS*/, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 14 /*RS*/, '*', - 0, // Alt key - ' ', // Space bar - 15, // Caps lock - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // F keys - 0, // Num lock - 0, // Scroll lock - 0, // Home key - 0, // Up arrow - 0, // Page up - '-', - 0, // Left arrow - 0, - 0, // Right arrow - '+', - 0, // End key - 0, // Down arrow - 0, // Page down - 0, // Insert key - 0, // Delete key - 0, 0, 0, - 0, // F11 - 0, // F12 - 0, // Other keys -}; - -char shift_keymap[128] = { - 0 /*E*/, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', - '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', - '\n', 17 /*C*/, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', - 14 /*LS*/, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 14 /*RS*/, '*', - 0, // Alt key - ' ', // Space bar - 15, // Caps lock - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // F keys - 0, // Num lock - 0, // Scroll lock - 0, // Home key - 0, // Up arrow - 0, // Page up - '-', - 0, // Left arrow - 0, - 0, // Right arrow - '+', - 0, // End key - 0, // Down arrow - 0, // Page down - 0, // Insert key - 0, // Delete key - 0, 0, 0, - 0, // F11 - 0, // F12 - 0, // Other keys -}; - -char *getch() -{ - // TODO: Add shift support - // TODO: Implement keyboard dev driver - u8 scancode = 42; //syscall_scancode(); - if ((scancode & 0x80) == 0) { // Press - return keymap[scancode]; - } else { // Release - return 0; - } -}
\ No newline at end of file diff --git a/src/userspace/libc/stdio/printf.c b/src/userspace/libc/stdio/printf.c deleted file mode 100644 index 3951250..0000000 --- a/src/userspace/libc/stdio/printf.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdarg.h> -#include <stdio.h> - -void printf(char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); -}
\ No newline at end of file diff --git a/src/userspace/libc/stdio/putch.c b/src/userspace/libc/stdio/putch.c deleted file mode 100644 index 2dad6dc..0000000 --- a/src/userspace/libc/stdio/putch.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <syscall.h> - -int is_transmit_empty() -{ - u8 value; - asm volatile("inb %1, %0" : "=a"(value) : "Nd"(0x3f8 + 5)); - return value & 0x20; -} - -void putch(char ch) -{ - while (is_transmit_empty() == 0) - ; - asm volatile("outb %0, %1" ::"a"(ch), "Nd"(0x3f8)); -} - -/*void putch(char ch) -{ - // TODO: Implement framebuffer writing - //if (ch != 0) - //syscall_putch(ch); -}*/
\ No newline at end of file diff --git a/src/userspace/libc/stdio/puts.c b/src/userspace/libc/stdio/puts.c deleted file mode 100644 index 979dd0a..0000000 --- a/src/userspace/libc/stdio/puts.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -void puts(char *data) -{ - for (u32 i = 0; i < strlen(data); i++) - putch(data[i]); -}
\ No newline at end of file diff --git a/src/userspace/libc/stdio/vprintf.c b/src/userspace/libc/stdio/vprintf.c deleted file mode 100644 index 691f153..0000000 --- a/src/userspace/libc/stdio/vprintf.c +++ /dev/null @@ -1,46 +0,0 @@ -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> - -void vprintf(char *fmt, va_list args) -{ - u8 readyToFormat = 0; - - char buff = 0; - - for (; *fmt; fmt++) { - if (readyToFormat) { - if (*fmt == '%') { - putch('%'); - readyToFormat = 0; - continue; - } - - buff = *fmt; - if (buff == 's') { - char *str = va_arg(args, char *); - puts(str); - readyToFormat = 0; - } else if (buff == 'x') { - char *p = htoa((u32)va_arg(args, int)); - puts(p); - free(p); - readyToFormat = 0; - } else if (buff == 'd') { - char *p = itoa(va_arg(args, int)); - puts(p); - free(p); - readyToFormat = 0; - } else if (buff == 'c') { - putch((char)va_arg(args, int)); - readyToFormat = 0; - } - } else { - if (*fmt == '%') - readyToFormat = 1; - else - putch(*fmt); - } - } -}
\ No newline at end of file diff --git a/src/userspace/libc/stdlib.h b/src/userspace/libc/stdlib.h deleted file mode 100644 index 4670b8c..0000000 --- a/src/userspace/libc/stdlib.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MELVIX_STDLIB_H -#define MELVIX_STDLIB_H - -#include <stdint.h> - -// String conversion -char *itoa(int n); -int atoi(char *str); -char *htoa(u32 n); -int htoi(char *str); - -// Exit functions -void exit(u32 code); -#define EXIT_SUCCESS 0 -#define EXIT_FAILURE 1 - -// Memory management -void *malloc(u32 size); -void free(void *addr); - -#endif
\ No newline at end of file diff --git a/src/userspace/libc/stdlib/atoi.c b/src/userspace/libc/stdlib/atoi.c deleted file mode 100644 index 80897eb..0000000 --- a/src/userspace/libc/stdlib/atoi.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <math.h> -#include <stddef.h> -#include <stdint.h> -#include <string.h> - -int atoi(char *str) -{ - u32 s_str = strlen(str); - if (!s_str) - return 0; - - u32 negative = 0; - if (str[0] == '-') - negative = 1; - - u32 i = 0; - if (negative) - i++; - - int ret = 0; - for (; i < s_str; i++) { - ret += (str[i] - '0') * pow(10, (int)((s_str - i) - 1)); - } - - if (negative) - ret *= -1; - return ret; -}
\ No newline at end of file diff --git a/src/userspace/libc/stdlib/exit.c b/src/userspace/libc/stdlib/exit.c deleted file mode 100644 index 03b54fe..0000000 --- a/src/userspace/libc/stdlib/exit.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -void exit(u32 code) -{ - syscall_exit(code); - while (1) { - }; -}
\ No newline at end of file diff --git a/src/userspace/libc/stdlib/free.c b/src/userspace/libc/stdlib/free.c deleted file mode 100644 index 65e9769..0000000 --- a/src/userspace/libc/stdlib/free.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -void free(void *addr) -{ - syscall_free((u32)addr); -}
\ No newline at end of file diff --git a/src/userspace/libc/stdlib/htoa.c b/src/userspace/libc/stdlib/htoa.c deleted file mode 100644 index 2b7d5c4..0000000 --- a/src/userspace/libc/stdlib/htoa.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -static const char HTOA_TABLE[] = "0123456789ABCDEF"; - -char *htoa(u32 n) -{ - char *ret = (char *)malloc(10); - - int i = 0; - while (n) { - ret[i++] = HTOA_TABLE[n & 0xF]; - n >>= 4; - } - - if (!i) { - ret[0] = '0'; - i++; - } - - for (; i <= 9; i++) - ret[i] = 0; - - char *aux = strdup(ret); - free(ret); - ret = aux; - - strinv(ret); - return ret; -}
\ No newline at end of file diff --git a/src/userspace/libc/stdlib/htoi.c b/src/userspace/libc/stdlib/htoi.c deleted file mode 100644 index 0d0ab30..0000000 --- a/src/userspace/libc/stdlib/htoi.c +++ /dev/null @@ -1,24 +0,0 @@ -#include <math.h> -#include <stddef.h> -#include <stdint.h> -#include <string.h> - -int htoi(char *str) -{ - u32 s_str = strlen(str); - - u32 i = 0; - int ret = 0; - for (; i < s_str; i++) { - char c = str[i]; - int aux = 0; - if (c >= '0' && c <= '9') - aux = c - '0'; - else if (c >= 'A' && c <= 'F') - aux = (c - 'A') + 10; - - ret += aux * pow(16, (int)((s_str - i) - 1)); - } - - return ret; -}
\ No newline at end of file diff --git a/src/userspace/libc/stdlib/itoa.c b/src/userspace/libc/stdlib/itoa.c deleted file mode 100644 index b960796..0000000 --- a/src/userspace/libc/stdlib/itoa.c +++ /dev/null @@ -1,43 +0,0 @@ -#include <math.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> - -static const char ITOA_TABLE[] = "0123456789"; - -char *itoa(int n) -{ - if (!n) { - char *ret = (char *)malloc(2); - ret[0] = '0'; - ret[1] = 0; - return ret; - } - u32 negative = (u32)(n < 0); - if (negative) - n *= -1; - - int sz; - for (sz = 0; n % pow(10, sz) != n; sz++) { - } - - char *ret = (char *)malloc((u32)(sz + 1)); - - for (int i = 0; i < sz; i++) { - int digit = (n % pow(10, i + 1)) / pow(10, i); - ret[i] = ITOA_TABLE[digit]; - } - ret[sz] = 0; - - if (negative) { - char *aux = (char *)malloc((u32)(sz + 2)); - strcpy(aux, ret); - aux[sz] = '-'; - aux[sz + 1] = 0; - free(ret); - ret = aux; - } - - strinv(ret); - return ret; -}
\ No newline at end of file diff --git a/src/userspace/libc/stdlib/malloc.c b/src/userspace/libc/stdlib/malloc.c deleted file mode 100644 index 5eb3caa..0000000 --- a/src/userspace/libc/stdlib/malloc.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -void *malloc(u32 size) -{ - return (void *)syscall_malloc(size); -}
\ No newline at end of file diff --git a/src/userspace/libc/string.h b/src/userspace/libc/string.h deleted file mode 100644 index 2eb2fb6..0000000 --- a/src/userspace/libc/string.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MELVIX_STRING_H -#define MELVIX_STRING_H - -#include <stddef.h> -#include <stdint.h> - -u32 strlen(char *str); - -void strcpy(char *dest, char *orig); - -void strdisp(char *str, int n); - -void strcat(char *dest, char *orig); - -void strcati(char *dest, char *orig); - -char strcmp(char *a, char *b); - -int strncmp(char *s1, char *s2, int c); - -char *strdup(char *orig); - -void strinv(char *str); - -char *strstr(char *in, char *str); - -char *strsep(char **stringp, char *delim); - -#endif
\ No newline at end of file diff --git a/src/userspace/libc/string/strcat.c b/src/userspace/libc/string/strcat.c deleted file mode 100644 index bb8f09b..0000000 --- a/src/userspace/libc/string/strcat.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdint.h> -#include <string.h> - -void strcat(char *dest, char *orig) -{ - u32 s_dest = strlen(dest); - u32 s_orig = strlen(orig); - - for (u32 i = 0; i < s_orig; i++) - dest[s_dest + i] = orig[i]; - dest[s_dest + s_orig] = 0; -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strcati.c b/src/userspace/libc/string/strcati.c deleted file mode 100644 index d82fbfc..0000000 --- a/src/userspace/libc/string/strcati.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <stdint.h> -#include <string.h> - -void strcati(char *dest, char *orig) -{ - u32 s_orig = strlen(orig); - strdisp(dest, (int)s_orig); - for (u32 i = 0; i < s_orig; i++) - dest[i] = orig[i]; -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strcmp.c b/src/userspace/libc/string/strcmp.c deleted file mode 100644 index 932877d..0000000 --- a/src/userspace/libc/string/strcmp.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdint.h> -#include <string.h> - -char strcmp(char *a, char *b) -{ - if (strlen(a) != strlen(b)) - return 1; - - for (u32 i = 0; i < strlen(a); i++) - if (a[i] != b[i]) - return 1; - - return 0; -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strcpy.c b/src/userspace/libc/string/strcpy.c deleted file mode 100644 index a12d3e0..0000000 --- a/src/userspace/libc/string/strcpy.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <stdint.h> -#include <string.h> - -void strcpy(char *dest, char *orig) -{ - u32 s_orig = strlen(orig); - - for (u32 i = 0; i < s_orig; i++) - dest[i] = orig[i]; - dest[s_orig] = 0; -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strdisp.c b/src/userspace/libc/string/strdisp.c deleted file mode 100644 index 88815ef..0000000 --- a/src/userspace/libc/string/strdisp.c +++ /dev/null @@ -1,15 +0,0 @@ -#include <stdint.h> -#include <string.h> - -void strdisponce(char *str) -{ - for (u32 i = sizeof(str) + 2; i > 0; i--) - str[i] = str[i - 1]; - str[0] = 0; -} - -void strdisp(char *str, int n) -{ - for (int i = 0; i < n; i++) - strdisponce(str); -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strdup.c b/src/userspace/libc/string/strdup.c deleted file mode 100644 index a42b02d..0000000 --- a/src/userspace/libc/string/strdup.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdint.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -char *strdup(char *orig) -{ - u32 s_orig = strlen(orig); - char *ret = (char *)malloc(s_orig + 1); - strcpy(ret, orig); - return ret; -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strinv.c b/src/userspace/libc/string/strinv.c deleted file mode 100644 index 261e57e..0000000 --- a/src/userspace/libc/string/strinv.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <stdint.h> -#include <string.h> - -void strinv(char *str) -{ - u32 s_str = strlen(str); - - int iterations = (int)s_str / 2; - for (int i = 0; i < iterations; i++) { - char aux = str[i]; - str[i] = str[(s_str - i) - 1]; - str[(s_str - i) - 1] = aux; - } -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strlen.c b/src/userspace/libc/string/strlen.c deleted file mode 100644 index cb04675..0000000 --- a/src/userspace/libc/string/strlen.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <stdint.h> - -u32 strlen(char *str) -{ - u32 len = 0; - while (str[len]) - len++; - return len; -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strncmp.c b/src/userspace/libc/string/strncmp.c deleted file mode 100644 index 450fbd8..0000000 --- a/src/userspace/libc/string/strncmp.c +++ /dev/null @@ -1,16 +0,0 @@ -int strncmp(char *s1, char *s2, int c) -{ - int result = 0; - - while (c) { - result = *s1 - *s2++; - - if ((result != 0) || (*s1++ == 0)) { - break; - } - - c--; - } - - return result; -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strsep.c b/src/userspace/libc/string/strsep.c deleted file mode 100644 index badbf0f..0000000 --- a/src/userspace/libc/string/strsep.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stddef.h> - -char *strsep(char **stringp, char *delim) -{ - char *s; - const char *spanp; - int c, sc; - char *tok; - if ((s = *stringp) == NULL) - return (NULL); - for (tok = s;;) { - c = *s++; - spanp = delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *stringp = s; - return (tok); - } - } while (sc != 0); - } -}
\ No newline at end of file diff --git a/src/userspace/libc/string/strstr.c b/src/userspace/libc/string/strstr.c deleted file mode 100644 index c87f3fc..0000000 --- a/src/userspace/libc/string/strstr.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stdint.h> -#include <string.h> - -char *strstr(char *in, char *str) -{ - char c; - u32 len; - - c = *str++; - if (!c) - return (char *)in; - - len = strlen(str); - do { - char sc; - - do { - sc = *in++; - if (!sc) - return (char *)0; - } while (sc != c); - } while (strncmp(in, str, len) != 0); - - return (char *)(in - 1); -}
\ No newline at end of file diff --git a/src/userspace/libc/syscall.c b/src/userspace/libc/syscall.c deleted file mode 100644 index fb00a12..0000000 --- a/src/userspace/libc/syscall.c +++ /dev/null @@ -1,30 +0,0 @@ -#include <common.h> -#include <stdint.h> -#include <syscall.h> - -/** - * DEFINITIONS - */ -DEFN_SYSCALL0(halt, SYS_HALT); - -DEFN_SYSCALL1(exit, SYS_EXIT, u32); - -DEFN_SYSCALL4(read, SYS_READ, char *, u32, u32, u8 *); - -DEFN_SYSCALL4(write, SYS_WRITE, char *, u32, u32, u8 *); - -DEFN_SYSCALL1(exec, SYS_EXEC, char *); - -DEFN_SYSCALL1(spawn, SYS_SPAWN, char *); - -DEFN_SYSCALL3(wait, SYS_WAIT, u32, u32 *, u32); - -DEFN_SYSCALL0(get_pid, SYS_GET_PID); - -DEFN_SYSCALL1(malloc, SYS_MALLOC, u32); - -DEFN_SYSCALL1(free, SYS_FREE, u32); - -DEFN_SYSCALL1(get, SYS_GET, u32); - -DEFN_SYSCALL2(map, SYS_MAP, u32, u8 *);
\ No newline at end of file diff --git a/src/userspace/libc/syscall.h b/src/userspace/libc/syscall.h deleted file mode 100644 index cb1551a..0000000 --- a/src/userspace/libc/syscall.h +++ /dev/null @@ -1,97 +0,0 @@ -#ifndef MELVIX_SYSCALL_H -#define MELVIX_SYSCALL_H - -#include <stdint.h> - -#define DECL_SYSCALL0(fn) int syscall_##fn(); -#define DECL_SYSCALL1(fn, p1) int syscall_##fn(p1); -#define DECL_SYSCALL2(fn, p1, p2) int syscall_##fn(p1, p2); -#define DECL_SYSCALL3(fn, p1, p2, p3) int syscall_##fn(p1, p2, p3); -#define DECL_SYSCALL4(fn, p1, p2, p3, p4) int syscall_##fn(p1, p2, p3, p4); -#define DECL_SYSCALL5(fn, p1, p2, p3, p4, p5) int syscall_##fn(p1, p2, p3, p4, p5); - -#define DEFN_SYSCALL0(fn, num) \ - int syscall_##fn() \ - { \ - int a; \ - asm volatile("int $0x80" : "=a"(a) : "0"(num)); \ - return a; \ - } - -#define DEFN_SYSCALL1(fn, num, P1) \ - int syscall_##fn(P1 p1) \ - { \ - int a; \ - asm volatile("int $0x80" : "=a"(a) : "0"(num), "b"((int)p1)); \ - return a; \ - } - -#define DEFN_SYSCALL2(fn, num, P1, P2) \ - int syscall_##fn(P1 p1, P2 p2) \ - { \ - int a; \ - asm volatile("int $0x80" : "=a"(a) : "0"(num), "b"((int)p1), "c"((int)p2)); \ - return a; \ - } - -#define DEFN_SYSCALL3(fn, num, P1, P2, P3) \ - int syscall_##fn(P1 p1, P2 p2, P3 p3) \ - { \ - int a; \ - asm volatile("int $0x80" \ - : "=a"(a) \ - : "0"(num), "b"((int)p1), "c"((int)p2), "d"((int)p3)); \ - return a; \ - } - -#define DEFN_SYSCALL4(fn, num, P1, P2, P3, P4) \ - int syscall_##fn(P1 p1, P2 p2, P3 p3, P4 p4) \ - { \ - int a; \ - asm volatile("int $0x80" \ - : "=a"(a) \ - : "0"(num), "b"((int)p1), "c"((int)p2), "d"((int)p3), "S"((int)p4)); \ - return a; \ - } - -#define DEFN_SYSCALL5(fn, num) \ - int syscall_##fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \ - { \ - int a; \ - asm volatile("int $0x80" \ - : "=a"(a) \ - : "0"(num), "b"((int)p1), "c"((int)p2), "d"((int)p3), "S"((int)p4), \ - "D"((int)p5)); \ - return a; \ - } - -/** - * DECLARATIONS - */ -DECL_SYSCALL0(halt); - -DECL_SYSCALL1(exit, u32); - -DECL_SYSCALL0(fork); - -DECL_SYSCALL4(read, char *, u32, u32, u8 *); - -DECL_SYSCALL4(write, char *, u32, u32, u8 *); - -DECL_SYSCALL1(exec, char *); - -DECL_SYSCALL1(spawn, char *); - -DECL_SYSCALL3(wait, u32, u32 *, u32); - -DECL_SYSCALL0(get_pid); - -DECL_SYSCALL1(malloc, u32); - -DECL_SYSCALL1(free, u32); - -DECL_SYSCALL1(get, u32); - -DECL_SYSCALL2(map, u32, u8 *); - -#endif
\ No newline at end of file diff --git a/src/userspace/libc/unistd.h b/src/userspace/libc/unistd.h deleted file mode 100644 index efe25c7..0000000 --- a/src/userspace/libc/unistd.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MELVIX_UNISTD_H -#define MELVIX_UNISTD_H - -#include <stdint.h> - -u32 exec(char *path); - -u32 spawn(char *path); - -u32 get_pid(); - -u32 read(char *path, u32 offset, u32 count, u8 *buf); - -u32 write(char *path, u32 offset, u32 count, u8 *buf); - -// These should be somewhere else ig -u32 wait(u32 *status); -u32 wait_pid(u32 pid, u32 *status, u32 options); - -#endif
\ No newline at end of file diff --git a/src/userspace/libc/unistd/exec.c b/src/userspace/libc/unistd/exec.c deleted file mode 100644 index fd08d57..0000000 --- a/src/userspace/libc/unistd/exec.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -u32 exec(char *path) -{ - return syscall_exec(path); -}
\ No newline at end of file diff --git a/src/userspace/libc/unistd/get_pid.c b/src/userspace/libc/unistd/get_pid.c deleted file mode 100644 index c42f460..0000000 --- a/src/userspace/libc/unistd/get_pid.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -u32 get_pid() -{ - return syscall_get_pid(); -}
\ No newline at end of file diff --git a/src/userspace/libc/unistd/read.c b/src/userspace/libc/unistd/read.c deleted file mode 100644 index 7ae2626..0000000 --- a/src/userspace/libc/unistd/read.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -u32 read(char *path, u32 offset, u32 count, u8 *buf) -{ - return syscall_read(path, offset, count, buf); -}
\ No newline at end of file diff --git a/src/userspace/libc/unistd/spawn.c b/src/userspace/libc/unistd/spawn.c deleted file mode 100644 index 91ed340..0000000 --- a/src/userspace/libc/unistd/spawn.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -u32 spawn(char *path) -{ - return syscall_spawn(path); -}
\ No newline at end of file diff --git a/src/userspace/libc/unistd/wait.c b/src/userspace/libc/unistd/wait.c deleted file mode 100644 index 7c0a6fb..0000000 --- a/src/userspace/libc/unistd/wait.c +++ /dev/null @@ -1,12 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -u32 wait_pid(u32 pid, u32 *status, u32 options) -{ - return syscall_wait(pid, status, options); -} - -u32 wait(u32 *status) -{ - return wait_pid(-1, status, 0); -}
\ No newline at end of file diff --git a/src/userspace/libc/unistd/write.c b/src/userspace/libc/unistd/write.c deleted file mode 100644 index cd1a0f6..0000000 --- a/src/userspace/libc/unistd/write.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <stdint.h> -#include <syscall.h> - -u32 write(char *path, u32 offset, u32 count, u8 *buf) -{ - return syscall_write(path, offset, count, buf); -}
\ No newline at end of file |