diff --git a/crosscompilemakefile.mak b/crosscompilemakefile.mak new file mode 100644 index 00000000..b5195a19 --- /dev/null +++ b/crosscompilemakefile.mak @@ -0,0 +1,35 @@ +ifndef CPU + CPU=x86 +endif + +ifeq ($(CPU),x86) + X86FAMILY=1 + CPUDEFINES=-DPLATFORM_X86 + CPUFLAGS=-m32 + CPULDFLAGS=-melf_i386 +endif + +ifeq ($(CPU),x64) + X86FAMILY=1 + CPUDEFINES=-DPLATFORM_X64 + CPUFLAGS=-m64 + CPULDFLAGS=-melf_x86_64 +endif + +LIBMAXSIROOT=$(OSROOT)/libmaxsi + +LIBC=$(LIBMAXSIROOT)/libc.a $(LIBMAXSIROOT)/start.o +LIBS=$(LIBC) + +CPPFLAGS=$(CPUDEFINES) +FLAGS=-nostdinc -nostdlib -fno-builtin -nostartfiles -nodefaultlibs +INCLUDES=-I $(LIBMAXSIROOT)/c/h/ -I $(OSROOT)/ + +LD=ld +LDFLAGS=$(CPULDFLAGS) +CC=gcc +CFLAGS=$(CPUFLAGS) $(FLAGS) $(INCLUDES) +CXX=g++ +CXXFLAGS=$(CPUFLAGS) $(FLAGS) $(INCLUDES) + + diff --git a/hello/Makefile b/hello/Makefile index 108a5fbe..af3e9291 100644 --- a/hello/Makefile +++ b/hello/Makefile @@ -1,46 +1,15 @@ -# This is a bit bothersome design, but it should serve well enough as a simple -# cross-compiler for the Sortix operating system. - -ifndef CPU - CPU=x86 -endif - -ifeq ($(CPU),x86) - X86FAMILY=1 - CPUDEFINES=-DPLATFORM_X86 - CPUFLAGS=-m32 - CPULDFLAGS=-melf_i386 -endif - -ifeq ($(CPU),x64) - X86FAMILY=1 - CPUDEFINES=-DPLATFORM_X64 - CPUFLAGS=-m64 - CPULDFLAGS=-melf_x86_64 -endif - -LIBMAXSIROOT=../libmaxsi - -INCLUDES=-I $(LIBMAXSIROOT)/c/h/ -I ../ -CPPFLAGS=$(CPUDEFINES) - -LD=ld -LDFLAGS=$(CPULDFLAGS) -Ttext 400000 $(LIBMAXSIROOT)/start.o -CC=gcc -CFLAGS=$(CPUFLAGS) -nostdinc -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-stack-protector $(INCLUDES) -CXX=g++ -CXXFLAGS=$(CPUFLAGS) -nostdinc -nostdlib -fno-builtin -nostartfiles -nodefaultlibs -fno-exceptions -fno-rtti -fno-stack-protector $(INCLUDES) -LIBC=$(LIBMAXSIROOT)/libc.a +# Set up variables such that we can easily cross-compile. +OSROOT=.. +include ../crosscompilemakefile.mak all: hello hello: hello.o - $(LD) $(LDFLAGS) hello.o -o hello.tmp $(LIBC) - objcopy -O binary hello.tmp hello + $(LD) $(LDFLAGS) hello.o -o hello $(LIBS) hello.o: hello.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -O2 -c hello.cpp -o hello.o clean: - rm -f hello.tmp hello.o hello + rm -f hello.o hello diff --git a/sortix/kernel.cpp b/sortix/kernel.cpp index 8e6dc179..ee4494a4 100644 --- a/sortix/kernel.cpp +++ b/sortix/kernel.cpp @@ -44,6 +44,7 @@ #include "uart.h" #include "serialterminal.h" #include "vgaterminal.h" +#include "elf.h" using namespace Maxsi; @@ -251,19 +252,14 @@ namespace Sortix if ( initrd != NULL ) { - addr_t loadat = process->_endcodesection; - - for ( size_t i = 0; i < initrdsize; i += 4096 ) + initstart = (Thread::Entry) ELF::Construct(initrd, initrdsize); + if ( initstart == NULL ) { - addr_t apppage = Page::Get(); - if ( apppage == 0 ) { Panic("kernel.cpp: not enough memory for initrd!"); } - VirtualMemory::MapUser(loadat + i, apppage); + Panic("kernel.cpp: Could not construct ELF program"); } - Memory::Copy((void*) loadat, initrd, initrdsize); - initstart = (Thread::Entry) loadat; - - process->_endcodesection += initrdsize; + // HACK: This should be determined from other information! + process->_endcodesection = 0x400000UL; } if ( Scheduler::CreateThread(process, initstart) == NULL )