Merge pull request #48 from Demki/master

add thumb/arm macros and change makefiles to reflect that.
This commit is contained in:
Cleverking2003
2020-05-01 09:18:07 +03:00
committed by GitHub
18 changed files with 35587 additions and 35585 deletions

View File

@@ -59,30 +59,30 @@ ARM7BIN := arm7/build/arm7.sbin
##################### Compiler Options #######################
MWCCVERSION := 2.0/base
MWCCVERSION = 2.0/base
CROSS := arm-none-eabi-
MWCCARM := tools/mwccarm/$(MWCCVERSION)/mwccarm.exe
MWCCARM = tools/mwccarm/$(MWCCVERSION)/mwccarm.exe
# Argh... due to EABI version shenanigans, we can't use GNU LD to link together
# MWCC built objects and GNU built ones. mwldarm, however, doesn't care, so we
# have to use mwldarm for now.
# TODO: Is there a hack workaround to let us go back to GNU LD? Ideally, the
# only dependency should be MWCCARM.
MWLDARM := tools/mwccarm/$(MWCCVERSION)/mwldarm.exe
MWASMARM := tools/mwccarm/$(MWCCVERSION)/mwasmarm.exe
MWLDARM = tools/mwccarm/$(MWCCVERSION)/mwldarm.exe
MWASMARM = tools/mwccarm/$(MWCCVERSION)/mwasmarm.exe
AS := $(WINE) $(MWASMARM)
CC := $(WINE) $(MWCCARM)
AS = $(WINE) $(MWASMARM)
CC = $(WINE) $(MWCCARM)
CPP := cpp -P
LD := $(WINE) $(MWLDARM)
LD = $(WINE) $(MWLDARM)
AR := $(CROSS)ar
OBJDUMP := $(CROSS)objdump
OBJCOPY := $(CROSS)objcopy
# ./tools/mwccarm/2.0/base/mwasmarm.exe -proc arm5te asm/arm9_thumb.s -o arm9.o
ASFLAGS = -proc arm5te
CFLAGS = -O4,p -proc v5te -thumb -fp soft -lang c99 -Cpp_exceptions off -ir include
CFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -ir include -ir include-mw
LDFLAGS = -map -nodead -w off -proc v5te -interworking -map -symtab -m _start
####################### Other Tools #########################

View File

@@ -58,32 +58,32 @@ O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
##################### Compiler Options #######################
MWCCVERSION := 2.0/base
MWCCVERSION = 2.0/base
TOOLS_DIR = ../tools
CROSS := arm-none-eabi-
MWCCARM := $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwccarm.exe
MWCCARM = $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwccarm.exe
# Argh... due to EABI version shenanigans, we can't use GNU LD to link together
# MWCC built objects and GNU built ones. mwldarm, however, doesn't care, so we
# have to use mwldarm for now.
# TODO: Is there a hack workaround to let us go back to GNU LD? Ideally, the
# only dependency should be MWCCARM.
MWLDARM := $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwldarm.exe
MWASMARM := $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwasmarm.exe
MWLDARM = $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwldarm.exe
MWASMARM = $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwasmarm.exe
MAKELSF := $(WINE) $(TOOLS_DIR)/bin/makelcf.exe
AS := $(WINE) $(MWASMARM)
CC := $(WINE) $(MWCCARM)
AS = $(WINE) $(MWASMARM)
CC = $(WINE) $(MWCCARM)
CPP := cpp -P
LD := $(WINE) $(MWLDARM)
LD = $(WINE) $(MWLDARM)
AR := $(CROSS)ar
OBJDUMP := $(CROSS)objdump
OBJCOPY := $(CROSS)objcopy
# ./tools/mwccarm/2.0/base/mwasmarm.exe -proc arm5te asm/arm7_thumb.s -o arm7.o
ASFLAGS = -proc arm4t -i ..
CFLAGS = -O4,p -proc v4t -thumb -fp soft -lang c99 -Cpp_exceptions off -ir ../include
CFLAGS = -O4,p -proc v4t -fp soft -lang c99 -Cpp_exceptions off -ir ../include -ir ../include-mw
LDFLAGS = -map -nodead -w off -proc v4t -interworking -map -symtab -m _start
####################### Other Tools #########################

