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?
Saving Kernel allocated page in linked list ?
-
amirsadig
Re:Saving Kernel allocated page in linked list ?
forgot something
the first function will be called before enabling paging.
the first function will be called before enabling paging.
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Saving Kernel allocated page in linked list ?
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 ...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;
}
finally, what does that last command do ? if you had P as the k_pgptr, you now haveelse
{
pg_ptr->next = _kpg_ptr->next;
_kpg_ptr->next = pg_ptr;
}
_kpg_ptr = pg_ptr;
}
}
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 ...
-
amirsadig
Re:Saving Kernel allocated page in linked list ?
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.