actually working x86 relocations

This commit is contained in:
Morten Delenk 2016-08-14 17:08:42 +02:00
parent 04f7a213b1
commit 4694d6f490
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
7 changed files with 31 additions and 17 deletions

View file

@ -8,7 +8,6 @@ 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;
@ -19,5 +18,5 @@ typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
typedef unsigned long int uintptr_t;
typedef unsigned long int size_t;
#endif
typedef __SIZE_TYPE__ size_t;

View file

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

View file

@ -54,6 +54,12 @@ void debugNumber(unsigned int i, int start) {
start++;
}
}
void adjustVTable(unsigned int** obj, unsigned int mod, int vtableSize) {
mod+=0x1000;
for(int i=0;i<vtableSize;i++) {
(*obj)[i]+=mod;
}
}
/**
* \function _start()
* \brief Initializes the kernel
@ -68,18 +74,20 @@ extern "C" void _start(void ** modtable) {
break;
DIAGPXL(15);
void(**(*fptr)(void*))() = load((Elf_Ehdr*) modtable[i]);
fptr=(void(**(*)(void*))())((unsigned int)fptr-8);
if(!fptr)
continue;
// fptr=(void(**(*)(void*))())((unsigned int)fptr-8);
DIAGPXL(16);
debugNumber((unsigned int)fptr,50);
// debugNumber((unsigned int)modtable[i],50+32);
if(!fptr)
continue;
DIAGPXL(17);
void(**table)()=fptr(modtable[i]);
DIAGPXL(18);
table=(void(**)())((unsigned int)table+(unsigned int)modtable[i]+0x1000);
unsigned int* tbl=(unsigned int*)table;
tbl[0]+=(unsigned int)modtable[i]+0x1000;
tbl[1]+=(unsigned int)modtable[i]+0x1000;
tbl[2]+=(unsigned int)modtable[i]+0x1000;
debugNumber((unsigned int)table[0],50+32);
ModType type=((getType_type)table[0])(); //Get module type
DIAGPXL(19);
@ -90,12 +98,15 @@ extern "C" void _start(void ** modtable) {
DIAGPXL(21);
((spawnAt_type)table[2])((void*)&out);
DIAGPXL(22);
adjustVTable((unsigned int**) &out, (unsigned int)modtable[i], 1);
out << "HI!\nbye!\n";
#ifdef ARM9
out << "Here arm9!\n";
#else
out << "Here arm11!\n";
#endif
char* x=(char*)0xB80000;
x[0]='H';
}
for(void(**i)()=&start_dtors;i<&end_dtors;i++)
(*i)(); //Calling destructors

View file

@ -6,8 +6,8 @@ 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
CFLAGS += -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../../../c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fPIC -pie
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 -pie -Wno-reorder -fdump-class-hierarchy
LDFLAGS += -nostdlib -nodefaultlibs -nostdlib -fno-builtin -T ../../link.ld
all: $(OBJS)
$(LD) $(LDFLAGS) -o ../../../../dsp_txt.elf $(OBJS) -lgcc

View file

@ -11,7 +11,7 @@ namespace {
*/
class Screen: public Base::Output {
public:
Screen() {}
Screen() {x=0;y=0;vmem = (uint16_t*)0xB8000;}
auto scroll() -> void {
for(int p=0;p<80*25;p++)
vmem[p]=vmem[p+80];

View file

@ -1,7 +1,7 @@
ENTRY(getTable)
SECTIONS
{
. = 0x106000;
. = /*0x106000;*/0;
module_start = .;
.text : {
*(.text)
@ -18,6 +18,10 @@ SECTIONS
*(.data.*)
*(.rodata)
*(.bss)
*(COMMON)
*(.plt)
*(.rel.plt)
*(.rel.dyn)
}
module_end = .;
}

Binary file not shown.