# HG changeset patch # User Josef 'Jeff' Sipek # Date 1565113133 14400 # Tue Aug 06 13:38:53 2019 -0400 # Node ID 43f435d0d45499596800caf9cd2ddebbe0f6d2b9 # Parent 5874e9bc3f8afb0f365cdc849123e38ed210f89d sastart: add a simple "standalone start" library We can avoid having to duplicate the same startup code over and over, by making a simple startup library that takes care of basic setup for us. E.g., it switches to z/Arch architecture mode, 64-bit addressing mode, and sets up a stack. In the future, it will do even more. Signed-off-by: Josef 'Jeff' Sipek diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -4,6 +4,7 @@ *.orig *.rej +*.a *.o *.raw diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ # SOFTWARE. # -SUBDIRS=lib cp nss loader +SUBDIRS=lib sastart cp nss loader all: build-installer diff --git a/sastart/Makefile b/sastart/Makefile new file mode 100644 --- /dev/null +++ b/sastart/Makefile @@ -0,0 +1,28 @@ +# +# Copyright (c) 2019 Josef 'Jeff' Sipek +# +# 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. +# + +LIB= sastart +SRCS= setmode.s \ + stack.s +BITS= 64 + +.include <${.CURDIR:H}/build.mk> diff --git a/loader/loader/setmode.s b/sastart/setmode.s copy from loader/loader/setmode.s copy to sastart/setmode.s --- a/loader/loader/setmode.s +++ b/sastart/setmode.s @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2009 Josef 'Jeff' Sipek + * Copyright (c) 2007-2019 Josef 'Jeff' Sipek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,53 +20,31 @@ * SOFTWARE. */ -.globl MAIN - .type MAIN, @function -MAIN: -# -# At this point, the machine is running in ESA390 mode. Let's load a new -# PSW, making it switch to 64-bit mode -# - - # switch to 64-bit mode - # - # Signal Processor - # Order 0x12: Set Architecture - # R1 bits 56-63 = 0x01 (switch all CPUs to z/Arch) - SR %r1, %r1 - LHI %r1, 0x1 # switch all to z/Arch - SR %r3, %r3 # CPU Address (CPU0000) - SIGP %r1, %r3, 0x12 # Signal, order 0x12 - SAM64 - # On error: - # Bit 55 = 1, cc1 (inval param) - # Bit 54 = 1, cc1 (incorrect state) - - # FIXME: check for errors? +#include -# -# At this point, we should be in 64-bit mode -# +/* + * The ESA/390 IPL entry point + * + * At this point, the machine is running in ESA/390 mode. Let's load + * a new PSW, making it switch to 64-bit mode + */ +ENTRY(_start390) + /* switch to 64-bit arch mode */ + SR %r1, %r1 + LHI %r1, 0x1 # switch all CPUs to z/Arch + SR %r3, %r3 # CPU Address + SIGP %r1, %r3, 0x12 # order 0x12 = set architecture - # - # It is unfortunate that the below code is required. - # - # Let's set the stack pointer to make gcc happy - # - # A standard stack frame is 160 bytes. - # - # NOTE: Once this thread of execution turns into the idle thread, - # the stack can be reused for something else. Since it's allocated - # in the 128th processor's PSA, we have to make sure that it won't - # get initialized until after the idle thread kicks in. - # + /* + * FIXME: check for errors? + * + * On error: + * Bit 55 = 1, cc1 (inval param) + * Bit 54 = 1, cc1 (incorrect state) + */ - # r15 = 0x100000 - # = (1 << 20) - # - SR %r15, %r15 - LHI %r15, 0x1 - SLL %r15, 20 - AHI %r15, -160 + /* switch to 64-bit addr mode */ + SAM64 - BRC 15,load_nucleus + J _start +SET_SIZE(_start390) diff --git a/sastart/stack.s b/sastart/stack.s new file mode 100644 --- /dev/null +++ b/sastart/stack.s @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2007-2019 Josef 'Jeff' Sipek + * + * 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. + */ + +#include + +/* + * The z/Arch IPL entry point (or called by _start390) + * + * At this point, the machine is running in z/Arch mode with 64-bit + * addressing mode. + */ +ENTRY(_start) + /* set up stack */ + LARL %r15, _stack + LA %r15, 4096-160(%r15) + + /* now jump to start code */ + BRAS %r14, start + + /* stop all CPUs in case we accidentally returned */ + J _die +SET_SIZE(_start) + +ENTRY(_die) + SR %r1, %r1 # not used, but should be zero + SR %r3, %r3 # CPU Address + SIGP %r1, %r3, 0x05 # order 0x05 = stop + + /* infinite loop in case sigp failed */ +0: + J 0b +SET_SIZE(_die) + +.bss +.align 4096 +.type _stack,@object +_stack: + .space 4096 +.size _stack, .-_stack