From 5481848e27fdd4fc859def9841a0283665531a46 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 13 Sep 2020 17:12:29 -0400 Subject: fixed some paging bugs, added fault handlers and new programs --- src/kernel/pmap.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/kernel/pmap.c') diff --git a/src/kernel/pmap.c b/src/kernel/pmap.c index 8634303..37c7261 100644 --- a/src/kernel/pmap.c +++ b/src/kernel/pmap.c @@ -77,8 +77,14 @@ void init_pagemap() { //a smarter algorithm might pick the smallest one available, //and go by bytes (or dwords) instead of bits where possible. void *allocate_kernel_pages(uint32_t n) { +//logsz("trace: allocate_kernel_pages("); +//char nbuf[11]; +//u32_dec(n, nbuf); +//logsz(nbuf); +//logsz(") = 0x"); + uint32_t run = 0; - + for (uint32_t page = KBSS_START >> 12; page < USER_START >> 12; ++page) { if (PAGE_USED(page)) run = 0; @@ -87,6 +93,9 @@ void *allocate_kernel_pages(uint32_t n) { for (uint32_t i = start; i <= page; ++i) SET_PAGE(i); kernel_pages_left -= n; + //u32_hex(start << 12, nbuf); + //logsz(nbuf); + //logch('\n'); return (void *)(start << 12); } } @@ -98,8 +107,14 @@ void *allocate_kernel_pages(uint32_t n) { //a smarter algorithm might pick the smallest one available, //and go by bytes (or dwords) instead of bits where possible. void *allocate_user_pages(uint32_t n) { +//logsz("trace: allocate_user_pages("); +//char nbuf[11]; +//u32_dec(n, nbuf); +//logsz(nbuf); +//logsz(") = 0x"); + uint32_t run = 0; - + for (uint32_t page = USER_START >> 12; page < 1048576; ++page) { if (PAGE_USED(page)) run = 0; @@ -108,6 +123,9 @@ void *allocate_user_pages(uint32_t n) { for (uint32_t i = start; i <= page; ++i) SET_PAGE(i); user_pages_left -= n; + //u32_hex(start << 12, nbuf); + //logsz(nbuf); + //logch('\n'); return (void *)(start << 12); } } @@ -117,6 +135,15 @@ void *allocate_user_pages(uint32_t n) { //in the future, change this to go by bytes or dwords instead of bits. void free_pages(const void *ptr, uint32_t n) { +//logsz("trace: free_pages(0x"); +//char nbuf[11]; +//u32_hex(ptr, nbuf); +//logsz(nbuf); +//logsz(", "); +//u32_dec(n, nbuf); +//logsz(nbuf); +//logsz(")\n"); + uint32_t page = (uint32_t)ptr >> 12; for (uint32_t i = page; i < page + n; ++i) CLEAR_PAGE(i); -- cgit v1.2.3