Added a working module loader for 3ds

This commit is contained in:
Morten Delenk 2016-08-08 19:41:56 +02:00
parent 02c2b586b7
commit 5ca5f282d0
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
7 changed files with 94 additions and 6 deletions

View file

@ -38,7 +38,8 @@ void init() {
FATFS fs;
FIL firm;
f_mount(&fs, "0:", 0);
arm9modtable[0]=0;
arm9modtable[0]=0x20000000;
arm9modtable[1]=0x20000000;
arm11modtable[0]=0;
if(f_open(&firm, "mtgos.firm", FA_READ | FA_OPEN_EXISTING) == FR_OK) {
DIAGPXL(1);
@ -60,9 +61,12 @@ void init() {
DIAGPXL(i+8);
}
DIAGPXL(12);
FIL dsp_txt;
f_open(&dsp_txt, "dsp_txt.elf", FA_READ | FA_OPEN_EXISTING);
f_read(&dsp_txt, (void*)0x20000000, f_size(&dsp_txt), &br);
void(**a11fpointer)(void**)=(void(**)(void**))0x1FFFFFF8;
*a11fpointer=hdr.arm11entry;
hdr.entrypoint(0); //Jump to kernel
hdr.entrypoint(arm9modtable); //Jump to kernel
}
for(;;);
}

View file

@ -8,6 +8,7 @@ typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long int uint64_t;
typedef unsigned int uintptr_t;
typedef unsigned int size_t;
#else
typedef signed char int8_t;
typedef signed short int16_t;
@ -18,5 +19,5 @@ typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
typedef unsigned long int uintptr_t;
#endif
typedef unsigned long int size_t;
typedef unsigned long int size_t;
#endif

2
do.sh
View file

@ -3,6 +3,7 @@ gmake clean
gmake loader.bin
gmake -C kernel
gmake -C kernel clean
gmake -C modules
mv kernel/mtgos.elf .
objcopy -O binary mtgos.elf mtgos.bin
gmake -C kernel subvar=11
@ -13,5 +14,6 @@ sudo mount_msdosfs /dev/da3s1 mount
sudo rm mount/{arm9loaderhax.bin,mtgos.firm}
sudo mv loader.bin mount/arm9loaderhax.bin
sudo mv mtgos.firm mount/mtgos.firm
sudo mv *.elf mount
sudo umount mount
echo "Remove SD card!"

View file

@ -41,6 +41,15 @@ auto load(Elf_Ehdr* file) -> void(**(*)(void*))() {
return nullptr;
}
MTGos::Base::Output out;
void debugNumber(unsigned int i, int start) {
while(i) {
if(i&1)
lfb[(start*6)+5]=0xFF;
i>>=1;
lfb[(start*6)+1]=0x50;
start++;
}
}
/**
* \function _start()
* \brief Initializes the kernel
@ -50,18 +59,28 @@ extern "C" void _start(void ** modtable) {
//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]);
debugNumber((unsigned int)fptr, 50);
DIAGPXL(16);
if(!fptr)
continue;
DIAGPXL(17);
void(**table)()=fptr(modtable[i]);
DIAGPXL(18);
ModType type=((getType_type)table[0])(); //Get module type
DIAGPXL(19);
if(type!=ModType::output_text)
continue;
DIAGPXL(20);
size_t size=((sizeof_type)table[1])(); //Get module size
DIAGPXL(21);
((spawnAt_type)table[2])((void*)&out);
out << "HI!\nbye!";
DIAGPXL(22);
//out << "HI!\nbye!";
}
for(void(**i)()=&start_dtors;i<&end_dtors;i++)
(*i)(); //Calling destructors

View file

@ -0,0 +1,26 @@
include ../../../../kernel.settings
SRCS = $(shell find . -name '*.cpp' -o -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))
CPP = $(PREFIX)g++
CC = $(PREFIX)gcc
LD = $(PREFIX)g++
CFLAGS += -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../../../c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpic
CPPFLAGS += -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../../../../c_include -I../../../../include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fpic -Wno-reorder -fdump-class-hierarchy
LDFLAGS += -nostdlib -nodefaultlibs -nostdlib -fno-builtin -T ../../link.ld
all: $(OBJS)
$(LD) $(LDFLAGS) -o ../../../../dsp_txt.elf $(OBJS) -lgcc
%.o: %.cpp
$(CPP) $(CPPFLAGS) -c -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^
%.o: %.S
$(CC) $(CFLAGS) -c -o $@ $^
clean:
rm -rf $(OBJS)
.PHONY: clean all

View file

@ -0,0 +1,36 @@
#include <moduleinterface.h>
#include <base/output.hpp>
#include <modstubs.h>
int x=0,y=0;
uint8_t* vmem = (uint8_t*)0x18300000;
#define DIAGPXL(i) (vmem[6*(i)]=vmem[6*(i)+1]=vmem[6*(i)+2]=0xFF)
void(*tbl[3])()={(void(*)())&getType,(void(*)())&size_of,(void(*)())&spawnAt};
table_type getTable() {
doCtors();
DIAGPXL(23);
return (table_type)&tbl;
}
auto getType() -> ModType {
DIAGPXL(24);
return ModType::output_text;
}
void debugNumber(unsigned int i, int start) {
while(i) {
if(i&1)
vmem[(start*6)+5]=0xFF;
i>>=1;
vmem[(start*6)+1]=0x50;
start++;
}
}
auto spawnAt(void* pos) -> bool {
debugNumber((unsigned int)pos,82);
DIAGPXL(25);
return false;
//new(pos) MTGos::Screen;
return true;
}
auto size_of() -> size_t {
DIAGPXL(26);
return 0;//sizeof(MTGos::Screen);
}

View file

@ -3,7 +3,7 @@ OUTPUT_FORMAT(elf32-littlearm)
OUTPUT_ARCH(arm)
SECTIONS
{
. = 0x20000000;
. = 0x20010000;
module_start = .;
.text : {
*(.text)