From 9b475d3db3275d4c34f02161ae70ced5595a0fdb Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Wed, 21 Feb 2024 20:06:35 +0100 Subject: 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. --- kernel/lib/list.c | 39 +++++++++++++++++++++++++++++++++++++++ kernel/lib/list.h | 13 +++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 kernel/lib/list.c create mode 100644 kernel/lib/list.h (limited to 'kernel/lib') 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 +#include +#include + +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); +} diff --git a/kernel/lib/list.h b/kernel/lib/list.h new file mode 100644 index 0000000..8c3cce4 --- /dev/null +++ b/kernel/lib/list.h @@ -0,0 +1,13 @@ +#ifndef LIST_H +#define LIST_H +struct list { + void **entries; + int tail_index; +}; + +int list_init(struct list *list); +void list_reset(struct list *list); +void list_free(struct list *list); +int list_add(struct list *list, void *entry); +int list_get(const struct list *list, int index, void **out); +#endif -- cgit v1.2.3