diff --git a/Makefile b/Makefile index 7b0a6a12..a9e8f793 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ endif REMOTE=192.168.2.6 REMOTEUSER=sortie REMOTECOPYDIR:=/home/$(REMOTEUSER)/Desktop/MaxsiOS -MODULES=libmaxsi hello pong sortix +MODULES=libmaxsi hello pong mkinitrd sortix VERSION=0.4 DEBNAME:=sortix_$(VERSION)_$(CPU) @@ -17,6 +17,7 @@ PACKAGENAME:=sortix ISODIR:=builds/$(DEBNAME)-iso ISOFILE:=builds/$(DEBNAME).iso JSNAME:=jssortix_$(VERSION)_$(CPU).bin +INITRDDIR:=initrd all: (for D in $(MODULES); do $(MAKE) all $(MFLAGS) --directory $$D; done) @@ -99,7 +100,12 @@ iso: all debsource mkdir -p $(ISODIR) cp -r isosrc/. $(ISODIR) cp sortix/sortix.bin $(ISODIR)/boot - cp hello/hello $(ISODIR)/boot/sortix.initrd + mkdir -p $(INITRDDIR) + cp hello/hello $(INITRDDIR) + cp pong/pong $(INITRDDIR) + cp $(INITRDDIR)/hello $(INITRDDIR)/init + (cd $(INITRDDIR) && ../mkinitrd/mkinitrd * -o ../$(ISODIR)/boot/sortix.initrd) + rm -rf $(INITRDDIR) cp builds/$(DEBSRCNAME)-src.tar.gz $(ISODIR) grub-mkrescue -o $(ISOFILE) $(ISODIR) rm -rf $(ISODIR) diff --git a/mkinitrd/.gitignore b/mkinitrd/.gitignore new file mode 100644 index 00000000..f5631bac --- /dev/null +++ b/mkinitrd/.gitignore @@ -0,0 +1,3 @@ +mkinitrd +lsinitrd +catinitrd diff --git a/sortix/kernel.cpp b/sortix/kernel.cpp index b54b0ba0..da1baf9f 100644 --- a/sortix/kernel.cpp +++ b/sortix/kernel.cpp @@ -45,6 +45,7 @@ #include "serialterminal.h" #include "vgaterminal.h" #include "elf.h" +#include "initrd.h" using namespace Maxsi; @@ -209,6 +210,8 @@ namespace Sortix initrd = modules[2*I+0]; break; } + + if ( initrd == NULL ) { PanicF("No initrd provided"); } #endif // Initialize the GDT and TSS structures. @@ -250,18 +253,22 @@ namespace Sortix Process* process = new Process(addrspace); if ( process == 0 ) { Panic("kernel.cpp: Could not allocate the first process!"); } - if ( initrd != NULL ) - { - initstart = (Thread::Entry) ELF::Construct(process, initrd, initrdsize); - if ( initstart == NULL ) - { - Panic("kernel.cpp: Could not construct ELF program"); - } + InitRD::Init(initrd, initrdsize); - // HACK: This should be determined from other information! - process->_endcodesection = 0x400000UL; + const char* initname = "init"; + size_t programsize = 0; + byte* program = InitRD::Open(initname, &programsize); + if ( program == NULL ) { PanicF("initrd did not contain '%s'", initname); } + + initstart = (Thread::Entry) ELF::Construct(process, program, programsize); + if ( initstart == NULL ) + { + Panic("kernel.cpp: Could not construct ELF program"); } + // HACK: This should be determined from other information! + process->_endcodesection = 0x400000UL; + if ( Scheduler::CreateThread(process, initstart) == NULL ) { Panic("Could not create a sample thread!");