bank8k: Redefine page map table to not include LOBANK
authorTormod Volden <debian.tormod@gmail.com>
Mon, 7 Jan 2019 21:28:53 +0000 (22:28 +0100)
committerAlan Cox <alan@linux.intel.com>
Tue, 8 Jan 2019 16:59:45 +0000 (16:59 +0000)
The first element corresponds to the first page slot to be mapped.

If LOBANK is not zero, we will have fewer page slots to go through.

Use moving ptr instead of indexing it, to keep all compilers from
messing up.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Kernel/bank8k.c

index b8791df..de56b73 100644 (file)
@@ -113,8 +113,8 @@ void pagemap_add(uint8_t page)
  */
 void pagemap_free(ptptr p)
 {
-       uint8_t *pt = (uint8_t *)p->p_page + LOBANK;
-       uint8_t *e = (uint8_t *)p->p_page + PTNUM;
+       uint8_t *pt = (uint8_t *)p->p_page;
+       uint8_t *e = (uint8_t *)p->p_page + PTNUM - LOBANK;
        uint8_t last = PAGE_INVALID;
 
        while(pt < e) {
@@ -177,7 +177,7 @@ int pagemap_alloc(ptptr p)
 #endif
 
        /* Allocate the pages upwards */
-       for (i = LOBANK; i < needed; i++)
+       for (i = 0; i < needed; i++)
                *ptr++ = pfree[--pfptr];
        /*
         *      A machine with a separate supervisor space should write
@@ -186,15 +186,16 @@ int pagemap_alloc(ptptr p)
         *      common space is right if it is high.
         */
 #ifdef CONFIG_SUPERVISOR_SPACE
-       while (i++ < PTNUM)
+       while (i++ < PTNUM - LOBANK)
                *ptr++ = PAGE_INVALID;
 #else
-       while (i++ < 8) {
+       while (i++ < 8 - LOBANK) {
                *ptr = ptr[-1];
                ptr++;
        }
 #ifdef CONFIG_VIDMAP8
-       ptr[8] = PAGE_INVALID;
+       ptr += LOBANK;
+       *ptr = PAGE_INVALID;
 #endif 
 #endif
        return 0;
@@ -231,11 +232,13 @@ int pagemap_realloc(usize_t code, usize_t size, usize_t stack)
        /* If we are shrinking then free pages and propogate the
           common page or invalid into the freed spaces */
        if (want < have) {
+               uint8_t last = ptr[7 - LOBANK];
+               ptr += want - 1;
                for (i = want; i < have; i++) {
-                       pfree[pfptr++] = ptr[i - 1];
+                       pfree[pfptr++] = *ptr;
                        /* We might replicate the top page or we might
                           replicate the invalid - both work */
-                       ptr[i - 1] = ptr[7];
+                       *ptr++ = last;
                }
                return 0;
        }
@@ -248,8 +251,9 @@ int pagemap_realloc(usize_t code, usize_t size, usize_t stack)
        if (want - have > pfptr)        /* We have no swap so poof... */
                return ENOMEM;
 #endif
+       ptr += have - 1;
        for (i = have; i < want; i++)
-               ptr[i - 1] = pfree[--pfptr];
+               *ptr++ = pfree[--pfptr];
        return 0;
 }