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 */ 77 .text 78ASENTRY_NOPROF(__start) 79 /* Set 64-bit mode if not yet set before branching to C */ 80 mfmsr %r20 81 li %r21,1 82 insrdi %r20,%r21,1,0 83 mtmsrd %r20 84 isync 85 nop /* Make this block a multiple of 8 bytes */ 86 87 /* Set up the TOC pointer */ 88 b 0f 89 .align 3 900: nop 91 bl 1f 92 .llong __tocbase + 0x8000 - . 931: mflr %r2 94 ld %r1,0(%r2) 95 add %r2,%r1,%r2 96 97 /* Get load offset */ 98 ld %r31,-0x8000(%r2) /* First TOC entry is TOC base */ 99 subf %r31,%r31,%r2 /* Subtract from real TOC base to get base */ 100 101 /* Set up the stack pointer */ 102 ld %r1,TOC_REF(tmpstk)(%r2) 103 addi %r1,%r1,TMPSTKSZ-96 104 add %r1,%r1,%r31 105 106 /* Relocate kernel */ 107 std %r3,48(%r1) 108 std %r4,56(%r1) 109 std %r5,64(%r1) 110 std %r6,72(%r1) 111 bl 1f 112 .llong _DYNAMIC-. 1131: mflr %r3 114 ld %r4,0(%r3) 115 add %r3,%r4,%r3 116 mr %r4,%r31 117 bl elf_reloc_self 118 nop 119 ld %r3,48(%r1) 120 ld %r4,56(%r1) 121 ld %r5,64(%r1) 122 ld %r6,72(%r1) 123 124 /* Begin CPU init */ 125 mr %r4,%r2 /* Replace ignored r4 with tocbase for trap handlers */ 126 bl powerpc_init 127 nop 128 129 /* Set stack pointer to new value and branch to mi_startup */ 130 mr %r1, %r3 131 li %r3, 0 132 std %r3, 0(%r1) 133 bl mi_startup 134 nop 135 136 /* Unreachable */ 137 b . 138 139#include <powerpc/aim/trap_subr64.S> 140