Added working relocations on ARM (3ds)
This commit is contained in:
parent
e8a05caa89
commit
ed9f968dd4
3 changed files with 27 additions and 63 deletions
|
@ -9,12 +9,12 @@
|
||||||
#define Elf_Ehdr Elf32_Ehdr
|
#define Elf_Ehdr Elf32_Ehdr
|
||||||
#define Elf_Phdr Elf32_Phdr
|
#define Elf_Phdr Elf32_Phdr
|
||||||
#endif
|
#endif
|
||||||
char *lfb=(char*)0x18346500;
|
#if defined(ARM9) || defined(ARM11)
|
||||||
#ifdef ARM9
|
#define PAGE_SIZE 0x10000
|
||||||
#define DIAGPXL(i) (lfb[6*(i)]=lfb[6*(i)+1]=lfb[6*(i)+2]=0xFF)
|
|
||||||
#else
|
#else
|
||||||
#define DIAGPXL(i) (0)
|
#define PAGE_SIZE 0x1000
|
||||||
#endif
|
#endif
|
||||||
|
char *lfb=(char*)0x18346500;
|
||||||
/** \brief beginning of constructor table */
|
/** \brief beginning of constructor table */
|
||||||
extern "C" void(*start_ctors)();
|
extern "C" void(*start_ctors)();
|
||||||
/** \brief end of constructor table */
|
/** \brief end of constructor table */
|
||||||
|
@ -45,17 +45,8 @@ auto load(Elf_Ehdr* file) -> void(**(*)(void*))() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
MTGos::Base::Output out;
|
MTGos::Base::Output out;
|
||||||
void debugNumber(uintptr_t i, int start) {
|
|
||||||
while(i) {
|
|
||||||
if(i&1)
|
|
||||||
lfb[(start*6)+5]=0xFF;
|
|
||||||
i>>=1;
|
|
||||||
lfb[(start*6)+1]=0x50;
|
|
||||||
start++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void adjustVTable(uintptr_t** obj, uintptr_t mod, int vtableSize) {
|
void adjustVTable(uintptr_t** obj, uintptr_t mod, int vtableSize) {
|
||||||
mod+=0x1000;
|
mod+=PAGE_SIZE;
|
||||||
for(int i=0;i<vtableSize;i++) {
|
for(int i=0;i<vtableSize;i++) {
|
||||||
(*obj)[i]+=mod;
|
(*obj)[i]+=mod;
|
||||||
}
|
}
|
||||||
|
@ -65,27 +56,15 @@ 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);
|
|
||||||
//for(void(**i)()=&start_ctors;i<&end_ctors;i++)
|
//for(void(**i)()=&start_ctors;i<&end_ctors;i++)
|
||||||
// (*i)(); //Calling constructors
|
// (*i)(); //Calling constructors
|
||||||
for(int i=0;i<1024;i++) {
|
for(int i=0;i<1024;i++) {
|
||||||
DIAGPXL(14);
|
|
||||||
if(!modtable[i])
|
if(!modtable[i])
|
||||||
break;
|
break;
|
||||||
DIAGPXL(15);
|
|
||||||
void(**(*fptr)(void*))() = load((Elf_Ehdr*) modtable[i]);
|
void(**(*fptr)(void*))() = load((Elf_Ehdr*) modtable[i]);
|
||||||
if(!fptr)
|
if(!fptr)
|
||||||
continue;
|
continue;
|
||||||
// fptr=(void(**(*)(void*))())((uintptr_t)fptr-8);
|
|
||||||
DIAGPXL(16);
|
|
||||||
// debugNumber((uintptr_t)modtable[i],50+32);
|
|
||||||
DIAGPXL(17);
|
|
||||||
void(**table)()=fptr(modtable[i]);
|
void(**table)()=fptr(modtable[i]);
|
||||||
//debugNumber((uintptr_t)table,50+96);
|
|
||||||
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);
|
||||||
|
@ -98,21 +77,15 @@ extern "C" void _start(void ** modtable) {
|
||||||
#endif
|
#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]+PAGE_SIZE;
|
||||||
tbl[1]+=(uintptr_t)modtable[i]+0x1000;
|
tbl[1]+=(uintptr_t)modtable[i]+PAGE_SIZE;
|
||||||
tbl[2]+=(uintptr_t)modtable[i]+0x1000;
|
tbl[2]+=(uintptr_t)modtable[i]+PAGE_SIZE;
|
||||||
DIAGPXL(500);
|
|
||||||
ModType type=((getType_type)table[0])(); //Get module type
|
ModType type=((getType_type)table[0])(); //Get module type
|
||||||
DIAGPXL(501);
|
if(type!=ModType::output_text)
|
||||||
//if(type!=ModType::output_text)
|
continue;
|
||||||
//continue;
|
|
||||||
DIAGPXL(502);
|
|
||||||
size_t size=((sizeof_type)table[1])(); //Get module size
|
size_t size=((sizeof_type)table[1])(); //Get module size
|
||||||
debugNumber((uintptr_t)size,50);
|
((spawnAt_type)table[2])((void*)&out); //Spawn module
|
||||||
DIAGPXL(503);
|
|
||||||
((spawnAt_type)table[2])((void*)&out);
|
|
||||||
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
|
||||||
|
|
|
@ -10,7 +10,6 @@ uint8_t* dmem = (uint8_t*)0x18300000;
|
||||||
uint8_t* vmem = (uint8_t*)0x18346500;
|
uint8_t* vmem = (uint8_t*)0x18346500;
|
||||||
#endif
|
#endif
|
||||||
static int x=0,y=0;
|
static int x=0,y=0;
|
||||||
#define DIAGPXL(i) (debugNumber(i,i))
|
|
||||||
#define CHR_HEIGHT 8
|
#define CHR_HEIGHT 8
|
||||||
#define CHR_WIDTH 8
|
#define CHR_WIDTH 8
|
||||||
#define HEIGHT 29
|
#define HEIGHT 29
|
||||||
|
@ -20,16 +19,6 @@ static int x=0,y=0;
|
||||||
#define WIDTH 40
|
#define WIDTH 40
|
||||||
#endif
|
#endif
|
||||||
#define BYTESPP 3
|
#define BYTESPP 3
|
||||||
void debugNumber(unsigned int i, int start) {
|
|
||||||
return;
|
|
||||||
while(i) {
|
|
||||||
if(i&1)
|
|
||||||
dmem[(start*6)+5]=0xFF;
|
|
||||||
i>>=1;
|
|
||||||
dmem[(start*6)+1]=0x50;
|
|
||||||
start++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
namespace MTGos {
|
namespace MTGos {
|
||||||
namespace {
|
namespace {
|
||||||
/**
|
/**
|
||||||
|
@ -38,8 +27,15 @@ namespace {
|
||||||
*/
|
*/
|
||||||
class Screen: public Base::Output {
|
class Screen: public Base::Output {
|
||||||
public:
|
public:
|
||||||
Screen() {DIAGPXL(31);}
|
Screen() {}
|
||||||
auto scroll() -> void {
|
auto scroll() -> void {
|
||||||
|
#ifndef ARM9
|
||||||
|
uint8_t* vmem = (uint8_t*)0x18300000;
|
||||||
|
uint8_t* dmem = (uint8_t*)0x18346500;
|
||||||
|
#else
|
||||||
|
uint8_t* dmem = (uint8_t*)0x18300000;
|
||||||
|
uint8_t* vmem = (uint8_t*)0x18346500;
|
||||||
|
#endif
|
||||||
for(int p=0;p<HEIGHT*WIDTH*CHR_HEIGHT*CHR_WIDTH*BYTESPP;p++)
|
for(int p=0;p<HEIGHT*WIDTH*CHR_HEIGHT*CHR_WIDTH*BYTESPP;p++)
|
||||||
vmem[p]=vmem[p+WIDTH*CHR_WIDTH*BYTESPP];
|
vmem[p]=vmem[p+WIDTH*CHR_WIDTH*BYTESPP];
|
||||||
for(int p=HEIGHT*WIDTH*CHR_HEIGHT*CHR_WIDTH*BYTESPP; p<(HEIGHT*WIDTH+WIDTH)*CHR_HEIGHT*CHR_WIDTH*BYTESPP; p++)
|
for(int p=HEIGHT*WIDTH*CHR_HEIGHT*CHR_WIDTH*BYTESPP; p<(HEIGHT*WIDTH+WIDTH)*CHR_HEIGHT*CHR_WIDTH*BYTESPP; p++)
|
||||||
|
@ -48,13 +44,14 @@ public:
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
virtual auto putChar(int c) -> void{
|
virtual auto putChar(int c) -> void{
|
||||||
|
#ifndef ARM9
|
||||||
|
uint8_t* vmem = (uint8_t*)0x18300000;
|
||||||
|
uint8_t* dmem = (uint8_t*)0x18346500;
|
||||||
|
#else
|
||||||
|
uint8_t* dmem = (uint8_t*)0x18300000;
|
||||||
|
uint8_t* vmem = (uint8_t*)0x18346500;
|
||||||
|
#endif
|
||||||
c&=0xFF;
|
c&=0xFF;
|
||||||
debugNumber((unsigned int)c,500);
|
|
||||||
for(int i=0;i<8;i++) {
|
|
||||||
debugNumber((unsigned int)font[c][i],532+8*i);
|
|
||||||
}
|
|
||||||
debugNumber((unsigned int)x,532+8*8);
|
|
||||||
debugNumber((unsigned int)y,532+8*8+32);
|
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case '\n':
|
case '\n':
|
||||||
x=0; y++;
|
x=0; y++;
|
||||||
|
@ -70,7 +67,6 @@ private:
|
||||||
x--;
|
x--;
|
||||||
break;
|
break;
|
||||||
case '\0':
|
case '\0':
|
||||||
DIAGPXL(32);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for(int cx=0;cx<CHR_WIDTH;cx++) {
|
for(int cx=0;cx<CHR_WIDTH;cx++) {
|
||||||
|
@ -93,7 +89,6 @@ private:
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
debugNumber((unsigned int)y,532+8*8+64);
|
|
||||||
if(y>HEIGHT)
|
if(y>HEIGHT)
|
||||||
scroll();
|
scroll();
|
||||||
}
|
}
|
||||||
|
@ -118,16 +113,12 @@ table_type getTable() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
auto getType() -> ModType {
|
auto getType() -> ModType {
|
||||||
DIAGPXL(24);
|
|
||||||
return ModType::output_text;
|
return ModType::output_text;
|
||||||
}
|
}
|
||||||
auto spawnAt(void* pos) -> bool {
|
auto spawnAt(void* pos) -> bool {
|
||||||
debugNumber((unsigned int)pos,82);
|
|
||||||
DIAGPXL(530);
|
|
||||||
new(pos) MTGos::Screen;
|
new(pos) MTGos::Screen;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
auto size_of() -> size_t {
|
auto size_of() -> size_t {
|
||||||
DIAGPXL(26);
|
|
||||||
return sizeof(MTGos::Screen);
|
return sizeof(MTGos::Screen);
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue