mirror of
https://github.com/libretro/RetroArch
synced 2025-03-06 04:13:52 +00:00
(memory/wii) Cleanups
This commit is contained in:
parent
f2701089e6
commit
2c325f0ea6
@ -1,5 +1,3 @@
|
||||
/** Adopted from WiiMC (Tantric 2009-2012) and WiiFlow (http://code.google.com/p/wiiflow/) */
|
||||
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <unistd.h>
|
||||
@ -14,24 +12,24 @@
|
||||
#include "../../gfx/drivers/ppc_asm.h"
|
||||
|
||||
/* Forbid the use of MEM2 through malloc */
|
||||
u32 MALLOC_MEM2 = 0;
|
||||
uint32_t MALLOC_MEM2 = 0;
|
||||
|
||||
/*** from libogc (lwp_heap.inl) ****/
|
||||
|
||||
static INLINE heap_block *__lwp_heap_blockat(heap_block *block, u32 offset)
|
||||
static INLINE heap_block *__lwp_heap_blockat(heap_block *block, uint32_t offset)
|
||||
{
|
||||
return (heap_block *) ((char *) block + offset);
|
||||
}
|
||||
|
||||
static INLINE heap_block *__lwp_heap_usrblockat(void *ptr)
|
||||
{
|
||||
u32 offset = *(((u32 *) ptr) - 1);
|
||||
uint32_t offset = *(((uint32_t *) ptr) - 1);
|
||||
return __lwp_heap_blockat(ptr, -offset + -HEAP_BLOCK_USED_OVERHEAD);
|
||||
}
|
||||
|
||||
static INLINE bool __lwp_heap_blockin(heap_cntrl *heap, heap_block *block)
|
||||
{
|
||||
return ((u32) block >= (u32) heap->start && (u32) block <= (u32) heap->final);
|
||||
return ((uint32_t) block >= (uint32_t) heap->start && (uint32_t) block <= (uint32_t) heap->final);
|
||||
}
|
||||
|
||||
static INLINE bool __lwp_heap_blockfree(heap_block *block)
|
||||
@ -39,17 +37,17 @@ static INLINE bool __lwp_heap_blockfree(heap_block *block)
|
||||
return !(block->front_flag & HEAP_BLOCK_USED);
|
||||
}
|
||||
|
||||
static INLINE u32 __lwp_heap_blocksize(heap_block *block)
|
||||
static INLINE uint32_t __lwp_heap_blocksize(heap_block *block)
|
||||
{
|
||||
return (block->front_flag & ~HEAP_BLOCK_USED);
|
||||
}
|
||||
|
||||
/*** end from libogc (lwp_heap.inl) ****/
|
||||
|
||||
static u32 __lwp_heap_block_size(heap_cntrl *theheap, void *ptr)
|
||||
static uint32_t __lwp_heap_block_size(heap_cntrl *theheap, void *ptr)
|
||||
{
|
||||
heap_block *block;
|
||||
u32 dsize, level;
|
||||
uint32_t dsize, level;
|
||||
(void)level;
|
||||
|
||||
_CPU_ISR_Disable(level);
|
||||
@ -66,14 +64,14 @@ static u32 __lwp_heap_block_size(heap_cntrl *theheap, void *ptr)
|
||||
return dsize;
|
||||
}
|
||||
|
||||
#define ROUNDUP32(v) (((u32)(v) + 0x1f) & ~0x1f)
|
||||
#define ROUNDUP32(v) (((uint32_t)(v) + 0x1f) & ~0x1f)
|
||||
|
||||
static heap_cntrl gx_mem2_heap;
|
||||
|
||||
bool gx_init_mem2(void)
|
||||
{
|
||||
void *heap_ptr;
|
||||
u32 level, size;
|
||||
uint32_t level, size;
|
||||
_CPU_ISR_Disable(level);
|
||||
|
||||
/* BIG NOTE: MEM2 on the Wii is 64MB, but a portion
|
||||
@ -92,7 +90,7 @@ bool gx_init_mem2(void)
|
||||
*/
|
||||
size = SYS_GetArena2Size() - 1024 * 256;
|
||||
|
||||
heap_ptr = (void *) ROUNDUP32(((u32) SYS_GetArena2Hi() - size));
|
||||
heap_ptr = (void *) ROUNDUP32(((uint32_t) SYS_GetArena2Hi() - size));
|
||||
|
||||
SYS_SetArena2Hi(heap_ptr);
|
||||
__lwp_heap_init(&gx_mem2_heap, heap_ptr, size, 32);
|
||||
@ -101,14 +99,14 @@ bool gx_init_mem2(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
void *_mem2_memalign(u8 align, u32 size)
|
||||
void *_mem2_memalign(uint8_t align, uint32_t size)
|
||||
{
|
||||
if(size == 0)
|
||||
return NULL;
|
||||
return __lwp_heap_allocate(&gx_mem2_heap, size);
|
||||
}
|
||||
|
||||
void *_mem2_malloc(u32 size)
|
||||
void *_mem2_malloc(uint32_t size)
|
||||
{
|
||||
return _mem2_memalign(32, size);
|
||||
}
|
||||
@ -119,9 +117,9 @@ void _mem2_free(void *ptr)
|
||||
__lwp_heap_free(&gx_mem2_heap, ptr);
|
||||
}
|
||||
|
||||
void *_mem2_realloc(void *ptr, u32 newsize)
|
||||
void *_mem2_realloc(void *ptr, uint32_t newsize)
|
||||
{
|
||||
u32 size;
|
||||
uint32_t size;
|
||||
void *newptr = NULL;
|
||||
|
||||
if (!ptr)
|
||||
@ -149,7 +147,7 @@ void *_mem2_realloc(void *ptr, u32 newsize)
|
||||
return newptr;
|
||||
}
|
||||
|
||||
void *_mem2_calloc(u32 num, u32 size)
|
||||
void *_mem2_calloc(uint32_t num, uint32_t size)
|
||||
{
|
||||
void *ptr = _mem2_malloc(num * size);
|
||||
|
||||
@ -192,14 +190,14 @@ char *_mem2_strndup(const char *s, size_t n)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
u32 gx_mem2_used(void)
|
||||
uint32_t gx_mem2_used(void)
|
||||
{
|
||||
heap_iblock info;
|
||||
__lwp_heap_getinfo(&gx_mem2_heap, &info);
|
||||
return info.used_size;
|
||||
}
|
||||
|
||||
u32 gx_mem2_total(void)
|
||||
uint32_t gx_mem2_total(void)
|
||||
{
|
||||
heap_iblock info;
|
||||
__lwp_heap_getinfo(&gx_mem2_heap, &info);
|
||||
@ -244,7 +242,7 @@ __attribute__ ((used)) void __wrap_free(void *p)
|
||||
if (!p)
|
||||
return;
|
||||
|
||||
if (((u32)p & 0x10000000) != 0)
|
||||
if (((uint32_t)p & 0x10000000) != 0)
|
||||
_mem2_free(p);
|
||||
else
|
||||
__real_free(p);
|
||||
@ -254,7 +252,7 @@ __attribute__ ((used)) void *__wrap_realloc(void *p, size_t size)
|
||||
{
|
||||
void *n;
|
||||
/* ptr from mem2 */
|
||||
if (((u32) p & 0x10000000) != 0)
|
||||
if (((uint32_t) p & 0x10000000) != 0)
|
||||
{
|
||||
n = _mem2_realloc(p, size);
|
||||
if (n != 0)
|
||||
@ -270,7 +268,7 @@ __attribute__ ((used)) void *__wrap_realloc(void *p, size_t size)
|
||||
}
|
||||
return n;
|
||||
}
|
||||
// ptr from malloc
|
||||
/* ptr from malloc */
|
||||
n = __real_realloc(p, size);
|
||||
if (n != 0)
|
||||
return n;
|
||||
@ -304,7 +302,7 @@ __attribute__ ((used)) void *__wrap_strndup(const char *s, size_t n)
|
||||
|
||||
__attribute__ ((used)) size_t __wrap_malloc_usable_size(void *p)
|
||||
{
|
||||
if (((u32) p & 0x10000000) != 0)
|
||||
if (((uint32_t) p & 0x10000000) != 0)
|
||||
return __lwp_heap_block_size(&gx_mem2_heap, p);
|
||||
return __real_malloc_usable_size(p);
|
||||
}
|
||||
|
@ -1,19 +1,12 @@
|
||||
/****************************************************************************
|
||||
* WiiMC
|
||||
* Tantric 2009-2012
|
||||
*
|
||||
* mem2_manager.h
|
||||
*
|
||||
* MEM2 allocator
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _MEM2_MANAGER_H
|
||||
#define _MEM2_MANAGER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
bool gx_init_mem2(void);
|
||||
|
||||
u32 gx_mem2_used(void);
|
||||
uint32_t gx_mem2_used(void);
|
||||
|
||||
u32 gx_mem2_total(void);
|
||||
uint32_t gx_mem2_total(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user