mirror of
https://github.com/libretro/RetroArch.git
synced 2024-10-07 14:23:29 +00:00
(ctr) style nits
This commit is contained in:
parent
e25472013f
commit
64e24ca514
@ -72,7 +72,6 @@ struct MemPool
|
||||
nPrev = n;
|
||||
}
|
||||
|
||||
//void CoalesceLeft(MemBlock* b);
|
||||
void CoalesceRight(MemBlock* b);
|
||||
|
||||
bool Allocate(MemChunk& chunk, u32 size, int align);
|
||||
@ -146,7 +145,7 @@ extern u32 __linear_heap, __linear_heap_size;
|
||||
static MemPool sLinearPool;
|
||||
static u32 sLinearPool_maxaddr;
|
||||
|
||||
static bool linearInit()
|
||||
static bool linearInit(void)
|
||||
{
|
||||
auto blk = MemBlock::Create((u8*)__linear_heap, __linear_heap_size);
|
||||
if (blk)
|
||||
@ -200,12 +199,14 @@ void* linearMemAlign(size_t size, size_t alignment)
|
||||
|
||||
void* linearAlloc(size_t size)
|
||||
{
|
||||
// extern PrintConsole* currentConsole;
|
||||
// if(currentConsole->consoleInitialised)
|
||||
// {
|
||||
// printf("linearAlloc : 0x%08X\n", size);
|
||||
// DEBUG_HOLD();
|
||||
// }
|
||||
#if 0
|
||||
extern PrintConsole* currentConsole;
|
||||
if(currentConsole->consoleInitialised)
|
||||
{
|
||||
printf("linearAlloc : 0x%08X\n", size);
|
||||
DEBUG_HOLD();
|
||||
}
|
||||
#endif
|
||||
return linearMemAlign(size, 0x80);
|
||||
}
|
||||
|
||||
@ -258,10 +259,12 @@ extern "C" void ctr_linear_free_pages(u32 pages)
|
||||
__linear_heap_size -= size;
|
||||
u32 tmp;
|
||||
svcControlMemory(&tmp, __linear_heap + __linear_heap_size, 0x0, size,
|
||||
MEMOP_FREE, (MemPerm)(MEMPERM_READ | MEMPERM_WRITE));
|
||||
MEMOP_FREE, (MemPerm)(MEMPERM_READ | MEMPERM_WRITE));
|
||||
|
||||
// printf("l:0x%08X-->0x%08X(-0x%08X) \n", sLinearPool.last->size + size, sLinearPool.last->size, size);
|
||||
// DEBUG_HOLD();
|
||||
#if 0
|
||||
printf("l:0x%08X-->0x%08X(-0x%08X) \n", sLinearPool.last->size + size, sLinearPool.last->size, size);
|
||||
DEBUG_HOLD();
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void ctr_linear_get_stats(void)
|
||||
|
@ -5,17 +5,6 @@
|
||||
|
||||
#include "ctr_debug.h"
|
||||
|
||||
//void* malloc(size_t nbytes)
|
||||
//{
|
||||
// void* ret = _malloc_r (_REENT, nbytes);
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
//void free (void* aptr)
|
||||
//{
|
||||
// _free_r (_REENT, aptr);
|
||||
//}
|
||||
|
||||
extern u32 __heapBase;
|
||||
extern u32 __heap_size;
|
||||
extern u32 __stack_bottom;
|
||||
@ -36,7 +25,6 @@ u32 ctr_get_stack_free(void)
|
||||
return ((u32)stack_bottom_current - __stack_bottom);
|
||||
}
|
||||
|
||||
|
||||
u32 ctr_get_stack_usage(void)
|
||||
{
|
||||
extern u32 __stacksize__;
|
||||
@ -57,8 +45,10 @@ void ctr_free_pages(u32 pages)
|
||||
if((ctr_get_linear_unused() >> 12) > pages + 0x100)
|
||||
return ctr_linear_free_pages(pages);
|
||||
|
||||
// if(linear_free_pages > pages + 0x400)
|
||||
// return ctr_linear_free_pages(pages);
|
||||
#if 0
|
||||
if(linear_free_pages > pages + 0x400)
|
||||
return ctr_linear_free_pages(pages);
|
||||
#endif
|
||||
|
||||
u32 stack_free = ctr_get_stack_free();
|
||||
u32 stack_usage = __stacksize__ > stack_free? __stacksize__ - stack_free: 0;
|
||||
@ -85,22 +75,24 @@ void ctr_free_pages(u32 pages)
|
||||
{
|
||||
u32 tmp;
|
||||
svcControlMemory(&tmp, __stack_bottom,
|
||||
0x0,
|
||||
stack_free_pages << 12,
|
||||
MEMOP_FREE, MEMPERM_READ | MEMPERM_WRITE);
|
||||
0x0,
|
||||
stack_free_pages << 12,
|
||||
MEMOP_FREE, MEMPERM_READ | MEMPERM_WRITE);
|
||||
__stack_bottom += stack_free_pages << 12;
|
||||
__stack_size_extra -= stack_free_pages << 12;
|
||||
__stacksize__ -= stack_free_pages << 12;
|
||||
// printf("s:0x%08X-->0x%08X(-0x%08X) \n", stack_free,
|
||||
// stack_free - (stack_free_pages << 12), stack_free_pages << 12);
|
||||
// DEBUG_HOLD();
|
||||
#if 0
|
||||
printf("s:0x%08X-->0x%08X(-0x%08X) \n", stack_free,
|
||||
stack_free - (stack_free_pages << 12), stack_free_pages << 12);
|
||||
DEBUG_HOLD();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
u32 ctr_get_free_space(void)
|
||||
{
|
||||
u32 app_memory = *((u32*)0x1FF80040);
|
||||
s64 mem_used;
|
||||
u32 app_memory = *((u32*)0x1FF80040);
|
||||
svcGetSystemInfo(&mem_used, 0, 1);
|
||||
return app_memory - (u32)mem_used;
|
||||
}
|
||||
@ -117,22 +109,22 @@ void ctr_request_free_pages(u32 pages)
|
||||
|
||||
void* _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
|
||||
{
|
||||
static u32 sbrk_top = 0;
|
||||
static u32 sbrk_top = 0;
|
||||
|
||||
if (!sbrk_top)
|
||||
if (!sbrk_top)
|
||||
sbrk_top = __heapBase;
|
||||
|
||||
u32 tmp;
|
||||
|
||||
int diff = ((sbrk_top + incr + 0xFFF) & ~0xFFF)
|
||||
- (__heapBase + __heap_size);
|
||||
- (__heapBase + __heap_size);
|
||||
|
||||
if (diff > 0)
|
||||
{
|
||||
ctr_request_free_pages(diff >> 12);
|
||||
|
||||
if (svcControlMemory(&tmp, __heapBase + __heap_size,
|
||||
0x0, diff, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE) < 0)
|
||||
0x0, diff, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE) < 0)
|
||||
{
|
||||
ptr->_errno = ENOMEM;
|
||||
return (caddr_t) -1;
|
||||
@ -143,9 +135,9 @@ void* _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
|
||||
|
||||
if (diff < 0)
|
||||
svcControlMemory(&tmp, __heapBase + __heap_size,
|
||||
0x0, -diff, MEMOP_FREE, MEMPERM_READ | MEMPERM_WRITE);
|
||||
0x0, -diff, MEMOP_FREE, MEMPERM_READ | MEMPERM_WRITE);
|
||||
|
||||
sbrk_top += incr;
|
||||
sbrk_top += incr;
|
||||
|
||||
return (caddr_t)(sbrk_top - incr);
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
#include <3ds.h>
|
||||
#include <sys/iosupport.h>
|
||||
#include <stdio.h>
|
||||
@ -17,6 +16,9 @@ u32 __heap_size;
|
||||
u32 __linear_heap;
|
||||
u32 __heapBase;
|
||||
|
||||
u32 __stack_bottom;
|
||||
u32 __stack_size_extra;
|
||||
|
||||
extern u32 __linear_heap_size_hbl;
|
||||
extern u32 __heap_size_hbl;
|
||||
|
||||
@ -26,11 +28,9 @@ void envDestroyHandles(void);
|
||||
void __appExit();
|
||||
void __libc_fini_array(void);
|
||||
|
||||
void __libctru_init(void (*retAddr)(void));
|
||||
void __appInit();
|
||||
void __libc_init_array(void);
|
||||
void __system_initSyscalls(void);
|
||||
void __system_allocateHeaps();
|
||||
void __system_initArgv();
|
||||
|
||||
void __ctru_exit(int rc);
|
||||
@ -38,31 +38,11 @@ int __libctru_gtod(struct _reent* ptr, struct timeval* tp, struct timezone* tz);
|
||||
void (*__system_retAddr)(void);
|
||||
extern void* __service_ptr;
|
||||
|
||||
u32 __stack_bottom;
|
||||
u32 __stack_size_extra;
|
||||
|
||||
Result __sync_init(void) __attribute__((weak));
|
||||
|
||||
void __attribute__((weak)) __libctru_init(void (*retAddr)(void))
|
||||
{
|
||||
// Store the return address
|
||||
__system_retAddr = envIsHomebrew() ? retAddr : NULL;
|
||||
|
||||
// Initialize the synchronization subsystem
|
||||
__sync_init();
|
||||
|
||||
// Initialize newlib support system calls
|
||||
__system_initSyscalls();
|
||||
|
||||
// Allocate application and linear heaps
|
||||
__system_allocateHeaps();
|
||||
|
||||
// Build argc/argv if present
|
||||
__system_initArgv();
|
||||
|
||||
}
|
||||
void __system_allocateHeaps()
|
||||
void __system_allocateHeaps(void)
|
||||
{
|
||||
extern char* fake_heap_end;
|
||||
u32 tmp = 0;
|
||||
|
||||
MemInfo stack_memInfo;
|
||||
@ -72,10 +52,10 @@ void __system_allocateHeaps()
|
||||
|
||||
svcQueryMemory(&stack_memInfo, &stack_pageInfo, sp_val);
|
||||
|
||||
__stacksize__ += 0xFFF;
|
||||
__stacksize__ &= ~0xFFF;
|
||||
__stack_size_extra = __stacksize__ > stack_memInfo.size ? __stacksize__ - stack_memInfo.size : 0;
|
||||
__stack_bottom = stack_memInfo.base_addr - __stack_size_extra;
|
||||
__stacksize__ += 0xFFF;
|
||||
__stacksize__ &= ~0xFFF;
|
||||
__stack_size_extra = __stacksize__ > stack_memInfo.size ? __stacksize__ - stack_memInfo.size : 0;
|
||||
__stack_bottom = stack_memInfo.base_addr - __stack_size_extra;
|
||||
|
||||
if (__stack_size_extra)
|
||||
{
|
||||
@ -83,21 +63,40 @@ void __system_allocateHeaps()
|
||||
memset((void*)__stack_bottom, 0xFC, __stack_size_extra);
|
||||
}
|
||||
|
||||
// setup the application heap
|
||||
__heapBase = 0x08000000;
|
||||
/* setup the application heap */
|
||||
__heapBase = 0x08000000;
|
||||
__heap_size = 0;
|
||||
|
||||
// Allocate the linear heap
|
||||
/* Allocate the linear heap */
|
||||
svcControlMemory(&__linear_heap, 0x0, 0x0, __linear_heap_size, MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
|
||||
// Set up newlib heap
|
||||
extern char* fake_heap_end;
|
||||
fake_heap_end = (char*)0x13F00000;
|
||||
|
||||
/* Set up newlib heap */
|
||||
fake_heap_end = (char*)0x13F00000;
|
||||
}
|
||||
|
||||
void __attribute__((weak)) __libctru_init(void (*retAddr)(void))
|
||||
{
|
||||
/* Store the return address */
|
||||
__system_retAddr = envIsHomebrew() ? retAddr : NULL;
|
||||
|
||||
/* Initialize the synchronization subsystem */
|
||||
__sync_init();
|
||||
|
||||
/* Initialize newlib support system calls */
|
||||
__system_initSyscalls();
|
||||
|
||||
/* Allocate application and linear heaps */
|
||||
__system_allocateHeaps();
|
||||
|
||||
/* Build argc/argv if present */
|
||||
__system_initArgv();
|
||||
}
|
||||
|
||||
|
||||
Result __sync_fini(void) __attribute__((weak));
|
||||
|
||||
extern char** __system_argv;
|
||||
|
||||
void __attribute__((noreturn)) __libctru_exit(int rc)
|
||||
{
|
||||
u32 tmp = 0;
|
||||
@ -105,26 +104,26 @@ void __attribute__((noreturn)) __libctru_exit(int rc)
|
||||
if (__system_argv)
|
||||
free(__system_argv);
|
||||
|
||||
// Unmap the linear heap
|
||||
/* Unmap the linear heap */
|
||||
svcControlMemory(&tmp, __linear_heap, 0x0, __linear_heap_size, MEMOP_FREE, 0x0);
|
||||
|
||||
// Unmap the application heap
|
||||
/* Unmap the application heap */
|
||||
svcControlMemory(&tmp, __heapBase, 0x0, __heap_size, MEMOP_FREE, 0x0);
|
||||
|
||||
if (__stack_size_extra)
|
||||
svcControlMemory(&tmp, __stack_bottom, 0x0, __stack_size_extra, MEMOP_FREE, 0x0);
|
||||
|
||||
// Close some handles
|
||||
/* Close some handles */
|
||||
envDestroyHandles();
|
||||
|
||||
if (__sync_fini)
|
||||
__sync_fini();
|
||||
|
||||
// Jump to the loader if it provided a callback
|
||||
/* Jump to the loader if it provided a callback */
|
||||
if (__system_retAddr)
|
||||
__system_retAddr();
|
||||
|
||||
// Since above did not jump, end this process
|
||||
/* Since above did not jump, end this process */
|
||||
svcExitProcess();
|
||||
}
|
||||
|
||||
@ -132,18 +131,18 @@ void __attribute__((noreturn)) __libctru_exit(int rc)
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// System globals we define here
|
||||
/* System globals we define here */
|
||||
int __system_argc;
|
||||
char** __system_argv;
|
||||
extern const char* __system_arglist;
|
||||
|
||||
void __system_initArgv()
|
||||
void __system_initArgv(void)
|
||||
{
|
||||
int i;
|
||||
struct
|
||||
{
|
||||
u32 argc;
|
||||
char args[];
|
||||
u32 argc;
|
||||
char args[];
|
||||
}*arg_struct = (void*)__system_arglist;
|
||||
|
||||
__system_argc = 0;
|
||||
@ -163,7 +162,7 @@ void __system_initArgv()
|
||||
while (i)
|
||||
{
|
||||
if(__system_argv[i] && isalnum(__system_argv[i][0])
|
||||
&& strncmp(__system_argv[i], "3dslink:/", 9))
|
||||
&& strncmp(__system_argv[i], "3dslink:/", 9))
|
||||
{
|
||||
__system_argv[1] = __system_argv[i];
|
||||
__system_argc = 2;
|
||||
@ -253,8 +252,8 @@ long sysconf(int name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case _SC_NPROCESSORS_ONLN:
|
||||
return 2;
|
||||
case _SC_NPROCESSORS_ONLN:
|
||||
return 2;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user