Page 1 of 1

getting page help

Posted: Tue Mar 07, 2006 6:56 pm
by GLneo
hi all, ok, i am working on a way to get a table entery for pages, the entire code:

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);
}    
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 ;)