but really I'm not really sure on how to test each componet or well do a full test that is
I really don't want to do what I just did again, I only tested the page allocator a little bit and then found a major bug that I basically had to rewrite the whole thing because of it
edit:
or if someone could maybe look at this code and say whats wrong with it
[edited again with the code]
Code: Select all
unsigned int is_free_bits(unsigned int *data,unsigned int start_bit,unsigned int num,unsigned int len){
unsigned int i,j=0,endbit,total,counter; //i bet i could've used less stack but anyway
endbit=num+start_bit; //make it the end bit
total=0;
counter=0;
for(i=start_bit;total<=endbit;i++,total++){
if(counter/8==len+1){return 2;} //bits go past length
counter++;
if(data[j]&(1<<i)!=0){return 4+total;} //the bits are not free-- subtract 4 and you got number of the set bit
if(i==31 && total<endbit){i=0;start_bit=0;j++;} //bits are free here but need to check next dword
}
return 1; //the bits are free
}
unsigned int num_set_bits(unsigned int *data,unsigned int start_bit,unsigned int len){
unsigned int i,j=0,endbit,total,counter; //i bet i could've used less stack but anyway
endbit=len*8+start_bit; //make it the end bit
total=0;
counter=0;
for(i=start_bit;total<=endbit;i++,total++){
if(counter/8==len+1){return 1;} //bits go past length --have to use signed stuff for this
counter++;
if(data[j]&(1<<i)==0){return total+4;} //the bits are not free-- subtract 4 and you got number of the set bit
if(i==31 && total<endbit){i=0;start_bit=0;j++;} //bits are free here but need to check next dword
}
return 0; //the bits are free
}
unsigned int* set_bits(unsigned int *data,unsigned int start_bit,unsigned int end_bit,unsigned int len){
unsigned int i,counter,j,total;
j=0;
counter=0;
total=0;
for(i=start_bit;total<=end_bit;i++,total++){
if(counter==len+1){return 0;} //goes past len
counter++;
data[j]=data[j]|(1<<i);
if(i==31 && total<end_bit){i=0;start_bit=0;j++;}
}
return data;
}
unsigned int* clear_bits(unsigned int *data,unsigned int start_bit,unsigned int end_bit,unsigned int len){
unsigned int i,counter,j,total;
j=0;
total=0;
counter=0;
for(i=start_bit;total<=end_bit;i++,total++){ //i gets roundoff every 32 cycles so we need one that don't
if(counter==len+1){return 0;} //goes past len
counter++;
data[j]=data[j]&(0xFFFFFFFF^(1<<i));
if(i==31 && total<end_bit){i=0;start_bit=0;j++;}
}
return data;
}
void *FreeCore(void *page_ptr,unsigned int num_pages);
void *AllocCore(unsigned int num_pages){
unsigned int i=0,t,j;unsigned int page,super_page;
unsigned char *tmp;
unsigned int index,index2,j2;
/*
while(superpages[i]==0xFFFFFFFF){
if(i>=32){return 0;} //error! couldnt find a free superpage
i++;
}
super_page=find_0_bit(superpages[i]);
super_page=super_page+(i*32);
i=super_page*1024; //this is the page number where the super page begins*/
if (num_pages>1){ //use a special allocation method
while(pages[i]==0xFFFFFFFF){
if(i>=32768){return 0;}
//k_printf("t3");
i++;
}
index=i;
t=find_0_bit(pages[i]);
j=t;
for(;;){
j=is_free_bits(&pages[index],t,num_pages,32768*4-index*4);
if(j==1){
if(set_bits(&pages[index],t,num_pages+t,32768*4-index*4)==0){return 0;} //means page table is full or there isn't enough room
return (index+(t*32))*4096; //this and above means that the bits were free
}
if(j==2){return 0;} //goes past length
if(j>=4){ //some bits weren't free
j=j-4; //we added 4 to it for error code
index=index+j/32; //advances index if past a dword
t=(j%32)+1;
t=num_set_bits(&pages[index],t,32768*4-index*4);
//if t is 0 then we just continue
if(t==1){return 0;} //goes beyond, full
t=t-4; //we added 4 on this one too
index=index+t/32; //advances index if past a dword
t=(t%32)+1;
//idk who would need 32 pages but anyway
//and now reset and will begin the loop again
}
} }else{ //if num_pages==1
}
while(pages[i]==0xFFFFFFFF){
if(i>=32768){return 0;}
//k_printf("t3");
i++;
}
page=find_0_bit(pages[i]);
pages[i]=pages[i]|(1<<page);
page=page+(i*32);
page=page*4096;
//if (i==0){ k_printf("t3");}
t=i;
return page;
}