Fixed x86-64 too

This commit is contained in:
Morten Delenk 2016-08-14 18:13:51 +02:00
parent 4694d6f490
commit d916802eb7
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
5 changed files with 25 additions and 21 deletions

View file

@ -4,10 +4,10 @@ LD=$(PREFIX)ld
SRCS = $(shell find . -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))
ASFLAGS =
CFLAGS += -fno-stack-protector -nostdinc -ffreestanding -std=c11 -fno-builtin -w -Werror -nostdlib -fpie
LDFLAGS = -T loader.ld
CFLAGS = -fno-stack-protector -nostdinc -ffreestanding -std=c11 -fno-builtin -w -Werror -nostdlib
LDFLAGS = -T loader.ld -z max-page-size=0x1000
all: $(OBJS)
$(LD) $(LDFLAGS) -o loader.bin $(OBJS)
$(LD) $(LDFLAGS) -z max-page-size=0x1000 -o loader.bin $(OBJS)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^

View file

@ -1,4 +1,4 @@
arch = x86
arch = x86_64
subvar = 9
MODE = debug
export PATH := $(HOME)/opt/bin:$(PATH)
@ -9,8 +9,8 @@ ifeq ($(arch),x86)
ARCHFLAGS = -m32
else
ifeq ($(arch),x86_64)
PREFIX = x86_64-mtgos-
libpath = x86_64-mtgos
PREFIX = x86_64-elf-
libpath = x86_64-elf
ARCHFLAGS = -m64 -mno-red-zone
LDFLAGS += -z max-page-size=0x1000
else

View file

@ -45,7 +45,7 @@ auto load(Elf_Ehdr* file) -> void(**(*)(void*))() {
return nullptr;
}
MTGos::Base::Output out;
void debugNumber(unsigned int i, int start) {
void debugNumber(uintptr_t i, int start) {
while(i) {
if(i&1)
lfb[(start*6)+5]=0xFF;
@ -54,7 +54,7 @@ void debugNumber(unsigned int i, int start) {
start++;
}
}
void adjustVTable(unsigned int** obj, unsigned int mod, int vtableSize) {
void adjustVTable(uintptr_t** obj, uintptr_t mod, int vtableSize) {
mod+=0x1000;
for(int i=0;i<vtableSize;i++) {
(*obj)[i]+=mod;
@ -76,19 +76,23 @@ extern "C" void _start(void ** modtable) {
void(**(*fptr)(void*))() = load((Elf_Ehdr*) modtable[i]);
if(!fptr)
continue;
// fptr=(void(**(*)(void*))())((unsigned int)fptr-8);
// fptr=(void(**(*)(void*))())((uintptr_t)fptr-8);
DIAGPXL(16);
debugNumber((unsigned int)fptr,50);
// debugNumber((unsigned int)modtable[i],50+32);
debugNumber((uintptr_t)fptr,50);
// debugNumber((uintptr_t)modtable[i],50+32);
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);
#ifndef __LP64__
//Relocate table
table=(void(**)())((uintptr_t)table+(uintptr_t)modtable[i]+0x1000);
#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;
debugNumber((uintptr_t)table[0],50+32);
ModType type=((getType_type)table[0])(); //Get module type
DIAGPXL(19);
if(type!=ModType::output_text)
@ -98,7 +102,7 @@ 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);
adjustVTable((uintptr_t**) &out, (uintptr_t)modtable[i], 1);
out << "HI!\nbye!\n";
#ifdef ARM9
out << "Here arm9!\n";

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

@ -3,7 +3,7 @@ OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_ARCH(i386:x86-64)
SECTIONS
{
. = 0x109000;
. = /*0x109000;*/0;
module_start = .;
.text : {
*(.text)