1/*-2* Copyright (C) 2010-2016 Nathan Whitehorn3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8* 1. Redistributions of source code must retain the above copyright9* notice, this list of conditions and the following disclaimer.10* 2. Redistributions in binary form must reproduce the above copyright11* notice, this list of conditions and the following disclaimer in the12* documentation and/or other materials provided with the distribution.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,18* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,19* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;20* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,21* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF23* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include "assym.inc"2728#include <sys/syscall.h>2930#include <machine/trap.h>31#include <machine/param.h>32#include <machine/spr.h>33#include <machine/asm.h>34#include <machine/vmparam.h>35#include "opt_platform.h"3637/* Locate the per-CPU data structure */38#define GET_CPUINFO(r) \39mfsprg0 r4041/*42* Compiled KERNBASE location and the kernel load address43*/44.globl kernbase45.set kernbase, KERNBASE4647/*48* Globals49*/50.data51.align 352GLOBAL(__startkernel)53.long begin54GLOBAL(__endkernel)55.long end56.align 457#define TMPSTKSZ 8192 /* 8K temporary stack */58GLOBAL(tmpstk)59.space TMPSTKSZ6061#ifdef KDB62#define TRAPSTKSZ 4096 /* 4k trap stack */63GLOBAL(trapstk)64.space TRAPSTKSZ65#endif6667.text68.globl btext69btext:7071/*72* Main kernel entry point.73*/74.text75.globl __start76__start:77/* Figure out where we are */78bl 1f79.long _DYNAMIC-.80.long _GLOBAL_OFFSET_TABLE_-.81.long tmpstk-.821: mflr %r308384/* Set up temporary stack pointer */85lwz %r1,8(%r30)86add %r1,%r1,%r3087addi %r1,%r1,(8+TMPSTKSZ-40)8889/* Relocate self */90stw %r3,16(%r1)91stw %r4,20(%r1)92stw %r5,24(%r1)93stw %r6,28(%r1)94stw %r7,32(%r1)9596lwz %r3,0(%r30) /* _DYNAMIC in %r3 */97add %r3,%r3,%r3098lwz %r4,4(%r30) /* GOT pointer */99add %r4,%r4,%r30100lwz %r4,4(%r4) /* got[0] is _DYNAMIC link addr */101subf %r4,%r4,%r3 /* subtract to calculate relocbase */102bl elf_reloc_self103104lwz %r3,16(%r1)105lwz %r4,20(%r1)106lwz %r5,24(%r1)107lwz %r6,28(%r1)108lwz %r7,32(%r1)109110/* MD setup */111bl powerpc_init112113/* Set stack pointer to new value and branch to mi_startup */114mr %r1, %r3115li %r3, 0116stw %r3, 0(%r1)117bl mi_startup118119/* mi_startup() does not return */120b .121122#include <powerpc/aim/trap_subr32.S>123124125