aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/kernel/syscall/syscall.c3
-rw-r--r--src/userspace/main.c16
-rw-r--r--src/userspace/mlibc/stdio/readline.c15
-rw-r--r--src/userspace/mlibc/string.h6
-rw-r--r--src/userspace/mlibc/string/memcmp.c14
-rw-r--r--src/userspace/mlibc/string/memcpy.c9
-rw-r--r--src/userspace/mlibc/string/memset.c8
7 files changed, 63 insertions, 8 deletions
diff --git a/src/kernel/syscall/syscall.c b/src/kernel/syscall/syscall.c
index 16d1ce4..7d5420d 100644
--- a/src/kernel/syscall/syscall.c
+++ b/src/kernel/syscall/syscall.c
@@ -29,8 +29,7 @@ void syscall_handler(struct regs *r)
if (!location)
return;
- uint32_t ret = location(r->ebx, r->ecx, r->edx, r->esi, r->edi);
- r->eax = ret;
+ r->eax = location(r->ebx, r->ecx, r->edx, r->esi, r->edi);
}
void syscalls_install()
diff --git a/src/userspace/main.c b/src/userspace/main.c
index 0bea7fa..63ce8f4 100644
--- a/src/userspace/main.c
+++ b/src/userspace/main.c
@@ -1,6 +1,13 @@
#include <syscall.h>
-#include <graphics/graphics.h>
#include <mlibc/stdio.h>
+#include <mlibc/string.h>
+
+int32_t starts_with(const char *a, const char *b)
+{
+ size_t length_pre = strlen(b);
+ size_t length_main = strlen(a);
+ return length_main < length_pre ? 0 : memcmp(b, a, length_pre) == 0;
+}
void user_main()
{
@@ -10,7 +17,10 @@ void user_main()
// init_framebuffer();
while (1) {
- char key = getch();
- writec(key);
+ char *input = readline();
+ if (starts_with(input, "ls")) {
+ char test[] = "WOOOHOOO\n";
+ syscall_write(test);
+ }
};
} \ No newline at end of file
diff --git a/src/userspace/mlibc/stdio/readline.c b/src/userspace/mlibc/stdio/readline.c
index a7082e6..b948884 100644
--- a/src/userspace/mlibc/stdio/readline.c
+++ b/src/userspace/mlibc/stdio/readline.c
@@ -1,7 +1,16 @@
-// #include <syscall.h>
+#include <syscall.h>
+#include <mlibc/string.h>
+#include <mlibc/stdio.h>
char *readline()
{
- // return (char *) syscall_read();
- return "0";
+ char *ret = "";
+ char buf = 0;
+ while (buf != '\n') {
+ buf = getch();
+ writec(buf);
+ strcpy(ret, buf);
+ }
+ strcpy(ret, buf);
+ return ret;
} \ No newline at end of file
diff --git a/src/userspace/mlibc/string.h b/src/userspace/mlibc/string.h
index fe925cb..153b7cb 100644
--- a/src/userspace/mlibc/string.h
+++ b/src/userspace/mlibc/string.h
@@ -19,4 +19,10 @@ char *strdup(const char *orig);
void strinv(char *str);
+void *memcpy(void *dest, const void *src, size_t count);
+
+void *memset(void *dest, char val, size_t count);
+
+int memcmp(const void *a_ptr, const void *b_ptr, size_t size);
+
#endif
diff --git a/src/userspace/mlibc/string/memcmp.c b/src/userspace/mlibc/string/memcmp.c
new file mode 100644
index 0000000..af2125c
--- /dev/null
+++ b/src/userspace/mlibc/string/memcmp.c
@@ -0,0 +1,14 @@
+#include <stddef.h>
+
+int memcmp(const void *a_ptr, const void *b_ptr, size_t size)
+{
+ const unsigned char *a = (const unsigned char *) a_ptr;
+ const unsigned char *b = (const unsigned char *) b_ptr;
+ for (size_t i = 0; i < size; i++) {
+ if (a[i] < b[i])
+ return -1;
+ else if (b[i] < a[i])
+ return 1;
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/memcpy.c b/src/userspace/mlibc/string/memcpy.c
new file mode 100644
index 0000000..e4e9c76
--- /dev/null
+++ b/src/userspace/mlibc/string/memcpy.c
@@ -0,0 +1,9 @@
+#include <stddef.h>
+
+void *memcpy(void *dest, const void *src, size_t count)
+{
+ const char *sp = (const char *) src;
+ char *dp = (char *) dest;
+ for (; count != 0; count--) *dp++ = *sp++;
+ return dest;
+} \ No newline at end of file
diff --git a/src/userspace/mlibc/string/memset.c b/src/userspace/mlibc/string/memset.c
new file mode 100644
index 0000000..fb5ab80
--- /dev/null
+++ b/src/userspace/mlibc/string/memset.c
@@ -0,0 +1,8 @@
+#include <stddef.h>
+
+void *memset(void *dest, char val, size_t count)
+{
+ char *temp = (char *) dest;
+ for (; count != 0; count--) *temp++ = val;
+ return dest;
+} \ No newline at end of file