From 90a1fcf7d46e10e3e163d11785badda0c8f5ba2a Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Thu, 13 Sep 2018 23:13:41 +0200 Subject: [PATCH] bank8k: Fix program size/top confusion Signed-off-by: Tormod Volden --- Kernel/bank8k.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel/bank8k.c b/Kernel/bank8k.c index b88a2fab..bc1d0eea 100644 --- a/Kernel/bank8k.c +++ b/Kernel/bank8k.c @@ -109,11 +109,11 @@ void pagemap_free(ptptr p) } } -static int maps_needed(uint16_t top) +static int maps_needed(uint16_t size) { /* On many platforms if you touch this or PROGTOP you must touch tricks.s */ - uint16_t needed = top + 0xFFFF - PROGTOP; + uint16_t needed = size - 1; /* Usually we have 0x1000 common - 1 for shift and inc */ needed >>= 13; /* in banks */ needed++; /* rounded */ @@ -130,7 +130,7 @@ static int maps_needed(uint16_t top) int pagemap_alloc(ptptr p) { uint8_t *ptr; - int needed = maps_needed(p->p_top); + int needed = maps_needed(p->p_top - MAPBASE); int i; /* Cheapest way to keep it non zero */ @@ -165,7 +165,7 @@ int pagemap_alloc(ptptr p) */ int pagemap_realloc(usize_t code, usize_t size, usize_t stack) { - int8_t have = maps_needed(udata.u_top); + int8_t have = maps_needed(udata.u_top - MAPBASE); int8_t want = maps_needed(size); uint8_t *ptr = (uint8_t *)udata.u_page; -- 2.34.1