3ds, however, won't work

This commit is contained in:
Morten Delenk 2016-08-14 20:04:41 +02:00
parent d916802eb7
commit e8a05caa89
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
6 changed files with 44 additions and 33 deletions

View file

@ -1,4 +1,4 @@
arch = x86_64 arch = 3ds
subvar = 9 subvar = 9
MODE = debug MODE = debug
export PATH := $(HOME)/opt/bin:$(PATH) export PATH := $(HOME)/opt/bin:$(PATH)

View file

@ -10,7 +10,7 @@
#define Elf_Phdr Elf32_Phdr #define Elf_Phdr Elf32_Phdr
#endif #endif
char *lfb=(char*)0x18346500; char *lfb=(char*)0x18346500;
#ifndef ARM9 #ifdef ARM9
#define DIAGPXL(i) (lfb[6*(i)]=lfb[6*(i)+1]=lfb[6*(i)+2]=0xFF) #define DIAGPXL(i) (lfb[6*(i)]=lfb[6*(i)+1]=lfb[6*(i)+2]=0xFF)
#else #else
#define DIAGPXL(i) (0) #define DIAGPXL(i) (0)
@ -65,6 +65,9 @@ void adjustVTable(uintptr_t** obj, uintptr_t mod, int vtableSize) {
* \brief Initializes the kernel * \brief Initializes the kernel
*/ */
extern "C" void _start(void ** modtable) { extern "C" void _start(void ** modtable) {
#ifdef ARM11
for(;;);
#endif
DIAGPXL(13); DIAGPXL(13);
//for(void(**i)()=&start_ctors;i<&end_ctors;i++) //for(void(**i)()=&start_ctors;i<&end_ctors;i++)
// (*i)(); //Calling constructors // (*i)(); //Calling constructors
@ -78,30 +81,38 @@ extern "C" void _start(void ** modtable) {
continue; continue;
// fptr=(void(**(*)(void*))())((uintptr_t)fptr-8); // fptr=(void(**(*)(void*))())((uintptr_t)fptr-8);
DIAGPXL(16); DIAGPXL(16);
debugNumber((uintptr_t)fptr,50);
// debugNumber((uintptr_t)modtable[i],50+32); // debugNumber((uintptr_t)modtable[i],50+32);
DIAGPXL(17); DIAGPXL(17);
void(**table)()=fptr(modtable[i]); void(**table)()=fptr(modtable[i]);
//debugNumber((uintptr_t)table,50+96);
DIAGPXL(18); DIAGPXL(18);
#ifndef __LP64__ #ifndef __LP64__
//Relocate table //Relocate table
table=(void(**)())((uintptr_t)table+(uintptr_t)modtable[i]+0x1000); table=(void(**)())((uintptr_t)table+(uintptr_t)modtable[i]+0x1000);
#endif
#ifdef ARM9
table = (void(**)())0x27FFFFE8;
#else
#ifdef ARM11
table = (void(**)())0x27FFFFF4;
#endif
#endif #endif
//Relocate table contents //Relocate table contents
uintptr_t* tbl=(uintptr_t*)table; uintptr_t* tbl=(uintptr_t*)table;;
tbl[0]+=(uintptr_t)modtable[i]+0x1000; tbl[0]+=(uintptr_t)modtable[i]+0x1000;
tbl[1]+=(uintptr_t)modtable[i]+0x1000; tbl[1]+=(uintptr_t)modtable[i]+0x1000;
tbl[2]+=(uintptr_t)modtable[i]+0x1000; tbl[2]+=(uintptr_t)modtable[i]+0x1000;
debugNumber((uintptr_t)table[0],50+32); DIAGPXL(500);
ModType type=((getType_type)table[0])(); //Get module type ModType type=((getType_type)table[0])(); //Get module type
DIAGPXL(19); DIAGPXL(501);
if(type!=ModType::output_text) //if(type!=ModType::output_text)
continue; //continue;
DIAGPXL(20); DIAGPXL(502);
size_t size=((sizeof_type)table[1])(); //Get module size size_t size=((sizeof_type)table[1])(); //Get module size
DIAGPXL(21); debugNumber((uintptr_t)size,50);
DIAGPXL(503);
((spawnAt_type)table[2])((void*)&out); ((spawnAt_type)table[2])((void*)&out);
DIAGPXL(22); DIAGPXL(504);
adjustVTable((uintptr_t**) &out, (uintptr_t)modtable[i], 1); adjustVTable((uintptr_t**) &out, (uintptr_t)modtable[i], 1);
out << "HI!\nbye!\n"; out << "HI!\nbye!\n";
#ifdef ARM9 #ifdef ARM9
@ -109,8 +120,6 @@ extern "C" void _start(void ** modtable) {
#else #else
out << "Here arm11!\n"; out << "Here arm11!\n";
#endif #endif
char* x=(char*)0xB80000;
x[0]='H';
} }
for(void(**i)()=&start_dtors;i<&end_dtors;i++) for(void(**i)()=&start_dtors;i<&end_dtors;i++)
(*i)(); //Calling destructors (*i)(); //Calling destructors

View file

@ -2,7 +2,7 @@
#include <base/output.hpp> #include <base/output.hpp>
#include <modstubs.h> #include <modstubs.h>
#include "stdfnt.h" #include "stdfnt.h"
#ifdef ARM9 #ifndef ARM9
uint8_t* vmem = (uint8_t*)0x18300000; uint8_t* vmem = (uint8_t*)0x18300000;
uint8_t* dmem = (uint8_t*)0x18346500; uint8_t* dmem = (uint8_t*)0x18346500;
#else #else
@ -14,7 +14,7 @@ static int x=0,y=0;
#define CHR_HEIGHT 8 #define CHR_HEIGHT 8
#define CHR_WIDTH 8 #define CHR_WIDTH 8
#define HEIGHT 29 #define HEIGHT 29
#ifdef ARM9 #ifndef ARM9
#define WIDTH 50 #define WIDTH 50
#else #else
#define WIDTH 40 #define WIDTH 40
@ -100,12 +100,22 @@ private:
}; };
} }
} }
void(*tbl[3])()={(void(*)())&getType,(void(*)())&size_of,(void(*)())&spawnAt}; //void(*tbl[3])()={(void(*)())&getType,(void(*)())&size_of,(void(*)())&spawnAt};
table_type getTable() { table_type getTable() {
x=y=0; #ifdef ARM9
// doCtors(); void(**tbl)() = (void(**)())0x27FFFFE8;
DIAGPXL(23); #else
return (table_type)&tbl; void(**tbl)() = (void(**)())0x27FFFFF4;
#endif
tbl[0]=(void(*)())&getType;
tbl[1]=(void(*)())&size_of;
tbl[2]=(void(*)())&spawnAt;
doCtors();
#ifdef ARM9
return (void(**)())0x27FFFFE8;
#else
return (void(**)())0x27FFFFF4;
#endif
} }
auto getType() -> ModType { auto getType() -> ModType {
DIAGPXL(24); DIAGPXL(24);
@ -113,7 +123,7 @@ auto getType() -> ModType {
} }
auto spawnAt(void* pos) -> bool { auto spawnAt(void* pos) -> bool {
debugNumber((unsigned int)pos,82); debugNumber((unsigned int)pos,82);
DIAGPXL(30); DIAGPXL(530);
new(pos) MTGos::Screen; new(pos) MTGos::Screen;
return true; return true;
} }

View file

@ -8,8 +8,6 @@ SECTIONS
.text : { .text : {
*(.text) *(.text)
*(.text.*) *(.text.*)
}
.data : {
start_ctors = .; start_ctors = .;
KEEP(*( .init_array )); KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* ))); KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
@ -20,22 +18,14 @@ SECTIONS
end_dtors = .; end_dtors = .;
*(.data) *(.data)
*(.data.*) *(.data.*)
}
.rodata : {
*(.rodata) *(.rodata)
}
.bss : {
*(.bss) *(.bss)
*(COMMON) *(COMMON)
}
.plt : {
*(.plt) *(.plt)
}
.rel.plt : {
*(.rel.plt) *(.rel.plt)
}
.rel.dyn : {
*(.rel.dyn) *(.rel.dyn)
*(.got)
*(.got.plt)
} }
module_end = .; module_end = .;
} }

View file

@ -22,6 +22,8 @@ SECTIONS
*(.plt) *(.plt)
*(.rel.plt) *(.rel.plt)
*(.rel.dyn) *(.rel.dyn)
*(.got)
*(.got.plt)
} }
module_end = .; module_end = .;
} }

BIN
mount/arm9loaderhax.bin Executable file

Binary file not shown.