Page 1 of 1

Saving Kernel allocated page in linked list ?

Posted: Fri Feb 07, 2003 1:30 pm
by amirsadig
when a page is is allocated for kernel, ut will be saved in (_kpg_ptr) with this function :
/* insert allocated page in kernel page list */
void insert_kernel_page (k_page_list *pg_ptr)
{
if( pg_ptr != NULL)
{
if (_kpg_ptr == NULL){
   pg_ptr->next = pg_ptr;
}
else
   {
    pg_ptr->next = _kpg_ptr->next;
    _kpg_ptr->next = pg_ptr;
   }

_kpg_ptr = pg_ptr;
}
}
you see this is a normal linked list.

when I add page to kernel :

// map the next 1 MB for the kernel
   for(i=256; i<512; i++)
    {
    k_page_list *pg_ptr;
    page_table = address ;
    pg_ptr->linearaddress = i << 12;
    insert_kernel_page(pg_ptr);
    phy_address = next_phy_address_av;
    address = address + 4096; // 4096 = 4kb
    next_phy_address_av = next_phy_address_av + 4096;
    }
note that:here is page dir = 0;

when I tried to print ( with test fuction) all linear address saved used by kernel it give me only the last one:

void print_krnl_addresses()
{
k_page_list *pg_ptr;
int i;
unsigned long first_addr = _kpg_ptr->linearaddress;
pg_ptr = _kpg_ptr;
kprintf(" first Linear Address : %X \n",_kpg_ptr->linearaddress);
for(i = 0; i < 15; i++){
kprintf(" Linear Address : %X \n",pg_ptr->linearaddress);
pg_ptr = _kpg_ptr->next;
kprintf(" Linear Address : %X \n",pg_ptr->next->linearaddress);
}
}

Is there something wrong here in my code?

Re:Saving Kernel allocated page in linked list ?

Posted: Fri Feb 07, 2003 1:32 pm
by amirsadig
forgot something :D

the first function will be called before enabling paging.

Re:Saving Kernel allocated page in linked list ?

Posted: Sat Feb 08, 2003 6:52 am
by Pype.Clicker
amirsadig wrote: when a page is is allocated for kernel, ut will be saved in (_kpg_ptr) with this function :
/* insert allocated page in kernel page list */
void insert_kernel_page (k_page_list *pg_ptr)
{
if( pg_ptr != NULL)
{
if (_kpg_ptr == NULL){
pg_ptr->next = pg_ptr;
}
what are you trying to do here ? initializing the list ? it appears that you link your new page to itself and leave the list unmodified ...
else
{
pg_ptr->next = _kpg_ptr->next;
_kpg_ptr->next = pg_ptr;
}

_kpg_ptr = pg_ptr;
}
}
finally, what does that last command do ? if you had P as the k_pgptr, you now have
P --> new --> P.next --> ...
and kpg_ptr refers to new (where is P disappeared ?)

I suggest you draw a sketch of what you plan to do because it seems obscure to me and does not look like a simple linked list at all ...

Re:Saving Kernel allocated page in linked list ?

Posted: Sat Feb 08, 2003 6:59 am
by amirsadig
you are right my idea was wrong. I can not use linked list befor I allocate a memory for the pointer. so that in my code it point allways to it self.