summaryrefslogtreecommitdiffstats
path: root/src/bootloader
diff options
context:
space:
mode:
authorMarty Gloff <mgloff@us.ibm.com>2015-12-17 10:10:47 -0600
committerStephen Cprek <smcprek@us.ibm.com>2016-02-19 17:06:42 -0600
commitb742fd9b5b3c07129abfa3c099655346f6b1e6a6 (patch)
treef3e3bd027ac048911296cd75b66e06efa0ea2519 /src/bootloader
parent6b3144d3d653cfb3d14cb74598b003cc7c653c73 (diff)
downloadtalos-hostboot-b742fd9b5b3c07129abfa3c099655346f6b1e6a6.tar.gz
talos-hostboot-b742fd9b5b3c07129abfa3c099655346f6b1e6a6.zip
Hostboot Bootloader Infrastructure
New and changed code to provide bootloader infrastructure. Changes to build bootloader and create the image file. Change-Id: Ie400f0ca6954b86e275fd68c9462f8d18eeec98a RTC:127211 Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/22856 Tested-by: Jenkins Server Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/bootloader')
-rw-r--r--src/bootloader/bl_builtins.C34
-rw-r--r--src/bootloader/bl_pnor_ecc.C37
-rw-r--r--src/bootloader/bl_start.S182
-rw-r--r--src/bootloader/bootloader.C84
-rw-r--r--src/bootloader/makefile33
5 files changed, 370 insertions, 0 deletions
diff --git a/src/bootloader/bl_builtins.C b/src/bootloader/bl_builtins.C
new file mode 100644
index 000000000..2e89c55b7
--- /dev/null
+++ b/src/bootloader/bl_builtins.C
@@ -0,0 +1,34 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/bootloader/bl_builtins.C $ */
+/* */
+/* OpenPOWER HostBoot Project */
+/* */
+/* Contributors Listed Below - COPYRIGHT 2015,2016 */
+/* [+] International Business Machines Corp. */
+/* */
+/* */
+/* Licensed under the Apache License, Version 2.0 (the "License"); */
+/* you may not use this file except in compliance with the License. */
+/* You may obtain a copy of the License at */
+/* */
+/* http://www.apache.org/licenses/LICENSE-2.0 */
+/* */
+/* Unless required by applicable law or agreed to in writing, software */
+/* distributed under the License is distributed on an "AS IS" BASIS, */
+/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
+/* implied. See the License for the specific language governing */
+/* permissions and limitations under the License. */
+/* */
+/* IBM_PROLOG_END_TAG */
+#include <bootloader/bootloader.H>
+
+#define bl_builtins_C
+
+#include <arch/ppc.H>
+
+#include <../libc++/builtins.C>
+
+#undef bl_builtins_C
+
diff --git a/src/bootloader/bl_pnor_ecc.C b/src/bootloader/bl_pnor_ecc.C
new file mode 100644
index 000000000..df7e9d6ee
--- /dev/null
+++ b/src/bootloader/bl_pnor_ecc.C
@@ -0,0 +1,37 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/bootloader/bl_pnor_ecc.C $ */
+/* */
+/* OpenPOWER HostBoot Project */
+/* */
+/* Contributors Listed Below - COPYRIGHT 2015,2016 */
+/* [+] International Business Machines Corp. */
+/* */
+/* */
+/* Licensed under the Apache License, Version 2.0 (the "License"); */
+/* you may not use this file except in compliance with the License. */
+/* You may obtain a copy of the License at */
+/* */
+/* http://www.apache.org/licenses/LICENSE-2.0 */
+/* */
+/* Unless required by applicable law or agreed to in writing, software */
+/* distributed under the License is distributed on an "AS IS" BASIS, */
+/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
+/* implied. See the License for the specific language governing */
+/* permissions and limitations under the License. */
+/* */
+/* IBM_PROLOG_END_TAG */
+#include <bootloader/bootloader.H>
+
+#define bl_pnor_ecc_C
+
+#include <stdio.h>
+#include <endian.h>
+
+#include <usr/pnor/ecc.H>
+
+#include <../usr/pnor/ecc.C>
+
+#undef bl_pnor_ecc_C
+
diff --git a/src/bootloader/bl_start.S b/src/bootloader/bl_start.S
new file mode 100644
index 000000000..9f190b11f
--- /dev/null
+++ b/src/bootloader/bl_start.S
@@ -0,0 +1,182 @@
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: src/bootloader/bl_start.S $
+#
+# OpenPOWER HostBoot Project
+#
+# Contributors Listed Below - COPYRIGHT 2015,2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+
+.include "kernel/ppcconsts.S"
+
+.section .text.bootloaderasm
+
+.global _start
+_start:
+ ;// Set thread priority high.
+ or 2,2,2
+
+ ;// Clear MSR[TA] (bit 1) and enable MSR[ME] (bit 51).
+ mfmsr r2
+ rldicl r2,r2,1,1 ;// Clear bit 1 - result [1-63,0]
+ rotrdi r2,r2,1 ;// Rotate right 1 - result [0,63]
+ ori r2,r2,4096 ;// Set bit 51
+ ;// Set up SRR0 / SRR1 to enable new MSR.
+ mtsrr1 r2
+ li r2, _start_postmsr@l
+ mtsrr0 r2
+ b _start_postmsr
+
+_start_postmsr:
+
+ ;// Determine if this is the first thread.
+ li r4, 2
+ ;// Read spinlock value.
+ lis r2, kernel_other_thread_spinlock@h
+ ori r2, r2, kernel_other_thread_spinlock@l
+ lwsync
+1:
+ ldarx r3, 0, r2
+ cmpwi r3, 0 ;// Non-zero means this thread wasn't first.
+ bnel cr0, _other_thread_error ;// Handle having multiple threads started
+ stdcx. r4, 0, r2 ;// Attempt to store 2.
+ bne 1b ;// Loop until sucessful at stwcx.
+ isync
+
+ b _main
+
+
+/* @TODO RTC:133821 might not be needed
+ ;// Relocate code
+ bl pre_relocate ;// fill LR with address
+pre_relocate:
+ mflr r2
+ lis r1,0x0010
+ cmpl cr0,r2,r1 ;// Check LR is less than 1MB
+ blt finished_relocate ;// No need to relocate if less than 1MB
+
+ ;// Get addresses for relocation.
+ ;// Write address in r5
+ ;// Read address in r1
+ li r5,0
+ lis r1, -1 ;// fill r1 with ffff..ff0000
+
+ and r1,r1,r2 ;// and with pre_relocate's address from r2 to get start of
+ ;// rom section.
+
+ ;// Update LR to low address.
+ clrldi r2,r2,48 ;// Equiv to ~(0x0FFFF)
+ mtlr 2
+
+ ;// Moving 1MB , so load r2 with (1MB / 8 bytes per word)
+ lis r2, 0x2
+ mtctr r2
+relocate_loop:
+ ;// The dcbst/sync/icbi/isync sequence comes from PowerISA
+ ld r4, 0(r1)
+ std r4, 0(r5)
+ dcbst 0,r5
+ sync
+ icbi 0,r5
+ isync
+ addi r1,r1,8
+ addi r5,r5,8
+ bdnz+ relocate_loop
+
+ ;// Now that we've relocated, erase exception prefix.
+ mfmsr r11
+
+ rldicl r11,r11,57,1 ;// Erase bit 6 ( equiv to r11 & ~(0x40))
+ rotldi r11,r11,7
+
+ mtmsr r11
+
+ ;// Jump to low address.
+ blr
+
+finished_relocate:
+ ;// Jump to main.
+ b _main
+@TODO RTC:133821 might not be needed */
+
+
+;// _main:
+;// Set up stack and TOC and call kernel's main.
+_main:
+ ;// Set up initial TOC Base
+ lis r2, main@h
+ ori r2, r2, main@l
+ ld r2,8(r2)
+
+ ;// Set up initial stack, space for 8 double-words
+ lis r1, kernel_stack@h
+ ori r1, r1, kernel_stack@l
+ addi r1, r1, 16320
+
+ ;// Call main.
+ bl main
+_main_loop:
+ b _main_loop
+
+
+;// @fn _other_thread_error:
+;// Used for threads other than first to handle this unexpected condition.
+_other_thread_error:
+ ;// Read spinlock value.
+ lis r2, kernel_other_thread_spinlock@h
+ ori r2, r2, kernel_other_thread_spinlock@l
+1:
+ ld r3, 0(r2)
+ ;// Loop until value is 1...
+ cmpi cr0, r3, 1
+ beq task_end_stub ;// End the multiple threads
+ or 1,1,1 ;// Lower thread priority.
+ b 1b
+
+
+ ;// @fn task_end_stub
+ ;// Stub to call a TASK_END syscall in the event that a task 'returns' from
+ ;// its entry point. We cannot call task_end() directly because profiling
+ ;// inserts garbage code into the task_end C function.
+.global task_end_stub
+task_end_stub:
+ mr r4, r3 ;// Move current rc (r3) to status value (r4)
+ li r3, 2 ;// TASK_END -> r3 (syscall number)
+ sc
+
+
+.section .data
+
+ .balign 1024
+kernel_stack:
+ .space 4*1024
+
+ .balign 8
+.global data_sandbox
+data_sandbox:
+ .space 64
+
+.global kernel_other_thread_spinlock
+kernel_other_thread_spinlock:
+ .space 8
+
+.global g_blScratchSpace
+g_blScratchSpace:
+ .space 8
+
diff --git a/src/bootloader/bootloader.C b/src/bootloader/bootloader.C
new file mode 100644
index 000000000..462217d76
--- /dev/null
+++ b/src/bootloader/bootloader.C
@@ -0,0 +1,84 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/bootloader/bootloader.C $ */
+/* */
+/* OpenPOWER HostBoot Project */
+/* */
+/* Contributors Listed Below - COPYRIGHT 2015,2016 */
+/* [+] International Business Machines Corp. */
+/* */
+/* */
+/* Licensed under the Apache License, Version 2.0 (the "License"); */
+/* you may not use this file except in compliance with the License. */
+/* You may obtain a copy of the License at */
+/* */
+/* http://www.apache.org/licenses/LICENSE-2.0 */
+/* */
+/* Unless required by applicable law or agreed to in writing, software */
+/* distributed under the License is distributed on an "AS IS" BASIS, */
+/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
+/* implied. See the License for the specific language governing */
+/* permissions and limitations under the License. */
+/* */
+/* IBM_PROLOG_END_TAG */
+#include <stdint.h>
+#include <bootloader/bootloader.H>
+#include <util/singleton.H>
+#include <kernel/cpu.H>
+
+#include <kernel/intmsghandler.H> // @TODO RTC:133821 might not be needed long-term
+
+#include <usr/pnor/ecc.H>
+
+#include <stdlib.h>
+
+extern uint64_t kernel_other_thread_spinlock;
+extern uint32_t data_sandbox[16]; // @TODO RTC:133821 temporary bringup
+
+namespace Bootloader{
+ extern "C"
+ int main()
+ {
+ // cppBootstrap(); @TODO RTC:133821 might not be needed long-term
+ // cv_blScratchSpace = ??? @TODO RTC:133821
+
+ // @TODO RTC:134064 Get location of HB base code in PNOR from TOC
+
+ // @TODO RTC:133821 Copy HB base code from PNOR to 0x200000
+
+ // Remove ECC from HB base code at 0x200000 and store result at 0x300000
+ PNOR::ECC::eccStatus rc = PNOR::ECC::CLEAN;
+// PNOR::ECC::removeECC(reinterpret_cast<uint8_t*>(0x200000),
+// reinterpret_cast<uint8_t*>(0x300000),
+// 0x100000); // @TODO RTC:133821 determine size
+
+ if (rc != PNOR::ECC::UNCORRECTABLE)
+ {
+// memcpy(reinterpret_cast<void*>(0x300000),
+// reinterpret_cast<void*>(0),
+// 0x100000); // @TODO RTC:133821 determine size // replace with asm cache inhibited instructions
+ }
+
+ // Ready to let the other CPUs go. @TODO RTC:133821 actually need to start relocated HB base code
+ lwsync();
+ kernel_other_thread_spinlock = 1;
+
+ data_sandbox[8] = 0x12345678; // @TODO RTC:133821 temporary bringup
+
+ MAGIC_INSTRUCTION(MAGIC_BREAK); // @TODO RTC:133821 temporary bringup
+
+ while(1); // @TODO
+ task_end_stub(); // @TODO
+ return 0;
+ }
+
+ void handleMMIO(uint64_t i_srcAddr,
+ uint64_t i_destAddr,
+ uint32_t i_size,
+ MMIOLoadStoreSizes i_ld_st_size)
+ {
+ // @TODO RTC:133821
+ }
+} // end namespace Bootloader
+
diff --git a/src/bootloader/makefile b/src/bootloader/makefile
new file mode 100644
index 000000000..cf5fe04a6
--- /dev/null
+++ b/src/bootloader/makefile
@@ -0,0 +1,33 @@
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: src/bootloader/makefile $
+#
+# OpenPOWER HostBoot Project
+#
+# Contributors Listed Below - COPYRIGHT 2015,2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+ROOTPATH = ../..
+
+OBJS += bl_start.o
+OBJS += bootloader.o
+OBJS += bl_pnor_ecc.o
+OBJS += bl_builtins.o
+
+include ${ROOTPATH}/config.mk
+
OpenPOWER on IntegriCloud