summaryrefslogtreecommitdiff
path: root/src/kernel/mem.c
diff options
context:
space:
mode:
authorBenji Dial <Benji3.141@gmail.com>2019-12-25 11:49:06 -0500
committerBenji Dial <Benji3.141@gmail.com>2019-12-25 11:49:06 -0500
commit2b7b69e1ffd00aefa60d73a5af3bacc1c803a930 (patch)
tree3773bc2c0dddf2e559a5008409e0ea87c3a7ca98 /src/kernel/mem.c
parent75207f727582b8c2350f0e9cd539e119586fe19a (diff)
downloadportland-os-2b7b69e1ffd00aefa60d73a5af3bacc1c803a930.tar.gz
more progress
Diffstat (limited to 'src/kernel/mem.c')
-rw-r--r--src/kernel/mem.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/kernel/mem.c b/src/kernel/mem.c
index 6544108..636c23e 100644
--- a/src/kernel/mem.c
+++ b/src/kernel/mem.c
@@ -20,9 +20,53 @@ OF THIS SOFTWARE.
#include "mem.h"
void *allocate_block(uint32_t size, uint16_t proc_n) {
- //TODO
+ struct mmap_entry *i = mmap_start;
+ while (i->whose || (i->length < size))
+ if (i->next)
+ i = i->next;
+ else
+ return (void *)0;
+ if (i->length == size) {
+ i->whose = proc_n;
+ return (void *)i->base;
+ }
+ uint32_t remaining = i->length - size;
+ i->whose = proc_n;
+ i->length = size;
+ struct mmap_entry *new;
+ //TODO: ALLOCATE NEW
+ new->base = i->base + size;
+ new->length = remaining;
+ new->whose = FREE;
+ new->next = i->next;
+ i->next = new;
+ return (void *)i->base;
}
void deallocate_block(void *start) {
- //TODO
+ struct mmap_entry *find = mmap_start;
+ while (find->base != (uint32_t)start)
+ if (find->next)
+ find = find->next;
+ else
+ return;
+ find->whose = FREE;
+
+ for (struct mmap_entry *find_after = mmap_start; find_after; find_after = find_after->next)
+ if (find_after->base == find->base + find->length) {
+ if (!find_after->whose) {
+ find->length += find_after->length;
+ find->next = find_after->next;
+ }
+ break;
+ }
+
+ for (struct mmap_entry *find_before = mmap_start; find_before; find_before = find_before->next)
+ if (find->base == find_before->base + find_before->length) {
+ if (!find_before->whose) {
+ find_before->length += find->length;
+ find_before->next = find->next;
+ }
+ break;
+ }
} \ No newline at end of file