Initial commit
This commit is contained in:
3
wiipax/stub/.gitignore
vendored
Normal file
3
wiipax/stub/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
stub_*.elf
|
||||
stub_*.c
|
||||
|
||||
1006
wiipax/stub/LzmaDec.c
Normal file
1006
wiipax/stub/LzmaDec.c
Normal file
File diff suppressed because it is too large
Load Diff
223
wiipax/stub/LzmaDec.h
Normal file
223
wiipax/stub/LzmaDec.h
Normal file
@@ -0,0 +1,223 @@
|
||||
/* LzmaDec.h -- LZMA Decoder
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZMADEC_H
|
||||
#define __LZMADEC_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/* #define _LZMA_PROB32 */
|
||||
/* _LZMA_PROB32 can increase the speed on some CPUs,
|
||||
but memory usage for CLzmaDec::probs will be doubled in that case */
|
||||
|
||||
#ifdef _LZMA_PROB32
|
||||
#define CLzmaProb UInt32
|
||||
#else
|
||||
#define CLzmaProb UInt16
|
||||
#endif
|
||||
|
||||
|
||||
/* ---------- LZMA Properties ---------- */
|
||||
|
||||
#define LZMA_PROPS_SIZE 5
|
||||
|
||||
typedef struct _CLzmaProps
|
||||
{
|
||||
unsigned lc, lp, pb;
|
||||
UInt32 dicSize;
|
||||
} CLzmaProps;
|
||||
|
||||
/* LzmaProps_Decode - decodes properties
|
||||
Returns:
|
||||
SZ_OK
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
*/
|
||||
|
||||
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
|
||||
|
||||
|
||||
/* ---------- LZMA Decoder state ---------- */
|
||||
|
||||
/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
|
||||
Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
|
||||
|
||||
#define LZMA_REQUIRED_INPUT_MAX 20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CLzmaProps prop;
|
||||
CLzmaProb *probs;
|
||||
Byte *dic;
|
||||
const Byte *buf;
|
||||
UInt32 range, code;
|
||||
SizeT dicPos;
|
||||
SizeT dicBufSize;
|
||||
UInt32 processedPos;
|
||||
UInt32 checkDicSize;
|
||||
unsigned state;
|
||||
UInt32 reps[4];
|
||||
unsigned remainLen;
|
||||
int needFlush;
|
||||
int needInitState;
|
||||
UInt32 numProbs;
|
||||
unsigned tempBufSize;
|
||||
Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
|
||||
} CLzmaDec;
|
||||
|
||||
#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
|
||||
|
||||
void LzmaDec_Init(CLzmaDec *p);
|
||||
|
||||
/* There are two types of LZMA streams:
|
||||
0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
|
||||
1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA_FINISH_ANY, /* finish at any point */
|
||||
LZMA_FINISH_END /* block must be finished at the end */
|
||||
} ELzmaFinishMode;
|
||||
|
||||
/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
|
||||
|
||||
You must use LZMA_FINISH_END, when you know that current output buffer
|
||||
covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
|
||||
|
||||
If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
|
||||
and output value of destLen will be less than output buffer size limit.
|
||||
You can check status result also.
|
||||
|
||||
You can use multiple checks to test data integrity after full decompression:
|
||||
1) Check Result and "status" variable.
|
||||
2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
|
||||
3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
|
||||
You must use correct finish mode in that case. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
|
||||
LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
|
||||
LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
|
||||
LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
|
||||
} ELzmaStatus;
|
||||
|
||||
/* ELzmaStatus is used only as output value for function call */
|
||||
|
||||
|
||||
/* ---------- Interfaces ---------- */
|
||||
|
||||
/* There are 3 levels of interfaces:
|
||||
1) Dictionary Interface
|
||||
2) Buffer Interface
|
||||
3) One Call Interface
|
||||
You can select any of these interfaces, but don't mix functions from different
|
||||
groups for same object. */
|
||||
|
||||
|
||||
/* There are two variants to allocate state for Dictionary Interface:
|
||||
1) LzmaDec_Allocate / LzmaDec_Free
|
||||
2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
|
||||
You can use variant 2, if you set dictionary buffer manually.
|
||||
For Buffer Interface you must always use variant 1.
|
||||
|
||||
LzmaDec_Allocate* can return:
|
||||
SZ_OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
*/
|
||||
|
||||
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
|
||||
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
|
||||
|
||||
SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
|
||||
void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
|
||||
|
||||
/* ---------- Dictionary Interface ---------- */
|
||||
|
||||
/* You can use it, if you want to eliminate the overhead for data copying from
|
||||
dictionary to some other external buffer.
|
||||
You must work with CLzmaDec variables directly in this interface.
|
||||
|
||||
STEPS:
|
||||
LzmaDec_Constr()
|
||||
LzmaDec_Allocate()
|
||||
for (each new stream)
|
||||
{
|
||||
LzmaDec_Init()
|
||||
while (it needs more decompression)
|
||||
{
|
||||
LzmaDec_DecodeToDic()
|
||||
use data from CLzmaDec::dic and update CLzmaDec::dicPos
|
||||
}
|
||||
}
|
||||
LzmaDec_Free()
|
||||
*/
|
||||
|
||||
/* LzmaDec_DecodeToDic
|
||||
|
||||
The decoding to internal dictionary buffer (CLzmaDec::dic).
|
||||
You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (dicLimit).
|
||||
LZMA_FINISH_ANY - Decode just dicLimit bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after dicLimit.
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_NEEDS_MORE_INPUT
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
*/
|
||||
|
||||
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
|
||||
|
||||
|
||||
/* ---------- Buffer Interface ---------- */
|
||||
|
||||
/* It's zlib-like interface.
|
||||
See LzmaDec_DecodeToDic description for information about STEPS and return results,
|
||||
but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
|
||||
to work with CLzmaDec variables manually.
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
*/
|
||||
|
||||
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
|
||||
|
||||
|
||||
/* ---------- One Call Interface ---------- */
|
||||
|
||||
/* LzmaDecode
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
|
||||
*/
|
||||
|
||||
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
|
||||
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
|
||||
ELzmaStatus *status, ISzAlloc *alloc);
|
||||
|
||||
#endif
|
||||
66
wiipax/stub/Makefile
Normal file
66
wiipax/stub/Makefile
Normal file
@@ -0,0 +1,66 @@
|
||||
include ../../broadway.mk
|
||||
|
||||
CFLAGS += -mno-eabi -mno-sdata -O2 -ffreestanding
|
||||
CFLAGS += -Wall -Wextra
|
||||
DEFINES =
|
||||
LDFLAGS += -nostartfiles -nodefaultlibs
|
||||
|
||||
OBJS_COMMON = crt0.o main.o string.o sync.o elf.o time.o LzmaDec.o
|
||||
TARGET_ID =
|
||||
|
||||
ifeq ($(DEVKITFAIL),1)
|
||||
DEFINES += -DDEVKITFAIL
|
||||
OBJS = $(OBJS_COMMON)
|
||||
LDSCRIPT = devkitfail.ld
|
||||
TARGET_ID = _dkf
|
||||
else
|
||||
ifeq ($(DKFAILCHANNEL),1)
|
||||
DEFINES += -DDEVKITFAIL
|
||||
OBJS = realmode.o $(OBJS_COMMON)
|
||||
LDSCRIPT = channel.ld
|
||||
TARGET_ID = _dkfc
|
||||
else
|
||||
OBJS = realmode.o plunge.o $(OBJS_COMMON)
|
||||
LDSCRIPT = realmode.ld
|
||||
TARGET_ID = _mini
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(NDEBUG),1)
|
||||
DEFINES += -DNDEBUG
|
||||
TARGET_DEBUG =
|
||||
else
|
||||
OBJS += exception.o exception_asm.o vsprintf.o gecko.o
|
||||
TARGET_DEBUG = _debug
|
||||
endif
|
||||
|
||||
TARGET = stub$(TARGET_ID)$(TARGET_DEBUG).elf
|
||||
|
||||
include ../../common.mk
|
||||
|
||||
all: xxd
|
||||
|
||||
xxd: $(TARGET)
|
||||
@echo " XXD $^"
|
||||
@xxd -i $(TARGET) > $(subst .elf,.c,$(TARGET))
|
||||
|
||||
distclean: clean
|
||||
rm -f stub_*.elf stub_*.c
|
||||
|
||||
release:
|
||||
$(Q)$(MAKE) clean
|
||||
$(Q)$(MAKE)
|
||||
$(Q)$(MAKE) clean
|
||||
$(Q)$(MAKE) NDEBUG=1
|
||||
$(Q)$(MAKE) NDEBUG=1 clean
|
||||
$(Q)$(MAKE) DEVKITFAIL=1
|
||||
$(Q)$(MAKE) DEVKITFAIL=1 clean
|
||||
$(Q)$(MAKE) DEVKITFAIL=1 NDEBUG=1
|
||||
$(Q)$(MAKE) DEVKITFAIL=1 NDEBUG=1 clean
|
||||
$(Q)$(MAKE) DKFAILCHANNEL=1
|
||||
$(Q)$(MAKE) DKFAILCHANNEL=1 clean
|
||||
$(Q)$(MAKE) DKFAILCHANNEL=1 NDEBUG=1
|
||||
$(Q)$(MAKE) DKFAILCHANNEL=1 NDEBUG=1 clean
|
||||
|
||||
.PHONY: release
|
||||
|
||||
208
wiipax/stub/Types.h
Normal file
208
wiipax/stub/Types.h
Normal file
@@ -0,0 +1,208 @@
|
||||
/* Types.h -- Basic types
|
||||
2008-11-23 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_TYPES_H
|
||||
#define __7Z_TYPES_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define SZ_OK 0
|
||||
|
||||
#define SZ_ERROR_DATA 1
|
||||
#define SZ_ERROR_MEM 2
|
||||
#define SZ_ERROR_CRC 3
|
||||
#define SZ_ERROR_UNSUPPORTED 4
|
||||
#define SZ_ERROR_PARAM 5
|
||||
#define SZ_ERROR_INPUT_EOF 6
|
||||
#define SZ_ERROR_OUTPUT_EOF 7
|
||||
#define SZ_ERROR_READ 8
|
||||
#define SZ_ERROR_WRITE 9
|
||||
#define SZ_ERROR_PROGRESS 10
|
||||
#define SZ_ERROR_FAIL 11
|
||||
#define SZ_ERROR_THREAD 12
|
||||
|
||||
#define SZ_ERROR_ARCHIVE 16
|
||||
#define SZ_ERROR_NO_ARCHIVE 17
|
||||
|
||||
typedef int SRes;
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef DWORD WRes;
|
||||
#else
|
||||
typedef int WRes;
|
||||
#endif
|
||||
|
||||
#ifndef RINOK
|
||||
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
|
||||
#endif
|
||||
|
||||
typedef unsigned char Byte;
|
||||
typedef short Int16;
|
||||
typedef unsigned short UInt16;
|
||||
|
||||
#ifdef _LZMA_UINT32_IS_ULONG
|
||||
typedef long Int32;
|
||||
typedef unsigned long UInt32;
|
||||
#else
|
||||
typedef int Int32;
|
||||
typedef unsigned int UInt32;
|
||||
#endif
|
||||
|
||||
#ifdef _SZ_NO_INT_64
|
||||
|
||||
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
|
||||
NOTES: Some code will work incorrectly in that case! */
|
||||
|
||||
typedef long Int64;
|
||||
typedef unsigned long UInt64;
|
||||
|
||||
#else
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 Int64;
|
||||
typedef unsigned __int64 UInt64;
|
||||
#else
|
||||
typedef long long int Int64;
|
||||
typedef unsigned long long int UInt64;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _LZMA_NO_SYSTEM_SIZE_T
|
||||
typedef UInt32 SizeT;
|
||||
#else
|
||||
typedef size_t SizeT;
|
||||
#endif
|
||||
|
||||
typedef int Bool;
|
||||
#define True 1
|
||||
#define False 0
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#if _MSC_VER >= 1300
|
||||
#define MY_NO_INLINE __declspec(noinline)
|
||||
#else
|
||||
#define MY_NO_INLINE
|
||||
#endif
|
||||
|
||||
#define MY_CDECL __cdecl
|
||||
#define MY_STD_CALL __stdcall
|
||||
#define MY_FAST_CALL MY_NO_INLINE __fastcall
|
||||
|
||||
#else
|
||||
|
||||
#define MY_CDECL
|
||||
#define MY_STD_CALL
|
||||
#define MY_FAST_CALL
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* The following interfaces use first parameter as pointer to structure */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Read)(void *p, void *buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
} ISeqInStream;
|
||||
|
||||
/* it can return SZ_ERROR_INPUT_EOF */
|
||||
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
|
||||
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
|
||||
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t (*Write)(void *p, const void *buf, size_t size);
|
||||
/* Returns: result - the number of actually written bytes.
|
||||
(result < size) means error */
|
||||
} ISeqOutStream;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SZ_SEEK_SET = 0,
|
||||
SZ_SEEK_CUR = 1,
|
||||
SZ_SEEK_END = 2
|
||||
} ESzSeek;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
|
||||
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||
} ISeekInStream;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Look)(void *p, void **buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) > input(*size)) is not allowed
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
SRes (*Skip)(void *p, size_t offset);
|
||||
/* offset must be <= output(*size) of Look */
|
||||
|
||||
SRes (*Read)(void *p, void *buf, size_t *size);
|
||||
/* reads directly (without buffer). It's same as ISeqInStream::Read */
|
||||
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||
} ILookInStream;
|
||||
|
||||
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
|
||||
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
|
||||
|
||||
/* reads via ILookInStream::Read */
|
||||
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
|
||||
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
|
||||
|
||||
#define LookToRead_BUF_SIZE (1 << 14)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ILookInStream s;
|
||||
ISeekInStream *realStream;
|
||||
size_t pos;
|
||||
size_t size;
|
||||
Byte buf[LookToRead_BUF_SIZE];
|
||||
} CLookToRead;
|
||||
|
||||
void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
|
||||
void LookToRead_Init(CLookToRead *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
ILookInStream *realStream;
|
||||
} CSecToLook;
|
||||
|
||||
void SecToLook_CreateVTable(CSecToLook *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
ILookInStream *realStream;
|
||||
} CSecToRead;
|
||||
|
||||
void SecToRead_CreateVTable(CSecToRead *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||
/* Returns: result. (result != SZ_OK) means break.
|
||||
Value (UInt64)(Int64)-1 for size means unknown value. */
|
||||
} ICompressProgress;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *(*Alloc)(void *p, size_t size);
|
||||
void (*Free)(void *p, void *address); /* address can be 0 */
|
||||
} ISzAlloc;
|
||||
|
||||
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
|
||||
#define IAlloc_Free(p, a) (p)->Free((p), a)
|
||||
|
||||
#endif
|
||||
64
wiipax/stub/channel.ld
Normal file
64
wiipax/stub/channel.ld
Normal file
@@ -0,0 +1,64 @@
|
||||
OUTPUT_FORMAT("elf32-powerpc")
|
||||
OUTPUT_ARCH(powerpc:common)
|
||||
|
||||
__mem1_start = 0x80004000;
|
||||
__mem2_start = 0x90010000;
|
||||
|
||||
__mem1_entry = _start - __mem2_start + __mem1_start;
|
||||
ENTRY(__mem1_entry)
|
||||
|
||||
PHDRS {
|
||||
realmode PT_LOAD FLAGS(5);
|
||||
paxx PT_LOAD FLAGS(7);
|
||||
}
|
||||
|
||||
SECTIONS {
|
||||
. = 0x80003400;
|
||||
|
||||
.realmode : { KEEP(*(.realmode)) } :realmode = 0
|
||||
|
||||
. = __mem2_start;
|
||||
|
||||
.start : AT(__mem1_start) { KEEP(*(.start)) } :paxx = 0
|
||||
.text : { *(.text) *(.text.*) }
|
||||
|
||||
. = ALIGN(4);
|
||||
|
||||
.payload : {
|
||||
__payload = .;
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
}
|
||||
|
||||
.rodata : { *(.rodata) *(.rodata.*) }
|
||||
|
||||
. = (( . +19)&0xFFFFFFF0) - 4;
|
||||
.padding : {
|
||||
LONG(0xdeadbeef);
|
||||
}
|
||||
|
||||
.sdata : { *(.sdata) *(.sdata.*) }
|
||||
.data : { *(.data) *(.data.*) }
|
||||
|
||||
. = ALIGN(32);
|
||||
__self_end = .;
|
||||
|
||||
__bss_start = .;
|
||||
.bss : { *(.bss) } :NONE = 0
|
||||
.sbss : { *(.sbss) }
|
||||
__bss_end = .;
|
||||
|
||||
. = ALIGN(32);
|
||||
|
||||
.stack : {
|
||||
_stack_top = .;
|
||||
. += 32768;
|
||||
_stack_bot = .;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
107
wiipax/stub/common.h
Normal file
107
wiipax/stub/common.h
Normal file
@@ -0,0 +1,107 @@
|
||||
#ifndef _LOADER_H_
|
||||
#define _LOADER_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
// Basic types.
|
||||
|
||||
typedef unsigned char u8;
|
||||
typedef signed char s8;
|
||||
typedef unsigned short int u16;
|
||||
typedef signed short int s16;
|
||||
typedef unsigned int u32;
|
||||
typedef signed int s32;
|
||||
|
||||
// Basic I/O.
|
||||
|
||||
static inline u32 read32(u32 addr) {
|
||||
u32 x;
|
||||
|
||||
asm volatile("lwz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void write32(u32 addr, u32 x) {
|
||||
asm("stw %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
|
||||
}
|
||||
|
||||
static inline u16 read16(u32 addr) {
|
||||
u16 x;
|
||||
|
||||
asm volatile("lhz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline u8 read8(u32 addr) {
|
||||
u8 x;
|
||||
|
||||
asm volatile("lbz %0,0(%1) ; sync" : "=r"(x) : "b"(0xc0000000 | addr));
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void write16(u32 addr, u16 x) {
|
||||
asm("sth %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
|
||||
}
|
||||
|
||||
static inline void write8(u32 addr, u8 x) {
|
||||
asm("stb %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr));
|
||||
}
|
||||
|
||||
static inline void mask32(u32 addr, u32 clear, u32 set)
|
||||
{
|
||||
write32(addr, (read32(addr)&(~clear)) | set);
|
||||
}
|
||||
|
||||
// Address mapping.
|
||||
|
||||
static inline u32 virt_to_phys(const void *p) {
|
||||
return (u32)p & 0x7fffffff;
|
||||
}
|
||||
|
||||
static inline void *phys_to_virt(u32 x) {
|
||||
return (void *)(x | 0x80000000);
|
||||
}
|
||||
|
||||
|
||||
// Cache synchronisation.
|
||||
|
||||
void sync_before_read(void *p, u32 len);
|
||||
void sync_after_write(const void *p, u32 len);
|
||||
void sync_before_exec(const void *p, u32 len);
|
||||
|
||||
|
||||
// Time.
|
||||
|
||||
void udelay(u32 us);
|
||||
|
||||
|
||||
// Special purpose registers.
|
||||
|
||||
#define mtspr(n, x) do { asm("mtspr %1,%0" : : "r"(x), "i"(n)); } while (0)
|
||||
#define mfspr(n) ({ \
|
||||
u32 x; asm volatile("mfspr %0,%1" : "=r"(x) : "i"(n)); x; \
|
||||
})
|
||||
|
||||
|
||||
// Exceptions.
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define printf(...) { }
|
||||
#else
|
||||
void exception_init(void);
|
||||
void gecko_init(void);
|
||||
int printf(const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
|
||||
// Debug: blink the tray led.
|
||||
|
||||
static inline void blink(void) {
|
||||
write32(0x0d8000c0, read32(0x0d8000c0) ^ 0x20);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
330
wiipax/stub/crt0.s
Normal file
330
wiipax/stub/crt0.s
Normal file
@@ -0,0 +1,330 @@
|
||||
# crt0.s file for the GameCube V1.0 by Costis (costis@gbaemu.com)!
|
||||
|
||||
.text
|
||||
.section .start,"ax",@progbits
|
||||
.extern _start
|
||||
.align 2
|
||||
.globl _start
|
||||
_start:
|
||||
|
||||
lis 3,__mem1_start@h
|
||||
ori 3,3,__mem1_start@l
|
||||
lis 4,__mem2_start@h
|
||||
ori 4,4,__mem2_start@l
|
||||
lis 5,__self_end@h
|
||||
ori 5,5,__self_end@l
|
||||
|
||||
_reloc_loop:
|
||||
lwz 2,0(3)
|
||||
stw 2,0(4)
|
||||
|
||||
addi 3,3,4
|
||||
addi 4,4,4
|
||||
cmplw 4,5
|
||||
blt _reloc_loop
|
||||
|
||||
lis 4,__mem2_start@h
|
||||
ori 4,4,__mem2_start@l
|
||||
_flush_loop:
|
||||
dcbst 0,4
|
||||
sync
|
||||
icbi 0,4
|
||||
addi 4,4,32
|
||||
cmplw 4,5
|
||||
blt _flush_loop
|
||||
|
||||
sync
|
||||
isync
|
||||
|
||||
lis 3,_mem2_entry@h
|
||||
ori 3,3,_mem2_entry@l
|
||||
mtctr 3
|
||||
bctr
|
||||
|
||||
_mem2_entry:
|
||||
# Clear all GPRs except
|
||||
.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
|
||||
li \i,0
|
||||
.endr
|
||||
|
||||
lis 1,_stack_bot@h
|
||||
ori 1,1,_stack_bot@l
|
||||
stwu 0,-64(1)
|
||||
|
||||
lis 2,0x8000
|
||||
stw 1,0x34(2) # write sp
|
||||
# lis 13,_SDA_BASE_@h
|
||||
# ori 13,13,_SDA_BASE_@l # Set the Small Data (Read\Write) base register.
|
||||
|
||||
bl InitHardware # Initialize the GameCube Hardware (Floating Point Registers, Caches, etc.)
|
||||
bl SystemInit # Initialize more cache aspects, clear a few SPR's, and disable interrupts.
|
||||
|
||||
# clear BSS
|
||||
lis 3, __bss_start@h
|
||||
ori 3, 3, __bss_start@l
|
||||
li 4, 0
|
||||
lis 5, __bss_end@h
|
||||
ori 5, 5, __bss_end@l
|
||||
sub 5, 5, 3
|
||||
|
||||
bl memset
|
||||
|
||||
mr 3, 28
|
||||
bl stubmain # Branch to the user code!
|
||||
|
||||
b .
|
||||
|
||||
InitHardware:
|
||||
mflr 31 # Store the link register in r31
|
||||
|
||||
bl PSInit # Initialize Paired Singles
|
||||
bl FPRInit # Initialize the FPR's
|
||||
bl CacheInit # Initialize the system caches
|
||||
|
||||
mtlr 31 # Retreive the link register from r31
|
||||
blr
|
||||
|
||||
PSInit:
|
||||
mfspr 3, 920 # (HID2)
|
||||
oris 3, 3, 0xA000
|
||||
mtspr 920, 3 # (HID2)
|
||||
|
||||
# Set the Instruction Cache invalidation bit in HID0
|
||||
mfspr 3,1008
|
||||
ori 3,3,0x0800
|
||||
mtspr 1008,3
|
||||
|
||||
sync
|
||||
|
||||
# Clear various Special Purpose Registers
|
||||
li 3,0
|
||||
mtspr 912,3
|
||||
mtspr 913,3
|
||||
mtspr 914,3
|
||||
mtspr 915,3
|
||||
mtspr 916,3
|
||||
mtspr 917,3
|
||||
mtspr 918,3
|
||||
mtspr 919,3
|
||||
|
||||
# Return
|
||||
blr
|
||||
|
||||
FPRInit:
|
||||
# Enable the Floating Point Registers
|
||||
mfmsr 3
|
||||
ori 3,3,0x2000
|
||||
mtmsr 3
|
||||
|
||||
# Clear all of the FPR's to 0
|
||||
lis 3, zfloat@h
|
||||
ori 3, 3, zfloat@l
|
||||
lfd 0, 0(3)
|
||||
fmr 1,0
|
||||
fmr 2,0
|
||||
fmr 3,0
|
||||
fmr 4,0
|
||||
fmr 5,0
|
||||
fmr 6,0
|
||||
fmr 7,0
|
||||
fmr 8,0
|
||||
fmr 9,0
|
||||
fmr 10,0
|
||||
fmr 11,0
|
||||
fmr 12,0
|
||||
fmr 13,0
|
||||
fmr 14,0
|
||||
fmr 15,0
|
||||
fmr 16,0
|
||||
fmr 17,0
|
||||
fmr 18,0
|
||||
fmr 19,0
|
||||
fmr 20,0
|
||||
fmr 21,0
|
||||
fmr 22,0
|
||||
fmr 23,0
|
||||
fmr 24,0
|
||||
fmr 25,0
|
||||
fmr 26,0
|
||||
fmr 27,0
|
||||
fmr 28,0
|
||||
fmr 29,0
|
||||
fmr 30,0
|
||||
fmr 31,0
|
||||
mtfsf 255,0
|
||||
|
||||
# Return
|
||||
blr
|
||||
|
||||
CacheInit:
|
||||
mflr 0
|
||||
stw 0, 4(1)
|
||||
stwu 1, -16(1)
|
||||
stw 31, 12(1)
|
||||
stw 30, 8(1)
|
||||
|
||||
mfspr 3,1008 # (HID0)
|
||||
rlwinm 0, 3, 0, 16, 16
|
||||
cmplwi 0, 0x0000 # Check if the Instruction Cache has been enabled or not.
|
||||
bne ICEnabled
|
||||
|
||||
# If not, then enable it.
|
||||
isync
|
||||
mfspr 3, 1008
|
||||
ori 3, 3, 0x8000
|
||||
mtspr 1008, 3
|
||||
|
||||
ICEnabled:
|
||||
mfspr 3, 1008 # bl PPCMfhid0
|
||||
rlwinm 0, 3, 0, 17, 17
|
||||
cmplwi 0, 0x0000 # Check if the Data Cache has been enabled or not.
|
||||
bne DCEnabled
|
||||
|
||||
# If not, then enable it.
|
||||
sync
|
||||
mfspr 3, 1008
|
||||
ori 3, 3, 0x4000
|
||||
mtspr 1008, 3
|
||||
|
||||
DCEnabled:
|
||||
|
||||
mfspr 3, 1017 # (L2CR)
|
||||
clrrwi 0, 3, 31 # Clear all of the bits except 31
|
||||
cmplwi 0, 0x0000
|
||||
bne L2GISkip # Skip the L2 Global Cache Invalidation process if it has already been done befor.
|
||||
|
||||
# Store the current state of the MSR in r30
|
||||
mfmsr 3
|
||||
mr 30,3
|
||||
|
||||
sync
|
||||
|
||||
# Enable Instruction and Data Address Translation
|
||||
li 3, 48
|
||||
mtmsr 3
|
||||
|
||||
sync
|
||||
sync
|
||||
|
||||
# Disable the L2 Global Cache.
|
||||
mfspr 3, 1017 # (L2CR
|
||||
clrlwi 3, 3, 1
|
||||
mtspr 1017, 3 # (L2CR)
|
||||
sync
|
||||
|
||||
# Invalidate the L2 Global Cache.
|
||||
bl L2GlobalInvalidate
|
||||
|
||||
# Restore the previous state of the MSR from r30
|
||||
mr 3, 30
|
||||
mtmsr 3
|
||||
|
||||
# Enable the L2 Global Cache and disable the L2 Data Only bit and the L2 Global Invalidate Bit.
|
||||
mfspr 3, 1017 # (L2CR)
|
||||
oris 0, 3, 0x8000
|
||||
rlwinm 3, 0, 0, 11, 9
|
||||
mtspr 1017, 3 # (L2CR)
|
||||
|
||||
|
||||
L2GISkip:
|
||||
# Restore the non-volatile registers to their previous values and return.
|
||||
lwz 0, 20(1)
|
||||
lwz 31, 12(1)
|
||||
lwz 30, 8(1)
|
||||
addi 1, 1, 16
|
||||
mtlr 0
|
||||
blr
|
||||
|
||||
L2GlobalInvalidate:
|
||||
mflr 0
|
||||
stw 0, 4(1)
|
||||
stwu 1, -16(1)
|
||||
stw 31, 12(1)
|
||||
sync
|
||||
|
||||
# Disable the L2 Cache.
|
||||
mfspr 3, 1017 # bl PPCMf1017
|
||||
clrlwi 3, 3, 1
|
||||
mtspr 1017, 3 # bl PPCMt1017
|
||||
|
||||
sync
|
||||
|
||||
# Initiate the L2 Cache Global Invalidation process.
|
||||
mfspr 3, 1017 # (L2CR)
|
||||
oris 3, 3, 0x0020
|
||||
mtspr 1017, 3 # (L2CR)
|
||||
|
||||
# Wait until the L2 Cache Global Invalidation has been completed.
|
||||
L2GICheckComplete:
|
||||
mfspr 3, 1017 # (L2CR)
|
||||
clrlwi 0, 3, 31
|
||||
cmplwi 0, 0x0000
|
||||
bne L2GICheckComplete
|
||||
|
||||
# Clear the L2 Data Only bit and the L2 Global Invalidate Bit.
|
||||
mfspr 3, 1017 # (L2CR)
|
||||
rlwinm 3, 3, 0, 11, 9
|
||||
mtspr 1017, 3 # (L2CR)
|
||||
|
||||
# Wait until the L2 Cache Global Invalidation status bit signifies that it is ready.
|
||||
L2GDICheckComplete:
|
||||
mfspr 3, 1017 # (L2CR)
|
||||
clrlwi 0, 3, 31
|
||||
cmplwi 0, 0x0000
|
||||
bne L2GDICheckComplete
|
||||
|
||||
# Restore the non-volatile registers to their previous values and return.
|
||||
lwz 0, 20(1)
|
||||
lwz 31, 12(1)
|
||||
addi 1, 1, 16
|
||||
mtlr 0
|
||||
blr
|
||||
|
||||
SystemInit:
|
||||
mflr 0
|
||||
stw 0, 4(1)
|
||||
stwu 1, -0x18(1)
|
||||
stw 31, 0x14(1)
|
||||
stw 30, 0x10(1)
|
||||
stw 29, 0xC(1)
|
||||
|
||||
# Disable interrupts!
|
||||
mfmsr 3
|
||||
rlwinm 4,3,0,17,15
|
||||
rlwinm 4,4,0,26,24
|
||||
mtmsr 4
|
||||
|
||||
# Clear various SPR's
|
||||
li 3,0
|
||||
mtspr 952, 3
|
||||
mtspr 956, 3
|
||||
mtspr 953, 3
|
||||
mtspr 954, 3
|
||||
mtspr 957, 3
|
||||
mtspr 958, 3
|
||||
|
||||
# Disable Speculative Bus Accesses to non-guarded space from both caches.
|
||||
mfspr 3, 1008 # (HID0)
|
||||
ori 3, 3, 0x0200
|
||||
mtspr 1008, 3
|
||||
|
||||
# Set the Non-IEEE mode in the FPSCR
|
||||
mtfsb1 29
|
||||
|
||||
mfspr 3,920 # (HID2)
|
||||
rlwinm 3, 3, 0, 2, 0
|
||||
mtspr 920,3 # (HID2)
|
||||
|
||||
# Restore the non-volatile registers to their previous values and return.
|
||||
lwz 0, 0x1C(1)
|
||||
lwz 31, 0x14(1)
|
||||
lwz 30, 0x10(1)
|
||||
lwz 29, 0xC(1)
|
||||
addi 1, 1, 0x18
|
||||
mtlr 0
|
||||
blr
|
||||
|
||||
zfloat:
|
||||
.float 0
|
||||
.align 4
|
||||
_got_start:
|
||||
59
wiipax/stub/devkitfail.ld
Normal file
59
wiipax/stub/devkitfail.ld
Normal file
@@ -0,0 +1,59 @@
|
||||
OUTPUT_FORMAT("elf32-powerpc")
|
||||
OUTPUT_ARCH(powerpc:common)
|
||||
|
||||
__mem1_start = 0x80004000;
|
||||
__mem2_start = 0x90010000;
|
||||
|
||||
__mem1_entry = _start - __mem2_start + __mem1_start;
|
||||
ENTRY(__mem1_entry)
|
||||
|
||||
PHDRS {
|
||||
paxx PT_LOAD FLAGS(7);
|
||||
}
|
||||
|
||||
SECTIONS {
|
||||
. = __mem2_start;
|
||||
|
||||
.start : AT(__mem1_start) { KEEP(*(.start)) } :paxx = 0
|
||||
.text : { *(.text) *(.text.*) }
|
||||
|
||||
. = ALIGN(4);
|
||||
|
||||
.payload : {
|
||||
__payload = .;
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
}
|
||||
|
||||
.rodata : { *(.rodata) *(.rodata.*) }
|
||||
|
||||
. = (( . +19)&0xFFFFFFF0) - 4;
|
||||
.padding : {
|
||||
LONG(0xdeadbeef);
|
||||
}
|
||||
|
||||
.sdata : { *(.sdata) *(.sdata.*) }
|
||||
.data : { *(.data) *(.data.*) }
|
||||
|
||||
. = ALIGN(32);
|
||||
__self_end = .;
|
||||
|
||||
__bss_start = .;
|
||||
.bss : { *(.bss) } :NONE = 0
|
||||
.sbss : { *(.sbss) }
|
||||
__bss_end = .;
|
||||
|
||||
. = ALIGN(32);
|
||||
|
||||
.stack : {
|
||||
_stack_top = .;
|
||||
. += 32768;
|
||||
_stack_bot = .;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
113
wiipax/stub/elf.c
Normal file
113
wiipax/stub/elf.c
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2001 William L. Pitts
|
||||
* Modifications (c) 2004 Felix Domke
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are freely
|
||||
* permitted provided that the above copyright notice and this
|
||||
* paragraph and the following disclaimer are duplicated in all
|
||||
* such forms.
|
||||
*
|
||||
* This software is provided "AS IS" and without any express or
|
||||
* implied warranties, including, without limitation, the implied
|
||||
* warranties of merchantability and fitness for a particular
|
||||
* purpose.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "elf_abi.h"
|
||||
#include "string.h"
|
||||
|
||||
int valid_elf_image (void *addr) {
|
||||
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
|
||||
|
||||
ehdr = (Elf32_Ehdr *) addr;
|
||||
|
||||
if (!IS_ELF (*ehdr))
|
||||
return 0;
|
||||
|
||||
if (ehdr->e_ident[EI_CLASS] != ELFCLASS32)
|
||||
return -1;
|
||||
|
||||
if (ehdr->e_ident[EI_DATA] != ELFDATA2MSB)
|
||||
return -1;
|
||||
|
||||
if (ehdr->e_ident[EI_VERSION] != EV_CURRENT)
|
||||
return -1;
|
||||
|
||||
if (ehdr->e_type != ET_EXEC)
|
||||
return -1;
|
||||
|
||||
if (ehdr->e_machine != EM_PPC)
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
u32 load_elf_image(void *addr) {
|
||||
Elf32_Ehdr *ehdr;
|
||||
Elf32_Phdr *phdrs;
|
||||
u8 *image;
|
||||
int i;
|
||||
|
||||
ehdr = (Elf32_Ehdr *)addr;
|
||||
|
||||
if(ehdr->e_phoff == 0 || ehdr->e_phnum == 0) {
|
||||
printf("ELF has no phdrs\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(ehdr->e_phentsize != sizeof(Elf32_Phdr)) {
|
||||
printf("Invalid ELF phdr size\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
phdrs = (Elf32_Phdr*)(addr + ehdr->e_phoff);
|
||||
|
||||
for(i = 0; i < ehdr->e_phnum; i++) {
|
||||
if(phdrs[i].p_type != PT_LOAD) {
|
||||
printf("skip PHDR %d of type %d\n", i, phdrs[i].p_type);
|
||||
continue;
|
||||
}
|
||||
|
||||
// translate paddr to this BAT setup
|
||||
phdrs[i].p_paddr &= 0x3FFFFFFF;
|
||||
phdrs[i].p_paddr |= 0x80000000;
|
||||
|
||||
printf("PHDR %d 0x%08x [0x%x] -> 0x%08x [0x%x] <", i,
|
||||
phdrs[i].p_offset, phdrs[i].p_filesz,
|
||||
phdrs[i].p_paddr, phdrs[i].p_memsz);
|
||||
|
||||
if(phdrs[i].p_flags & PF_R)
|
||||
printf("R");
|
||||
if(phdrs[i].p_flags & PF_W)
|
||||
printf("W");
|
||||
if(phdrs[i].p_flags & PF_X)
|
||||
printf("X");
|
||||
printf(">\n");
|
||||
|
||||
if(phdrs[i].p_filesz > phdrs[i].p_memsz) {
|
||||
printf("-> file size > mem size\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(phdrs[i].p_filesz) {
|
||||
printf("-> load 0x%x\n", phdrs[i].p_filesz);
|
||||
image = (u8 *)(addr + phdrs[i].p_offset);
|
||||
memcpy((void *)phdrs[i].p_paddr, (const void *)image,
|
||||
phdrs[i].p_filesz);
|
||||
memset((void *)image, 0, phdrs[i].p_filesz);
|
||||
|
||||
sync_after_write((void *)phdrs[i].p_paddr, phdrs[i].p_memsz);
|
||||
|
||||
if(phdrs[i].p_flags & PF_X)
|
||||
sync_before_exec((void *)phdrs[i].p_paddr, phdrs[i].p_memsz);
|
||||
} else {
|
||||
printf ("-> skip\n");
|
||||
}
|
||||
}
|
||||
|
||||
// entry point of the ELF _has_ to be correct - no translation done
|
||||
return ehdr->e_entry;
|
||||
}
|
||||
|
||||
7
wiipax/stub/elf.h
Normal file
7
wiipax/stub/elf.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _ELF_H
|
||||
#define _ELF_H
|
||||
|
||||
int valid_elf_image (void *addr);
|
||||
u32 load_elf_image (void *addr);
|
||||
|
||||
#endif
|
||||
594
wiipax/stub/elf_abi.h
Normal file
594
wiipax/stub/elf_abi.h
Normal file
@@ -0,0 +1,594 @@
|
||||
/*
|
||||
* Copyright (c) 1995, 1996, 2001, 2002
|
||||
* Erik Theisen. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the ELF ABI header file
|
||||
* formerly known as "elf_abi.h".
|
||||
*/
|
||||
|
||||
#ifndef _ELF_ABI_H
|
||||
#define _ELF_ABI_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/*
|
||||
* This version doesn't work for 64-bit ABIs - Erik.
|
||||
*/
|
||||
|
||||
/*
|
||||
* These typedefs need to be handled better.
|
||||
*/
|
||||
typedef u32 Elf32_Addr; /* Unsigned program address */
|
||||
typedef u32 Elf32_Off; /* Unsigned file offset */
|
||||
typedef s32 Elf32_Sword; /* Signed large integer */
|
||||
typedef u32 Elf32_Word; /* Unsigned large integer */
|
||||
typedef u16 Elf32_Half; /* Unsigned medium integer */
|
||||
|
||||
/* e_ident[] identification indexes */
|
||||
#define EI_MAG0 0 /* file ID */
|
||||
#define EI_MAG1 1 /* file ID */
|
||||
#define EI_MAG2 2 /* file ID */
|
||||
#define EI_MAG3 3 /* file ID */
|
||||
#define EI_CLASS 4 /* file class */
|
||||
#define EI_DATA 5 /* data encoding */
|
||||
#define EI_VERSION 6 /* ELF header version */
|
||||
#define EI_OSABI 7 /* OS/ABI specific ELF extensions */
|
||||
#define EI_ABIVERSION 8 /* ABI target version */
|
||||
#define EI_PAD 9 /* start of pad bytes */
|
||||
#define EI_NIDENT 16 /* Size of e_ident[] */
|
||||
|
||||
/* e_ident[] magic number */
|
||||
#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
|
||||
#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
|
||||
#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
|
||||
#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
|
||||
#define ELFMAG "\177ELF" /* magic */
|
||||
#define SELFMAG 4 /* size of magic */
|
||||
|
||||
/* e_ident[] file class */
|
||||
#define ELFCLASSNONE 0 /* invalid */
|
||||
#define ELFCLASS32 1 /* 32-bit objs */
|
||||
#define ELFCLASS64 2 /* 64-bit objs */
|
||||
#define ELFCLASSNUM 3 /* number of classes */
|
||||
|
||||
/* e_ident[] data encoding */
|
||||
#define ELFDATANONE 0 /* invalid */
|
||||
#define ELFDATA2LSB 1 /* Little-Endian */
|
||||
#define ELFDATA2MSB 2 /* Big-Endian */
|
||||
#define ELFDATANUM 3 /* number of data encode defines */
|
||||
|
||||
/* e_ident[] OS/ABI specific ELF extensions */
|
||||
#define ELFOSABI_NONE 0 /* No extension specified */
|
||||
#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
|
||||
#define ELFOSABI_NETBSD 2 /* NetBSD */
|
||||
#define ELFOSABI_LINUX 3 /* Linux */
|
||||
#define ELFOSABI_SOLARIS 6 /* Sun Solaris */
|
||||
#define ELFOSABI_AIX 7 /* AIX */
|
||||
#define ELFOSABI_IRIX 8 /* IRIX */
|
||||
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
|
||||
#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
|
||||
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
|
||||
#define ELFOSABI_OPENBSD 12 /* OpenBSD */
|
||||
/* 64-255 Architecture-specific value range */
|
||||
|
||||
/* e_ident[] ABI Version */
|
||||
#define ELFABIVERSION 0
|
||||
|
||||
/* e_ident */
|
||||
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
||||
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
||||
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
|
||||
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
||||
|
||||
/* ELF Header */
|
||||
typedef struct elfhdr{
|
||||
unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
|
||||
Elf32_Half e_type; /* object file type */
|
||||
Elf32_Half e_machine; /* machine */
|
||||
Elf32_Word e_version; /* object file version */
|
||||
Elf32_Addr e_entry; /* virtual entry point */
|
||||
Elf32_Off e_phoff; /* program header table offset */
|
||||
Elf32_Off e_shoff; /* section header table offset */
|
||||
Elf32_Word e_flags; /* processor-specific flags */
|
||||
Elf32_Half e_ehsize; /* ELF header size */
|
||||
Elf32_Half e_phentsize; /* program header entry size */
|
||||
Elf32_Half e_phnum; /* number of program header entries */
|
||||
Elf32_Half e_shentsize; /* section header entry size */
|
||||
Elf32_Half e_shnum; /* number of section header entries */
|
||||
Elf32_Half e_shstrndx; /* section header table's "section
|
||||
header string table" entry offset */
|
||||
} Elf32_Ehdr;
|
||||
|
||||
/* e_type */
|
||||
#define ET_NONE 0 /* No file type */
|
||||
#define ET_REL 1 /* relocatable file */
|
||||
#define ET_EXEC 2 /* executable file */
|
||||
#define ET_DYN 3 /* shared object file */
|
||||
#define ET_CORE 4 /* core file */
|
||||
#define ET_NUM 5 /* number of types */
|
||||
#define ET_LOOS 0xfe00 /* reserved range for operating */
|
||||
#define ET_HIOS 0xfeff /* system specific e_type */
|
||||
#define ET_LOPROC 0xff00 /* reserved range for processor */
|
||||
#define ET_HIPROC 0xffff /* specific e_type */
|
||||
|
||||
/* e_machine */
|
||||
#define EM_NONE 0 /* No Machine */
|
||||
#define EM_M32 1 /* AT&T WE 32100 */
|
||||
#define EM_SPARC 2 /* SPARC */
|
||||
#define EM_386 3 /* Intel 80386 */
|
||||
#define EM_68K 4 /* Motorola 68000 */
|
||||
#define EM_88K 5 /* Motorola 88000 */
|
||||
#if 0
|
||||
#define EM_486 6 /* RESERVED - was Intel 80486 */
|
||||
#endif
|
||||
#define EM_860 7 /* Intel 80860 */
|
||||
#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
|
||||
#define EM_S370 9 /* IBM System/370 Processor */
|
||||
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||
#if 0
|
||||
#define EM_SPARC64 11 /* RESERVED - was SPARC v9
|
||||
64-bit unoffical */
|
||||
#endif
|
||||
/* RESERVED 11-14 for future use */
|
||||
#define EM_PARISC 15 /* HPPA */
|
||||
/* RESERVED 16 for future use */
|
||||
#define EM_VPP500 17 /* Fujitsu VPP500 */
|
||||
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
|
||||
#define EM_960 19 /* Intel 80960 */
|
||||
#define EM_PPC 20 /* PowerPC */
|
||||
#define EM_PPC64 21 /* 64-bit PowerPC */
|
||||
#define EM_S390 22 /* IBM System/390 Processor */
|
||||
/* RESERVED 23-35 for future use */
|
||||
#define EM_V800 36 /* NEC V800 */
|
||||
#define EM_FR20 37 /* Fujitsu FR20 */
|
||||
#define EM_RH32 38 /* TRW RH-32 */
|
||||
#define EM_RCE 39 /* Motorola RCE */
|
||||
#define EM_ARM 40 /* Advanced Risc Machines ARM */
|
||||
#define EM_ALPHA 41 /* Digital Alpha */
|
||||
#define EM_SH 42 /* Hitachi SH */
|
||||
#define EM_SPARCV9 43 /* SPARC Version 9 */
|
||||
#define EM_TRICORE 44 /* Siemens TriCore embedded processor */
|
||||
#define EM_ARC 45 /* Argonaut RISC Core */
|
||||
#define EM_H8_300 46 /* Hitachi H8/300 */
|
||||
#define EM_H8_300H 47 /* Hitachi H8/300H */
|
||||
#define EM_H8S 48 /* Hitachi H8S */
|
||||
#define EM_H8_500 49 /* Hitachi H8/500 */
|
||||
#define EM_IA_64 50 /* Intel Merced */
|
||||
#define EM_MIPS_X 51 /* Stanford MIPS-X */
|
||||
#define EM_COLDFIRE 52 /* Motorola Coldfire */
|
||||
#define EM_68HC12 53 /* Motorola M68HC12 */
|
||||
#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/
|
||||
#define EM_PCP 55 /* Siemens PCP */
|
||||
#define EM_NCPU 56 /* Sony nCPU embeeded RISC */
|
||||
#define EM_NDR1 57 /* Denso NDR1 microprocessor */
|
||||
#define EM_STARCORE 58 /* Motorola Start*Core processor */
|
||||
#define EM_ME16 59 /* Toyota ME16 processor */
|
||||
#define EM_ST100 60 /* STMicroelectronic ST100 processor */
|
||||
#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/
|
||||
#define EM_X86_64 62 /* AMD x86-64 */
|
||||
#define EM_PDSP 63 /* Sony DSP Processor */
|
||||
/* RESERVED 64,65 for future use */
|
||||
#define EM_FX66 66 /* Siemens FX66 microcontroller */
|
||||
#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
|
||||
#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
|
||||
#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
|
||||
#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
|
||||
#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
|
||||
#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
|
||||
#define EM_SVX 73 /* Silicon Graphics SVx */
|
||||
#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
|
||||
#define EM_VAX 75 /* Digital VAX */
|
||||
#define EM_CHRIS 76 /* Axis Communications embedded proc. */
|
||||
#define EM_JAVELIN 77 /* Infineon Technologies emb. proc. */
|
||||
#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
|
||||
#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
|
||||
#define EM_MMIX 80 /* Donald Knuth's edu 64-bit proc. */
|
||||
#define EM_HUANY 81 /* Harvard University mach-indep objs */
|
||||
#define EM_PRISM 82 /* SiTera Prism */
|
||||
#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
|
||||
#define EM_FR30 84 /* Fujitsu FR30 */
|
||||
#define EM_D10V 85 /* Mitsubishi DV10V */
|
||||
#define EM_D30V 86 /* Mitsubishi DV30V */
|
||||
#define EM_V850 87 /* NEC v850 */
|
||||
#define EM_M32R 88 /* Mitsubishi M32R */
|
||||
#define EM_MN10300 89 /* Matsushita MN10200 */
|
||||
#define EM_MN10200 90 /* Matsushita MN10200 */
|
||||
#define EM_PJ 91 /* picoJava */
|
||||
#define EM_NUM 92 /* number of machine types */
|
||||
|
||||
/* Version */
|
||||
#define EV_NONE 0 /* Invalid */
|
||||
#define EV_CURRENT 1 /* Current */
|
||||
#define EV_NUM 2 /* number of versions */
|
||||
|
||||
/* Section Header */
|
||||
typedef struct {
|
||||
Elf32_Word sh_name; /* name - index into section header
|
||||
string table section */
|
||||
Elf32_Word sh_type; /* type */
|
||||
Elf32_Word sh_flags; /* flags */
|
||||
Elf32_Addr sh_addr; /* address */
|
||||
Elf32_Off sh_offset; /* file offset */
|
||||
Elf32_Word sh_size; /* section size */
|
||||
Elf32_Word sh_link; /* section header table index link */
|
||||
Elf32_Word sh_info; /* extra information */
|
||||
Elf32_Word sh_addralign; /* address alignment */
|
||||
Elf32_Word sh_entsize; /* section entry size */
|
||||
} Elf32_Shdr;
|
||||
|
||||
/* Special Section Indexes */
|
||||
#define SHN_UNDEF 0 /* undefined */
|
||||
#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
|
||||
#define SHN_LOPROC 0xff00 /* reserved range for processor */
|
||||
#define SHN_HIPROC 0xff1f /* specific section indexes */
|
||||
#define SHN_LOOS 0xff20 /* reserved range for operating */
|
||||
#define SHN_HIOS 0xff3f /* specific semantics */
|
||||
#define SHN_ABS 0xfff1 /* absolute value */
|
||||
#define SHN_COMMON 0xfff2 /* common symbol */
|
||||
#define SHN_XINDEX 0xffff /* Index is an extra table */
|
||||
#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
|
||||
|
||||
/* sh_type */
|
||||
#define SHT_NULL 0 /* inactive */
|
||||
#define SHT_PROGBITS 1 /* program defined information */
|
||||
#define SHT_SYMTAB 2 /* symbol table section */
|
||||
#define SHT_STRTAB 3 /* string table section */
|
||||
#define SHT_RELA 4 /* relocation section with addends*/
|
||||
#define SHT_HASH 5 /* symbol hash table section */
|
||||
#define SHT_DYNAMIC 6 /* dynamic section */
|
||||
#define SHT_NOTE 7 /* note section */
|
||||
#define SHT_NOBITS 8 /* no space section */
|
||||
#define SHT_REL 9 /* relation section without addends */
|
||||
#define SHT_SHLIB 10 /* reserved - purpose unknown */
|
||||
#define SHT_DYNSYM 11 /* dynamic symbol table section */
|
||||
#define SHT_INIT_ARRAY 14 /* Array of constructors */
|
||||
#define SHT_FINI_ARRAY 15 /* Array of destructors */
|
||||
#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
|
||||
#define SHT_GROUP 17 /* Section group */
|
||||
#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
|
||||
#define SHT_NUM 19 /* number of section types */
|
||||
#define SHT_LOOS 0x60000000 /* Start OS-specific */
|
||||
#define SHT_HIOS 0x6fffffff /* End OS-specific */
|
||||
#define SHT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define SHT_HIPROC 0x7fffffff /* specific section header types */
|
||||
#define SHT_LOUSER 0x80000000 /* reserved range for application */
|
||||
#define SHT_HIUSER 0xffffffff /* specific indexes */
|
||||
|
||||
/* Section names */
|
||||
#define ELF_BSS ".bss" /* uninitialized data */
|
||||
#define ELF_COMMENT ".comment" /* version control information */
|
||||
#define ELF_DATA ".data" /* initialized data */
|
||||
#define ELF_DATA1 ".data1" /* initialized data */
|
||||
#define ELF_DEBUG ".debug" /* debug */
|
||||
#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
|
||||
#define ELF_DYNSTR ".dynstr" /* dynamic string table */
|
||||
#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
|
||||
#define ELF_FINI ".fini" /* termination code */
|
||||
#define ELF_FINI_ARRAY ".fini_array" /* Array of destructors */
|
||||
#define ELF_GOT ".got" /* global offset table */
|
||||
#define ELF_HASH ".hash" /* symbol hash table */
|
||||
#define ELF_INIT ".init" /* initialization code */
|
||||
#define ELF_INIT_ARRAY ".init_array" /* Array of constuctors */
|
||||
#define ELF_INTERP ".interp" /* Pathname of program interpreter */
|
||||
#define ELF_LINE ".line" /* Symbolic line numnber information */
|
||||
#define ELF_NOTE ".note" /* Contains note section */
|
||||
#define ELF_PLT ".plt" /* Procedure linkage table */
|
||||
#define ELF_PREINIT_ARRAY ".preinit_array" /* Array of pre-constructors */
|
||||
#define ELF_REL_DATA ".rel.data" /* relocation data */
|
||||
#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
|
||||
#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
|
||||
#define ELF_REL_DYN ".rel.dyn" /* relocaltion dynamic link info */
|
||||
#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
|
||||
#define ELF_REL_TEXT ".rel.text" /* relocation code */
|
||||
#define ELF_RODATA ".rodata" /* read-only data */
|
||||
#define ELF_RODATA1 ".rodata1" /* read-only data */
|
||||
#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
|
||||
#define ELF_STRTAB ".strtab" /* string table */
|
||||
#define ELF_SYMTAB ".symtab" /* symbol table */
|
||||
#define ELF_SYMTAB_SHNDX ".symtab_shndx"/* symbol table section index */
|
||||
#define ELF_TBSS ".tbss" /* thread local uninit data */
|
||||
#define ELF_TDATA ".tdata" /* thread local init data */
|
||||
#define ELF_TDATA1 ".tdata1" /* thread local init data */
|
||||
#define ELF_TEXT ".text" /* code */
|
||||
|
||||
/* Section Attribute Flags - sh_flags */
|
||||
#define SHF_WRITE 0x1 /* Writable */
|
||||
#define SHF_ALLOC 0x2 /* occupies memory */
|
||||
#define SHF_EXECINSTR 0x4 /* executable */
|
||||
#define SHF_MERGE 0x10 /* Might be merged */
|
||||
#define SHF_STRINGS 0x20 /* Contains NULL terminated strings */
|
||||
#define SHF_INFO_LINK 0x40 /* sh_info contains SHT index */
|
||||
#define SHF_LINK_ORDER 0x80 /* Preserve order after combining*/
|
||||
#define SHF_OS_NONCONFORMING 0x100 /* Non-standard OS specific handling */
|
||||
#define SHF_GROUP 0x200 /* Member of section group */
|
||||
#define SHF_TLS 0x400 /* Thread local storage */
|
||||
#define SHF_MASKOS 0x0ff00000 /* OS specific */
|
||||
#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||
/* specific section attributes */
|
||||
|
||||
/* Section Group Flags */
|
||||
#define GRP_COMDAT 0x1 /* COMDAT group */
|
||||
#define GRP_MASKOS 0x0ff00000 /* Mask OS specific flags */
|
||||
#define GRP_MASKPROC 0xf0000000 /* Mask processor specific flags */
|
||||
|
||||
/* Symbol Table Entry */
|
||||
typedef struct elf32_sym {
|
||||
Elf32_Word st_name; /* name - index into string table */
|
||||
Elf32_Addr st_value; /* symbol value */
|
||||
Elf32_Word st_size; /* symbol size */
|
||||
unsigned char st_info; /* type and binding */
|
||||
unsigned char st_other; /* 0 - no defined meaning */
|
||||
Elf32_Half st_shndx; /* section header index */
|
||||
} Elf32_Sym;
|
||||
|
||||
/* Symbol table index */
|
||||
#define STN_UNDEF 0 /* undefined */
|
||||
|
||||
/* Extract symbol info - st_info */
|
||||
#define ELF32_ST_BIND(x) ((x) >> 4)
|
||||
#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
||||
#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
|
||||
#define ELF32_ST_VISIBILITY(x) ((x) & 0x3)
|
||||
|
||||
/* Symbol Binding - ELF32_ST_BIND - st_info */
|
||||
#define STB_LOCAL 0 /* Local symbol */
|
||||
#define STB_GLOBAL 1 /* Global symbol */
|
||||
#define STB_WEAK 2 /* like global - lower precedence */
|
||||
#define STB_NUM 3 /* number of symbol bindings */
|
||||
#define STB_LOOS 10 /* reserved range for operating */
|
||||
#define STB_HIOS 12 /* system specific symbol bindings */
|
||||
#define STB_LOPROC 13 /* reserved range for processor */
|
||||
#define STB_HIPROC 15 /* specific symbol bindings */
|
||||
|
||||
/* Symbol type - ELF32_ST_TYPE - st_info */
|
||||
#define STT_NOTYPE 0 /* not specified */
|
||||
#define STT_OBJECT 1 /* data object */
|
||||
#define STT_FUNC 2 /* function */
|
||||
#define STT_SECTION 3 /* section */
|
||||
#define STT_FILE 4 /* file */
|
||||
#define STT_NUM 5 /* number of symbol types */
|
||||
#define STT_TLS 6 /* Thread local storage symbol */
|
||||
#define STT_LOOS 10 /* reserved range for operating */
|
||||
#define STT_HIOS 12 /* system specific symbol types */
|
||||
#define STT_LOPROC 13 /* reserved range for processor */
|
||||
#define STT_HIPROC 15 /* specific symbol types */
|
||||
|
||||
/* Symbol visibility - ELF32_ST_VISIBILITY - st_other */
|
||||
#define STV_DEFAULT 0 /* Normal visibility rules */
|
||||
#define STV_INTERNAL 1 /* Processor specific hidden class */
|
||||
#define STV_HIDDEN 2 /* Symbol unavailable in other mods */
|
||||
#define STV_PROTECTED 3 /* Not preemptible, not exported */
|
||||
|
||||
|
||||
/* Relocation entry with implicit addend */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset; /* offset of relocation */
|
||||
Elf32_Word r_info; /* symbol table index and type */
|
||||
} Elf32_Rel;
|
||||
|
||||
/* Relocation entry with explicit addend */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset; /* offset of relocation */
|
||||
Elf32_Word r_info; /* symbol table index and type */
|
||||
Elf32_Sword r_addend;
|
||||
} Elf32_Rela;
|
||||
|
||||
/* Extract relocation info - r_info */
|
||||
#define ELF32_R_SYM(i) ((i) >> 8)
|
||||
#define ELF32_R_TYPE(i) ((unsigned char) (i))
|
||||
#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
|
||||
|
||||
/* Program Header */
|
||||
typedef struct {
|
||||
Elf32_Word p_type; /* segment type */
|
||||
Elf32_Off p_offset; /* segment offset */
|
||||
Elf32_Addr p_vaddr; /* virtual address of segment */
|
||||
Elf32_Addr p_paddr; /* physical address - ignored? */
|
||||
Elf32_Word p_filesz; /* number of bytes in file for seg. */
|
||||
Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
|
||||
Elf32_Word p_flags; /* flags */
|
||||
Elf32_Word p_align; /* memory alignment */
|
||||
} Elf32_Phdr;
|
||||
|
||||
/* Segment types - p_type */
|
||||
#define PT_NULL 0 /* unused */
|
||||
#define PT_LOAD 1 /* loadable segment */
|
||||
#define PT_DYNAMIC 2 /* dynamic linking section */
|
||||
#define PT_INTERP 3 /* the RTLD */
|
||||
#define PT_NOTE 4 /* auxiliary information */
|
||||
#define PT_SHLIB 5 /* reserved - purpose undefined */
|
||||
#define PT_PHDR 6 /* program header */
|
||||
#define PT_TLS 7 /* Thread local storage template */
|
||||
#define PT_NUM 8 /* Number of segment types */
|
||||
#define PT_LOOS 0x60000000 /* reserved range for operating */
|
||||
#define PT_HIOS 0x6fffffff /* system specific segment types */
|
||||
#define PT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define PT_HIPROC 0x7fffffff /* specific segment types */
|
||||
|
||||
/* Segment flags - p_flags */
|
||||
#define PF_X 0x1 /* Executable */
|
||||
#define PF_W 0x2 /* Writable */
|
||||
#define PF_R 0x4 /* Readable */
|
||||
#define PF_MASKOS 0x0ff00000 /* OS specific segment flags */
|
||||
#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
|
||||
/* specific segment flags */
|
||||
/* Dynamic structure */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Sword d_tag; /* controls meaning of d_val */
|
||||
union
|
||||
{
|
||||
Elf32_Word d_val; /* Multiple meanings - see d_tag */
|
||||
Elf32_Addr d_ptr; /* program virtual address */
|
||||
} d_un;
|
||||
} Elf32_Dyn;
|
||||
|
||||
extern Elf32_Dyn _DYNAMIC[];
|
||||
|
||||
/* Dynamic Array Tags - d_tag */
|
||||
#define DT_NULL 0 /* marks end of _DYNAMIC array */
|
||||
#define DT_NEEDED 1 /* string table offset of needed lib */
|
||||
#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
|
||||
#define DT_PLTGOT 3 /* address PLT/GOT */
|
||||
#define DT_HASH 4 /* address of symbol hash table */
|
||||
#define DT_STRTAB 5 /* address of string table */
|
||||
#define DT_SYMTAB 6 /* address of symbol table */
|
||||
#define DT_RELA 7 /* address of relocation table */
|
||||
#define DT_RELASZ 8 /* size of relocation table */
|
||||
#define DT_RELAENT 9 /* size of relocation entry */
|
||||
#define DT_STRSZ 10 /* size of string table */
|
||||
#define DT_SYMENT 11 /* size of symbol table entry */
|
||||
#define DT_INIT 12 /* address of initialization func. */
|
||||
#define DT_FINI 13 /* address of termination function */
|
||||
#define DT_SONAME 14 /* string table offset of shared obj */
|
||||
#define DT_RPATH 15 /* string table offset of library
|
||||
search path */
|
||||
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
|
||||
#define DT_REL 17 /* address of rel. tbl. w addends */
|
||||
#define DT_RELSZ 18 /* size of DT_REL relocation table */
|
||||
#define DT_RELENT 19 /* size of DT_REL relocation entry */
|
||||
#define DT_PLTREL 20 /* PLT referenced relocation entry */
|
||||
#define DT_DEBUG 21 /* bugger */
|
||||
#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
|
||||
#define DT_JMPREL 23 /* add. of PLT's relocation entries */
|
||||
#define DT_BIND_NOW 24 /* Process relocations of object */
|
||||
#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
|
||||
#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
|
||||
#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
|
||||
#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
|
||||
#define DT_RUNPATH 29 /* Library search path */
|
||||
#define DT_FLAGS 30 /* Flags for the object being loaded */
|
||||
#define DT_ENCODING 32 /* Start of encoded range */
|
||||
#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
|
||||
#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
|
||||
#define DT_NUM 34 /* Number used. */
|
||||
#define DT_LOOS 0x60000000 /* reserved range for OS */
|
||||
#define DT_HIOS 0x6fffffff /* specific dynamic array tags */
|
||||
#define DT_LOPROC 0x70000000 /* reserved range for processor */
|
||||
#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
|
||||
|
||||
/* Dynamic Tag Flags - d_un.d_val */
|
||||
#define DF_ORIGIN 0x01 /* Object may use DF_ORIGIN */
|
||||
#define DF_SYMBOLIC 0x02 /* Symbol resolutions starts here */
|
||||
#define DF_TEXTREL 0x04 /* Object contains text relocations */
|
||||
#define DF_BIND_NOW 0x08 /* No lazy binding for this object */
|
||||
#define DF_STATIC_TLS 0x10 /* Static thread local storage */
|
||||
|
||||
/* Standard ELF hashing function */
|
||||
unsigned long elf_hash(const unsigned char *name);
|
||||
|
||||
#define ELF_TARG_VER 1 /* The ver for which this code is intended */
|
||||
|
||||
/*
|
||||
* XXX - PowerPC defines really don't belong in here,
|
||||
* but we'll put them in for simplicity.
|
||||
*/
|
||||
|
||||
/* Values for Elf32/64_Ehdr.e_flags. */
|
||||
#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
|
||||
|
||||
/* Cygnus local bits below */
|
||||
#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
|
||||
#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
|
||||
flag */
|
||||
|
||||
/* PowerPC relocations defined by the ABIs */
|
||||
#define R_PPC_NONE 0
|
||||
#define R_PPC_ADDR32 1 /* 32bit absolute address */
|
||||
#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
|
||||
#define R_PPC_ADDR16 3 /* 16bit absolute address */
|
||||
#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
|
||||
#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
|
||||
#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
|
||||
#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
|
||||
#define R_PPC_ADDR14_BRTAKEN 8
|
||||
#define R_PPC_ADDR14_BRNTAKEN 9
|
||||
#define R_PPC_REL24 10 /* PC relative 26 bit */
|
||||
#define R_PPC_REL14 11 /* PC relative 16 bit */
|
||||
#define R_PPC_REL14_BRTAKEN 12
|
||||
#define R_PPC_REL14_BRNTAKEN 13
|
||||
#define R_PPC_GOT16 14
|
||||
#define R_PPC_GOT16_LO 15
|
||||
#define R_PPC_GOT16_HI 16
|
||||
#define R_PPC_GOT16_HA 17
|
||||
#define R_PPC_PLTREL24 18
|
||||
#define R_PPC_COPY 19
|
||||
#define R_PPC_GLOB_DAT 20
|
||||
#define R_PPC_JMP_SLOT 21
|
||||
#define R_PPC_RELATIVE 22
|
||||
#define R_PPC_LOCAL24PC 23
|
||||
#define R_PPC_UADDR32 24
|
||||
#define R_PPC_UADDR16 25
|
||||
#define R_PPC_REL32 26
|
||||
#define R_PPC_PLT32 27
|
||||
#define R_PPC_PLTREL32 28
|
||||
#define R_PPC_PLT16_LO 29
|
||||
#define R_PPC_PLT16_HI 30
|
||||
#define R_PPC_PLT16_HA 31
|
||||
#define R_PPC_SDAREL16 32
|
||||
#define R_PPC_SECTOFF 33
|
||||
#define R_PPC_SECTOFF_LO 34
|
||||
#define R_PPC_SECTOFF_HI 35
|
||||
#define R_PPC_SECTOFF_HA 36
|
||||
/* Keep this the last entry. */
|
||||
#define R_PPC_NUM 37
|
||||
|
||||
/* The remaining relocs are from the Embedded ELF ABI, and are not
|
||||
in the SVR4 ELF ABI. */
|
||||
#define R_PPC_EMB_NADDR32 101
|
||||
#define R_PPC_EMB_NADDR16 102
|
||||
#define R_PPC_EMB_NADDR16_LO 103
|
||||
#define R_PPC_EMB_NADDR16_HI 104
|
||||
#define R_PPC_EMB_NADDR16_HA 105
|
||||
#define R_PPC_EMB_SDAI16 106
|
||||
#define R_PPC_EMB_SDA2I16 107
|
||||
#define R_PPC_EMB_SDA2REL 108
|
||||
#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
|
||||
#define R_PPC_EMB_MRKREF 110
|
||||
#define R_PPC_EMB_RELSEC16 111
|
||||
#define R_PPC_EMB_RELST_LO 112
|
||||
#define R_PPC_EMB_RELST_HI 113
|
||||
#define R_PPC_EMB_RELST_HA 114
|
||||
#define R_PPC_EMB_BIT_FLD 115
|
||||
#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
|
||||
|
||||
/* Diab tool relocations. */
|
||||
#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
|
||||
#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
|
||||
#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
|
||||
#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
|
||||
#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
|
||||
#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
|
||||
|
||||
/* This is a phony reloc to handle any old fashioned TOC16 references
|
||||
that may still be in object files. */
|
||||
#define R_PPC_TOC16 255
|
||||
|
||||
#endif /* _ELF_H */
|
||||
|
||||
52
wiipax/stub/exception.c
Normal file
52
wiipax/stub/exception.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "common.h"
|
||||
#include "string.h"
|
||||
|
||||
extern char exception_asm_start, exception_asm_end;
|
||||
|
||||
void exception_handler(int exception)
|
||||
{
|
||||
u32 *x;
|
||||
u32 i;
|
||||
|
||||
printf("\nException %04x occurred!\n", exception);
|
||||
|
||||
x = (u32 *)0x80003500;
|
||||
|
||||
printf("\n R0..R7 R8..R15 R16..R23 R24..R31\n");
|
||||
for (i = 0; i < 8; i++) {
|
||||
printf("%08x %08x %08x %08x\n", x[0], x[8], x[16], x[24]);
|
||||
x++;
|
||||
}
|
||||
x += 24;
|
||||
|
||||
printf("\n CR/XER LR/CTR SRR0/SRR1 DAR/DSISR\n");
|
||||
for (i = 0; i < 2; i++) {
|
||||
printf("%08x %08x %08x %08x\n", x[0], x[2], x[4], x[6]);
|
||||
x++;
|
||||
}
|
||||
|
||||
// Hang.
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
void exception_init(void)
|
||||
{
|
||||
u32 vector;
|
||||
u32 len_asm;
|
||||
|
||||
for (vector = 0x100; vector < 0x1800; vector += 0x10) {
|
||||
u32 *insn = (u32 *)(0x80000000 + vector);
|
||||
|
||||
insn[0] = 0xbc003500; // stmw 0,0x3500(0)
|
||||
insn[1] = 0x38600000 | vector; // li 3,vector
|
||||
insn[2] = 0x48003602; // ba 0x3600
|
||||
insn[3] = 0;
|
||||
}
|
||||
sync_before_exec((void *)0x80000100, 0x1f00);
|
||||
|
||||
len_asm = &exception_asm_end - &exception_asm_start;
|
||||
memcpy((void *)0x80003600, &exception_asm_start, len_asm);
|
||||
sync_before_exec((void *)0x80003600, len_asm);
|
||||
}
|
||||
|
||||
21
wiipax/stub/exception_asm.s
Normal file
21
wiipax/stub/exception_asm.s
Normal file
@@ -0,0 +1,21 @@
|
||||
.globl exception_asm_start, exception_asm_end
|
||||
|
||||
exception_asm_start:
|
||||
# store all interesting regs
|
||||
mfcr 0 ; stw 0,0x3580(0)
|
||||
mfxer 0 ; stw 0,0x3584(0)
|
||||
mflr 0 ; stw 0,0x3588(0)
|
||||
mfctr 0 ; stw 0,0x358c(0)
|
||||
mfsrr0 0 ; stw 0,0x3590(0)
|
||||
mfsrr1 0 ; stw 0,0x3594(0)
|
||||
mfdar 0 ; stw 0,0x3598(0)
|
||||
mfdsisr 0 ; stw 0,0x359c(0)
|
||||
|
||||
# switch on FP, DR, IR
|
||||
mfmsr 0 ; ori 0,0,0x2030 ; mtsrr1 0
|
||||
|
||||
# go to C handler
|
||||
lis 0,exception_handler@h ; ori 0,0,exception_handler@l ; mtsrr0 0
|
||||
rfi
|
||||
exception_asm_end:
|
||||
|
||||
185
wiipax/stub/gecko.c
Normal file
185
wiipax/stub/gecko.c
Normal file
@@ -0,0 +1,185 @@
|
||||
#include "common.h"
|
||||
#include "vsprintf.h"
|
||||
|
||||
#define EXI_REG_BASE 0xd806800
|
||||
#define EXI0_REG_BASE (EXI_REG_BASE+0x000)
|
||||
#define EXI1_REG_BASE (EXI_REG_BASE+0x014)
|
||||
#define EXI2_REG_BASE (EXI_REG_BASE+0x028)
|
||||
|
||||
#define EXI0_CSR (EXI0_REG_BASE+0x000)
|
||||
#define EXI0_MAR (EXI0_REG_BASE+0x004)
|
||||
#define EXI0_LENGTH (EXI0_REG_BASE+0x008)
|
||||
#define EXI0_CR (EXI0_REG_BASE+0x00c)
|
||||
#define EXI0_DATA (EXI0_REG_BASE+0x010)
|
||||
|
||||
#define EXI1_CSR (EXI1_REG_BASE+0x000)
|
||||
#define EXI1_MAR (EXI1_REG_BASE+0x004)
|
||||
#define EXI1_LENGTH (EXI1_REG_BASE+0x008)
|
||||
#define EXI1_CR (EXI1_REG_BASE+0x00c)
|
||||
#define EXI1_DATA (EXI1_REG_BASE+0x010)
|
||||
|
||||
#define EXI2_CSR (EXI2_REG_BASE+0x000)
|
||||
#define EXI2_MAR (EXI2_REG_BASE+0x004)
|
||||
#define EXI2_LENGTH (EXI2_REG_BASE+0x008)
|
||||
#define EXI2_CR (EXI2_REG_BASE+0x00c)
|
||||
#define EXI2_DATA (EXI2_REG_BASE+0x010)
|
||||
|
||||
static int gecko_console_enabled = 0;
|
||||
|
||||
static u32 _gecko_command(u32 command) {
|
||||
u32 i;
|
||||
// Memory Card Port B (Channel 1, Device 0, Frequency 3 (32Mhz Clock))
|
||||
write32(EXI1_CSR, 0xd0);
|
||||
write32(EXI1_DATA, command);
|
||||
write32(EXI1_CR, 0x19);
|
||||
i = 1000;
|
||||
while ((read32(EXI1_CR) & 1) && (i--));
|
||||
i = read32(EXI1_DATA);
|
||||
write32(EXI1_CSR, 0);
|
||||
return i;
|
||||
}
|
||||
|
||||
static u32 _gecko_sendbyte(char sendbyte) {
|
||||
u32 i = 0;
|
||||
i = _gecko_command(0xB0000000 | (sendbyte<<20));
|
||||
if (i&0x04000000)
|
||||
return 1; // Return 1 if byte was sent
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static u32 _gecko_recvbyte(char *recvbyte) {
|
||||
u32 i = 0;
|
||||
*recvbyte = 0;
|
||||
i = _gecko_command(0xA0000000);
|
||||
if (i&0x08000000) {
|
||||
// Return 1 if byte was received
|
||||
*recvbyte = (i>>16)&0xff;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 _gecko_checksend(void) {
|
||||
u32 i = 0;
|
||||
i = _gecko_command(0xC0000000);
|
||||
if (i&0x04000000)
|
||||
return 1; // Return 1 if safe to send
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 _gecko_checkrecv(void) {
|
||||
u32 i = 0;
|
||||
i = _gecko_command(0xD0000000);
|
||||
if (i&0x04000000)
|
||||
return 1; // Return 1 if safe to recv
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gecko_flush(void) {
|
||||
char tmp;
|
||||
while(_gecko_recvbyte(&tmp));
|
||||
}
|
||||
#endif
|
||||
|
||||
static int gecko_isalive(void) {
|
||||
u32 i = 0;
|
||||
i = _gecko_command(0x90000000);
|
||||
if (i&0x04700000)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int gecko_recvbuffer(void *buffer, u32 size) {
|
||||
u32 left = size;
|
||||
char *ptr = (char*)buffer;
|
||||
|
||||
while(left>0) {
|
||||
if(!_gecko_recvbyte(ptr))
|
||||
break;
|
||||
ptr++;
|
||||
left--;
|
||||
}
|
||||
return (size - left);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int gecko_sendbuffer(const void *buffer, u32 size) {
|
||||
u32 left = size;
|
||||
char *ptr = (char*)buffer;
|
||||
|
||||
while(left>0) {
|
||||
if(!_gecko_sendbyte(*ptr))
|
||||
break;
|
||||
ptr++;
|
||||
left--;
|
||||
}
|
||||
return (size - left);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int gecko_recvbuffer_safe(void *buffer, u32 size) {
|
||||
u32 left = size;
|
||||
char *ptr = (char*)buffer;
|
||||
|
||||
while(left>0) {
|
||||
if(_gecko_checkrecv()) {
|
||||
if(!_gecko_recvbyte(ptr))
|
||||
break;
|
||||
ptr++;
|
||||
left--;
|
||||
}
|
||||
}
|
||||
return (size - left);
|
||||
}
|
||||
|
||||
static int gecko_sendbuffer_safe(const void *buffer, u32 size) {
|
||||
u32 left = size;
|
||||
char *ptr = (char*)buffer;
|
||||
|
||||
while(left>0) {
|
||||
if(_gecko_checksend()) {
|
||||
if(!_gecko_sendbyte(*ptr))
|
||||
break;
|
||||
ptr++;
|
||||
left--;
|
||||
}
|
||||
}
|
||||
return (size - left);
|
||||
}
|
||||
#endif
|
||||
|
||||
void gecko_init(void)
|
||||
{
|
||||
// unlock EXI
|
||||
write32(0x0d00643c, 0);
|
||||
|
||||
write32(EXI0_CSR, 0);
|
||||
write32(EXI1_CSR, 0);
|
||||
write32(EXI2_CSR, 0);
|
||||
write32(EXI0_CSR, 0x2000);
|
||||
write32(EXI0_CSR, 3<<10);
|
||||
write32(EXI1_CSR, 3<<10);
|
||||
|
||||
if (!gecko_isalive())
|
||||
return;
|
||||
|
||||
gecko_console_enabled = 1;
|
||||
}
|
||||
|
||||
int printf(const char *fmt, ...) {
|
||||
if (!gecko_console_enabled)
|
||||
return 0;
|
||||
|
||||
va_list args;
|
||||
char buffer[1024];
|
||||
int i;
|
||||
|
||||
va_start(args, fmt);
|
||||
i = vsprintf(buffer, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
return gecko_sendbuffer(buffer, i);
|
||||
}
|
||||
|
||||
109
wiipax/stub/main.c
Normal file
109
wiipax/stub/main.c
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "common.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "elf.h"
|
||||
|
||||
#include "LzmaDec.h"
|
||||
|
||||
extern const u8 __self_start[], __self_end[];
|
||||
extern const u8 __payload[];
|
||||
|
||||
extern void _plunge(u32 entry);
|
||||
|
||||
typedef struct {
|
||||
u8 * const data;
|
||||
const u32 len_in;
|
||||
const u32 len_out;
|
||||
const u8 props[LZMA_PROPS_SIZE];
|
||||
} __attribute__((packed)) _payload;
|
||||
|
||||
const _payload * const payload = (void *) __payload;
|
||||
|
||||
u8 * const code_buffer = (u8 *) 0x90100000;
|
||||
|
||||
static void *lz_malloc(void *p, size_t size) {
|
||||
(void) p;
|
||||
(void) size;
|
||||
printf("lz_malloc %u\n", size);
|
||||
return (void *) 0x90081000;
|
||||
}
|
||||
|
||||
static void lz_free(void *p, void *address) {
|
||||
(void) p;
|
||||
(void) address;
|
||||
printf("lz_free %p\n", address);
|
||||
}
|
||||
|
||||
static const ISzAlloc lz_alloc = { lz_malloc, lz_free };
|
||||
|
||||
static inline __attribute__((always_inline)) int decode(void) {
|
||||
SizeT len_in;
|
||||
SizeT len_out;
|
||||
ELzmaStatus status;
|
||||
SRes res;
|
||||
|
||||
len_in = payload->len_in;
|
||||
len_out = payload->len_out;
|
||||
|
||||
printf("in: %d out: %d\n", len_in, len_out);
|
||||
|
||||
res = LzmaDecode(code_buffer, &len_out, payload->data, &len_in,
|
||||
payload->props, LZMA_PROPS_SIZE, LZMA_FINISH_END,
|
||||
&status, (ISzAlloc*)&lz_alloc);
|
||||
|
||||
if (res != SZ_OK) {
|
||||
printf("decoding error %d (%u)\n", res, status);
|
||||
return res;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stubmain(void) {
|
||||
#ifndef NDEBUG
|
||||
exception_init();
|
||||
#endif
|
||||
|
||||
// clear interrupt mask
|
||||
write32(0x0c003004, 0);
|
||||
|
||||
#ifndef NDEBUG
|
||||
#ifndef DEVKITFAIL
|
||||
udelay(500 * 1000); // wait for mini - avoid EXI battle
|
||||
#endif
|
||||
gecko_init();
|
||||
#endif
|
||||
printf("hello world\n");
|
||||
printf("payload @%p blob @%p\n", payload, payload->data);
|
||||
|
||||
if (decode() == 0 && valid_elf_image(code_buffer)) {
|
||||
printf("Valid ELF image detected.\n");
|
||||
u32 entry = load_elf_image(code_buffer);
|
||||
|
||||
if (entry) {
|
||||
// Disable all IRQs; ack all pending IRQs.
|
||||
write32(0x0c003004, 0);
|
||||
write32(0x0c003000, 0xffffffff);
|
||||
|
||||
printf("Branching to 0x%08x\n", entry);
|
||||
#ifndef DEVKITFAIL
|
||||
// detect failkit apps packed with the mini stub
|
||||
if (entry & 0xc0000000) {
|
||||
void (*ep)() = (void (*)()) entry;
|
||||
ep();
|
||||
} else {
|
||||
_plunge(entry);
|
||||
}
|
||||
#else
|
||||
void (*ep)() = (void (*)()) entry;
|
||||
ep();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
error:
|
||||
blink();
|
||||
udelay(500000);
|
||||
goto error;
|
||||
}
|
||||
|
||||
13
wiipax/stub/plunge.S
Normal file
13
wiipax/stub/plunge.S
Normal file
@@ -0,0 +1,13 @@
|
||||
.text
|
||||
.section .text
|
||||
.globl _plunge
|
||||
|
||||
_plunge:
|
||||
isync
|
||||
mtsrr0 3
|
||||
|
||||
mfmsr 3
|
||||
li 4,0x30
|
||||
andc 3,3,4
|
||||
mtsrr1 3
|
||||
rfi
|
||||
101
wiipax/stub/realmode.S
Normal file
101
wiipax/stub/realmode.S
Normal file
@@ -0,0 +1,101 @@
|
||||
#define IBAT0U 528
|
||||
#define IBAT0L 529
|
||||
#define IBAT1U 530
|
||||
#define IBAT1L 531
|
||||
#define IBAT2U 532
|
||||
#define IBAT2L 533
|
||||
#define IBAT3U 534
|
||||
#define IBAT3L 535
|
||||
#define IBAT4U 560
|
||||
#define IBAT4L 561
|
||||
#define IBAT5U 562
|
||||
#define IBAT5L 563
|
||||
#define IBAT6U 564
|
||||
#define IBAT6L 565
|
||||
#define IBAT7U 566
|
||||
#define IBAT7L 567
|
||||
|
||||
#define DBAT0U 536
|
||||
#define DBAT0L 537
|
||||
#define DBAT1U 538
|
||||
#define DBAT1L 539
|
||||
#define DBAT2U 540
|
||||
#define DBAT2L 541
|
||||
#define DBAT3U 542
|
||||
#define DBAT3L 543
|
||||
#define DBAT4U 568
|
||||
#define DBAT4L 569
|
||||
#define DBAT5U 570
|
||||
#define DBAT5L 571
|
||||
#define DBAT6U 572
|
||||
#define DBAT6L 573
|
||||
#define DBAT7U 574
|
||||
#define DBAT7L 575
|
||||
|
||||
|
||||
.text
|
||||
.section .realmode,"ax",@progbits
|
||||
.extern _start
|
||||
.align 2
|
||||
.globl _realmode_vector
|
||||
|
||||
_realmode_vector:
|
||||
// HID0 = 00110c64:
|
||||
// bus checkstops off, sleep modes off,
|
||||
// caches off, caches invalidate,
|
||||
// store gathering off, enable data cache
|
||||
// flush assist, enable branch target cache,
|
||||
// enable branch history table
|
||||
lis 3,0x0011 ; ori 3,3,0x0c64 ; mtspr 1008,3 ; isync
|
||||
|
||||
// MSR = 00002000 (FP on)
|
||||
li 4,0x2000 ; mtmsr 4
|
||||
|
||||
// HID0 |= 0000c000 (caches on)
|
||||
ori 3,3,0xc000 ; mtspr 1008,3 ; isync
|
||||
|
||||
// clear all BATs
|
||||
li 0,0
|
||||
mtspr 528,0 ; mtspr 530,0 ; mtspr 532,0 ; mtspr 534,0 // IBATU 0..3
|
||||
mtspr 536,0 ; mtspr 538,0 ; mtspr 540,0 ; mtspr 542,0 // DBATU 0..3
|
||||
mtspr 560,0 ; mtspr 562,0 ; mtspr 564,0 ; mtspr 566,0 // IBATU 4..7
|
||||
mtspr 568,0 ; mtspr 570,0 ; mtspr 572,0 ; mtspr 574,0 // DBATU 4..7
|
||||
isync
|
||||
|
||||
// clear all SRs
|
||||
lis 0,0x8000
|
||||
mtsr 0,0 ; mtsr 1,0 ; mtsr 2,0 ; mtsr 3,0
|
||||
mtsr 4,0 ; mtsr 5,0 ; mtsr 6,0 ; mtsr 7,0
|
||||
mtsr 8,0 ; mtsr 9,0 ; mtsr 10,0 ; mtsr 11,0
|
||||
mtsr 12,0 ; mtsr 13,0 ; mtsr 14,0 ; mtsr 15,0
|
||||
isync
|
||||
|
||||
// set [DI]BAT0 for 256MB@80000000,
|
||||
// real 00000000, WIMG=0000, R/W
|
||||
li 3,2 ; lis 4,0x8000 ; ori 4,4,0x1fff
|
||||
mtspr IBAT0L,3 ; mtspr IBAT0U,4 ; mtspr DBAT0L,3 ; mtspr DBAT0U,4 ; isync
|
||||
|
||||
// set [DI]BAT4 for 256MB@90000000,
|
||||
// real 10000000, WIMG=0000, R/W
|
||||
addis 3,3,0x1000 ; addis 4,4,0x1000
|
||||
mtspr IBAT4L,3 ; mtspr IBAT4U,4 ; mtspr DBAT4L,3 ; mtspr DBAT4U,4 ; isync
|
||||
|
||||
// set DBAT1 for 256MB@c0000000,
|
||||
// real 00000000, WIMG=0101, R/W
|
||||
li 3,0x2a ; lis 4,0xc000 ; ori 4,4,0x1fff
|
||||
mtspr DBAT1L,3 ; mtspr DBAT1U,4 ; isync
|
||||
|
||||
// set DBAT5 for 256MB@d0000000,
|
||||
// real 10000000, WIMG=0101, R/W
|
||||
addis 3,3,0x1000 ; addis 4,4,0x1000
|
||||
mtspr DBAT5L,3 ; mtspr DBAT5U,4 ; isync
|
||||
|
||||
// enable [DI]BAT4-7 in HID4
|
||||
lis 3, 0x8200
|
||||
mtspr 1011,3
|
||||
|
||||
// set MSR[DR:IR] = 11, jump to _start
|
||||
lis 3,__mem1_entry@h ; ori 3,3,__mem1_entry@l ; mtsrr0 3
|
||||
|
||||
mfmsr 3 ; ori 3,3,0x30 ; mtsrr1 3
|
||||
rfi
|
||||
64
wiipax/stub/realmode.ld
Normal file
64
wiipax/stub/realmode.ld
Normal file
@@ -0,0 +1,64 @@
|
||||
OUTPUT_FORMAT("elf32-powerpc")
|
||||
OUTPUT_ARCH(powerpc:common)
|
||||
|
||||
__mem1_start = 0x80004000;
|
||||
__mem2_start = 0x90010000;
|
||||
|
||||
__mem1_entry = _start - __mem2_start + __mem1_start;
|
||||
ENTRY(_realmode_vector)
|
||||
|
||||
PHDRS {
|
||||
realmode PT_LOAD FLAGS(5);
|
||||
paxx PT_LOAD FLAGS(7);
|
||||
}
|
||||
|
||||
SECTIONS {
|
||||
. = 0x00003400;
|
||||
|
||||
.realmode : { *(.realmode) } :realmode = 0
|
||||
|
||||
. = __mem2_start;
|
||||
|
||||
.start : AT(__mem1_start & 0x3FFFFFFF) { KEEP(*(.start)) } :paxx = 0
|
||||
.text : { *(.text) *(.text.*) }
|
||||
|
||||
. = ALIGN(4);
|
||||
|
||||
.payload : {
|
||||
__payload = .;
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
LONG(0);
|
||||
}
|
||||
|
||||
.rodata : { *(.rodata) *(.rodata.*) }
|
||||
|
||||
. = (( . +19)&0xFFFFFFF0) - 4;
|
||||
.padding : {
|
||||
LONG(0xdeadbeef);
|
||||
}
|
||||
|
||||
.sdata : { *(.sdata) *(.sdata.*) }
|
||||
.data : { *(.data) *(.data.*) }
|
||||
|
||||
. = ALIGN(32);
|
||||
__self_end = .;
|
||||
|
||||
__bss_start = .;
|
||||
.bss : { *(.bss) } :NONE = 0
|
||||
.sbss : { *(.sbss) }
|
||||
__bss_end = .;
|
||||
|
||||
. = ALIGN(32);
|
||||
|
||||
.stack : {
|
||||
_stack_top = .;
|
||||
. += 32768;
|
||||
_stack_bot = .;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
94
wiipax/stub/string.c
Normal file
94
wiipax/stub/string.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* linux/lib/string.c
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
#include "string.h"
|
||||
|
||||
size_t strnlen(const char *s, size_t count)
|
||||
{
|
||||
const char *sc;
|
||||
|
||||
for (sc = s; count-- && *sc != '\0'; ++sc)
|
||||
/* nothing */;
|
||||
return sc - s;
|
||||
}
|
||||
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
const char *sc;
|
||||
|
||||
for (sc = s; *sc != '\0'; ++sc)
|
||||
/* nothing */;
|
||||
return sc - s;
|
||||
}
|
||||
|
||||
char *strncpy(char *dst, const char *src, size_t n)
|
||||
{
|
||||
char *ret = dst;
|
||||
|
||||
while (n && (*dst++ = *src++))
|
||||
n--;
|
||||
|
||||
while (n--)
|
||||
*dst++ = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *strcpy(char *dst, const char *src)
|
||||
{
|
||||
char *ret = dst;
|
||||
|
||||
while ((*dst++ = *src++))
|
||||
;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int strcmp(const char *p, const char *q)
|
||||
{
|
||||
for (;;) {
|
||||
unsigned char a, b;
|
||||
a = *p++;
|
||||
b = *q++;
|
||||
if (a == 0 || a != b)
|
||||
return a - b;
|
||||
}
|
||||
}
|
||||
|
||||
void *memset(void *dst, int x, size_t n)
|
||||
{
|
||||
unsigned char *p;
|
||||
|
||||
for (p = dst; n; n--)
|
||||
*p++ = x;
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
unsigned char *p;
|
||||
const unsigned char *q;
|
||||
|
||||
for (p = dst, q = src; n; n--)
|
||||
*p++ = *q++;
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
unsigned char *us1 = (unsigned char *) s1;
|
||||
unsigned char *us2 = (unsigned char *) s2;
|
||||
while (n-- != 0) {
|
||||
if (*us1 != *us2)
|
||||
return (*us1 < *us2) ? -1 : +1;
|
||||
us1++;
|
||||
us2++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
15
wiipax/stub/string.h
Normal file
15
wiipax/stub/string.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _STRING_H_
|
||||
#define _STRING_H_
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
char *strcpy(char *, const char *);
|
||||
char *strncpy(char *, const char *, size_t);
|
||||
int strcmp(const char *, const char *);
|
||||
size_t strlen(const char *);
|
||||
size_t strnlen(const char *, size_t);
|
||||
void *memset(void *, int, size_t);
|
||||
void *memcpy(void *, const void *, size_t);
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
#endif
|
||||
40
wiipax/stub/sync.c
Normal file
40
wiipax/stub/sync.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "common.h"
|
||||
|
||||
void sync_before_read(void *p, u32 len)
|
||||
{
|
||||
u32 a, b;
|
||||
|
||||
a = (u32)p & ~0x1f;
|
||||
b = ((u32)p + len + 0x1f) & ~0x1f;
|
||||
|
||||
for ( ; a < b; a += 32)
|
||||
asm("dcbi 0,%0" : : "b"(a));
|
||||
|
||||
asm("sync ; isync");
|
||||
}
|
||||
|
||||
void sync_after_write(const void *p, u32 len)
|
||||
{
|
||||
u32 a, b;
|
||||
|
||||
a = (u32)p & ~0x1f;
|
||||
b = ((u32)p + len + 0x1f) & ~0x1f;
|
||||
|
||||
for ( ; a < b; a += 32)
|
||||
asm("dcbst 0,%0" : : "b"(a));
|
||||
|
||||
asm("sync ; isync");
|
||||
}
|
||||
|
||||
void sync_before_exec(const void *p, u32 len)
|
||||
{
|
||||
u32 a, b;
|
||||
|
||||
a = (u32)p & ~0x1f;
|
||||
b = ((u32)p + len + 0x1f) & ~0x1f;
|
||||
|
||||
for ( ; a < b; a += 32)
|
||||
asm("dcbst 0,%0 ; sync ; icbi 0,%0" : : "b"(a));
|
||||
|
||||
asm("sync ; isync");
|
||||
}
|
||||
27
wiipax/stub/time.c
Normal file
27
wiipax/stub/time.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "common.h"
|
||||
|
||||
// Timebase frequency is bus frequency / 4. Ignore roundoff, this
|
||||
// doesn't have to be very accurate.
|
||||
#define TICKS_PER_USEC (243/4)
|
||||
|
||||
static u32 mftb(void)
|
||||
{
|
||||
u32 x;
|
||||
|
||||
asm volatile("mftb %0" : "=r"(x));
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static void __delay(u32 ticks)
|
||||
{
|
||||
u32 start = mftb();
|
||||
|
||||
while (mftb() - start < ticks)
|
||||
;
|
||||
}
|
||||
|
||||
void udelay(u32 us)
|
||||
{
|
||||
__delay(TICKS_PER_USEC * us);
|
||||
}
|
||||
291
wiipax/stub/vsprintf.c
Normal file
291
wiipax/stub/vsprintf.c
Normal file
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* linux/lib/vsprintf.c
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
|
||||
/*
|
||||
* Wirzenius wrote this portably, Torvalds fucked it up :-)
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "string.h"
|
||||
|
||||
static inline int isdigit(int c)
|
||||
{
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
static inline int isxdigit(int c)
|
||||
{
|
||||
return (c >= '0' && c <= '9')
|
||||
|| (c >= 'a' && c <= 'f')
|
||||
|| (c >= 'A' && c <= 'F');
|
||||
}
|
||||
|
||||
static inline int islower(int c)
|
||||
{
|
||||
return c >= 'a' && c <= 'z';
|
||||
}
|
||||
|
||||
static inline int toupper(int c)
|
||||
{
|
||||
if (islower(c))
|
||||
c -= 'a'-'A';
|
||||
return c;
|
||||
}
|
||||
|
||||
static int skip_atoi(const char **s)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
while (isdigit(**s))
|
||||
i = i*10 + *((*s)++) - '0';
|
||||
return i;
|
||||
}
|
||||
|
||||
#define ZEROPAD 1 /* pad with zero */
|
||||
#define SIGN 2 /* unsigned/signed long */
|
||||
#define PLUS 4 /* show plus */
|
||||
#define SPACE 8 /* space if plus */
|
||||
#define LEFT 16 /* left justified */
|
||||
#define SPECIAL 32 /* 0x */
|
||||
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
|
||||
|
||||
#define do_div(n,base) ({ \
|
||||
int __res; \
|
||||
__res = ((unsigned long) n) % (unsigned) base; \
|
||||
n = ((unsigned long) n) / (unsigned) base; \
|
||||
__res; })
|
||||
|
||||
static char * number(char * str, long num, int base, int size, int precision
|
||||
,int type)
|
||||
{
|
||||
char c,sign,tmp[66];
|
||||
const char *digits="0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
int i;
|
||||
|
||||
if (type & LARGE)
|
||||
digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
if (type & LEFT)
|
||||
type &= ~ZEROPAD;
|
||||
if (base < 2 || base > 36)
|
||||
return 0;
|
||||
c = (type & ZEROPAD) ? '0' : ' ';
|
||||
sign = 0;
|
||||
if (type & SIGN) {
|
||||
if (num < 0) {
|
||||
sign = '-';
|
||||
num = -num;
|
||||
size--;
|
||||
} else if (type & PLUS) {
|
||||
sign = '+';
|
||||
size--;
|
||||
} else if (type & SPACE) {
|
||||
sign = ' ';
|
||||
size--;
|
||||
}
|
||||
}
|
||||
if (type & SPECIAL) {
|
||||
if (base == 16)
|
||||
size -= 2;
|
||||
else if (base == 8)
|
||||
size--;
|
||||
}
|
||||
i = 0;
|
||||
if (num == 0)
|
||||
tmp[i++]='0';
|
||||
else while (num != 0)
|
||||
tmp[i++] = digits[do_div(num,base)];
|
||||
if (i > precision)
|
||||
precision = i;
|
||||
size -= precision;
|
||||
if (!(type&(ZEROPAD+LEFT)))
|
||||
while(size-->0)
|
||||
*str++ = ' ';
|
||||
if (sign)
|
||||
*str++ = sign;
|
||||
if (type & SPECIAL) {
|
||||
if (base==8)
|
||||
*str++ = '0';
|
||||
else if (base==16) {
|
||||
*str++ = '0';
|
||||
*str++ = digits[33];
|
||||
}
|
||||
}
|
||||
if (!(type & LEFT))
|
||||
while (size-- > 0)
|
||||
*str++ = c;
|
||||
while (i < precision--)
|
||||
*str++ = '0';
|
||||
while (i-- > 0)
|
||||
*str++ = tmp[i];
|
||||
while (size-- > 0)
|
||||
*str++ = ' ';
|
||||
return str;
|
||||
}
|
||||
|
||||
int vsprintf(char *buf, const char *fmt, va_list args)
|
||||
{
|
||||
int len;
|
||||
unsigned long num;
|
||||
int i, base;
|
||||
char * str;
|
||||
const char *s;
|
||||
|
||||
int flags; /* flags to number() */
|
||||
|
||||
int field_width; /* width of output field */
|
||||
int precision; /* min. # of digits for integers; max
|
||||
number of chars for from string */
|
||||
int qualifier; /* 'h', 'l', or 'L' for integer fields */
|
||||
|
||||
for (str=buf ; *fmt ; ++fmt) {
|
||||
if (*fmt != '%') {
|
||||
*str++ = *fmt;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* process flags */
|
||||
flags = 0;
|
||||
repeat:
|
||||
++fmt; /* this also skips first '%' */
|
||||
switch (*fmt) {
|
||||
case '-': flags |= LEFT; goto repeat;
|
||||
case '+': flags |= PLUS; goto repeat;
|
||||
case ' ': flags |= SPACE; goto repeat;
|
||||
case '#': flags |= SPECIAL; goto repeat;
|
||||
case '0': flags |= ZEROPAD; goto repeat;
|
||||
}
|
||||
|
||||
/* get field width */
|
||||
field_width = -1;
|
||||
if (isdigit(*fmt))
|
||||
field_width = skip_atoi(&fmt);
|
||||
else if (*fmt == '*') {
|
||||
++fmt;
|
||||
/* it's the next argument */
|
||||
field_width = va_arg(args, int);
|
||||
if (field_width < 0) {
|
||||
field_width = -field_width;
|
||||
flags |= LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
/* get the precision */
|
||||
precision = -1;
|
||||
if (*fmt == '.') {
|
||||
++fmt;
|
||||
if (isdigit(*fmt))
|
||||
precision = skip_atoi(&fmt);
|
||||
else if (*fmt == '*') {
|
||||
++fmt;
|
||||
/* it's the next argument */
|
||||
precision = va_arg(args, int);
|
||||
}
|
||||
if (precision < 0)
|
||||
precision = 0;
|
||||
}
|
||||
|
||||
/* get the conversion qualifier */
|
||||
qualifier = -1;
|
||||
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') {
|
||||
qualifier = *fmt;
|
||||
++fmt;
|
||||
}
|
||||
|
||||
/* default base */
|
||||
base = 10;
|
||||
|
||||
switch (*fmt) {
|
||||
case 'c':
|
||||
if (!(flags & LEFT))
|
||||
while (--field_width > 0)
|
||||
*str++ = ' ';
|
||||
*str++ = (unsigned char) va_arg(args, int);
|
||||
while (--field_width > 0)
|
||||
*str++ = ' ';
|
||||
continue;
|
||||
|
||||
case 's':
|
||||
s = va_arg(args, char *);
|
||||
if (!s)
|
||||
s = "<NULL>";
|
||||
|
||||
len = strnlen(s, precision);
|
||||
|
||||
if (!(flags & LEFT))
|
||||
while (len < field_width--)
|
||||
*str++ = ' ';
|
||||
for (i = 0; i < len; ++i)
|
||||
*str++ = *s++;
|
||||
while (len < field_width--)
|
||||
*str++ = ' ';
|
||||
continue;
|
||||
|
||||
case 'p':
|
||||
if (field_width == -1) {
|
||||
field_width = 2*sizeof(void *);
|
||||
flags |= ZEROPAD;
|
||||
}
|
||||
str = number(str,
|
||||
(unsigned long) va_arg(args, void *), 16,
|
||||
field_width, precision, flags);
|
||||
continue;
|
||||
|
||||
|
||||
case 'n':
|
||||
if (qualifier == 'l') {
|
||||
long * ip = va_arg(args, long *);
|
||||
*ip = (str - buf);
|
||||
} else {
|
||||
int * ip = va_arg(args, int *);
|
||||
*ip = (str - buf);
|
||||
}
|
||||
continue;
|
||||
|
||||
case '%':
|
||||
*str++ = '%';
|
||||
continue;
|
||||
|
||||
/* integer number formats - set up the flags and "break" */
|
||||
case 'o':
|
||||
base = 8;
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
flags |= LARGE;
|
||||
case 'x':
|
||||
base = 16;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
case 'i':
|
||||
flags |= SIGN;
|
||||
case 'u':
|
||||
break;
|
||||
|
||||
default:
|
||||
*str++ = '%';
|
||||
if (*fmt)
|
||||
*str++ = *fmt;
|
||||
else
|
||||
--fmt;
|
||||
continue;
|
||||
}
|
||||
if (qualifier == 'l')
|
||||
num = va_arg(args, unsigned long);
|
||||
else if (qualifier == 'h') {
|
||||
num = (unsigned short) va_arg(args, int);
|
||||
if (flags & SIGN)
|
||||
num = (short) num;
|
||||
} else if (flags & SIGN)
|
||||
num = va_arg(args, int);
|
||||
else
|
||||
num = va_arg(args, unsigned int);
|
||||
str = number(str, num, base, field_width, precision, flags);
|
||||
}
|
||||
*str = '\0';
|
||||
return str-buf;
|
||||
}
|
||||
9
wiipax/stub/vsprintf.h
Normal file
9
wiipax/stub/vsprintf.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _VSPRINTF_H_
|
||||
#define _VSPRINTF_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
int vsprintf(char *buf, const char *fmt, va_list args);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user