1/* $FreeBSD$ */ 2 3/*- 4 * Copyright (C) 2010-2016 Nathan Whitehorn 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29 30#include "assym.s" 31 32#include <sys/syscall.h> 33 34#include <machine/trap.h> 35#include <machine/param.h> 36#include <machine/spr.h> 37#include <machine/asm.h> 38 39#ifdef _CALL_ELF 40.abiversion _CALL_ELF 41#endif 42 43/* Glue for linker script */ 44.globl kernbase 45.set kernbase, KERNBASE 46 47/* 48 * Globals 49 */ 50 .data 51 .align 3 52GLOBAL(__startkernel) 53 .llong begin 54GLOBAL(__endkernel) 55 .llong end 56 57 .align 4 58#define TMPSTKSZ 16384 /* 16K temporary stack */ 59GLOBAL(tmpstk) 60 .space TMPSTKSZ 61 62TOC_ENTRY(tmpstk) 63 64 .text 65 .globl btext 66btext: 67 68/* 69 * Main kernel entry point. 70 * 71 * Calling convention: 72 * r3: Flattened Device Tree pointer (or zero) 73 * r4: ignored 74 * r5: OF client interface pointer (or zero) 75 * r6: Loader metadata pointer (or zero) 76 * r7: Magic cookie (0xfb5d104d) to indicate that r6 has loader metadata 77 */ 78 .text 79ASENTRY_NOPROF(__start) 80 /* Set 64-bit mode if not yet set before branching to C */ 81 mfmsr %r20 82 li %r21,1 83 insrdi %r20,%r21,1,0 84 mtmsrd %r20 85 isync 86 nop /* Make this block a multiple of 8 bytes */ 87 88 /* Set up the TOC pointer */ 89 b 0f 90 .align 3 910: nop 92 bl 1f 93 .llong __tocbase + 0x8000 - . 941: mflr %r2 95 ld %r1,0(%r2) 96 add %r2,%r1,%r2 97 98 /* Get load offset */ 99 ld %r31,-0x8000(%r2) /* First TOC entry is TOC base */ 100 subf %r31,%r31,%r2 /* Subtract from real TOC base to get base */ 101 102 /* Set up the stack pointer */ 103 ld %r1,TOC_REF(tmpstk)(%r2) 104 addi %r1,%r1,TMPSTKSZ-96 105 add %r1,%r1,%r31 106 107 /* Relocate kernel */ 108 std %r3,48(%r1) 109 std %r4,56(%r1) 110 std %r5,64(%r1) 111 std %r6,72(%r1) 112 std %r7,80(%r1) 113 114 bl 1f 115 .llong _DYNAMIC-. 1161: mflr %r3 117 ld %r4,0(%r3) 118 add %r3,%r4,%r3 119 mr %r4,%r31 120 bl elf_reloc_self 121 nop 122 ld %r3,48(%r1) 123 ld %r4,56(%r1) 124 ld %r5,64(%r1) 125 ld %r6,72(%r1) 126 ld %r7,80(%r1) 127 128 /* Begin CPU init */ 129 mr %r4,%r2 /* Replace ignored r4 with tocbase for trap handlers */ 130 bl powerpc_init 131 nop 132 133 /* Set stack pointer to new value and branch to mi_startup */ 134 mr %r1, %r3 135 li %r3, 0 136 std %r3, 0(%r1) 137 bl mi_startup 138 nop 139 140 /* Unreachable */ 141 b . 142 143#include <powerpc/aim/trap_subr64.S> 144