Yes, i understand what you mean.
The "idea" that i had, was not to store the physical starting adresses of free pages, but their "numbers", ie starting_adress/4096, hoping to need a smaller integer-type and safe space that way.
But when i calculated how many bit those numbers would need, i found out that i would still have to use unsigned long - integers for the stack.
I changed the free and alloc funtions now to use (or free) new physical pages for the stack, when needed.
I think logically my code is right, but i am not quite sure, if my pointer arithmetic is right:
Since the stack consists of dwords and a dword = 4 bytes, the stack needs a new page, when page_sp has reached a multiple of 4096/4=1024. Similiar calculations are in the alloc and free functions to calculate virtual adresses for the new/deleted page.
I also wonder if there is a better solution than using the boolean variables f and a, as in the code below.
These are the new alloc and free functions:
unsigned long alloc_pageframe()
static bool f;
unsigned long adress;
//not even the space of the table left - out of memory
//0 is used as retvalue, as everybody knows that 0x00000 is reserved
//give away space from the stack, if a stackpage becomes available now
else if((page_sp+1)%1024==0 && f==false)
//next call, page_sp will not have changed, still we do
//not want to re-allocate the stackpage, but act as in "else"-case
return physical((unsigned long)page_stack + ((page_sp+1)*4));
//else pop some adress
//do the pop and return the adress
void free_pageframe(unsigned long adress)
static bool a;
//If we need more space for the stack, get another pageframe for it
if((page_sp+2)%1024==0 && a==false)
//next call, page_sp will be unchanged, yet we do not
//want to map another pageframe, but act as in "else"-case
//use the given adress for the new stackpage. Do not free it.
set_pagetableentry(page_sp+2)/1024, adress, stack_table, 3);
//Else just push the freed adress to the stack
//do the push
My post might be a bit unorganized and weird.
If the code fails to explain the parts my language missed as well, just complain