Saving Kernel allocated page in linked list ?
Posted: Fri Feb 07, 2003 1:30 pm
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?
/* 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?