summaryrefslogtreecommitdiff
path: root/kernel/lib/list.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-02-21 20:06:35 +0100
committerAnton Kling <anton@kling.gg>2024-02-21 20:06:35 +0100
commit9b475d3db3275d4c34f02161ae70ced5595a0fdb (patch)
tree0c50e4af3ce52017f295c44f6f4319e4a43de085 /kernel/lib/list.c
parent6c9cb0bd8ceb039ce387c850e25adc6f99cfcd6f (diff)
Kernel: Remove all inline assembly.
Now the kernel does not rely upon inline assembly which is often very error prone. This also means that the kernel could probably be compiled with any c99 compiler which would help future bootstrapping.
Diffstat (limited to 'kernel/lib/list.c')
-rw-r--r--kernel/lib/list.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/kernel/lib/list.c b/kernel/lib/list.c
new file mode 100644
index 0000000..12104d8
--- /dev/null
+++ b/kernel/lib/list.c
@@ -0,0 +1,39 @@
+#include <assert.h>
+#include <kmalloc.h>
+#include <lib/list.h>
+
+int list_init(struct list *list) {
+ // TODO: Make it dynamic
+ list->entries = kmalloc(sizeof(void *) * 100);
+ if (!list->entries) {
+ return 0;
+ }
+ list->tail_index = -1;
+ return 1;
+}
+
+void list_reset(struct list *list) {
+ list->tail_index = -1;
+}
+
+int list_add(struct list *list, void *entry) {
+ if (list->tail_index > 100 - 1) {
+ kprintf("Error: list has run out of space\n");
+ assert(0);
+ }
+ list->tail_index++;
+ list->entries[list->tail_index] = entry;
+ return 1;
+}
+
+int list_get(const struct list *list, int index, void **out) {
+ if (index > list->tail_index) {
+ return 0;
+ }
+ *out = list->entries[index];
+ return 1;
+}
+
+void list_free(struct list *list) {
+ kfree(list->entries);
+}