View File

@@ -67,28 +67,28 @@ TOOLS_DIR = ../tools
CROSS := arm-none-eabi-
MWCCARM := $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwccarm.exe
MWCCARM = $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwccarm.exe
# Argh... due to EABI version shenanigans, we can't use GNU LD to link together
# MWCC built objects and GNU built ones. mwldarm, however, doesn't care, so we
# have to use mwldarm for now.
# TODO: Is there a hack workaround to let us go back to GNU LD? Ideally, the
# only dependency should be MWCCARM.
MWLDARM := $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwldarm.exe
MWASMARM := $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwasmarm.exe
MWLDARM = $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwldarm.exe
MWASMARM = $(TOOLS_DIR)/mwccarm/$(MWCCVERSION)/mwasmarm.exe
MAKELSF := $(WINE) $(TOOLS_DIR)/bin/makelcf.exe
MAKELSF_FLAGS := -DCONST_34=0x34 -DCONST_3F=0x3F
AS := $(WINE) $(MWASMARM)
CC := $(WINE) $(MWCCARM)
AS = $(WINE) $(MWASMARM)
CC = $(WINE) $(MWCCARM)
CPP := cpp -P
LD := $(WINE) $(MWLDARM)
LD = $(WINE) $(MWLDARM)
AR := $(CROSS)ar
OBJDUMP := $(CROSS)objdump
OBJCOPY := $(CROSS)objcopy
# ./tools/mwccarm/2.0/base/mwasmarm.exe -proc arm5te asm/arm9_thumb.s -o arm9.o
ASFLAGS = -proc arm5te -i ..
CFLAGS = -O4,p -proc v5te -thumb -fp soft -lang c99 -Cpp_exceptions off -ir ../include
CFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -ir ../include -ir ../include-mw -interworking
LDFLAGS = -map -nodead -w off -proc v5te -interworking -map -symtab -m _start
####################### Other Tools #########################
@@ -146,8 +146,8 @@ ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS))
######################## Special Rules ########################
# TODO: Move out to lib/Makefile
build/lib/src/%.o: CC := $(WINE) $(TOOLS_DIR)/mwccarm/1.2/sp2p3/mwccarm.exe
build/lib/src/%.o: CFLAGS := -O4,p -proc arm9tdmi -interworking -ir include -ir ../include -lang c99
build/lib/src/%.o: MWCCVERSION = 1.2/sp2p3
build/src/FUN_020910A4.o: MWCCVERSION = 1.2/sp2p3
####################### Everything Else ######################

View File

