From 5e20311dd2b87c7da26152e5c0f8ec723fc7b029 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 31 May 2015 18:29:51 +0100 Subject: [PATCH] kernel: add p_top so we can do swap in banking modes not just fixed bank --- Kernel/bank16k.c | 9 ++++++--- Kernel/bank16k_low.c | 2 +- Kernel/bank32k.c | 2 +- Kernel/bankfixed.c | 3 +++ Kernel/include/kernel.h | 1 + Kernel/start.c | 1 + Kernel/syscall_exec16.c | 1 + Library/include/proc.h | 1 + 8 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Kernel/bank16k.c b/Kernel/bank16k.c index 6d780240..c7f7e311 100644 --- a/Kernel/bank16k.c +++ b/Kernel/bank16k.c @@ -75,13 +75,12 @@ static int maps_needed(uint16_t top) * We have a hackish fix for init that would be nice * resolve. * - * FIXME: we need to move udata.u_top into p-> in order to - * support banked swapping. + * Use p-> not udata. The udata is not yet swapped in! */ int pagemap_alloc(ptptr p) { uint8_t *ptr = (uint8_t *) & p->p_page; - int needed = maps_needed(udata.u_top); + int needed = maps_needed(p->p_top); int i; #ifdef SWAPDEV @@ -164,6 +163,8 @@ uint16_t pagemap_mem_used(void) * Swap out the memory of a process to make room * for something else. For bank16k do this as four operations * ready for when we pass page values not processes to the drivers + * + * FIXME: bank16k should only read/write out the banks that are in use */ int swapout(ptptr p) @@ -210,6 +211,8 @@ int swapout(ptptr p) /* * Swap ourself in: must be on the swap stack when we do this + * + * FIXME: bank16k should only read/write out the banks that are in use */ void swapin(ptptr p, uint16_t map) { diff --git a/Kernel/bank16k_low.c b/Kernel/bank16k_low.c index 57255bad..0798f889 100644 --- a/Kernel/bank16k_low.c +++ b/Kernel/bank16k_low.c @@ -81,7 +81,7 @@ static int maps_needed(uint16_t top) int pagemap_alloc(ptptr p) { uint8_t *ptr = (uint8_t *) & p->p_page; - int needed = maps_needed(udata.u_top); + int needed = maps_needed(p->p_top); int i; #ifdef SWAPDEV diff --git a/Kernel/bank32k.c b/Kernel/bank32k.c index 34d70723..086c3428 100644 --- a/Kernel/bank32k.c +++ b/Kernel/bank32k.c @@ -87,7 +87,7 @@ static int maps_needed(uint16_t top) int pagemap_alloc(ptptr p) { uint8_t *ptr = (uint8_t *) & p->p_page; - int needed = maps_needed(udata.u_top); + int needed = maps_needed(p->p_top); #ifdef SWAPDEV /* Throw our toys out of our pram until we have enough room */ diff --git a/Kernel/bankfixed.c b/Kernel/bankfixed.c index a0fa6f11..5552afe1 100644 --- a/Kernel/bankfixed.c +++ b/Kernel/bankfixed.c @@ -85,6 +85,9 @@ uint16_t pagemap_mem_used(void) /* * Swap out the memory of a process to make room * for something else + * + * FIXME: we can write out base - p_top, then the udata providing + * we also modify our read logic here as well */ int swapout(ptptr p) { diff --git a/Kernel/include/kernel.h b/Kernel/include/kernel.h index 7aa66114..22c2488f 100644 --- a/Kernel/include/kernel.h +++ b/Kernel/include/kernel.h @@ -353,6 +353,7 @@ typedef struct p_tab { /**HP**/ uint16_t p_pgrp; /* Process group */ uint8_t p_nice; + usize_t p_top; /* Copy of u_top */ #ifdef CONFIG_PROFIL uint8_t p_profscale; void * p_profbuf; diff --git a/Kernel/start.c b/Kernel/start.c index b49043ed..d80f484f 100644 --- a/Kernel/start.c +++ b/Kernel/start.c @@ -67,6 +67,7 @@ void create_init(void) init_process = ptab_alloc(); udata.u_ptab = init_process; udata.u_top = PROGLOAD + 4096; /* Plenty for the boot */ + init_process->p_top = udata.u_top; map_init(); newproc(init_process); diff --git a/Kernel/syscall_exec16.c b/Kernel/syscall_exec16.c index 603c634f..a1d42ad0 100644 --- a/Kernel/syscall_exec16.c +++ b/Kernel/syscall_exec16.c @@ -154,6 +154,7 @@ arg_t _execve(void) /* From this point on we are commmited to the exec() completing */ udata.u_top = top; + udata.u_ptab->p_top = top; /* setuid, setgid if executable requires it */ if (ino->c_node.i_mode & SET_UID) diff --git a/Library/include/proc.h b/Library/include/proc.h index 7bc36d30..9b8408b4 100644 --- a/Library/include/proc.h +++ b/Library/include/proc.h @@ -47,6 +47,7 @@ typedef struct p_tab { /**HP**/ uint16_t p_pgrp; /* Process group */ uint8_t p_nice; + uint16_t p_top; /* Copy of u_top : FIXME: usize_t */ #ifdef CONFIG_PROFIL uint8_t p_profscale; void * p_profbuf; -- 2.34.1