(Wii) Code style cleanups

This commit is contained in:
twinaphex 2012-12-18 08:42:53 +01:00
parent 5cd6017ff5
commit 0ff8dba2c3
4 changed files with 40 additions and 67 deletions

View File

@ -1,17 +1,8 @@
#ifndef _DOLLOADER_H_
#define _DOLLOADER_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*entrypoint) (void);
u32 load_dol_image(const void *dolstart);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -27,20 +27,20 @@
* ====================================================================== */
s32 valid_elf_image (void *addr)
{
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
ehdr = (Elf32_Ehdr *) addr;
ehdr = (Elf32_Ehdr *) addr;
if (!IS_ELF (*ehdr))
return 0;
if (!IS_ELF (*ehdr))
return 0;
if (ehdr->e_type != ET_EXEC)
return -1;
if (ehdr->e_type != ET_EXEC)
return -1;
if (ehdr->e_machine != EM_PPC)
return -1;
if (ehdr->e_machine != EM_PPC)
return -1;
return 1;
return 1;
}
@ -50,43 +50,43 @@ s32 valid_elf_image (void *addr)
* ====================================================================== */
u32 load_elf_image (void *elfstart) {
Elf32_Ehdr *ehdr;
Elf32_Phdr *phdrs;
u8 *image;
int i;
Elf32_Ehdr *ehdr;
Elf32_Phdr *phdrs;
u8 *image;
int i;
ehdr = (Elf32_Ehdr *) elfstart;
ehdr = (Elf32_Ehdr *) elfstart;
if(ehdr->e_phoff == 0 || ehdr->e_phnum == 0)
return 0;
if(ehdr->e_phoff == 0 || ehdr->e_phnum == 0)
return 0;
if(ehdr->e_phentsize != sizeof(Elf32_Phdr))
return 0;
if(ehdr->e_phentsize != sizeof(Elf32_Phdr))
return 0;
phdrs = (Elf32_Phdr*)(elfstart + ehdr->e_phoff);
phdrs = (Elf32_Phdr*)(elfstart + ehdr->e_phoff);
for(i=0;i<ehdr->e_phnum;i++) {
for(i=0;i<ehdr->e_phnum;i++) {
if(phdrs[i].p_type != PT_LOAD)
continue;
if(phdrs[i].p_type != PT_LOAD)
continue;
phdrs[i].p_paddr &= 0x3FFFFFFF;
phdrs[i].p_paddr |= 0x80000000;
phdrs[i].p_paddr &= 0x3FFFFFFF;
phdrs[i].p_paddr |= 0x80000000;
if(phdrs[i].p_filesz > phdrs[i].p_memsz)
return 0;
if(phdrs[i].p_filesz > phdrs[i].p_memsz)
return 0;
if(!phdrs[i].p_filesz)
continue;
if(!phdrs[i].p_filesz)
continue;
image = (u8 *) (elfstart + phdrs[i].p_offset);
memcpy ((void *) phdrs[i].p_paddr, (const void *) image, phdrs[i].p_filesz);
image = (u8 *) (elfstart + phdrs[i].p_offset);
memcpy ((void *) phdrs[i].p_paddr, (const void *) image, phdrs[i].p_filesz);
sync_before_exec ((void *) phdrs[i].p_paddr, phdrs[i].p_memsz);
sync_before_exec ((void *) phdrs[i].p_paddr, phdrs[i].p_memsz);
//if(phdrs[i].p_flags & PF_X)
//ICInvalidateRange ((void *) phdrs[i].p_paddr, phdrs[i].p_memsz);
}
//if(phdrs[i].p_flags & PF_X)
//ICInvalidateRange ((void *) phdrs[i].p_paddr, phdrs[i].p_memsz);
}
return ((ehdr->e_entry & 0x3FFFFFFF) | 0x80000000);
return ((ehdr->e_entry & 0x3FFFFFFF) | 0x80000000);
}

View File

@ -1,16 +1,7 @@
#ifndef _ELFLOADER_H_
#define _ELFLOADER_H_
#ifdef __cplusplus
extern "C"
{
#endif
s32 valid_elf_image (void *addr);
u32 load_elf_image (void *addr);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -16,28 +16,28 @@ u32 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, u32 offset)
{
return (heap_block *) ((char *) block + offset);
}
static __inline__ heap_block *__lwp_heap_usrblockat(void *ptr)
static inline heap_block *__lwp_heap_usrblockat(void *ptr)
{
u32 offset = *(((u32 *) ptr) - 1);
return __lwp_heap_blockat(ptr, -offset + -HEAP_BLOCK_USED_OVERHEAD);
}
static __inline__ bool __lwp_heap_blockin(heap_cntrl *heap, heap_block *block)
static inline bool __lwp_heap_blockin(heap_cntrl *heap, heap_block *block)
{
return ((u32) block >= (u32) heap->start && (u32) block <= (u32) heap->final);
}
static __inline__ bool __lwp_heap_blockfree(heap_block *block)
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 u32 __lwp_heap_blocksize(heap_block *block)
{
return (block->front_flag & ~HEAP_BLOCK_USED);
}
@ -197,11 +197,6 @@ u32 gx_mem2_total()
return info.used_size + info.free_size;
}
#ifdef __cplusplus
extern "C"
{
#endif
void *__real_malloc(size_t size);
void *__real_calloc(size_t n, size_t size);
void *__real_memalign(size_t a, size_t size);
@ -304,7 +299,3 @@ __attribute__ ((used)) size_t __wrap_malloc_usable_size(void *p)
return __lwp_heap_block_size(&gx_mem2_heap, p);
return __real_malloc_usable_size(p);
}
#ifdef __cplusplus
}
#endif