GSoC/Buflib: Add buflib memory alocator to the core.

The buflib memory allocator is handle based and can free and
compact, move or resize memory on demand. This allows to effeciently
allocate memory dynamically without an MMU, by avoiding fragmentation
through memory compaction.

This patch adds the buflib library to the core, along with
convinience wrappers to omit the context parameter. Compaction is
not yet enabled, but will be in a later patch. Therefore, this acts as a
replacement for buffer_alloc/buffer_get_buffer() with the benifit of a debug
menu.

See buflib.h for some API documentation.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30380 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2011-08-30 14:01:33 +00:00
parent c940811ade
commit d0b72e2590
26 changed files with 1453 additions and 125 deletions

View file

@ -30,7 +30,7 @@
#include "dm320.h"
#include "ata.h"
#include "string.h"
#include "buffer.h"
#include "core_alloc.h"
#include "logf.h"
#include "ata-defines.h"
@ -202,7 +202,11 @@ struct cfs_direntry_item
static bool cfs_inited = false;
static unsigned long cfs_start;
#ifdef BOOTLOADER
static unsigned long *sectors;
#else
static int sectors_handle;
#endif
#define CFS_START ( ((hdr->partitions[1].start*hdr->sector_size) & ~0xFFFF) + 0x10000 )
#define CFS_CLUSTER2CLUSTER(x) ( (CFS_START/512)+((x)-1)*64 )
@ -299,7 +303,8 @@ static void cfs_init(void)
_ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inodes_nr[1]), 1, &sector);
inode = (struct cfs_inode*)&sector;
#ifndef BOOTLOADER
sectors = (unsigned long*)buffer_alloc(VFAT_SECTOR_SIZE(inode->filesize));
sectors_handle = core_alloc("ata sectors", VFAT_SECTOR_SIZE(inode->filesize));
unsigned long *sectors = core_get_data(sectors_handle);
#else
static unsigned long _sector[VFAT_SECTOR_SIZE(1024*1024*1024)]; /* 1GB guess */
sectors = _sector;
@ -322,6 +327,9 @@ static void cfs_init(void)
_ata_read_sectors(CFS_CLUSTER2CLUSTER(inode->second_class_chain_second_cluster), 64, &vfat_data[1]);
/* First class chain */
#ifndef BOOTLOADER
sectors = core_get_data(sectors_handle);
#endif
for(j=0; j<12; j++)
{
if( (inode->first_class_chain[j] & 0xFFFF) != 0xFFFF &&
@ -331,6 +339,9 @@ static void cfs_init(void)
}
/* Second class chain */
#ifndef BOOTLOADER
sectors = core_get_data(sectors_handle);
#endif
for(j=0; j<0x8000/4; j++)
{
if( (vfat_data[0][j] & 0xFFFF) != 0xFFFF &&
@ -351,6 +362,9 @@ static void cfs_init(void)
/* Read third class subchain(s) */
_ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_data[1][j]), 64, &vfat_data[0]);
#ifndef BOOTLOADER
sectors = core_get_data(sectors_handle);
#endif
for(k=0; k<0x8000/4; k++)
{
if( (vfat_data[0][k] & 0xFFFF) != 0xFFFF &&
@ -376,6 +390,9 @@ static inline unsigned long map_sector(unsigned long sector)
* Sector mapping: start of CFS + FAT_SECTOR2CFS_SECTOR(sector) + missing part
* FAT works with sectors of 0x200 bytes, CFS with sectors of 0x8000 bytes.
*/
#ifndef BOOTLOADER
unsigned long *sectors = core_get_data(sectors_handle);
#endif
return cfs_start+sectors[sector/64]*64+sector%64;
}