summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2024-02-24 14:47:25 -0600
committerDanny Holman <dholman@gymli.org>2024-02-24 14:55:51 -0600
commit891f1010bbdc1351bda8d2a6139094a14bdfd5e1 (patch)
treef8fcc9a273ca8df783aee243fcb3aa545887633c /kernel
parent2ce0f8af51dae9e7d591ff5fd038f89d6ca9dbbe (diff)
kernel: string: add a strcpy function
Add an implmentation of strcpy. This function is used in several places in the kernel to copy strings between memory addresses. Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/init.c25
-rw-r--r--kernel/string.c8
2 files changed, 29 insertions, 4 deletions
diff --git a/kernel/init.c b/kernel/init.c
index 195ce92..86567a4 100644
--- a/kernel/init.c
+++ b/kernel/init.c
@@ -1,8 +1,25 @@
-#include <kernel/tty.h>
#include <kernel/io.h>
+#include <kernel/mem.h>
+#include <kernel/string.h>
#include <kernel/serial.h>
-void kernel_main(void) {
- tty_init();
- kprintf("Hello world\n");
+void jump_userspace(void);
+
+char rootfs[1024];
+
+int start_init(int argc, char* argv[]) {
+ return 0;
+}
+
+void process_cmd(char *cmdline) {
+ char *token = strtok(cmdline, " ");
+ while (token != NULL) {
+ if (strncmp(token, "root=", 5) == 0)
+ strcpy(rootfs, &token[6]);
+ }
+}
+
+void kernel_main(char *cmdline) {
+ kprintf("Box Kernel version %s\n", VERSION);
+ serial_init();
}
diff --git a/kernel/string.c b/kernel/string.c
index 35dc16e..fa0fd3f 100644
--- a/kernel/string.c
+++ b/kernel/string.c
@@ -31,6 +31,14 @@ void* memcpy(void* __restrict dest, const void* __restrict src, size_t n) {
return dest;
}
+char* strncpy(char* __restrict dest, const char* __restrict src, size_t n) {
+ for (int i = 0; i < n; i++) {
+ if (src[i] == '\0')
+ break;
+ dest[i] = src[i];
+ }
+}
+
char* strcpy(char* __restrict dest, const char* __restrict src) {
if (strlen(src) > strlen(dest))
return NULL;