aboutsummaryrefslogtreecommitdiff
path: root/kernel/string.S
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-20 11:43:08 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-20 11:43:08 +0100
commitfb9627cc985912a57de8b4bedc98991e290e4075 (patch)
treeb7f0f72df6c6feb6beb672523afde5f793c87755 /kernel/string.S
parentd3afdd9284f7e9838fbde4c941193ec2032d6a26 (diff)
downloadfbos-fb9627cc985912a57de8b4bedc98991e290e4075.tar.gz
fbos-fb9627cc985912a57de8b4bedc98991e290e4075.zip
Fetch the initrd address from the DTB blob
The kernel entry has a pointer to the DTB blob as a parameter. From this pointer we can parse the the DTB blob to find the properties "chosen->linux,initrd-start" and "chosen->linux,initrd-start". These properties are guaranteed to have 64-bit addresses which point where the initrd is in memory, which we need to fetch the binaries to be loaded. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'kernel/string.S')
-rw-r--r--kernel/string.S46
1 files changed, 46 insertions, 0 deletions
diff --git a/kernel/string.S b/kernel/string.S
new file mode 100644
index 0000000..d09bbac
--- /dev/null
+++ b/kernel/string.S
@@ -0,0 +1,46 @@
+/*
+ * Defined in include/fbos/string.h
+ *
+ * size_t strlen(const char *str)
+ *
+ * Returns (a0): string length.
+ * Parameter (a0): string to measure.
+ * Clobbers: t0, t1.
+ */
+.globl strlen
+.type strlen, @function
+strlen:
+ mv t1, a0
+1:
+ lbu t0, 0(t1)
+ beqz t0, 2f
+ addi t1, t1, 1
+ j 1b
+2:
+ sub a0, t1, a0
+ ret
+
+/*
+ * Defined in include/fbos/string.h
+ *
+ * int strcmp(const char *s1, const char *s2)
+ *
+ * Returns (a0): comparison result as in stdlib.
+ * Parameter (a0, a1): strings to compare.
+ * Clobbers: t0, t1.
+ */
+.globl strcmp
+.type strcmp, @function
+strcmp:
+1:
+ lbu t0, 0(a0)
+ lbu t1, 0(a1)
+ bne t0, t1, 2f
+ addi a0, a0, 1
+ addi a1, a1, 1
+ bnez t0, 1b
+ li a0, 0
+ ret
+2:
+ sub a0, t0, t1
+ ret