@@ -117,6 +117,8 @@ SECTIONS {
scrcmd.o (.text)
unk_02046030.o (.text)
unk_0208AC14.o (.text)
FUN_020910A4.o (.text)
unk_020910EC.o (.text)
unk_020AF030.o (.text)
/* Nitro SDK */
FX_mtx22.o (.text)

File diff suppressed because it is too large Load Diff

35502
arm9/asm/unk_020910EC.s Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -3802,3 +3802,6 @@
.extern thunk_FUN_020afda0_2
.extern thunk_FUN_020b5040
.extern wcslen
.extern FUN_0209105C
.extern FUN_020910A4

View File

@@ -1,7 +1,7 @@
//
// Created by red031000 on 2020-04-27.
//
#include "function_target.h"
#include "consts.h"
#include "os_arena.h"
#include "os_protectionRegion.h"
@@ -16,7 +16,7 @@ extern void SDK_SECTION_ARENA_DTCM_START(); // TODO: technically this should be
extern void SDK_IRQ_STACKSIZE(); // TODO: technically this should be defined in the lcf
extern void SDK_SYS_STACKSIZE(); // TODO: technically this should be defined in the lcf
void OS_InitArena() {
ARM_FUNC void OS_InitArena() {
if (OSi_Initialized) {
return;
}
@@ -41,7 +41,7 @@ void OS_InitArena() {
OS_SetArenaLo(OS_ARENA_WRAM_MAIN, OS_GetInitArenaLo(OS_ARENA_WRAM_MAIN));
}
void OS_InitArenaEx() {
ARM_FUNC void OS_InitArenaEx() {
OS_SetArenaHi(2, OS_GetInitArenaHi(OS_ARENA_MAINEX));
OS_SetArenaLo(2, OS_GetInitArenaLo(OS_ARENA_MAINEX));
@@ -51,15 +51,15 @@ void OS_InitArenaEx() {
}
}
void* OS_GetArenaHi(OSArenaId id) {
ARM_FUNC void* OS_GetArenaHi(OSArenaId id) {
return OSi_GetArenaInfo().hi[id];
}
void* OS_GetArenaLo(OSArenaId id) {
ARM_FUNC void* OS_GetArenaLo(OSArenaId id) {
return OSi_GetArenaInfo().lo[id];
}
void* OS_GetInitArenaHi(OSArenaId id) {
ARM_FUNC void* OS_GetInitArenaHi(OSArenaId id) {
switch (id) {
case OS_ARENA_MAIN:
return (void *)OSi_MAIN_ARENA_HI_DEFAULT;
@@ -97,7 +97,7 @@ void* OS_GetInitArenaHi(OSArenaId id) {
}
}
void* OS_GetInitArenaLo(OSArenaId id) {
ARM_FUNC void* OS_GetInitArenaLo(OSArenaId id) {
switch (id) {
case OS_ARENA_MAIN:
return (void *)SDK_MAIN_ARENA_LO;
@@ -120,15 +120,15 @@ void* OS_GetInitArenaLo(OSArenaId id) {
}
}
void OS_SetArenaHi(OSArenaId id, void* newHi) {
ARM_FUNC void OS_SetArenaHi(OSArenaId id, void* newHi) {
OSi_GetArenaInfo().hi[id] = newHi;
}
void OS_SetArenaLo(OSArenaId id, void* newLo) {
ARM_FUNC void OS_SetArenaLo(OSArenaId id, void* newLo) {
OSi_GetArenaInfo().lo[id] = newLo;
}
void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align) {
ARM_FUNC void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align) {
void* ptr;
u8* arenaLo;
ptr = OS_GetArenaLo(id);
@@ -146,7 +146,7 @@ void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align) {
return ptr;
}
void* OS_AllocFromArenaHi(OSArenaId id, u32 size, u32 align) {
ARM_FUNC void* OS_AllocFromArenaHi(OSArenaId id, u32 size, u32 align) {
void* ptr;
u8* arenaHi;

View File

@@ -2,11 +2,11 @@
u32 UNK_021D7500[8];
void MOD01_021D74E0(void)
THUMB_FUNC void MOD01_021D74E0(void)
{
UNK_021D7500[1]++;
}
void (*UNK_021D74F0[4])(void) = {
THUMB_FUNC void (*UNK_021D74F0[4])(void) = {
MOD01_021D74E0
};

View File

@@ -3,7 +3,7 @@
extern struct Unk2106FA0 gBacklightTop;
void FUN_02000DF4(void)
THUMB_FUNC void FUN_02000DF4(void)
{
gBacklightTop.unk8 = -1;
gBacklightTop.unkC = 0;

10
arm9/src/FUN_020910A4.c Normal file
View File

@@ -0,0 +1,10 @@
#include "global.h"
void * (* gUnk021C8C70)(u32);
ARM_FUNC void* FUN_020910A4(u32 size)
{
if (gUnk021C8C70 != NULL)
return gUnk021C8C70(size);
return OS_AllocFromHeap(OS_ARENA_MAIN, -1, size);
}

View File

@@ -3,7 +3,6 @@
extern struct Unk2106FA0 gBacklightTop;
extern struct Unk2106FA0 gBacklightTop_2; // same as the first one, it's referenced twice in the constant pool...
extern struct Unk2106FA0 gUnknown2106FB8;
extern struct Unk21C48B8 gUnknown21C48B8;
extern s32 gUnk027FFC20;
@@ -24,7 +23,7 @@ extern struct Unk21DBE18 gUnk021DBE18;
extern struct Unk21DBE18 gUnk021D76C8;
void NitroMain(void)
THUMB_FUNC void NitroMain(void)
{
InitSystemForTheGame();
InitGraphicMemory();

View File

@@ -3,7 +3,7 @@
u16 ScriptReadHalfword(struct ScriptContext *ctx);
void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTableEnd)
THUMB_FUNC void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTableEnd)
{
u32 i;
@@ -23,33 +23,33 @@ void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTable
ctx->unk74 = 0;
}
u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr)
THUMB_FUNC u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr)
{
ctx->scriptPtr = ptr;
ctx->mode = 1;
return 1;
}
void SetupNativeScript(struct ScriptContext *ctx, u8 (*ptr)(struct ScriptContext *))
THUMB_FUNC void SetupNativeScript(struct ScriptContext *ctx, u8 (*ptr)(struct ScriptContext *))
{
ctx->mode = 2;
ctx->nativePtr = ptr;
}
void StopScript(struct ScriptContext *ctx)
THUMB_FUNC void StopScript(struct ScriptContext *ctx)
{
ctx->mode = 0;
ctx->scriptPtr = 0;
}
void FUN_02038B6C(struct ScriptContext *ctx, int r1)
THUMB_FUNC void FUN_02038B6C(struct ScriptContext *ctx, int r1)
{
ctx->unk74 = r1;
}
extern void ErrorHandling(void);
u8 RunScriptCommand(struct ScriptContext *ctx)
THUMB_FUNC u8 RunScriptCommand(struct ScriptContext *ctx)
{
if (ctx->mode == 0)
return FALSE;
@@ -97,7 +97,7 @@ u8 RunScriptCommand(struct ScriptContext *ctx)
return TRUE;
}
u8 ScriptPush(struct ScriptContext *ctx, const u8 *ptr)
THUMB_FUNC u8 ScriptPush(struct ScriptContext *ctx, const u8 *ptr)
{
if (ctx->stackDepth + 1 >= 20)
{
@@ -111,7 +111,7 @@ u8 ScriptPush(struct ScriptContext *ctx, const u8 *ptr)
}
}
const u8 *ScriptPop(struct ScriptContext *ctx)
THUMB_FUNC const u8 *ScriptPop(struct ScriptContext *ctx)
{
if (ctx->stackDepth == 0)
return NULL;
@@ -120,31 +120,31 @@ const u8 *ScriptPop(struct ScriptContext *ctx)
return ctx->stack[ctx->stackDepth];
}
void ScriptJump(struct ScriptContext *ctx, const u8 *ptr)
THUMB_FUNC void ScriptJump(struct ScriptContext *ctx, const u8 *ptr)
{
ctx->scriptPtr = ptr;
}
u8 ScriptCall(struct ScriptContext *ctx, const u8 *ptr)
THUMB_FUNC u8 ScriptCall(struct ScriptContext *ctx, const u8 *ptr)
{
u8 ret = ScriptPush(ctx, ctx->scriptPtr);
ctx->scriptPtr = ptr;
return ret;
}
void ScriptReturn(struct ScriptContext *ctx)
THUMB_FUNC void ScriptReturn(struct ScriptContext *ctx)
{
ctx->scriptPtr = ScriptPop(ctx);
}
u16 ScriptReadHalfword(struct ScriptContext *ctx)
THUMB_FUNC u16 ScriptReadHalfword(struct ScriptContext *ctx)
{
u16 value = *(ctx->scriptPtr++);
value += *(ctx->scriptPtr++) << 8;
return value;
}
u32 ScriptReadWord(struct ScriptContext *ctx)
THUMB_FUNC u32 ScriptReadWord(struct ScriptContext *ctx)
{
u32 value0 = *(ctx->scriptPtr++);
u32 value1 = *(ctx->scriptPtr++);

View File

@@ -34,7 +34,7 @@ s32 gPowersOfTen[] = {
static const u16 EOS = 0xFFFF;
void StringCopy(u16 *dest, const u16 *src)
THUMB_FUNC void StringCopy(u16 *dest, const u16 *src)
{
u16 c = *src;
while (c != EOS) {
@@ -46,7 +46,7 @@ void StringCopy(u16 *dest, const u16 *src)
*dest = EOS;
}
u16 *StringCopyN(u16 *dest, const u16 *src, u32 num)
THUMB_FUNC u16 *StringCopyN(u16 *dest, const u16 *src, u32 num)
{
u32 copied = 0;
if (num > copied) {
@@ -62,7 +62,7 @@ u16 *StringCopyN(u16 *dest, const u16 *src, u32 num)
return dest + num;
}
u32 StringLength(const u16 *s)
THUMB_FUNC u32 StringLength(const u16 *s)
{
u16 c = *s;
u32 len = 0;
@@ -74,7 +74,7 @@ u32 StringLength(const u16 *s)
return len;
}
BOOL StringNotEqual(const u16 *s1, const u16 *s2)
THUMB_FUNC BOOL StringNotEqual(const u16 *s1, const u16 *s2)
{
for (; *s1 == *s2; s1++, s2++) {
if (*s1 == EOS)
@@ -83,7 +83,7 @@ BOOL StringNotEqual(const u16 *s1, const u16 *s2)
return TRUE;
}
BOOL StringNotEqualN(const u16 *s1, const u16 *s2, u32 num)
THUMB_FUNC BOOL StringNotEqualN(const u16 *s1, const u16 *s2, u32 num)
{
u16 c1, c2;
c2 = *s2;
@@ -104,7 +104,7 @@ BOOL StringNotEqualN(const u16 *s1, const u16 *s2, u32 num)
return TRUE;
}
u16 *StringFill(u16 *dest, u16 value, u32 num)
THUMB_FUNC u16 *StringFill(u16 *dest, u16 value, u32 num)
{
u32 copied = 0;
if (num > copied) {
@@ -118,7 +118,7 @@ u16 *StringFill(u16 *dest, u16 value, u32 num)
return dest + copied;
}
u16 *StringFillEOS(u16 *dest, u32 num)
THUMB_FUNC u16 *StringFillEOS(u16 *dest, u32 num)
{
return StringFill(dest, EOS, num);
}
@@ -131,7 +131,7 @@ enum PrintingMode {
const u16 NON_DIGIT = 0xE2;
u16 *ConvertUIntToDecimalString(u16 *dest, u32 value, enum PrintingMode mode, u32 n)
THUMB_FUNC u16 *ConvertUIntToDecimalString(u16 *dest, u32 value, enum PrintingMode mode, u32 n)
{
for (u32 x = gPowersOfTen[n - 1]; x != 0; x = x / 10) {
u16 res = value / x;

View File

@@ -18,9 +18,9 @@ Unk_02106A04 = 0x02106A04;
// .bss
gBacklightTop = 0x02106FA0;
gBacklightTop_2 = 0x02106FA0;
gUnknown2106FB8 = 0x02106FB8;
gUnknown21C48B8 = 0x021C48B8;
gUnk021C4918 = 0x021C4918;
gUnk021C8C70 = 0x021C8C70;
OSi_IrqCallbackInfo = 0x021D341C;
isInitialized = 0x021D347C;
OSi_StackForDestructor = 0x021D3480;

View File

@@ -0,0 +1,7 @@
#ifndef GUARD_FUNCTION_TARGET_H
#define GUARD_FUNCTION_TARGET_H
#define ARM_FUNC _Pragma("thumb off")
#define THUMB_FUNC _Pragma("thumb on")
#endif //GUARD_FUNCTION_TARGET_H

View File

@@ -1,6 +1,7 @@
#ifndef GUARD_GLOBAL_H
#define GUARD_GLOBAL_H
#include "function_target.h"
#include "nitro/nitro.h"
#endif //GUARD_GLOBAL_H

View File

@@ -16,7 +16,6 @@ Unk_02106A04 = 0x02106A04;
// .bss
gBacklightTop = 0x02106FA0;
gBacklightTop_2 = 0x02106FA0;
gUnknown2106FB8 = 0x02106FB8;
gUnknown21C48B8 = 0x021C48B8;
gUnk021C4918 = 0x021C4918;
OSi_IrqCallbackInfo = 0x021D341C;