Fixed x86-64 too
This commit is contained in:
parent
4694d6f490
commit
d916802eb7
5 changed files with 25 additions and 21 deletions
|
@ -4,10 +4,10 @@ LD=$(PREFIX)ld
|
||||||
SRCS = $(shell find . -name '*.[cS]')
|
SRCS = $(shell find . -name '*.[cS]')
|
||||||
OBJS = $(addsuffix .o,$(basename $(SRCS)))
|
OBJS = $(addsuffix .o,$(basename $(SRCS)))
|
||||||
ASFLAGS =
|
ASFLAGS =
|
||||||
CFLAGS += -fno-stack-protector -nostdinc -ffreestanding -std=c11 -fno-builtin -w -Werror -nostdlib -fpie
|
CFLAGS = -fno-stack-protector -nostdinc -ffreestanding -std=c11 -fno-builtin -w -Werror -nostdlib
|
||||||
LDFLAGS = -T loader.ld
|
LDFLAGS = -T loader.ld -z max-page-size=0x1000
|
||||||
all: $(OBJS)
|
all: $(OBJS)
|
||||||
$(LD) $(LDFLAGS) -o loader.bin $(OBJS)
|
$(LD) $(LDFLAGS) -z max-page-size=0x1000 -o loader.bin $(OBJS)
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CFLAGS) -c -o $@ $^
|
$(CC) $(CFLAGS) -c -o $@ $^
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
arch = x86
|
arch = x86_64
|
||||||
subvar = 9
|
subvar = 9
|
||||||
MODE = debug
|
MODE = debug
|
||||||
export PATH := $(HOME)/opt/bin:$(PATH)
|
export PATH := $(HOME)/opt/bin:$(PATH)
|
||||||
|
@ -9,8 +9,8 @@ ifeq ($(arch),x86)
|
||||||
ARCHFLAGS = -m32
|
ARCHFLAGS = -m32
|
||||||
else
|
else
|
||||||
ifeq ($(arch),x86_64)
|
ifeq ($(arch),x86_64)
|
||||||
PREFIX = x86_64-mtgos-
|
PREFIX = x86_64-elf-
|
||||||
libpath = x86_64-mtgos
|
libpath = x86_64-elf
|
||||||
ARCHFLAGS = -m64 -mno-red-zone
|
ARCHFLAGS = -m64 -mno-red-zone
|
||||||
LDFLAGS += -z max-page-size=0x1000
|
LDFLAGS += -z max-page-size=0x1000
|
||||||
else
|
else
|
||||||
|
|
|
@ -45,7 +45,7 @@ auto load(Elf_Ehdr* file) -> void(**(*)(void*))() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
MTGos::Base::Output out;
|
MTGos::Base::Output out;
|
||||||
void debugNumber(unsigned int i, int start) {
|
void debugNumber(uintptr_t i, int start) {
|
||||||
while(i) {
|
while(i) {
|
||||||
if(i&1)
|
if(i&1)
|
||||||
lfb[(start*6)+5]=0xFF;
|
lfb[(start*6)+5]=0xFF;
|
||||||
|
@ -54,7 +54,7 @@ void debugNumber(unsigned int i, int start) {
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void adjustVTable(unsigned int** obj, unsigned int mod, int vtableSize) {
|
void adjustVTable(uintptr_t** obj, uintptr_t mod, int vtableSize) {
|
||||||
mod+=0x1000;
|
mod+=0x1000;
|
||||||
for(int i=0;i<vtableSize;i++) {
|
for(int i=0;i<vtableSize;i++) {
|
||||||
(*obj)[i]+=mod;
|
(*obj)[i]+=mod;
|
||||||
|
@ -76,19 +76,23 @@ extern "C" void _start(void ** modtable) {
|
||||||
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*))())((unsigned int)fptr-8);
|
// fptr=(void(**(*)(void*))())((uintptr_t)fptr-8);
|
||||||
DIAGPXL(16);
|
DIAGPXL(16);
|
||||||
debugNumber((unsigned int)fptr,50);
|
debugNumber((uintptr_t)fptr,50);
|
||||||
// debugNumber((unsigned int)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]);
|
||||||
DIAGPXL(18);
|
DIAGPXL(18);
|
||||||
table=(void(**)())((unsigned int)table+(unsigned int)modtable[i]+0x1000);
|
#ifndef __LP64__
|
||||||
unsigned int* tbl=(unsigned int*)table;
|
//Relocate table
|
||||||
tbl[0]+=(unsigned int)modtable[i]+0x1000;
|
table=(void(**)())((uintptr_t)table+(uintptr_t)modtable[i]+0x1000);
|
||||||
tbl[1]+=(unsigned int)modtable[i]+0x1000;
|
#endif
|
||||||
tbl[2]+=(unsigned int)modtable[i]+0x1000;
|
//Relocate table contents
|
||||||
debugNumber((unsigned int)table[0],50+32);
|
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;
|
||||||
|
debugNumber((uintptr_t)table[0],50+32);
|
||||||
ModType type=((getType_type)table[0])(); //Get module type
|
ModType type=((getType_type)table[0])(); //Get module type
|
||||||
DIAGPXL(19);
|
DIAGPXL(19);
|
||||||
if(type!=ModType::output_text)
|
if(type!=ModType::output_text)
|
||||||
|
@ -98,7 +102,7 @@ extern "C" void _start(void ** modtable) {
|
||||||
DIAGPXL(21);
|
DIAGPXL(21);
|
||||||
((spawnAt_type)table[2])((void*)&out);
|
((spawnAt_type)table[2])((void*)&out);
|
||||||
DIAGPXL(22);
|
DIAGPXL(22);
|
||||||
adjustVTable((unsigned int**) &out, (unsigned int)modtable[i], 1);
|
adjustVTable((uintptr_t**) &out, (uintptr_t)modtable[i], 1);
|
||||||
out << "HI!\nbye!\n";
|
out << "HI!\nbye!\n";
|
||||||
#ifdef ARM9
|
#ifdef ARM9
|
||||||
out << "Here arm9!\n";
|
out << "Here arm9!\n";
|
||||||
|
|
|
@ -6,8 +6,8 @@ CPP = $(PREFIX)g++
|
||||||
CC = $(PREFIX)gcc
|
CC = $(PREFIX)gcc
|
||||||
LD = $(PREFIX)g++
|
LD = $(PREFIX)g++
|
||||||
|
|
||||||
CFLAGS += -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../../../c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpic
|
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 -Wno-reorder -fdump-class-hierarchy
|
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
|
LDFLAGS += -nostdlib -nodefaultlibs -nostdlib -fno-builtin -T ../../link.ld
|
||||||
all: $(OBJS)
|
all: $(OBJS)
|
||||||
$(LD) $(LDFLAGS) -o ../../../../dsp_txt.elf $(OBJS) -lgcc
|
$(LD) $(LDFLAGS) -o ../../../../dsp_txt.elf $(OBJS) -lgcc
|
||||||
|
|
|
@ -3,7 +3,7 @@ OUTPUT_FORMAT(elf64-x86-64)
|
||||||
OUTPUT_ARCH(i386:x86-64)
|
OUTPUT_ARCH(i386:x86-64)
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
. = 0x109000;
|
. = /*0x109000;*/0;
|
||||||
module_start = .;
|
module_start = .;
|
||||||
.text : {
|
.text : {
|
||||||
*(.text)
|
*(.text)
|
||||||
|
|
Loading…
Reference in a new issue