diff --git a/libraries/libmesosphere/include/mesosphere/init/kern_init_layout.hpp b/libraries/libmesosphere/include/mesosphere/init/kern_init_layout.hpp index 904defc41..620ef85fe 100644 --- a/libraries/libmesosphere/include/mesosphere/init/kern_init_layout.hpp +++ b/libraries/libmesosphere/include/mesosphere/init/kern_init_layout.hpp @@ -27,7 +27,7 @@ namespace ams::kern::init { u32 rw_end_offset; u32 bss_offset; u32 bss_end_offset; - u32 ini_end_offset; + u32 ini_load_offset; u32 dynamic_offset; u32 init_array_offset; u32 init_array_end_offset; diff --git a/libraries/libmesosphere/source/svc/kern_svc_tables.cpp b/libraries/libmesosphere/source/arch/arm64/svc/kern_svc_tables.cpp similarity index 96% rename from libraries/libmesosphere/source/svc/kern_svc_tables.cpp rename to libraries/libmesosphere/source/arch/arm64/svc/kern_svc_tables.cpp index a2fd6a28d..bc5b264fa 100644 --- a/libraries/libmesosphere/source/svc/kern_svc_tables.cpp +++ b/libraries/libmesosphere/source/arch/arm64/svc/kern_svc_tables.cpp @@ -16,6 +16,8 @@ #include #include +/* TODO: Enable compilation of this file when the kernel supports supervisor calls. */ +#if 0 namespace ams::kern::svc { namespace { @@ -41,7 +43,6 @@ namespace ams::kern::svc { } - /* TODO: 32-bit ABI */ const std::array SvcTable64From32 = [] { std::array table = {}; @@ -65,3 +66,4 @@ namespace ams::kern::svc { }(); } +#endif \ No newline at end of file diff --git a/mesosphere/Makefile b/mesosphere/Makefile index 31b597a1c..f511441d1 100644 --- a/mesosphere/Makefile +++ b/mesosphere/Makefile @@ -9,7 +9,8 @@ clean: $(CLEAN_TARGETS) @rm -f mesosphere.bin mesosphere.bin: $(TARGETS) - @echo "todo: py script" + @python build_mesosphere.py + @echo "Built mesosphere.bin..." $(TARGETS): $(MAKE) -C $@ diff --git a/mesosphere/build_mesosphere.py b/mesosphere/build_mesosphere.py new file mode 100644 index 000000000..d7e4087da --- /dev/null +++ b/mesosphere/build_mesosphere.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +import sys, os +from struct import pack as pk, unpack as up + +def align_up(val, algn): + val += algn - 1 + return val - (val % algn) + + +def main(argc, argv): + if argc != 1: + print('Usage: %s' % argv[0]) + return 1 + with open('kernel_ldr/kernel_ldr.bin', 'rb') as f: + kernel_ldr = f.read() + with open('kernel/kernel.bin', 'rb') as f: + kernel = f.read() + kernel_metadata_offset = up('= len(kernel)) + + embedded_ini = b'' + embedded_ini_offset = align_up(kernel_end, 0x1000) + 0x1000 + embedded_ini_end = embedded_ini_offset + 0 # TODO: Create and embed an INI, eventually. + + kernel_ldr_offset = align_up(embedded_ini_end, 0x1000) + 0x1000 + kernel_ldr_end = kernel_ldr_offset + len(kernel_ldr) + + with open('mesosphere.bin', 'wb') as f: + f.write(kernel[:kernel_metadata_offset + 8]) + f.write(pk('bss_offset; - const uintptr_t ini_end_offset = layout->ini_end_offset; + const uintptr_t ini_load_offset = layout->ini_load_offset; const uintptr_t dynamic_offset = layout->dynamic_offset; const uintptr_t init_array_offset = layout->init_array_offset; const uintptr_t init_array_end_offset = layout->init_array_end_offset; @@ -277,9 +277,11 @@ namespace ams::kern::init::loader { /* Decide if Kernel should have enlarged resource region. */ const bool use_extra_resources = KSystemControl::Init::ShouldIncreaseThreadResourceLimit(); const size_t resource_region_size = KernelResourceRegionSize + (use_extra_resources ? ExtraKernelResourceSize : 0); + static_assert(KernelResourceRegionSize > InitialProcessBinarySizeMax); + static_assert(KernelResourceRegionSize + ExtraKernelResourceSize > InitialProcessBinarySizeMax); /* Setup the INI1 header in memory for the kernel. */ - const uintptr_t ini_end_address = base_address + ini_end_offset + resource_region_size; + const uintptr_t ini_end_address = base_address + ini_load_offset + resource_region_size; const uintptr_t ini_load_address = ini_end_address - InitialProcessBinarySizeMax; if (ini_base_address != ini_load_address) { /* The INI is not at the correct address, so we need to relocate it. */