Added working relocations on ARM (3ds)

This commit is contained in:
Morten Delenk 2016-08-20 10:56:13 +02:00
parent e8a05caa89
commit ed9f968dd4
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
3 changed files with 27 additions and 63 deletions

View file

@ -9,12 +9,12 @@
#define Elf_Ehdr Elf32_Ehdr
#define Elf_Phdr Elf32_Phdr
#endif
char *lfb=(char*)0x18346500;
#ifdef ARM9
#define DIAGPXL(i) (lfb[6*(i)]=lfb[6*(i)+1]=lfb[6*(i)+2]=0xFF)
#if defined(ARM9) || defined(ARM11)
#define PAGE_SIZE 0x10000
#else
#define DIAGPXL(i) (0)
#define PAGE_SIZE 0x1000
#endif
char *lfb=(char*)0x18346500;
/** \brief beginning of constructor table */
extern "C" void(*start_ctors)();
/** \brief end of constructor table */
@ -45,17 +45,8 @@ auto load(Elf_Ehdr* file) -> void(**(*)(void*))() {
return nullptr;
}
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) {
mod+=0x1000;
mod+=PAGE_SIZE;
for(int i=0;i<vtableSize;i++) {
(*obj)[i]+=mod;
}
@ -65,27 +56,15 @@ void adjustVTable(uintptr_t** obj, uintptr_t mod, int vtableSize) {
* \brief Initializes the kernel
*/
extern "C" void _start(void ** modtable) {
#ifdef ARM11
for(;;);
#endif
DIAGPXL(13);
//for(void(**i)()=&start_ctors;i<&end_ctors;i++)
// (*i)(); //Calling constructors
for(int i=0;i<1024;i++) {
DIAGPXL(14);
if(!modtable[i])
break;
DIAGPXL(15);
void(**(*fptr)(void*))() = load((Elf_Ehdr*) modtable[i]);
if(!fptr)
continue;
// fptr=(void(**(*)(void*))())((uintptr_t)fptr-8);
DIAGPXL(16);
// debugNumber((uintptr_t)modtable[i],50+32);
DIAGPXL(17);
void(**table)()=fptr(modtable[i]);
//debugNumber((uintptr_t)table,50+96);
DIAGPXL(18);
#ifndef __LP64__
//Relocate table
table=(void(**)())((uintptr_t)table+(uintptr_t)modtable[i]+0x1000);
@ -98,21 +77,15 @@ extern "C" void _start(void ** modtable) {
#endif
#endif
//Relocate table contents
uintptr_t* tbl=(uintptr_t*)table;;
tbl[0]+=(uintptr_t)modtable[i]+0x1000;
tbl[1]+=(uintptr_t)modtable[i]+0x1000;
tbl[2]+=(uintptr_t)modtable[i]+0x1000;
DIAGPXL(500);
uintptr_t* tbl=(uintptr_t*)table;
tbl[0]+=(uintptr_t)modtable[i]+PAGE_SIZE;
tbl[1]+=(uintptr_t)modtable[i]+PAGE_SIZE;
tbl[2]+=(uintptr_t)modtable[i]+PAGE_SIZE;
ModType type=((getType_type)table[0])(); //Get module type
DIAGPXL(501);
//if(type!=ModType::output_text)
//continue;
DIAGPXL(502);
if(type!=ModType::output_text)
continue;
size_t size=((sizeof_type)table[1])(); //Get module size
debugNumber((uintptr_t)size,50);
DIAGPXL(503);
((spawnAt_type)table[2])((void*)&out);
DIAGPXL(504);
((spawnAt_type)table[2])((void*)&out); //Spawn module
adjustVTable((uintptr_t**) &out, (uintptr_t)modtable[i], 1);
out << "HI!\nbye!\n";
#ifdef ARM9

View file

@ -10,7 +10,6 @@ uint8_t* dmem = (uint8_t*)0x18300000;
uint8_t* vmem = (uint8_t*)0x18346500;
#endif
static int x=0,y=0;
#define DIAGPXL(i) (debugNumber(i,i))
#define CHR_HEIGHT 8
#define CHR_WIDTH 8
#define HEIGHT 29
@ -20,16 +19,6 @@ static int x=0,y=0;
#define WIDTH 40
#endif
#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 {
/**
@ -38,8 +27,15 @@ namespace {
*/
class Screen: public Base::Output {
public:
Screen() {DIAGPXL(31);}
Screen() {}
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++)
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++)
@ -48,13 +44,14 @@ public:
}
private:
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;
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) {
case '\n':
x=0; y++;
@ -70,7 +67,6 @@ private:
x--;
break;
case '\0':
DIAGPXL(32);
break;
default:
for(int cx=0;cx<CHR_WIDTH;cx++) {
@ -93,7 +89,6 @@ private:
}
break;
}
debugNumber((unsigned int)y,532+8*8+64);
if(y>HEIGHT)
scroll();
}
@ -118,16 +113,12 @@ table_type getTable() {
#endif
}
auto getType() -> ModType {
DIAGPXL(24);
return ModType::output_text;
}
auto spawnAt(void* pos) -> bool {
debugNumber((unsigned int)pos,82);
DIAGPXL(530);
new(pos) MTGos::Screen;
return true;
}
auto size_of() -> size_t {
DIAGPXL(26);
return sizeof(MTGos::Screen);
}

Binary file not shown.