-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write page_alloc (no page_free). #48
- Loading branch information
Showing
3 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @file | ||
* @brief page allocator header | ||
* @details | ||
* | ||
* @date 04.04.10 | ||
* @author Fedor Burdun | ||
*/ | ||
|
||
#ifndef __PAGE_ALLOC_H_ | ||
#define __PAGE_ALLOC_H_ | ||
|
||
#ifdef DEBUG_x86_ONLY /* Code included for debug specific */ | ||
#include <malloc.h> | ||
#else /* Embox specific code */ | ||
#endif /* End of specific code */ | ||
|
||
struct pmark_t; | ||
|
||
#ifdef DEBUG_x86_ONLY /* Code included for debug specific */ | ||
|
||
typedef long psize_t; | ||
typedef struct pmark_t* paddr_t; | ||
const psize_t MAXPAGECOUNT = 0xffff; | ||
const paddr_t SIZEOFPAGE = 0x00ff; | ||
struct paddr_t *cmark_p; | ||
void *mem; | ||
int palloc_hasinit = 0x0000; | ||
|
||
#else /* Embox specific code */ | ||
|
||
#endif /* End of specific code */ | ||
|
||
/* structure of page marker */ | ||
struct pmark_t { | ||
psize_t psize; | ||
paddr_t *pnext; | ||
paddr_t *pprev; | ||
}; | ||
|
||
/* */ | ||
paddr_t page_alloc(psize_t); | ||
void page_free(paddr_t); | ||
|
||
#endif /* __PAGE_ALLOC_H_ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @file | ||
* @brief test page allocator | ||
* @details | ||
* | ||
* @date 04.04.10 | ||
* @author Fedor Burdun | ||
*/ | ||
|
||
|
||
#define DEBUG_x86_ONLY | ||
#include "page_alloc.h" | ||
|
||
#if 0 | ||
#include "../../src/lib/page_alloc/page_alloc.c" | ||
#endif | ||
|
||
int main() { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* @file | ||
* @brief page allocator | ||
* @details | ||
* | ||
* @date 04.04.10 | ||
* @author Fedor Burdun | ||
*/ | ||
|
||
#if 0 /* Example code for use from header file */ | ||
typedef long psize_t; | ||
typedef long paddr_t; | ||
const psize_t MAXPAGECOUNT = 0xffff; | ||
const paddr_t SIZEOFPAGE = 0xff; | ||
pmark_t *cmark_p; | ||
void *mem; | ||
|
||
#ifdef DEBUG_x86_ONLY /* Code included for debug specific */ | ||
#else /* Embox specific code */ | ||
#endif /* End of specific code */ | ||
|
||
/* structure of page marker */ | ||
struct pmark_t { | ||
psize_t psize; | ||
pmark_t *pnext; | ||
}; | ||
|
||
#endif | ||
|
||
/* copy mark structure */ | ||
paddr_t copy_mark( paddr_t from , paddr_t to ) { | ||
to->psize = from->psize; | ||
to->pnext = from->pnext; | ||
to->pprev = from->pprev; | ||
return to; | ||
} | ||
|
||
/* Initialize page allocator */ | ||
void page_alloc_init() { | ||
#ifdef DEBUG_x86_ONLY /* Code included for debug specific */ | ||
mem = malloc( MAXPAGECOUNT * SIZEOFPAGE ); | ||
#else /* Embox specific code */ | ||
#endif /* End of specific code */ | ||
cmark_p = mem; | ||
cmark_p->psize = MAXPAGECOUNT; | ||
cmark_p->pnext = cmark_p; | ||
palloc_hasinit = 1; | ||
} | ||
|
||
/* allocate page */ | ||
paddr_t page_alloc(psize_t psize) { | ||
if (!palloc_hasinit) { | ||
page_alloc_init(); | ||
} | ||
/* find first proper block */ | ||
struct pmark_t *pcur; | ||
pcur = cmark_p->next; | ||
while ( pcur != cmark_p && pcur->psize < psize ) { | ||
pcur = pcur->next; | ||
} | ||
/* check finded block */ | ||
if ( pcur->psize >= psize ) { | ||
/* change list and return value */ | ||
if (pcur->psize > psize ) { | ||
pcur->psize = pcur->psize - psize; | ||
cmark_p = copy_mark( pcur , pcur + SIZEOFPAGE * psize ); | ||
return pcur; | ||
} else { | ||
/* psize == pcur->psize */ | ||
pcur->pprev->next = pcur->next; | ||
return pcur; | ||
} | ||
} else { | ||
#if 0 | ||
page_defrag(); | ||
return page_alloc(psize); | ||
#endif | ||
/* generate memory error */ | ||
} | ||
} | ||
|
||
/* free page that was allocated */ | ||
void page_free(paddr_t paddr) { | ||
/* find */ | ||
} | ||
|
||
/* defragmentation pages */ | ||
void page_defrag() { | ||
} | ||
|