2011-08-30 14:01:33 +00:00
|
|
|
|
2011-11-29 00:42:27 +00:00
|
|
|
#include "config.h"
|
2011-08-30 14:01:33 +00:00
|
|
|
#include <string.h>
|
2011-11-29 00:42:27 +00:00
|
|
|
#include "system.h"
|
2011-08-30 14:01:33 +00:00
|
|
|
#include "core_alloc.h"
|
|
|
|
#include "buflib.h"
|
|
|
|
|
|
|
|
/* not static so it can be discovered by core_get_data() */
|
|
|
|
struct buflib_context core_ctx;
|
2011-10-05 18:32:19 +00:00
|
|
|
|
2012-03-03 18:37:40 +00:00
|
|
|
#if (CONFIG_PLATFORM & PLATFORM_NATIVE) && !defined(__PCTOOL__)
|
2021-10-02 06:19:10 +00:00
|
|
|
|
2011-11-29 00:42:27 +00:00
|
|
|
#if defined(IPOD_VIDEO) && !defined(BOOTLOADER)
|
2021-10-02 06:19:10 +00:00
|
|
|
/* defined in linker script */
|
|
|
|
extern unsigned char audiobuffer[];
|
2011-11-29 00:42:27 +00:00
|
|
|
extern unsigned char *audiobufend_lds[];
|
2021-10-02 06:19:10 +00:00
|
|
|
/* pointer to end of audio buffer filled at runtime allocator_init */
|
2011-11-29 00:42:27 +00:00
|
|
|
unsigned char *audiobufend;
|
2021-10-02 06:19:10 +00:00
|
|
|
#elif defined(SANSA_E200) && defined(HAVE_BOOTLOADER_USB_MODE)
|
|
|
|
/* defined in linker script */
|
|
|
|
extern unsigned char freebuffer[];
|
|
|
|
extern unsigned char freebufferend[];
|
|
|
|
/* map linker symbol to the audiobuffer in order to use core_alloc */
|
|
|
|
unsigned char *audiobuffer = (unsigned char *)freebuffer;
|
|
|
|
unsigned char *audiobufend = (unsigned char *)freebufferend;
|
|
|
|
#else /* !IPOD_VIDEO, !SANSA_E200&&BOOTLOADERUSB */
|
2011-11-29 00:42:27 +00:00
|
|
|
/* defined in linker script */
|
|
|
|
extern unsigned char audiobuffer[];
|
2021-10-02 06:19:10 +00:00
|
|
|
extern unsigned char audiobufend[];
|
|
|
|
#endif
|
|
|
|
|
2011-11-29 00:42:27 +00:00
|
|
|
#else /* PLATFORM_HOSTED */
|
2015-01-11 17:02:43 +00:00
|
|
|
static unsigned char audiobuffer[((MEMORYSIZE)*1024-768)*1024];
|
2011-11-29 00:42:27 +00:00
|
|
|
unsigned char *audiobufend = audiobuffer + sizeof(audiobuffer);
|
|
|
|
extern unsigned char *audiobufend;
|
|
|
|
#endif
|
|
|
|
|
2023-01-02 19:18:02 +00:00
|
|
|
#ifdef BUFLIB_DEBUG_PRINT
|
2011-10-05 18:32:19 +00:00
|
|
|
/* debug test alloc */
|
|
|
|
static int test_alloc;
|
2023-01-02 19:18:02 +00:00
|
|
|
#endif
|
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
void core_allocator_init(void)
|
|
|
|
{
|
2011-11-29 00:42:27 +00:00
|
|
|
unsigned char *start = ALIGN_UP(audiobuffer, sizeof(intptr_t));
|
|
|
|
|
|
|
|
#if defined(IPOD_VIDEO) && !defined(BOOTLOADER) && !defined(SIMULATOR)
|
|
|
|
audiobufend=(unsigned char *)audiobufend_lds;
|
|
|
|
if(MEMORYSIZE==64 && probed_ramsize!=64)
|
|
|
|
{
|
|
|
|
audiobufend -= (32<<20);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
buflib_init(&core_ctx, start, audiobufend - start);
|
2011-10-05 18:32:19 +00:00
|
|
|
|
2023-01-02 19:18:02 +00:00
|
|
|
#ifdef BUFLIB_DEBUG_PRINT
|
2022-10-15 22:55:39 +00:00
|
|
|
test_alloc = core_alloc(112);
|
2023-01-02 19:18:02 +00:00
|
|
|
#endif
|
2011-08-30 14:01:33 +00:00
|
|
|
}
|
|
|
|
|
2015-01-02 17:41:30 +00:00
|
|
|
/* Allocate memory in the "core" context. See documentation
|
|
|
|
* of buflib_alloc_ex() for details.
|
|
|
|
*
|
|
|
|
* Note: Buffers allocated by this functions are movable.
|
|
|
|
* Don't pass them to functions that call yield()
|
|
|
|
* like disc input/output. */
|
2022-10-15 22:55:39 +00:00
|
|
|
int core_alloc(size_t size)
|
2011-08-30 14:01:33 +00:00
|
|
|
{
|
2022-10-15 22:55:39 +00:00
|
|
|
return buflib_alloc_ex(&core_ctx, size, NULL);
|
2011-08-30 14:01:33 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 22:55:39 +00:00
|
|
|
int core_alloc_ex(size_t size, struct buflib_callbacks *ops)
|
2011-08-30 14:01:33 +00:00
|
|
|
{
|
2022-10-15 22:55:39 +00:00
|
|
|
return buflib_alloc_ex(&core_ctx, size, ops);
|
2011-08-30 14:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t core_available(void)
|
|
|
|
{
|
|
|
|
return buflib_available(&core_ctx);
|
|
|
|
}
|
|
|
|
|
2013-05-29 05:07:34 +00:00
|
|
|
size_t core_allocatable(void)
|
|
|
|
{
|
|
|
|
return buflib_allocatable(&core_ctx);
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
int core_free(int handle)
|
|
|
|
{
|
|
|
|
return buflib_free(&core_ctx, handle);
|
|
|
|
}
|
|
|
|
|
2022-10-15 22:55:39 +00:00
|
|
|
int core_alloc_maximum(size_t *size, struct buflib_callbacks *ops)
|
2011-08-30 14:01:33 +00:00
|
|
|
{
|
2022-10-15 22:55:39 +00:00
|
|
|
return buflib_alloc_maximum(&core_ctx, size, ops);
|
2011-08-30 14:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool core_shrink(int handle, void* new_start, size_t new_size)
|
|
|
|
{
|
|
|
|
return buflib_shrink(&core_ctx, handle, new_start, new_size);
|
|
|
|
}
|
|
|
|
|
2022-04-03 09:48:14 +00:00
|
|
|
void core_pin(int handle)
|
|
|
|
{
|
|
|
|
buflib_pin(&core_ctx, handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void core_unpin(int handle)
|
|
|
|
{
|
|
|
|
buflib_unpin(&core_ctx, handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned core_pin_count(int handle)
|
|
|
|
{
|
|
|
|
return buflib_pin_count(&core_ctx, handle);
|
|
|
|
}
|
|
|
|
|
2023-01-02 19:18:02 +00:00
|
|
|
#ifdef BUFLIB_DEBUG_PRINT
|
2011-08-30 14:01:33 +00:00
|
|
|
int core_get_num_blocks(void)
|
|
|
|
{
|
|
|
|
return buflib_get_num_blocks(&core_ctx);
|
|
|
|
}
|
|
|
|
|
2023-01-02 19:18:02 +00:00
|
|
|
bool core_print_block_at(int block_num, char* buf, size_t bufsize)
|
2011-08-30 14:01:33 +00:00
|
|
|
{
|
2023-01-02 19:18:02 +00:00
|
|
|
return buflib_print_block_at(&core_ctx, block_num, buf, bufsize);
|
2011-08-30 14:01:33 +00:00
|
|
|
}
|
2014-01-09 20:37:07 +00:00
|
|
|
|
2023-01-02 19:18:02 +00:00
|
|
|
bool core_test_free(void)
|
|
|
|
{
|
|
|
|
bool ret = test_alloc > 0;
|
|
|
|
if (ret)
|
|
|
|
test_alloc = core_free(test_alloc);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BUFLIB_DEBUG_CHECK_VALID
|
2014-01-09 20:37:07 +00:00
|
|
|
void core_check_valid(void)
|
|
|
|
{
|
|
|
|
buflib_check_valid(&core_ctx);
|
|
|
|
}
|
|
|
|
#endif
|