getting page help

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
GLneo

getting page help

Post 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 ;)
Post Reply