Skip to content

Commit

Permalink
Made of compilation test_page_alloc
Browse files Browse the repository at this point in the history
It isn't right, but it's work. #48.
  • Loading branch information
fijiol committed Apr 8, 2010
1 parent 292af18 commit 4c2b1ca
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 74 deletions.
25 changes: 18 additions & 7 deletions extended_test/page_alloc/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@

MACROS = ./macros.h
INCLUDES = ../../src/include
#MACROS = ./macros.h
#INCLUDES = ../../src/include
#INCLUDES = ./

CC = gcc -I $(INCLUDES) -imacros $(MACROS)

page_alloc:
$(CC) ../../src/lib/page_alloc/page_alloc.c
#CC = gcc -I $(INCLUDES) -imacros $(MACROS) # -D EXTENDED_TEST
#CC = gcc -include ../../src/include/lib/page_alloc.h -imacros $(MACROS) # -D EXTENDED_TEST
#CC = gcc -include ../../src/include/lib/page_alloc.h -D EXTENDED_TEST
CC = gcc -I ./ -D EXTENDED_TEST

.PHONY: test
test: page_alloc
$(CC) ./test_page_alloc.c
cp ../../src/include/lib/page_alloc.h ./lib/
$(CC) ./test_page_alloc.c page_alloc -o test_page_alloc

page_alloc:
cp ../../src/include/lib/page_alloc.h ./lib/
$(CC) ../../src/lib/page_alloc/page_alloc.c -c -o page_alloc

clean:
rm ./lib/page_alloc.h
rm ./page_alloc
rm ./test_page_alloc

3 changes: 0 additions & 3 deletions extended_test/page_alloc/macros.h

This file was deleted.

46 changes: 0 additions & 46 deletions extended_test/page_alloc/page_alloc.h

This file was deleted.

12 changes: 10 additions & 2 deletions src/include/lib/page_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@
#ifndef __PAGE_ALLOC_H_
#define __PAGE_ALLOC_H_

#include <types.h>
#ifndef EXTENDED_TEST
# include <types.h>
#else
# include <bits/types.h>
# include <unistd.h>
# include <cdio/types.h>
#endif

/** Structure of page marker. It occupies at the begin of each free memory
* block
* psize - count of page
* pnext, pprev - pointers other free blocks
*/
typedef struct pmark {
size_t psize;
size_t psize;
struct pmark *pnext;
struct pmark *pprev;
}pmark_t;
Expand Down
33 changes: 17 additions & 16 deletions src/lib/page_alloc/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#define PAGE_QUANTITY 0x100
#define PAGE_SIZE 0x100

int page_alloc_hasinit = 0;

#ifdef EXTENDED_TEST
static uint8_t page_pool[PAGE_SIZE][PAGE_QUANTITY]
static pmark_t *cmark_p = (pmark_t *);
static uint8_t page_pool[PAGE_SIZE][PAGE_QUANTITY];
static pmark_t *cmark_p = (pmark_t *) page_pool;
#else
#define START_MEMORY_ADDR 0x40000000
static pmark_t *cmark_p = (pmark_t *)START_MEMORY_ADDR;
Expand All @@ -34,12 +36,6 @@ static pmark_t *copy_mark( pmark_t *from , pmark_t *to ) {

/* Initialize page allocator */
int page_alloc_init(void) {
#ifdef DEBUG_x86_ONLY /* Code included for debug specific */
//we allocated this static
//mem = malloc( MAXPAGECOUNT * SIZEOFPAGE );
#else /* Embox specific code */
#endif /* End of specific code */
//cmark_p = mem;
cmark_p->psize = PAGE_QUANTITY;
cmark_p->pnext = cmark_p;
cmark_p->pprev = cmark_p;
Expand All @@ -48,18 +44,20 @@ int page_alloc_init(void) {

/* allocate page */
pmark_t *page_alloc(void) {
size_t psize = PAGE_SIZE;
// if (!palloc_hasinit) {
// page_alloc_init();
// }
/* find first proper block */
size_t psize = 1;
pmark_t *pcur;

if (!page_alloc_hasinit) {
page_alloc_init();
page_alloc_hasinit = 1;
}
/* find first proper block */
pcur = cmark_p->pnext;
while ( pcur != cmark_p /*&& pcur->psize < psize */) {
pcur = pcur->pnext;
}
/* check finded block */
if ( pcur->psize >= PAGE_SIZE ) {
if ( pcur->psize >= psize ) {
/* change list and return value */
if (pcur->psize > psize ) {
pcur->psize = pcur->psize - psize;
Expand All @@ -68,6 +66,7 @@ pmark_t *page_alloc(void) {
} else {
/* psize == pcur->psize */
pcur->pprev->pnext = pcur->pnext;
cmark_p = pcur->pnext;
return pcur;
}

Expand All @@ -79,7 +78,9 @@ pmark_t *page_alloc(void) {
/* free page that was allocated */
void page_free(pmark_t *paddr) {
/* find */
paddr->psize = 1;
paddr->pprev = cmark_p->pprev;
cmark_p->pprev = paddr;
paddr->pnext = cmark_p;
}



0 comments on commit 4c2b1ca

Please sign in to comment.