From 5652d7c0c6a8db05699f2b4334e4615e1ba22127 Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Tue, 16 Jul 2013 15:29:15 -0500 Subject: Initial Hostboot Runtime image support. RTC: 76675 Change-Id: Ibd21cf5b555e6dcee182a2f1a292b47d4f384ba0 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/6127 Tested-by: Jenkins Server Reviewed-by: A. Patrick Williams III --- src/build/buildpnor/defaultPnorLayout.xml | 7 ++ src/build/linker/linker.C | 11 +- src/build/mkrules/cflags.env.mk | 5 + src/build/mkrules/dist.targets.mk | 1 + src/build/mkrules/hbfw/img/makefile | 5 +- src/build/mkrules/images.rules.mk | 10 +- src/include/builtins.h | 5 + src/include/runtime/interface.h | 79 ++++++++++++++ src/include/stdio.h | 47 +++++---- src/include/usr/cxxtest/TestSuite.H | 22 +++- src/include/usr/pnor/pnorif.H | 3 +- src/kernel/basesegment.C | 2 +- src/lib/stdio.C | 88 +++++++++------- src/makefile | 37 +++++-- src/runtime/makefile | 29 ++++++ src/runtime/rt_assert.C | 41 ++++++++ src/runtime/rt_console.C | 39 +++++++ src/runtime/rt_main.C | 123 ++++++++++++++++++++++ src/runtime/rt_start.S | 72 +++++++++++++ src/runtime/rt_stdlib.C | 56 ++++++++++ src/runtime/rt_sync.C | 29 ++++++ src/runtime/rt_vfs.C | 125 +++++++++++++++++++++++ src/usr/cxxtest/makefile | 30 +++--- src/usr/cxxtest/runtime/makefile | 31 ++++++ src/usr/cxxtest/runtime/rt_cxxtestexec.C | 76 ++++++++++++++ src/usr/pnor/pnorrp.C | 1 + src/usr/testcore/lib/makefile | 30 +++--- src/usr/testcore/lib/runtime/makefile | 30 ++++++ src/usr/testcore/makefile | 30 +++--- src/usr/testcore/rtloader/loader.H | 164 ++++++++++++++++++++++++++++++ src/usr/testcore/rtloader/makefile | 28 +++++ src/usr/trace/compdesc.C | 2 + src/usr/trace/makefile | 4 +- src/usr/trace/runtime/makefile | 30 ++++++ src/usr/trace/runtime/rt_service.C | 96 +++++++++++++++++ src/usr/trace/service.H | 4 +- 36 files changed, 1264 insertions(+), 128 deletions(-) create mode 100644 src/include/runtime/interface.h create mode 100644 src/runtime/makefile create mode 100644 src/runtime/rt_assert.C create mode 100644 src/runtime/rt_console.C create mode 100644 src/runtime/rt_main.C create mode 100644 src/runtime/rt_start.S create mode 100644 src/runtime/rt_stdlib.C create mode 100644 src/runtime/rt_sync.C create mode 100644 src/runtime/rt_vfs.C create mode 100644 src/usr/cxxtest/runtime/makefile create mode 100644 src/usr/cxxtest/runtime/rt_cxxtestexec.C create mode 100644 src/usr/testcore/lib/runtime/makefile create mode 100644 src/usr/testcore/rtloader/loader.H create mode 100644 src/usr/testcore/rtloader/makefile create mode 100644 src/usr/trace/runtime/makefile create mode 100644 src/usr/trace/runtime/rt_service.C (limited to 'src') diff --git a/src/build/buildpnor/defaultPnorLayout.xml b/src/build/buildpnor/defaultPnorLayout.xml index 57623706a..102b0fad3 100644 --- a/src/build/buildpnor/defaultPnorLayout.xml +++ b/src/build/buildpnor/defaultPnorLayout.xml @@ -94,6 +94,13 @@ Layout Description 0x1400000 A +
+ Hostboot Runtime Services for Sapphire (2MB) + HBRT + 0x2190000 + 0x200000 + A +
Special PNOR Test Space (32K) TEST diff --git a/src/build/linker/linker.C b/src/build/linker/linker.C index cebfb31d5..e0ca2adc2 100644 --- a/src/build/linker/linker.C +++ b/src/build/linker/linker.C @@ -271,6 +271,7 @@ vector module_tables; map weak_symbols; set all_symbols; set weak_symbols_to_check; +bool includes_extended_image = false; //----------------------------------------------------------------------------- // MAIN @@ -330,6 +331,7 @@ int main(int argc, char** argv) { base_addr = strtoul(fname.c_str()+11,NULL,16) * 0x1000; isOutput = true; + includes_extended_image = true; } else { @@ -423,9 +425,11 @@ int main(int argc, char** argv) // cout << "Updating last address..." << std::hex; + const Symbol& last_address_symbol = + objects[0].symbols[VFS_TOSTRING(VFS_LAST_ADDRESS)]; uint64_t last_address_entry_address = - objects[0].symbols[VFS_TOSTRING(VFS_LAST_ADDRESS)].address + - objects[0].offset + objects[0].data.vma_offset; + last_address_symbol.address + last_address_symbol.base + + objects[0].offset; fseek(objects[0].iv_output, last_address_entry_address, SEEK_SET); @@ -435,7 +439,8 @@ int main(int argc, char** argv) cout << last_address << " to " << last_address_entry_address << endl; - // Output relocation data. + // Output relocation data for single file images. (non-extended) + if (!includes_extended_image) { fseek(objects[0].iv_output, 0, SEEK_END); char temp64[sizeof(uint64_t)]; diff --git a/src/build/mkrules/cflags.env.mk b/src/build/mkrules/cflags.env.mk index 1ab9b9a30..106dc408b 100644 --- a/src/build/mkrules/cflags.env.mk +++ b/src/build/mkrules/cflags.env.mk @@ -44,3 +44,8 @@ INCFLAGS = $(addprefix -I, $(INCDIR) ) ASMINCFLAGS = $(addprefix $(lastword -Wa,-I), $(INCDIR)) FLAGS_FILTER ?= $(1) + +ifdef HOSTBOOT_RUNTIME +CFLAGS += -D__HOSTBOOT_RUNTIME=1 +TRACE_FLAGS += --full-strings +endif diff --git a/src/build/mkrules/dist.targets.mk b/src/build/mkrules/dist.targets.mk index c7afac9ee..b36c92a34 100644 --- a/src/build/mkrules/dist.targets.mk +++ b/src/build/mkrules/dist.targets.mk @@ -79,6 +79,7 @@ COPY_RENAME_FILES = \ hbicore.bin:img/hbicore$(UNDERSCORE_TEST).bin:vpo \ img/hostboot.bin:img/hbicore$(UNDERSCORE_TEST).bin:fsp \ img/hostboot_extended.bin:img/hbicore$(UNDERSCORE_TEST)_extended.bin:fsp \ + img/hostboot_runtime.bin:img/hbirt$(UNDERSCORE_TEST).bin:fsp \ vbu_MURANO.pnor:img/vbu$(UNDERSCORE_TEST)_MURANO.pnor:vpo \ vbu_VENICE.pnor:img/vbu$(UNDERSCORE_TEST)_VENICE.pnor:vpo \ hbicore.syms:img/hbicore$(UNDERSCORE_TEST).syms:tools,vpo \ diff --git a/src/build/mkrules/hbfw/img/makefile b/src/build/mkrules/hbfw/img/makefile index f56194cab..54d1baa39 100755 --- a/src/build/mkrules/hbfw/img/makefile +++ b/src/build/mkrules/hbfw/img/makefile @@ -47,7 +47,8 @@ install_all: build_pnor_images ################################################# BASE_IMAGE = hostboot.bin EXT_IMAGE = hostboot_extended.bin -BASE_IMAGES = ${BASE_IMAGE} ${EXT_IMAGE} +HBRT_IMAGE = hostboot_runtime.bin +BASE_IMAGES = ${BASE_IMAGE} ${EXT_IMAGE} ${HBRT_IMAGE} BASE_W_HEADER_IMAGE = hostboot.header.bin BASE_W_HEADER_ECC_IMAGE = hostboot.header.bin.ecc BASE_ECC_IMAGE = hostboot.bin.ecc @@ -88,7 +89,7 @@ PNOR_BUILD_SCRIPT = ${buildpnor.pl:P} #so need to use tryinclude for now. .tryinclude <${.PATH:Ffips_pnor.mk}> -HOSTBOOT_DEFAULT_SECTIONS = HBB=${BASE_W_HEADER_ECC_IMAGE},HBI=${EXT_IMAGE} +HOSTBOOT_DEFAULT_SECTIONS = HBB=${BASE_W_HEADER_ECC_IMAGE},HBI=${EXT_IMAGE},HBRT=${HBRT_IMAGE} HBFW_OBJPATH = ${.PATH:M*obj*} ENGD_OBJPATH = ${HBFW_OBJPATH:S/hbfw\/img/engd\/href/g} diff --git a/src/build/mkrules/images.rules.mk b/src/build/mkrules/images.rules.mk index 190f29be5..3b660925c 100644 --- a/src/build/mkrules/images.rules.mk +++ b/src/build/mkrules/images.rules.mk @@ -37,7 +37,7 @@ define ELF_template $$(IMGDIR)/$(1).elf: $$(addprefix $$(OBJDIR)/, $$($(1)_OBJECTS)) \ $$(ROOTPATH)/src/kernel.ld $$(C2) " LD $$(notdir $$@)" - $$(C1)$$(LD) -static $$(LDFLAGS) \ + $$(C1)$$(LD) -static $$(LDFLAGS) $$($$*_LDFLAGS) \ $$(addprefix $$(OBJDIR)/, $$($(1)_OBJECTS)) \ $$($(1)_LDFLAGS) -T $$(ROOTPATH)/src/kernel.ld -o $$@ endef @@ -49,8 +49,11 @@ $(IMGDIR)/%.bin: $(IMGDIR)/%.elf \ $(C2) " LINKER $(notdir $@)" $(C1)set -o pipefail && $(CUSTOM_LINKER) $@ $< \ $(addprefix $(IMGDIR)/lib, $(addsuffix .so, $($*_MODULES))) \ + $(if $($*_EXTENDED_MODULES), \ --extended=0x40000 $(IMGDIR)/$*_extended.bin \ - $(addprefix $(IMGDIR)/lib, $(addsuffix .so, $($*_EXTENDED_MODULES))) \ + $(addprefix $(IMGDIR)/lib, \ + $(addsuffix .so, $($*_EXTENDED_MODULES))) \ + ) \ $(addprefix $(IMGDIR)/, $($*_DATA_MODULES)) \ | bzip2 -zc > $(IMGDIR)/.$*.lnkout.bz2 $(C1)$(ROOTPATH)/src/build/tools/addimgid $@ $< @@ -58,7 +61,8 @@ $(IMGDIR)/%.bin: $(IMGDIR)/%.elf \ $(IMGDIR)/%.list.bz2 $(IMGDIR)/%.syms: $(IMGDIR)/%.bin $(C2) " GENLIST $(notdir $*)" $(C1)(cd $(ROOTPATH)&& \ - src/build/linker/gensyms $*.bin $*_extended.bin 0x40000000 \ + src/build/linker/gensyms $*.bin \ + $(if $($*_EXTENDED_MODULES), $*_extended.bin 0x40000000) \ > ./img/$*.syms && \ src/build/linker/genlist $*.bin | bzip2 -zc > ./img/$*.list.bz2) diff --git a/src/include/builtins.h b/src/include/builtins.h index 1c07e8d04..03bf5325a 100644 --- a/src/include/builtins.h +++ b/src/include/builtins.h @@ -41,6 +41,11 @@ extern "C" */ #define ALWAYS_INLINE __attribute__((always_inline)) +/** + * Use of this macro will ensure that a function is never inlined. + */ +#define NEVER_INLINE __attribute__((noinline)) + /** * Use of this macro will ensure a data structure is aligned on a cacheline boundary */ diff --git a/src/include/runtime/interface.h b/src/include/runtime/interface.h new file mode 100644 index 000000000..fd3e1ba79 --- /dev/null +++ b/src/include/runtime/interface.h @@ -0,0 +1,79 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/include/runtime/interface.h $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#ifndef __RUNTIME__INTERFACE_H +#define __RUNTIME__INTERFACE_H + +/** @file interface.h + * @brief Interfaces between Hostboot Runtime and Sapphire. + * + * This file has two structures of function pointers: hostInterfaces_t and + * runtimeInterfaces_t. hostInterfaces are provided by Sapphire (or a + * similar environment, such as Hostboot IPL's CxxTest execution). + * runtimeInterfaces are provided by Hostboot Runtime to Sapphire. + * + * @note This file must be in C rather than C++. + */ + +#include + +/** @typedef hostInterfaces_t + * @brief Interfaces provided by the underlying environment (ex. Sapphire). + * + * @note Some of these functions are not required (marked optional) and + * may be NULL. + */ +typedef struct hostInterfaces +{ + /** Put a string to the console. */ + void (*puts)(const char*); + /** Critical failure in runtime execution. */ + void (*assert)(); + + /** OPTIONAL. Hint to environment that the page may be executed. */ + int (*set_page_execute)(void*); + + /** malloc */ + void* (*malloc)(size_t); + /** free */ + void (*free)(void*); + /** realloc */ + void* (*realloc)(void*, size_t); + +} hostInterfaces_t; + +typedef struct runtimeInterfaces +{ + /** Execute CxxTests that may be contained in the image. + * + * @param[in] - Pointer to CxxTestStats structure for results reporting. + */ + void (*cxxtestExecute)(void*); + +} runtimeInterfaces_t; + +#ifdef __HOSTBOOT_RUNTIME +extern hostInterfaces_t* g_hostInterfaces; +runtimeInterfaces_t* getRuntimeInterfaces(); +#endif + +#endif diff --git a/src/include/stdio.h b/src/include/stdio.h index abf4c3b72..0e066af3b 100644 --- a/src/include/stdio.h +++ b/src/include/stdio.h @@ -1,34 +1,37 @@ -// IBM_PROLOG_BEGIN_TAG -// This is an automatically generated prolog. -// -// $Source: src/include/stdio.h $ -// -// IBM CONFIDENTIAL -// -// COPYRIGHT International Business Machines Corp. 2011 -// -// p1 -// -// Object Code Only (OCO) source materials -// Licensed Internal Code Source Materials -// IBM HostBoot Licensed Internal Code -// -// The source code for this program is not published or other- -// wise divested of its trade secrets, irrespective of what has -// been deposited with the U.S. Copyright Office. -// -// Origin: 30 -// -// IBM_PROLOG_END +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/include/stdio.h $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2011,2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ #ifndef __STDIO_H #define __STDIO_H +#include + #ifdef __cplusplus extern "C" { #endif int sprintf(char *str, const char * format, ...); +int vsprintf(char *str, const char * format, va_list); #ifdef __cplusplus diff --git a/src/include/usr/cxxtest/TestSuite.H b/src/include/usr/cxxtest/TestSuite.H index cfeb76be0..af6b03b50 100755 --- a/src/include/usr/cxxtest/TestSuite.H +++ b/src/include/usr/cxxtest/TestSuite.H @@ -5,7 +5,7 @@ /* */ /* IBM CONFIDENTIAL */ /* */ -/* COPYRIGHT International Business Machines Corp. 2011,2012 */ +/* COPYRIGHT International Business Machines Corp. 2011,2013 */ /* */ /* p1 */ /* */ @@ -110,6 +110,26 @@ extern uint64_t g_ModulesCompleted; #define TS_FAIL(...) TRACFCOMP( g_trac_test, "!!!TS_FAIL> " __VA_ARGS__); \ CxxTest::doFailTest( __FILE__, __LINE__ ) +// These are all implemented in the cxxtest_data.C that gets put into the base +// image. +extern uint64_t g_TotalTests; +extern uint64_t g_TraceCalls; +extern uint64_t g_Warnings; +extern uint64_t g_FailedTests; +extern uint64_t g_ModulesStarted; +extern uint64_t g_ModulesCompleted; + +// Statistics structure for passing original pointers to the runtime test suite. +struct CxxTestStats +{ + uint64_t* totalTests; + uint64_t* traceCalls; + uint64_t* warnings; + uint64_t* failedTests; + uint64_t* modulesStarted; + uint64_t* modulesCompleted; +}; + } #endif // __cxxtest__TestSuite_h__ diff --git a/src/include/usr/pnor/pnorif.H b/src/include/usr/pnor/pnorif.H index 4f3b5d930..bc3594f70 100644 --- a/src/include/usr/pnor/pnorif.H +++ b/src/include/usr/pnor/pnorif.H @@ -5,7 +5,7 @@ /* */ /* IBM CONFIDENTIAL */ /* */ -/* COPYRIGHT International Business Machines Corp. 2011,2012 */ +/* COPYRIGHT International Business Machines Corp. 2011,2013 */ /* */ /* p1 */ /* */ @@ -44,6 +44,7 @@ enum SectionId SBE_IPL, /**< Self-Boot Engine IPL image */ WINK, /**< Sleep Winkle Reference image */ PAYLOAD, /**< HAL/OPAL */ + HB_RUNTIME, /**< Hostboot Runtime (for Sapphire) */ HB_DATA, /**< Hostboot Data */ GUARD_DATA, /**< Guard Data */ HB_ERRLOGS, /**< Hostboot Error log Repository */ diff --git a/src/kernel/basesegment.C b/src/kernel/basesegment.C index e9f966433..c9843beda 100644 --- a/src/kernel/basesegment.C +++ b/src/kernel/basesegment.C @@ -73,7 +73,7 @@ void BaseSegment::_init() if (i == 0) continue; // Set pages in kernel text section to be read-only / executable. - if (((uint64_t)&data_load_address) > i) + if ((ALIGN_PAGE_DOWN((uint64_t)&data_load_address)) > i) { // Set the Text section to Excutable (implies read) iv_block->setPhysicalPage(i, i, EXECUTABLE); diff --git a/src/lib/stdio.C b/src/lib/stdio.C index 0dc617276..0bdb63873 100644 --- a/src/lib/stdio.C +++ b/src/lib/stdio.C @@ -1,25 +1,25 @@ -// IBM_PROLOG_BEGIN_TAG -// This is an automatically generated prolog. -// -// $Source: src/lib/stdio.C $ -// -// IBM CONFIDENTIAL -// -// COPYRIGHT International Business Machines Corp. 2011 -// -// p1 -// -// Object Code Only (OCO) source materials -// Licensed Internal Code Source Materials -// IBM HostBoot Licensed Internal Code -// -// The source code for this program is not published or other- -// wise divested of its trade secrets, irrespective of what has -// been deposited with the U.S. Copyright Office. -// -// Origin: 30 -// -// IBM_PROLOG_END +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/lib/stdio.C $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2011,2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ #include #include #include @@ -28,24 +28,24 @@ class SprintfBuffer { public: - int putc(int c) - { - if ('\b' == c) - { - iv_pos--; - } - else - { - iv_buffer[iv_pos++] = c; - } - return c; - } + int putc(int c) + { + if ('\b' == c) + { + iv_pos--; + } + else + { + iv_buffer[iv_pos++] = c; + } + return c; + } - explicit SprintfBuffer(char* buf) : iv_pos(0), iv_buffer(buf) {}; + explicit SprintfBuffer(char* buf) : iv_pos(0), iv_buffer(buf) {}; private: - size_t iv_pos; - char * iv_buffer; + size_t iv_pos; + char * iv_buffer; }; int sprintf(char *str, const char * format, ...) @@ -58,9 +58,21 @@ int sprintf(char *str, const char * format, ...) SprintfBuffer console(str); size_t count = vasprintf(mem_ptr_fun(console, &SprintfBuffer::putc), - format, args); + format, args); va_end(args); console.putc('\0'); return count; } + +int vsprintf(char *str, const char * format, va_list args) +{ + using Util::mem_ptr_fun; + + SprintfBuffer console(str); + size_t count = vasprintf(mem_ptr_fun(console, &SprintfBuffer::putc), + format, args); + + console.putc('\0'); + return count; +} diff --git a/src/makefile b/src/makefile index 1a8a81ec7..33dad720c 100644 --- a/src/makefile +++ b/src/makefile @@ -23,13 +23,11 @@ ROOTPATH = .. -SUBDIRS = kernel.d lib.d libc++.d sys.d usr.d build.d -IMGS = hbicore hbicore_test +SUBDIRS = kernel.d lib.d libc++.d sys.d usr.d build.d runtime.d +IMGS = hbicore hbicore_test hbirt hbirt_test -BASE_OBJECTS = console.o spinlock.o string.o string_ext.o stdlib.o ctype.o \ - assert.o stdio.o builtins.o vfs_init.o heapmgr.o pagemgr.o \ - math.o barrier.o idebug.o intmsghandler.o deferred.o \ - idletask.o splaytree.o +BASE_OBJECTS = string.o string_ext.o ctype.o math.o builtins.o stdio.o \ + splaytree.o cxxtest_data.o ifdef HOSTBOOT_PROFILE BASE_OBJECTS += gcov.o @@ -41,9 +39,12 @@ DIRECT_BOOT_OBJECTS = start.o kernel.o taskmgr.o cpumgr.o syscall.o \ syscall_msg.o syscall_mmio.o syscall_time.o \ syscall_mm.o init_main.o vfs_main.o sync.o futexmgr.o \ ptmgr.o segmentmgr.o basesegment.o devicesegment.o \ - block.o cxxtest_data.o cpuid.o misc.o msghandler.o \ - blockmsghdlr.o stacksegment.o softpatch_p8.o \ - shutdown.o forceattn_p8.o terminate.o ipc.o machchk.o + block.o misc.o msghandler.o blockmsghdlr.o \ + stacksegment.o softpatch_p8.o shutdown.o forceattn_p8.o \ + terminate.o ipc.o machchk.o console.o spinlock.o \ + heapmgr.o pagemgr.o barrier.o idebug.o intmsghandler.o \ + deferred.o idletask.o vfs_init.o cpuid.o stdlib.o \ + assert.o BASE_MODULES = trace errl devicefw scom xscom initservice \ secureboot_base pnor vfs @@ -66,7 +67,13 @@ TESTCASE_MODULES = cxxtest testtrace testerrl testdevicefw testsyslib \ testpnor testi2c testfsi testvfs testhwas testintr testvpd \ testpore testutil testmbox testmdia testprdf testattn \ testscan testruntime testibscom testdump testsecureboot \ - testfsiscom + testfsiscom testrtloader + +RUNTIME_OBJECTS = rt_start.o rt_main.o rt_console.o rt_stdlib.o rt_sync.o \ + rt_assert.o rt_vfs.o +RUNTIME_MODULES = trace_rt +RUNTIME_DATA_MODULES = +RUNTIME_TESTCASE_MODULES = cxxtest_rt testsyslib_rt RELOCATABLE_IMAGE_LDFLAGS = -pie --export-dynamic @@ -98,6 +105,16 @@ hbicore_test_EXTENDED_MODULES = ${hbicore_EXTENDED_MODULES} ${TESTCASE_MODULES} hbicore_test_DATA_MODULES = ${hbicore_DATA_MODULES} testdata \ test_signed_container +hbirt_OBJECTS = ${RUNTIME_OBJECTS} ${BASE_OBJECTS} +hbirt_MODULES = ${RUNTIME_MODULES} +hbirt_DATA_MODULES = ${RUNTIME_DATA_MODULES} +hbirt_LDFLAGS = ${RELOCATABLE_IMAGE_LDFLAGS} + +hbirt_test_OBJECTS = ${hbirt_OBJECTS} +hbirt_test_MODULES = ${hbirt_MODULES} ${RUNTIME_TESTCASE_MODULES} +hbirt_test_DATA_MODULES = ${hbirt_DATA_MODULES} +hbirt_test_LDFLAGS = ${RELOCATABLE_IMAGE_LDFLAGS} + IMAGE_PASS_POST += buildpnor imgsizecheck IMAGE_PASS_POST += $(IMGDIR)/hbotStringFile diff --git a/src/runtime/makefile b/src/runtime/makefile new file mode 100644 index 000000000..06ea1d3bc --- /dev/null +++ b/src/runtime/makefile @@ -0,0 +1,29 @@ +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/runtime/makefile $ +# +# IBM CONFIDENTIAL +# +# COPYRIGHT International Business Machines Corp. 2013 +# +# p1 +# +# Object Code Only (OCO) source materials +# Licensed Internal Code Source Materials +# IBM HostBoot Licensed Internal Code +# +# The source code for this program is not published or otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. +# +# Origin: 30 +# +# IBM_PROLOG_END_TAG +HOSTBOOT_RUNTIME = 1 +ROOTPATH = ../.. + +OBJS = rt_start.o rt_main.o rt_console.o rt_stdlib.o rt_sync.o rt_assert.o \ + rt_vfs.o + +include ${ROOTPATH}/config.mk diff --git a/src/runtime/rt_assert.C b/src/runtime/rt_assert.C new file mode 100644 index 000000000..9821a0fad --- /dev/null +++ b/src/runtime/rt_assert.C @@ -0,0 +1,41 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/runtime/rt_assert.C $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include +#include +#include +#include + +/** Hook location for trace module to set up when loaded. */ +namespace TRACE { void (*traceCallback)(void*, size_t) = NULL; }; + +extern "C" void __assert(AssertBehavior i_assertb, int i_line) +{ + if (i_assertb != ASSERT_TRACE_DONE) + { + printk("Assertion failed @%p on line %d.\n", + linkRegister(), i_line); + } + + g_hostInterfaces->assert(); + while(1); +} diff --git a/src/runtime/rt_console.C b/src/runtime/rt_console.C new file mode 100644 index 000000000..930e37462 --- /dev/null +++ b/src/runtime/rt_console.C @@ -0,0 +1,39 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/runtime/rt_console.C $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include +#include +#include +#include + +void printk(const char* str, ...) +{ + va_list args; + va_start(args, str); + + char buffer[512]; + vsprintf(buffer, str, args); + + va_end(args); + + g_hostInterfaces->puts(buffer); +} diff --git a/src/runtime/rt_main.C b/src/runtime/rt_main.C new file mode 100644 index 000000000..910a0d1d8 --- /dev/null +++ b/src/runtime/rt_main.C @@ -0,0 +1,123 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/runtime/rt_main.C $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include +#include +#include +#include +#include +#include + +// Address of the first writable page, initialized by the linker. +extern void* data_load_address; +// Forward declaration to vfs code. +void vfs_module_init(); + + +/** @fn _main + * + * @brief Entry point called from Sapphire to initialize RT image. + * + * @param[in] intf - Runtime interfaces structure from Sapphire. + * @param[in] base - Memory address of the start of the RT image. + * + * @return - runtimeInterfaces_t* - Pointer to RT image's interfaces. + * + * This function is required to be in the .text.intvects section so that + * it is placed into the first page (4k) of the image. When HB IPL + * loads the RT image for CxxTest execution it will only mark the first + * page executable. The remainder is marked execute via callbacks from + * within _main. + */ +extern "C" +{ + runtimeInterfaces_t* _main(hostInterfaces_t*, uint64_t base) + SYMB_SECTION(".text.intvects"); +} + +/** @fn rt_start + * + * @brief Remainder of RT image initializion. + * + * After _main marks pages executable we can leave the first page of the + * image. This function performs the bulk of the initialization: + * + * 1) Call C++ constructors for this image. + * 2) Load all modules in the image. + * + * @param[in] intf - Runtime interfaces structure from Sapphire. + */ +runtimeInterfaces_t* rt_start(hostInterfaces_t*) NEVER_INLINE; + +/** Call C++ constructors present in this image. */ +void rt_cppBootstrap(); + +runtimeInterfaces_t* _main(hostInterfaces_t* intf, uint64_t base) +{ + // Ensure remainder of image has text pages marked execute. + for (uint64_t i = base; + i < ALIGN_PAGE_DOWN((uint64_t)&data_load_address); + i += PAGESIZE) + { + (intf->set_page_execute)(reinterpret_cast(i)); + } + + // Tail-recurse to real entry point. + return rt_start(intf); +} + +runtimeInterfaces_t* rt_start(hostInterfaces_t* intf) +{ + (intf->puts)("Starting Runtime Services....\n"); + + // Save a pointer to interfaces from Sapphire. + g_hostInterfaces = intf; + + // Call C++ constructors. + rt_cppBootstrap(); + + // Initialize all modules. + vfs_module_init(); + + // Return our interface pointer structure. + return getRuntimeInterfaces(); +} + +void rt_cppBootstrap() +{ + // Call default constructors for any static objects. + extern void (*ctor_start_address)(); + extern void (*ctor_end_address)(); + void(**ctors)() = &ctor_start_address; + while(ctors != &ctor_end_address) + { + (*ctors)(); + ctors++; + } +} + +hostInterfaces_t* g_hostInterfaces = NULL; + +runtimeInterfaces_t* getRuntimeInterfaces() +{ + return &Singleton::instance(); +} diff --git a/src/runtime/rt_start.S b/src/runtime/rt_start.S new file mode 100644 index 000000000..cea710b57 --- /dev/null +++ b/src/runtime/rt_start.S @@ -0,0 +1,72 @@ +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/runtime/rt_start.S $ +# +# IBM CONFIDENTIAL +# +# COPYRIGHT International Business Machines Corp. 2013 +# +# p1 +# +# Object Code Only (OCO) source materials +# Licensed Internal Code Source Materials +# IBM HostBoot Licensed Internal Code +# +# The source code for this program is not published or otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. +# +# Origin: 30 +# +# IBM_PROLOG_END_TAG +.include "kernel/ppcconsts.S" + +.section .text.intvects + +.org 0x100; +_init: + mflr r10 # Save LR + bl 1f # Get current address by branch-with-link. +1: + mflr r4 # Extract current address. + mtlr r10 # Restore LR. + clrrdi r4, r4, 12 # Align address to 4k. + + addi r10, r4, 0x2000 # Find VFS_LAST_ADDRESS symbol. + ld r10, 0(r10) # Read start of relocation table. + add r10, r10, r4 + + ld r8, 0(r10) # Get count of relocations. + + cmpi cr0, r8, 0 # Perform relocations (if any). + beq 2f + mtctr r8 +1: + ldu r8, 8(r10) # Get relocation destination + add r8, r8, r4 + ld r7, 0(r8) # Get relocation address + add r7, r7, r4 + std r7, 0(r8) # Update relocation address. + bdnz 1b # Decrement CTR and continue loop. +2: + addi r10, r4, 0x2008 # Find pointer to main TOC. + ld r10, 0(r10) # Dereference pointer to get TOC entry. + ld r2, 8(r10) + ld r10, 0(r10) + mtctr r10 + bctr + +.section .text.kernelasm # @2000 +.global VFS_LAST_ADDRESS +VFS_LAST_ADDRESS: + .space 8 +main_toc_ptr: + .quad _main + + +.section .data + +.global hbi_ImageId +hbi_ImageId: + .space 128 diff --git a/src/runtime/rt_stdlib.C b/src/runtime/rt_stdlib.C new file mode 100644 index 000000000..ec92badc6 --- /dev/null +++ b/src/runtime/rt_stdlib.C @@ -0,0 +1,56 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/runtime/rt_stdlib.C $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include +#include +#include + +void* malloc(size_t s) +{ + return g_hostInterfaces->malloc(s); +} + +void free(void* p) +{ + g_hostInterfaces->free(p); +} + +void* realloc(void* p, size_t s) +{ + return g_hostInterfaces->realloc(p, s); +} + +void* calloc(size_t num, size_t size) +{ + // Allocate a block of memory for an array of 'num' elements, each of them + // 'size' bytes long and initialize to zero + size_t total_size = num * size; + void* mem = NULL; + + if (total_size) + { + mem = malloc(total_size); + memset(mem, 0, total_size); + } + + return mem; +} diff --git a/src/runtime/rt_sync.C b/src/runtime/rt_sync.C new file mode 100644 index 000000000..037bdaa25 --- /dev/null +++ b/src/runtime/rt_sync.C @@ -0,0 +1,29 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/runtime/rt_sync.C $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include + +void mutex_init(mutex_t*) {}; +void mutex_destroy(mutex_t*) {}; +void mutex_lock(mutex_t*) {}; +void mutex_unlock(mutex_t*) {}; + diff --git a/src/runtime/rt_vfs.C b/src/runtime/rt_vfs.C new file mode 100644 index 000000000..7558f222c --- /dev/null +++ b/src/runtime/rt_vfs.C @@ -0,0 +1,125 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/runtime/rt_vfs.C $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include +#include +#include +#include +#include +#include +#include + +VfsSystemModule VFS_MODULES[VFS_MODULE_MAX]; + +void vfs_module_init() +{ + printk("Initializing modules.\n"); + + VfsSystemModule* module = &VFS_MODULES[0]; + while ('\0' != module->module[0]) + { + uint64_t textsize = (uint64_t)module->data - (uint64_t)module->text; + if (textsize != 0) + { + for (uint64_t i = (uint64_t)module->text; + i < (uint64_t)module->data; + i += PAGESIZE) + { + g_hostInterfaces->set_page_execute(reinterpret_cast(i)); + } + } + + ++module; + } + + module = &VFS_MODULES[0]; + while ('\0' != module->module[0]) + { + printk("\tIniting module %s...", module->module); + if (NULL != module->init) + { + (module->init)(NULL); + } + printk("done.\n"); + + ++module; + } + + printk("Modules initialized.\n"); + +} + +VfsSystemModule * vfs_find_module(VfsSystemModule * i_table, + const char * i_name) +{ + VfsSystemModule* module = i_table; + VfsSystemModule* ret = NULL; + while ('\0' != module->module[0]) + { + if (0 == strcmp(i_name,module->module)) + { + ret = module; + break; + } + module++; + } + return ret; +} + +void* vfs_start_entrypoint(VfsSystemModule * i_module) +{ + void* ptr = reinterpret_cast(-ENOENT); + if(i_module != NULL) + { + if (i_module->start == NULL) + { + // module has no start() routine + ptr = reinterpret_cast(-ENOEXEC); + } + else + { + ptr = reinterpret_cast(i_module->start); + } + } + return ptr; +} + +namespace VFS +{ + void find_test_modules(std::vector & o_list) + { + o_list.clear(); + + for(VfsSystemModule* vfsItr = &VFS_MODULES[0]; + '\0' != vfsItr->module[0]; + vfsItr++) + { + if (0 == memcmp(vfsItr->module, "libtest", 7)) + { + if (NULL != vfsItr->start) + { + o_list.push_back(vfsItr->module); + } + } + } + } +} diff --git a/src/usr/cxxtest/makefile b/src/usr/cxxtest/makefile index 979ae0bd4..c02f22d8d 100644 --- a/src/usr/cxxtest/makefile +++ b/src/usr/cxxtest/makefile @@ -1,30 +1,30 @@ -# IBM_PROLOG_BEGIN_TAG -# This is an automatically generated prolog. +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. # -# $Source: src/usr/cxxtest/makefile $ +# $Source: src/usr/cxxtest/makefile $ # -# IBM CONFIDENTIAL +# IBM CONFIDENTIAL # -# COPYRIGHT International Business Machines Corp. 2011 +# COPYRIGHT International Business Machines Corp. 2011,2013 # -# p1 +# p1 # -# Object Code Only (OCO) source materials -# Licensed Internal Code Source Materials -# IBM HostBoot Licensed Internal Code +# Object Code Only (OCO) source materials +# Licensed Internal Code Source Materials +# IBM HostBoot Licensed Internal Code # -# The source code for this program is not published or other- -# wise divested of its trade secrets, irrespective of what has -# been deposited with the U.S. Copyright Office. +# The source code for this program is not published or otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. # -# Origin: 30 +# Origin: 30 # -# IBM_PROLOG_END +# IBM_PROLOG_END_TAG ROOTPATH = ../../.. MODULE = cxxtest -SUBDIRS=test.d +SUBDIRS=test.d runtime.d OBJS = TestSuite.o cxxtestexec.o diff --git a/src/usr/cxxtest/runtime/makefile b/src/usr/cxxtest/runtime/makefile new file mode 100644 index 000000000..4bdab1441 --- /dev/null +++ b/src/usr/cxxtest/runtime/makefile @@ -0,0 +1,31 @@ +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/usr/cxxtest/runtime/makefile $ +# +# IBM CONFIDENTIAL +# +# COPYRIGHT International Business Machines Corp. 2013 +# +# p1 +# +# Object Code Only (OCO) source materials +# Licensed Internal Code Source Materials +# IBM HostBoot Licensed Internal Code +# +# The source code for this program is not published or otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. +# +# Origin: 30 +# +# IBM_PROLOG_END_TAG +HOSTBOOT_RUNTIME = 1 +ROOTPATH = ../../../.. +MODULE = cxxtest_rt + +OBJS = TestSuite.o rt_cxxtestexec.o + +VPATH += .. + +include ${ROOTPATH}/config.mk diff --git a/src/usr/cxxtest/runtime/rt_cxxtestexec.C b/src/usr/cxxtest/runtime/rt_cxxtestexec.C new file mode 100644 index 000000000..08956f00a --- /dev/null +++ b/src/usr/cxxtest/runtime/rt_cxxtestexec.C @@ -0,0 +1,76 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/cxxtest/runtime/rt_cxxtestexec.C $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include +#include +#include +#include + +#include +#include + +trace_desc_t *g_trac_cxxtest = NULL; +TRAC_INIT(&g_trac_cxxtest, CXXTEST_COMP_NAME, KILOBYTE ); + +namespace CxxTest +{ + void execute(void* io_stats) + { + CxxTestStats* stats = reinterpret_cast(io_stats); + + std::vector module_list; + VFS::find_test_modules(module_list); + + printk("Running Runtime CXX Tests: %ld\n", module_list.size()); + + g_ModulesStarted++; + for (std::vector::const_iterator i = module_list.begin(); + i != module_list.end(); + ++i) + { + g_ModulesStarted++; + + printk("\tRunning Runtime test: %s\n", *i); + void* (*start_entry)(void*) = reinterpret_cast( + vfs_start_entrypoint(vfs_find_module(VFS_MODULES, *i))); + start_entry(NULL); + } + + g_ModulesCompleted++; + + __sync_add_and_fetch(stats->totalTests, g_TotalTests); + __sync_add_and_fetch(stats->traceCalls, g_TraceCalls); + __sync_add_and_fetch(stats->warnings, g_Warnings); + __sync_add_and_fetch(stats->failedTests, g_FailedTests); + __sync_add_and_fetch(stats->modulesStarted, g_ModulesStarted); + __sync_add_and_fetch(stats->modulesCompleted, g_ModulesCompleted); + } + + struct registerCxxTest + { + registerCxxTest() + { + getRuntimeInterfaces()->cxxtestExecute = &execute; + } + }; + registerCxxTest g_register; +} diff --git a/src/usr/pnor/pnorrp.C b/src/usr/pnor/pnorrp.C index 015b9f6ce..debc1bf7e 100644 --- a/src/usr/pnor/pnorrp.C +++ b/src/usr/pnor/pnorrp.C @@ -57,6 +57,7 @@ const char* cv_EYECATCHER[] = { //@todo - convert there to uint64_t "SBE", /**< PNOR::SBE_IPL : Self-Boot Enginer IPL image */ "WINK", /**< PNOR::WINK : Sleep Winkle Reference image */ "PAYLOAD",/**< PNOR::PAYLOAD : HAL/OPAL */ + "HBRT", /**< PNOR::HB_RUNTIME : Hostboot Runtime (for Sapphire) */ "HBD", /**< PNOR::HB_DATA : Hostboot Data */ "GUARD", /**< PNOR::GUARD_DATA : Hostboot Data */ "HBEL", /**< PNOR::HB_ERRLOGS : Hostboot Error log Repository */ diff --git a/src/usr/testcore/lib/makefile b/src/usr/testcore/lib/makefile index e6cd02321..e2516304e 100644 --- a/src/usr/testcore/lib/makefile +++ b/src/usr/testcore/lib/makefile @@ -1,28 +1,30 @@ -# IBM_PROLOG_BEGIN_TAG -# This is an automatically generated prolog. +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. # -# $Source: src/usr/testcore/lib/makefile $ +# $Source: src/usr/testcore/lib/makefile $ # -# IBM CONFIDENTIAL +# IBM CONFIDENTIAL # -# COPYRIGHT International Business Machines Corp. 2011 +# COPYRIGHT International Business Machines Corp. 2011,2013 # -# p1 +# p1 # -# Object Code Only (OCO) source materials -# Licensed Internal Code Source Materials -# IBM HostBoot Licensed Internal Code +# Object Code Only (OCO) source materials +# Licensed Internal Code Source Materials +# IBM HostBoot Licensed Internal Code # -# The source code for this program is not published or other- -# wise divested of its trade secrets, irrespective of what has -# been deposited with the U.S. Copyright Office. +# The source code for this program is not published or otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. # -# Origin: 30 +# Origin: 30 # -# IBM_PROLOG_END +# IBM_PROLOG_END_TAG ROOTPATH = ../../../.. MODULE = testsyslib TESTS = *.H +SUBDIRS = runtime.d + include ${ROOTPATH}/config.mk diff --git a/src/usr/testcore/lib/runtime/makefile b/src/usr/testcore/lib/runtime/makefile new file mode 100644 index 000000000..a745479fd --- /dev/null +++ b/src/usr/testcore/lib/runtime/makefile @@ -0,0 +1,30 @@ +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/usr/testcore/lib/runtime/makefile $ +# +# IBM CONFIDENTIAL +# +# COPYRIGHT International Business Machines Corp. 2013 +# +# p1 +# +# Object Code Only (OCO) source materials +# Licensed Internal Code Source Materials +# IBM HostBoot Licensed Internal Code +# +# The source code for this program is not published or otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. +# +# Origin: 30 +# +# IBM_PROLOG_END_TAG +HOSTBOOT_RUNTIME = 1 +ROOTPATH = ../../../../.. + +MODULE = testsyslib_rt +TESTCASES = stltest.H string.H +TESTS = $(addprefix ../,$(TESTCASES)) + +include $(ROOTPATH)/config.mk diff --git a/src/usr/testcore/makefile b/src/usr/testcore/makefile index 4e1deec5b..a11fbeb1a 100644 --- a/src/usr/testcore/makefile +++ b/src/usr/testcore/makefile @@ -1,28 +1,28 @@ -# IBM_PROLOG_BEGIN_TAG -# This is an automatically generated prolog. +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. # -# $Source: src/usr/testcore/makefile $ +# $Source: src/usr/testcore/makefile $ # -# IBM CONFIDENTIAL +# IBM CONFIDENTIAL # -# COPYRIGHT International Business Machines Corp. 2011 +# COPYRIGHT International Business Machines Corp. 2011,2013 # -# p1 +# p1 # -# Object Code Only (OCO) source materials -# Licensed Internal Code Source Materials -# IBM HostBoot Licensed Internal Code +# Object Code Only (OCO) source materials +# Licensed Internal Code Source Materials +# IBM HostBoot Licensed Internal Code # -# The source code for this program is not published or other- -# wise divested of its trade secrets, irrespective of what has -# been deposited with the U.S. Copyright Office. +# The source code for this program is not published or otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. # -# Origin: 30 +# Origin: 30 # -# IBM_PROLOG_END +# IBM_PROLOG_END_TAG ROOTPATH = ../../.. -SUBDIRS = lib.d kernel.d +SUBDIRS = lib.d kernel.d rtloader.d include ${ROOTPATH}/config.mk diff --git a/src/usr/testcore/rtloader/loader.H b/src/usr/testcore/rtloader/loader.H new file mode 100644 index 000000000..9b17fcea5 --- /dev/null +++ b/src/usr/testcore/rtloader/loader.H @@ -0,0 +1,164 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/testcore/rtloader/loader.H $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#ifndef __TESTCORE_RTLOADER_LOADER_H +#define __TESTCORE_RTLOADER_LOADER_H + +#include +#include +#include + +#include + +class RuntimeLoaderTest : public CxxTest::TestSuite +{ + public: + void testLoader() + { + static const uint64_t HEADER_OFFSET = 0x2000; + + PNOR::SectionInfo_t runtimeSection; + + errlHndl_t l_errl = + PNOR::getSectionInfo(PNOR::HB_RUNTIME, PNOR::CURRENT_SIDE, + runtimeSection); + + if (l_errl) + { + TS_WARN("Could not find runtime section."); + delete l_errl; + return; + } + + if (runtimeSection.size < HEADER_OFFSET) + { + TS_FAIL("Runtime image is not big enough. %x", + runtimeSection.size); + return; + } + + uint64_t imageSize = + *reinterpret_cast(runtimeSection.vaddr + + HEADER_OFFSET); + if (runtimeSection.size < imageSize + sizeof(uint64_t)) + { + TS_FAIL("Image header has too big a size: %x, %x", + runtimeSection.size, imageSize); + return; + } + + uint64_t relocations = + *reinterpret_cast(runtimeSection.vaddr + imageSize); + imageSize += (relocations + 1) * sizeof(uint64_t); + + if (runtimeSection.size < imageSize) + { + TS_FAIL("Image header + relocations is too big: %x, %x, %d", + runtimeSection.size, imageSize, relocations); + return; + } + + void* imageArea = malloc(ALIGN_PAGE(imageSize)); + memcpy(imageArea, reinterpret_cast(runtimeSection.vaddr), + imageSize); + mm_icache_invalidate(imageArea, + ALIGN_PAGE(imageSize) / sizeof(uint64_t)); + + + mm_set_permission(imageArea, HEADER_OFFSET, EXECUTABLE); + + TRACFCOMP(g_trac_test, "Runtime image loaded @ %x", imageArea); + + do + { + hostInterfaces_t* intf = new hostInterfaces_t(); + intf->puts = rt_puts; + intf->set_page_execute = rt_setPageExecute; + intf->malloc = malloc; + intf->free = free; + intf->realloc = realloc; + intf->assert = rt_assert; + + // Call init. + runtimeInterfaces_t* rtInterface = + reinterpret_cast( + callViaCtr( + reinterpret_cast(imageArea) + 0x100, + intf, NULL) + ); + if (NULL == rtInterface) + { + TS_FAIL("Failed to init runtime services."); + break; + } + + { + using namespace CxxTest; + + // Initialize statistics structure. + CxxTestStats cxxTestStats = + { &g_TotalTests, &g_TraceCalls, &g_Warnings, + &g_FailedTests, &g_ModulesStarted, + &g_ModulesCompleted }; + + // Call CxxTest entry. + (*rtInterface->cxxtestExecute)(&cxxTestStats); + } + + } while(0); + + mm_set_permission(imageArea, imageSize, WRITABLE); + free(imageArea); + } + + private: + uint64_t callViaCtr(uint64_t entry, void* param0, void* param1) + { + register uint64_t result = 0; + + asm volatile("mtctr %1; mr 3, %2 ; mr 4, %3; " + "std 2, 40(1); bctrl; ld 2, 40(1); " + "mr %0, 3" : + "=r" (result) : "r" (entry), "r" (param0), "r" (param1) : + "lr","ctr","r0","r3","r4","r5","r6","r7","r8","r9", + "r10","r11"); // TODO: Need to double check the ABI here. + + return result; + } + + static void rt_puts(const char* str) + { + TRACFCOMP(g_trac_test, "RUNTIME MSG: %s", str); + } + + static int rt_setPageExecute(void* addr) + { + return mm_set_permission(addr, PAGESIZE, EXECUTABLE); + } + + static void rt_assert() + { + assert(false); + } +}; + +#endif diff --git a/src/usr/testcore/rtloader/makefile b/src/usr/testcore/rtloader/makefile new file mode 100644 index 000000000..0fcd01d42 --- /dev/null +++ b/src/usr/testcore/rtloader/makefile @@ -0,0 +1,28 @@ +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/usr/testcore/rtloader/makefile $ +# +# IBM CONFIDENTIAL +# +# COPYRIGHT International Business Machines Corp. 2011,2013 +# +# p1 +# +# Object Code Only (OCO) source materials +# Licensed Internal Code Source Materials +# IBM HostBoot Licensed Internal Code +# +# The source code for this program is not published or otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. +# +# Origin: 30 +# +# IBM_PROLOG_END_TAG +ROOTPATH = ../../../.. + +MODULE = testrtloader +TESTS = *.H + +include ${ROOTPATH}/config.mk diff --git a/src/usr/trace/compdesc.C b/src/usr/trace/compdesc.C index ddfd860dc..35f4de0c5 100644 --- a/src/usr/trace/compdesc.C +++ b/src/usr/trace/compdesc.C @@ -93,6 +93,7 @@ namespace TRACE l_rc = &iv_components.back(); } +#ifndef __HOSTBOOT_RUNTIME // TODO: RTC 79408 // Check for special SCAN component to force enable debug trace on. if (0 == memcmp(l_compName, "SCAN", 5)) { @@ -107,6 +108,7 @@ namespace TRACE l_rc->iv_debugEnabled = true; } } +#endif mutex_unlock(&iv_mutex); return l_rc; diff --git a/src/usr/trace/makefile b/src/usr/trace/makefile index c58a11a4f..6195ae522 100644 --- a/src/usr/trace/makefile +++ b/src/usr/trace/makefile @@ -5,7 +5,7 @@ # # IBM CONFIDENTIAL # -# COPYRIGHT International Business Machines Corp. 2011,2012 +# COPYRIGHT International Business Machines Corp. 2011,2013 # # p1 # @@ -26,6 +26,6 @@ MODULE = trace OBJS = interface.o service.o compdesc.o buffer.o bufferpage.o daemonif.o \ debug.o assert.o -SUBDIRS = daemon.d test.d +SUBDIRS = daemon.d test.d runtime.d include ${ROOTPATH}/config.mk diff --git a/src/usr/trace/runtime/makefile b/src/usr/trace/runtime/makefile new file mode 100644 index 000000000..6c4f21407 --- /dev/null +++ b/src/usr/trace/runtime/makefile @@ -0,0 +1,30 @@ +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/usr/trace/runtime/makefile $ +# +# IBM CONFIDENTIAL +# +# COPYRIGHT International Business Machines Corp. 2013 +# +# p1 +# +# Object Code Only (OCO) source materials +# Licensed Internal Code Source Materials +# IBM HostBoot Licensed Internal Code +# +# The source code for this program is not published or otherwise +# divested of its trade secrets, irrespective of what has been +# deposited with the U.S. Copyright Office. +# +# Origin: 30 +# +# IBM_PROLOG_END_TAG +HOSTBOOT_RUNTIME = 1 +ROOTPATH = ../../../.. +MODULE = trace_rt + +OBJS = interface.o assert.o compdesc.o rt_service.o + +VPATH += .. +include $(ROOTPATH)/config.mk diff --git a/src/usr/trace/runtime/rt_service.C b/src/usr/trace/runtime/rt_service.C new file mode 100644 index 000000000..2bb697d3e --- /dev/null +++ b/src/usr/trace/runtime/rt_service.C @@ -0,0 +1,96 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/usr/trace/runtime/rt_service.C $ */ +/* */ +/* IBM CONFIDENTIAL */ +/* */ +/* COPYRIGHT International Business Machines Corp. 2013 */ +/* */ +/* p1 */ +/* */ +/* Object Code Only (OCO) source materials */ +/* Licensed Internal Code Source Materials */ +/* IBM HostBoot Licensed Internal Code */ +/* */ +/* The source code for this program is not published or otherwise */ +/* divested of its trade secrets, irrespective of what has been */ +/* deposited with the U.S. Copyright Office. */ +/* */ +/* Origin: 30 */ +/* */ +/* IBM_PROLOG_END_TAG */ +#include "../service.H" +#include "../compdesc.H" +#include +#include +#include +#include + +namespace TRACE +{ + + Service::Service() + { + } + + Service::~Service() + { + // No need to destruct the service. + assert(0); + } + + void Service::writeEntry(ComponentDesc* i_td, + trace_hash_val i_hash, + const char * i_fmt, + uint32_t i_line, + uint32_t i_type, + va_list i_args) + { + if (unlikely(i_type == TRACE_DEBUG)) + { + if (!i_td->iv_debugEnabled) + { + return; + } + } + + char output[KILOBYTE]; + vsprintf(output, i_fmt, i_args); // TODO: RTC 79420 : + // Potential buffer overrun. + g_hostInterfaces->puts(output); + } + + void Service::writeBinEntry(ComponentDesc* i_td, + trace_hash_val i_hash, + uint32_t i_ine, + const void* i_ptr, + uint32_t i_size, + uint32_t i_type) + { + if (unlikely(i_type == TRACE_DEBUG)) + { + if (!i_td->iv_debugEnabled) + { + return; + } + } + + // TODO: RTC 79420 + + } + + size_t Service::getBuffer(ComponentDesc* i_comp, + void * o_data, + size_t i_size) + { + // No way to get the buffer back in runtime. + return 0; + } + + void Service::flushBuffers() + { + // No-op in runtime. + } + +} diff --git a/src/usr/trace/service.H b/src/usr/trace/service.H index 1f81d9a2f..61e9bc494 100644 --- a/src/usr/trace/service.H +++ b/src/usr/trace/service.H @@ -5,7 +5,7 @@ /* */ /* IBM CONFIDENTIAL */ /* */ -/* COPYRIGHT International Business Machines Corp. 2012 */ +/* COPYRIGHT International Business Machines Corp. 2012,2013 */ /* */ /* p1 */ /* */ @@ -144,6 +144,7 @@ namespace TRACE friend class TRACEDAEMON::Daemon; private: +#ifndef __HOSTBOOT_RUNTIME /** Front-size buffers */ Buffer* iv_buffers[BUFFER_COUNT]; // slow / fast buffers. /** Interface to signal daemon. */ @@ -155,6 +156,7 @@ namespace TRACE static Service* getGlobalInstance(); /** Copy the current time into the timestamp. */ void _createTimeStamp(trace_entry_stamp_t* o_entry); +#endif }; } -- cgit v1.2.1