summaryrefslogtreecommitdiff
path: root/src/kernel/mem.c
diff options
context:
space:
mode:
authorBenji Dial <benji3.141@gmail.com>2020-05-16 09:53:58 -0400
committerBenji Dial <benji3.141@gmail.com>2020-05-16 09:53:58 -0400
commitc0daede46df4f546639bd2d3e11dcf064d554966 (patch)
tree2042d915325dc66baf063238b8a3c685bb91d17b /src/kernel/mem.c
parentf7820301d583ae190b683bdd1371ee6f7a35ac16 (diff)
downloadportland-os-c0daede46df4f546639bd2d3e11dcf064d554966.tar.gz
starting over
Diffstat (limited to 'src/kernel/mem.c')
-rw-r--r--src/kernel/mem.c88
1 files changed, 0 insertions, 88 deletions
diff --git a/src/kernel/mem.c b/src/kernel/mem.c
deleted file mode 100644
index d9322a9..0000000
--- a/src/kernel/mem.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
-Copyright 2019 Benji Dial
-
-Permission to use, copy, modify, and/or distribute this
-software for any purpose with or without fee is hereby
-granted, provided that the above copyright notice and this
-permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS
-ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
-EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
-RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
-OF THIS SOFTWARE.
-*/
-
-#include "mem.h"
-
-uint32_t last_byte = 0;
-uint32_t last_mask = 0x00000001;
-
-void *allocate_block(uint32_t size, uint16_t proc_n) {
- for (struct mmap_entry *find = mmap_start; find; find = find->after)
- if (!find->whose) {
- if (find->length == size) {
- find->whose = proc_n;
- return (void *)find->base;
- }
- else if (find->length > size) {
- uint32_t byte = last_byte;
- uint32_t mask = last_mask;
- while (mmap_bitmap[byte] & mask) {
- if ((byte == last_byte) && (mask == last_mask)) {
- while (find = find->after)
- if (find->length == size) {
- find->whose = proc_n;
- return (void *)find->base;
- }
- return (void *)0;
- }
- if (!(mask <<= 1)) {
- mask = 0x00000001;
- if (++byte == MMAP_SIZE)
- byte = 0;
- }
- }
- mmap_bitmap[last_byte = byte] |= last_mask = mask;
- struct mmap_entry *new = mmap_bss + (byte << 5);
- while (mask >>= 1)
- ++new;
- ((((new->after = find->after)->before = new)->before = find)->after = new)->base = find->base + size;
- new->length = find->length - size;
- find->length = size;
- find->whose = proc_n;
- new->whose = FREE;
- return (void *)find->base;
- }
- }
- return (void *)0;
-}
-
-void deallocate_block(void *start) {
- struct mmap_entry *find = mmap_start;
- while (find->base != (uint32_t)start)
- if (find->after)
- find = find->after;
- else
- return;
- find->whose = FREE;
- while (find->before && !find->before->whose) {
- find->before->length += find->length;
- if (find->before->after = find->after)
- find->after->before = find->before;
- unmark_entry(find);
- find = find->before;
- }
- if (!find->before)
- mmap_start = find;
- while (find->after && !find->after->whose) {
- find->length += find->after->length;
- unmark_entry(find->after);
- if (find->after = find->after->after)
- find->after->before = find;
- }
-} \ No newline at end of file