aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/paging/ordered_array.c
diff options
context:
space:
mode:
authorMarvin Borner2019-10-12 23:28:01 +0200
committerMarvin Borner2019-10-12 23:31:27 +0200
commit876df2125f4f24803d5471894e5308e7425ebfd2 (patch)
treea91b066e93c6694c41384ae8f2e296167715768c /src/kernel/paging/ordered_array.c
parentb2f80382659e739d5e37eefff1ebcdfd023bb9fb (diff)
Paging and heap rewrite
VESA drawing causes a Page fault because it tries to use a pointer to the framebuffer which was created before the paging has been initialized. If the resolution is set after the paging has been initialized the CPU throws a triple fault because the int32 call can not happen with paging turned on. To be fixed soon!
Diffstat (limited to 'src/kernel/paging/ordered_array.c')
-rw-r--r--src/kernel/paging/ordered_array.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/kernel/paging/ordered_array.c b/src/kernel/paging/ordered_array.c
new file mode 100644
index 0000000..563a936
--- /dev/null
+++ b/src/kernel/paging/ordered_array.c
@@ -0,0 +1,66 @@
+#include <stdint.h>
+#include "ordered_array.h"
+#include "kheap.h"
+#include "../lib/lib.h"
+#include "../system.h"
+
+char standard_lessthan_predicate(type_t a, type_t b) {
+ return (a < b) ? 1 : 0;
+}
+
+ordered_array_t create_ordered_array(uint32_t max_size, lessthan_predicate_t less_than) {
+ ordered_array_t to_ret;
+ to_ret.array = (void *) kmalloc(max_size * sizeof(type_t));
+ memory_set(to_ret.array, 0, max_size * sizeof(type_t));
+ to_ret.size = 0;
+ to_ret.max_size = max_size;
+ to_ret.less_than = less_than;
+ return to_ret;
+}
+
+ordered_array_t place_ordered_array(void *addr, uint32_t max_size, lessthan_predicate_t less_than) {
+ ordered_array_t to_ret;
+ to_ret.array = (type_t *) addr;
+ memory_set(to_ret.array, 0, max_size * sizeof(type_t));
+ to_ret.size = 0;
+ to_ret.max_size = max_size;
+ to_ret.less_than = less_than;
+ return to_ret;
+}
+
+void destroy_ordered_array(ordered_array_t *array) {
+ kfree(array->array);
+}
+
+void insert_ordered_array(type_t item, ordered_array_t *array) {
+ assert(array->less_than);
+ uint32_t iterator = 0;
+ while (iterator < array->size && array->less_than(array->array[iterator], item))
+ iterator++;
+ if (iterator == array->size)
+ array->array[array->size++] = item;
+ else {
+ type_t tmp = array->array[iterator];
+ array->array[iterator] = item;
+ while (iterator < array->size) {
+ iterator++;
+ type_t tmp2 = array->array[iterator];
+ array->array[iterator] = tmp;
+ tmp = tmp2;
+ }
+ array->size++;
+ }
+}
+
+type_t lookup_ordered_array(uint32_t i, ordered_array_t *array) {
+ assert(i < array->size);
+ return array->array[i];
+}
+
+void remove_ordered_array(uint32_t i, ordered_array_t *array) {
+ while (i < array->size) {
+ array->array[i] = array->array[i + 1];
+ i++;
+ }
+ array->size--;
+}