diff --git a/.gitmodules b/.gitmodules index e9ec8162..84805ac4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -12,3 +12,6 @@ path = 3rdparty/ihk url = https://github.com/ManyThreads/ihk.git ignore = dirty +[submodule "3rdparty/tbb"] + path = 3rdparty/tbb + url = git@github.com:ManyThreads/tbb.git diff --git a/3rdparty/install-tbb.sh b/3rdparty/install-tbb.sh new file mode 100755 index 00000000..0001ea8d --- /dev/null +++ b/3rdparty/install-tbb.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +TBBDIR="${SCRIPTDIR}/tbb" +CXXDIR="${SCRIPTDIR}/cxx-amd64" +TBB_BUILD_PREFIX="my_tbb" + +MYFLAGS=" -std=c++11 -march=native -Wfatal-errors -g" +MYFLAGS+=" -fno-stack-protector" +MYFLAGS+=" -nostdlib -nostdinc -nostdinc++" +MYFLAGS+=" -isystem ${CXXDIR}/usr/include/c++/v1" +MYFLAGS+=" -isystem ${CXXDIR}/usr/include" + +export CXXFLAGS="${MYFLAGS} ${CPLUS_FLAGS}" +export tbb_build_prefix="${TBB_BUILD_PREFIX}" + +echo $CPLUS_FLAGS + +cd $TBBDIR +make clean default +make extra_inc=big_iron.inc +cd - diff --git a/3rdparty/musl b/3rdparty/musl index 9680582a..790bd394 160000 --- a/3rdparty/musl +++ b/3rdparty/musl @@ -1 +1 @@ -Subproject commit 9680582a257de9d20b94ee26ddf6f9dc10df948e +Subproject commit 790bd3943e419933cf56366197b9f6668ae8c53e diff --git a/3rdparty/tbb b/3rdparty/tbb new file mode 160000 index 00000000..dda6d323 --- /dev/null +++ b/3rdparty/tbb @@ -0,0 +1 @@ +Subproject commit dda6d323f817d05a96f95612d3b158c43cfca241 diff --git a/Makefile.user b/Makefile.user index bf438808..56127727 100644 --- a/Makefile.user +++ b/Makefile.user @@ -10,6 +10,7 @@ CPPFLAGS+= -DMLOG_PORTAL=FilterError CPPFLAGS+= -DMLOG_SCHED=FilterError CPPFLAGS+= -DMLOG_SYSCALL=FilterError CPPFLAGS+= -DMLOG_TASKLET=FilterError +CPPFLAGS+= -DMLOG_PROCESSORMGMT=FilterWarning #CPPFLAGS+= -DTRACE #CPPFLAGS+= -DNDEBUG diff --git a/kernel-amd64.config b/kernel-amd64.config index 76a8bc4f..ec0167b2 100644 --- a/kernel-amd64.config +++ b/kernel-amd64.config @@ -19,8 +19,11 @@ "plugin-rapl-driver-intel", "app-init-example", "test-synchronous-task", + "plugin-processor-allocator" ] [config.vars] mythos_root = ".." cxx_path = "../3rdparty/cxx-amd64/usr" + tbb_build_path = "../3rdparty/tbb/build/my_tbb_release" + tbb_inc_path = "../3rdparty/tbb/include" diff --git a/kernel-ihk.config b/kernel-ihk.config index 070dc3f3..4bbf9be7 100644 --- a/kernel-ihk.config +++ b/kernel-ihk.config @@ -23,3 +23,5 @@ [config.vars] mythos_root = ".." cxx_path = "../3rdparty/cxx-amd64/usr" + tbb_build_path = "../3rdparty/tbb/build/my_tbb_release" + tbb_inc_path = "../3rdparty/tbb/include" diff --git a/kernel-knc.config b/kernel-knc.config index 1a7b2262..ec7b4cb3 100644 --- a/kernel-knc.config +++ b/kernel-knc.config @@ -26,3 +26,5 @@ [config.vars] mythos_root = ".." cxx_path = "../3rdparty/cxx-knc/usr" + tbb_build_path = "../3rdparty/tbb/build/my_tbb_release" + tbb_inc_path = "../3rdparty/tbb/include" diff --git a/kernel/app/init-example/app/init.cc b/kernel/app/init-example/app/init.cc index 7b33e85d..461df1cd 100644 --- a/kernel/app/init-example/app/init.cc +++ b/kernel/app/init-example/app/init.cc @@ -28,6 +28,7 @@ #include "mythos/invocation.hh" #include "mythos/protocol/CpuDriverKNC.hh" #include "mythos/PciMsgQueueMPSC.hh" +#include "mythos/InfoFrame.hh" #include "runtime/Portal.hh" #include "runtime/ExecutionContext.hh" #include "runtime/CapMap.hh" @@ -36,6 +37,7 @@ #include "runtime/PageMap.hh" #include "runtime/KernelMemory.hh" #include "runtime/CapAlloc.hh" +#include "runtime/ProcessorAllocator.hh" #include "runtime/tls.hh" #include "runtime/mlog.hh" #include "runtime/InterruptControl.hh" @@ -44,6 +46,8 @@ #include "runtime/umem.hh" #include "runtime/Mutex.hh" #include "runtime/cgaScreen.hh" +#include "runtime/process.hh" +#include "tbb/tbb.h" #include #include @@ -55,20 +59,23 @@ #include -mythos::InvocationBuf* msg_ptr asm("msg_ptr"); +mythos::InfoFrame* info_ptr asm("info_ptr"); int main() asm("main"); +extern char process_test_image_start SYMBOL("process_test_image_start"); + constexpr uint64_t stacksize = 4*4096; char initstack[stacksize]; char* initstack_top = initstack+stacksize; -mythos::Portal portal(mythos::init::PORTAL, msg_ptr); +mythos::Portal portal(mythos::init::PORTAL, info_ptr->getInvocationBuf()); mythos::CapMap myCS(mythos::init::CSPACE); mythos::PageMap myAS(mythos::init::PML4); mythos::KernelMemory kmem(mythos::init::KM); mythos::KObject device_memory(mythos::init::DEVICE_MEM); cap_alloc_t capAlloc(myCS); mythos::RaplDriverIntel rapl(mythos::init::RAPL_DRIVER_INTEL); +mythos::ProcessorAllocator pa(mythos::init::PROCESSOR_ALLOCATOR); char threadstack[stacksize]; char* thread1stack_top = threadstack+stacksize/2; @@ -99,7 +106,7 @@ void test_Portal() MLOG_ERROR(mlog::app, "test_Portal begin"); mythos::PortalLock pl(portal); // future access will fail if the portal is in use already MLOG_INFO(mlog::app, "test_Portal: allocate portal"); - uintptr_t vaddr = mythos::round_up(uintptr_t(msg_ptr) + 1, mythos::align2M); + uintptr_t vaddr = mythos::round_up(info_ptr->getInfoEnd(), mythos::align2M); // allocate a portal mythos::Portal p2(capAlloc(), (void*)vaddr); auto res1 = p2.create(pl, kmem).wait(); @@ -181,7 +188,9 @@ void test_tls() auto tls = mythos::setupNewTLS(); MLOG_INFO(mlog::app, "test_EC: create ec1 TLS", DVARhex(tls)); ASSERT(tls != nullptr); - auto res1 = ec1.create(kmem).as(myAS).cs(myCS).sched(mythos::init::SCHEDULERS_START + 1) + auto sc = pa.alloc(pl).wait(); + TEST(sc); + auto res1 = ec1.create(kmem).as(myAS).cs(myCS).sched(sc->cap) .prepareStack(thread1stack_top).startFun(threadFun, nullptr) .suspended(false).fs(tls) .invokeVia(pl).wait(); @@ -189,15 +198,16 @@ void test_tls() TEST(ec1.setFSGS(pl,(uint64_t) tls, 0).wait()); mythos::syscall_signal(ec1.cap()); MLOG_INFO(mlog::app, "End test tls"); + capAlloc.free(ec1.cap(), pl); } void test_heap() { MLOG_INFO(mlog::app, "Test heap"); mythos::PortalLock pl(portal); - auto size = 4*1024*1024; // 2 MB + auto size = 64*1024*1024; // 2 MB auto align = 2*1024*1024; // 2 MB - uintptr_t vaddr = mythos::round_up(uintptr_t(msg_ptr) + 1, align); + uintptr_t vaddr = mythos::round_up(info_ptr->getInfoEnd() + align2M, align2M); // allocate a 2MiB frame mythos::Frame f(capAlloc()); auto res2 = f.create(pl, kmem, size, align).wait(); @@ -318,7 +328,9 @@ void test_ExecutionContext() auto tls1 = mythos::setupNewTLS(); ASSERT(tls1 != nullptr); - auto res1 = ec1.create(kmem).as(myAS).cs(myCS).sched(mythos::init::SCHEDULERS_START) + auto sc1 = pa.alloc(pl).wait(); + TEST(sc1); + auto res1 = ec1.create(kmem).as(myAS).cs(myCS).sched(sc1->cap) .prepareStack(thread1stack_top).startFun(&thread_main, nullptr) .suspended(false).fs(tls1) .invokeVia(pl).wait(); @@ -327,7 +339,9 @@ void test_ExecutionContext() MLOG_INFO(mlog::app, "test_EC: create ec2"); auto tls2 = mythos::setupNewTLS(); ASSERT(tls2 != nullptr); - auto res2 = ec2.create(kmem).as(myAS).cs(myCS).sched(mythos::init::SCHEDULERS_START+1) + auto sc2 = pa.alloc(pl).wait(); + TEST(sc2); + auto res2 = ec2.create(kmem).as(myAS).cs(myCS).sched(sc2->cap) .prepareStack(thread2stack_top).startFun(&thread_main, nullptr) .suspended(false).fs(tls2) .invokeVia(pl).wait(); @@ -341,6 +355,11 @@ void test_ExecutionContext() MLOG_INFO(mlog::app, "sending notifications"); mythos::syscall_signal(ec1.cap()); mythos::syscall_signal(ec2.cap()); + { + mythos::PortalLock pl(portal); + TEST(capAlloc.free(ec1, pl)); + TEST(capAlloc.free(ec2, pl)); + } MLOG_INFO(mlog::app, "End Test ExecutionContext"); } @@ -353,7 +372,9 @@ void test_InterruptControl() { mythos::ExecutionContext ec(capAlloc()); auto tls = mythos::setupNewTLS(); ASSERT(tls != nullptr); - auto res1 = ec.create(kmem).as(myAS).cs(myCS).sched(mythos::init::SCHEDULERS_START + 2) + auto sc = pa.alloc(pl).wait(); + TEST(sc); + auto res1 = ec.create(kmem).as(myAS).cs(myCS).sched(sc->cap) .prepareStack(thread3stack_top).startFun(&thread_main, nullptr) .suspended(false).fs(tls) .invokeVia(pl).wait(); @@ -364,6 +385,28 @@ void test_InterruptControl() { MLOG_INFO(mlog::app, "test_InterruptControl end"); } +void test_TBB(){ + MLOG_INFO(mlog::app, "Test TBB"); + + class say_hello + { + int id; + public: + say_hello(int i) : id(i) { } + void operator( ) ( ) const + { + printf("hello from task %d\n",id); + } + }; + + tbb::task_group tg; + for(int i=0; i<10; i++){ + tg.run(say_hello(i)); // spawn 1st task and return + } + tg.wait( ); // wait for tasks to complete + MLOG_INFO(mlog::app, "Test finished"); +} + bool primeTest(uint64_t n){ if(n == 0 | n == 1){ @@ -476,13 +519,34 @@ void test_CgaScreen(){ MLOG_INFO(mlog::app, "Test CGA finished"); } +void test_processor_allocator(){ + MLOG_INFO(mlog::app, "Test processor allocator"); + mythos::PortalLock pl(portal); + auto sc = pa.alloc(pl).wait(); + TEST(sc); + auto res = pa.free(pl, sc->cap).wait(); + TEST(res); + MLOG_INFO(mlog::app, "Test processor allocator finished"); +} + +void test_process(){ + MLOG_INFO(mlog::app, "Test process"); + + mythos::PortalLock pl(portal); + + Process p(&process_test_image_start); + p.createProcess(pl); + + MLOG_INFO(mlog::app, "Test process finished"); +} + int main() { char const str[] = "Hello world!"; mythos::syscall_debug(str, sizeof(str)-1); - MLOG_ERROR(mlog::app, "application is starting :)", DVARhex(msg_ptr), DVARhex(initstack_top)); + MLOG_ERROR(mlog::app, "application is starting :)", DVARhex(info_ptr), DVARhex(initstack_top)); - test_float(); + //test_float(); test_Example(); test_Portal(); test_heap(); // heap must be initialized for tls test @@ -492,7 +556,10 @@ int main() //test_HostChannel(portal, 24*1024*1024, 2*1024*1024); test_ExecutionContext(); test_pthreads(); - //test_Rapl(); + test_Rapl(); + test_processor_allocator(); + test_TBB(); + test_process(); //test_CgaScreen(); char const end[] = "bye, cruel world!"; diff --git a/kernel/app/init-example/mcconf.module b/kernel/app/init-example/mcconf.module index 49bb85d1..6a78c0a6 100644 --- a/kernel/app/init-example/mcconf.module +++ b/kernel/app/init-example/mcconf.module @@ -1,8 +1,8 @@ # -*- mode:toml; -*- [module.app-init-example] - appfiles = [ "app/init.cc" ] + initappfiles = [ "app/init.cc" ] provides = [ "app/init.elf" ] - requires = [ "crtbegin"] + requires = [ "crtbegin", "app-process-test"] makefile_head = ''' TARGETS += app/init.elf diff --git a/kernel/app/process_test/app/images.S b/kernel/app/process_test/app/images.S new file mode 100644 index 00000000..9dc60b1a --- /dev/null +++ b/kernel/app/process_test/app/images.S @@ -0,0 +1,33 @@ +/* -*- mode:asm; indent-tabs-mode:nil -*- */ +/* MIT License -- MyThOS: The Many-Threads Operating System + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Copyright 2020 Philipp Gypser and contributors, BTU Cottbus-Senftenberg + */ + +// copy this section for each elf image +.global process_test_image_start +process_test_image_start: + .incbin "process_test/process_test.elf" + +.global process_test_image_end +process_test_image_end: diff --git a/kernel/app/process_test/mcconf.module b/kernel/app/process_test/mcconf.module new file mode 100644 index 00000000..1581228f --- /dev/null +++ b/kernel/app/process_test/mcconf.module @@ -0,0 +1,28 @@ +# -*- mode:toml; -*- +[module.app-process-test] + initappfiles = [ "app/images.S" ] + processtestappfiles = [ "process_test/process_test.cc", "process_test/mlog.cc" ] + requires = [ "crtbegin"] + provides = [ "app-process-test" ] + + makefile_head = ''' +TARGETS += process_test/process_test.elf +PROCESSTESTAPP_CXX ?= $(APP_CXX) +PROCESSTESTAPP_AS ?= $(APP_AS) +PROCESSTESTAPP_CXXFLAGS += $(APP_CXXFLAGS) +PROCESSTESTAPP_CPPFLAGS += $(APP_CPPFLAGS) +PROCESSTESTAPP_CXXFLAGS += -fno-stack-protector +PROCESSTESTAPP_ASFLAGS += $(APP_ASFLAGS) +APP_IMAGES = process_test/process_test.elf +''' + + makefile_body = ''' +app/images.o: $(APP_IMAGES) + +process_test/process_test.elf: $(PROCESSTESTAPPFILES_OBJ) $(APPFILES_OBJ) $(CRTFILES_OBJ) + $(APP_CXX) $(APP_LDFLAGS) $(APP_CXXFLAGS) -nostdlib -o $@ runtime/start.o runtime/crtbegin.o $(PROCESSTESTAPPFILES_OBJ) $(APPFILES_OBJ) $(APP_LIBS) runtime/crtend.o + $(NM) $@ | cut -d " " -f 1,3 | c++filt -t > process_test.sym + $(OBJDUMP) -dS $@ | c++filt > process_test.disasm + $(STRIP) $@ +''' + diff --git a/kernel/app/process_test/process_test/mlog.cc b/kernel/app/process_test/process_test/mlog.cc new file mode 100644 index 00000000..725c2c40 --- /dev/null +++ b/kernel/app/process_test/process_test/mlog.cc @@ -0,0 +1,34 @@ +/* -*- mode:C++; -*- */ +/* MIT License -- MyThOS: The Many-Threads Operating System + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Copyright 2020 Philipp Gypser, Randolf Rotta, Maik Krüger, and contributors, BTU Cottbus-Senftenberg + */ + +#include "runtime/mlog.hh" +#include "util/error-trace.hh" + +namespace mlog { + Logger app("process-test"); + Logger throw_error("throw"); + Logger testLog("Test"); +} // namespace mlog diff --git a/kernel/app/process_test/process_test/process_test.cc b/kernel/app/process_test/process_test/process_test.cc new file mode 100644 index 00000000..1a23ffa0 --- /dev/null +++ b/kernel/app/process_test/process_test/process_test.cc @@ -0,0 +1,72 @@ +/* -*- mode:C++; indent-tabs-mode:nil; -*- */ +/* MIT License -- MyThOS: The Many-Threads Operating System + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Copyright 2020 Philipp Gypser and contributors, BTU Cottbus-Senftenberg + */ + +#include "mythos/init.hh" +#include "mythos/invocation.hh" +#include "mythos/InfoFrame.hh" +#include "runtime/Portal.hh" +#include "runtime/ExecutionContext.hh" +#include "runtime/CapMap.hh" +#include "runtime/RaplDriverIntel.hh" +#include "runtime/Example.hh" +#include "runtime/PageMap.hh" +#include "runtime/KernelMemory.hh" +#include "runtime/SimpleCapAlloc.hh" +#include "runtime/ProcessorAllocator.hh" +#include "runtime/tls.hh" +#include "runtime/mlog.hh" +#include "runtime/InterruptControl.hh" +#include +#include "util/optional.hh" +#include "runtime/umem.hh" +#include "runtime/Mutex.hh" + + +mythos::InfoFrame* info_ptr asm("info_ptr"); +int main() asm("main"); + +constexpr uint64_t stacksize = 4*4096; +char initstack[stacksize]; +char* initstack_top = initstack+stacksize; + +mythos::Portal portal(mythos::init::PORTAL, info_ptr->getInvocationBuf()); +mythos::CapMap myCS(mythos::init::CSPACE); +mythos::PageMap myAS(mythos::init::PML4); +mythos::KernelMemory kmem(mythos::init::KM); +mythos::KObject device_memory(mythos::init::DEVICE_MEM); +mythos::SimpleCapAlloc< mythos::init::APP_CAP_START + , mythos::init::SIZE-mythos::init::APP_CAP_START> capAlloc(myCS); +mythos::RaplDriverIntel rapl(mythos::init::RAPL_DRIVER_INTEL); +mythos::ProcessorAllocator pa(mythos::init::PROCESSOR_ALLOCATOR); + + +int main() +{ + MLOG_ERROR(mlog::app, "New process started :)"); + MLOG_INFO(mlog::app, "info frame", DVARhex(info_ptr), DVAR(info_ptr->getNumThreads()), DVAR(info_ptr->getPsPerTSC())); + + return 0; +} diff --git a/kernel/async/monitor-common/async/Place.hh b/kernel/async/monitor-common/async/Place.hh index 571bbb8f..8b60fe9a 100644 --- a/kernel/async/monitor-common/async/Place.hh +++ b/kernel/async/monitor-common/async/Place.hh @@ -113,6 +113,8 @@ public: /** true if the hardware thread is currently in kernel mode and processing tasks. */ bool isActive() const { return nestingMonitor.load(std::memory_order_relaxed); } + cpu::ThreadID getThreadID(){ return threadID; } + protected: void pushPrivate(TaskletBase* msg) { ASSERT(isLocal()); diff --git a/kernel/boot/init-loader-amd64/boot/load_init.cc b/kernel/boot/init-loader-amd64/boot/load_init.cc index 5e00f6f3..4dbc9c75 100644 --- a/kernel/boot/init-loader-amd64/boot/load_init.cc +++ b/kernel/boot/init-loader-amd64/boot/load_init.cc @@ -44,11 +44,14 @@ #include "boot/mlog.hh" #include "boot/memory-root.hh" #include "boot/DeployHWThread.hh" +#include "mythos/InfoFrame.hh" namespace mythos { Event event::initLoader; +Event event::initLoaderEarly; +Event event::initInfoFrame; namespace boot { @@ -59,6 +62,9 @@ InitLoader::InitLoader(char* image) , capAlloc(init::CAP_ALLOC_START, init::CAP_ALLOC_END-init::CAP_ALLOC_START) , memMapper(&capAlloc, mythos::init::KM) + // default: no processor allocator present + , processorAllocatorPresent(false) + , initSC(init::SCHEDULERS_START) { MLOG_INFO(mlog::boot, "found init application image at", (void*)image); } @@ -69,13 +75,17 @@ optional InitLoader::load() { if (!_img.isValid()) RETURN(Error::GENERIC_ERROR); + event::initLoaderEarly.emit(*this); + // order matters here optional res(Error::SUCCESS); if (res) res = initCSpace(); auto ipc_vaddr = loadImage(); res = ipc_vaddr; - if (res) MLOG_INFO(mlog::boot, "init invokation buffer", DVARhex(*ipc_vaddr)); - if (res) res = createPortal(*ipc_vaddr, init::PORTAL); + if (res) MLOG_INFO(mlog::boot, "init info frame/invokation buffer", DVARhex(*ipc_vaddr)); + auto infoFramePtr = createInfoFrame(*ipc_vaddr); + res = infoFramePtr; + if (res) res = createPortal(*infoFramePtr, init::PORTAL); if (res) res = createEC(*ipc_vaddr); RETURN(res); } @@ -157,12 +167,14 @@ optional InitLoader::initCSpace() if (!res) RETHROW(res); } - ASSERT(cpu::getNumThreads() <= init::SCHEDULERS_START - init::APP_CAP_START); - MLOG_INFO(mlog::boot, "... create scheduling context caps in caps", - init::SCHEDULERS_START, "till", init::SCHEDULERS_START+cpu::getNumThreads()-1); - for (cpu::ThreadID id = 0; id < cpu::getNumThreads(); ++id) { - auto res = csSet(init::SCHEDULERS_START+id, boot::getScheduler(id)); - if (!res) RETHROW(res); + if(!processorAllocatorPresent){ + ASSERT(cpu::getNumThreads() <= init::SCHEDULERS_START - init::APP_CAP_START); + MLOG_INFO(mlog::boot, "... create scheduling context caps in caps", + init::SCHEDULERS_START, "till", init::SCHEDULERS_START+cpu::getNumThreads()-1); + for (cpu::ThreadID id = 0; id < cpu::getNumThreads(); ++id) { + auto res = csSet(init::SCHEDULERS_START+id, boot::getScheduler(id)); + if (!res) RETHROW(res); + } } ASSERT(cpu::getNumThreads() <= init::INTERRUPT_CONTROL_START - init::APP_CAP_START); @@ -178,20 +190,36 @@ optional InitLoader::initCSpace() RETURN(Error::SUCCESS); } +optional InitLoader::createInfoFrame(uintptr_t ipc_vaddr) +{ + auto size = round_up(sizeof(InfoFrame), align2M); + MLOG_INFO(mlog::boot, "... create info frame"); + auto frameCap = memMapper.createFrame(init::INFO_FRAME, size, align2M); + if (!frameCap) RETHROW(frameCap); + MLOG_INFO(mlog::boot, "... map info frame", + DVAR(*frameCap), DVARhex(ipc_vaddr)); + memMapper.mmap(ipc_vaddr, size, true, false, *frameCap, 0); -optional InitLoader::createPortal(uintptr_t ipc_vaddr, CapPtr dstPortal) + auto frameEntry = capAlloc.get(*frameCap); + if (!frameEntry) RETHROW(frameEntry); + TypedCap