diff options
Diffstat (limited to 'src/kernel/mem.c')
-rw-r--r-- | src/kernel/mem.c | 88 |
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 |