getting page help
Posted: Tue Mar 07, 2006 6:56 pm
hi all, ok, i am working on a way to get a table entery for pages, the entire code:
the void *get_page() is the code i'm working on, but i think there is bugs in other code in this file. When i test the function i get this: attachment
thx
Code: Select all
/*
* los/drivers/pport/pport.c
*
* Copyleft (C) 2005 Andrew Davis
*/
#include <los/memory.h>
typedef struct
{
unsigned char byte[4096];
}__attribute__ ((packed)) BITMAP;
unsigned int page_count;
static BITMAP *bitmap = (BITMAP *)0x200;
unsigned int get_page_state(unsigned int page)
{
return (bitmap + ((page / (4096 * 8))*4096))->byte[(page % (4096 * 8)) / 8] & (1 << ((page % (4096 * 8)) % 8));
}
unsigned int flip_page(unsigned int page)
{
if (page > page_count || page < 0) return 1;
(bitmap + (page / (4096 * 8)) * 4096)->byte[(page % (4096 * 8)) / 8] ^= 1 << ((page%(4096*8))%8);
return 0;
}
void *get_page()
{
unsigned int page = 0;
while(get_page_state(page))page++; // move to free page
if(flip_page(page))return (void *)-1;
return (void *)(page * 4096);
}
thx